v4l2: bufferpool: reset buffer size in release_buffer
[platform/upstream/gst-plugins-good.git] / sys / v4l2 / gstv4l2bufferpool.c
index 6208d13..f885156 100644 (file)
@@ -40,8 +40,6 @@
 
 #include <gstv4l2bufferpool.h>
 
-#include "gstv4l2src.h"
-#include "gstv4l2sink.h"
 #include "v4l2_calls.h"
 #include "gst/gst-i18n-plugin.h"
 #include <gst/glib-compat-private.h>
@@ -382,7 +380,7 @@ gst_v4l2_buffer_pool_set_config (GstBufferPool * bpool, GstStructure * config)
   pool->copy_threshold = copy_threshold;
 
   if (obj->mode == GST_V4L2_IO_DMABUF)
-       allocator = gst_dmabuf_allocator_obtain ();
+    allocator = gst_dmabuf_allocator_obtain ();
 
   if (pool->allocator)
     gst_object_unref (pool->allocator);
@@ -524,8 +522,9 @@ gst_v4l2_buffer_pool_stop (GstBufferPool * bpool)
   ret = GST_BUFFER_POOL_CLASS (parent_class)->stop (bpool);
 
   /* then free the remaining buffers */
-  for (n = 0; n < pool->num_queued; n++) {
-    gst_v4l2_buffer_pool_free_buffer (bpool, pool->buffers[n]);
+  for (n = 0; n < pool->num_buffers; n++) {
+    if (pool->buffers[n])
+      gst_v4l2_buffer_pool_free_buffer (bpool, pool->buffers[n]);
   }
   pool->num_queued = 0;
   g_free (pool->buffers);
@@ -684,8 +683,6 @@ gst_v4l2_buffer_pool_dqbuf (GstV4l2BufferPool * pool, GstBuffer ** buffer)
   /* this can change at every frame, esp. with jpeg */
   if (obj->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
     gst_buffer_resize (outbuf, 0, vbuffer.bytesused);
-  else
-    gst_buffer_resize (outbuf, 0, vbuffer.length);
 
   GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
 
@@ -888,12 +885,20 @@ gst_v4l2_buffer_pool_release_buffer (GstBufferPool * bpool, GstBuffer * buffer)
         case GST_V4L2_IO_MMAP:
         {
           GstV4l2Meta *meta;
+          guint index;
 
           meta = GST_V4L2_META_GET (buffer);
           g_assert (meta != NULL);
 
-          if (pool->buffers[meta->vbuffer.index] == NULL) {
-            GST_LOG_OBJECT (pool, "buffer not queued, putting on free list");
+          index = meta->vbuffer.index;
+
+          if (pool->buffers[index] == NULL) {
+            GST_LOG_OBJECT (pool, "buffer %u not queued, putting on free list",
+                index);
+
+            /* reset to the full length, in case it was changed */
+            gst_buffer_resize (buffer, 0, meta->vbuffer.length);
+
             /* playback, put the buffer back in the queue to refill later. */
             GST_BUFFER_POOL_CLASS (parent_class)->release_buffer (bpool,
                 buffer);
@@ -901,7 +906,7 @@ gst_v4l2_buffer_pool_release_buffer (GstBufferPool * bpool, GstBuffer * buffer)
             /* the buffer is queued in the device but maybe not played yet. We just
              * leave it there and not make it available for future calls to acquire
              * for now. The buffer will be dequeued and reused later. */
-            GST_LOG_OBJECT (pool, "buffer is queued");
+            GST_LOG_OBJECT (pool, "buffer %u is queued", index);
           }
           break;
         }