rtcp: Helper function for reading rtcp header

This commit is contained in:
Joni Räsänen 2021-06-08 15:09:05 +03:00
parent 8bb7340029
commit c337b803d5
6 changed files with 23 additions and 24 deletions

View File

@ -357,6 +357,9 @@ namespace uvgrtp {
rtp_error_t construct_rtcp_header(size_t packet_size, uint8_t*& frame,
uint16_t secondField, uvgrtp::frame::RTCP_FRAME_TYPE frame_type, bool addLocalSSRC);
/* read the header values from rtcp packet */
void read_rtcp_header(uint8_t* packet, uvgrtp::frame::rtcp_header& header, bool app);
/* Pointer to RTP context from which clock rate etc. info is collected and which is
* used to change SSRC if a collision is detected */
uvgrtp::rtp *rtp_;

View File

@ -543,4 +543,16 @@ rtp_error_t uvgrtp::rtcp::construct_rtcp_header(size_t packet_size,
}
return RTP_OK;
}
void uvgrtp::rtcp::read_rtcp_header(uint8_t* packet, uvgrtp::frame::rtcp_header& header, bool app)
{
header.version = (packet[0] >> 6) & 0x3;
header.padding = (packet[0] >> 5) & 0x1;
if (app)
header.pkt_subtype = packet[0] & 0x1f;
else
header.count = packet[0] & 0x1f;
header.length = ntohs(*(uint16_t*)&packet[2]);
}

View File

@ -29,14 +29,10 @@ rtp_error_t uvgrtp::rtcp::handle_app_packet(uint8_t *packet, size_t size)
return RTP_INVALID_VALUE;
auto frame = new uvgrtp::frame::rtcp_app_packet;
auto ret = RTP_OK;
frame->header.version = (packet[0] >> 6) & 0x3;
frame->header.padding = (packet[0] >> 5) & 0x1;
frame->header.pkt_subtype = packet[0] & 0x1f;
frame->header.length = ntohs(*(uint16_t *)&packet[2]);
read_rtcp_header(packet, frame->header, true);
frame->ssrc = ntohl(*(uint32_t *)&packet[4]);
auto ret = RTP_OK;
if (srtcp_ && (ret = srtcp_->handle_rtcp_decryption(flags_, frame->ssrc, packet, size)) != RTP_OK)
return ret;

View File

@ -29,14 +29,10 @@ rtp_error_t uvgrtp::rtcp::handle_receiver_report_packet(uint8_t *packet, size_t
return RTP_INVALID_VALUE;
auto frame = new uvgrtp::frame::rtcp_receiver_report;
auto ret = RTP_OK;
frame->header.version = (packet[0] >> 6) & 0x3;
frame->header.padding = (packet[0] >> 5) & 0x1;
frame->header.count = packet[0] & 0x1f;
frame->header.length = ntohs(*(uint16_t *)&packet[2]);
read_rtcp_header(packet, frame->header, false);
frame->ssrc = ntohl(*(uint32_t *)&packet[4]);
auto ret = RTP_OK;
if (srtcp_ && (ret = srtcp_->handle_rtcp_decryption(flags_, frame->ssrc, packet, size)) != RTP_OK)
return ret;

View File

@ -29,14 +29,10 @@ rtp_error_t uvgrtp::rtcp::handle_sdes_packet(uint8_t *packet, size_t size)
return RTP_INVALID_VALUE;
auto frame = new uvgrtp::frame::rtcp_sdes_packet;
auto ret = RTP_OK;
frame->header.version = (packet[0] >> 6) & 0x3;
frame->header.padding = (packet[0] >> 5) & 0x1;
frame->header.count = packet[0] & 0x1f;
frame->header.length = ntohs(*(uint16_t *)&packet[2]);
read_rtcp_header(packet, frame->header, false);
frame->ssrc = ntohl(*(uint32_t *)&packet[4]);
auto ret = RTP_OK;
if (srtcp_ && (ret = srtcp_->handle_rtcp_decryption(flags_, frame->ssrc, packet, size)) != RTP_OK)
return ret;

View File

@ -29,14 +29,10 @@ rtp_error_t uvgrtp::rtcp::handle_sender_report_packet(uint8_t *packet, size_t si
return RTP_INVALID_VALUE;
auto frame = new uvgrtp::frame::rtcp_sender_report;
auto ret = RTP_OK;
frame->header.version = (packet[0] >> 6) & 0x3;
frame->header.padding = (packet[0] >> 5) & 0x1;
frame->header.count = packet[0] & 0x1f;
frame->header.length = ntohs(*(uint16_t *)&packet[2]);
read_rtcp_header(packet, frame->header, false);
frame->ssrc = ntohl(*(uint32_t *)&packet[4]);
auto ret = RTP_OK;
if (srtcp_ && (ret = srtcp_->handle_rtcp_decryption(flags_, frame->ssrc, packet, size)) != RTP_OK)
return ret;