Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtcp_packet/app.cc

Issue 1998633002: [rtcp] App::Parse updated not to use RTCPUtility, (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: feedback Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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) {
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 if (packet.payload_size_bytes() % 4 != 0) {
42 LOG(LS_WARNING)
43 << "Packet payload must be 32 bits aligned to make a valid APP packet";
44 return false;
45 }
46 sub_type_ = packet.fmt();
47 ssrc_ = ByteReader<uint32_t>::ReadBigEndian(&packet.payload()[0]);
48 name_ = ByteReader<uint32_t>::ReadBigEndian(&packet.payload()[4]);
49 data_.SetData(packet.payload() + kAppBaseLength,
50 packet.payload_size_bytes() - kAppBaseLength);
42 return true; 51 return true;
43 } 52 }
44 53
45 void App::WithSubType(uint8_t subtype) { 54 void App::WithSubType(uint8_t subtype) {
46 RTC_DCHECK_LE(subtype, 0x1f); 55 RTC_DCHECK_LE(subtype, 0x1f);
47 sub_type_ = subtype; 56 sub_type_ = subtype;
48 } 57 }
49 58
50 void App::WithData(const uint8_t* data, size_t data_length) { 59 void App::WithData(const uint8_t* data, size_t data_length) {
51 RTC_DCHECK(data); 60 RTC_DCHECK(data);
52 RTC_DCHECK_EQ(0u, data_length % 4) << "Data must be 32 bits aligned."; 61 RTC_DCHECK_EQ(data_length % 4, 0u) << "Data must be 32 bits aligned.";
53 RTC_DCHECK(data_length <= kMaxDataSize) << "App data size << " << data_length 62 RTC_DCHECK_LE(data_length, kMaxDataSize) << "App data size " << data_length
54 << "exceed maximum of " 63 << " exceed maximum of "
55 << kMaxDataSize << " bytes."; 64 << kMaxDataSize << " bytes.";
56 data_.SetData(data, data_length); 65 data_.SetData(data, data_length);
57 } 66 }
58 67
59 bool App::Create(uint8_t* packet, 68 bool App::Create(uint8_t* packet,
60 size_t* index, 69 size_t* index,
61 size_t max_length, 70 size_t max_length,
62 RtcpPacket::PacketReadyCallback* callback) const { 71 RtcpPacket::PacketReadyCallback* callback) const {
63 while (*index + BlockLength() > max_length) { 72 while (*index + BlockLength() > max_length) {
64 if (!OnBufferFull(packet, index, callback)) 73 if (!OnBufferFull(packet, index, callback))
65 return false; 74 return false;
66 } 75 }
67 const size_t index_end = *index + BlockLength(); 76 const size_t index_end = *index + BlockLength();
68 CreateHeader(sub_type_, kPacketType, HeaderLength(), packet, index); 77 CreateHeader(sub_type_, kPacketType, HeaderLength(), packet, index);
69 78
70 ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 0], ssrc_); 79 ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 0], ssrc_);
71 ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 4], name_); 80 ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 4], name_);
72 memcpy(&packet[*index + 8], data_.data(), data_.size()); 81 memcpy(&packet[*index + 8], data_.data(), data_.size());
73 *index += (8 + data_.size()); 82 *index += (8 + data_.size());
74 RTC_DCHECK_EQ(index_end, *index); 83 RTC_DCHECK_EQ(index_end, *index);
75 return true; 84 return true;
76 } 85 }
77 86
78 } // namespace rtcp 87 } // namespace rtcp
79 } // namespace webrtc 88 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet/app.h ('k') | webrtc/modules/rtp_rtcp/source/rtcp_packet/app_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698