commit bee22a976dd53674b45e7e19bbff936181cc98ca
Author: gb <gbeauchesne@splitted-desktop.com>
Date:   Tue Mar 2 23:45:51 2010 +0100

    Fix SW fallback on VA-API error during context initialization.

commit 5b2fbfd54a0eed1af6d11268093ce0421662af39
Author: gb <gbeauchesne@splitted-desktop.com>
Date:   Tue Mar 2 23:35:21 2010 +0100

    Rework fallback to SW if VA-API is not selected with --hwaccel.

diff --git a/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp b/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp
index da881fc..f935109 100644
--- a/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp
+++ b/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp
@@ -46,6 +46,7 @@ extern "C" {
 #include "FLVParser.h"
 
 #if USE_VAAPI
+#  include "vaapi_utils.h"
 #  include "VideoDecoderFfmpegVaapi.h"
 #  include "GnashVaapiImage.h"
 #endif
@@ -312,9 +313,11 @@ VideoDecoderFfmpeg::init(enum CodecID codecId, int /*width*/, int /*height*/,
     ctx->release_buffer = release_buffer;
 
 #if USE_VAAPI
-    VaapiContextFfmpeg *vactx = VaapiContextFfmpeg::create(codecId);
-    if (vactx)
-        reset_context(ctx, vactx);
+    if (vaapi_is_enabled()) {
+        VaapiContextFfmpeg *vactx = VaapiContextFfmpeg::create(codecId);
+        if (vactx)
+            reset_context(ctx, vactx);
+    }
 #endif
 
     int ret = avcodec_open(ctx, _videoCodec);
diff --git a/libvaapi/VaapiDisplay.cpp b/libvaapi/VaapiDisplay.cpp
index 7c2dbda..21f497e 100644
--- a/libvaapi/VaapiDisplay.cpp
+++ b/libvaapi/VaapiDisplay.cpp
@@ -19,6 +19,7 @@
 
 #include "log.h"
 #include "VaapiDisplay.h"
+#include "VaapiException.h"
 #include "vaapi_utils.h"
 
 namespace gnash {
@@ -28,7 +29,8 @@ VaapiDisplay::VaapiDisplay(VADisplay display)
 {
     GNASH_REPORT_FUNCTION;
 
-    init();
+    if (!init())
+        throw VaapiException("Could not create VA-API display");
 }
 
 VaapiDisplay::~VaapiDisplay()
diff --git a/libvaapi/VaapiGlobalContext.cpp b/libvaapi/VaapiGlobalContext.cpp
index f44e29c..7ed7c7d 100644
--- a/libvaapi/VaapiGlobalContext.cpp
+++ b/libvaapi/VaapiGlobalContext.cpp
@@ -27,6 +27,7 @@
 #ifdef USE_VAAPI_GLX
 #include "VaapiDisplayGLX.h"
 #endif
+#include "VaapiException.h"
 #include "vaapi_utils.h"
 
 namespace gnash {
@@ -35,7 +36,9 @@ VaapiGlobalContext::VaapiGlobalContext(std::auto_ptr<VaapiDisplay> display)
     : _display(display)
 {
     GNASH_REPORT_FUNCTION;
-    init();
+
+    if (!init())
+        throw VaapiException("could not initialize VA-API global context");
 }
 
 VaapiGlobalContext::~VaapiGlobalContext()
@@ -130,21 +133,24 @@ VaapiGlobalContext *VaapiGlobalContext::get()
 
     static std::auto_ptr<VaapiGlobalContext> vaapi_global_context;
 
-    if (!vaapi_is_enabled())
-        return NULL;
-
     if (!vaapi_global_context.get()) {
         std::auto_ptr<VaapiDisplay> dpy;
         /* XXX: this won't work with multiple renders built-in */
+        try {
 #if USE_VAAPI_GLX
-        dpy.reset(new VaapiDisplayGLX());
+            dpy.reset(new VaapiDisplayGLX());
 #else
-        dpy.reset(new VaapiDisplayX11());
+            dpy.reset(new VaapiDisplayX11());
 #endif
-        if (!dpy.get()) {
+            if (!dpy.get()) {
+                return NULL;
+            }
+            vaapi_global_context.reset(new VaapiGlobalContext(dpy));
+        }
+        catch (...) {
+            vaapi_set_is_enabled(false);
             return NULL;
         }
-        vaapi_global_context.reset(new VaapiGlobalContext(dpy));
     }
     return vaapi_global_context.get();
 }
