Skip to content

Commit 7f3abfd

Browse files
authored
Merge pull request #1824 from CastagnaIT/stream_selection_fixes
Fix regressions and improvements to stream selection
2 parents 8a4990b + 704bd42 commit 7f3abfd

File tree

15 files changed

+252
-58
lines changed

15 files changed

+252
-58
lines changed

inputstream.adaptive/resources/language/resource.language.en_gb/strings.po

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,14 @@ msgctxt "#30171"
164164
msgid "Defines the initial bandwidth when it cannot be automatically determined. This value can be overridden by the minimum bandwidth setting."
165165
msgstr ""
166166

167-
#empty strings from id 30171 to 30173
167+
msgctxt "#30172"
168+
msgid "Resolution limit"
169+
msgstr ""
170+
171+
#. Description of setting with label #30172
172+
msgctxt "#30173"
173+
msgid "If set, based on the capabilities of the video stream an attempt will be made to limit the range of resolutions to the one chosen."
174+
msgstr ""
168175

169176
#. To set the stream selection type (refer to RepresentationChooser's)
170177
msgctxt "#30174"
@@ -228,44 +235,49 @@ msgctxt "#30204"
228235
msgid "Decrypter path"
229236
msgstr ""
230237

231-
#empty strings from id 30205 to 30209
238+
#empty strings from id 30205 to 30208
239+
240+
#. Item list value of setting with label #30172
241+
msgctxt "#30209"
242+
msgid "Disabled"
243+
msgstr ""
232244

233245
#. Item list value of setting with label #30110, #30113
234246
msgctxt "#30210"
235247
msgid "Auto"
236248
msgstr ""
237249

238-
#. Item list value of setting with label #30110, #30113
250+
#. Item list value of setting with label #30110, #30113, #30172
239251
msgctxt "#30211"
240252
msgid "480p"
241253
msgstr ""
242254

243-
#. Item list value of setting with label #30110, #30113
255+
#. Item list value of setting with label #30110, #30113, #30172
244256
msgctxt "#30212"
245257
msgid "640p"
246258
msgstr ""
247259

248-
#. Item list value of setting with label #30110, #30113
260+
#. Item list value of setting with label #30110, #30113, #30172
249261
msgctxt "#30213"
250262
msgid "720p"
251263
msgstr ""
252264

253-
#. Item list value of setting with label #30110, #30113
265+
#. Item list value of setting with label #30110, #30113, #30172
254266
msgctxt "#30214"
255267
msgid "1080p"
256268
msgstr ""
257269

258-
#. Item list value of setting with label #30110, #30113
270+
#. Item list value of setting with label #30110, #30113, #30172
259271
msgctxt "#30215"
260272
msgid "2K"
261273
msgstr ""
262274

263-
#. Item list value of setting with label #30110, #30113
275+
#. Item list value of setting with label #30110, #30113, #30172
264276
msgctxt "#30216"
265277
msgid "1440p"
266278
msgstr ""
267279

268-
#. Item list value of setting with label #30110, #30113
280+
#. Item list value of setting with label #30110, #30113, #30172
269281
msgctxt "#30217"
270282
msgid "4K"
271283
msgstr ""

inputstream.adaptive/resources/settings.xml.in

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,30 @@
6969
</dependencies>
7070
<control type="spinner" format="string" />
7171
</setting>
72+
<setting parent="adaptivestream.type" id="adaptivestream.res.rangelimit" type="string" label="30172" help="30173">
73+
<level>0</level>
74+
<default>disabled</default>
75+
<constraints>
76+
<options>
77+
<option label="30209">disabled</option>
78+
<option label="30211">480p</option>
79+
<option label="30212">640p</option>
80+
<option label="30213">720p</option>
81+
<option label="30214">1080p</option>
82+
<option label="30215">2K</option>
83+
<option label="30216">1440p</option>
84+
<option label="30217">4K</option>
85+
</options>
86+
</constraints>
87+
<dependencies>
88+
<dependency type="visible">
89+
<or>
90+
<condition setting="adaptivestream.type">ask-quality</condition>
91+
</or>
92+
</dependency>
93+
</dependencies>
94+
<control type="spinner" format="string" />
95+
</setting>
7296
<setting parent="adaptivestream.type" id="adaptivestream.bandwidth.init.auto" type="boolean" label="30168" help="30169">
7397
<level>0</level>
7498
<default>true</default>

src/CompSettings.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,16 @@ std::pair<int, int> ADP::SETTINGS::CCompSettings::GetResSecureMax() const
5555
return val;
5656
}
5757

58+
std::pair<int, int> ADP::SETTINGS::CCompSettings::GetResRangeLimit() const
59+
{
60+
std::pair<int, int> val;
61+
if (!STRING::GetMapValue(RES_CONV_LIST,
62+
kodi::addon::GetSettingString("adaptivestream.res.rangelimit"), val))
63+
LOG::Log(LOGERROR, "Unknown value for \"adaptivestream.res.rangelimit\" setting");
64+
65+
return val;
66+
}
67+
5868
bool ADP::SETTINGS::CCompSettings::IsBandwidthInitAuto() const
5969
{
6070
return kodi::addon::GetSettingBoolean("adaptivestream.bandwidth.init.auto");

src/CompSettings.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ namespace SETTINGS
2626
// Generic conversion map from family of resolutions to a common pixel format.
2727
// If modified, the changes should reflect XML settings and Kodi properties related to resolutions.
2828
const std::map<std::string, std::pair<int, int>> RES_CONV_LIST{
29-
{"auto", {0, 0}}, {"480p", {640, 480}}, {"640p", {960, 640}}, {"720p", {1280, 720}},
30-
{"1080p", {1920, 1080}}, {"2K", {2048, 1080}}, {"1440p", {2560, 1440}}, {"4K", {3840, 2160}}};
29+
{"disabled", {0, 0}}, {"auto", {0, 0}}, {"480p", {640, 480}},
30+
{"640p", {960, 640}}, {"720p", {1280, 720}}, {"1080p", {1920, 1080}},
31+
{"2K", {2048, 1080}}, {"1440p", {2560, 1440}}, {"4K", {3840, 2160}}};
3132

3233
enum class StreamSelMode
3334
{
@@ -50,6 +51,7 @@ class ATTR_DLL_LOCAL CCompSettings
5051

5152
std::pair<int, int> GetResMax() const;
5253
std::pair<int, int> GetResSecureMax() const;
54+
std::pair<int, int> GetResRangeLimit() const;
5355

5456
bool IsBandwidthInitAuto() const;
5557
uint32_t GetBandwidthInit() const;

src/Session.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,12 @@ void SESSION::CSession::InitializePeriod()
304304
else
305305
isManualStreamSelection = streamSelectionMode == CHOOSER::StreamSelection::MANUAL;
306306

307+
const bool isDefaultAdpSet{adp == defVideoAdpSet};
308+
307309
// Get the default initial stream repr. based on "adaptive repr. chooser"
308310
CRepresentation* defaultRepr{m_reprChooser->GetRepresentation(adp)};
311+
if (isDefaultAdpSet)
312+
m_reprChooser->LogDetails(defaultRepr);
309313

310314
if (isManualStreamSelection)
311315
{
@@ -320,9 +324,9 @@ void SESSION::CSession::InitializePeriod()
320324
if (!currentRepr->isPlayable)
321325
continue;
322326

323-
const bool isDefaultRepr{adp == defVideoAdpSet && currentRepr == defaultRepr}; // meant for video only
327+
const bool isDefaultVideoRepr{isDefaultAdpSet && currentRepr == defaultRepr};
324328

325-
AddStream(adp, currentRepr, isDefaultRepr, uniqueId, audioLanguageOrig);
329+
AddStream(adp, currentRepr, isDefaultVideoRepr, uniqueId, audioLanguageOrig);
326330
}
327331
}
328332
else
@@ -335,16 +339,14 @@ void SESSION::CSession::InitializePeriod()
335339
uint32_t uniqueId{adpIndex};
336340
uniqueId |= reprIndex << 16;
337341

338-
const bool isDefaultRepr{adp == defVideoAdpSet}; // meant for video only
339-
340-
AddStream(adp, defaultRepr, isDefaultRepr, uniqueId, audioLanguageOrig);
342+
AddStream(adp, defaultRepr, isDefaultAdpSet, uniqueId, audioLanguageOrig);
341343
}
342344
}
343345
}
344346

345347
void SESSION::CSession::AddStream(PLAYLIST::CAdaptationSet* adp,
346348
PLAYLIST::CRepresentation* initialRepr,
347-
bool isDefaultRepr,
349+
bool isDefaultVideoRepr,
348350
uint32_t uniqueId,
349351
std::string_view audioLanguageOrig)
350352
{
@@ -360,7 +362,7 @@ void SESSION::CSession::AddStream(PLAYLIST::CAdaptationSet* adp,
360362
case StreamType::VIDEO:
361363
{
362364
stream.m_info.SetStreamType(INPUTSTREAM_TYPE_VIDEO);
363-
if (isDefaultRepr)
365+
if (isDefaultVideoRepr)
364366
flags |= INPUTSTREAM_FLAG_DEFAULT;
365367
break;
366368
}
@@ -1180,6 +1182,8 @@ PLAYLIST::CAdaptationSet* SESSION::CSession::DetermineDefaultAdpSet()
11801182
CODEC::FOURCC_HEVC, CODEC::FOURCC_AV01, CODEC::NAME_AV1, CODEC::FOURCC_VP09,
11811183
CODEC::NAME_VP9, CODEC::FOURCC_AVC_, CODEC::FOURCC_H264};
11821184

1185+
CAdaptationSet* defaultAdp{nullptr}; // Default determined by codec order
1186+
11831187
for (auto& codecCC : videoCodecOrder)
11841188
{
11851189
CAdaptationSet* currAdp{nullptr};
@@ -1189,10 +1193,16 @@ PLAYLIST::CAdaptationSet* SESSION::CSession::DetermineDefaultAdpSet()
11891193
if (currAdp->GetRepresentations().empty() || currAdp->GetStreamType() != StreamType::VIDEO)
11901194
continue;
11911195

1192-
if (CODEC::Contains(currAdp->GetCodecs(), codecCC))
1196+
if (currAdp->IsDefault()) // Override by manifest custom parameter
1197+
{
11931198
return currAdp;
1199+
}
1200+
else if (CODEC::Contains(currAdp->GetCodecs(), codecCC) && !defaultAdp)
1201+
{
1202+
defaultAdp = currAdp;
1203+
}
11941204
}
11951205
}
11961206

1197-
return nullptr;
1207+
return defaultAdp;
11981208
}

src/Session.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ class ATTR_DLL_LOCAL CSession : public adaptive::AdaptiveStreamObserver
5757
/*! \brief Create and push back a new Stream object
5858
* \param adp The AdaptationSet of the stream
5959
* \param repr The Representation of the stream
60-
* \param isDefaultRepr Whether this Representation is the default
60+
* \param isDefaultVideoRepr Whether this video Representation is the default
6161
* \param uniqueId A unique identifier for the Representation
6262
*/
6363
void AddStream(PLAYLIST::CAdaptationSet* adp,
6464
PLAYLIST::CRepresentation* repr,
65-
bool isDefaultRepr,
65+
bool isDefaultVideoRepr,
6666
uint32_t uniqueId,
6767
std::string_view audioLanguageOrig);
6868

src/common/Chooser.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,13 @@ void CHOOSER::IRepresentationChooser::OnUpdateScreenRes()
114114
}
115115
}
116116

117-
void CHOOSER::IRepresentationChooser::LogDetails(PLAYLIST::CRepresentation* currentRep,
118-
PLAYLIST::CRepresentation* nextRep)
117+
void CHOOSER::IRepresentationChooser::LogDetails(const PLAYLIST::CRepresentation* rep)
118+
{
119+
LogDetails(nullptr, rep);
120+
}
121+
122+
void CHOOSER::IRepresentationChooser::LogDetails(const PLAYLIST::CRepresentation* currentRep,
123+
const PLAYLIST::CRepresentation* nextRep)
119124
{
120125
if (!nextRep)
121126
return;

src/common/Chooser.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,17 @@ class ATTR_DLL_LOCAL IRepresentationChooser
121121
PLAYLIST::CAdaptationSet* adp,
122122
PLAYLIST::CRepresentation* currentRep) = 0;
123123

124+
/*!
125+
* \brief Prints details of the specified representation in the log
126+
*/
127+
void LogDetails(const PLAYLIST::CRepresentation* rep);
128+
124129
protected:
125130
/*!
126131
* \brief Prints details of the selected or changed representation in the log
127132
*/
128-
void LogDetails(PLAYLIST::CRepresentation* currentRep,
129-
PLAYLIST::CRepresentation* nextRep);
133+
void LogDetails(const PLAYLIST::CRepresentation* currentRep,
134+
const PLAYLIST::CRepresentation* nextRep);
130135

131136
bool m_isSecureSession{false};
132137

0 commit comments

Comments
 (0)