rtmp-services-main.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #include <util/text-lookup.h>
  2. #include <util/threading.h>
  3. #include <util/platform.h>
  4. #include <util/dstr.h>
  5. #include <obs-module.h>
  6. #include <file-updater/file-updater.h>
  7. #include "rtmp-format-ver.h"
  8. #include "service-specific/showroom.h"
  9. #include "service-specific/dacast.h"
  10. OBS_DECLARE_MODULE()
  11. OBS_MODULE_USE_DEFAULT_LOCALE("rtmp-services", "en-US")
  12. MODULE_EXPORT const char *obs_module_description(void)
  13. {
  14. return "OBS core RTMP services";
  15. }
  16. #if defined(ENABLE_SERVICE_UPDATES)
  17. static const char *RTMP_SERVICES_LOG_STR = "[rtmp-services plugin] ";
  18. static const char *RTMP_SERVICES_URL = (const char *)SERVICES_URL;
  19. #endif
  20. extern struct obs_service_info rtmp_common_service;
  21. extern struct obs_service_info rtmp_custom_service;
  22. static update_info_t *update_info = NULL;
  23. static struct dstr module_name = {0};
  24. const char *get_module_name(void)
  25. {
  26. return module_name.array;
  27. }
  28. static bool confirm_service_file(void *param, struct file_download_data *file)
  29. {
  30. if (astrcmpi(file->name, "services.json") == 0) {
  31. obs_data_t *data;
  32. int format_version;
  33. data = obs_data_create_from_json((char *)file->buffer.array);
  34. if (!data)
  35. return false;
  36. format_version = (int)obs_data_get_int(data, "format_version");
  37. obs_data_release(data);
  38. if (format_version != RTMP_SERVICES_FORMAT_VERSION)
  39. return false;
  40. }
  41. UNUSED_PARAMETER(param);
  42. return true;
  43. }
  44. extern void init_twitch_data(void);
  45. extern void load_twitch_data(void);
  46. extern void unload_twitch_data(void);
  47. extern void twitch_ingests_refresh(int seconds);
  48. extern void init_amazon_ivs_data(void);
  49. extern void load_amazon_ivs_data(void);
  50. extern void unload_amazon_ivs_data(void);
  51. extern void amazon_ivs_ingests_refresh(int seconds);
  52. static void refresh_callback(void *unused, calldata_t *cd)
  53. {
  54. int seconds = (int)calldata_int(cd, "seconds");
  55. if (seconds <= 0)
  56. seconds = 3;
  57. if (seconds > 10)
  58. seconds = 10;
  59. twitch_ingests_refresh(seconds);
  60. UNUSED_PARAMETER(unused);
  61. }
  62. static void amazon_ivs_refresh_callback(void *unused, calldata_t *cd)
  63. {
  64. int seconds = (int)calldata_int(cd, "seconds");
  65. if (seconds <= 0)
  66. seconds = 3;
  67. if (seconds > 10)
  68. seconds = 10;
  69. amazon_ivs_ingests_refresh(seconds);
  70. UNUSED_PARAMETER(unused);
  71. }
  72. bool obs_module_load(void)
  73. {
  74. init_twitch_data();
  75. init_dacast_data();
  76. init_amazon_ivs_data();
  77. dstr_copy(&module_name, "rtmp-services plugin (libobs ");
  78. dstr_cat(&module_name, obs_get_version_string());
  79. dstr_cat(&module_name, ")");
  80. proc_handler_t *ph = obs_get_proc_handler();
  81. proc_handler_add(ph, "void twitch_ingests_refresh(int seconds)", refresh_callback, NULL);
  82. proc_handler_add(ph, "void amazon_ivs_ingests_refresh(int seconds)", amazon_ivs_refresh_callback, NULL);
  83. #if defined(ENABLE_SERVICE_UPDATES)
  84. char *local_dir = obs_module_file("");
  85. char *cache_dir = obs_module_config_path("");
  86. char update_url[128];
  87. snprintf(update_url, sizeof(update_url), "%s/v%d", RTMP_SERVICES_URL, RTMP_SERVICES_FORMAT_VERSION);
  88. if (cache_dir) {
  89. update_info = update_info_create(RTMP_SERVICES_LOG_STR, module_name.array, update_url, local_dir,
  90. cache_dir, confirm_service_file, NULL);
  91. }
  92. load_twitch_data();
  93. load_amazon_ivs_data();
  94. bfree(local_dir);
  95. bfree(cache_dir);
  96. #endif
  97. obs_register_service(&rtmp_common_service);
  98. obs_register_service(&rtmp_custom_service);
  99. return true;
  100. }
  101. void obs_module_unload(void)
  102. {
  103. update_info_destroy(update_info);
  104. unload_twitch_data();
  105. free_showroom_data();
  106. unload_dacast_data();
  107. unload_amazon_ivs_data();
  108. dstr_free(&module_name);
  109. }