rtmp-services-main.c 2.5 KB

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