rtmp-custom.c 3.1 KB

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