forked from xbmc/inputstream.adaptive
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAdaptationSet.cpp
More file actions
180 lines (155 loc) · 5.78 KB
/
Copy pathAdaptationSet.cpp
File metadata and controls
180 lines (155 loc) · 5.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
* Copyright (C) 2023 Team Kodi
* This file is part of Kodi - https://kodi.tv
*
* SPDX-License-Identifier: GPL-2.0-or-later
* See LICENSES/README.md for more information.
*/
#include "AdaptationSet.h"
#include "Representation.h"
#include "kodi/tools/StringUtils.h"
#include "../utils/StringUtils.h"
#include <algorithm> // any_of
using namespace PLAYLIST;
using namespace UTILS;
using namespace kodi::tools;
void PLAYLIST::CAdaptationSet::AddCodecs(std::string_view codecs)
{
std::set<std::string> list = STRING::Split(codecs.data(), ',');
m_codecs.insert(list.begin(), list.end());
}
bool PLAYLIST::CAdaptationSet::ContainsCodec(std::string_view codec)
{
if (std::any_of(m_codecs.begin(), m_codecs.end(),
[codec](const std::string_view name) { return STRING::Contains(name, codec); }))
{
return true;
}
return false;
}
void PLAYLIST::CAdaptationSet::AddSwitchingIds(std::string_view switchingIds)
{
std::vector<std::string> list = StringUtils::Split(switchingIds.data(), ',');
m_switchingIds.insert(m_switchingIds.end(), list.begin(), list.end());
}
void PLAYLIST::CAdaptationSet::AddRepresentation(
std::unique_ptr<CRepresentation>& representation)
{
m_representations.push_back(std::move(representation));
}
std::vector<CRepresentation*> PLAYLIST::CAdaptationSet::GetRepresentationsPtr()
{
std::vector<CRepresentation*> ptrReprs;
std::transform(m_representations.begin(), m_representations.end(), back_inserter(ptrReprs),
[](const std::unique_ptr<CRepresentation>& r) { return r.get(); });
return ptrReprs;
}
void PLAYLIST::CAdaptationSet::CopyHLSData(const CAdaptationSet* other)
{
m_representations.reserve(other->m_representations.size());
for (const auto& otherRep : other->m_representations)
{
std::unique_ptr<CRepresentation> rep = CRepresentation::MakeUniquePtr(this);
rep->CopyHLSData(otherRep.get());
m_representations.push_back(std::move(rep));
}
m_streamType = other->m_streamType;
m_duration = other->m_duration;
m_startPts = other->m_startPts;
m_startNumber = other->m_startNumber;
m_isImpaired = other->m_isImpaired;
m_isOriginal = other->m_isOriginal;
m_isDefault = other->m_isDefault;
m_isForced = other->m_isForced;
m_language = other->m_language;
m_mimeType = other->m_mimeType;
m_baseUrl = other->m_baseUrl;
m_id = other->m_id;
m_group = other->m_group;
m_codecs = other->m_codecs;
m_name = other->m_name;
}
bool PLAYLIST::CAdaptationSet::IsMergeable(const CAdaptationSet* other) const
{
if (m_streamType != other->m_streamType)
return false;
if (m_streamType == StreamType::VIDEO)
{
if (m_group == other->m_group &&
std::find(m_switchingIds.begin(), m_switchingIds.end(), other->m_id) !=
m_switchingIds.end() &&
std::find(other->m_switchingIds.begin(), other->m_switchingIds.end(), m_id) !=
other->m_switchingIds.end())
{
return true;
}
}
else if (m_streamType == StreamType::AUDIO)
{
if (m_id == other->m_id && m_startPts == other->m_startPts &&
m_startNumber == other->m_startNumber && m_duration == other->m_duration &&
m_group == other->m_group && m_language == other->m_language && m_name == other->m_name &&
m_baseUrl == other->m_baseUrl && m_isDefault == other->m_isDefault &&
m_isOriginal == other->m_isOriginal && m_isForced == other->m_isForced &&
m_isImpaired == other->m_isImpaired && m_mimeType == other->m_mimeType &&
m_audioChannels == other->m_audioChannels && m_codecs == other->m_codecs)
{
return true;
}
}
return false;
}
bool PLAYLIST::CAdaptationSet::Compare(const std::unique_ptr<CAdaptationSet>& left,
const std::unique_ptr<CAdaptationSet>& right)
{
if (left->m_streamType != right->m_streamType)
return left->m_streamType < right->m_streamType;
if (left->m_isDefault != right->m_isDefault)
return left->m_isDefault;
if (left->m_streamType == StreamType::AUDIO)
{
if (left->m_name != right->m_name)
return left->m_name < right->m_name;
if (left->m_isImpaired != right->m_isImpaired)
return !left->m_isImpaired;
if (left->m_isOriginal != right->m_isOriginal)
return left->m_isOriginal;
if (!left->m_representations.empty() && !right->m_representations.empty())
{
const PLAYLIST::CRepresentation* leftRepr = left->m_representations[0].get();
const PLAYLIST::CRepresentation* rightRepr = right->m_representations[0].get();
if (leftRepr->GetCodecs() != rightRepr->GetCodecs())
return leftRepr->GetCodecs() < rightRepr->GetCodecs();
if (leftRepr->GetAudioChannels() != rightRepr->GetAudioChannels())
return leftRepr->GetAudioChannels() < rightRepr->GetAudioChannels();
}
}
else if (left->m_streamType == StreamType::SUBTITLE)
{
if (left->m_isImpaired != right->m_isImpaired)
return !left->m_isImpaired;
if (left->m_isForced != right->m_isForced)
return left->m_isForced;
}
return false;
}
std::vector<std::unique_ptr<CAdaptationSet>>::const_iterator PLAYLIST::CAdaptationSet::
FindAudioAdpSet(const std::vector<std::unique_ptr<CAdaptationSet>>& adpSets,
const std::string langCode,
bool isPreferStereo,
bool filterImpaired)
{
for (auto& itAdpSet = adpSets.cbegin(); itAdpSet != adpSets.cend(); itAdpSet++)
{
auto adpSet = itAdpSet->get();
if (adpSet->GetStreamType() == StreamType::AUDIO &&
STRING::CompareNoCase(adpSet->GetLanguage(), langCode) &&
(isPreferStereo ? adpSet->GetRepresentations()[0]->GetAudioChannels() <= 2
: adpSet->GetRepresentations()[0]->GetAudioChannels() > 2) &&
adpSet->IsImpaired() == filterImpaired)
{
return itAdpSet;
}
}
return adpSets.end();
}