正在显示
12 个修改的文件
包含
148 行增加
和
83 行删除
@@ -3,7 +3,9 @@ | @@ -3,7 +3,9 @@ | ||
3 | ############################################################################################# | 3 | ############################################################################################# |
4 | # RTMP sections | 4 | # RTMP sections |
5 | ############################################################################################# | 5 | ############################################################################################# |
6 | -# the rtmp listen ports, split by space. | 6 | +# the rtmp listen ports, split by space, each listen entry is <[ip:]port> |
7 | +# for example, 192.168.1.100:1935 10.10.10.100:1935 | ||
8 | +# where the ip is optional, default to 0.0.0.0, that is 1935 equals to 0.0.0.0:1935 | ||
7 | listen 1935; | 9 | listen 1935; |
8 | # the pid file | 10 | # the pid file |
9 | # to ensure only one process can use a pid file | 11 | # to ensure only one process can use a pid file |
@@ -106,7 +108,9 @@ http_api { | @@ -106,7 +108,9 @@ http_api { | ||
106 | # whether http api is enabled. | 108 | # whether http api is enabled. |
107 | # default: off | 109 | # default: off |
108 | enabled on; | 110 | enabled on; |
109 | - # the http api port | 111 | + # the http api listen entry is <[ip:]port> |
112 | + # for example, 192.168.1.100:1985 | ||
113 | + # where the ip is optional, default to 0.0.0.0, that is 1985 equals to 0.0.0.0:1985 | ||
110 | # default: 1985 | 114 | # default: 1985 |
111 | listen 1985; | 115 | listen 1985; |
112 | # whether enable crossdomain request. | 116 | # whether enable crossdomain request. |
@@ -127,7 +131,9 @@ http_server { | @@ -127,7 +131,9 @@ http_server { | ||
127 | # whether http streaming service is enabled. | 131 | # whether http streaming service is enabled. |
128 | # default: off | 132 | # default: off |
129 | enabled on; | 133 | enabled on; |
130 | - # the http streaming port | 134 | + # the http streaming listen entry is <[ip:]port> |
135 | + # for example, 192.168.1.100:8080 | ||
136 | + # where the ip is optional, default to 0.0.0.0, that is 8080 equals to 0.0.0.0:8080 | ||
131 | # @remark, if use lower port, for instance 80, user must start srs by root. | 137 | # @remark, if use lower port, for instance 80, user must start srs by root. |
132 | # default: 8080 | 138 | # default: 8080 |
133 | listen 8080; | 139 | listen 8080; |
@@ -162,6 +168,7 @@ stream_caster { | @@ -162,6 +168,7 @@ stream_caster { | ||
162 | # the listen port for stream caster. | 168 | # the listen port for stream caster. |
163 | # for mpegts_over_udp caster, listen at udp port. for example, 8935. | 169 | # for mpegts_over_udp caster, listen at udp port. for example, 8935. |
164 | # for rtsp caster, listen at tcp port. for example, 554. | 170 | # for rtsp caster, listen at tcp port. for example, 554. |
171 | + # TODO: support listen at <[ip:]port> | ||
165 | listen 8935; | 172 | listen 8935; |
166 | # for the rtsp caster, the rtp server local port over udp, | 173 | # for the rtsp caster, the rtp server local port over udp, |
167 | # which reply the rtsp setup request message, the port will be used: | 174 | # which reply the rtsp setup request message, the port will be used: |
@@ -1586,7 +1586,7 @@ int SrsConfig::check_config() | @@ -1586,7 +1586,7 @@ int SrsConfig::check_config() | ||
1586 | // check listen for rtmp. | 1586 | // check listen for rtmp. |
1587 | //////////////////////////////////////////////////////////////////////// | 1587 | //////////////////////////////////////////////////////////////////////// |
1588 | if (true) { | 1588 | if (true) { |
1589 | - vector<string> listens = get_listen(); | 1589 | + vector<string> listens = get_listens(); |
1590 | if (listens.size() <= 0) { | 1590 | if (listens.size() <= 0) { |
1591 | ret = ERROR_SYSTEM_CONFIG_INVALID; | 1591 | ret = ERROR_SYSTEM_CONFIG_INVALID; |
1592 | srs_error("directive \"listen\" is empty, ret=%d", ret); | 1592 | srs_error("directive \"listen\" is empty, ret=%d", ret); |
@@ -1613,11 +1613,11 @@ int SrsConfig::check_config() | @@ -1613,11 +1613,11 @@ int SrsConfig::check_config() | ||
1613 | 1613 | ||
1614 | // check max connections of system limits | 1614 | // check max connections of system limits |
1615 | if (true) { | 1615 | if (true) { |
1616 | - int nb_consumed_fds = (int)get_listen().size(); | ||
1617 | - if (get_http_api_listen() > 0) { | 1616 | + int nb_consumed_fds = (int)get_listens().size(); |
1617 | + if (!get_http_api_listen().empty()) { | ||
1618 | nb_consumed_fds++; | 1618 | nb_consumed_fds++; |
1619 | } | 1619 | } |
1620 | - if (get_http_stream_listen() > 0) { | 1620 | + if (!get_http_stream_listen().empty()) { |
1621 | nb_consumed_fds++; | 1621 | nb_consumed_fds++; |
1622 | } | 1622 | } |
1623 | if (get_log_tank_file()) { | 1623 | if (get_log_tank_file()) { |
@@ -1694,20 +1694,20 @@ int SrsConfig::check_config() | @@ -1694,20 +1694,20 @@ int SrsConfig::check_config() | ||
1694 | //////////////////////////////////////////////////////////////////////// | 1694 | //////////////////////////////////////////////////////////////////////// |
1695 | // check http api | 1695 | // check http api |
1696 | //////////////////////////////////////////////////////////////////////// | 1696 | //////////////////////////////////////////////////////////////////////// |
1697 | - if (get_http_api_listen() <= 0) { | 1697 | + if (get_http_api_listen().empty()) { |
1698 | ret = ERROR_SYSTEM_CONFIG_INVALID; | 1698 | ret = ERROR_SYSTEM_CONFIG_INVALID; |
1699 | - srs_error("directive http_api listen invalid, listen=%d, ret=%d", | ||
1700 | - get_http_api_listen(), ret); | 1699 | + srs_error("directive http_api listen invalid, listen=%s, ret=%d", |
1700 | + get_http_api_listen().c_str(), ret); | ||
1701 | return ret; | 1701 | return ret; |
1702 | } | 1702 | } |
1703 | 1703 | ||
1704 | //////////////////////////////////////////////////////////////////////// | 1704 | //////////////////////////////////////////////////////////////////////// |
1705 | // check http stream | 1705 | // check http stream |
1706 | //////////////////////////////////////////////////////////////////////// | 1706 | //////////////////////////////////////////////////////////////////////// |
1707 | - if (get_http_stream_listen() <= 0) { | 1707 | + if (get_http_stream_listen().empty()) { |
1708 | ret = ERROR_SYSTEM_CONFIG_INVALID; | 1708 | ret = ERROR_SYSTEM_CONFIG_INVALID; |
1709 | - srs_error("directive http_stream listen invalid, listen=%d, ret=%d", | ||
1710 | - get_http_stream_listen(), ret); | 1709 | + srs_error("directive http_stream listen invalid, listen=%s, ret=%d", |
1710 | + get_http_stream_listen().c_str(), ret); | ||
1711 | return ret; | 1711 | return ret; |
1712 | } | 1712 | } |
1713 | 1713 | ||
@@ -1858,7 +1858,7 @@ int SrsConfig::get_max_connections() | @@ -1858,7 +1858,7 @@ int SrsConfig::get_max_connections() | ||
1858 | return ::atoi(conf->arg0().c_str()); | 1858 | return ::atoi(conf->arg0().c_str()); |
1859 | } | 1859 | } |
1860 | 1860 | ||
1861 | -vector<string> SrsConfig::get_listen() | 1861 | +vector<string> SrsConfig::get_listens() |
1862 | { | 1862 | { |
1863 | std::vector<string> ports; | 1863 | std::vector<string> ports; |
1864 | 1864 | ||
@@ -3546,7 +3546,7 @@ bool SrsConfig::get_http_api_enabled(SrsConfDirective* conf) | @@ -3546,7 +3546,7 @@ bool SrsConfig::get_http_api_enabled(SrsConfDirective* conf) | ||
3546 | return false; | 3546 | return false; |
3547 | } | 3547 | } |
3548 | 3548 | ||
3549 | -int SrsConfig::get_http_api_listen() | 3549 | +string SrsConfig::get_http_api_listen() |
3550 | { | 3550 | { |
3551 | SrsConfDirective* conf = get_http_api(); | 3551 | SrsConfDirective* conf = get_http_api(); |
3552 | 3552 | ||
@@ -3559,7 +3559,7 @@ int SrsConfig::get_http_api_listen() | @@ -3559,7 +3559,7 @@ int SrsConfig::get_http_api_listen() | ||
3559 | return SRS_CONF_DEFAULT_HTTP_API_PORT; | 3559 | return SRS_CONF_DEFAULT_HTTP_API_PORT; |
3560 | } | 3560 | } |
3561 | 3561 | ||
3562 | - return ::atoi(conf->arg0().c_str()); | 3562 | + return conf->arg0(); |
3563 | } | 3563 | } |
3564 | 3564 | ||
3565 | bool SrsConfig::get_http_api_crossdomain() | 3565 | bool SrsConfig::get_http_api_crossdomain() |
@@ -3609,7 +3609,7 @@ bool SrsConfig::get_http_stream_enabled(SrsConfDirective* conf) | @@ -3609,7 +3609,7 @@ bool SrsConfig::get_http_stream_enabled(SrsConfDirective* conf) | ||
3609 | return false; | 3609 | return false; |
3610 | } | 3610 | } |
3611 | 3611 | ||
3612 | -int SrsConfig::get_http_stream_listen() | 3612 | +string SrsConfig::get_http_stream_listen() |
3613 | { | 3613 | { |
3614 | SrsConfDirective* conf = get_http_stream(); | 3614 | SrsConfDirective* conf = get_http_stream(); |
3615 | 3615 | ||
@@ -3622,7 +3622,7 @@ int SrsConfig::get_http_stream_listen() | @@ -3622,7 +3622,7 @@ int SrsConfig::get_http_stream_listen() | ||
3622 | return SRS_CONF_DEFAULT_HTTP_STREAM_PORT; | 3622 | return SRS_CONF_DEFAULT_HTTP_STREAM_PORT; |
3623 | } | 3623 | } |
3624 | 3624 | ||
3625 | - return ::atoi(conf->arg0().c_str()); | 3625 | + return conf->arg0(); |
3626 | } | 3626 | } |
3627 | 3627 | ||
3628 | string SrsConfig::get_http_stream_dir() | 3628 | string SrsConfig::get_http_stream_dir() |
@@ -77,8 +77,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -77,8 +77,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
77 | #define SRS_CONF_DEFAULT_HTTP_DIR SRS_CONF_DEFAULT_HLS_PATH | 77 | #define SRS_CONF_DEFAULT_HTTP_DIR SRS_CONF_DEFAULT_HLS_PATH |
78 | #define SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE 0 | 78 | #define SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE 0 |
79 | 79 | ||
80 | -#define SRS_CONF_DEFAULT_HTTP_STREAM_PORT 8080 | ||
81 | -#define SRS_CONF_DEFAULT_HTTP_API_PORT 1985 | 80 | +#define SRS_CONF_DEFAULT_HTTP_STREAM_PORT "8080" |
81 | +#define SRS_CONF_DEFAULT_HTTP_API_PORT "1985" | ||
82 | #define SRS_CONF_DEFAULT_HTTP_API_CROSSDOMAIN true | 82 | #define SRS_CONF_DEFAULT_HTTP_API_CROSSDOMAIN true |
83 | 83 | ||
84 | #define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_ENABLED false | 84 | #define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_ENABLED false |
@@ -411,7 +411,7 @@ public: | @@ -411,7 +411,7 @@ public: | ||
411 | * user can specifies multiple listen ports, | 411 | * user can specifies multiple listen ports, |
412 | * each args of directive is a listen port. | 412 | * each args of directive is a listen port. |
413 | */ | 413 | */ |
414 | - virtual std::vector<std::string> get_listen(); | 414 | + virtual std::vector<std::string> get_listens(); |
415 | /** | 415 | /** |
416 | * get the pid file path. | 416 | * get the pid file path. |
417 | * the pid file is used to save the pid of SRS, | 417 | * the pid file is used to save the pid of SRS, |
@@ -990,7 +990,7 @@ public: | @@ -990,7 +990,7 @@ public: | ||
990 | /** | 990 | /** |
991 | * get the http api listen port. | 991 | * get the http api listen port. |
992 | */ | 992 | */ |
993 | - virtual int get_http_api_listen(); | 993 | + virtual std::string get_http_api_listen(); |
994 | /** | 994 | /** |
995 | * whether enable crossdomain for http api. | 995 | * whether enable crossdomain for http api. |
996 | */ | 996 | */ |
@@ -1013,7 +1013,7 @@ public: | @@ -1013,7 +1013,7 @@ public: | ||
1013 | /** | 1013 | /** |
1014 | * get the http stream listen port. | 1014 | * get the http stream listen port. |
1015 | */ | 1015 | */ |
1016 | - virtual int get_http_stream_listen(); | 1016 | + virtual std::string get_http_stream_listen(); |
1017 | /** | 1017 | /** |
1018 | * get the http stream root dir. | 1018 | * get the http stream root dir. |
1019 | */ | 1019 | */ |
@@ -33,6 +33,7 @@ using namespace std; | @@ -33,6 +33,7 @@ using namespace std; | ||
33 | #include <srs_app_ffmpeg.hpp> | 33 | #include <srs_app_ffmpeg.hpp> |
34 | #include <srs_app_pithy_print.hpp> | 34 | #include <srs_app_pithy_print.hpp> |
35 | #include <srs_kernel_utility.hpp> | 35 | #include <srs_kernel_utility.hpp> |
36 | +#include <srs_app_utility.hpp> | ||
36 | 37 | ||
37 | // when error, ingester sleep for a while and retry. | 38 | // when error, ingester sleep for a while and retry. |
38 | // ingest never sleep a long time, for we must start the stream ASAP. | 39 | // 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 | @@ -228,9 +229,15 @@ int SrsIngester::initialize_ffmpeg(SrsFFMPEG* ffmpeg, SrsConfDirective* vhost, S | ||
228 | { | 229 | { |
229 | int ret = ERROR_SUCCESS; | 230 | int ret = ERROR_SUCCESS; |
230 | 231 | ||
231 | - std::vector<std::string> ports = _srs_config->get_listen(); | ||
232 | - srs_assert(ports.size() > 0); | ||
233 | - std::string port = ports[0]; | 232 | + std::string port; |
233 | + if (true) { | ||
234 | + std::vector<std::string> ip_ports = _srs_config->get_listens(); | ||
235 | + srs_assert(ip_ports.size() > 0); | ||
236 | + | ||
237 | + std::string ep = ip_ports[0]; | ||
238 | + std::string ip; | ||
239 | + srs_parse_endpoint(ep, ip, port); | ||
240 | + } | ||
234 | 241 | ||
235 | std::string output = _srs_config->get_engine_output(engine); | 242 | std::string output = _srs_config->get_engine_output(engine); |
236 | // output stream, to other/self server | 243 | // output stream, to other/self server |
@@ -30,6 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -30,6 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
30 | #include <sys/types.h> | 30 | #include <sys/types.h> |
31 | #include <sys/stat.h> | 31 | #include <sys/stat.h> |
32 | #include <fcntl.h> | 32 | #include <fcntl.h> |
33 | +using namespace std; | ||
33 | 34 | ||
34 | #include <srs_kernel_log.hpp> | 35 | #include <srs_kernel_log.hpp> |
35 | #include <srs_kernel_error.hpp> | 36 | #include <srs_kernel_error.hpp> |
@@ -61,9 +62,10 @@ ISrsTcpHandler::~ISrsTcpHandler() | @@ -61,9 +62,10 @@ ISrsTcpHandler::~ISrsTcpHandler() | ||
61 | { | 62 | { |
62 | } | 63 | } |
63 | 64 | ||
64 | -SrsUdpListener::SrsUdpListener(ISrsUdpHandler* h, int p) | 65 | +SrsUdpListener::SrsUdpListener(ISrsUdpHandler* h, string i, int p) |
65 | { | 66 | { |
66 | handler = h; | 67 | handler = h; |
68 | + ip = i; | ||
67 | port = p; | 69 | port = p; |
68 | 70 | ||
69 | _fd = -1; | 71 | _fd = -1; |
@@ -101,42 +103,42 @@ int SrsUdpListener::listen() | @@ -101,42 +103,42 @@ int SrsUdpListener::listen() | ||
101 | 103 | ||
102 | if ((_fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { | 104 | if ((_fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { |
103 | ret = ERROR_SOCKET_CREATE; | 105 | ret = ERROR_SOCKET_CREATE; |
104 | - srs_error("create linux socket error. port=%d, ret=%d", port, ret); | 106 | + srs_error("create linux socket error. port=%d, ret=%d", ip.c_str(), port, ret); |
105 | return ret; | 107 | return ret; |
106 | } | 108 | } |
107 | - srs_verbose("create linux socket success. port=%d, fd=%d", port, _fd); | 109 | + srs_verbose("create linux socket success. port=%d, fd=%d", ip.c_str(), port, _fd); |
108 | 110 | ||
109 | int reuse_socket = 1; | 111 | int reuse_socket = 1; |
110 | if (setsockopt(_fd, SOL_SOCKET, SO_REUSEADDR, &reuse_socket, sizeof(int)) == -1) { | 112 | if (setsockopt(_fd, SOL_SOCKET, SO_REUSEADDR, &reuse_socket, sizeof(int)) == -1) { |
111 | ret = ERROR_SOCKET_SETREUSE; | 113 | ret = ERROR_SOCKET_SETREUSE; |
112 | - srs_error("setsockopt reuse-addr error. port=%d, ret=%d", port, ret); | 114 | + srs_error("setsockopt reuse-addr error. port=%d, ret=%d", ip.c_str(), port, ret); |
113 | return ret; | 115 | return ret; |
114 | } | 116 | } |
115 | - srs_verbose("setsockopt reuse-addr success. port=%d, fd=%d", port, _fd); | 117 | + srs_verbose("setsockopt reuse-addr success. port=%d, fd=%d", ip.c_str(), port, _fd); |
116 | 118 | ||
117 | sockaddr_in addr; | 119 | sockaddr_in addr; |
118 | addr.sin_family = AF_INET; | 120 | addr.sin_family = AF_INET; |
119 | addr.sin_port = htons(port); | 121 | addr.sin_port = htons(port); |
120 | - addr.sin_addr.s_addr = INADDR_ANY; | 122 | + addr.sin_addr.s_addr = inet_addr(ip.c_str()); |
121 | if (bind(_fd, (const sockaddr*)&addr, sizeof(sockaddr_in)) == -1) { | 123 | if (bind(_fd, (const sockaddr*)&addr, sizeof(sockaddr_in)) == -1) { |
122 | ret = ERROR_SOCKET_BIND; | 124 | ret = ERROR_SOCKET_BIND; |
123 | - srs_error("bind socket error. port=%d, ret=%d", port, ret); | 125 | + srs_error("bind socket error. ep=%s:%d, ret=%d", ip.c_str(), port, ret); |
124 | return ret; | 126 | return ret; |
125 | } | 127 | } |
126 | - srs_verbose("bind socket success. port=%d, fd=%d", port, _fd); | 128 | + srs_verbose("bind socket success. ep=%s:%d, fd=%d", ip.c_str(), port, _fd); |
127 | 129 | ||
128 | if ((stfd = st_netfd_open_socket(_fd)) == NULL){ | 130 | if ((stfd = st_netfd_open_socket(_fd)) == NULL){ |
129 | ret = ERROR_ST_OPEN_SOCKET; | 131 | ret = ERROR_ST_OPEN_SOCKET; |
130 | - srs_error("st_netfd_open_socket open socket failed. port=%d, ret=%d", port, ret); | 132 | + srs_error("st_netfd_open_socket open socket failed. ep=%s:%d, ret=%d", ip.c_str(), port, ret); |
131 | return ret; | 133 | return ret; |
132 | } | 134 | } |
133 | - srs_verbose("st open socket success. port=%d, fd=%d", port, _fd); | 135 | + srs_verbose("st open socket success. ep=%s:%d, fd=%d", ip.c_str(), port, _fd); |
134 | 136 | ||
135 | if ((ret = pthread->start()) != ERROR_SUCCESS) { | 137 | if ((ret = pthread->start()) != ERROR_SUCCESS) { |
136 | - srs_error("st_thread_create listen thread error. port=%d, ret=%d", port, ret); | 138 | + srs_error("st_thread_create listen thread error. ep=%s:%d, ret=%d", ip.c_str(), port, ret); |
137 | return ret; | 139 | return ret; |
138 | } | 140 | } |
139 | - srs_verbose("create st listen thread success, port=%d", port); | 141 | + srs_verbose("create st listen thread success, ep=%s:%d", ip.c_str(), port); |
140 | 142 | ||
141 | return ret; | 143 | return ret; |
142 | } | 144 | } |
@@ -169,9 +171,10 @@ int SrsUdpListener::cycle() | @@ -169,9 +171,10 @@ int SrsUdpListener::cycle() | ||
169 | return ret; | 171 | return ret; |
170 | } | 172 | } |
171 | 173 | ||
172 | -SrsTcpListener::SrsTcpListener(ISrsTcpHandler* h, int p) | 174 | +SrsTcpListener::SrsTcpListener(ISrsTcpHandler* h, string i, int p) |
173 | { | 175 | { |
174 | handler = h; | 176 | handler = h; |
177 | + ip = i; | ||
175 | port = p; | 178 | port = p; |
176 | 179 | ||
177 | _fd = -1; | 180 | _fd = -1; |
@@ -220,33 +223,33 @@ int SrsTcpListener::listen() | @@ -220,33 +223,33 @@ int SrsTcpListener::listen() | ||
220 | sockaddr_in addr; | 223 | sockaddr_in addr; |
221 | addr.sin_family = AF_INET; | 224 | addr.sin_family = AF_INET; |
222 | addr.sin_port = htons(port); | 225 | addr.sin_port = htons(port); |
223 | - addr.sin_addr.s_addr = INADDR_ANY; | 226 | + addr.sin_addr.s_addr = inet_addr(ip.c_str()); |
224 | if (bind(_fd, (const sockaddr*)&addr, sizeof(sockaddr_in)) == -1) { | 227 | if (bind(_fd, (const sockaddr*)&addr, sizeof(sockaddr_in)) == -1) { |
225 | ret = ERROR_SOCKET_BIND; | 228 | ret = ERROR_SOCKET_BIND; |
226 | - srs_error("bind socket error. port=%d, ret=%d", port, ret); | 229 | + srs_error("bind socket error. ep=%s:%d, ret=%d", ip.c_str(), port, ret); |
227 | return ret; | 230 | return ret; |
228 | } | 231 | } |
229 | - srs_verbose("bind socket success. port=%d, fd=%d", port, _fd); | 232 | + srs_verbose("bind socket success. ep=%s:%d, fd=%d", ip.c_str(), port, _fd); |
230 | 233 | ||
231 | if (::listen(_fd, SERVER_LISTEN_BACKLOG) == -1) { | 234 | if (::listen(_fd, SERVER_LISTEN_BACKLOG) == -1) { |
232 | ret = ERROR_SOCKET_LISTEN; | 235 | ret = ERROR_SOCKET_LISTEN; |
233 | - srs_error("listen socket error. port=%d, ret=%d", port, ret); | 236 | + srs_error("listen socket error. ep=%s:%d, ret=%d", ip.c_str(), port, ret); |
234 | return ret; | 237 | return ret; |
235 | } | 238 | } |
236 | - srs_verbose("listen socket success. port=%d, fd=%d", port, _fd); | 239 | + srs_verbose("listen socket success. ep=%s:%d, fd=%d", ip.c_str(), port, _fd); |
237 | 240 | ||
238 | if ((stfd = st_netfd_open_socket(_fd)) == NULL){ | 241 | if ((stfd = st_netfd_open_socket(_fd)) == NULL){ |
239 | ret = ERROR_ST_OPEN_SOCKET; | 242 | ret = ERROR_ST_OPEN_SOCKET; |
240 | - srs_error("st_netfd_open_socket open socket failed. port=%d, ret=%d", port, ret); | 243 | + srs_error("st_netfd_open_socket open socket failed. ep=%s:%d, ret=%d", ip.c_str(), port, ret); |
241 | return ret; | 244 | return ret; |
242 | } | 245 | } |
243 | - srs_verbose("st open socket success. port=%d, fd=%d", port, _fd); | 246 | + srs_verbose("st open socket success. ep=%s:%d, fd=%d", ip.c_str(), port, _fd); |
244 | 247 | ||
245 | if ((ret = pthread->start()) != ERROR_SUCCESS) { | 248 | if ((ret = pthread->start()) != ERROR_SUCCESS) { |
246 | - srs_error("st_thread_create listen thread error. port=%d, ret=%d", port, ret); | 249 | + srs_error("st_thread_create listen thread error. ep=%s:%d, ret=%d", ip.c_str(), port, ret); |
247 | return ret; | 250 | return ret; |
248 | } | 251 | } |
249 | - srs_verbose("create st listen thread success, port=%d", port); | 252 | + srs_verbose("create st listen thread success, ep=%s:%d", ip.c_str(), port); |
250 | 253 | ||
251 | return ret; | 254 | return ret; |
252 | } | 255 | } |
@@ -30,6 +30,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -30,6 +30,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
30 | 30 | ||
31 | #include <srs_core.hpp> | 31 | #include <srs_core.hpp> |
32 | 32 | ||
33 | +#include <string> | ||
34 | + | ||
33 | #include <srs_app_st.hpp> | 35 | #include <srs_app_st.hpp> |
34 | #include <srs_app_thread.hpp> | 36 | #include <srs_app_thread.hpp> |
35 | 37 | ||
@@ -85,9 +87,10 @@ private: | @@ -85,9 +87,10 @@ private: | ||
85 | int nb_buf; | 87 | int nb_buf; |
86 | private: | 88 | private: |
87 | ISrsUdpHandler* handler; | 89 | ISrsUdpHandler* handler; |
90 | + std::string ip; | ||
88 | int port; | 91 | int port; |
89 | public: | 92 | public: |
90 | - SrsUdpListener(ISrsUdpHandler* h, int p); | 93 | + SrsUdpListener(ISrsUdpHandler* h, std::string i, int p); |
91 | virtual ~SrsUdpListener(); | 94 | virtual ~SrsUdpListener(); |
92 | public: | 95 | public: |
93 | virtual int fd(); | 96 | virtual int fd(); |
@@ -109,9 +112,10 @@ private: | @@ -109,9 +112,10 @@ private: | ||
109 | SrsThread* pthread; | 112 | SrsThread* pthread; |
110 | private: | 113 | private: |
111 | ISrsTcpHandler* handler; | 114 | ISrsTcpHandler* handler; |
115 | + std::string ip; | ||
112 | int port; | 116 | int port; |
113 | public: | 117 | public: |
114 | - SrsTcpListener(ISrsTcpHandler* h, int p); | 118 | + SrsTcpListener(ISrsTcpHandler* h, std::string i, int p); |
115 | virtual ~SrsTcpListener(); | 119 | virtual ~SrsTcpListener(); |
116 | public: | 120 | public: |
117 | virtual int fd(); | 121 | virtual int fd(); |
@@ -50,7 +50,8 @@ SrsRtpConn::SrsRtpConn(SrsRtspConn* r, int p, int sid) | @@ -50,7 +50,8 @@ SrsRtpConn::SrsRtpConn(SrsRtspConn* r, int p, int sid) | ||
50 | rtsp = r; | 50 | rtsp = r; |
51 | _port = p; | 51 | _port = p; |
52 | stream_id = sid; | 52 | stream_id = sid; |
53 | - listener = new SrsUdpListener(this, p); | 53 | + // TODO: support listen at <[ip:]port> |
54 | + listener = new SrsUdpListener(this, "0.0.0.0", p); | ||
54 | cache = new SrsRtpPacket(); | 55 | cache = new SrsRtpPacket(); |
55 | pprint = SrsPithyPrint::create_caster(); | 56 | pprint = SrsPithyPrint::create_caster(); |
56 | } | 57 | } |
@@ -136,14 +136,15 @@ SrsStreamListener::~SrsStreamListener() | @@ -136,14 +136,15 @@ SrsStreamListener::~SrsStreamListener() | ||
136 | srs_freep(listener); | 136 | srs_freep(listener); |
137 | } | 137 | } |
138 | 138 | ||
139 | -int SrsStreamListener::listen(int port) | 139 | +int SrsStreamListener::listen(string ip, int port) |
140 | { | 140 | { |
141 | int ret = ERROR_SUCCESS; | 141 | int ret = ERROR_SUCCESS; |
142 | 142 | ||
143 | + _ip = ip; | ||
143 | _port = port; | 144 | _port = port; |
144 | 145 | ||
145 | srs_freep(listener); | 146 | srs_freep(listener); |
146 | - listener = new SrsTcpListener(this, port); | 147 | + listener = new SrsTcpListener(this, ip, port); |
147 | 148 | ||
148 | if ((ret = listener->listen()) != ERROR_SUCCESS) { | 149 | if ((ret = listener->listen()) != ERROR_SUCCESS) { |
149 | srs_error("tcp listen failed. ret=%d", ret); | 150 | srs_error("tcp listen failed. ret=%d", ret); |
@@ -151,10 +152,10 @@ int SrsStreamListener::listen(int port) | @@ -151,10 +152,10 @@ int SrsStreamListener::listen(int port) | ||
151 | } | 152 | } |
152 | 153 | ||
153 | srs_info("listen thread cid=%d, current_cid=%d, " | 154 | srs_info("listen thread cid=%d, current_cid=%d, " |
154 | - "listen at port=%d, type=%d, fd=%d started success, port=%d", | ||
155 | - pthread->cid(), _srs_context->get_id(), _port, _type, fd, port); | 155 | + "listen at port=%d, type=%d, fd=%d started success, ep=%s:%d", |
156 | + pthread->cid(), _srs_context->get_id(), _port, _type, fd, ip.c_str(), port); | ||
156 | 157 | ||
157 | - srs_trace("%s listen at tcp://%d, fd=%d", srs_listener_type2string(_type).c_str(), _port, listener->fd()); | 158 | + srs_trace("%s listen at tcp://%s:%d, fd=%d", srs_listener_type2string(_type).c_str(), ip.c_str(), _port, listener->fd()); |
158 | 159 | ||
159 | return ret; | 160 | return ret; |
160 | } | 161 | } |
@@ -190,7 +191,7 @@ SrsRtspListener::~SrsRtspListener() | @@ -190,7 +191,7 @@ SrsRtspListener::~SrsRtspListener() | ||
190 | srs_freep(listener); | 191 | srs_freep(listener); |
191 | } | 192 | } |
192 | 193 | ||
193 | -int SrsRtspListener::listen(int port) | 194 | +int SrsRtspListener::listen(string ip, int port) |
194 | { | 195 | { |
195 | int ret = ERROR_SUCCESS; | 196 | int ret = ERROR_SUCCESS; |
196 | 197 | ||
@@ -198,10 +199,11 @@ int SrsRtspListener::listen(int port) | @@ -198,10 +199,11 @@ int SrsRtspListener::listen(int port) | ||
198 | // we just assert here for unknown stream caster. | 199 | // we just assert here for unknown stream caster. |
199 | srs_assert(_type == SrsListenerRtsp); | 200 | srs_assert(_type == SrsListenerRtsp); |
200 | 201 | ||
202 | + _ip = ip; | ||
201 | _port = port; | 203 | _port = port; |
202 | 204 | ||
203 | srs_freep(listener); | 205 | srs_freep(listener); |
204 | - listener = new SrsTcpListener(this, port); | 206 | + listener = new SrsTcpListener(this, ip, port); |
205 | 207 | ||
206 | if ((ret = listener->listen()) != ERROR_SUCCESS) { | 208 | if ((ret = listener->listen()) != ERROR_SUCCESS) { |
207 | srs_error("udp caster listen failed. ret=%d", ret); | 209 | srs_error("udp caster listen failed. ret=%d", ret); |
@@ -209,10 +211,10 @@ int SrsRtspListener::listen(int port) | @@ -209,10 +211,10 @@ int SrsRtspListener::listen(int port) | ||
209 | } | 211 | } |
210 | 212 | ||
211 | srs_info("listen thread cid=%d, current_cid=%d, " | 213 | srs_info("listen thread cid=%d, current_cid=%d, " |
212 | - "listen at port=%d, type=%d, fd=%d started success, port=%d", | ||
213 | - pthread->cid(), _srs_context->get_id(), _port, _type, fd, port); | 214 | + "listen at port=%d, type=%d, fd=%d started success, ep=%s:%d", |
215 | + pthread->cid(), _srs_context->get_id(), _port, _type, fd, ip.c_str(), port); | ||
214 | 216 | ||
215 | - srs_trace("%s listen at tcp://%d, fd=%d", srs_listener_type2string(_type).c_str(), _port, listener->fd()); | 217 | + srs_trace("%s listen at tcp://%s:%d, fd=%d", srs_listener_type2string(_type).c_str(), ip.c_str(), _port, listener->fd()); |
216 | 218 | ||
217 | return ret; | 219 | return ret; |
218 | } | 220 | } |
@@ -248,7 +250,7 @@ SrsUdpCasterListener::~SrsUdpCasterListener() | @@ -248,7 +250,7 @@ SrsUdpCasterListener::~SrsUdpCasterListener() | ||
248 | srs_freep(listener); | 250 | srs_freep(listener); |
249 | } | 251 | } |
250 | 252 | ||
251 | -int SrsUdpCasterListener::listen(int port) | 253 | +int SrsUdpCasterListener::listen(string ip, int port) |
252 | { | 254 | { |
253 | int ret = ERROR_SUCCESS; | 255 | int ret = ERROR_SUCCESS; |
254 | 256 | ||
@@ -256,10 +258,11 @@ int SrsUdpCasterListener::listen(int port) | @@ -256,10 +258,11 @@ int SrsUdpCasterListener::listen(int port) | ||
256 | // we just assert here for unknown stream caster. | 258 | // we just assert here for unknown stream caster. |
257 | srs_assert(_type == SrsListenerMpegTsOverUdp); | 259 | srs_assert(_type == SrsListenerMpegTsOverUdp); |
258 | 260 | ||
261 | + _ip = ip; | ||
259 | _port = port; | 262 | _port = port; |
260 | 263 | ||
261 | srs_freep(listener); | 264 | srs_freep(listener); |
262 | - listener = new SrsUdpListener(caster, port); | 265 | + listener = new SrsUdpListener(caster, ip, port); |
263 | 266 | ||
264 | if ((ret = listener->listen()) != ERROR_SUCCESS) { | 267 | if ((ret = listener->listen()) != ERROR_SUCCESS) { |
265 | srs_error("udp caster listen failed. ret=%d", ret); | 268 | srs_error("udp caster listen failed. ret=%d", ret); |
@@ -267,10 +270,10 @@ int SrsUdpCasterListener::listen(int port) | @@ -267,10 +270,10 @@ int SrsUdpCasterListener::listen(int port) | ||
267 | } | 270 | } |
268 | 271 | ||
269 | srs_info("listen thread cid=%d, current_cid=%d, " | 272 | srs_info("listen thread cid=%d, current_cid=%d, " |
270 | - "listen at port=%d, type=%d, fd=%d started success, port=%d", | ||
271 | - pthread->cid(), _srs_context->get_id(), _port, _type, fd, port); | 273 | + "listen at port=%d, type=%d, fd=%d started success, ep=%s:%d", |
274 | + pthread->cid(), _srs_context->get_id(), _port, _type, fd, ip.c_str(), port); | ||
272 | 275 | ||
273 | - srs_trace("%s listen at udp://%d, fd=%d", srs_listener_type2string(_type).c_str(), _port, listener->fd()); | 276 | + srs_trace("%s listen at udp://%s:%d, fd=%d", srs_listener_type2string(_type).c_str(), ip.c_str(), _port, listener->fd()); |
274 | 277 | ||
275 | return ret; | 278 | return ret; |
276 | } | 279 | } |
@@ -881,18 +884,21 @@ int SrsServer::listen_rtmp() | @@ -881,18 +884,21 @@ int SrsServer::listen_rtmp() | ||
881 | int ret = ERROR_SUCCESS; | 884 | int ret = ERROR_SUCCESS; |
882 | 885 | ||
883 | // stream service port. | 886 | // stream service port. |
884 | - std::vector<std::string> ports = _srs_config->get_listen(); | ||
885 | - srs_assert((int)ports.size() > 0); | 887 | + std::vector<std::string> ip_ports = _srs_config->get_listens(); |
888 | + srs_assert((int)ip_ports.size() > 0); | ||
886 | 889 | ||
887 | close_listeners(SrsListenerRtmpStream); | 890 | close_listeners(SrsListenerRtmpStream); |
888 | 891 | ||
889 | - for (int i = 0; i < (int)ports.size(); i++) { | 892 | + for (int i = 0; i < (int)ip_ports.size(); i++) { |
890 | SrsListener* listener = new SrsStreamListener(this, SrsListenerRtmpStream); | 893 | SrsListener* listener = new SrsStreamListener(this, SrsListenerRtmpStream); |
891 | listeners.push_back(listener); | 894 | listeners.push_back(listener); |
892 | 895 | ||
893 | - int port = ::atoi(ports[i].c_str()); | ||
894 | - if ((ret = listener->listen(port)) != ERROR_SUCCESS) { | ||
895 | - srs_error("RTMP stream listen at port %d failed. ret=%d", port, ret); | 896 | + std::string ip; |
897 | + int port; | ||
898 | + srs_parse_endpoint(ip_ports[i], ip, port); | ||
899 | + | ||
900 | + if ((ret = listener->listen(ip, port)) != ERROR_SUCCESS) { | ||
901 | + srs_error("RTMP stream listen at %s:%d failed. ret=%d", ip.c_str(), port, ret); | ||
896 | return ret; | 902 | return ret; |
897 | } | 903 | } |
898 | } | 904 | } |
@@ -910,9 +916,14 @@ int SrsServer::listen_http_api() | @@ -910,9 +916,14 @@ int SrsServer::listen_http_api() | ||
910 | SrsListener* listener = new SrsStreamListener(this, SrsListenerHttpApi); | 916 | SrsListener* listener = new SrsStreamListener(this, SrsListenerHttpApi); |
911 | listeners.push_back(listener); | 917 | listeners.push_back(listener); |
912 | 918 | ||
913 | - int port = _srs_config->get_http_api_listen(); | ||
914 | - if ((ret = listener->listen(port)) != ERROR_SUCCESS) { | ||
915 | - srs_error("HTTP api listen at port %d failed. ret=%d", port, ret); | 919 | + std::string ep = _srs_config->get_http_api_listen(); |
920 | + | ||
921 | + std::string ip; | ||
922 | + int port; | ||
923 | + srs_parse_endpoint(ep, ip, port); | ||
924 | + | ||
925 | + if ((ret = listener->listen(ip, port)) != ERROR_SUCCESS) { | ||
926 | + srs_error("HTTP api listen at %s:%d failed. ret=%d", ip.c_str(), port, ret); | ||
916 | return ret; | 927 | return ret; |
917 | } | 928 | } |
918 | } | 929 | } |
@@ -931,9 +942,14 @@ int SrsServer::listen_http_stream() | @@ -931,9 +942,14 @@ int SrsServer::listen_http_stream() | ||
931 | SrsListener* listener = new SrsStreamListener(this, SrsListenerHttpStream); | 942 | SrsListener* listener = new SrsStreamListener(this, SrsListenerHttpStream); |
932 | listeners.push_back(listener); | 943 | listeners.push_back(listener); |
933 | 944 | ||
934 | - int port = _srs_config->get_http_stream_listen(); | ||
935 | - if ((ret = listener->listen(port)) != ERROR_SUCCESS) { | ||
936 | - srs_error("HTTP stream listen at port %d failed. ret=%d", port, ret); | 945 | + std::string ep = _srs_config->get_http_stream_listen(); |
946 | + | ||
947 | + std::string ip; | ||
948 | + int port; | ||
949 | + srs_parse_endpoint(ep, ip, port); | ||
950 | + | ||
951 | + if ((ret = listener->listen(ip, port)) != ERROR_SUCCESS) { | ||
952 | + srs_error("HTTP stream listen at %s:%d failed. ret=%d", ip.c_str(), port, ret); | ||
937 | return ret; | 953 | return ret; |
938 | } | 954 | } |
939 | } | 955 | } |
@@ -76,6 +76,7 @@ class SrsListener | @@ -76,6 +76,7 @@ class SrsListener | ||
76 | protected: | 76 | protected: |
77 | SrsListenerType _type; | 77 | SrsListenerType _type; |
78 | protected: | 78 | protected: |
79 | + std::string _ip; | ||
79 | int _port; | 80 | int _port; |
80 | SrsServer* _server; | 81 | SrsServer* _server; |
81 | public: | 82 | public: |
@@ -83,7 +84,7 @@ public: | @@ -83,7 +84,7 @@ public: | ||
83 | virtual ~SrsListener(); | 84 | virtual ~SrsListener(); |
84 | public: | 85 | public: |
85 | virtual SrsListenerType type(); | 86 | virtual SrsListenerType type(); |
86 | - virtual int listen(int port) = 0; | 87 | + virtual int listen(std::string ip, int port) = 0; |
87 | }; | 88 | }; |
88 | 89 | ||
89 | /** | 90 | /** |
@@ -97,7 +98,7 @@ public: | @@ -97,7 +98,7 @@ public: | ||
97 | SrsStreamListener(SrsServer* server, SrsListenerType type); | 98 | SrsStreamListener(SrsServer* server, SrsListenerType type); |
98 | virtual ~SrsStreamListener(); | 99 | virtual ~SrsStreamListener(); |
99 | public: | 100 | public: |
100 | - virtual int listen(int port); | 101 | + virtual int listen(std::string ip, int port); |
101 | // ISrsTcpHandler | 102 | // ISrsTcpHandler |
102 | public: | 103 | public: |
103 | virtual int on_tcp_client(st_netfd_t stfd); | 104 | virtual int on_tcp_client(st_netfd_t stfd); |
@@ -116,7 +117,7 @@ public: | @@ -116,7 +117,7 @@ public: | ||
116 | SrsRtspListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c); | 117 | SrsRtspListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c); |
117 | virtual ~SrsRtspListener(); | 118 | virtual ~SrsRtspListener(); |
118 | public: | 119 | public: |
119 | - virtual int listen(int port); | 120 | + virtual int listen(std::string ip, int port); |
120 | // ISrsTcpHandler | 121 | // ISrsTcpHandler |
121 | public: | 122 | public: |
122 | virtual int on_tcp_client(st_netfd_t stfd); | 123 | virtual int on_tcp_client(st_netfd_t stfd); |
@@ -134,7 +135,7 @@ public: | @@ -134,7 +135,7 @@ public: | ||
134 | SrsUdpCasterListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c); | 135 | SrsUdpCasterListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c); |
135 | virtual ~SrsUdpCasterListener(); | 136 | virtual ~SrsUdpCasterListener(); |
136 | public: | 137 | public: |
137 | - virtual int listen(int port); | 138 | + virtual int listen(std::string ip, int port); |
138 | }; | 139 | }; |
139 | #endif | 140 | #endif |
140 | 141 |
@@ -110,6 +110,25 @@ int srs_get_log_level(string level) | @@ -110,6 +110,25 @@ int srs_get_log_level(string level) | ||
110 | } | 110 | } |
111 | } | 111 | } |
112 | 112 | ||
113 | +void srs_parse_endpoint(string ip_port, string& ip, string& port) | ||
114 | +{ | ||
115 | + ip = "0.0.0.0"; | ||
116 | + port = ip_port; | ||
117 | + | ||
118 | + size_t pos = string::npos; | ||
119 | + if ((pos = port.find(":")) != string::npos) { | ||
120 | + ip = port.substr(0, pos); | ||
121 | + port = port.substr(pos + 1); | ||
122 | + } | ||
123 | +} | ||
124 | + | ||
125 | +void srs_parse_endpoint(string ip_port, string& ip, int& port) | ||
126 | +{ | ||
127 | + std::string the_port; | ||
128 | + srs_parse_endpoint(ip_port, ip, the_port); | ||
129 | + port = ::atoi(the_port.c_str()); | ||
130 | +} | ||
131 | + | ||
113 | static SrsRusage _srs_system_rusage; | 132 | static SrsRusage _srs_system_rusage; |
114 | 133 | ||
115 | SrsRusage::SrsRusage() | 134 | SrsRusage::SrsRusage() |
@@ -50,6 +50,13 @@ extern int srs_socket_connect(std::string server, int port, int64_t timeout, st_ | @@ -50,6 +50,13 @@ extern int srs_socket_connect(std::string server, int port, int64_t timeout, st_ | ||
50 | */ | 50 | */ |
51 | extern int srs_get_log_level(std::string level); | 51 | extern int srs_get_log_level(std::string level); |
52 | 52 | ||
53 | +/** | ||
54 | +* parse the endpoint to ip and port. | ||
55 | +* @param ip_port the ip and port which formats in <[ip:]port> | ||
56 | + */ | ||
57 | +extern void srs_parse_endpoint(std::string ip_port, std::string& ip, std::string& port); | ||
58 | +extern void srs_parse_endpoint(std::string ip_port, std::string& ip, int& port); | ||
59 | + | ||
53 | // current process resouce usage. | 60 | // current process resouce usage. |
54 | // @see: man getrusage | 61 | // @see: man getrusage |
55 | class SrsRusage | 62 | class SrsRusage |
@@ -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 147 | 34 | +#define VERSION_REVISION 148 |
35 | 35 | ||
36 | // server info. | 36 | // server info. |
37 | #define RTMP_SIG_SRS_KEY "SRS" | 37 | #define RTMP_SIG_SRS_KEY "SRS" |
-
请 注册 或 登录 后发表评论