Skip to content

Commit eb979b3

Browse files
authored
Merge pull request #1826 from CastagnaIT/cleanup_adp
[Session] Removed GetAdaptationSet uses and some other cleanups
2 parents dcc79d8 + 7cc805a commit eb979b3

File tree

4 files changed

+35
-37
lines changed

4 files changed

+35
-37
lines changed

src/Session.cpp

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ bool SESSION::CSession::Initialize(std::string manifestUrl)
135135
return true;
136136
}
137137

138-
bool SESSION::CSession::CheckPlayableStreams()
138+
bool SESSION::CSession::CheckPlayableStreams(PLAYLIST::CPeriod* period)
139139
{
140140
auto& kodiPropCfg = CSrvBroker::GetKodiProps().GetConfig();
141141

@@ -147,10 +147,8 @@ bool SESSION::CSession::CheckPlayableStreams()
147147
return;
148148
}
149149
*/
150-
uint32_t adpIndex{0};
151-
CAdaptationSet* adp{nullptr};
152150

153-
while ((adp = m_adaptiveTree->GetAdaptationSet(adpIndex++)))
151+
for (auto& adp : period->GetAdaptationSets())
154152
{
155153
for (auto& repr : adp->GetRepresentations())
156154
{
@@ -169,8 +167,8 @@ bool SESSION::CSession::CheckPlayableStreams()
169167
DRM::DRMInfo initDrmInfo;
170168

171169
if (m_drmEngine.InitializeSession(repr->DrmInfos(), DRM::DRMMediaType::VIDEO,
172-
m_adaptiveTree->m_currentPeriod->IsSecureDecodeNeeded(),
173-
isInfo, repr.get(), adp, false, initDrmInfo))
170+
period->IsSecureDecodeNeeded(), isInfo, repr.get(),
171+
adp.get(), false, initDrmInfo))
174172
{
175173
if (!isInfo.GetCryptoSession().GetSessionId().empty())
176174
{
@@ -261,17 +259,21 @@ void SESSION::CSession::InitializePeriod()
261259
m_adaptiveTree->OnPeriodChange();
262260
}
263261

264-
m_chapterStartTime = GetChapterStartTime();
265-
266262
// Clean to create new SESSION::STREAM objects. One for each AdaptationSet/Representation
267263
m_streams.clear();
268264

269-
// Note: this could initialize DRM on all streams right here, instead of CInputStreamAdaptive::OpenStream
270-
if (!CheckPlayableStreams())
265+
CPeriod* currPeriod = m_adaptiveTree->m_currentPeriod;
266+
if (!currPeriod)
267+
{
268+
LOG::LogF(LOGFATAL, "No period found on AdaptiveTree class");
271269
return;
270+
}
272271

273-
uint32_t adpIndex{0};
274-
CAdaptationSet* adp{nullptr};
272+
m_chapterStartTime = GetChapterStartTime();
273+
274+
// Note: this could initialize DRM on all streams right here, instead of CInputStreamAdaptive::OpenStream
275+
if (!CheckPlayableStreams(currPeriod))
276+
return;
275277

276278
CHOOSER::StreamSelection streamSelectionMode = m_reprChooser->GetStreamSelectionMode();
277279
//! @todo: GetAudioLangOrig property should be reworked to allow override or set
@@ -283,11 +285,14 @@ void SESSION::CSession::InitializePeriod()
283285

284286
// For multi-codec manifests, determine which codec to use by default,
285287
// then choose the appropriate AdaptationSet. It may also depend on the Chooser behavior.
286-
CAdaptationSet* defVideoAdpSet = m_reprChooser->GetPreferredVideoAdpSet(
287-
m_adaptiveTree->m_currentPeriod, DetermineDefaultAdpSet());
288+
const CAdaptationSet* defVideoAdpSet =
289+
m_reprChooser->GetPreferredVideoAdpSet(currPeriod, DetermineDefaultAdpSet(currPeriod));
288290

289-
while ((adp = m_adaptiveTree->GetAdaptationSet(adpIndex++)))
291+
uint32_t adpIndex{0};
292+
for (auto& adp : currPeriod->GetAdaptationSets())
290293
{
294+
adpIndex++;
295+
291296
if (adp->GetRepresentations().empty())
292297
continue;
293298

@@ -304,10 +309,10 @@ void SESSION::CSession::InitializePeriod()
304309
else
305310
isManualStreamSelection = streamSelectionMode == CHOOSER::StreamSelection::MANUAL;
306311

307-
const bool isDefaultAdpSet{adp == defVideoAdpSet};
312+
const bool isDefaultAdpSet{adp.get() == defVideoAdpSet};
308313

309314
// Get the default initial stream repr. based on "adaptive repr. chooser"
310-
CRepresentation* defaultRepr{m_reprChooser->GetRepresentation(adp)};
315+
CRepresentation* defaultRepr{m_reprChooser->GetRepresentation(adp.get())};
311316
if (isDefaultAdpSet)
312317
m_reprChooser->LogDetails(defaultRepr);
313318

@@ -326,7 +331,7 @@ void SESSION::CSession::InitializePeriod()
326331

327332
const bool isDefaultVideoRepr{isDefaultAdpSet && currentRepr == defaultRepr};
328333

329-
AddStream(adp, currentRepr, isDefaultVideoRepr, uniqueId, audioLanguageOrig);
334+
AddStream(adp.get(), currentRepr, isDefaultVideoRepr, uniqueId, audioLanguageOrig);
330335
}
331336
}
332337
else
@@ -339,7 +344,7 @@ void SESSION::CSession::InitializePeriod()
339344
uint32_t uniqueId{adpIndex};
340345
uniqueId |= reprIndex << 16;
341346

342-
AddStream(adp, defaultRepr, isDefaultAdpSet, uniqueId, audioLanguageOrig);
347+
AddStream(adp.get(), defaultRepr, isDefaultAdpSet, uniqueId, audioLanguageOrig);
343348
}
344349
}
345350
}
@@ -1181,7 +1186,7 @@ bool SESSION::CSession::SeekChapter(int ch)
11811186
return false;
11821187
}
11831188

1184-
PLAYLIST::CAdaptationSet* SESSION::CSession::DetermineDefaultAdpSet()
1189+
PLAYLIST::CAdaptationSet* SESSION::CSession::DetermineDefaultAdpSet(PLAYLIST::CPeriod* period)
11851190
{
11861191
//! @todo: this is a rough first implementation that have a fixed codec priority order,
11871192
//! and only for video streams. In the future it should be improved
@@ -1199,20 +1204,18 @@ PLAYLIST::CAdaptationSet* SESSION::CSession::DetermineDefaultAdpSet()
11991204

12001205
for (auto& codecCC : videoCodecOrder)
12011206
{
1202-
CAdaptationSet* currAdp{nullptr};
1203-
uint32_t adpIndex{0};
1204-
while ((currAdp = m_adaptiveTree->GetAdaptationSet(adpIndex++)))
1207+
for (auto& adp : period->GetAdaptationSets())
12051208
{
1206-
if (currAdp->GetRepresentations().empty() || currAdp->GetStreamType() != StreamType::VIDEO)
1209+
if (adp->GetRepresentations().empty() || adp->GetStreamType() != StreamType::VIDEO)
12071210
continue;
12081211

1209-
if (currAdp->IsDefault()) // Override by manifest custom parameter
1212+
if (adp->IsDefault()) // Override by manifest custom parameter
12101213
{
1211-
return currAdp;
1214+
return adp.get();
12121215
}
1213-
else if (CODEC::Contains(currAdp->GetCodecs(), codecCC) && !defaultAdp)
1216+
else if (CODEC::Contains(adp->GetCodecs(), codecCC) && !defaultAdp)
12141217
{
1215-
defaultAdp = currAdp;
1218+
defaultAdp = adp.get();
12161219
}
12171220
}
12181221
}

src/Session.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ATTR_DLL_LOCAL CSession : public adaptive::AdaptiveStreamObserver
3838
*/
3939
bool Initialize(std::string manifestUrl);
4040

41-
bool CheckPlayableStreams();
41+
bool CheckPlayableStreams(PLAYLIST::CPeriod* period);
4242

4343
/*!
4444
* \brief Initialize adaptive tree period
@@ -273,9 +273,10 @@ class ATTR_DLL_LOCAL CSession : public adaptive::AdaptiveStreamObserver
273273
/*!
274274
* \brief Determine the AdaptationSet that should be the default to be played,
275275
* the behavior is mainly based on codec types
276+
* \param period The period where get adaptation sets
276277
* \return The AdaptationSet, or nullptr if unhandled
277278
*/
278-
PLAYLIST::CAdaptationSet* DetermineDefaultAdpSet();
279+
PLAYLIST::CAdaptationSet* DetermineDefaultAdpSet(PLAYLIST::CPeriod* period);
279280

280281
private:
281282
DRM::CDRMEngine m_drmEngine;

src/common/AdaptationSet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class ATTR_DLL_LOCAL CAdaptationSet : public CCommonSegAttribs, public CCommonAt
9696

9797
void AddRepresentation(std::unique_ptr<CRepresentation>& representation);
9898
std::vector<std::unique_ptr<CRepresentation>>& GetRepresentations() { return m_representations; }
99+
const std::vector<std::unique_ptr<CRepresentation>>& GetRepresentations() const { return m_representations; }
99100
std::vector<CRepresentation*> GetRepresentationsPtr();
100101

101102
bool IsImpaired() const { return m_isImpaired; }

src/common/AdaptiveTree.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,13 +209,6 @@ class ATTR_DLL_LOCAL AdaptiveTree
209209
return false;
210210
}
211211

212-
PLAYLIST::CAdaptationSet* GetAdaptationSet(size_t pos) const
213-
{
214-
return m_currentPeriod && pos < m_currentPeriod->GetAdaptationSets().size()
215-
? m_currentPeriod->GetAdaptationSets()[pos].get()
216-
: nullptr;
217-
}
218-
219212
/*!
220213
* \brief Checks if a period change is in progress (m_nextPeriod is set).
221214
* \return True the period will be changed, otherwise false.

0 commit comments

Comments
 (0)