obs-encoder.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. * Outputs
  20. * ===========================================
  21. *
  22. * An output takes raw audio and/or video and processes and/or outputs it
  23. * to a destination, whether that destination be a file, network, or other.
  24. *
  25. * A module with outputs needs to export these functions:
  26. * + enum_outputs
  27. *
  28. * Each individual output is then exported by it's name. For example, an
  29. * output named "myoutput" would have the following exports:
  30. * + myoutput_getname
  31. * + myoutput_create
  32. * + myoutput_destroy
  33. * + myoutput_start
  34. * + myoutput_stop
  35. * + myoutput_encoders
  36. *
  37. * [and optionally]
  38. * + myoutput_setencoder
  39. * + myoutput_getencoder
  40. * + myoutput_config
  41. * + myoutput_pause
  42. *
  43. * ===========================================
  44. * Primary Exports
  45. * ===========================================
  46. * const char *enum_outputs(size_t idx);
  47. * idx: index of the output.
  48. * Return value: Output identifier name. NULL when no more available.
  49. *
  50. * ===========================================
  51. * Output Exports
  52. * ===========================================
  53. * const char *[name]_getname(const char *locale);
  54. * Returns the full translated name of the output type (seen by the user).
  55. *
  56. * ---------------------------------------------------------
  57. * void *[name]_create(const char *settings, obs_output_t output);
  58. * Creates an output.
  59. *
  60. * settings: Settings of the output.
  61. * output: pointer to main output
  62. * Return value: Internal output pointer, or NULL if failed.
  63. *
  64. * ---------------------------------------------------------
  65. * void [name]_destroy(void *data);
  66. * Destroys the output.
  67. *
  68. * ---------------------------------------------------------
  69. * void [name]_update(void *data, const char *settings)
  70. * Updates the output's settings
  71. *
  72. * settings: New settings of the output
  73. *
  74. * ---------------------------------------------------------
  75. * bool [name]_reset(void *data)
  76. * Starts output
  77. *
  78. * Return value: true if successful
  79. *
  80. * ---------------------------------------------------------
  81. * int [name]_encode(void *data, void *frames, size_t size,
  82. * struct encoder_packet **packets)
  83. *
  84. * frames: frame data
  85. * size: size of data pointed to by the frame parameter
  86. * packets: returned packets, or NULL if none
  87. * Return value: number of output frames
  88. *
  89. * ---------------------------------------------------------
  90. * bool [name]_reset(void *data)
  91. * Resets encoder data
  92. *
  93. * Return value: true if successful
  94. *
  95. * ===========================================
  96. * Optional Output Exports
  97. * ===========================================
  98. * void [name]_setbitrate(void *data, uint32_t bitrate, uint32_t buffersize);
  99. * Sets the bitrate of the encoder
  100. */
  101. struct obs_encoder;
  102. struct encoder_info {
  103. const char *id;
  104. const char *(*getname)(const char *locale);
  105. void *(*create)(const char *settings, struct obs_encoder *encoder);
  106. void (*destroy)(void *data);
  107. void (*update)(void *data, const char *settings);
  108. bool (*reset)(void *data);
  109. int (*encode)(void *data, void *frames, size_t size,
  110. struct encoder_packet **packets);
  111. int (*getheader)(void *data, struct encoder_packet **packets);
  112. /* optional */
  113. void (*setbitrate)(void *data, uint32_t bitrate, uint32_t buffersize);
  114. void (*request_keyframe)(void *data);
  115. };
  116. struct obs_encoder_callback {
  117. void (*new_packet)(void *param, struct encoder_packet *packet);
  118. void *param;
  119. };
  120. struct obs_encoder {
  121. char *name;
  122. void *data;
  123. struct encoder_info callbacks;
  124. struct dstr settings;
  125. pthread_mutex_t data_callbacks_mutex;
  126. DARRAY(struct obs_encoder_callback) data_callbacks;
  127. };
  128. extern bool load_encoder_info(void *module, const char *module_name,
  129. const char *encoder_name, struct encoder_info *info);