obs-encoder.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /******************************************************************************
  2. Copyright (C) 2013-2014 by Hugh Bailey <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #pragma once
  15. /** Specifies the encoder type */
  16. enum obs_encoder_type {
  17. OBS_ENCODER_AUDIO,
  18. OBS_ENCODER_VIDEO
  19. };
  20. /** Encoder output packet */
  21. struct encoder_packet {
  22. uint8_t *data; /**< Packet data */
  23. size_t size; /**< Packet size */
  24. int64_t pts; /**< Presentation timestamp */
  25. int64_t dts; /**< Decode timestamp */
  26. int32_t timebase_num; /**< Timebase numerator */
  27. int32_t timebase_den; /**< Timebase denominator */
  28. enum obs_encoder_type type; /**< Encoder type */
  29. bool keyframe; /**< Is a keyframe */
  30. /**
  31. * Packet priority
  32. *
  33. * This is generally use by video encoders to specify the priority
  34. * of the packet.
  35. */
  36. int priority;
  37. /**
  38. * Dropped packet priority
  39. *
  40. * If this packet needs to be dropped, the next packet must be of this
  41. * priority or higher to continue transmission.
  42. */
  43. int drop_priority;
  44. };
  45. /** Encoder input frame */
  46. struct encoder_frame {
  47. /** Data for the frame/audio */
  48. uint8_t *data[MAX_AV_PLANES];
  49. /** size of each plane */
  50. uint32_t linesize[MAX_AV_PLANES];
  51. /** Number of frames (audio only) */
  52. uint32_t frames;
  53. /** Presentation timestamp */
  54. int64_t pts;
  55. };
  56. /**
  57. * Encoder interface
  58. *
  59. * Encoders have a limited usage with OBS. You are not generally supposed to
  60. * implement every encoder out there. Generally, these are limited or specific
  61. * encoders for h264/aac for streaming and recording. It doesn't have to be
  62. * *just* h264 or aac of course, but generally those are the expected encoders.
  63. *
  64. * That being said, other encoders will be kept in mind for future use.
  65. */
  66. struct obs_encoder_info {
  67. /* ----------------------------------------------------------------- */
  68. /* Required implementation*/
  69. /** Specifies the named identifier of this encoder */
  70. const char *id;
  71. /** Specifies the encoder type (video or audio) */
  72. enum obs_encoder_type type;
  73. /** Specifies the codec */
  74. const char *codec;
  75. /**
  76. * Gets the full translated name of this encoder
  77. *
  78. * @param locale Locale to use for translation
  79. * @return Translated name of the encoder
  80. */
  81. const char *(*getname)(const char *locale);
  82. /**
  83. * Creates the encoder with the specified settings
  84. *
  85. * @param settings Settings for the encoder
  86. * @param encoder OBS encoder context
  87. * @return Data associated with this encoder context
  88. */
  89. void *(*create)(obs_data_t settings, obs_encoder_t encoder);
  90. /**
  91. * Destroys the encoder data
  92. *
  93. * @param data Data associated with this encoder context
  94. */
  95. void (*destroy)(void *data);
  96. /**
  97. * Initializes the encoder with the specified settings
  98. *
  99. * @param data Data associated with this encoder context
  100. * @param settings Settings for the encoder
  101. * @return true if the encoder settings are valid and the
  102. * encoder is ready to be used, false otherwise
  103. */
  104. bool (*initialize)(void *data, obs_data_t settings);
  105. /**
  106. * Encodes frame(s), and outputs encoded packets as they become
  107. * available.
  108. *
  109. * @param data Data associated with this encoder
  110. * context
  111. * @param[in] frame Raw audio/video data to encode
  112. * @param[out] packet Encoder packet output, if any
  113. * @param[out] received_packet Set to true if a packet was received,
  114. * false otherwise
  115. * @return true if successful, false otherwise.
  116. */
  117. bool (*encode)(void *data, struct encoder_frame *frame,
  118. struct encoder_packet *packet, bool *received_packet);
  119. /* ----------------------------------------------------------------- */
  120. /* Optional implementation */
  121. /**
  122. * Gets the default settings for this encoder
  123. *
  124. * @param[out] settings Data to assign default settings to
  125. */
  126. void (*defaults)(obs_data_t settings);
  127. /**
  128. * Gets the property information of this encoder
  129. *
  130. * @param locale The locale to translate with
  131. * @return The properties data
  132. */
  133. obs_properties_t (*properties)(const char *locale);
  134. /**
  135. * Updates the settings for this encoder (usually used for things like
  136. * changeing birate while active)
  137. *
  138. * @param data Data associated with this encoder context
  139. * @param settings New settings for this encoder
  140. * @return true if successful, false otherwise
  141. */
  142. bool (*update)(void *data, obs_data_t settings);
  143. /**
  144. * Returns extra data associated with this encoder (usually header)
  145. *
  146. * @param data Data associated with this encoder context
  147. * @param[out] extra_data Pointer to receive the extra data
  148. * @param[out] size Pointer to receive the size of the extra
  149. * data
  150. * @return true if extra data available, false
  151. * otherwise
  152. */
  153. bool (*extra_data)(void *data, uint8_t **extra_data, size_t *size);
  154. /**
  155. * Gets the SEI data, if any
  156. *
  157. * @param data Data associated with this encoder context
  158. * @param[out] sei_data Pointer to receive the SEI data
  159. * @param[out] size Pointer to receive the SEI data size
  160. * @return true if SEI data available, false otherwise
  161. */
  162. bool (*sei_data)(void *data, uint8_t **sei_data, size_t *size);
  163. /**
  164. * Returns desired audio format and sample information
  165. *
  166. * @param data Data associated with this encoder context
  167. * @param[out] info Audio format information
  168. * @return true if specific format is desired, false
  169. * otherwise
  170. */
  171. bool (*audio_info)(void *data, struct audio_convert_info *info);
  172. /**
  173. * Returns desired video format information
  174. *
  175. * @param data Data associated with this encoder context
  176. * @param[out] info Video format information
  177. * @return true if specific format is desired, false
  178. * otherwise
  179. */
  180. bool (*video_info)(void *data, struct video_scale_info *info);
  181. };
  182. /**
  183. * Register an encoder definition to the current obs context. This should be
  184. * used in obs_module_load.
  185. *
  186. * @param info Pointer to the source definition structure.
  187. */
  188. EXPORT void obs_register_encoder(const struct obs_encoder_info *info);