diff options
author | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2016-07-17 14:49:56 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@s-opensource.com> | 2016-07-17 15:30:36 -0400 |
commit | 9488fed623eff249273b83503abfc8a20409f6b1 (patch) | |
tree | 3c71050ce059e20db63662d4b8d25f487d451cf2 | |
parent | 4c21d4fb1b16eaaa6462e76a0eb6b70235a966ea (diff) |
[media] doc-rst: move videobuf documentation to media/kapi
This document describes a kapi framework. Move it to the right
place.
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
-rw-r--r-- | Documentation/media/kapi/v4l2-controls.rst | 169 | ||||
-rw-r--r-- | Documentation/media/kapi/videobuf.rst (renamed from Documentation/video4linux/videobuf) | 0 |
2 files changed, 122 insertions, 47 deletions
diff --git a/Documentation/media/kapi/v4l2-controls.rst b/Documentation/media/kapi/v4l2-controls.rst index 5e759cab4538..8ff9ee806042 100644 --- a/Documentation/media/kapi/v4l2-controls.rst +++ b/Documentation/media/kapi/v4l2-controls.rst | |||
@@ -1,5 +1,8 @@ | |||
1 | V4L2 Controls | ||
2 | ============= | ||
3 | |||
1 | Introduction | 4 | Introduction |
2 | ============ | 5 | ------------ |
3 | 6 | ||
4 | The V4L2 control API seems simple enough, but quickly becomes very hard to | 7 | The V4L2 control API seems simple enough, but quickly becomes very hard to |
5 | implement correctly in drivers. But much of the code needed to handle controls | 8 | implement correctly in drivers. But much of the code needed to handle controls |
@@ -26,7 +29,7 @@ for V4L2 drivers and struct v4l2_subdev for sub-device drivers. | |||
26 | 29 | ||
27 | 30 | ||
28 | Objects in the framework | 31 | Objects in the framework |
29 | ======================== | 32 | ------------------------ |
30 | 33 | ||
31 | There are two main objects: | 34 | There are two main objects: |
32 | 35 | ||
@@ -39,12 +42,14 @@ controls, possibly to controls owned by other handlers. | |||
39 | 42 | ||
40 | 43 | ||
41 | Basic usage for V4L2 and sub-device drivers | 44 | Basic usage for V4L2 and sub-device drivers |
42 | =========================================== | 45 | ------------------------------------------- |
43 | 46 | ||
44 | 1) Prepare the driver: | 47 | 1) Prepare the driver: |
45 | 48 | ||
46 | 1.1) Add the handler to your driver's top-level struct: | 49 | 1.1) Add the handler to your driver's top-level struct: |
47 | 50 | ||
51 | .. code-block:: none | ||
52 | |||
48 | struct foo_dev { | 53 | struct foo_dev { |
49 | ... | 54 | ... |
50 | struct v4l2_ctrl_handler ctrl_handler; | 55 | struct v4l2_ctrl_handler ctrl_handler; |
@@ -55,16 +60,20 @@ Basic usage for V4L2 and sub-device drivers | |||
55 | 60 | ||
56 | 1.2) Initialize the handler: | 61 | 1.2) Initialize the handler: |
57 | 62 | ||
63 | .. code-block:: none | ||
64 | |||
58 | v4l2_ctrl_handler_init(&foo->ctrl_handler, nr_of_controls); | 65 | v4l2_ctrl_handler_init(&foo->ctrl_handler, nr_of_controls); |
59 | 66 | ||
60 | The second argument is a hint telling the function how many controls this | 67 | The second argument is a hint telling the function how many controls this |
61 | handler is expected to handle. It will allocate a hashtable based on this | 68 | handler is expected to handle. It will allocate a hashtable based on this |
62 | information. It is a hint only. | 69 | information. It is a hint only. |
63 | 70 | ||
64 | 1.3) Hook the control handler into the driver: | 71 | 1.3) Hook the control handler into the driver: |
65 | 72 | ||
66 | 1.3.1) For V4L2 drivers do this: | 73 | 1.3.1) For V4L2 drivers do this: |
67 | 74 | ||
75 | .. code-block:: none | ||
76 | |||
68 | struct foo_dev { | 77 | struct foo_dev { |
69 | ... | 78 | ... |
70 | struct v4l2_device v4l2_dev; | 79 | struct v4l2_device v4l2_dev; |
@@ -75,15 +84,17 @@ Basic usage for V4L2 and sub-device drivers | |||
75 | 84 | ||
76 | foo->v4l2_dev.ctrl_handler = &foo->ctrl_handler; | 85 | foo->v4l2_dev.ctrl_handler = &foo->ctrl_handler; |
77 | 86 | ||
78 | Where foo->v4l2_dev is of type struct v4l2_device. | 87 | Where foo->v4l2_dev is of type struct v4l2_device. |
79 | 88 | ||
80 | Finally, remove all control functions from your v4l2_ioctl_ops (if any): | 89 | Finally, remove all control functions from your v4l2_ioctl_ops (if any): |
81 | vidioc_queryctrl, vidioc_query_ext_ctrl, vidioc_querymenu, vidioc_g_ctrl, | 90 | vidioc_queryctrl, vidioc_query_ext_ctrl, vidioc_querymenu, vidioc_g_ctrl, |
82 | vidioc_s_ctrl, vidioc_g_ext_ctrls, vidioc_try_ext_ctrls and vidioc_s_ext_ctrls. | 91 | vidioc_s_ctrl, vidioc_g_ext_ctrls, vidioc_try_ext_ctrls and vidioc_s_ext_ctrls. |
83 | Those are now no longer needed. | 92 | Those are now no longer needed. |
84 | 93 | ||
85 | 1.3.2) For sub-device drivers do this: | 94 | 1.3.2) For sub-device drivers do this: |
86 | 95 | ||
96 | .. code-block:: none | ||
97 | |||
87 | struct foo_dev { | 98 | struct foo_dev { |
88 | ... | 99 | ... |
89 | struct v4l2_subdev sd; | 100 | struct v4l2_subdev sd; |
@@ -94,10 +105,12 @@ Basic usage for V4L2 and sub-device drivers | |||
94 | 105 | ||
95 | foo->sd.ctrl_handler = &foo->ctrl_handler; | 106 | foo->sd.ctrl_handler = &foo->ctrl_handler; |
96 | 107 | ||
97 | Where foo->sd is of type struct v4l2_subdev. | 108 | Where foo->sd is of type struct v4l2_subdev. |
98 | 109 | ||
99 | And set all core control ops in your struct v4l2_subdev_core_ops to these | 110 | And set all core control ops in your struct v4l2_subdev_core_ops to these |
100 | helpers: | 111 | helpers: |
112 | |||
113 | .. code-block:: none | ||
101 | 114 | ||
102 | .queryctrl = v4l2_subdev_queryctrl, | 115 | .queryctrl = v4l2_subdev_queryctrl, |
103 | .querymenu = v4l2_subdev_querymenu, | 116 | .querymenu = v4l2_subdev_querymenu, |
@@ -107,12 +120,14 @@ Basic usage for V4L2 and sub-device drivers | |||
107 | .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, | 120 | .try_ext_ctrls = v4l2_subdev_try_ext_ctrls, |
108 | .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, | 121 | .s_ext_ctrls = v4l2_subdev_s_ext_ctrls, |
109 | 122 | ||
110 | Note: this is a temporary solution only. Once all V4L2 drivers that depend | 123 | Note: this is a temporary solution only. Once all V4L2 drivers that depend |
111 | on subdev drivers are converted to the control framework these helpers will | 124 | on subdev drivers are converted to the control framework these helpers will |
112 | no longer be needed. | 125 | no longer be needed. |
113 | 126 | ||
114 | 1.4) Clean up the handler at the end: | 127 | 1.4) Clean up the handler at the end: |
115 | 128 | ||
129 | .. code-block:: none | ||
130 | |||
116 | v4l2_ctrl_handler_free(&foo->ctrl_handler); | 131 | v4l2_ctrl_handler_free(&foo->ctrl_handler); |
117 | 132 | ||
118 | 133 | ||
@@ -120,12 +135,16 @@ Basic usage for V4L2 and sub-device drivers | |||
120 | 135 | ||
121 | You add non-menu controls by calling v4l2_ctrl_new_std: | 136 | You add non-menu controls by calling v4l2_ctrl_new_std: |
122 | 137 | ||
138 | .. code-block:: none | ||
139 | |||
123 | struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl, | 140 | struct v4l2_ctrl *v4l2_ctrl_new_std(struct v4l2_ctrl_handler *hdl, |
124 | const struct v4l2_ctrl_ops *ops, | 141 | const struct v4l2_ctrl_ops *ops, |
125 | u32 id, s32 min, s32 max, u32 step, s32 def); | 142 | u32 id, s32 min, s32 max, u32 step, s32 def); |
126 | 143 | ||
127 | Menu and integer menu controls are added by calling v4l2_ctrl_new_std_menu: | 144 | Menu and integer menu controls are added by calling v4l2_ctrl_new_std_menu: |
128 | 145 | ||
146 | .. code-block:: none | ||
147 | |||
129 | struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl, | 148 | struct v4l2_ctrl *v4l2_ctrl_new_std_menu(struct v4l2_ctrl_handler *hdl, |
130 | const struct v4l2_ctrl_ops *ops, | 149 | const struct v4l2_ctrl_ops *ops, |
131 | u32 id, s32 max, s32 skip_mask, s32 def); | 150 | u32 id, s32 max, s32 skip_mask, s32 def); |
@@ -133,6 +152,8 @@ Menu and integer menu controls are added by calling v4l2_ctrl_new_std_menu: | |||
133 | Menu controls with a driver specific menu are added by calling | 152 | Menu controls with a driver specific menu are added by calling |
134 | v4l2_ctrl_new_std_menu_items: | 153 | v4l2_ctrl_new_std_menu_items: |
135 | 154 | ||
155 | .. code-block:: none | ||
156 | |||
136 | struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items( | 157 | struct v4l2_ctrl *v4l2_ctrl_new_std_menu_items( |
137 | struct v4l2_ctrl_handler *hdl, | 158 | struct v4l2_ctrl_handler *hdl, |
138 | const struct v4l2_ctrl_ops *ops, u32 id, s32 max, | 159 | const struct v4l2_ctrl_ops *ops, u32 id, s32 max, |
@@ -141,12 +162,16 @@ v4l2_ctrl_new_std_menu_items: | |||
141 | Integer menu controls with a driver specific menu can be added by calling | 162 | Integer menu controls with a driver specific menu can be added by calling |
142 | v4l2_ctrl_new_int_menu: | 163 | v4l2_ctrl_new_int_menu: |
143 | 164 | ||
165 | .. code-block:: none | ||
166 | |||
144 | struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl, | 167 | struct v4l2_ctrl *v4l2_ctrl_new_int_menu(struct v4l2_ctrl_handler *hdl, |
145 | const struct v4l2_ctrl_ops *ops, | 168 | const struct v4l2_ctrl_ops *ops, |
146 | u32 id, s32 max, s32 def, const s64 *qmenu_int); | 169 | u32 id, s32 max, s32 def, const s64 *qmenu_int); |
147 | 170 | ||
148 | These functions are typically called right after the v4l2_ctrl_handler_init: | 171 | These functions are typically called right after the v4l2_ctrl_handler_init: |
149 | 172 | ||
173 | .. code-block:: none | ||
174 | |||
150 | static const s64 exp_bias_qmenu[] = { | 175 | static const s64 exp_bias_qmenu[] = { |
151 | -2, -1, 0, 1, 2 | 176 | -2, -1, 0, 1, 2 |
152 | }; | 177 | }; |
@@ -223,6 +248,8 @@ a bit faster that way. | |||
223 | 248 | ||
224 | 3) Optionally force initial control setup: | 249 | 3) Optionally force initial control setup: |
225 | 250 | ||
251 | .. code-block:: none | ||
252 | |||
226 | v4l2_ctrl_handler_setup(&foo->ctrl_handler); | 253 | v4l2_ctrl_handler_setup(&foo->ctrl_handler); |
227 | 254 | ||
228 | This will call s_ctrl for all controls unconditionally. Effectively this | 255 | This will call s_ctrl for all controls unconditionally. Effectively this |
@@ -232,12 +259,16 @@ the hardware are in sync. | |||
232 | 259 | ||
233 | 4) Finally: implement the v4l2_ctrl_ops | 260 | 4) Finally: implement the v4l2_ctrl_ops |
234 | 261 | ||
262 | .. code-block:: none | ||
263 | |||
235 | static const struct v4l2_ctrl_ops foo_ctrl_ops = { | 264 | static const struct v4l2_ctrl_ops foo_ctrl_ops = { |
236 | .s_ctrl = foo_s_ctrl, | 265 | .s_ctrl = foo_s_ctrl, |
237 | }; | 266 | }; |
238 | 267 | ||
239 | Usually all you need is s_ctrl: | 268 | Usually all you need is s_ctrl: |
240 | 269 | ||
270 | .. code-block:: none | ||
271 | |||
241 | static int foo_s_ctrl(struct v4l2_ctrl *ctrl) | 272 | static int foo_s_ctrl(struct v4l2_ctrl *ctrl) |
242 | { | 273 | { |
243 | struct foo *state = container_of(ctrl->handler, struct foo, ctrl_handler); | 274 | struct foo *state = container_of(ctrl->handler, struct foo, ctrl_handler); |
@@ -262,16 +293,14 @@ to do any validation of control values, or implement QUERYCTRL, QUERY_EXT_CTRL | |||
262 | and QUERYMENU. And G/S_CTRL as well as G/TRY/S_EXT_CTRLS are automatically supported. | 293 | and QUERYMENU. And G/S_CTRL as well as G/TRY/S_EXT_CTRLS are automatically supported. |
263 | 294 | ||
264 | 295 | ||
265 | ============================================================================== | 296 | .. note:: |
266 | 297 | ||
267 | The remainder of this document deals with more advanced topics and scenarios. | 298 | The remainder sections deal with more advanced controls topics and scenarios. |
268 | In practice the basic usage as described above is sufficient for most drivers. | 299 | In practice the basic usage as described above is sufficient for most drivers. |
269 | |||
270 | =============================================================================== | ||
271 | 300 | ||
272 | 301 | ||
273 | Inheriting Controls | 302 | Inheriting Controls |
274 | =================== | 303 | ------------------- |
275 | 304 | ||
276 | When a sub-device is registered with a V4L2 driver by calling | 305 | When a sub-device is registered with a V4L2 driver by calling |
277 | v4l2_device_register_subdev() and the ctrl_handler fields of both v4l2_subdev | 306 | v4l2_device_register_subdev() and the ctrl_handler fields of both v4l2_subdev |
@@ -286,21 +315,25 @@ of v4l2_device. | |||
286 | 315 | ||
287 | 316 | ||
288 | Accessing Control Values | 317 | Accessing Control Values |
289 | ======================== | 318 | ------------------------ |
290 | 319 | ||
291 | The following union is used inside the control framework to access control | 320 | The following union is used inside the control framework to access control |
292 | values: | 321 | values: |
293 | 322 | ||
294 | union v4l2_ctrl_ptr { | 323 | .. code-block:: none |
295 | s32 *p_s32; | 324 | |
296 | s64 *p_s64; | 325 | union v4l2_ctrl_ptr { |
297 | char *p_char; | 326 | s32 *p_s32; |
298 | void *p; | 327 | s64 *p_s64; |
299 | }; | 328 | char *p_char; |
329 | void *p; | ||
330 | }; | ||
300 | 331 | ||
301 | The v4l2_ctrl struct contains these fields that can be used to access both | 332 | The v4l2_ctrl struct contains these fields that can be used to access both |
302 | current and new values: | 333 | current and new values: |
303 | 334 | ||
335 | .. code-block:: none | ||
336 | |||
304 | s32 val; | 337 | s32 val; |
305 | struct { | 338 | struct { |
306 | s32 val; | 339 | s32 val; |
@@ -312,6 +345,8 @@ current and new values: | |||
312 | 345 | ||
313 | If the control has a simple s32 type type, then: | 346 | If the control has a simple s32 type type, then: |
314 | 347 | ||
348 | .. code-block:: none | ||
349 | |||
315 | &ctrl->val == ctrl->p_new.p_s32 | 350 | &ctrl->val == ctrl->p_new.p_s32 |
316 | &ctrl->cur.val == ctrl->p_cur.p_s32 | 351 | &ctrl->cur.val == ctrl->p_cur.p_s32 |
317 | 352 | ||
@@ -334,6 +369,8 @@ exception is for controls that return a volatile register such as a signal | |||
334 | strength read-out that changes continuously. In that case you will need to | 369 | strength read-out that changes continuously. In that case you will need to |
335 | implement g_volatile_ctrl like this: | 370 | implement g_volatile_ctrl like this: |
336 | 371 | ||
372 | .. code-block:: none | ||
373 | |||
337 | static int foo_g_volatile_ctrl(struct v4l2_ctrl *ctrl) | 374 | static int foo_g_volatile_ctrl(struct v4l2_ctrl *ctrl) |
338 | { | 375 | { |
339 | switch (ctrl->id) { | 376 | switch (ctrl->id) { |
@@ -350,6 +387,8 @@ changes. | |||
350 | 387 | ||
351 | To mark a control as volatile you have to set V4L2_CTRL_FLAG_VOLATILE: | 388 | To mark a control as volatile you have to set V4L2_CTRL_FLAG_VOLATILE: |
352 | 389 | ||
390 | .. code-block:: none | ||
391 | |||
353 | ctrl = v4l2_ctrl_new_std(&sd->ctrl_handler, ...); | 392 | ctrl = v4l2_ctrl_new_std(&sd->ctrl_handler, ...); |
354 | if (ctrl) | 393 | if (ctrl) |
355 | ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE; | 394 | ctrl->flags |= V4L2_CTRL_FLAG_VOLATILE; |
@@ -369,6 +408,8 @@ not to introduce deadlocks. | |||
369 | Outside of the control ops you have to go through to helper functions to get | 408 | Outside of the control ops you have to go through to helper functions to get |
370 | or set a single control value safely in your driver: | 409 | or set a single control value safely in your driver: |
371 | 410 | ||
411 | .. code-block:: none | ||
412 | |||
372 | s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl); | 413 | s32 v4l2_ctrl_g_ctrl(struct v4l2_ctrl *ctrl); |
373 | int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val); | 414 | int v4l2_ctrl_s_ctrl(struct v4l2_ctrl *ctrl, s32 val); |
374 | 415 | ||
@@ -378,6 +419,8 @@ will result in a deadlock since these helpers lock the handler as well. | |||
378 | 419 | ||
379 | You can also take the handler lock yourself: | 420 | You can also take the handler lock yourself: |
380 | 421 | ||
422 | .. code-block:: none | ||
423 | |||
381 | mutex_lock(&state->ctrl_handler.lock); | 424 | mutex_lock(&state->ctrl_handler.lock); |
382 | pr_info("String value is '%s'\n", ctrl1->p_cur.p_char); | 425 | pr_info("String value is '%s'\n", ctrl1->p_cur.p_char); |
383 | pr_info("Integer value is '%s'\n", ctrl2->cur.val); | 426 | pr_info("Integer value is '%s'\n", ctrl2->cur.val); |
@@ -385,10 +428,12 @@ You can also take the handler lock yourself: | |||
385 | 428 | ||
386 | 429 | ||
387 | Menu Controls | 430 | Menu Controls |
388 | ============= | 431 | ------------- |
389 | 432 | ||
390 | The v4l2_ctrl struct contains this union: | 433 | The v4l2_ctrl struct contains this union: |
391 | 434 | ||
435 | .. code-block:: none | ||
436 | |||
392 | union { | 437 | union { |
393 | u32 step; | 438 | u32 step; |
394 | u32 menu_skip_mask; | 439 | u32 menu_skip_mask; |
@@ -411,10 +456,12 @@ control, or by calling v4l2_ctrl_new_std_menu(). | |||
411 | 456 | ||
412 | 457 | ||
413 | Custom Controls | 458 | Custom Controls |
414 | =============== | 459 | --------------- |
415 | 460 | ||
416 | Driver specific controls can be created using v4l2_ctrl_new_custom(): | 461 | Driver specific controls can be created using v4l2_ctrl_new_custom(): |
417 | 462 | ||
463 | .. code-block:: none | ||
464 | |||
418 | static const struct v4l2_ctrl_config ctrl_filter = { | 465 | static const struct v4l2_ctrl_config ctrl_filter = { |
419 | .ops = &ctrl_custom_ops, | 466 | .ops = &ctrl_custom_ops, |
420 | .id = V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER, | 467 | .id = V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER, |
@@ -437,7 +484,7 @@ control and will fill in the name, type and flags fields accordingly. | |||
437 | 484 | ||
438 | 485 | ||
439 | Active and Grabbed Controls | 486 | Active and Grabbed Controls |
440 | =========================== | 487 | --------------------------- |
441 | 488 | ||
442 | If you get more complex relationships between controls, then you may have to | 489 | If you get more complex relationships between controls, then you may have to |
443 | activate and deactivate controls. For example, if the Chroma AGC control is | 490 | activate and deactivate controls. For example, if the Chroma AGC control is |
@@ -461,16 +508,18 @@ starts or stops streaming. | |||
461 | 508 | ||
462 | 509 | ||
463 | Control Clusters | 510 | Control Clusters |
464 | ================ | 511 | ---------------- |
465 | 512 | ||
466 | By default all controls are independent from the others. But in more | 513 | By default all controls are independent from the others. But in more |
467 | complex scenarios you can get dependencies from one control to another. | 514 | complex scenarios you can get dependencies from one control to another. |
468 | In that case you need to 'cluster' them: | 515 | In that case you need to 'cluster' them: |
469 | 516 | ||
517 | .. code-block:: none | ||
518 | |||
470 | struct foo { | 519 | struct foo { |
471 | struct v4l2_ctrl_handler ctrl_handler; | 520 | struct v4l2_ctrl_handler ctrl_handler; |
472 | #define AUDIO_CL_VOLUME (0) | 521 | #define AUDIO_CL_VOLUME (0) |
473 | #define AUDIO_CL_MUTE (1) | 522 | #define AUDIO_CL_MUTE (1) |
474 | struct v4l2_ctrl *audio_cluster[2]; | 523 | struct v4l2_ctrl *audio_cluster[2]; |
475 | ... | 524 | ... |
476 | }; | 525 | }; |
@@ -489,6 +538,8 @@ composite control. Similar to how a 'struct' works in C. | |||
489 | So when s_ctrl is called with V4L2_CID_AUDIO_VOLUME as argument, you should set | 538 | So when s_ctrl is called with V4L2_CID_AUDIO_VOLUME as argument, you should set |
490 | all two controls belonging to the audio_cluster: | 539 | all two controls belonging to the audio_cluster: |
491 | 540 | ||
541 | .. code-block:: none | ||
542 | |||
492 | static int foo_s_ctrl(struct v4l2_ctrl *ctrl) | 543 | static int foo_s_ctrl(struct v4l2_ctrl *ctrl) |
493 | { | 544 | { |
494 | struct foo *state = container_of(ctrl->handler, struct foo, ctrl_handler); | 545 | struct foo *state = container_of(ctrl->handler, struct foo, ctrl_handler); |
@@ -509,12 +560,16 @@ all two controls belonging to the audio_cluster: | |||
509 | 560 | ||
510 | In the example above the following are equivalent for the VOLUME case: | 561 | In the example above the following are equivalent for the VOLUME case: |
511 | 562 | ||
563 | .. code-block:: none | ||
564 | |||
512 | ctrl == ctrl->cluster[AUDIO_CL_VOLUME] == state->audio_cluster[AUDIO_CL_VOLUME] | 565 | ctrl == ctrl->cluster[AUDIO_CL_VOLUME] == state->audio_cluster[AUDIO_CL_VOLUME] |
513 | ctrl->cluster[AUDIO_CL_MUTE] == state->audio_cluster[AUDIO_CL_MUTE] | 566 | ctrl->cluster[AUDIO_CL_MUTE] == state->audio_cluster[AUDIO_CL_MUTE] |
514 | 567 | ||
515 | In practice using cluster arrays like this becomes very tiresome. So instead | 568 | In practice using cluster arrays like this becomes very tiresome. So instead |
516 | the following equivalent method is used: | 569 | the following equivalent method is used: |
517 | 570 | ||
571 | .. code-block:: none | ||
572 | |||
518 | struct { | 573 | struct { |
519 | /* audio cluster */ | 574 | /* audio cluster */ |
520 | struct v4l2_ctrl *volume; | 575 | struct v4l2_ctrl *volume; |
@@ -525,6 +580,8 @@ The anonymous struct is used to clearly 'cluster' these two control pointers, | |||
525 | but it serves no other purpose. The effect is the same as creating an | 580 | but it serves no other purpose. The effect is the same as creating an |
526 | array with two control pointers. So you can just do: | 581 | array with two control pointers. So you can just do: |
527 | 582 | ||
583 | .. code-block:: none | ||
584 | |||
528 | state->volume = v4l2_ctrl_new_std(&state->ctrl_handler, ...); | 585 | state->volume = v4l2_ctrl_new_std(&state->ctrl_handler, ...); |
529 | state->mute = v4l2_ctrl_new_std(&state->ctrl_handler, ...); | 586 | state->mute = v4l2_ctrl_new_std(&state->ctrl_handler, ...); |
530 | v4l2_ctrl_cluster(2, &state->volume); | 587 | v4l2_ctrl_cluster(2, &state->volume); |
@@ -554,7 +611,7 @@ The 'is_new' flag is always 1 when called from v4l2_ctrl_handler_setup(). | |||
554 | 611 | ||
555 | 612 | ||
556 | Handling autogain/gain-type Controls with Auto Clusters | 613 | Handling autogain/gain-type Controls with Auto Clusters |
557 | ======================================================= | 614 | ------------------------------------------------------- |
558 | 615 | ||
559 | A common type of control cluster is one that handles 'auto-foo/foo'-type | 616 | A common type of control cluster is one that handles 'auto-foo/foo'-type |
560 | controls. Typical examples are autogain/gain, autoexposure/exposure, | 617 | controls. Typical examples are autogain/gain, autoexposure/exposure, |
@@ -579,8 +636,10 @@ changing that control affects the control flags of the manual controls. | |||
579 | In order to simplify this a special variation of v4l2_ctrl_cluster was | 636 | In order to simplify this a special variation of v4l2_ctrl_cluster was |
580 | introduced: | 637 | introduced: |
581 | 638 | ||
582 | void v4l2_ctrl_auto_cluster(unsigned ncontrols, struct v4l2_ctrl **controls, | 639 | .. code-block:: none |
583 | u8 manual_val, bool set_volatile); | 640 | |
641 | void v4l2_ctrl_auto_cluster(unsigned ncontrols, struct v4l2_ctrl **controls, | ||
642 | u8 manual_val, bool set_volatile); | ||
584 | 643 | ||
585 | The first two arguments are identical to v4l2_ctrl_cluster. The third argument | 644 | The first two arguments are identical to v4l2_ctrl_cluster. The third argument |
586 | tells the framework which value switches the cluster into manual mode. The | 645 | tells the framework which value switches the cluster into manual mode. The |
@@ -597,7 +656,7 @@ flag and volatile handling. | |||
597 | 656 | ||
598 | 657 | ||
599 | VIDIOC_LOG_STATUS Support | 658 | VIDIOC_LOG_STATUS Support |
600 | ========================= | 659 | ------------------------- |
601 | 660 | ||
602 | This ioctl allow you to dump the current status of a driver to the kernel log. | 661 | This ioctl allow you to dump the current status of a driver to the kernel log. |
603 | The v4l2_ctrl_handler_log_status(ctrl_handler, prefix) can be used to dump the | 662 | The v4l2_ctrl_handler_log_status(ctrl_handler, prefix) can be used to dump the |
@@ -607,7 +666,7 @@ for you. | |||
607 | 666 | ||
608 | 667 | ||
609 | Different Handlers for Different Video Nodes | 668 | Different Handlers for Different Video Nodes |
610 | ============================================ | 669 | -------------------------------------------- |
611 | 670 | ||
612 | Usually the V4L2 driver has just one control handler that is global for | 671 | Usually the V4L2 driver has just one control handler that is global for |
613 | all video nodes. But you can also specify different control handlers for | 672 | all video nodes. But you can also specify different control handlers for |
@@ -632,6 +691,8 @@ of another handler (e.g. for a video device node), then you should first add | |||
632 | the controls to the first handler, add the other controls to the second | 691 | the controls to the first handler, add the other controls to the second |
633 | handler and finally add the first handler to the second. For example: | 692 | handler and finally add the first handler to the second. For example: |
634 | 693 | ||
694 | .. code-block:: none | ||
695 | |||
635 | v4l2_ctrl_new_std(&radio_ctrl_handler, &radio_ops, V4L2_CID_AUDIO_VOLUME, ...); | 696 | v4l2_ctrl_new_std(&radio_ctrl_handler, &radio_ops, V4L2_CID_AUDIO_VOLUME, ...); |
636 | v4l2_ctrl_new_std(&radio_ctrl_handler, &radio_ops, V4L2_CID_AUDIO_MUTE, ...); | 697 | v4l2_ctrl_new_std(&radio_ctrl_handler, &radio_ops, V4L2_CID_AUDIO_MUTE, ...); |
637 | v4l2_ctrl_new_std(&video_ctrl_handler, &video_ops, V4L2_CID_BRIGHTNESS, ...); | 698 | v4l2_ctrl_new_std(&video_ctrl_handler, &video_ops, V4L2_CID_BRIGHTNESS, ...); |
@@ -644,6 +705,8 @@ all controls. | |||
644 | 705 | ||
645 | Or you can add specific controls to a handler: | 706 | Or you can add specific controls to a handler: |
646 | 707 | ||
708 | .. code-block:: none | ||
709 | |||
647 | volume = v4l2_ctrl_new_std(&video_ctrl_handler, &ops, V4L2_CID_AUDIO_VOLUME, ...); | 710 | volume = v4l2_ctrl_new_std(&video_ctrl_handler, &ops, V4L2_CID_AUDIO_VOLUME, ...); |
648 | v4l2_ctrl_new_std(&video_ctrl_handler, &ops, V4L2_CID_BRIGHTNESS, ...); | 711 | v4l2_ctrl_new_std(&video_ctrl_handler, &ops, V4L2_CID_BRIGHTNESS, ...); |
649 | v4l2_ctrl_new_std(&video_ctrl_handler, &ops, V4L2_CID_CONTRAST, ...); | 712 | v4l2_ctrl_new_std(&video_ctrl_handler, &ops, V4L2_CID_CONTRAST, ...); |
@@ -651,6 +714,8 @@ Or you can add specific controls to a handler: | |||
651 | What you should not do is make two identical controls for two handlers. | 714 | What you should not do is make two identical controls for two handlers. |
652 | For example: | 715 | For example: |
653 | 716 | ||
717 | .. code-block:: none | ||
718 | |||
654 | v4l2_ctrl_new_std(&radio_ctrl_handler, &radio_ops, V4L2_CID_AUDIO_MUTE, ...); | 719 | v4l2_ctrl_new_std(&radio_ctrl_handler, &radio_ops, V4L2_CID_AUDIO_MUTE, ...); |
655 | v4l2_ctrl_new_std(&video_ctrl_handler, &video_ops, V4L2_CID_AUDIO_MUTE, ...); | 720 | v4l2_ctrl_new_std(&video_ctrl_handler, &video_ops, V4L2_CID_AUDIO_MUTE, ...); |
656 | 721 | ||
@@ -660,7 +725,7 @@ can twiddle. | |||
660 | 725 | ||
661 | 726 | ||
662 | Finding Controls | 727 | Finding Controls |
663 | ================ | 728 | ---------------- |
664 | 729 | ||
665 | Normally you have created the controls yourself and you can store the struct | 730 | Normally you have created the controls yourself and you can store the struct |
666 | v4l2_ctrl pointer into your own struct. | 731 | v4l2_ctrl pointer into your own struct. |
@@ -670,6 +735,8 @@ not own. For example, if you have to find a volume control from a subdev. | |||
670 | 735 | ||
671 | You can do that by calling v4l2_ctrl_find: | 736 | You can do that by calling v4l2_ctrl_find: |
672 | 737 | ||
738 | .. code-block:: none | ||
739 | |||
673 | struct v4l2_ctrl *volume; | 740 | struct v4l2_ctrl *volume; |
674 | 741 | ||
675 | volume = v4l2_ctrl_find(sd->ctrl_handler, V4L2_CID_AUDIO_VOLUME); | 742 | volume = v4l2_ctrl_find(sd->ctrl_handler, V4L2_CID_AUDIO_VOLUME); |
@@ -677,6 +744,8 @@ You can do that by calling v4l2_ctrl_find: | |||
677 | Since v4l2_ctrl_find will lock the handler you have to be careful where you | 744 | Since v4l2_ctrl_find will lock the handler you have to be careful where you |
678 | use it. For example, this is not a good idea: | 745 | use it. For example, this is not a good idea: |
679 | 746 | ||
747 | .. code-block:: none | ||
748 | |||
680 | struct v4l2_ctrl_handler ctrl_handler; | 749 | struct v4l2_ctrl_handler ctrl_handler; |
681 | 750 | ||
682 | v4l2_ctrl_new_std(&ctrl_handler, &video_ops, V4L2_CID_BRIGHTNESS, ...); | 751 | v4l2_ctrl_new_std(&ctrl_handler, &video_ops, V4L2_CID_BRIGHTNESS, ...); |
@@ -684,6 +753,8 @@ use it. For example, this is not a good idea: | |||
684 | 753 | ||
685 | ...and in video_ops.s_ctrl: | 754 | ...and in video_ops.s_ctrl: |
686 | 755 | ||
756 | .. code-block:: none | ||
757 | |||
687 | case V4L2_CID_BRIGHTNESS: | 758 | case V4L2_CID_BRIGHTNESS: |
688 | contrast = v4l2_find_ctrl(&ctrl_handler, V4L2_CID_CONTRAST); | 759 | contrast = v4l2_find_ctrl(&ctrl_handler, V4L2_CID_CONTRAST); |
689 | ... | 760 | ... |
@@ -695,7 +766,7 @@ It is recommended not to use this function from inside the control ops. | |||
695 | 766 | ||
696 | 767 | ||
697 | Inheriting Controls | 768 | Inheriting Controls |
698 | =================== | 769 | ------------------- |
699 | 770 | ||
700 | When one control handler is added to another using v4l2_ctrl_add_handler, then | 771 | When one control handler is added to another using v4l2_ctrl_add_handler, then |
701 | by default all controls from one are merged to the other. But a subdev might | 772 | by default all controls from one are merged to the other. But a subdev might |
@@ -704,6 +775,8 @@ not when it is used in consumer-level hardware. In that case you want to keep | |||
704 | those low-level controls local to the subdev. You can do this by simply | 775 | those low-level controls local to the subdev. You can do this by simply |
705 | setting the 'is_private' flag of the control to 1: | 776 | setting the 'is_private' flag of the control to 1: |
706 | 777 | ||
778 | .. code-block:: none | ||
779 | |||
707 | static const struct v4l2_ctrl_config ctrl_private = { | 780 | static const struct v4l2_ctrl_config ctrl_private = { |
708 | .ops = &ctrl_custom_ops, | 781 | .ops = &ctrl_custom_ops, |
709 | .id = V4L2_CID_..., | 782 | .id = V4L2_CID_..., |
@@ -720,7 +793,7 @@ These controls will now be skipped when v4l2_ctrl_add_handler is called. | |||
720 | 793 | ||
721 | 794 | ||
722 | V4L2_CTRL_TYPE_CTRL_CLASS Controls | 795 | V4L2_CTRL_TYPE_CTRL_CLASS Controls |
723 | ================================== | 796 | ---------------------------------- |
724 | 797 | ||
725 | Controls of this type can be used by GUIs to get the name of the control class. | 798 | Controls of this type can be used by GUIs to get the name of the control class. |
726 | A fully featured GUI can make a dialog with multiple tabs with each tab | 799 | A fully featured GUI can make a dialog with multiple tabs with each tab |
@@ -733,14 +806,16 @@ class is added. | |||
733 | 806 | ||
734 | 807 | ||
735 | Adding Notify Callbacks | 808 | Adding Notify Callbacks |
736 | ======================= | 809 | ----------------------- |
737 | 810 | ||
738 | Sometimes the platform or bridge driver needs to be notified when a control | 811 | Sometimes the platform or bridge driver needs to be notified when a control |
739 | from a sub-device driver changes. You can set a notify callback by calling | 812 | from a sub-device driver changes. You can set a notify callback by calling |
740 | this function: | 813 | this function: |
741 | 814 | ||
742 | void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, | 815 | .. code-block:: none |
743 | void (*notify)(struct v4l2_ctrl *ctrl, void *priv), void *priv); | 816 | |
817 | void v4l2_ctrl_notify(struct v4l2_ctrl *ctrl, | ||
818 | void (*notify)(struct v4l2_ctrl *ctrl, void *priv), void *priv); | ||
744 | 819 | ||
745 | Whenever the give control changes value the notify callback will be called | 820 | Whenever the give control changes value the notify callback will be called |
746 | with a pointer to the control and the priv pointer that was passed with | 821 | with a pointer to the control and the priv pointer that was passed with |
diff --git a/Documentation/video4linux/videobuf b/Documentation/media/kapi/videobuf.rst index 3ffe9e960b6f..3ffe9e960b6f 100644 --- a/Documentation/video4linux/videobuf +++ b/Documentation/media/kapi/videobuf.rst | |||