Chromium Code Reviews| Index: webrtc/modules/rtp_rtcp/source/rtcp_sender.cc |
| diff --git a/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc b/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc |
| index 55ca9a72f98a6b538d2955ce6b143329db551d8d..49e44a634daf58a13de638606bca394e818da2c0 100644 |
| --- a/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc |
| +++ b/webrtc/modules/rtp_rtcp/source/rtcp_sender.cc |
| @@ -120,6 +120,12 @@ class RTCPSender::PacketBuiltCallback |
| void OnPacketReady(uint8_t* data, size_t length) override { |
| context_->position += length; |
| } |
| + bool BuildPacket(const rtcp::RtcpPacket& packet) { |
| + return packet.BuildExternalBuffer( |
| + &context_->buffer[context_->position], |
| + context_->buffer_size - context_->position, |
| + this); |
|
åsapersson
2015/07/31 13:36:42
nit: remove extra space
sprang_webrtc
2015/07/31 14:15:53
Done.
|
| + } |
| private: |
| RtcpContext* const context_; |
| @@ -501,11 +507,8 @@ RTCPSender::BuildResult RTCPSender::BuildSR(RtcpContext* ctx) { |
| report.WithReportBlock(it.second); |
| PacketBuiltCallback callback(ctx); |
| - if (!report.BuildExternalBuffer(&ctx->buffer[ctx->position], |
| - ctx->buffer_size - ctx->position, |
| - &callback)) { |
| + if (!callback.BuildPacket(report)) |
| return BuildResult::kTruncated; |
| - } |
| report_blocks_.clear(); |
| return BuildResult::kSuccess; |
| @@ -522,10 +525,8 @@ RTCPSender::BuildResult RTCPSender::BuildSDES(RtcpContext* ctx) { |
| sdes.WithCName(it.first, it.second); |
| PacketBuiltCallback callback(ctx); |
| - if (!sdes.BuildExternalBuffer(&ctx->buffer[ctx->position], |
| - ctx->buffer_size - ctx->position, &callback)) { |
| + if (!callback.BuildPacket(sdes)) |
| return BuildResult::kTruncated; |
| - } |
| return BuildResult::kSuccess; |
| } |
| @@ -537,11 +538,8 @@ RTCPSender::BuildResult RTCPSender::BuildRR(RtcpContext* ctx) { |
| report.WithReportBlock(it.second); |
| PacketBuiltCallback callback(ctx); |
| - if (!report.BuildExternalBuffer(&ctx->buffer[ctx->position], |
| - ctx->buffer_size - ctx->position, |
| - &callback)) { |
| + if (!callback.BuildPacket(report)) |
| return BuildResult::kTruncated; |
| - } |
| report_blocks_.clear(); |
| @@ -549,24 +547,13 @@ RTCPSender::BuildResult RTCPSender::BuildRR(RtcpContext* ctx) { |
| } |
| RTCPSender::BuildResult RTCPSender::BuildPLI(RtcpContext* ctx) { |
| - // sanity |
| - if (ctx->position + 12 >= IP_PACKET_SIZE) |
| - return BuildResult::kTruncated; |
| - |
| - // add picture loss indicator |
| - uint8_t FMT = 1; |
| - *ctx->AllocateData(1) = 0x80 + FMT; |
| - *ctx->AllocateData(1) = 206; |
| + rtcp::Pli pli; |
| + pli.From(ssrc_); |
| + pli.To(remote_ssrc_); |
| - // Used fixed length of 2 |
| - *ctx->AllocateData(1) = 0; |
| - *ctx->AllocateData(1) = 2; |
| - |
| - // Add our own SSRC |
| - ByteWriter<uint32_t>::WriteBigEndian(ctx->AllocateData(4), ssrc_); |
| - |
| - // Add the remote SSRC |
| - ByteWriter<uint32_t>::WriteBigEndian(ctx->AllocateData(4), remote_ssrc_); |
| + PacketBuiltCallback callback(ctx); |
| + if (!callback.BuildPacket(pli)) |
| + return BuildResult::kTruncated; |
| TRACE_EVENT_INSTANT0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), |
| "RTCPSender::PLI"); |