obs-encoder.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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_PACKET_AUDIO,
  18. OBS_PACKET_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. enum obs_encoder_type type; /**< Encoder type */
  27. /**
  28. * Packet priority
  29. *
  30. * This is generally use by video encoders to specify the priority
  31. * of the packet. If this frame is dropped, it will have to wait for
  32. * another packet of drop_priority.
  33. */
  34. int priority;
  35. /**
  36. * Dropped packet priority
  37. *
  38. * If this packet is dropped, the next packet must be of this priority
  39. * or higher to continue transmission.
  40. */
  41. int drop_priority;
  42. };
  43. /** Encoder input frame */
  44. struct encoder_frame {
  45. /** Data for the frame/audio */
  46. uint8_t *data[MAX_AV_PLANES];
  47. /** size of each plane */
  48. uint32_t linesize[MAX_AV_PLANES];
  49. /** Number of frames (audio only) */
  50. uint32_t frames;
  51. /** Presentation timestamp */
  52. int64_t pts;
  53. };
  54. /**
  55. * Encoder interface
  56. *
  57. * Encoders have a limited usage with OBS. You are not generally supposed to
  58. * implement every encoder out there. Generally, these are limited or specific
  59. * encoders for h264/aac for streaming and recording. It doesn't have to be
  60. * *just* h264 or aac of course, but generally those are the expected encoders.
  61. *
  62. * That being said, other encoders will be kept in mind for future use.
  63. */
  64. struct obs_encoder_info {
  65. /* ----------------------------------------------------------------- */
  66. /* Required implementation*/
  67. /** Specifies the named identifier of this encoder */
  68. const char *id;
  69. /**
  70. * Gets the full translated name of this encoder
  71. *
  72. * @param locale Locale to use for translation
  73. * @return Translated name of the encoder
  74. */
  75. const char *(*getname)(const char *locale);
  76. /**
  77. * Creates the encoder with the specified settings
  78. *
  79. * @param settings Settings for the encoder
  80. * @param encoder OBS encoder context
  81. * @return Data associated with this encoder context
  82. */
  83. void *(*create)(obs_data_t settings, obs_encoder_t encoder);
  84. /**
  85. * Destroys the encoder data
  86. *
  87. * @param data Data associated with this encoder context
  88. */
  89. void (*destroy)(void *data);
  90. /**
  91. * Resets the encoder with the specified settings
  92. *
  93. * @param data Data associated with this encoder context
  94. * @param settings New settings for the encoder
  95. * @return true if successful, false otherwise
  96. */
  97. bool (*reset)(void *data, obs_data_t settings);
  98. /**
  99. * Encodes frame(s), and outputs encoded packets as they become
  100. * available.
  101. *
  102. * @param data Data associated with this encoder
  103. * context
  104. * @param[in] frame Raw audio/video data to encode
  105. * @param[out] packet Encoder packet output, if any
  106. * @param[out] received_packet Set to true if a packet was received,
  107. * false otherwise
  108. * @return true if successful, false otherwise.
  109. */
  110. int (*encode)(void *data, const struct encoder_frame *frame,
  111. struct encoder_packet *packet, bool *received_packet);
  112. /* ----------------------------------------------------------------- */
  113. /* Optional implementation */
  114. /**
  115. * Gets the default settings for this encoder
  116. *
  117. * @param[out] settings Data to assign default settings to
  118. */
  119. void (*defaults)(obs_data_t settings);
  120. /**
  121. * Gets the property information of this encoder
  122. *
  123. * @param locale The locale to translate with
  124. * @return The properties data
  125. */
  126. obs_properties_t (*properties)(const char *locale);
  127. /**
  128. * Updates the settings for this encoder
  129. *
  130. * @param data Data associated with this encoder context
  131. * @param settings New settings for this encoder
  132. */
  133. void (*update)(void *data, obs_data_t settings);
  134. /**
  135. * Returns extra data associated with this encoder (usually header)
  136. *
  137. * @param data Data associated with this encoder context
  138. * @param extra_data Pointer to receive the extra data
  139. * @param size Pointer to receive the size of the extra data
  140. */
  141. bool (*get_extra_data)(void *data, uint8_t **extra_data, size_t *size);
  142. };
  143. /**
  144. * Register an encoder definition to the current obs context. This should be
  145. * used in obs_module_load.
  146. *
  147. * @param info Pointer to the source definition structure.
  148. */
  149. EXPORT void obs_register_encoder(const struct obs_encoder_info *info);