rtmp-custom.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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", obs_module_text("UseAuth"));
  58. obs_properties_add_text(ppts, "username", obs_module_text("Username"),
  59. OBS_TEXT_DEFAULT);
  60. obs_properties_add_text(ppts, "password", obs_module_text("Password"),
  61. OBS_TEXT_PASSWORD);
  62. obs_property_set_modified_callback(p, use_auth_modified);
  63. return ppts;
  64. }
  65. static const char *rtmp_custom_url(void *data)
  66. {
  67. struct rtmp_custom *service = data;
  68. return service->server;
  69. }
  70. static const char *rtmp_custom_key(void *data)
  71. {
  72. struct rtmp_custom *service = data;
  73. return service->key;
  74. }
  75. static const char *rtmp_custom_username(void *data)
  76. {
  77. struct rtmp_custom *service = data;
  78. if (!service->use_auth)
  79. return NULL;
  80. return service->username;
  81. }
  82. static const char *rtmp_custom_password(void *data)
  83. {
  84. struct rtmp_custom *service = data;
  85. if (!service->use_auth)
  86. return NULL;
  87. return service->password;
  88. }
  89. struct obs_service_info rtmp_custom_service = {
  90. .id = "rtmp_custom",
  91. .get_name = rtmp_custom_name,
  92. .create = rtmp_custom_create,
  93. .destroy = rtmp_custom_destroy,
  94. .update = rtmp_custom_update,
  95. .get_properties = rtmp_custom_properties,
  96. .get_url = rtmp_custom_url,
  97. .get_key = rtmp_custom_key,
  98. .get_username = rtmp_custom_username,
  99. .get_password = rtmp_custom_password
  100. };