From 450a936783bb58159cc57af024254a873f9b2e43 Mon Sep 17 00:00:00 2001 From: SteveR-PMP Date: Thu, 14 Mar 2024 16:28:53 -0700 Subject: [PATCH 1/4] force exact command-line ordering for HLS by breaking grouping --- packager/hls/base/master_playlist.cc | 84 +++++++++++++++------------- 1 file changed, 46 insertions(+), 38 deletions(-) diff --git a/packager/hls/base/master_playlist.cc b/packager/hls/base/master_playlist.cc index 0b5c22f9350..11582021f80 100644 --- a/packager/hls/base/master_playlist.cc +++ b/packager/hls/base/master_playlist.cc @@ -55,6 +55,14 @@ struct Variant { uint64_t avg_audio_bitrate = 0; }; +// This structure is used to store the playlist and its tags. +struct MediaTagslist { + const MediaPlaylist* playlist; + std::string group_id; + bool is_default; + bool is_autoselect; +}; + uint64_t GetMaximumMaxBitrate(const std::list playlists) { uint64_t max = 0; for (const auto& playlist : playlists) { @@ -364,11 +372,12 @@ void BuildMediaTag(const MediaPlaylist& playlist, out->append("\n"); } -void BuildMediaTags( - std::list>>& groups, +std::list BuildMediaTags( + const std::map>& groups, const std::string& default_language, - const std::string& base_url, - std::string* out) { + const std::string& base_url) { + std::list mediaTag_playlist; + for (const auto& group : groups) { const std::string& group_id = group.first; const auto& playlists = group.second; @@ -412,22 +421,24 @@ void BuildMediaTags( is_autoselect = true; } - BuildMediaTag(*playlist, group_id, is_default, is_autoselect, base_url, - out); + MediaTagslist mediaTagslist; + mediaTagslist.playlist = playlist; + mediaTagslist.group_id = group_id; + mediaTagslist.is_default = is_default; + mediaTagslist.is_autoselect = is_autoselect; + mediaTag_playlist.push_back(mediaTagslist); } } + + return mediaTag_playlist; } -bool ListOrderFn(const MediaPlaylist*& a, const MediaPlaylist*& b) { +bool PlaylistOrderFn(const MediaPlaylist*& a, const MediaPlaylist*& b) { return a->GetMediaInfo().index() < b->GetMediaInfo().index(); } -bool GroupOrderFn(std::pair>& a, - std::pair>& b) { - a.second.sort(ListOrderFn); - b.second.sort(ListOrderFn); - return a.second.front()->GetMediaInfo().index() < - b.second.front()->GetMediaInfo().index(); +bool TagslistOrderFn(const MediaTagslist& a, const MediaTagslist& b) { + return a.playlist->GetMediaInfo().index() < b.playlist->GetMediaInfo().index(); } void AppendPlaylists(const std::string& default_audio_language, @@ -435,7 +446,8 @@ void AppendPlaylists(const std::string& default_audio_language, const std::string& base_url, const std::list& playlists, std::string* content) { - std::map> audio_playlist_groups; + std::map> + audio_playlist_groups; std::map> subtitle_playlist_groups; std::list video_playlists; @@ -465,38 +477,34 @@ void AppendPlaylists(const std::string& default_audio_language, } } - // convert the std::map to std::list and reorder it if indexes were provided - std::list>> - audio_groups_list(audio_playlist_groups.begin(), - audio_playlist_groups.end()); - std::list>> - subtitle_groups_list(subtitle_playlist_groups.begin(), - subtitle_playlist_groups.end()); if (has_index) { - audio_groups_list.sort(GroupOrderFn); - for (const auto& group : audio_groups_list) { - std::list group_playlists = group.second; - group_playlists.sort(ListOrderFn); - } - subtitle_groups_list.sort(GroupOrderFn); - for (const auto& group : subtitle_groups_list) { - std::list group_playlists = group.second; - group_playlists.sort(ListOrderFn); - } - video_playlists.sort(ListOrderFn); - iframe_playlists.sort(ListOrderFn); + video_playlists.sort(PlaylistOrderFn); + iframe_playlists.sort(PlaylistOrderFn); } if (!audio_playlist_groups.empty()) { content->append("\n"); - BuildMediaTags(audio_groups_list, default_audio_language, base_url, - content); + std::list audio_playlists = + BuildMediaTags(audio_playlist_groups, default_audio_language, base_url); + if (has_index) { + audio_playlists.sort(TagslistOrderFn); + } + for (const auto& pl : audio_playlists) { + BuildMediaTag(*pl.playlist, pl.group_id, pl.is_default, pl.is_autoselect, base_url, content); + } } + if (!subtitle_playlist_groups.empty()) { content->append("\n"); - BuildMediaTags(subtitle_groups_list, default_text_language, base_url, - content); + std::list subtitle_playlists = + BuildMediaTags(subtitle_playlist_groups, default_text_language, base_url); + if (has_index) { + subtitle_playlists.sort(TagslistOrderFn); + } + for (const auto& pl : subtitle_playlists) { + BuildMediaTag(*pl.playlist, pl.group_id, pl.is_default, pl.is_autoselect, base_url, content); + } } std::list variants = @@ -522,7 +530,7 @@ void AppendPlaylists(const std::string& default_audio_language, if (!audio_playlist_groups.empty() && video_playlists.empty() && subtitle_playlist_groups.empty()) { content->append("\n"); - for (const auto& playlist_group : audio_groups_list) { + for (const auto& playlist_group : audio_playlist_groups) { Variant variant; // Populate |audio_group_id|, which will be propagated to "AUDIO" field. // Leaving other fields, e.g. xxx_audio_bitrate in |Variant|, as From 5bc2ba4a85b2c9f134af1f45ec9a786b381a7c1d Mon Sep 17 00:00:00 2001 From: SteveR-PMP Date: Fri, 15 Mar 2024 16:49:13 -0700 Subject: [PATCH 2/4] lint --- packager/hls/base/master_playlist.cc | 18 ++++++++++-------- .../media/formats/mp2t/es_parser_teletext.cc | 3 ++- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packager/hls/base/master_playlist.cc b/packager/hls/base/master_playlist.cc index 11582021f80..ae845550c3e 100644 --- a/packager/hls/base/master_playlist.cc +++ b/packager/hls/base/master_playlist.cc @@ -438,7 +438,8 @@ bool PlaylistOrderFn(const MediaPlaylist*& a, const MediaPlaylist*& b) { } bool TagslistOrderFn(const MediaTagslist& a, const MediaTagslist& b) { - return a.playlist->GetMediaInfo().index() < b.playlist->GetMediaInfo().index(); + return a.playlist->GetMediaInfo().index() < + b.playlist->GetMediaInfo().index(); } void AppendPlaylists(const std::string& default_audio_language, @@ -446,8 +447,7 @@ void AppendPlaylists(const std::string& default_audio_language, const std::string& base_url, const std::list& playlists, std::string* content) { - std::map> - audio_playlist_groups; + std::map> audio_playlist_groups; std::map> subtitle_playlist_groups; std::list video_playlists; @@ -485,25 +485,27 @@ void AppendPlaylists(const std::string& default_audio_language, if (!audio_playlist_groups.empty()) { content->append("\n"); std::list audio_playlists = - BuildMediaTags(audio_playlist_groups, default_audio_language, base_url); + BuildMediaTags(audio_playlist_groups, default_audio_language, base_url); if (has_index) { audio_playlists.sort(TagslistOrderFn); } for (const auto& pl : audio_playlists) { - BuildMediaTag(*pl.playlist, pl.group_id, pl.is_default, pl.is_autoselect, base_url, content); + BuildMediaTag(*pl.playlist, pl.group_id, pl.is_default, pl.is_autoselect, + base_url, content); } } if (!subtitle_playlist_groups.empty()) { content->append("\n"); - std::list subtitle_playlists = - BuildMediaTags(subtitle_playlist_groups, default_text_language, base_url); + std::list subtitle_playlists = BuildMediaTags( + subtitle_playlist_groups, default_text_language, base_url); if (has_index) { subtitle_playlists.sort(TagslistOrderFn); } for (const auto& pl : subtitle_playlists) { - BuildMediaTag(*pl.playlist, pl.group_id, pl.is_default, pl.is_autoselect, base_url, content); + BuildMediaTag(*pl.playlist, pl.group_id, pl.is_default, pl.is_autoselect, + base_url, content); } } diff --git a/packager/media/formats/mp2t/es_parser_teletext.cc b/packager/media/formats/mp2t/es_parser_teletext.cc index 8e859d1b1da..50f1e25ec08 100644 --- a/packager/media/formats/mp2t/es_parser_teletext.cc +++ b/packager/media/formats/mp2t/es_parser_teletext.cc @@ -278,7 +278,8 @@ bool EsParserTeletext::ParseDataBlock(const int64_t pts, } void EsParserTeletext::UpdateCharset() { - memcpy(current_charset_, TELETEXT_CHARSET_G0_LATIN, sizeof(TELETEXT_CHARSET_G0_LATIN)); + memcpy(current_charset_, TELETEXT_CHARSET_G0_LATIN, + sizeof(TELETEXT_CHARSET_G0_LATIN)); if (charset_code_ > 7) { return; } From ab2736ab5050cb2c29f531547eb6e22d59e2ca29 Mon Sep 17 00:00:00 2001 From: SteveR-PMP Date: Fri, 15 Mar 2024 16:52:55 -0700 Subject: [PATCH 3/4] lint --- packager/hls/base/master_playlist.cc | 6 +++--- packager/media/formats/mp2t/es_parser_teletext.cc | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packager/hls/base/master_playlist.cc b/packager/hls/base/master_playlist.cc index ae845550c3e..d83d6fe343e 100644 --- a/packager/hls/base/master_playlist.cc +++ b/packager/hls/base/master_playlist.cc @@ -438,7 +438,7 @@ bool PlaylistOrderFn(const MediaPlaylist*& a, const MediaPlaylist*& b) { } bool TagslistOrderFn(const MediaTagslist& a, const MediaTagslist& b) { - return a.playlist->GetMediaInfo().index() < + return a.playlist->GetMediaInfo().index() < b.playlist->GetMediaInfo().index(); } @@ -490,7 +490,7 @@ void AppendPlaylists(const std::string& default_audio_language, audio_playlists.sort(TagslistOrderFn); } for (const auto& pl : audio_playlists) { - BuildMediaTag(*pl.playlist, pl.group_id, pl.is_default, pl.is_autoselect, + BuildMediaTag(*pl.playlist, pl.group_id, pl.is_default, pl.is_autoselect, base_url, content); } } @@ -504,7 +504,7 @@ void AppendPlaylists(const std::string& default_audio_language, subtitle_playlists.sort(TagslistOrderFn); } for (const auto& pl : subtitle_playlists) { - BuildMediaTag(*pl.playlist, pl.group_id, pl.is_default, pl.is_autoselect, + BuildMediaTag(*pl.playlist, pl.group_id, pl.is_default, pl.is_autoselect, base_url, content); } } diff --git a/packager/media/formats/mp2t/es_parser_teletext.cc b/packager/media/formats/mp2t/es_parser_teletext.cc index 50f1e25ec08..7aeb408bb37 100644 --- a/packager/media/formats/mp2t/es_parser_teletext.cc +++ b/packager/media/formats/mp2t/es_parser_teletext.cc @@ -278,7 +278,7 @@ bool EsParserTeletext::ParseDataBlock(const int64_t pts, } void EsParserTeletext::UpdateCharset() { - memcpy(current_charset_, TELETEXT_CHARSET_G0_LATIN, + memcpy(current_charset_, TELETEXT_CHARSET_G0_LATIN, sizeof(TELETEXT_CHARSET_G0_LATIN)); if (charset_code_ > 7) { return; From 6861ad6fe9d4a252b08f134916f6f50cf43f61f9 Mon Sep 17 00:00:00 2001 From: SteveR-PMP Date: Fri, 15 Mar 2024 16:54:21 -0700 Subject: [PATCH 4/4] lint --- packager/hls/base/master_playlist.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/packager/hls/base/master_playlist.cc b/packager/hls/base/master_playlist.cc index d83d6fe343e..9a89ac8bdb3 100644 --- a/packager/hls/base/master_playlist.cc +++ b/packager/hls/base/master_playlist.cc @@ -494,7 +494,6 @@ void AppendPlaylists(const std::string& default_audio_language, base_url, content); } } - if (!subtitle_playlist_groups.empty()) { content->append("\n");