From fd0002e49925dc2c48c5912fb1bf603f8558b76e Mon Sep 17 00:00:00 2001 From: winlin Date: Wed, 16 Apr 2014 09:28:02 +0800 Subject: [PATCH] add dvr framework --- trunk/configure | 2 +- .../app/{srs_app_flv.cpp => srs_app_dvr.cpp} | 2 +- .../app/{srs_app_flv.hpp => srs_app_dvr.hpp} | 6 +-- trunk/src/app/srs_app_source.cpp | 50 ++++++++++++++++++- trunk/src/app/srs_app_source.hpp | 7 +++ trunk/src/srs/srs.upp | 4 +- 6 files changed, 63 insertions(+), 8 deletions(-) rename trunk/src/app/{srs_app_flv.cpp => srs_app_dvr.cpp} (98%) rename trunk/src/app/{srs_app_flv.hpp => srs_app_dvr.hpp} (96%) diff --git a/trunk/configure b/trunk/configure index 572fff00d..99b3b5324 100755 --- a/trunk/configure +++ b/trunk/configure @@ -440,7 +440,7 @@ MODULE_FILES=("srs_app_server" "srs_app_conn" "srs_app_rtmp_conn" "srs_app_socke "srs_app_http" "srs_app_thread" "srs_app_bandwidth" "srs_app_st" "srs_app_log" "srs_app_config" "srs_app_pithy_print" "srs_app_reload" "srs_app_http_api" "srs_app_http_conn" "srs_app_http_hooks" "srs_app_json" "srs_app_ingest" - "srs_app_ffmpeg" "srs_app_utility" "srs_app_flv") + "srs_app_ffmpeg" "srs_app_utility" "srs_app_dvr") APP_INCS="src/app"; MODULE_DIR=${APP_INCS} . auto/modules.sh APP_OBJS="${MODULE_OBJS[@]}" # diff --git a/trunk/src/app/srs_app_flv.cpp b/trunk/src/app/srs_app_dvr.cpp similarity index 98% rename from trunk/src/app/srs_app_flv.cpp rename to trunk/src/app/srs_app_dvr.cpp index 3ffb72e9f..8a9e0ae49 100644 --- a/trunk/src/app/srs_app_flv.cpp +++ b/trunk/src/app/srs_app_dvr.cpp @@ -21,7 +21,7 @@ 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 #ifdef SRS_AUTO_DVR diff --git a/trunk/src/app/srs_app_flv.hpp b/trunk/src/app/srs_app_dvr.hpp similarity index 96% rename from trunk/src/app/srs_app_flv.hpp rename to trunk/src/app/srs_app_dvr.hpp index 0d70d3c0a..078a75973 100644 --- a/trunk/src/app/srs_app_flv.hpp +++ b/trunk/src/app/srs_app_dvr.hpp @@ -21,11 +21,11 @@ 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_FLV_HPP -#define SRS_APP_FLV_HPP +#ifndef SRS_APP_DVR_HPP +#define SRS_APP_DVR_HPP /* -#include +#include */ #include diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index 7faca8971..0c1550d8a 100644 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -36,6 +36,7 @@ using namespace std; #include #include #include +#include #define CONST_MAX_JITTER_MS 500 #define DEFAULT_FRAME_TIME_MS 40 @@ -431,6 +432,9 @@ SrsSource::SrsSource(SrsRequest* _req) #ifdef SRS_AUTO_HLS hls = new SrsHls(this); #endif +#ifdef SRS_AUTO_DVR + dvr = new SrsDvr(this); +#endif #ifdef SRS_AUTO_TRANSCODE encoder = new SrsEncoder(); #endif @@ -477,6 +481,9 @@ SrsSource::~SrsSource() #ifdef SRS_AUTO_HLS srs_freep(hls); #endif +#ifdef SRS_AUTO_DVR + srs_freep(dvr); +#endif #ifdef SRS_AUTO_TRANSCODE srs_freep(encoder); #endif @@ -678,6 +685,13 @@ int SrsSource::on_meta_data(SrsCommonMessage* msg, SrsOnMetaDataPacket* metadata } #endif +#ifdef SRS_AUTO_DVR + if (metadata && (ret = dvr->on_meta_data(metadata->metadata)) != ERROR_SUCCESS) { + srs_error("dvr process onMetaData message failed. ret=%d", ret); + return ret; + } +#endif + metadata->metadata->set("server", SrsAmf0Any::str(RTMP_SIG_SRS_KEY" "RTMP_SIG_SRS_VERSION" ("RTMP_SIG_SRS_URL_SHORT")")); metadata->metadata->set("contributor", SrsAmf0Any::str(RTMP_SIG_SRS_PRIMARY_AUTHROS)); @@ -772,6 +786,18 @@ int SrsSource::on_audio(SrsCommonMessage* audio) } #endif +#ifdef SRS_AUTO_DVR + if ((ret = dvr->on_audio(msg->copy())) != ERROR_SUCCESS) { + srs_warn("dvr process audio message failed, ignore and disable dvr. ret=%d", ret); + + // unpublish, ignore ret. + dvr->on_unpublish(); + + // ignore. + ret = ERROR_SUCCESS; + } +#endif + // copy to all consumer if (true) { std::vector::iterator it; @@ -849,6 +875,18 @@ int SrsSource::on_video(SrsCommonMessage* video) } #endif +#ifdef SRS_AUTO_DVR + if ((ret = dvr->on_video(msg->copy())) != ERROR_SUCCESS) { + srs_warn("dvr process video message failed, ignore and disable dvr. ret=%d", ret); + + // unpublish, ignore ret. + dvr->on_unpublish(); + + // ignore. + ret = ERROR_SUCCESS; + } +#endif + // copy to all consumer if (true) { std::vector::iterator it; @@ -932,6 +970,13 @@ int SrsSource::on_publish(SrsRequest* _req) return ret; } #endif + +#ifdef SRS_AUTO_DVR + if ((ret = dvr->on_publish(req)) != ERROR_SUCCESS) { + srs_error("start dvr failed. ret=%d", ret); + return ret; + } +#endif return ret; } @@ -945,10 +990,13 @@ void SrsSource::on_unpublish() encoder->on_unpublish(); #endif - // TODO: HLS should continue previous sequence and stream. #ifdef SRS_AUTO_HLS hls->on_unpublish(); #endif + +#ifdef SRS_AUTO_DVR + dvr->on_unpublish(); +#endif gop_cache->clear(); diff --git a/trunk/src/app/srs_app_source.hpp b/trunk/src/app/srs_app_source.hpp index 93732e777..1087726f9 100644 --- a/trunk/src/app/srs_app_source.hpp +++ b/trunk/src/app/srs_app_source.hpp @@ -46,6 +46,9 @@ class SrsRequest; #ifdef SRS_AUTO_HLS class SrsHls; #endif +#ifdef SRS_AUTO_DVR +class SrsDvr; +#endif #ifdef SRS_AUTO_TRANSCODE class SrsEncoder; #endif @@ -222,6 +225,10 @@ private: // hls handler. #ifdef SRS_AUTO_HLS SrsHls* hls; +#endif + // dvr handler. +#ifdef SRS_AUTO_DVR + SrsDvr* dvr; #endif // transcoding handler. #ifdef SRS_AUTO_TRANSCODE diff --git a/trunk/src/srs/srs.upp b/trunk/src/srs/srs.upp index 3ed79d2e1..0af75902f 100755 --- a/trunk/src/srs/srs.upp +++ b/trunk/src/srs/srs.upp @@ -47,12 +47,12 @@ file ..\app\srs_app_conn.cpp, ..\app\srs_app_config.hpp, ..\app\srs_app_config.cpp, + ..\app\srs_app_dvr.hpp, + ..\app\srs_app_dvr.cpp, ..\app\srs_app_encoder.hpp, ..\app\srs_app_encoder.cpp, ..\app\srs_app_ffmpeg.hpp, ..\app\srs_app_ffmpeg.cpp, - ..\app\srs_app_flv.hpp, - ..\app\srs_app_flv.cpp, ..\app\srs_app_forward.hpp, ..\app\srs_app_forward.cpp, ..\app\srs_app_hls.hpp,