rtmp-custom.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #include <obs-module.h>
  2. struct rtmp_custom {
  3. char *server, *key;
  4. bool use_auth;
  5. char *username, *password;
  6. };
  7. static const char *rtmp_custom_name(void *unused)
  8. {
  9. UNUSED_PARAMETER(unused);
  10. return obs_module_text("CustomStreamingServer");
  11. }
  12. static void rtmp_custom_update(void *data, obs_data_t *settings)
  13. {
  14. struct rtmp_custom *service = data;
  15. bfree(service->server);
  16. bfree(service->key);
  17. bfree(service->username);
  18. bfree(service->password);
  19. service->server = bstrdup(obs_data_get_string(settings, "server"));
  20. service->key = bstrdup(obs_data_get_string(settings, "key"));
  21. service->use_auth = obs_data_get_bool(settings, "use_auth");
  22. service->username = bstrdup(obs_data_get_string(settings, "username"));
  23. service->password = bstrdup(obs_data_get_string(settings, "password"));
  24. }
  25. static void rtmp_custom_destroy(void *data)
  26. {
  27. struct rtmp_custom *service = data;
  28. bfree(service->server);
  29. bfree(service->key);
  30. bfree(service->username);
  31. bfree(service->password);
  32. bfree(service);
  33. }
  34. static void *rtmp_custom_create(obs_data_t *settings, obs_service_t *service)
  35. {
  36. struct rtmp_custom *data = bzalloc(sizeof(struct rtmp_custom));
  37. rtmp_custom_update(data, settings);
  38. UNUSED_PARAMETER(service);
  39. return data;
  40. }
  41. static bool use_auth_modified(obs_properties_t *ppts, obs_property_t *p,
  42. obs_data_t *settings)
  43. {
  44. bool use_auth = obs_data_get_bool(settings, "use_auth");
  45. p = obs_properties_get(ppts, "username");
  46. obs_property_set_visible(p, use_auth);
  47. p = obs_properties_get(ppts, "password");
  48. obs_property_set_visible(p, use_auth);
  49. return true;
  50. }
  51. static obs_properties_t *rtmp_custom_properties(void *unused)
  52. {
  53. UNUSED_PARAMETER(unused);
  54. obs_properties_t *ppts = obs_properties_create();
  55. obs_property_t *p;
  56. obs_properties_add_text(ppts, "server", "URL", OBS_TEXT_DEFAULT);
  57. obs_properties_add_text(ppts, "key", obs_module_text("StreamKey"),
  58. OBS_TEXT_PASSWORD);
  59. p = obs_properties_add_bool(ppts, "use_auth",
  60. obs_module_text("UseAuth"));
  61. obs_properties_add_text(ppts, "username", obs_module_text("Username"),
  62. OBS_TEXT_DEFAULT);
  63. obs_properties_add_text(ppts, "password", obs_module_text("Password"),
  64. OBS_TEXT_PASSWORD);
  65. obs_property_set_modified_callback(p, use_auth_modified);
  66. return ppts;
  67. }
  68. static const char *rtmp_custom_url(void *data)
  69. {
  70. struct rtmp_custom *service = data;
  71. return service->server;
  72. }
  73. static const char *rtmp_custom_key(void *data)
  74. {
  75. struct rtmp_custom *service = data;
  76. return service->key;
  77. }
  78. static const char *rtmp_custom_username(void *data)
  79. {
  80. struct rtmp_custom *service = data;
  81. if (!service->use_auth)
  82. return NULL;
  83. return service->username;
  84. }
  85. static const char *rtmp_custom_password(void *data)
  86. {
  87. struct rtmp_custom *service = data;
  88. if (!service->use_auth)
  89. return NULL;
  90. return service->password;
  91. }
  92. struct obs_service_info rtmp_custom_service = {
  93. .id = "rtmp_custom",
  94. .get_name = rtmp_custom_name,
  95. .create = rtmp_custom_create,
  96. .destroy = rtmp_custom_destroy,
  97. .update = rtmp_custom_update,
  98. .get_properties = rtmp_custom_properties,
  99. .get_url = rtmp_custom_url,
  100. .get_key = rtmp_custom_key,
  101. .get_username = rtmp_custom_username,
  102. .get_password = rtmp_custom_password,
  103. };