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 Special devices muxing/demuxing library
33 * Libavdevice is a complementary library to @ref libavf "libavformat". It
34 * provides various "special" platform-specific muxers and demuxers, e.g. for
35 * grabbing devices, audio capture and playback etc. As a consequence, the
36 * (de)muxers in libavdevice are of the AVFMT_NOFILE type (they use their own
37 * I/O functions). The filename passed to avformat_open_input() often does not
38 * refer to an actually existing file, but has some special device-specific
39 * meaning - e.g. for x11grab it is the display name.
41 * To use libavdevice, simply call avdevice_register_all() to register all
42 * compiled muxers and demuxers. They all use standard libavformat API.
46 #include "libavutil/log.h"
47 #include "libavutil/opt.h"
48 #include "libavutil/dict.h"
49 #include "libavformat/avformat.h"
52 * Return the LIBAVDEVICE_VERSION_INT constant.
54 unsigned avdevice_version(void);
57 * Return the libavdevice build-time configuration.
59 const char *avdevice_configuration(void);
62 * Return the libavdevice license.
64 const char *avdevice_license(void);
67 * Initialize libavdevice and register all the input and output devices.
68 * @warning This function is not thread safe.
70 void avdevice_register_all(void);
73 * Audio input devices iterator.
75 * If d is NULL, returns the first registered input audio/video device,
76 * if d is non-NULL, returns the next registered input audio/video device after d
77 * or NULL if d is the last one.
79 AVInputFormat
*av_input_audio_device_next(AVInputFormat
*d
);
82 * Video input devices iterator.
84 * If d is NULL, returns the first registered input audio/video device,
85 * if d is non-NULL, returns the next registered input audio/video device after d
86 * or NULL if d is the last one.
88 AVInputFormat
*av_input_video_device_next(AVInputFormat
*d
);
91 * Audio output devices iterator.
93 * If d is NULL, returns the first registered output audio/video device,
94 * if d is non-NULL, returns the next registered output audio/video device after d
95 * or NULL if d is the last one.
97 AVOutputFormat
*av_output_audio_device_next(AVOutputFormat
*d
);
100 * Video output devices iterator.
102 * If d is NULL, returns the first registered output audio/video device,
103 * if d is non-NULL, returns the next registered output audio/video device after d
104 * or NULL if d is the last one.
106 AVOutputFormat
*av_output_video_device_next(AVOutputFormat
*d
);
108 typedef struct AVDeviceRect
{
109 int x
; /**< x coordinate of top left corner */
110 int y
; /**< y coordinate of top left corner */
111 int width
; /**< width */
112 int height
; /**< height */
116 * Message types used by avdevice_app_to_dev_control_message().
118 enum AVAppToDevMessageType
{
122 AV_APP_TO_DEV_NONE
= MKBETAG('N','O','N','E'),
125 * Window size change message.
127 * Message is sent to the device every time the application changes the size
128 * of the window device renders to.
129 * Message should also be sent right after window is created.
131 * data: AVDeviceRect: new window size.
133 AV_APP_TO_DEV_WINDOW_SIZE
= MKBETAG('G','E','O','M'),
136 * Repaint request message.
138 * Message is sent to the device when window has to be repainted.
140 * data: AVDeviceRect: area required to be repainted.
141 * NULL: whole area is required to be repainted.
143 AV_APP_TO_DEV_WINDOW_REPAINT
= MKBETAG('R','E','P','A'),
146 * Request pause/play.
148 * Application requests pause/unpause playback.
149 * Mostly usable with devices that have internal buffer.
150 * By default devices are not paused.
154 AV_APP_TO_DEV_PAUSE
= MKBETAG('P', 'A', 'U', ' '),
155 AV_APP_TO_DEV_PLAY
= MKBETAG('P', 'L', 'A', 'Y'),
156 AV_APP_TO_DEV_TOGGLE_PAUSE
= MKBETAG('P', 'A', 'U', 'T'),
159 * Volume control message.
161 * Set volume level. It may be device-dependent if volume
162 * is changed per stream or system wide. Per stream volume
163 * change is expected when possible.
165 * data: double: new volume with range of 0.0 - 1.0.
167 AV_APP_TO_DEV_SET_VOLUME
= MKBETAG('S', 'V', 'O', 'L'),
170 * Mute control messages.
172 * Change mute state. It may be device-dependent if mute status
173 * is changed per stream or system wide. Per stream mute status
174 * change is expected when possible.
178 AV_APP_TO_DEV_MUTE
= MKBETAG(' ', 'M', 'U', 'T'),
179 AV_APP_TO_DEV_UNMUTE
= MKBETAG('U', 'M', 'U', 'T'),
180 AV_APP_TO_DEV_TOGGLE_MUTE
= MKBETAG('T', 'M', 'U', 'T'),
183 * Get volume/mute messages.
185 * Force the device to send AV_DEV_TO_APP_VOLUME_LEVEL_CHANGED or
186 * AV_DEV_TO_APP_MUTE_STATE_CHANGED command respectively.
190 AV_APP_TO_DEV_GET_VOLUME
= MKBETAG('G', 'V', 'O', 'L'),
191 AV_APP_TO_DEV_GET_MUTE
= MKBETAG('G', 'M', 'U', 'T'),
195 * Message types used by avdevice_dev_to_app_control_message().
197 enum AVDevToAppMessageType
{
201 AV_DEV_TO_APP_NONE
= MKBETAG('N','O','N','E'),
204 * Create window buffer message.
206 * Device requests to create a window buffer. Exact meaning is device-
207 * and application-dependent. Message is sent before rendering first
208 * frame and all one-shot initializations should be done here.
209 * Application is allowed to ignore preferred window buffer size.
211 * @note: Application is obligated to inform about window buffer size
212 * with AV_APP_TO_DEV_WINDOW_SIZE message.
214 * data: AVDeviceRect: preferred size of the window buffer.
215 * NULL: no preferred size of the window buffer.
217 AV_DEV_TO_APP_CREATE_WINDOW_BUFFER
= MKBETAG('B','C','R','E'),
220 * Prepare window buffer message.
222 * Device requests to prepare a window buffer for rendering.
223 * Exact meaning is device- and application-dependent.
224 * Message is sent before rendering of each frame.
228 AV_DEV_TO_APP_PREPARE_WINDOW_BUFFER
= MKBETAG('B','P','R','E'),
231 * Display window buffer message.
233 * Device requests to display a window buffer.
234 * Message is sent when new frame is ready to be displayed.
235 * Usually buffers need to be swapped in handler of this message.
239 AV_DEV_TO_APP_DISPLAY_WINDOW_BUFFER
= MKBETAG('B','D','I','S'),
242 * Destroy window buffer message.
244 * Device requests to destroy a window buffer.
245 * Message is sent when device is about to be destroyed and window
246 * buffer is not required anymore.
250 AV_DEV_TO_APP_DESTROY_WINDOW_BUFFER
= MKBETAG('B','D','E','S'),
253 * Buffer fullness status messages.
255 * Device signals buffer overflow/underflow.
259 AV_DEV_TO_APP_BUFFER_OVERFLOW
= MKBETAG('B','O','F','L'),
260 AV_DEV_TO_APP_BUFFER_UNDERFLOW
= MKBETAG('B','U','F','L'),
263 * Buffer readable/writable.
265 * Device informs that buffer is readable/writable.
266 * When possible, device informs how many bytes can be read/write.
268 * @warning Device may not inform when number of bytes than can be read/write changes.
270 * data: int64_t: amount of bytes available to read/write.
271 * NULL: amount of bytes available to read/write is not known.
273 AV_DEV_TO_APP_BUFFER_READABLE
= MKBETAG('B','R','D',' '),
274 AV_DEV_TO_APP_BUFFER_WRITABLE
= MKBETAG('B','W','R',' '),
277 * Mute state change message.
279 * Device informs that mute state has changed.
281 * data: int: 0 for not muted state, non-zero for muted state.
283 AV_DEV_TO_APP_MUTE_STATE_CHANGED
= MKBETAG('C','M','U','T'),
286 * Volume level change message.
288 * Device informs that volume level has changed.
290 * data: double: new volume with range of 0.0 - 1.0.
292 AV_DEV_TO_APP_VOLUME_LEVEL_CHANGED
= MKBETAG('C','V','O','L'),
296 * Send control message from application to device.
298 * @param s device context.
299 * @param type message type.
300 * @param data message data. Exact type depends on message type.
301 * @param data_size size of message data.
302 * @return >= 0 on success, negative on error.
303 * AVERROR(ENOSYS) when device doesn't implement handler of the message.
305 int avdevice_app_to_dev_control_message(struct AVFormatContext
*s
,
306 enum AVAppToDevMessageType type
,
307 void *data
, size_t data_size
);
310 * Send control message from device to application.
312 * @param s device context.
313 * @param type message type.
314 * @param data message data. Can be NULL.
315 * @param data_size size of message data.
316 * @return >= 0 on success, negative on error.
317 * AVERROR(ENOSYS) when application doesn't implement handler of the message.
319 int avdevice_dev_to_app_control_message(struct AVFormatContext
*s
,
320 enum AVDevToAppMessageType type
,
321 void *data
, size_t data_size
);
324 * Following API allows user to probe device capabilities (supported codecs,
325 * pixel formats, sample formats, resolutions, channel counts, etc).
326 * It is build on top op AVOption API.
327 * Queried capabilities allows to set up converters of video or audio
328 * parameters that fit to the device.
330 * List of capabilities that can be queried:
331 * - Capabilities valid for both audio and video devices:
332 * - codec: supported audio/video codecs.
333 * type: AV_OPT_TYPE_INT (AVCodecID value)
334 * - Capabilities valid for audio devices:
335 * - sample_format: supported sample formats.
336 * type: AV_OPT_TYPE_INT (AVSampleFormat value)
337 * - sample_rate: supported sample rates.
338 * type: AV_OPT_TYPE_INT
339 * - channels: supported number of channels.
340 * type: AV_OPT_TYPE_INT
341 * - channel_layout: supported channel layouts.
342 * type: AV_OPT_TYPE_INT64
343 * - Capabilities valid for video devices:
344 * - pixel_format: supported pixel formats.
345 * type: AV_OPT_TYPE_INT (AVPixelFormat value)
346 * - window_size: supported window sizes (describes size of the window size presented to the user).
347 * type: AV_OPT_TYPE_IMAGE_SIZE
348 * - frame_size: supported frame sizes (describes size of provided video frames).
349 * type: AV_OPT_TYPE_IMAGE_SIZE
350 * - fps: supported fps values
351 * type: AV_OPT_TYPE_RATIONAL
353 * Value of the capability may be set by user using av_opt_set() function
354 * and AVDeviceCapabilitiesQuery object. Following queries will
355 * limit results to the values matching already set capabilities.
356 * For example, setting a codec may impact number of formats or fps values
357 * returned during next query. Setting invalid value may limit results to zero.
359 * Example of the usage basing on opengl output device:
362 * AVFormatContext *oc = NULL;
363 * AVDeviceCapabilitiesQuery *caps = NULL;
364 * AVOptionRanges *ranges;
367 * if ((ret = avformat_alloc_output_context2(&oc, NULL, "opengl", NULL)) < 0)
369 * if (avdevice_capabilities_create(&caps, oc, NULL) < 0)
373 * if (av_opt_query_ranges(&ranges, caps, "codec", AV_OPT_MULTI_COMPONENT_RANGE)) < 0)
375 * //pick codec here and set it
376 * av_opt_set(caps, "codec", AV_CODEC_ID_RAWVIDEO, 0);
379 * if (av_opt_query_ranges(&ranges, caps, "pixel_format", AV_OPT_MULTI_COMPONENT_RANGE)) < 0)
381 * //pick format here and set it
382 * av_opt_set(caps, "pixel_format", AV_PIX_FMT_YUV420P, 0);
384 * //query and set more capabilities
388 * avdevice_capabilities_free(&query, oc);
389 * avformat_free_context(oc);
394 * Structure describes device capabilities.
396 * It is used by devices in conjunction with av_device_capabilities AVOption table
397 * to implement capabilities probing API based on AVOption API. Should not be used directly.
399 typedef struct AVDeviceCapabilitiesQuery
{
400 const AVClass
*av_class
;
401 AVFormatContext
*device_context
;
402 enum AVCodecID codec
;
403 enum AVSampleFormat sample_format
;
404 enum AVPixelFormat pixel_format
;
407 int64_t channel_layout
;
413 } AVDeviceCapabilitiesQuery
;
416 * AVOption table used by devices to implement device capabilities API. Should not be used by a user.
418 extern const AVOption av_device_capabilities
[];
421 * Initialize capabilities probing API based on AVOption API.
423 * avdevice_capabilities_free() must be called when query capabilities API is
426 * @param[out] caps Device capabilities data. Pointer to a NULL pointer must be passed.
427 * @param s Context of the device.
428 * @param device_options An AVDictionary filled with device-private options.
429 * On return this parameter will be destroyed and replaced with a dict
430 * containing options that were not found. May be NULL.
431 * The same options must be passed later to avformat_write_header() for output
432 * devices or avformat_open_input() for input devices, or at any other place
433 * that affects device-private options.
435 * @return >= 0 on success, negative otherwise.
437 int avdevice_capabilities_create(AVDeviceCapabilitiesQuery
**caps
, AVFormatContext
*s
,
438 AVDictionary
**device_options
);
441 * Free resources created by avdevice_capabilities_create()
443 * @param caps Device capabilities data to be freed.
444 * @param s Context of the device.
446 void avdevice_capabilities_free(AVDeviceCapabilitiesQuery
**caps
, AVFormatContext
*s
);
449 * Structure describes basic parameters of the device.
451 typedef struct AVDeviceInfo
{
452 char *device_name
; /**< device name, format depends on device */
453 char *device_description
; /**< human friendly name */
459 typedef struct AVDeviceInfoList
{
460 AVDeviceInfo
**devices
; /**< list of autodetected devices */
461 int nb_devices
; /**< number of autodetected devices */
462 int default_device
; /**< index of default device or -1 if no default */
468 * Returns available device names and their parameters.
470 * @note: Some devices may accept system-dependent device names that cannot be
471 * autodetected. The list returned by this function cannot be assumed to
472 * be always completed.
474 * @param s device context.
475 * @param[out] device_list list of autodetected devices.
476 * @return count of autodetected devices, negative on error.
478 int avdevice_list_devices(struct AVFormatContext
*s
, AVDeviceInfoList
**device_list
);
481 * Convenient function to free result of avdevice_list_devices().
483 * @param devices device list to be freed.
485 void avdevice_free_list_devices(AVDeviceInfoList
**device_list
);
487 #endif /* AVDEVICE_AVDEVICE_H */