|
|
@@ -210,6 +210,73 @@ static bool CreateAACEncoder(OBSEncoder &res, string &id, int bitrate,
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+static inline bool can_use_output(const char *prot, const char *output,
|
|
|
+ const char *prot_test1,
|
|
|
+ const char *prot_test2 = nullptr)
|
|
|
+{
|
|
|
+ return (strcmp(prot, prot_test1) == 0 ||
|
|
|
+ (prot_test2 && strcmp(prot, prot_test2) == 0)) &&
|
|
|
+ (obs_get_output_flags(output) & OBS_OUTPUT_SERVICE) != 0;
|
|
|
+}
|
|
|
+
|
|
|
+static bool return_first_id(void *data, const char *id)
|
|
|
+{
|
|
|
+ const char **output = (const char **)data;
|
|
|
+
|
|
|
+ *output = id;
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+static const char *GetStreamOutputType(const obs_service_t *service)
|
|
|
+{
|
|
|
+ const char *protocol = obs_service_get_protocol(service);
|
|
|
+ const char *output = nullptr;
|
|
|
+
|
|
|
+ if (!protocol) {
|
|
|
+ blog(LOG_WARNING, "The service '%s' has no protocol set",
|
|
|
+ obs_service_get_id(service));
|
|
|
+ return nullptr;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!obs_is_output_protocol_registered(protocol)) {
|
|
|
+ blog(LOG_WARNING, "The protocol '%s' is not registered",
|
|
|
+ protocol);
|
|
|
+ return nullptr;
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Check if the service has a preferred output type */
|
|
|
+ output = obs_service_get_preferred_output_type(service);
|
|
|
+ if (output) {
|
|
|
+ if ((obs_get_output_flags(output) & OBS_OUTPUT_SERVICE) != 0)
|
|
|
+ return output;
|
|
|
+
|
|
|
+ blog(LOG_WARNING,
|
|
|
+ "The output '%s' is not registered, fallback to another one",
|
|
|
+ output);
|
|
|
+ }
|
|
|
+
|
|
|
+ /* Otherwise, prefer first-party output types */
|
|
|
+ if (can_use_output(protocol, "rtmp_output", "RTMP", "RTMPS")) {
|
|
|
+ return "rtmp_output";
|
|
|
+ } else if (can_use_output(protocol, "ffmpeg_hls_muxer", "HLS")) {
|
|
|
+ return "ffmpeg_hls_muxer";
|
|
|
+ } else if (can_use_output(protocol, "ffmpeg_mpegts_muxer", "SRT",
|
|
|
+ "RIST")) {
|
|
|
+ return "ffmpeg_mpegts_muxer";
|
|
|
+ }
|
|
|
+
|
|
|
+ /* If third-party protocol, use the first enumerated type */
|
|
|
+ obs_enum_output_types_with_protocol(protocol, &output, return_first_id);
|
|
|
+ if (output)
|
|
|
+ return output;
|
|
|
+
|
|
|
+ blog(LOG_WARNING,
|
|
|
+ "No output compatible with the service '%s' is registered",
|
|
|
+ obs_service_get_id(service));
|
|
|
+
|
|
|
+ return nullptr;
|
|
|
+}
|
|
|
+
|
|
|
/* ------------------------------------------------------------------------ */
|
|
|
|
|
|
inline BasicOutputHandler::BasicOutputHandler(OBSBasic *main_) : main(main_)
|
|
|
@@ -913,18 +980,9 @@ bool SimpleOutput::SetupStreaming(obs_service_t *service)
|
|
|
|
|
|
/* --------------------- */
|
|
|
|
|
|
- const char *type = obs_service_get_output_type(service);
|
|
|
- if (!type) {
|
|
|
- type = "rtmp_output";
|
|
|
- const char *url = obs_service_get_url(service);
|
|
|
- if (url != NULL &&
|
|
|
- strncmp(url, FTL_PROTOCOL, strlen(FTL_PROTOCOL)) == 0) {
|
|
|
- type = "ftl_output";
|
|
|
- } else if (url != NULL && strncmp(url, RTMP_PROTOCOL,
|
|
|
- strlen(RTMP_PROTOCOL)) != 0) {
|
|
|
- type = "ffmpeg_mpegts_muxer";
|
|
|
- }
|
|
|
- }
|
|
|
+ const char *type = GetStreamOutputType(service);
|
|
|
+ if (!type)
|
|
|
+ return false;
|
|
|
|
|
|
/* XXX: this is messy and disgusting and should be refactored */
|
|
|
if (outputType != type) {
|
|
|
@@ -1898,18 +1956,9 @@ bool AdvancedOutput::SetupStreaming(obs_service_t *service)
|
|
|
|
|
|
/* --------------------- */
|
|
|
|
|
|
- const char *type = obs_service_get_output_type(service);
|
|
|
- if (!type) {
|
|
|
- type = "rtmp_output";
|
|
|
- const char *url = obs_service_get_url(service);
|
|
|
- if (url != NULL &&
|
|
|
- strncmp(url, FTL_PROTOCOL, strlen(FTL_PROTOCOL)) == 0) {
|
|
|
- type = "ftl_output";
|
|
|
- } else if (url != NULL && strncmp(url, RTMP_PROTOCOL,
|
|
|
- strlen(RTMP_PROTOCOL)) != 0) {
|
|
|
- type = "ffmpeg_mpegts_muxer";
|
|
|
- }
|
|
|
- }
|
|
|
+ const char *type = GetStreamOutputType(service);
|
|
|
+ if (!type)
|
|
|
+ return false;
|
|
|
|
|
|
/* XXX: this is messy and disgusting and should be refactored */
|
|
|
if (outputType != type) {
|