Chromium Code Reviews| 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/app.h" | 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/app.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 | 16 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/common_header.h" |
| 17 using webrtc::RTCPUtility::RtcpCommonHeader; | |
| 18 | 17 |
| 19 namespace webrtc { | 18 namespace webrtc { |
| 20 namespace rtcp { | 19 namespace rtcp { |
| 21 | 20 constexpr uint8_t App::kPacketType; |
| 21 constexpr size_t App::kMaxDataSize; | |
| 22 // Application-Defined packet (APP) (RFC 3550). | 22 // Application-Defined packet (APP) (RFC 3550). |
| 23 // | 23 // |
| 24 // 0 1 2 3 | 24 // 0 1 2 3 |
| 25 // 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 // 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 |
| 26 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 26 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 27 // |V=2|P| subtype | PT=APP=204 | length | | 27 // |V=2|P| subtype | PT=APP=204 | length | |
| 28 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 28 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 29 // 0 | SSRC/CSRC | | 29 // 0 | SSRC/CSRC | |
| 30 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 30 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 31 // 4 | name (ASCII) | | 31 // 4 | name (ASCII) | |
| 32 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 32 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 33 // 8 | application-dependent data ... | 33 // 8 | application-dependent data ... |
| 34 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 34 // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 35 bool App::Parse(const RtcpCommonHeader& header, const uint8_t* payload) { | 35 bool App::Parse(const CommonHeader& packet) { |
| 36 RTC_DCHECK(header.packet_type == kPacketType); | 36 RTC_DCHECK_EQ(packet.type(), kPacketType); |
| 37 | 37 if (packet.payload_size_bytes() < kAppBaseLength) { |
|
åsapersson
2016/07/26 09:58:15
is payload_size_bytes multiple of 4 here or should
danilchap
2016/07/26 11:37:02
Good point.
It is possible to create a packet wher
| |
| 38 sub_type_ = header.count_or_format; | 38 LOG(LS_WARNING) << "Packet is too small to be a valid APP packet"; |
| 39 ssrc_ = ByteReader<uint32_t>::ReadBigEndian(&payload[0]); | 39 return false; |
| 40 name_ = ByteReader<uint32_t>::ReadBigEndian(&payload[4]); | 40 } |
| 41 data_.SetData(&payload[8], header.payload_size_bytes - 8); | 41 sub_type_ = packet.fmt(); |
| 42 ssrc_ = ByteReader<uint32_t>::ReadBigEndian(&packet.payload()[0]); | |
| 43 name_ = ByteReader<uint32_t>::ReadBigEndian(&packet.payload()[4]); | |
| 44 data_.SetData(packet.payload() + kAppBaseLength, | |
| 45 packet.payload_size_bytes() - kAppBaseLength); | |
| 42 return true; | 46 return true; |
| 43 } | 47 } |
| 44 | 48 |
| 45 void App::WithSubType(uint8_t subtype) { | 49 void App::WithSubType(uint8_t subtype) { |
| 46 RTC_DCHECK_LE(subtype, 0x1f); | 50 RTC_DCHECK_LE(subtype, 0x1f); |
| 47 sub_type_ = subtype; | 51 sub_type_ = subtype; |
| 48 } | 52 } |
| 49 | 53 |
| 50 void App::WithData(const uint8_t* data, size_t data_length) { | 54 void App::WithData(const uint8_t* data, size_t data_length) { |
| 51 RTC_DCHECK(data); | 55 RTC_DCHECK(data); |
| 52 RTC_DCHECK_EQ(0u, data_length % 4) << "Data must be 32 bits aligned."; | 56 RTC_DCHECK_EQ(data_length % 4, 0u) << "Data must be 32 bits aligned."; |
| 53 RTC_DCHECK(data_length <= kMaxDataSize) << "App data size << " << data_length | 57 RTC_DCHECK_LE(data_length, kMaxDataSize) << "App data size " << data_length |
| 54 << "exceed maximum of " | 58 << " exceed maximum of " |
| 55 << kMaxDataSize << " bytes."; | 59 << kMaxDataSize << " bytes."; |
| 56 data_.SetData(data, data_length); | 60 data_.SetData(data, data_length); |
| 57 } | 61 } |
| 58 | 62 |
| 59 bool App::Create(uint8_t* packet, | 63 bool App::Create(uint8_t* packet, |
| 60 size_t* index, | 64 size_t* index, |
| 61 size_t max_length, | 65 size_t max_length, |
| 62 RtcpPacket::PacketReadyCallback* callback) const { | 66 RtcpPacket::PacketReadyCallback* callback) const { |
| 63 while (*index + BlockLength() > max_length) { | 67 while (*index + BlockLength() > max_length) { |
| 64 if (!OnBufferFull(packet, index, callback)) | 68 if (!OnBufferFull(packet, index, callback)) |
| 65 return false; | 69 return false; |
| 66 } | 70 } |
| 67 const size_t index_end = *index + BlockLength(); | 71 const size_t index_end = *index + BlockLength(); |
| 68 CreateHeader(sub_type_, kPacketType, HeaderLength(), packet, index); | 72 CreateHeader(sub_type_, kPacketType, HeaderLength(), packet, index); |
| 69 | 73 |
| 70 ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 0], ssrc_); | 74 ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 0], ssrc_); |
| 71 ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 4], name_); | 75 ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 4], name_); |
| 72 memcpy(&packet[*index + 8], data_.data(), data_.size()); | 76 memcpy(&packet[*index + 8], data_.data(), data_.size()); |
| 73 *index += (8 + data_.size()); | 77 *index += (8 + data_.size()); |
| 74 RTC_DCHECK_EQ(index_end, *index); | 78 RTC_DCHECK_EQ(index_end, *index); |
| 75 return true; | 79 return true; |
| 76 } | 80 } |
| 77 | 81 |
| 78 } // namespace rtcp | 82 } // namespace rtcp |
| 79 } // namespace webrtc | 83 } // namespace webrtc |
| OLD | NEW |