blob: 3db3394f6de03fee58eae7035c52ca894dad3cc9 [file] [log] [blame]
danilchapf8385ad2015-11-27 05:36:09 -08001/*
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
danilchapf752f852016-03-23 08:25:25 -070013#include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h"
Edward Lemurc20978e2017-07-06 19:44:34 +020014#include "webrtc/rtc_base/checks.h"
15#include "webrtc/rtc_base/logging.h"
danilchapf8385ad2015-11-27 05:36:09 -080016
17namespace webrtc {
18namespace rtcp {
danilchap2f255d82016-10-17 02:07:54 -070019constexpr uint8_t Pli::kFeedbackMessageType;
danilchapf8385ad2015-11-27 05:36:09 -080020// 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.
danilchapf752f852016-03-23 08:25:25 -070039bool Pli::Parse(const CommonHeader& packet) {
danilchap2f255d82016-10-17 02:07:54 -070040 RTC_DCHECK_EQ(packet.type(), kPacketType);
41 RTC_DCHECK_EQ(packet.fmt(), kFeedbackMessageType);
danilchapf8385ad2015-11-27 05:36:09 -080042
danilchapf752f852016-03-23 08:25:25 -070043 if (packet.payload_size_bytes() < kCommonFeedbackLength) {
danilchapf8385ad2015-11-27 05:36:09 -080044 LOG(LS_WARNING) << "Packet is too small to be a valid PLI packet";
45 return false;
46 }
47
danilchapf752f852016-03-23 08:25:25 -070048 ParseCommonFeedback(packet.payload());
danilchapf8385ad2015-11-27 05:36:09 -080049 return true;
50}
51
eladalon8fa21c42017-06-16 07:07:47 -070052size_t Pli::BlockLength() const {
53 return kHeaderLength + kCommonFeedbackLength;
54}
55
danilchapf8385ad2015-11-27 05:36:09 -080056bool 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