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