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 xcbgrab 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  * Iterate over all registered output devices.
70  *
71  * @param opaque a pointer where libavdevice will store the iteration state. Must
72  * point to NULL to start the iteration.
73  *
74  * @return the next registered output device or NULL when the iteration is
75  * finished
76  */
77 const AVOutputFormat *av_outdev_iterate(void **opaque);
78 
79 /**
80  * Iterate over all registered input devices.
81  *
82  * @param opaque a pointer where libavdevice will store the iteration state. Must
83  * point to NULL to start the iteration.
84  *
85  * @return the next registered input device or NULL when the iteration is
86  * finished
87  */
88 const AVInputFormat *av_indev_iterate(void **opaque);
89 
90 #if FF_API_NEXT
91 /**
92  * Initialize libavdevice and register all the input and output devices.
93  */
94 void avdevice_register_all(void);
95 
96 /**
97  * Audio input devices iterator.
98  *
99  * If d is NULL, returns the first registered input audio/video device,
100  * if d is non-NULL, returns the next registered input audio/video device after d
101  * or NULL if d is the last one.
102  */
105 
106 /**
107  * Video input devices iterator.
108  *
109  * If d is NULL, returns the first registered input audio/video device,
110  * if d is non-NULL, returns the next registered input audio/video device after d
111  * or NULL if d is the last one.
112  */
115 
116 /**
117  * Audio output devices iterator.
118  *
119  * If d is NULL, returns the first registered output audio/video device,
120  * if d is non-NULL, returns the next registered output audio/video device after d
121  * or NULL if d is the last one.
122  */
125 
126 /**
127  * Video output devices iterator.
128  *
129  * If d is NULL, returns the first registered output audio/video device,
130  * if d is non-NULL, returns the next registered output audio/video device after d
131  * or NULL if d is the last one.
132  */
135 #endif
136 
137 typedef struct AVDeviceRect {
138  int x; /**< x coordinate of top left corner */
139  int y; /**< y coordinate of top left corner */
140  int width; /**< width */
141  int height; /**< height */
142 } AVDeviceRect;
143 
144 /**
145  * Message types used by avdevice_app_to_dev_control_message().
146  */
148  /**
149  * Dummy message.
150  */
151  AV_APP_TO_DEV_NONE = MKBETAG('N','O','N','E'),
152 
153  /**
154  * Window size change message.
155  *
156  * Message is sent to the device every time the application changes the size
157  * of the window device renders to.
158  * Message should also be sent right after window is created.
159  *
160  * data: AVDeviceRect: new window size.
161  */
162  AV_APP_TO_DEV_WINDOW_SIZE = MKBETAG('G','E','O','M'),
163 
164  /**
165  * Repaint request message.
166  *
167  * Message is sent to the device when window has to be repainted.
168  *
169  * data: AVDeviceRect: area required to be repainted.
170  * NULL: whole area is required to be repainted.
171  */
173 
174  /**
175  * Request pause/play.
176  *
177  * Application requests pause/unpause playback.
178  * Mostly usable with devices that have internal buffer.
179  * By default devices are not paused.
180  *
181  * data: NULL
182  */
183  AV_APP_TO_DEV_PAUSE = MKBETAG('P', 'A', 'U', ' '),
184  AV_APP_TO_DEV_PLAY = MKBETAG('P', 'L', 'A', 'Y'),
185  AV_APP_TO_DEV_TOGGLE_PAUSE = MKBETAG('P', 'A', 'U', 'T'),
186 
187  /**
188  * Volume control message.
189  *
190  * Set volume level. It may be device-dependent if volume
191  * is changed per stream or system wide. Per stream volume
192  * change is expected when possible.
193  *
194  * data: double: new volume with range of 0.0 - 1.0.
195  */
196  AV_APP_TO_DEV_SET_VOLUME = MKBETAG('S', 'V', 'O', 'L'),
197 
198  /**
199  * Mute control messages.
200  *
201  * Change mute state. It may be device-dependent if mute status
202  * is changed per stream or system wide. Per stream mute status
203  * change is expected when possible.
204  *
205  * data: NULL.
206  */
207  AV_APP_TO_DEV_MUTE = MKBETAG(' ', 'M', 'U', 'T'),
208  AV_APP_TO_DEV_UNMUTE = MKBETAG('U', 'M', 'U', 'T'),
209  AV_APP_TO_DEV_TOGGLE_MUTE = MKBETAG('T', 'M', 'U', 'T'),
210 
211  /**
212  * Get volume/mute messages.
213  *
214  * Force the device to send AV_DEV_TO_APP_VOLUME_LEVEL_CHANGED or
215  * AV_DEV_TO_APP_MUTE_STATE_CHANGED command respectively.
216  *
217  * data: NULL.
218  */
219  AV_APP_TO_DEV_GET_VOLUME = MKBETAG('G', 'V', 'O', 'L'),
220  AV_APP_TO_DEV_GET_MUTE = MKBETAG('G', 'M', 'U', 'T'),
221 };
222 
223 /**
224  * Message types used by avdevice_dev_to_app_control_message().
225  */
227  /**
228  * Dummy message.
229  */
230  AV_DEV_TO_APP_NONE = MKBETAG('N','O','N','E'),
231 
232  /**
233  * Create window buffer message.
234  *
235  * Device requests to create a window buffer. Exact meaning is device-
236  * and application-dependent. Message is sent before rendering first
237  * frame and all one-shot initializations should be done here.
238  * Application is allowed to ignore preferred window buffer size.
239  *
240  * @note: Application is obligated to inform about window buffer size
241  * with AV_APP_TO_DEV_WINDOW_SIZE message.
242  *
243  * data: AVDeviceRect: preferred size of the window buffer.
244  * NULL: no preferred size of the window buffer.
245  */
247 
248  /**
249  * Prepare window buffer message.
250  *
251  * Device requests to prepare a window buffer for rendering.
252  * Exact meaning is device- and application-dependent.
253  * Message is sent before rendering of each frame.
254  *
255  * data: NULL.
256  */
258 
259  /**
260  * Display window buffer message.
261  *
262  * Device requests to display a window buffer.
263  * Message is sent when new frame is ready to be displayed.
264  * Usually buffers need to be swapped in handler of this message.
265  *
266  * data: NULL.
267  */
269 
270  /**
271  * Destroy window buffer message.
272  *
273  * Device requests to destroy a window buffer.
274  * Message is sent when device is about to be destroyed and window
275  * buffer is not required anymore.
276  *
277  * data: NULL.
278  */
280 
281  /**
282  * Buffer fullness status messages.
283  *
284  * Device signals buffer overflow/underflow.
285  *
286  * data: NULL.
287  */
290 
291  /**
292  * Buffer readable/writable.
293  *
294  * Device informs that buffer is readable/writable.
295  * When possible, device informs how many bytes can be read/write.
296  *
297  * @warning Device may not inform when number of bytes than can be read/write changes.
298  *
299  * data: int64_t: amount of bytes available to read/write.
300  * NULL: amount of bytes available to read/write is not known.
301  */
304 
305  /**
306  * Mute state change message.
307  *
308  * Device informs that mute state has changed.
309  *
310  * data: int: 0 for not muted state, non-zero for muted state.
311  */
313 
314  /**
315  * Volume level change message.
316  *
317  * Device informs that volume level has changed.
318  *
319  * data: double: new volume with range of 0.0 - 1.0.
320  */
322 };
323 
324 /**
325  * Send control message from application to device.
326  *
327  * @param s device context.
328  * @param type message type.
329  * @param data message data. Exact type depends on message type.
330  * @param data_size size of message data.
331  * @return >= 0 on success, negative on error.
332  * AVERROR(ENOSYS) when device doesn't implement handler of the message.
333  */
336  void *data, size_t data_size);
337 
338 /**
339  * Send control message from device to application.
340  *
341  * @param s device context.
342  * @param type message type.
343  * @param data message data. Can be NULL.
344  * @param data_size size of message data.
345  * @return >= 0 on success, negative on error.
346  * AVERROR(ENOSYS) when application doesn't implement handler of the message.
347  */
350  void *data, size_t data_size);
351 
352 /**
353  * Following API allows user to probe device capabilities (supported codecs,
354  * pixel formats, sample formats, resolutions, channel counts, etc).
355  * It is build on top op AVOption API.
356  * Queried capabilities make it possible to set up converters of video or audio
357  * parameters that fit to the device.
358  *
359  * List of capabilities that can be queried:
360  * - Capabilities valid for both audio and video devices:
361  * - codec: supported audio/video codecs.
362  * type: AV_OPT_TYPE_INT (AVCodecID value)
363  * - Capabilities valid for audio devices:
364  * - sample_format: supported sample formats.
365  * type: AV_OPT_TYPE_INT (AVSampleFormat value)
366  * - sample_rate: supported sample rates.
367  * type: AV_OPT_TYPE_INT
368  * - channels: supported number of channels.
369  * type: AV_OPT_TYPE_INT
370  * - channel_layout: supported channel layouts.
371  * type: AV_OPT_TYPE_INT64
372  * - Capabilities valid for video devices:
373  * - pixel_format: supported pixel formats.
374  * type: AV_OPT_TYPE_INT (AVPixelFormat value)
375  * - window_size: supported window sizes (describes size of the window size presented to the user).
376  * type: AV_OPT_TYPE_IMAGE_SIZE
377  * - frame_size: supported frame sizes (describes size of provided video frames).
378  * type: AV_OPT_TYPE_IMAGE_SIZE
379  * - fps: supported fps values
380  * type: AV_OPT_TYPE_RATIONAL
381  *
382  * Value of the capability may be set by user using av_opt_set() function
383  * and AVDeviceCapabilitiesQuery object. Following queries will
384  * limit results to the values matching already set capabilities.
385  * For example, setting a codec may impact number of formats or fps values
386  * returned during next query. Setting invalid value may limit results to zero.
387  *
388  * Example of the usage basing on opengl output device:
389  *
390  * @code
391  * AVFormatContext *oc = NULL;
392  * AVDeviceCapabilitiesQuery *caps = NULL;
393  * AVOptionRanges *ranges;
394  * int ret;
395  *
396  * if ((ret = avformat_alloc_output_context2(&oc, NULL, "opengl", NULL)) < 0)
397  * goto fail;
398  * if (avdevice_capabilities_create(&caps, oc, NULL) < 0)
399  * goto fail;
400  *
401  * //query codecs
402  * if (av_opt_query_ranges(&ranges, caps, "codec", AV_OPT_MULTI_COMPONENT_RANGE)) < 0)
403  * goto fail;
404  * //pick codec here and set it
405  * av_opt_set(caps, "codec", AV_CODEC_ID_RAWVIDEO, 0);
406  *
407  * //query format
408  * if (av_opt_query_ranges(&ranges, caps, "pixel_format", AV_OPT_MULTI_COMPONENT_RANGE)) < 0)
409  * goto fail;
410  * //pick format here and set it
411  * av_opt_set(caps, "pixel_format", AV_PIX_FMT_YUV420P, 0);
412  *
413  * //query and set more capabilities
414  *
415  * fail:
416  * //clean up code
417  * avdevice_capabilities_free(&query, oc);
418  * avformat_free_context(oc);
419  * @endcode
420  */
421 
422 /**
423  * Structure describes device capabilities.
424  *
425  * It is used by devices in conjunction with av_device_capabilities AVOption table
426  * to implement capabilities probing API based on AVOption API. Should not be used directly.
427  */
435  int channels;
436  int64_t channel_layout;
443 
444 /**
445  * AVOption table used by devices to implement device capabilities API. Should not be used by a user.
446  */
447 extern const AVOption av_device_capabilities[];
448 
449 /**
450  * Initialize capabilities probing API based on AVOption API.
451  *
452  * avdevice_capabilities_free() must be called when query capabilities API is
453  * not used anymore.
454  *
455  * @param[out] caps Device capabilities data. Pointer to a NULL pointer must be passed.
456  * @param s Context of the device.
457  * @param device_options An AVDictionary filled with device-private options.
458  * On return this parameter will be destroyed and replaced with a dict
459  * containing options that were not found. May be NULL.
460  * The same options must be passed later to avformat_write_header() for output
461  * devices or avformat_open_input() for input devices, or at any other place
462  * that affects device-private options.
463  *
464  * @return >= 0 on success, negative otherwise.
465  */
467  AVDictionary **device_options);
468 
469 /**
470  * Free resources created by avdevice_capabilities_create()
471  *
472  * @param caps Device capabilities data to be freed.
473  * @param s Context of the device.
474  */
476 
477 /**
478  * Structure describes basic parameters of the device.
479  */
480 typedef struct AVDeviceInfo {
481  char *device_name; /**< device name, format depends on device */
482  char *device_description; /**< human friendly name */
483 } AVDeviceInfo;
484 
485 /**
486  * List of devices.
487  */
488 typedef struct AVDeviceInfoList {
489  AVDeviceInfo **devices; /**< list of autodetected devices */
490  int nb_devices; /**< number of autodetected devices */
491  int default_device; /**< index of default device or -1 if no default */
493 
494 /**
495  * List devices.
496  *
497  * Returns available device names and their parameters.
498  *
499  * @note: Some devices may accept system-dependent device names that cannot be
500  * autodetected. The list returned by this function cannot be assumed to
501  * be always completed.
502  *
503  * @param s device context.
504  * @param[out] device_list list of autodetected devices.
505  * @return count of autodetected devices, negative on error.
506  */
507 int avdevice_list_devices(struct AVFormatContext *s, AVDeviceInfoList **device_list);
508 
509 /**
510  * Convenient function to free result of avdevice_list_devices().
511  *
512  * @param devices device list to be freed.
513  */
514 void avdevice_free_list_devices(AVDeviceInfoList **device_list);
515 
516 /**
517  * List devices.
518  *
519  * Returns available device names and their parameters.
520  * These are convinient wrappers for avdevice_list_devices().
521  * Device context is allocated and deallocated internally.
522  *
523  * @param device device format. May be NULL if device name is set.
524  * @param device_name device name. May be NULL if device format is set.
525  * @param device_options An AVDictionary filled with device-private options. May be NULL.
526  * The same options must be passed later to avformat_write_header() for output
527  * devices or avformat_open_input() for input devices, or at any other place
528  * that affects device-private options.
529  * @param[out] device_list list of autodetected devices
530  * @return count of autodetected devices, negative on error.
531  * @note device argument takes precedence over device_name when both are set.
532  */
533 int avdevice_list_input_sources(struct AVInputFormat *device, const char *device_name,
534  AVDictionary *device_options, AVDeviceInfoList **device_list);
535 int avdevice_list_output_sinks(struct AVOutputFormat *device, const char *device_name,
536  AVDictionary *device_options, AVDeviceInfoList **device_list);
537 
538 /**
539  * @}
540  */
541 
542 #endif /* AVDEVICE_AVDEVICE_H */
attribute_deprecated AVOutputFormat * av_output_audio_device_next(AVOutputFormat *d)
Audio output devices iterator.
Window size change message.
Definition: avdevice.h:162
const char * avdevice_configuration(void)
Return the libavdevice build-time configuration.
Definition: avdevice.c:70
Repaint request message.
Definition: avdevice.h:172
Structure describes basic parameters of the device.
Definition: avdevice.h:480
const char * s
Definition: avisynth_c.h:768
Prepare window buffer message.
Definition: avdevice.h:257
int x
x coordinate of top left corner
Definition: avdevice.h:138
Dummy message.
Definition: avdevice.h:230
AVOption.
Definition: opt.h:246
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
char * device_description
human friendly name
Definition: avdevice.h:482
void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s)
Free resources created by avdevice_capabilities_create()
Definition: avdevice.c:126
char * device_name
device name, format depends on device
Definition: avdevice.h:481
Volume level change message.
Definition: avdevice.h:321
int avdevice_list_devices(struct AVFormatContext *s, AVDeviceInfoList **device_list)
List devices.
Definition: avdevice.c:141
Buffer fullness status messages.
Definition: avdevice.h:288
Display window buffer message.
Definition: avdevice.h:268
Format I/O context.
Definition: avformat.h:1341
Create window buffer message.
Definition: avdevice.h:246
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:89
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:97
AVDevToAppMessageType
Message types used by avdevice_dev_to_app_control_message().
Definition: avdevice.h:226
void avdevice_free_list_devices(AVDeviceInfoList **device_list)
Convenient function to free result of avdevice_list_devices().
Definition: avdevice.c:204
AVOptions.
attribute_deprecated AVInputFormat * av_input_video_device_next(AVInputFormat *d)
Video input devices iterator.
Get volume/mute messages.
Definition: avdevice.h:219
const AVClass * av_class
Definition: avdevice.h:429
const AVOutputFormat * av_outdev_iterate(void **opaque)
Iterate over all registered output devices.
Definition: alldevices.c:69
attribute_deprecated AVInputFormat * av_input_audio_device_next(AVInputFormat *d)
Audio input devices iterator.
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: avcodec.h:215
attribute_deprecated AVOutputFormat * av_output_video_device_next(AVOutputFormat *d)
Video output devices iterator.
enum AVSampleFormat sample_format
Definition: avdevice.h:432
Request pause/play.
Definition: avdevice.h:183
AVDeviceInfo ** devices
list of autodetected devices
Definition: avdevice.h:489
Volume control message.
Definition: avdevice.h:196
int avdevice_list_input_sources(struct AVInputFormat *device, const char *device_name, AVDictionary *device_options, AVDeviceInfoList **device_list)
List devices.
Definition: avdevice.c:182
AVFormatContext * device_context
Definition: avdevice.h:430
Mute control messages.
Definition: avdevice.h:207
int avdevice_list_output_sinks(struct AVOutputFormat *device, const char *device_name, AVDictionary *device_options, AVDeviceInfoList **device_list)
Definition: avdevice.c:193
enum AVPixelFormat pixel_format
Definition: avdevice.h:433
const AVOption av_device_capabilities[]
AVOption table used by devices to implement device capabilities API.
Definition: avdevice.c:36
Dummy message.
Definition: avdevice.h:151
Destroy window buffer message.
Definition: avdevice.h:279
enum AVCodecID codec
Definition: avdevice.h:431
int height
height
Definition: avdevice.h:141
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
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:312
int default_device
index of default device or -1 if no default
Definition: avdevice.h:491
List of devices.
Definition: avdevice.h:488
Libavdevice version macros.
int width
width
Definition: avdevice.h:140
#define attribute_deprecated
Definition: attributes.h:94
void avdevice_register_all(void)
Initialize libavdevice and register all the input and output devices.
Main libavformat public API header.
#define MKBETAG(a, b, c, d)
Definition: common.h:367
unsigned avdevice_version(void)
Return the LIBAVDEVICE_VERSION_INT constant.
Definition: avdevice.c:64
Buffer readable/writable.
Definition: avdevice.h:302
AVAppToDevMessageType
Message types used by avdevice_app_to_dev_control_message().
Definition: avdevice.h:147
int y
y coordinate of top left corner
Definition: avdevice.h:139
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:81
const AVInputFormat * av_indev_iterate(void **opaque)
Iterate over all registered input devices.
Definition: alldevices.c:79
int nb_devices
number of autodetected devices
Definition: avdevice.h:490
Following API allows user to probe device capabilities (supported codecs, pixel formats, sample formats, resolutions, channel counts, etc).
Definition: avdevice.h:428
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60