RTC: Support ignore padding for RTP header

pull/1831/head
winlin 5 years ago
parent 6ff048ed35
commit e9731fe0c1

@ -1196,21 +1196,24 @@ srs_error_t SrsRtcPublisher::on_rtp(char* data, int nb_data)
return err;
}
// We must parse the TWCC from RTP header before SRTP unprotect, because:
// 1. Client may send some padding packets with invalid SequenceNumber, which causes the SRTP fail.
// 2. Server may send multiple duplicated NACK to client, and got more than one ARQ packet, which also fail SRTP.
// so, we must parse the header before SRTP unprotect(which may fail and drop packet).
if (0 != twcc_ext_id_) {
SrsBuffer b0(data, nb_data); SrsRtpHeader h0;
h0.set_decode_only_header(true);
h0.ignore_padding(true);
h0.set_extensions(&extension_types_);
if ((err = h0.decode(&b0)) != srs_success) {
return srs_error_wrap(err, "process twcc to decode rtp header");
return srs_error_wrap(err, "twcc decode header");
}
uint16_t twcc_sn = 0;
if ((err = h0.get_twcc_sequence_number(twcc_sn)) == srs_success) {
if((err = on_twcc(twcc_sn)) != srs_success) {
return srs_error_wrap(err, "fail to process twcc packet");
return srs_error_wrap(err, "on twcc");
}
} else {
// TODO: FIXME: process no twcc seq number for audio ssrc
srs_error_reset(err);
}
}

@ -319,7 +319,7 @@ SrsRtpHeader::SrsRtpHeader()
sequence = 0;
timestamp = 0;
ssrc = 0;
decode_only_header_ = false;
ignore_padding_ = false;
}
SrsRtpHeader::~SrsRtpHeader()
@ -377,7 +377,7 @@ srs_error_t SrsRtpHeader::decode(SrsBuffer* buf)
}
}
if (padding && !buf->empty() && !decode_only_header_) {
if (padding && !ignore_padding_ && !buf->empty()) {
padding_length = *(reinterpret_cast<uint8_t*>(buf->data() + buf->size() - 1));
if (!buf->require(padding_length)) {
return srs_error_new(ERROR_RTC_RTP_MUXER, "padding requires %d bytes", padding_length);
@ -449,9 +449,9 @@ void SrsRtpHeader::set_extensions(const SrsRtpExtensionTypes* extmap)
}
}
void SrsRtpHeader::set_decode_only_header(bool only_header)
void SrsRtpHeader::ignore_padding(bool v)
{
decode_only_header_ = only_header;
ignore_padding_ = v;
}
srs_error_t SrsRtpHeader::get_twcc_sequence_number(uint16_t& twcc_sn)

@ -175,7 +175,7 @@ private:
uint32_t ssrc;
uint32_t csrc[15];
SrsRtpExtensions extensions_;
bool decode_only_header_;
bool ignore_padding_;
public:
SrsRtpHeader();
virtual ~SrsRtpHeader();
@ -200,7 +200,7 @@ public:
void set_padding(uint8_t v);
uint8_t get_padding() const;
void set_extensions(const SrsRtpExtensionTypes* extmap);
void set_decode_only_header(bool only_header);
void ignore_padding(bool v);
srs_error_t get_twcc_sequence_number(uint16_t& twcc_sn);
srs_error_t set_twcc_sequence_number(uint8_t id, uint16_t sn);
};

Loading…
Cancel
Save