mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 11:51:57 +00:00
fix #149, RTMP/HTTP support bind to <[ip:]port>. 2.0.148
This commit is contained in:
commit
713cedfbb4
11 changed files with 147 additions and 82 deletions
|
@ -3,7 +3,9 @@
|
||||||
#############################################################################################
|
#############################################################################################
|
||||||
# RTMP sections
|
# 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;
|
listen 1935;
|
||||||
# the pid file
|
# the pid file
|
||||||
# to ensure only one process can use a pid file
|
# to ensure only one process can use a pid file
|
||||||
|
@ -106,7 +108,9 @@ http_api {
|
||||||
# whether http api is enabled.
|
# whether http api is enabled.
|
||||||
# default: off
|
# default: off
|
||||||
enabled on;
|
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
|
# default: 1985
|
||||||
listen 1985;
|
listen 1985;
|
||||||
# whether enable crossdomain request.
|
# whether enable crossdomain request.
|
||||||
|
@ -127,7 +131,9 @@ http_server {
|
||||||
# whether http streaming service is enabled.
|
# whether http streaming service is enabled.
|
||||||
# default: off
|
# default: off
|
||||||
enabled on;
|
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.
|
# @remark, if use lower port, for instance 80, user must start srs by root.
|
||||||
# default: 8080
|
# default: 8080
|
||||||
listen 8080;
|
listen 8080;
|
||||||
|
@ -162,6 +168,7 @@ stream_caster {
|
||||||
# the listen port for stream caster.
|
# the listen port for stream caster.
|
||||||
# for mpegts_over_udp caster, listen at udp port. for example, 8935.
|
# for mpegts_over_udp caster, listen at udp port. for example, 8935.
|
||||||
# for rtsp caster, listen at tcp port. for example, 554.
|
# for rtsp caster, listen at tcp port. for example, 554.
|
||||||
|
# TODO: support listen at <[ip:]port>
|
||||||
listen 8935;
|
listen 8935;
|
||||||
# for the rtsp caster, the rtp server local port over udp,
|
# for the rtsp caster, the rtp server local port over udp,
|
||||||
# which reply the rtsp setup request message, the port will be used:
|
# which reply the rtsp setup request message, the port will be used:
|
||||||
|
|
|
@ -1586,7 +1586,7 @@ int SrsConfig::check_config()
|
||||||
// check listen for rtmp.
|
// check listen for rtmp.
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
if (true) {
|
if (true) {
|
||||||
vector<string> listens = get_listen();
|
vector<string> listens = get_listens();
|
||||||
if (listens.size() <= 0) {
|
if (listens.size() <= 0) {
|
||||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||||
srs_error("directive \"listen\" is empty, ret=%d", ret);
|
srs_error("directive \"listen\" is empty, ret=%d", ret);
|
||||||
|
@ -1613,11 +1613,11 @@ int SrsConfig::check_config()
|
||||||
|
|
||||||
// check max connections of system limits
|
// check max connections of system limits
|
||||||
if (true) {
|
if (true) {
|
||||||
int nb_consumed_fds = (int)get_listen().size();
|
int nb_consumed_fds = (int)get_listens().size();
|
||||||
if (get_http_api_listen() > 0) {
|
if (!get_http_api_listen().empty()) {
|
||||||
nb_consumed_fds++;
|
nb_consumed_fds++;
|
||||||
}
|
}
|
||||||
if (get_http_stream_listen() > 0) {
|
if (!get_http_stream_listen().empty()) {
|
||||||
nb_consumed_fds++;
|
nb_consumed_fds++;
|
||||||
}
|
}
|
||||||
if (get_log_tank_file()) {
|
if (get_log_tank_file()) {
|
||||||
|
@ -1694,20 +1694,20 @@ int SrsConfig::check_config()
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// check http api
|
// check http api
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
if (get_http_api_listen() <= 0) {
|
if (get_http_api_listen().empty()) {
|
||||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||||
srs_error("directive http_api listen invalid, listen=%d, ret=%d",
|
srs_error("directive http_api listen invalid, listen=%s, ret=%d",
|
||||||
get_http_api_listen(), ret);
|
get_http_api_listen().c_str(), ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
// check http stream
|
// check http stream
|
||||||
////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////
|
||||||
if (get_http_stream_listen() <= 0) {
|
if (get_http_stream_listen().empty()) {
|
||||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||||
srs_error("directive http_stream listen invalid, listen=%d, ret=%d",
|
srs_error("directive http_stream listen invalid, listen=%s, ret=%d",
|
||||||
get_http_stream_listen(), ret);
|
get_http_stream_listen().c_str(), ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1858,7 +1858,7 @@ int SrsConfig::get_max_connections()
|
||||||
return ::atoi(conf->arg0().c_str());
|
return ::atoi(conf->arg0().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<string> SrsConfig::get_listen()
|
vector<string> SrsConfig::get_listens()
|
||||||
{
|
{
|
||||||
std::vector<string> ports;
|
std::vector<string> ports;
|
||||||
|
|
||||||
|
@ -3546,7 +3546,7 @@ bool SrsConfig::get_http_api_enabled(SrsConfDirective* conf)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsConfig::get_http_api_listen()
|
string SrsConfig::get_http_api_listen()
|
||||||
{
|
{
|
||||||
SrsConfDirective* conf = get_http_api();
|
SrsConfDirective* conf = get_http_api();
|
||||||
|
|
||||||
|
@ -3559,7 +3559,7 @@ int SrsConfig::get_http_api_listen()
|
||||||
return SRS_CONF_DEFAULT_HTTP_API_PORT;
|
return SRS_CONF_DEFAULT_HTTP_API_PORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ::atoi(conf->arg0().c_str());
|
return conf->arg0();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsConfig::get_http_api_crossdomain()
|
bool SrsConfig::get_http_api_crossdomain()
|
||||||
|
@ -3609,7 +3609,7 @@ bool SrsConfig::get_http_stream_enabled(SrsConfDirective* conf)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsConfig::get_http_stream_listen()
|
string SrsConfig::get_http_stream_listen()
|
||||||
{
|
{
|
||||||
SrsConfDirective* conf = get_http_stream();
|
SrsConfDirective* conf = get_http_stream();
|
||||||
|
|
||||||
|
@ -3622,7 +3622,7 @@ int SrsConfig::get_http_stream_listen()
|
||||||
return SRS_CONF_DEFAULT_HTTP_STREAM_PORT;
|
return SRS_CONF_DEFAULT_HTTP_STREAM_PORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ::atoi(conf->arg0().c_str());
|
return conf->arg0();
|
||||||
}
|
}
|
||||||
|
|
||||||
string SrsConfig::get_http_stream_dir()
|
string SrsConfig::get_http_stream_dir()
|
||||||
|
|
|
@ -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_DIR SRS_CONF_DEFAULT_HLS_PATH
|
||||||
#define SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE 0
|
#define SRS_CONF_DEFAULT_HTTP_AUDIO_FAST_CACHE 0
|
||||||
|
|
||||||
#define SRS_CONF_DEFAULT_HTTP_STREAM_PORT 8080
|
#define SRS_CONF_DEFAULT_HTTP_STREAM_PORT "8080"
|
||||||
#define SRS_CONF_DEFAULT_HTTP_API_PORT 1985
|
#define SRS_CONF_DEFAULT_HTTP_API_PORT "1985"
|
||||||
#define SRS_CONF_DEFAULT_HTTP_API_CROSSDOMAIN true
|
#define SRS_CONF_DEFAULT_HTTP_API_CROSSDOMAIN true
|
||||||
|
|
||||||
#define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_ENABLED false
|
#define SRS_CONF_DEFAULT_HTTP_HEAETBEAT_ENABLED false
|
||||||
|
@ -411,7 +411,7 @@ public:
|
||||||
* user can specifies multiple listen ports,
|
* user can specifies multiple listen ports,
|
||||||
* each args of directive is a listen port.
|
* each args of directive is a listen port.
|
||||||
*/
|
*/
|
||||||
virtual std::vector<std::string> get_listen();
|
virtual std::vector<std::string> get_listens();
|
||||||
/**
|
/**
|
||||||
* get the pid file path.
|
* get the pid file path.
|
||||||
* the pid file is used to save the pid of SRS,
|
* the pid file is used to save the pid of SRS,
|
||||||
|
@ -990,7 +990,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* get the http api listen port.
|
* 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.
|
* whether enable crossdomain for http api.
|
||||||
*/
|
*/
|
||||||
|
@ -1013,7 +1013,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* get the http stream listen port.
|
* 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.
|
* get the http stream root dir.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -33,6 +33,7 @@ using namespace std;
|
||||||
#include <srs_app_ffmpeg.hpp>
|
#include <srs_app_ffmpeg.hpp>
|
||||||
#include <srs_app_pithy_print.hpp>
|
#include <srs_app_pithy_print.hpp>
|
||||||
#include <srs_kernel_utility.hpp>
|
#include <srs_kernel_utility.hpp>
|
||||||
|
#include <srs_app_utility.hpp>
|
||||||
|
|
||||||
// when error, ingester sleep for a while and retry.
|
// when error, ingester sleep for a while and retry.
|
||||||
// ingest never sleep a long time, for we must start the stream ASAP.
|
// 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;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
std::vector<std::string> ports = _srs_config->get_listen();
|
std::string port;
|
||||||
srs_assert(ports.size() > 0);
|
if (true) {
|
||||||
std::string port = ports[0];
|
std::vector<std::string> 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);
|
std::string output = _srs_config->get_engine_output(engine);
|
||||||
// output stream, to other/self server
|
// output stream, to other/self server
|
||||||
|
|
|
@ -30,6 +30,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
#include <srs_kernel_log.hpp>
|
#include <srs_kernel_log.hpp>
|
||||||
#include <srs_kernel_error.hpp>
|
#include <srs_kernel_error.hpp>
|
||||||
|
@ -61,9 +62,10 @@ ISrsTcpHandler::~ISrsTcpHandler()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsUdpListener::SrsUdpListener(ISrsUdpHandler* h, int p)
|
SrsUdpListener::SrsUdpListener(ISrsUdpHandler* h, string i, int p)
|
||||||
{
|
{
|
||||||
handler = h;
|
handler = h;
|
||||||
|
ip = i;
|
||||||
port = p;
|
port = p;
|
||||||
|
|
||||||
_fd = -1;
|
_fd = -1;
|
||||||
|
@ -101,42 +103,42 @@ int SrsUdpListener::listen()
|
||||||
|
|
||||||
if ((_fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
|
if ((_fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
|
||||||
ret = ERROR_SOCKET_CREATE;
|
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;
|
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;
|
int reuse_socket = 1;
|
||||||
if (setsockopt(_fd, SOL_SOCKET, SO_REUSEADDR, &reuse_socket, sizeof(int)) == -1) {
|
if (setsockopt(_fd, SOL_SOCKET, SO_REUSEADDR, &reuse_socket, sizeof(int)) == -1) {
|
||||||
ret = ERROR_SOCKET_SETREUSE;
|
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;
|
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;
|
sockaddr_in addr;
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_port = htons(port);
|
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) {
|
if (bind(_fd, (const sockaddr*)&addr, sizeof(sockaddr_in)) == -1) {
|
||||||
ret = ERROR_SOCKET_BIND;
|
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;
|
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){
|
if ((stfd = st_netfd_open_socket(_fd)) == NULL){
|
||||||
ret = ERROR_ST_OPEN_SOCKET;
|
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;
|
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) {
|
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;
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -169,9 +171,10 @@ int SrsUdpListener::cycle()
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsTcpListener::SrsTcpListener(ISrsTcpHandler* h, int p)
|
SrsTcpListener::SrsTcpListener(ISrsTcpHandler* h, string i, int p)
|
||||||
{
|
{
|
||||||
handler = h;
|
handler = h;
|
||||||
|
ip = i;
|
||||||
port = p;
|
port = p;
|
||||||
|
|
||||||
_fd = -1;
|
_fd = -1;
|
||||||
|
@ -220,33 +223,33 @@ int SrsTcpListener::listen()
|
||||||
sockaddr_in addr;
|
sockaddr_in addr;
|
||||||
addr.sin_family = AF_INET;
|
addr.sin_family = AF_INET;
|
||||||
addr.sin_port = htons(port);
|
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) {
|
if (bind(_fd, (const sockaddr*)&addr, sizeof(sockaddr_in)) == -1) {
|
||||||
ret = ERROR_SOCKET_BIND;
|
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;
|
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) {
|
if (::listen(_fd, SERVER_LISTEN_BACKLOG) == -1) {
|
||||||
ret = ERROR_SOCKET_LISTEN;
|
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;
|
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){
|
if ((stfd = st_netfd_open_socket(_fd)) == NULL){
|
||||||
ret = ERROR_ST_OPEN_SOCKET;
|
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;
|
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) {
|
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;
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
#include <srs_app_st.hpp>
|
#include <srs_app_st.hpp>
|
||||||
#include <srs_app_thread.hpp>
|
#include <srs_app_thread.hpp>
|
||||||
|
|
||||||
|
@ -85,9 +87,10 @@ private:
|
||||||
int nb_buf;
|
int nb_buf;
|
||||||
private:
|
private:
|
||||||
ISrsUdpHandler* handler;
|
ISrsUdpHandler* handler;
|
||||||
|
std::string ip;
|
||||||
int port;
|
int port;
|
||||||
public:
|
public:
|
||||||
SrsUdpListener(ISrsUdpHandler* h, int p);
|
SrsUdpListener(ISrsUdpHandler* h, std::string i, int p);
|
||||||
virtual ~SrsUdpListener();
|
virtual ~SrsUdpListener();
|
||||||
public:
|
public:
|
||||||
virtual int fd();
|
virtual int fd();
|
||||||
|
@ -109,9 +112,10 @@ private:
|
||||||
SrsThread* pthread;
|
SrsThread* pthread;
|
||||||
private:
|
private:
|
||||||
ISrsTcpHandler* handler;
|
ISrsTcpHandler* handler;
|
||||||
|
std::string ip;
|
||||||
int port;
|
int port;
|
||||||
public:
|
public:
|
||||||
SrsTcpListener(ISrsTcpHandler* h, int p);
|
SrsTcpListener(ISrsTcpHandler* h, std::string i, int p);
|
||||||
virtual ~SrsTcpListener();
|
virtual ~SrsTcpListener();
|
||||||
public:
|
public:
|
||||||
virtual int fd();
|
virtual int fd();
|
||||||
|
|
|
@ -50,7 +50,8 @@ SrsRtpConn::SrsRtpConn(SrsRtspConn* r, int p, int sid)
|
||||||
rtsp = r;
|
rtsp = r;
|
||||||
_port = p;
|
_port = p;
|
||||||
stream_id = sid;
|
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();
|
cache = new SrsRtpPacket();
|
||||||
pprint = SrsPithyPrint::create_caster();
|
pprint = SrsPithyPrint::create_caster();
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,14 +136,15 @@ SrsStreamListener::~SrsStreamListener()
|
||||||
srs_freep(listener);
|
srs_freep(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsStreamListener::listen(int port)
|
int SrsStreamListener::listen(string ip, int port)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
_ip = ip;
|
||||||
_port = port;
|
_port = port;
|
||||||
|
|
||||||
srs_freep(listener);
|
srs_freep(listener);
|
||||||
listener = new SrsTcpListener(this, port);
|
listener = new SrsTcpListener(this, ip, port);
|
||||||
|
|
||||||
if ((ret = listener->listen()) != ERROR_SUCCESS) {
|
if ((ret = listener->listen()) != ERROR_SUCCESS) {
|
||||||
srs_error("tcp listen failed. ret=%d", ret);
|
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, "
|
srs_info("listen thread cid=%d, current_cid=%d, "
|
||||||
"listen at port=%d, type=%d, fd=%d started success, port=%d",
|
"listen at port=%d, type=%d, fd=%d started success, ep=%s:%d",
|
||||||
pthread->cid(), _srs_context->get_id(), _port, _type, fd, port);
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -190,7 +191,7 @@ SrsRtspListener::~SrsRtspListener()
|
||||||
srs_freep(listener);
|
srs_freep(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsRtspListener::listen(int port)
|
int SrsRtspListener::listen(string ip, int port)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -198,10 +199,11 @@ int SrsRtspListener::listen(int port)
|
||||||
// we just assert here for unknown stream caster.
|
// we just assert here for unknown stream caster.
|
||||||
srs_assert(_type == SrsListenerRtsp);
|
srs_assert(_type == SrsListenerRtsp);
|
||||||
|
|
||||||
|
_ip = ip;
|
||||||
_port = port;
|
_port = port;
|
||||||
|
|
||||||
srs_freep(listener);
|
srs_freep(listener);
|
||||||
listener = new SrsTcpListener(this, port);
|
listener = new SrsTcpListener(this, ip, port);
|
||||||
|
|
||||||
if ((ret = listener->listen()) != ERROR_SUCCESS) {
|
if ((ret = listener->listen()) != ERROR_SUCCESS) {
|
||||||
srs_error("udp caster listen failed. ret=%d", ret);
|
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, "
|
srs_info("listen thread cid=%d, current_cid=%d, "
|
||||||
"listen at port=%d, type=%d, fd=%d started success, port=%d",
|
"listen at port=%d, type=%d, fd=%d started success, ep=%s:%d",
|
||||||
pthread->cid(), _srs_context->get_id(), _port, _type, fd, port);
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -248,7 +250,7 @@ SrsUdpCasterListener::~SrsUdpCasterListener()
|
||||||
srs_freep(listener);
|
srs_freep(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsUdpCasterListener::listen(int port)
|
int SrsUdpCasterListener::listen(string ip, int port)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
|
@ -256,10 +258,11 @@ int SrsUdpCasterListener::listen(int port)
|
||||||
// we just assert here for unknown stream caster.
|
// we just assert here for unknown stream caster.
|
||||||
srs_assert(_type == SrsListenerMpegTsOverUdp);
|
srs_assert(_type == SrsListenerMpegTsOverUdp);
|
||||||
|
|
||||||
|
_ip = ip;
|
||||||
_port = port;
|
_port = port;
|
||||||
|
|
||||||
srs_freep(listener);
|
srs_freep(listener);
|
||||||
listener = new SrsUdpListener(caster, port);
|
listener = new SrsUdpListener(caster, ip, port);
|
||||||
|
|
||||||
if ((ret = listener->listen()) != ERROR_SUCCESS) {
|
if ((ret = listener->listen()) != ERROR_SUCCESS) {
|
||||||
srs_error("udp caster listen failed. ret=%d", ret);
|
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, "
|
srs_info("listen thread cid=%d, current_cid=%d, "
|
||||||
"listen at port=%d, type=%d, fd=%d started success, port=%d",
|
"listen at port=%d, type=%d, fd=%d started success, ep=%s:%d",
|
||||||
pthread->cid(), _srs_context->get_id(), _port, _type, fd, port);
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -881,18 +884,21 @@ int SrsServer::listen_rtmp()
|
||||||
int ret = ERROR_SUCCESS;
|
int ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
// stream service port.
|
// stream service port.
|
||||||
std::vector<std::string> ports = _srs_config->get_listen();
|
std::vector<std::string> ip_ports = _srs_config->get_listens();
|
||||||
srs_assert((int)ports.size() > 0);
|
srs_assert((int)ip_ports.size() > 0);
|
||||||
|
|
||||||
close_listeners(SrsListenerRtmpStream);
|
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);
|
SrsListener* listener = new SrsStreamListener(this, SrsListenerRtmpStream);
|
||||||
listeners.push_back(listener);
|
listeners.push_back(listener);
|
||||||
|
|
||||||
int port = ::atoi(ports[i].c_str());
|
std::string ip;
|
||||||
if ((ret = listener->listen(port)) != ERROR_SUCCESS) {
|
int port;
|
||||||
srs_error("RTMP stream listen at port %d failed. ret=%d", port, ret);
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -910,9 +916,14 @@ int SrsServer::listen_http_api()
|
||||||
SrsListener* listener = new SrsStreamListener(this, SrsListenerHttpApi);
|
SrsListener* listener = new SrsStreamListener(this, SrsListenerHttpApi);
|
||||||
listeners.push_back(listener);
|
listeners.push_back(listener);
|
||||||
|
|
||||||
int port = _srs_config->get_http_api_listen();
|
std::string ep = _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 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;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -931,9 +942,14 @@ int SrsServer::listen_http_stream()
|
||||||
SrsListener* listener = new SrsStreamListener(this, SrsListenerHttpStream);
|
SrsListener* listener = new SrsStreamListener(this, SrsListenerHttpStream);
|
||||||
listeners.push_back(listener);
|
listeners.push_back(listener);
|
||||||
|
|
||||||
int port = _srs_config->get_http_stream_listen();
|
std::string ep = _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 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;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,7 @@ class SrsListener
|
||||||
protected:
|
protected:
|
||||||
SrsListenerType _type;
|
SrsListenerType _type;
|
||||||
protected:
|
protected:
|
||||||
|
std::string _ip;
|
||||||
int _port;
|
int _port;
|
||||||
SrsServer* _server;
|
SrsServer* _server;
|
||||||
public:
|
public:
|
||||||
|
@ -83,7 +84,7 @@ public:
|
||||||
virtual ~SrsListener();
|
virtual ~SrsListener();
|
||||||
public:
|
public:
|
||||||
virtual SrsListenerType type();
|
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);
|
SrsStreamListener(SrsServer* server, SrsListenerType type);
|
||||||
virtual ~SrsStreamListener();
|
virtual ~SrsStreamListener();
|
||||||
public:
|
public:
|
||||||
virtual int listen(int port);
|
virtual int listen(std::string ip, int port);
|
||||||
// ISrsTcpHandler
|
// ISrsTcpHandler
|
||||||
public:
|
public:
|
||||||
virtual int on_tcp_client(st_netfd_t stfd);
|
virtual int on_tcp_client(st_netfd_t stfd);
|
||||||
|
@ -116,7 +117,7 @@ public:
|
||||||
SrsRtspListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c);
|
SrsRtspListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c);
|
||||||
virtual ~SrsRtspListener();
|
virtual ~SrsRtspListener();
|
||||||
public:
|
public:
|
||||||
virtual int listen(int port);
|
virtual int listen(std::string ip, int port);
|
||||||
// ISrsTcpHandler
|
// ISrsTcpHandler
|
||||||
public:
|
public:
|
||||||
virtual int on_tcp_client(st_netfd_t stfd);
|
virtual int on_tcp_client(st_netfd_t stfd);
|
||||||
|
@ -134,7 +135,7 @@ public:
|
||||||
SrsUdpCasterListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c);
|
SrsUdpCasterListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c);
|
||||||
virtual ~SrsUdpCasterListener();
|
virtual ~SrsUdpCasterListener();
|
||||||
public:
|
public:
|
||||||
virtual int listen(int port);
|
virtual int listen(std::string ip, int port);
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -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;
|
static SrsRusage _srs_system_rusage;
|
||||||
|
|
||||||
SrsRusage::SrsRusage()
|
SrsRusage::SrsRusage()
|
||||||
|
|
|
@ -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);
|
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.
|
// current process resouce usage.
|
||||||
// @see: man getrusage
|
// @see: man getrusage
|
||||||
class SrsRusage
|
class SrsRusage
|
||||||
|
|
Loading…
Reference in a new issue