OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 13 matching lines...) Expand all Loading... |
24 ByteWriter<uint16_t>::WriteBigEndian(buffer + *offset, value); | 24 ByteWriter<uint16_t>::WriteBigEndian(buffer + *offset, value); |
25 *offset += 2; | 25 *offset += 2; |
26 } | 26 } |
27 } // namespace | 27 } // namespace |
28 | 28 |
29 void RtcpPacket::Append(RtcpPacket* packet) { | 29 void RtcpPacket::Append(RtcpPacket* packet) { |
30 assert(packet); | 30 assert(packet); |
31 appended_packets_.push_back(packet); | 31 appended_packets_.push_back(packet); |
32 } | 32 } |
33 | 33 |
34 rtc::scoped_ptr<RawPacket> RtcpPacket::Build() const { | 34 rtc::Buffer RtcpPacket::Build() const { |
35 size_t length = 0; | 35 size_t length = 0; |
36 rtc::scoped_ptr<RawPacket> packet(new RawPacket(IP_PACKET_SIZE)); | 36 rtc::Buffer packet(IP_PACKET_SIZE); |
37 | 37 |
38 class PacketVerifier : public PacketReadyCallback { | 38 class PacketVerifier : public PacketReadyCallback { |
39 public: | 39 public: |
40 explicit PacketVerifier(RawPacket* packet) | 40 explicit PacketVerifier(rtc::Buffer* packet) |
41 : called_(false), packet_(packet) {} | 41 : called_(false), packet_(packet) {} |
42 virtual ~PacketVerifier() {} | 42 virtual ~PacketVerifier() {} |
43 void OnPacketReady(uint8_t* data, size_t length) override { | 43 void OnPacketReady(uint8_t* data, size_t length) override { |
44 RTC_CHECK(!called_) << "Fragmentation not supported."; | 44 RTC_CHECK(!called_) << "Fragmentation not supported."; |
45 called_ = true; | 45 called_ = true; |
46 packet_->SetLength(length); | 46 packet_->SetSize(length); |
47 } | 47 } |
48 | 48 |
49 private: | 49 private: |
50 bool called_; | 50 bool called_; |
51 RawPacket* const packet_; | 51 rtc::Buffer* const packet_; |
52 } verifier(packet.get()); | 52 } verifier(&packet); |
53 CreateAndAddAppended(packet->MutableBuffer(), &length, packet->BufferLength(), | 53 CreateAndAddAppended(packet.data(), &length, packet.capacity(), &verifier); |
54 &verifier); | 54 OnBufferFull(packet.data(), &length, &verifier); |
55 OnBufferFull(packet->MutableBuffer(), &length, &verifier); | |
56 return packet; | 55 return packet; |
57 } | 56 } |
58 | 57 |
59 bool RtcpPacket::Build(PacketReadyCallback* callback) const { | 58 bool RtcpPacket::Build(PacketReadyCallback* callback) const { |
60 uint8_t buffer[IP_PACKET_SIZE]; | 59 uint8_t buffer[IP_PACKET_SIZE]; |
61 return BuildExternalBuffer(buffer, IP_PACKET_SIZE, callback); | 60 return BuildExternalBuffer(buffer, IP_PACKET_SIZE, callback); |
62 } | 61 } |
63 | 62 |
64 bool RtcpPacket::BuildExternalBuffer(uint8_t* buffer, | 63 bool RtcpPacket::BuildExternalBuffer(uint8_t* buffer, |
65 size_t max_length, | 64 size_t max_length, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 size_t length, | 114 size_t length, |
116 uint8_t* buffer, | 115 uint8_t* buffer, |
117 size_t* pos) { | 116 size_t* pos) { |
118 assert(length <= 0xffff); | 117 assert(length <= 0xffff); |
119 const uint8_t kVersion = 2; | 118 const uint8_t kVersion = 2; |
120 AssignUWord8(buffer, pos, (kVersion << 6) + count_or_format); | 119 AssignUWord8(buffer, pos, (kVersion << 6) + count_or_format); |
121 AssignUWord8(buffer, pos, packet_type); | 120 AssignUWord8(buffer, pos, packet_type); |
122 AssignUWord16(buffer, pos, length); | 121 AssignUWord16(buffer, pos, length); |
123 } | 122 } |
124 | 123 |
125 RawPacket::RawPacket(size_t buffer_length) | |
126 : buffer_length_(buffer_length), length_(0) { | |
127 buffer_.reset(new uint8_t[buffer_length]); | |
128 } | |
129 | |
130 RawPacket::RawPacket(const uint8_t* packet, size_t packet_length) | |
131 : buffer_length_(packet_length), length_(packet_length) { | |
132 buffer_.reset(new uint8_t[packet_length]); | |
133 memcpy(buffer_.get(), packet, packet_length); | |
134 } | |
135 | |
136 const uint8_t* RawPacket::Buffer() const { | |
137 return buffer_.get(); | |
138 } | |
139 | |
140 uint8_t* RawPacket::MutableBuffer() { | |
141 return buffer_.get(); | |
142 } | |
143 | |
144 size_t RawPacket::BufferLength() const { | |
145 return buffer_length_; | |
146 } | |
147 | |
148 size_t RawPacket::Length() const { | |
149 return length_; | |
150 } | |
151 | |
152 void RawPacket::SetLength(size_t length) { | |
153 assert(length <= buffer_length_); | |
154 length_ = length; | |
155 } | |
156 | |
157 } // namespace rtcp | 124 } // namespace rtcp |
158 } // namespace webrtc | 125 } // namespace webrtc |
OLD | NEW |