rtmp-services-main.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. static void refresh_callback(void *unused, calldata_t *cd)
  49. {
  50. int seconds = (int)calldata_int(cd, "seconds");
  51. if (seconds <= 0)
  52. seconds = 3;
  53. if (seconds > 10)
  54. seconds = 10;
  55. twitch_ingests_refresh(seconds);
  56. UNUSED_PARAMETER(unused);
  57. }
  58. bool obs_module_load(void)
  59. {
  60. init_twitch_data();
  61. init_dacast_data();
  62. dstr_copy(&module_name, "rtmp-services plugin (libobs ");
  63. dstr_cat(&module_name, obs_get_version_string());
  64. dstr_cat(&module_name, ")");
  65. proc_handler_t *ph = obs_get_proc_handler();
  66. proc_handler_add(ph, "void twitch_ingests_refresh(int seconds)",
  67. refresh_callback, NULL);
  68. #if defined(ENABLE_SERVICE_UPDATES)
  69. char *local_dir = obs_module_file("");
  70. char *cache_dir = obs_module_config_path("");
  71. char update_url[128];
  72. snprintf(update_url, sizeof(update_url), "%s/v%d", RTMP_SERVICES_URL,
  73. RTMP_SERVICES_FORMAT_VERSION);
  74. if (cache_dir) {
  75. update_info = update_info_create(RTMP_SERVICES_LOG_STR,
  76. module_name.array, update_url,
  77. local_dir, cache_dir,
  78. confirm_service_file, NULL);
  79. }
  80. load_twitch_data();
  81. bfree(local_dir);
  82. bfree(cache_dir);
  83. #endif
  84. obs_register_service(&rtmp_common_service);
  85. obs_register_service(&rtmp_custom_service);
  86. return true;
  87. }
  88. void obs_module_unload(void)
  89. {
  90. update_info_destroy(update_info);
  91. unload_twitch_data();
  92. free_showroom_data();
  93. unload_dacast_data();
  94. dstr_free(&module_name);
  95. }