v4l2videodec: Don't lock the decoder when stopping task
[platform/upstream/gst-plugins-good.git] / sys / v4l2 / gstv4l2videodec.c
index 866ce67..9de0b54 100644 (file)
@@ -74,8 +74,8 @@ gst_v4l2_video_dec_set_property (GObject * object,
           pspec);
       break;
     case PROP_CAPTURE_IO_MODE:
-      gst_v4l2_object_set_property_helper (self->v4l2capture, prop_id, value,
-          pspec);
+      gst_v4l2_object_set_property_helper (self->v4l2capture, PROP_IO_MODE,
+          value, pspec);
       break;
 
     case PROP_DEVICE:
@@ -213,9 +213,10 @@ gst_v4l2_video_dec_stop (GstVideoDecoder * decoder)
   gst_v4l2_object_unlock (self->v4l2output);
   gst_v4l2_object_unlock (self->v4l2capture);
 
-  GST_VIDEO_DECODER_STREAM_LOCK (decoder);
   /* Wait for capture thread to stop */
   gst_pad_stop_task (decoder->srcpad);
+
+  GST_VIDEO_DECODER_STREAM_LOCK (decoder);
   self->output_flow = GST_FLOW_OK;
   GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
 
@@ -273,17 +274,18 @@ gst_v4l2_video_dec_flush (GstVideoDecoder * decoder)
   GST_DEBUG_OBJECT (self, "Flushing");
 
   /* Wait for capture thread to stop */
+  GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
   gst_pad_stop_task (decoder->srcpad);
+  GST_VIDEO_DECODER_STREAM_LOCK (decoder);
   self->output_flow = GST_FLOW_OK;
 
   if (self->v4l2output->pool)
-    gst_v4l2_buffer_pool_flush (GST_V4L2_BUFFER_POOL (self->v4l2output->pool));
+    gst_v4l2_buffer_pool_stop_streaming (GST_V4L2_BUFFER_POOL
+        (self->v4l2output->pool));
 
   if (self->v4l2capture->pool)
-    gst_v4l2_buffer_pool_flush (GST_V4L2_BUFFER_POOL (self->v4l2capture->pool));
-
-  /* Output will remain flushing until new frame comes in */
-  gst_v4l2_object_unlock_stop (self->v4l2capture);
+    gst_v4l2_buffer_pool_stop_streaming (GST_V4L2_BUFFER_POOL
+        (self->v4l2capture->pool));
 
   return TRUE;
 }
@@ -313,7 +315,7 @@ gst_v4l2_video_dec_finish (GstVideoDecoder * decoder)
     buffer = gst_buffer_new ();
     ret =
         gst_v4l2_buffer_pool_process (GST_V4L2_BUFFER_POOL (self->
-            v4l2output->pool), buffer);
+            v4l2output->pool), &buffer);
     gst_buffer_unref (buffer);
   }
   GST_VIDEO_DECODER_STREAM_LOCK (decoder);
@@ -396,7 +398,7 @@ gst_v4l2_video_dec_loop (GstVideoDecoder * decoder)
   GST_LOG_OBJECT (decoder, "Process output buffer");
   ret =
       gst_v4l2_buffer_pool_process (GST_V4L2_BUFFER_POOL (self->
-          v4l2capture->pool), buffer);
+          v4l2capture->pool), &buffer);
 
   if (ret != GST_FLOW_OK)
     goto beach;
@@ -467,14 +469,25 @@ gst_v4l2_video_dec_handle_frame (GstVideoDecoder * decoder,
       frame->input_buffer = NULL;
     }
 
-    if (!gst_buffer_pool_set_active (pool, TRUE))
-      goto activate_failed;
+    /* Ensure input internal pool is active */
+    if (!gst_buffer_pool_is_active (pool)) {
+      GstStructure *config = gst_buffer_pool_get_config (pool);
+      gst_buffer_pool_config_set_params (config, self->input_state->caps,
+          self->v4l2output->info.size, 2, 2);
+
+      /* There is no reason to refuse this config */
+      if (!gst_buffer_pool_set_config (pool, config))
+        goto activate_failed;
+
+      if (!gst_buffer_pool_set_active (pool, TRUE))
+        goto activate_failed;
+    }
 
     GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
     gst_v4l2_object_unlock_stop (self->v4l2output);
     ret =
         gst_v4l2_buffer_pool_process (GST_V4L2_BUFFER_POOL (self->
-            v4l2output->pool), codec_data);
+            v4l2output->pool), &codec_data);
     gst_v4l2_object_unlock (self->v4l2output);
     GST_VIDEO_DECODER_STREAM_LOCK (decoder);
 
@@ -514,7 +527,10 @@ gst_v4l2_video_dec_handle_frame (GstVideoDecoder * decoder,
     GST_DEBUG_OBJECT (self, "Starting decoding thread");
 
     /* Enable processing input */
+    gst_v4l2_buffer_pool_start_streaming (GST_V4L2_BUFFER_POOL
+        (self->v4l2capture->pool));
     gst_v4l2_object_unlock_stop (self->v4l2output);
+    gst_v4l2_object_unlock_stop (self->v4l2capture);
 
     /* Start the processing task, when it quits, the task will disable input
      * processing to unlock input if draining, or prevent potential block */
@@ -527,7 +543,7 @@ gst_v4l2_video_dec_handle_frame (GstVideoDecoder * decoder,
     GST_VIDEO_DECODER_STREAM_UNLOCK (decoder);
     ret =
         gst_v4l2_buffer_pool_process (GST_V4L2_BUFFER_POOL (self->v4l2output->
-            pool), frame->input_buffer);
+            pool), &frame->input_buffer);
     GST_VIDEO_DECODER_STREAM_LOCK (decoder);
 
     if (ret == GST_FLOW_FLUSHING) {
@@ -552,7 +568,7 @@ not_negotiated:
 activate_failed:
   {
     GST_ELEMENT_ERROR (self, RESOURCE, SETTINGS,
-        (_("Failed to allocated required memory.")),
+        (_("Failed to allocate required memory.")),
         ("Buffer pool activation failed"));
     return GST_FLOW_ERROR;
   }
@@ -811,7 +827,7 @@ gst_v4l2_video_dec_class_init (GstV4l2VideoDecClass * klass)
    *
    * Capture IO Mode
    */
-  g_object_class_install_property (gobject_class, PROP_IO_MODE,
+  g_object_class_install_property (gobject_class, PROP_CAPTURE_IO_MODE,
       g_param_spec_enum ("capture-io-mode", "Capture IO mode",
           "Capture I/O mode",
           GST_TYPE_V4L2_IO_MODE, GST_V4L2_IO_AUTO,