rtmp-services-main.c 2.8 KB

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