mpeg2: fix crash when there is no free surface to decode into.
authorGwenole Beauchesne <gwenole.beauchesne@intel.com>
Mon, 6 Feb 2012 14:54:09 +0000 (15:54 +0100)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Mon, 6 Feb 2012 14:54:42 +0000 (15:54 +0100)
gst-libs/gst/vaapi/gstvaapidecoder.c
gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c
gst-libs/gst/vaapi/gstvaapidecoder_priv.h

index a83004e..b316a8a 100644 (file)
@@ -99,14 +99,13 @@ pop_buffer(GstVaapiDecoder *decoder)
 static GstVaapiDecoderStatus
 decode_step(GstVaapiDecoder *decoder)
 {
-    GstVaapiDecoderPrivate * const priv = decoder->priv;
     GstVaapiDecoderStatus status;
     GstBuffer *buffer;
 
     /* Decoding will fail if there is no surface left */
-    if (priv->context &&
-        gst_vaapi_context_get_surface_count(priv->context) == 0)
-        return GST_VAAPI_DECODER_STATUS_ERROR_NO_SURFACE;
+    status = gst_vaapi_decoder_check_status(decoder);
+    if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
+        return status;
 
     do {
         buffer = pop_buffer(decoder);
@@ -561,3 +560,13 @@ gst_vaapi_decoder_push_surface_proxy(
 {
     return push_surface(decoder, proxy);
 }
+
+GstVaapiDecoderStatus
+gst_vaapi_decoder_check_status(GstVaapiDecoder *decoder)
+{
+    GstVaapiDecoderPrivate * const priv = decoder->priv;
+
+    if (priv->context && gst_vaapi_context_get_surface_count(priv->context) < 1)
+        return GST_VAAPI_DECODER_STATUS_ERROR_NO_SURFACE;
+    return GST_VAAPI_DECODER_STATUS_SUCCESS;
+}
index 3e6c5aa..a702b96 100644 (file)
@@ -685,6 +685,10 @@ decode_buffer(GstVaapiDecoderMpeg2 *decoder, GstBuffer *buffer)
         gst_adapter_flush(priv->adapter, ofs);
         size -= ofs;
 
+        status = gst_vaapi_decoder_check_status(decoder);
+        if (status != GST_VAAPI_DECODER_STATUS_SUCCESS)
+            break;
+
         if (size < 8)
             break;
         ofs = scan_for_start_code(priv->adapter, 4, size - 4, NULL);
index 87ce200..45478d4 100644 (file)
@@ -171,6 +171,10 @@ gst_vaapi_decoder_push_surface_proxy(
     GstVaapiSurfaceProxy *proxy
 ) attribute_hidden;
 
+GstVaapiDecoderStatus
+gst_vaapi_decoder_check_status(GstVaapiDecoder *decoder)
+    attribute_hidden;
+
 G_END_DECLS
 
 #endif /* GST_VAAPI_DECODER_PRIV_H */