Skip to content

Commit

Permalink
[HLSTree] Check for already add uri variant/rendition
Browse files Browse the repository at this point in the history
  • Loading branch information
CastagnaIT committed Aug 26, 2023
1 parent 99402f7 commit decc930
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/parser/HLSTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "../utils/log.h"
#include "kodi/tools/StringUtils.h"

#include <algorithm>
#include <optional>
#include <sstream>

Expand Down Expand Up @@ -974,6 +975,19 @@ bool adaptive::CHLSTree::ParseMultivariantPlaylist(const std::string& data)
rend.m_isForced = attribs["FORCED"] == "YES";
rend.m_characteristics = attribs["CHARACTERISTICS"];
rend.m_uri = attribs["URI"];
std::string uri = attribs["URI"];

if (!uri.empty())
{
// Check if this uri has been already added
if (std::any_of(pl.m_audioRenditions.cbegin(), pl.m_audioRenditions.cend(),
[&uri](const Rendition& v) { return v.m_uri == uri; }) ||
std::any_of(pl.m_subtitleRenditions.cbegin(), pl.m_subtitleRenditions.cend(),
[&uri](const Rendition& v) { return v.m_uri == uri; }))
{
rend.m_isUriDuplicate = true;
}
}

if (streamType == StreamType::AUDIO)
pl.m_audioRenditions.emplace_back(rend);
Expand Down Expand Up @@ -1017,6 +1031,13 @@ bool adaptive::CHLSTree::ParseMultivariantPlaylist(const std::string& data)
var.m_groupIdSubtitles = attribs["SUBTITLES"];
var.m_uri = uri;

// Check if this uri has been already added
if (std::any_of(pl.m_variants.cbegin(), pl.m_variants.cend(),
[&uri](const Variant& v) { return v.m_uri == uri; }))
{
var.m_isUriDuplicate = true;
}

pl.m_variants.emplace_back(var);
}
else if (tagName == "#EXT-X-SESSION-KEY")
Expand Down Expand Up @@ -1050,6 +1071,9 @@ bool adaptive::CHLSTree::ParseMultivariantPlaylist(const std::string& data)
// Add audio renditions (do not take in account variants references)
for (const Rendition& r : pl.m_audioRenditions)
{
if (r.m_isUriDuplicate)
continue;

auto newAdpSet = CAdaptationSet::MakeUniquePtr(period.get());
auto newRepr = CRepresentation::MakeUniquePtr(newAdpSet.get());

Expand Down Expand Up @@ -1096,6 +1120,9 @@ bool adaptive::CHLSTree::ParseMultivariantPlaylist(const std::string& data)
// Add subtitles renditions (do not take in account variants references)
for (const Rendition& r : pl.m_subtitleRenditions)
{
if (r.m_isUriDuplicate)
continue;

auto newAdpSet = CAdaptationSet::MakeUniquePtr(period.get());
auto newRepr = CRepresentation::MakeUniquePtr(newAdpSet.get());

Expand All @@ -1112,6 +1139,9 @@ bool adaptive::CHLSTree::ParseMultivariantPlaylist(const std::string& data)
// Add variants
for (const Variant& var : pl.m_variants)
{
if (var.m_isUriDuplicate)
continue;

if (var.m_bandwidth == 0)
LOG::LogF(LOGWARNING, "Variant with malformed bandwidth attribute");

Expand Down
4 changes: 4 additions & 0 deletions src/parser/HLSTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ class ATTR_DLL_LOCAL CHLSTree : public AdaptiveTree
std::string m_characteristics;
std::string m_uri;
int m_features{REND_FEATURE_NONE};
// Means that another rendition have same uri
bool m_isUriDuplicate{false};
};

// \brief Usually refer to an EXT-X-STREAM-INF tag
Expand All @@ -91,6 +93,8 @@ class ATTR_DLL_LOCAL CHLSTree : public AdaptiveTree
std::string m_groupIdAudio;
std::string m_groupIdSubtitles;
std::string m_uri;
// Means that another variant have same uri
bool m_isUriDuplicate{false};
};

struct MultivariantPlaylist
Expand Down

0 comments on commit decc930

Please sign in to comment.