obs-encoder.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. * Starts the encoder
  98. *
  99. * @param data Data associated with this encoder context
  100. * @param settings Settings for the encoder
  101. * @return true if successful, false otherwise
  102. */
  103. bool (*start)(void *data, obs_data_t settings);
  104. /**
  105. * Encodes frame(s), and outputs encoded packets as they become
  106. * available.
  107. *
  108. * @param data Data associated with this encoder
  109. * context
  110. * @param[in] frame Raw audio/video data to encode
  111. * @param[out] packet Encoder packet output, if any
  112. * @param[out] received_packet Set to true if a packet was received,
  113. * false otherwise
  114. * @return true if successful, false otherwise.
  115. */
  116. bool (*encode)(void *data, struct encoder_frame *frame,
  117. struct encoder_packet *packet, bool *received_packet);
  118. /* ----------------------------------------------------------------- */
  119. /* Optional implementation */
  120. /**
  121. * Gets the default settings for this encoder
  122. *
  123. * @param[out] settings Data to assign default settings to
  124. */
  125. void (*defaults)(obs_data_t settings);
  126. /**
  127. * Stops the encoder
  128. *
  129. * @param data Data associated with this encoder context
  130. */
  131. void (*stop)(void *data);
  132. /**
  133. * Gets the property information of this encoder
  134. *
  135. * @param locale The locale to translate with
  136. * @return The properties data
  137. */
  138. obs_properties_t (*properties)(const char *locale);
  139. /**
  140. * Updates the settings for this encoder (usually used for things like
  141. * changeing birate while active)
  142. *
  143. * @param data Data associated with this encoder context
  144. * @param settings New settings for this encoder
  145. * @return true if successful, false otherwise
  146. */
  147. bool (*update)(void *data, obs_data_t settings);
  148. /**
  149. * Returns extra data associated with this encoder (usually header)
  150. *
  151. * @param data Data associated with this encoder context
  152. * @param[out] extra_data Pointer to receive the extra data
  153. * @param[out] size Pointer to receive the size of the extra
  154. * data
  155. * @return true if extra data available, false
  156. * otherwise
  157. */
  158. bool (*extra_data)(void *data, uint8_t **extra_data, size_t *size);
  159. /**
  160. * Gets the SEI data, if any
  161. *
  162. * @param data Data associated with this encoder context
  163. * @param[out] sei_data Pointer to receive the SEI data
  164. * @param[out] size Pointer to receive the SEI data size
  165. * @return true if SEI data available, false otherwise
  166. */
  167. bool (*sei_data)(void *data, uint8_t **sei_data, size_t *size);
  168. /**
  169. * Returns desired audio format and sample information
  170. *
  171. * @param data Data associated with this encoder context
  172. * @param[out] info Audio format information
  173. * @return true if specific format is desired, false
  174. * otherwise
  175. */
  176. bool (*audio_info)(void *data, struct audio_convert_info *info);
  177. /**
  178. * Returns desired video format information
  179. *
  180. * @param data Data associated with this encoder context
  181. * @param[out] info Video format information
  182. * @return true if specific format is desired, false
  183. * otherwise
  184. */
  185. bool (*video_info)(void *data, struct video_scale_info *info);
  186. };
  187. /**
  188. * Register an encoder definition to the current obs context. This should be
  189. * used in obs_module_load.
  190. *
  191. * @param info Pointer to the source definition structure.
  192. */
  193. EXPORT void obs_register_encoder(const struct obs_encoder_info *info);