Line data Source code
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 "webrtc/modules/rtp_rtcp/source/rtcp_packet/sli.h"
12 :
13 : #include "webrtc/base/checks.h"
14 : #include "webrtc/base/logging.h"
15 : #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
16 : #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h"
17 :
18 : namespace webrtc {
19 : namespace rtcp {
20 : constexpr uint8_t Sli::kFeedbackMessageType;
21 : // RFC 4585: Feedback format.
22 : //
23 : // Common packet format:
24 : //
25 : // 0 1 2 3
26 : // 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
27 : // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
28 : // |V=2|P| FMT | PT | length |
29 : // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
30 : // | SSRC of packet sender |
31 : // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 : // | SSRC of media source |
33 : // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
34 : // : Feedback Control Information (FCI) :
35 : // : :
36 : //
37 : // Slice loss indication (SLI) (RFC 4585).
38 : // FCI:
39 : // 0 1 2 3
40 : // 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
41 : // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
42 : // | First | Number | PictureID |
43 : // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
44 0 : Sli::Macroblocks::Macroblocks(uint8_t picture_id,
45 : uint16_t first,
46 0 : uint16_t number) {
47 0 : RTC_DCHECK_LE(first, 0x1fff);
48 0 : RTC_DCHECK_LE(number, 0x1fff);
49 0 : RTC_DCHECK_LE(picture_id, 0x3f);
50 0 : item_ = (first << 19) | (number << 6) | picture_id;
51 0 : }
52 :
53 0 : void Sli::Macroblocks::Parse(const uint8_t* buffer) {
54 0 : item_ = ByteReader<uint32_t>::ReadBigEndian(buffer);
55 0 : }
56 :
57 0 : void Sli::Macroblocks::Create(uint8_t* buffer) const {
58 0 : ByteWriter<uint32_t>::WriteBigEndian(buffer, item_);
59 0 : }
60 :
61 0 : bool Sli::Parse(const CommonHeader& packet) {
62 0 : RTC_DCHECK_EQ(packet.type(), kPacketType);
63 0 : RTC_DCHECK_EQ(packet.fmt(), kFeedbackMessageType);
64 :
65 0 : if (packet.payload_size_bytes() <
66 : kCommonFeedbackLength + Macroblocks::kLength) {
67 0 : LOG(LS_WARNING) << "Packet is too small to be a valid SLI packet";
68 0 : return false;
69 : }
70 :
71 : size_t number_of_items =
72 0 : (packet.payload_size_bytes() - kCommonFeedbackLength) /
73 0 : Macroblocks::kLength;
74 :
75 0 : ParseCommonFeedback(packet.payload());
76 0 : items_.resize(number_of_items);
77 :
78 0 : const uint8_t* next_item = packet.payload() + kCommonFeedbackLength;
79 0 : for (Macroblocks& item : items_) {
80 0 : item.Parse(next_item);
81 0 : next_item += Macroblocks::kLength;
82 : }
83 :
84 0 : return true;
85 : }
86 :
87 0 : bool Sli::Create(uint8_t* packet,
88 : size_t* index,
89 : size_t max_length,
90 : RtcpPacket::PacketReadyCallback* callback) const {
91 0 : RTC_DCHECK(!items_.empty());
92 0 : while (*index + BlockLength() > max_length) {
93 0 : if (!OnBufferFull(packet, index, callback))
94 0 : return false;
95 : }
96 0 : CreateHeader(kFeedbackMessageType, kPacketType, HeaderLength(), packet,
97 0 : index);
98 0 : CreateCommonFeedback(packet + *index);
99 0 : *index += kCommonFeedbackLength;
100 0 : for (const Macroblocks& item : items_) {
101 0 : item.Create(packet + *index);
102 0 : *index += Macroblocks::kLength;
103 : }
104 0 : return true;
105 : }
106 :
107 : } // namespace rtcp
108 : } // namespace webrtc
|