winlin

for #133, add rtsp listener and handler.

@@ -141,17 +141,37 @@ http_server { @@ -141,17 +141,37 @@ http_server {
141 stream_caster { 141 stream_caster {
142 # whether stream caster is enabled. 142 # whether stream caster is enabled.
143 # default: off 143 # default: off
144 - enabled on; 144 + enabled off;
145 # the caster type of stream, the casters: 145 # the caster type of stream, the casters:
146 # mpegts_over_udp, MPEG-TS over UDP caster. 146 # mpegts_over_udp, MPEG-TS over UDP caster.
  147 + # rtsp, Real Time Streaming Protocol (RTSP).
147 caster mpegts_over_udp; 148 caster mpegts_over_udp;
148 # the output rtmp url. 149 # the output rtmp url.
149 - # for example, rtmp://127.0.0.1/live/livestream. 150 + # for mpegts_over_udp caster, the typically output url:
  151 + # rtmp://127.0.0.1/live/livestream
  152 + # for rtsp caster, the typically output url:
  153 + # rtmp://127.0.0.1/[app]/[stream]
  154 + # for example, the rtsp url:
  155 + # rtsp://192.168.1.173:8544/live/livestream.sdp
  156 + # where the [app] is "live" and [stream] is "livestream", output is:
  157 + # rtmp://127.0.0.1/live/livestream
150 output rtmp://127.0.0.1/live/livestream; 158 output rtmp://127.0.0.1/live/livestream;
151 # the listen port for stream caster. 159 # the listen port for stream caster.
152 - # for caster:  
153 - # mpegts_over_udp, listen at udp port.  
154 - listen 1935; 160 + # for mpegts_over_udp caster, listen at udp port.
  161 + # for rtsp caster, listen at tcp port.
  162 + listen 8935;
  163 +}
  164 +stream_caster {
  165 + enabled off;
  166 + caster mpegts_over_udp;
  167 + output rtmp://127.0.0.1/live/livestream;
  168 + listen 8935;
  169 +}
  170 +stream_caster {
  171 + enabled on;
  172 + caster rtsp;
  173 + output rtmp://127.0.0.1/[app]/[stream];
  174 + listen 554;
155 } 175 }
156 176
157 ############################################################################################# 177 #############################################################################################
@@ -392,7 +392,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then @@ -392,7 +392,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
392 "srs_app_json" "srs_app_ingest" "srs_app_ffmpeg" "srs_app_utility" "srs_app_dvr" "srs_app_edge" 392 "srs_app_json" "srs_app_ingest" "srs_app_ffmpeg" "srs_app_utility" "srs_app_dvr" "srs_app_edge"
393 "srs_app_kbps" "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client" 393 "srs_app_kbps" "srs_app_heartbeat" "srs_app_empty" "srs_app_http_client"
394 "srs_app_recv_thread" "srs_app_security" "srs_app_statistic" 394 "srs_app_recv_thread" "srs_app_security" "srs_app_statistic"
395 - "srs_app_mpegts_udp") 395 + "srs_app_mpegts_udp" "srs_app_rtsp")
396 APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh 396 APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh
397 APP_OBJS="${MODULE_OBJS[@]}" 397 APP_OBJS="${MODULE_OBJS[@]}"
398 fi 398 fi
@@ -112,6 +112,8 @@ file @@ -112,6 +112,8 @@ file
112 ../../src/app/srs_app_reload.cpp, 112 ../../src/app/srs_app_reload.cpp,
113 ../../src/app/srs_app_rtmp_conn.hpp, 113 ../../src/app/srs_app_rtmp_conn.hpp,
114 ../../src/app/srs_app_rtmp_conn.cpp, 114 ../../src/app/srs_app_rtmp_conn.cpp,
  115 + ../../src/app/srs_app_rtsp.hpp,
  116 + ../../src/app/srs_app_rtsp.cpp,
115 ../../src/app/srs_app_pithy_print.hpp, 117 ../../src/app/srs_app_pithy_print.hpp,
116 ../../src/app/srs_app_pithy_print.cpp, 118 ../../src/app/srs_app_pithy_print.cpp,
117 ../../src/app/srs_app_security.hpp, 119 ../../src/app/srs_app_security.hpp,
@@ -87,6 +87,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @@ -87,6 +87,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
87 87
88 #define SRS_CONF_DEFAULT_STREAM_CASTER_ENABLED false 88 #define SRS_CONF_DEFAULT_STREAM_CASTER_ENABLED false
89 #define SRS_CONF_DEFAULT_STREAM_CASTER_MPEGTS_OVER_UDP "mpegts_over_udp" 89 #define SRS_CONF_DEFAULT_STREAM_CASTER_MPEGTS_OVER_UDP "mpegts_over_udp"
  90 +#define SRS_CONF_DEFAULT_STREAM_CASTER_RTSP "rtsp"
90 91
91 #define SRS_CONF_DEFAULT_STATS_NETWORK_DEVICE_INDEX 0 92 #define SRS_CONF_DEFAULT_STATS_NETWORK_DEVICE_INDEX 0
92 93
  1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013-2015 winlin
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +
  24 +#include <srs_app_rtsp.hpp>
  25 +
  26 +#include <srs_app_config.hpp>
  27 +
  28 +#ifdef SRS_AUTO_STREAM_CASTER
  29 +
  30 +ISrsRtspHandler::ISrsRtspHandler()
  31 +{
  32 +}
  33 +
  34 +ISrsRtspHandler::~ISrsRtspHandler()
  35 +{
  36 +}
  37 +
  38 +SrsRtspConn::SrsRtspConn(SrsConfDirective* c)
  39 +{
  40 + output = _srs_config->get_stream_caster_output(c);
  41 +}
  42 +
  43 +SrsRtspConn::~SrsRtspConn()
  44 +{
  45 +}
  46 +
  47 +#endif
  48 +
  1 +/*
  2 +The MIT License (MIT)
  3 +
  4 +Copyright (c) 2013-2015 winlin
  5 +
  6 +Permission is hereby granted, free of charge, to any person obtaining a copy of
  7 +this software and associated documentation files (the "Software"), to deal in
  8 +the Software without restriction, including without limitation the rights to
  9 +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
  10 +the Software, and to permit persons to whom the Software is furnished to do so,
  11 +subject to the following conditions:
  12 +
  13 +The above copyright notice and this permission notice shall be included in all
  14 +copies or substantial portions of the Software.
  15 +
  16 +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17 +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
  18 +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
  19 +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
  20 +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  21 +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22 +*/
  23 +
  24 +#ifndef SRS_APP_RTSP_HPP
  25 +#define SRS_APP_RTSP_HPP
  26 +
  27 +/*
  28 +#include <srs_app_rtsp.hpp>
  29 +*/
  30 +
  31 +#include <srs_core.hpp>
  32 +
  33 +#include <string>
  34 +
  35 +#ifdef SRS_AUTO_STREAM_CASTER
  36 +
  37 +class SrsConfDirective;
  38 +
  39 +/**
  40 +* the handler for rtsp handler.
  41 +*/
  42 +class ISrsRtspHandler
  43 +{
  44 +public:
  45 + ISrsRtspHandler();
  46 + virtual ~ISrsRtspHandler();
  47 +};
  48 +
  49 +/**
  50 +* the connection for rtsp.
  51 +*/
  52 +class SrsRtspConn : public ISrsRtspHandler
  53 +{
  54 +private:
  55 + std::string output;
  56 +public:
  57 + SrsRtspConn(SrsConfDirective* c);
  58 + virtual ~SrsRtspConn();
  59 +};
  60 +
  61 +#endif
  62 +
  63 +#endif
@@ -46,6 +46,7 @@ using namespace std; @@ -46,6 +46,7 @@ using namespace std;
46 #include <srs_app_utility.hpp> 46 #include <srs_app_utility.hpp>
47 #include <srs_app_heartbeat.hpp> 47 #include <srs_app_heartbeat.hpp>
48 #include <srs_app_mpegts_udp.hpp> 48 #include <srs_app_mpegts_udp.hpp>
  49 +#include <srs_app_rtsp.hpp>
49 50
50 // signal defines. 51 // signal defines.
51 #define SIGNAL_RELOAD SIGHUP 52 #define SIGNAL_RELOAD SIGHUP
@@ -112,6 +113,8 @@ std::string __srs_listener_type2string(SrsListenerType type) @@ -112,6 +113,8 @@ std::string __srs_listener_type2string(SrsListenerType type)
112 return "HTTP-Server"; 113 return "HTTP-Server";
113 case SrsListenerMpegTsOverUdp: 114 case SrsListenerMpegTsOverUdp:
114 return "MPEG-TS over UDP"; 115 return "MPEG-TS over UDP";
  116 + case SrsListenerRtsp:
  117 + return "RTSP";
115 default: 118 default:
116 return "UNKONWN"; 119 return "UNKONWN";
117 } 120 }
@@ -229,6 +232,44 @@ int SrsListener::cycle() @@ -229,6 +232,44 @@ int SrsListener::cycle()
229 } 232 }
230 233
231 #ifdef SRS_AUTO_STREAM_CASTER 234 #ifdef SRS_AUTO_STREAM_CASTER
  235 +SrsRtspListener::SrsRtspListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c) : SrsListener(server, type)
  236 +{
  237 + _type = type;
  238 +
  239 + // the caller already ensure the type is ok,
  240 + // we just assert here for unknown stream caster.
  241 + srs_assert(_type == SrsListenerRtsp);
  242 + if (_type == SrsListenerRtsp) {
  243 + caster = new SrsRtspConn(c);
  244 + }
  245 +}
  246 +
  247 +SrsRtspListener::~SrsRtspListener()
  248 +{
  249 + srs_freep(caster);
  250 +}
  251 +
  252 +int SrsRtspListener::cycle()
  253 +{
  254 + int ret = ERROR_SUCCESS;
  255 +
  256 + st_netfd_t client_stfd = st_accept(stfd, NULL, NULL, ST_UTIME_NO_TIMEOUT);
  257 +
  258 + if(client_stfd == NULL){
  259 + // ignore error.
  260 + srs_error("ignore accept thread stoppped for accept client error");
  261 + return ret;
  262 + }
  263 + srs_verbose("get a client. fd=%d", st_netfd_fileno(client_stfd));
  264 +
  265 + if ((ret = _server->accept_client(_type, client_stfd)) != ERROR_SUCCESS) {
  266 + srs_warn("accept client error. ret=%d", ret);
  267 + return ret;
  268 + }
  269 +
  270 + return ret;
  271 +}
  272 +
232 SrsUdpListener::SrsUdpListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c) : SrsListener(server, type) 273 SrsUdpListener::SrsUdpListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c) : SrsListener(server, type)
233 { 274 {
234 _type = type; 275 _type = type;
@@ -1022,11 +1063,13 @@ int SrsServer::listen_stream_caster() @@ -1022,11 +1063,13 @@ int SrsServer::listen_stream_caster()
1022 continue; 1063 continue;
1023 } 1064 }
1024 1065
1025 - SrsUdpListener* listener = NULL; 1066 + SrsListener* listener = NULL;
1026 1067
1027 std::string caster = _srs_config->get_stream_caster_engine(stream_caster); 1068 std::string caster = _srs_config->get_stream_caster_engine(stream_caster);
1028 if (caster == SRS_CONF_DEFAULT_STREAM_CASTER_MPEGTS_OVER_UDP) { 1069 if (caster == SRS_CONF_DEFAULT_STREAM_CASTER_MPEGTS_OVER_UDP) {
1029 listener = new SrsUdpListener(this, SrsListenerMpegTsOverUdp, stream_caster); 1070 listener = new SrsUdpListener(this, SrsListenerMpegTsOverUdp, stream_caster);
  1071 + } else if (caster == SRS_CONF_DEFAULT_STREAM_CASTER_RTSP) {
  1072 + listener = new SrsRtspListener(this, SrsListenerRtsp, stream_caster);
1030 } else { 1073 } else {
1031 ret = ERROR_STREAM_CASTER_ENGINE; 1074 ret = ERROR_STREAM_CASTER_ENGINE;
1032 srs_error("unsupported stream caster %s. ret=%d", caster.c_str(), ret); 1075 srs_error("unsupported stream caster %s. ret=%d", caster.c_str(), ret);
@@ -48,6 +48,7 @@ class SrsHttpHeartbeat; @@ -48,6 +48,7 @@ class SrsHttpHeartbeat;
48 class SrsKbps; 48 class SrsKbps;
49 class SrsConfDirective; 49 class SrsConfDirective;
50 class ISrsUdpHandler; 50 class ISrsUdpHandler;
  51 +class ISrsRtspHandler;
51 52
52 // listener type for server to identify the connection, 53 // listener type for server to identify the connection,
53 // that is, use different type to process the connection. 54 // that is, use different type to process the connection.
@@ -61,6 +62,8 @@ enum SrsListenerType @@ -61,6 +62,8 @@ enum SrsListenerType
61 SrsListenerHttpStream = 2, 62 SrsListenerHttpStream = 2,
62 // UDP stream, MPEG-TS over udp. 63 // UDP stream, MPEG-TS over udp.
63 SrsListenerMpegTsOverUdp = 3, 64 SrsListenerMpegTsOverUdp = 3,
  65 + // TCP stream, RTSP stream.
  66 + SrsListenerRtsp = 4,
64 }; 67 };
65 68
66 /** 69 /**
@@ -89,6 +92,21 @@ public: @@ -89,6 +92,21 @@ public:
89 92
90 #ifdef SRS_AUTO_STREAM_CASTER 93 #ifdef SRS_AUTO_STREAM_CASTER
91 /** 94 /**
  95 +* the tcp listener, for rtsp server.
  96 +*/
  97 +class SrsRtspListener : public SrsListener
  98 +{
  99 +private:
  100 + ISrsRtspHandler* caster;
  101 +public:
  102 + SrsRtspListener(SrsServer* server, SrsListenerType type, SrsConfDirective* c);
  103 + virtual ~SrsRtspListener();
  104 +// interface ISrsThreadHandler.
  105 +public:
  106 + virtual int cycle();
  107 +};
  108 +
  109 +/**
92 * the udp listener, for udp server. 110 * the udp listener, for udp server.
93 */ 111 */
94 class SrsUdpListener : public SrsListener 112 class SrsUdpListener : public SrsListener
@@ -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 118 34 +#define VERSION_REVISION 119
35 35
36 // server info. 36 // server info.
37 #define RTMP_SIG_SRS_KEY "SRS" 37 #define RTMP_SIG_SRS_KEY "SRS"
@@ -132,6 +132,12 @@ void show_macro_features() @@ -132,6 +132,12 @@ void show_macro_features()
132 srs_warn("check feature compile ffmpeg: off"); 132 srs_warn("check feature compile ffmpeg: off");
133 #endif 133 #endif
134 134
  135 +#ifdef SRS_AUTO_STREAM_CASTER
  136 + srs_trace("stream caster: on");
  137 +#else
  138 + srs_warn("stream caster: off");
  139 +#endif
  140 +
135 #ifdef SRS_PERF_MERGED_READ 141 #ifdef SRS_PERF_MERGED_READ
136 srs_trace("MR(merged-read): on, @see %s", RTMP_SIG_SRS_ISSUES(241)); 142 srs_trace("MR(merged-read): on, @see %s", RTMP_SIG_SRS_ISSUES(241));
137 #else 143 #else