diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2014-02-04 07:55:19 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <m.chehab@samsung.com> | 2014-02-04 10:00:19 -0500 |
commit | 5d5f87bce6cd30cde2ea02f9f8338d6dba97f8d2 (patch) | |
tree | f6fa156d5d310110e97ce13da9283293e8ac865d /Documentation/DocBook | |
parent | 26f08db9b0d10dc901f7565fc350943ea46e0381 (diff) |
[media] DocBook: partial rewrite of "Opening and Closing Devices"
This section was horribly out of date. A lot of references to old and
obsolete behavior have been dropped.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Diffstat (limited to 'Documentation/DocBook')
-rw-r--r-- | Documentation/DocBook/media/v4l/common.xml | 191 | ||||
-rw-r--r-- | Documentation/DocBook/media/v4l/v4l2.xml | 2 |
2 files changed, 70 insertions, 123 deletions
diff --git a/Documentation/DocBook/media/v4l/common.xml b/Documentation/DocBook/media/v4l/common.xml index 0936dd24ed3d..71f6bf9e735e 100644 --- a/Documentation/DocBook/media/v4l/common.xml +++ b/Documentation/DocBook/media/v4l/common.xml | |||
@@ -38,70 +38,41 @@ the basic concepts applicable to all devices.</para> | |||
38 | 38 | ||
39 | <para>V4L2 drivers are implemented as kernel modules, loaded | 39 | <para>V4L2 drivers are implemented as kernel modules, loaded |
40 | manually by the system administrator or automatically when a device is | 40 | manually by the system administrator or automatically when a device is |
41 | first opened. The driver modules plug into the "videodev" kernel | 41 | first discovered. The driver modules plug into the "videodev" kernel |
42 | module. It provides helper functions and a common application | 42 | module. It provides helper functions and a common application |
43 | interface specified in this document.</para> | 43 | interface specified in this document.</para> |
44 | 44 | ||
45 | <para>Each driver thus loaded registers one or more device nodes | 45 | <para>Each driver thus loaded registers one or more device nodes |
46 | with major number 81 and a minor number between 0 and 255. Assigning | 46 | with major number 81 and a minor number between 0 and 255. Minor numbers |
47 | minor numbers to V4L2 devices is entirely up to the system administrator, | 47 | are allocated dynamically unless the kernel is compiled with the kernel |
48 | this is primarily intended to solve conflicts between devices.<footnote> | 48 | option CONFIG_VIDEO_FIXED_MINOR_RANGES. In that case minor numbers are |
49 | <para>Access permissions are associated with character | 49 | allocated in ranges depending on the device node type (video, radio, etc.).</para> |
50 | device special files, hence we must ensure device numbers cannot | 50 | |
51 | change with the module load order. To this end minor numbers are no | 51 | <para>Many drivers support "video_nr", "radio_nr" or "vbi_nr" |
52 | longer automatically assigned by the "videodev" module as in V4L but | 52 | module options to select specific video/radio/vbi node numbers. This allows |
53 | requested by the driver. The defaults will suffice for most people | 53 | the user to request that the device node is named e.g. /dev/video5 instead |
54 | unless two drivers compete for the same minor numbers.</para> | 54 | of leaving it to chance. When the driver supports multiple devices of the same |
55 | </footnote> The module options to select minor numbers are named | 55 | type more than one device node number can be assigned, separated by commas: |
56 | after the device special file with a "_nr" suffix. For example "video_nr" | 56 | <informalexample> |
57 | for <filename>/dev/video</filename> video capture devices. The number is | ||
58 | an offset to the base minor number associated with the device type. | ||
59 | <footnote> | ||
60 | <para>In earlier versions of the V4L2 API the module options | ||
61 | where named after the device special file with a "unit_" prefix, expressing | ||
62 | the minor number itself, not an offset. Rationale for this change is unknown. | ||
63 | Lastly the naming and semantics are just a convention among driver writers, | ||
64 | the point to note is that minor numbers are not supposed to be hardcoded | ||
65 | into drivers.</para> | ||
66 | </footnote> When the driver supports multiple devices of the same | ||
67 | type more than one minor number can be assigned, separated by commas: | ||
68 | <informalexample> | ||
69 | <screen> | 57 | <screen> |
70 | > insmod mydriver.o video_nr=0,1 radio_nr=0,1</screen> | 58 | > modprobe mydriver video_nr=0,1 radio_nr=0,1</screen> |
71 | </informalexample></para> | 59 | </informalexample></para> |
72 | 60 | ||
73 | <para>In <filename>/etc/modules.conf</filename> this may be | 61 | <para>In <filename>/etc/modules.conf</filename> this may be |
74 | written as: <informalexample> | 62 | written as: <informalexample> |
75 | <screen> | 63 | <screen> |
76 | alias char-major-81-0 mydriver | 64 | options mydriver video_nr=0,1 radio_nr=0,1 |
77 | alias char-major-81-1 mydriver | ||
78 | alias char-major-81-64 mydriver <co id="alias" /> | ||
79 | options mydriver video_nr=0,1 radio_nr=0,1 <co id="options" /> | ||
80 | </screen> | 65 | </screen> |
81 | <calloutlist> | 66 | </informalexample> When no device node number is given as module |
82 | <callout arearefs="alias"> | 67 | option the driver supplies a default.</para> |
83 | <para>When an application attempts to open a device | 68 | |
84 | special file with major number 81 and minor number 0, 1, or 64, load | 69 | <para>Normally udev will create the device nodes in /dev automatically |
85 | "mydriver" (and the "videodev" module it depends upon).</para> | 70 | for you. If udev is not installed, then you need to enable the |
86 | </callout> | 71 | CONFIG_VIDEO_FIXED_MINOR_RANGES kernel option in order to be able to correctly |
87 | <callout arearefs="options"> | 72 | relate a minor number to a device node number. I.e., you need to be certain |
88 | <para>Register the first two video capture devices with | 73 | that minor number 5 maps to device node name video5. With this kernel option |
89 | minor number 0 and 1 (base number is 0), the first two radio device | 74 | different device types have different minor number ranges. These ranges are |
90 | with minor number 64 and 65 (base 64).</para> | 75 | listed in <xref linkend="devices" />. |
91 | </callout> | ||
92 | </calloutlist> | ||
93 | </informalexample> When no minor number is given as module | ||
94 | option the driver supplies a default. <xref linkend="devices" /> | ||
95 | recommends the base minor numbers to be used for the various device | ||
96 | types. Obviously minor numbers must be unique. When the number is | ||
97 | already in use the <emphasis>offending device</emphasis> will not be | ||
98 | registered. <!-- Blessed by Linus Torvalds on | ||
99 | linux-kernel@vger.kernel.org, 2002-11-20. --></para> | ||
100 | |||
101 | <para>By convention system administrators create various | ||
102 | character device special files with these major and minor numbers in | ||
103 | the <filename>/dev</filename> directory. The names recommended for the | ||
104 | different V4L2 device types are listed in <xref linkend="devices" />. | ||
105 | </para> | 76 | </para> |
106 | 77 | ||
107 | <para>The creation of character special files (with | 78 | <para>The creation of character special files (with |
@@ -110,85 +81,66 @@ devices cannot be opened by major and minor number. That means | |||
110 | applications cannot <emphasis>reliable</emphasis> scan for loaded or | 81 | applications cannot <emphasis>reliable</emphasis> scan for loaded or |
111 | installed drivers. The user must enter a device name, or the | 82 | installed drivers. The user must enter a device name, or the |
112 | application can try the conventional device names.</para> | 83 | application can try the conventional device names.</para> |
113 | |||
114 | <para>Under the device filesystem (devfs) the minor number | ||
115 | options are ignored. V4L2 drivers (or by proxy the "videodev" module) | ||
116 | automatically create the required device files in the | ||
117 | <filename>/dev/v4l</filename> directory using the conventional device | ||
118 | names above.</para> | ||
119 | </section> | 84 | </section> |
120 | 85 | ||
121 | <section id="related"> | 86 | <section id="related"> |
122 | <title>Related Devices</title> | 87 | <title>Related Devices</title> |
123 | 88 | ||
124 | <para>Devices can support several related functions. For example | 89 | <para>Devices can support several functions. For example |
125 | video capturing, video overlay and VBI capturing are related because | 90 | video capturing, VBI capturing and radio support.</para> |
126 | these functions share, amongst other, the same video input and tuner | 91 | |
127 | frequency. V4L and earlier versions of V4L2 used the same device name | 92 | <para>The V4L2 API creates different nodes for each of these functions.</para> |
128 | and minor number for video capturing and overlay, but different ones | 93 | |
129 | for VBI. Experience showed this approach has several problems<footnote> | 94 | <para>The V4L2 API was designed with the idea that one device node could support |
130 | <para>Given a device file name one cannot reliable find | 95 | all functions. However, in practice this never worked: this 'feature' |
131 | related devices. For once names are arbitrary and in a system with | 96 | was never used by applications and many drivers did not support it and if |
132 | multiple devices, where only some support VBI capturing, a | 97 | they did it was certainly never tested. In addition, switching a device |
133 | <filename>/dev/video2</filename> is not necessarily related to | 98 | node between different functions only works when using the streaming I/O |
134 | <filename>/dev/vbi2</filename>. The V4L | 99 | API, not with the read()/write() API.</para> |
135 | <constant>VIDIOCGUNIT</constant> ioctl would require a search for a | 100 | |
136 | device file with a particular major and minor number.</para> | 101 | <para>Today each device node supports just one function.</para> |
137 | </footnote>, and to make things worse the V4L videodev module | ||
138 | used to prohibit multiple opens of a device.</para> | ||
139 | |||
140 | <para>As a remedy the present version of the V4L2 API relaxed the | ||
141 | concept of device types with specific names and minor numbers. For | ||
142 | compatibility with old applications drivers must still register different | ||
143 | minor numbers to assign a default function to the device. But if related | ||
144 | functions are supported by the driver they must be available under all | ||
145 | registered minor numbers. The desired function can be selected after | ||
146 | opening the device as described in <xref linkend="devices" />.</para> | ||
147 | |||
148 | <para>Imagine a driver supporting video capturing, video | ||
149 | overlay, raw VBI capturing, and FM radio reception. It registers three | ||
150 | devices with minor number 0, 64 and 224 (this numbering scheme is | ||
151 | inherited from the V4L API). Regardless if | ||
152 | <filename>/dev/video</filename> (81, 0) or | ||
153 | <filename>/dev/vbi</filename> (81, 224) is opened the application can | ||
154 | select any one of the video capturing, overlay or VBI capturing | ||
155 | functions. Without programming (e. g. reading from the device | ||
156 | with <application>dd</application> or <application>cat</application>) | ||
157 | <filename>/dev/video</filename> captures video images, while | ||
158 | <filename>/dev/vbi</filename> captures raw VBI data. | ||
159 | <filename>/dev/radio</filename> (81, 64) is invariable a radio device, | ||
160 | unrelated to the video functions. Being unrelated does not imply the | ||
161 | devices can be used at the same time, however. The &func-open; | ||
162 | function may very well return an &EBUSY;.</para> | ||
163 | 102 | ||
164 | <para>Besides video input or output the hardware may also | 103 | <para>Besides video input or output the hardware may also |
165 | support audio sampling or playback. If so, these functions are | 104 | support audio sampling or playback. If so, these functions are |
166 | implemented as OSS or ALSA PCM devices and eventually OSS or ALSA | 105 | implemented as ALSA PCM devices with optional ALSA audio mixer |
167 | audio mixer. The V4L2 API makes no provisions yet to find these | 106 | devices.</para> |
168 | related devices. If you have an idea please write to the linux-media | 107 | |
169 | mailing list: &v4l-ml;.</para> | 108 | <para>One problem with all these devices is that the V4L2 API |
109 | makes no provisions to find these related devices. Some really | ||
110 | complex devices use the Media Controller (see <xref linkend="media_controller" />) | ||
111 | which can be used for this purpose. But most drivers do not use it, | ||
112 | and while some code exists that uses sysfs to discover related devices | ||
113 | (see libmedia_dev in the <ulink url="http://git.linuxtv.org/v4l-utils/">v4l-utils</ulink> | ||
114 | git repository), there is no library yet that can provide a single API towards | ||
115 | both Media Controller-based devices and devices that do not use the Media Controller. | ||
116 | If you want to work on this please write to the linux-media mailing list: &v4l-ml;.</para> | ||
170 | </section> | 117 | </section> |
171 | 118 | ||
172 | <section> | 119 | <section> |
173 | <title>Multiple Opens</title> | 120 | <title>Multiple Opens</title> |
174 | 121 | ||
175 | <para>In general, V4L2 devices can be opened more than once. | 122 | <para>V4L2 devices can be opened more than once.<footnote><para> |
123 | There are still some old and obscure drivers that have not been updated to | ||
124 | allow for multiple opens. This implies that for such drivers &func-open; can | ||
125 | return an &EBUSY; when the device is already in use.</para></footnote> | ||
176 | When this is supported by the driver, users can for example start a | 126 | When this is supported by the driver, users can for example start a |
177 | "panel" application to change controls like brightness or audio | 127 | "panel" application to change controls like brightness or audio |
178 | volume, while another application captures video and audio. In other words, panel | 128 | volume, while another application captures video and audio. In other words, panel |
179 | applications are comparable to an OSS or ALSA audio mixer application. | 129 | applications are comparable to an ALSA audio mixer application. |
180 | When a device supports multiple functions like capturing and overlay | 130 | Just opening a V4L2 device should not change the state of the device.<footnote> |
181 | <emphasis>simultaneously</emphasis>, multiple opens allow concurrent | 131 | <para>Unfortunately, opening a radio device often switches the state of the |
182 | use of the device by forked processes or specialized applications.</para> | 132 | device to radio mode in many drivers. This behavior should be fixed eventually |
183 | 133 | as it violates the V4L2 specification.</para></footnote></para> | |
184 | <para>Multiple opens are optional, although drivers should | 134 | |
185 | permit at least concurrent accesses without data exchange, &ie; panel | 135 | <para>Once an application has allocated the memory buffers needed for |
186 | applications. This implies &func-open; can return an &EBUSY; when the | 136 | streaming data (by calling the &VIDIOC-REQBUFS; or &VIDIOC-CREATE-BUFS; ioctls, |
187 | device is already in use, as well as &func-ioctl; functions initiating | 137 | or implicitly by calling the &func-read; or &func-write; functions) that |
188 | data exchange (namely the &VIDIOC-S-FMT; ioctl), and the &func-read; | 138 | application (filehandle) becomes the owner of the device. It is no longer |
189 | and &func-write; functions.</para> | 139 | allowed to make changes that would affect the buffer sizes (e.g. by calling |
190 | 140 | the &VIDIOC-S-FMT; ioctl) and other applications are no longer allowed to allocate | |
191 | <para>Mere opening a V4L2 device does not grant exclusive | 141 | buffers or start or stop streaming. The &EBUSY; will be returned instead.</para> |
142 | |||
143 | <para>Merely opening a V4L2 device does not grant exclusive | ||
192 | access.<footnote> | 144 | access.<footnote> |
193 | <para>Drivers could recognize the | 145 | <para>Drivers could recognize the |
194 | <constant>O_EXCL</constant> open flag. Presently this is not required, | 146 | <constant>O_EXCL</constant> open flag. Presently this is not required, |
@@ -206,12 +158,7 @@ additional access privileges using the priority mechanism described in | |||
206 | <para>V4L2 drivers should not support multiple applications | 158 | <para>V4L2 drivers should not support multiple applications |
207 | reading or writing the same data stream on a device by copying | 159 | reading or writing the same data stream on a device by copying |
208 | buffers, time multiplexing or similar means. This is better handled by | 160 | buffers, time multiplexing or similar means. This is better handled by |
209 | a proxy application in user space. When the driver supports stream | 161 | a proxy application in user space.</para> |
210 | sharing anyway it must be implemented transparently. The V4L2 API does | ||
211 | not specify how conflicts are solved. <!-- For example O_EXCL when the | ||
212 | application does not want to be preempted, PROT_READ mmapped buffers | ||
213 | which can be mapped twice, what happens when image formats do not | ||
214 | match etc.--></para> | ||
215 | </section> | 162 | </section> |
216 | 163 | ||
217 | <section> | 164 | <section> |
diff --git a/Documentation/DocBook/media/v4l/v4l2.xml b/Documentation/DocBook/media/v4l/v4l2.xml index 087e8465e09a..6bf35328dcbf 100644 --- a/Documentation/DocBook/media/v4l/v4l2.xml +++ b/Documentation/DocBook/media/v4l/v4l2.xml | |||
@@ -145,7 +145,7 @@ applications. --> | |||
145 | <revnumber>3.15</revnumber> | 145 | <revnumber>3.15</revnumber> |
146 | <date>2014-02-03</date> | 146 | <date>2014-02-03</date> |
147 | <authorinitials>hv</authorinitials> | 147 | <authorinitials>hv</authorinitials> |
148 | <revremark>Update several sections of "Common API Elements": | 148 | <revremark>Update several sections of "Common API Elements": "Opening and Closing Devices" |
149 | "Querying Capabilities", "Application Priority", "Video Inputs and Outputs", "Audio Inputs and Outputs" | 149 | "Querying Capabilities", "Application Priority", "Video Inputs and Outputs", "Audio Inputs and Outputs" |
150 | "Tuners and Modulators", "Video Standards" and "Digital Video (DV) Timings". | 150 | "Tuners and Modulators", "Video Standards" and "Digital Video (DV) Timings". |
151 | </revremark> | 151 | </revremark> |