正在显示
1 个修改的文件
包含
64 行增加
和
63 行删除
@@ -60,9 +60,9 @@ SrsHttpHooks::~SrsHttpHooks() | @@ -60,9 +60,9 @@ SrsHttpHooks::~SrsHttpHooks() | ||
60 | int SrsHttpHooks::on_connect(string url, SrsRequest* req) | 60 | int SrsHttpHooks::on_connect(string url, SrsRequest* req) |
61 | { | 61 | { |
62 | int ret = ERROR_SUCCESS; | 62 | int ret = ERROR_SUCCESS; |
63 | - | 63 | + |
64 | int client_id = _srs_context->get_id(); | 64 | int client_id = _srs_context->get_id(); |
65 | - | 65 | + |
66 | std::stringstream ss; | 66 | std::stringstream ss; |
67 | ss << SRS_JOBJECT_START | 67 | ss << SRS_JOBJECT_START |
68 | << SRS_JFIELD_STR("action", "on_connect") << SRS_JFIELD_CONT | 68 | << SRS_JFIELD_STR("action", "on_connect") << SRS_JFIELD_CONT |
@@ -73,7 +73,7 @@ int SrsHttpHooks::on_connect(string url, SrsRequest* req) | @@ -73,7 +73,7 @@ int SrsHttpHooks::on_connect(string url, SrsRequest* req) | ||
73 | << SRS_JFIELD_STR("tcUrl", req->tcUrl) << SRS_JFIELD_CONT | 73 | << SRS_JFIELD_STR("tcUrl", req->tcUrl) << SRS_JFIELD_CONT |
74 | << SRS_JFIELD_STR("pageUrl", req->pageUrl) | 74 | << SRS_JFIELD_STR("pageUrl", req->pageUrl) |
75 | << SRS_JOBJECT_END; | 75 | << SRS_JOBJECT_END; |
76 | - | 76 | + |
77 | std::string data = ss.str(); | 77 | std::string data = ss.str(); |
78 | std::string res; | 78 | std::string res; |
79 | int status_code; | 79 | int status_code; |
@@ -83,20 +83,20 @@ int SrsHttpHooks::on_connect(string url, SrsRequest* req) | @@ -83,20 +83,20 @@ int SrsHttpHooks::on_connect(string url, SrsRequest* req) | ||
83 | client_id, url.c_str(), data.c_str(), res.c_str(), status_code, ret); | 83 | client_id, url.c_str(), data.c_str(), res.c_str(), status_code, ret); |
84 | return ret; | 84 | return ret; |
85 | } | 85 | } |
86 | - | 86 | + |
87 | srs_trace("http hook on_connect success. " | 87 | srs_trace("http hook on_connect success. " |
88 | "client_id=%d, url=%s, request=%s, response=%s, ret=%d", | 88 | "client_id=%d, url=%s, request=%s, response=%s, ret=%d", |
89 | client_id, url.c_str(), data.c_str(), res.c_str(), ret); | 89 | client_id, url.c_str(), data.c_str(), res.c_str(), ret); |
90 | - | 90 | + |
91 | return ret; | 91 | return ret; |
92 | } | 92 | } |
93 | 93 | ||
94 | void SrsHttpHooks::on_close(string url, SrsRequest* req, int64_t send_bytes, int64_t recv_bytes) | 94 | void SrsHttpHooks::on_close(string url, SrsRequest* req, int64_t send_bytes, int64_t recv_bytes) |
95 | { | 95 | { |
96 | int ret = ERROR_SUCCESS; | 96 | int ret = ERROR_SUCCESS; |
97 | - | 97 | + |
98 | int client_id = _srs_context->get_id(); | 98 | int client_id = _srs_context->get_id(); |
99 | - | 99 | + |
100 | std::stringstream ss; | 100 | std::stringstream ss; |
101 | ss << SRS_JOBJECT_START | 101 | ss << SRS_JOBJECT_START |
102 | << SRS_JFIELD_STR("action", "on_close") << SRS_JFIELD_CONT | 102 | << SRS_JFIELD_STR("action", "on_close") << SRS_JFIELD_CONT |
@@ -107,7 +107,7 @@ void SrsHttpHooks::on_close(string url, SrsRequest* req, int64_t send_bytes, int | @@ -107,7 +107,7 @@ void SrsHttpHooks::on_close(string url, SrsRequest* req, int64_t send_bytes, int | ||
107 | << SRS_JFIELD_ORG("recv_bytes", recv_bytes) << SRS_JFIELD_CONT | 107 | << SRS_JFIELD_ORG("recv_bytes", recv_bytes) << SRS_JFIELD_CONT |
108 | << SRS_JFIELD_STR("app", req->app) | 108 | << SRS_JFIELD_STR("app", req->app) |
109 | << SRS_JOBJECT_END; | 109 | << SRS_JOBJECT_END; |
110 | - | 110 | + |
111 | std::string data = ss.str(); | 111 | std::string data = ss.str(); |
112 | std::string res; | 112 | std::string res; |
113 | int status_code; | 113 | int status_code; |
@@ -117,20 +117,20 @@ void SrsHttpHooks::on_close(string url, SrsRequest* req, int64_t send_bytes, int | @@ -117,20 +117,20 @@ void SrsHttpHooks::on_close(string url, SrsRequest* req, int64_t send_bytes, int | ||
117 | client_id, url.c_str(), data.c_str(), res.c_str(), status_code, ret); | 117 | client_id, url.c_str(), data.c_str(), res.c_str(), status_code, ret); |
118 | return; | 118 | return; |
119 | } | 119 | } |
120 | - | 120 | + |
121 | srs_trace("http hook on_close success. " | 121 | srs_trace("http hook on_close success. " |
122 | "client_id=%d, url=%s, request=%s, response=%s, ret=%d", | 122 | "client_id=%d, url=%s, request=%s, response=%s, ret=%d", |
123 | client_id, url.c_str(), data.c_str(), res.c_str(), ret); | 123 | client_id, url.c_str(), data.c_str(), res.c_str(), ret); |
124 | - | 124 | + |
125 | return; | 125 | return; |
126 | } | 126 | } |
127 | 127 | ||
128 | int SrsHttpHooks::on_publish(string url, SrsRequest* req) | 128 | int SrsHttpHooks::on_publish(string url, SrsRequest* req) |
129 | { | 129 | { |
130 | int ret = ERROR_SUCCESS; | 130 | int ret = ERROR_SUCCESS; |
131 | - | 131 | + |
132 | int client_id = _srs_context->get_id(); | 132 | int client_id = _srs_context->get_id(); |
133 | - | 133 | + |
134 | std::stringstream ss; | 134 | std::stringstream ss; |
135 | ss << SRS_JOBJECT_START | 135 | ss << SRS_JOBJECT_START |
136 | << SRS_JFIELD_STR("action", "on_publish") << SRS_JFIELD_CONT | 136 | << SRS_JFIELD_STR("action", "on_publish") << SRS_JFIELD_CONT |
@@ -138,9 +138,10 @@ int SrsHttpHooks::on_publish(string url, SrsRequest* req) | @@ -138,9 +138,10 @@ int SrsHttpHooks::on_publish(string url, SrsRequest* req) | ||
138 | << SRS_JFIELD_STR("ip", req->ip) << SRS_JFIELD_CONT | 138 | << SRS_JFIELD_STR("ip", req->ip) << SRS_JFIELD_CONT |
139 | << SRS_JFIELD_STR("vhost", req->vhost) << SRS_JFIELD_CONT | 139 | << SRS_JFIELD_STR("vhost", req->vhost) << SRS_JFIELD_CONT |
140 | << SRS_JFIELD_STR("app", req->app) << SRS_JFIELD_CONT | 140 | << SRS_JFIELD_STR("app", req->app) << SRS_JFIELD_CONT |
141 | + << SRS_JFIELD_STR("tcUrl", req->tcUrl) << SRS_JFIELD_CONT // Add tcUrl for auth publish rtmp stream client | ||
141 | << SRS_JFIELD_STR("stream", req->stream) | 142 | << SRS_JFIELD_STR("stream", req->stream) |
142 | << SRS_JOBJECT_END; | 143 | << SRS_JOBJECT_END; |
143 | - | 144 | + |
144 | std::string data = ss.str(); | 145 | std::string data = ss.str(); |
145 | std::string res; | 146 | std::string res; |
146 | int status_code; | 147 | int status_code; |
@@ -150,20 +151,20 @@ int SrsHttpHooks::on_publish(string url, SrsRequest* req) | @@ -150,20 +151,20 @@ int SrsHttpHooks::on_publish(string url, SrsRequest* req) | ||
150 | client_id, url.c_str(), data.c_str(), res.c_str(), status_code, ret); | 151 | client_id, url.c_str(), data.c_str(), res.c_str(), status_code, ret); |
151 | return ret; | 152 | return ret; |
152 | } | 153 | } |
153 | - | 154 | + |
154 | srs_trace("http hook on_publish success. " | 155 | srs_trace("http hook on_publish success. " |
155 | "client_id=%d, url=%s, request=%s, response=%s, ret=%d", | 156 | "client_id=%d, url=%s, request=%s, response=%s, ret=%d", |
156 | client_id, url.c_str(), data.c_str(), res.c_str(), ret); | 157 | client_id, url.c_str(), data.c_str(), res.c_str(), ret); |
157 | - | 158 | + |
158 | return ret; | 159 | return ret; |
159 | } | 160 | } |
160 | 161 | ||
161 | void SrsHttpHooks::on_unpublish(string url, SrsRequest* req) | 162 | void SrsHttpHooks::on_unpublish(string url, SrsRequest* req) |
162 | { | 163 | { |
163 | int ret = ERROR_SUCCESS; | 164 | int ret = ERROR_SUCCESS; |
164 | - | 165 | + |
165 | int client_id = _srs_context->get_id(); | 166 | int client_id = _srs_context->get_id(); |
166 | - | 167 | + |
167 | std::stringstream ss; | 168 | std::stringstream ss; |
168 | ss << SRS_JOBJECT_START | 169 | ss << SRS_JOBJECT_START |
169 | << SRS_JFIELD_STR("action", "on_unpublish") << SRS_JFIELD_CONT | 170 | << SRS_JFIELD_STR("action", "on_unpublish") << SRS_JFIELD_CONT |
@@ -173,7 +174,7 @@ void SrsHttpHooks::on_unpublish(string url, SrsRequest* req) | @@ -173,7 +174,7 @@ void SrsHttpHooks::on_unpublish(string url, SrsRequest* req) | ||
173 | << SRS_JFIELD_STR("app", req->app) << SRS_JFIELD_CONT | 174 | << SRS_JFIELD_STR("app", req->app) << SRS_JFIELD_CONT |
174 | << SRS_JFIELD_STR("stream", req->stream) | 175 | << SRS_JFIELD_STR("stream", req->stream) |
175 | << SRS_JOBJECT_END; | 176 | << SRS_JOBJECT_END; |
176 | - | 177 | + |
177 | std::string data = ss.str(); | 178 | std::string data = ss.str(); |
178 | std::string res; | 179 | std::string res; |
179 | int status_code; | 180 | int status_code; |
@@ -183,20 +184,20 @@ void SrsHttpHooks::on_unpublish(string url, SrsRequest* req) | @@ -183,20 +184,20 @@ void SrsHttpHooks::on_unpublish(string url, SrsRequest* req) | ||
183 | client_id, url.c_str(), data.c_str(), res.c_str(), status_code, ret); | 184 | client_id, url.c_str(), data.c_str(), res.c_str(), status_code, ret); |
184 | return; | 185 | return; |
185 | } | 186 | } |
186 | - | 187 | + |
187 | srs_trace("http hook on_unpublish success. " | 188 | srs_trace("http hook on_unpublish success. " |
188 | "client_id=%d, url=%s, request=%s, response=%s, ret=%d", | 189 | "client_id=%d, url=%s, request=%s, response=%s, ret=%d", |
189 | client_id, url.c_str(), data.c_str(), res.c_str(), ret); | 190 | client_id, url.c_str(), data.c_str(), res.c_str(), ret); |
190 | - | 191 | + |
191 | return; | 192 | return; |
192 | } | 193 | } |
193 | 194 | ||
194 | int SrsHttpHooks::on_play(string url, SrsRequest* req) | 195 | int SrsHttpHooks::on_play(string url, SrsRequest* req) |
195 | { | 196 | { |
196 | int ret = ERROR_SUCCESS; | 197 | int ret = ERROR_SUCCESS; |
197 | - | 198 | + |
198 | int client_id = _srs_context->get_id(); | 199 | int client_id = _srs_context->get_id(); |
199 | - | 200 | + |
200 | std::stringstream ss; | 201 | std::stringstream ss; |
201 | ss << SRS_JOBJECT_START | 202 | ss << SRS_JOBJECT_START |
202 | << SRS_JFIELD_STR("action", "on_play") << SRS_JFIELD_CONT | 203 | << SRS_JFIELD_STR("action", "on_play") << SRS_JFIELD_CONT |
@@ -207,7 +208,7 @@ int SrsHttpHooks::on_play(string url, SrsRequest* req) | @@ -207,7 +208,7 @@ int SrsHttpHooks::on_play(string url, SrsRequest* req) | ||
207 | << SRS_JFIELD_STR("stream", req->stream) << SRS_JFIELD_CONT | 208 | << SRS_JFIELD_STR("stream", req->stream) << SRS_JFIELD_CONT |
208 | << SRS_JFIELD_STR("pageUrl", req->pageUrl) | 209 | << SRS_JFIELD_STR("pageUrl", req->pageUrl) |
209 | << SRS_JOBJECT_END; | 210 | << SRS_JOBJECT_END; |
210 | - | 211 | + |
211 | std::string data = ss.str(); | 212 | std::string data = ss.str(); |
212 | std::string res; | 213 | std::string res; |
213 | int status_code; | 214 | int status_code; |
@@ -217,20 +218,20 @@ int SrsHttpHooks::on_play(string url, SrsRequest* req) | @@ -217,20 +218,20 @@ int SrsHttpHooks::on_play(string url, SrsRequest* req) | ||
217 | client_id, url.c_str(), data.c_str(), res.c_str(), status_code, ret); | 218 | client_id, url.c_str(), data.c_str(), res.c_str(), status_code, ret); |
218 | return ret; | 219 | return ret; |
219 | } | 220 | } |
220 | - | 221 | + |
221 | srs_trace("http hook on_play success. " | 222 | srs_trace("http hook on_play success. " |
222 | "client_id=%d, url=%s, request=%s, response=%s, ret=%d", | 223 | "client_id=%d, url=%s, request=%s, response=%s, ret=%d", |
223 | client_id, url.c_str(), data.c_str(), res.c_str(), ret); | 224 | client_id, url.c_str(), data.c_str(), res.c_str(), ret); |
224 | - | 225 | + |
225 | return ret; | 226 | return ret; |
226 | } | 227 | } |
227 | 228 | ||
228 | void SrsHttpHooks::on_stop(string url, SrsRequest* req) | 229 | void SrsHttpHooks::on_stop(string url, SrsRequest* req) |
229 | { | 230 | { |
230 | int ret = ERROR_SUCCESS; | 231 | int ret = ERROR_SUCCESS; |
231 | - | 232 | + |
232 | int client_id = _srs_context->get_id(); | 233 | int client_id = _srs_context->get_id(); |
233 | - | 234 | + |
234 | std::stringstream ss; | 235 | std::stringstream ss; |
235 | ss << SRS_JOBJECT_START | 236 | ss << SRS_JOBJECT_START |
236 | << SRS_JFIELD_STR("action", "on_stop") << SRS_JFIELD_CONT | 237 | << SRS_JFIELD_STR("action", "on_stop") << SRS_JFIELD_CONT |
@@ -240,7 +241,7 @@ void SrsHttpHooks::on_stop(string url, SrsRequest* req) | @@ -240,7 +241,7 @@ void SrsHttpHooks::on_stop(string url, SrsRequest* req) | ||
240 | << SRS_JFIELD_STR("app", req->app) << SRS_JFIELD_CONT | 241 | << SRS_JFIELD_STR("app", req->app) << SRS_JFIELD_CONT |
241 | << SRS_JFIELD_STR("stream", req->stream) | 242 | << SRS_JFIELD_STR("stream", req->stream) |
242 | << SRS_JOBJECT_END; | 243 | << SRS_JOBJECT_END; |
243 | - | 244 | + |
244 | std::string data = ss.str(); | 245 | std::string data = ss.str(); |
245 | std::string res; | 246 | std::string res; |
246 | int status_code; | 247 | int status_code; |
@@ -250,21 +251,21 @@ void SrsHttpHooks::on_stop(string url, SrsRequest* req) | @@ -250,21 +251,21 @@ void SrsHttpHooks::on_stop(string url, SrsRequest* req) | ||
250 | client_id, url.c_str(), data.c_str(), res.c_str(), status_code, ret); | 251 | client_id, url.c_str(), data.c_str(), res.c_str(), status_code, ret); |
251 | return; | 252 | return; |
252 | } | 253 | } |
253 | - | 254 | + |
254 | srs_trace("http hook on_stop success. " | 255 | srs_trace("http hook on_stop success. " |
255 | "client_id=%d, url=%s, request=%s, response=%s, ret=%d", | 256 | "client_id=%d, url=%s, request=%s, response=%s, ret=%d", |
256 | client_id, url.c_str(), data.c_str(), res.c_str(), ret); | 257 | client_id, url.c_str(), data.c_str(), res.c_str(), ret); |
257 | - | 258 | + |
258 | return; | 259 | return; |
259 | } | 260 | } |
260 | 261 | ||
261 | int SrsHttpHooks::on_dvr(int cid, string url, SrsRequest* req, string file) | 262 | int SrsHttpHooks::on_dvr(int cid, string url, SrsRequest* req, string file) |
262 | { | 263 | { |
263 | int ret = ERROR_SUCCESS; | 264 | int ret = ERROR_SUCCESS; |
264 | - | 265 | + |
265 | int client_id = cid; | 266 | int client_id = cid; |
266 | std::string cwd = _srs_config->cwd(); | 267 | std::string cwd = _srs_config->cwd(); |
267 | - | 268 | + |
268 | std::stringstream ss; | 269 | std::stringstream ss; |
269 | ss << SRS_JOBJECT_START | 270 | ss << SRS_JOBJECT_START |
270 | << SRS_JFIELD_STR("action", "on_dvr") << SRS_JFIELD_CONT | 271 | << SRS_JFIELD_STR("action", "on_dvr") << SRS_JFIELD_CONT |
@@ -276,7 +277,7 @@ int SrsHttpHooks::on_dvr(int cid, string url, SrsRequest* req, string file) | @@ -276,7 +277,7 @@ int SrsHttpHooks::on_dvr(int cid, string url, SrsRequest* req, string file) | ||
276 | << SRS_JFIELD_STR("cwd", cwd) << SRS_JFIELD_CONT | 277 | << SRS_JFIELD_STR("cwd", cwd) << SRS_JFIELD_CONT |
277 | << SRS_JFIELD_STR("file", file) | 278 | << SRS_JFIELD_STR("file", file) |
278 | << SRS_JOBJECT_END; | 279 | << SRS_JOBJECT_END; |
279 | - | 280 | + |
280 | std::string data = ss.str(); | 281 | std::string data = ss.str(); |
281 | std::string res; | 282 | std::string res; |
282 | int status_code; | 283 | int status_code; |
@@ -286,27 +287,27 @@ int SrsHttpHooks::on_dvr(int cid, string url, SrsRequest* req, string file) | @@ -286,27 +287,27 @@ int SrsHttpHooks::on_dvr(int cid, string url, SrsRequest* req, string file) | ||
286 | client_id, url.c_str(), data.c_str(), res.c_str(), status_code, ret); | 287 | client_id, url.c_str(), data.c_str(), res.c_str(), status_code, ret); |
287 | return ret; | 288 | return ret; |
288 | } | 289 | } |
289 | - | 290 | + |
290 | srs_trace("http hook on_dvr success. " | 291 | srs_trace("http hook on_dvr success. " |
291 | "client_id=%d, url=%s, request=%s, response=%s, ret=%d", | 292 | "client_id=%d, url=%s, request=%s, response=%s, ret=%d", |
292 | client_id, url.c_str(), data.c_str(), res.c_str(), ret); | 293 | client_id, url.c_str(), data.c_str(), res.c_str(), ret); |
293 | - | 294 | + |
294 | return ret; | 295 | return ret; |
295 | } | 296 | } |
296 | 297 | ||
297 | int SrsHttpHooks::on_hls(int cid, string url, SrsRequest* req, string file, string ts_url, string m3u8, string m3u8_url, int sn, double duration) | 298 | int SrsHttpHooks::on_hls(int cid, string url, SrsRequest* req, string file, string ts_url, string m3u8, string m3u8_url, int sn, double duration) |
298 | { | 299 | { |
299 | int ret = ERROR_SUCCESS; | 300 | int ret = ERROR_SUCCESS; |
300 | - | 301 | + |
301 | int client_id = cid; | 302 | int client_id = cid; |
302 | std::string cwd = _srs_config->cwd(); | 303 | std::string cwd = _srs_config->cwd(); |
303 | - | 304 | + |
304 | // the ts_url is under the same dir of m3u8_url. | 305 | // the ts_url is under the same dir of m3u8_url. |
305 | string prefix = srs_path_dirname(m3u8_url); | 306 | string prefix = srs_path_dirname(m3u8_url); |
306 | if (!prefix.empty() && !srs_string_is_http(ts_url)) { | 307 | if (!prefix.empty() && !srs_string_is_http(ts_url)) { |
307 | ts_url = prefix + "/" + ts_url; | 308 | ts_url = prefix + "/" + ts_url; |
308 | } | 309 | } |
309 | - | 310 | + |
310 | std::stringstream ss; | 311 | std::stringstream ss; |
311 | ss << SRS_JOBJECT_START | 312 | ss << SRS_JOBJECT_START |
312 | << SRS_JFIELD_STR("action", "on_hls") << SRS_JFIELD_CONT | 313 | << SRS_JFIELD_STR("action", "on_hls") << SRS_JFIELD_CONT |
@@ -323,7 +324,7 @@ int SrsHttpHooks::on_hls(int cid, string url, SrsRequest* req, string file, stri | @@ -323,7 +324,7 @@ int SrsHttpHooks::on_hls(int cid, string url, SrsRequest* req, string file, stri | ||
323 | << SRS_JFIELD_STR("m3u8_url", m3u8_url) << SRS_JFIELD_CONT | 324 | << SRS_JFIELD_STR("m3u8_url", m3u8_url) << SRS_JFIELD_CONT |
324 | << SRS_JFIELD_ORG("seq_no", sn) | 325 | << SRS_JFIELD_ORG("seq_no", sn) |
325 | << SRS_JOBJECT_END; | 326 | << SRS_JOBJECT_END; |
326 | - | 327 | + |
327 | std::string data = ss.str(); | 328 | std::string data = ss.str(); |
328 | std::string res; | 329 | std::string res; |
329 | int status_code; | 330 | int status_code; |
@@ -333,42 +334,42 @@ int SrsHttpHooks::on_hls(int cid, string url, SrsRequest* req, string file, stri | @@ -333,42 +334,42 @@ int SrsHttpHooks::on_hls(int cid, string url, SrsRequest* req, string file, stri | ||
333 | client_id, url.c_str(), data.c_str(), res.c_str(), status_code, ret); | 334 | client_id, url.c_str(), data.c_str(), res.c_str(), status_code, ret); |
334 | return ret; | 335 | return ret; |
335 | } | 336 | } |
336 | - | 337 | + |
337 | srs_trace("http hook on_hls success. " | 338 | srs_trace("http hook on_hls success. " |
338 | "client_id=%d, url=%s, request=%s, response=%s, ret=%d", | 339 | "client_id=%d, url=%s, request=%s, response=%s, ret=%d", |
339 | client_id, url.c_str(), data.c_str(), res.c_str(), ret); | 340 | client_id, url.c_str(), data.c_str(), res.c_str(), ret); |
340 | - | 341 | + |
341 | return ret; | 342 | return ret; |
342 | } | 343 | } |
343 | 344 | ||
344 | int SrsHttpHooks::on_hls_notify(int cid, std::string url, SrsRequest* req, std::string ts_url, int nb_notify) | 345 | int SrsHttpHooks::on_hls_notify(int cid, std::string url, SrsRequest* req, std::string ts_url, int nb_notify) |
345 | { | 346 | { |
346 | int ret = ERROR_SUCCESS; | 347 | int ret = ERROR_SUCCESS; |
347 | - | 348 | + |
348 | int client_id = cid; | 349 | int client_id = cid; |
349 | std::string cwd = _srs_config->cwd(); | 350 | std::string cwd = _srs_config->cwd(); |
350 | - | 351 | + |
351 | if (srs_string_is_http(ts_url)) { | 352 | if (srs_string_is_http(ts_url)) { |
352 | url = ts_url; | 353 | url = ts_url; |
353 | } | 354 | } |
354 | - | 355 | + |
355 | url = srs_string_replace(url, "[app]", req->app); | 356 | url = srs_string_replace(url, "[app]", req->app); |
356 | url = srs_string_replace(url, "[stream]", req->stream); | 357 | url = srs_string_replace(url, "[stream]", req->stream); |
357 | url = srs_string_replace(url, "[ts_url]", ts_url); | 358 | url = srs_string_replace(url, "[ts_url]", ts_url); |
358 | - | 359 | + |
359 | int64_t starttime = srs_update_system_time_ms(); | 360 | int64_t starttime = srs_update_system_time_ms(); |
360 | - | 361 | + |
361 | SrsHttpUri uri; | 362 | SrsHttpUri uri; |
362 | if ((ret = uri.initialize(url)) != ERROR_SUCCESS) { | 363 | if ((ret = uri.initialize(url)) != ERROR_SUCCESS) { |
363 | srs_error("http: post failed. url=%s, ret=%d", url.c_str(), ret); | 364 | srs_error("http: post failed. url=%s, ret=%d", url.c_str(), ret); |
364 | return ret; | 365 | return ret; |
365 | } | 366 | } |
366 | - | 367 | + |
367 | SrsHttpClient http; | 368 | SrsHttpClient http; |
368 | if ((ret = http.initialize(uri.get_host(), uri.get_port(), SRS_HLS_NOTIFY_TIMEOUT_US)) != ERROR_SUCCESS) { | 369 | if ((ret = http.initialize(uri.get_host(), uri.get_port(), SRS_HLS_NOTIFY_TIMEOUT_US)) != ERROR_SUCCESS) { |
369 | return ret; | 370 | return ret; |
370 | } | 371 | } |
371 | - | 372 | + |
372 | std::string path = uri.get_query(); | 373 | std::string path = uri.get_query(); |
373 | if (path.empty()) { | 374 | if (path.empty()) { |
374 | path = uri.get_path(); | 375 | path = uri.get_path(); |
@@ -378,17 +379,17 @@ int SrsHttpHooks::on_hls_notify(int cid, std::string url, SrsRequest* req, std:: | @@ -378,17 +379,17 @@ int SrsHttpHooks::on_hls_notify(int cid, std::string url, SrsRequest* req, std:: | ||
378 | path += uri.get_query(); | 379 | path += uri.get_query(); |
379 | } | 380 | } |
380 | srs_warn("GET %s", path.c_str()); | 381 | srs_warn("GET %s", path.c_str()); |
381 | - | 382 | + |
382 | ISrsHttpMessage* msg = NULL; | 383 | ISrsHttpMessage* msg = NULL; |
383 | if ((ret = http.get(path.c_str(), "", &msg)) != ERROR_SUCCESS) { | 384 | if ((ret = http.get(path.c_str(), "", &msg)) != ERROR_SUCCESS) { |
384 | return ret; | 385 | return ret; |
385 | } | 386 | } |
386 | SrsAutoFree(ISrsHttpMessage, msg); | 387 | SrsAutoFree(ISrsHttpMessage, msg); |
387 | - | 388 | + |
388 | int nb_buf = srs_min(nb_notify, SRS_HTTP_READ_BUFFER); | 389 | int nb_buf = srs_min(nb_notify, SRS_HTTP_READ_BUFFER); |
389 | char* buf = new char[nb_buf]; | 390 | char* buf = new char[nb_buf]; |
390 | SrsAutoFreeA(char, buf); | 391 | SrsAutoFreeA(char, buf); |
391 | - | 392 | + |
392 | int nb_read = 0; | 393 | int nb_read = 0; |
393 | ISrsHttpResponseReader* br = msg->body_reader(); | 394 | ISrsHttpResponseReader* br = msg->body_reader(); |
394 | while (nb_read < nb_notify && !br->eof()) { | 395 | while (nb_read < nb_notify && !br->eof()) { |
@@ -398,43 +399,43 @@ int SrsHttpHooks::on_hls_notify(int cid, std::string url, SrsRequest* req, std:: | @@ -398,43 +399,43 @@ int SrsHttpHooks::on_hls_notify(int cid, std::string url, SrsRequest* req, std:: | ||
398 | } | 399 | } |
399 | nb_read += nb_bytes; | 400 | nb_read += nb_bytes; |
400 | } | 401 | } |
401 | - | 402 | + |
402 | int spenttime = (int)(srs_update_system_time_ms() - starttime); | 403 | int spenttime = (int)(srs_update_system_time_ms() - starttime); |
403 | srs_trace("http hook on_hls_notify success. client_id=%d, url=%s, code=%d, spent=%dms, read=%dB, ret=%d", | 404 | srs_trace("http hook on_hls_notify success. client_id=%d, url=%s, code=%d, spent=%dms, read=%dB, ret=%d", |
404 | client_id, url.c_str(), msg->status_code(), spenttime, nb_read, ret); | 405 | client_id, url.c_str(), msg->status_code(), spenttime, nb_read, ret); |
405 | - | 406 | + |
406 | // ignore any error for on_hls_notify. | 407 | // ignore any error for on_hls_notify. |
407 | ret = ERROR_SUCCESS; | 408 | ret = ERROR_SUCCESS; |
408 | - | 409 | + |
409 | return ret; | 410 | return ret; |
410 | } | 411 | } |
411 | 412 | ||
412 | int SrsHttpHooks::do_post(std::string url, std::string req, int& code, string& res) | 413 | int SrsHttpHooks::do_post(std::string url, std::string req, int& code, string& res) |
413 | { | 414 | { |
414 | int ret = ERROR_SUCCESS; | 415 | int ret = ERROR_SUCCESS; |
415 | - | 416 | + |
416 | SrsHttpUri uri; | 417 | SrsHttpUri uri; |
417 | if ((ret = uri.initialize(url)) != ERROR_SUCCESS) { | 418 | if ((ret = uri.initialize(url)) != ERROR_SUCCESS) { |
418 | srs_error("http: post failed. url=%s, ret=%d", url.c_str(), ret); | 419 | srs_error("http: post failed. url=%s, ret=%d", url.c_str(), ret); |
419 | return ret; | 420 | return ret; |
420 | } | 421 | } |
421 | - | 422 | + |
422 | SrsHttpClient http; | 423 | SrsHttpClient http; |
423 | if ((ret = http.initialize(uri.get_host(), uri.get_port())) != ERROR_SUCCESS) { | 424 | if ((ret = http.initialize(uri.get_host(), uri.get_port())) != ERROR_SUCCESS) { |
424 | return ret; | 425 | return ret; |
425 | } | 426 | } |
426 | - | 427 | + |
427 | ISrsHttpMessage* msg = NULL; | 428 | ISrsHttpMessage* msg = NULL; |
428 | if ((ret = http.post(uri.get_path(), req, &msg)) != ERROR_SUCCESS) { | 429 | if ((ret = http.post(uri.get_path(), req, &msg)) != ERROR_SUCCESS) { |
429 | return ret; | 430 | return ret; |
430 | } | 431 | } |
431 | SrsAutoFree(ISrsHttpMessage, msg); | 432 | SrsAutoFree(ISrsHttpMessage, msg); |
432 | - | 433 | + |
433 | code = msg->status_code(); | 434 | code = msg->status_code(); |
434 | if ((ret = msg->body_read_all(res)) != ERROR_SUCCESS) { | 435 | if ((ret = msg->body_read_all(res)) != ERROR_SUCCESS) { |
435 | return ret; | 436 | return ret; |
436 | } | 437 | } |
437 | - | 438 | + |
438 | // ensure the http status is ok. | 439 | // ensure the http status is ok. |
439 | // https://github.com/ossrs/srs/issues/158 | 440 | // https://github.com/ossrs/srs/issues/158 |
440 | if (code != SRS_CONSTS_HTTP_OK) { | 441 | if (code != SRS_CONSTS_HTTP_OK) { |
@@ -442,14 +443,14 @@ int SrsHttpHooks::do_post(std::string url, std::string req, int& code, string& r | @@ -442,14 +443,14 @@ int SrsHttpHooks::do_post(std::string url, std::string req, int& code, string& r | ||
442 | srs_error("invalid response status=%d. ret=%d", code, ret); | 443 | srs_error("invalid response status=%d. ret=%d", code, ret); |
443 | return ret; | 444 | return ret; |
444 | } | 445 | } |
445 | - | 446 | + |
446 | // should never be empty. | 447 | // should never be empty. |
447 | if (res.empty()) { | 448 | if (res.empty()) { |
448 | ret = ERROR_HTTP_DATA_INVALID; | 449 | ret = ERROR_HTTP_DATA_INVALID; |
449 | srs_error("invalid empty response. ret=%d", ret); | 450 | srs_error("invalid empty response. ret=%d", ret); |
450 | return ret; | 451 | return ret; |
451 | } | 452 | } |
452 | - | 453 | + |
453 | // parse string res to json. | 454 | // parse string res to json. |
454 | SrsJsonAny* info = SrsJsonAny::loads((char*)res.c_str()); | 455 | SrsJsonAny* info = SrsJsonAny::loads((char*)res.c_str()); |
455 | if (!info) { | 456 | if (!info) { |
@@ -458,7 +459,7 @@ int SrsHttpHooks::do_post(std::string url, std::string req, int& code, string& r | @@ -458,7 +459,7 @@ int SrsHttpHooks::do_post(std::string url, std::string req, int& code, string& r | ||
458 | return ret; | 459 | return ret; |
459 | } | 460 | } |
460 | SrsAutoFree(SrsJsonAny, info); | 461 | SrsAutoFree(SrsJsonAny, info); |
461 | - | 462 | + |
462 | // response error code in string. | 463 | // response error code in string. |
463 | if (!info->is_object()) { | 464 | if (!info->is_object()) { |
464 | if (res != SRS_HTTP_RESPONSE_OK) { | 465 | if (res != SRS_HTTP_RESPONSE_OK) { |
@@ -468,7 +469,7 @@ int SrsHttpHooks::do_post(std::string url, std::string req, int& code, string& r | @@ -468,7 +469,7 @@ int SrsHttpHooks::do_post(std::string url, std::string req, int& code, string& r | ||
468 | } | 469 | } |
469 | return ret; | 470 | return ret; |
470 | } | 471 | } |
471 | - | 472 | + |
472 | // response standard object, format in json: {"code": 0, "data": ""} | 473 | // response standard object, format in json: {"code": 0, "data": ""} |
473 | SrsJsonObject* res_info = info->to_object(); | 474 | SrsJsonObject* res_info = info->to_object(); |
474 | SrsJsonAny* res_code = NULL; | 475 | SrsJsonAny* res_code = NULL; |
-
请 注册 或 登录 后发表评论