]> git.sesse.net Git - ffmpeg/blob - libavdevice/avdevice.h
Merge commit '4754345027eb85cfa51aeb88beec68d7b036c11e'
[ffmpeg] / libavdevice / avdevice.h
1 /*
2  * This file is part of FFmpeg.
3  *
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.
8  *
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.
13  *
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
17  */
18
19 #ifndef AVDEVICE_AVDEVICE_H
20 #define AVDEVICE_AVDEVICE_H
21
22 #include "version.h"
23
24 /**
25  * @file
26  * @ingroup lavd
27  * Main libavdevice API header
28  */
29
30 /**
31  * @defgroup lavd Special devices muxing/demuxing library
32  * @{
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.
40  *
41  * To use libavdevice, simply call avdevice_register_all() to register all
42  * compiled muxers and demuxers. They all use standard libavformat API.
43  * @}
44  */
45
46 #include "libavformat/avformat.h"
47
48 /**
49  * Return the LIBAVDEVICE_VERSION_INT constant.
50  */
51 unsigned avdevice_version(void);
52
53 /**
54  * Return the libavdevice build-time configuration.
55  */
56 const char *avdevice_configuration(void);
57
58 /**
59  * Return the libavdevice license.
60  */
61 const char *avdevice_license(void);
62
63 /**
64  * Initialize libavdevice and register all the input and output devices.
65  * @warning This function is not thread safe.
66  */
67 void avdevice_register_all(void);
68
69 /**
70  * Audio input devices iterator.
71  *
72  * If d is NULL, returns the first registered input audio/video device,
73  * if d is non-NULL, returns the next registered input audio/video device after d
74  * or NULL if d is the last one.
75  */
76 AVInputFormat *av_input_audio_device_next(AVInputFormat  *d);
77
78 /**
79  * Video 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 d
83  * or NULL if d is the last one.
84  */
85 AVInputFormat *av_input_video_device_next(AVInputFormat  *d);
86
87 /**
88  * Audio output devices iterator.
89  *
90  * If d is NULL, returns the first registered output audio/video device,
91  * if d is non-NULL, returns the next registered output audio/video device after d
92  * or NULL if d is the last one.
93  */
94 AVOutputFormat *av_output_audio_device_next(AVOutputFormat *d);
95
96 /**
97  * Video 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 d
101  * or NULL if d is the last one.
102  */
103 AVOutputFormat *av_output_video_device_next(AVOutputFormat *d);
104
105 typedef struct AVDeviceRect {
106     int x;      /**< x coordinate of top left corner */
107     int y;      /**< y coordinate of top left corner */
108     int width;  /**< width */
109     int height; /**< height */
110 } AVDeviceRect;
111
112 /**
113  * Message types used by avdevice_app_to_dev_control_message().
114  */
115 enum AVAppToDevMessageType {
116     /**
117      * Dummy message.
118      */
119     AV_APP_TO_DEV_NONE = MKBETAG('N','O','N','E'),
120
121     /**
122      * Window size change message.
123      *
124      * Message is sent to the device every time the application changes the size
125      * of the window device renders to.
126      * Message should also be sent right after window is created.
127      *
128      * data: AVDeviceRect: new window size.
129      */
130     AV_APP_TO_DEV_WINDOW_SIZE = MKBETAG('G','E','O','M'),
131
132     /**
133      * Repaint request message.
134      *
135      * Message is sent to the device when window have to be rapainted.
136      *
137      * data: AVDeviceRect: area required to be repainted.
138      *       NULL: whole area is required to be repainted.
139      */
140     AV_APP_TO_DEV_WINDOW_REPAINT = MKBETAG('R','E','P','A')
141 };
142
143 /**
144  * Message types used by avdevice_dev_to_app_control_message().
145  */
146 enum AVDevToAppMessageType {
147     /**
148      * Dummy message.
149      */
150     AV_DEV_TO_APP_NONE = MKBETAG('N','O','N','E'),
151
152     /**
153      * Create window buffer message.
154      *
155      * Device requests to create a window buffer. Exact meaning is device-
156      * and application-dependent. Message is sent before rendering first
157      * frame and all one-shot initializations should be done here.
158      * Application is allowed to ignore preferred window buffer size.
159      *
160      * @note: Application is obligated to inform about window buffer size
161      *        with AV_APP_TO_DEV_WINDOW_SIZE message.
162      *
163      * data: AVDeviceRect: preferred size of the window buffer.
164      *       NULL: no preferred size of the window buffer.
165      */
166     AV_DEV_TO_APP_CREATE_WINDOW_BUFFER = MKBETAG('B','C','R','E'),
167
168     /**
169      * Prepare window buffer message.
170      *
171      * Device requests to prepare a window buffer for rendering.
172      * Exact meaning is device- and application-dependent.
173      * Message is sent before rendering of each frame.
174      *
175      * data: NULL.
176      */
177     AV_DEV_TO_APP_PREPARE_WINDOW_BUFFER = MKBETAG('B','P','R','E'),
178
179     /**
180      * Display window buffer message.
181      *
182      * Device requests to display a window buffer.
183      * Message is sent when new frame is ready to be displyed.
184      * Usually buffers need to be swapped in handler of this message.
185      *
186      * data: NULL.
187      */
188     AV_DEV_TO_APP_DISPLAY_WINDOW_BUFFER = MKBETAG('B','D','I','S'),
189
190     /**
191      * Destroy window buffer message.
192      *
193      * Device requests to destroy a window buffer.
194      * Message is sent when device is about to be destroyed and window
195      * buffer is not required anymore.
196      *
197      * data: NULL.
198      */
199     AV_DEV_TO_APP_DESTROY_WINDOW_BUFFER = MKBETAG('B','D','E','S')
200 };
201
202 /**
203  * Send control message from application to device.
204  *
205  * @param s         device context.
206  * @param type      message type.
207  * @param data      message data. Exact type depends on message type.
208  * @param data_size size of message data.
209  * @return >= 0 on success, negative on error.
210  *         AVERROR(ENOSYS) when device doesn't implement handler of the message.
211  */
212 int avdevice_app_to_dev_control_message(struct AVFormatContext *s,
213                                         enum AVAppToDevMessageType type,
214                                         void *data, size_t data_size);
215
216 /**
217  * Send control message from device to application.
218  *
219  * @param s         device context.
220  * @param type      message type.
221  * @param data      message data. Can be NULL.
222  * @param data_size size of message data.
223  * @return >= 0 on success, negative on error.
224  *         AVERROR(ENOSYS) when application doesn't implement handler of the message.
225  */
226 int avdevice_dev_to_app_control_message(struct AVFormatContext *s,
227                                         enum AVDevToAppMessageType type,
228                                         void *data, size_t data_size);
229
230 /**
231  * Structure describes basic parameters of the device.
232  */
233 typedef struct AVDeviceInfo {
234     char *device_name;                   /**< device name, format depends on device */
235     char *device_description;            /**< human friendly name */
236 } AVDeviceInfo;
237
238 /**
239  * List of devices.
240  */
241 typedef struct AVDeviceInfoList {
242     AVDeviceInfo **devices;              /**< list of autodetected devices */
243     int nb_devices;                      /**< number of autodetected devices */
244     int default_device;                  /**< index of default device or -1 if no default */
245 } AVDeviceInfoList;
246
247 /**
248  * List devices.
249  *
250  * Returns available device names and their parameters.
251  *
252  * @note: Some devices may accept system-dependent device names that cannot be
253  *        autodetected. The list returned by this function cannot be assumed to
254  *        be always completed.
255  *
256  * @param s                device context.
257  * @param[out] device_list list of autodetected devices.
258  * @return count of autodetected devices, negative on error.
259  */
260 int avdevice_list_devices(struct AVFormatContext *s, AVDeviceInfoList **device_list);
261
262 /**
263  * Convinient function to free result of avdevice_list_devices().
264  *
265  * @param devices device list to be freed.
266  */
267 void avdevice_free_list_devices(AVDeviceInfoList **device_list);
268
269 #endif /* AVDEVICE_AVDEVICE_H */