From: Gwenole Beauchesne Date: Mon, 6 Feb 2012 14:54:09 +0000 (+0100) Subject: mpeg2: fix crash when there is no free surface to decode into. X-Git-Tag: 0.3.5~20 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d75d70d395d48eb02ef31b5656131b85c8221a97;p=platform%2Fupstream%2Fgstreamer-vaapi.git mpeg2: fix crash when there is no free surface to decode into. --- diff --git a/gst-libs/gst/vaapi/gstvaapidecoder.c b/gst-libs/gst/vaapi/gstvaapidecoder.c index a83004e..b316a8a 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder.c +++ b/gst-libs/gst/vaapi/gstvaapidecoder.c @@ -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; +} diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c b/gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c index 3e6c5aa..a702b96 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c +++ b/gst-libs/gst/vaapi/gstvaapidecoder_mpeg2.c @@ -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); diff --git a/gst-libs/gst/vaapi/gstvaapidecoder_priv.h b/gst-libs/gst/vaapi/gstvaapidecoder_priv.h index 87ce200..45478d4 100644 --- a/gst-libs/gst/vaapi/gstvaapidecoder_priv.h +++ b/gst-libs/gst/vaapi/gstvaapidecoder_priv.h @@ -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 */