danilchap | f8385ad | 2015-11-27 05:36:09 -0800 | [diff] [blame] | 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 "webrtc/modules/rtp_rtcp/source/rtcp_packet/pli.h" |
| 12 | |
danilchap | f752f85 | 2016-03-23 08:25:25 -0700 | [diff] [blame] | 13 | #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 14 | #include "webrtc/rtc_base/checks.h" |
| 15 | #include "webrtc/rtc_base/logging.h" |
danilchap | f8385ad | 2015-11-27 05:36:09 -0800 | [diff] [blame] | 16 | |
| 17 | namespace webrtc { |
| 18 | namespace rtcp { |
danilchap | 2f255d8 | 2016-10-17 02:07:54 -0700 | [diff] [blame] | 19 | constexpr uint8_t Pli::kFeedbackMessageType; |
danilchap | f8385ad | 2015-11-27 05:36:09 -0800 | [diff] [blame] | 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 | // |
| 37 | // Picture loss indication (PLI) (RFC 4585). |
| 38 | // FCI: no feedback control information. |
danilchap | f752f85 | 2016-03-23 08:25:25 -0700 | [diff] [blame] | 39 | bool Pli::Parse(const CommonHeader& packet) { |
danilchap | 2f255d8 | 2016-10-17 02:07:54 -0700 | [diff] [blame] | 40 | RTC_DCHECK_EQ(packet.type(), kPacketType); |
| 41 | RTC_DCHECK_EQ(packet.fmt(), kFeedbackMessageType); |
danilchap | f8385ad | 2015-11-27 05:36:09 -0800 | [diff] [blame] | 42 | |
danilchap | f752f85 | 2016-03-23 08:25:25 -0700 | [diff] [blame] | 43 | if (packet.payload_size_bytes() < kCommonFeedbackLength) { |
danilchap | f8385ad | 2015-11-27 05:36:09 -0800 | [diff] [blame] | 44 | LOG(LS_WARNING) << "Packet is too small to be a valid PLI packet"; |
| 45 | return false; |
| 46 | } |
| 47 | |
danilchap | f752f85 | 2016-03-23 08:25:25 -0700 | [diff] [blame] | 48 | ParseCommonFeedback(packet.payload()); |
danilchap | f8385ad | 2015-11-27 05:36:09 -0800 | [diff] [blame] | 49 | return true; |
| 50 | } |
| 51 | |
eladalon | 8fa21c4 | 2017-06-16 07:07:47 -0700 | [diff] [blame] | 52 | size_t Pli::BlockLength() const { |
| 53 | return kHeaderLength + kCommonFeedbackLength; |
| 54 | } |
| 55 | |
danilchap | f8385ad | 2015-11-27 05:36:09 -0800 | [diff] [blame] | 56 | bool Pli::Create(uint8_t* packet, |
| 57 | size_t* index, |
| 58 | size_t max_length, |
| 59 | RtcpPacket::PacketReadyCallback* callback) const { |
| 60 | while (*index + BlockLength() > max_length) { |
| 61 | if (!OnBufferFull(packet, index, callback)) |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | CreateHeader(kFeedbackMessageType, kPacketType, HeaderLength(), packet, |
| 66 | index); |
| 67 | CreateCommonFeedback(packet + *index); |
| 68 | *index += kCommonFeedbackLength; |
| 69 | return true; |
| 70 | } |
| 71 | |
| 72 | } // namespace rtcp |
| 73 | } // namespace webrtc |