You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

234 lines
7.4KB

  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.h"
  21. /**
  22. * @file
  23. * @ingroup lavd
  24. * Main libavdevice API header
  25. */
  26. /**
  27. * @defgroup lavd Special devices muxing/demuxing library
  28. * @{
  29. * Libavdevice is a complementary library to @ref libavf "libavformat". It
  30. * provides various "special" platform-specific muxers and demuxers, e.g. for
  31. * grabbing devices, audio capture and playback etc. As a consequence, the
  32. * (de)muxers in libavdevice are of the AVFMT_NOFILE type (they use their own
  33. * I/O functions). The filename passed to avformat_open_input() often does not
  34. * refer to an actually existing file, but has some special device-specific
  35. * meaning - e.g. for x11grab it is the display name.
  36. *
  37. * To use libavdevice, simply call avdevice_register_all() to register all
  38. * compiled muxers and demuxers. They all use standard libavformat API.
  39. * @}
  40. */
  41. #include "libavformat/avformat.h"
  42. /**
  43. * Return the LIBAVDEVICE_VERSION_INT constant.
  44. */
  45. unsigned avdevice_version(void);
  46. /**
  47. * Return the libavdevice build-time configuration.
  48. */
  49. const char *avdevice_configuration(void);
  50. /**
  51. * Return the libavdevice license.
  52. */
  53. const char *avdevice_license(void);
  54. /**
  55. * Initialize libavdevice and register all the input and output devices.
  56. * @warning This function is not thread safe.
  57. */
  58. void avdevice_register_all(void);
  59. typedef struct AVDeviceRect {
  60. int x; /**< x coordinate of top left corner */
  61. int y; /**< y coordinate of top left corner */
  62. int width; /**< width */
  63. int height; /**< height */
  64. } AVDeviceRect;
  65. /**
  66. * Message types used by avdevice_app_to_dev_control_message().
  67. */
  68. enum AVAppToDevMessageType {
  69. /**
  70. * Dummy message.
  71. */
  72. AV_APP_TO_DEV_NONE = MKBETAG('N','O','N','E'),
  73. /**
  74. * Window size change message.
  75. *
  76. * Message is sent to the device every time the application changes the size
  77. * of the window device renders to.
  78. * Message should also be sent right after window is created.
  79. *
  80. * data: AVDeviceRect: new window size.
  81. */
  82. AV_APP_TO_DEV_WINDOW_SIZE = MKBETAG('G','E','O','M'),
  83. /**
  84. * Repaint request message.
  85. *
  86. * Message is sent to the device when window have to be rapainted.
  87. *
  88. * data: AVDeviceRect: area required to be repainted.
  89. * NULL: whole area is required to be repainted.
  90. */
  91. AV_APP_TO_DEV_WINDOW_REPAINT = MKBETAG('R','E','P','A')
  92. };
  93. /**
  94. * Message types used by avdevice_dev_to_app_control_message().
  95. */
  96. enum AVDevToAppMessageType {
  97. /**
  98. * Dummy message.
  99. */
  100. AV_DEV_TO_APP_NONE = MKBETAG('N','O','N','E'),
  101. /**
  102. * Create window buffer message.
  103. *
  104. * Device requests to create a window buffer. Exact meaning is device-
  105. * and application-dependent. Message is sent before rendering first
  106. * frame and all one-shot initializations should be done here.
  107. * Application is allowed to ignore preferred window buffer size.
  108. *
  109. * @note: Application is obligated to inform about window buffer size
  110. * with AV_APP_TO_DEV_WINDOW_SIZE message.
  111. *
  112. * data: AVDeviceRect: preferred size of the window buffer.
  113. * NULL: no preferred size of the window buffer.
  114. */
  115. AV_DEV_TO_APP_CREATE_WINDOW_BUFFER = MKBETAG('B','C','R','E'),
  116. /**
  117. * Prepare window buffer message.
  118. *
  119. * Device requests to prepare a window buffer for rendering.
  120. * Exact meaning is device- and application-dependent.
  121. * Message is sent before rendering of each frame.
  122. *
  123. * data: NULL.
  124. */
  125. AV_DEV_TO_APP_PREPARE_WINDOW_BUFFER = MKBETAG('B','P','R','E'),
  126. /**
  127. * Display window buffer message.
  128. *
  129. * Device requests to display a window buffer.
  130. * Message is sent when new frame is ready to be displyed.
  131. * Usually buffers need to be swapped in handler of this message.
  132. *
  133. * data: NULL.
  134. */
  135. AV_DEV_TO_APP_DISPLAY_WINDOW_BUFFER = MKBETAG('B','D','I','S'),
  136. /**
  137. * Destroy window buffer message.
  138. *
  139. * Device requests to destroy a window buffer.
  140. * Message is sent when device is about to be destroyed and window
  141. * buffer is not required anymore.
  142. *
  143. * data: NULL.
  144. */
  145. AV_DEV_TO_APP_DESTROY_WINDOW_BUFFER = MKBETAG('B','D','E','S')
  146. };
  147. /**
  148. * Send control message from application to device.
  149. *
  150. * @param s device context.
  151. * @param type message type.
  152. * @param data message data. Exact type depends on message type.
  153. * @param data_size size of message data.
  154. * @return >= 0 on success, negative on error.
  155. * AVERROR(ENOSYS) when device doesn't implement handler of the message.
  156. */
  157. int avdevice_app_to_dev_control_message(struct AVFormatContext *s,
  158. enum AVAppToDevMessageType type,
  159. void *data, size_t data_size);
  160. /**
  161. * Send control message from device to application.
  162. *
  163. * @param s device context.
  164. * @param type message type.
  165. * @param data message data. Can be NULL.
  166. * @param data_size size of message data.
  167. * @return >= 0 on success, negative on error.
  168. * AVERROR(ENOSYS) when application doesn't implement handler of the message.
  169. */
  170. int avdevice_dev_to_app_control_message(struct AVFormatContext *s,
  171. enum AVDevToAppMessageType type,
  172. void *data, size_t data_size);
  173. /**
  174. * Structure describes basic parameters of the device.
  175. */
  176. typedef struct AVDeviceInfo {
  177. char *device_name; /**< device name, format depends on device */
  178. char *device_description; /**< human friendly name */
  179. } AVDeviceInfo;
  180. /**
  181. * List of devices.
  182. */
  183. typedef struct AVDeviceInfoList {
  184. AVDeviceInfo **devices; /**< list of autodetected devices */
  185. int nb_devices; /**< number of autodetected devices */
  186. int default_device; /**< index of default device or -1 if no default */
  187. } AVDeviceInfoList;
  188. /**
  189. * List devices.
  190. *
  191. * Returns available device names and their parameters.
  192. *
  193. * @note: Some devices may accept system-dependent device names that cannot be
  194. * autodetected. The list returned by this function cannot be assumed to
  195. * be always completed.
  196. *
  197. * @param s device context.
  198. * @param[out] device_list list of autodetected devices.
  199. * @return count of autodetected devices, negative on error.
  200. */
  201. int avdevice_list_devices(struct AVFormatContext *s, AVDeviceInfoList **device_list);
  202. /**
  203. * Convinient function to free result of avdevice_list_devices().
  204. *
  205. * @param devices device list to be freed.
  206. */
  207. void avdevice_free_list_devices(AVDeviceInfoList **device_list);
  208. #endif /* AVDEVICE_AVDEVICE_H */