FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
avdevice.h
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #ifndef AVDEVICE_AVDEVICE_H
20 #define AVDEVICE_AVDEVICE_H
21 
22 #include "version.h"
23 
24 /**
25  * @file
26  * @ingroup lavd
27  * Main libavdevice API header
28  */
29 
30 /**
31  * @defgroup lavd libavdevice
32  * Special devices muxing/demuxing library.
33  *
34  * Libavdevice is a complementary library to @ref libavf "libavformat". It
35  * provides various "special" platform-specific muxers and demuxers, e.g. for
36  * grabbing devices, audio capture and playback etc. As a consequence, the
37  * (de)muxers in libavdevice are of the AVFMT_NOFILE type (they use their own
38  * I/O functions). The filename passed to avformat_open_input() often does not
39  * refer to an actually existing file, but has some special device-specific
40  * meaning - e.g. for x11grab it is the display name.
41  *
42  * To use libavdevice, simply call avdevice_register_all() to register all
43  * compiled muxers and demuxers. They all use standard libavformat API.
44  *
45  * @{
46  */
47 
48 #include "libavutil/log.h"
49 #include "libavutil/opt.h"
50 #include "libavutil/dict.h"
51 #include "libavformat/avformat.h"
52 
53 /**
54  * Return the LIBAVDEVICE_VERSION_INT constant.
55  */
56 unsigned avdevice_version(void);
57 
58 /**
59  * Return the libavdevice build-time configuration.
60  */
61 const char *avdevice_configuration(void);
62 
63 /**
64  * Return the libavdevice license.
65  */
66 const char *avdevice_license(void);
67 
68 /**
69  * Initialize libavdevice and register all the input and output devices.
70  * @warning This function is not thread safe.
71  */
72 void avdevice_register_all(void);
73 
74 /**
75  * Audio input devices iterator.
76  *
77  * If d is NULL, returns the first registered input audio/video device,
78  * if d is non-NULL, returns the next registered input audio/video device after d
79  * or NULL if d is the last one.
80  */
82 
83 /**
84  * Video input devices iterator.
85  *
86  * If d is NULL, returns the first registered input audio/video device,
87  * if d is non-NULL, returns the next registered input audio/video device after d
88  * or NULL if d is the last one.
89  */
91 
92 /**
93  * Audio output devices iterator.
94  *
95  * If d is NULL, returns the first registered output audio/video device,
96  * if d is non-NULL, returns the next registered output audio/video device after d
97  * or NULL if d is the last one.
98  */
100 
101 /**
102  * Video output devices iterator.
103  *
104  * If d is NULL, returns the first registered output audio/video device,
105  * if d is non-NULL, returns the next registered output audio/video device after d
106  * or NULL if d is the last one.
107  */
109 
110 typedef struct AVDeviceRect {
111  int x; /**< x coordinate of top left corner */
112  int y; /**< y coordinate of top left corner */
113  int width; /**< width */
114  int height; /**< height */
115 } AVDeviceRect;
116 
117 /**
118  * Message types used by avdevice_app_to_dev_control_message().
119  */
121  /**
122  * Dummy message.
123  */
124  AV_APP_TO_DEV_NONE = MKBETAG('N','O','N','E'),
125 
126  /**
127  * Window size change message.
128  *
129  * Message is sent to the device every time the application changes the size
130  * of the window device renders to.
131  * Message should also be sent right after window is created.
132  *
133  * data: AVDeviceRect: new window size.
134  */
135  AV_APP_TO_DEV_WINDOW_SIZE = MKBETAG('G','E','O','M'),
136 
137  /**
138  * Repaint request message.
139  *
140  * Message is sent to the device when window has to be repainted.
141  *
142  * data: AVDeviceRect: area required to be repainted.
143  * NULL: whole area is required to be repainted.
144  */
146 
147  /**
148  * Request pause/play.
149  *
150  * Application requests pause/unpause playback.
151  * Mostly usable with devices that have internal buffer.
152  * By default devices are not paused.
153  *
154  * data: NULL
155  */
156  AV_APP_TO_DEV_PAUSE = MKBETAG('P', 'A', 'U', ' '),
157  AV_APP_TO_DEV_PLAY = MKBETAG('P', 'L', 'A', 'Y'),
158  AV_APP_TO_DEV_TOGGLE_PAUSE = MKBETAG('P', 'A', 'U', 'T'),
159 
160  /**
161  * Volume control message.
162  *
163  * Set volume level. It may be device-dependent if volume
164  * is changed per stream or system wide. Per stream volume
165  * change is expected when possible.
166  *
167  * data: double: new volume with range of 0.0 - 1.0.
168  */
169  AV_APP_TO_DEV_SET_VOLUME = MKBETAG('S', 'V', 'O', 'L'),
170 
171  /**
172  * Mute control messages.
173  *
174  * Change mute state. It may be device-dependent if mute status
175  * is changed per stream or system wide. Per stream mute status
176  * change is expected when possible.
177  *
178  * data: NULL.
179  */
180  AV_APP_TO_DEV_MUTE = MKBETAG(' ', 'M', 'U', 'T'),
181  AV_APP_TO_DEV_UNMUTE = MKBETAG('U', 'M', 'U', 'T'),
182  AV_APP_TO_DEV_TOGGLE_MUTE = MKBETAG('T', 'M', 'U', 'T'),
183 
184  /**
185  * Get volume/mute messages.
186  *
187  * Force the device to send AV_DEV_TO_APP_VOLUME_LEVEL_CHANGED or
188  * AV_DEV_TO_APP_MUTE_STATE_CHANGED command respectively.
189  *
190  * data: NULL.
191  */
192  AV_APP_TO_DEV_GET_VOLUME = MKBETAG('G', 'V', 'O', 'L'),
193  AV_APP_TO_DEV_GET_MUTE = MKBETAG('G', 'M', 'U', 'T'),
194 };
195 
196 /**
197  * Message types used by avdevice_dev_to_app_control_message().
198  */
200  /**
201  * Dummy message.
202  */
203  AV_DEV_TO_APP_NONE = MKBETAG('N','O','N','E'),
204 
205  /**
206  * Create window buffer message.
207  *
208  * Device requests to create a window buffer. Exact meaning is device-
209  * and application-dependent. Message is sent before rendering first
210  * frame and all one-shot initializations should be done here.
211  * Application is allowed to ignore preferred window buffer size.
212  *
213  * @note: Application is obligated to inform about window buffer size
214  * with AV_APP_TO_DEV_WINDOW_SIZE message.
215  *
216  * data: AVDeviceRect: preferred size of the window buffer.
217  * NULL: no preferred size of the window buffer.
218  */
220 
221  /**
222  * Prepare window buffer message.
223  *
224  * Device requests to prepare a window buffer for rendering.
225  * Exact meaning is device- and application-dependent.
226  * Message is sent before rendering of each frame.
227  *
228  * data: NULL.
229  */
231 
232  /**
233  * Display window buffer message.
234  *
235  * Device requests to display a window buffer.
236  * Message is sent when new frame is ready to be displayed.
237  * Usually buffers need to be swapped in handler of this message.
238  *
239  * data: NULL.
240  */
242 
243  /**
244  * Destroy window buffer message.
245  *
246  * Device requests to destroy a window buffer.
247  * Message is sent when device is about to be destroyed and window
248  * buffer is not required anymore.
249  *
250  * data: NULL.
251  */
253 
254  /**
255  * Buffer fullness status messages.
256  *
257  * Device signals buffer overflow/underflow.
258  *
259  * data: NULL.
260  */
263 
264  /**
265  * Buffer readable/writable.
266  *
267  * Device informs that buffer is readable/writable.
268  * When possible, device informs how many bytes can be read/write.
269  *
270  * @warning Device may not inform when number of bytes than can be read/write changes.
271  *
272  * data: int64_t: amount of bytes available to read/write.
273  * NULL: amount of bytes available to read/write is not known.
274  */
277 
278  /**
279  * Mute state change message.
280  *
281  * Device informs that mute state has changed.
282  *
283  * data: int: 0 for not muted state, non-zero for muted state.
284  */
286 
287  /**
288  * Volume level change message.
289  *
290  * Device informs that volume level has changed.
291  *
292  * data: double: new volume with range of 0.0 - 1.0.
293  */
295 };
296 
297 /**
298  * Send control message from application to device.
299  *
300  * @param s device context.
301  * @param type message type.
302  * @param data message data. Exact type depends on message type.
303  * @param data_size size of message data.
304  * @return >= 0 on success, negative on error.
305  * AVERROR(ENOSYS) when device doesn't implement handler of the message.
306  */
309  void *data, size_t data_size);
310 
311 /**
312  * Send control message from device to application.
313  *
314  * @param s device context.
315  * @param type message type.
316  * @param data message data. Can be NULL.
317  * @param data_size size of message data.
318  * @return >= 0 on success, negative on error.
319  * AVERROR(ENOSYS) when application doesn't implement handler of the message.
320  */
323  void *data, size_t data_size);
324 
325 /**
326  * Following API allows user to probe device capabilities (supported codecs,
327  * pixel formats, sample formats, resolutions, channel counts, etc).
328  * It is build on top op AVOption API.
329  * Queried capabilities make it possible to set up converters of video or audio
330  * parameters that fit to the device.
331  *
332  * List of capabilities that can be queried:
333  * - Capabilities valid for both audio and video devices:
334  * - codec: supported audio/video codecs.
335  * type: AV_OPT_TYPE_INT (AVCodecID value)
336  * - Capabilities valid for audio devices:
337  * - sample_format: supported sample formats.
338  * type: AV_OPT_TYPE_INT (AVSampleFormat value)
339  * - sample_rate: supported sample rates.
340  * type: AV_OPT_TYPE_INT
341  * - channels: supported number of channels.
342  * type: AV_OPT_TYPE_INT
343  * - channel_layout: supported channel layouts.
344  * type: AV_OPT_TYPE_INT64
345  * - Capabilities valid for video devices:
346  * - pixel_format: supported pixel formats.
347  * type: AV_OPT_TYPE_INT (AVPixelFormat value)
348  * - window_size: supported window sizes (describes size of the window size presented to the user).
349  * type: AV_OPT_TYPE_IMAGE_SIZE
350  * - frame_size: supported frame sizes (describes size of provided video frames).
351  * type: AV_OPT_TYPE_IMAGE_SIZE
352  * - fps: supported fps values
353  * type: AV_OPT_TYPE_RATIONAL
354  *
355  * Value of the capability may be set by user using av_opt_set() function
356  * and AVDeviceCapabilitiesQuery object. Following queries will
357  * limit results to the values matching already set capabilities.
358  * For example, setting a codec may impact number of formats or fps values
359  * returned during next query. Setting invalid value may limit results to zero.
360  *
361  * Example of the usage basing on opengl output device:
362  *
363  * @code
364  * AVFormatContext *oc = NULL;
365  * AVDeviceCapabilitiesQuery *caps = NULL;
366  * AVOptionRanges *ranges;
367  * int ret;
368  *
369  * if ((ret = avformat_alloc_output_context2(&oc, NULL, "opengl", NULL)) < 0)
370  * goto fail;
371  * if (avdevice_capabilities_create(&caps, oc, NULL) < 0)
372  * goto fail;
373  *
374  * //query codecs
375  * if (av_opt_query_ranges(&ranges, caps, "codec", AV_OPT_MULTI_COMPONENT_RANGE)) < 0)
376  * goto fail;
377  * //pick codec here and set it
378  * av_opt_set(caps, "codec", AV_CODEC_ID_RAWVIDEO, 0);
379  *
380  * //query format
381  * if (av_opt_query_ranges(&ranges, caps, "pixel_format", AV_OPT_MULTI_COMPONENT_RANGE)) < 0)
382  * goto fail;
383  * //pick format here and set it
384  * av_opt_set(caps, "pixel_format", AV_PIX_FMT_YUV420P, 0);
385  *
386  * //query and set more capabilities
387  *
388  * fail:
389  * //clean up code
390  * avdevice_capabilities_free(&query, oc);
391  * avformat_free_context(oc);
392  * @endcode
393  */
394 
395 /**
396  * Structure describes device capabilities.
397  *
398  * It is used by devices in conjunction with av_device_capabilities AVOption table
399  * to implement capabilities probing API based on AVOption API. Should not be used directly.
400  */
408  int channels;
409  int64_t channel_layout;
416 
417 /**
418  * AVOption table used by devices to implement device capabilities API. Should not be used by a user.
419  */
420 extern const AVOption av_device_capabilities[];
421 
422 /**
423  * Initialize capabilities probing API based on AVOption API.
424  *
425  * avdevice_capabilities_free() must be called when query capabilities API is
426  * not used anymore.
427  *
428  * @param[out] caps Device capabilities data. Pointer to a NULL pointer must be passed.
429  * @param s Context of the device.
430  * @param device_options An AVDictionary filled with device-private options.
431  * On return this parameter will be destroyed and replaced with a dict
432  * containing options that were not found. May be NULL.
433  * The same options must be passed later to avformat_write_header() for output
434  * devices or avformat_open_input() for input devices, or at any other place
435  * that affects device-private options.
436  *
437  * @return >= 0 on success, negative otherwise.
438  */
440  AVDictionary **device_options);
441 
442 /**
443  * Free resources created by avdevice_capabilities_create()
444  *
445  * @param caps Device capabilities data to be freed.
446  * @param s Context of the device.
447  */
449 
450 /**
451  * Structure describes basic parameters of the device.
452  */
453 typedef struct AVDeviceInfo {
454  char *device_name; /**< device name, format depends on device */
455  char *device_description; /**< human friendly name */
456 } AVDeviceInfo;
457 
458 /**
459  * List of devices.
460  */
461 typedef struct AVDeviceInfoList {
462  AVDeviceInfo **devices; /**< list of autodetected devices */
463  int nb_devices; /**< number of autodetected devices */
464  int default_device; /**< index of default device or -1 if no default */
466 
467 /**
468  * List devices.
469  *
470  * Returns available device names and their parameters.
471  *
472  * @note: Some devices may accept system-dependent device names that cannot be
473  * autodetected. The list returned by this function cannot be assumed to
474  * be always completed.
475  *
476  * @param s device context.
477  * @param[out] device_list list of autodetected devices.
478  * @return count of autodetected devices, negative on error.
479  */
480 int avdevice_list_devices(struct AVFormatContext *s, AVDeviceInfoList **device_list);
481 
482 /**
483  * Convenient function to free result of avdevice_list_devices().
484  *
485  * @param devices device list to be freed.
486  */
487 void avdevice_free_list_devices(AVDeviceInfoList **device_list);
488 
489 /**
490  * List devices.
491  *
492  * Returns available device names and their parameters.
493  * These are convinient wrappers for avdevice_list_devices().
494  * Device context is allocated and deallocated internally.
495  *
496  * @param device device format. May be NULL if device name is set.
497  * @param device_name device name. May be NULL if device format is set.
498  * @param device_options An AVDictionary filled with device-private options. May be NULL.
499  * The same options must be passed later to avformat_write_header() for output
500  * devices or avformat_open_input() for input devices, or at any other place
501  * that affects device-private options.
502  * @param[out] device_list list of autodetected devices
503  * @return count of autodetected devices, negative on error.
504  * @note device argument takes precedence over device_name when both are set.
505  */
506 int avdevice_list_input_sources(struct AVInputFormat *device, const char *device_name,
507  AVDictionary *device_options, AVDeviceInfoList **device_list);
508 int avdevice_list_output_sinks(struct AVOutputFormat *device, const char *device_name,
509  AVDictionary *device_options, AVDeviceInfoList **device_list);
510 
511 /**
512  * @}
513  */
514 
515 #endif /* AVDEVICE_AVDEVICE_H */
Window size change message.
Definition: avdevice.h:135
const char * avdevice_configuration(void)
Return the libavdevice build-time configuration.
Definition: avdevice.c:70
Repaint request message.
Definition: avdevice.h:145
Structure describes basic parameters of the device.
Definition: avdevice.h:453
const char * s
Definition: avisynth_c.h:768
AVOutputFormat * av_output_audio_device_next(AVOutputFormat *d)
Audio output devices iterator.
Definition: avdevice.c:115
Prepare window buffer message.
Definition: avdevice.h:230
int x
x coordinate of top left corner
Definition: avdevice.h:111
Dummy message.
Definition: avdevice.h:203
AVOption.
Definition: opt.h:245
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
char * device_description
human friendly name
Definition: avdevice.h:455
void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s)
Free resources created by avdevice_capabilities_create()
Definition: avdevice.c:172
char * device_name
device name, format depends on device
Definition: avdevice.h:454
Volume level change message.
Definition: avdevice.h:294
int avdevice_list_devices(struct AVFormatContext *s, AVDeviceInfoList **device_list)
List devices.
Definition: avdevice.c:187
Buffer fullness status messages.
Definition: avdevice.h:261
Display window buffer message.
Definition: avdevice.h:241
Format I/O context.
Definition: avformat.h:1338
Create window buffer message.
Definition: avdevice.h:219
int avdevice_dev_to_app_control_message(struct AVFormatContext *s, enum AVDevToAppMessageType type, void *data, size_t data_size)
Send control message from device to application.
Definition: avdevice.c:135
Public dictionary API.
int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s, AVDictionary **device_options)
Initialize capabilities probing API based on AVOption API.
Definition: avdevice.c:143
AVDevToAppMessageType
Message types used by avdevice_dev_to_app_control_message().
Definition: avdevice.h:199
void avdevice_free_list_devices(AVDeviceInfoList **device_list)
Convenient function to free result of avdevice_list_devices().
Definition: avdevice.c:250
AVOptions.
AVOutputFormat * av_output_video_device_next(AVOutputFormat *d)
Video output devices iterator.
Definition: avdevice.c:121
Get volume/mute messages.
Definition: avdevice.h:192
const AVClass * av_class
Definition: avdevice.h:402
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:191
enum AVSampleFormat sample_format
Definition: avdevice.h:405
Request pause/play.
Definition: avdevice.h:156
AVDeviceInfo ** devices
list of autodetected devices
Definition: avdevice.h:462
Volume control message.
Definition: avdevice.h:169
int avdevice_list_input_sources(struct AVInputFormat *device, const char *device_name, AVDictionary *device_options, AVDeviceInfoList **device_list)
List devices.
Definition: avdevice.c:228
AVFormatContext * device_context
Definition: avdevice.h:403
Mute control messages.
Definition: avdevice.h:180
int avdevice_list_output_sinks(struct AVOutputFormat *device, const char *device_name, AVDictionary *device_options, AVDeviceInfoList **device_list)
Definition: avdevice.c:239
enum AVPixelFormat pixel_format
Definition: avdevice.h:406
const AVOption av_device_capabilities[]
AVOption table used by devices to implement device capabilities API.
Definition: avdevice.c:36
Dummy message.
Definition: avdevice.h:124
Destroy window buffer message.
Definition: avdevice.h:252
enum AVCodecID codec
Definition: avdevice.h:404
AVInputFormat * av_input_video_device_next(AVInputFormat *d)
Video input devices iterator.
Definition: avdevice.c:109
int height
height
Definition: avdevice.h:114
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:58
GLint GLenum type
Definition: opengl_enc.c:105
Describe the class of an AVClass context structure.
Definition: log.h:67
AVInputFormat * av_input_audio_device_next(AVInputFormat *d)
Audio input devices iterator.
Definition: avdevice.c:103
Rational number (pair of numerator and denominator).
Definition: rational.h:58
const char * avdevice_license(void)
Return the libavdevice license.
Definition: avdevice.c:75
Mute state change message.
Definition: avdevice.h:285
int default_device
index of default device or -1 if no default
Definition: avdevice.h:464
List of devices.
Definition: avdevice.h:461
Libavdevice version macros.
int width
width
Definition: avdevice.h:113
void avdevice_register_all(void)
Initialize libavdevice and register all the input and output devices.
Definition: alldevices.c:40
Main libavformat public API header.
#define MKBETAG(a, b, c, d)
Definition: common.h:343
unsigned avdevice_version(void)
Return the LIBAVDEVICE_VERSION_INT constant.
Definition: avdevice.c:64
Buffer readable/writable.
Definition: avdevice.h:275
AVAppToDevMessageType
Message types used by avdevice_app_to_dev_control_message().
Definition: avdevice.h:120
int y
y coordinate of top left corner
Definition: avdevice.h:112
int avdevice_app_to_dev_control_message(struct AVFormatContext *s, enum AVAppToDevMessageType type, void *data, size_t data_size)
Send control message from application to device.
Definition: avdevice.c:127
int nb_devices
number of autodetected devices
Definition: avdevice.h:463
Following API allows user to probe device capabilities (supported codecs, pixel formats, sample formats, resolutions, channel counts, etc).
Definition: avdevice.h:401
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60