vaapiencode: fix possible hang on SIGINT.
authorWind Yuan <feng.yuan@intel.com>
Tue, 17 Dec 2013 09:23:42 +0000 (04:23 -0500)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Tue, 14 Jan 2014 18:14:41 +0000 (19:14 +0100)
vaapiencode might hang when the pipeline is stopped without any EOS,
e.g. when <Ctrl>+C is pressed, thus causing the srcpad task to keep
running and locked. This fixes a possible deadlock on state change
from PAUSED to READY.

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

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
gst/vaapi/gstvaapiencode.c

index 2ac023d..9344f97 100644 (file)
@@ -595,6 +595,22 @@ gst_vaapiencode_finish (GstVideoEncoder * venc)
   return ret;
 }
 
+static GstStateChangeReturn
+gst_vaapiencode_change_state (GstElement * element, GstStateChange transition)
+{
+  GstVaapiEncode *const encode = GST_VAAPIENCODE_CAST (element);
+
+  switch (transition) {
+    case GST_STATE_CHANGE_PAUSED_TO_READY:
+      gst_pad_stop_task (GST_VAAPI_PLUGIN_BASE_SRC_PAD (encode));
+      break;
+    default:
+      break;
+  }
+  return GST_ELEMENT_CLASS (gst_vaapiencode_parent_class)->
+      change_state (element, transition);
+}
+
 #if GST_CHECK_VERSION(1,0,0)
 static gboolean
 gst_vaapiencode_propose_allocation (GstVideoEncoder * venc, GstQuery * query)
@@ -639,6 +655,7 @@ static void
 gst_vaapiencode_class_init (GstVaapiEncodeClass * klass)
 {
   GObjectClass *const object_class = G_OBJECT_CLASS (klass);
+  GstElementClass *const element_class = GST_ELEMENT_CLASS (klass);
   GstVideoEncoderClass *const venc_class = GST_VIDEO_ENCODER_CLASS (klass);
 
   GST_DEBUG_CATEGORY_INIT (gst_vaapiencode_debug,
@@ -648,6 +665,9 @@ gst_vaapiencode_class_init (GstVaapiEncodeClass * klass)
 
   object_class->finalize = gst_vaapiencode_finalize;
 
+  element_class->change_state =
+      GST_DEBUG_FUNCPTR (gst_vaapiencode_change_state);
+
   venc_class->open = GST_DEBUG_FUNCPTR (gst_vaapiencode_open);
   venc_class->close = GST_DEBUG_FUNCPTR (gst_vaapiencode_close);
   venc_class->set_format = GST_DEBUG_FUNCPTR (gst_vaapiencode_set_format);