obs-output.c 3.4 KB

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