rtmp-custom.c 3.1 KB

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