mirror of
https://github.com/ossrs/srs.git
synced 2025-02-15 04:42:04 +00:00
Refactor the RTC sender audio queue
This commit is contained in:
parent
a23f102874
commit
a812183144
4 changed files with 16 additions and 36 deletions
|
@ -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(
|
||||
|
|
|
@ -1936,20 +1936,16 @@ srs_error_t SrsRtcPublisher::collect_audio_frames()
|
|||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
std::vector<std::vector<SrsRtpPacket2*> > frames;
|
||||
std::vector<SrsRtpPacket2*> frames;
|
||||
audio_queue_->collect_frames(audio_nack_, frames);
|
||||
|
||||
for (size_t i = 0; i < frames.size(); ++i) {
|
||||
vector<SrsRtpPacket2*>& 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;
|
||||
|
|
|
@ -408,21 +408,7 @@ SrsRtpAudioQueue::~SrsRtpAudioQueue()
|
|||
{
|
||||
}
|
||||
|
||||
void SrsRtpAudioQueue::collect_frames(SrsRtpNackForReceiver* nack, std::vector<std::vector<SrsRtpPacket2*> >& 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<vector<SrsRtpPacket2*> >& frames, SrsRtpNackForReceiver* nack)
|
||||
void SrsRtpAudioQueue::collect_frames(SrsRtpNackForReceiver* nack, vector<SrsRtpPacket2*>& frames)
|
||||
{
|
||||
// When done, s point to the next available packet.
|
||||
uint16_t next = queue_->low();
|
||||
|
@ -437,12 +423,8 @@ void SrsRtpAudioQueue::collect_packet(vector<vector<SrsRtpPacket2*> >& frames, S
|
|||
}
|
||||
|
||||
// OK, collect packet to frame.
|
||||
vector<SrsRtpPacket2*> 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<vector<SrsRtpPacket2*> >& 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)
|
||||
|
|
|
@ -193,10 +193,7 @@ public:
|
|||
SrsRtpAudioQueue(int capacity);
|
||||
virtual ~SrsRtpAudioQueue();
|
||||
public:
|
||||
virtual void collect_frames(SrsRtpNackForReceiver* nack, std::vector<std::vector<SrsRtpPacket2*> >& frames);
|
||||
private:
|
||||
virtual void on_overflow(SrsRtpNackForReceiver* nack);
|
||||
virtual void collect_packet(std::vector<std::vector<SrsRtpPacket2*> >& frames, SrsRtpNackForReceiver* nack);
|
||||
virtual void collect_frames(SrsRtpNackForReceiver* nack, std::vector<SrsRtpPacket2*>& frames);
|
||||
};
|
||||
|
||||
class SrsRtpVideoQueue : public SrsRtpQueue
|
||||
|
|
Loading…
Reference in a new issue