| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/extended_jitter_report.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/extended_jitter_report.h" |
| 12 | 12 |
| 13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
| 14 #include "webrtc/base/logging.h" | 14 #include "webrtc/base/logging.h" |
| 15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
| 16 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | 16 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h" |
| 17 | |
| 18 using webrtc::RTCPUtility::RtcpCommonHeader; | |
| 19 | 17 |
| 20 namespace webrtc { | 18 namespace webrtc { |
| 21 namespace rtcp { | 19 namespace rtcp { |
| 22 | 20 constexpr uint8_t ExtendedJitterReport::kPacketType; |
| 23 // Transmission Time Offsets in RTP Streams (RFC 5450). | 21 // Transmission Time Offsets in RTP Streams (RFC 5450). |
| 24 // | 22 // |
| 25 // 0 1 2 3 | 23 // 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 | 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 |
| 27 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 25 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 28 // hdr |V=2|P| RC | PT=IJ=195 | length | | 26 // hdr |V=2|P| RC | PT=IJ=195 | length | |
| 29 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 27 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 30 // | inter-arrival jitter | | 28 // | inter-arrival jitter | |
| 31 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 29 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 32 // . . | 30 // . . |
| 33 // . . | 31 // . . |
| 34 // . . | 32 // . . |
| 35 // | inter-arrival jitter | | 33 // | inter-arrival jitter | |
| 36 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 34 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 37 // | 35 // |
| 38 // If present, this RTCP packet must be placed after a receiver report | 36 // 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 | 37 // (inside a compound RTCP packet), and MUST have the same value for RC |
| 40 // (reception report count) as the receiver report. | 38 // (reception report count) as the receiver report. |
| 41 | 39 |
| 42 bool ExtendedJitterReport::Parse(const RtcpCommonHeader& header, | 40 bool ExtendedJitterReport::Parse(const CommonHeader& packet) { |
| 43 const uint8_t* payload) { | 41 RTC_DCHECK_EQ(packet.type(), kPacketType); |
| 44 RTC_DCHECK(header.packet_type == kPacketType); | |
| 45 | 42 |
| 46 const uint8_t jitters_count = header.count_or_format; | 43 const uint8_t number_of_jitters = packet.count(); |
| 47 const size_t kJitterSizeBytes = 4u; | |
| 48 | 44 |
| 49 if (header.payload_size_bytes < jitters_count * kJitterSizeBytes) { | 45 if (packet.payload_size_bytes() < number_of_jitters * kJitterSizeBytes) { |
| 50 LOG(LS_WARNING) << "Packet is too small to contain all the jitter."; | 46 LOG(LS_WARNING) << "Packet is too small to contain all the jitter."; |
| 51 return false; | 47 return false; |
| 52 } | 48 } |
| 53 | 49 |
| 54 inter_arrival_jitters_.resize(jitters_count); | 50 inter_arrival_jitters_.resize(number_of_jitters); |
| 55 for (size_t index = 0; index < jitters_count; ++index) { | 51 for (size_t index = 0; index < number_of_jitters; ++index) { |
| 56 inter_arrival_jitters_[index] = | 52 inter_arrival_jitters_[index] = ByteReader<uint32_t>::ReadBigEndian( |
| 57 ByteReader<uint32_t>::ReadBigEndian(&payload[index * kJitterSizeBytes]); | 53 &packet.payload()[index * kJitterSizeBytes]); |
| 58 } | 54 } |
| 59 | 55 |
| 60 return true; | 56 return true; |
| 61 } | 57 } |
| 62 | 58 |
| 63 bool ExtendedJitterReport::WithJitter(uint32_t jitter) { | 59 bool ExtendedJitterReport::WithJitter(uint32_t jitter) { |
| 64 if (inter_arrival_jitters_.size() >= kMaxNumberOfJitters) { | 60 if (inter_arrival_jitters_.size() >= kMaxNumberOfJitters) { |
| 65 LOG(LS_WARNING) << "Max inter-arrival jitter items reached."; | 61 LOG(LS_WARNING) << "Max inter-arrival jitter items reached."; |
| 66 return false; | 62 return false; |
| 67 } | 63 } |
| 68 inter_arrival_jitters_.push_back(jitter); | 64 inter_arrival_jitters_.push_back(jitter); |
| 69 return true; | 65 return true; |
| 70 } | 66 } |
| 71 | 67 |
| 72 bool ExtendedJitterReport::Create( | 68 bool ExtendedJitterReport::Create( |
| 73 uint8_t* packet, | 69 uint8_t* packet, |
| 74 size_t* index, | 70 size_t* index, |
| 75 size_t max_length, | 71 size_t max_length, |
| 76 RtcpPacket::PacketReadyCallback* callback) const { | 72 RtcpPacket::PacketReadyCallback* callback) const { |
| 77 while (*index + BlockLength() > max_length) { | 73 while (*index + BlockLength() > max_length) { |
| 78 if (!OnBufferFull(packet, index, callback)) | 74 if (!OnBufferFull(packet, index, callback)) |
| 79 return false; | 75 return false; |
| 80 } | 76 } |
| 81 const size_t index_end = *index + BlockLength(); | 77 const size_t index_end = *index + BlockLength(); |
| 82 size_t length = inter_arrival_jitters_.size(); | 78 size_t length = inter_arrival_jitters_.size(); |
| 83 CreateHeader(length, kPacketType, length, packet, index); | 79 CreateHeader(length, kPacketType, length, packet, index); |
| 84 | 80 |
| 85 for (uint32_t jitter : inter_arrival_jitters_) { | 81 for (uint32_t jitter : inter_arrival_jitters_) { |
| 86 ByteWriter<uint32_t>::WriteBigEndian(packet + *index, jitter); | 82 ByteWriter<uint32_t>::WriteBigEndian(packet + *index, jitter); |
| 87 *index += sizeof(uint32_t); | 83 *index += kJitterSizeBytes; |
| 88 } | 84 } |
| 89 // Sanity check. | 85 // Sanity check. |
| 90 RTC_DCHECK_EQ(index_end, *index); | 86 RTC_DCHECK_EQ(index_end, *index); |
| 91 return true; | 87 return true; |
| 92 } | 88 } |
| 93 | 89 |
| 94 } // namespace rtcp | 90 } // namespace rtcp |
| 95 } // namespace webrtc | 91 } // namespace webrtc |
| OLD | NEW |