rtmp-services-main.c 2.6 KB

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