2 * This file is part of FFmpeg.
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.
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.
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
19 #ifndef AVDEVICE_AVDEVICE_H
20 #define AVDEVICE_AVDEVICE_H
27 * Main libavdevice API header
31 * @defgroup lavd libavdevice
32 * Special devices muxing/demuxing library.
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.
42 * To use libavdevice, simply call avdevice_register_all() to register all
43 * compiled muxers and demuxers. They all use standard libavformat API.
48 #include "libavutil/log.h"
49 #include "libavutil/opt.h"
50 #include "libavutil/dict.h"
51 #include "libavformat/avformat.h"
54 * Return the LIBAVDEVICE_VERSION_INT constant.
56 unsigned avdevice_version(void);
59 * Return the libavdevice build-time configuration.
61 const char *avdevice_configuration(void);
64 * Return the libavdevice license.
66 const char *avdevice_license(void);
69 * Initialize libavdevice and register all the input and output devices.
70 * @warning This function is not thread safe.
72 void avdevice_register_all(void);
75 * Audio input devices iterator.
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.
81 AVInputFormat *av_input_audio_device_next(AVInputFormat *d);
84 * Video input devices iterator.
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.
90 AVInputFormat *av_input_video_device_next(AVInputFormat *d);
93 * Audio output devices iterator.
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.
99 AVOutputFormat *av_output_audio_device_next(AVOutputFormat *d);
102 * Video output devices iterator.
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.
108 AVOutputFormat *av_output_video_device_next(AVOutputFormat *d);
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 */
118 * Message types used by avdevice_app_to_dev_control_message().
120 enum AVAppToDevMessageType {
124 AV_APP_TO_DEV_NONE = MKBETAG('N','O','N','E'),
127 * Window size change message.
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.
133 * data: AVDeviceRect: new window size.
135 AV_APP_TO_DEV_WINDOW_SIZE = MKBETAG('G','E','O','M'),
138 * Repaint request message.
140 * Message is sent to the device when window has to be repainted.
142 * data: AVDeviceRect: area required to be repainted.
143 * NULL: whole area is required to be repainted.
145 AV_APP_TO_DEV_WINDOW_REPAINT = MKBETAG('R','E','P','A'),
148 * Request pause/play.
150 * Application requests pause/unpause playback.
151 * Mostly usable with devices that have internal buffer.
152 * By default devices are not paused.
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'),
161 * Volume control message.
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.
167 * data: double: new volume with range of 0.0 - 1.0.
169 AV_APP_TO_DEV_SET_VOLUME = MKBETAG('S', 'V', 'O', 'L'),
172 * Mute control messages.
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.
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'),
185 * Get volume/mute messages.
187 * Force the device to send AV_DEV_TO_APP_VOLUME_LEVEL_CHANGED or
188 * AV_DEV_TO_APP_MUTE_STATE_CHANGED command respectively.
192 AV_APP_TO_DEV_GET_VOLUME = MKBETAG('G', 'V', 'O', 'L'),
193 AV_APP_TO_DEV_GET_MUTE = MKBETAG('G', 'M', 'U', 'T'),
197 * Message types used by avdevice_dev_to_app_control_message().
199 enum AVDevToAppMessageType {
203 AV_DEV_TO_APP_NONE = MKBETAG('N','O','N','E'),
206 * Create window buffer message.
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.
213 * @note: Application is obligated to inform about window buffer size
214 * with AV_APP_TO_DEV_WINDOW_SIZE message.
216 * data: AVDeviceRect: preferred size of the window buffer.
217 * NULL: no preferred size of the window buffer.
219 AV_DEV_TO_APP_CREATE_WINDOW_BUFFER = MKBETAG('B','C','R','E'),
222 * Prepare window buffer message.
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.
230 AV_DEV_TO_APP_PREPARE_WINDOW_BUFFER = MKBETAG('B','P','R','E'),
233 * Display window buffer message.
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.
241 AV_DEV_TO_APP_DISPLAY_WINDOW_BUFFER = MKBETAG('B','D','I','S'),
244 * Destroy window buffer message.
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.
252 AV_DEV_TO_APP_DESTROY_WINDOW_BUFFER = MKBETAG('B','D','E','S'),
255 * Buffer fullness status messages.
257 * Device signals buffer overflow/underflow.
261 AV_DEV_TO_APP_BUFFER_OVERFLOW = MKBETAG('B','O','F','L'),
262 AV_DEV_TO_APP_BUFFER_UNDERFLOW = MKBETAG('B','U','F','L'),
265 * Buffer readable/writable.
267 * Device informs that buffer is readable/writable.
268 * When possible, device informs how many bytes can be read/write.
270 * @warning Device may not inform when number of bytes than can be read/write changes.
272 * data: int64_t: amount of bytes available to read/write.
273 * NULL: amount of bytes available to read/write is not known.
275 AV_DEV_TO_APP_BUFFER_READABLE = MKBETAG('B','R','D',' '),
276 AV_DEV_TO_APP_BUFFER_WRITABLE = MKBETAG('B','W','R',' '),
279 * Mute state change message.
281 * Device informs that mute state has changed.
283 * data: int: 0 for not muted state, non-zero for muted state.
285 AV_DEV_TO_APP_MUTE_STATE_CHANGED = MKBETAG('C','M','U','T'),
288 * Volume level change message.
290 * Device informs that volume level has changed.
292 * data: double: new volume with range of 0.0 - 1.0.
294 AV_DEV_TO_APP_VOLUME_LEVEL_CHANGED = MKBETAG('C','V','O','L'),
298 * Send control message from application to device.
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.
307 int avdevice_app_to_dev_control_message(struct AVFormatContext *s,
308 enum AVAppToDevMessageType type,
309 void *data, size_t data_size);
312 * Send control message from device to application.
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.
321 int avdevice_dev_to_app_control_message(struct AVFormatContext *s,
322 enum AVDevToAppMessageType type,
323 void *data, size_t data_size);
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.
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
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.
361 * Example of the usage basing on opengl output device:
364 * AVFormatContext *oc = NULL;
365 * AVDeviceCapabilitiesQuery *caps = NULL;
366 * AVOptionRanges *ranges;
369 * if ((ret = avformat_alloc_output_context2(&oc, NULL, "opengl", NULL)) < 0)
371 * if (avdevice_capabilities_create(&caps, oc, NULL) < 0)
375 * if (av_opt_query_ranges(&ranges, caps, "codec", AV_OPT_MULTI_COMPONENT_RANGE)) < 0)
377 * //pick codec here and set it
378 * av_opt_set(caps, "codec", AV_CODEC_ID_RAWVIDEO, 0);
381 * if (av_opt_query_ranges(&ranges, caps, "pixel_format", AV_OPT_MULTI_COMPONENT_RANGE)) < 0)
383 * //pick format here and set it
384 * av_opt_set(caps, "pixel_format", AV_PIX_FMT_YUV420P, 0);
386 * //query and set more capabilities
390 * avdevice_capabilities_free(&query, oc);
391 * avformat_free_context(oc);
396 * Structure describes device capabilities.
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.
401 typedef struct AVDeviceCapabilitiesQuery {
402 const AVClass *av_class;
403 AVFormatContext *device_context;
404 enum AVCodecID codec;
405 enum AVSampleFormat sample_format;
406 enum AVPixelFormat pixel_format;
409 int64_t channel_layout;
415 } AVDeviceCapabilitiesQuery;
418 * AVOption table used by devices to implement device capabilities API. Should not be used by a user.
420 extern const AVOption av_device_capabilities[];
423 * Initialize capabilities probing API based on AVOption API.
425 * avdevice_capabilities_free() must be called when query capabilities API is
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.
437 * @return >= 0 on success, negative otherwise.
439 int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s,
440 AVDictionary **device_options);
443 * Free resources created by avdevice_capabilities_create()
445 * @param caps Device capabilities data to be freed.
446 * @param s Context of the device.
448 void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s);
451 * Structure describes basic parameters of the device.
453 typedef struct AVDeviceInfo {
454 char *device_name; /**< device name, format depends on device */
455 char *device_description; /**< human friendly name */
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 */
470 * Returns available device names and their parameters.
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.
476 * @param s device context.
477 * @param[out] device_list list of autodetected devices.
478 * @return count of autodetected devices, negative on error.
480 int avdevice_list_devices(struct AVFormatContext *s, AVDeviceInfoList **device_list);
483 * Convenient function to free result of avdevice_list_devices().
485 * @param devices device list to be freed.
487 void avdevice_free_list_devices(AVDeviceInfoList **device_list);
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.
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.
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);
515 #endif /* AVDEVICE_AVDEVICE_H */