From a812183144f412acbb99e8e5b82ae16d82fc2a0d Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 3 May 2020 14:28:51 +0800 Subject: [PATCH] Refactor the RTC sender audio queue --- trunk/research/players/rtc_publisher.html | 6 ++--- trunk/src/app/srs_app_rtc_conn.cpp | 14 +++++------- trunk/src/app/srs_app_rtp_queue.cpp | 27 ++++++----------------- trunk/src/app/srs_app_rtp_queue.hpp | 5 +---- 4 files changed, 16 insertions(+), 36 deletions(-) diff --git a/trunk/research/players/rtc_publisher.html b/trunk/research/players/rtc_publisher.html index 0035a20aa..bb33c9dec 100644 --- a/trunk/research/players/rtc_publisher.html +++ b/trunk/research/players/rtc_publisher.html @@ -72,9 +72,9 @@ var constraints = { "audio": true, "video": { - "width": { "min": "480", "max": "1920" }, - "height": { "min": "320", "max": "1080" }, - "frameRate": { "min": "15", "max": "60" } + "width": { "min": "480", "max": "720" }, + "height": { "min": "320", "max": "480" }, + "frameRate": { "min": "15", "max": "30" } } }; navigator.mediaDevices.getUserMedia( diff --git a/trunk/src/app/srs_app_rtc_conn.cpp b/trunk/src/app/srs_app_rtc_conn.cpp index df078d71e..19a8d24e1 100644 --- a/trunk/src/app/srs_app_rtc_conn.cpp +++ b/trunk/src/app/srs_app_rtc_conn.cpp @@ -1936,20 +1936,16 @@ srs_error_t SrsRtcPublisher::collect_audio_frames() { srs_error_t err = srs_success; - std::vector > frames; + std::vector frames; audio_queue_->collect_frames(audio_nack_, frames); for (size_t i = 0; i < frames.size(); ++i) { - vector& packets = frames[i]; + SrsRtpPacket2* pkt = frames[i]; - for (size_t j = 0; j < packets.size(); ++j) { - SrsRtpPacket2* pkt = packets[j]; + // TODO: FIXME: Check error. + do_collect_audio_frame(pkt); - // TODO: FIXME: Check error. - do_collect_audio_frame(pkt); - - srs_freep(pkt); - } + srs_freep(pkt); } return err; diff --git a/trunk/src/app/srs_app_rtp_queue.cpp b/trunk/src/app/srs_app_rtp_queue.cpp index a3831949f..511ff90a1 100644 --- a/trunk/src/app/srs_app_rtp_queue.cpp +++ b/trunk/src/app/srs_app_rtp_queue.cpp @@ -408,21 +408,7 @@ SrsRtpAudioQueue::~SrsRtpAudioQueue() { } -void SrsRtpAudioQueue::collect_frames(SrsRtpNackForReceiver* nack, std::vector >& frames) -{ - collect_packet(frames, nack); - - if (queue_->overflow()) { - on_overflow(nack); - } -} - -void SrsRtpAudioQueue::on_overflow(SrsRtpNackForReceiver* nack) -{ - queue_->advance_to(queue_->high()); -} - -void SrsRtpAudioQueue::collect_packet(vector >& frames, SrsRtpNackForReceiver* nack) +void SrsRtpAudioQueue::collect_frames(SrsRtpNackForReceiver* nack, vector& frames) { // When done, s point to the next available packet. uint16_t next = queue_->low(); @@ -437,12 +423,8 @@ void SrsRtpAudioQueue::collect_packet(vector >& frames, S } // OK, collect packet to frame. - vector frame; - frame.push_back(pkt); - - // Done, we got the last packet of frame. nn_collected_frames++; - frames.push_back(frame); + frames.push_back(pkt); } if (queue_->low() != next) { @@ -452,6 +434,11 @@ void SrsRtpAudioQueue::collect_packet(vector >& frames, S srs_verbose("collect on frame, update head seq=%u t %u", queue_->low(), next); queue_->advance_to(next); } + + // For audio, if overflow, clear all packets. + if (queue_->overflow()) { + queue_->advance_to(queue_->high()); + } } SrsRtpVideoQueue::SrsRtpVideoQueue(int capacity) : SrsRtpQueue(capacity) diff --git a/trunk/src/app/srs_app_rtp_queue.hpp b/trunk/src/app/srs_app_rtp_queue.hpp index a605df185..445b2c6a7 100644 --- a/trunk/src/app/srs_app_rtp_queue.hpp +++ b/trunk/src/app/srs_app_rtp_queue.hpp @@ -193,10 +193,7 @@ public: SrsRtpAudioQueue(int capacity); virtual ~SrsRtpAudioQueue(); public: - virtual void collect_frames(SrsRtpNackForReceiver* nack, std::vector >& frames); -private: - virtual void on_overflow(SrsRtpNackForReceiver* nack); - virtual void collect_packet(std::vector >& frames, SrsRtpNackForReceiver* nack); + virtual void collect_frames(SrsRtpNackForReceiver* nack, std::vector& frames); }; class SrsRtpVideoQueue : public SrsRtpQueue