正在显示
9 个修改的文件
包含
146 行增加
和
55 行删除
| @@ -212,6 +212,7 @@ int SrsEdgeIngester::ingest() | @@ -212,6 +212,7 @@ int SrsEdgeIngester::ingest() | ||
| 212 | return ret; | 212 | return ret; |
| 213 | } | 213 | } |
| 214 | 214 | ||
| 215 | +// TODO: FIXME: refine the connect_app. | ||
| 215 | int SrsEdgeIngester::connect_app(string ep_server, string ep_port) | 216 | int SrsEdgeIngester::connect_app(string ep_server, string ep_port) |
| 216 | { | 217 | { |
| 217 | int ret = ERROR_SUCCESS; | 218 | int ret = ERROR_SUCCESS; |
| @@ -641,6 +642,7 @@ int SrsEdgeForwarder::connect_server(string& ep_server, string& ep_port) | @@ -641,6 +642,7 @@ int SrsEdgeForwarder::connect_server(string& ep_server, string& ep_port) | ||
| 641 | return ret; | 642 | return ret; |
| 642 | } | 643 | } |
| 643 | 644 | ||
| 645 | +// TODO: FIXME: refine the connect_app. | ||
| 644 | int SrsEdgeForwarder::connect_app(string ep_server, string ep_port) | 646 | int SrsEdgeForwarder::connect_app(string ep_server, string ep_port) |
| 645 | { | 647 | { |
| 646 | int ret = ERROR_SUCCESS; | 648 | int ret = ERROR_SUCCESS; |
| @@ -28,6 +28,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -28,6 +28,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 28 | #include <netinet/in.h> | 28 | #include <netinet/in.h> |
| 29 | #include <arpa/inet.h> | 29 | #include <arpa/inet.h> |
| 30 | 30 | ||
| 31 | +using namespace std; | ||
| 32 | + | ||
| 31 | #include <srs_app_source.hpp> | 33 | #include <srs_app_source.hpp> |
| 32 | #include <srs_core_autofree.hpp> | 34 | #include <srs_core_autofree.hpp> |
| 33 | #include <srs_app_st_socket.hpp> | 35 | #include <srs_app_st_socket.hpp> |
| @@ -43,6 +45,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -43,6 +45,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 43 | #include <srs_kernel_utility.hpp> | 45 | #include <srs_kernel_utility.hpp> |
| 44 | #include <srs_protocol_msg_array.hpp> | 46 | #include <srs_protocol_msg_array.hpp> |
| 45 | #include <srs_app_utility.hpp> | 47 | #include <srs_app_utility.hpp> |
| 48 | +#include <srs_protocol_amf0.hpp> | ||
| 46 | 49 | ||
| 47 | // when error, forwarder sleep for a while and retry. | 50 | // when error, forwarder sleep for a while and retry. |
| 48 | #define SRS_FORWARDER_SLEEP_US (int64_t)(3*1000*1000LL) | 51 | #define SRS_FORWARDER_SLEEP_US (int64_t)(3*1000*1000LL) |
| @@ -51,6 +54,7 @@ SrsForwarder::SrsForwarder(SrsSource* _source) | @@ -51,6 +54,7 @@ SrsForwarder::SrsForwarder(SrsSource* _source) | ||
| 51 | { | 54 | { |
| 52 | source = _source; | 55 | source = _source; |
| 53 | 56 | ||
| 57 | + _req = NULL; | ||
| 54 | io = NULL; | 58 | io = NULL; |
| 55 | client = NULL; | 59 | client = NULL; |
| 56 | stfd = NULL; | 60 | stfd = NULL; |
| @@ -72,37 +76,34 @@ SrsForwarder::~SrsForwarder() | @@ -72,37 +76,34 @@ SrsForwarder::~SrsForwarder() | ||
| 72 | srs_freep(kbps); | 76 | srs_freep(kbps); |
| 73 | } | 77 | } |
| 74 | 78 | ||
| 79 | +int SrsForwarder::initialize(SrsRequest* req, string ep_forward) | ||
| 80 | +{ | ||
| 81 | + int ret = ERROR_SUCCESS; | ||
| 82 | + | ||
| 83 | + // it's ok to use the request object, | ||
| 84 | + // SrsSource already copy it and never delete it. | ||
| 85 | + _req = req; | ||
| 86 | + | ||
| 87 | + // the ep(endpoint) to forward to | ||
| 88 | + _ep_forward = ep_forward; | ||
| 89 | + | ||
| 90 | + return ret; | ||
| 91 | +} | ||
| 92 | + | ||
| 75 | void SrsForwarder::set_queue_size(double queue_size) | 93 | void SrsForwarder::set_queue_size(double queue_size) |
| 76 | { | 94 | { |
| 77 | queue->set_queue_size(queue_size); | 95 | queue->set_queue_size(queue_size); |
| 78 | } | 96 | } |
| 79 | 97 | ||
| 80 | -int SrsForwarder::on_publish(SrsRequest* req, std::string forward_server) | 98 | +int SrsForwarder::on_publish() |
| 81 | { | 99 | { |
| 82 | int ret = ERROR_SUCCESS; | 100 | int ret = ERROR_SUCCESS; |
| 83 | 101 | ||
| 84 | - // TODO: FIXME: directly use the req object. | ||
| 85 | - // forward app | ||
| 86 | - app = req->app; | ||
| 87 | - vhost = req->vhost; | 102 | + SrsRequest* req = _req; |
| 88 | 103 | ||
| 89 | - stream_name = req->stream; | ||
| 90 | - server = forward_server; | ||
| 91 | - std::string s_port = SRS_CONSTS_RTMP_DEFAULT_PORT; | ||
| 92 | - port = ::atoi(SRS_CONSTS_RTMP_DEFAULT_PORT); | ||
| 93 | - | ||
| 94 | - // TODO: FIXME: parse complex params | ||
| 95 | - size_t pos = forward_server.find(":"); | ||
| 96 | - if (pos != std::string::npos) { | ||
| 97 | - s_port = forward_server.substr(pos + 1); | ||
| 98 | - server = forward_server.substr(0, pos); | ||
| 99 | - } | ||
| 100 | - // discovery vhost | ||
| 101 | - std::string vhost = req->vhost; | ||
| 102 | - port = ::atoi(s_port.c_str()); | ||
| 103 | - | ||
| 104 | - // generate tcUrl | ||
| 105 | - tc_url = srs_generate_tc_url(forward_server, vhost, req->app, s_port, req->param); | 104 | + // discovery the server port and tcUrl from req and ep_forward. |
| 105 | + std::string server, port, tc_url; | ||
| 106 | + discovery_ep(server, port, tc_url); | ||
| 106 | 107 | ||
| 107 | // dead loop check | 108 | // dead loop check |
| 108 | std::string source_ep = "rtmp://"; | 109 | std::string source_ep = "rtmp://"; |
| @@ -113,15 +114,15 @@ int SrsForwarder::on_publish(SrsRequest* req, std::string forward_server) | @@ -113,15 +114,15 @@ int SrsForwarder::on_publish(SrsRequest* req, std::string forward_server) | ||
| 113 | source_ep += req->vhost; | 114 | source_ep += req->vhost; |
| 114 | 115 | ||
| 115 | std::string dest_ep = "rtmp://"; | 116 | std::string dest_ep = "rtmp://"; |
| 116 | - if (forward_server == SRS_CONSTS_LOCALHOST) { | 117 | + if (_ep_forward == SRS_CONSTS_LOCALHOST) { |
| 117 | dest_ep += req->host; | 118 | dest_ep += req->host; |
| 118 | } else { | 119 | } else { |
| 119 | - dest_ep += forward_server; | 120 | + dest_ep += _ep_forward; |
| 120 | } | 121 | } |
| 121 | dest_ep += ":"; | 122 | dest_ep += ":"; |
| 122 | - dest_ep += s_port; | 123 | + dest_ep += port; |
| 123 | dest_ep += "?vhost="; | 124 | dest_ep += "?vhost="; |
| 124 | - dest_ep += vhost; | 125 | + dest_ep += req->vhost; |
| 125 | 126 | ||
| 126 | if (source_ep == dest_ep) { | 127 | if (source_ep == dest_ep) { |
| 127 | ret = ERROR_SYSTEM_FORWARD_LOOP; | 128 | ret = ERROR_SYSTEM_FORWARD_LOOP; |
| @@ -131,7 +132,7 @@ int SrsForwarder::on_publish(SrsRequest* req, std::string forward_server) | @@ -131,7 +132,7 @@ int SrsForwarder::on_publish(SrsRequest* req, std::string forward_server) | ||
| 131 | } | 132 | } |
| 132 | srs_trace("start forward %s to %s, tcUrl=%s, stream=%s", | 133 | srs_trace("start forward %s to %s, tcUrl=%s, stream=%s", |
| 133 | source_ep.c_str(), dest_ep.c_str(), tc_url.c_str(), | 134 | source_ep.c_str(), dest_ep.c_str(), tc_url.c_str(), |
| 134 | - stream_name.c_str()); | 135 | + req->stream.c_str()); |
| 135 | 136 | ||
| 136 | if ((ret = pthread->start()) != ERROR_SUCCESS) { | 137 | if ((ret = pthread->start()) != ERROR_SUCCESS) { |
| 137 | srs_error("start srs thread failed. ret=%d", ret); | 138 | srs_error("start srs thread failed. ret=%d", ret); |
| @@ -205,7 +206,8 @@ int SrsForwarder::cycle() | @@ -205,7 +206,8 @@ int SrsForwarder::cycle() | ||
| 205 | { | 206 | { |
| 206 | int ret = ERROR_SUCCESS; | 207 | int ret = ERROR_SUCCESS; |
| 207 | 208 | ||
| 208 | - if ((ret = connect_server()) != ERROR_SUCCESS) { | 209 | + std::string ep_server, ep_port; |
| 210 | + if ((ret = connect_server(ep_server, ep_port)) != ERROR_SUCCESS) { | ||
| 209 | return ret; | 211 | return ret; |
| 210 | } | 212 | } |
| 211 | srs_assert(client); | 213 | srs_assert(client); |
| @@ -217,12 +219,8 @@ int SrsForwarder::cycle() | @@ -217,12 +219,8 @@ int SrsForwarder::cycle() | ||
| 217 | srs_error("handshake with server failed. ret=%d", ret); | 219 | srs_error("handshake with server failed. ret=%d", ret); |
| 218 | return ret; | 220 | return ret; |
| 219 | } | 221 | } |
| 220 | - // TODO: FIXME: take debug info for srs, @see SrsEdgeForwarder.connect_server. | ||
| 221 | - // @see https://github.com/winlinvip/simple-rtmp-server/issues/160 | ||
| 222 | - // the debug_srs_upnode is config in vhost and default to true. | ||
| 223 | - bool debug_srs_upnode = _srs_config->get_debug_srs_upnode(vhost); | ||
| 224 | - if ((ret = client->connect_app(app, tc_url, NULL, debug_srs_upnode)) != ERROR_SUCCESS) { | ||
| 225 | - srs_error("connect with server failed, tcUrl=%s. ret=%d", tc_url.c_str(), ret); | 222 | + if ((ret = connect_app(ep_server, ep_port)) != ERROR_SUCCESS) { |
| 223 | + srs_error("connect with server failed. ret=%d", ret); | ||
| 226 | return ret; | 224 | return ret; |
| 227 | } | 225 | } |
| 228 | if ((ret = client->create_stream(stream_id)) != ERROR_SUCCESS) { | 226 | if ((ret = client->create_stream(stream_id)) != ERROR_SUCCESS) { |
| @@ -230,9 +228,9 @@ int SrsForwarder::cycle() | @@ -230,9 +228,9 @@ int SrsForwarder::cycle() | ||
| 230 | return ret; | 228 | return ret; |
| 231 | } | 229 | } |
| 232 | 230 | ||
| 233 | - if ((ret = client->publish(stream_name, stream_id)) != ERROR_SUCCESS) { | 231 | + if ((ret = client->publish(_req->stream, stream_id)) != ERROR_SUCCESS) { |
| 234 | srs_error("connect with server failed, stream_name=%s, stream_id=%d. ret=%d", | 232 | srs_error("connect with server failed, stream_name=%s, stream_id=%d. ret=%d", |
| 235 | - stream_name.c_str(), stream_id, ret); | 233 | + _req->stream.c_str(), stream_id, ret); |
| 236 | return ret; | 234 | return ret; |
| 237 | } | 235 | } |
| 238 | 236 | ||
| @@ -253,18 +251,45 @@ void SrsForwarder::close_underlayer_socket() | @@ -253,18 +251,45 @@ void SrsForwarder::close_underlayer_socket() | ||
| 253 | srs_close_stfd(stfd); | 251 | srs_close_stfd(stfd); |
| 254 | } | 252 | } |
| 255 | 253 | ||
| 256 | -int SrsForwarder::connect_server() | 254 | +void SrsForwarder::discovery_ep(string& server, string& port, string& tc_url) |
| 255 | +{ | ||
| 256 | + SrsRequest* req = _req; | ||
| 257 | + | ||
| 258 | + server = _ep_forward; | ||
| 259 | + port = SRS_CONSTS_RTMP_DEFAULT_PORT; | ||
| 260 | + | ||
| 261 | + // TODO: FIXME: parse complex params | ||
| 262 | + size_t pos = _ep_forward.find(":"); | ||
| 263 | + if (pos != std::string::npos) { | ||
| 264 | + port = _ep_forward.substr(pos + 1); | ||
| 265 | + server = _ep_forward.substr(0, pos); | ||
| 266 | + } | ||
| 267 | + | ||
| 268 | + // generate tcUrl | ||
| 269 | + tc_url = srs_generate_tc_url(server, req->vhost, req->app, port, req->param); | ||
| 270 | +} | ||
| 271 | + | ||
| 272 | +int SrsForwarder::connect_server(string& ep_server, string& ep_port) | ||
| 257 | { | 273 | { |
| 258 | int ret = ERROR_SUCCESS; | 274 | int ret = ERROR_SUCCESS; |
| 259 | 275 | ||
| 260 | // reopen | 276 | // reopen |
| 261 | close_underlayer_socket(); | 277 | close_underlayer_socket(); |
| 262 | 278 | ||
| 279 | + // discovery the server port and tcUrl from req and ep_forward. | ||
| 280 | + std::string server, s_port, tc_url; | ||
| 281 | + discovery_ep(server, s_port, tc_url); | ||
| 282 | + int port = ::atoi(s_port.c_str()); | ||
| 283 | + | ||
| 284 | + // output the connected server and port. | ||
| 285 | + ep_server = server; | ||
| 286 | + ep_port = s_port; | ||
| 287 | + | ||
| 263 | // open socket. | 288 | // open socket. |
| 264 | int64_t timeout = SRS_FORWARDER_SLEEP_US; | 289 | int64_t timeout = SRS_FORWARDER_SLEEP_US; |
| 265 | - if ((ret = srs_socket_connect(server, port, timeout, &stfd)) != ERROR_SUCCESS) { | 290 | + if ((ret = srs_socket_connect(ep_server, port, timeout, &stfd)) != ERROR_SUCCESS) { |
| 266 | srs_warn("forward failed, stream=%s, tcUrl=%s to server=%s, port=%d, timeout=%"PRId64", ret=%d", | 291 | srs_warn("forward failed, stream=%s, tcUrl=%s to server=%s, port=%d, timeout=%"PRId64", ret=%d", |
| 267 | - stream_name.c_str(), tc_url.c_str(), server.c_str(), port, timeout, ret); | 292 | + _req->stream.c_str(), _req->tcUrl.c_str(), server.c_str(), port, timeout, ret); |
| 268 | return ret; | 293 | return ret; |
| 269 | } | 294 | } |
| 270 | 295 | ||
| @@ -278,7 +303,58 @@ int SrsForwarder::connect_server() | @@ -278,7 +303,58 @@ int SrsForwarder::connect_server() | ||
| 278 | kbps->set_io(io, io); | 303 | kbps->set_io(io, io); |
| 279 | 304 | ||
| 280 | srs_trace("forward connected, stream=%s, tcUrl=%s to server=%s, port=%d", | 305 | srs_trace("forward connected, stream=%s, tcUrl=%s to server=%s, port=%d", |
| 281 | - stream_name.c_str(), tc_url.c_str(), server.c_str(), port); | 306 | + _req->stream.c_str(), _req->tcUrl.c_str(), server.c_str(), port); |
| 307 | + | ||
| 308 | + return ret; | ||
| 309 | +} | ||
| 310 | + | ||
| 311 | +// TODO: FIXME: refine the connect_app. | ||
| 312 | +int SrsForwarder::connect_app(string ep_server, string ep_port) | ||
| 313 | +{ | ||
| 314 | + int ret = ERROR_SUCCESS; | ||
| 315 | + | ||
| 316 | + SrsRequest* req = _req; | ||
| 317 | + | ||
| 318 | + // args of request takes the srs info. | ||
| 319 | + if (req->args == NULL) { | ||
| 320 | + req->args = SrsAmf0Any::object(); | ||
| 321 | + } | ||
| 322 | + | ||
| 323 | + // notify server the edge identity, | ||
| 324 | + // @see https://github.com/winlinvip/simple-rtmp-server/issues/147 | ||
| 325 | + SrsAmf0Object* data = req->args; | ||
| 326 | + data->set("srs_sig", SrsAmf0Any::str(RTMP_SIG_SRS_KEY)); | ||
| 327 | + data->set("srs_server", SrsAmf0Any::str(RTMP_SIG_SRS_KEY" "RTMP_SIG_SRS_VERSION" ("RTMP_SIG_SRS_URL_SHORT")")); | ||
| 328 | + data->set("srs_license", SrsAmf0Any::str(RTMP_SIG_SRS_LICENSE)); | ||
| 329 | + data->set("srs_role", SrsAmf0Any::str(RTMP_SIG_SRS_ROLE)); | ||
| 330 | + data->set("srs_url", SrsAmf0Any::str(RTMP_SIG_SRS_URL)); | ||
| 331 | + data->set("srs_version", SrsAmf0Any::str(RTMP_SIG_SRS_VERSION)); | ||
| 332 | + data->set("srs_site", SrsAmf0Any::str(RTMP_SIG_SRS_WEB)); | ||
| 333 | + data->set("srs_email", SrsAmf0Any::str(RTMP_SIG_SRS_EMAIL)); | ||
| 334 | + data->set("srs_copyright", SrsAmf0Any::str(RTMP_SIG_SRS_COPYRIGHT)); | ||
| 335 | + data->set("srs_primary_authors", SrsAmf0Any::str(RTMP_SIG_SRS_PRIMARY_AUTHROS)); | ||
| 336 | + // for edge to directly get the id of client. | ||
| 337 | + data->set("srs_pid", SrsAmf0Any::number(getpid())); | ||
| 338 | + data->set("srs_id", SrsAmf0Any::number(_srs_context->get_id())); | ||
| 339 | + | ||
| 340 | + // local ip of edge | ||
| 341 | + std::vector<std::string> ips = srs_get_local_ipv4_ips(); | ||
| 342 | + assert(_srs_config->get_stats_network() < (int)ips.size()); | ||
| 343 | + std::string local_ip = ips[_srs_config->get_stats_network()]; | ||
| 344 | + data->set("srs_server_ip", SrsAmf0Any::str(local_ip.c_str())); | ||
| 345 | + | ||
| 346 | + // generate the tcUrl | ||
| 347 | + std::string param = ""; | ||
| 348 | + std::string tc_url = srs_generate_tc_url(ep_server, req->vhost, req->app, ep_port, param); | ||
| 349 | + | ||
| 350 | + // upnode server identity will show in the connect_app of client. | ||
| 351 | + // @see https://github.com/winlinvip/simple-rtmp-server/issues/160 | ||
| 352 | + // the debug_srs_upnode is config in vhost and default to true. | ||
| 353 | + bool debug_srs_upnode = _srs_config->get_debug_srs_upnode(req->vhost); | ||
| 354 | + if ((ret = client->connect_app(req->app, tc_url, req, debug_srs_upnode)) != ERROR_SUCCESS) { | ||
| 355 | + srs_error("connect with server failed, tcUrl=%s. ret=%d", tc_url.c_str(), ret); | ||
| 356 | + return ret; | ||
| 357 | + } | ||
| 282 | 358 | ||
| 283 | return ret; | 359 | return ret; |
| 284 | } | 360 | } |
| @@ -51,13 +51,10 @@ class SrsKbps; | @@ -51,13 +51,10 @@ class SrsKbps; | ||
| 51 | class SrsForwarder : public ISrsThreadHandler | 51 | class SrsForwarder : public ISrsThreadHandler |
| 52 | { | 52 | { |
| 53 | private: | 53 | private: |
| 54 | - std::string app; | ||
| 55 | - std::string tc_url; | ||
| 56 | - std::string vhost; | ||
| 57 | - std::string stream_name; | 54 | + // the ep to forward, server[:port]. |
| 55 | + std::string _ep_forward; | ||
| 56 | + SrsRequest* _req; | ||
| 58 | int stream_id; | 57 | int stream_id; |
| 59 | - std::string server; | ||
| 60 | - int port; | ||
| 61 | private: | 58 | private: |
| 62 | st_netfd_t stfd; | 59 | st_netfd_t stfd; |
| 63 | SrsThread* pthread; | 60 | SrsThread* pthread; |
| @@ -72,9 +69,10 @@ public: | @@ -72,9 +69,10 @@ public: | ||
| 72 | SrsForwarder(SrsSource* _source); | 69 | SrsForwarder(SrsSource* _source); |
| 73 | virtual ~SrsForwarder(); | 70 | virtual ~SrsForwarder(); |
| 74 | public: | 71 | public: |
| 72 | + virtual int initialize(SrsRequest* req, std::string ep_forward); | ||
| 75 | virtual void set_queue_size(double queue_size); | 73 | virtual void set_queue_size(double queue_size); |
| 76 | public: | 74 | public: |
| 77 | - virtual int on_publish(SrsRequest* req, std::string forward_server); | 75 | + virtual int on_publish(); |
| 78 | virtual void on_unpublish(); | 76 | virtual void on_unpublish(); |
| 79 | virtual int on_meta_data(SrsSharedPtrMessage* metadata); | 77 | virtual int on_meta_data(SrsSharedPtrMessage* metadata); |
| 80 | virtual int on_audio(SrsSharedPtrMessage* msg); | 78 | virtual int on_audio(SrsSharedPtrMessage* msg); |
| @@ -84,8 +82,9 @@ public: | @@ -84,8 +82,9 @@ public: | ||
| 84 | virtual int cycle(); | 82 | virtual int cycle(); |
| 85 | private: | 83 | private: |
| 86 | virtual void close_underlayer_socket(); | 84 | virtual void close_underlayer_socket(); |
| 87 | - // TODO: FIXME: take debug info for srs, @see SrsEdgeForwarder.connect_server. | ||
| 88 | - virtual int connect_server(); | 85 | + virtual void discovery_ep(std::string& server, std::string& port, std::string& tc_url); |
| 86 | + virtual int connect_server(std::string& ep_server, std::string& ep_port); | ||
| 87 | + virtual int connect_app(std::string ep_server, std::string ep_port); | ||
| 89 | virtual int forward(); | 88 | virtual int forward(); |
| 90 | }; | 89 | }; |
| 91 | 90 |
| @@ -1045,7 +1045,9 @@ int SrsRtmpConn::do_token_traverse_auth(SrsStSocket* io, SrsRtmpClient* client) | @@ -1045,7 +1045,9 @@ int SrsRtmpConn::do_token_traverse_auth(SrsStSocket* io, SrsRtmpClient* client) | ||
| 1045 | srs_error("handshake with server failed. ret=%d", ret); | 1045 | srs_error("handshake with server failed. ret=%d", ret); |
| 1046 | return ret; | 1046 | return ret; |
| 1047 | } | 1047 | } |
| 1048 | - if ((ret = client->connect_app(req->app, req->tcUrl, req)) != ERROR_SUCCESS) { | 1048 | + |
| 1049 | + // for token tranverse, always take the debug info(which carries token). | ||
| 1050 | + if ((ret = client->connect_app(req->app, req->tcUrl, req, true)) != ERROR_SUCCESS) { | ||
| 1049 | srs_error("connect with server failed, tcUrl=%s. ret=%d", req->tcUrl.c_str(), ret); | 1051 | srs_error("connect with server failed, tcUrl=%s. ret=%d", req->tcUrl.c_str(), ret); |
| 1050 | return ret; | 1052 | return ret; |
| 1051 | } | 1053 | } |
| @@ -1386,6 +1386,7 @@ int SrsSource::on_publish() | @@ -1386,6 +1386,7 @@ int SrsSource::on_publish() | ||
| 1386 | return ret; | 1386 | return ret; |
| 1387 | } | 1387 | } |
| 1388 | 1388 | ||
| 1389 | + // TODO: FIXME: use initialize to set req. | ||
| 1389 | #ifdef SRS_AUTO_TRANSCODE | 1390 | #ifdef SRS_AUTO_TRANSCODE |
| 1390 | if ((ret = encoder->on_publish(_req)) != ERROR_SUCCESS) { | 1391 | if ((ret = encoder->on_publish(_req)) != ERROR_SUCCESS) { |
| 1391 | srs_error("start encoder failed. ret=%d", ret); | 1392 | srs_error("start encoder failed. ret=%d", ret); |
| @@ -1393,6 +1394,7 @@ int SrsSource::on_publish() | @@ -1393,6 +1394,7 @@ int SrsSource::on_publish() | ||
| 1393 | } | 1394 | } |
| 1394 | #endif | 1395 | #endif |
| 1395 | 1396 | ||
| 1397 | + // TODO: FIXME: use initialize to set req. | ||
| 1396 | #ifdef SRS_AUTO_HLS | 1398 | #ifdef SRS_AUTO_HLS |
| 1397 | if ((ret = hls->on_publish(_req)) != ERROR_SUCCESS) { | 1399 | if ((ret = hls->on_publish(_req)) != ERROR_SUCCESS) { |
| 1398 | srs_error("start hls failed. ret=%d", ret); | 1400 | srs_error("start hls failed. ret=%d", ret); |
| @@ -1400,6 +1402,7 @@ int SrsSource::on_publish() | @@ -1400,6 +1402,7 @@ int SrsSource::on_publish() | ||
| 1400 | } | 1402 | } |
| 1401 | #endif | 1403 | #endif |
| 1402 | 1404 | ||
| 1405 | + // TODO: FIXME: use initialize to set req. | ||
| 1403 | #ifdef SRS_AUTO_DVR | 1406 | #ifdef SRS_AUTO_DVR |
| 1404 | if ((ret = dvr->on_publish(_req)) != ERROR_SUCCESS) { | 1407 | if ((ret = dvr->on_publish(_req)) != ERROR_SUCCESS) { |
| 1405 | srs_error("start dvr failed. ret=%d", ret); | 1408 | srs_error("start dvr failed. ret=%d", ret); |
| @@ -1548,11 +1551,16 @@ int SrsSource::create_forwarders() | @@ -1548,11 +1551,16 @@ int SrsSource::create_forwarders() | ||
| 1548 | 1551 | ||
| 1549 | SrsForwarder* forwarder = new SrsForwarder(this); | 1552 | SrsForwarder* forwarder = new SrsForwarder(this); |
| 1550 | forwarders.push_back(forwarder); | 1553 | forwarders.push_back(forwarder); |
| 1554 | + | ||
| 1555 | + // initialize the forwarder with request. | ||
| 1556 | + if ((ret = forwarder->initialize(_req, forward_server)) != ERROR_SUCCESS) { | ||
| 1557 | + return ret; | ||
| 1558 | + } | ||
| 1551 | 1559 | ||
| 1552 | double queue_size = _srs_config->get_queue_length(_req->vhost); | 1560 | double queue_size = _srs_config->get_queue_length(_req->vhost); |
| 1553 | forwarder->set_queue_size(queue_size); | 1561 | forwarder->set_queue_size(queue_size); |
| 1554 | 1562 | ||
| 1555 | - if ((ret = forwarder->on_publish(_req, forward_server)) != ERROR_SUCCESS) { | 1563 | + if ((ret = forwarder->on_publish()) != ERROR_SUCCESS) { |
| 1556 | srs_error("start forwarder failed. " | 1564 | srs_error("start forwarder failed. " |
| 1557 | "vhost=%s, app=%s, stream=%s, forward-to=%s", | 1565 | "vhost=%s, app=%s, stream=%s, forward-to=%s", |
| 1558 | _req->vhost.c_str(), _req->app.c_str(), _req->stream.c_str(), | 1566 | _req->vhost.c_str(), _req->app.c_str(), _req->stream.c_str(), |
| @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | // current release version | 31 | // current release version |
| 32 | #define VERSION_MAJOR "0" | 32 | #define VERSION_MAJOR "0" |
| 33 | #define VERSION_MINOR "9" | 33 | #define VERSION_MINOR "9" |
| 34 | -#define VERSION_REVISION "201" | 34 | +#define VERSION_REVISION "202" |
| 35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION | 35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION |
| 36 | // server info. | 36 | // server info. |
| 37 | #define RTMP_SIG_SRS_KEY "SRS" | 37 | #define RTMP_SIG_SRS_KEY "SRS" |
| @@ -253,7 +253,10 @@ int srs_connect_app(srs_rtmp_t rtmp) | @@ -253,7 +253,10 @@ int srs_connect_app(srs_rtmp_t rtmp) | ||
| 253 | context->ip, context->vhost, context->app, context->port, | 253 | context->ip, context->vhost, context->app, context->port, |
| 254 | context->param | 254 | context->param |
| 255 | ); | 255 | ); |
| 256 | - if ((ret = context->rtmp->connect_app(context->app, tcUrl)) != ERROR_SUCCESS) { | 256 | + |
| 257 | + if ((ret = context->rtmp->connect_app( | ||
| 258 | + context->app, tcUrl, NULL, true)) != ERROR_SUCCESS) | ||
| 259 | + { | ||
| 257 | return ret; | 260 | return ret; |
| 258 | } | 261 | } |
| 259 | 262 |
| @@ -434,7 +434,8 @@ int SrsRtmpClient::complex_handshake() | @@ -434,7 +434,8 @@ int SrsRtmpClient::complex_handshake() | ||
| 434 | return ret; | 434 | return ret; |
| 435 | } | 435 | } |
| 436 | 436 | ||
| 437 | -int SrsRtmpClient::connect_app(string app, string tc_url, SrsRequest* req, bool debug_srs_upnode) | 437 | +int SrsRtmpClient::connect_app(string app, string tc_url, |
| 438 | + SrsRequest* req, bool debug_srs_upnode) | ||
| 438 | { | 439 | { |
| 439 | std::string srs_server_ip; | 440 | std::string srs_server_ip; |
| 440 | std::string srs_server; | 441 | std::string srs_server; |
| @@ -248,7 +248,7 @@ public: | @@ -248,7 +248,7 @@ public: | ||
| 248 | * args for edge to origin traverse auth, @see SrsRequest.args | 248 | * args for edge to origin traverse auth, @see SrsRequest.args |
| 249 | */ | 249 | */ |
| 250 | virtual int connect_app(std::string app, std::string tc_url, | 250 | virtual int connect_app(std::string app, std::string tc_url, |
| 251 | - SrsRequest* req=NULL, bool debug_srs_upnode=true); | 251 | + SrsRequest* req, bool debug_srs_upnode); |
| 252 | /** | 252 | /** |
| 253 | * connect to server, get the debug srs info. | 253 | * connect to server, get the debug srs info. |
| 254 | * | 254 | * |
-
请 注册 或 登录 后发表评论