mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
RTC: Parse TWCC SN fastly.
This commit is contained in:
parent
79a6907a65
commit
719df6fa41
3 changed files with 65 additions and 8 deletions
|
@ -70,6 +70,68 @@ uint8_t srs_rtp_fast_parse_pt(char* buf, int size)
|
|||
}
|
||||
return buf[1] & 0x7f;
|
||||
}
|
||||
srs_error_t srs_rtp_fast_parse_twcc(char* buf, int size, SrsRtpExtensionTypes* ext_types, uint16_t& twcc_sn)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
int need_size = 12 /*rtp head fix len*/ + 4 /* extension header len*/ + 3 /* twcc extension len*/;
|
||||
if(size < (need_size)) {
|
||||
return srs_error_new(ERROR_RTC_RTP_MUXER, "required %d bytes, actual %d", need_size, size);
|
||||
}
|
||||
|
||||
uint8_t first = buf[0];
|
||||
bool extension = (first & 0x10);
|
||||
uint8_t cc = (first & 0x0F);
|
||||
|
||||
if(!extension) {
|
||||
return srs_error_new(ERROR_RTC_RTP, "no extension in rtp");
|
||||
}
|
||||
|
||||
need_size += cc * 4; // csrc size
|
||||
if(size < (need_size)) {
|
||||
return srs_error_new(ERROR_RTC_RTP_MUXER, "required %d bytes, actual %d", need_size, size);
|
||||
}
|
||||
buf += 12 + 4*cc;
|
||||
|
||||
uint16_t value = *((uint16_t*)buf);
|
||||
value = ntohs(value);
|
||||
if(0xBEDE != value) {
|
||||
return srs_error_new(ERROR_RTC_RTP_MUXER, "no support this type(0x%02x) extension", value);
|
||||
}
|
||||
buf += 2;
|
||||
|
||||
uint16_t extension_length = ntohs(*((uint16_t*)buf));
|
||||
buf += 2;
|
||||
extension_length *= 4;
|
||||
need_size += extension_length; // entension size
|
||||
if(size < (need_size)) {
|
||||
return srs_error_new(ERROR_RTC_RTP_MUXER, "required %d bytes, actual %d", need_size, size);
|
||||
}
|
||||
|
||||
while(extension_length > 0) {
|
||||
uint8_t v = buf[0];
|
||||
buf++;
|
||||
extension_length--;
|
||||
if(0 == v) {
|
||||
continue;
|
||||
}
|
||||
|
||||
uint8_t id = (v & 0xF0) >>4;
|
||||
uint8_t len = (v & 0x0F) + 1;
|
||||
|
||||
SrsRtpExtensionType xtype = ext_types->get_type(id);
|
||||
if(xtype == kRtpExtensionTransportSequenceNumber) {
|
||||
twcc_sn = ntohs(*((uint16_t*)buf));
|
||||
return err;
|
||||
} else {
|
||||
buf += len;
|
||||
extension_length -= len;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
// If value is newer than pre_value,return true; otherwise false
|
||||
bool srs_seq_is_newer(uint16_t value, uint16_t pre_value)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue