@@ -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 }
0 commit comments