From cf7f54d6f40db4bb751d8ec0d5df2f81b4eda690 Mon Sep 17 00:00:00 2001 From: sprang Date: Thu, 13 Aug 2015 04:37:42 -0700 Subject: [PATCH] Use RtcpPacket to send RPSI in RtcpSender BUG=webrtc:2450 Review URL: https://codereview.webrtc.org/1291013002 Cr-Commit-Position: refs/heads/master@{#9704} --- webrtc/modules/rtp_rtcp/source/rtcp_sender.cc | 61 +++---------------- 1 file changed, 8 insertions(+), 53 deletions(-) diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc b/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc index 066b179c6d..e118fb262c 100644 --- a/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc +++ b/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc @@ -624,61 +624,16 @@ RTCPSender::BuildResult RTCPSender::BuildRPSI(RtcpContext* ctx) { if (ctx->feedback_state.send_payload_type == 0xFF) return BuildResult::kError; - // sanity - if (ctx->position + 24 >= IP_PACKET_SIZE) + rtcp::Rpsi rpsi; + rpsi.From(ssrc_); + rpsi.To(remote_ssrc_); + rpsi.WithPayloadType(ctx->feedback_state.send_payload_type); + rpsi.WithPictureId(ctx->picture_id); + + PacketBuiltCallback callback(ctx); + if (!callback.BuildPacket(rpsi)) return BuildResult::kTruncated; - // add Reference Picture Selection Indication - uint8_t FMT = 3; - *ctx->AllocateData(1) = 0x80 + FMT; - *ctx->AllocateData(1) = 206; - - // calc length - uint32_t bitsRequired = 7; - uint8_t bytesRequired = 1; - while ((ctx->picture_id >> bitsRequired) > 0) { - bitsRequired += 7; - bytesRequired++; - } - - uint8_t size = 3; - if (bytesRequired > 6) { - size = 5; - } else if (bytesRequired > 2) { - size = 4; - } - *ctx->AllocateData(1) = 0; - *ctx->AllocateData(1) = size; - - // Add our own SSRC - ByteWriter::WriteBigEndian(ctx->AllocateData(4), ssrc_); - - // Add the remote SSRC - ByteWriter::WriteBigEndian(ctx->AllocateData(4), remote_ssrc_); - - // calc padding length - uint8_t paddingBytes = 4 - ((2 + bytesRequired) % 4); - if (paddingBytes == 4) - paddingBytes = 0; - // add padding length in bits - *ctx->AllocateData(1) = paddingBytes * 8; // padding can be 0, 8, 16 or 24 - - // add payload type - *ctx->AllocateData(1) = ctx->feedback_state.send_payload_type; - - // add picture ID - for (int i = bytesRequired - 1; i > 0; --i) { - *ctx->AllocateData(1) = - 0x80 | static_cast(ctx->picture_id >> (i * 7)); - } - // add last byte of picture ID - *ctx->AllocateData(1) = static_cast(ctx->picture_id & 0x7f); - - // add padding - for (int j = 0; j < paddingBytes; j++) { - *ctx->AllocateData(1) = 0; - } - return BuildResult::kSuccess; }