xref: /aosp_15_r20/external/webrtc/modules/rtp_rtcp/source/rtcp_packet/rapid_resync_request.cc (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2016 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/rapid_resync_request.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 RapidResyncRequest::kFeedbackMessageType;
20 // RFC 4585: Feedback format.
21 // Rapid Resynchronisation Request (draft-perkins-avt-rapid-rtp-sync-03).
22 //
23 //   0                   1                   2                   3
24 //   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
25 //  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
26 //  |V=2|P|  FMT=5  |     PT=205    |         length=2              |
27 //  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
28 //  |                  SSRC of packet sender                        |
29 //  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
30 //  |                  SSRC of media source                         |
31 //  +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Parse(const CommonHeader & packet)32 bool RapidResyncRequest::Parse(const CommonHeader& packet) {
33   RTC_DCHECK_EQ(packet.type(), kPacketType);
34   RTC_DCHECK_EQ(packet.fmt(), kFeedbackMessageType);
35 
36   if (packet.payload_size_bytes() != kCommonFeedbackLength) {
37     RTC_LOG(LS_WARNING) << "Packet payload size should be "
38                         << kCommonFeedbackLength << " instead of "
39                         << packet.payload_size_bytes()
40                         << " to be a valid Rapid Resynchronisation Request";
41     return false;
42   }
43 
44   ParseCommonFeedback(packet.payload());
45   return true;
46 }
47 
BlockLength() const48 size_t RapidResyncRequest::BlockLength() const {
49   return kHeaderLength + kCommonFeedbackLength;
50 }
51 
Create(uint8_t * packet,size_t * index,size_t max_length,PacketReadyCallback callback) const52 bool RapidResyncRequest::Create(uint8_t* packet,
53                                 size_t* index,
54                                 size_t max_length,
55                                 PacketReadyCallback callback) const {
56   while (*index + BlockLength() > max_length) {
57     if (!OnBufferFull(packet, index, callback))
58       return false;
59   }
60 
61   CreateHeader(kFeedbackMessageType, kPacketType, HeaderLength(), packet,
62                index);
63   CreateCommonFeedback(packet + *index);
64   *index += kCommonFeedbackLength;
65   return true;
66 }
67 }  // namespace rtcp
68 }  // namespace webrtc
69