vaapidecode: Check the condition after taking the lock
authorOlivier Crete <olivier.crete@collabora.com>
Wed, 4 Feb 2015 16:34:59 +0000 (18:34 +0200)
committerSreerenj Balachandran <sreerenj.balachandran@intel.com>
Wed, 4 Feb 2015 16:34:59 +0000 (18:34 +0200)
Otherwise the condition could become true before the lock
is taken and the g_cond_signal() could be called
before the g_cond_wait(), so the g_cond_wait() is never
awoken.

https://bugzilla.gnome.org/show_bug.cgi?id=740645

gst-libs/gst/vaapi/gstvaapidecoder.h
gst-libs/gst/vaapi/gstvaapidecoder_priv.h
gst/vaapi/gstvaapidecode.c

index f98b345..77587d4 100644 (file)
@@ -129,6 +129,9 @@ gst_vaapi_decoder_decode (GstVaapiDecoder * decoder,
 GstVaapiDecoderStatus
 gst_vaapi_decoder_flush (GstVaapiDecoder * decoder);
 
+GstVaapiDecoderStatus
+gst_vaapi_decoder_check_status (GstVaapiDecoder * decoder);
+
 G_END_DECLS
 
 #endif /* GST_VAAPI_DECODER_H */
index 5a5cde4..2ac56e8 100644 (file)
@@ -275,10 +275,6 @@ gst_vaapi_decoder_push_frame (GstVaapiDecoder * decoder,
 
 G_GNUC_INTERNAL
 GstVaapiDecoderStatus
-gst_vaapi_decoder_check_status (GstVaapiDecoder * decoder);
-
-G_GNUC_INTERNAL
-GstVaapiDecoderStatus
 gst_vaapi_decoder_decode_codec_data (GstVaapiDecoder * decoder);
 
 G_END_DECLS
index a9c2462..f0e25cc 100644 (file)
@@ -235,13 +235,16 @@ gst_vaapidecode_decode_frame(GstVideoDecoder *vdec, GstVideoCodecFrame *frame)
     GstVaapiDecoderStatus status;
     GstFlowReturn ret;
 
+
     /* Decode current frame */
     for (;;) {
         status = gst_vaapi_decoder_decode(decode->decoder, frame);
         if (status == GST_VAAPI_DECODER_STATUS_ERROR_NO_SURFACE) {
             GST_VIDEO_DECODER_STREAM_UNLOCK(vdec);
             g_mutex_lock(&decode->decoder_mutex);
-            g_cond_wait(&decode->decoder_ready, &decode->decoder_mutex);
+            if (gst_vaapi_decoder_check_status (decode->decoder) ==
+                GST_VAAPI_DECODER_STATUS_ERROR_NO_SURFACE)
+              g_cond_wait(&decode->decoder_ready, &decode->decoder_mutex);
             g_mutex_unlock(&decode->decoder_mutex);
             GST_VIDEO_DECODER_STREAM_LOCK(vdec);
             if (decode->decoder_loop_status < 0)