Line data Source code
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/extended_jitter_report.h"
12 :
13 : #include <utility>
14 :
15 : #include "webrtc/base/checks.h"
16 : #include "webrtc/base/logging.h"
17 : #include "webrtc/modules/rtp_rtcp/source/byte_io.h"
18 : #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h"
19 :
20 : namespace webrtc {
21 : namespace rtcp {
22 : constexpr uint8_t ExtendedJitterReport::kPacketType;
23 : // Transmission Time Offsets in RTP Streams (RFC 5450).
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 : // hdr |V=2|P| RC | PT=IJ=195 | length |
29 : // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
30 : // | inter-arrival jitter |
31 : // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
32 : // . .
33 : // . .
34 : // . .
35 : // | inter-arrival jitter |
36 : // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
37 : //
38 : // If present, this RTCP packet must be placed after a receiver report
39 : // (inside a compound RTCP packet), and MUST have the same value for RC
40 : // (reception report count) as the receiver report.
41 :
42 0 : bool ExtendedJitterReport::Parse(const CommonHeader& packet) {
43 0 : RTC_DCHECK_EQ(packet.type(), kPacketType);
44 :
45 0 : const uint8_t number_of_jitters = packet.count();
46 :
47 0 : if (packet.payload_size_bytes() < number_of_jitters * kJitterSizeBytes) {
48 0 : LOG(LS_WARNING) << "Packet is too small to contain all the jitter.";
49 0 : return false;
50 : }
51 :
52 0 : inter_arrival_jitters_.resize(number_of_jitters);
53 0 : for (size_t index = 0; index < number_of_jitters; ++index) {
54 0 : inter_arrival_jitters_[index] = ByteReader<uint32_t>::ReadBigEndian(
55 0 : &packet.payload()[index * kJitterSizeBytes]);
56 : }
57 :
58 0 : return true;
59 : }
60 :
61 0 : bool ExtendedJitterReport::SetJitterValues(std::vector<uint32_t> values) {
62 0 : if (values.size() > kMaxNumberOfJitterValues) {
63 0 : LOG(LS_WARNING) << "Too many inter-arrival jitter items.";
64 0 : return false;
65 : }
66 0 : inter_arrival_jitters_ = std::move(values);
67 0 : return true;
68 : }
69 :
70 0 : bool ExtendedJitterReport::Create(
71 : uint8_t* packet,
72 : size_t* index,
73 : size_t max_length,
74 : RtcpPacket::PacketReadyCallback* callback) const {
75 0 : while (*index + BlockLength() > max_length) {
76 0 : if (!OnBufferFull(packet, index, callback))
77 0 : return false;
78 : }
79 0 : const size_t index_end = *index + BlockLength();
80 0 : size_t length = inter_arrival_jitters_.size();
81 0 : CreateHeader(length, kPacketType, length, packet, index);
82 :
83 0 : for (uint32_t jitter : inter_arrival_jitters_) {
84 0 : ByteWriter<uint32_t>::WriteBigEndian(packet + *index, jitter);
85 0 : *index += kJitterSizeBytes;
86 : }
87 : // Sanity check.
88 0 : RTC_DCHECK_EQ(index_end, *index);
89 0 : return true;
90 : }
91 :
92 : } // namespace rtcp
93 : } // namespace webrtc
|