Delete unused rtpdump code in media/base.
Reading and writing RTP files is implemented elsewhere,
in test/rtp_file_reader.cc and test/rtp_file_writer.cc;
that code is untouched by this cl.
BUG=webrtc:6974
Review-Url: https://codereview.webrtc.org/2633453002
Cr-Original-Commit-Position: refs/heads/master@{#16046}
Cr-Mirrored-From: https://chromium.googlesource.com/external/webrtc
Cr-Mirrored-Commit: 61f31ee37607f5c3ba2c5930e6ab48f2b69b4c5f
diff --git a/media/BUILD.gn b/media/BUILD.gn
index 4e54d5a..23aa0f0 100644
--- a/media/BUILD.gn
+++ b/media/BUILD.gn
@@ -61,8 +61,6 @@
"base/mediaengine.h",
"base/rtpdataengine.cc",
"base/rtpdataengine.h",
- "base/rtpdump.cc",
- "base/rtpdump.h",
"base/rtputils.cc",
"base/rtputils.h",
"base/streamparams.cc",
@@ -324,7 +322,6 @@
sources = [
"base/codec_unittest.cc",
"base/rtpdataengine_unittest.cc",
- "base/rtpdump_unittest.cc",
"base/rtputils_unittest.cc",
"base/streamparams_unittest.cc",
"base/turnutils_unittest.cc",
diff --git a/media/base/rtpdump.cc b/media/base/rtpdump.cc
deleted file mode 100644
index 2460859..0000000
--- a/media/base/rtpdump.cc
+++ /dev/null
@@ -1,407 +0,0 @@
-/*
- * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-#include "webrtc/media/base/rtpdump.h"
-
-#include <ctype.h>
-
-#include <string>
-
-#include "webrtc/base/byteorder.h"
-#include "webrtc/base/logging.h"
-#include "webrtc/base/timeutils.h"
-#include "webrtc/media/base/rtputils.h"
-
-namespace {
-static const int kRtpSsrcOffset = 8;
-const int kWarnSlowWritesDelayMs = 50;
-} // namespace
-
-namespace cricket {
-
-const char RtpDumpFileHeader::kFirstLine[] = "#!rtpplay1.0 0.0.0.0/0\n";
-
-RtpDumpFileHeader::RtpDumpFileHeader(int64_t start_ms, uint32_t s, uint16_t p)
- : start_sec(static_cast<uint32_t>(start_ms / 1000)),
- start_usec(static_cast<uint32_t>(start_ms % 1000 * 1000)),
- source(s),
- port(p),
- padding(0) {}
-
-void RtpDumpFileHeader::WriteToByteBuffer(rtc::ByteBufferWriter* buf) {
- buf->WriteUInt32(start_sec);
- buf->WriteUInt32(start_usec);
- buf->WriteUInt32(source);
- buf->WriteUInt16(port);
- buf->WriteUInt16(padding);
-}
-
-static const int kDefaultTimeIncrease = 30;
-
-bool RtpDumpPacket::IsValidRtpPacket() const {
- return original_data_len >= data.size() &&
- data.size() >= kMinRtpPacketLen;
-}
-
-bool RtpDumpPacket::IsValidRtcpPacket() const {
- return original_data_len == 0 &&
- data.size() >= kMinRtcpPacketLen;
-}
-
-bool RtpDumpPacket::GetRtpPayloadType(int* pt) const {
- return IsValidRtpPacket() &&
- cricket::GetRtpPayloadType(&data[0], data.size(), pt);
-}
-
-bool RtpDumpPacket::GetRtpSeqNum(int* seq_num) const {
- return IsValidRtpPacket() &&
- cricket::GetRtpSeqNum(&data[0], data.size(), seq_num);
-}
-
-bool RtpDumpPacket::GetRtpTimestamp(uint32_t* ts) const {
- return IsValidRtpPacket() &&
- cricket::GetRtpTimestamp(&data[0], data.size(), ts);
-}
-
-bool RtpDumpPacket::GetRtpSsrc(uint32_t* ssrc) const {
- return IsValidRtpPacket() &&
- cricket::GetRtpSsrc(&data[0], data.size(), ssrc);
-}
-
-bool RtpDumpPacket::GetRtpHeaderLen(size_t* len) const {
- return IsValidRtpPacket() &&
- cricket::GetRtpHeaderLen(&data[0], data.size(), len);
-}
-
-bool RtpDumpPacket::GetRtcpType(int* type) const {
- return IsValidRtcpPacket() &&
- cricket::GetRtcpType(&data[0], data.size(), type);
-}
-
-///////////////////////////////////////////////////////////////////////////
-// Implementation of RtpDumpReader.
-///////////////////////////////////////////////////////////////////////////
-
-void RtpDumpReader::SetSsrc(uint32_t ssrc) {
- ssrc_override_ = ssrc;
-}
-
-rtc::StreamResult RtpDumpReader::ReadPacket(RtpDumpPacket* packet) {
- if (!packet) return rtc::SR_ERROR;
-
- rtc::StreamResult res = rtc::SR_SUCCESS;
- // Read the file header if it has not been read yet.
- if (!file_header_read_) {
- res = ReadFileHeader();
- if (res != rtc::SR_SUCCESS) {
- return res;
- }
- file_header_read_ = true;
- }
-
- // Read the RTP dump packet header.
- char header[RtpDumpPacket::kHeaderLength];
- res = stream_->ReadAll(header, sizeof(header), NULL, NULL);
- if (res != rtc::SR_SUCCESS) {
- return res;
- }
- rtc::ByteBufferReader buf(header, sizeof(header));
- uint16_t dump_packet_len;
- uint16_t data_len;
- // Read the full length of the rtpdump packet, including the rtpdump header.
- buf.ReadUInt16(&dump_packet_len);
- packet->data.resize(dump_packet_len - sizeof(header));
- // Read the size of the original packet, which may be larger than the size in
- // the rtpdump file, in the event that only part of the packet (perhaps just
- // the header) was recorded. Note that this field is set to zero for RTCP
- // packets, which have their own internal length field.
- buf.ReadUInt16(&data_len);
- packet->original_data_len = data_len;
- // Read the elapsed time for this packet (different than RTP timestamp).
- buf.ReadUInt32(&packet->elapsed_time);
-
- // Read the actual RTP or RTCP packet.
- res = stream_->ReadAll(&packet->data[0], packet->data.size(), NULL, NULL);
-
- // If the packet is RTP and we have specified a ssrc, replace the RTP ssrc
- // with the specified ssrc.
- if (res == rtc::SR_SUCCESS &&
- packet->IsValidRtpPacket() &&
- ssrc_override_ != 0) {
- rtc::SetBE32(&packet->data[kRtpSsrcOffset], ssrc_override_);
- }
-
- return res;
-}
-
-rtc::StreamResult RtpDumpReader::ReadFileHeader() {
- // Read the first line.
- std::string first_line;
- rtc::StreamResult res = stream_->ReadLine(&first_line);
- if (res != rtc::SR_SUCCESS) {
- return res;
- }
- if (!CheckFirstLine(first_line)) {
- return rtc::SR_ERROR;
- }
-
- // Read the 16 byte file header.
- char header[RtpDumpFileHeader::kHeaderLength];
- res = stream_->ReadAll(header, sizeof(header), NULL, NULL);
- if (res == rtc::SR_SUCCESS) {
- rtc::ByteBufferReader buf(header, sizeof(header));
- uint32_t start_sec;
- uint32_t start_usec;
- buf.ReadUInt32(&start_sec);
- buf.ReadUInt32(&start_usec);
- start_time_ms_ = static_cast<int64_t>(start_sec * 1000 + start_usec / 1000);
- // Increase the length by 1 since first_line does not contain the ending \n.
- first_line_and_file_header_len_ = first_line.size() + 1 + sizeof(header);
- }
- return res;
-}
-
-bool RtpDumpReader::CheckFirstLine(const std::string& first_line) {
- // The first line is like "#!rtpplay1.0 address/port"
- bool matched = (0 == first_line.find("#!rtpplay1.0 "));
-
- // The address could be IP or hostname. We do not check it here. Instead, we
- // check the port at the end.
- size_t pos = first_line.find('/');
- matched &= (pos != std::string::npos && pos < first_line.size() - 1);
- for (++pos; pos < first_line.size() && matched; ++pos) {
- matched &= (0 != isdigit(first_line[pos]));
- }
-
- return matched;
-}
-
-///////////////////////////////////////////////////////////////////////////
-// Implementation of RtpDumpLoopReader.
-///////////////////////////////////////////////////////////////////////////
-RtpDumpLoopReader::RtpDumpLoopReader(rtc::StreamInterface* stream)
- : RtpDumpReader(stream),
- loop_count_(0),
- elapsed_time_increases_(0),
- rtp_seq_num_increase_(0),
- rtp_timestamp_increase_(0),
- packet_count_(0),
- frame_count_(0),
- first_elapsed_time_(0),
- first_rtp_seq_num_(0),
- first_rtp_timestamp_(0),
- prev_elapsed_time_(0),
- prev_rtp_seq_num_(0),
- prev_rtp_timestamp_(0) {
-}
-
-rtc::StreamResult RtpDumpLoopReader::ReadPacket(RtpDumpPacket* packet) {
- if (!packet) return rtc::SR_ERROR;
-
- rtc::StreamResult res = RtpDumpReader::ReadPacket(packet);
- if (rtc::SR_SUCCESS == res) {
- if (0 == loop_count_) {
- // During the first loop, we update the statistics of the input stream.
- UpdateStreamStatistics(*packet);
- }
- } else if (rtc::SR_EOS == res) {
- if (0 == loop_count_) {
- // At the end of the first loop, calculate elapsed_time_increases_,
- // rtp_seq_num_increase_, and rtp_timestamp_increase_, which will be
- // used during the second and later loops.
- CalculateIncreases();
- }
-
- // Rewind the input stream to the first dump packet and read again.
- ++loop_count_;
- if (RewindToFirstDumpPacket()) {
- res = RtpDumpReader::ReadPacket(packet);
- }
- }
-
- if (rtc::SR_SUCCESS == res && loop_count_ > 0) {
- // During the second and later loops, we update the elapsed time of the dump
- // packet. If the dumped packet is a RTP packet, we also update its RTP
- // sequence number and timestamp.
- UpdateDumpPacket(packet);
- }
-
- return res;
-}
-
-void RtpDumpLoopReader::UpdateStreamStatistics(const RtpDumpPacket& packet) {
- // Get the RTP sequence number and timestamp of the dump packet.
- int rtp_seq_num = 0;
- packet.GetRtpSeqNum(&rtp_seq_num);
- uint32_t rtp_timestamp = 0;
- packet.GetRtpTimestamp(&rtp_timestamp);
-
- // Set the timestamps and sequence number for the first dump packet.
- if (0 == packet_count_++) {
- first_elapsed_time_ = packet.elapsed_time;
- first_rtp_seq_num_ = rtp_seq_num;
- first_rtp_timestamp_ = rtp_timestamp;
- // The first packet belongs to a new payload frame.
- ++frame_count_;
- } else if (rtp_timestamp != prev_rtp_timestamp_) {
- // The current and previous packets belong to different payload frames.
- ++frame_count_;
- }
-
- prev_elapsed_time_ = packet.elapsed_time;
- prev_rtp_timestamp_ = rtp_timestamp;
- prev_rtp_seq_num_ = rtp_seq_num;
-}
-
-void RtpDumpLoopReader::CalculateIncreases() {
- // At this time, prev_elapsed_time_, prev_rtp_seq_num_, and
- // prev_rtp_timestamp_ are values of the last dump packet in the input stream.
- rtp_seq_num_increase_ = prev_rtp_seq_num_ - first_rtp_seq_num_ + 1;
- // If we have only one packet or frame, we use the default timestamp
- // increase. Otherwise, we use the difference between the first and the last
- // packets or frames.
- elapsed_time_increases_ = packet_count_ <= 1 ? kDefaultTimeIncrease :
- (prev_elapsed_time_ - first_elapsed_time_) * packet_count_ /
- (packet_count_ - 1);
- rtp_timestamp_increase_ = frame_count_ <= 1 ? kDefaultTimeIncrease :
- (prev_rtp_timestamp_ - first_rtp_timestamp_) * frame_count_ /
- (frame_count_ - 1);
-}
-
-void RtpDumpLoopReader::UpdateDumpPacket(RtpDumpPacket* packet) {
- // Increase the elapsed time of the dump packet.
- packet->elapsed_time += loop_count_ * elapsed_time_increases_;
-
- if (packet->IsValidRtpPacket()) {
- // Get the old RTP sequence number and timestamp.
- int sequence = 0;
- packet->GetRtpSeqNum(&sequence);
- uint32_t timestamp = 0;
- packet->GetRtpTimestamp(×tamp);
- // Increase the RTP sequence number and timestamp.
- sequence += loop_count_ * rtp_seq_num_increase_;
- timestamp += loop_count_ * rtp_timestamp_increase_;
- // Write the updated sequence number and timestamp back to the RTP packet.
- rtc::ByteBufferWriter buffer;
- buffer.WriteUInt16(sequence);
- buffer.WriteUInt32(timestamp);
- memcpy(&packet->data[2], buffer.Data(), buffer.Length());
- }
-}
-
-///////////////////////////////////////////////////////////////////////////
-// Implementation of RtpDumpWriter.
-///////////////////////////////////////////////////////////////////////////
-
-RtpDumpWriter::RtpDumpWriter(rtc::StreamInterface* stream)
- : stream_(stream),
- packet_filter_(PF_ALL),
- file_header_written_(false),
- start_time_ms_(rtc::TimeMillis()),
- warn_slow_writes_delay_(kWarnSlowWritesDelayMs) {}
-
-void RtpDumpWriter::set_packet_filter(int filter) {
- packet_filter_ = filter;
- LOG(LS_INFO) << "RtpDumpWriter set_packet_filter to " << packet_filter_;
-}
-
-uint32_t RtpDumpWriter::GetElapsedTime() const {
- return static_cast<uint32_t>(rtc::TimeSince(start_time_ms_));
-}
-
-rtc::StreamResult RtpDumpWriter::WriteFileHeader() {
- rtc::StreamResult res = WriteToStream(
- RtpDumpFileHeader::kFirstLine,
- strlen(RtpDumpFileHeader::kFirstLine));
- if (res != rtc::SR_SUCCESS) {
- return res;
- }
-
- rtc::ByteBufferWriter buf;
- RtpDumpFileHeader file_header(rtc::TimeMillis(), 0, 0);
- file_header.WriteToByteBuffer(&buf);
- return WriteToStream(buf.Data(), buf.Length());
-}
-
-rtc::StreamResult RtpDumpWriter::WritePacket(const void* data,
- size_t data_len,
- uint32_t elapsed,
- bool rtcp) {
- if (!stream_ || !data || 0 == data_len) return rtc::SR_ERROR;
-
- rtc::StreamResult res = rtc::SR_SUCCESS;
- // Write the file header if it has not been written yet.
- if (!file_header_written_) {
- res = WriteFileHeader();
- if (res != rtc::SR_SUCCESS) {
- return res;
- }
- file_header_written_ = true;
- }
-
- // Figure out what to write.
- size_t write_len = FilterPacket(data, data_len, rtcp);
- if (write_len == 0) {
- return rtc::SR_SUCCESS;
- }
-
- // Write the dump packet header.
- rtc::ByteBufferWriter buf;
- buf.WriteUInt16(
- static_cast<uint16_t>(RtpDumpPacket::kHeaderLength + write_len));
- buf.WriteUInt16(static_cast<uint16_t>(rtcp ? 0 : data_len));
- buf.WriteUInt32(elapsed);
- res = WriteToStream(buf.Data(), buf.Length());
- if (res != rtc::SR_SUCCESS) {
- return res;
- }
-
- // Write the header or full packet as indicated by write_len.
- return WriteToStream(data, write_len);
-}
-
-size_t RtpDumpWriter::FilterPacket(const void* data, size_t data_len,
- bool rtcp) {
- size_t filtered_len = 0;
- if (!rtcp) {
- if ((packet_filter_ & PF_RTPPACKET) == PF_RTPPACKET) {
- // RTP header + payload
- filtered_len = data_len;
- } else if ((packet_filter_ & PF_RTPHEADER) == PF_RTPHEADER) {
- // RTP header only
- size_t header_len;
- if (GetRtpHeaderLen(data, data_len, &header_len)) {
- filtered_len = header_len;
- }
- }
- } else {
- if ((packet_filter_ & PF_RTCPPACKET) == PF_RTCPPACKET) {
- // RTCP header + payload
- filtered_len = data_len;
- }
- }
-
- return filtered_len;
-}
-
-rtc::StreamResult RtpDumpWriter::WriteToStream(
- const void* data, size_t data_len) {
- int64_t before = rtc::TimeMillis();
- rtc::StreamResult result =
- stream_->WriteAll(data, data_len, NULL, NULL);
- int64_t delay = rtc::TimeSince(before);
- if (delay >= warn_slow_writes_delay_) {
- LOG(LS_WARNING) << "Slow RtpDump: took " << delay << "ms to write "
- << data_len << " bytes.";
- }
- return result;
-}
-
-} // namespace cricket
diff --git a/media/base/rtpdump.h b/media/base/rtpdump.h
deleted file mode 100644
index 8ea7800..0000000
--- a/media/base/rtpdump.h
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
- * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-#ifndef WEBRTC_MEDIA_BASE_RTPDUMP_H_
-#define WEBRTC_MEDIA_BASE_RTPDUMP_H_
-
-#include <string.h>
-
-#include <string>
-#include <vector>
-
-#include "webrtc/base/basictypes.h"
-#include "webrtc/base/bytebuffer.h"
-#include "webrtc/base/constructormagic.h"
-#include "webrtc/base/stream.h"
-
-namespace cricket {
-
-// We use the RTP dump file format compatible to the format used by rtptools
-// (http://www.cs.columbia.edu/irt/software/rtptools/) and Wireshark
-// (http://wiki.wireshark.org/rtpdump). In particular, the file starts with the
-// first line "#!rtpplay1.0 address/port\n", followed by a 16 byte file header.
-// For each packet, the file contains a 8 byte dump packet header, followed by
-// the actual RTP or RTCP packet.
-
-enum RtpDumpPacketFilter {
- PF_NONE = 0x0,
- PF_RTPHEADER = 0x1,
- PF_RTPPACKET = 0x3, // includes header
- // PF_RTCPHEADER = 0x4, // TODO(juberti)
- PF_RTCPPACKET = 0xC, // includes header
- PF_ALL = 0xF
-};
-
-struct RtpDumpFileHeader {
- RtpDumpFileHeader(int64_t start_ms, uint32_t s, uint16_t p);
- void WriteToByteBuffer(rtc::ByteBufferWriter* buf);
-
- static const char kFirstLine[];
- static const size_t kHeaderLength = 16;
- uint32_t start_sec; // start of recording, the seconds part.
- uint32_t start_usec; // start of recording, the microseconds part.
- uint32_t source; // network source (multicast address).
- uint16_t port; // UDP port.
- uint16_t padding; // 2 bytes padding.
-};
-
-struct RtpDumpPacket {
- RtpDumpPacket() {}
-
- RtpDumpPacket(const void* d, size_t s, uint32_t elapsed, bool rtcp)
- : elapsed_time(elapsed), original_data_len((rtcp) ? 0 : s) {
- data.resize(s);
- memcpy(&data[0], d, s);
- }
-
- // In the rtpdump file format, RTCP packets have their data len set to zero,
- // since RTCP has an internal length field.
- bool is_rtcp() const { return original_data_len == 0; }
- bool IsValidRtpPacket() const;
- bool IsValidRtcpPacket() const;
- // Get the payload type, sequence number, timestampe, and SSRC of the RTP
- // packet. Return true and set the output parameter if successful.
- bool GetRtpPayloadType(int* pt) const;
- bool GetRtpSeqNum(int* seq_num) const;
- bool GetRtpTimestamp(uint32_t* ts) const;
- bool GetRtpSsrc(uint32_t* ssrc) const;
- bool GetRtpHeaderLen(size_t* len) const;
- // Get the type of the RTCP packet. Return true and set the output parameter
- // if successful.
- bool GetRtcpType(int* type) const;
-
- static const size_t kHeaderLength = 8;
- uint32_t elapsed_time; // Milliseconds since the start of recording.
- std::vector<uint8_t> data; // The actual RTP or RTCP packet.
- size_t original_data_len; // The original length of the packet; may be
- // greater than data.size() if only part of the
- // packet was recorded.
-};
-
-class RtpDumpReader {
- public:
- explicit RtpDumpReader(rtc::StreamInterface* stream)
- : stream_(stream),
- file_header_read_(false),
- first_line_and_file_header_len_(0),
- start_time_ms_(0),
- ssrc_override_(0) {
- }
- virtual ~RtpDumpReader() {}
-
- // Use the specified ssrc, rather than the ssrc from dump, for RTP packets.
- void SetSsrc(uint32_t ssrc);
- virtual rtc::StreamResult ReadPacket(RtpDumpPacket* packet);
-
- protected:
- rtc::StreamResult ReadFileHeader();
- bool RewindToFirstDumpPacket() {
- return stream_->SetPosition(first_line_and_file_header_len_);
- }
-
- private:
- // Check if its matches "#!rtpplay1.0 address/port\n".
- bool CheckFirstLine(const std::string& first_line);
-
- rtc::StreamInterface* stream_;
- bool file_header_read_;
- size_t first_line_and_file_header_len_;
- int64_t start_time_ms_;
- uint32_t ssrc_override_;
-
- RTC_DISALLOW_COPY_AND_ASSIGN(RtpDumpReader);
-};
-
-// RtpDumpLoopReader reads RTP dump packets from the input stream and rewinds
-// the stream when it ends. RtpDumpLoopReader maintains the elapsed time, the
-// RTP sequence number and the RTP timestamp properly. RtpDumpLoopReader can
-// handle both RTP dump and RTCP dump. We assume that the dump does not mix
-// RTP packets and RTCP packets.
-class RtpDumpLoopReader : public RtpDumpReader {
- public:
- explicit RtpDumpLoopReader(rtc::StreamInterface* stream);
- virtual rtc::StreamResult ReadPacket(RtpDumpPacket* packet);
-
- private:
- // During the first loop, update the statistics, including packet count, frame
- // count, timestamps, and sequence number, of the input stream.
- void UpdateStreamStatistics(const RtpDumpPacket& packet);
-
- // At the end of first loop, calculate elapsed_time_increases_,
- // rtp_seq_num_increase_, and rtp_timestamp_increase_.
- void CalculateIncreases();
-
- // During the second and later loops, update the elapsed time of the dump
- // packet. If the dumped packet is a RTP packet, update its RTP sequence
- // number and timestamp as well.
- void UpdateDumpPacket(RtpDumpPacket* packet);
-
- int loop_count_;
- // How much to increase the elapsed time, RTP sequence number, RTP timestampe
- // for each loop. They are calcualted with the variables below during the
- // first loop.
- uint32_t elapsed_time_increases_;
- int rtp_seq_num_increase_;
- uint32_t rtp_timestamp_increase_;
- // How many RTP packets and how many payload frames in the input stream. RTP
- // packets belong to the same frame have the same RTP timestamp, different
- // dump timestamp, and different RTP sequence number.
- uint32_t packet_count_;
- uint32_t frame_count_;
- // The elapsed time, RTP sequence number, and RTP timestamp of the first and
- // the previous dump packets in the input stream.
- uint32_t first_elapsed_time_;
- int first_rtp_seq_num_;
- int64_t first_rtp_timestamp_;
- uint32_t prev_elapsed_time_;
- int prev_rtp_seq_num_;
- int64_t prev_rtp_timestamp_;
-
- RTC_DISALLOW_COPY_AND_ASSIGN(RtpDumpLoopReader);
-};
-
-class RtpDumpWriter {
- public:
- explicit RtpDumpWriter(rtc::StreamInterface* stream);
-
- // Filter to control what packets we actually record.
- void set_packet_filter(int filter);
- // Write a RTP or RTCP packet. The parameters data points to the packet and
- // data_len is its length.
- rtc::StreamResult WriteRtpPacket(const void* data, size_t data_len) {
- return WritePacket(data, data_len, GetElapsedTime(), false);
- }
- rtc::StreamResult WriteRtcpPacket(const void* data, size_t data_len) {
- return WritePacket(data, data_len, GetElapsedTime(), true);
- }
- rtc::StreamResult WritePacket(const RtpDumpPacket& packet) {
- return WritePacket(&packet.data[0], packet.data.size(), packet.elapsed_time,
- packet.is_rtcp());
- }
- uint32_t GetElapsedTime() const;
-
- bool GetDumpSize(size_t* size) {
- // Note that we use GetPosition(), rather than GetSize(), to avoid flush the
- // stream per write.
- return stream_ && size && stream_->GetPosition(size);
- }
-
- protected:
- rtc::StreamResult WriteFileHeader();
-
- private:
- rtc::StreamResult WritePacket(const void* data,
- size_t data_len,
- uint32_t elapsed,
- bool rtcp);
- size_t FilterPacket(const void* data, size_t data_len, bool rtcp);
- rtc::StreamResult WriteToStream(const void* data, size_t data_len);
-
- rtc::StreamInterface* stream_;
- int packet_filter_;
- bool file_header_written_;
- int64_t start_time_ms_; // Time when the record starts.
- // If writing to the stream takes longer than this many ms, log a warning.
- int64_t warn_slow_writes_delay_;
- RTC_DISALLOW_COPY_AND_ASSIGN(RtpDumpWriter);
-};
-
-} // namespace cricket
-
-#endif // WEBRTC_MEDIA_BASE_RTPDUMP_H_
diff --git a/media/base/rtpdump_unittest.cc b/media/base/rtpdump_unittest.cc
deleted file mode 100644
index 748ceab..0000000
--- a/media/base/rtpdump_unittest.cc
+++ /dev/null
@@ -1,282 +0,0 @@
-/*
- * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
- *
- * Use of this source code is governed by a BSD-style license
- * that can be found in the LICENSE file in the root of the source
- * tree. An additional intellectual property rights grant can be found
- * in the file PATENTS. All contributing project authors may
- * be found in the AUTHORS file in the root of the source tree.
- */
-
-#include <memory>
-#include <string>
-
-#include "webrtc/base/bytebuffer.h"
-#include "webrtc/base/gunit.h"
-#include "webrtc/base/thread.h"
-#include "webrtc/media/base/rtpdump.h"
-#include "webrtc/media/base/rtputils.h"
-#include "webrtc/media/base/testutils.h"
-
-namespace cricket {
-
-static const uint32_t kTestSsrc = 1;
-
-// Test that we read the correct header fields from the RTP/RTCP packet.
-TEST(RtpDumpTest, ReadRtpDumpPacket) {
- rtc::ByteBufferWriter rtp_buf;
- RtpTestUtility::kTestRawRtpPackets[0].WriteToByteBuffer(kTestSsrc, &rtp_buf);
- RtpDumpPacket rtp_packet(rtp_buf.Data(), rtp_buf.Length(), 0, false);
-
- int payload_type;
- int seq_num;
- uint32_t ts;
- uint32_t ssrc;
- int rtcp_type;
- EXPECT_FALSE(rtp_packet.is_rtcp());
- EXPECT_TRUE(rtp_packet.IsValidRtpPacket());
- EXPECT_FALSE(rtp_packet.IsValidRtcpPacket());
- EXPECT_TRUE(rtp_packet.GetRtpPayloadType(&payload_type));
- EXPECT_EQ(0, payload_type);
- EXPECT_TRUE(rtp_packet.GetRtpSeqNum(&seq_num));
- EXPECT_EQ(0, seq_num);
- EXPECT_TRUE(rtp_packet.GetRtpTimestamp(&ts));
- EXPECT_EQ(0U, ts);
- EXPECT_TRUE(rtp_packet.GetRtpSsrc(&ssrc));
- EXPECT_EQ(kTestSsrc, ssrc);
- EXPECT_FALSE(rtp_packet.GetRtcpType(&rtcp_type));
-
- rtc::ByteBufferWriter rtcp_buf;
- RtpTestUtility::kTestRawRtcpPackets[0].WriteToByteBuffer(&rtcp_buf);
- RtpDumpPacket rtcp_packet(rtcp_buf.Data(), rtcp_buf.Length(), 0, true);
-
- EXPECT_TRUE(rtcp_packet.is_rtcp());
- EXPECT_FALSE(rtcp_packet.IsValidRtpPacket());
- EXPECT_TRUE(rtcp_packet.IsValidRtcpPacket());
- EXPECT_TRUE(rtcp_packet.GetRtcpType(&rtcp_type));
- EXPECT_EQ(0, rtcp_type);
-}
-
-// Test that we read only the RTP dump file.
-TEST(RtpDumpTest, ReadRtpDumpFile) {
- RtpDumpPacket packet;
- rtc::MemoryStream stream;
- RtpDumpWriter writer(&stream);
- std::unique_ptr<RtpDumpReader> reader;
-
- // Write a RTP packet to the stream, which is a valid RTP dump. Next, we will
- // change the first line to make the RTP dump valid or invalid.
- ASSERT_TRUE(RtpTestUtility::WriteTestPackets(1, false, kTestSsrc, &writer));
- stream.Rewind();
- reader.reset(new RtpDumpReader(&stream));
- EXPECT_EQ(rtc::SR_SUCCESS, reader->ReadPacket(&packet));
-
- // The first line is correct.
- stream.Rewind();
- const char new_line[] = "#!rtpplay1.0 1.1.1.1/1\n";
- EXPECT_EQ(rtc::SR_SUCCESS,
- stream.WriteAll(new_line, strlen(new_line), NULL, NULL));
- stream.Rewind();
- reader.reset(new RtpDumpReader(&stream));
- EXPECT_EQ(rtc::SR_SUCCESS, reader->ReadPacket(&packet));
-
- // The first line is not correct: not started with #!rtpplay1.0.
- stream.Rewind();
- const char new_line2[] = "#!rtpplaz1.0 0.0.0.0/0\n";
- EXPECT_EQ(rtc::SR_SUCCESS,
- stream.WriteAll(new_line2, strlen(new_line2), NULL, NULL));
- stream.Rewind();
- reader.reset(new RtpDumpReader(&stream));
- EXPECT_EQ(rtc::SR_ERROR, reader->ReadPacket(&packet));
-
- // The first line is not correct: no port.
- stream.Rewind();
- const char new_line3[] = "#!rtpplay1.0 0.0.0.0//\n";
- EXPECT_EQ(rtc::SR_SUCCESS,
- stream.WriteAll(new_line3, strlen(new_line3), NULL, NULL));
- stream.Rewind();
- reader.reset(new RtpDumpReader(&stream));
- EXPECT_EQ(rtc::SR_ERROR, reader->ReadPacket(&packet));
-}
-
-// Test that we read the same RTP packets that rtp dump writes.
-TEST(RtpDumpTest, WriteReadSameRtp) {
- rtc::MemoryStream stream;
- RtpDumpWriter writer(&stream);
- ASSERT_TRUE(RtpTestUtility::WriteTestPackets(
- RtpTestUtility::GetTestPacketCount(), false, kTestSsrc, &writer));
- EXPECT_TRUE(RtpTestUtility::VerifyTestPacketsFromStream(
- RtpTestUtility::GetTestPacketCount(), &stream, kTestSsrc));
-
- // Check stream has only RtpTestUtility::GetTestPacketCount() packets.
- RtpDumpPacket packet;
- RtpDumpReader reader(&stream);
- for (size_t i = 0; i < RtpTestUtility::GetTestPacketCount(); ++i) {
- EXPECT_EQ(rtc::SR_SUCCESS, reader.ReadPacket(&packet));
- uint32_t ssrc;
- EXPECT_TRUE(GetRtpSsrc(&packet.data[0], packet.data.size(), &ssrc));
- EXPECT_EQ(kTestSsrc, ssrc);
- }
- // No more packets to read.
- EXPECT_EQ(rtc::SR_EOS, reader.ReadPacket(&packet));
-
- // Rewind the stream and read again with a specified ssrc.
- stream.Rewind();
- RtpDumpReader reader_w_ssrc(&stream);
- const uint32_t send_ssrc = kTestSsrc + 1;
- reader_w_ssrc.SetSsrc(send_ssrc);
- for (size_t i = 0; i < RtpTestUtility::GetTestPacketCount(); ++i) {
- EXPECT_EQ(rtc::SR_SUCCESS, reader_w_ssrc.ReadPacket(&packet));
- EXPECT_FALSE(packet.is_rtcp());
- EXPECT_EQ(packet.original_data_len, packet.data.size());
- uint32_t ssrc;
- EXPECT_TRUE(GetRtpSsrc(&packet.data[0], packet.data.size(), &ssrc));
- EXPECT_EQ(send_ssrc, ssrc);
- }
- // No more packets to read.
- EXPECT_EQ(rtc::SR_EOS, reader_w_ssrc.ReadPacket(&packet));
-}
-
-// Test that we read the same RTCP packets that rtp dump writes.
-TEST(RtpDumpTest, WriteReadSameRtcp) {
- rtc::MemoryStream stream;
- RtpDumpWriter writer(&stream);
- ASSERT_TRUE(RtpTestUtility::WriteTestPackets(
- RtpTestUtility::GetTestPacketCount(), true, kTestSsrc, &writer));
- EXPECT_TRUE(RtpTestUtility::VerifyTestPacketsFromStream(
- RtpTestUtility::GetTestPacketCount(), &stream, kTestSsrc));
-
- // Check stream has only RtpTestUtility::GetTestPacketCount() packets.
- RtpDumpPacket packet;
- RtpDumpReader reader(&stream);
- reader.SetSsrc(kTestSsrc + 1); // Does not affect RTCP packet.
- for (size_t i = 0; i < RtpTestUtility::GetTestPacketCount(); ++i) {
- EXPECT_EQ(rtc::SR_SUCCESS, reader.ReadPacket(&packet));
- EXPECT_TRUE(packet.is_rtcp());
- EXPECT_EQ(0U, packet.original_data_len);
- }
- // No more packets to read.
- EXPECT_EQ(rtc::SR_EOS, reader.ReadPacket(&packet));
-}
-
-// Test dumping only RTP packet headers.
-TEST(RtpDumpTest, WriteReadRtpHeadersOnly) {
- rtc::MemoryStream stream;
- RtpDumpWriter writer(&stream);
- writer.set_packet_filter(PF_RTPHEADER);
-
- // Write some RTP and RTCP packets. RTP packets should only have headers;
- // RTCP packets should be eaten.
- ASSERT_TRUE(RtpTestUtility::WriteTestPackets(
- RtpTestUtility::GetTestPacketCount(), false, kTestSsrc, &writer));
- ASSERT_TRUE(RtpTestUtility::WriteTestPackets(
- RtpTestUtility::GetTestPacketCount(), true, kTestSsrc, &writer));
- stream.Rewind();
-
- // Check that only RTP packet headers are present.
- RtpDumpPacket packet;
- RtpDumpReader reader(&stream);
- for (size_t i = 0; i < RtpTestUtility::GetTestPacketCount(); ++i) {
- EXPECT_EQ(rtc::SR_SUCCESS, reader.ReadPacket(&packet));
- EXPECT_FALSE(packet.is_rtcp());
- size_t len = 0;
- packet.GetRtpHeaderLen(&len);
- EXPECT_EQ(len, packet.data.size());
- EXPECT_GT(packet.original_data_len, packet.data.size());
- }
- // No more packets to read.
- EXPECT_EQ(rtc::SR_EOS, reader.ReadPacket(&packet));
-}
-
-// Test dumping only RTCP packets.
-TEST(RtpDumpTest, WriteReadRtcpOnly) {
- rtc::MemoryStream stream;
- RtpDumpWriter writer(&stream);
- writer.set_packet_filter(PF_RTCPPACKET);
-
- // Write some RTP and RTCP packets. RTP packets should be eaten.
- ASSERT_TRUE(RtpTestUtility::WriteTestPackets(
- RtpTestUtility::GetTestPacketCount(), false, kTestSsrc, &writer));
- ASSERT_TRUE(RtpTestUtility::WriteTestPackets(
- RtpTestUtility::GetTestPacketCount(), true, kTestSsrc, &writer));
- stream.Rewind();
-
- // Check that only RTCP packets are present.
- RtpDumpPacket packet;
- RtpDumpReader reader(&stream);
- for (size_t i = 0; i < RtpTestUtility::GetTestPacketCount(); ++i) {
- EXPECT_EQ(rtc::SR_SUCCESS, reader.ReadPacket(&packet));
- EXPECT_TRUE(packet.is_rtcp());
- EXPECT_EQ(0U, packet.original_data_len);
- }
- // No more packets to read.
- EXPECT_EQ(rtc::SR_EOS, reader.ReadPacket(&packet));
-}
-
-// Test that RtpDumpLoopReader reads RTP packets continously and the elapsed
-// time, the sequence number, and timestamp are maintained properly.
-TEST(RtpDumpTest, LoopReadRtp) {
- rtc::MemoryStream stream;
- RtpDumpWriter writer(&stream);
- ASSERT_TRUE(RtpTestUtility::WriteTestPackets(
- RtpTestUtility::GetTestPacketCount(), false, kTestSsrc, &writer));
- EXPECT_TRUE(RtpTestUtility::VerifyTestPacketsFromStream(
- 3 * RtpTestUtility::GetTestPacketCount(), &stream, kTestSsrc));
-}
-
-// Test that RtpDumpLoopReader reads RTCP packets continously and the elapsed
-// time is maintained properly.
-TEST(RtpDumpTest, LoopReadRtcp) {
- rtc::MemoryStream stream;
- RtpDumpWriter writer(&stream);
- ASSERT_TRUE(RtpTestUtility::WriteTestPackets(
- RtpTestUtility::GetTestPacketCount(), true, kTestSsrc, &writer));
- EXPECT_TRUE(RtpTestUtility::VerifyTestPacketsFromStream(
- 3 * RtpTestUtility::GetTestPacketCount(), &stream, kTestSsrc));
-}
-
-// Test that RtpDumpLoopReader reads continously from stream with a single RTP
-// packets.
-TEST(RtpDumpTest, LoopReadSingleRtp) {
- rtc::MemoryStream stream;
- RtpDumpWriter writer(&stream);
- ASSERT_TRUE(RtpTestUtility::WriteTestPackets(1, false, kTestSsrc, &writer));
-
- // The regular reader can read only one packet.
- RtpDumpPacket packet;
- stream.Rewind();
- RtpDumpReader reader(&stream);
- EXPECT_EQ(rtc::SR_SUCCESS, reader.ReadPacket(&packet));
- EXPECT_EQ(rtc::SR_EOS, reader.ReadPacket(&packet));
-
- // The loop reader reads three packets from the input stream.
- stream.Rewind();
- RtpDumpLoopReader loop_reader(&stream);
- EXPECT_EQ(rtc::SR_SUCCESS, loop_reader.ReadPacket(&packet));
- EXPECT_EQ(rtc::SR_SUCCESS, loop_reader.ReadPacket(&packet));
- EXPECT_EQ(rtc::SR_SUCCESS, loop_reader.ReadPacket(&packet));
-}
-
-// Test that RtpDumpLoopReader reads continously from stream with a single RTCP
-// packets.
-TEST(RtpDumpTest, LoopReadSingleRtcp) {
- rtc::MemoryStream stream;
- RtpDumpWriter writer(&stream);
- ASSERT_TRUE(RtpTestUtility::WriteTestPackets(1, true, kTestSsrc, &writer));
-
- // The regular reader can read only one packet.
- RtpDumpPacket packet;
- stream.Rewind();
- RtpDumpReader reader(&stream);
- EXPECT_EQ(rtc::SR_SUCCESS, reader.ReadPacket(&packet));
- EXPECT_EQ(rtc::SR_EOS, reader.ReadPacket(&packet));
-
- // The loop reader reads three packets from the input stream.
- stream.Rewind();
- RtpDumpLoopReader loop_reader(&stream);
- EXPECT_EQ(rtc::SR_SUCCESS, loop_reader.ReadPacket(&packet));
- EXPECT_EQ(rtc::SR_SUCCESS, loop_reader.ReadPacket(&packet));
- EXPECT_EQ(rtc::SR_SUCCESS, loop_reader.ReadPacket(&packet));
-}
-
-} // namespace cricket
diff --git a/media/base/testutils.cc b/media/base/testutils.cc
index 0af8d16..aa92aea 100644
--- a/media/base/testutils.cc
+++ b/media/base/testutils.cc
@@ -22,7 +22,6 @@
#include "webrtc/base/stream.h"
#include "webrtc/base/stringutils.h"
#include "webrtc/base/testutils.h"
-#include "webrtc/media/base/rtpdump.h"
#include "webrtc/media/base/videocapturer.h"
namespace cricket {
@@ -97,117 +96,6 @@
0 == memcmp(payload, packet.payload, sizeof(payload));
}
-/////////////////////////////////////////////////////////////////////////
-// Implementation of class RtpTestUtility
-/////////////////////////////////////////////////////////////////////////
-const RawRtpPacket RtpTestUtility::kTestRawRtpPackets[] = {
- {0x80, 0, 0, 0, RtpTestUtility::kDefaultSsrc, "RTP frame 0"},
- {0x80, 0, 1, 30, RtpTestUtility::kDefaultSsrc, "RTP frame 1"},
- {0x80, 0, 2, 30, RtpTestUtility::kDefaultSsrc, "RTP frame 1"},
- {0x80, 0, 3, 60, RtpTestUtility::kDefaultSsrc, "RTP frame 2"}
-};
-const RawRtcpPacket RtpTestUtility::kTestRawRtcpPackets[] = {
- // The Version is 2, the Length is 2, and the payload has 8 bytes.
- {0x80, 0, 2, "RTCP0000"},
- {0x80, 0, 2, "RTCP0001"},
- {0x80, 0, 2, "RTCP0002"},
- {0x80, 0, 2, "RTCP0003"},
-};
-
-size_t RtpTestUtility::GetTestPacketCount() {
- return std::min(arraysize(kTestRawRtpPackets),
- arraysize(kTestRawRtcpPackets));
-}
-
-bool RtpTestUtility::WriteTestPackets(size_t count,
- bool rtcp,
- uint32_t rtp_ssrc,
- RtpDumpWriter* writer) {
- if (!writer || count > GetTestPacketCount()) return false;
-
- bool result = true;
- uint32_t elapsed_time_ms = 0;
- for (size_t i = 0; i < count && result; ++i) {
- rtc::ByteBufferWriter buf;
- if (rtcp) {
- kTestRawRtcpPackets[i].WriteToByteBuffer(&buf);
- } else {
- kTestRawRtpPackets[i].WriteToByteBuffer(rtp_ssrc, &buf);
- }
-
- RtpDumpPacket dump_packet(buf.Data(), buf.Length(), elapsed_time_ms, rtcp);
- elapsed_time_ms += kElapsedTimeInterval;
- result &= (rtc::SR_SUCCESS == writer->WritePacket(dump_packet));
- }
- return result;
-}
-
-bool RtpTestUtility::VerifyTestPacketsFromStream(size_t count,
- rtc::StreamInterface* stream,
- uint32_t ssrc) {
- if (!stream) return false;
-
- uint32_t prev_elapsed_time = 0;
- bool result = true;
- stream->Rewind();
- RtpDumpLoopReader reader(stream);
- for (size_t i = 0; i < count && result; ++i) {
- // Which loop and which index in the loop are we reading now.
- size_t loop = i / GetTestPacketCount();
- size_t index = i % GetTestPacketCount();
-
- RtpDumpPacket packet;
- result &= (rtc::SR_SUCCESS == reader.ReadPacket(&packet));
- // Check the elapsed time of the dump packet.
- result &= (packet.elapsed_time >= prev_elapsed_time);
- prev_elapsed_time = packet.elapsed_time;
-
- // Check the RTP or RTCP packet.
- rtc::ByteBufferReader buf(reinterpret_cast<const char*>(&packet.data[0]),
- packet.data.size());
- if (packet.is_rtcp()) {
- // RTCP packet.
- RawRtcpPacket rtcp_packet;
- result &= rtcp_packet.ReadFromByteBuffer(&buf);
- result &= rtcp_packet.EqualsTo(kTestRawRtcpPackets[index]);
- } else {
- // RTP packet.
- RawRtpPacket rtp_packet;
- result &= rtp_packet.ReadFromByteBuffer(&buf);
- result &= rtp_packet.SameExceptSeqNumTimestampSsrc(
- kTestRawRtpPackets[index],
- static_cast<uint16_t>(kTestRawRtpPackets[index].sequence_number +
- loop * GetTestPacketCount()),
- static_cast<uint32_t>(kTestRawRtpPackets[index].timestamp +
- loop * kRtpTimestampIncrease),
- ssrc);
- }
- }
-
- stream->Rewind();
- return result;
-}
-
-bool RtpTestUtility::VerifyPacket(const RtpDumpPacket* dump,
- const RawRtpPacket* raw,
- bool header_only) {
- if (!dump || !raw) return false;
-
- rtc::ByteBufferWriter buf;
- raw->WriteToByteBuffer(RtpTestUtility::kDefaultSsrc, &buf);
-
- if (header_only) {
- size_t header_len = 0;
- dump->GetRtpHeaderLen(&header_len);
- return header_len == dump->data.size() &&
- buf.Length() > dump->data.size() &&
- 0 == memcmp(buf.Data(), &dump->data[0], dump->data.size());
- } else {
- return buf.Length() == dump->data.size() &&
- 0 == memcmp(buf.Data(), &dump->data[0], dump->data.size());
- }
-}
-
// Implementation of VideoCaptureListener.
VideoCapturerListener::VideoCapturerListener(VideoCapturer* capturer)
: capturer_(capturer),
diff --git a/media/base/testutils.h b/media/base/testutils.h
index 966a25b..b0aacd5 100644
--- a/media/base/testutils.h
+++ b/media/base/testutils.h
@@ -79,43 +79,6 @@
char payload[16];
};
-class RtpTestUtility {
- public:
- static size_t GetTestPacketCount();
-
- // Write the first count number of kTestRawRtcpPackets or kTestRawRtpPackets,
- // depending on the flag rtcp. If it is RTP, use the specified SSRC. Return
- // true if successful.
- static bool WriteTestPackets(size_t count,
- bool rtcp,
- uint32_t rtp_ssrc,
- RtpDumpWriter* writer);
-
- // Loop read the first count number of packets from the specified stream.
- // Verify the elapsed time of the dump packets increase monotonically. If the
- // stream is a RTP stream, verify the RTP sequence number, timestamp, and
- // payload. If the stream is a RTCP stream, verify the RTCP header and
- // payload.
- static bool VerifyTestPacketsFromStream(size_t count,
- rtc::StreamInterface* stream,
- uint32_t ssrc);
-
- // Verify the dump packet is the same as the raw RTP packet.
- static bool VerifyPacket(const RtpDumpPacket* dump,
- const RawRtpPacket* raw,
- bool header_only);
-
- static const uint32_t kDefaultSsrc = 1;
- static const uint32_t kRtpTimestampIncrease = 90;
- static const uint32_t kDefaultTimeIncrease = 30;
- static const uint32_t kElapsedTimeInterval = 10;
- static const RawRtpPacket kTestRawRtpPackets[];
- static const RawRtcpPacket kTestRawRtcpPackets[];
-
- private:
- RtpTestUtility() {}
-};
-
// Test helper for testing VideoCapturer implementations.
class VideoCapturerListener
: public sigslot::has_slots<>,