forked from xbmc/inputstream.adaptive
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathPropertiesUtils.cpp
More file actions
198 lines (180 loc) · 7.71 KB
/
Copy pathPropertiesUtils.cpp
File metadata and controls
198 lines (180 loc) · 7.71 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
* Copyright (C) 2022 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 "PropertiesUtils.h"
#include "SettingsUtils.h"
#include "StringUtils.h"
#include "Utils.h"
#include "log.h"
#include <string_view>
using namespace UTILS::PROPERTIES;
namespace
{
// clang-format off
constexpr std::string_view PROP_LICENSE_TYPE = "inputstream.adaptive.license_type";
constexpr std::string_view PROP_LICENSE_KEY = "inputstream.adaptive.license_key";
constexpr std::string_view PROP_LICENSE_DATA = "inputstream.adaptive.license_data";
constexpr std::string_view PROP_LICENSE_FLAGS = "inputstream.adaptive.license_flags";
constexpr std::string_view PROP_SERVER_CERT = "inputstream.adaptive.server_certificate";
constexpr std::string_view PROP_MANIFEST_TYPE = "inputstream.adaptive.manifest_type"; //! @todo: deprecated, to be removed on next Kodi release
constexpr std::string_view PROP_MANIFEST_UPD_PARAM = "inputstream.adaptive.manifest_update_parameter";
constexpr std::string_view PROP_MANIFEST_PARAMS = "inputstream.adaptive.manifest_params";
constexpr std::string_view PROP_MANIFEST_HEADERS = "inputstream.adaptive.manifest_headers";
constexpr std::string_view PROP_STREAM_PARAMS = "inputstream.adaptive.stream_params";
constexpr std::string_view PROP_STREAM_HEADERS = "inputstream.adaptive.stream_headers";
constexpr std::string_view PROP_AUDIO_LANG_ORIG = "inputstream.adaptive.original_audio_language"; //! @todo: deprecated, to be removed on next Kodi release
constexpr std::string_view PROP_STREAMS_CONFIG = "inputstream.adaptive.streams_config";
constexpr std::string_view PROP_PLAY_TIMESHIFT_BUFFER = "inputstream.adaptive.play_timeshift_buffer";
constexpr std::string_view PROP_LIVE_DELAY = "inputstream.adaptive.live_delay";
constexpr std::string_view PROP_PRE_INIT_DATA = "inputstream.adaptive.pre_init_data";
// Chooser's properties
constexpr std::string_view PROP_STREAM_SELECTION_TYPE = "inputstream.adaptive.stream_selection_type";
constexpr std::string_view PROP_CHOOSER_BANDWIDTH_MAX = "inputstream.adaptive.chooser_bandwidth_max";
constexpr std::string_view PROP_CHOOSER_RES_MAX = "inputstream.adaptive.chooser_resolution_max";
constexpr std::string_view PROP_CHOOSER_RES_SECURE_MAX = "inputstream.adaptive.chooser_resolution_secure_max";
// clang-format on
} // unnamed namespace
KodiProperties UTILS::PROPERTIES::ParseKodiProperties(
const std::map<std::string, std::string> properties)
{
KodiProperties props;
for (auto& prop : properties)
{
bool logPropValRedacted{false};
if (prop.first == PROP_LICENSE_TYPE)
{
props.m_licenseType = prop.second;
}
else if (prop.first == PROP_LICENSE_KEY)
{
props.m_licenseKey = prop.second;
logPropValRedacted = true;
}
else if (prop.first == PROP_LICENSE_DATA)
{
props.m_licenseData = prop.second;
logPropValRedacted = true;
}
else if (prop.first == PROP_LICENSE_FLAGS)
{
if (prop.second.find("persistent_storage") != std::string::npos)
props.m_isLicensePersistentStorage = true;
if (prop.second.find("force_secure_decoder") != std::string::npos)
props.m_isLicenseForceSecureDecoder = true;
}
else if (prop.first == PROP_SERVER_CERT)
{
props.m_serverCertificate = prop.second;
logPropValRedacted = true;
}
else if (prop.first == PROP_MANIFEST_TYPE) //! @todo: deprecated, to be removed on next Kodi release
{
LOG::Log(
LOGWARNING,
"Warning \"inputstream.adaptive.manifest_type\" property is deprecated and "
"will be removed next Kodi version, the manifest type is now automatically detected.\n"
"If you are using a proxy remember to add the appropriate \"content-type\" header "
"to the HTTP manifest response\nSee Wiki page \"How to provide custom manifest/license\" "
"to learn more about it.");
if (STRING::CompareNoCase(prop.second, "MPD"))
props.m_manifestType = ManifestType::MPD;
else if (STRING::CompareNoCase(prop.second, "ISM"))
props.m_manifestType = ManifestType::ISM;
else if (STRING::CompareNoCase(prop.second, "HLS"))
props.m_manifestType = ManifestType::HLS;
else
LOG::LogF(LOGERROR, "Manifest type \"%s\" is not supported", prop.second.c_str());
}
else if (prop.first == PROP_MANIFEST_UPD_PARAM)
{
props.m_manifestUpdateParam = prop.second;
}
else if (prop.first == PROP_MANIFEST_PARAMS)
{
props.m_manifestParams = prop.second;
}
else if (prop.first == PROP_MANIFEST_HEADERS)
{
ParseHeaderString(props.m_manifestHeaders, prop.second);
}
else if (prop.first == PROP_STREAM_PARAMS)
{
props.m_streamParams = prop.second;
}
else if (prop.first == PROP_STREAM_HEADERS)
{
ParseHeaderString(props.m_streamHeaders, prop.second);
}
else if (prop.first == PROP_AUDIO_LANG_ORIG) //! @todo: deprecated, to be removed on next Kodi release
{
LOG::Log(LOGWARNING,
"Warning \"inputstream.adaptive.original_audio_language\" property is deprecated "
"has been replaced by \"inputstream.adaptive.stream_audio_cfg\". "
"Please read Wiki \"Integration\" page to learn more about the new properties.");
props.m_audioLangOriginal = prop.second;
}
else if (prop.first == PROP_STREAMS_CONFIG)
{
auto values = STRING::ToMap(prop.second, '=', ';');
if (STRING::KeyExists(values, "audio_langcode_default"))
props.m_audioLangDefault = STRING::Trim(values["audio_langcode_default"]);
if (STRING::KeyExists(values, "audio_langcode_original"))
props.m_audioLangOriginal = STRING::Trim(values["audio_langcode_original"]);
if (STRING::KeyExists(values, "audio_prefer_stereo"))
props.m_audioPrefStereo = values["audio_prefer_stereo"] == "true";
if (STRING::KeyExists(values, "audio_prefer_type"))
props.m_audioPrefType = STRING::Trim(values["audio_prefer_type"]);
if (STRING::KeyExists(values, "subtitles_langcode_default"))
props.m_subtitleLangDefault = STRING::Trim(values["subtitles_langcode_default"]);
}
else if (prop.first == PROP_PLAY_TIMESHIFT_BUFFER)
{
props.m_playTimeshiftBuffer = STRING::CompareNoCase(prop.second, "true");
}
else if (prop.first == PROP_LIVE_DELAY)
{
props.m_liveDelay = STRING::ToUint64(prop.second);
}
else if (prop.first == PROP_PRE_INIT_DATA)
{
props.m_drmPreInitData = prop.second;
logPropValRedacted = true;
}
else if (prop.first == PROP_STREAM_SELECTION_TYPE)
{
props.m_streamSelectionType = prop.second;
}
else if (prop.first == PROP_CHOOSER_BANDWIDTH_MAX)
{
props.m_chooserProps.m_bandwidthMax = static_cast<uint32_t>(std::stoi(prop.second));
}
else if (prop.first == PROP_CHOOSER_RES_MAX)
{
std::pair<int, int> res;
if (SETTINGS::ParseResolutionLimit(prop.second, res))
props.m_chooserProps.m_resolutionMax = res;
else
LOG::Log(LOGERROR, "Resolution not valid on \"%s\" property.", prop.first.c_str());
}
else if (prop.first == PROP_CHOOSER_RES_SECURE_MAX)
{
std::pair<int, int> res;
if (SETTINGS::ParseResolutionLimit(prop.second, res))
props.m_chooserProps.m_resolutionSecureMax = res;
else
LOG::Log(LOGERROR, "Resolution not valid on \"%s\" property.", prop.first.c_str());
}
else
{
LOG::Log(LOGWARNING, "Property found \"%s\" is not supported", prop.first.c_str());
continue;
}
LOG::Log(LOGDEBUG, "Property found \"%s\" value: %s", prop.first.c_str(),
logPropValRedacted ? "[redacted]" : prop.second.c_str());
}
return props;
}