diff --git a/trunk/conf/srs.conf b/trunk/conf/srs.conf index af5369792..087b921b7 100755 --- a/trunk/conf/srs.conf +++ b/trunk/conf/srs.conf @@ -20,6 +20,7 @@ vhost __defaultVhost__ { enabled on; ffmpeg ./objs/ffmpeg/bin/ffmpeg; engine fd{ + enabled on; vcodec libx264; vbitrate 300; vfps 20; @@ -47,9 +48,12 @@ vhost all.transcode.vhost.com { enabled on; # the ffmpeg ffmpeg ./objs/ffmpeg/bin/ffmpeg; + # the transcode engine for matched stream. # all matched stream will transcoded to the following stream. # the transcode set name(ie. hd) is optional and not used. engine super{ + # whether the engine is enabled + enabled on; # video encoder name vcodec libx264; # video bitrate, in kbps @@ -92,6 +96,7 @@ vhost all.transcode.vhost.com { output rtmp://[vhost]:[port]/[app]/[stream]_super; } engine hd{ + enabled on; vcodec libx264; vbitrate 1200; vfps 25; @@ -111,6 +116,7 @@ vhost all.transcode.vhost.com { output rtmp://[vhost]:[port]/[app]/[stream]_hd; } engine sd{ + enabled on; vcodec libx264; vbitrate 800; vfps 25; @@ -130,6 +136,7 @@ vhost all.transcode.vhost.com { output rtmp://[vhost]:[port]/[app]/[stream]_sd; } engine fast{ + enabled on; vcodec libx264; vbitrate 300; vfps 20; @@ -150,6 +157,30 @@ vhost all.transcode.vhost.com { } } } +# transcode all app and stream of app +vhost app.transcode.vhost.com { + # the streaming transcode configs. + # if app specified, transcode all streams of app. + transcode live { + enabled on; + ffmpeg ./objs/ffmpeg/bin/ffmpeg; + engine fd{ + enabled off; + } + } +} +# transcode specified stream. +vhost stream.transcode.vhost.com { + # the streaming transcode configs. + # if stream specified, transcode the matched stream. + transcode live/livestream { + enabled on; + ffmpeg ./objs/ffmpeg/bin/ffmpeg; + engine fd{ + enabled off; + } + } +} # the vhost which forward publish streams. vhost forward.vhost.com { # forward all publish stream to the specified server. diff --git a/trunk/configure b/trunk/configure index 989f1ebd6..f0a1c6aa0 100755 --- a/trunk/configure +++ b/trunk/configure @@ -98,7 +98,7 @@ MODULE_FILES=("srs_core" "srs_core_log" "srs_core_server" "srs_core_stream" "srs_core_source" "srs_core_codec" "srs_core_handshake" "srs_core_pithy_print" "srs_core_config" "srs_core_refer" "srs_core_reload" - "srs_core_hls" "srs_core_forward") + "srs_core_hls" "srs_core_forward" "srs_core_encoder") MODULE_DIR="src/core" . auto/modules.sh CORE_OBJS="${MODULE_OBJS[@]}" diff --git a/trunk/src/core/srs_core_config.cpp b/trunk/src/core/srs_core_config.cpp index 812bf0172..8ccd54e3c 100644 --- a/trunk/src/core/srs_core_config.cpp +++ b/trunk/src/core/srs_core_config.cpp @@ -568,6 +568,17 @@ SrsConfDirective* SrsConfig::get_vhost_enabled(std::string vhost) return conf->get("enabled"); } +SrsConfDirective* SrsConfig::get_transcode(std::string vhost) +{ + SrsConfDirective* conf = get_vhost(vhost); + + if (!conf) { + return NULL; + } + + return conf->get("transcode"); +} + SrsConfDirective* SrsConfig::get_gop_cache(std::string vhost) { SrsConfDirective* conf = get_vhost(vhost); @@ -732,6 +743,7 @@ int SrsConfig::parse_file(const char* filename) // TODO: check other config. // TODO: check hls. // TODO: check ssl. + // TODO: check ffmpeg. return ret; } diff --git a/trunk/src/core/srs_core_config.hpp b/trunk/src/core/srs_core_config.hpp index 5f57cfa1e..984e12742 100644 --- a/trunk/src/core/srs_core_config.hpp +++ b/trunk/src/core/srs_core_config.hpp @@ -114,6 +114,7 @@ public: virtual int parse_options(int argc, char** argv); virtual SrsConfDirective* get_vhost(std::string vhost); virtual SrsConfDirective* get_vhost_enabled(std::string vhost); + virtual SrsConfDirective* get_transcode(std::string vhost); virtual SrsConfDirective* get_gop_cache(std::string vhost); virtual SrsConfDirective* get_forward(std::string vhost); virtual SrsConfDirective* get_hls(std::string vhost); diff --git a/trunk/src/core/srs_core_encoder.cpp b/trunk/src/core/srs_core_encoder.cpp new file mode 100644 index 000000000..f31ceb99e --- /dev/null +++ b/trunk/src/core/srs_core_encoder.cpp @@ -0,0 +1,46 @@ +/* +The MIT License (MIT) + +Copyright (c) 2013 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 + +#include +#include + +SrsEncoder::SrsEncoder() +{ +} + +SrsEncoder::~SrsEncoder() +{ +} + +int SrsEncoder::on_publish(std::string vhost, std::string app, std::string stream) +{ + int ret = ERROR_SUCCESS; + return ret; +} + +void SrsEncoder::on_unpublish() +{ +} + diff --git a/trunk/src/core/srs_core_encoder.hpp b/trunk/src/core/srs_core_encoder.hpp new file mode 100644 index 000000000..3ea39ee08 --- /dev/null +++ b/trunk/src/core/srs_core_encoder.hpp @@ -0,0 +1,44 @@ +/* +The MIT License (MIT) + +Copyright (c) 2013 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_CORE_ENCODER_HPP +#define SRS_CORE_ENCODER_HPP + +/* +#include +*/ +#include + +#include + +class SrsEncoder +{ +public: + SrsEncoder(); + virtual ~SrsEncoder(); +public: + virtual int on_publish(std::string vhost, std::string app, std::string stream); + virtual void on_unpublish(); +}; + +#endif diff --git a/trunk/src/core/srs_core_source.cpp b/trunk/src/core/srs_core_source.cpp index 9b2791164..1dd7cd6d5 100644 --- a/trunk/src/core/srs_core_source.cpp +++ b/trunk/src/core/srs_core_source.cpp @@ -33,6 +33,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include #include +#include #define CONST_MAX_JITTER_MS 500 #define DEFAULT_FRAME_TIME_MS 10 @@ -354,6 +355,9 @@ SrsSource::SrsSource(std::string _stream_url) #ifdef SRS_HLS hls = new SrsHls(); #endif +#ifdef SRS_FFMPEG + encoder = new SrsEncoder(); +#endif cache_metadata = cache_sh_video = cache_sh_audio = NULL; @@ -392,6 +396,9 @@ SrsSource::~SrsSource() #ifdef SRS_HLS srs_freep(hls); #endif +#ifdef SRS_FFMPEG + srs_freep(encoder); +#endif } bool SrsSource::can_publish() @@ -617,6 +624,12 @@ int SrsSource::on_publish(std::string vhost, std::string app, std::string stream } #endif +#ifdef SRS_FFMPEG + if ((ret = encoder->on_publish(vhost, app, stream)) != ERROR_SUCCESS) { + return ret; + } +#endif + // TODO: support reload. // create forwarders @@ -645,6 +658,10 @@ void SrsSource::on_unpublish() hls->on_unpublish(); #endif +#ifdef SRS_FFMPEG + encoder->on_unpublish(); +#endif + // close all forwarders std::vector::iterator it; for (it = forwarders.begin(); it != forwarders.end(); ++it) { diff --git a/trunk/src/core/srs_core_source.hpp b/trunk/src/core/srs_core_source.hpp index 315859d08..d449dba48 100644 --- a/trunk/src/core/srs_core_source.hpp +++ b/trunk/src/core/srs_core_source.hpp @@ -42,6 +42,9 @@ class SrsForwarder; #ifdef SRS_HLS class SrsHls; #endif +#ifdef SRS_FFMPEG +class SrsEncoder; +#endif /** * time jitter detect and correct, @@ -171,6 +174,10 @@ private: // hls handler. #ifdef SRS_HLS SrsHls* hls; +#endif + // transcoding handler. +#ifdef SRS_FFMPEG + SrsEncoder* encoder; #endif // gop cache for client fast startup. SrsGopCache* gop_cache; diff --git a/trunk/src/srs/srs.upp b/trunk/src/srs/srs.upp index 614993b14..1129baaa8 100644 --- a/trunk/src/srs/srs.upp +++ b/trunk/src/srs/srs.upp @@ -26,6 +26,8 @@ file ..\core\srs_core_source.cpp, ..\core\srs_core_forward.hpp, ..\core\srs_core_forward.cpp, + ..\core\srs_core_encoder.hpp, + ..\core\srs_core_encoder.cpp, ..\core\srs_core_hls.hpp, ..\core\srs_core_hls.cpp, ..\core\srs_core_codec.hpp,