| OLD | NEW |
| 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 10 matching lines...) Expand all Loading... |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 static const int kRtpSsrcOffset = 8; | 23 static const int kRtpSsrcOffset = 8; |
| 24 const int kWarnSlowWritesDelayMs = 50; | 24 const int kWarnSlowWritesDelayMs = 50; |
| 25 } // namespace | 25 } // namespace |
| 26 | 26 |
| 27 namespace cricket { | 27 namespace cricket { |
| 28 | 28 |
| 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(int64_t start_ms, uint32_t s, uint16_t p) |
| 32 : start_sec(start_ms / 1000), | 32 : start_sec(static_cast<uint32_t>(start_ms / 1000)), |
| 33 start_usec(start_ms % 1000 * 1000), | 33 start_usec(static_cast<uint32_t>(start_ms % 1000 * 1000)), |
| 34 source(s), | 34 source(s), |
| 35 port(p), | 35 port(p), |
| 36 padding(0) { | 36 padding(0) {} |
| 37 } | |
| 38 | 37 |
| 39 void RtpDumpFileHeader::WriteToByteBuffer(rtc::ByteBufferWriter* buf) { | 38 void RtpDumpFileHeader::WriteToByteBuffer(rtc::ByteBufferWriter* buf) { |
| 40 buf->WriteUInt32(start_sec); | 39 buf->WriteUInt32(start_sec); |
| 41 buf->WriteUInt32(start_usec); | 40 buf->WriteUInt32(start_usec); |
| 42 buf->WriteUInt32(source); | 41 buf->WriteUInt32(source); |
| 43 buf->WriteUInt16(port); | 42 buf->WriteUInt16(port); |
| 44 buf->WriteUInt16(padding); | 43 buf->WriteUInt16(padding); |
| 45 } | 44 } |
| 46 | 45 |
| 47 static const uint32_t kDefaultTimeIncrease = 30; | 46 static const int kDefaultTimeIncrease = 30; |
| 48 | 47 |
| 49 bool RtpDumpPacket::IsValidRtpPacket() const { | 48 bool RtpDumpPacket::IsValidRtpPacket() const { |
| 50 return original_data_len >= data.size() && | 49 return original_data_len >= data.size() && |
| 51 data.size() >= kMinRtpPacketLen; | 50 data.size() >= kMinRtpPacketLen; |
| 52 } | 51 } |
| 53 | 52 |
| 54 bool RtpDumpPacket::IsValidRtcpPacket() const { | 53 bool RtpDumpPacket::IsValidRtcpPacket() const { |
| 55 return original_data_len == 0 && | 54 return original_data_len == 0 && |
| 56 data.size() >= kMinRtcpPacketLen; | 55 data.size() >= kMinRtcpPacketLen; |
| 57 } | 56 } |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 154 |
| 156 // Read the 16 byte file header. | 155 // Read the 16 byte file header. |
| 157 char header[RtpDumpFileHeader::kHeaderLength]; | 156 char header[RtpDumpFileHeader::kHeaderLength]; |
| 158 res = stream_->ReadAll(header, sizeof(header), NULL, NULL); | 157 res = stream_->ReadAll(header, sizeof(header), NULL, NULL); |
| 159 if (res == rtc::SR_SUCCESS) { | 158 if (res == rtc::SR_SUCCESS) { |
| 160 rtc::ByteBufferReader buf(header, sizeof(header)); | 159 rtc::ByteBufferReader buf(header, sizeof(header)); |
| 161 uint32_t start_sec; | 160 uint32_t start_sec; |
| 162 uint32_t start_usec; | 161 uint32_t start_usec; |
| 163 buf.ReadUInt32(&start_sec); | 162 buf.ReadUInt32(&start_sec); |
| 164 buf.ReadUInt32(&start_usec); | 163 buf.ReadUInt32(&start_usec); |
| 165 start_time_ms_ = start_sec * 1000 + start_usec / 1000; | 164 start_time_ms_ = static_cast<int64_t>(start_sec * 1000 + start_usec / 1000); |
| 166 // Increase the length by 1 since first_line does not contain the ending \n. | 165 // 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); | 166 first_line_and_file_header_len_ = first_line.size() + 1 + sizeof(header); |
| 168 } | 167 } |
| 169 return res; | 168 return res; |
| 170 } | 169 } |
| 171 | 170 |
| 172 bool RtpDumpReader::CheckFirstLine(const std::string& first_line) { | 171 bool RtpDumpReader::CheckFirstLine(const std::string& first_line) { |
| 173 // The first line is like "#!rtpplay1.0 address/port" | 172 // The first line is like "#!rtpplay1.0 address/port" |
| 174 bool matched = (0 == first_line.find("#!rtpplay1.0 ")); | 173 bool matched = (0 == first_line.find("#!rtpplay1.0 ")); |
| 175 | 174 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 } | 297 } |
| 299 | 298 |
| 300 /////////////////////////////////////////////////////////////////////////// | 299 /////////////////////////////////////////////////////////////////////////// |
| 301 // Implementation of RtpDumpWriter. | 300 // Implementation of RtpDumpWriter. |
| 302 /////////////////////////////////////////////////////////////////////////// | 301 /////////////////////////////////////////////////////////////////////////// |
| 303 | 302 |
| 304 RtpDumpWriter::RtpDumpWriter(rtc::StreamInterface* stream) | 303 RtpDumpWriter::RtpDumpWriter(rtc::StreamInterface* stream) |
| 305 : stream_(stream), | 304 : stream_(stream), |
| 306 packet_filter_(PF_ALL), | 305 packet_filter_(PF_ALL), |
| 307 file_header_written_(false), | 306 file_header_written_(false), |
| 308 start_time_ms_(rtc::Time()), | 307 start_time_ms_(rtc::TimeMillis()), |
| 309 warn_slow_writes_delay_(kWarnSlowWritesDelayMs) { | 308 warn_slow_writes_delay_(kWarnSlowWritesDelayMs) {} |
| 310 } | |
| 311 | 309 |
| 312 void RtpDumpWriter::set_packet_filter(int filter) { | 310 void RtpDumpWriter::set_packet_filter(int filter) { |
| 313 packet_filter_ = filter; | 311 packet_filter_ = filter; |
| 314 LOG(LS_INFO) << "RtpDumpWriter set_packet_filter to " << packet_filter_; | 312 LOG(LS_INFO) << "RtpDumpWriter set_packet_filter to " << packet_filter_; |
| 315 } | 313 } |
| 316 | 314 |
| 317 uint32_t RtpDumpWriter::GetElapsedTime() const { | 315 uint32_t RtpDumpWriter::GetElapsedTime() const { |
| 318 return rtc::TimeSince(start_time_ms_); | 316 return static_cast<uint32_t>(rtc::TimeSince(start_time_ms_)); |
| 319 } | 317 } |
| 320 | 318 |
| 321 rtc::StreamResult RtpDumpWriter::WriteFileHeader() { | 319 rtc::StreamResult RtpDumpWriter::WriteFileHeader() { |
| 322 rtc::StreamResult res = WriteToStream( | 320 rtc::StreamResult res = WriteToStream( |
| 323 RtpDumpFileHeader::kFirstLine, | 321 RtpDumpFileHeader::kFirstLine, |
| 324 strlen(RtpDumpFileHeader::kFirstLine)); | 322 strlen(RtpDumpFileHeader::kFirstLine)); |
| 325 if (res != rtc::SR_SUCCESS) { | 323 if (res != rtc::SR_SUCCESS) { |
| 326 return res; | 324 return res; |
| 327 } | 325 } |
| 328 | 326 |
| 329 rtc::ByteBufferWriter buf; | 327 rtc::ByteBufferWriter buf; |
| 330 RtpDumpFileHeader file_header(rtc::Time(), 0, 0); | 328 RtpDumpFileHeader file_header(rtc::TimeMillis(), 0, 0); |
| 331 file_header.WriteToByteBuffer(&buf); | 329 file_header.WriteToByteBuffer(&buf); |
| 332 return WriteToStream(buf.Data(), buf.Length()); | 330 return WriteToStream(buf.Data(), buf.Length()); |
| 333 } | 331 } |
| 334 | 332 |
| 335 rtc::StreamResult RtpDumpWriter::WritePacket(const void* data, | 333 rtc::StreamResult RtpDumpWriter::WritePacket(const void* data, |
| 336 size_t data_len, | 334 size_t data_len, |
| 337 uint32_t elapsed, | 335 uint32_t elapsed, |
| 338 bool rtcp) { | 336 bool rtcp) { |
| 339 if (!stream_ || !data || 0 == data_len) return rtc::SR_ERROR; | 337 if (!stream_ || !data || 0 == data_len) return rtc::SR_ERROR; |
| 340 | 338 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 // RTCP header + payload | 386 // RTCP header + payload |
| 389 filtered_len = data_len; | 387 filtered_len = data_len; |
| 390 } | 388 } |
| 391 } | 389 } |
| 392 | 390 |
| 393 return filtered_len; | 391 return filtered_len; |
| 394 } | 392 } |
| 395 | 393 |
| 396 rtc::StreamResult RtpDumpWriter::WriteToStream( | 394 rtc::StreamResult RtpDumpWriter::WriteToStream( |
| 397 const void* data, size_t data_len) { | 395 const void* data, size_t data_len) { |
| 398 uint32_t before = rtc::Time(); | 396 int64_t before = rtc::TimeMillis(); |
| 399 rtc::StreamResult result = | 397 rtc::StreamResult result = |
| 400 stream_->WriteAll(data, data_len, NULL, NULL); | 398 stream_->WriteAll(data, data_len, NULL, NULL); |
| 401 uint32_t delay = rtc::TimeSince(before); | 399 int64_t delay = rtc::TimeSince(before); |
| 402 if (delay >= warn_slow_writes_delay_) { | 400 if (delay >= warn_slow_writes_delay_) { |
| 403 LOG(LS_WARNING) << "Slow RtpDump: took " << delay << "ms to write " | 401 LOG(LS_WARNING) << "Slow RtpDump: took " << delay << "ms to write " |
| 404 << data_len << " bytes."; | 402 << data_len << " bytes."; |
| 405 } | 403 } |
| 406 return result; | 404 return result; |
| 407 } | 405 } |
| 408 | 406 |
| 409 } // namespace cricket | 407 } // namespace cricket |
| OLD | NEW |