refine the mix correct algorithm, mix when got 10+ av or got 1 video and 1 audio.
正在显示
2 个修改的文件
包含
16 行增加
和
3 行删除
@@ -54,6 +54,9 @@ using namespace std; | @@ -54,6 +54,9 @@ using namespace std; | ||
54 | // 115 packets is 3s. | 54 | // 115 packets is 3s. |
55 | #define SRS_PURE_AUDIO_GUESS_COUNT 115 | 55 | #define SRS_PURE_AUDIO_GUESS_COUNT 115 |
56 | 56 | ||
57 | +// when got these videos or audios, mix ok. | ||
58 | +#define SRS_MIX_CORRECT_MIX_AV 10 | ||
59 | + | ||
57 | int _srs_time_jitter_string2int(std::string time_jitter) | 60 | int _srs_time_jitter_string2int(std::string time_jitter) |
58 | { | 61 | { |
59 | if (time_jitter == "full") { | 62 | if (time_jitter == "full") { |
@@ -810,6 +813,7 @@ void SrsSource::destroy() | @@ -810,6 +813,7 @@ void SrsSource::destroy() | ||
810 | SrsMixQueue::SrsMixQueue() | 813 | SrsMixQueue::SrsMixQueue() |
811 | { | 814 | { |
812 | nb_videos = 0; | 815 | nb_videos = 0; |
816 | + nb_audios = 0; | ||
813 | } | 817 | } |
814 | 818 | ||
815 | SrsMixQueue::~SrsMixQueue() | 819 | SrsMixQueue::~SrsMixQueue() |
@@ -827,6 +831,7 @@ void SrsMixQueue::clear() | @@ -827,6 +831,7 @@ void SrsMixQueue::clear() | ||
827 | msgs.clear(); | 831 | msgs.clear(); |
828 | 832 | ||
829 | nb_videos = 0; | 833 | nb_videos = 0; |
834 | + nb_audios = 0; | ||
830 | } | 835 | } |
831 | 836 | ||
832 | void SrsMixQueue::push(SrsSharedPtrMessage* msg) | 837 | void SrsMixQueue::push(SrsSharedPtrMessage* msg) |
@@ -835,14 +840,19 @@ void SrsMixQueue::push(SrsSharedPtrMessage* msg) | @@ -835,14 +840,19 @@ void SrsMixQueue::push(SrsSharedPtrMessage* msg) | ||
835 | 840 | ||
836 | if (msg->is_video()) { | 841 | if (msg->is_video()) { |
837 | nb_videos++; | 842 | nb_videos++; |
843 | + } else { | ||
844 | + nb_audios++; | ||
838 | } | 845 | } |
839 | } | 846 | } |
840 | 847 | ||
841 | SrsSharedPtrMessage* SrsMixQueue::pop() | 848 | SrsSharedPtrMessage* SrsMixQueue::pop() |
842 | { | 849 | { |
843 | - // always keep 2+ videos | ||
844 | - if (nb_videos < 2) { | ||
845 | - return NULL; | 850 | + // when got 10+ videos or audios, mix ok. |
851 | + // when got 1 video and 1 audio, mix ok. | ||
852 | + if (nb_videos < SRS_MIX_CORRECT_MIX_AV && nb_audios < SRS_MIX_CORRECT_MIX_AV) { | ||
853 | + if (nb_videos < 1 || nb_audios < 1) { | ||
854 | + return NULL; | ||
855 | + } | ||
846 | } | 856 | } |
847 | 857 | ||
848 | // pop the first msg. | 858 | // pop the first msg. |
@@ -852,6 +862,8 @@ SrsSharedPtrMessage* SrsMixQueue::pop() | @@ -852,6 +862,8 @@ SrsSharedPtrMessage* SrsMixQueue::pop() | ||
852 | 862 | ||
853 | if (msg->is_video()) { | 863 | if (msg->is_video()) { |
854 | nb_videos--; | 864 | nb_videos--; |
865 | + } else { | ||
866 | + nb_audios--; | ||
855 | } | 867 | } |
856 | 868 | ||
857 | return msg; | 869 | return msg; |
@@ -375,6 +375,7 @@ class SrsMixQueue | @@ -375,6 +375,7 @@ class SrsMixQueue | ||
375 | { | 375 | { |
376 | private: | 376 | private: |
377 | u_int32_t nb_videos; | 377 | u_int32_t nb_videos; |
378 | + u_int32_t nb_audios; | ||
378 | std::multimap<int64_t, SrsSharedPtrMessage*> msgs; | 379 | std::multimap<int64_t, SrsSharedPtrMessage*> msgs; |
379 | public: | 380 | public: |
380 | SrsMixQueue(); | 381 | SrsMixQueue(); |
-
请 注册 或 登录 后发表评论