Skip to content

Commit 704bd42

Browse files
committed
[ChooserAskQuality] Add new range resolution limit setting
1 parent 6d13c5d commit 704bd42

File tree

6 files changed

+114
-35
lines changed

6 files changed

+114
-35
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/common/ChooserAskQuality.cpp

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "ChooserAskQuality.h"
1010

1111
#include "AdaptationSet.h"
12+
#include "CompSettings.h"
1213
#include "CompKodiProps.h"
1314
#include "ReprSelector.h"
1415
#include "Representation.h"
@@ -44,6 +45,27 @@ std::string CovertFpsToString(float value)
4445

4546
return str;
4647
}
48+
49+
std::string CreateStreamName(const CRepresentation* repr)
50+
{
51+
std::string streamName{kodi::addon::GetLocalizedString(30232)};
52+
STRING::ReplaceFirst(streamName, "{codec}", CODEC::GetVideoDesc(repr->GetCodecs()));
53+
54+
float fps{static_cast<float>(repr->GetFrameRate())};
55+
if (fps > 0 && repr->GetFrameRateScale() > 0)
56+
fps /= repr->GetFrameRateScale();
57+
58+
std::string quality = "(";
59+
if (repr->GetWidth() > 0 && repr->GetHeight() > 0)
60+
quality += StringUtils::Format("%ix%i, ", repr->GetWidth(), repr->GetHeight());
61+
if (fps > 0)
62+
quality += StringUtils::Format("%s fps, ", CovertFpsToString(fps).c_str());
63+
64+
quality += StringUtils::Format("%u Kbps)", repr->GetBandwidth() / 1000);
65+
STRING::ReplaceFirst(streamName, "{quality}", quality);
66+
67+
return streamName;
68+
}
4769
} // unnamed namespace
4870

4971
CRepresentationChooserAskQuality::CRepresentationChooserAskQuality()
@@ -53,6 +75,13 @@ CRepresentationChooserAskQuality::CRepresentationChooserAskQuality()
5375

5476
void CRepresentationChooserAskQuality::Initialize(const ADP::KODI_PROPS::ChooserProps& props)
5577
{
78+
auto& settings = CSrvBroker::GetSettings();
79+
m_resRangeLimit = settings.GetResRangeLimit();
80+
81+
LOG::Log(LOGDEBUG,
82+
"[Repr. chooser] Configuration\n"
83+
"Resolution range limit: %ix%i",
84+
m_resRangeLimit.first, m_resRangeLimit.second);
5685
}
5786

5887
void CRepresentationChooserAskQuality::PostInit()
@@ -94,40 +123,41 @@ PLAYLIST::CAdaptationSet* CHOOSER::CRepresentationChooserAskQuality::GetPreferre
94123
if (adpSet->GetStreamType() != StreamType::VIDEO || adpSet->GetRepresentations().size() == 0)
95124
continue;
96125

97-
CRepresentation* bestRep{nullptr};
98-
99-
// preferred adaptation set, in order to have a preferred codec for multi-codec manifests
100-
if (adpSetPreferred == adpSet.get())
126+
if (m_resRangeLimit.first != 0) // Show only the nearest resolution to the preference
101127
{
102-
bestRep = selector.Highest(adpSetPreferred);
103-
}
128+
CRepresentationSelector selector{m_resRangeLimit.first, m_resRangeLimit.second};
129+
CRepresentation* nearestRep = selector.Nearest(adpSet.get());
104130

105-
for (auto& repr : adpSet->GetRepresentations())
106-
{
107-
if (!repr->isPlayable)
108-
continue;
131+
if (nearestRep)
132+
{
133+
entries.emplace_back(CreateStreamName(nearestRep));
134+
entriesOjb.emplace_back(adpSet.get(), nearestRep);
109135

110-
std::string entryName{kodi::addon::GetLocalizedString(30232)};
111-
STRING::ReplaceFirst(entryName, "{codec}", CODEC::GetVideoDesc(repr->GetCodecs()));
112-
113-
float fps{static_cast<float>(repr->GetFrameRate())};
114-
if (fps > 0 && repr->GetFrameRateScale() > 0)
115-
fps /= repr->GetFrameRateScale();
136+
if (adpSet.get() == adpSetPreferred)
137+
preselIndex = static_cast<int>(entries.size()) - 1;
138+
}
139+
}
140+
else // Show all resolutions
141+
{
142+
CRepresentation* bestRep{nullptr};
116143

117-
std::string quality = "(";
118-
if (repr->GetWidth() > 0 && repr->GetHeight() > 0)
119-
quality += StringUtils::Format("%ix%i, ", repr->GetWidth(), repr->GetHeight());
120-
if (fps > 0)
121-
quality += StringUtils::Format("%s fps, ", CovertFpsToString(fps).c_str());
144+
// preferred adaptation set, in order to have a preferred codec for multi-codec manifests
145+
if (adpSetPreferred == adpSet.get())
146+
{
147+
bestRep = selector.Highest(adpSetPreferred);
148+
}
122149

123-
quality += StringUtils::Format("%u Kbps)", repr->GetBandwidth() / 1000);
124-
STRING::ReplaceFirst(entryName, "{quality}", quality);
150+
for (auto& repr : adpSet->GetRepresentations())
151+
{
152+
if (!repr->isPlayable)
153+
continue;
125154

126-
entries.emplace_back(entryName);
155+
entries.emplace_back(CreateStreamName(repr.get()));
127156
entriesOjb.emplace_back(adpSet.get(), repr.get());
128157

129158
if (repr.get() == bestRep)
130159
preselIndex = static_cast<int>(entries.size()) - 1;
160+
}
131161
}
132162
}
133163

src/common/ChooserAskQuality.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class ATTR_DLL_LOCAL CRepresentationChooserAskQuality : public IRepresentationCh
3333

3434
private:
3535
bool m_isDialogShown{false};
36+
std::pair<int, int> m_resRangeLimit;
3637
int m_selectedResWidth{0};
3738
int m_selectedResHeight{0};
3839
uint32_t m_selectedBandwidth{0};

0 commit comments

Comments
 (0)