v4l2videodec: Add lock for queue and stream off

Add lock for queue and stream off, or v4l2 core will complain it.
Remove sink event task stop as flush() will do the same.

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

UpStream Status: Pending

Signed-off-by: Song Bing<bing.song@nxp.com>
diff --git a/sys/v4l2/gstv4l2bufferpool.c b/sys/v4l2/gstv4l2bufferpool.c
index 2653331..92beb88 100644
--- a/sys/v4l2/gstv4l2bufferpool.c
+++ b/sys/v4l2/gstv4l2bufferpool.c
@@ -690,6 +690,8 @@
   if (!pool->streaming)
     return;
 
+  GST_OBJECT_LOCK (pool);
+
   switch (obj->mode) {
     case GST_V4L2_IO_MMAP:
     case GST_V4L2_IO_USERPTR:
@@ -726,6 +728,8 @@
       g_atomic_int_add (&pool->num_queued, -1);
     }
   }
+
+  GST_OBJECT_UNLOCK (pool);
 }
 
 static gboolean
@@ -1162,6 +1166,8 @@
   gsize size;
   gint i;
 
+  GST_OBJECT_LOCK (pool);
+
   res = gst_v4l2_allocator_dqbuf (pool->vallocator, &group);
   if (res == GST_FLOW_EOS)
     goto eos;
@@ -1178,11 +1184,11 @@
   /* mark the buffer outstanding */
   pool->buffers[group->buffer.index] = NULL;
   if (g_atomic_int_dec_and_test (&pool->num_queued)) {
-    GST_OBJECT_LOCK (pool);
     pool->empty = TRUE;
-    GST_OBJECT_UNLOCK (pool);
   }
 
+  GST_OBJECT_UNLOCK (pool);
+
   timestamp = GST_TIMEVAL_TO_TIME (group->buffer.timestamp);
 
   size = 0;
@@ -1291,14 +1297,17 @@
   /* ERRORS */
 eos:
   {
+    GST_OBJECT_UNLOCK (pool);
     return GST_FLOW_EOS;
   }
 dqbuf_failed:
   {
+    GST_OBJECT_UNLOCK (pool);
     return GST_FLOW_ERROR;
   }
 no_buffer:
   {
+    GST_OBJECT_UNLOCK (pool);
     GST_ERROR_OBJECT (pool, "No free buffer found in the pool at index %d.",
         group->buffer.index);
     return GST_FLOW_ERROR;
diff --git a/sys/v4l2/gstv4l2videodec.c b/sys/v4l2/gstv4l2videodec.c
index b0eea9f..b9e00bc 100644
--- a/sys/v4l2/gstv4l2videodec.c
+++ b/sys/v4l2/gstv4l2videodec.c
@@ -938,28 +938,8 @@
   GstV4l2VideoDec *self = GST_V4L2_VIDEO_DEC (decoder);
   gboolean ret;
 
-  switch (GST_EVENT_TYPE (event)) {
-    case GST_EVENT_FLUSH_START:
-      GST_DEBUG_OBJECT (self, "flush start");
-      gst_v4l2_object_unlock (self->v4l2output);
-      gst_v4l2_object_unlock (self->v4l2capture);
-      break;
-    default:
-      break;
-  }
-
   ret = GST_VIDEO_DECODER_CLASS (parent_class)->sink_event (decoder, event);
 
-  switch (GST_EVENT_TYPE (event)) {
-    case GST_EVENT_FLUSH_START:
-      /* The processing thread should stop now, wait for it */
-      gst_pad_stop_task (decoder->srcpad);
-      GST_DEBUG_OBJECT (self, "flush start done");
-      break;
-    default:
-      break;
-  }
-
   return ret;
 }