obs-encoder.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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_setbitrate
  40. * + myencoder_request_keyframe
  41. *
  42. * ===========================================
  43. * Primary Exports
  44. * ===========================================
  45. * const char *enum_encoders(size_t idx);
  46. * idx: index of the encoder.
  47. * Return value: Encoder identifier name. NULL when no more available.
  48. *
  49. * ===========================================
  50. * Encoder Exports
  51. * ===========================================
  52. * const char *[name]_getname(const char *locale);
  53. * Returns the full translated name of the encoder type
  54. * (seen by the user).
  55. *
  56. * ---------------------------------------------------------
  57. * void *[name]_create(obs_data_t settings, const char *name,
  58. * obs_encoder_t encoder);
  59. * Creates an encoder.
  60. *
  61. * settings: Settings of the encoder.
  62. * name: Name of the encoder.
  63. * encoder: Pointer to encoder context.
  64. * Return value: Internal encoder pointer, or NULL if failed.
  65. *
  66. * ---------------------------------------------------------
  67. * void [name]_destroy(void *data);
  68. * Destroys the encoder.
  69. *
  70. * ---------------------------------------------------------
  71. * void [name]_update(void *data, obs_data_t settings)
  72. * Updates the encoder's settings
  73. *
  74. * settings: New settings of the encoder
  75. *
  76. * ---------------------------------------------------------
  77. * bool [name]_reset(void *data)
  78. * Restarts encoder
  79. *
  80. * Return value: true if successful
  81. *
  82. * ---------------------------------------------------------
  83. * int [name]_encode(void *data, void *frames, size_t size,
  84. * struct encoder_packet **packets)
  85. * Encodes data.
  86. *
  87. * frames: frame data
  88. * size: size of data pointed to by the frame parameter
  89. * packets: returned packets, or NULL if none
  90. * Return value: number of encoder frames
  91. *
  92. * ---------------------------------------------------------
  93. * int [name]_getheader(void *data, struct encoder_packet **packets)
  94. * Returns the header packets for this encoder.
  95. *
  96. * packets: returned packets, or NULL if none
  97. * Return value: number of encoder frames
  98. *
  99. * ===========================================
  100. * Optional Encoder Exports
  101. * ===========================================
  102. * bool [name]_setbitrate(void *data, uint32_t bitrate, uint32_t buffersize);
  103. * Sets the bitrate of the encoder
  104. *
  105. * bitrate: Bitrate
  106. * buffersize: Buffer size
  107. * Returns true if successful/compatible
  108. *
  109. * ---------------------------------------------------------
  110. * bool [name]_request_keyframe(void *data)
  111. * Requests a keyframe from the encoder
  112. *
  113. * Returns true if successful/compatible.
  114. */
  115. struct obs_encoder;
  116. struct encoder_info {
  117. const char *id;
  118. const char *(*getname)(const char *locale);
  119. void *(*create)(obs_data_t settings, struct obs_encoder *encoder);
  120. void (*destroy)(void *data);
  121. void (*update)(void *data, obs_data_t settings);
  122. bool (*reset)(void *data);
  123. int (*encode)(void *data, void *frames, size_t size,
  124. struct encoder_packet **packets);
  125. int (*getheader)(void *data, struct encoder_packet **packets);
  126. /* optional */
  127. bool (*setbitrate)(void *data, uint32_t bitrate, uint32_t buffersize);
  128. bool (*request_keyframe)(void *data);
  129. };
  130. struct obs_encoder_callback {
  131. void (*new_packet)(void *param, struct encoder_packet *packet);
  132. void *param;
  133. };
  134. struct obs_encoder {
  135. char *name;
  136. void *data;
  137. struct encoder_info callbacks;
  138. obs_data_t settings;
  139. pthread_mutex_t data_callbacks_mutex;
  140. DARRAY(struct obs_encoder_callback) data_callbacks;
  141. };
  142. extern bool load_encoder_info(void *module, const char *module_name,
  143. const char *encoder_name, struct encoder_info *info);