Skip to content

Commit

Permalink
Added support for ${SourceStream} macro in StreamName of StreamMap files
Browse files Browse the repository at this point in the history
  • Loading branch information
Keukhan committed Jan 3, 2025
1 parent c876833 commit c0afd90
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
26 changes: 20 additions & 6 deletions src/projects/publishers/file/file_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,26 +382,31 @@ namespace pub
{
std::vector<std::shared_ptr<info::Record>> 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");
Expand All @@ -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());

Expand Down
33 changes: 16 additions & 17 deletions src/projects/publishers/push/push_application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,28 @@ 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");
ov::String protocol = curr_node.child_value("Protocol");
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());

Expand All @@ -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<info::Push>();
if(push == nullptr)
{
Expand Down

0 comments on commit c0afd90

Please sign in to comment.