+ switch (obj->mode) {
+ case GST_V4L2_IO_RW:
+ /* we preallocate 1 buffer, this value also instructs the latency
+ * calculation to have 1 frame latency max */
+ num_buffers = 1;
+ copy_threshold = 0;
+ break;
+ case GST_V4L2_IO_DMABUF:
+ case GST_V4L2_IO_MMAP:
+ {
+ /* request a reasonable number of buffers when no max specified. We will
+ * copy when we run out of buffers */
+ if (max_buffers == 0)
+ num_buffers = 4;
+ else
+ num_buffers = max_buffers;
+
+ /* first, lets request buffers, and see how many we can get: */
+ GST_DEBUG_OBJECT (pool, "starting, requesting %d MMAP buffers",
+ num_buffers);
+
+ memset (&breq, 0, sizeof (struct v4l2_requestbuffers));
+ breq.type = obj->type;
+ breq.count = num_buffers;
+ breq.memory = V4L2_MEMORY_MMAP;
+
+ if (v4l2_ioctl (pool->video_fd, VIDIOC_REQBUFS, &breq) < 0)
+ goto reqbufs_failed;
+
+ GST_LOG_OBJECT (pool, " count: %u", breq.count);
+ GST_LOG_OBJECT (pool, " type: %d", breq.type);
+ GST_LOG_OBJECT (pool, " memory: %d", breq.memory);
+
+ if (breq.count < GST_V4L2_MIN_BUFFERS)
+ goto no_buffers;
+
+ if (num_buffers != breq.count) {
+ GST_WARNING_OBJECT (pool, "using %u buffers instead", breq.count);
+ num_buffers = breq.count;
+ }
+ /* update min buffers with the amount of buffers we just reserved. We need
+ * to configure this value in the bufferpool so that the default start
+ * implementation calls our allocate function */
+ min_buffers = breq.count;
+
+ if (max_buffers == 0 || num_buffers < max_buffers) {
+ /* if we are asked to provide more buffers than we have allocated, start
+ * copying buffers when we only have 2 buffers left in the pool */
+ copy_threshold = 2;
+ } else {
+ /* we are certain that we have enough buffers so we don't need to
+ * copy */
+ copy_threshold = 0;
+ }
+ break;
+ }
+ case GST_V4L2_IO_USERPTR:
+ default:
+ num_buffers = 0;
+ copy_threshold = 0;
+ g_assert_not_reached ();
+ break;
+ }
+