From a07986f4eee916f3aa957cbfe217fa82261f92c6 Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 22 Jan 2017 17:07:55 +0800 Subject: [PATCH] for #742, refine code --- trunk/src/app/srs_app_source.cpp | 144 +++++++++++++++---------------- 1 file changed, 72 insertions(+), 72 deletions(-) diff --git a/trunk/src/app/srs_app_source.cpp b/trunk/src/app/srs_app_source.cpp index 921052fd0e..0dd1ad14cb 100755 --- a/trunk/src/app/srs_app_source.cpp +++ b/trunk/src/app/srs_app_source.cpp @@ -764,6 +764,78 @@ bool srs_hls_can_continue(int ret, SrsSharedPtrMessage* sh, SrsSharedPtrMessage* return false; } +SrsMixQueue::SrsMixQueue() +{ + nb_videos = 0; + nb_audios = 0; +} + +SrsMixQueue::~SrsMixQueue() +{ + clear(); +} + +void SrsMixQueue::clear() +{ + std::multimap::iterator it; + for (it = msgs.begin(); it != msgs.end(); ++it) { + SrsSharedPtrMessage* msg = it->second; + srs_freep(msg); + } + msgs.clear(); + + nb_videos = 0; + nb_audios = 0; +} + +void SrsMixQueue::push(SrsSharedPtrMessage* msg) +{ + msgs.insert(std::make_pair(msg->timestamp, msg)); + + if (msg->is_video()) { + nb_videos++; + } else { + nb_audios++; + } +} + +SrsSharedPtrMessage* SrsMixQueue::pop() +{ + 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. + std::multimap::iterator it = msgs.begin(); + SrsSharedPtrMessage* msg = it->second; + msgs.erase(it); + + if (msg->is_video()) { + nb_videos--; + } else { + nb_audios--; + } + + return msg; +} + SrsOriginHub::SrsOriginHub(SrsSource* s) { source = s; @@ -1659,78 +1731,6 @@ void SrsSource::destroy() pool.clear(); } -SrsMixQueue::SrsMixQueue() -{ - nb_videos = 0; - nb_audios = 0; -} - -SrsMixQueue::~SrsMixQueue() -{ - clear(); -} - -void SrsMixQueue::clear() -{ - std::multimap::iterator it; - for (it = msgs.begin(); it != msgs.end(); ++it) { - SrsSharedPtrMessage* msg = it->second; - srs_freep(msg); - } - msgs.clear(); - - nb_videos = 0; - nb_audios = 0; -} - -void SrsMixQueue::push(SrsSharedPtrMessage* msg) -{ - msgs.insert(std::make_pair(msg->timestamp, msg)); - - if (msg->is_video()) { - nb_videos++; - } else { - nb_audios++; - } -} - -SrsSharedPtrMessage* SrsMixQueue::pop() -{ - 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. - std::multimap::iterator it = msgs.begin(); - SrsSharedPtrMessage* msg = it->second; - msgs.erase(it); - - if (msg->is_video()) { - nb_videos--; - } else { - nb_audios--; - } - - return msg; -} - SrsSource::SrsSource() { req = NULL;