obs-output.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 3 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. #include "obs.h"
  15. #include "obs-data.h"
  16. bool get_output_info(void *module, const char *module_name,
  17. const char *output_name, struct output_info *info)
  18. {
  19. info->create = load_module_subfunc(module, module_name,
  20. output_name, "create", true);
  21. info->destroy = load_module_subfunc(module, module_name,
  22. output_name, "destroy", true);
  23. info->start = load_module_subfunc(module, module_name,
  24. output_name, "start", true);
  25. info->stop = load_module_subfunc(module, module_name,
  26. output_name, "stop", true);
  27. if (!info->create || !info->destroy || !info->start || !info->stop)
  28. return false;
  29. info->config = load_module_subfunc(module, module_name,
  30. output_name, "config", false);
  31. info->pause = load_module_subfunc(module, module_name,
  32. output_name, "pause", false);
  33. info->name = output_name;
  34. return true;
  35. }
  36. static inline const struct output_info *find_output(const char *type)
  37. {
  38. size_t i;
  39. for (i = 0; i < obs->output_types.num; i++)
  40. if (strcmp(obs->output_types.array[i].name, type) == 0)
  41. return obs->output_types.array+i;
  42. return NULL;
  43. }
  44. obs_output_t obs_output_create(const char *type, const char *settings)
  45. {
  46. const struct output_info *info = find_output(type);
  47. struct obs_output *output;
  48. if (!info) {
  49. blog(LOG_WARNING, "Output type '%s' not found", type);
  50. return NULL;
  51. }
  52. output = bmalloc(sizeof(struct obs_output));
  53. output->data = info->create(settings, output);
  54. if (!output->data) {
  55. bfree(output);
  56. return NULL;
  57. }
  58. dstr_init_copy(&output->settings, settings);
  59. memcpy(&output->callbacks, info, sizeof(struct output_info));
  60. return output;
  61. }
  62. void obs_output_destroy(obs_output_t output)
  63. {
  64. if (output) {
  65. output->callbacks.destroy(output->data);
  66. dstr_free(&output->settings);
  67. bfree(output);
  68. }
  69. }
  70. void obs_output_start(obs_output_t output)
  71. {
  72. output->callbacks.start(output->data);
  73. }
  74. void obs_output_stop(obs_output_t output)
  75. {
  76. output->callbacks.stop(output->data);
  77. }
  78. bool obs_output_canconfig(obs_output_t output)
  79. {
  80. return output->callbacks.config != NULL;
  81. }
  82. void obs_output_config(obs_output_t output, void *parent)
  83. {
  84. if (output->callbacks.config)
  85. output->callbacks.config(output->data, parent);
  86. }
  87. bool obs_output_canpause(obs_output_t output)
  88. {
  89. return output->callbacks.pause != NULL;
  90. }
  91. void obs_output_pause(obs_output_t output)
  92. {
  93. if (output->callbacks.pause)
  94. output->callbacks.pause(output->data);
  95. }
  96. void obs_output_save_settings(obs_output_t output, const char *settings)
  97. {
  98. dstr_copy(&output->settings, settings);
  99. }