Refine on_rtcp for RTC

pull/1754/head
winlin 5 years ago
parent 9614af070c
commit 26bcc09017

File diff suppressed because it is too large Load Diff

@ -267,6 +267,14 @@ public:
void simulate_nack_drop(int nn);
private:
void simulate_drop_packet(SrsRtpHeader* h, int nn_bytes);
public:
srs_error_t on_rtcp(char* data, int nb_data);
private:
srs_error_t on_rtcp_sr(char* buf, int nb_buf);
srs_error_t on_rtcp_xr(char* buf, int nb_buf);
srs_error_t on_rtcp_feedback(char* data, int nb_data);
srs_error_t on_rtcp_ps_feedback(char* data, int nb_data);
srs_error_t on_rtcp_rr(char* data, int nb_data);
};
class SrsRtcPublisher : virtual public ISrsHourGlass, virtual public ISrsRtpPacketDecodeHandler
@ -298,8 +306,6 @@ public:
virtual ~SrsRtcPublisher();
public:
srs_error_t initialize(uint32_t vssrc, uint32_t assrc, SrsRequest* req);
srs_error_t on_rtcp_sender_report(char* buf, int nb_buf);
srs_error_t on_rtcp_xr(char* buf, int nb_buf);
private:
void check_send_nacks(SrsRtpNackForReceiver* nack, uint32_t ssrc);
srs_error_t send_rtcp_rr(uint32_t ssrc, SrsRtpQueue* rtp_queue);
@ -308,11 +314,17 @@ private:
public:
srs_error_t on_rtp(char* buf, int nb_buf);
virtual void on_before_decode_payload(SrsRtpPacket2* pkt, SrsBuffer* buf, ISrsCodec** ppayload);
srs_error_t on_rtcp(char* data, int nb_data);
private:
srs_error_t on_audio(SrsRtpPacket2* pkt);
srs_error_t on_audio_frame(SrsRtpPacket2* frame);
srs_error_t on_video(SrsRtpPacket2* pkt);
srs_error_t on_video_frame(SrsRtpPacket2* frame);
srs_error_t on_rtcp_sr(char* buf, int nb_buf);
srs_error_t on_rtcp_xr(char* buf, int nb_buf);
srs_error_t on_rtcp_feedback(char* data, int nb_data);
srs_error_t on_rtcp_ps_feedback(char* data, int nb_data);
srs_error_t on_rtcp_rr(char* data, int nb_data);
public:
void request_keyframe();
// interface ISrsHourGlass
@ -382,8 +394,8 @@ public:
// The peer address may change, we can identify that by STUN messages.
srs_error_t on_stun(SrsUdpMuxSocket* skt, SrsStunPacket* r);
srs_error_t on_dtls(char* data, int nb_data);
srs_error_t on_rtcp(char* data, int nb_data);
srs_error_t on_rtp(char* data, int nb_data);
srs_error_t on_rtcp(char* data, int nb_data);
public:
srs_error_t on_connection_established();
srs_error_t start_play();
@ -395,11 +407,6 @@ public:
void simulate_nack_drop(int nn);
private:
srs_error_t on_binding_request(SrsStunPacket* r);
srs_error_t on_rtcp_feedback(char* data, int nb_data);
srs_error_t on_rtcp_ps_feedback(char* data, int nb_data);
srs_error_t on_rtcp_xr(char* data, int nb_data);
srs_error_t on_rtcp_sender_report(char* data, int nb_data);
srs_error_t on_rtcp_receiver_report(char* data, int nb_data);
};
class SrsUdpMuxSender : virtual public ISrsUdpSender, virtual public ISrsCoroutineHandler, virtual public ISrsReloadHandler

@ -226,9 +226,26 @@ void SrsRtpQueue::insert_into_nack_list(SrsRtpNackForReceiver* nack, uint16_t fi
nack->check_queue_size();
}
SrsRtpAudioPacket::SrsRtpAudioPacket()
{
pkt = NULL;
}
SrsRtpAudioPacket::~SrsRtpAudioPacket()
{
srs_freep(pkt);
}
SrsRtpPacket2* SrsRtpAudioPacket::detach()
{
SrsRtpPacket2* p = pkt;
pkt = NULL;
return p;
}
SrsRtpAudioQueue::SrsRtpAudioQueue(int capacity)
{
queue_ = new SrsRtpRingBuffer<SrsRtpPacket2*>(capacity);
queue_ = new SrsRtpRingBuffer<SrsRtpAudioPacket*>(capacity);
}
SrsRtpAudioQueue::~SrsRtpAudioQueue()
@ -287,7 +304,9 @@ srs_error_t SrsRtpAudioQueue::consume(SrsRtpNackForReceiver* nack, SrsRtpPacket2
}
// Save packet at the position seq.
queue_->set(seq, pkt);
SrsRtpAudioPacket* apkt = new SrsRtpAudioPacket();
apkt->pkt = pkt;
queue_->set(seq, apkt);
return err;
}
@ -300,14 +319,14 @@ void SrsRtpAudioQueue::collect_frames(SrsRtpNackForReceiver* nack, vector<SrsRtp
// If nack disabled, we ignore any empty packet.
if (!nack) {
for (; next != queue_->end; ++next) {
SrsRtpPacket2* pkt = queue_->at(next);
SrsRtpAudioPacket* pkt = queue_->at(next);
if (pkt) {
frames.push_back(pkt);
frames.push_back(pkt->detach());
}
}
} else {
for (; next != queue_->end; ++next) {
SrsRtpPacket2* pkt = queue_->at(next);
SrsRtpAudioPacket* pkt = queue_->at(next);
// TODO: FIXME: Should not wait for NACK packets.
// Not found or in NACK, stop collecting frame.
@ -316,15 +335,12 @@ void SrsRtpAudioQueue::collect_frames(SrsRtpNackForReceiver* nack, vector<SrsRtp
break;
}
frames.push_back(pkt);
frames.push_back(pkt->detach());
}
}
// Reap packets from begin to next.
if (next != queue_->begin) {
// Reset the range of packets to NULL in buffer.
queue_->reset(queue_->begin, next);
srs_verbose("RTC collect audio [%u, %u, %u]", queue_->begin, next, queue_->end);
queue_->advance_to(next);
}
@ -562,9 +578,6 @@ void SrsRtpVideoQueue::collect_frame(SrsRtpNackForReceiver* nack, SrsRtpPacket2*
}
if (next != queue_->begin) {
// Reset the range of packets to NULL in buffer.
queue_->reset(queue_->begin, next);
srs_verbose("RTC collect video [%u, %u, %u]", queue_->begin, next, queue_->end);
queue_->advance_to(next);
}
@ -572,10 +585,6 @@ void SrsRtpVideoQueue::collect_frame(SrsRtpNackForReceiver* nack, SrsRtpPacket2*
// Merge packets to one packet.
covert_frame(frame, ppkt);
for (int i = 0; i < (int)frame.size(); i++) {
SrsRtpVideoPacket* pkt = frame[i];
srs_freep(pkt);
}
return;
}

@ -173,12 +173,6 @@ public:
void remove(uint16_t at) {
set(at, NULL);
}
// Directly reset range [first, last) to NULL.
void reset(uint16_t first, uint16_t last) {
for (uint16_t s = first; s != last; ++s) {
queue_[s % capacity_] = NULL;
}
}
// Whether queue overflow or heavy(too many packets and need clear).
bool overflow() {
return srs_rtp_seq_distance(begin, end) >= capacity_;
@ -254,10 +248,21 @@ protected:
void insert_into_nack_list(SrsRtpNackForReceiver* nack, uint16_t first, uint16_t last);
};
class SrsRtpAudioPacket
{
public:
SrsRtpPacket2* pkt;
public:
SrsRtpAudioPacket();
virtual ~SrsRtpAudioPacket();
public:
SrsRtpPacket2* detach();
};
class SrsRtpAudioQueue : public SrsRtpQueue
{
private:
SrsRtpRingBuffer<SrsRtpPacket2*>* queue_;
SrsRtpRingBuffer<SrsRtpAudioPacket*>* queue_;
public:
SrsRtpAudioQueue(int capacity);
virtual ~SrsRtpAudioQueue();

Loading…
Cancel
Save