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_TBM_SUPPORT_FOR_V4L2_DECODER
49 #include <gst/allocators/gsttizenmemory.h>
50 #endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
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_TBM_SUPPORT_FOR_V4L2_DECODER
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);
108 static GstV4l2TizenBuffer *gst_v4l2_tizen_buffer_new (GstBuffer *v4l2_buffer, int index, GstV4l2BufferPool *v4l2_pool)
110 GstV4l2TizenBuffer *tizen_buffer = NULL;
111 GstMemory *memory = NULL;
113 tizen_buffer = g_new0 (GstV4l2TizenBuffer, 1);
114 tizen_buffer->index = index;
115 tizen_buffer->v4l2_buffer = v4l2_buffer;
116 tizen_buffer->gst_buffer = gst_buffer_new ();
117 tizen_buffer->v4l2_pool = v4l2_pool;
119 memory = gst_tizen_allocator_alloc_surface (v4l2_pool->tallocator,
120 &v4l2_pool->obj->info, v4l2_pool->vallocator->groups[index]->surface, (gpointer)tizen_buffer,
121 (GDestroyNotify)gst_v4l2_tizen_buffer_finalize);
123 gst_buffer_append_memory (tizen_buffer->gst_buffer, memory);
124 gst_buffer_set_size (tizen_buffer->gst_buffer, v4l2_pool->vallocator->s_info.size);
126 g_mutex_lock (&v4l2_pool->buffer_lock);
128 v4l2_pool->live_buffer_count++;
130 GST_DEBUG_OBJECT (v4l2_pool, "new buffer[tizen:%p,v4l2:%p,gst:%p], size[%d], live[%d]",
131 tizen_buffer, v4l2_buffer, tizen_buffer->gst_buffer,
132 v4l2_pool->vallocator->s_info.size, v4l2_pool->live_buffer_count);
134 g_mutex_unlock (&v4l2_pool->buffer_lock);
138 #endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
141 gst_v4l2_is_buffer_valid (GstBuffer * buffer, GstV4l2MemoryGroup ** out_group)
143 GstMemory *mem = gst_buffer_peek_memory (buffer, 0);
144 gboolean valid = FALSE;
146 if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY))
149 if (gst_is_dmabuf_memory (mem))
150 mem = gst_mini_object_get_qdata (GST_MINI_OBJECT (mem),
151 GST_V4L2_MEMORY_QUARK);
153 if (mem && gst_is_v4l2_memory (mem)) {
154 GstV4l2Memory *vmem = (GstV4l2Memory *) mem;
155 GstV4l2MemoryGroup *group = vmem->group;
158 if (group->n_mem != gst_buffer_n_memory (buffer))
161 for (i = 0; i < group->n_mem; i++) {
162 if (group->mem[i] != gst_buffer_peek_memory (buffer, i))
165 if (!gst_memory_is_writable (group->mem[i]))
179 gst_v4l2_buffer_pool_copy_buffer (GstV4l2BufferPool * pool, GstBuffer * dest,
182 const GstVideoFormatInfo *finfo = pool->caps_info.finfo;
184 GST_LOG_OBJECT (pool, "copying buffer");
186 if (finfo && (finfo->format != GST_VIDEO_FORMAT_UNKNOWN &&
187 finfo->format != GST_VIDEO_FORMAT_ENCODED)) {
188 GstVideoFrame src_frame, dest_frame;
190 GST_DEBUG_OBJECT (pool, "copy video frame");
192 /* we have raw video, use videoframe copy to get strides right */
193 if (!gst_video_frame_map (&src_frame, &pool->caps_info, src, GST_MAP_READ))
196 if (!gst_video_frame_map (&dest_frame, &pool->caps_info, dest,
198 gst_video_frame_unmap (&src_frame);
202 gst_video_frame_copy (&dest_frame, &src_frame);
204 gst_video_frame_unmap (&src_frame);
205 gst_video_frame_unmap (&dest_frame);
209 GST_DEBUG_OBJECT (pool, "copy raw bytes");
211 if (!gst_buffer_map (src, &map, GST_MAP_READ))
214 gst_buffer_fill (dest, 0, map.data, gst_buffer_get_size (src));
216 gst_buffer_unmap (src, &map);
217 gst_buffer_resize (dest, 0, gst_buffer_get_size (src));
220 gst_buffer_copy_into (dest, src,
221 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
223 GST_CAT_LOG_OBJECT (CAT_PERFORMANCE, pool, "slow copy into buffer %p", dest);
229 GST_ERROR_OBJECT (pool, "could not map buffer");
230 return GST_FLOW_ERROR;
243 gst_v4l2_buffer_pool_import_quark (void)
245 static GQuark quark = 0;
248 quark = g_quark_from_string ("GstV4l2BufferPoolUsePtrData");
254 _unmap_userptr_frame (struct UserPtrData *data)
257 gst_video_frame_unmap (&data->frame);
259 gst_buffer_unmap (data->buffer, &data->map);
262 gst_buffer_unref (data->buffer);
264 g_slice_free (struct UserPtrData, data);
268 gst_v4l2_buffer_pool_import_userptr (GstV4l2BufferPool * pool,
269 GstBuffer * dest, GstBuffer * src)
271 GstFlowReturn ret = GST_FLOW_OK;
272 GstV4l2MemoryGroup *group = NULL;
274 const GstVideoFormatInfo *finfo = pool->caps_info.finfo;
275 struct UserPtrData *data = NULL;
277 GST_LOG_OBJECT (pool, "importing userptr");
280 if (!gst_v4l2_is_buffer_valid (dest, &group))
283 if (V4L2_TYPE_IS_OUTPUT (pool->obj->type))
284 flags = GST_MAP_READ;
286 flags = GST_MAP_WRITE;
288 data = g_slice_new0 (struct UserPtrData);
290 if (finfo && (finfo->format != GST_VIDEO_FORMAT_UNKNOWN &&
291 finfo->format != GST_VIDEO_FORMAT_ENCODED)) {
292 gsize size[GST_VIDEO_MAX_PLANES] = { 0, };
295 data->is_frame = TRUE;
297 if (!gst_video_frame_map (&data->frame, &pool->caps_info, src, flags))
300 for (i = 0; i < GST_VIDEO_FORMAT_INFO_N_PLANES (finfo); i++) {
301 if (GST_VIDEO_FORMAT_INFO_IS_TILED (finfo)) {
302 gint tinfo = GST_VIDEO_FRAME_PLANE_STRIDE (&data->frame, i);
306 pstride = GST_VIDEO_TILE_X_TILES (tinfo) <<
307 GST_VIDEO_FORMAT_INFO_TILE_WS (finfo);
309 pheight = GST_VIDEO_TILE_Y_TILES (tinfo) <<
310 GST_VIDEO_FORMAT_INFO_TILE_HS (finfo);
312 size[i] = pstride * pheight;
314 size[i] = GST_VIDEO_FRAME_PLANE_STRIDE (&data->frame, i) *
315 GST_VIDEO_FRAME_COMP_HEIGHT (&data->frame, i);
319 /* In the single planar API, planes must be contiguous in memory and
320 * therefore they must have expected size. ie: no padding.
321 * To check these conditions, we check that plane 'i' start address
322 * + plane 'i' size equals to plane 'i+1' start address */
323 if (!V4L2_TYPE_IS_MULTIPLANAR (pool->obj->type)) {
324 for (i = 0; i < (GST_VIDEO_FORMAT_INFO_N_PLANES (finfo) - 1); i++) {
325 const struct v4l2_pix_format *pix_fmt = &pool->obj->format.fmt.pix;
327 gint estride = gst_v4l2_object_extrapolate_stride (finfo, i,
328 pix_fmt->bytesperline);
329 guint eheight = GST_VIDEO_FORMAT_INFO_SCALE_HEIGHT (finfo, i,
332 tmp = ((guint8 *) data->frame.data[i]) + estride * eheight;
333 if (tmp != data->frame.data[i + 1])
334 goto non_contiguous_mem;
338 if (!gst_v4l2_allocator_import_userptr (pool->vallocator, group,
339 data->frame.info.size, finfo->n_planes, data->frame.data, size))
345 data->is_frame = FALSE;
347 if (!gst_buffer_map (src, &data->map, flags))
350 ptr[0] = data->map.data;
351 size[0] = data->map.size;
353 if (!gst_v4l2_allocator_import_userptr (pool->vallocator, group,
354 data->map.size, 1, ptr, size))
358 data->buffer = gst_buffer_ref (src);
360 gst_mini_object_set_qdata (GST_MINI_OBJECT (dest), GST_V4L2_IMPORT_QUARK,
361 data, (GDestroyNotify) _unmap_userptr_frame);
363 gst_buffer_copy_into (dest, src,
364 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
370 GST_ERROR_OBJECT (pool, "destination buffer invalid or not from our pool");
371 return GST_FLOW_ERROR;
375 GST_ERROR_OBJECT (pool, "could not map buffer");
376 g_slice_free (struct UserPtrData, data);
377 return GST_FLOW_ERROR;
381 GST_ERROR_OBJECT (pool, "memory is not contiguous or plane size mismatch");
382 _unmap_userptr_frame (data);
383 return GST_FLOW_ERROR;
387 GST_ERROR_OBJECT (pool, "failed to import data");
388 _unmap_userptr_frame (data);
389 return GST_FLOW_ERROR;
394 gst_v4l2_buffer_pool_import_dmabuf (GstV4l2BufferPool * pool,
395 GstBuffer * dest, GstBuffer * src)
397 GstV4l2MemoryGroup *group = NULL;
398 GstMemory *dma_mem[GST_VIDEO_MAX_PLANES] = { 0 };
399 guint n_mem = gst_buffer_n_memory (src);
402 GST_LOG_OBJECT (pool, "importing dmabuf");
404 if (!gst_v4l2_is_buffer_valid (dest, &group))
407 if (n_mem > GST_VIDEO_MAX_PLANES)
410 for (i = 0; i < n_mem; i++)
411 dma_mem[i] = gst_buffer_peek_memory (src, i);
413 if (!gst_v4l2_allocator_import_dmabuf (pool->vallocator, group, n_mem,
417 gst_mini_object_set_qdata (GST_MINI_OBJECT (dest), GST_V4L2_IMPORT_QUARK,
418 gst_buffer_ref (src), (GDestroyNotify) gst_buffer_unref);
420 gst_buffer_copy_into (dest, src,
421 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
427 GST_ERROR_OBJECT (pool, "destination buffer invalid or not from our pool");
428 return GST_FLOW_ERROR;
432 GST_ERROR_OBJECT (pool, "could not map buffer");
433 return GST_FLOW_ERROR;
437 GST_ERROR_OBJECT (pool, "failed to import dmabuf");
438 return GST_FLOW_ERROR;
443 gst_v4l2_buffer_pool_prepare_buffer (GstV4l2BufferPool * pool,
444 GstBuffer * dest, GstBuffer * src)
446 GstFlowReturn ret = GST_FLOW_OK;
447 gboolean own_src = FALSE;
450 if (pool->other_pool == NULL) {
451 GST_ERROR_OBJECT (pool, "can't prepare buffer, source buffer missing");
452 return GST_FLOW_ERROR;
455 ret = gst_buffer_pool_acquire_buffer (pool->other_pool, &src, NULL);
456 if (ret != GST_FLOW_OK) {
457 GST_ERROR_OBJECT (pool, "failed to acquire buffer from downstream pool");
464 switch (pool->obj->mode) {
465 case GST_V4L2_IO_MMAP:
466 case GST_V4L2_IO_DMABUF:
467 ret = gst_v4l2_buffer_pool_copy_buffer (pool, dest, src);
469 case GST_V4L2_IO_USERPTR:
470 ret = gst_v4l2_buffer_pool_import_userptr (pool, dest, src);
472 case GST_V4L2_IO_DMABUF_IMPORT:
473 ret = gst_v4l2_buffer_pool_import_dmabuf (pool, dest, src);
480 gst_buffer_unref (src);
487 gst_v4l2_buffer_pool_alloc_buffer (GstBufferPool * bpool, GstBuffer ** buffer,
488 GstBufferPoolAcquireParams * params)
490 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool);
491 GstV4l2MemoryGroup *group = NULL;
492 GstBuffer *newbuf = NULL;
502 gst_buffer_new_allocate (pool->allocator, pool->size, &pool->params);
504 case GST_V4L2_IO_MMAP:
505 group = gst_v4l2_allocator_alloc_mmap (pool->vallocator);
507 case GST_V4L2_IO_DMABUF:
508 group = gst_v4l2_allocator_alloc_dmabuf (pool->vallocator,
511 case GST_V4L2_IO_USERPTR:
512 group = gst_v4l2_allocator_alloc_userptr (pool->vallocator);
514 case GST_V4L2_IO_DMABUF_IMPORT:
515 group = gst_v4l2_allocator_alloc_dmabufin (pool->vallocator);
519 g_assert_not_reached ();
525 newbuf = gst_buffer_new ();
527 for (i = 0; i < group->n_mem; i++)
528 gst_buffer_append_memory (newbuf, group->mem[i]);
529 } else if (newbuf == NULL) {
530 goto allocation_failed;
533 /* add metadata to raw video buffers */
534 if (pool->add_videometa)
535 gst_buffer_add_video_meta_full (newbuf, GST_VIDEO_FRAME_FLAG_NONE,
536 GST_VIDEO_INFO_FORMAT (info), GST_VIDEO_INFO_WIDTH (info),
537 GST_VIDEO_INFO_HEIGHT (info), GST_VIDEO_INFO_N_PLANES (info),
538 info->offset, info->stride);
547 GST_ERROR_OBJECT (pool, "failed to allocate buffer");
548 return GST_FLOW_ERROR;
553 gst_v4l2_buffer_pool_set_config (GstBufferPool * bpool, GstStructure * config)
555 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool);
556 GstV4l2Object *obj = pool->obj;
558 guint size, min_buffers, max_buffers;
559 GstAllocator *allocator;
560 GstAllocationParams params;
561 gboolean can_allocate = FALSE;
562 gboolean updated = FALSE;
565 pool->add_videometa =
566 gst_buffer_pool_config_has_option (config,
567 GST_BUFFER_POOL_OPTION_VIDEO_META);
569 /* parse the config and keep around */
570 if (!gst_buffer_pool_config_get_params (config, &caps, &size, &min_buffers,
574 if (!gst_buffer_pool_config_get_allocator (config, &allocator, ¶ms))
577 GST_DEBUG_OBJECT (pool, "config %" GST_PTR_FORMAT, config);
580 gst_object_unref (pool->allocator);
581 pool->allocator = NULL;
584 case GST_V4L2_IO_DMABUF:
585 pool->allocator = gst_dmabuf_allocator_new ();
586 can_allocate = GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, MMAP);
588 case GST_V4L2_IO_MMAP:
589 can_allocate = GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, MMAP);
591 case GST_V4L2_IO_USERPTR:
593 GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, USERPTR);
595 case GST_V4L2_IO_DMABUF_IMPORT:
596 can_allocate = GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, DMABUF);
600 pool->allocator = g_object_ref (allocator);
601 pool->params = params;
602 /* No need to change the configuration */
606 g_assert_not_reached ();
610 /* libv4l2 conversion code does not handle CREATE_BUFS, and may lead to
611 * instability and crash, disable it for now */
612 if (can_allocate && obj->fmtdesc->flags & V4L2_FMT_FLAG_EMULATED) {
613 GST_WARNING_OBJECT (pool,
614 "libv4l2 converter detected, disabling CREATE_BUFS");
615 can_allocate = FALSE;
616 GST_OBJECT_FLAG_UNSET (pool->vallocator,
617 GST_V4L2_ALLOCATOR_FLAG_MMAP_CREATE_BUFS
618 | GST_V4L2_ALLOCATOR_FLAG_USERPTR_CREATE_BUFS
619 | GST_V4L2_ALLOCATOR_FLAG_DMABUF_CREATE_BUFS);
622 if (min_buffers < GST_V4L2_MIN_BUFFERS) {
624 min_buffers = GST_V4L2_MIN_BUFFERS;
625 GST_INFO_OBJECT (pool, "increasing minimum buffers to %u", min_buffers);
628 /* respect driver requirements */
629 if (min_buffers < obj->min_buffers) {
631 min_buffers = obj->min_buffers;
632 GST_INFO_OBJECT (pool, "increasing minimum buffers to %u", min_buffers);
635 if (max_buffers > VIDEO_MAX_FRAME || max_buffers == 0) {
637 max_buffers = VIDEO_MAX_FRAME;
638 GST_INFO_OBJECT (pool, "reducing maximum buffers to %u", max_buffers);
641 if (min_buffers > max_buffers) {
643 min_buffers = max_buffers;
644 GST_INFO_OBJECT (pool, "reducing minimum buffers to %u", min_buffers);
645 } else if (min_buffers != max_buffers) {
648 max_buffers = min_buffers;
649 GST_INFO_OBJECT (pool, "can't allocate, setting maximum to minimum");
653 if (!pool->add_videometa && obj->need_video_meta) {
654 GST_INFO_OBJECT (pool, "adding needed video meta");
656 gst_buffer_pool_config_add_option (config,
657 GST_BUFFER_POOL_OPTION_VIDEO_META);
660 /* Always update the config to ensure the configured size matches */
661 gst_buffer_pool_config_set_params (config, caps, obj->info.size, min_buffers,
664 /* keep a GstVideoInfo with defaults for the when we need to copy */
665 gst_video_info_from_caps (&pool->caps_info, caps);
668 ret = GST_BUFFER_POOL_CLASS (parent_class)->set_config (bpool, config);
670 /* If anything was changed documentation recommand to return FALSE */
671 return !updated && ret;
676 GST_ERROR_OBJECT (pool, "invalid config %" GST_PTR_FORMAT, config);
682 gst_v4l2_buffer_pool_resurrect_buffer (GstV4l2BufferPool * pool)
684 GstBufferPoolAcquireParams params = { 0 };
685 GstBuffer *buffer = NULL;
688 GST_DEBUG_OBJECT (pool, "A buffer was lost, reallocating it");
690 /* block recursive calls to this function */
691 g_signal_handler_block (pool->vallocator, pool->group_released_handler);
694 (GstBufferPoolAcquireFlags) GST_V4L2_BUFFER_POOL_ACQUIRE_FLAG_RESURRECT |
695 GST_BUFFER_POOL_ACQUIRE_FLAG_DONTWAIT;
697 gst_buffer_pool_acquire_buffer (GST_BUFFER_POOL (pool), &buffer, ¶ms);
699 if (ret == GST_FLOW_OK)
700 gst_buffer_unref (buffer);
702 g_signal_handler_unblock (pool->vallocator, pool->group_released_handler);
708 gst_v4l2_buffer_pool_streamon (GstV4l2BufferPool * pool)
710 GstV4l2Object *obj = pool->obj;
716 case GST_V4L2_IO_MMAP:
717 case GST_V4L2_IO_USERPTR:
718 case GST_V4L2_IO_DMABUF:
719 case GST_V4L2_IO_DMABUF_IMPORT:
720 #ifndef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER
721 if (!V4L2_TYPE_IS_OUTPUT (pool->obj->type)) {
724 /* For captures, we need to enqueue buffers before we start streaming,
725 * so the driver don't underflow immediatly. As we have put then back
726 * into the base class queue, resurrect them, then releasing will queue
728 for (i = 0; i < pool->num_allocated; i++)
729 gst_v4l2_buffer_pool_resurrect_buffer (pool);
731 #endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
733 if (obj->ioctl (pool->video_fd, VIDIOC_STREAMON, &obj->type) < 0)
734 goto streamon_failed;
736 pool->streaming = TRUE;
738 GST_DEBUG_OBJECT (pool, "Started streaming");
748 GST_ERROR_OBJECT (pool, "error with STREAMON %d (%s)", errno,
754 /* Call with streamlock held, or when streaming threads are down */
756 gst_v4l2_buffer_pool_streamoff (GstV4l2BufferPool * pool)
758 GstBufferPoolClass *pclass = GST_BUFFER_POOL_CLASS (parent_class);
759 GstV4l2Object *obj = pool->obj;
761 #ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER
763 #endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
765 if (!pool->streaming)
768 #ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER
769 if (!V4L2_TYPE_IS_OUTPUT(pool->obj->type)) {
770 g_mutex_lock (&pool->buffer_lock);
772 GST_INFO_OBJECT (pool, "live buffer[%d]", pool->live_buffer_count);
774 if (pool->live_buffer_count > 0) {
775 end_time = g_get_monotonic_time () + G_TIME_SPAN_SECOND;
778 GST_WARNING_OBJECT (pool, "wait for live buffer[%d]", pool->live_buffer_count);
780 if (!g_cond_wait_until (&pool->buffer_cond, &pool->buffer_lock, end_time)) {
781 GST_ERROR_OBJECT (pool, "failed to wait live buffer[%d]", pool->live_buffer_count);
785 GST_WARNING_OBJECT (pool, "signal received, check again : live count[%d]",
786 pool->live_buffer_count);
787 } while (pool->live_buffer_count > 0);
790 g_mutex_unlock (&pool->buffer_lock);
792 #endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
794 case GST_V4L2_IO_MMAP:
795 case GST_V4L2_IO_USERPTR:
796 case GST_V4L2_IO_DMABUF:
797 case GST_V4L2_IO_DMABUF_IMPORT:
799 if (obj->ioctl (pool->video_fd, VIDIOC_STREAMOFF, &obj->type) < 0)
800 GST_WARNING_OBJECT (pool, "STREAMOFF failed with errno %d (%s)",
801 errno, g_strerror (errno));
803 pool->streaming = FALSE;
805 GST_DEBUG_OBJECT (pool, "Stopped streaming");
807 if (pool->vallocator)
808 gst_v4l2_allocator_flush (pool->vallocator);
814 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
815 if (pool->buffers[i]) {
816 GstBuffer *buffer = pool->buffers[i];
817 GstBufferPool *bpool = GST_BUFFER_POOL (pool);
819 pool->buffers[i] = NULL;
821 if (V4L2_TYPE_IS_OUTPUT (pool->obj->type))
822 gst_v4l2_buffer_pool_release_buffer (bpool, buffer);
823 else /* Don't re-enqueue capture buffer on stop */
824 pclass->release_buffer (bpool, buffer);
826 g_atomic_int_add (&pool->num_queued, -1);
832 gst_v4l2_buffer_pool_start (GstBufferPool * bpool)
834 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool);
835 GstBufferPoolClass *pclass = GST_BUFFER_POOL_CLASS (parent_class);
836 GstV4l2Object *obj = pool->obj;
837 GstStructure *config;
839 guint size, min_buffers, max_buffers;
840 guint max_latency, min_latency, copy_threshold = 0;
841 gboolean can_allocate = FALSE, ret = TRUE;
843 GST_DEBUG_OBJECT (pool, "activating pool");
845 if (pool->other_pool) {
848 if (!gst_buffer_pool_set_active (pool->other_pool, TRUE))
849 goto other_pool_failed;
851 if (gst_buffer_pool_acquire_buffer (pool->other_pool, &buffer, NULL) !=
853 goto other_pool_failed;
855 if (!gst_v4l2_object_try_import (obj, buffer)) {
856 gst_buffer_unref (buffer);
859 gst_buffer_unref (buffer);
862 config = gst_buffer_pool_get_config (bpool);
863 if (!gst_buffer_pool_config_get_params (config, &caps, &size, &min_buffers,
867 min_latency = MAX (GST_V4L2_MIN_BUFFERS, obj->min_buffers);
873 /* This workaround a unfixable bug in libv4l2 when RW is emulated on top
874 * of MMAP. In this case, the first read initialize the queues, but the
875 * poll before that will always fail. Doing an empty read, forces the
876 * queue to be initialized now. We only do this if we have a streaming
878 if (obj->device_caps & V4L2_CAP_STREAMING)
879 obj->read (obj->video_fd, NULL, 0);
882 case GST_V4L2_IO_DMABUF:
883 case GST_V4L2_IO_MMAP:
887 can_allocate = GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, MMAP);
889 /* first, lets request buffers, and see how many we can get: */
890 GST_DEBUG_OBJECT (pool, "requesting %d MMAP buffers", min_buffers);
892 count = gst_v4l2_allocator_start (pool->vallocator, min_buffers,
894 pool->num_allocated = count;
896 if (count < GST_V4L2_MIN_BUFFERS) {
901 /* V4L2 buffer pool are often very limited in the amount of buffers it
902 * can offer. The copy_threshold will workaround this limitation by
903 * falling back to copy if the pipeline needed more buffers. This also
904 * prevent having to do REQBUFS(N)/REQBUFS(0) everytime configure is
906 if (count != min_buffers || pool->enable_copy_threshold) {
907 GST_WARNING_OBJECT (pool,
908 "Uncertain or not enough buffers, enabling copy threshold");
910 copy_threshold = min_latency;
915 case GST_V4L2_IO_USERPTR:
920 GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, USERPTR);
922 GST_DEBUG_OBJECT (pool, "requesting %d USERPTR buffers", min_buffers);
924 count = gst_v4l2_allocator_start (pool->vallocator, min_buffers,
925 V4L2_MEMORY_USERPTR);
927 /* There is no rational to not get what we asked */
928 if (count < min_buffers) {
936 case GST_V4L2_IO_DMABUF_IMPORT:
940 can_allocate = GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, DMABUF);
942 GST_DEBUG_OBJECT (pool, "requesting %d DMABUF buffers", min_buffers);
944 count = gst_v4l2_allocator_start (pool->vallocator, min_buffers,
947 /* There is no rational to not get what we asked */
948 if (count < min_buffers) {
959 g_assert_not_reached ();
964 max_latency = max_buffers;
966 max_latency = min_buffers;
969 pool->copy_threshold = copy_threshold;
970 pool->max_latency = max_latency;
971 pool->min_latency = min_latency;
972 pool->num_queued = 0;
974 if (max_buffers != 0 && max_buffers < min_buffers)
975 max_buffers = min_buffers;
977 gst_buffer_pool_config_set_params (config, caps, size, min_buffers,
979 pclass->set_config (bpool, config);
980 gst_structure_free (config);
982 /* now, allocate the buffers: */
983 if (!pclass->start (bpool))
986 if (!V4L2_TYPE_IS_OUTPUT (obj->type)) {
987 if (g_atomic_int_get (&pool->num_queued) < min_buffers)
990 pool->group_released_handler =
991 g_signal_connect_swapped (pool->vallocator, "group-released",
992 G_CALLBACK (gst_v4l2_buffer_pool_resurrect_buffer), pool);
993 ret = gst_v4l2_buffer_pool_streamon (pool);
1001 GST_ERROR_OBJECT (pool, "invalid config %" GST_PTR_FORMAT, config);
1002 gst_structure_free (config);
1007 GST_ERROR_OBJECT (pool,
1008 "we received %d buffer from device '%s', we want at least %d",
1009 min_buffers, obj->videodev, GST_V4L2_MIN_BUFFERS);
1010 gst_structure_free (config);
1015 GST_ERROR_OBJECT (pool, "allocate failed");
1020 GST_ERROR_OBJECT (pool, "failed to activate the other pool %"
1021 GST_PTR_FORMAT, pool->other_pool);
1026 GST_ERROR_OBJECT (pool, "failed to queue buffers into the capture queue");
1031 GST_ERROR_OBJECT (pool, "cannot import buffers from downstream pool");
1037 gst_v4l2_buffer_pool_vallocator_stop (GstV4l2BufferPool * pool)
1041 if (!pool->vallocator)
1044 vret = gst_v4l2_allocator_stop (pool->vallocator);
1046 if (vret == GST_V4L2_BUSY)
1047 GST_WARNING_OBJECT (pool, "some buffers are still outstanding");
1049 return (vret == GST_V4L2_OK);
1053 gst_v4l2_buffer_pool_stop (GstBufferPool * bpool)
1055 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool);
1059 return gst_v4l2_buffer_pool_vallocator_stop (pool);
1061 GST_DEBUG_OBJECT (pool, "stopping pool");
1063 if (pool->group_released_handler > 0) {
1064 g_signal_handler_disconnect (pool->vallocator,
1065 pool->group_released_handler);
1066 pool->group_released_handler = 0;
1069 if (pool->other_pool) {
1070 gst_buffer_pool_set_active (pool->other_pool, FALSE);
1071 gst_object_unref (pool->other_pool);
1072 pool->other_pool = NULL;
1075 gst_v4l2_buffer_pool_streamoff (pool);
1077 ret = GST_BUFFER_POOL_CLASS (parent_class)->stop (bpool);
1080 ret = gst_v4l2_buffer_pool_vallocator_stop (pool);
1086 gst_v4l2_buffer_pool_orphan (GstBufferPool ** bpool)
1088 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (*bpool);
1091 if (!GST_V4L2_ALLOCATOR_CAN_ORPHAN_BUFS (pool->vallocator))
1094 if (g_getenv ("GST_V4L2_FORCE_DRAIN"))
1097 GST_DEBUG_OBJECT (pool, "orphaning pool");
1099 gst_buffer_pool_set_active (*bpool, FALSE);
1101 * If the buffer pool has outstanding buffers, it will not be stopped
1102 * by the base class when set inactive. Stop it manually and mark it
1105 ret = gst_v4l2_buffer_pool_stop (*bpool);
1107 ret = gst_v4l2_allocator_orphan (pool->vallocator);
1112 pool->orphaned = TRUE;
1113 gst_object_unref (*bpool);
1121 gst_v4l2_buffer_pool_flush_start (GstBufferPool * bpool)
1123 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool);
1125 GST_DEBUG_OBJECT (pool, "start flushing");
1127 gst_poll_set_flushing (pool->poll, TRUE);
1129 GST_OBJECT_LOCK (pool);
1130 pool->empty = FALSE;
1131 g_cond_broadcast (&pool->empty_cond);
1132 GST_OBJECT_UNLOCK (pool);
1134 if (pool->other_pool)
1135 gst_buffer_pool_set_flushing (pool->other_pool, TRUE);
1139 gst_v4l2_buffer_pool_flush_stop (GstBufferPool * bpool)
1141 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool);
1143 GST_DEBUG_OBJECT (pool, "stop flushing");
1145 if (pool->other_pool)
1146 gst_buffer_pool_set_flushing (pool->other_pool, FALSE);
1148 gst_poll_set_flushing (pool->poll, FALSE);
1151 static GstFlowReturn
1152 gst_v4l2_buffer_pool_poll (GstV4l2BufferPool * pool, gboolean wait)
1155 GstClockTime timeout;
1158 timeout = GST_CLOCK_TIME_NONE;
1162 /* In RW mode there is no queue, hence no need to wait while the queue is
1164 if (pool->obj->mode != GST_V4L2_IO_RW) {
1165 GST_OBJECT_LOCK (pool);
1167 if (!wait && pool->empty) {
1168 GST_OBJECT_UNLOCK (pool);
1173 g_cond_wait (&pool->empty_cond, GST_OBJECT_GET_LOCK (pool));
1175 GST_OBJECT_UNLOCK (pool);
1178 if (!pool->can_poll_device) {
1185 GST_LOG_OBJECT (pool, "polling device");
1188 ret = gst_poll_wait (pool->poll, timeout);
1189 if (G_UNLIKELY (ret < 0)) {
1197 GST_WARNING_OBJECT (pool,
1198 "v4l2 device doesn't support polling. Disabling"
1199 " using libv4l2 in this case may cause deadlocks");
1200 pool->can_poll_device = FALSE;
1207 if (gst_poll_fd_has_error (pool->poll, &pool->pollfd))
1219 GST_DEBUG_OBJECT (pool, "stop called");
1220 return GST_FLOW_FLUSHING;
1224 GST_ELEMENT_ERROR (pool->obj->element, RESOURCE, READ, (NULL),
1225 ("poll error %d: %s (%d)", ret, g_strerror (errno), errno));
1226 return GST_FLOW_ERROR;
1229 return GST_FLOW_CUSTOM_SUCCESS;
1232 static GstFlowReturn
1233 gst_v4l2_buffer_pool_qbuf (GstV4l2BufferPool * pool, GstBuffer * buf,
1234 GstV4l2MemoryGroup * group)
1236 const GstV4l2Object *obj = pool->obj;
1237 GstClockTime timestamp;
1240 index = group->buffer.index;
1242 if (pool->buffers[index] != NULL)
1243 goto already_queued;
1245 GST_LOG_OBJECT (pool, "queuing buffer %i", index);
1247 if (V4L2_TYPE_IS_OUTPUT (obj->type)) {
1248 enum v4l2_field field;
1250 /* Except when field is set to alternate, buffer field is the same as
1251 * the one defined in format */
1252 if (V4L2_TYPE_IS_MULTIPLANAR (obj->type))
1253 field = obj->format.fmt.pix_mp.field;
1255 field = obj->format.fmt.pix.field;
1257 /* NB: At this moment, we can't have alternate mode because it not handled
1259 if (field == V4L2_FIELD_ALTERNATE) {
1260 if (GST_BUFFER_FLAG_IS_SET (buf, GST_VIDEO_FRAME_FLAG_TFF))
1261 field = V4L2_FIELD_TOP;
1263 field = V4L2_FIELD_BOTTOM;
1266 group->buffer.field = field;
1269 if (GST_BUFFER_TIMESTAMP_IS_VALID (buf)) {
1270 timestamp = GST_BUFFER_TIMESTAMP (buf);
1271 GST_TIME_TO_TIMEVAL (timestamp, group->buffer.timestamp);
1274 GST_OBJECT_LOCK (pool);
1275 g_atomic_int_inc (&pool->num_queued);
1276 pool->buffers[index] = buf;
1278 if (!gst_v4l2_allocator_qbuf (pool->vallocator, group))
1281 pool->empty = FALSE;
1282 g_cond_signal (&pool->empty_cond);
1283 GST_OBJECT_UNLOCK (pool);
1289 GST_ERROR_OBJECT (pool, "the buffer %i was already queued", index);
1290 return GST_FLOW_ERROR;
1294 GST_ERROR_OBJECT (pool, "could not queue a buffer %i", index);
1295 /* Mark broken buffer to the allocator */
1296 GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_TAG_MEMORY);
1297 g_atomic_int_add (&pool->num_queued, -1);
1298 pool->buffers[index] = NULL;
1299 GST_OBJECT_UNLOCK (pool);
1300 return GST_FLOW_ERROR;
1304 static GstFlowReturn
1305 gst_v4l2_buffer_pool_dqbuf (GstV4l2BufferPool * pool, GstBuffer ** buffer,
1309 GstBuffer *outbuf = NULL;
1310 GstV4l2Object *obj = pool->obj;
1311 GstClockTime timestamp;
1312 GstV4l2MemoryGroup *group;
1313 GstVideoMeta *vmeta;
1316 #ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER
1317 GstV4l2TizenBuffer *tizen_buffer = NULL;
1318 #endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
1320 if ((res = gst_v4l2_buffer_pool_poll (pool, wait)) < GST_FLOW_OK)
1323 if (res == GST_FLOW_CUSTOM_SUCCESS) {
1324 GST_LOG_OBJECT (pool, "nothing to dequeue");
1328 GST_LOG_OBJECT (pool, "dequeueing a buffer");
1330 res = gst_v4l2_allocator_dqbuf (pool->vallocator, &group);
1331 if (res == GST_FLOW_EOS)
1333 if (res != GST_FLOW_OK)
1336 /* get our GstBuffer with that index from the pool, if the buffer was
1337 * outstanding we have a serious problem.
1339 outbuf = pool->buffers[group->buffer.index];
1343 /* mark the buffer outstanding */
1344 pool->buffers[group->buffer.index] = NULL;
1345 if (g_atomic_int_dec_and_test (&pool->num_queued)) {
1346 GST_OBJECT_LOCK (pool);
1348 GST_OBJECT_UNLOCK (pool);
1351 timestamp = GST_TIMEVAL_TO_TIME (group->buffer.timestamp);
1354 vmeta = gst_buffer_get_video_meta (outbuf);
1355 for (i = 0; i < group->n_mem; i++) {
1356 GST_LOG_OBJECT (pool,
1357 "dequeued buffer %p seq:%d (ix=%d), mem %p used %d, plane=%d, flags %08x, ts %"
1358 GST_TIME_FORMAT ", pool-queued=%d, buffer=%p", outbuf,
1359 group->buffer.sequence, group->buffer.index, group->mem[i],
1360 group->planes[i].bytesused, i, group->buffer.flags,
1361 GST_TIME_ARGS (timestamp), pool->num_queued, outbuf);
1364 vmeta->offset[i] = size;
1365 size += gst_memory_get_sizes (group->mem[i], NULL, NULL);
1369 /* Ignore timestamp and field for OUTPUT device */
1370 if (V4L2_TYPE_IS_OUTPUT (obj->type))
1373 /* Check for driver bug in reporting feild */
1374 if (group->buffer.field == V4L2_FIELD_ANY) {
1375 /* Only warn once to avoid the spamming */
1376 #ifndef GST_DISABLE_GST_DEBUG
1377 if (!pool->has_warned_on_buggy_field) {
1378 pool->has_warned_on_buggy_field = TRUE;
1379 GST_WARNING_OBJECT (pool,
1380 "Driver should never set v4l2_buffer.field to ANY");
1384 /* Use the value from the format (works for UVC bug) */
1385 group->buffer.field = obj->format.fmt.pix.field;
1387 /* If driver also has buggy S_FMT, assume progressive */
1388 if (group->buffer.field == V4L2_FIELD_ANY) {
1389 #ifndef GST_DISABLE_GST_DEBUG
1390 if (!pool->has_warned_on_buggy_field) {
1391 pool->has_warned_on_buggy_field = TRUE;
1392 GST_WARNING_OBJECT (pool,
1393 "Driver should never set v4l2_format.pix.field to ANY");
1397 group->buffer.field = V4L2_FIELD_NONE;
1401 /* set top/bottom field first if v4l2_buffer has the information */
1402 switch (group->buffer.field) {
1403 case V4L2_FIELD_NONE:
1404 GST_BUFFER_FLAG_UNSET (outbuf, GST_VIDEO_BUFFER_FLAG_INTERLACED);
1405 GST_BUFFER_FLAG_UNSET (outbuf, GST_VIDEO_BUFFER_FLAG_TFF);
1407 case V4L2_FIELD_INTERLACED_TB:
1408 GST_BUFFER_FLAG_SET (outbuf, GST_VIDEO_BUFFER_FLAG_INTERLACED);
1409 GST_BUFFER_FLAG_SET (outbuf, GST_VIDEO_BUFFER_FLAG_TFF);
1411 case V4L2_FIELD_INTERLACED_BT:
1412 GST_BUFFER_FLAG_SET (outbuf, GST_VIDEO_BUFFER_FLAG_INTERLACED);
1413 GST_BUFFER_FLAG_UNSET (outbuf, GST_VIDEO_BUFFER_FLAG_TFF);
1415 case V4L2_FIELD_INTERLACED:
1416 GST_BUFFER_FLAG_SET (outbuf, GST_VIDEO_BUFFER_FLAG_INTERLACED);
1417 if (obj->tv_norm == V4L2_STD_NTSC_M ||
1418 obj->tv_norm == V4L2_STD_NTSC_M_JP ||
1419 obj->tv_norm == V4L2_STD_NTSC_M_KR) {
1420 GST_BUFFER_FLAG_UNSET (outbuf, GST_VIDEO_BUFFER_FLAG_TFF);
1422 GST_BUFFER_FLAG_SET (outbuf, GST_VIDEO_BUFFER_FLAG_TFF);
1426 GST_BUFFER_FLAG_UNSET (outbuf, GST_VIDEO_BUFFER_FLAG_INTERLACED);
1427 GST_BUFFER_FLAG_UNSET (outbuf, GST_VIDEO_BUFFER_FLAG_TFF);
1428 GST_FIXME_OBJECT (pool,
1429 "Unhandled enum v4l2_field %d - treating as progressive",
1430 group->buffer.field);
1434 if (GST_VIDEO_INFO_FORMAT (&obj->info) == GST_VIDEO_FORMAT_ENCODED) {
1435 if ((group->buffer.flags & V4L2_BUF_FLAG_KEYFRAME) ||
1436 GST_V4L2_PIXELFORMAT (obj) == V4L2_PIX_FMT_MJPEG ||
1437 GST_V4L2_PIXELFORMAT (obj) == V4L2_PIX_FMT_JPEG ||
1438 GST_V4L2_PIXELFORMAT (obj) == V4L2_PIX_FMT_PJPG)
1439 GST_BUFFER_FLAG_UNSET (outbuf, GST_BUFFER_FLAG_DELTA_UNIT);
1441 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DELTA_UNIT);
1444 if (group->buffer.flags & V4L2_BUF_FLAG_ERROR)
1445 GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_CORRUPTED);
1447 GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
1448 GST_BUFFER_OFFSET (outbuf) = group->buffer.sequence;
1449 GST_BUFFER_OFFSET_END (outbuf) = group->buffer.sequence + 1;
1451 #ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER
1452 if (group->surface) {
1453 tizen_buffer = gst_v4l2_tizen_buffer_new (outbuf, group->buffer.index, pool);
1454 if (!tizen_buffer) {
1455 GST_ERROR_OBJECT (pool, "tizen buffer failed for index[%d]", group->buffer.index);
1458 outbuf = tizen_buffer->gst_buffer;
1460 #endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
1469 GST_DEBUG_OBJECT (pool, "poll error %s", gst_flow_get_name (res));
1474 return GST_FLOW_EOS;
1478 return GST_FLOW_ERROR;
1482 GST_ERROR_OBJECT (pool, "No free buffer found in the pool at index %d.",
1483 group->buffer.index);
1484 return GST_FLOW_ERROR;
1488 static GstFlowReturn
1489 gst_v4l2_buffer_pool_acquire_buffer (GstBufferPool * bpool, GstBuffer ** buffer,
1490 GstBufferPoolAcquireParams * params)
1493 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool);
1494 GstBufferPoolClass *pclass = GST_BUFFER_POOL_CLASS (parent_class);
1495 GstV4l2Object *obj = pool->obj;
1497 GST_DEBUG_OBJECT (pool, "acquire");
1499 /* If this is being called to resurrect a lost buffer */
1500 if (params && params->flags & GST_V4L2_BUFFER_POOL_ACQUIRE_FLAG_RESURRECT) {
1501 ret = pclass->acquire_buffer (bpool, buffer, params);
1505 switch (obj->type) {
1506 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1507 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
1508 /* capture, This function should return a buffer with new captured data */
1509 switch (obj->mode) {
1510 case GST_V4L2_IO_RW:
1512 /* take empty buffer from the pool */
1513 ret = pclass->acquire_buffer (bpool, buffer, params);
1516 case GST_V4L2_IO_DMABUF:
1517 case GST_V4L2_IO_MMAP:
1518 case GST_V4L2_IO_USERPTR:
1519 case GST_V4L2_IO_DMABUF_IMPORT:
1521 /* just dequeue a buffer, we basically use the queue of v4l2 as the
1522 * storage for our buffers. This function does poll first so we can
1523 * interrupt it fine. */
1524 ret = gst_v4l2_buffer_pool_dqbuf (pool, buffer, TRUE);
1528 ret = GST_FLOW_ERROR;
1529 g_assert_not_reached ();
1535 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1536 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
1537 /* playback, This function should return an empty buffer */
1538 switch (obj->mode) {
1539 case GST_V4L2_IO_RW:
1540 /* get an empty buffer */
1541 ret = pclass->acquire_buffer (bpool, buffer, params);
1544 case GST_V4L2_IO_MMAP:
1545 case GST_V4L2_IO_DMABUF:
1546 case GST_V4L2_IO_USERPTR:
1547 case GST_V4L2_IO_DMABUF_IMPORT:
1548 /* get a free unqueued buffer */
1549 ret = pclass->acquire_buffer (bpool, buffer, params);
1553 ret = GST_FLOW_ERROR;
1554 g_assert_not_reached ();
1560 ret = GST_FLOW_ERROR;
1561 g_assert_not_reached ();
1569 gst_v4l2_buffer_pool_release_buffer (GstBufferPool * bpool, GstBuffer * buffer)
1571 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool);
1572 GstBufferPoolClass *pclass = GST_BUFFER_POOL_CLASS (parent_class);
1573 GstV4l2Object *obj = pool->obj;
1575 GST_DEBUG_OBJECT (pool, "release buffer %p", buffer);
1577 /* If the buffer's pool has been orphaned, dispose of it so that
1578 * the pool resources can be freed */
1579 if (pool->orphaned) {
1580 GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY);
1581 pclass->release_buffer (bpool, buffer);
1585 switch (obj->type) {
1586 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1587 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
1588 /* capture, put the buffer back in the queue so that we can refill it
1590 switch (obj->mode) {
1591 case GST_V4L2_IO_RW:
1592 /* release back in the pool */
1593 pclass->release_buffer (bpool, buffer);
1596 case GST_V4L2_IO_DMABUF:
1597 case GST_V4L2_IO_MMAP:
1598 case GST_V4L2_IO_USERPTR:
1599 case GST_V4L2_IO_DMABUF_IMPORT:
1601 GstV4l2MemoryGroup *group;
1602 if (gst_v4l2_is_buffer_valid (buffer, &group)) {
1603 GstFlowReturn ret = GST_FLOW_OK;
1605 gst_v4l2_allocator_reset_group (pool->vallocator, group);
1606 /* queue back in the device */
1607 if (pool->other_pool)
1608 ret = gst_v4l2_buffer_pool_prepare_buffer (pool, buffer, NULL);
1609 if (ret != GST_FLOW_OK ||
1610 gst_v4l2_buffer_pool_qbuf (pool, buffer, group) != GST_FLOW_OK)
1611 pclass->release_buffer (bpool, buffer);
1613 /* Simply release invalide/modified buffer, the allocator will
1614 * give it back later */
1615 GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY);
1616 pclass->release_buffer (bpool, buffer);
1621 g_assert_not_reached ();
1626 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1627 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
1628 switch (obj->mode) {
1629 case GST_V4L2_IO_RW:
1630 /* release back in the pool */
1631 pclass->release_buffer (bpool, buffer);
1634 case GST_V4L2_IO_MMAP:
1635 case GST_V4L2_IO_DMABUF:
1636 case GST_V4L2_IO_USERPTR:
1637 case GST_V4L2_IO_DMABUF_IMPORT:
1639 GstV4l2MemoryGroup *group;
1642 if (!gst_v4l2_is_buffer_valid (buffer, &group)) {
1643 /* Simply release invalide/modified buffer, the allocator will
1644 * give it back later */
1645 GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY);
1646 pclass->release_buffer (bpool, buffer);
1650 index = group->buffer.index;
1652 if (pool->buffers[index] == NULL) {
1653 GST_LOG_OBJECT (pool, "buffer %u not queued, putting on free list",
1656 /* Remove qdata, this will unmap any map data in userptr */
1657 gst_mini_object_set_qdata (GST_MINI_OBJECT (buffer),
1658 GST_V4L2_IMPORT_QUARK, NULL, NULL);
1660 /* reset to default size */
1661 gst_v4l2_allocator_reset_group (pool->vallocator, group);
1663 /* playback, put the buffer back in the queue to refill later. */
1664 pclass->release_buffer (bpool, buffer);
1666 /* the buffer is queued in the device but maybe not played yet. We just
1667 * leave it there and not make it available for future calls to acquire
1668 * for now. The buffer will be dequeued and reused later. */
1669 GST_LOG_OBJECT (pool, "buffer %u is queued", index);
1675 g_assert_not_reached ();
1681 g_assert_not_reached ();
1687 gst_v4l2_buffer_pool_dispose (GObject * object)
1689 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (object);
1691 if (pool->vallocator)
1692 gst_object_unref (pool->vallocator);
1693 pool->vallocator = NULL;
1695 if (pool->allocator)
1696 gst_object_unref (pool->allocator);
1697 pool->allocator = NULL;
1699 #ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER
1700 g_cond_clear (&pool->buffer_cond);
1701 g_mutex_clear (&pool->buffer_lock);
1703 if (pool->tallocator)
1704 gst_object_unref (pool->tallocator);
1705 pool->tallocator = NULL;
1706 #endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
1707 if (pool->other_pool)
1708 gst_object_unref (pool->other_pool);
1709 pool->other_pool = NULL;
1711 G_OBJECT_CLASS (parent_class)->dispose (object);
1715 gst_v4l2_buffer_pool_finalize (GObject * object)
1717 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (object);
1719 if (pool->video_fd >= 0)
1720 pool->obj->close (pool->video_fd);
1722 gst_poll_free (pool->poll);
1724 /* This can't be done in dispose method because we must not set pointer
1725 * to NULL as it is part of the v4l2object and dispose could be called
1727 gst_object_unref (pool->obj->element);
1729 g_cond_clear (&pool->empty_cond);
1731 /* FIXME have we done enough here ? */
1733 G_OBJECT_CLASS (parent_class)->finalize (object);
1737 gst_v4l2_buffer_pool_init (GstV4l2BufferPool * pool)
1739 pool->poll = gst_poll_new (TRUE);
1740 pool->can_poll_device = TRUE;
1741 g_cond_init (&pool->empty_cond);
1743 pool->orphaned = FALSE;
1747 gst_v4l2_buffer_pool_class_init (GstV4l2BufferPoolClass * klass)
1749 GObjectClass *object_class = G_OBJECT_CLASS (klass);
1750 GstBufferPoolClass *bufferpool_class = GST_BUFFER_POOL_CLASS (klass);
1752 object_class->dispose = gst_v4l2_buffer_pool_dispose;
1753 object_class->finalize = gst_v4l2_buffer_pool_finalize;
1755 bufferpool_class->start = gst_v4l2_buffer_pool_start;
1756 bufferpool_class->stop = gst_v4l2_buffer_pool_stop;
1757 bufferpool_class->set_config = gst_v4l2_buffer_pool_set_config;
1758 bufferpool_class->alloc_buffer = gst_v4l2_buffer_pool_alloc_buffer;
1759 bufferpool_class->acquire_buffer = gst_v4l2_buffer_pool_acquire_buffer;
1760 bufferpool_class->release_buffer = gst_v4l2_buffer_pool_release_buffer;
1761 bufferpool_class->flush_start = gst_v4l2_buffer_pool_flush_start;
1762 bufferpool_class->flush_stop = gst_v4l2_buffer_pool_flush_stop;
1764 GST_DEBUG_CATEGORY_INIT (v4l2bufferpool_debug, "v4l2bufferpool", 0,
1765 "V4L2 Buffer Pool");
1766 GST_DEBUG_CATEGORY_GET (CAT_PERFORMANCE, "GST_PERFORMANCE");
1770 * gst_v4l2_buffer_pool_new:
1771 * @obj: the v4l2 object owning the pool
1773 * Construct a new buffer pool.
1775 * Returns: the new pool, use gst_object_unref() to free resources
1778 gst_v4l2_buffer_pool_new (GstV4l2Object * obj, GstCaps * caps)
1780 GstV4l2BufferPool *pool;
1781 GstStructure *config;
1782 gchar *name, *parent_name;
1785 fd = obj->dup (obj->video_fd);
1789 /* setting a significant unique name */
1790 parent_name = gst_object_get_name (GST_OBJECT (obj->element));
1791 name = g_strconcat (parent_name, ":", "pool:",
1792 V4L2_TYPE_IS_OUTPUT (obj->type) ? "sink" : "src", NULL);
1793 g_free (parent_name);
1795 pool = (GstV4l2BufferPool *) g_object_new (GST_TYPE_V4L2_BUFFER_POOL,
1796 "name", name, NULL);
1797 g_object_ref_sink (pool);
1800 gst_poll_fd_init (&pool->pollfd);
1801 pool->pollfd.fd = fd;
1802 gst_poll_add_fd (pool->poll, &pool->pollfd);
1803 if (V4L2_TYPE_IS_OUTPUT (obj->type))
1804 gst_poll_fd_ctl_write (pool->poll, &pool->pollfd, TRUE);
1806 gst_poll_fd_ctl_read (pool->poll, &pool->pollfd, TRUE);
1808 pool->video_fd = fd;
1810 pool->can_poll_device = TRUE;
1812 #ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER
1813 pool->tallocator = gst_tizen_allocator_new ();
1814 if (pool->tallocator == NULL)
1815 goto allocator_failed;
1817 g_mutex_init (&pool->buffer_lock);
1818 g_cond_init (&pool->buffer_cond);
1819 #endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
1820 pool->vallocator = gst_v4l2_allocator_new (GST_OBJECT (pool), obj);
1821 if (pool->vallocator == NULL)
1822 goto allocator_failed;
1824 gst_object_ref (obj->element);
1826 config = gst_buffer_pool_get_config (GST_BUFFER_POOL_CAST (pool));
1827 gst_buffer_pool_config_set_params (config, caps, obj->info.size, 0, 0);
1828 /* This will simply set a default config, but will not configure the pool
1829 * because min and max are not valid */
1830 gst_buffer_pool_set_config (GST_BUFFER_POOL_CAST (pool), config);
1832 return GST_BUFFER_POOL (pool);
1837 GST_ERROR ("failed to dup fd %d (%s)", errno, g_strerror (errno));
1842 #ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER
1843 if (pool->tallocator) {
1844 gst_object_unref (pool->tallocator);
1845 pool->tallocator = NULL;
1847 #endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
1848 GST_ERROR_OBJECT (pool, "Failed to create V4L2 allocator");
1849 gst_object_unref (pool);
1854 static GstFlowReturn
1855 gst_v4l2_do_read (GstV4l2BufferPool * pool, GstBuffer * buf)
1858 GstV4l2Object *obj = pool->obj;
1863 toread = obj->info.size;
1865 GST_LOG_OBJECT (pool, "reading %d bytes into buffer %p", toread, buf);
1867 gst_buffer_map (buf, &map, GST_MAP_WRITE);
1870 if ((res = gst_v4l2_buffer_pool_poll (pool, TRUE)) != GST_FLOW_OK)
1873 amount = obj->read (obj->video_fd, map.data, toread);
1875 if (amount == toread) {
1877 } else if (amount == -1) {
1878 if (errno == EAGAIN || errno == EINTR) {
1883 /* short reads can happen if a signal interrupts the read */
1888 GST_LOG_OBJECT (pool, "read %d bytes", amount);
1889 gst_buffer_unmap (buf, &map);
1890 gst_buffer_resize (buf, 0, amount);
1897 GST_DEBUG ("poll error %s", gst_flow_get_name (res));
1902 GST_ELEMENT_ERROR (obj->element, RESOURCE, READ,
1903 (_("Error reading %d bytes from device '%s'."),
1904 toread, obj->videodev), GST_ERROR_SYSTEM);
1905 res = GST_FLOW_ERROR;
1910 gst_buffer_unmap (buf, &map);
1911 gst_buffer_resize (buf, 0, 0);
1917 * gst_v4l2_buffer_pool_process:
1918 * @bpool: a #GstBufferPool
1919 * @buf: a #GstBuffer, maybe be replaced
1921 * Process @buf in @bpool. For capture devices, this functions fills @buf with
1922 * data from the device. For output devices, this functions send the contents of
1923 * @buf to the device for playback.
1925 * Returns: %GST_FLOW_OK on success.
1928 gst_v4l2_buffer_pool_process (GstV4l2BufferPool * pool, GstBuffer ** buf)
1930 GstFlowReturn ret = GST_FLOW_OK;
1931 GstBufferPool *bpool = GST_BUFFER_POOL_CAST (pool);
1932 GstV4l2Object *obj = pool->obj;
1934 GST_DEBUG_OBJECT (pool, "process buffer %p", buf);
1936 if (GST_BUFFER_POOL_IS_FLUSHING (pool))
1937 return GST_FLOW_FLUSHING;
1939 switch (obj->type) {
1940 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1941 case V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE:
1943 switch (obj->mode) {
1944 case GST_V4L2_IO_RW:
1945 /* capture into the buffer */
1946 ret = gst_v4l2_do_read (pool, *buf);
1949 case GST_V4L2_IO_MMAP:
1950 case GST_V4L2_IO_DMABUF:
1954 if ((*buf)->pool == bpool) {
1956 gsize size = gst_buffer_get_size (*buf);
1958 /* Legacy M2M devices return empty buffer when drained */
1959 if (size == 0 && GST_V4L2_IS_M2M (obj->device_caps))
1962 if (GST_VIDEO_INFO_FORMAT (&pool->caps_info) !=
1963 GST_VIDEO_FORMAT_ENCODED && size < pool->size)
1964 goto buffer_truncated;
1966 num_queued = g_atomic_int_get (&pool->num_queued);
1967 GST_TRACE_OBJECT (pool, "Only %i buffer left in the capture queue.",
1970 /* If we have no more buffer, and can allocate it time to do so */
1971 if (num_queued == 0) {
1972 if (GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, MMAP)) {
1973 ret = gst_v4l2_buffer_pool_resurrect_buffer (pool);
1974 if (ret == GST_FLOW_OK)
1979 /* start copying buffers when we are running low on buffers */
1980 if (num_queued < pool->copy_threshold) {
1983 if (GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, MMAP)) {
1984 ret = gst_v4l2_buffer_pool_resurrect_buffer (pool);
1985 if (ret == GST_FLOW_OK)
1989 /* copy the buffer */
1990 copy = gst_buffer_copy_region (*buf,
1991 GST_BUFFER_COPY_ALL | GST_BUFFER_COPY_DEEP, 0, -1);
1992 GST_LOG_OBJECT (pool, "copy buffer %p->%p", *buf, copy);
1994 /* and requeue so that we can continue capturing */
1995 gst_buffer_unref (*buf);
2000 /* nothing, data was inside the buffer when we did _acquire() */
2004 /* buffer not from our pool, grab a frame and copy it into the target */
2005 if ((ret = gst_v4l2_buffer_pool_dqbuf (pool, &tmp, TRUE))
2009 /* An empty buffer on capture indicates the end of stream */
2010 if (gst_buffer_get_size (tmp) == 0) {
2011 gst_v4l2_buffer_pool_release_buffer (bpool, tmp);
2013 /* Legacy M2M devices return empty buffer when drained */
2014 if (GST_V4L2_IS_M2M (obj->device_caps))
2017 #ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER
2018 if (pool->obj->mode == GST_V4L2_IO_DMABUF) {
2019 gst_buffer_unref (*buf);
2022 #endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
2023 ret = gst_v4l2_buffer_pool_copy_buffer (pool, *buf, tmp);
2025 /* an queue the buffer again after the copy */
2026 gst_v4l2_buffer_pool_release_buffer (bpool, tmp);
2027 #ifdef TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER
2029 #endif /* TIZEN_FEATURE_TBM_SUPPORT_FOR_V4L2_DECODER */
2031 if (ret != GST_FLOW_OK)
2036 case GST_V4L2_IO_USERPTR:
2038 struct UserPtrData *data;
2041 /* Replace our buffer with downstream allocated buffer */
2042 data = gst_mini_object_steal_qdata (GST_MINI_OBJECT (*buf),
2043 GST_V4L2_IMPORT_QUARK);
2044 tmp = gst_buffer_ref (data->buffer);
2045 _unmap_userptr_frame (data);
2047 /* Now tmp is writable, copy the flags and timestamp */
2048 gst_buffer_copy_into (tmp, *buf,
2049 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
2051 gst_buffer_replace (buf, tmp);
2052 gst_buffer_unref (tmp);
2056 case GST_V4L2_IO_DMABUF_IMPORT:
2060 /* Replace our buffer with downstream allocated buffer */
2061 tmp = gst_mini_object_steal_qdata (GST_MINI_OBJECT (*buf),
2062 GST_V4L2_IMPORT_QUARK);
2064 gst_buffer_copy_into (tmp, *buf,
2065 GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
2067 gst_buffer_replace (buf, tmp);
2068 gst_buffer_unref (tmp);
2073 g_assert_not_reached ();
2078 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
2079 case V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE:
2081 switch (obj->mode) {
2082 case GST_V4L2_IO_RW:
2083 /* FIXME, do write() */
2084 GST_WARNING_OBJECT (pool, "implement write()");
2087 case GST_V4L2_IO_USERPTR:
2088 case GST_V4L2_IO_DMABUF_IMPORT:
2089 case GST_V4L2_IO_DMABUF:
2090 case GST_V4L2_IO_MMAP:
2092 GstBuffer *to_queue = NULL;
2094 GstV4l2MemoryGroup *group;
2097 if ((*buf)->pool != bpool)
2100 if (!gst_v4l2_is_buffer_valid (*buf, &group))
2103 index = group->buffer.index;
2105 GST_LOG_OBJECT (pool, "processing buffer %i from our pool", index);
2107 if (pool->buffers[index] != NULL) {
2108 GST_LOG_OBJECT (pool, "buffer %i already queued, copying", index);
2112 /* we can queue directly */
2113 to_queue = gst_buffer_ref (*buf);
2116 if (to_queue == NULL) {
2117 GstBufferPoolAcquireParams params = { 0 };
2119 GST_LOG_OBJECT (pool, "alloc buffer from our pool");
2121 /* this can return EOS if all buffers are outstanding which would
2122 * be strange because we would expect the upstream element to have
2123 * allocated them and returned to us.. */
2124 params.flags = GST_BUFFER_POOL_ACQUIRE_FLAG_DONTWAIT;
2125 ret = gst_buffer_pool_acquire_buffer (bpool, &to_queue, ¶ms);
2126 if (ret != GST_FLOW_OK)
2127 goto acquire_failed;
2129 ret = gst_v4l2_buffer_pool_prepare_buffer (pool, to_queue, *buf);
2130 if (ret != GST_FLOW_OK) {
2131 gst_buffer_unref (to_queue);
2132 goto prepare_failed;
2135 /* retreive the group */
2136 gst_v4l2_is_buffer_valid (to_queue, &group);
2139 if ((ret = gst_v4l2_buffer_pool_qbuf (pool, to_queue, group))
2143 /* if we are not streaming yet (this is the first buffer, start
2145 if (!gst_v4l2_buffer_pool_streamon (pool)) {
2146 /* don't check return value because qbuf would have failed */
2147 gst_v4l2_is_buffer_valid (to_queue, &group);
2149 /* qbuf has stored to_queue buffer but we are not in
2150 * streaming state, so the flush logic won't be performed.
2151 * To avoid leaks, flush the allocator and restore the queued
2152 * buffer as non-queued */
2153 gst_v4l2_allocator_flush (pool->vallocator);
2155 pool->buffers[group->buffer.index] = NULL;
2157 gst_mini_object_set_qdata (GST_MINI_OBJECT (to_queue),
2158 GST_V4L2_IMPORT_QUARK, NULL, NULL);
2159 gst_buffer_unref (to_queue);
2160 g_atomic_int_add (&pool->num_queued, -1);
2164 /* Remove our ref, we will still hold this buffer in acquire as needed,
2165 * otherwise the pool will think it is outstanding and will refuse to stop. */
2166 gst_buffer_unref (to_queue);
2168 /* release as many buffer as possible */
2169 while (gst_v4l2_buffer_pool_dqbuf (pool, &buffer, FALSE) ==
2171 if (buffer->pool == NULL)
2172 gst_v4l2_buffer_pool_release_buffer (bpool, buffer);
2175 if (g_atomic_int_get (&pool->num_queued) >= pool->min_latency) {
2176 /* all buffers are queued, try to dequeue one and release it back
2177 * into the pool so that _acquire can get to it again. */
2178 ret = gst_v4l2_buffer_pool_dqbuf (pool, &buffer, TRUE);
2179 if (ret == GST_FLOW_OK && buffer->pool == NULL)
2180 /* release the rendered buffer back into the pool. This wakes up any
2181 * thread waiting for a buffer in _acquire(). */
2182 gst_v4l2_buffer_pool_release_buffer (bpool, buffer);
2187 g_assert_not_reached ();
2192 g_assert_not_reached ();
2201 GST_ERROR_OBJECT (pool, "failed to copy buffer");
2206 GST_WARNING_OBJECT (pool,
2207 "Dropping truncated buffer, this is likely a driver bug.");
2208 gst_buffer_unref (*buf);
2210 return GST_V4L2_FLOW_CORRUPTED_BUFFER;
2214 GST_DEBUG_OBJECT (pool, "end of stream reached");
2215 gst_buffer_unref (*buf);
2217 return GST_V4L2_FLOW_LAST_BUFFER;
2221 if (ret == GST_FLOW_FLUSHING)
2222 GST_DEBUG_OBJECT (pool, "flushing");
2224 GST_WARNING_OBJECT (pool, "failed to acquire a buffer: %s",
2225 gst_flow_get_name (ret));
2230 GST_ERROR_OBJECT (pool, "failed to prepare data");
2235 GST_ERROR_OBJECT (pool, "failed to queue buffer");
2240 GST_ERROR_OBJECT (pool, "failed to start streaming");
2241 return GST_FLOW_ERROR;
2246 gst_v4l2_buffer_pool_set_other_pool (GstV4l2BufferPool * pool,
2247 GstBufferPool * other_pool)
2249 g_return_if_fail (!gst_buffer_pool_is_active (GST_BUFFER_POOL (pool)));
2251 if (pool->other_pool)
2252 gst_object_unref (pool->other_pool);
2253 pool->other_pool = gst_object_ref (other_pool);
2257 gst_v4l2_buffer_pool_copy_at_threshold (GstV4l2BufferPool * pool, gboolean copy)
2259 GST_OBJECT_LOCK (pool);
2260 pool->enable_copy_threshold = copy;
2261 GST_OBJECT_UNLOCK (pool);
2265 gst_v4l2_buffer_pool_flush (GstBufferPool * bpool)
2267 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool);
2268 gboolean ret = TRUE;
2270 gst_v4l2_buffer_pool_streamoff (pool);
2272 if (!V4L2_TYPE_IS_OUTPUT (pool->obj->type))
2273 ret = gst_v4l2_buffer_pool_streamon (pool);