正在显示
7 个修改的文件
包含
91 行增加
和
8 行删除
| @@ -562,6 +562,7 @@ Supported operating systems and hardware: | @@ -562,6 +562,7 @@ Supported operating systems and hardware: | ||
| 562 | 562 | ||
| 563 | ### SRS 2.0 history | 563 | ### SRS 2.0 history |
| 564 | 564 | ||
| 565 | +* v2.0, 2015-03-30, for [#372](https://github.com/winlinvip/simple-rtmp-server/issues/372), support transform vhost of edge 2.0.155. | ||
| 565 | * v2.0, 2015-03-30, for [#366](https://github.com/winlinvip/simple-rtmp-server/issues/366), config hls to disable cleanup of ts. 2.0.154. | 566 | * v2.0, 2015-03-30, for [#366](https://github.com/winlinvip/simple-rtmp-server/issues/366), config hls to disable cleanup of ts. 2.0.154. |
| 566 | * v2.0, 2015-03-31, support server cycle handler. 2.0.153. | 567 | * v2.0, 2015-03-31, support server cycle handler. 2.0.153. |
| 567 | * v2.0, 2015-03-31, support on_hls for http hooks. 2.0.152. | 568 | * v2.0, 2015-03-31, support on_hls for http hooks. 2.0.152. |
| @@ -284,6 +284,17 @@ vhost same.edge.srs.com { | @@ -284,6 +284,17 @@ vhost same.edge.srs.com { | ||
| 284 | token_traverse off; | 284 | token_traverse off; |
| 285 | } | 285 | } |
| 286 | 286 | ||
| 287 | +# vhost for edge, edge transform vhost to fetch from another vhost. | ||
| 288 | +vhost transform.edge.srs.com { | ||
| 289 | + mode remote; | ||
| 290 | + origin 127.0.0.1:1935; | ||
| 291 | + # the vhost to transform for edge, | ||
| 292 | + # to fetch from the specified vhost at origin, | ||
| 293 | + # if not specified, use the current vhost of edge in origin, the variable [vhost]. | ||
| 294 | + # default: [vhost] | ||
| 295 | + vhost same.edge.srs.com; | ||
| 296 | +} | ||
| 297 | + | ||
| 287 | # vhost for dvr | 298 | # vhost for dvr |
| 288 | vhost dvr.srs.com { | 299 | vhost dvr.srs.com { |
| 289 | # dvr RTMP stream to file, | 300 | # dvr RTMP stream to file, |
trunk/conf/transform.edge.conf
0 → 100644
| 1 | +# the config for srs origin-edge cluster | ||
| 2 | +# @see https://github.com/winlinvip/simple-rtmp-server/wiki/v2_CN_Edge#transform-vhost | ||
| 3 | +# @see full.conf for detail config. | ||
| 4 | + | ||
| 5 | +listen 1935; | ||
| 6 | +max_connections 1000; | ||
| 7 | +vhost __defaultVhost__ { | ||
| 8 | +} | ||
| 9 | +vhost source.srs.com { | ||
| 10 | + ingest livestream { | ||
| 11 | + enabled on; | ||
| 12 | + input { | ||
| 13 | + type file; | ||
| 14 | + url ./doc/source.200kbps.768x320.flv; | ||
| 15 | + } | ||
| 16 | + ffmpeg ./objs/ffmpeg/bin/ffmpeg; | ||
| 17 | + engine { | ||
| 18 | + enabled off; | ||
| 19 | + output rtmp://127.0.0.1:[port]/live?vhost=[vhost]/livestream; | ||
| 20 | + } | ||
| 21 | + } | ||
| 22 | +} | ||
| 23 | +vhost transform.srs.edge.com { | ||
| 24 | + mode remote; | ||
| 25 | + origin 127.0.0.1:1935; | ||
| 26 | + vhost source.srs.com; | ||
| 27 | +} |
| @@ -1409,7 +1409,7 @@ int SrsConfig::check_config() | @@ -1409,7 +1409,7 @@ int SrsConfig::check_config() | ||
| 1409 | SrsConfDirective* conf = vhost->at(i); | 1409 | SrsConfDirective* conf = vhost->at(i); |
| 1410 | string n = conf->name; | 1410 | string n = conf->name; |
| 1411 | if (n != "enabled" && n != "chunk_size" | 1411 | if (n != "enabled" && n != "chunk_size" |
| 1412 | - && n != "mode" && n != "origin" && n != "token_traverse" | 1412 | + && n != "mode" && n != "origin" && n != "token_traverse" && n != "vhost" |
| 1413 | && n != "dvr" && n != "ingest" && n != "hls" && n != "http_hooks" | 1413 | && n != "dvr" && n != "ingest" && n != "hls" && n != "http_hooks" |
| 1414 | && n != "gop_cache" && n != "queue_length" | 1414 | && n != "gop_cache" && n != "queue_length" |
| 1415 | && n != "refer" && n != "refer_publish" && n != "refer_play" | 1415 | && n != "refer" && n != "refer_publish" && n != "refer_play" |
| @@ -2517,12 +2517,12 @@ bool SrsConfig::get_vhost_is_edge(SrsConfDirective* vhost) | @@ -2517,12 +2517,12 @@ bool SrsConfig::get_vhost_is_edge(SrsConfDirective* vhost) | ||
| 2517 | SrsConfDirective* conf = vhost; | 2517 | SrsConfDirective* conf = vhost; |
| 2518 | 2518 | ||
| 2519 | if (!conf) { | 2519 | if (!conf) { |
| 2520 | - return false; | 2520 | + return SRS_CONF_DEFAULT_EDGE_MODE; |
| 2521 | } | 2521 | } |
| 2522 | 2522 | ||
| 2523 | conf = conf->get("mode"); | 2523 | conf = conf->get("mode"); |
| 2524 | if (!conf || conf->arg0() != "remote") { | 2524 | if (!conf || conf->arg0() != "remote") { |
| 2525 | - return false; | 2525 | + return SRS_CONF_DEFAULT_EDGE_MODE; |
| 2526 | } | 2526 | } |
| 2527 | 2527 | ||
| 2528 | return true; | 2528 | return true; |
| @@ -2544,17 +2544,33 @@ bool SrsConfig::get_vhost_edge_token_traverse(string vhost) | @@ -2544,17 +2544,33 @@ bool SrsConfig::get_vhost_edge_token_traverse(string vhost) | ||
| 2544 | SrsConfDirective* conf = get_vhost(vhost); | 2544 | SrsConfDirective* conf = get_vhost(vhost); |
| 2545 | 2545 | ||
| 2546 | if (!conf) { | 2546 | if (!conf) { |
| 2547 | - return false; | 2547 | + return SRS_CONF_DEFAULT_EDGE_TOKEN_TRAVERSE; |
| 2548 | } | 2548 | } |
| 2549 | 2549 | ||
| 2550 | conf = conf->get("token_traverse"); | 2550 | conf = conf->get("token_traverse"); |
| 2551 | if (!conf || conf->arg0() != "on") { | 2551 | if (!conf || conf->arg0() != "on") { |
| 2552 | - return false; | 2552 | + return SRS_CONF_DEFAULT_EDGE_TOKEN_TRAVERSE; |
| 2553 | } | 2553 | } |
| 2554 | 2554 | ||
| 2555 | return true; | 2555 | return true; |
| 2556 | } | 2556 | } |
| 2557 | 2557 | ||
| 2558 | +string SrsConfig::get_vhost_edge_transform_vhost(string vhost) | ||
| 2559 | +{ | ||
| 2560 | + SrsConfDirective* conf = get_vhost(vhost); | ||
| 2561 | + | ||
| 2562 | + if (!conf) { | ||
| 2563 | + return SRS_CONF_DEFAULT_EDGE_TRANSFORM_VHOST; | ||
| 2564 | + } | ||
| 2565 | + | ||
| 2566 | + conf = conf->get("vhost"); | ||
| 2567 | + if (!conf || conf->arg0().empty()) { | ||
| 2568 | + return SRS_CONF_DEFAULT_EDGE_TRANSFORM_VHOST; | ||
| 2569 | + } | ||
| 2570 | + | ||
| 2571 | + return conf->arg0(); | ||
| 2572 | +} | ||
| 2573 | + | ||
| 2558 | bool SrsConfig::get_security_enabled(string vhost) | 2574 | bool SrsConfig::get_security_enabled(string vhost) |
| 2559 | { | 2575 | { |
| 2560 | SrsConfDirective* conf = get_vhost(vhost); | 2576 | SrsConfDirective* conf = get_vhost(vhost); |
| @@ -106,6 +106,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -106,6 +106,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 106 | #define SRS_CONF_DEFAULT_TRANSCODE_IFORMAT "flv" | 106 | #define SRS_CONF_DEFAULT_TRANSCODE_IFORMAT "flv" |
| 107 | #define SRS_CONF_DEFAULT_TRANSCODE_OFORMAT "flv" | 107 | #define SRS_CONF_DEFAULT_TRANSCODE_OFORMAT "flv" |
| 108 | 108 | ||
| 109 | +#define SRS_CONF_DEFAULT_EDGE_MODE false | ||
| 110 | +#define SRS_CONF_DEFAULT_EDGE_TOKEN_TRAVERSE false | ||
| 111 | +#define SRS_CONF_DEFAULT_EDGE_TRANSFORM_VHOST "[vhost]" | ||
| 112 | + | ||
| 109 | // hds default value | 113 | // hds default value |
| 110 | #define SRS_CONF_DEFAULT_HDS_PATH "./objs/nginx/html" | 114 | #define SRS_CONF_DEFAULT_HDS_PATH "./objs/nginx/html" |
| 111 | #define SRS_CONF_DEFAULT_HDS_WINDOW (60) | 115 | #define SRS_CONF_DEFAULT_HDS_WINDOW (60) |
| @@ -688,6 +692,11 @@ public: | @@ -688,6 +692,11 @@ public: | ||
| 688 | * all clients connected to edge must be tranverse to origin to verify. | 692 | * all clients connected to edge must be tranverse to origin to verify. |
| 689 | */ | 693 | */ |
| 690 | virtual bool get_vhost_edge_token_traverse(std::string vhost); | 694 | virtual bool get_vhost_edge_token_traverse(std::string vhost); |
| 695 | + /** | ||
| 696 | + * get the transformed vhost for edge, | ||
| 697 | + * @see https://github.com/winlinvip/simple-rtmp-server/issues/372 | ||
| 698 | + */ | ||
| 699 | + virtual std::string get_vhost_edge_transform_vhost(std::string vhost); | ||
| 691 | // vhost security section | 700 | // vhost security section |
| 692 | public: | 701 | public: |
| 693 | /** | 702 | /** |
| @@ -43,6 +43,7 @@ using namespace std; | @@ -43,6 +43,7 @@ using namespace std; | ||
| 43 | #include <srs_rtmp_msg_array.hpp> | 43 | #include <srs_rtmp_msg_array.hpp> |
| 44 | #include <srs_app_utility.hpp> | 44 | #include <srs_app_utility.hpp> |
| 45 | #include <srs_rtmp_amf0.hpp> | 45 | #include <srs_rtmp_amf0.hpp> |
| 46 | +#include <srs_kernel_utility.hpp> | ||
| 46 | 47 | ||
| 47 | // when error, edge ingester sleep for a while and retry. | 48 | // when error, edge ingester sleep for a while and retry. |
| 48 | #define SRS_EDGE_INGESTER_SLEEP_US (int64_t)(1*1000*1000LL) | 49 | #define SRS_EDGE_INGESTER_SLEEP_US (int64_t)(1*1000*1000LL) |
| @@ -240,9 +241,18 @@ int SrsEdgeIngester::connect_app(string ep_server, string ep_port) | @@ -240,9 +241,18 @@ int SrsEdgeIngester::connect_app(string ep_server, string ep_port) | ||
| 240 | std::string local_ip = ips[_srs_config->get_stats_network()]; | 241 | std::string local_ip = ips[_srs_config->get_stats_network()]; |
| 241 | data->set("srs_server_ip", SrsAmf0Any::str(local_ip.c_str())); | 242 | data->set("srs_server_ip", SrsAmf0Any::str(local_ip.c_str())); |
| 242 | 243 | ||
| 244 | + // support vhost tranform for edge, | ||
| 245 | + // @see https://github.com/winlinvip/simple-rtmp-server/issues/372 | ||
| 246 | + std::string vhost = _srs_config->get_vhost_edge_transform_vhost(req->vhost); | ||
| 247 | + vhost = srs_string_replace(vhost, "[vhost]", req->vhost); | ||
| 243 | // generate the tcUrl | 248 | // generate the tcUrl |
| 244 | std::string param = ""; | 249 | std::string param = ""; |
| 245 | - std::string tc_url = srs_generate_tc_url(ep_server, req->vhost, req->app, ep_port, param); | 250 | + std::string tc_url = srs_generate_tc_url(ep_server, vhost, req->app, ep_port, param); |
| 251 | + srs_trace("edge ingest from %s:%s at %s", ep_server.c_str(), ep_port.c_str(), tc_url.c_str()); | ||
| 252 | + | ||
| 253 | + // replace the tcUrl in request, | ||
| 254 | + // which will replace the tc_url in client.connect_app(). | ||
| 255 | + req->tcUrl = tc_url; | ||
| 246 | 256 | ||
| 247 | // upnode server identity will show in the connect_app of client. | 257 | // upnode server identity will show in the connect_app of client. |
| 248 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/160 | 258 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/160 |
| @@ -662,9 +672,18 @@ int SrsEdgeForwarder::connect_app(string ep_server, string ep_port) | @@ -662,9 +672,18 @@ int SrsEdgeForwarder::connect_app(string ep_server, string ep_port) | ||
| 662 | std::string local_ip = ips[_srs_config->get_stats_network()]; | 672 | std::string local_ip = ips[_srs_config->get_stats_network()]; |
| 663 | data->set("srs_server_ip", SrsAmf0Any::str(local_ip.c_str())); | 673 | data->set("srs_server_ip", SrsAmf0Any::str(local_ip.c_str())); |
| 664 | 674 | ||
| 675 | + // support vhost tranform for edge, | ||
| 676 | + // @see https://github.com/winlinvip/simple-rtmp-server/issues/372 | ||
| 677 | + std::string vhost = _srs_config->get_vhost_edge_transform_vhost(req->vhost); | ||
| 678 | + vhost = srs_string_replace(vhost, "[vhost]", req->vhost); | ||
| 665 | // generate the tcUrl | 679 | // generate the tcUrl |
| 666 | std::string param = ""; | 680 | std::string param = ""; |
| 667 | - std::string tc_url = srs_generate_tc_url(ep_server, req->vhost, req->app, ep_port, param); | 681 | + std::string tc_url = srs_generate_tc_url(ep_server, vhost, req->app, ep_port, param); |
| 682 | + srs_trace("edge forward to %s:%s at %s", ep_server.c_str(), ep_port.c_str(), tc_url.c_str()); | ||
| 683 | + | ||
| 684 | + // replace the tcUrl in request, | ||
| 685 | + // which will replace the tc_url in client.connect_app(). | ||
| 686 | + req->tcUrl = tc_url; | ||
| 668 | 687 | ||
| 669 | // upnode server identity will show in the connect_app of client. | 688 | // upnode server identity will show in the connect_app of client. |
| 670 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/160 | 689 | // @see https://github.com/winlinvip/simple-rtmp-server/issues/160 |
| @@ -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 2 | 32 | #define VERSION_MAJOR 2 |
| 33 | #define VERSION_MINOR 0 | 33 | #define VERSION_MINOR 0 |
| 34 | -#define VERSION_REVISION 154 | 34 | +#define VERSION_REVISION 155 |
| 35 | 35 | ||
| 36 | // server info. | 36 | // server info. |
| 37 | #define RTMP_SIG_SRS_KEY "SRS" | 37 | #define RTMP_SIG_SRS_KEY "SRS" |
-
请 注册 或 登录 后发表评论