obs-encoder.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /******************************************************************************
  2. Copyright (C) 2013 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. #include "util/c99defs.h"
  16. #include "util/dstr.h"
  17. /*
  18. * ===========================================
  19. * Encoders
  20. * ===========================================
  21. *
  22. * An encoder context allows data to be encoded from raw output, and allow
  23. * it to be used to output contexts (such as outputting to stream).
  24. *
  25. * A module with encoders needs to export these functions:
  26. * + enum_encoders
  27. *
  28. * Each individual encoder is then exported by it's name. For example, an
  29. * encoder named "myencoder" would have the following exports:
  30. * + myencoder_getname
  31. * + myencoder_create
  32. * + myencoder_destroy
  33. * + myencoder_update
  34. * + myencoder_reset
  35. * + myencoder_encode
  36. * + myencoder_getheader
  37. *
  38. * [and optionally]
  39. * + myencoder_properties
  40. * + myencoder_setbitrate
  41. * + myencoder_request_keyframe
  42. *
  43. * ===========================================
  44. * Primary Exports
  45. * ===========================================
  46. * const char *enum_encoders(size_t idx);
  47. * idx: index of the encoder.
  48. * Return value: Encoder identifier name. NULL when no more available.
  49. *
  50. * ===========================================
  51. * Encoder Exports
  52. * ===========================================
  53. * const char *[name]_getname(const char *locale);
  54. * Returns the full translated name of the encoder type
  55. * (seen by the user).
  56. *
  57. * ---------------------------------------------------------
  58. * void *[name]_create(obs_data_t settings, const char *name,
  59. * obs_encoder_t encoder);
  60. * Creates an encoder.
  61. *
  62. * settings: Settings of the encoder.
  63. * name: Name of the encoder.
  64. * encoder: Pointer to encoder context.
  65. * Return value: Internal encoder pointer, or NULL if failed.
  66. *
  67. * ---------------------------------------------------------
  68. * void [name]_destroy(void *data);
  69. * Destroys the encoder.
  70. *
  71. * ---------------------------------------------------------
  72. * void [name]_update(void *data, obs_data_t settings)
  73. * Updates the encoder's settings
  74. *
  75. * settings: New settings of the encoder
  76. *
  77. * ---------------------------------------------------------
  78. * bool [name]_reset(void *data)
  79. * Restarts encoder
  80. *
  81. * Return value: true if successful
  82. *
  83. * ---------------------------------------------------------
  84. * int [name]_encode(void *data, void *frames, size_t size,
  85. * struct encoder_packet **packets)
  86. * Encodes data.
  87. *
  88. * frames: frame data
  89. * size: size of data pointed to by the frame parameter
  90. * packets: returned packets, or NULL if none
  91. * Return value: number of encoder frames
  92. *
  93. * ---------------------------------------------------------
  94. * int [name]_getheader(void *data, struct encoder_packet **packets)
  95. * Returns the header packets for this encoder.
  96. *
  97. * packets: returned packets, or NULL if none
  98. * Return value: number of encoder frames
  99. *
  100. * ===========================================
  101. * Optional Encoder Exports
  102. * ===========================================
  103. * obs_properties_t [name]_properties(const char *locale);
  104. * Returns the properties of this particular encoder type, if any.
  105. *
  106. * ---------------------------------------------------------
  107. * bool [name]_setbitrate(void *data, uint32_t bitrate, uint32_t buffersize);
  108. * Sets the bitrate of the encoder
  109. *
  110. * bitrate: Bitrate
  111. * buffersize: Buffer size
  112. * Returns true if successful/compatible
  113. *
  114. * ---------------------------------------------------------
  115. * bool [name]_request_keyframe(void *data)
  116. * Requests a keyframe from the encoder
  117. *
  118. * Returns true if successful/compatible.
  119. */
  120. struct obs_encoder;
  121. struct encoder_info {
  122. const char *id;
  123. const char *(*getname)(const char *locale);
  124. void *(*create)(obs_data_t settings, struct obs_encoder *encoder);
  125. void (*destroy)(void *data);
  126. void (*update)(void *data, obs_data_t settings);
  127. bool (*reset)(void *data);
  128. int (*encode)(void *data, void *frames, size_t size,
  129. struct encoder_packet **packets);
  130. int (*getheader)(void *data, struct encoder_packet **packets);
  131. /* optional */
  132. obs_properties_t (*properties)(const char *locale);
  133. bool (*setbitrate)(void *data, uint32_t bitrate, uint32_t buffersize);
  134. bool (*request_keyframe)(void *data);
  135. };
  136. struct obs_encoder_callback {
  137. void (*new_packet)(void *param, struct encoder_packet *packet);
  138. void *param;
  139. };
  140. struct obs_encoder {
  141. char *name;
  142. void *data;
  143. struct encoder_info callbacks;
  144. obs_data_t settings;
  145. pthread_mutex_t data_callbacks_mutex;
  146. DARRAY(struct obs_encoder_callback) data_callbacks;
  147. };
  148. extern bool load_encoder_info(void *module, const char *module_name,
  149. const char *encoder_name, struct encoder_info *info);