Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

398 linhas
13KB

  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. #ifndef AVDEVICE_AVDEVICE_H
  19. #define AVDEVICE_AVDEVICE_H
  20. #include "version_major.h"
  21. #ifndef HAVE_AV_CONFIG_H
  22. /* When included as part of the ffmpeg build, only include the major version
  23. * to avoid unnecessary rebuilds. When included externally, keep including
  24. * the full version information. */
  25. #include "version.h"
  26. #endif
  27. /**
  28. * @file
  29. * @ingroup lavd
  30. * Main libavdevice API header
  31. */
  32. /**
  33. * @defgroup lavd libavdevice
  34. * Special devices muxing/demuxing library.
  35. *
  36. * Libavdevice is a complementary library to @ref libavf "libavformat". It
  37. * provides various "special" platform-specific muxers and demuxers, e.g. for
  38. * grabbing devices, audio capture and playback etc. As a consequence, the
  39. * (de)muxers in libavdevice are of the AVFMT_NOFILE type (they use their own
  40. * I/O functions). The filename passed to avformat_open_input() often does not
  41. * refer to an actually existing file, but has some special device-specific
  42. * meaning - e.g. for xcbgrab it is the display name.
  43. *
  44. * To use libavdevice, simply call avdevice_register_all() to register all
  45. * compiled muxers and demuxers. They all use standard libavformat API.
  46. *
  47. * @{
  48. */
  49. #include "libavutil/log.h"
  50. #include "libavutil/opt.h"
  51. #include "libavutil/dict.h"
  52. #include "libavformat/avformat.h"
  53. /**
  54. * Return the LIBAVDEVICE_VERSION_INT constant.
  55. */
  56. unsigned avdevice_version(void);
  57. /**
  58. * Return the libavdevice build-time configuration.
  59. */
  60. const char *avdevice_configuration(void);
  61. /**
  62. * Return the libavdevice license.
  63. */
  64. const char *avdevice_license(void);
  65. /**
  66. * Initialize libavdevice and register all the input and output devices.
  67. */
  68. void avdevice_register_all(void);
  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. const AVInputFormat *av_input_audio_device_next(const AVInputFormat *d);
  77. /**
  78. * Video input devices iterator.
  79. *
  80. * If d is NULL, returns the first registered input audio/video device,
  81. * if d is non-NULL, returns the next registered input audio/video device after d
  82. * or NULL if d is the last one.
  83. */
  84. const AVInputFormat *av_input_video_device_next(const AVInputFormat *d);
  85. /**
  86. * Audio output devices iterator.
  87. *
  88. * If d is NULL, returns the first registered output audio/video device,
  89. * if d is non-NULL, returns the next registered output audio/video device after d
  90. * or NULL if d is the last one.
  91. */
  92. const AVOutputFormat *av_output_audio_device_next(const AVOutputFormat *d);
  93. /**
  94. * Video output devices iterator.
  95. *
  96. * If d is NULL, returns the first registered output audio/video device,
  97. * if d is non-NULL, returns the next registered output audio/video device after d
  98. * or NULL if d is the last one.
  99. */
  100. const AVOutputFormat *av_output_video_device_next(const AVOutputFormat *d);
  101. typedef struct AVDeviceRect {
  102. int x; /**< x coordinate of top left corner */
  103. int y; /**< y coordinate of top left corner */
  104. int width; /**< width */
  105. int height; /**< height */
  106. } AVDeviceRect;
  107. /**
  108. * Message types used by avdevice_app_to_dev_control_message().
  109. */
  110. enum AVAppToDevMessageType {
  111. /**
  112. * Dummy message.
  113. */
  114. AV_APP_TO_DEV_NONE = MKBETAG('N','O','N','E'),
  115. /**
  116. * Window size change message.
  117. *
  118. * Message is sent to the device every time the application changes the size
  119. * of the window device renders to.
  120. * Message should also be sent right after window is created.
  121. *
  122. * data: AVDeviceRect: new window size.
  123. */
  124. AV_APP_TO_DEV_WINDOW_SIZE = MKBETAG('G','E','O','M'),
  125. /**
  126. * Repaint request message.
  127. *
  128. * Message is sent to the device when window has to be repainted.
  129. *
  130. * data: AVDeviceRect: area required to be repainted.
  131. * NULL: whole area is required to be repainted.
  132. */
  133. AV_APP_TO_DEV_WINDOW_REPAINT = MKBETAG('R','E','P','A'),
  134. /**
  135. * Request pause/play.
  136. *
  137. * Application requests pause/unpause playback.
  138. * Mostly usable with devices that have internal buffer.
  139. * By default devices are not paused.
  140. *
  141. * data: NULL
  142. */
  143. AV_APP_TO_DEV_PAUSE = MKBETAG('P', 'A', 'U', ' '),
  144. AV_APP_TO_DEV_PLAY = MKBETAG('P', 'L', 'A', 'Y'),
  145. AV_APP_TO_DEV_TOGGLE_PAUSE = MKBETAG('P', 'A', 'U', 'T'),
  146. /**
  147. * Volume control message.
  148. *
  149. * Set volume level. It may be device-dependent if volume
  150. * is changed per stream or system wide. Per stream volume
  151. * change is expected when possible.
  152. *
  153. * data: double: new volume with range of 0.0 - 1.0.
  154. */
  155. AV_APP_TO_DEV_SET_VOLUME = MKBETAG('S', 'V', 'O', 'L'),
  156. /**
  157. * Mute control messages.
  158. *
  159. * Change mute state. It may be device-dependent if mute status
  160. * is changed per stream or system wide. Per stream mute status
  161. * change is expected when possible.
  162. *
  163. * data: NULL.
  164. */
  165. AV_APP_TO_DEV_MUTE = MKBETAG(' ', 'M', 'U', 'T'),
  166. AV_APP_TO_DEV_UNMUTE = MKBETAG('U', 'M', 'U', 'T'),
  167. AV_APP_TO_DEV_TOGGLE_MUTE = MKBETAG('T', 'M', 'U', 'T'),
  168. /**
  169. * Get volume/mute messages.
  170. *
  171. * Force the device to send AV_DEV_TO_APP_VOLUME_LEVEL_CHANGED or
  172. * AV_DEV_TO_APP_MUTE_STATE_CHANGED command respectively.
  173. *
  174. * data: NULL.
  175. */
  176. AV_APP_TO_DEV_GET_VOLUME = MKBETAG('G', 'V', 'O', 'L'),
  177. AV_APP_TO_DEV_GET_MUTE = MKBETAG('G', 'M', 'U', 'T'),
  178. };
  179. /**
  180. * Message types used by avdevice_dev_to_app_control_message().
  181. */
  182. enum AVDevToAppMessageType {
  183. /**
  184. * Dummy message.
  185. */
  186. AV_DEV_TO_APP_NONE = MKBETAG('N','O','N','E'),
  187. /**
  188. * Create window buffer message.
  189. *
  190. * Device requests to create a window buffer. Exact meaning is device-
  191. * and application-dependent. Message is sent before rendering first
  192. * frame and all one-shot initializations should be done here.
  193. * Application is allowed to ignore preferred window buffer size.
  194. *
  195. * @note: Application is obligated to inform about window buffer size
  196. * with AV_APP_TO_DEV_WINDOW_SIZE message.
  197. *
  198. * data: AVDeviceRect: preferred size of the window buffer.
  199. * NULL: no preferred size of the window buffer.
  200. */
  201. AV_DEV_TO_APP_CREATE_WINDOW_BUFFER = MKBETAG('B','C','R','E'),
  202. /**
  203. * Prepare window buffer message.
  204. *
  205. * Device requests to prepare a window buffer for rendering.
  206. * Exact meaning is device- and application-dependent.
  207. * Message is sent before rendering of each frame.
  208. *
  209. * data: NULL.
  210. */
  211. AV_DEV_TO_APP_PREPARE_WINDOW_BUFFER = MKBETAG('B','P','R','E'),
  212. /**
  213. * Display window buffer message.
  214. *
  215. * Device requests to display a window buffer.
  216. * Message is sent when new frame is ready to be displayed.
  217. * Usually buffers need to be swapped in handler of this message.
  218. *
  219. * data: NULL.
  220. */
  221. AV_DEV_TO_APP_DISPLAY_WINDOW_BUFFER = MKBETAG('B','D','I','S'),
  222. /**
  223. * Destroy window buffer message.
  224. *
  225. * Device requests to destroy a window buffer.
  226. * Message is sent when device is about to be destroyed and window
  227. * buffer is not required anymore.
  228. *
  229. * data: NULL.
  230. */
  231. AV_DEV_TO_APP_DESTROY_WINDOW_BUFFER = MKBETAG('B','D','E','S'),
  232. /**
  233. * Buffer fullness status messages.
  234. *
  235. * Device signals buffer overflow/underflow.
  236. *
  237. * data: NULL.
  238. */
  239. AV_DEV_TO_APP_BUFFER_OVERFLOW = MKBETAG('B','O','F','L'),
  240. AV_DEV_TO_APP_BUFFER_UNDERFLOW = MKBETAG('B','U','F','L'),
  241. /**
  242. * Buffer readable/writable.
  243. *
  244. * Device informs that buffer is readable/writable.
  245. * When possible, device informs how many bytes can be read/write.
  246. *
  247. * @warning Device may not inform when number of bytes than can be read/write changes.
  248. *
  249. * data: int64_t: amount of bytes available to read/write.
  250. * NULL: amount of bytes available to read/write is not known.
  251. */
  252. AV_DEV_TO_APP_BUFFER_READABLE = MKBETAG('B','R','D',' '),
  253. AV_DEV_TO_APP_BUFFER_WRITABLE = MKBETAG('B','W','R',' '),
  254. /**
  255. * Mute state change message.
  256. *
  257. * Device informs that mute state has changed.
  258. *
  259. * data: int: 0 for not muted state, non-zero for muted state.
  260. */
  261. AV_DEV_TO_APP_MUTE_STATE_CHANGED = MKBETAG('C','M','U','T'),
  262. /**
  263. * Volume level change message.
  264. *
  265. * Device informs that volume level has changed.
  266. *
  267. * data: double: new volume with range of 0.0 - 1.0.
  268. */
  269. AV_DEV_TO_APP_VOLUME_LEVEL_CHANGED = MKBETAG('C','V','O','L'),
  270. };
  271. /**
  272. * Send control message from application to device.
  273. *
  274. * @param s device context.
  275. * @param type message type.
  276. * @param data message data. Exact type depends on message type.
  277. * @param data_size size of message data.
  278. * @return >= 0 on success, negative on error.
  279. * AVERROR(ENOSYS) when device doesn't implement handler of the message.
  280. */
  281. int avdevice_app_to_dev_control_message(struct AVFormatContext *s,
  282. enum AVAppToDevMessageType type,
  283. void *data, size_t data_size);
  284. /**
  285. * Send control message from device to application.
  286. *
  287. * @param s device context.
  288. * @param type message type.
  289. * @param data message data. Can be NULL.
  290. * @param data_size size of message data.
  291. * @return >= 0 on success, negative on error.
  292. * AVERROR(ENOSYS) when application doesn't implement handler of the message.
  293. */
  294. int avdevice_dev_to_app_control_message(struct AVFormatContext *s,
  295. enum AVDevToAppMessageType type,
  296. void *data, size_t data_size);
  297. /**
  298. * Structure describes basic parameters of the device.
  299. */
  300. typedef struct AVDeviceInfo {
  301. char *device_name; /**< device name, format depends on device */
  302. char *device_description; /**< human friendly name */
  303. enum AVMediaType *media_types; /**< array indicating what media types(s), if any, a device can provide. If null, cannot provide any */
  304. int nb_media_types; /**< length of media_types array, 0 if device cannot provide any media types */
  305. } AVDeviceInfo;
  306. /**
  307. * List of devices.
  308. */
  309. typedef struct AVDeviceInfoList {
  310. AVDeviceInfo **devices; /**< list of autodetected devices */
  311. int nb_devices; /**< number of autodetected devices */
  312. int default_device; /**< index of default device or -1 if no default */
  313. } AVDeviceInfoList;
  314. /**
  315. * List devices.
  316. *
  317. * Returns available device names and their parameters.
  318. *
  319. * @note: Some devices may accept system-dependent device names that cannot be
  320. * autodetected. The list returned by this function cannot be assumed to
  321. * be always completed.
  322. *
  323. * @param s device context.
  324. * @param[out] device_list list of autodetected devices.
  325. * @return count of autodetected devices, negative on error.
  326. */
  327. int avdevice_list_devices(struct AVFormatContext *s, AVDeviceInfoList **device_list);
  328. /**
  329. * Convenient function to free result of avdevice_list_devices().
  330. *
  331. * @param device_list device list to be freed.
  332. */
  333. void avdevice_free_list_devices(AVDeviceInfoList **device_list);
  334. /**
  335. * List devices.
  336. *
  337. * Returns available device names and their parameters.
  338. * These are convinient wrappers for avdevice_list_devices().
  339. * Device context is allocated and deallocated internally.
  340. *
  341. * @param device device format. May be NULL if device name is set.
  342. * @param device_name device name. May be NULL if device format is set.
  343. * @param device_options An AVDictionary filled with device-private options. May be NULL.
  344. * The same options must be passed later to avformat_write_header() for output
  345. * devices or avformat_open_input() for input devices, or at any other place
  346. * that affects device-private options.
  347. * @param[out] device_list list of autodetected devices
  348. * @return count of autodetected devices, negative on error.
  349. * @note device argument takes precedence over device_name when both are set.
  350. */
  351. int avdevice_list_input_sources(const AVInputFormat *device, const char *device_name,
  352. AVDictionary *device_options, AVDeviceInfoList **device_list);
  353. int avdevice_list_output_sinks(const AVOutputFormat *device, const char *device_name,
  354. AVDictionary *device_options, AVDeviceInfoList **device_list);
  355. /**
  356. * @}
  357. */
  358. #endif /* AVDEVICE_AVDEVICE_H */