pli.cc (2628B)
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 <cstddef> 14 #include <cstdint> 15 16 #include "modules/rtp_rtcp/source/rtcp_packet/common_header.h" 17 #include "rtc_base/checks.h" 18 #include "rtc_base/logging.h" 19 20 namespace webrtc { 21 namespace rtcp { 22 // RFC 4585: Feedback format. 23 // 24 // Common packet format: 25 // 26 // 0 1 2 3 27 // 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 28 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 29 // |V=2|P| FMT | PT | length | 30 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 31 // | SSRC of packet sender | 32 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 33 // | SSRC of media source | 34 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 35 // : Feedback Control Information (FCI) : 36 // : : 37 38 Pli::Pli() = default; 39 40 Pli::Pli(const Pli& pli) = default; 41 42 Pli::~Pli() = default; 43 44 // 45 // Picture loss indication (PLI) (RFC 4585). 46 // FCI: no feedback control information. 47 bool Pli::Parse(const CommonHeader& packet) { 48 RTC_DCHECK_EQ(packet.type(), kPacketType); 49 RTC_DCHECK_EQ(packet.fmt(), kFeedbackMessageType); 50 51 if (packet.payload_size_bytes() < kCommonFeedbackLength) { 52 RTC_LOG(LS_WARNING) << "Packet is too small to be a valid PLI packet"; 53 return false; 54 } 55 56 ParseCommonFeedback(packet.payload()); 57 return true; 58 } 59 60 size_t Pli::BlockLength() const { 61 return kHeaderLength + kCommonFeedbackLength; 62 } 63 64 bool Pli::Create(uint8_t* packet, 65 size_t* index, 66 size_t max_length, 67 PacketReadyCallback callback) const { 68 while (*index + BlockLength() > max_length) { 69 if (!OnBufferFull(packet, index, callback)) 70 return false; 71 } 72 73 CreateHeader(kFeedbackMessageType, kPacketType, HeaderLength(), packet, 74 index); 75 CreateCommonFeedback(packet + *index); 76 *index += kCommonFeedbackLength; 77 return true; 78 } 79 80 } // namespace rtcp 81 } // namespace webrtc