mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
for #133, add rtsp listener and handler.
This commit is contained in:
parent
78f34ad46f
commit
e81e090239
10 changed files with 209 additions and 8 deletions
|
@ -141,17 +141,37 @@ http_server {
|
|||
stream_caster {
|
||||
# whether stream caster is enabled.
|
||||
# default: off
|
||||
enabled on;
|
||||
enabled off;
|
||||
# the caster type of stream, the casters:
|
||||
# mpegts_over_udp, MPEG-TS over UDP caster.
|
||||
# rtsp, Real Time Streaming Protocol (RTSP).
|
||||
caster mpegts_over_udp;
|
||||
# the output rtmp url.
|
||||
# for example, rtmp://127.0.0.1/live/livestream.
|
||||
# for mpegts_over_udp caster, the typically output url:
|
||||
# rtmp://127.0.0.1/live/livestream
|
||||
# for rtsp caster, the typically output url:
|
||||
# rtmp://127.0.0.1/[app]/[stream]
|
||||
# for example, the rtsp url:
|
||||
# rtsp://192.168.1.173:8544/live/livestream.sdp
|
||||
# where the [app] is "live" and [stream] is "livestream", output is:
|
||||
# rtmp://127.0.0.1/live/livestream
|
||||
output rtmp://127.0.0.1/live/livestream;
|
||||
# the listen port for stream caster.
|
||||
# for caster:
|
||||
# mpegts_over_udp, listen at udp port.
|
||||
listen 1935;
|
||||
# for mpegts_over_udp caster, listen at udp port.
|
||||
# for rtsp caster, listen at tcp port.
|
||||
listen 8935;
|
||||
}
|
||||
stream_caster {
|
||||
enabled off;
|
||||
caster mpegts_over_udp;
|
||||
output rtmp://127.0.0.1/live/livestream;
|
||||
listen 8935;
|
||||
}
|
||||
stream_caster {
|
||||
enabled on;
|
||||
caster rtsp;
|
||||
output rtmp://127.0.0.1/[app]/[stream];
|
||||
listen 554;
|
||||
}
|
||||
|
||||
#############################################################################################
|
||||
|
|
2
trunk/configure
vendored
2
trunk/configure
vendored
|
@ -392,7 +392,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
|
|||
"srs_app_json" "srs_app_ingest" "srs_app_ffmpeg" "srs_app_utility" "srs_app_dvr" "srs_app_edge"
|
||||
"srs_app_kbps" "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client"
|
||||
"srs_app_recv_thread" "srs_app_security" "srs_app_statistic"
|
||||
"srs_app_mpegts_udp")
|
||||
"srs_app_mpegts_udp" "srs_app_rtsp")
|
||||
APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh
|
||||
APP_OBJS="${MODULE_OBJS[@]}"
|
||||
fi
|
||||
|
|
|
@ -112,6 +112,8 @@ file
|
|||
../../src/app/srs_app_reload.cpp,
|
||||
../../src/app/srs_app_rtmp_conn.hpp,
|
||||
../../src/app/srs_app_rtmp_conn.cpp,
|
||||
../../src/app/srs_app_rtsp.hpp,
|
||||
../../src/app/srs_app_rtsp.cpp,
|
||||
../../src/app/srs_app_pithy_print.hpp,
|
||||
../../src/app/srs_app_pithy_print.cpp,
|
||||
../../src/app/srs_app_security.hpp,
|
||||
|
|
|
@ -87,6 +87,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|||
|
||||
#define SRS_CONF_DEFAULT_STREAM_CASTER_ENABLED false
|
||||
#define SRS_CONF_DEFAULT_STREAM_CASTER_MPEGTS_OVER_UDP "mpegts_over_udp"
|
||||
#define SRS_CONF_DEFAULT_STREAM_CASTER_RTSP "rtsp"
|
||||
|
||||
#define SRS_CONF_DEFAULT_STATS_NETWORK_DEVICE_INDEX 0
|
||||
|
||||
|
|
48
trunk/src/app/srs_app_rtsp.cpp
Normal file
48
trunk/src/app/srs_app_rtsp.cpp
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2015 winlin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <srs_app_rtsp.hpp>
|
||||
|
||||
#include <srs_app_config.hpp>
|
||||
|
||||
#ifdef SRS_AUTO_STREAM_CASTER
|
||||
|
||||
ISrsRtspHandler::ISrsRtspHandler()
|
||||
{
|
||||
}
|
||||
|
||||
ISrsRtspHandler::~ISrsRtspHandler()
|
||||
{
|
||||
}
|
||||
|
||||
SrsRtspConn::SrsRtspConn(SrsConfDirective* c)
|
||||
{
|
||||
output = _srs_config->get_stream_caster_output(c);
|
||||
}
|
||||
|
||||
SrsRtspConn::~SrsRtspConn()
|
||||
{
|
||||
}
|
||||
|
||||
#endif
|
||||
|
63
trunk/src/app/srs_app_rtsp.hpp
Normal file
63
trunk/src/app/srs_app_rtsp.hpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013-2015 winlin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef SRS_APP_RTSP_HPP
|
||||
#define SRS_APP_RTSP_HPP
|
||||
|
||||
/*
|
||||
#include <srs_app_rtsp.hpp>
|
||||
*/
|
||||
|
||||
#include <srs_core.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
#ifdef SRS_AUTO_STREAM_CASTER
|
||||
|
||||
class SrsConfDirective;
|
||||
|
||||
/**
|
||||
* the handler for rtsp handler.
|
||||
*/
|
||||
class ISrsRtspHandler
|
||||
{
|
||||
public:
|
||||
ISrsRtspHandler();
|
||||
virtual ~ISrsRtspHandler();
|
||||
};
|
||||
|
||||
/**
|
||||
* the connection for rtsp.
|
||||
*/
|
||||
class SrsRtspConn : public ISrsRtspHandler
|
||||
{
|
||||
private:
|
||||
std::string output;
|
||||
public:
|
||||
SrsRtspConn(SrsConfDirective* c);
|
||||
virtual ~SrsRtspConn();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -46,6 +46,7 @@ using namespace std;
|
|||
#include <srs_app_utility.hpp>
|
||||
#include <srs_app_heartbeat.hpp>
|
||||
#include <srs_app_mpegts_udp.hpp>
|
||||
#include <srs_app_rtsp.hpp>
|
||||
|
||||
// signal defines.
|
||||
#define SIGNAL_RELOAD SIGHUP
|
||||
|
@ -112,6 +113,8 @@ std::string __srs_listener_type2string(SrsListenerType type)
|
|||
return "HTTP-Server";
|
||||
case SrsListenerMpegTsOverUdp:
|
||||
return "MPEG-TS over UDP";
|
||||
case SrsListenerRtsp:
|
||||
return "RTSP";
|
||||
default:
|
||||
return "UNKONWN";
|
||||
}
|
||||
|
@ -229,6 +232,44 @@ int SrsListener::cycle()
|
|||
}
|
||||
|
||||
#ifdef SRS_AUTO_STREAM_CASTER
|
||||
SrsRtspListener::SrsRtspListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c) : SrsListener(server, type)
|
||||
{
|
||||
_type = type;
|
||||
|
||||
// the caller already ensure the type is ok,
|
||||
// we just assert here for unknown stream caster.
|
||||
srs_assert(_type == SrsListenerRtsp);
|
||||
if (_type == SrsListenerRtsp) {
|
||||
caster = new SrsRtspConn(c);
|
||||
}
|
||||
}
|
||||
|
||||
SrsRtspListener::~SrsRtspListener()
|
||||
{
|
||||
srs_freep(caster);
|
||||
}
|
||||
|
||||
int SrsRtspListener::cycle()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
st_netfd_t client_stfd = st_accept(stfd, NULL, NULL, ST_UTIME_NO_TIMEOUT);
|
||||
|
||||
if(client_stfd == NULL){
|
||||
// ignore error.
|
||||
srs_error("ignore accept thread stoppped for accept client error");
|
||||
return ret;
|
||||
}
|
||||
srs_verbose("get a client. fd=%d", st_netfd_fileno(client_stfd));
|
||||
|
||||
if ((ret = _server->accept_client(_type, client_stfd)) != ERROR_SUCCESS) {
|
||||
srs_warn("accept client error. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
SrsUdpListener::SrsUdpListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c) : SrsListener(server, type)
|
||||
{
|
||||
_type = type;
|
||||
|
@ -1022,11 +1063,13 @@ int SrsServer::listen_stream_caster()
|
|||
continue;
|
||||
}
|
||||
|
||||
SrsUdpListener* listener = NULL;
|
||||
SrsListener* listener = NULL;
|
||||
|
||||
std::string caster = _srs_config->get_stream_caster_engine(stream_caster);
|
||||
if (caster == SRS_CONF_DEFAULT_STREAM_CASTER_MPEGTS_OVER_UDP) {
|
||||
listener = new SrsUdpListener(this, SrsListenerMpegTsOverUdp, stream_caster);
|
||||
} else if (caster == SRS_CONF_DEFAULT_STREAM_CASTER_RTSP) {
|
||||
listener = new SrsRtspListener(this, SrsListenerRtsp, stream_caster);
|
||||
} else {
|
||||
ret = ERROR_STREAM_CASTER_ENGINE;
|
||||
srs_error("unsupported stream caster %s. ret=%d", caster.c_str(), ret);
|
||||
|
|
|
@ -48,6 +48,7 @@ class SrsHttpHeartbeat;
|
|||
class SrsKbps;
|
||||
class SrsConfDirective;
|
||||
class ISrsUdpHandler;
|
||||
class ISrsRtspHandler;
|
||||
|
||||
// listener type for server to identify the connection,
|
||||
// that is, use different type to process the connection.
|
||||
|
@ -61,6 +62,8 @@ enum SrsListenerType
|
|||
SrsListenerHttpStream = 2,
|
||||
// UDP stream, MPEG-TS over udp.
|
||||
SrsListenerMpegTsOverUdp = 3,
|
||||
// TCP stream, RTSP stream.
|
||||
SrsListenerRtsp = 4,
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -88,6 +91,21 @@ public:
|
|||
};
|
||||
|
||||
#ifdef SRS_AUTO_STREAM_CASTER
|
||||
/**
|
||||
* the tcp listener, for rtsp server.
|
||||
*/
|
||||
class SrsRtspListener : public SrsListener
|
||||
{
|
||||
private:
|
||||
ISrsRtspHandler* caster;
|
||||
public:
|
||||
SrsRtspListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c);
|
||||
virtual ~SrsRtspListener();
|
||||
// interface ISrsThreadHandler.
|
||||
public:
|
||||
virtual int cycle();
|
||||
};
|
||||
|
||||
/**
|
||||
* the udp listener, for udp server.
|
||||
*/
|
||||
|
|
|
@ -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 118
|
||||
#define VERSION_REVISION 119
|
||||
|
||||
// server info.
|
||||
#define RTMP_SIG_SRS_KEY "SRS"
|
||||
|
|
|
@ -132,6 +132,12 @@ void show_macro_features()
|
|||
srs_warn("check feature compile ffmpeg: off");
|
||||
#endif
|
||||
|
||||
#ifdef SRS_AUTO_STREAM_CASTER
|
||||
srs_trace("stream caster: on");
|
||||
#else
|
||||
srs_warn("stream caster: off");
|
||||
#endif
|
||||
|
||||
#ifdef SRS_PERF_MERGED_READ
|
||||
srs_trace("MR(merged-read): on, @see %s", RTMP_SIG_SRS_ISSUES(241));
|
||||
#else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue