From b6feb0742fb8e1f93d0ad6aebc69251c781e07eb Mon Sep 17 00:00:00 2001 From: winlin Date: Mon, 23 Mar 2015 23:13:57 +0800 Subject: [PATCH] fix #149, RTMP/HTTP support bind to <[ip:]port>. 2.0.148 --- trunk/conf/full.conf | 13 ++++-- trunk/src/app/srs_app_config.cpp | 30 ++++++------- trunk/src/app/srs_app_config.hpp | 10 ++--- trunk/src/app/srs_app_ingest.cpp | 13 ++++-- trunk/src/app/srs_app_listener.cpp | 47 ++++++++++---------- trunk/src/app/srs_app_listener.hpp | 8 +++- trunk/src/app/srs_app_rtsp.cpp | 3 +- trunk/src/app/srs_app_server.cpp | 70 ++++++++++++++++++------------ trunk/src/app/srs_app_server.hpp | 9 ++-- trunk/src/app/srs_app_utility.cpp | 19 ++++++++ trunk/src/app/srs_app_utility.hpp | 7 +++ trunk/src/core/srs_core.hpp | 2 +- 12 files changed, 148 insertions(+), 83 deletions(-) diff --git a/trunk/conf/full.conf b/trunk/conf/full.conf index 7b03ac303..46eb83b8f 100644 --- a/trunk/conf/full.conf +++ b/trunk/conf/full.conf @@ -3,7 +3,9 @@ ############################################################################################# # RTMP sections ############################################################################################# -# the rtmp listen ports, split by space. +# the rtmp listen ports, split by space, each listen entry is <[ip:]port> +# for example, 192.168.1.100:1935 10.10.10.100:1935 +# where the ip is optional, default to 0.0.0.0, that is 1935 equals to 0.0.0.0:1935 listen 1935; # the pid file # to ensure only one process can use a pid file @@ -106,7 +108,9 @@ http_api { # whether http api is enabled. # default: off enabled on; - # the http api port + # the http api listen entry is <[ip:]port> + # for example, 192.168.1.100:1985 + # where the ip is optional, default to 0.0.0.0, that is 1985 equals to 0.0.0.0:1985 # default: 1985 listen 1985; # whether enable crossdomain request. @@ -127,7 +131,9 @@ http_server { # whether http streaming service is enabled. # default: off enabled on; - # the http streaming port + # the http streaming listen entry is <[ip:]port> + # for example, 192.168.1.100:8080 + # where the ip is optional, default to 0.0.0.0, that is 8080 equals to 0.0.0.0:8080 # @remark, if use lower port, for instance 80, user must start srs by root. # default: 8080 listen 8080; @@ -162,6 +168,7 @@ stream_caster { # the listen port for stream caster. # for mpegts_over_udp caster, listen at udp port. for example, 8935. # for rtsp caster, listen at tcp port. for example, 554. + # TODO: support listen at <[ip:]port> listen 8935; # for the rtsp caster, the rtp server local port over udp, # which reply the rtsp setup request message, the port will be used: diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index abbebcc07..1af1d03d0 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -1586,7 +1586,7 @@ int SrsConfig::check_config() // check listen for rtmp. //////////////////////////////////////////////////////////////////////// if (true) { - vector listens = get_listen(); + vector listens = get_listens(); if (listens.size() <= 0) { ret = ERROR_SYSTEM_CONFIG_INVALID; srs_error("directive \"listen\" is empty, ret=%d", ret); @@ -1613,11 +1613,11 @@ int SrsConfig::check_config() // check max connections of system limits if (true) { - int nb_consumed_fds = (int)get_listen().size(); - if (get_http_api_listen() > 0) { + int nb_consumed_fds = (int)get_listens().size(); + if (!get_http_api_listen().empty()) { nb_consumed_fds++; } - if (get_http_stream_listen() > 0) { + if (!get_http_stream_listen().empty()) { nb_consumed_fds++; } if (get_log_tank_file()) { @@ -1694,20 +1694,20 @@ int SrsConfig::check_config() //////////////////////////////////////////////////////////////////////// // check http api //////////////////////////////////////////////////////////////////////// - if (get_http_api_listen() <= 0) { + if (get_http_api_listen().empty()) { ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("directive http_api listen invalid, listen=%d, ret=%d", - get_http_api_listen(), ret); + srs_error("directive http_api listen invalid, listen=%s, ret=%d", + get_http_api_listen().c_str(), ret); return ret; } //////////////////////////////////////////////////////////////////////// // check http stream //////////////////////////////////////////////////////////////////////// - if (get_http_stream_listen() <= 0) { + if (get_http_stream_listen().empty()) { ret = ERROR_SYSTEM_CONFIG_INVALID; - srs_error("directive http_stream listen invalid, listen=%d, ret=%d", - get_http_stream_listen(), ret); + srs_error("directive http_stream listen invalid, listen=%s, ret=%d", + get_http_stream_listen().c_str(), ret); return ret; } @@ -1858,7 +1858,7 @@ int SrsConfig::get_max_connections() return ::atoi(conf->arg0().c_str()); } -vector SrsConfig::get_listen() +vector SrsConfig::get_listens() { std::vector ports; @@ -3546,7 +3546,7 @@ bool SrsConfig::get_http_api_enabled(SrsConfDirective* conf) return false; } -int SrsConfig::get_http_api_listen() +string SrsConfig::get_http_api_listen() { SrsConfDirective* conf = get_http_api(); @@ -3559,7 +3559,7 @@ int SrsConfig::get_http_api_listen() return SRS_CONF_DEFAULT_HTTP_API_PORT; } - return ::atoi(conf->arg0().c_str()); + return conf->arg0(); } bool SrsConfig::get_http_api_crossdomain() @@ -3609,7 +3609,7 @@ bool SrsConfig::get_http_stream_enabled(SrsConfDirective* conf) return false; } -int SrsConfig::get_http_stream_listen() +string SrsConfig::get_http_stream_listen() { SrsConfDirective* conf = get_http_stream(); @@ -3622,7 +3622,7 @@ int SrsConfig::get_http_stream_listen() return SRS_CONF_DEFAULT_HTTP_STREAM_PORT; } - return ::atoi(conf->arg0().c_str()); + return conf->arg0(); } string SrsConfig::get_http_stream_dir() diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 80c875ac9..6692c8fd6 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -77,8 +77,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #define SRS_CONF_DEFAULT_HTTP_DIR SRS_CONF_DEFAULT_HLS_PATH #define SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE 0 -#define SRS_CONF_DEFAULT_HTTP_STREAM_PORT 8080 -#define SRS_CONF_DEFAULT_HTTP_API_PORT 1985 +#define SRS_CONF_DEFAULT_HTTP_STREAM_PORT "8080" +#define SRS_CONF_DEFAULT_HTTP_API_PORT "1985" #define SRS_CONF_DEFAULT_HTTP_API_CROSSDOMAIN true #define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_ENABLED false @@ -411,7 +411,7 @@ public: * user can specifies multiple listen ports, * each args of directive is a listen port. */ - virtual std::vector get_listen(); + virtual std::vector get_listens(); /** * get the pid file path. * the pid file is used to save the pid of SRS, @@ -990,7 +990,7 @@ public: /** * get the http api listen port. */ - virtual int get_http_api_listen(); + virtual std::string get_http_api_listen(); /** * whether enable crossdomain for http api. */ @@ -1013,7 +1013,7 @@ public: /** * get the http stream listen port. */ - virtual int get_http_stream_listen(); + virtual std::string get_http_stream_listen(); /** * get the http stream root dir. */ diff --git a/trunk/src/app/srs_app_ingest.cpp b/trunk/src/app/srs_app_ingest.cpp index f28145182..19e4459e2 100644 --- a/trunk/src/app/srs_app_ingest.cpp +++ b/trunk/src/app/srs_app_ingest.cpp @@ -33,6 +33,7 @@ using namespace std; #include #include #include +#include // when error, ingester sleep for a while and retry. // ingest never sleep a long time, for we must start the stream ASAP. @@ -228,9 +229,15 @@ int SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, S { int ret = ERROR_SUCCESS; - std::vector ports = _srs_config->get_listen(); - srs_assert(ports.size() > 0); - std::string port = ports[0]; + std::string port; + if (true) { + std::vector ip_ports = _srs_config->get_listens(); + srs_assert(ip_ports.size() > 0); + + std::string ep = ip_ports[0]; + std::string ip; + srs_parse_endpoint(ep, ip, port); + } std::string output = _srs_config->get_engine_output(engine); // output stream, to other/self server diff --git a/trunk/src/app/srs_app_listener.cpp b/trunk/src/app/srs_app_listener.cpp index 2a82fa506..327f065f7 100644 --- a/trunk/src/app/srs_app_listener.cpp +++ b/trunk/src/app/srs_app_listener.cpp @@ -30,6 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include #include +using namespace std; #include #include @@ -61,9 +62,10 @@ ISrsTcpHandler::~ISrsTcpHandler() { } -SrsUdpListener::SrsUdpListener(ISrsUdpHandler* h, int p) +SrsUdpListener::SrsUdpListener(ISrsUdpHandler* h, string i, int p) { handler = h; + ip = i; port = p; _fd = -1; @@ -101,42 +103,42 @@ int SrsUdpListener::listen() if ((_fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { ret = ERROR_SOCKET_CREATE; - srs_error("create linux socket error. port=%d, ret=%d", port, ret); + srs_error("create linux socket error. port=%d, ret=%d", ip.c_str(), port, ret); return ret; } - srs_verbose("create linux socket success. port=%d, fd=%d", port, _fd); + srs_verbose("create linux socket success. port=%d, fd=%d", ip.c_str(), port, _fd); int reuse_socket = 1; if (setsockopt(_fd, SOL_SOCKET, SO_REUSEADDR, &reuse_socket, sizeof(int)) == -1) { ret = ERROR_SOCKET_SETREUSE; - srs_error("setsockopt reuse-addr error. port=%d, ret=%d", port, ret); + srs_error("setsockopt reuse-addr error. port=%d, ret=%d", ip.c_str(), port, ret); return ret; } - srs_verbose("setsockopt reuse-addr success. port=%d, fd=%d", port, _fd); + srs_verbose("setsockopt reuse-addr success. port=%d, fd=%d", ip.c_str(), port, _fd); sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = htons(port); - addr.sin_addr.s_addr = INADDR_ANY; + addr.sin_addr.s_addr = inet_addr(ip.c_str()); if (bind(_fd, (const sockaddr*)&addr, sizeof(sockaddr_in)) == -1) { ret = ERROR_SOCKET_BIND; - srs_error("bind socket error. port=%d, ret=%d", port, ret); + srs_error("bind socket error. ep=%s:%d, ret=%d", ip.c_str(), port, ret); return ret; } - srs_verbose("bind socket success. port=%d, fd=%d", port, _fd); + srs_verbose("bind socket success. ep=%s:%d, fd=%d", ip.c_str(), port, _fd); if ((stfd = st_netfd_open_socket(_fd)) == NULL){ ret = ERROR_ST_OPEN_SOCKET; - srs_error("st_netfd_open_socket open socket failed. port=%d, ret=%d", port, ret); + srs_error("st_netfd_open_socket open socket failed. ep=%s:%d, ret=%d", ip.c_str(), port, ret); return ret; } - srs_verbose("st open socket success. port=%d, fd=%d", port, _fd); + srs_verbose("st open socket success. ep=%s:%d, fd=%d", ip.c_str(), port, _fd); if ((ret = pthread->start()) != ERROR_SUCCESS) { - srs_error("st_thread_create listen thread error. port=%d, ret=%d", port, ret); + srs_error("st_thread_create listen thread error. ep=%s:%d, ret=%d", ip.c_str(), port, ret); return ret; } - srs_verbose("create st listen thread success, port=%d", port); + srs_verbose("create st listen thread success, ep=%s:%d", ip.c_str(), port); return ret; } @@ -169,9 +171,10 @@ int SrsUdpListener::cycle() return ret; } -SrsTcpListener::SrsTcpListener(ISrsTcpHandler* h, int p) +SrsTcpListener::SrsTcpListener(ISrsTcpHandler* h, string i, int p) { handler = h; + ip = i; port = p; _fd = -1; @@ -220,33 +223,33 @@ int SrsTcpListener::listen() sockaddr_in addr; addr.sin_family = AF_INET; addr.sin_port = htons(port); - addr.sin_addr.s_addr = INADDR_ANY; + addr.sin_addr.s_addr = inet_addr(ip.c_str()); if (bind(_fd, (const sockaddr*)&addr, sizeof(sockaddr_in)) == -1) { ret = ERROR_SOCKET_BIND; - srs_error("bind socket error. port=%d, ret=%d", port, ret); + srs_error("bind socket error. ep=%s:%d, ret=%d", ip.c_str(), port, ret); return ret; } - srs_verbose("bind socket success. port=%d, fd=%d", port, _fd); + srs_verbose("bind socket success. ep=%s:%d, fd=%d", ip.c_str(), port, _fd); if (::listen(_fd, SERVER_LISTEN_BACKLOG) == -1) { ret = ERROR_SOCKET_LISTEN; - srs_error("listen socket error. port=%d, ret=%d", port, ret); + srs_error("listen socket error. ep=%s:%d, ret=%d", ip.c_str(), port, ret); return ret; } - srs_verbose("listen socket success. port=%d, fd=%d", port, _fd); + srs_verbose("listen socket success. ep=%s:%d, fd=%d", ip.c_str(), port, _fd); if ((stfd = st_netfd_open_socket(_fd)) == NULL){ ret = ERROR_ST_OPEN_SOCKET; - srs_error("st_netfd_open_socket open socket failed. port=%d, ret=%d", port, ret); + srs_error("st_netfd_open_socket open socket failed. ep=%s:%d, ret=%d", ip.c_str(), port, ret); return ret; } - srs_verbose("st open socket success. port=%d, fd=%d", port, _fd); + srs_verbose("st open socket success. ep=%s:%d, fd=%d", ip.c_str(), port, _fd); if ((ret = pthread->start()) != ERROR_SUCCESS) { - srs_error("st_thread_create listen thread error. port=%d, ret=%d", port, ret); + srs_error("st_thread_create listen thread error. ep=%s:%d, ret=%d", ip.c_str(), port, ret); return ret; } - srs_verbose("create st listen thread success, port=%d", port); + srs_verbose("create st listen thread success, ep=%s:%d", ip.c_str(), port); return ret; } diff --git a/trunk/src/app/srs_app_listener.hpp b/trunk/src/app/srs_app_listener.hpp index 5cf240043..036678822 100644 --- a/trunk/src/app/srs_app_listener.hpp +++ b/trunk/src/app/srs_app_listener.hpp @@ -30,6 +30,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include +#include + #include #include @@ -85,9 +87,10 @@ private: int nb_buf; private: ISrsUdpHandler* handler; + std::string ip; int port; public: - SrsUdpListener(ISrsUdpHandler* h, int p); + SrsUdpListener(ISrsUdpHandler* h, std::string i, int p); virtual ~SrsUdpListener(); public: virtual int fd(); @@ -109,9 +112,10 @@ private: SrsThread* pthread; private: ISrsTcpHandler* handler; + std::string ip; int port; public: - SrsTcpListener(ISrsTcpHandler* h, int p); + SrsTcpListener(ISrsTcpHandler* h, std::string i, int p); virtual ~SrsTcpListener(); public: virtual int fd(); diff --git a/trunk/src/app/srs_app_rtsp.cpp b/trunk/src/app/srs_app_rtsp.cpp index ad1c4f360..504532ecc 100644 --- a/trunk/src/app/srs_app_rtsp.cpp +++ b/trunk/src/app/srs_app_rtsp.cpp @@ -50,7 +50,8 @@ SrsRtpConn::SrsRtpConn(SrsRtspConn* r, int p, int sid) rtsp = r; _port = p; stream_id = sid; - listener = new SrsUdpListener(this, p); + // TODO: support listen at <[ip:]port> + listener = new SrsUdpListener(this, "0.0.0.0", p); cache = new SrsRtpPacket(); pprint = SrsPithyPrint::create_caster(); } diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index 0e9bedfb1..a8bef6452 100644 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -136,14 +136,15 @@ SrsStreamListener::~SrsStreamListener() srs_freep(listener); } -int SrsStreamListener::listen(int port) +int SrsStreamListener::listen(string ip, int port) { int ret = ERROR_SUCCESS; + _ip = ip; _port = port; srs_freep(listener); - listener = new SrsTcpListener(this, port); + listener = new SrsTcpListener(this, ip, port); if ((ret = listener->listen()) != ERROR_SUCCESS) { srs_error("tcp listen failed. ret=%d", ret); @@ -151,10 +152,10 @@ int SrsStreamListener::listen(int port) } srs_info("listen thread cid=%d, current_cid=%d, " - "listen at port=%d, type=%d, fd=%d started success, port=%d", - pthread->cid(), _srs_context->get_id(), _port, _type, fd, port); + "listen at port=%d, type=%d, fd=%d started success, ep=%s:%d", + pthread->cid(), _srs_context->get_id(), _port, _type, fd, ip.c_str(), port); - srs_trace("%s listen at tcp://%d, fd=%d", srs_listener_type2string(_type).c_str(), _port, listener->fd()); + srs_trace("%s listen at tcp://%s:%d, fd=%d", srs_listener_type2string(_type).c_str(), ip.c_str(), _port, listener->fd()); return ret; } @@ -190,7 +191,7 @@ SrsRtspListener::~SrsRtspListener() srs_freep(listener); } -int SrsRtspListener::listen(int port) +int SrsRtspListener::listen(string ip, int port) { int ret = ERROR_SUCCESS; @@ -198,10 +199,11 @@ int SrsRtspListener::listen(int port) // we just assert here for unknown stream caster. srs_assert(_type == SrsListenerRtsp); + _ip = ip; _port = port; srs_freep(listener); - listener = new SrsTcpListener(this, port); + listener = new SrsTcpListener(this, ip, port); if ((ret = listener->listen()) != ERROR_SUCCESS) { srs_error("udp caster listen failed. ret=%d", ret); @@ -209,10 +211,10 @@ int SrsRtspListener::listen(int port) } srs_info("listen thread cid=%d, current_cid=%d, " - "listen at port=%d, type=%d, fd=%d started success, port=%d", - pthread->cid(), _srs_context->get_id(), _port, _type, fd, port); + "listen at port=%d, type=%d, fd=%d started success, ep=%s:%d", + pthread->cid(), _srs_context->get_id(), _port, _type, fd, ip.c_str(), port); - srs_trace("%s listen at tcp://%d, fd=%d", srs_listener_type2string(_type).c_str(), _port, listener->fd()); + srs_trace("%s listen at tcp://%s:%d, fd=%d", srs_listener_type2string(_type).c_str(), ip.c_str(), _port, listener->fd()); return ret; } @@ -248,7 +250,7 @@ SrsUdpCasterListener::~SrsUdpCasterListener() srs_freep(listener); } -int SrsUdpCasterListener::listen(int port) +int SrsUdpCasterListener::listen(string ip, int port) { int ret = ERROR_SUCCESS; @@ -256,10 +258,11 @@ int SrsUdpCasterListener::listen(int port) // we just assert here for unknown stream caster. srs_assert(_type == SrsListenerMpegTsOverUdp); + _ip = ip; _port = port; srs_freep(listener); - listener = new SrsUdpListener(caster, port); + listener = new SrsUdpListener(caster, ip, port); if ((ret = listener->listen()) != ERROR_SUCCESS) { srs_error("udp caster listen failed. ret=%d", ret); @@ -267,10 +270,10 @@ int SrsUdpCasterListener::listen(int port) } srs_info("listen thread cid=%d, current_cid=%d, " - "listen at port=%d, type=%d, fd=%d started success, port=%d", - pthread->cid(), _srs_context->get_id(), _port, _type, fd, port); + "listen at port=%d, type=%d, fd=%d started success, ep=%s:%d", + pthread->cid(), _srs_context->get_id(), _port, _type, fd, ip.c_str(), port); - srs_trace("%s listen at udp://%d, fd=%d", srs_listener_type2string(_type).c_str(), _port, listener->fd()); + srs_trace("%s listen at udp://%s:%d, fd=%d", srs_listener_type2string(_type).c_str(), ip.c_str(), _port, listener->fd()); return ret; } @@ -881,18 +884,21 @@ int SrsServer::listen_rtmp() int ret = ERROR_SUCCESS; // stream service port. - std::vector ports = _srs_config->get_listen(); - srs_assert((int)ports.size() > 0); + std::vector ip_ports = _srs_config->get_listens(); + srs_assert((int)ip_ports.size() > 0); close_listeners(SrsListenerRtmpStream); - for (int i = 0; i < (int)ports.size(); i++) { + for (int i = 0; i < (int)ip_ports.size(); i++) { SrsListener* listener = new SrsStreamListener(this, SrsListenerRtmpStream); listeners.push_back(listener); - int port = ::atoi(ports[i].c_str()); - if ((ret = listener->listen(port)) != ERROR_SUCCESS) { - srs_error("RTMP stream listen at port %d failed. ret=%d", port, ret); + std::string ip; + int port; + srs_parse_endpoint(ip_ports[i], ip, port); + + if ((ret = listener->listen(ip, port)) != ERROR_SUCCESS) { + srs_error("RTMP stream listen at %s:%d failed. ret=%d", ip.c_str(), port, ret); return ret; } } @@ -910,9 +916,14 @@ int SrsServer::listen_http_api() SrsListener* listener = new SrsStreamListener(this, SrsListenerHttpApi); listeners.push_back(listener); - int port = _srs_config->get_http_api_listen(); - if ((ret = listener->listen(port)) != ERROR_SUCCESS) { - srs_error("HTTP api listen at port %d failed. ret=%d", port, ret); + std::string ep = _srs_config->get_http_api_listen(); + + std::string ip; + int port; + srs_parse_endpoint(ep, ip, port); + + if ((ret = listener->listen(ip, port)) != ERROR_SUCCESS) { + srs_error("HTTP api listen at %s:%d failed. ret=%d", ip.c_str(), port, ret); return ret; } } @@ -931,9 +942,14 @@ int SrsServer::listen_http_stream() SrsListener* listener = new SrsStreamListener(this, SrsListenerHttpStream); listeners.push_back(listener); - int port = _srs_config->get_http_stream_listen(); - if ((ret = listener->listen(port)) != ERROR_SUCCESS) { - srs_error("HTTP stream listen at port %d failed. ret=%d", port, ret); + std::string ep = _srs_config->get_http_stream_listen(); + + std::string ip; + int port; + srs_parse_endpoint(ep, ip, port); + + if ((ret = listener->listen(ip, port)) != ERROR_SUCCESS) { + srs_error("HTTP stream listen at %s:%d failed. ret=%d", ip.c_str(), port, ret); return ret; } } diff --git a/trunk/src/app/srs_app_server.hpp b/trunk/src/app/srs_app_server.hpp index 9a9314c61..f6279e608 100644 --- a/trunk/src/app/srs_app_server.hpp +++ b/trunk/src/app/srs_app_server.hpp @@ -76,6 +76,7 @@ class SrsListener protected: SrsListenerType _type; protected: + std::string _ip; int _port; SrsServer* _server; public: @@ -83,7 +84,7 @@ public: virtual ~SrsListener(); public: virtual SrsListenerType type(); - virtual int listen(int port) = 0; + virtual int listen(std::string ip, int port) = 0; }; /** @@ -97,7 +98,7 @@ public: SrsStreamListener(SrsServer* server, SrsListenerType type); virtual ~SrsStreamListener(); public: - virtual int listen(int port); + virtual int listen(std::string ip, int port); // ISrsTcpHandler public: virtual int on_tcp_client(st_netfd_t stfd); @@ -116,7 +117,7 @@ public: SrsRtspListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c); virtual ~SrsRtspListener(); public: - virtual int listen(int port); + virtual int listen(std::string ip, int port); // ISrsTcpHandler public: virtual int on_tcp_client(st_netfd_t stfd); @@ -134,7 +135,7 @@ public: SrsUdpCasterListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c); virtual ~SrsUdpCasterListener(); public: - virtual int listen(int port); + virtual int listen(std::string ip, int port); }; #endif diff --git a/trunk/src/app/srs_app_utility.cpp b/trunk/src/app/srs_app_utility.cpp index fac242e7b..d5ac6abed 100644 --- a/trunk/src/app/srs_app_utility.cpp +++ b/trunk/src/app/srs_app_utility.cpp @@ -110,6 +110,25 @@ int srs_get_log_level(string level) } } +void srs_parse_endpoint(string ip_port, string& ip, string& port) +{ + ip = "0.0.0.0"; + port = ip_port; + + size_t pos = string::npos; + if ((pos = port.find(":")) != string::npos) { + ip = port.substr(0, pos); + port = port.substr(pos + 1); + } +} + +void srs_parse_endpoint(string ip_port, string& ip, int& port) +{ + std::string the_port; + srs_parse_endpoint(ip_port, ip, the_port); + port = ::atoi(the_port.c_str()); +} + static SrsRusage _srs_system_rusage; SrsRusage::SrsRusage() diff --git a/trunk/src/app/srs_app_utility.hpp b/trunk/src/app/srs_app_utility.hpp index 34e3eccbb..150ce71ca 100644 --- a/trunk/src/app/srs_app_utility.hpp +++ b/trunk/src/app/srs_app_utility.hpp @@ -50,6 +50,13 @@ extern int srs_socket_connect(std::string server, int port, int64_t timeout, st_ */ extern int srs_get_log_level(std::string level); +/** +* parse the endpoint to ip and port. +* @param ip_port the ip and port which formats in <[ip:]port> + */ +extern void srs_parse_endpoint(std::string ip_port, std::string& ip, std::string& port); +extern void srs_parse_endpoint(std::string ip_port, std::string& ip, int& port); + // current process resouce usage. // @see: man getrusage class SrsRusage diff --git a/trunk/src/core/srs_core.hpp b/trunk/src/core/srs_core.hpp index 90e91e8e9..75bf53d7a 100644 --- a/trunk/src/core/srs_core.hpp +++ b/trunk/src/core/srs_core.hpp @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. // current release version #define VERSION_MAJOR 2 #define VERSION_MINOR 0 -#define VERSION_REVISION 147 +#define VERSION_REVISION 148 // server info. #define RTMP_SIG_SRS_KEY "SRS"