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 have to be rapainted.
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'),
160 * Message types used by avdevice_dev_to_app_control_message().
162 enum AVDevToAppMessageType {
166 AV_DEV_TO_APP_NONE = MKBETAG('N','O','N','E'),
169 * Create window buffer message.
171 * Device requests to create a window buffer. Exact meaning is device-
172 * and application-dependent. Message is sent before rendering first
173 * frame and all one-shot initializations should be done here.
174 * Application is allowed to ignore preferred window buffer size.
176 * @note: Application is obligated to inform about window buffer size
177 * with AV_APP_TO_DEV_WINDOW_SIZE message.
179 * data: AVDeviceRect: preferred size of the window buffer.
180 * NULL: no preferred size of the window buffer.
182 AV_DEV_TO_APP_CREATE_WINDOW_BUFFER = MKBETAG('B','C','R','E'),
185 * Prepare window buffer message.
187 * Device requests to prepare a window buffer for rendering.
188 * Exact meaning is device- and application-dependent.
189 * Message is sent before rendering of each frame.
193 AV_DEV_TO_APP_PREPARE_WINDOW_BUFFER = MKBETAG('B','P','R','E'),
196 * Display window buffer message.
198 * Device requests to display a window buffer.
199 * Message is sent when new frame is ready to be displyed.
200 * Usually buffers need to be swapped in handler of this message.
204 AV_DEV_TO_APP_DISPLAY_WINDOW_BUFFER = MKBETAG('B','D','I','S'),
207 * Destroy window buffer message.
209 * Device requests to destroy a window buffer.
210 * Message is sent when device is about to be destroyed and window
211 * buffer is not required anymore.
215 AV_DEV_TO_APP_DESTROY_WINDOW_BUFFER = MKBETAG('B','D','E','S'),
218 * Buffer fullness status messages.
220 * Device signals buffer overflow/underflow.
224 AV_DEV_TO_APP_BUFFER_OVERFLOW = MKBETAG('B','O','F','L'),
225 AV_DEV_TO_APP_BUFFER_UNDERFLOW = MKBETAG('B','U','F','L'),
228 * Buffer readable/writable.
230 * Device informs that buffer is readable/writable.
231 * When possible, device informs how many bytes can be read/write.
233 * @warning Device may not inform when number of bytes than can be read/write changes.
235 * data: int64_t: amount of bytes available to read/write.
236 * NULL: amount of bytes available to read/write is not known.
238 AV_DEV_TO_APP_BUFFER_READABLE = MKBETAG('B','R','D',' '),
239 AV_DEV_TO_APP_BUFFER_WRITABLE = MKBETAG('B','W','R',' '),
243 * Send control message from application to device.
245 * @param s device context.
246 * @param type message type.
247 * @param data message data. Exact type depends on message type.
248 * @param data_size size of message data.
249 * @return >= 0 on success, negative on error.
250 * AVERROR(ENOSYS) when device doesn't implement handler of the message.
252 int avdevice_app_to_dev_control_message(struct AVFormatContext *s,
253 enum AVAppToDevMessageType type,
254 void *data, size_t data_size);
257 * Send control message from device to application.
259 * @param s device context.
260 * @param type message type.
261 * @param data message data. Can be NULL.
262 * @param data_size size of message data.
263 * @return >= 0 on success, negative on error.
264 * AVERROR(ENOSYS) when application doesn't implement handler of the message.
266 int avdevice_dev_to_app_control_message(struct AVFormatContext *s,
267 enum AVDevToAppMessageType type,
268 void *data, size_t data_size);
271 * Following API allows user to probe device capabilities (supported codecs,
272 * pixel formats, sample formats, resolutions, channel counts, etc).
273 * It is build on top op AVOption API.
274 * Queried capabilities allows to set up converters of video or audio
275 * parameters that fit to the device.
277 * List of capablities that can be queried:
278 * - Capabilities valid for both audio and video devices:
279 * - codec: supported audio/video codecs.
280 * type: AV_OPT_TYPE_INT (AVCodecID value)
281 * - Capabilities valid for audio devices:
282 * - sample_format: supported sample formats.
283 * type: AV_OPT_TYPE_INT (AVSampleFormat value)
284 * - sample_rate: supported sample rates.
285 * type: AV_OPT_TYPE_INT
286 * - channels: supported number of channels.
287 * type: AV_OPT_TYPE_INT
288 * - channel_layout: supported channel layouts.
289 * type: AV_OPT_TYPE_INT64
290 * - Capabilities valid for video devices:
291 * - pixel_format: supported pixel formats.
292 * type: AV_OPT_TYPE_INT (AVPixelFormat value)
293 * - window_size: supported window sizes (describes size of the window size presented to the user).
294 * type: AV_OPT_TYPE_IMAGE_SIZE
295 * - frame_size: supported frame sizes (describes size of provided video frames).
296 * type: AV_OPT_TYPE_IMAGE_SIZE
297 * - fps: supported fps values
298 * type: AV_OPT_TYPE_RATIONAL
300 * Value of the capability may be set by user using av_opt_set() function
301 * and AVDeviceCapabilitiesQuery object. Following queries will
302 * limit results to the values matching already set capabilities.
303 * For example, setting a codec may impact number of formats or fps values
304 * returned during next query. Setting invalid value may limit results to zero.
306 * Example of the usage basing on opengl output device:
309 * AVFormatContext *oc = NULL;
310 * AVDeviceCapabilitiesQuery *caps = NULL;
311 * AVOptionRanges *ranges;
314 * if ((ret = avformat_alloc_output_context2(&oc, NULL, "opengl", NULL)) < 0)
316 * if (avdevice_capabilities_create(&caps, oc, NULL) < 0)
320 * if (av_opt_query_ranges(&ranges, caps, "codec", AV_OPT_MULTI_COMPONENT_RANGE)) < 0)
322 * //pick codec here and set it
323 * av_opt_set(caps, "codec", AV_CODEC_ID_RAWVIDEO, 0);
326 * if (av_opt_query_ranges(&ranges, caps, "pixel_format", AV_OPT_MULTI_COMPONENT_RANGE)) < 0)
328 * //pick format here and set it
329 * av_opt_set(caps, "pixel_format", AV_PIX_FMT_YUV420P, 0);
331 * //query and set more capabilities
335 * avdevice_capabilities_free(&query, oc);
336 * avformat_free_context(oc);
341 * Structure describes device capabilites.
343 * It is used by devices in conjuntion with av_device_capabilities AVOption table
344 * to implement capabilities probing API based on AVOption API. Should not be used directly.
346 typedef struct AVDeviceCapabilitiesQuery {
347 const AVClass *class;
348 AVFormatContext *device_context;
349 enum AVCodecID codec;
350 enum AVSampleFormat sample_format;
351 enum AVPixelFormat pixel_format;
354 int64_t channel_layout;
360 } AVDeviceCapabilitiesQuery;
363 * AVOption table used by devices to implement device capabilites API. Should not be used by a user.
365 extern const AVOption av_device_capabilities[];
368 * Initialize capabilities probing API based on AVOption API.
370 * avdevice_capabilities_free() must be called when query capabilities API is
373 * @param[out] caps Device capabilities data. Pointer to a NULL pointer must be passed.
374 * @param s Context of the device.
375 * @param device_options An AVDictionary filled with device-private options.
376 * On return this parameter will be destroyed and replaced with a dict
377 * containing options that were not found. May be NULL.
378 * The same options must be passed later to avformat_write_header() for output
379 * devices or avformat_open_input() for input devices, or at any other place
380 * that affects device-private options.
382 * @return >= 0 on success, negative otherwise.
384 int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s,
385 AVDictionary **device_options);
388 * Free resources created by avdevice_capabilities_create()
390 * @param caps Device capabilities data to be freed.
391 * @param s Context of the device.
393 void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s);
396 * Structure describes basic parameters of the device.
398 typedef struct AVDeviceInfo {
399 char *device_name; /**< device name, format depends on device */
400 char *device_description; /**< human friendly name */
406 typedef struct AVDeviceInfoList {
407 AVDeviceInfo **devices; /**< list of autodetected devices */
408 int nb_devices; /**< number of autodetected devices */
409 int default_device; /**< index of default device or -1 if no default */
415 * Returns available device names and their parameters.
417 * @note: Some devices may accept system-dependent device names that cannot be
418 * autodetected. The list returned by this function cannot be assumed to
419 * be always completed.
421 * @param s device context.
422 * @param[out] device_list list of autodetected devices.
423 * @return count of autodetected devices, negative on error.
425 int avdevice_list_devices(struct AVFormatContext *s, AVDeviceInfoList **device_list);
428 * Convinient function to free result of avdevice_list_devices().
430 * @param devices device list to be freed.
432 void avdevice_free_list_devices(AVDeviceInfoList **device_list);
434 #endif /* AVDEVICE_AVDEVICE_H */