1
0

null-output.c 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /******************************************************************************
  2. Copyright (C) 2023 by Lain 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 <util/threading.h>
  15. #include <obs-module.h>
  16. struct null_output {
  17. obs_output_t *output;
  18. pthread_t stop_thread;
  19. bool stop_thread_active;
  20. };
  21. static const char *null_output_getname(void *unused)
  22. {
  23. UNUSED_PARAMETER(unused);
  24. return "Null Encoding Output";
  25. }
  26. static void *null_output_create(obs_data_t *settings, obs_output_t *output)
  27. {
  28. struct null_output *context = bzalloc(sizeof(*context));
  29. context->output = output;
  30. UNUSED_PARAMETER(settings);
  31. return context;
  32. }
  33. static void null_output_destroy(void *data)
  34. {
  35. struct null_output *context = data;
  36. if (context->stop_thread_active)
  37. pthread_join(context->stop_thread, NULL);
  38. bfree(context);
  39. }
  40. static bool null_output_start(void *data)
  41. {
  42. struct null_output *context = data;
  43. if (!obs_output_can_begin_data_capture(context->output, 0))
  44. return false;
  45. if (!obs_output_initialize_encoders(context->output, 0))
  46. return false;
  47. if (context->stop_thread_active)
  48. pthread_join(context->stop_thread, NULL);
  49. obs_output_begin_data_capture(context->output, 0);
  50. return true;
  51. }
  52. static void *stop_thread(void *data)
  53. {
  54. struct null_output *context = data;
  55. obs_output_end_data_capture(context->output);
  56. context->stop_thread_active = false;
  57. return NULL;
  58. }
  59. static void null_output_stop(void *data, uint64_t ts)
  60. {
  61. struct null_output *context = data;
  62. UNUSED_PARAMETER(ts);
  63. context->stop_thread_active = pthread_create(&context->stop_thread, NULL, stop_thread, data) == 0;
  64. }
  65. static void null_output_data(void *data, struct encoder_packet *packet)
  66. {
  67. UNUSED_PARAMETER(data);
  68. UNUSED_PARAMETER(packet);
  69. }
  70. struct obs_output_info null_output_info = {
  71. .id = "null_output",
  72. .flags = OBS_OUTPUT_AV | OBS_OUTPUT_ENCODED | OBS_OUTPUT_MULTI_TRACK_AV,
  73. .get_name = null_output_getname,
  74. .create = null_output_create,
  75. .destroy = null_output_destroy,
  76. .start = null_output_start,
  77. .stop = null_output_stop,
  78. .encoded_packet = null_output_data,
  79. };