-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathr_dash2ts_debug.cpp
189 lines (145 loc) · 5.23 KB
/
r_dash2ts_debug.cpp
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
#include <unistd.h>
#include <iomanip>
#include "streamplayer.h"
#include "addonhandler.h"
#include "logger.h"
extern bool verbose;
extern bool saveonly;
extern bool use_TCP;
extern std::string headers;
std::string &Trim(std::string &, const char *const);
std::string urlEncode(const std::string& str) {
std::ostringstream encodedStream;
encodedStream << std::hex << std::uppercase << std::setfill('0');
for (char c : str) {
if (std::isalnum(c) || c == '-' || c == '_' || c == '.' || c == '~') {
encodedStream << c;
} else {
encodedStream << '%' << std::setw(2) << static_cast<unsigned int>(static_cast<unsigned char>(c));
}
}
return encodedStream.str();
}
void usage() {
printf("Usage: r_dash2ts -u url_to_manifest.mpd\n");
printf(" -a user_agent\n");
printf(" -c cookies\n");
printf(" -r referer\n");
printf(" -k path_to_kodi\n");
printf(" -p probeFfmpeg only\n");
}
int main(int argc, char *argv[]) {
std::string url;
std::string path_to_kodi;
std::string user_agent;
std::string cookies;
std::string referer;
int api_version = 0;
int loglevel = 1;
bool probeOnly = false;
verbose = true;
saveonly = true;
use_TCP = false;
int c;
while ((c = getopt(argc, argv, "u:a:c:r:k:p")) != -1) {
switch (c) {
case 'u': // URL to Manifest
url = std::string(optarg);
continue;
case 'a': // user agent
user_agent = std::string(optarg);
continue;
case 'c': // cookies
cookies = std::string(optarg);
continue;
case 'r': // referer
referer = std::string(optarg);
continue;
case 'k': // path to kodi
path_to_kodi = std::string(optarg);
continue;
case 'p': // probe only
probeOnly = true;
continue;
default:
usage();
exit(EXIT_FAILURE);
}
break;
}
if (path_to_kodi.empty()) {
// set default for VDR*ELEC
path_to_kodi = "/storage/.kodi";
}
if (url.empty() || user_agent.empty() || cookies.empty() || referer.empty()) {
usage();
exit(EXIT_FAILURE);
}
logger.set_level(spdlog::level::trace);
auto handler = new AddonHandler(path_to_kodi); // Init AddonHandler
// Load the inputstream.adaptive Library and get the API Version
api_version = handler->LoadAddon();
INFO("Found inputstream.adaptive Library, version {}", api_version);
std::string httpHeader = "Referer=" + referer + "&User-Agent=" + user_agent + "&cookie=" + urlEncode(cookies);
// kodi 22+
handler->AddProp("inputstream.adaptive.common_headers", httpHeader.c_str());
// kodi 20+
// handler->AddProp("inputstream.adaptive.stream_params", "paramname=value¶mname2=value2");
handler->AddProp("inputstream.adaptive.manifest_headers", httpHeader.c_str());
// kodi 21+
handler->AddProp("inputstream.adaptive.stream_headers", httpHeader.c_str());
// all
handler->AddProp("inputstream.adaptive.config", "{\"internal_cookies\":true}");
handler->SetResolution(1920, 1080);
bool ret = handler->OpenURL(const_cast<char *>(url.c_str()));
if (ret) {
INFO("Open URL {}");
if (probeOnly) {
// print result and exit
printf("dash2ts result:%d:%d:%d:%ld:%ld:%d,\n", handler->GetTotalTime(0, true), handler->GetTime(), handler->GetCapabilities(), handler->PositionStream(), handler->LengthStream(), handler->IsRealTimeStream() ? 1 : 0);
exit(EXIT_SUCCESS);
}
} else {
ERROR("Unable to open URL {}", url);
exit(EXIT_FAILURE);
}
auto caps = handler->GetCapabilities();
printf("Capabilities:\n");
if (caps & INPUTSTREAM_SUPPORTS_IDEMUX) {
printf (" INPUTSTREAM_SUPPORTS_IDEMUX\n");
}
if (caps & INPUTSTREAM_SUPPORTS_IPOSTIME) {
printf (" INPUTSTREAM_SUPPORTS_IPOSTIME\n");
}
if (caps & INPUTSTREAM_SUPPORTS_IDISPLAYTIME) {
printf (" INPUTSTREAM_SUPPORTS_IDISPLAYTIME\n");
}
if (caps & INPUTSTREAM_SUPPORTS_SEEK) {
printf (" INPUTSTREAM_SUPPORTS_SEEK\n");
}
if (caps & INPUTSTREAM_SUPPORTS_PAUSE) {
printf (" INPUTSTREAM_SUPPORTS_PAUSE\n");
}
if (caps & INPUTSTREAM_SUPPORTS_ITIME) {
printf (" INPUTSTREAM_SUPPORTS_ITIME\n");
}
if (caps & INPUTSTREAM_SUPPORTS_ICHAPTER) {
printf (" INPUTSTREAM_SUPPORTS_ICHAPTER\n");
}
// 3183
if (!handler->PosTime(3183 * 1000)) {
printf("PosTime to 45 minutes\n");
} else {
printf("PosTime failed\n");
}
printf ("STREAM_MSEC_TO_TIME(0) = %f\n", STREAM_MSEC_TO_TIME(0));
printf ("STREAM_MSEC_TO_TIME(45 min) = %f\n", STREAM_MSEC_TO_TIME(1000 * 60 * 45));
printf("Time: %d\n", handler->GetTime());
printf("TotalTime: %d\n", handler->GetTotalTime(0, true));
// start streaming
auto player = new StreamPlayer(0);
player->StreamPlay(handler);
delete handler;
delete player;
exit(EXIT_SUCCESS);
}