Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtcp_sender.cc

Issue 1262153003: Use RtcpPacket to send PLI in RtcpSender (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Formatting Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 // TODO(sprang): Once all builders use RtcpPacket, call SendToNetwork() here. 114 // TODO(sprang): Once all builders use RtcpPacket, call SendToNetwork() here.
115 class RTCPSender::PacketBuiltCallback 115 class RTCPSender::PacketBuiltCallback
116 : public rtcp::RtcpPacket::PacketReadyCallback { 116 : public rtcp::RtcpPacket::PacketReadyCallback {
117 public: 117 public:
118 PacketBuiltCallback(RtcpContext* context) : context_(context) {} 118 PacketBuiltCallback(RtcpContext* context) : context_(context) {}
119 virtual ~PacketBuiltCallback() {} 119 virtual ~PacketBuiltCallback() {}
120 void OnPacketReady(uint8_t* data, size_t length) override { 120 void OnPacketReady(uint8_t* data, size_t length) override {
121 context_->position += length; 121 context_->position += length;
122 } 122 }
123 bool BuildPacket(const rtcp::RtcpPacket& packet) {
124 return packet.BuildExternalBuffer(
125 &context_->buffer[context_->position],
126 context_->buffer_size - context_->position, this);
127 }
123 128
124 private: 129 private:
125 RtcpContext* const context_; 130 RtcpContext* const context_;
126 }; 131 };
127 132
128 RTCPSender::RTCPSender( 133 RTCPSender::RTCPSender(
129 int32_t id, 134 int32_t id,
130 bool audio, 135 bool audio,
131 Clock* clock, 136 Clock* clock,
132 ReceiveStatistics* receive_statistics, 137 ReceiveStatistics* receive_statistics,
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 report.WithNtpSec(ctx->ntp_sec); 499 report.WithNtpSec(ctx->ntp_sec);
495 report.WithNtpFrac(ctx->ntp_frac); 500 report.WithNtpFrac(ctx->ntp_frac);
496 report.WithRtpTimestamp(rtp_timestamp); 501 report.WithRtpTimestamp(rtp_timestamp);
497 report.WithPacketCount(ctx->feedback_state.packets_sent); 502 report.WithPacketCount(ctx->feedback_state.packets_sent);
498 report.WithOctetCount(ctx->feedback_state.media_bytes_sent); 503 report.WithOctetCount(ctx->feedback_state.media_bytes_sent);
499 504
500 for (auto it : report_blocks_) 505 for (auto it : report_blocks_)
501 report.WithReportBlock(it.second); 506 report.WithReportBlock(it.second);
502 507
503 PacketBuiltCallback callback(ctx); 508 PacketBuiltCallback callback(ctx);
504 if (!report.BuildExternalBuffer(&ctx->buffer[ctx->position], 509 if (!callback.BuildPacket(report))
505 ctx->buffer_size - ctx->position,
506 &callback)) {
507 return BuildResult::kTruncated; 510 return BuildResult::kTruncated;
508 }
509 511
510 report_blocks_.clear(); 512 report_blocks_.clear();
511 return BuildResult::kSuccess; 513 return BuildResult::kSuccess;
512 } 514 }
513 515
514 RTCPSender::BuildResult RTCPSender::BuildSDES(RtcpContext* ctx) { 516 RTCPSender::BuildResult RTCPSender::BuildSDES(RtcpContext* ctx) {
515 size_t length_cname = cname_.length(); 517 size_t length_cname = cname_.length();
516 CHECK_LT(length_cname, static_cast<size_t>(RTCP_CNAME_SIZE)); 518 CHECK_LT(length_cname, static_cast<size_t>(RTCP_CNAME_SIZE));
517 519
518 rtcp::Sdes sdes; 520 rtcp::Sdes sdes;
519 sdes.WithCName(ssrc_, cname_); 521 sdes.WithCName(ssrc_, cname_);
520 522
521 for (const auto it : csrc_cnames_) 523 for (const auto it : csrc_cnames_)
522 sdes.WithCName(it.first, it.second); 524 sdes.WithCName(it.first, it.second);
523 525
524 PacketBuiltCallback callback(ctx); 526 PacketBuiltCallback callback(ctx);
525 if (!sdes.BuildExternalBuffer(&ctx->buffer[ctx->position], 527 if (!callback.BuildPacket(sdes))
526 ctx->buffer_size - ctx->position, &callback)) {
527 return BuildResult::kTruncated; 528 return BuildResult::kTruncated;
528 }
529 529
530 return BuildResult::kSuccess; 530 return BuildResult::kSuccess;
531 } 531 }
532 532
533 RTCPSender::BuildResult RTCPSender::BuildRR(RtcpContext* ctx) { 533 RTCPSender::BuildResult RTCPSender::BuildRR(RtcpContext* ctx) {
534 rtcp::ReceiverReport report; 534 rtcp::ReceiverReport report;
535 report.From(ssrc_); 535 report.From(ssrc_);
536 for (auto it : report_blocks_) 536 for (auto it : report_blocks_)
537 report.WithReportBlock(it.second); 537 report.WithReportBlock(it.second);
538 538
539 PacketBuiltCallback callback(ctx); 539 PacketBuiltCallback callback(ctx);
540 if (!report.BuildExternalBuffer(&ctx->buffer[ctx->position], 540 if (!callback.BuildPacket(report))
541 ctx->buffer_size - ctx->position,
542 &callback)) {
543 return BuildResult::kTruncated; 541 return BuildResult::kTruncated;
544 }
545 542
546 report_blocks_.clear(); 543 report_blocks_.clear();
547 544
548 return BuildResult::kSuccess; 545 return BuildResult::kSuccess;
549 } 546 }
550 547
551 RTCPSender::BuildResult RTCPSender::BuildPLI(RtcpContext* ctx) { 548 RTCPSender::BuildResult RTCPSender::BuildPLI(RtcpContext* ctx) {
552 // sanity 549 rtcp::Pli pli;
553 if (ctx->position + 12 >= IP_PACKET_SIZE) 550 pli.From(ssrc_);
551 pli.To(remote_ssrc_);
552
553 PacketBuiltCallback callback(ctx);
554 if (!callback.BuildPacket(pli))
554 return BuildResult::kTruncated; 555 return BuildResult::kTruncated;
555 556
556 // add picture loss indicator
557 uint8_t FMT = 1;
558 *ctx->AllocateData(1) = 0x80 + FMT;
559 *ctx->AllocateData(1) = 206;
560
561 // Used fixed length of 2
562 *ctx->AllocateData(1) = 0;
563 *ctx->AllocateData(1) = 2;
564
565 // Add our own SSRC
566 ByteWriter<uint32_t>::WriteBigEndian(ctx->AllocateData(4), ssrc_);
567
568 // Add the remote SSRC
569 ByteWriter<uint32_t>::WriteBigEndian(ctx->AllocateData(4), remote_ssrc_);
570
571 TRACE_EVENT_INSTANT0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), 557 TRACE_EVENT_INSTANT0(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"),
572 "RTCPSender::PLI"); 558 "RTCPSender::PLI");
573 ++packet_type_counter_.pli_packets; 559 ++packet_type_counter_.pli_packets;
574 TRACE_COUNTER_ID1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RTCP_PLICount", 560 TRACE_COUNTER_ID1(TRACE_DISABLED_BY_DEFAULT("webrtc_rtp"), "RTCP_PLICount",
575 ssrc_, packet_type_counter_.pli_packets); 561 ssrc_, packet_type_counter_.pli_packets);
576 562
577 return BuildResult::kSuccess; 563 return BuildResult::kSuccess;
578 } 564 }
579 565
580 RTCPSender::BuildResult RTCPSender::BuildFIR(RtcpContext* ctx) { 566 RTCPSender::BuildResult RTCPSender::BuildFIR(RtcpContext* ctx) {
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after
1502 1488
1503 bool RTCPSender::AllVolatileFlagsConsumed() const { 1489 bool RTCPSender::AllVolatileFlagsConsumed() const {
1504 for (const ReportFlag& flag : report_flags_) { 1490 for (const ReportFlag& flag : report_flags_) {
1505 if (flag.is_volatile) 1491 if (flag.is_volatile)
1506 return false; 1492 return false;
1507 } 1493 }
1508 return true; 1494 return true;
1509 } 1495 }
1510 1496
1511 } // namespace webrtc 1497 } // namespace webrtc
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698