From beb0431746e0ad9c889859c2a38362ad08332207 Mon Sep 17 00:00:00 2001 From: winlin Date: Sat, 6 Jun 2015 22:04:24 +0800 Subject: [PATCH] detect the monotonically increase and warn to use mix_correct --- trunk/src/app/srs_app_source.cpp | 25 +++++++++++++++++++++++++ trunk/src/app/srs_app_source.hpp | 3 +++ 2 files changed, 28 insertions(+) diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index e063f980c..72d0f08c2 100755 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -900,6 +900,9 @@ SrsSource::SrsSource() gop_cache = new SrsGopCache(); aggregate_stream = new SrsStream(); + is_monotonically_increase = false; + last_packet_time = 0; + _srs_config->subscribe(this); atc = false; } @@ -1467,6 +1470,15 @@ int SrsSource::on_audio(SrsCommonMessage* shared_audio) { int ret = ERROR_SUCCESS; + // monotically increase detect. + if (!mix_correct && is_monotonically_increase) { + if (last_packet_time > 0 && shared_audio->header.timestamp < last_packet_time) { + is_monotonically_increase = false; + srs_warn("stream not monotonically increase, please open mix_correct."); + } + } + last_packet_time = shared_audio->header.timestamp; + // convert shared_audio to msg, user should not use shared_audio again. // the payload is transfer to msg, and set to NULL in shared_audio. SrsSharedPtrMessage msg; @@ -1649,6 +1661,15 @@ int SrsSource::on_video(SrsCommonMessage* shared_video) { int ret = ERROR_SUCCESS; + // monotically increase detect. + if (!mix_correct && is_monotonically_increase) { + if (last_packet_time > 0 && shared_video->header.timestamp < last_packet_time) { + is_monotonically_increase = false; + srs_warn("stream not monotonically increase, please open mix_correct."); + } + } + last_packet_time = shared_video->header.timestamp; + // drop any unknown header video. // @see https://github.com/simple-rtmp-server/srs/issues/421 if (!SrsFlvCodec::video_is_acceptable(shared_video->payload, shared_video->size)) { @@ -1970,6 +1991,10 @@ int SrsSource::on_publish() // reset the mix queue. mix_queue->clear(); + // detect the monotonically again. + is_monotonically_increase = true; + last_packet_time = 0; + // create forwarders if ((ret = create_forwarders()) != ERROR_SUCCESS) { srs_error("create forwarders failed. ret=%d", ret); diff --git a/trunk/src/app/srs_app_source.hpp b/trunk/src/app/srs_app_source.hpp index dc36eada5..bdb4d5f4c 100644 --- a/trunk/src/app/srs_app_source.hpp +++ b/trunk/src/app/srs_app_source.hpp @@ -437,6 +437,9 @@ private: // whether use interlaced/mixed algorithm to correct timestamp. bool mix_correct; SrsMixQueue* mix_queue; + // whether stream is monotonically increase. + bool is_monotonically_increase; + int64_t last_packet_time; // hls handler. #ifdef SRS_AUTO_HLS SrsHls* hls;