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 |
(...skipping 14 matching lines...) Expand all Loading... |
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 |
| 36 App::App() : sub_type_(0), ssrc_(0), name_(0) {} |
| 37 |
| 38 App::~App() = default; |
| 39 |
35 bool App::Parse(const CommonHeader& packet) { | 40 bool App::Parse(const CommonHeader& packet) { |
36 RTC_DCHECK_EQ(packet.type(), kPacketType); | 41 RTC_DCHECK_EQ(packet.type(), kPacketType); |
37 if (packet.payload_size_bytes() < kAppBaseLength) { | 42 if (packet.payload_size_bytes() < kAppBaseLength) { |
38 LOG(LS_WARNING) << "Packet is too small to be a valid APP packet"; | 43 LOG(LS_WARNING) << "Packet is too small to be a valid APP packet"; |
39 return false; | 44 return false; |
40 } | 45 } |
41 if (packet.payload_size_bytes() % 4 != 0) { | 46 if (packet.payload_size_bytes() % 4 != 0) { |
42 LOG(LS_WARNING) | 47 LOG(LS_WARNING) |
43 << "Packet payload must be 32 bits aligned to make a valid APP packet"; | 48 << "Packet payload must be 32 bits aligned to make a valid APP packet"; |
44 return false; | 49 return false; |
(...skipping 13 matching lines...) Expand all Loading... |
58 | 63 |
59 void App::SetData(const uint8_t* data, size_t data_length) { | 64 void App::SetData(const uint8_t* data, size_t data_length) { |
60 RTC_DCHECK(data); | 65 RTC_DCHECK(data); |
61 RTC_DCHECK_EQ(data_length % 4, 0) << "Data must be 32 bits aligned."; | 66 RTC_DCHECK_EQ(data_length % 4, 0) << "Data must be 32 bits aligned."; |
62 RTC_DCHECK_LE(data_length, kMaxDataSize) << "App data size " << data_length | 67 RTC_DCHECK_LE(data_length, kMaxDataSize) << "App data size " << data_length |
63 << " exceed maximum of " | 68 << " exceed maximum of " |
64 << kMaxDataSize << " bytes."; | 69 << kMaxDataSize << " bytes."; |
65 data_.SetData(data, data_length); | 70 data_.SetData(data, data_length); |
66 } | 71 } |
67 | 72 |
| 73 size_t App::BlockLength() const { |
| 74 return kHeaderLength + kAppBaseLength + data_.size(); |
| 75 } |
| 76 |
68 bool App::Create(uint8_t* packet, | 77 bool App::Create(uint8_t* packet, |
69 size_t* index, | 78 size_t* index, |
70 size_t max_length, | 79 size_t max_length, |
71 RtcpPacket::PacketReadyCallback* callback) const { | 80 RtcpPacket::PacketReadyCallback* callback) const { |
72 while (*index + BlockLength() > max_length) { | 81 while (*index + BlockLength() > max_length) { |
73 if (!OnBufferFull(packet, index, callback)) | 82 if (!OnBufferFull(packet, index, callback)) |
74 return false; | 83 return false; |
75 } | 84 } |
76 const size_t index_end = *index + BlockLength(); | 85 const size_t index_end = *index + BlockLength(); |
77 CreateHeader(sub_type_, kPacketType, HeaderLength(), packet, index); | 86 CreateHeader(sub_type_, kPacketType, HeaderLength(), packet, index); |
78 | 87 |
79 ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 0], ssrc_); | 88 ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 0], ssrc_); |
80 ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 4], name_); | 89 ByteWriter<uint32_t>::WriteBigEndian(&packet[*index + 4], name_); |
81 memcpy(&packet[*index + 8], data_.data(), data_.size()); | 90 memcpy(&packet[*index + 8], data_.data(), data_.size()); |
82 *index += (8 + data_.size()); | 91 *index += (8 + data_.size()); |
83 RTC_DCHECK_EQ(index_end, *index); | 92 RTC_DCHECK_EQ(index_end, *index); |
84 return true; | 93 return true; |
85 } | 94 } |
86 | 95 |
87 } // namespace rtcp | 96 } // namespace rtcp |
88 } // namespace webrtc | 97 } // namespace webrtc |
OLD | NEW |