-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtranscoderremoteclient.cpp
166 lines (143 loc) · 5.17 KB
/
transcoderremoteclient.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
#include "transcoderremoteclient.h"
#include "logger.h"
TranscoderRemoteClient::TranscoderRemoteClient(std::string transcoderIp, int transcoderPort, std::string browserIp, int browserPort, std::string vdrIp, int vdrPort)
: transcoderIp(transcoderIp), transcoderPort(transcoderPort),
browserIp(browserIp), browserPort(browserPort),
vdrIp(vdrIp), vdrPort(vdrPort) {
client = new httplib::Client(transcoderIp, transcoderPort);
client->set_read_timeout(15, 0);
client->set_keep_alive(true);
}
TranscoderRemoteClient::~TranscoderRemoteClient() {
delete client;
}
std::string TranscoderRemoteClient::Probe(std::string url, std::string cookies, std::string referer, std::string userAgent, std::string postfix) {
httplib::Params params;
params.emplace("url", url);
params.emplace("cookies", cookies);
params.emplace("referer", referer);
params.emplace("userAgent", userAgent);
params.emplace("responseIp", browserIp);
params.emplace("responsePort", std::to_string(browserPort));
params.emplace("vdrIp", vdrIp);
params.emplace("vdrPort", std::to_string(vdrPort));
params.emplace("postfix", postfix);
if (auto res = client->Post("/Probe", params)) {
if (res->status != 200) {
TRACE("Http result: {}", res->status);
return "";
} else {
TRACE("Probe sent: {}", res->status);
return res->body;
}
} else {
auto err = res.error();
ERROR("Http error: {}", httplib::to_string(err));
return "";
}
}
bool TranscoderRemoteClient::StreamUrl(std::string url, std::string cookies, std::string referer, std::string userAgent, int32_t mpdStart) {
httplib::Params params;
params.emplace("url", url);
params.emplace("cookies", cookies);
params.emplace("referer", referer);
params.emplace("userAgent", userAgent);
params.emplace("responseIp", browserIp);
params.emplace("responsePort", std::to_string(browserPort));
params.emplace("vdrIp", vdrIp);
params.emplace("vdrPort", std::to_string(vdrPort));
params.emplace("mpdStart", std::to_string(mpdStart));
if (auto res = client->Post("/StreamUrl", params)) {
if (res->status != 200) {
TRACE("Http result: {}", res->status);
return false;
} else {
TRACE("StreamURl sent: {}", res->status);
}
} else {
auto err = res.error();
ERROR("Http error: {}", httplib::to_string(err));
return false;
}
return true;
}
bool TranscoderRemoteClient::Pause() {
httplib::Params params;
params.emplace("streamId", browserIp + "_" + std::to_string(browserPort));
if (auto res = client->Post("/Pause", params)) {
if (res->status != 200) {
TRACE("Http result: {}", res->status);
return false;
}
} else {
auto err = res.error();
ERROR("Http error: {}", httplib::to_string(err));
return false;
}
return true;
}
bool TranscoderRemoteClient::Seek(std::string seekTo) {
httplib::Params params;
params.emplace("streamId", browserIp + "_" + std::to_string(browserPort));
params.emplace("seekTo", seekTo);
if (auto res = client->Post("/SeekTo", params)) {
if (res->status != 200) {
TRACE("Http result: {}", res->status);
return false;
}
} else {
auto err = res.error();
ERROR("Http error: {}", httplib::to_string(err));
return false;
}
return true;
}
bool TranscoderRemoteClient::Resume(std::string position) {
httplib::Params params;
params.emplace("streamId", browserIp + "_" + std::to_string(browserPort));
params.emplace("position", position);
if (auto res = client->Post("/Resume", params)) {
if (res->status != 200) {
TRACE("Http result: {}", res->status);
return false;
}
} else {
auto err = res.error();
ERROR("Http error: {}", httplib::to_string(err));
return false;
}
return true;
}
bool TranscoderRemoteClient::Stop(std::string& reason) const {
httplib::Params params;
params.emplace("streamId", browserIp + "_" + std::to_string(browserPort));
params.emplace("reason", reason);
if (auto res = client->Post("/Stop", params)) {
if (res->status != 200) {
TRACE("Http result: {}", res->status);
return false;
}
} else {
auto err = res.error();
ERROR("Http error: {}", httplib::to_string(err));
return false;
}
return true;
}
std::string TranscoderRemoteClient::GetAudioInfo() {
httplib::Params params;
params.emplace("streamId", browserIp + "_" + std::to_string(browserPort));
if (auto res = client->Post("/AudioInfo", params)) {
if (res->status != 200) {
TRACE("Http result: {}", res->status);
return "{}";
} else {
TRACE("AudioInfo: {}", res->status);
return res->body;
}
} else {
auto err = res.error();
ERROR("Http error: {}", httplib::to_string(err));
return "{}";
}
}