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