/*1* This file is part of FFmpeg.2*3* FFmpeg is free software; you can redistribute it and/or4* modify it under the terms of the GNU Lesser General Public5* License as published by the Free Software Foundation; either6* version 2.1 of the License, or (at your option) any later version.7*8* FFmpeg is distributed in the hope that it will be useful,9* but WITHOUT ANY WARRANTY; without even the implied warranty of10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU11* Lesser General Public License for more details.12*13* You should have received a copy of the GNU Lesser General Public14* License along with FFmpeg; if not, write to the Free Software15* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA16*/1718#ifndef AVDEVICE_AVDEVICE_H19#define AVDEVICE_AVDEVICE_H2021#include "version.h"2223/**24* @file25* @ingroup lavd26* Main libavdevice API header27*/2829/**30* @defgroup lavd Special devices muxing/demuxing library31* @{32* Libavdevice is a complementary library to @ref libavf "libavformat". It33* provides various "special" platform-specific muxers and demuxers, e.g. for34* grabbing devices, audio capture and playback etc. As a consequence, the35* (de)muxers in libavdevice are of the AVFMT_NOFILE type (they use their own36* I/O functions). The filename passed to avformat_open_input() often does not37* refer to an actually existing file, but has some special device-specific38* meaning - e.g. for x11grab it is the display name.39*40* To use libavdevice, simply call avdevice_register_all() to register all41* compiled muxers and demuxers. They all use standard libavformat API.42* @}43*/4445#include "libavutil/log.h"46#include "libavutil/opt.h"47#include "libavutil/dict.h"48#include "libavformat/avformat.h"4950/**51* Return the LIBAVDEVICE_VERSION_INT constant.52*/53unsigned avdevice_version(void);5455/**56* Return the libavdevice build-time configuration.57*/58const char *avdevice_configuration(void);5960/**61* Return the libavdevice license.62*/63const char *avdevice_license(void);6465/**66* Initialize libavdevice and register all the input and output devices.67* @warning This function is not thread safe.68*/69void avdevice_register_all(void);7071/**72* Audio input devices iterator.73*74* If d is NULL, returns the first registered input audio/video device,75* if d is non-NULL, returns the next registered input audio/video device after d76* or NULL if d is the last one.77*/78AVInputFormat *av_input_audio_device_next(AVInputFormat *d);7980/**81* Video input devices iterator.82*83* If d is NULL, returns the first registered input audio/video device,84* if d is non-NULL, returns the next registered input audio/video device after d85* or NULL if d is the last one.86*/87AVInputFormat *av_input_video_device_next(AVInputFormat *d);8889/**90* Audio output devices iterator.91*92* If d is NULL, returns the first registered output audio/video device,93* if d is non-NULL, returns the next registered output audio/video device after d94* or NULL if d is the last one.95*/96AVOutputFormat *av_output_audio_device_next(AVOutputFormat *d);9798/**99* Video output devices iterator.100*101* If d is NULL, returns the first registered output audio/video device,102* if d is non-NULL, returns the next registered output audio/video device after d103* or NULL if d is the last one.104*/105AVOutputFormat *av_output_video_device_next(AVOutputFormat *d);106107typedef struct AVDeviceRect {108int x; /**< x coordinate of top left corner */109int y; /**< y coordinate of top left corner */110int width; /**< width */111int height; /**< height */112} AVDeviceRect;113114/**115* Message types used by avdevice_app_to_dev_control_message().116*/117enum AVAppToDevMessageType {118/**119* Dummy message.120*/121AV_APP_TO_DEV_NONE = MKBETAG('N','O','N','E'),122123/**124* Window size change message.125*126* Message is sent to the device every time the application changes the size127* of the window device renders to.128* Message should also be sent right after window is created.129*130* data: AVDeviceRect: new window size.131*/132AV_APP_TO_DEV_WINDOW_SIZE = MKBETAG('G','E','O','M'),133134/**135* Repaint request message.136*137* Message is sent to the device when window has to be repainted.138*139* data: AVDeviceRect: area required to be repainted.140* NULL: whole area is required to be repainted.141*/142AV_APP_TO_DEV_WINDOW_REPAINT = MKBETAG('R','E','P','A'),143144/**145* Request pause/play.146*147* Application requests pause/unpause playback.148* Mostly usable with devices that have internal buffer.149* By default devices are not paused.150*151* data: NULL152*/153AV_APP_TO_DEV_PAUSE = MKBETAG('P', 'A', 'U', ' '),154AV_APP_TO_DEV_PLAY = MKBETAG('P', 'L', 'A', 'Y'),155AV_APP_TO_DEV_TOGGLE_PAUSE = MKBETAG('P', 'A', 'U', 'T'),156157/**158* Volume control message.159*160* Set volume level. It may be device-dependent if volume161* is changed per stream or system wide. Per stream volume162* change is expected when possible.163*164* data: double: new volume with range of 0.0 - 1.0.165*/166AV_APP_TO_DEV_SET_VOLUME = MKBETAG('S', 'V', 'O', 'L'),167168/**169* Mute control messages.170*171* Change mute state. It may be device-dependent if mute status172* is changed per stream or system wide. Per stream mute status173* change is expected when possible.174*175* data: NULL.176*/177AV_APP_TO_DEV_MUTE = MKBETAG(' ', 'M', 'U', 'T'),178AV_APP_TO_DEV_UNMUTE = MKBETAG('U', 'M', 'U', 'T'),179AV_APP_TO_DEV_TOGGLE_MUTE = MKBETAG('T', 'M', 'U', 'T'),180181/**182* Get volume/mute messages.183*184* Force the device to send AV_DEV_TO_APP_VOLUME_LEVEL_CHANGED or185* AV_DEV_TO_APP_MUTE_STATE_CHANGED command respectively.186*187* data: NULL.188*/189AV_APP_TO_DEV_GET_VOLUME = MKBETAG('G', 'V', 'O', 'L'),190AV_APP_TO_DEV_GET_MUTE = MKBETAG('G', 'M', 'U', 'T'),191};192193/**194* Message types used by avdevice_dev_to_app_control_message().195*/196enum AVDevToAppMessageType {197/**198* Dummy message.199*/200AV_DEV_TO_APP_NONE = MKBETAG('N','O','N','E'),201202/**203* Create window buffer message.204*205* Device requests to create a window buffer. Exact meaning is device-206* and application-dependent. Message is sent before rendering first207* frame and all one-shot initializations should be done here.208* Application is allowed to ignore preferred window buffer size.209*210* @note: Application is obligated to inform about window buffer size211* with AV_APP_TO_DEV_WINDOW_SIZE message.212*213* data: AVDeviceRect: preferred size of the window buffer.214* NULL: no preferred size of the window buffer.215*/216AV_DEV_TO_APP_CREATE_WINDOW_BUFFER = MKBETAG('B','C','R','E'),217218/**219* Prepare window buffer message.220*221* Device requests to prepare a window buffer for rendering.222* Exact meaning is device- and application-dependent.223* Message is sent before rendering of each frame.224*225* data: NULL.226*/227AV_DEV_TO_APP_PREPARE_WINDOW_BUFFER = MKBETAG('B','P','R','E'),228229/**230* Display window buffer message.231*232* Device requests to display a window buffer.233* Message is sent when new frame is ready to be displayed.234* Usually buffers need to be swapped in handler of this message.235*236* data: NULL.237*/238AV_DEV_TO_APP_DISPLAY_WINDOW_BUFFER = MKBETAG('B','D','I','S'),239240/**241* Destroy window buffer message.242*243* Device requests to destroy a window buffer.244* Message is sent when device is about to be destroyed and window245* buffer is not required anymore.246*247* data: NULL.248*/249AV_DEV_TO_APP_DESTROY_WINDOW_BUFFER = MKBETAG('B','D','E','S'),250251/**252* Buffer fullness status messages.253*254* Device signals buffer overflow/underflow.255*256* data: NULL.257*/258AV_DEV_TO_APP_BUFFER_OVERFLOW = MKBETAG('B','O','F','L'),259AV_DEV_TO_APP_BUFFER_UNDERFLOW = MKBETAG('B','U','F','L'),260261/**262* Buffer readable/writable.263*264* Device informs that buffer is readable/writable.265* When possible, device informs how many bytes can be read/write.266*267* @warning Device may not inform when number of bytes than can be read/write changes.268*269* data: int64_t: amount of bytes available to read/write.270* NULL: amount of bytes available to read/write is not known.271*/272AV_DEV_TO_APP_BUFFER_READABLE = MKBETAG('B','R','D',' '),273AV_DEV_TO_APP_BUFFER_WRITABLE = MKBETAG('B','W','R',' '),274275/**276* Mute state change message.277*278* Device informs that mute state has changed.279*280* data: int: 0 for not muted state, non-zero for muted state.281*/282AV_DEV_TO_APP_MUTE_STATE_CHANGED = MKBETAG('C','M','U','T'),283284/**285* Volume level change message.286*287* Device informs that volume level has changed.288*289* data: double: new volume with range of 0.0 - 1.0.290*/291AV_DEV_TO_APP_VOLUME_LEVEL_CHANGED = MKBETAG('C','V','O','L'),292};293294/**295* Send control message from application to device.296*297* @param s device context.298* @param type message type.299* @param data message data. Exact type depends on message type.300* @param data_size size of message data.301* @return >= 0 on success, negative on error.302* AVERROR(ENOSYS) when device doesn't implement handler of the message.303*/304int avdevice_app_to_dev_control_message(struct AVFormatContext *s,305enum AVAppToDevMessageType type,306void *data, size_t data_size);307308/**309* Send control message from device to application.310*311* @param s device context.312* @param type message type.313* @param data message data. Can be NULL.314* @param data_size size of message data.315* @return >= 0 on success, negative on error.316* AVERROR(ENOSYS) when application doesn't implement handler of the message.317*/318int avdevice_dev_to_app_control_message(struct AVFormatContext *s,319enum AVDevToAppMessageType type,320void *data, size_t data_size);321322/**323* Following API allows user to probe device capabilities (supported codecs,324* pixel formats, sample formats, resolutions, channel counts, etc).325* It is build on top op AVOption API.326* Queried capabilities make it possible to set up converters of video or audio327* parameters that fit to the device.328*329* List of capabilities that can be queried:330* - Capabilities valid for both audio and video devices:331* - codec: supported audio/video codecs.332* type: AV_OPT_TYPE_INT (AVCodecID value)333* - Capabilities valid for audio devices:334* - sample_format: supported sample formats.335* type: AV_OPT_TYPE_INT (AVSampleFormat value)336* - sample_rate: supported sample rates.337* type: AV_OPT_TYPE_INT338* - channels: supported number of channels.339* type: AV_OPT_TYPE_INT340* - channel_layout: supported channel layouts.341* type: AV_OPT_TYPE_INT64342* - Capabilities valid for video devices:343* - pixel_format: supported pixel formats.344* type: AV_OPT_TYPE_INT (AVPixelFormat value)345* - window_size: supported window sizes (describes size of the window size presented to the user).346* type: AV_OPT_TYPE_IMAGE_SIZE347* - frame_size: supported frame sizes (describes size of provided video frames).348* type: AV_OPT_TYPE_IMAGE_SIZE349* - fps: supported fps values350* type: AV_OPT_TYPE_RATIONAL351*352* Value of the capability may be set by user using av_opt_set() function353* and AVDeviceCapabilitiesQuery object. Following queries will354* limit results to the values matching already set capabilities.355* For example, setting a codec may impact number of formats or fps values356* returned during next query. Setting invalid value may limit results to zero.357*358* Example of the usage basing on opengl output device:359*360* @code361* AVFormatContext *oc = NULL;362* AVDeviceCapabilitiesQuery *caps = NULL;363* AVOptionRanges *ranges;364* int ret;365*366* if ((ret = avformat_alloc_output_context2(&oc, NULL, "opengl", NULL)) < 0)367* goto fail;368* if (avdevice_capabilities_create(&caps, oc, NULL) < 0)369* goto fail;370*371* //query codecs372* if (av_opt_query_ranges(&ranges, caps, "codec", AV_OPT_MULTI_COMPONENT_RANGE)) < 0)373* goto fail;374* //pick codec here and set it375* av_opt_set(caps, "codec", AV_CODEC_ID_RAWVIDEO, 0);376*377* //query format378* if (av_opt_query_ranges(&ranges, caps, "pixel_format", AV_OPT_MULTI_COMPONENT_RANGE)) < 0)379* goto fail;380* //pick format here and set it381* av_opt_set(caps, "pixel_format", AV_PIX_FMT_YUV420P, 0);382*383* //query and set more capabilities384*385* fail:386* //clean up code387* avdevice_capabilities_free(&query, oc);388* avformat_free_context(oc);389* @endcode390*/391392/**393* Structure describes device capabilities.394*395* It is used by devices in conjunction with av_device_capabilities AVOption table396* to implement capabilities probing API based on AVOption API. Should not be used directly.397*/398typedef struct AVDeviceCapabilitiesQuery {399const AVClass *av_class;400AVFormatContext *device_context;401enum AVCodecID codec;402enum AVSampleFormat sample_format;403enum AVPixelFormat pixel_format;404int sample_rate;405int channels;406int64_t channel_layout;407int window_width;408int window_height;409int frame_width;410int frame_height;411AVRational fps;412} AVDeviceCapabilitiesQuery;413414/**415* AVOption table used by devices to implement device capabilities API. Should not be used by a user.416*/417extern const AVOption av_device_capabilities[];418419/**420* Initialize capabilities probing API based on AVOption API.421*422* avdevice_capabilities_free() must be called when query capabilities API is423* not used anymore.424*425* @param[out] caps Device capabilities data. Pointer to a NULL pointer must be passed.426* @param s Context of the device.427* @param device_options An AVDictionary filled with device-private options.428* On return this parameter will be destroyed and replaced with a dict429* containing options that were not found. May be NULL.430* The same options must be passed later to avformat_write_header() for output431* devices or avformat_open_input() for input devices, or at any other place432* that affects device-private options.433*434* @return >= 0 on success, negative otherwise.435*/436int avdevice_capabilities_create(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s,437AVDictionary **device_options);438439/**440* Free resources created by avdevice_capabilities_create()441*442* @param caps Device capabilities data to be freed.443* @param s Context of the device.444*/445void avdevice_capabilities_free(AVDeviceCapabilitiesQuery **caps, AVFormatContext *s);446447/**448* Structure describes basic parameters of the device.449*/450typedef struct AVDeviceInfo {451char *device_name; /**< device name, format depends on device */452char *device_description; /**< human friendly name */453} AVDeviceInfo;454455/**456* List of devices.457*/458typedef struct AVDeviceInfoList {459AVDeviceInfo **devices; /**< list of autodetected devices */460int nb_devices; /**< number of autodetected devices */461int default_device; /**< index of default device or -1 if no default */462} AVDeviceInfoList;463464/**465* List devices.466*467* Returns available device names and their parameters.468*469* @note: Some devices may accept system-dependent device names that cannot be470* autodetected. The list returned by this function cannot be assumed to471* be always completed.472*473* @param s device context.474* @param[out] device_list list of autodetected devices.475* @return count of autodetected devices, negative on error.476*/477int avdevice_list_devices(struct AVFormatContext *s, AVDeviceInfoList **device_list);478479/**480* Convenient function to free result of avdevice_list_devices().481*482* @param devices device list to be freed.483*/484void avdevice_free_list_devices(AVDeviceInfoList **device_list);485486/**487* List devices.488*489* Returns available device names and their parameters.490* These are convinient wrappers for avdevice_list_devices().491* Device context is allocated and deallocated internally.492*493* @param device device format. May be NULL if device name is set.494* @param device_name device name. May be NULL if device format is set.495* @param device_options An AVDictionary filled with device-private options. May be NULL.496* The same options must be passed later to avformat_write_header() for output497* devices or avformat_open_input() for input devices, or at any other place498* that affects device-private options.499* @param[out] device_list list of autodetected devices500* @return count of autodetected devices, negative on error.501* @note device argument takes precedence over device_name when both are set.502*/503int avdevice_list_input_sources(struct AVInputFormat *device, const char *device_name,504AVDictionary *device_options, AVDeviceInfoList **device_list);505int avdevice_list_output_sinks(struct AVOutputFormat *device, const char *device_name,506AVDictionary *device_options, AVDeviceInfoList **device_list);507508#endif /* AVDEVICE_AVDEVICE_H */509510511