正在显示
3 个修改的文件
包含
55 行增加
和
39 行删除
| @@ -184,6 +184,7 @@ int SrsDynamicHttpConn::do_proxy(ISrsHttpResponseReader* rr, SrsFlvDecoder* dec) | @@ -184,6 +184,7 @@ int SrsDynamicHttpConn::do_proxy(ISrsHttpResponseReader* rr, SrsFlvDecoder* dec) | ||
| 184 | pprint->elapse(); | 184 | pprint->elapse(); |
| 185 | 185 | ||
| 186 | if ((ret = sdk->connect(output, SRS_CONSTS_RTMP_RECV_TIMEOUT_US)) != ERROR_SUCCESS) { | 186 | if ((ret = sdk->connect(output, SRS_CONSTS_RTMP_RECV_TIMEOUT_US)) != ERROR_SUCCESS) { |
| 187 | + srs_error("flv: connect %s failed. ret=%d", output.c_str(), ret); | ||
| 187 | return ret; | 188 | return ret; |
| 188 | } | 189 | } |
| 189 | 190 |
| @@ -94,6 +94,11 @@ SrsSimpleRtmpClient::~SrsSimpleRtmpClient() | @@ -94,6 +94,11 @@ SrsSimpleRtmpClient::~SrsSimpleRtmpClient() | ||
| 94 | 94 | ||
| 95 | int SrsSimpleRtmpClient::connect(string url, int64_t timeout) | 95 | int SrsSimpleRtmpClient::connect(string url, int64_t timeout) |
| 96 | { | 96 | { |
| 97 | + return connect(url, "", timeout); | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +int SrsSimpleRtmpClient::connect(string url, string vhost, int64_t timeout) | ||
| 101 | +{ | ||
| 97 | int ret = ERROR_SUCCESS; | 102 | int ret = ERROR_SUCCESS; |
| 98 | 103 | ||
| 99 | // when ok, ignore. | 104 | // when ok, ignore. |
| @@ -122,21 +127,21 @@ int SrsSimpleRtmpClient::connect(string url, int64_t timeout) | @@ -122,21 +127,21 @@ int SrsSimpleRtmpClient::connect(string url, int64_t timeout) | ||
| 122 | 127 | ||
| 123 | // connect to vhost/app | 128 | // connect to vhost/app |
| 124 | if ((ret = client->handshake()) != ERROR_SUCCESS) { | 129 | if ((ret = client->handshake()) != ERROR_SUCCESS) { |
| 125 | - srs_error("mpegts: handshake with server failed. ret=%d", ret); | 130 | + srs_error("sdk: handshake with server failed. ret=%d", ret); |
| 126 | return ret; | 131 | return ret; |
| 127 | } | 132 | } |
| 128 | - if ((ret = connect_app(req->host, req->port)) != ERROR_SUCCESS) { | ||
| 129 | - srs_error("mpegts: connect with server failed. ret=%d", ret); | 133 | + if ((ret = connect_app(vhost)) != ERROR_SUCCESS) { |
| 134 | + srs_error("sdk: connect with server failed. ret=%d", ret); | ||
| 130 | return ret; | 135 | return ret; |
| 131 | } | 136 | } |
| 132 | if ((ret = client->create_stream(stream_id)) != ERROR_SUCCESS) { | 137 | if ((ret = client->create_stream(stream_id)) != ERROR_SUCCESS) { |
| 133 | - srs_error("mpegts: connect with server failed, stream_id=%d. ret=%d", stream_id, ret); | 138 | + srs_error("sdk: connect with server failed, stream_id=%d. ret=%d", stream_id, ret); |
| 134 | return ret; | 139 | return ret; |
| 135 | } | 140 | } |
| 136 | 141 | ||
| 137 | // publish. | 142 | // publish. |
| 138 | if ((ret = client->publish(req->stream, stream_id)) != ERROR_SUCCESS) { | 143 | if ((ret = client->publish(req->stream, stream_id)) != ERROR_SUCCESS) { |
| 139 | - srs_error("mpegts: publish failed, stream=%s, stream_id=%d. ret=%d", | 144 | + srs_error("sdk: publish failed, stream=%s, stream_id=%d. ret=%d", |
| 140 | req->stream.c_str(), stream_id, ret); | 145 | req->stream.c_str(), stream_id, ret); |
| 141 | return ret; | 146 | return ret; |
| 142 | } | 147 | } |
| @@ -144,35 +149,7 @@ int SrsSimpleRtmpClient::connect(string url, int64_t timeout) | @@ -144,35 +149,7 @@ int SrsSimpleRtmpClient::connect(string url, int64_t timeout) | ||
| 144 | return ret; | 149 | return ret; |
| 145 | } | 150 | } |
| 146 | 151 | ||
| 147 | -void SrsSimpleRtmpClient::close() | ||
| 148 | -{ | ||
| 149 | - transport->close(); | ||
| 150 | - | ||
| 151 | - srs_freep(client); | ||
| 152 | - srs_freep(req); | ||
| 153 | -} | ||
| 154 | - | ||
| 155 | -int SrsSimpleRtmpClient::rtmp_write_packet(char type, u_int32_t timestamp, char* data, int size) | ||
| 156 | -{ | ||
| 157 | - int ret = ERROR_SUCCESS; | ||
| 158 | - | ||
| 159 | - SrsSharedPtrMessage* msg = NULL; | ||
| 160 | - | ||
| 161 | - if ((ret = srs_rtmp_create_msg(type, timestamp, data, size, stream_id, &msg)) != ERROR_SUCCESS) { | ||
| 162 | - srs_error("flv: create shared ptr msg failed. ret=%d", ret); | ||
| 163 | - return ret; | ||
| 164 | - } | ||
| 165 | - srs_assert(msg); | ||
| 166 | - | ||
| 167 | - // send out encoded msg. | ||
| 168 | - if ((ret = client->send_and_free_message(msg, stream_id)) != ERROR_SUCCESS) { | ||
| 169 | - return ret; | ||
| 170 | - } | ||
| 171 | - | ||
| 172 | - return ret; | ||
| 173 | -} | ||
| 174 | - | ||
| 175 | -int SrsSimpleRtmpClient::connect_app(string ep_server, int ep_port) | 152 | +int SrsSimpleRtmpClient::connect_app(string vhost) |
| 176 | { | 153 | { |
| 177 | int ret = ERROR_SUCCESS; | 154 | int ret = ERROR_SUCCESS; |
| 178 | 155 | ||
| @@ -185,7 +162,7 @@ int SrsSimpleRtmpClient::connect_app(string ep_server, int ep_port) | @@ -185,7 +162,7 @@ int SrsSimpleRtmpClient::connect_app(string ep_server, int ep_port) | ||
| 185 | // @see https://github.com/simple-rtmp-server/srs/issues/147 | 162 | // @see https://github.com/simple-rtmp-server/srs/issues/147 |
| 186 | SrsAmf0Object* data = req->args; | 163 | SrsAmf0Object* data = req->args; |
| 187 | data->set("srs_sig", SrsAmf0Any::str(RTMP_SIG_SRS_KEY)); | 164 | data->set("srs_sig", SrsAmf0Any::str(RTMP_SIG_SRS_KEY)); |
| 188 | - data->set("srs_server", SrsAmf0Any::str(RTMP_SIG_SRS_KEY" "RTMP_SIG_SRS_VERSION" ("RTMP_SIG_SRS_URL_SHORT")")); | 165 | + data->set("srs_server", SrsAmf0Any::str(RTMP_SIG_SRS_SERVER)); |
| 189 | data->set("srs_license", SrsAmf0Any::str(RTMP_SIG_SRS_LICENSE)); | 166 | data->set("srs_license", SrsAmf0Any::str(RTMP_SIG_SRS_LICENSE)); |
| 190 | data->set("srs_role", SrsAmf0Any::str(RTMP_SIG_SRS_ROLE)); | 167 | data->set("srs_role", SrsAmf0Any::str(RTMP_SIG_SRS_ROLE)); |
| 191 | data->set("srs_url", SrsAmf0Any::str(RTMP_SIG_SRS_URL)); | 168 | data->set("srs_url", SrsAmf0Any::str(RTMP_SIG_SRS_URL)); |
| @@ -207,14 +184,22 @@ int SrsSimpleRtmpClient::connect_app(string ep_server, int ep_port) | @@ -207,14 +184,22 @@ int SrsSimpleRtmpClient::connect_app(string ep_server, int ep_port) | ||
| 207 | 184 | ||
| 208 | // generate the tcUrl | 185 | // generate the tcUrl |
| 209 | std::string param = ""; | 186 | std::string param = ""; |
| 210 | - std::string tc_url = srs_generate_tc_url(ep_server, req->vhost, req->app, ep_port, param); | 187 | + std::string target_vhost = req->vhost; |
| 188 | + if (vhost.empty()) { | ||
| 189 | + target_vhost = vhost; | ||
| 190 | + } | ||
| 191 | + std::string tc_url = srs_generate_tc_url(req->host, target_vhost, req->app, req->port, param); | ||
| 192 | + | ||
| 193 | + // replace the tcUrl in request, | ||
| 194 | + // which will replace the tc_url in client.connect_app(). | ||
| 195 | + req->tcUrl = tc_url; | ||
| 211 | 196 | ||
| 212 | // upnode server identity will show in the connect_app of client. | 197 | // upnode server identity will show in the connect_app of client. |
| 213 | // @see https://github.com/simple-rtmp-server/srs/issues/160 | 198 | // @see https://github.com/simple-rtmp-server/srs/issues/160 |
| 214 | // the debug_srs_upnode is config in vhost and default to true. | 199 | // the debug_srs_upnode is config in vhost and default to true. |
| 215 | bool debug_srs_upnode = _srs_config->get_debug_srs_upnode(req->vhost); | 200 | bool debug_srs_upnode = _srs_config->get_debug_srs_upnode(req->vhost); |
| 216 | if ((ret = client->connect_app(req->app, tc_url, req, debug_srs_upnode)) != ERROR_SUCCESS) { | 201 | if ((ret = client->connect_app(req->app, tc_url, req, debug_srs_upnode)) != ERROR_SUCCESS) { |
| 217 | - srs_error("mpegts: connect with server failed, tcUrl=%s, dsu=%d. ret=%d", | 202 | + srs_error("sdk: connect with server failed, tcUrl=%s, dsu=%d. ret=%d", |
| 218 | tc_url.c_str(), debug_srs_upnode, ret); | 203 | tc_url.c_str(), debug_srs_upnode, ret); |
| 219 | return ret; | 204 | return ret; |
| 220 | } | 205 | } |
| @@ -222,6 +207,34 @@ int SrsSimpleRtmpClient::connect_app(string ep_server, int ep_port) | @@ -222,6 +207,34 @@ int SrsSimpleRtmpClient::connect_app(string ep_server, int ep_port) | ||
| 222 | return ret; | 207 | return ret; |
| 223 | } | 208 | } |
| 224 | 209 | ||
| 210 | +void SrsSimpleRtmpClient::close() | ||
| 211 | +{ | ||
| 212 | + transport->close(); | ||
| 213 | + | ||
| 214 | + srs_freep(client); | ||
| 215 | + srs_freep(req); | ||
| 216 | +} | ||
| 217 | + | ||
| 218 | +int SrsSimpleRtmpClient::rtmp_write_packet(char type, u_int32_t timestamp, char* data, int size) | ||
| 219 | +{ | ||
| 220 | + int ret = ERROR_SUCCESS; | ||
| 221 | + | ||
| 222 | + SrsSharedPtrMessage* msg = NULL; | ||
| 223 | + | ||
| 224 | + if ((ret = srs_rtmp_create_msg(type, timestamp, data, size, stream_id, &msg)) != ERROR_SUCCESS) { | ||
| 225 | + srs_error("sdk: create shared ptr msg failed. ret=%d", ret); | ||
| 226 | + return ret; | ||
| 227 | + } | ||
| 228 | + srs_assert(msg); | ||
| 229 | + | ||
| 230 | + // send out encoded msg. | ||
| 231 | + if ((ret = client->send_and_free_message(msg, stream_id)) != ERROR_SUCCESS) { | ||
| 232 | + return ret; | ||
| 233 | + } | ||
| 234 | + | ||
| 235 | + return ret; | ||
| 236 | +} | ||
| 237 | + | ||
| 225 | SrsRtmpConn::SrsRtmpConn(SrsServer* svr, st_netfd_t c) | 238 | SrsRtmpConn::SrsRtmpConn(SrsServer* svr, st_netfd_t c) |
| 226 | : SrsConnection(svr, c) | 239 | : SrsConnection(svr, c) |
| 227 | { | 240 | { |
| @@ -72,11 +72,13 @@ public: | @@ -72,11 +72,13 @@ public: | ||
| 72 | virtual ~SrsSimpleRtmpClient(); | 72 | virtual ~SrsSimpleRtmpClient(); |
| 73 | public: | 73 | public: |
| 74 | virtual int connect(std::string url, int64_t timeout); | 74 | virtual int connect(std::string url, int64_t timeout); |
| 75 | + virtual int connect(std::string url, std::string vhost, int64_t timeout); | ||
| 76 | +private: | ||
| 77 | + virtual int connect_app(std::string vhost); | ||
| 78 | +public: | ||
| 75 | virtual void close(); | 79 | virtual void close(); |
| 76 | public: | 80 | public: |
| 77 | virtual int rtmp_write_packet(char type, u_int32_t timestamp, char* data, int size); | 81 | virtual int rtmp_write_packet(char type, u_int32_t timestamp, char* data, int size); |
| 78 | -private: | ||
| 79 | - virtual int connect_app(std::string ep_server, int ep_port); | ||
| 80 | }; | 82 | }; |
| 81 | 83 | ||
| 82 | /** | 84 | /** |
-
请 注册 或 登录 后发表评论