Path: blob/master/dep/ffmpeg/include/libavdevice/avdevice.h
4216 views
/*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_major.h"22#ifndef HAVE_AV_CONFIG_H23/* When included as part of the ffmpeg build, only include the major version24* to avoid unnecessary rebuilds. When included externally, keep including25* the full version information. */26#include "version.h"27#endif2829/**30* @file31* @ingroup lavd32* Main libavdevice API header33*/3435/**36* @defgroup lavd libavdevice37* Special devices muxing/demuxing library.38*39* Libavdevice is a complementary library to @ref libavf "libavformat". It40* provides various "special" platform-specific muxers and demuxers, e.g. for41* grabbing devices, audio capture and playback etc. As a consequence, the42* (de)muxers in libavdevice are of the AVFMT_NOFILE type (they use their own43* I/O functions). The filename passed to avformat_open_input() often does not44* refer to an actually existing file, but has some special device-specific45* meaning - e.g. for xcbgrab it is the display name.46*47* To use libavdevice, simply call avdevice_register_all() to register all48* compiled muxers and demuxers. They all use standard libavformat API.49*50* @{51*/5253#include "libavutil/log.h"54#include "libavutil/opt.h"55#include "libavutil/dict.h"56#include "libavformat/avformat.h"5758/**59* Return the LIBAVDEVICE_VERSION_INT constant.60*/61unsigned avdevice_version(void);6263/**64* Return the libavdevice build-time configuration.65*/66const char *avdevice_configuration(void);6768/**69* Return the libavdevice license.70*/71const char *avdevice_license(void);7273/**74* Initialize libavdevice and register all the input and output devices.75*/76void avdevice_register_all(void);7778/**79* Audio input devices iterator.80*81* If d is NULL, returns the first registered input audio/video device,82* if d is non-NULL, returns the next registered input audio/video device after d83* or NULL if d is the last one.84*/85const AVInputFormat *av_input_audio_device_next(const AVInputFormat *d);8687/**88* Video input devices iterator.89*90* If d is NULL, returns the first registered input audio/video device,91* if d is non-NULL, returns the next registered input audio/video device after d92* or NULL if d is the last one.93*/94const AVInputFormat *av_input_video_device_next(const AVInputFormat *d);9596/**97* Audio output devices iterator.98*99* If d is NULL, returns the first registered output audio/video device,100* if d is non-NULL, returns the next registered output audio/video device after d101* or NULL if d is the last one.102*/103const AVOutputFormat *av_output_audio_device_next(const AVOutputFormat *d);104105/**106* Video output devices iterator.107*108* If d is NULL, returns the first registered output audio/video device,109* if d is non-NULL, returns the next registered output audio/video device after d110* or NULL if d is the last one.111*/112const AVOutputFormat *av_output_video_device_next(const AVOutputFormat *d);113114typedef struct AVDeviceRect {115int x; /**< x coordinate of top left corner */116int y; /**< y coordinate of top left corner */117int width; /**< width */118int height; /**< height */119} AVDeviceRect;120121/**122* Message types used by avdevice_app_to_dev_control_message().123*/124enum AVAppToDevMessageType {125/**126* Dummy message.127*/128AV_APP_TO_DEV_NONE = MKBETAG('N','O','N','E'),129130/**131* Window size change message.132*133* Message is sent to the device every time the application changes the size134* of the window device renders to.135* Message should also be sent right after window is created.136*137* data: AVDeviceRect: new window size.138*/139AV_APP_TO_DEV_WINDOW_SIZE = MKBETAG('G','E','O','M'),140141/**142* Repaint request message.143*144* Message is sent to the device when window has to be repainted.145*146* data: AVDeviceRect: area required to be repainted.147* NULL: whole area is required to be repainted.148*/149AV_APP_TO_DEV_WINDOW_REPAINT = MKBETAG('R','E','P','A'),150151/**152* Request pause/play.153*154* Application requests pause/unpause playback.155* Mostly usable with devices that have internal buffer.156* By default devices are not paused.157*158* data: NULL159*/160AV_APP_TO_DEV_PAUSE = MKBETAG('P', 'A', 'U', ' '),161AV_APP_TO_DEV_PLAY = MKBETAG('P', 'L', 'A', 'Y'),162AV_APP_TO_DEV_TOGGLE_PAUSE = MKBETAG('P', 'A', 'U', 'T'),163164/**165* Volume control message.166*167* Set volume level. It may be device-dependent if volume168* is changed per stream or system wide. Per stream volume169* change is expected when possible.170*171* data: double: new volume with range of 0.0 - 1.0.172*/173AV_APP_TO_DEV_SET_VOLUME = MKBETAG('S', 'V', 'O', 'L'),174175/**176* Mute control messages.177*178* Change mute state. It may be device-dependent if mute status179* is changed per stream or system wide. Per stream mute status180* change is expected when possible.181*182* data: NULL.183*/184AV_APP_TO_DEV_MUTE = MKBETAG(' ', 'M', 'U', 'T'),185AV_APP_TO_DEV_UNMUTE = MKBETAG('U', 'M', 'U', 'T'),186AV_APP_TO_DEV_TOGGLE_MUTE = MKBETAG('T', 'M', 'U', 'T'),187188/**189* Get volume/mute messages.190*191* Force the device to send AV_DEV_TO_APP_VOLUME_LEVEL_CHANGED or192* AV_DEV_TO_APP_MUTE_STATE_CHANGED command respectively.193*194* data: NULL.195*/196AV_APP_TO_DEV_GET_VOLUME = MKBETAG('G', 'V', 'O', 'L'),197AV_APP_TO_DEV_GET_MUTE = MKBETAG('G', 'M', 'U', 'T'),198};199200/**201* Message types used by avdevice_dev_to_app_control_message().202*/203enum AVDevToAppMessageType {204/**205* Dummy message.206*/207AV_DEV_TO_APP_NONE = MKBETAG('N','O','N','E'),208209/**210* Create window buffer message.211*212* Device requests to create a window buffer. Exact meaning is device-213* and application-dependent. Message is sent before rendering first214* frame and all one-shot initializations should be done here.215* Application is allowed to ignore preferred window buffer size.216*217* @note: Application is obligated to inform about window buffer size218* with AV_APP_TO_DEV_WINDOW_SIZE message.219*220* data: AVDeviceRect: preferred size of the window buffer.221* NULL: no preferred size of the window buffer.222*/223AV_DEV_TO_APP_CREATE_WINDOW_BUFFER = MKBETAG('B','C','R','E'),224225/**226* Prepare window buffer message.227*228* Device requests to prepare a window buffer for rendering.229* Exact meaning is device- and application-dependent.230* Message is sent before rendering of each frame.231*232* data: NULL.233*/234AV_DEV_TO_APP_PREPARE_WINDOW_BUFFER = MKBETAG('B','P','R','E'),235236/**237* Display window buffer message.238*239* Device requests to display a window buffer.240* Message is sent when new frame is ready to be displayed.241* Usually buffers need to be swapped in handler of this message.242*243* data: NULL.244*/245AV_DEV_TO_APP_DISPLAY_WINDOW_BUFFER = MKBETAG('B','D','I','S'),246247/**248* Destroy window buffer message.249*250* Device requests to destroy a window buffer.251* Message is sent when device is about to be destroyed and window252* buffer is not required anymore.253*254* data: NULL.255*/256AV_DEV_TO_APP_DESTROY_WINDOW_BUFFER = MKBETAG('B','D','E','S'),257258/**259* Buffer fullness status messages.260*261* Device signals buffer overflow/underflow.262*263* data: NULL.264*/265AV_DEV_TO_APP_BUFFER_OVERFLOW = MKBETAG('B','O','F','L'),266AV_DEV_TO_APP_BUFFER_UNDERFLOW = MKBETAG('B','U','F','L'),267268/**269* Buffer readable/writable.270*271* Device informs that buffer is readable/writable.272* When possible, device informs how many bytes can be read/write.273*274* @warning Device may not inform when number of bytes than can be read/write changes.275*276* data: int64_t: amount of bytes available to read/write.277* NULL: amount of bytes available to read/write is not known.278*/279AV_DEV_TO_APP_BUFFER_READABLE = MKBETAG('B','R','D',' '),280AV_DEV_TO_APP_BUFFER_WRITABLE = MKBETAG('B','W','R',' '),281282/**283* Mute state change message.284*285* Device informs that mute state has changed.286*287* data: int: 0 for not muted state, non-zero for muted state.288*/289AV_DEV_TO_APP_MUTE_STATE_CHANGED = MKBETAG('C','M','U','T'),290291/**292* Volume level change message.293*294* Device informs that volume level has changed.295*296* data: double: new volume with range of 0.0 - 1.0.297*/298AV_DEV_TO_APP_VOLUME_LEVEL_CHANGED = MKBETAG('C','V','O','L'),299};300301/**302* Send control message from application to device.303*304* @param s device context.305* @param type message type.306* @param data message data. Exact type depends on message type.307* @param data_size size of message data.308* @return >= 0 on success, negative on error.309* AVERROR(ENOSYS) when device doesn't implement handler of the message.310*/311int avdevice_app_to_dev_control_message(struct AVFormatContext *s,312enum AVAppToDevMessageType type,313void *data, size_t data_size);314315/**316* Send control message from device to application.317*318* @param s device context.319* @param type message type.320* @param data message data. Can be NULL.321* @param data_size size of message data.322* @return >= 0 on success, negative on error.323* AVERROR(ENOSYS) when application doesn't implement handler of the message.324*/325int avdevice_dev_to_app_control_message(struct AVFormatContext *s,326enum AVDevToAppMessageType type,327void *data, size_t data_size);328329/**330* Structure describes basic parameters of the device.331*/332typedef struct AVDeviceInfo {333char *device_name; /**< device name, format depends on device */334char *device_description; /**< human friendly name */335enum AVMediaType *media_types; /**< array indicating what media types(s), if any, a device can provide. If null, cannot provide any */336int nb_media_types; /**< length of media_types array, 0 if device cannot provide any media types */337} AVDeviceInfo;338339/**340* List of devices.341*/342typedef struct AVDeviceInfoList {343AVDeviceInfo **devices; /**< list of autodetected devices */344int nb_devices; /**< number of autodetected devices */345int default_device; /**< index of default device or -1 if no default */346} AVDeviceInfoList;347348/**349* List devices.350*351* Returns available device names and their parameters.352*353* @note: Some devices may accept system-dependent device names that cannot be354* autodetected. The list returned by this function cannot be assumed to355* be always completed.356*357* @param s device context.358* @param[out] device_list list of autodetected devices.359* @return count of autodetected devices, negative on error.360*/361int avdevice_list_devices(struct AVFormatContext *s, AVDeviceInfoList **device_list);362363/**364* Convenient function to free result of avdevice_list_devices().365*366* @param device_list device list to be freed.367*/368void avdevice_free_list_devices(AVDeviceInfoList **device_list);369370/**371* List devices.372*373* Returns available device names and their parameters.374* These are convinient wrappers for avdevice_list_devices().375* Device context is allocated and deallocated internally.376*377* @param device device format. May be NULL if device name is set.378* @param device_name device name. May be NULL if device format is set.379* @param device_options An AVDictionary filled with device-private options. May be NULL.380* The same options must be passed later to avformat_write_header() for output381* devices or avformat_open_input() for input devices, or at any other place382* that affects device-private options.383* @param[out] device_list list of autodetected devices384* @return count of autodetected devices, negative on error.385* @note device argument takes precedence over device_name when both are set.386*/387int avdevice_list_input_sources(const AVInputFormat *device, const char *device_name,388AVDictionary *device_options, AVDeviceInfoList **device_list);389int avdevice_list_output_sinks(const AVOutputFormat *device, const char *device_name,390AVDictionary *device_options, AVDeviceInfoList **device_list);391392/**393* @}394*/395396#endif /* AVDEVICE_AVDEVICE_H */397398399