Debian Codegraph @

utils/libmedia_dev/README

raw
1 1) Why such library is needed
2 ==========================
3
4 Media devices can be very complex. It is not trivial how to detect what's the
5 other devices associated with a video node.
6
7 This API provides the capabilities of getting the associated devices with a
8 video node.
9
10 It is currently implemented at http://git.linuxtv.org/v4l-utils.git, at the
11 utils/libmedia_dev/. After validating it, it makes sense to move it to be
12 part of libv4l.
13
14 2) Provided functions
15 ==================
16
17 The API defines a macro with its current version. Currently, it is:
18
19 #define GET_MEDIA_DEVICES_VERSION 0x0104
20
21 Each device type that is known by the API is defined inside enum device_type,
22 currently defined as:
23
24 enum device_type {
25 UNKNOWN = 65535,
26 NONE = 65534,
27 MEDIA_V4L_VIDEO = 0,
28 MEDIA_V4L_VBI,
29 MEDIA_DVB_FRONTEND,
30 MEDIA_DVB_DEMUX,
31 MEDIA_DVB_DVR,
32 MEDIA_DVB_NET,
33 MEDIA_DVB_CA,
34 MEDIA_SND_CARD,
35 MEDIA_SND_CAP,
36 MEDIA_SND_OUT,
37 MEDIA_SND_CONTROL,
38 MEDIA_SND_HW,
39 };
40
41 The first function discovers the media devices and stores the information
42 at an internal representation. Such representation should be opaque to
43 the userspace applications, as it can change from version to version.
44
45 2.1) Device discover and release functions
46 =====================================
47
48 The device discover is done by calling:
49
50 void *discover_media_devices(void);
51
52 In order to release the opaque structure, a free method is provided:
53
54 void free_media_devices(void *opaque);
55
56 2.2) Functions to help printing the discovered devices
57 =================================================
58
59 In order to allow printing the device type, a function is provided to
60 convert from enum device_type into string:
61
62 char *media_device_type(enum device_type type);
63
64 All discovered devices can be displayed by calling:
65
66 void display_media_devices(void *opaque);
67
68 2.3) Functions to get device associations
69 ====================================
70
71 The API provides 3 methods to get the associated devices:
72
73 a) get_associated_device: returns the next device associated with another one
74
75 char *get_associated_device(void *opaque,
76 char *last_seek,
77 enum device_type desired_type,
78 char *seek_device,
79 enum device_type seek_type);
80 The parameters are:
81
82 opaque: media devices opaque descriptor
83 last_seek: last seek result. Use NULL to get the first result
84 desired_type: type of the desired device
85 seek_device: name of the device with you want to get an association.
86 seek_type: type of the seek device. Using NONE produces the same
87 result of using NULL for the seek_device.
88
89 This function seeks inside the media_devices struct for the next device
90 that it is associated with a seek parameter.
91 It can be used to get an alsa device associated with a video device. If
92 the seek_device is NULL or seek_type is NONE, it will just search for
93 devices of the desired_type.
94
95
96 b) fget_associated_device: returns the next device associated with another one
97
98 char *fget_associated_device(void *opaque,
99 char *last_seek,
100 enum device_type desired_type,
101 int fd_seek_device,
102 enum device_type seek_type);
103
104 The parameters are:
105
106 opaque: media devices opaque descriptor
107 last_seek: last seek result. Use NULL to get the first result
108 desired_type: type of the desired device
109 fd_seek_device: file handler for the device where the association will
110 be made
111 seek_type: type of the seek device. Using NONE produces the same
112 result of using NULL for the seek_device.
113
114 This function seeks inside the media_devices struct for the next device
115 that it is associated with a seek parameter.
116 It can be used to get an alsa device associated with an open file descriptor
117
118 c) get_not_associated_device: Returns the next device not associated with
119 an specific device type.
120
121 char *get_not_associated_device(void *opaque,
122 char *last_seek,
123 enum device_type desired_type,
124 enum device_type not_desired_type);
125
126 The parameters are:
127
128 opaque: media devices opaque descriptor
129 last_seek: last seek result. Use NULL to get the first result
130 desired_type: type of the desired device
131 not_desired_type: type of the seek device
132
133 This function seeks inside the media_devices struct for the next physical
134 device that doesn't support a non_desired type.
135 This method is useful for example to return the audio devices that are
136 provided by the motherboard.
137
138 3) Examples with typical usecases
139 ==============================
140
141 a) Just displaying all media devices:
142
143 void *md = discover_media_devices();
144 display_media_devices(md);
145 free_media_devices(md);
146
147 The devices will be shown at the order they appear at the computer buses.
148
149 b) For video0, prints the associated alsa capture device(s):
150
151 void *md = discover_media_devices();
152 char *devname = NULL, video0 = "/dev/video0";
153 do {
154 devname = get_associated_device(md, devname, MEDIA_SND_CAP,
155 video0, MEDIA_V4L_VIDEO);
156 if (devname)
157 printf("Alsa capture: %s\n", devname);
158 } while (devname);
159 free_media_devices(md);
160
161 Note: the video0 string can be declarated as "/dev/video0" or as just "video0",
162 as the search functions will discard any patch on it.
163
164 c) Get the alsa capture device associated with an opened file descriptor:
165
166 int fd = open("/dev/video0", O_RDWR);
167 ...
168 void *md = discover_media_devices();
169 vid = fget_associated_device(md, NULL, MEDIA_SND_CAP, fd,
170 MEDIA_V4L_VIDEO);
171 printf("\n\nAlsa device = %s\n", vid);
172 close(fd);
173 free_media_devices(md);
174
175 d) Get the mainboard alsa playback devices:
176
177 char *devname = NULL;
178 void *md = discover_media_devices();
179 do {
180 devname = get_not_associated_device(md, devname, MEDIA_SND_OUT,
181 MEDIA_V4L_VIDEO);
182 if (devname)
183 printf("Alsa playback: %s\n", devname);
184 } while (devname);
185 free_media_devices(md);
186
187 e) Get all video devices:
188
189 void *md = discover_media_devices();
190 char *vid = NULL;
191 do {
192 vid = get_associated_device(md, vid, MEDIA_V4L_VIDEO,
193 NULL, NONE);
194 if (!vid)
195 break;
196 printf("Video device: %s\n", vid);
197 } while (vid);
198 free_media_devices(md);