From 9743e025415b9306a3bebca99c76f1acda8e04f1 Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 14 Jul 2015 11:28:00 +0800 Subject: [PATCH] refine the mix correct algorithm. --- trunk/src/app/srs_app_source.cpp | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index 4b25901f1..5dd98c204 100755 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -55,8 +55,8 @@ using namespace std; // 115 packets is 3s. #define SRS_PURE_AUDIO_GUESS_COUNT 115 -// when got these videos or audios, mix ok. -#define SRS_MIX_CORRECT_MIX_AV 10 +// when got these videos or audios, pure audio or video, mix ok. +#define SRS_MIX_CORRECT_PURE_AV 10 int _srs_time_jitter_string2int(std::string time_jitter) { @@ -849,12 +849,25 @@ void SrsMixQueue::push(SrsSharedPtrMessage* msg) SrsSharedPtrMessage* SrsMixQueue::pop() { - // when got 10+ videos or audios, mix ok. - // when got 1 video and 1 audio, mix ok. - if (nb_videos < SRS_MIX_CORRECT_MIX_AV && nb_audios < SRS_MIX_CORRECT_MIX_AV) { - if (nb_videos < 1 || nb_audios < 1) { - return NULL; - } + bool mix_ok = false; + + // pure video + if (nb_videos >= SRS_MIX_CORRECT_PURE_AV && nb_audios == 0) { + mix_ok = true; + } + + // pure audio + if (nb_audios >= SRS_MIX_CORRECT_PURE_AV && nb_videos == 0) { + mix_ok = true; + } + + // got 1 video and 1 audio, mix ok. + if (nb_videos >= 1 && nb_audios >= 1) { + mix_ok = true; + } + + if (!mix_ok) { + return NULL; } // pop the first msg.