• Home
  • Raw
  • Download

Lines Matching full:pool

7  * gstv4l2bufferpool.c V4L2 buffer pool class
125 gst_v4l2_buffer_pool_copy_buffer (GstV4l2BufferPool * pool, GstBuffer * dest, in gst_v4l2_buffer_pool_copy_buffer() argument
128 const GstVideoFormatInfo *finfo = pool->caps_info.finfo; in gst_v4l2_buffer_pool_copy_buffer()
130 GST_LOG_OBJECT (pool, "copying buffer"); in gst_v4l2_buffer_pool_copy_buffer()
136 GST_DEBUG_OBJECT (pool, "copy video frame"); in gst_v4l2_buffer_pool_copy_buffer()
139 if (!gst_video_frame_map (&src_frame, &pool->caps_info, src, GST_MAP_READ)) in gst_v4l2_buffer_pool_copy_buffer()
142 if (!gst_video_frame_map (&dest_frame, &pool->caps_info, dest, in gst_v4l2_buffer_pool_copy_buffer()
155 GST_DEBUG_OBJECT (pool, "copy raw bytes"); in gst_v4l2_buffer_pool_copy_buffer()
169 GST_CAT_LOG_OBJECT (CAT_PERFORMANCE, pool, "slow copy into buffer %p", dest); in gst_v4l2_buffer_pool_copy_buffer()
175 GST_ERROR_OBJECT (pool, "could not map buffer"); in gst_v4l2_buffer_pool_copy_buffer()
214 gst_v4l2_buffer_pool_import_userptr (GstV4l2BufferPool * pool, in gst_v4l2_buffer_pool_import_userptr() argument
220 const GstVideoFormatInfo *finfo = pool->caps_info.finfo; in gst_v4l2_buffer_pool_import_userptr()
223 GST_LOG_OBJECT (pool, "importing userptr"); in gst_v4l2_buffer_pool_import_userptr()
229 if (V4L2_TYPE_IS_OUTPUT (pool->obj->type)) in gst_v4l2_buffer_pool_import_userptr()
243 if (!gst_video_frame_map (&data->frame, &pool->caps_info, src, flags)) in gst_v4l2_buffer_pool_import_userptr()
269 if (!V4L2_TYPE_IS_MULTIPLANAR (pool->obj->type)) { in gst_v4l2_buffer_pool_import_userptr()
271 const struct v4l2_pix_format *pix_fmt = &pool->obj->format.fmt.pix; in gst_v4l2_buffer_pool_import_userptr()
284 if (!gst_v4l2_allocator_import_userptr (pool->vallocator, group, in gst_v4l2_buffer_pool_import_userptr()
299 if (!gst_v4l2_allocator_import_userptr (pool->vallocator, group, in gst_v4l2_buffer_pool_import_userptr()
316 GST_ERROR_OBJECT (pool, "destination buffer invalid or not from our pool"); in gst_v4l2_buffer_pool_import_userptr()
321 GST_ERROR_OBJECT (pool, "could not map buffer"); in gst_v4l2_buffer_pool_import_userptr()
327 GST_ERROR_OBJECT (pool, "memory is not contiguous or plane size mismatch"); in gst_v4l2_buffer_pool_import_userptr()
333 GST_ERROR_OBJECT (pool, "failed to import data"); in gst_v4l2_buffer_pool_import_userptr()
340 gst_v4l2_buffer_pool_import_dmabuf (GstV4l2BufferPool * pool, in gst_v4l2_buffer_pool_import_dmabuf() argument
348 GST_LOG_OBJECT (pool, "importing dmabuf"); in gst_v4l2_buffer_pool_import_dmabuf()
359 if (!gst_v4l2_allocator_import_dmabuf (pool->vallocator, group, n_mem, in gst_v4l2_buffer_pool_import_dmabuf()
373 GST_ERROR_OBJECT (pool, "destination buffer invalid or not from our pool"); in gst_v4l2_buffer_pool_import_dmabuf()
378 GST_ERROR_OBJECT (pool, "could not map buffer"); in gst_v4l2_buffer_pool_import_dmabuf()
383 GST_ERROR_OBJECT (pool, "failed to import dmabuf"); in gst_v4l2_buffer_pool_import_dmabuf()
389 gst_v4l2_buffer_pool_prepare_buffer (GstV4l2BufferPool * pool, in gst_v4l2_buffer_pool_prepare_buffer() argument
396 if (pool->other_pool == NULL) { in gst_v4l2_buffer_pool_prepare_buffer()
397 GST_ERROR_OBJECT (pool, "can't prepare buffer, source buffer missing"); in gst_v4l2_buffer_pool_prepare_buffer()
401 ret = gst_buffer_pool_acquire_buffer (pool->other_pool, &src, NULL); in gst_v4l2_buffer_pool_prepare_buffer()
403 GST_ERROR_OBJECT (pool, "failed to acquire buffer from downstream pool"); in gst_v4l2_buffer_pool_prepare_buffer()
410 switch (pool->obj->mode) { in gst_v4l2_buffer_pool_prepare_buffer()
413 ret = gst_v4l2_buffer_pool_copy_buffer (pool, dest, src); in gst_v4l2_buffer_pool_prepare_buffer()
416 ret = gst_v4l2_buffer_pool_import_userptr (pool, dest, src); in gst_v4l2_buffer_pool_prepare_buffer()
419 ret = gst_v4l2_buffer_pool_import_dmabuf (pool, dest, src); in gst_v4l2_buffer_pool_prepare_buffer()
436 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool); in gst_v4l2_buffer_pool_alloc_buffer() local
442 obj = pool->obj; in gst_v4l2_buffer_pool_alloc_buffer()
448 gst_buffer_new_allocate (pool->allocator, pool->size, &pool->params); in gst_v4l2_buffer_pool_alloc_buffer()
451 group = gst_v4l2_allocator_alloc_mmap (pool->vallocator); in gst_v4l2_buffer_pool_alloc_buffer()
454 group = gst_v4l2_allocator_alloc_dmabuf (pool->vallocator, in gst_v4l2_buffer_pool_alloc_buffer()
455 pool->allocator); in gst_v4l2_buffer_pool_alloc_buffer()
458 group = gst_v4l2_allocator_alloc_userptr (pool->vallocator); in gst_v4l2_buffer_pool_alloc_buffer()
461 group = gst_v4l2_allocator_alloc_dmabufin (pool->vallocator); in gst_v4l2_buffer_pool_alloc_buffer()
476 if (g_atomic_int_get (&pool->buffer_state[group->buffer.index])) { in gst_v4l2_buffer_pool_alloc_buffer()
477 GST_WARNING_OBJECT (pool, "newly allocated buffer %u is not free", in gst_v4l2_buffer_pool_alloc_buffer()
485 if (pool->add_videometa) { in gst_v4l2_buffer_pool_alloc_buffer()
502 GST_ERROR_OBJECT (pool, "failed to allocate buffer"); in gst_v4l2_buffer_pool_alloc_buffer()
510 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool); in gst_v4l2_buffer_pool_set_config() local
511 GstV4l2Object *obj = pool->obj; in gst_v4l2_buffer_pool_set_config()
520 pool->add_videometa = in gst_v4l2_buffer_pool_set_config()
532 GST_DEBUG_OBJECT (pool, "config %" GST_PTR_FORMAT, config); in gst_v4l2_buffer_pool_set_config()
534 if (pool->allocator) in gst_v4l2_buffer_pool_set_config()
535 gst_object_unref (pool->allocator); in gst_v4l2_buffer_pool_set_config()
536 pool->allocator = NULL; in gst_v4l2_buffer_pool_set_config()
540 pool->allocator = gst_dmabuf_allocator_new (); in gst_v4l2_buffer_pool_set_config()
541 can_allocate = GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, MMAP); in gst_v4l2_buffer_pool_set_config()
544 can_allocate = GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, MMAP); in gst_v4l2_buffer_pool_set_config()
548 GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, USERPTR); in gst_v4l2_buffer_pool_set_config()
551 can_allocate = GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, DMABUF); in gst_v4l2_buffer_pool_set_config()
555 pool->allocator = g_object_ref (allocator); in gst_v4l2_buffer_pool_set_config()
556 pool->params = params; in gst_v4l2_buffer_pool_set_config()
568 GST_WARNING_OBJECT (pool, in gst_v4l2_buffer_pool_set_config()
571 GST_OBJECT_FLAG_UNSET (pool->vallocator, in gst_v4l2_buffer_pool_set_config()
580 GST_INFO_OBJECT (pool, "increasing minimum buffers to %u", min_buffers); in gst_v4l2_buffer_pool_set_config()
587 GST_INFO_OBJECT (pool, "increasing minimum buffers to %u", min_buffers); in gst_v4l2_buffer_pool_set_config()
593 GST_INFO_OBJECT (pool, "reducing maximum buffers to %u", max_buffers); in gst_v4l2_buffer_pool_set_config()
599 GST_INFO_OBJECT (pool, "reducing minimum buffers to %u", min_buffers); in gst_v4l2_buffer_pool_set_config()
604 GST_INFO_OBJECT (pool, "can't allocate, setting maximum to minimum"); in gst_v4l2_buffer_pool_set_config()
608 if (!pool->add_videometa && obj->need_video_meta) { in gst_v4l2_buffer_pool_set_config()
609 GST_INFO_OBJECT (pool, "adding needed video meta"); in gst_v4l2_buffer_pool_set_config()
620 gst_video_info_from_caps (&pool->caps_info, caps); in gst_v4l2_buffer_pool_set_config()
631 GST_ERROR_OBJECT (pool, "invalid config %" GST_PTR_FORMAT, config); in gst_v4l2_buffer_pool_set_config()
637 gst_v4l2_buffer_pool_resurrect_buffer (GstV4l2BufferPool * pool) in gst_v4l2_buffer_pool_resurrect_buffer() argument
643 GST_DEBUG_OBJECT (pool, "A buffer was lost, reallocating it"); in gst_v4l2_buffer_pool_resurrect_buffer()
646 g_signal_handler_block (pool->vallocator, pool->group_released_handler); in gst_v4l2_buffer_pool_resurrect_buffer()
652 gst_buffer_pool_acquire_buffer (GST_BUFFER_POOL (pool), &buffer, &params); in gst_v4l2_buffer_pool_resurrect_buffer()
657 g_signal_handler_unblock (pool->vallocator, pool->group_released_handler); in gst_v4l2_buffer_pool_resurrect_buffer()
663 gst_v4l2_buffer_pool_streamon (GstV4l2BufferPool * pool) in gst_v4l2_buffer_pool_streamon() argument
665 GstV4l2Object *obj = pool->obj; in gst_v4l2_buffer_pool_streamon()
667 if (pool->streaming) in gst_v4l2_buffer_pool_streamon()
675 if (!V4L2_TYPE_IS_OUTPUT (pool->obj->type)) { in gst_v4l2_buffer_pool_streamon()
679 num_queued = g_atomic_int_get (&pool->num_queued); in gst_v4l2_buffer_pool_streamon()
680 if (num_queued < pool->num_allocated) in gst_v4l2_buffer_pool_streamon()
681 n = pool->num_allocated - num_queued; in gst_v4l2_buffer_pool_streamon()
688 gst_v4l2_buffer_pool_resurrect_buffer (pool); in gst_v4l2_buffer_pool_streamon()
691 if (obj->ioctl (pool->video_fd, VIDIOC_STREAMON, &obj->type) < 0) in gst_v4l2_buffer_pool_streamon()
694 pool->streaming = TRUE; in gst_v4l2_buffer_pool_streamon()
696 GST_DEBUG_OBJECT (pool, "Started streaming"); in gst_v4l2_buffer_pool_streamon()
706 GST_ERROR_OBJECT (pool, "error with STREAMON %d (%s)", errno, in gst_v4l2_buffer_pool_streamon()
714 gst_v4l2_buffer_pool_streamoff (GstV4l2BufferPool * pool) in gst_v4l2_buffer_pool_streamoff() argument
717 GstV4l2Object *obj = pool->obj; in gst_v4l2_buffer_pool_streamoff()
720 if (!pool->streaming) in gst_v4l2_buffer_pool_streamoff()
729 if (obj->ioctl (pool->video_fd, VIDIOC_STREAMOFF, &obj->type) < 0) in gst_v4l2_buffer_pool_streamoff()
730 GST_WARNING_OBJECT (pool, "STREAMOFF failed with errno %d (%s)", in gst_v4l2_buffer_pool_streamoff()
733 pool->streaming = FALSE; in gst_v4l2_buffer_pool_streamoff()
735 GST_DEBUG_OBJECT (pool, "Stopped streaming"); in gst_v4l2_buffer_pool_streamoff()
737 if (pool->vallocator) in gst_v4l2_buffer_pool_streamoff()
738 gst_v4l2_allocator_flush (pool->vallocator); in gst_v4l2_buffer_pool_streamoff()
746 g_atomic_int_and (&pool->buffer_state[i], ~BUFFER_STATE_QUEUED); in gst_v4l2_buffer_pool_streamoff()
747 if ((old_buffer_state & BUFFER_STATE_QUEUED) && pool->buffers[i]) { in gst_v4l2_buffer_pool_streamoff()
748 GstBuffer *buffer = pool->buffers[i]; in gst_v4l2_buffer_pool_streamoff()
749 GstBufferPool *bpool = GST_BUFFER_POOL (pool); in gst_v4l2_buffer_pool_streamoff()
751 pool->buffers[i] = NULL; in gst_v4l2_buffer_pool_streamoff()
754 if (V4L2_TYPE_IS_OUTPUT (pool->obj->type)) in gst_v4l2_buffer_pool_streamoff()
761 g_atomic_int_add (&pool->num_queued, -1); in gst_v4l2_buffer_pool_streamoff()
769 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool); in gst_v4l2_buffer_pool_start() local
771 GstV4l2Object *obj = pool->obj; in gst_v4l2_buffer_pool_start()
778 GST_DEBUG_OBJECT (pool, "activating pool"); in gst_v4l2_buffer_pool_start()
780 if (pool->other_pool) { in gst_v4l2_buffer_pool_start()
783 if (!gst_buffer_pool_set_active (pool->other_pool, TRUE)) in gst_v4l2_buffer_pool_start()
786 if (gst_buffer_pool_acquire_buffer (pool->other_pool, &buffer, NULL) != in gst_v4l2_buffer_pool_start()
822 can_allocate = GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, MMAP); in gst_v4l2_buffer_pool_start()
825 GST_DEBUG_OBJECT (pool, "requesting %d MMAP buffers", min_buffers); in gst_v4l2_buffer_pool_start()
827 count = gst_v4l2_allocator_start (pool->vallocator, min_buffers, in gst_v4l2_buffer_pool_start()
829 pool->num_allocated = count; in gst_v4l2_buffer_pool_start()
836 /* V4L2 buffer pool are often very limited in the amount of buffers it in gst_v4l2_buffer_pool_start()
841 if (count != min_buffers || pool->enable_copy_threshold) { in gst_v4l2_buffer_pool_start()
842 GST_WARNING_OBJECT (pool, in gst_v4l2_buffer_pool_start()
855 GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, USERPTR); in gst_v4l2_buffer_pool_start()
857 GST_DEBUG_OBJECT (pool, "requesting %d USERPTR buffers", min_buffers); in gst_v4l2_buffer_pool_start()
859 count = gst_v4l2_allocator_start (pool->vallocator, min_buffers, in gst_v4l2_buffer_pool_start()
861 pool->num_allocated = count; in gst_v4l2_buffer_pool_start()
876 can_allocate = GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, DMABUF); in gst_v4l2_buffer_pool_start()
878 GST_DEBUG_OBJECT (pool, "requesting %d DMABUF buffers", min_buffers); in gst_v4l2_buffer_pool_start()
880 count = gst_v4l2_allocator_start (pool->vallocator, min_buffers, in gst_v4l2_buffer_pool_start()
882 pool->num_allocated = count; in gst_v4l2_buffer_pool_start()
905 pool->size = size; in gst_v4l2_buffer_pool_start()
906 pool->copy_threshold = copy_threshold; in gst_v4l2_buffer_pool_start()
907 pool->max_latency = max_latency; in gst_v4l2_buffer_pool_start()
908 pool->min_latency = min_latency; in gst_v4l2_buffer_pool_start()
909 pool->num_queued = 0; in gst_v4l2_buffer_pool_start()
924 if (g_atomic_int_get (&pool->num_queued) < pool->num_allocated) in gst_v4l2_buffer_pool_start()
927 pool->group_released_handler = in gst_v4l2_buffer_pool_start()
928 g_signal_connect_swapped (pool->vallocator, "group-released", in gst_v4l2_buffer_pool_start()
929 G_CALLBACK (gst_v4l2_buffer_pool_resurrect_buffer), pool); in gst_v4l2_buffer_pool_start()
930 ret = gst_v4l2_buffer_pool_streamon (pool); in gst_v4l2_buffer_pool_start()
938 GST_ERROR_OBJECT (pool, "invalid config %" GST_PTR_FORMAT, config); in gst_v4l2_buffer_pool_start()
944 GST_ERROR_OBJECT (pool, in gst_v4l2_buffer_pool_start()
952 GST_ERROR_OBJECT (pool, "allocate failed"); in gst_v4l2_buffer_pool_start()
957 GST_ERROR_OBJECT (pool, "failed to activate the other pool %" in gst_v4l2_buffer_pool_start()
958 GST_PTR_FORMAT, pool->other_pool); in gst_v4l2_buffer_pool_start()
963 GST_ERROR_OBJECT (pool, "failed to queue buffers into the capture queue"); in gst_v4l2_buffer_pool_start()
968 GST_ERROR_OBJECT (pool, "cannot import buffers from downstream pool"); in gst_v4l2_buffer_pool_start()
974 gst_v4l2_buffer_pool_vallocator_stop (GstV4l2BufferPool * pool) in gst_v4l2_buffer_pool_vallocator_stop() argument
978 if (!pool->vallocator) in gst_v4l2_buffer_pool_vallocator_stop()
981 vret = gst_v4l2_allocator_stop (pool->vallocator); in gst_v4l2_buffer_pool_vallocator_stop()
984 GST_WARNING_OBJECT (pool, "some buffers are still outstanding"); in gst_v4l2_buffer_pool_vallocator_stop()
992 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool); in gst_v4l2_buffer_pool_stop() local
995 GST_DEBUG_OBJECT (pool, "stopping pool"); in gst_v4l2_buffer_pool_stop()
997 if (pool->group_released_handler > 0) { in gst_v4l2_buffer_pool_stop()
998 g_signal_handler_disconnect (pool->vallocator, in gst_v4l2_buffer_pool_stop()
999 pool->group_released_handler); in gst_v4l2_buffer_pool_stop()
1000 pool->group_released_handler = 0; in gst_v4l2_buffer_pool_stop()
1003 if (pool->other_pool) { in gst_v4l2_buffer_pool_stop()
1004 gst_buffer_pool_set_active (pool->other_pool, FALSE); in gst_v4l2_buffer_pool_stop()
1005 gst_object_unref (pool->other_pool); in gst_v4l2_buffer_pool_stop()
1006 pool->other_pool = NULL; in gst_v4l2_buffer_pool_stop()
1009 if (!pool->orphaned) in gst_v4l2_buffer_pool_stop()
1010 gst_v4l2_buffer_pool_streamoff (pool); in gst_v4l2_buffer_pool_stop()
1015 ret = gst_v4l2_buffer_pool_vallocator_stop (pool); in gst_v4l2_buffer_pool_stop()
1023 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (*bpool); in gst_v4l2_buffer_pool_orphan() local
1026 g_return_val_if_fail (pool->orphaned == FALSE, FALSE); in gst_v4l2_buffer_pool_orphan()
1028 if (!GST_V4L2_ALLOCATOR_CAN_ORPHAN_BUFS (pool->vallocator)) in gst_v4l2_buffer_pool_orphan()
1034 GST_DEBUG_OBJECT (pool, "orphaning pool"); in gst_v4l2_buffer_pool_orphan()
1038 * workaround of not being able to use the pool hidden activation lock. */ in gst_v4l2_buffer_pool_orphan()
1039 GST_OBJECT_LOCK (pool); in gst_v4l2_buffer_pool_orphan()
1041 gst_v4l2_buffer_pool_streamoff (pool); in gst_v4l2_buffer_pool_orphan()
1042 ret = gst_v4l2_allocator_orphan (pool->vallocator); in gst_v4l2_buffer_pool_orphan()
1044 pool->orphaned = TRUE; in gst_v4l2_buffer_pool_orphan()
1046 GST_OBJECT_UNLOCK (pool); in gst_v4l2_buffer_pool_orphan()
1059 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool); in gst_v4l2_buffer_pool_flush_start() local
1061 GST_DEBUG_OBJECT (pool, "start flushing"); in gst_v4l2_buffer_pool_flush_start()
1063 gst_poll_set_flushing (pool->poll, TRUE); in gst_v4l2_buffer_pool_flush_start()
1065 GST_OBJECT_LOCK (pool); in gst_v4l2_buffer_pool_flush_start()
1066 pool->empty = FALSE; in gst_v4l2_buffer_pool_flush_start()
1067 g_cond_broadcast (&pool->empty_cond); in gst_v4l2_buffer_pool_flush_start()
1068 GST_OBJECT_UNLOCK (pool); in gst_v4l2_buffer_pool_flush_start()
1070 if (pool->other_pool && gst_buffer_pool_is_active (pool->other_pool)) in gst_v4l2_buffer_pool_flush_start()
1071 gst_buffer_pool_set_flushing (pool->other_pool, TRUE); in gst_v4l2_buffer_pool_flush_start()
1077 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool); in gst_v4l2_buffer_pool_flush_stop() local
1079 GST_DEBUG_OBJECT (pool, "stop flushing"); in gst_v4l2_buffer_pool_flush_stop()
1081 if (pool->other_pool && gst_buffer_pool_is_active (pool->other_pool)) in gst_v4l2_buffer_pool_flush_stop()
1082 gst_buffer_pool_set_flushing (pool->other_pool, FALSE); in gst_v4l2_buffer_pool_flush_stop()
1084 gst_poll_set_flushing (pool->poll, FALSE); in gst_v4l2_buffer_pool_flush_stop()
1088 gst_v4l2_buffer_pool_poll (GstV4l2BufferPool * pool, gboolean wait) in gst_v4l2_buffer_pool_poll() argument
1100 if (pool->obj->mode != GST_V4L2_IO_RW) { in gst_v4l2_buffer_pool_poll()
1101 GST_OBJECT_LOCK (pool); in gst_v4l2_buffer_pool_poll()
1103 if (!wait && pool->empty) { in gst_v4l2_buffer_pool_poll()
1104 GST_OBJECT_UNLOCK (pool); in gst_v4l2_buffer_pool_poll()
1108 while (pool->empty) in gst_v4l2_buffer_pool_poll()
1109 g_cond_wait (&pool->empty_cond, GST_OBJECT_GET_LOCK (pool)); in gst_v4l2_buffer_pool_poll()
1111 GST_OBJECT_UNLOCK (pool); in gst_v4l2_buffer_pool_poll()
1114 if (!pool->can_poll_device) { in gst_v4l2_buffer_pool_poll()
1121 GST_LOG_OBJECT (pool, "polling device"); in gst_v4l2_buffer_pool_poll()
1124 ret = gst_poll_wait (pool->poll, timeout); in gst_v4l2_buffer_pool_poll()
1133 GST_WARNING_OBJECT (pool, in gst_v4l2_buffer_pool_poll()
1136 pool->can_poll_device = FALSE; in gst_v4l2_buffer_pool_poll()
1143 if (gst_poll_fd_has_error (pool->poll, &pool->pollfd)) in gst_v4l2_buffer_pool_poll()
1147 if (gst_poll_fd_has_pri (pool->poll, &pool->pollfd)) { in gst_v4l2_buffer_pool_poll()
1150 if (!gst_v4l2_dequeue_event (pool->obj, &event)) in gst_v4l2_buffer_pool_poll()
1154 GST_INFO_OBJECT (pool, "Received unhandled event, ignoring."); in gst_v4l2_buffer_pool_poll()
1159 GST_DEBUG_OBJECT (pool, in gst_v4l2_buffer_pool_poll()
1176 GST_DEBUG_OBJECT (pool, "stop called"); in gst_v4l2_buffer_pool_poll()
1181 GST_ELEMENT_ERROR (pool->obj->element, RESOURCE, READ, (NULL), in gst_v4l2_buffer_pool_poll()
1191 GST_ELEMENT_ERROR (pool->obj->element, RESOURCE, READ, (NULL), in gst_v4l2_buffer_pool_poll()
1198 gst_v4l2_buffer_pool_qbuf (GstV4l2BufferPool * pool, GstBuffer * buf, in gst_v4l2_buffer_pool_qbuf() argument
1201 const GstV4l2Object *obj = pool->obj; in gst_v4l2_buffer_pool_qbuf()
1208 g_atomic_int_or (&pool->buffer_state[index], BUFFER_STATE_QUEUED); in gst_v4l2_buffer_pool_qbuf()
1212 GST_LOG_OBJECT (pool, "queuing buffer %i, previous-state = %i", index, in gst_v4l2_buffer_pool_qbuf()
1240 GST_OBJECT_LOCK (pool); in gst_v4l2_buffer_pool_qbuf()
1242 /* If the pool was orphaned, don't try to queue any returned buffers. in gst_v4l2_buffer_pool_qbuf()
1245 if (pool->orphaned) in gst_v4l2_buffer_pool_qbuf()
1248 g_atomic_int_inc (&pool->num_queued); in gst_v4l2_buffer_pool_qbuf()
1249 pool->buffers[index] = buf; in gst_v4l2_buffer_pool_qbuf()
1251 if (!gst_v4l2_allocator_qbuf (pool->vallocator, group)) in gst_v4l2_buffer_pool_qbuf()
1254 pool->empty = FALSE; in gst_v4l2_buffer_pool_qbuf()
1255 g_cond_signal (&pool->empty_cond); in gst_v4l2_buffer_pool_qbuf()
1256 GST_OBJECT_UNLOCK (pool); in gst_v4l2_buffer_pool_qbuf()
1262 GST_ERROR_OBJECT (pool, "the buffer %i was already queued", index); in gst_v4l2_buffer_pool_qbuf()
1267 GST_DEBUG_OBJECT (pool, "pool was orphaned, not queuing back buffer."); in gst_v4l2_buffer_pool_qbuf()
1269 g_atomic_int_and (&pool->buffer_state[index], ~BUFFER_STATE_QUEUED); in gst_v4l2_buffer_pool_qbuf()
1270 GST_OBJECT_UNLOCK (pool); in gst_v4l2_buffer_pool_qbuf()
1275 GST_ERROR_OBJECT (pool, "could not queue a buffer %i", index); in gst_v4l2_buffer_pool_qbuf()
1278 g_atomic_int_add (&pool->num_queued, -1); in gst_v4l2_buffer_pool_qbuf()
1279 pool->buffers[index] = NULL; in gst_v4l2_buffer_pool_qbuf()
1280 g_atomic_int_and (&pool->buffer_state[index], ~BUFFER_STATE_QUEUED); in gst_v4l2_buffer_pool_qbuf()
1281 GST_OBJECT_UNLOCK (pool); in gst_v4l2_buffer_pool_qbuf()
1287 gst_v4l2_buffer_pool_dqbuf (GstV4l2BufferPool * pool, GstBuffer ** buffer, in gst_v4l2_buffer_pool_dqbuf() argument
1292 GstV4l2Object *obj = pool->obj; in gst_v4l2_buffer_pool_dqbuf()
1300 if ((res = gst_v4l2_buffer_pool_poll (pool, wait)) < GST_FLOW_OK) in gst_v4l2_buffer_pool_dqbuf()
1304 GST_LOG_OBJECT (pool, "nothing to dequeue"); in gst_v4l2_buffer_pool_dqbuf()
1309 GST_INFO_OBJECT (pool, "Resolution change detected."); in gst_v4l2_buffer_pool_dqbuf()
1313 GST_LOG_OBJECT (pool, "dequeueing a buffer"); in gst_v4l2_buffer_pool_dqbuf()
1315 res = gst_v4l2_allocator_dqbuf (pool->vallocator, &group); in gst_v4l2_buffer_pool_dqbuf()
1322 g_atomic_int_and (&pool->buffer_state[group->buffer.index], in gst_v4l2_buffer_pool_dqbuf()
1330 GST_WARNING_OBJECT (pool, "unexpected outstanding buffer %u", in gst_v4l2_buffer_pool_dqbuf()
1334 outbuf = pool->buffers[group->buffer.index]; in gst_v4l2_buffer_pool_dqbuf()
1338 pool->buffers[group->buffer.index] = NULL; in gst_v4l2_buffer_pool_dqbuf()
1339 if (g_atomic_int_dec_and_test (&pool->num_queued)) { in gst_v4l2_buffer_pool_dqbuf()
1340 GST_OBJECT_LOCK (pool); in gst_v4l2_buffer_pool_dqbuf()
1341 pool->empty = TRUE; in gst_v4l2_buffer_pool_dqbuf()
1342 GST_OBJECT_UNLOCK (pool); in gst_v4l2_buffer_pool_dqbuf()
1350 GST_LOG_OBJECT (pool, in gst_v4l2_buffer_pool_dqbuf()
1352 GST_TIME_FORMAT ", pool-queued=%d, buffer=%p, previous-state=%i", in gst_v4l2_buffer_pool_dqbuf()
1355 GST_TIME_ARGS (timestamp), pool->num_queued, outbuf, old_buffer_state); in gst_v4l2_buffer_pool_dqbuf()
1371 if (!pool->has_warned_on_buggy_field) { in gst_v4l2_buffer_pool_dqbuf()
1372 pool->has_warned_on_buggy_field = TRUE; in gst_v4l2_buffer_pool_dqbuf()
1373 GST_WARNING_OBJECT (pool, in gst_v4l2_buffer_pool_dqbuf()
1384 if (!pool->has_warned_on_buggy_field) { in gst_v4l2_buffer_pool_dqbuf()
1385 pool->has_warned_on_buggy_field = TRUE; in gst_v4l2_buffer_pool_dqbuf()
1386 GST_WARNING_OBJECT (pool, in gst_v4l2_buffer_pool_dqbuf()
1430 GST_FIXME_OBJECT (pool, in gst_v4l2_buffer_pool_dqbuf()
1461 GST_DEBUG_OBJECT (pool, "poll error %s", gst_flow_get_name (res)); in gst_v4l2_buffer_pool_dqbuf()
1474 GST_ERROR_OBJECT (pool, "No free buffer found in the pool at index %d.", in gst_v4l2_buffer_pool_dqbuf()
1485 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool); in gst_v4l2_buffer_pool_acquire_buffer() local
1487 GstV4l2Object *obj = pool->obj; in gst_v4l2_buffer_pool_acquire_buffer()
1489 GST_DEBUG_OBJECT (pool, "acquire"); in gst_v4l2_buffer_pool_acquire_buffer()
1504 /* take empty buffer from the pool */ in gst_v4l2_buffer_pool_acquire_buffer()
1516 ret = gst_v4l2_buffer_pool_dqbuf (pool, buffer, NULL, TRUE); in gst_v4l2_buffer_pool_acquire_buffer()
1561 GST_LOG_OBJECT (pool, "mark buffer %u outstanding", group->buffer.index); in gst_v4l2_buffer_pool_acquire_buffer()
1562 g_atomic_int_or (&pool->buffer_state[group->buffer.index], in gst_v4l2_buffer_pool_acquire_buffer()
1582 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool); in gst_v4l2_buffer_pool_complete_release_buffer() local
1584 GstV4l2Object *obj = pool->obj; in gst_v4l2_buffer_pool_complete_release_buffer()
1586 GST_DEBUG_OBJECT (pool, "complete release buffer %p (queued = %s)", buffer, in gst_v4l2_buffer_pool_complete_release_buffer()
1595 GST_WARNING_OBJECT (pool, in gst_v4l2_buffer_pool_complete_release_buffer()
1601 /* release back in the pool */ in gst_v4l2_buffer_pool_complete_release_buffer()
1614 gst_v4l2_allocator_reset_group (pool->vallocator, group); in gst_v4l2_buffer_pool_complete_release_buffer()
1616 if (pool->other_pool) in gst_v4l2_buffer_pool_complete_release_buffer()
1617 ret = gst_v4l2_buffer_pool_prepare_buffer (pool, buffer, NULL); in gst_v4l2_buffer_pool_complete_release_buffer()
1619 gst_v4l2_buffer_pool_qbuf (pool, buffer, group, in gst_v4l2_buffer_pool_complete_release_buffer()
1640 /* release back in the pool */ in gst_v4l2_buffer_pool_complete_release_buffer()
1663 GST_LOG_OBJECT (pool, "buffer %u not queued, putting on free list", in gst_v4l2_buffer_pool_complete_release_buffer()
1671 gst_v4l2_allocator_reset_group (pool->vallocator, group); in gst_v4l2_buffer_pool_complete_release_buffer()
1679 GST_LOG_OBJECT (pool, "buffer %u is queued", index); in gst_v4l2_buffer_pool_complete_release_buffer()
1699 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool); in gst_v4l2_buffer_pool_release_buffer() local
1705 g_atomic_int_and (&pool->buffer_state[group->buffer.index], in gst_v4l2_buffer_pool_release_buffer()
1708 GST_LOG_OBJECT (pool, "mark buffer %u not outstanding", in gst_v4l2_buffer_pool_release_buffer()
1718 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (object); in gst_v4l2_buffer_pool_dispose() local
1720 if (pool->vallocator) in gst_v4l2_buffer_pool_dispose()
1721 gst_object_unref (pool->vallocator); in gst_v4l2_buffer_pool_dispose()
1722 pool->vallocator = NULL; in gst_v4l2_buffer_pool_dispose()
1724 if (pool->allocator) in gst_v4l2_buffer_pool_dispose()
1725 gst_object_unref (pool->allocator); in gst_v4l2_buffer_pool_dispose()
1726 pool->allocator = NULL; in gst_v4l2_buffer_pool_dispose()
1728 if (pool->other_pool) in gst_v4l2_buffer_pool_dispose()
1729 gst_object_unref (pool->other_pool); in gst_v4l2_buffer_pool_dispose()
1730 pool->other_pool = NULL; in gst_v4l2_buffer_pool_dispose()
1738 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (object); in gst_v4l2_buffer_pool_finalize() local
1740 if (pool->video_fd >= 0) in gst_v4l2_buffer_pool_finalize()
1741 pool->obj->close (pool->video_fd); in gst_v4l2_buffer_pool_finalize()
1743 gst_poll_free (pool->poll); in gst_v4l2_buffer_pool_finalize()
1748 gst_object_unref (pool->obj->element); in gst_v4l2_buffer_pool_finalize()
1750 g_cond_clear (&pool->empty_cond); in gst_v4l2_buffer_pool_finalize()
1758 gst_v4l2_buffer_pool_init (GstV4l2BufferPool * pool) in gst_v4l2_buffer_pool_init() argument
1760 pool->poll = gst_poll_new (TRUE); in gst_v4l2_buffer_pool_init()
1761 pool->can_poll_device = TRUE; in gst_v4l2_buffer_pool_init()
1762 g_cond_init (&pool->empty_cond); in gst_v4l2_buffer_pool_init()
1763 pool->empty = TRUE; in gst_v4l2_buffer_pool_init()
1764 pool->orphaned = FALSE; in gst_v4l2_buffer_pool_init()
1766 g_atomic_int_set (&pool->buffer_state[i], BUFFER_STATE_FREE); in gst_v4l2_buffer_pool_init()
1788 "V4L2 Buffer Pool"); in gst_v4l2_buffer_pool_class_init()
1794 * @obj: the v4l2 object owning the pool
1796 * Construct a new buffer pool.
1798 * Returns: the new pool, use gst_object_unref() to free resources
1803 GstV4l2BufferPool *pool; in gst_v4l2_buffer_pool_new() local
1814 name = g_strdup_printf ("%s:pool%u:%s", in gst_v4l2_buffer_pool_new()
1819 pool = (GstV4l2BufferPool *) g_object_new (GST_TYPE_V4L2_BUFFER_POOL, in gst_v4l2_buffer_pool_new()
1821 g_object_ref_sink (pool); in gst_v4l2_buffer_pool_new()
1824 gst_poll_fd_init (&pool->pollfd); in gst_v4l2_buffer_pool_new()
1825 pool->pollfd.fd = fd; in gst_v4l2_buffer_pool_new()
1826 gst_poll_add_fd (pool->poll, &pool->pollfd); in gst_v4l2_buffer_pool_new()
1828 gst_poll_fd_ctl_write (pool->poll, &pool->pollfd, TRUE); in gst_v4l2_buffer_pool_new()
1830 gst_poll_fd_ctl_read (pool->poll, &pool->pollfd, TRUE); in gst_v4l2_buffer_pool_new()
1832 pool->video_fd = fd; in gst_v4l2_buffer_pool_new()
1833 pool->obj = obj; in gst_v4l2_buffer_pool_new()
1834 pool->can_poll_device = TRUE; in gst_v4l2_buffer_pool_new()
1836 pool->vallocator = gst_v4l2_allocator_new (GST_OBJECT (pool), obj); in gst_v4l2_buffer_pool_new()
1837 if (pool->vallocator == NULL) in gst_v4l2_buffer_pool_new()
1842 config = gst_buffer_pool_get_config (GST_BUFFER_POOL_CAST (pool)); in gst_v4l2_buffer_pool_new()
1844 /* This will simply set a default config, but will not configure the pool in gst_v4l2_buffer_pool_new()
1846 gst_buffer_pool_set_config (GST_BUFFER_POOL_CAST (pool), config); in gst_v4l2_buffer_pool_new()
1848 return GST_BUFFER_POOL (pool); in gst_v4l2_buffer_pool_new()
1858 GST_ERROR_OBJECT (pool, "Failed to create V4L2 allocator"); in gst_v4l2_buffer_pool_new()
1859 gst_object_unref (pool); in gst_v4l2_buffer_pool_new()
1865 gst_v4l2_do_read (GstV4l2BufferPool * pool, GstBuffer * buf) in gst_v4l2_do_read() argument
1868 GstV4l2Object *obj = pool->obj; in gst_v4l2_do_read()
1875 GST_LOG_OBJECT (pool, "reading %d bytes into buffer %p", toread, buf); in gst_v4l2_do_read()
1880 if ((res = gst_v4l2_buffer_pool_poll (pool, TRUE)) != GST_FLOW_OK) in gst_v4l2_do_read()
1898 GST_LOG_OBJECT (pool, "read %d bytes", amount); in gst_v4l2_do_read()
1942 gst_v4l2_buffer_pool_process (GstV4l2BufferPool * pool, GstBuffer ** buf, in gst_v4l2_buffer_pool_process() argument
1946 GstBufferPool *bpool = GST_BUFFER_POOL_CAST (pool); in gst_v4l2_buffer_pool_process()
1947 GstV4l2Object *obj = pool->obj; in gst_v4l2_buffer_pool_process()
1949 GST_DEBUG_OBJECT (pool, "process buffer %p", buf); in gst_v4l2_buffer_pool_process()
1951 if (GST_BUFFER_POOL_IS_FLUSHING (pool)) in gst_v4l2_buffer_pool_process()
1961 ret = gst_v4l2_do_read (pool, *buf); in gst_v4l2_buffer_pool_process()
1969 if ((*buf)->pool == bpool) { in gst_v4l2_buffer_pool_process()
1977 if (GST_VIDEO_INFO_FORMAT (&pool->caps_info) != in gst_v4l2_buffer_pool_process()
1978 GST_VIDEO_FORMAT_ENCODED && size < pool->size) in gst_v4l2_buffer_pool_process()
1981 num_queued = g_atomic_int_get (&pool->num_queued); in gst_v4l2_buffer_pool_process()
1982 GST_TRACE_OBJECT (pool, "Only %i buffer left in the capture queue.", in gst_v4l2_buffer_pool_process()
1987 if (GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, MMAP)) { in gst_v4l2_buffer_pool_process()
1988 ret = gst_v4l2_buffer_pool_resurrect_buffer (pool); in gst_v4l2_buffer_pool_process()
1995 if (num_queued < pool->copy_threshold) { in gst_v4l2_buffer_pool_process()
1998 if (GST_V4L2_ALLOCATOR_CAN_ALLOCATE (pool->vallocator, MMAP)) { in gst_v4l2_buffer_pool_process()
1999 ret = gst_v4l2_buffer_pool_resurrect_buffer (pool); in gst_v4l2_buffer_pool_process()
2007 GST_LOG_OBJECT (pool, "copy buffer %p->%p", *buf, copy); in gst_v4l2_buffer_pool_process()
2019 /* buffer not from our pool, grab a frame and copy it into the target */ in gst_v4l2_buffer_pool_process()
2020 if ((ret = gst_v4l2_buffer_pool_dqbuf (pool, &tmp, NULL, TRUE)) in gst_v4l2_buffer_pool_process()
2033 ret = gst_v4l2_buffer_pool_copy_buffer (pool, *buf, tmp); in gst_v4l2_buffer_pool_process()
2091 GST_WARNING_OBJECT (pool, "implement write()"); in gst_v4l2_buffer_pool_process()
2105 if ((*buf)->pool != bpool) in gst_v4l2_buffer_pool_process()
2113 GST_LOG_OBJECT (pool, "processing buffer %i from our pool", index); in gst_v4l2_buffer_pool_process()
2115 if (g_atomic_int_get (&pool->buffer_state[index]) & in gst_v4l2_buffer_pool_process()
2117 GST_LOG_OBJECT (pool, "buffer %i already queued, copying", index); in gst_v4l2_buffer_pool_process()
2128 GST_LOG_OBJECT (pool, "alloc buffer from our pool"); in gst_v4l2_buffer_pool_process()
2138 ret = gst_v4l2_buffer_pool_prepare_buffer (pool, to_queue, *buf); in gst_v4l2_buffer_pool_process()
2149 gst_v4l2_buffer_pool_qbuf (pool, to_queue, group, in gst_v4l2_buffer_pool_process()
2156 if (!gst_v4l2_buffer_pool_streamon (pool)) { in gst_v4l2_buffer_pool_process()
2164 gst_v4l2_allocator_flush (pool->vallocator); in gst_v4l2_buffer_pool_process()
2166 pool->buffers[group->buffer.index] = NULL; in gst_v4l2_buffer_pool_process()
2167 g_atomic_int_and (&pool->buffer_state[group->buffer.index], in gst_v4l2_buffer_pool_process()
2173 g_atomic_int_add (&pool->num_queued, -1); in gst_v4l2_buffer_pool_process()
2178 * otherwise the pool will think it is outstanding and will refuse to stop. */ in gst_v4l2_buffer_pool_process()
2182 while (gst_v4l2_buffer_pool_dqbuf (pool, &buffer, &outstanding, in gst_v4l2_buffer_pool_process()
2189 if (g_atomic_int_get (&pool->num_queued) >= pool->min_latency) { in gst_v4l2_buffer_pool_process()
2191 * into the pool so that _acquire can get to it again. */ in gst_v4l2_buffer_pool_process()
2193 gst_v4l2_buffer_pool_dqbuf (pool, &buffer, &outstanding, TRUE); in gst_v4l2_buffer_pool_process()
2195 /* release the rendered buffer back into the pool. This wakes up any in gst_v4l2_buffer_pool_process()
2217 GST_ERROR_OBJECT (pool, "failed to copy buffer"); in gst_v4l2_buffer_pool_process()
2222 GST_WARNING_OBJECT (pool, in gst_v4l2_buffer_pool_process()
2230 GST_DEBUG_OBJECT (pool, "end of stream reached"); in gst_v4l2_buffer_pool_process()
2238 GST_DEBUG_OBJECT (pool, "flushing"); in gst_v4l2_buffer_pool_process()
2240 GST_WARNING_OBJECT (pool, "failed to acquire a buffer: %s", in gst_v4l2_buffer_pool_process()
2246 GST_ERROR_OBJECT (pool, "failed to prepare data"); in gst_v4l2_buffer_pool_process()
2251 GST_ERROR_OBJECT (pool, "failed to queue buffer"); in gst_v4l2_buffer_pool_process()
2256 GST_ERROR_OBJECT (pool, "failed to start streaming"); in gst_v4l2_buffer_pool_process()
2262 gst_v4l2_buffer_pool_set_other_pool (GstV4l2BufferPool * pool, in gst_v4l2_buffer_pool_set_other_pool() argument
2265 g_return_if_fail (!gst_buffer_pool_is_active (GST_BUFFER_POOL (pool))); in gst_v4l2_buffer_pool_set_other_pool()
2267 if (pool->other_pool) in gst_v4l2_buffer_pool_set_other_pool()
2268 gst_object_unref (pool->other_pool); in gst_v4l2_buffer_pool_set_other_pool()
2269 pool->other_pool = gst_object_ref (other_pool); in gst_v4l2_buffer_pool_set_other_pool()
2273 gst_v4l2_buffer_pool_copy_at_threshold (GstV4l2BufferPool * pool, gboolean copy) in gst_v4l2_buffer_pool_copy_at_threshold() argument
2275 GST_OBJECT_LOCK (pool); in gst_v4l2_buffer_pool_copy_at_threshold()
2276 pool->enable_copy_threshold = copy; in gst_v4l2_buffer_pool_copy_at_threshold()
2277 GST_OBJECT_UNLOCK (pool); in gst_v4l2_buffer_pool_copy_at_threshold()
2283 GstV4l2BufferPool *pool = GST_V4L2_BUFFER_POOL (bpool); in gst_v4l2_buffer_pool_flush() local
2286 gst_v4l2_buffer_pool_streamoff (pool); in gst_v4l2_buffer_pool_flush()
2288 if (!V4L2_TYPE_IS_OUTPUT (pool->obj->type)) in gst_v4l2_buffer_pool_flush()
2289 ret = gst_v4l2_buffer_pool_streamon (pool); in gst_v4l2_buffer_pool_flush()
2296 * @pool: a #GstBufferPool
2298 * When this is called, the pool will subscribe to the
2304 gst_v4l2_buffer_pool_enable_resolution_change (GstV4l2BufferPool * pool) in gst_v4l2_buffer_pool_enable_resolution_change() argument
2308 g_return_if_fail (!gst_buffer_pool_is_active (GST_BUFFER_POOL (pool))); in gst_v4l2_buffer_pool_enable_resolution_change()
2311 gst_v4l2_get_input (pool->obj, &input_id); in gst_v4l2_buffer_pool_enable_resolution_change()
2313 if (gst_v4l2_subscribe_event (pool->obj, V4L2_EVENT_SOURCE_CHANGE, input_id)) in gst_v4l2_buffer_pool_enable_resolution_change()
2314 gst_poll_fd_ctl_pri (pool->poll, &pool->pollfd, TRUE); in gst_v4l2_buffer_pool_enable_resolution_change()