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

Side by Side Diff: webrtc/media/base/rtpdump.cc

Issue 1821083002: Split ByteBuffer into writer/reader objects. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 9 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
« no previous file with comments | « webrtc/media/base/rtpdump.h ('k') | webrtc/media/base/rtpdump_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2010 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 18 matching lines...) Expand all
29 const char RtpDumpFileHeader::kFirstLine[] = "#!rtpplay1.0 0.0.0.0/0\n"; 29 const char RtpDumpFileHeader::kFirstLine[] = "#!rtpplay1.0 0.0.0.0/0\n";
30 30
31 RtpDumpFileHeader::RtpDumpFileHeader(uint32_t start_ms, uint32_t s, uint16_t p) 31 RtpDumpFileHeader::RtpDumpFileHeader(uint32_t start_ms, uint32_t s, uint16_t p)
32 : start_sec(start_ms / 1000), 32 : start_sec(start_ms / 1000),
33 start_usec(start_ms % 1000 * 1000), 33 start_usec(start_ms % 1000 * 1000),
34 source(s), 34 source(s),
35 port(p), 35 port(p),
36 padding(0) { 36 padding(0) {
37 } 37 }
38 38
39 void RtpDumpFileHeader::WriteToByteBuffer(rtc::ByteBuffer* buf) { 39 void RtpDumpFileHeader::WriteToByteBuffer(rtc::ByteBufferWriter* buf) {
40 buf->WriteUInt32(start_sec); 40 buf->WriteUInt32(start_sec);
41 buf->WriteUInt32(start_usec); 41 buf->WriteUInt32(start_usec);
42 buf->WriteUInt32(source); 42 buf->WriteUInt32(source);
43 buf->WriteUInt16(port); 43 buf->WriteUInt16(port);
44 buf->WriteUInt16(padding); 44 buf->WriteUInt16(padding);
45 } 45 }
46 46
47 static const uint32_t kDefaultTimeIncrease = 30; 47 static const uint32_t kDefaultTimeIncrease = 30;
48 48
49 bool RtpDumpPacket::IsValidRtpPacket() const { 49 bool RtpDumpPacket::IsValidRtpPacket() const {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 106 }
107 file_header_read_ = true; 107 file_header_read_ = true;
108 } 108 }
109 109
110 // Read the RTP dump packet header. 110 // Read the RTP dump packet header.
111 char header[RtpDumpPacket::kHeaderLength]; 111 char header[RtpDumpPacket::kHeaderLength];
112 res = stream_->ReadAll(header, sizeof(header), NULL, NULL); 112 res = stream_->ReadAll(header, sizeof(header), NULL, NULL);
113 if (res != rtc::SR_SUCCESS) { 113 if (res != rtc::SR_SUCCESS) {
114 return res; 114 return res;
115 } 115 }
116 rtc::ByteBuffer buf(header, sizeof(header)); 116 rtc::ByteBufferReader buf(header, sizeof(header));
117 uint16_t dump_packet_len; 117 uint16_t dump_packet_len;
118 uint16_t data_len; 118 uint16_t data_len;
119 // Read the full length of the rtpdump packet, including the rtpdump header. 119 // Read the full length of the rtpdump packet, including the rtpdump header.
120 buf.ReadUInt16(&dump_packet_len); 120 buf.ReadUInt16(&dump_packet_len);
121 packet->data.resize(dump_packet_len - sizeof(header)); 121 packet->data.resize(dump_packet_len - sizeof(header));
122 // Read the size of the original packet, which may be larger than the size in 122 // Read the size of the original packet, which may be larger than the size in
123 // the rtpdump file, in the event that only part of the packet (perhaps just 123 // the rtpdump file, in the event that only part of the packet (perhaps just
124 // the header) was recorded. Note that this field is set to zero for RTCP 124 // the header) was recorded. Note that this field is set to zero for RTCP
125 // packets, which have their own internal length field. 125 // packets, which have their own internal length field.
126 buf.ReadUInt16(&data_len); 126 buf.ReadUInt16(&data_len);
(...skipping 23 matching lines...) Expand all
150 return res; 150 return res;
151 } 151 }
152 if (!CheckFirstLine(first_line)) { 152 if (!CheckFirstLine(first_line)) {
153 return rtc::SR_ERROR; 153 return rtc::SR_ERROR;
154 } 154 }
155 155
156 // Read the 16 byte file header. 156 // Read the 16 byte file header.
157 char header[RtpDumpFileHeader::kHeaderLength]; 157 char header[RtpDumpFileHeader::kHeaderLength];
158 res = stream_->ReadAll(header, sizeof(header), NULL, NULL); 158 res = stream_->ReadAll(header, sizeof(header), NULL, NULL);
159 if (res == rtc::SR_SUCCESS) { 159 if (res == rtc::SR_SUCCESS) {
160 rtc::ByteBuffer buf(header, sizeof(header)); 160 rtc::ByteBufferReader buf(header, sizeof(header));
161 uint32_t start_sec; 161 uint32_t start_sec;
162 uint32_t start_usec; 162 uint32_t start_usec;
163 buf.ReadUInt32(&start_sec); 163 buf.ReadUInt32(&start_sec);
164 buf.ReadUInt32(&start_usec); 164 buf.ReadUInt32(&start_usec);
165 start_time_ms_ = start_sec * 1000 + start_usec / 1000; 165 start_time_ms_ = start_sec * 1000 + start_usec / 1000;
166 // Increase the length by 1 since first_line does not contain the ending \n. 166 // Increase the length by 1 since first_line does not contain the ending \n.
167 first_line_and_file_header_len_ = first_line.size() + 1 + sizeof(header); 167 first_line_and_file_header_len_ = first_line.size() + 1 + sizeof(header);
168 } 168 }
169 return res; 169 return res;
170 } 170 }
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 if (packet->IsValidRtpPacket()) { 283 if (packet->IsValidRtpPacket()) {
284 // Get the old RTP sequence number and timestamp. 284 // Get the old RTP sequence number and timestamp.
285 int sequence = 0; 285 int sequence = 0;
286 packet->GetRtpSeqNum(&sequence); 286 packet->GetRtpSeqNum(&sequence);
287 uint32_t timestamp = 0; 287 uint32_t timestamp = 0;
288 packet->GetRtpTimestamp(&timestamp); 288 packet->GetRtpTimestamp(&timestamp);
289 // Increase the RTP sequence number and timestamp. 289 // Increase the RTP sequence number and timestamp.
290 sequence += loop_count_ * rtp_seq_num_increase_; 290 sequence += loop_count_ * rtp_seq_num_increase_;
291 timestamp += loop_count_ * rtp_timestamp_increase_; 291 timestamp += loop_count_ * rtp_timestamp_increase_;
292 // Write the updated sequence number and timestamp back to the RTP packet. 292 // Write the updated sequence number and timestamp back to the RTP packet.
293 rtc::ByteBuffer buffer; 293 rtc::ByteBufferWriter buffer;
294 buffer.WriteUInt16(sequence); 294 buffer.WriteUInt16(sequence);
295 buffer.WriteUInt32(timestamp); 295 buffer.WriteUInt32(timestamp);
296 memcpy(&packet->data[2], buffer.Data(), buffer.Length()); 296 memcpy(&packet->data[2], buffer.Data(), buffer.Length());
297 } 297 }
298 } 298 }
299 299
300 /////////////////////////////////////////////////////////////////////////// 300 ///////////////////////////////////////////////////////////////////////////
301 // Implementation of RtpDumpWriter. 301 // Implementation of RtpDumpWriter.
302 /////////////////////////////////////////////////////////////////////////// 302 ///////////////////////////////////////////////////////////////////////////
303 303
(...skipping 15 matching lines...) Expand all
319 } 319 }
320 320
321 rtc::StreamResult RtpDumpWriter::WriteFileHeader() { 321 rtc::StreamResult RtpDumpWriter::WriteFileHeader() {
322 rtc::StreamResult res = WriteToStream( 322 rtc::StreamResult res = WriteToStream(
323 RtpDumpFileHeader::kFirstLine, 323 RtpDumpFileHeader::kFirstLine,
324 strlen(RtpDumpFileHeader::kFirstLine)); 324 strlen(RtpDumpFileHeader::kFirstLine));
325 if (res != rtc::SR_SUCCESS) { 325 if (res != rtc::SR_SUCCESS) {
326 return res; 326 return res;
327 } 327 }
328 328
329 rtc::ByteBuffer buf; 329 rtc::ByteBufferWriter buf;
330 RtpDumpFileHeader file_header(rtc::Time(), 0, 0); 330 RtpDumpFileHeader file_header(rtc::Time(), 0, 0);
331 file_header.WriteToByteBuffer(&buf); 331 file_header.WriteToByteBuffer(&buf);
332 return WriteToStream(buf.Data(), buf.Length()); 332 return WriteToStream(buf.Data(), buf.Length());
333 } 333 }
334 334
335 rtc::StreamResult RtpDumpWriter::WritePacket(const void* data, 335 rtc::StreamResult RtpDumpWriter::WritePacket(const void* data,
336 size_t data_len, 336 size_t data_len,
337 uint32_t elapsed, 337 uint32_t elapsed,
338 bool rtcp) { 338 bool rtcp) {
339 if (!stream_ || !data || 0 == data_len) return rtc::SR_ERROR; 339 if (!stream_ || !data || 0 == data_len) return rtc::SR_ERROR;
340 340
341 rtc::StreamResult res = rtc::SR_SUCCESS; 341 rtc::StreamResult res = rtc::SR_SUCCESS;
342 // Write the file header if it has not been written yet. 342 // Write the file header if it has not been written yet.
343 if (!file_header_written_) { 343 if (!file_header_written_) {
344 res = WriteFileHeader(); 344 res = WriteFileHeader();
345 if (res != rtc::SR_SUCCESS) { 345 if (res != rtc::SR_SUCCESS) {
346 return res; 346 return res;
347 } 347 }
348 file_header_written_ = true; 348 file_header_written_ = true;
349 } 349 }
350 350
351 // Figure out what to write. 351 // Figure out what to write.
352 size_t write_len = FilterPacket(data, data_len, rtcp); 352 size_t write_len = FilterPacket(data, data_len, rtcp);
353 if (write_len == 0) { 353 if (write_len == 0) {
354 return rtc::SR_SUCCESS; 354 return rtc::SR_SUCCESS;
355 } 355 }
356 356
357 // Write the dump packet header. 357 // Write the dump packet header.
358 rtc::ByteBuffer buf; 358 rtc::ByteBufferWriter buf;
359 buf.WriteUInt16( 359 buf.WriteUInt16(
360 static_cast<uint16_t>(RtpDumpPacket::kHeaderLength + write_len)); 360 static_cast<uint16_t>(RtpDumpPacket::kHeaderLength + write_len));
361 buf.WriteUInt16(static_cast<uint16_t>(rtcp ? 0 : data_len)); 361 buf.WriteUInt16(static_cast<uint16_t>(rtcp ? 0 : data_len));
362 buf.WriteUInt32(elapsed); 362 buf.WriteUInt32(elapsed);
363 res = WriteToStream(buf.Data(), buf.Length()); 363 res = WriteToStream(buf.Data(), buf.Length());
364 if (res != rtc::SR_SUCCESS) { 364 if (res != rtc::SR_SUCCESS) {
365 return res; 365 return res;
366 } 366 }
367 367
368 // Write the header or full packet as indicated by write_len. 368 // Write the header or full packet as indicated by write_len.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 stream_->WriteAll(data, data_len, NULL, NULL); 400 stream_->WriteAll(data, data_len, NULL, NULL);
401 uint32_t delay = rtc::TimeSince(before); 401 uint32_t delay = rtc::TimeSince(before);
402 if (delay >= warn_slow_writes_delay_) { 402 if (delay >= warn_slow_writes_delay_) {
403 LOG(LS_WARNING) << "Slow RtpDump: took " << delay << "ms to write " 403 LOG(LS_WARNING) << "Slow RtpDump: took " << delay << "ms to write "
404 << data_len << " bytes."; 404 << data_len << " bytes.";
405 } 405 }
406 return result; 406 return result;
407 } 407 }
408 408
409 } // namespace cricket 409 } // namespace cricket
OLDNEW
« no previous file with comments | « webrtc/media/base/rtpdump.h ('k') | webrtc/media/base/rtpdump_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698