Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 "webrtc/base/checks.h" | |
| 14 #include "webrtc/base/logging.h" | |
| 15 #include "webrtc/modules/rtp_rtcp/source/rtp_utility.h" | |
| 16 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | |
| 17 | |
| 18 using webrtc::RTCPUtility::RtcpCommonHeader; | |
| 19 | |
| 20 namespace webrtc { | |
| 21 namespace rtcp { | |
| 22 | |
| 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 bool ExtendedJitterReport::Parse(const RtcpCommonHeader& header, | |
| 42 const uint8_t* payload) { | |
| 43 RTC_DCHECK(header.packet_type == kPacketType); | |
|
åsapersson
2015/11/12 15:44:31
RTC_DCHECK_EQ(kPacketType, ...
danilchap
2015/11/13 09:52:48
Unfortunetly this syntax creates additional compli
| |
| 44 | |
| 45 const uint8_t jitters_count = header.count_or_format; | |
| 46 const size_t kJitterSize = 4u; | |
|
åsapersson
2015/11/12 15:44:31
maybe kJitterSizeBytes
danilchap
2015/11/13 09:52:48
Done.
| |
| 47 | |
| 48 if (header.payload_size_bytes < jitters_count * kJitterSize) { | |
| 49 LOG(LS_WARNING) << "Packet is too small to contain all the jitter"; | |
|
åsapersson
2015/11/12 15:44:31
nit: period
danilchap
2015/11/13 09:52:48
Done.
| |
| 50 return false; | |
| 51 } | |
| 52 | |
| 53 inter_arrival_jitters_.resize(jitters_count); | |
| 54 for (size_t index = 0; index < jitters_count; ++index) { | |
| 55 inter_arrival_jitters_[index] = | |
| 56 ByteReader<uint32_t>::ReadBigEndian(&payload[index * kJitterSize]); | |
| 57 } | |
| 58 | |
| 59 return true; | |
| 60 } | |
| 61 | |
| 62 bool ExtendedJitterReport::WithJitter(uint32_t jitter) { | |
| 63 if (inter_arrival_jitters_.size() >= kMaxNumberOfJitters) { | |
| 64 LOG(LS_WARNING) << "Max inter-arrival jitter items reached."; | |
| 65 return false; | |
| 66 } | |
| 67 inter_arrival_jitters_.push_back(jitter); | |
| 68 return true; | |
| 69 } | |
| 70 | |
| 71 bool ExtendedJitterReport::Create( | |
| 72 uint8_t* packet, | |
| 73 size_t* index, | |
| 74 size_t max_length, | |
| 75 RtcpPacket::PacketReadyCallback* callback) const { | |
| 76 while (*index + BlockLength() > max_length) { | |
| 77 if (!OnBufferFull(packet, index, callback)) | |
| 78 return false; | |
| 79 } | |
| 80 const size_t index_end = *index + BlockLength(); | |
| 81 size_t length = inter_arrival_jitters_.size(); | |
| 82 CreateHeader(length, kPacketType, length, packet, index); | |
| 83 | |
| 84 for (uint32_t jitter : inter_arrival_jitters_) { | |
| 85 ByteWriter<uint32_t>::WriteBigEndian(packet + *index, jitter); | |
| 86 *index += sizeof(uint32_t); | |
| 87 } | |
| 88 // Sanity check. | |
| 89 RTC_DCHECK_EQ(index_end, *index); | |
| 90 return true; | |
| 91 } | |
| 92 | |
| 93 } // namespace rtcp | |
| 94 } // namespace webrtc | |
| OLD | NEW |