3 * Copyright (C) 2001-2002 Ronald Bultje <rbultje@ronald.bitfreak.net>
4 * 2006 Edgard Lima <edgard.lima@gmail.com>
5 * 2009 Texas Instruments, Inc - http://www.ti.com/
7 * gstv4l2bufferpool.c V4L2 buffer pool class
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
22 * Boston, MA 02110-1301, USA.
30 # define _GNU_SOURCE /* O_CLOEXEC */
38 #include "gst/video/video.h"
39 #include "gst/video/gstvideometa.h"
40 #include "gst/video/gstvideopool.h"
41 #include "gst/allocators/gstdmabuf.h"
43 #include <gstv4l2bufferpool.h>
45 #include "gstv4l2object.h"
46 #include "gst/gst-i18n-plugin.h"
47 #include <gst/glib-compat-private.h>
48 #ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
49 #include <gst/allocators/gsttizenmemory.h>
50 #endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
52 GST_DEBUG_CATEGORY_STATIC (v4l2bufferpool_debug);
53 GST_DEBUG_CATEGORY_STATIC (CAT_PERFORMANCE);
54 #define GST_CAT_DEFAULT v4l2bufferpool_debug
56 #define GST_V4L2_IMPORT_QUARK gst_v4l2_buffer_pool_import_quark ()
61 #define gst_v4l2_buffer_pool_parent_class parent_class
62 G_DEFINE_TYPE (GstV4l2BufferPool, gst_v4l2_buffer_pool, GST_TYPE_BUFFER_POOL);
64 enum _GstV4l2BufferPoolAcquireFlags
66 GST_V4L2_BUFFER_POOL_ACQUIRE_FLAG_RESURRECT =
67 GST_BUFFER_POOL_ACQUIRE_FLAG_LAST,
68 GST_V4L2_BUFFER_POOL_ACQUIRE_FLAG_LAST
71 static void gst_v4l2_buffer_pool_release_buffer (GstBufferPool * bpool,
73 #ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
74 typedef struct _GstV4l2TizenBuffer GstV4l2TizenBuffer;
75 struct _GstV4l2TizenBuffer {
77 GstBuffer *gst_buffer;
78 GstBuffer *v4l2_buffer;
79 GstV4l2BufferPool *v4l2_pool;
82 static void gst_v4l2_tizen_buffer_finalize (GstV4l2TizenBuffer *tizen_buffer)
84 GstV4l2BufferPool *pool = NULL;
87 GST_ERROR ("NULL buffer");
91 pool = tizen_buffer->v4l2_pool;
93 gst_v4l2_buffer_pool_release_buffer (GST_BUFFER_POOL_CAST (pool), tizen_buffer->v4l2_buffer);
95 g_mutex_lock (&pool->buffer_lock);
97 pool->live_buffer_count--;
99 GST_DEBUG_OBJECT (pool, "release buffer[%d][tizen:%p,v4l2:%p,gst:%p], live[%d]",
100 tizen_buffer->index, tizen_buffer, tizen_buffer->v4l2_buffer,
101 tizen_buffer->gst_buffer, pool->live_buffer_count);
103 g_cond_signal (&pool->buffer_cond);
105 g_mutex_unlock (&pool->buffer_lock);
107 gst_object_unref (pool);
109 g_free(tizen_buffer);
112 static GstV4l2TizenBuffer *gst_v4l2_tizen_buffer_new (GstBuffer *v4l2_buffer, int index, GstV4l2BufferPool *v4l2_pool)
114 GstV4l2TizenBuffer *tizen_buffer = NULL;
115 GstMemory *memory = NULL;
117 tizen_buffer = g_new0 (GstV4l2TizenBuffer, 1);
118 tizen_buffer->index = index;
119 tizen_buffer->v4l2_buffer = v4l2_buffer;
120 tizen_buffer->gst_buffer = gst_buffer_new ();
121 tizen_buffer->v4l2_pool = gst_object_ref (v4l2_pool);
123 memory = gst_tizen_allocator_alloc_surface (v4l2_pool->tallocator,
124 &v4l2_pool->obj->info, v4l2_pool->vallocator->groups[index]->surface, (gpointer)tizen_buffer,
125 (GDestroyNotify)gst_v4l2_tizen_buffer_finalize);
127 gst_buffer_append_memory (tizen_buffer->gst_buffer, memory);
128 gst_buffer_set_size (tizen_buffer->gst_buffer, v4l2_pool->vallocator->s_info.size);
130 g_mutex_lock (&v4l2_pool->buffer_lock);
132 v4l2_pool->live_buffer_count++;
134 GST_DEBUG_OBJECT (v4l2_pool, "new buffer[tizen:%p,v4l2:%p,gst:%p], size[%d], live[%d]",
135 tizen_buffer, v4l2_buffer, tizen_buffer->gst_buffer,
136 v4l2_pool->vallocator->s_info.size, v4l2_pool->live_buffer_count);
138 g_mutex_unlock (&v4l2_pool->buffer_lock);
142 #endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
145 gst_v4l2_is_buffer_valid (GstBuffer * buffer, GstV4l2MemoryGroup ** out_group)
147 GstMemory *mem = gst_buffer_peek_memory (buffer, 0);
148 gboolean valid = FALSE;
150 if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY))
153 if (gst_is_dmabuf_memory (mem))
154 mem = gst_mini_object_get_qdata (GST_MINI_OBJECT (mem),
155 GST_V4L2_MEMORY_QUARK);
157 if (mem && gst_is_v4l2_memory (mem)) {
158 GstV4l2Memory *vmem = (GstV4l2Memory *) mem;
159 GstV4l2MemoryGroup *group = vmem->group;
162 if (group->n_mem != gst_buffer_n_memory (buffer))
165 for (i = 0; i < group->n_mem; i++) {
166 if (group->mem[i] != gst_buffer_peek_memory (buffer, i))
169 if (!gst_memory_is_writable (group->mem[i]))
183 gst_v4l2_buffer_pool_copy_buffer (GstV4l2BufferPool * pool, GstBuffer * dest,
186 const GstVideoFormatInfo *finfo = pool->caps_info.finfo;
188 GST_LOG_OBJECT (pool, "copying buffer");
190 if (finfo && (finfo->format != GST_VIDEO_FORMAT_UNKNOWN &&
191 finfo->format != GST_VIDEO_FORMAT_ENCODED)) {
192 GstVideoFrame src_frame, dest_frame;
194 GST_DEBUG_OBJECT (pool, "copy video frame");
196 /* we have raw video, use videoframe copy to get strides right */
197 if (!gst_video_frame_map (&src_frame, &pool->caps_info, src, GST_MAP_READ))
200 if (!gst_video_frame_map (&dest_frame, &pool->caps_info, dest,
202 gst_video_frame_unmap (&src_frame);
206 gst_video_frame_copy (&dest_frame, &src_frame);
208 gst_video_frame_unmap (&src_frame);
209 gst_video_frame_unmap (&dest_frame);
213 GST_DEBUG_OBJECT (pool, "copy raw bytes");
215 if (!gst_buffer_map (src, &map, GST_MAP_READ))
218 gst_buffer_fill (dest, 0, map.data, gst_buffer_get_size (src));
220 gst_buffer_unmap (src, &map);
221 gst_buffer_resize (dest, 0, gst_buffer_get_size (src));
224 gst_buffer_copy_into (dest, src,
225 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
227 GST_CAT_LOG_OBJECT (CAT_PERFORMANCE, pool, "slow copy into buffer %p", dest);
233 GST_ERROR_OBJECT (pool, "could not map buffer");
234 return GST_FLOW_ERROR;
247 gst_v4l2_buffer_pool_import_quark (void)
249 static GQuark quark = 0;
252 quark = g_quark_from_string ("GstV4l2BufferPoolUsePtrData");
258 _unmap_userptr_frame (struct UserPtrData *data)
261 gst_video_frame_unmap (&data->frame);
263 gst_buffer_unmap (data->buffer, &data->map);
266 gst_buffer_unref (data->buffer);
268 g_slice_free (struct UserPtrData, data);
272 gst_v4l2_buffer_pool_import_userptr (GstV4l2BufferPool * pool,
273 GstBuffer * dest, GstBuffer * src)
275 GstFlowReturn ret = GST_FLOW_OK;
276 GstV4l2MemoryGroup *group = NULL;
278 const GstVideoFormatInfo *finfo = pool->caps_info.finfo;
279 struct UserPtrData *data = NULL;
281 GST_LOG_OBJECT (pool, "importing userptr");
284 if (!gst_v4l2_is_buffer_valid (dest, &group))
287 if (V4L2_TYPE_IS_OUTPUT (pool->obj->type))
288 flags = GST_MAP_READ;
290 flags = GST_MAP_WRITE;
292 data = g_slice_new0 (struct UserPtrData);
294 if (finfo && (finfo->format != GST_VIDEO_FORMAT_UNKNOWN &&
295 finfo->format != GST_VIDEO_FORMAT_ENCODED)) {
296 gsize size[GST_VIDEO_MAX_PLANES] = { 0, };
299 data->is_frame = TRUE;
301 if (!gst_video_frame_map (&data->frame, &pool->caps_info, src, flags))
304 for (i = 0; i < GST_VIDEO_FORMAT_INFO_N_PLANES (finfo); i++) {
305 if (GST_VIDEO_FORMAT_INFO_IS_TILED (finfo)) {
306 gint tinfo = GST_VIDEO_FRAME_PLANE_STRIDE (&data->frame, i);
310 pstride = GST_VIDEO_TILE_X_TILES (tinfo) <<
311 GST_VIDEO_FORMAT_INFO_TILE_WS (finfo);
313 pheight = GST_VIDEO_TILE_Y_TILES (tinfo) <<
314 GST_VIDEO_FORMAT_INFO_TILE_HS (finfo);
316 size[i] = pstride * pheight;
318 size[i] = GST_VIDEO_FRAME_PLANE_STRIDE (&data->frame, i) *
319 GST_VIDEO_FRAME_COMP_HEIGHT (&data->frame, i);
323 /* In the single planar API, planes must be contiguous in memory and
324 * therefore they must have expected size. ie: no padding.
325 * To check these conditions, we check that plane 'i' start address
326 * + plane 'i' size equals to plane 'i+1' start address */
327 if (!V4L2_TYPE_IS_MULTIPLANAR (pool->obj->type)) {
328 for (i = 0; i < (GST_VIDEO_FORMAT_INFO_N_PLANES (finfo) - 1); i++) {
329 const struct v4l2_pix_format *pix_fmt = &pool->obj->format.fmt.pix;
331 gint estride = gst_v4l2_object_extrapolate_stride (finfo, i,
332 pix_fmt->bytesperline);
333 guint eheight = GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (finfo, i,
336 tmp = ((guint8 *) data->frame.data[i]) + estride * eheight;
337 if (tmp != data->frame.data[i + 1])
338 goto non_contiguous_mem;
342 if (!gst_v4l2_allocator_import_userptr (pool->vallocator, group,
343 data->frame.info.size, finfo->n_planes, data->frame.data, size))
349 data->is_frame = FALSE;
351 if (!gst_buffer_map (src, &data->map, flags))
354 ptr[0] = data->map.data;
355 size[0] = data->map.size;
357 if (!gst_v4l2_allocator_import_userptr (pool->vallocator, group,
358 data->map.size, 1, ptr, size))
362 data->buffer = gst_buffer_ref (src);
364 gst_mini_object_set_qdata (GST_MINI_OBJECT (dest), GST_V4L2_IMPORT_QUARK,
365 data, (GDestroyNotify) _unmap_userptr_frame);
367 gst_buffer_copy_into (dest, src,
368 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
374 GST_ERROR_OBJECT (pool, "destination buffer invalid or not from our pool");
375 return GST_FLOW_ERROR;
379 GST_ERROR_OBJECT (pool, "could not map buffer");
380 g_slice_free (struct UserPtrData, data);
381 return GST_FLOW_ERROR;
385 GST_ERROR_OBJECT (pool, "memory is not contiguous or plane size mismatch");
386 _unmap_userptr_frame (data);
387 return GST_FLOW_ERROR;
391 GST_ERROR_OBJECT (pool, "failed to import data");
392 _unmap_userptr_frame (data);
393 return GST_FLOW_ERROR;
398 gst_v4l2_buffer_pool_import_dmabuf (GstV4l2BufferPool * pool,
399 GstBuffer * dest, GstBuffer * src)
401 GstV4l2MemoryGroup *group = NULL;
402 GstMemory *dma_mem[GST_VIDEO_MAX_PLANES] = { 0 };
403 guint n_mem = gst_buffer_n_memory (src);
406 GST_LOG_OBJECT (pool, "importing dmabuf");
408 if (!gst_v4l2_is_buffer_valid (dest, &group))
411 if (n_mem > GST_VIDEO_MAX_PLANES)
414 for (i = 0; i < n_mem; i++)
415 dma_mem[i] = gst_buffer_peek_memory (src, i);
417 if (!gst_v4l2_allocator_import_dmabuf (pool->vallocator, group, n_mem,
421 gst_mini_object_set_qdata (GST_MINI_OBJECT (dest), GST_V4L2_IMPORT_QUARK,
422 gst_buffer_ref (src), (GDestroyNotify) gst_buffer_unref);
424 gst_buffer_copy_into (dest, src,
425 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
431 GST_ERROR_OBJECT (pool, "destination buffer invalid or not from our pool");
432 return GST_FLOW_ERROR;
436 GST_ERROR_OBJECT (pool, "could not map buffer");
437 return GST_FLOW_ERROR;
441 GST_ERROR_OBJECT (pool, "failed to import dmabuf");
442 return GST_FLOW_ERROR;
447 gst_v4l2_buffer_pool_prepare_buffer (GstV4l2BufferPool * pool,
448 GstBuffer * dest, GstBuffer * src)
450 GstFlowReturn ret = GST_FLOW_OK;
451 gboolean own_src = FALSE;
454 if (pool->other_pool == NULL) {
455 GST_ERROR_OBJECT (pool, "can't prepare buffer, source buffer missing");
456 return GST_FLOW_ERROR;
459 ret = gst_buffer_pool_acquire_buffer (pool->other_pool, &src, NULL);
460 if (ret != GST_FLOW_OK) {
461 GST_ERROR_OBJECT (pool, "failed to acquire buffer from downstream pool");
468 switch (pool->obj->mode) {
469 case GST_V4L2_IO_MMAP:
470 case GST_V4L2_IO_DMABUF:
471 ret = gst_v4l2_buffer_pool_copy_buffer (pool, dest, src);
473 case GST_V4L2_IO_USERPTR:
474 ret = gst_v4l2_buffer_pool_import_userptr (pool, dest, src);
476 case GST_V4L2_IO_DMABUF_IMPORT:
477 ret = gst_v4l2_buffer_pool_import_dmabuf (pool, dest, src);
484 gst_buffer_unref (src);
491 gst_v4l2_buffer_pool_alloc_buffer (GstBufferPool * bpool, GstBuffer ** buffer,
492 GstBufferPoolAcquireParams * params)
494 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool);
495 GstV4l2MemoryGroup *group = NULL;
496 GstBuffer *newbuf = NULL;
506 gst_buffer_new_allocate (pool->allocator, pool->size, &pool->params);
508 case GST_V4L2_IO_MMAP:
509 group = gst_v4l2_allocator_alloc_mmap (pool->vallocator);
511 case GST_V4L2_IO_DMABUF:
512 group = gst_v4l2_allocator_alloc_dmabuf (pool->vallocator,
515 case GST_V4L2_IO_USERPTR:
516 group = gst_v4l2_allocator_alloc_userptr (pool->vallocator);
518 case GST_V4L2_IO_DMABUF_IMPORT:
519 group = gst_v4l2_allocator_alloc_dmabufin (pool->vallocator);
523 g_assert_not_reached ();
529 newbuf = gst_buffer_new ();
531 for (i = 0; i < group->n_mem; i++)
532 gst_buffer_append_memory (newbuf, group->mem[i]);
533 } else if (newbuf == NULL) {
534 goto allocation_failed;
537 /* add metadata to raw video buffers */
538 if (pool->add_videometa)
539 gst_buffer_add_video_meta_full (newbuf, GST_VIDEO_FRAME_FLAG_NONE,
540 GST_VIDEO_INFO_FORMAT (info), GST_VIDEO_INFO_WIDTH (info),
541 GST_VIDEO_INFO_HEIGHT (info), GST_VIDEO_INFO_N_PLANES (info),
542 info->offset, info->stride);
551 GST_ERROR_OBJECT (pool, "failed to allocate buffer");
552 return GST_FLOW_ERROR;
557 gst_v4l2_buffer_pool_set_config (GstBufferPool * bpool, GstStructure * config)
559 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool);
560 GstV4l2Object *obj = pool->obj;
562 guint size, min_buffers, max_buffers;
563 GstAllocator *allocator;
564 GstAllocationParams params;
565 gboolean can_allocate = FALSE;
566 gboolean updated = FALSE;
569 pool->add_videometa =
570 gst_buffer_pool_config_has_option (config,
571 GST_BUFFER_POOL_OPTION_VIDEO_META);
573 /* parse the config and keep around */
574 if (!gst_buffer_pool_config_get_params (config, &caps, &size, &min_buffers,
578 if (!gst_buffer_pool_config_get_allocator (config, &allocator, ¶ms))
581 GST_DEBUG_OBJECT (pool, "config %" GST_PTR_FORMAT, config);
584 gst_object_unref (pool->allocator);
585 pool->allocator = NULL;
588 case GST_V4L2_IO_DMABUF:
589 pool->allocator = gst_dmabuf_allocator_new ();
590 can_allocate = GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, MMAP);
592 case GST_V4L2_IO_MMAP:
593 can_allocate = GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, MMAP);
595 case GST_V4L2_IO_USERPTR:
597 GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, USERPTR);
599 case GST_V4L2_IO_DMABUF_IMPORT:
600 can_allocate = GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, DMABUF);
604 pool->allocator = g_object_ref (allocator);
605 pool->params = params;
606 /* No need to change the configuration */
610 g_assert_not_reached ();
614 /* libv4l2 conversion code does not handle CREATE_BUFS, and may lead to
615 * instability and crash, disable it for now */
616 if (can_allocate && obj->fmtdesc->flags & V4L2_FMT_FLAG_EMULATED) {
617 GST_WARNING_OBJECT (pool,
618 "libv4l2 converter detected, disabling CREATE_BUFS");
619 can_allocate = FALSE;
620 GST_OBJECT_FLAG_UNSET (pool->vallocator,
621 GST_V4L2_ALLOCATOR_FLAG_MMAP_CREATE_BUFS
622 | GST_V4L2_ALLOCATOR_FLAG_USERPTR_CREATE_BUFS
623 | GST_V4L2_ALLOCATOR_FLAG_DMABUF_CREATE_BUFS);
626 if (min_buffers < GST_V4L2_MIN_BUFFERS) {
628 min_buffers = GST_V4L2_MIN_BUFFERS;
629 GST_INFO_OBJECT (pool, "increasing minimum buffers to %u", min_buffers);
632 /* respect driver requirements */
633 if (min_buffers < obj->min_buffers) {
635 min_buffers = obj->min_buffers;
636 GST_INFO_OBJECT (pool, "increasing minimum buffers to %u", min_buffers);
639 if (max_buffers > VIDEO_MAX_FRAME || max_buffers == 0) {
641 max_buffers = VIDEO_MAX_FRAME;
642 GST_INFO_OBJECT (pool, "reducing maximum buffers to %u", max_buffers);
645 if (min_buffers > max_buffers) {
647 min_buffers = max_buffers;
648 GST_INFO_OBJECT (pool, "reducing minimum buffers to %u", min_buffers);
649 } else if (min_buffers != max_buffers) {
652 max_buffers = min_buffers;
653 GST_INFO_OBJECT (pool, "can't allocate, setting maximum to minimum");
657 if (!pool->add_videometa && obj->need_video_meta) {
658 GST_INFO_OBJECT (pool, "adding needed video meta");
660 gst_buffer_pool_config_add_option (config,
661 GST_BUFFER_POOL_OPTION_VIDEO_META);
664 /* Always update the config to ensure the configured size matches */
665 gst_buffer_pool_config_set_params (config, caps, obj->info.size, min_buffers,
668 /* keep a GstVideoInfo with defaults for the when we need to copy */
669 gst_video_info_from_caps (&pool->caps_info, caps);
672 ret = GST_BUFFER_POOL_CLASS (parent_class)->set_config (bpool, config);
674 /* If anything was changed documentation recommand to return FALSE */
675 return !updated && ret;
680 GST_ERROR_OBJECT (pool, "invalid config %" GST_PTR_FORMAT, config);
686 gst_v4l2_buffer_pool_resurrect_buffer (GstV4l2BufferPool * pool)
688 GstBufferPoolAcquireParams params = { 0 };
689 GstBuffer *buffer = NULL;
692 GST_DEBUG_OBJECT (pool, "A buffer was lost, reallocating it");
694 /* block recursive calls to this function */
695 g_signal_handler_block (pool->vallocator, pool->group_released_handler);
698 (GstBufferPoolAcquireFlags) GST_V4L2_BUFFER_POOL_ACQUIRE_FLAG_RESURRECT |
699 GST_BUFFER_POOL_ACQUIRE_FLAG_DONTWAIT;
701 gst_buffer_pool_acquire_buffer (GST_BUFFER_POOL (pool), &buffer, ¶ms);
703 if (ret == GST_FLOW_OK)
704 gst_buffer_unref (buffer);
706 g_signal_handler_unblock (pool->vallocator, pool->group_released_handler);
712 gst_v4l2_buffer_pool_streamon (GstV4l2BufferPool * pool)
714 GstV4l2Object *obj = pool->obj;
720 case GST_V4L2_IO_MMAP:
721 case GST_V4L2_IO_USERPTR:
722 case GST_V4L2_IO_DMABUF:
723 case GST_V4L2_IO_DMABUF_IMPORT:
724 if (!V4L2_TYPE_IS_OUTPUT (pool->obj->type)) {
728 num_queued = g_atomic_int_get (&pool->num_queued);
729 if (num_queued < pool->num_allocated)
730 n = pool->num_allocated - num_queued;
732 /* For captures, we need to enqueue buffers before we start streaming,
733 * so the driver don't underflow immediatly. As we have put then back
734 * into the base class queue, resurrect them, then releasing will queue
736 for (i = 0; i < n; i++)
737 gst_v4l2_buffer_pool_resurrect_buffer (pool);
740 if (obj->ioctl (pool->video_fd, VIDIOC_STREAMON, &obj->type) < 0)
741 goto streamon_failed;
743 pool->streaming = TRUE;
745 GST_DEBUG_OBJECT (pool, "Started streaming");
755 GST_ERROR_OBJECT (pool, "error with STREAMON %d (%s)", errno,
761 /* Call with streamlock held, or when streaming threads are down */
763 gst_v4l2_buffer_pool_streamoff (GstV4l2BufferPool * pool)
765 GstBufferPoolClass *pclass = GST_BUFFER_POOL_CLASS (parent_class);
766 GstV4l2Object *obj = pool->obj;
768 #ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
770 #endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
772 if (!pool->streaming)
775 #ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
776 if (obj->tbm_output && !V4L2_TYPE_IS_OUTPUT(pool->obj->type)) {
777 g_mutex_lock (&pool->buffer_lock);
779 GST_INFO_OBJECT (pool, "live buffer[%d]", pool->live_buffer_count);
781 if (pool->live_buffer_count > 0) {
782 end_time = g_get_monotonic_time () + G_TIME_SPAN_SECOND;
785 GST_WARNING_OBJECT (pool, "wait for live buffer[%d]", pool->live_buffer_count);
787 if (!g_cond_wait_until (&pool->buffer_cond, &pool->buffer_lock, end_time)) {
788 GST_ERROR_OBJECT (pool, "failed to wait live buffer[%d]", pool->live_buffer_count);
792 GST_WARNING_OBJECT (pool, "signal received, check again : live count[%d]",
793 pool->live_buffer_count);
794 } while (pool->live_buffer_count > 0);
797 g_mutex_unlock (&pool->buffer_lock);
799 #endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
801 case GST_V4L2_IO_MMAP:
802 case GST_V4L2_IO_USERPTR:
803 case GST_V4L2_IO_DMABUF:
804 case GST_V4L2_IO_DMABUF_IMPORT:
806 if (obj->ioctl (pool->video_fd, VIDIOC_STREAMOFF, &obj->type) < 0)
807 GST_WARNING_OBJECT (pool, "STREAMOFF failed with errno %d (%s)",
808 errno, g_strerror (errno));
810 pool->streaming = FALSE;
812 GST_DEBUG_OBJECT (pool, "Stopped streaming");
814 if (pool->vallocator)
815 gst_v4l2_allocator_flush (pool->vallocator);
821 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
822 if (pool->buffers[i]) {
823 GstBuffer *buffer = pool->buffers[i];
824 GstBufferPool *bpool = GST_BUFFER_POOL (pool);
826 pool->buffers[i] = NULL;
828 if (V4L2_TYPE_IS_OUTPUT (pool->obj->type))
829 gst_v4l2_buffer_pool_release_buffer (bpool, buffer);
830 else /* Don't re-enqueue capture buffer on stop */
831 pclass->release_buffer (bpool, buffer);
833 g_atomic_int_add (&pool->num_queued, -1);
839 gst_v4l2_buffer_pool_start (GstBufferPool * bpool)
841 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool);
842 GstBufferPoolClass *pclass = GST_BUFFER_POOL_CLASS (parent_class);
843 GstV4l2Object *obj = pool->obj;
844 GstStructure *config;
846 guint size, min_buffers, max_buffers;
847 guint max_latency, min_latency, copy_threshold = 0;
848 gboolean can_allocate = FALSE, ret = TRUE;
850 GST_DEBUG_OBJECT (pool, "activating pool");
852 if (pool->other_pool) {
855 if (!gst_buffer_pool_set_active (pool->other_pool, TRUE))
856 goto other_pool_failed;
858 if (gst_buffer_pool_acquire_buffer (pool->other_pool, &buffer, NULL) !=
860 goto other_pool_failed;
862 if (!gst_v4l2_object_try_import (obj, buffer)) {
863 gst_buffer_unref (buffer);
866 gst_buffer_unref (buffer);
869 config = gst_buffer_pool_get_config (bpool);
870 if (!gst_buffer_pool_config_get_params (config, &caps, &size, &min_buffers,
874 min_latency = MAX (GST_V4L2_MIN_BUFFERS, obj->min_buffers);
880 /* This workaround a unfixable bug in libv4l2 when RW is emulated on top
881 * of MMAP. In this case, the first read initialize the queues, but the
882 * poll before that will always fail. Doing an empty read, forces the
883 * queue to be initialized now. We only do this if we have a streaming
885 if (obj->device_caps & V4L2_CAP_STREAMING)
886 obj->read (obj->video_fd, NULL, 0);
889 case GST_V4L2_IO_DMABUF:
890 case GST_V4L2_IO_MMAP:
894 can_allocate = GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, MMAP);
896 /* first, lets request buffers, and see how many we can get: */
897 GST_DEBUG_OBJECT (pool, "requesting %d MMAP buffers", min_buffers);
899 count = gst_v4l2_allocator_start (pool->vallocator, min_buffers,
901 pool->num_allocated = count;
903 if (count < GST_V4L2_MIN_BUFFERS) {
908 /* V4L2 buffer pool are often very limited in the amount of buffers it
909 * can offer. The copy_threshold will workaround this limitation by
910 * falling back to copy if the pipeline needed more buffers. This also
911 * prevent having to do REQBUFS(N)/REQBUFS(0) everytime configure is
913 if (count != min_buffers || pool->enable_copy_threshold) {
914 GST_WARNING_OBJECT (pool,
915 "Uncertain or not enough buffers, enabling copy threshold");
917 copy_threshold = min_latency;
922 case GST_V4L2_IO_USERPTR:
927 GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, USERPTR);
929 GST_DEBUG_OBJECT (pool, "requesting %d USERPTR buffers", min_buffers);
931 count = gst_v4l2_allocator_start (pool->vallocator, min_buffers,
932 V4L2_MEMORY_USERPTR);
934 /* There is no rational to not get what we asked */
935 if (count < min_buffers) {
943 case GST_V4L2_IO_DMABUF_IMPORT:
947 can_allocate = GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, DMABUF);
949 GST_DEBUG_OBJECT (pool, "requesting %d DMABUF buffers", min_buffers);
951 count = gst_v4l2_allocator_start (pool->vallocator, min_buffers,
954 /* There is no rational to not get what we asked */
955 if (count < min_buffers) {
966 g_assert_not_reached ();
971 max_latency = max_buffers;
973 max_latency = min_buffers;
976 pool->copy_threshold = copy_threshold;
977 pool->max_latency = max_latency;
978 pool->min_latency = min_latency;
979 pool->num_queued = 0;
981 if (max_buffers != 0 && max_buffers < min_buffers)
982 max_buffers = min_buffers;
984 gst_buffer_pool_config_set_params (config, caps, size, min_buffers,
986 pclass->set_config (bpool, config);
987 gst_structure_free (config);
989 /* now, allocate the buffers: */
990 if (!pclass->start (bpool))
993 if (!V4L2_TYPE_IS_OUTPUT (obj->type)) {
994 if (g_atomic_int_get (&pool->num_queued) < min_buffers)
997 pool->group_released_handler =
998 g_signal_connect_swapped (pool->vallocator, "group-released",
999 G_CALLBACK (gst_v4l2_buffer_pool_resurrect_buffer), pool);
1000 ret = gst_v4l2_buffer_pool_streamon (pool);
1008 GST_ERROR_OBJECT (pool, "invalid config %" GST_PTR_FORMAT, config);
1009 gst_structure_free (config);
1014 GST_ERROR_OBJECT (pool,
1015 "we received %d buffer from device '%s', we want at least %d",
1016 min_buffers, obj->videodev, GST_V4L2_MIN_BUFFERS);
1017 gst_structure_free (config);
1022 GST_ERROR_OBJECT (pool, "allocate failed");
1027 GST_ERROR_OBJECT (pool, "failed to activate the other pool %"
1028 GST_PTR_FORMAT, pool->other_pool);
1033 GST_ERROR_OBJECT (pool, "failed to queue buffers into the capture queue");
1038 GST_ERROR_OBJECT (pool, "cannot import buffers from downstream pool");
1044 gst_v4l2_buffer_pool_vallocator_stop (GstV4l2BufferPool * pool)
1048 if (!pool->vallocator)
1051 vret = gst_v4l2_allocator_stop (pool->vallocator);
1053 if (vret == GST_V4L2_BUSY)
1054 GST_WARNING_OBJECT (pool, "some buffers are still outstanding");
1056 return (vret == GST_V4L2_OK);
1060 gst_v4l2_buffer_pool_stop (GstBufferPool * bpool)
1062 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool);
1066 return gst_v4l2_buffer_pool_vallocator_stop (pool);
1068 GST_DEBUG_OBJECT (pool, "stopping pool");
1070 if (pool->group_released_handler > 0) {
1071 g_signal_handler_disconnect (pool->vallocator,
1072 pool->group_released_handler);
1073 pool->group_released_handler = 0;
1076 if (pool->other_pool) {
1077 gst_buffer_pool_set_active (pool->other_pool, FALSE);
1078 gst_object_unref (pool->other_pool);
1079 pool->other_pool = NULL;
1082 gst_v4l2_buffer_pool_streamoff (pool);
1084 ret = GST_BUFFER_POOL_CLASS (parent_class)->stop (bpool);
1087 ret = gst_v4l2_buffer_pool_vallocator_stop (pool);
1093 gst_v4l2_buffer_pool_orphan (GstBufferPool ** bpool)
1095 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (*bpool);
1098 if (!GST_V4L2_ALLOCATOR_CAN_ORPHAN_BUFS (pool->vallocator))
1101 if (g_getenv ("GST_V4L2_FORCE_DRAIN"))
1104 GST_DEBUG_OBJECT (pool, "orphaning pool");
1106 gst_buffer_pool_set_active (*bpool, FALSE);
1108 * If the buffer pool has outstanding buffers, it will not be stopped
1109 * by the base class when set inactive. Stop it manually and mark it
1112 ret = gst_v4l2_buffer_pool_stop (*bpool);
1114 ret = gst_v4l2_allocator_orphan (pool->vallocator);
1119 pool->orphaned = TRUE;
1120 gst_object_unref (*bpool);
1128 gst_v4l2_buffer_pool_flush_start (GstBufferPool * bpool)
1130 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool);
1132 GST_DEBUG_OBJECT (pool, "start flushing");
1134 gst_poll_set_flushing (pool->poll, TRUE);
1136 GST_OBJECT_LOCK (pool);
1137 pool->empty = FALSE;
1138 g_cond_broadcast (&pool->empty_cond);
1139 GST_OBJECT_UNLOCK (pool);
1141 if (pool->other_pool)
1142 gst_buffer_pool_set_flushing (pool->other_pool, TRUE);
1146 gst_v4l2_buffer_pool_flush_stop (GstBufferPool * bpool)
1148 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool);
1150 GST_DEBUG_OBJECT (pool, "stop flushing");
1152 if (pool->other_pool)
1153 gst_buffer_pool_set_flushing (pool->other_pool, FALSE);
1155 gst_poll_set_flushing (pool->poll, FALSE);
1158 static GstFlowReturn
1159 gst_v4l2_buffer_pool_poll (GstV4l2BufferPool * pool, gboolean wait)
1162 GstClockTime timeout;
1165 timeout = GST_CLOCK_TIME_NONE;
1169 /* In RW mode there is no queue, hence no need to wait while the queue is
1171 if (pool->obj->mode != GST_V4L2_IO_RW) {
1172 GST_OBJECT_LOCK (pool);
1174 if (!wait && pool->empty) {
1175 GST_OBJECT_UNLOCK (pool);
1180 g_cond_wait (&pool->empty_cond, GST_OBJECT_GET_LOCK (pool));
1182 GST_OBJECT_UNLOCK (pool);
1185 if (!pool->can_poll_device) {
1192 GST_LOG_OBJECT (pool, "polling device");
1195 ret = gst_poll_wait (pool->poll, timeout);
1196 if (G_UNLIKELY (ret < 0)) {
1204 GST_WARNING_OBJECT (pool,
1205 "v4l2 device doesn't support polling. Disabling"
1206 " using libv4l2 in this case may cause deadlocks");
1207 pool->can_poll_device = FALSE;
1214 if (gst_poll_fd_has_error (pool->poll, &pool->pollfd))
1226 GST_DEBUG_OBJECT (pool, "stop called");
1227 return GST_FLOW_FLUSHING;
1231 GST_ELEMENT_ERROR (pool->obj->element, RESOURCE, READ, (NULL),
1232 ("poll error %d: %s (%d)", ret, g_strerror (errno), errno));
1233 return GST_FLOW_ERROR;
1236 return GST_FLOW_CUSTOM_SUCCESS;
1239 static GstFlowReturn
1240 gst_v4l2_buffer_pool_qbuf (GstV4l2BufferPool * pool, GstBuffer * buf,
1241 GstV4l2MemoryGroup * group)
1243 const GstV4l2Object *obj = pool->obj;
1244 GstClockTime timestamp;
1247 index = group->buffer.index;
1249 if (pool->buffers[index] != NULL)
1250 goto already_queued;
1252 GST_LOG_OBJECT (pool, "queuing buffer %i", index);
1254 if (V4L2_TYPE_IS_OUTPUT (obj->type)) {
1255 enum v4l2_field field;
1257 /* Except when field is set to alternate, buffer field is the same as
1258 * the one defined in format */
1259 if (V4L2_TYPE_IS_MULTIPLANAR (obj->type))
1260 field = obj->format.fmt.pix_mp.field;
1262 field = obj->format.fmt.pix.field;
1264 /* NB: At this moment, we can't have alternate mode because it not handled
1266 if (field == V4L2_FIELD_ALTERNATE) {
1267 if (GST_BUFFER_FLAG_IS_SET (buf, GST_VIDEO_FRAME_FLAG_TFF))
1268 field = V4L2_FIELD_TOP;
1270 field = V4L2_FIELD_BOTTOM;
1273 group->buffer.field = field;
1276 if (GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
1277 timestamp = GST_BUFFER_TIMESTAMP (buf);
1278 GST_TIME_TO_TIMEVAL (timestamp, group->buffer.timestamp);
1281 GST_OBJECT_LOCK (pool);
1282 g_atomic_int_inc (&pool->num_queued);
1283 pool->buffers[index] = buf;
1285 if (!gst_v4l2_allocator_qbuf (pool->vallocator, group))
1288 pool->empty = FALSE;
1289 g_cond_signal (&pool->empty_cond);
1290 GST_OBJECT_UNLOCK (pool);
1296 GST_ERROR_OBJECT (pool, "the buffer %i was already queued", index);
1297 return GST_FLOW_ERROR;
1301 GST_ERROR_OBJECT (pool, "could not queue a buffer %i", index);
1302 /* Mark broken buffer to the allocator */
1303 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_TAG_MEMORY);
1304 g_atomic_int_add (&pool->num_queued, -1);
1305 pool->buffers[index] = NULL;
1306 GST_OBJECT_UNLOCK (pool);
1307 return GST_FLOW_ERROR;
1311 static GstFlowReturn
1312 gst_v4l2_buffer_pool_dqbuf (GstV4l2BufferPool * pool, GstBuffer ** buffer,
1316 GstBuffer *outbuf = NULL;
1317 GstV4l2Object *obj = pool->obj;
1318 GstClockTime timestamp;
1319 GstV4l2MemoryGroup *group;
1320 GstVideoMeta *vmeta;
1323 #ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
1324 GstV4l2TizenBuffer *tizen_buffer = NULL;
1325 #endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
1327 if ((res = gst_v4l2_buffer_pool_poll (pool, wait)) < GST_FLOW_OK)
1330 if (res == GST_FLOW_CUSTOM_SUCCESS) {
1331 GST_LOG_OBJECT (pool, "nothing to dequeue");
1335 GST_LOG_OBJECT (pool, "dequeueing a buffer");
1337 res = gst_v4l2_allocator_dqbuf (pool->vallocator, &group);
1338 if (res == GST_FLOW_EOS)
1340 if (res != GST_FLOW_OK)
1343 /* get our GstBuffer with that index from the pool, if the buffer was
1344 * outstanding we have a serious problem.
1346 outbuf = pool->buffers[group->buffer.index];
1350 /* mark the buffer outstanding */
1351 pool->buffers[group->buffer.index] = NULL;
1352 if (g_atomic_int_dec_and_test (&pool->num_queued)) {
1353 GST_OBJECT_LOCK (pool);
1355 GST_OBJECT_UNLOCK (pool);
1358 timestamp = GST_TIMEVAL_TO_TIME (group->buffer.timestamp);
1361 vmeta = gst_buffer_get_video_meta (outbuf);
1362 for (i = 0; i < group->n_mem; i++) {
1363 GST_LOG_OBJECT (pool,
1364 "dequeued buffer %p seq:%d (ix=%d), mem %p used %d, plane=%d, flags %08x, ts %"
1365 GST_TIME_FORMAT ", pool-queued=%d, buffer=%p", outbuf,
1366 group->buffer.sequence, group->buffer.index, group->mem[i],
1367 group->planes[i].bytesused, i, group->buffer.flags,
1368 GST_TIME_ARGS (timestamp), pool->num_queued, outbuf);
1371 vmeta->offset[i] = size;
1372 size += gst_memory_get_sizes (group->mem[i], NULL, NULL);
1376 /* Ignore timestamp and field for OUTPUT device */
1377 if (V4L2_TYPE_IS_OUTPUT (obj->type))
1380 /* Check for driver bug in reporting feild */
1381 if (group->buffer.field == V4L2_FIELD_ANY) {
1382 /* Only warn once to avoid the spamming */
1383 #ifndef GST_DISABLE_GST_DEBUG
1384 if (!pool->has_warned_on_buggy_field) {
1385 pool->has_warned_on_buggy_field = TRUE;
1386 GST_WARNING_OBJECT (pool,
1387 "Driver should never set v4l2_buffer.field to ANY");
1391 /* Use the value from the format (works for UVC bug) */
1392 group->buffer.field = obj->format.fmt.pix.field;
1394 /* If driver also has buggy S_FMT, assume progressive */
1395 if (group->buffer.field == V4L2_FIELD_ANY) {
1396 #ifndef GST_DISABLE_GST_DEBUG
1397 if (!pool->has_warned_on_buggy_field) {
1398 pool->has_warned_on_buggy_field = TRUE;
1399 GST_WARNING_OBJECT (pool,
1400 "Driver should never set v4l2_format.pix.field to ANY");
1404 group->buffer.field = V4L2_FIELD_NONE;
1408 /* set top/bottom field first if v4l2_buffer has the information */
1409 switch (group->buffer.field) {
1410 case V4L2_FIELD_NONE:
1411 GST_BUFFER_FLAG_UNSET (outbuf, GST_VIDEO_BUFFER_FLAG_INTERLACED);
1412 GST_BUFFER_FLAG_UNSET (outbuf, GST_VIDEO_BUFFER_FLAG_TFF);
1414 case V4L2_FIELD_INTERLACED_TB:
1415 GST_BUFFER_FLAG_SET (outbuf, GST_VIDEO_BUFFER_FLAG_INTERLACED);
1416 GST_BUFFER_FLAG_SET (outbuf, GST_VIDEO_BUFFER_FLAG_TFF);
1418 case V4L2_FIELD_INTERLACED_BT:
1419 GST_BUFFER_FLAG_SET (outbuf, GST_VIDEO_BUFFER_FLAG_INTERLACED);
1420 GST_BUFFER_FLAG_UNSET (outbuf, GST_VIDEO_BUFFER_FLAG_TFF);
1422 case V4L2_FIELD_INTERLACED:
1423 GST_BUFFER_FLAG_SET (outbuf, GST_VIDEO_BUFFER_FLAG_INTERLACED);
1424 if (obj->tv_norm == V4L2_STD_NTSC_M ||
1425 obj->tv_norm == V4L2_STD_NTSC_M_JP ||
1426 obj->tv_norm == V4L2_STD_NTSC_M_KR) {
1427 GST_BUFFER_FLAG_UNSET (outbuf, GST_VIDEO_BUFFER_FLAG_TFF);
1429 GST_BUFFER_FLAG_SET (outbuf, GST_VIDEO_BUFFER_FLAG_TFF);
1433 GST_BUFFER_FLAG_UNSET (outbuf, GST_VIDEO_BUFFER_FLAG_INTERLACED);
1434 GST_BUFFER_FLAG_UNSET (outbuf, GST_VIDEO_BUFFER_FLAG_TFF);
1435 GST_FIXME_OBJECT (pool,
1436 "Unhandled enum v4l2_field %d - treating as progressive",
1437 group->buffer.field);
1441 if (GST_VIDEO_INFO_FORMAT (&obj->info) == GST_VIDEO_FORMAT_ENCODED) {
1442 if ((group->buffer.flags & V4L2_BUF_FLAG_KEYFRAME) ||
1443 GST_V4L2_PIXELFORMAT (obj) == V4L2_PIX_FMT_MJPEG ||
1444 GST_V4L2_PIXELFORMAT (obj) == V4L2_PIX_FMT_JPEG ||
1445 GST_V4L2_PIXELFORMAT (obj) == V4L2_PIX_FMT_PJPG)
1446 GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_DELTA_UNIT);
1448 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DELTA_UNIT);
1451 if (group->buffer.flags & V4L2_BUF_FLAG_ERROR)
1452 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_CORRUPTED);
1454 GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
1455 GST_BUFFER_OFFSET (outbuf) = group->buffer.sequence;
1456 GST_BUFFER_OFFSET_END (outbuf) = group->buffer.sequence + 1;
1458 #ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
1459 if (group->surface) {
1460 tizen_buffer = gst_v4l2_tizen_buffer_new (outbuf, group->buffer.index, pool);
1461 if (!tizen_buffer) {
1462 GST_ERROR_OBJECT (pool, "tizen buffer failed for index[%d]", group->buffer.index);
1465 outbuf = tizen_buffer->gst_buffer;
1467 #endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
1476 GST_DEBUG_OBJECT (pool, "poll error %s", gst_flow_get_name (res));
1481 return GST_FLOW_EOS;
1485 return GST_FLOW_ERROR;
1489 GST_ERROR_OBJECT (pool, "No free buffer found in the pool at index %d.",
1490 group->buffer.index);
1491 return GST_FLOW_ERROR;
1495 static GstFlowReturn
1496 gst_v4l2_buffer_pool_acquire_buffer (GstBufferPool * bpool, GstBuffer ** buffer,
1497 GstBufferPoolAcquireParams * params)
1500 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool);
1501 GstBufferPoolClass *pclass = GST_BUFFER_POOL_CLASS (parent_class);
1502 GstV4l2Object *obj = pool->obj;
1504 GST_DEBUG_OBJECT (pool, "acquire");
1506 /* If this is being called to resurrect a lost buffer */
1507 if (params && params->flags & GST_V4L2_BUFFER_POOL_ACQUIRE_FLAG_RESURRECT) {
1508 ret = pclass->acquire_buffer (bpool, buffer, params);
1512 switch (obj->type) {
1513 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1514 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
1515 /* capture, This function should return a buffer with new captured data */
1516 switch (obj->mode) {
1517 case GST_V4L2_IO_RW:
1519 /* take empty buffer from the pool */
1520 ret = pclass->acquire_buffer (bpool, buffer, params);
1523 case GST_V4L2_IO_DMABUF:
1524 case GST_V4L2_IO_MMAP:
1525 case GST_V4L2_IO_USERPTR:
1526 case GST_V4L2_IO_DMABUF_IMPORT:
1528 /* just dequeue a buffer, we basically use the queue of v4l2 as the
1529 * storage for our buffers. This function does poll first so we can
1530 * interrupt it fine. */
1531 ret = gst_v4l2_buffer_pool_dqbuf (pool, buffer, TRUE);
1535 ret = GST_FLOW_ERROR;
1536 g_assert_not_reached ();
1542 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1543 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
1544 /* playback, This function should return an empty buffer */
1545 switch (obj->mode) {
1546 case GST_V4L2_IO_RW:
1547 /* get an empty buffer */
1548 ret = pclass->acquire_buffer (bpool, buffer, params);
1551 case GST_V4L2_IO_MMAP:
1552 case GST_V4L2_IO_DMABUF:
1553 case GST_V4L2_IO_USERPTR:
1554 case GST_V4L2_IO_DMABUF_IMPORT:
1555 /* get a free unqueued buffer */
1556 ret = pclass->acquire_buffer (bpool, buffer, params);
1560 ret = GST_FLOW_ERROR;
1561 g_assert_not_reached ();
1567 ret = GST_FLOW_ERROR;
1568 g_assert_not_reached ();
1576 gst_v4l2_buffer_pool_release_buffer (GstBufferPool * bpool, GstBuffer * buffer)
1578 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool);
1579 GstBufferPoolClass *pclass = GST_BUFFER_POOL_CLASS (parent_class);
1580 GstV4l2Object *obj = pool->obj;
1582 GST_DEBUG_OBJECT (pool, "release buffer %p", buffer);
1584 /* If the buffer's pool has been orphaned, dispose of it so that
1585 * the pool resources can be freed */
1586 if (pool->orphaned) {
1587 GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY);
1588 pclass->release_buffer (bpool, buffer);
1592 switch (obj->type) {
1593 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1594 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
1595 /* capture, put the buffer back in the queue so that we can refill it
1597 switch (obj->mode) {
1598 case GST_V4L2_IO_RW:
1599 /* release back in the pool */
1600 pclass->release_buffer (bpool, buffer);
1603 case GST_V4L2_IO_DMABUF:
1604 case GST_V4L2_IO_MMAP:
1605 case GST_V4L2_IO_USERPTR:
1606 case GST_V4L2_IO_DMABUF_IMPORT:
1608 GstV4l2MemoryGroup *group;
1609 if (gst_v4l2_is_buffer_valid (buffer, &group)) {
1610 GstFlowReturn ret = GST_FLOW_OK;
1612 gst_v4l2_allocator_reset_group (pool->vallocator, group);
1613 /* queue back in the device */
1614 if (pool->other_pool)
1615 ret = gst_v4l2_buffer_pool_prepare_buffer (pool, buffer, NULL);
1616 if (ret != GST_FLOW_OK ||
1617 gst_v4l2_buffer_pool_qbuf (pool, buffer, group) != GST_FLOW_OK)
1618 pclass->release_buffer (bpool, buffer);
1620 /* Simply release invalide/modified buffer, the allocator will
1621 * give it back later */
1622 GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY);
1623 pclass->release_buffer (bpool, buffer);
1628 g_assert_not_reached ();
1633 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1634 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
1635 switch (obj->mode) {
1636 case GST_V4L2_IO_RW:
1637 /* release back in the pool */
1638 pclass->release_buffer (bpool, buffer);
1641 case GST_V4L2_IO_MMAP:
1642 case GST_V4L2_IO_DMABUF:
1643 case GST_V4L2_IO_USERPTR:
1644 case GST_V4L2_IO_DMABUF_IMPORT:
1646 GstV4l2MemoryGroup *group;
1649 if (!gst_v4l2_is_buffer_valid (buffer, &group)) {
1650 /* Simply release invalide/modified buffer, the allocator will
1651 * give it back later */
1652 GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY);
1653 pclass->release_buffer (bpool, buffer);
1657 index = group->buffer.index;
1659 if (pool->buffers[index] == NULL) {
1660 GST_LOG_OBJECT (pool, "buffer %u not queued, putting on free list",
1663 /* Remove qdata, this will unmap any map data in userptr */
1664 gst_mini_object_set_qdata (GST_MINI_OBJECT (buffer),
1665 GST_V4L2_IMPORT_QUARK, NULL, NULL);
1667 /* reset to default size */
1668 gst_v4l2_allocator_reset_group (pool->vallocator, group);
1670 /* playback, put the buffer back in the queue to refill later. */
1671 pclass->release_buffer (bpool, buffer);
1673 /* the buffer is queued in the device but maybe not played yet. We just
1674 * leave it there and not make it available for future calls to acquire
1675 * for now. The buffer will be dequeued and reused later. */
1676 GST_LOG_OBJECT (pool, "buffer %u is queued", index);
1682 g_assert_not_reached ();
1688 g_assert_not_reached ();
1694 gst_v4l2_buffer_pool_dispose (GObject * object)
1696 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (object);
1698 if (pool->vallocator)
1699 gst_object_unref (pool->vallocator);
1700 pool->vallocator = NULL;
1702 if (pool->allocator)
1703 gst_object_unref (pool->allocator);
1704 pool->allocator = NULL;
1706 #ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
1707 g_cond_clear (&pool->buffer_cond);
1708 g_mutex_clear (&pool->buffer_lock);
1710 if (pool->tallocator)
1711 gst_object_unref (pool->tallocator);
1712 pool->tallocator = NULL;
1713 #endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
1714 if (pool->other_pool)
1715 gst_object_unref (pool->other_pool);
1716 pool->other_pool = NULL;
1718 G_OBJECT_CLASS (parent_class)->dispose (object);
1722 gst_v4l2_buffer_pool_finalize (GObject * object)
1724 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (object);
1726 if (pool->video_fd >= 0)
1727 pool->obj->close (pool->video_fd);
1729 gst_poll_free (pool->poll);
1731 /* This can't be done in dispose method because we must not set pointer
1732 * to NULL as it is part of the v4l2object and dispose could be called
1734 gst_object_unref (pool->obj->element);
1736 g_cond_clear (&pool->empty_cond);
1738 /* FIXME have we done enough here ? */
1740 G_OBJECT_CLASS (parent_class)->finalize (object);
1744 gst_v4l2_buffer_pool_init (GstV4l2BufferPool * pool)
1746 pool->poll = gst_poll_new (TRUE);
1747 pool->can_poll_device = TRUE;
1748 g_cond_init (&pool->empty_cond);
1750 pool->orphaned = FALSE;
1754 gst_v4l2_buffer_pool_class_init (GstV4l2BufferPoolClass * klass)
1756 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1757 GstBufferPoolClass *bufferpool_class = GST_BUFFER_POOL_CLASS (klass);
1759 object_class->dispose = gst_v4l2_buffer_pool_dispose;
1760 object_class->finalize = gst_v4l2_buffer_pool_finalize;
1762 bufferpool_class->start = gst_v4l2_buffer_pool_start;
1763 bufferpool_class->stop = gst_v4l2_buffer_pool_stop;
1764 bufferpool_class->set_config = gst_v4l2_buffer_pool_set_config;
1765 bufferpool_class->alloc_buffer = gst_v4l2_buffer_pool_alloc_buffer;
1766 bufferpool_class->acquire_buffer = gst_v4l2_buffer_pool_acquire_buffer;
1767 bufferpool_class->release_buffer = gst_v4l2_buffer_pool_release_buffer;
1768 bufferpool_class->flush_start = gst_v4l2_buffer_pool_flush_start;
1769 bufferpool_class->flush_stop = gst_v4l2_buffer_pool_flush_stop;
1771 GST_DEBUG_CATEGORY_INIT (v4l2bufferpool_debug, "v4l2bufferpool", 0,
1772 "V4L2 Buffer Pool");
1773 GST_DEBUG_CATEGORY_GET (CAT_PERFORMANCE, "GST_PERFORMANCE");
1777 * gst_v4l2_buffer_pool_new:
1778 * @obj: the v4l2 object owning the pool
1780 * Construct a new buffer pool.
1782 * Returns: the new pool, use gst_object_unref() to free resources
1785 gst_v4l2_buffer_pool_new (GstV4l2Object * obj, GstCaps * caps)
1787 GstV4l2BufferPool *pool;
1788 GstStructure *config;
1789 gchar *name, *parent_name;
1792 fd = obj->dup (obj->video_fd);
1796 /* setting a significant unique name */
1797 parent_name = gst_object_get_name (GST_OBJECT (obj->element));
1798 name = g_strconcat (parent_name, ":", "pool:",
1799 V4L2_TYPE_IS_OUTPUT (obj->type) ? "sink" : "src", NULL);
1800 g_free (parent_name);
1802 pool = (GstV4l2BufferPool *) g_object_new (GST_TYPE_V4L2_BUFFER_POOL,
1803 "name", name, NULL);
1804 g_object_ref_sink (pool);
1807 gst_poll_fd_init (&pool->pollfd);
1808 pool->pollfd.fd = fd;
1809 gst_poll_add_fd (pool->poll, &pool->pollfd);
1810 if (V4L2_TYPE_IS_OUTPUT (obj->type))
1811 gst_poll_fd_ctl_write (pool->poll, &pool->pollfd, TRUE);
1813 gst_poll_fd_ctl_read (pool->poll, &pool->pollfd, TRUE);
1815 pool->video_fd = fd;
1817 pool->can_poll_device = TRUE;
1819 #ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
1820 pool->tallocator = gst_tizen_allocator_new ();
1821 if (pool->tallocator == NULL)
1822 goto allocator_failed;
1824 g_mutex_init (&pool->buffer_lock);
1825 g_cond_init (&pool->buffer_cond);
1826 #endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
1827 pool->vallocator = gst_v4l2_allocator_new (GST_OBJECT (pool), obj);
1828 if (pool->vallocator == NULL)
1829 goto allocator_failed;
1831 gst_object_ref (obj->element);
1833 config = gst_buffer_pool_get_config (GST_BUFFER_POOL_CAST (pool));
1834 gst_buffer_pool_config_set_params (config, caps, obj->info.size, 0, 0);
1835 /* This will simply set a default config, but will not configure the pool
1836 * because min and max are not valid */
1837 gst_buffer_pool_set_config (GST_BUFFER_POOL_CAST (pool), config);
1839 return GST_BUFFER_POOL (pool);
1844 GST_ERROR ("failed to dup fd %d (%s)", errno, g_strerror (errno));
1849 #ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
1850 if (pool->tallocator) {
1851 gst_object_unref (pool->tallocator);
1852 pool->tallocator = NULL;
1854 #endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
1855 GST_ERROR_OBJECT (pool, "Failed to create V4L2 allocator");
1856 gst_object_unref (pool);
1861 static GstFlowReturn
1862 gst_v4l2_do_read (GstV4l2BufferPool * pool, GstBuffer * buf)
1865 GstV4l2Object *obj = pool->obj;
1870 toread = obj->info.size;
1872 GST_LOG_OBJECT (pool, "reading %d bytes into buffer %p", toread, buf);
1874 gst_buffer_map (buf, &map, GST_MAP_WRITE);
1877 if ((res = gst_v4l2_buffer_pool_poll (pool, TRUE)) != GST_FLOW_OK)
1880 amount = obj->read (obj->video_fd, map.data, toread);
1882 if (amount == toread) {
1884 } else if (amount == -1) {
1885 if (errno == EAGAIN || errno == EINTR) {
1890 /* short reads can happen if a signal interrupts the read */
1895 GST_LOG_OBJECT (pool, "read %d bytes", amount);
1896 gst_buffer_unmap (buf, &map);
1897 gst_buffer_resize (buf, 0, amount);
1904 GST_DEBUG ("poll error %s", gst_flow_get_name (res));
1909 GST_ELEMENT_ERROR (obj->element, RESOURCE, READ,
1910 (_("Error reading %d bytes from device '%s'."),
1911 toread, obj->videodev), GST_ERROR_SYSTEM);
1912 res = GST_FLOW_ERROR;
1917 gst_buffer_unmap (buf, &map);
1918 gst_buffer_resize (buf, 0, 0);
1924 * gst_v4l2_buffer_pool_process:
1925 * @bpool: a #GstBufferPool
1926 * @buf: a #GstBuffer, maybe be replaced
1928 * Process @buf in @bpool. For capture devices, this functions fills @buf with
1929 * data from the device. For output devices, this functions send the contents of
1930 * @buf to the device for playback.
1932 * Returns: %GST_FLOW_OK on success.
1935 gst_v4l2_buffer_pool_process (GstV4l2BufferPool * pool, GstBuffer ** buf)
1937 GstFlowReturn ret = GST_FLOW_OK;
1938 GstBufferPool *bpool = GST_BUFFER_POOL_CAST (pool);
1939 GstV4l2Object *obj = pool->obj;
1941 GST_DEBUG_OBJECT (pool, "process buffer %p", buf);
1943 if (GST_BUFFER_POOL_IS_FLUSHING (pool))
1944 return GST_FLOW_FLUSHING;
1946 switch (obj->type) {
1947 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1948 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
1950 switch (obj->mode) {
1951 case GST_V4L2_IO_RW:
1952 /* capture into the buffer */
1953 ret = gst_v4l2_do_read (pool, *buf);
1956 case GST_V4L2_IO_MMAP:
1957 case GST_V4L2_IO_DMABUF:
1961 if ((*buf)->pool == bpool) {
1963 gsize size = gst_buffer_get_size (*buf);
1965 /* Legacy M2M devices return empty buffer when drained */
1966 if (size == 0 && GST_V4L2_IS_M2M (obj->device_caps))
1969 if (GST_VIDEO_INFO_FORMAT (&pool->caps_info) !=
1970 GST_VIDEO_FORMAT_ENCODED && size < pool->size)
1971 goto buffer_truncated;
1973 num_queued = g_atomic_int_get (&pool->num_queued);
1974 GST_TRACE_OBJECT (pool, "Only %i buffer left in the capture queue.",
1977 /* If we have no more buffer, and can allocate it time to do so */
1978 if (num_queued == 0) {
1979 if (GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, MMAP)) {
1980 ret = gst_v4l2_buffer_pool_resurrect_buffer (pool);
1981 if (ret == GST_FLOW_OK)
1986 /* start copying buffers when we are running low on buffers */
1987 if (num_queued < pool->copy_threshold) {
1990 if (GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, MMAP)) {
1991 ret = gst_v4l2_buffer_pool_resurrect_buffer (pool);
1992 if (ret == GST_FLOW_OK)
1996 /* copy the buffer */
1997 copy = gst_buffer_copy_region (*buf,
1998 GST_BUFFER_COPY_ALL | GST_BUFFER_COPY_DEEP, 0, -1);
1999 GST_LOG_OBJECT (pool, "copy buffer %p->%p", *buf, copy);
2001 /* and requeue so that we can continue capturing */
2002 gst_buffer_unref (*buf);
2007 /* nothing, data was inside the buffer when we did _acquire() */
2011 /* buffer not from our pool, grab a frame and copy it into the target */
2012 if ((ret = gst_v4l2_buffer_pool_dqbuf (pool, &tmp, TRUE))
2016 /* An empty buffer on capture indicates the end of stream */
2017 if (gst_buffer_get_size (tmp) == 0) {
2018 gst_v4l2_buffer_pool_release_buffer (bpool, tmp);
2020 /* Legacy M2M devices return empty buffer when drained */
2021 if (GST_V4L2_IS_M2M (obj->device_caps))
2024 #ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
2025 if (pool->obj->tbm_output && pool->obj->mode == GST_V4L2_IO_DMABUF) {
2026 gst_buffer_unref (*buf);
2029 #endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
2030 ret = gst_v4l2_buffer_pool_copy_buffer (pool, *buf, tmp);
2032 /* an queue the buffer again after the copy */
2033 gst_v4l2_buffer_pool_release_buffer (bpool, tmp);
2034 #ifdef TIZEN_FEATURE_V4L2_TBM_SUPPORT
2036 #endif /* TIZEN_FEATURE_V4L2_TBM_SUPPORT */
2038 if (ret != GST_FLOW_OK)
2043 case GST_V4L2_IO_USERPTR:
2045 struct UserPtrData *data;
2048 /* Replace our buffer with downstream allocated buffer */
2049 data = gst_mini_object_steal_qdata (GST_MINI_OBJECT (*buf),
2050 GST_V4L2_IMPORT_QUARK);
2051 tmp = gst_buffer_ref (data->buffer);
2052 _unmap_userptr_frame (data);
2054 /* Now tmp is writable, copy the flags and timestamp */
2055 gst_buffer_copy_into (tmp, *buf,
2056 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
2058 gst_buffer_replace (buf, tmp);
2059 gst_buffer_unref (tmp);
2063 case GST_V4L2_IO_DMABUF_IMPORT:
2067 /* Replace our buffer with downstream allocated buffer */
2068 tmp = gst_mini_object_steal_qdata (GST_MINI_OBJECT (*buf),
2069 GST_V4L2_IMPORT_QUARK);
2071 gst_buffer_copy_into (tmp, *buf,
2072 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
2074 gst_buffer_replace (buf, tmp);
2075 gst_buffer_unref (tmp);
2080 g_assert_not_reached ();
2085 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
2086 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
2088 switch (obj->mode) {
2089 case GST_V4L2_IO_RW:
2090 /* FIXME, do write() */
2091 GST_WARNING_OBJECT (pool, "implement write()");
2094 case GST_V4L2_IO_USERPTR:
2095 case GST_V4L2_IO_DMABUF_IMPORT:
2096 case GST_V4L2_IO_DMABUF:
2097 case GST_V4L2_IO_MMAP:
2099 GstBuffer *to_queue = NULL;
2101 GstV4l2MemoryGroup *group;
2104 if ((*buf)->pool != bpool)
2107 if (!gst_v4l2_is_buffer_valid (*buf, &group))
2110 index = group->buffer.index;
2112 GST_LOG_OBJECT (pool, "processing buffer %i from our pool", index);
2114 if (pool->buffers[index] != NULL) {
2115 GST_LOG_OBJECT (pool, "buffer %i already queued, copying", index);
2119 /* we can queue directly */
2120 to_queue = gst_buffer_ref (*buf);
2123 if (to_queue == NULL) {
2124 GstBufferPoolAcquireParams params = { 0 };
2126 GST_LOG_OBJECT (pool, "alloc buffer from our pool");
2128 /* this can return EOS if all buffers are outstanding which would
2129 * be strange because we would expect the upstream element to have
2130 * allocated them and returned to us.. */
2131 params.flags = GST_BUFFER_POOL_ACQUIRE_FLAG_DONTWAIT;
2132 ret = gst_buffer_pool_acquire_buffer (bpool, &to_queue, ¶ms);
2133 if (ret != GST_FLOW_OK)
2134 goto acquire_failed;
2136 ret = gst_v4l2_buffer_pool_prepare_buffer (pool, to_queue, *buf);
2137 if (ret != GST_FLOW_OK) {
2138 gst_buffer_unref (to_queue);
2139 goto prepare_failed;
2142 /* retreive the group */
2143 gst_v4l2_is_buffer_valid (to_queue, &group);
2146 if ((ret = gst_v4l2_buffer_pool_qbuf (pool, to_queue, group))
2150 /* if we are not streaming yet (this is the first buffer, start
2152 if (!gst_v4l2_buffer_pool_streamon (pool)) {
2153 /* don't check return value because qbuf would have failed */
2154 gst_v4l2_is_buffer_valid (to_queue, &group);
2156 /* qbuf has stored to_queue buffer but we are not in
2157 * streaming state, so the flush logic won't be performed.
2158 * To avoid leaks, flush the allocator and restore the queued
2159 * buffer as non-queued */
2160 gst_v4l2_allocator_flush (pool->vallocator);
2162 pool->buffers[group->buffer.index] = NULL;
2164 gst_mini_object_set_qdata (GST_MINI_OBJECT (to_queue),
2165 GST_V4L2_IMPORT_QUARK, NULL, NULL);
2166 gst_buffer_unref (to_queue);
2167 g_atomic_int_add (&pool->num_queued, -1);
2171 /* Remove our ref, we will still hold this buffer in acquire as needed,
2172 * otherwise the pool will think it is outstanding and will refuse to stop. */
2173 gst_buffer_unref (to_queue);
2175 /* release as many buffer as possible */
2176 while (gst_v4l2_buffer_pool_dqbuf (pool, &buffer, FALSE) ==
2178 if (buffer->pool == NULL)
2179 gst_v4l2_buffer_pool_release_buffer (bpool, buffer);
2182 if (g_atomic_int_get (&pool->num_queued) >= pool->min_latency) {
2183 /* all buffers are queued, try to dequeue one and release it back
2184 * into the pool so that _acquire can get to it again. */
2185 ret = gst_v4l2_buffer_pool_dqbuf (pool, &buffer, TRUE);
2186 if (ret == GST_FLOW_OK && buffer->pool == NULL)
2187 /* release the rendered buffer back into the pool. This wakes up any
2188 * thread waiting for a buffer in _acquire(). */
2189 gst_v4l2_buffer_pool_release_buffer (bpool, buffer);
2194 g_assert_not_reached ();
2199 g_assert_not_reached ();
2208 GST_ERROR_OBJECT (pool, "failed to copy buffer");
2213 GST_WARNING_OBJECT (pool,
2214 "Dropping truncated buffer, this is likely a driver bug.");
2215 gst_buffer_unref (*buf);
2217 return GST_V4L2_FLOW_CORRUPTED_BUFFER;
2221 GST_DEBUG_OBJECT (pool, "end of stream reached");
2222 gst_buffer_unref (*buf);
2224 return GST_V4L2_FLOW_LAST_BUFFER;
2228 if (ret == GST_FLOW_FLUSHING)
2229 GST_DEBUG_OBJECT (pool, "flushing");
2231 GST_WARNING_OBJECT (pool, "failed to acquire a buffer: %s",
2232 gst_flow_get_name (ret));
2237 GST_ERROR_OBJECT (pool, "failed to prepare data");
2242 GST_ERROR_OBJECT (pool, "failed to queue buffer");
2247 GST_ERROR_OBJECT (pool, "failed to start streaming");
2248 return GST_FLOW_ERROR;
2253 gst_v4l2_buffer_pool_set_other_pool (GstV4l2BufferPool * pool,
2254 GstBufferPool * other_pool)
2256 g_return_if_fail (!gst_buffer_pool_is_active (GST_BUFFER_POOL (pool)));
2258 if (pool->other_pool)
2259 gst_object_unref (pool->other_pool);
2260 pool->other_pool = gst_object_ref (other_pool);
2264 gst_v4l2_buffer_pool_copy_at_threshold (GstV4l2BufferPool * pool, gboolean copy)
2266 GST_OBJECT_LOCK (pool);
2267 pool->enable_copy_threshold = copy;
2268 GST_OBJECT_UNLOCK (pool);
2272 gst_v4l2_buffer_pool_flush (GstBufferPool * bpool)
2274 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool);
2275 gboolean ret = TRUE;
2277 gst_v4l2_buffer_pool_streamoff (pool);
2279 if (!V4L2_TYPE_IS_OUTPUT (pool->obj->type))
2280 ret = gst_v4l2_buffer_pool_streamon (pool);