1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-15 04:42:04 +00:00

Refactor publisher ring buffer, allow startup drop frame

This commit is contained in:
winlin 2020-05-03 18:07:09 +08:00
parent 2dc8e8dca1
commit 128fc9d8c7
2 changed files with 6 additions and 14 deletions

View file

@ -192,7 +192,7 @@ uint32_t SrsRtpRingBuffer::get_extended_highest_sequence()
return nn_seq_flip_backs * 65536 + high_; return nn_seq_flip_backs * 65536 + high_;
} }
void SrsRtpRingBuffer::update(uint16_t seq, bool startup, uint16_t& nack_low, uint16_t& nack_high) void SrsRtpRingBuffer::update(uint16_t seq, uint16_t& nack_low, uint16_t& nack_high)
{ {
if (!initialized_) { if (!initialized_) {
initialized_ = true; initialized_ = true;
@ -219,11 +219,8 @@ void SrsRtpRingBuffer::update(uint16_t seq, bool startup, uint16_t& nack_low, ui
// When startup, we may receive packets in chaos order. // When startup, we may receive packets in chaos order.
// Because we don't know the ISN(initiazlie sequence number), the first packet // Because we don't know the ISN(initiazlie sequence number), the first packet
// we received maybe no the first packet client sent. // we received maybe no the first packet client sent.
if (startup) { // @remark We only log a warning, because it seems ok for publisher.
nack_low = seq + 1; srs_warn("too old seq %u, range [%u, %u]", seq, low_, high_);
nack_high = low_;
low_ = seq;
}
} }
} }
@ -234,7 +231,6 @@ SrsRtpPacket2* SrsRtpRingBuffer::at(uint16_t seq)
SrsRtpQueue::SrsRtpQueue(int capacity) SrsRtpQueue::SrsRtpQueue(int capacity)
{ {
nn_collected_frames = 0;
queue_ = new SrsRtpRingBuffer(capacity); queue_ = new SrsRtpRingBuffer(capacity);
jitter_ = 0; jitter_ = 0;
@ -288,9 +284,9 @@ srs_error_t SrsRtpQueue::consume(SrsRtpNackForReceiver* nack, SrsRtpPacket2* pkt
if (!nack_info) { if (!nack_info) {
++num_of_packet_received_; ++num_of_packet_received_;
uint16_t nack_low = 0, nack_high = 0; uint16_t nack_low = 0, nack_high = 0;
queue_->update(seq, !nn_collected_frames, nack_low, nack_high); queue_->update(seq, nack_low, nack_high);
if (srs_rtp_seq_distance(nack_low, nack_high)) { if (srs_rtp_seq_distance(nack_low, nack_high)) {
srs_trace("update nack seq=%u, startup=%d, range [%u, %u]", seq, !nn_collected_frames, nack_low, nack_high); srs_trace("update seq=%u, nack range [%u, %u]", seq, nack_low, nack_high);
insert_into_nack_list(nack, nack_low, nack_high); insert_into_nack_list(nack, nack_low, nack_high);
} }
} }
@ -374,8 +370,6 @@ void SrsRtpAudioQueue::collect_frames(SrsRtpNackForReceiver* nack, vector<SrsRtp
break; break;
} }
// OK, collect packet to frame.
nn_collected_frames++;
frames.push_back(pkt); frames.push_back(pkt);
} }
@ -474,7 +468,6 @@ void SrsRtpVideoQueue::collect_frames(SrsRtpNackForReceiver* nack, std::vector<S
return; return;
} }
nn_collected_frames++;
frames.push_back(pkt); frames.push_back(pkt);
} }

View file

@ -146,7 +146,7 @@ public:
// The highest sequence number, calculate the flip back base. // The highest sequence number, calculate the flip back base.
uint32_t get_extended_highest_sequence(); uint32_t get_extended_highest_sequence();
// Update the sequence, got the nack range by [low, high]. // Update the sequence, got the nack range by [low, high].
void update(uint16_t seq, bool startup, uint16_t& nack_low, uint16_t& nack_high); void update(uint16_t seq, uint16_t& nack_low, uint16_t& nack_high);
// Get the packet by seq. // Get the packet by seq.
SrsRtpPacket2* at(uint16_t seq); SrsRtpPacket2* at(uint16_t seq);
}; };
@ -163,7 +163,6 @@ private:
uint64_t number_of_packet_lossed_; uint64_t number_of_packet_lossed_;
protected: protected:
SrsRtpRingBuffer* queue_; SrsRtpRingBuffer* queue_;
uint64_t nn_collected_frames;
public: public:
SrsRtpQueue(int capacity); SrsRtpQueue(int capacity);
virtual ~SrsRtpQueue(); virtual ~SrsRtpQueue();