From c0afd90f80aa4661bf32f9785205e450f6b8079b Mon Sep 17 00:00:00 2001 From: Keukhan Date: Fri, 3 Jan 2025 17:42:39 +0900 Subject: [PATCH] Added support for ${SourceStream} macro in StreamName of StreamMap files --- .../publishers/file/file_application.cpp | 26 +++++++++++---- .../publishers/push/push_application.cpp | 33 +++++++++---------- 2 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/projects/publishers/file/file_application.cpp b/src/projects/publishers/file/file_application.cpp index d5d9364f6..38eff53aa 100755 --- a/src/projects/publishers/file/file_application.cpp +++ b/src/projects/publishers/file/file_application.cpp @@ -382,26 +382,31 @@ namespace pub { std::vector> results; - ov::String final_path = ov::GetFilePath(file_path, cfg::ConfigManager::GetInstance()->GetConfigPath()); + ov::String real_path = ov::GetFilePath(file_path, cfg::ConfigManager::GetInstance()->GetConfigPath()); pugi::xml_document xml_doc; - auto load_result = xml_doc.load_file(final_path.CStr()); + auto load_result = xml_doc.load_file(real_path.CStr()); if (load_result == false) { - logte("FileStream(%s/%s) - Failed to load Record info file(%s) status(%d) description(%s)", GetVHostAppName().CStr(), stream_info->GetName().CStr(), final_path.CStr(), load_result.status, load_result.description()); + logte("FileStream(%s/%s) - Failed to load Record info file(%s) status(%d) description(%s)", GetVHostAppName().CStr(), stream_info->GetName().CStr(), real_path.CStr(), load_result.status, load_result.description()); return results; } auto root_node = xml_doc.child("RecordInfo"); if (root_node.empty()) { - logte("FileStream(%s/%s) - Failed to load Record info file(%s) because root node is not found", GetVHostAppName().CStr(), stream_info->GetName().CStr(), final_path.CStr()); + logte("FileStream(%s/%s) - Failed to load Record info file(%s) because root node is not found", GetVHostAppName().CStr(), stream_info->GetName().CStr(), real_path.CStr()); return results; } for (pugi::xml_node record_node = root_node.child("Record"); record_node; record_node = record_node.next_sibling("Record")) { bool enable = (strcmp(record_node.child_value("Enable"), "true") == 0) ? true : false; + if (enable == false) + { + continue; + } + ov::String target_stream_name = record_node.child_value("StreamName"); ov::String file_path = record_node.child_value("FilePath"); ov::String info_path = record_node.child_value("InfoPath"); @@ -411,12 +416,21 @@ namespace pub ov::String segment_rule = record_node.child_value("SegmentRule"); ov::String metadata = record_node.child_value("Metadata"); - if(enable == false) + + // Get the source stream name. If no linked input stream, use the current output stream name. + ov::String source_stream_name = stream_info->GetName(); + if (stream_info->GetLinkedInputStream() != nullptr) { - continue; + source_stream_name = stream_info->GetLinkedInputStream()->GetName(); + } + else + { + source_stream_name = stream_info->GetName(); } // stream_name can be regex + target_stream_name = target_stream_name.Replace("${SourceStream}", source_stream_name.CStr()); + ov::Regex _target_stream_name_regex = ov::Regex::CompiledRegex(ov::Regex::WildCardRegex(target_stream_name)); auto match_result = _target_stream_name_regex.Matches(stream_info->GetName().CStr()); diff --git a/src/projects/publishers/push/push_application.cpp b/src/projects/publishers/push/push_application.cpp index 4315abd62..b75321e4a 100755 --- a/src/projects/publishers/push/push_application.cpp +++ b/src/projects/publishers/push/push_application.cpp @@ -391,6 +391,7 @@ namespace pub continue; } + // Get configuration values ov::String map_id = curr_node.child_value("Id"); ov::String target_stream_name = curr_node.child_value("StreamName"); ov::String variant_names = curr_node.child_value("VariantNames"); @@ -398,7 +399,20 @@ namespace pub ov::String url = curr_node.child_value("Url"); ov::String stream_key = curr_node.child_value("StreamKey"); + // Get the source stream name. If no linked input stream, use the current output stream name. + ov::String source_stream_name = stream_info->GetName(); + if (stream_info->GetLinkedInputStream() != nullptr) + { + source_stream_name = stream_info->GetLinkedInputStream()->GetName(); + } + else + { + source_stream_name = stream_info->GetName(); + } + // stream_name can be regex + target_stream_name = target_stream_name.Replace("${SourceStream}", source_stream_name.CStr()); + ov::Regex _target_stream_name_regex = ov::Regex::CompiledRegex(ov::Regex::WildCardRegex(target_stream_name)); auto match_result = _target_stream_name_regex.Matches(stream_info->GetName().CStr()); @@ -410,31 +424,16 @@ namespace pub // Macro replacement for stream name url = url.Replace("${Application}", stream_info->GetApplicationName()); url = url.Replace("${Stream}", stream_info->GetName().CStr()); - if (stream_info->GetLinkedInputStream() != nullptr) - { - url = url.Replace("${SourceStream}", stream_info->GetLinkedInputStream()->GetName().CStr()); - } - else - { - url = url.Replace("${SourceStream}", stream_info->GetName().CStr()); - } + url = url.Replace("${SourceStream}", source_stream_name.CStr()); // Macro replacement for stream key if(stream_key.IsEmpty() == false) { stream_key = stream_key.Replace("${Application}", stream_info->GetApplicationName()); stream_key = stream_key.Replace("${Stream}", stream_info->GetName().CStr()); - if (stream_info->GetLinkedInputStream() != nullptr) - { - stream_key = stream_key.Replace("${SourceStream}", stream_info->GetLinkedInputStream()->GetName().CStr()); - } - else - { - stream_key = stream_key.Replace("${SourceStream}", stream_info->GetName().CStr()); - } + stream_key = stream_key.Replace("${SourceStream}", source_stream_name.CStr()); } - auto push = std::make_shared(); if(push == nullptr) {