From c412a9c177bf3000d814e295ff532537a04b64ca Mon Sep 17 00:00:00 2001 From: philipel Date: Fri, 30 Dec 2022 13:15:35 +0100 Subject: [PATCH] Record packets starting from a zero offset in RtpDumpWriter. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug: webrtc:14801 Change-Id: I5afb305003e3abde46829500a8b0eb48d95da2b3 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/289960 Commit-Queue: Philip Eliasson Reviewed-by: Erik Språng Cr-Commit-Position: refs/heads/main@{#38982} --- test/BUILD.gn | 5 ++++- test/rtp_file_writer.cc | 7 ++++++- test/rtp_file_writer_unittest.cc | 13 ++++++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/test/BUILD.gn b/test/BUILD.gn index ab42ede40d..9842ba2733 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -231,7 +231,10 @@ rtc_library("rtp_test_utils") { "../rtc_base/synchronization:mutex", "../rtc_base/system:arch", ] - absl_deps = [ "//third_party/abseil-cpp/absl/strings" ] + absl_deps = [ + "//third_party/abseil-cpp/absl/strings", + "//third_party/abseil-cpp/absl/types:optional", + ] } rtc_library("field_trial") { diff --git a/test/rtp_file_writer.cc b/test/rtp_file_writer.cc index c80b6387a7..22f664abc8 100644 --- a/test/rtp_file_writer.cc +++ b/test/rtp_file_writer.cc @@ -15,6 +15,7 @@ #include +#include "absl/types/optional.h" #include "rtc_base/checks.h" namespace webrtc { @@ -42,9 +43,12 @@ class RtpDumpWriter : public RtpFileWriter { RtpDumpWriter& operator=(const RtpDumpWriter&) = delete; bool WritePacket(const RtpPacket* packet) override { + if (!first_packet_time_) { + first_packet_time_ = packet->time_ms; + } uint16_t len = static_cast(packet->length + kPacketHeaderSize); uint16_t plen = static_cast(packet->original_length); - uint32_t offset = packet->time_ms; + uint32_t offset = packet->time_ms - *first_packet_time_; RTC_CHECK(WriteUint16(len)); RTC_CHECK(WriteUint16(plen)); RTC_CHECK(WriteUint32(offset)); @@ -88,6 +92,7 @@ class RtpDumpWriter : public RtpFileWriter { } FILE* file_; + absl::optional first_packet_time_; }; RtpFileWriter* RtpFileWriter::Create(FileFormat format, diff --git a/test/rtp_file_writer_unittest.cc b/test/rtp_file_writer_unittest.cc index a6281c7787..2396d7c346 100644 --- a/test/rtp_file_writer_unittest.cc +++ b/test/rtp_file_writer_unittest.cc @@ -29,13 +29,13 @@ class RtpFileWriterTest : public ::testing::Test { test::RtpFileWriter::Create(test::RtpFileWriter::kRtpDump, filename_)); } - void WriteRtpPackets(int num_packets) { + void WriteRtpPackets(int num_packets, int time_ms_offset = 0) { ASSERT_TRUE(rtp_writer_.get() != NULL); test::RtpPacket packet; for (int i = 1; i <= num_packets; ++i) { packet.length = i; packet.original_length = i; - packet.time_ms = i; + packet.time_ms = i + time_ms_offset; memset(packet.data, i, packet.length); EXPECT_TRUE(rtp_writer_->WritePacket(&packet)); } @@ -55,7 +55,7 @@ class RtpFileWriterTest : public ::testing::Test { ++i; EXPECT_EQ(static_cast(i), packet.length); EXPECT_EQ(static_cast(i), packet.original_length); - EXPECT_EQ(static_cast(i), packet.time_ms); + EXPECT_EQ(static_cast(i - 1), packet.time_ms); for (int j = 0; j < i; ++j) { EXPECT_EQ(i, packet.data[j]); } @@ -75,4 +75,11 @@ TEST_F(RtpFileWriterTest, WriteToRtpDump) { VerifyFileContents(10); } +TEST_F(RtpFileWriterTest, WriteToRtpDumpWithOffset) { + Init("test_rtp_file_writer.rtp"); + WriteRtpPackets(10, 100); + CloseOutputFile(); + VerifyFileContents(10); +} + } // namespace webrtc