rtmp-services-main.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 bool confirm_service_file(void *param, struct file_download_data *file)
  17. {
  18. if (astrcmpi(file->name, "services.json") == 0) {
  19. obs_data_t *data;
  20. int format_version;
  21. data = obs_data_create_from_json((char*)file->buffer.array);
  22. if (!data)
  23. return false;
  24. format_version = (int)obs_data_get_int(data, "format_version");
  25. obs_data_release(data);
  26. if (format_version != RTMP_SERVICES_FORMAT_VERSION)
  27. return false;
  28. }
  29. UNUSED_PARAMETER(param);
  30. return true;
  31. }
  32. bool obs_module_load(void)
  33. {
  34. char *local_dir = obs_module_file("");
  35. char *cache_dir = obs_module_config_path("");
  36. if (cache_dir) {
  37. update_info = update_info_create(
  38. RTMP_SERVICES_LOG_STR,
  39. RTMP_SERVICES_VER_STR,
  40. RTMP_SERVICES_URL,
  41. local_dir,
  42. cache_dir,
  43. confirm_service_file, NULL);
  44. }
  45. bfree(local_dir);
  46. bfree(cache_dir);
  47. obs_register_service(&rtmp_common_service);
  48. obs_register_service(&rtmp_custom_service);
  49. return true;
  50. }
  51. void obs_module_unload(void)
  52. {
  53. update_info_destroy(update_info);
  54. }