• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3  *
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
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include "modules/rtp_rtcp/source/rtcp_packet/pli.h"
12 
13 #include "modules/rtp_rtcp/source/rtcp_packet/common_header.h"
14 #include "rtc_base/checks.h"
15 #include "rtc_base/logging.h"
16 
17 namespace webrtc {
18 namespace rtcp {
19 constexpr uint8_t Pli::kFeedbackMessageType;
20 // RFC 4585: Feedback format.
21 //
22 // Common packet format:
23 //
24 //   0                   1                   2                   3
25 //   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
26 //  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
27 //  |V=2|P|   FMT   |       PT      |          length               |
28 //  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
29 //  |                  SSRC of packet sender                        |
30 //  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
31 //  |                  SSRC of media source                         |
32 //  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
33 //  :            Feedback Control Information (FCI)                 :
34 //  :                                                               :
35 
36 Pli::Pli() = default;
37 
38 Pli::Pli(const Pli& pli) = default;
39 
40 Pli::~Pli() = default;
41 
42 //
43 // Picture loss indication (PLI) (RFC 4585).
44 // FCI: no feedback control information.
Parse(const CommonHeader & packet)45 bool Pli::Parse(const CommonHeader& packet) {
46   RTC_DCHECK_EQ(packet.type(), kPacketType);
47   RTC_DCHECK_EQ(packet.fmt(), kFeedbackMessageType);
48 
49   if (packet.payload_size_bytes() < kCommonFeedbackLength) {
50     RTC_LOG(LS_WARNING) << "Packet is too small to be a valid PLI packet";
51     return false;
52   }
53 
54   ParseCommonFeedback(packet.payload());
55   return true;
56 }
57 
BlockLength() const58 size_t Pli::BlockLength() const {
59   return kHeaderLength + kCommonFeedbackLength;
60 }
61 
Create(uint8_t * packet,size_t * index,size_t max_length,PacketReadyCallback callback) const62 bool Pli::Create(uint8_t* packet,
63                  size_t* index,
64                  size_t max_length,
65                  PacketReadyCallback callback) const {
66   while (*index + BlockLength() > max_length) {
67     if (!OnBufferFull(packet, index, callback))
68       return false;
69   }
70 
71   CreateHeader(kFeedbackMessageType, kPacketType, HeaderLength(), packet,
72                index);
73   CreateCommonFeedback(packet + *index);
74   *index += kCommonFeedbackLength;
75   return true;
76 }
77 
78 }  // namespace rtcp
79 }  // namespace webrtc
80