History

media: core: Report the maximum possible number of buffers for the queue

Use one of the struct v4l2_create_buffers reserved bytes to report the maximum possible number of buffers for the queue. V4l2 framework set V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS flags in queue capabilities so userland can know when the field is valid. Does the same change in v4l2_create_buffers32 structure.

Benjamin Gaignard committed 3 years ago

Commit d055a761 parent c8385306 files · +26 −6Browse files

Unified · Split

6 files
  1. Documentation/userspace-api/media/v4l/vidioc-create-bufs.rst +6 −2
  2. Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst +1 −0
  3. drivers/media/common/videobuf2/videobuf2-v4l2.c +2 −0
  4. drivers/media/v4l2-core/v4l2-compat-ioctl32.c +9 −1
  5. drivers/media/v4l2-core/v4l2-ioctl.c +2 −2
  6. include/uapi/linux/videodev2.h +6 −1
Documentation/userspace-api/media/v4l/vidioc-create-bufs.rst+6−2
@@ -116,9 +116,13 @@ than the number requested. · 115 unmodified lines
116116 - ``flags``
117117 - Specifies additional buffer management attributes.
118118 See :ref:`memory-flags`.
119−
120119 * - __u32
121− - ``reserved``\ [6]
120+ - ``max_num_buffers``
121+ - If the V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS capability flag is set
122+ this field indicates the maximum possible number of buffers
123+ for this queue.
124+ * - __u32
125+ - ``reserved``\ [5]
122126 - A place holder for future extensions. Drivers and applications
123127 must set the array to zero.
124128
Documentation/userspace-api/media/v4l/vidioc-reqbufs.rst+1−0
@@ -120,6 +120,7 @@ aborting or finishing any DMA in progress, an implicit · 119 unmodified lines
120120 .. _V4L2-BUF-CAP-SUPPORTS-ORPHANED-BUFS:
121121 .. _V4L2-BUF-CAP-SUPPORTS-M2M-HOLD-CAPTURE-BUF:
122122 .. _V4L2-BUF-CAP-SUPPORTS-MMAP-CACHE-HINTS:
123+.. _V4L2-BUF-CAP-SUPPORTS-MAX-NUM-BUFFERS:
123124
124125 .. raw:: latex
125126
drivers/media/common/videobuf2/videobuf2-v4l2.c+2−0
@@ -756,6 +756,8 @@ int vb2_create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create) · 755 unmodified lines
756756 fill_buf_caps(q, &create->capabilities);
757757 validate_memory_flags(q, create->memory, &create->flags);
758758 create->index = vb2_get_num_buffers(q);
759+ create->max_num_buffers = q->max_num_buffers;
760+ create->capabilities |= V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS;
759761 if (create->count == 0)
760762 return ret != -EBUSY ? ret : 0;
761763
drivers/media/v4l2-core/v4l2-compat-ioctl32.c+9−1
@@ -116,6 +116,9 @@ struct v4l2_format32 { · 115 unmodified lines
116116 * @flags: additional buffer management attributes (ignored unless the
117117 * queue has V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS capability and
118118 * configured for MMAP streaming I/O).
119+ * @max_num_buffers: if V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS capability flag is set
120+ * this field indicate the maximum possible number of buffers
121+ * for this queue.
119122 * @reserved: future extensions
120123 */
121124 struct v4l2_create_buffers32 {
@@ -125,7 +128,8 @@ struct v4l2_create_buffers32 { · 3 unmodified lines
125128 struct v4l2_format32 format;
126129 __u32 capabilities;
127130 __u32 flags;
128− __u32 reserved[6];
131+ __u32 max_num_buffers;
132+ __u32 reserved[5];
129133 };
130134
131135 static int get_v4l2_format32(struct v4l2_format *p64,
@@ -175,6 +179,9 @@ static int get_v4l2_create32(struct v4l2_create_buffers *p64, · 43 unmodified lines
175179 return -EFAULT;
176180 if (copy_from_user(&p64->flags, &p32->flags, sizeof(p32->flags)))
177181 return -EFAULT;
182+ if (copy_from_user(&p64->max_num_buffers, &p32->max_num_buffers,
183+ sizeof(p32->max_num_buffers)))
184+ return -EFAULT;
178185 return get_v4l2_format32(&p64->format, &p32->format);
179186 }
180187
@@ -221,6 +228,7 @@ static int put_v4l2_create32(struct v4l2_create_buffers *p64, · 40 unmodified lines
221228 offsetof(struct v4l2_create_buffers32, format)) ||
222229 put_user(p64->capabilities, &p32->capabilities) ||
223230 put_user(p64->flags, &p32->flags) ||
231+ put_user(p64->max_num_buffers, &p32->max_num_buffers) ||
224232 copy_to_user(p32->reserved, p64->reserved, sizeof(p64->reserved)))
225233 return -EFAULT;
226234 return put_v4l2_format32(&p64->format, &p32->format);
drivers/media/v4l2-core/v4l2-ioctl.c+2−2
@@ -483,9 +483,9 @@ static void v4l_print_create_buffers(const void *arg, bool write_only) · 482 unmodified lines
483483 {
484484 const struct v4l2_create_buffers *p = arg;
485485
486− pr_cont("index=%d, count=%d, memory=%s, capabilities=0x%08x, ",
486+ pr_cont("index=%d, count=%d, memory=%s, capabilities=0x%08x, max num buffers=%u",
487487 p->index, p->count, prt_names(p->memory, v4l2_memory_names),
488− p->capabilities);
488+ p->capabilities, p->max_num_buffers);
489489 v4l_print_format(&p->format, write_only);
490490 }
491491
include/uapi/linux/videodev2.h+6−1
@@ -1035,6 +1035,7 @@ struct v4l2_requestbuffers { · 1034 unmodified lines
10351035 #define V4L2_BUF_CAP_SUPPORTS_ORPHANED_BUFS (1 << 4)
10361036 #define V4L2_BUF_CAP_SUPPORTS_M2M_HOLD_CAPTURE_BUF (1 << 5)
10371037 #define V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS (1 << 6)
1038+#define V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS (1 << 7)
10381039
10391040 /**
10401041 * struct v4l2_plane - plane info for multi-planar buffers
@@ -2605,6 +2606,9 @@ struct v4l2_dbg_chip_info { · 1564 unmodified lines
26052606 * @flags: additional buffer management attributes (ignored unless the
26062607 * queue has V4L2_BUF_CAP_SUPPORTS_MMAP_CACHE_HINTS capability
26072608 * and configured for MMAP streaming I/O).
2609+ * @max_num_buffers: if V4L2_BUF_CAP_SUPPORTS_MAX_NUM_BUFFERS capability flag is set
2610+ * this field indicate the maximum possible number of buffers
2611+ * for this queue.
26082612 * @reserved: future extensions
26092613 */
26102614 struct v4l2_create_buffers {
@@ -2614,7 +2618,8 @@ struct v4l2_create_buffers { · 3 unmodified lines
26142618 struct v4l2_format format;
26152619 __u32 capabilities;
26162620 __u32 flags;
2617− __u32 reserved[6];
2621+ __u32 max_num_buffers;
2622+ __u32 reserved[5];
26182623 };
26192624
26202625 /*

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t