mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 05:40:42 +01:00
Record packets starting from a zero offset in RtpDumpWriter.
Bug: webrtc:14801 Change-Id: I5afb305003e3abde46829500a8b0eb48d95da2b3 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/289960 Commit-Queue: Philip Eliasson <philipel@webrtc.org> Reviewed-by: Erik Språng <sprang@webrtc.org> Cr-Commit-Position: refs/heads/main@{#38982}
This commit is contained in:
parent
81aab48878
commit
c412a9c177
3 changed files with 20 additions and 5 deletions
|
@ -231,7 +231,10 @@ rtc_library("rtp_test_utils") {
|
||||||
"../rtc_base/synchronization:mutex",
|
"../rtc_base/synchronization:mutex",
|
||||||
"../rtc_base/system:arch",
|
"../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") {
|
rtc_library("field_trial") {
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "absl/types/optional.h"
|
||||||
#include "rtc_base/checks.h"
|
#include "rtc_base/checks.h"
|
||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
|
@ -42,9 +43,12 @@ class RtpDumpWriter : public RtpFileWriter {
|
||||||
RtpDumpWriter& operator=(const RtpDumpWriter&) = delete;
|
RtpDumpWriter& operator=(const RtpDumpWriter&) = delete;
|
||||||
|
|
||||||
bool WritePacket(const RtpPacket* packet) override {
|
bool WritePacket(const RtpPacket* packet) override {
|
||||||
|
if (!first_packet_time_) {
|
||||||
|
first_packet_time_ = packet->time_ms;
|
||||||
|
}
|
||||||
uint16_t len = static_cast<uint16_t>(packet->length + kPacketHeaderSize);
|
uint16_t len = static_cast<uint16_t>(packet->length + kPacketHeaderSize);
|
||||||
uint16_t plen = static_cast<uint16_t>(packet->original_length);
|
uint16_t plen = static_cast<uint16_t>(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(len));
|
||||||
RTC_CHECK(WriteUint16(plen));
|
RTC_CHECK(WriteUint16(plen));
|
||||||
RTC_CHECK(WriteUint32(offset));
|
RTC_CHECK(WriteUint32(offset));
|
||||||
|
@ -88,6 +92,7 @@ class RtpDumpWriter : public RtpFileWriter {
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE* file_;
|
FILE* file_;
|
||||||
|
absl::optional<uint32_t> first_packet_time_;
|
||||||
};
|
};
|
||||||
|
|
||||||
RtpFileWriter* RtpFileWriter::Create(FileFormat format,
|
RtpFileWriter* RtpFileWriter::Create(FileFormat format,
|
||||||
|
|
|
@ -29,13 +29,13 @@ class RtpFileWriterTest : public ::testing::Test {
|
||||||
test::RtpFileWriter::Create(test::RtpFileWriter::kRtpDump, filename_));
|
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);
|
ASSERT_TRUE(rtp_writer_.get() != NULL);
|
||||||
test::RtpPacket packet;
|
test::RtpPacket packet;
|
||||||
for (int i = 1; i <= num_packets; ++i) {
|
for (int i = 1; i <= num_packets; ++i) {
|
||||||
packet.length = i;
|
packet.length = i;
|
||||||
packet.original_length = i;
|
packet.original_length = i;
|
||||||
packet.time_ms = i;
|
packet.time_ms = i + time_ms_offset;
|
||||||
memset(packet.data, i, packet.length);
|
memset(packet.data, i, packet.length);
|
||||||
EXPECT_TRUE(rtp_writer_->WritePacket(&packet));
|
EXPECT_TRUE(rtp_writer_->WritePacket(&packet));
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,7 @@ class RtpFileWriterTest : public ::testing::Test {
|
||||||
++i;
|
++i;
|
||||||
EXPECT_EQ(static_cast<size_t>(i), packet.length);
|
EXPECT_EQ(static_cast<size_t>(i), packet.length);
|
||||||
EXPECT_EQ(static_cast<size_t>(i), packet.original_length);
|
EXPECT_EQ(static_cast<size_t>(i), packet.original_length);
|
||||||
EXPECT_EQ(static_cast<uint32_t>(i), packet.time_ms);
|
EXPECT_EQ(static_cast<uint32_t>(i - 1), packet.time_ms);
|
||||||
for (int j = 0; j < i; ++j) {
|
for (int j = 0; j < i; ++j) {
|
||||||
EXPECT_EQ(i, packet.data[j]);
|
EXPECT_EQ(i, packet.data[j]);
|
||||||
}
|
}
|
||||||
|
@ -75,4 +75,11 @@ TEST_F(RtpFileWriterTest, WriteToRtpDump) {
|
||||||
VerifyFileContents(10);
|
VerifyFileContents(10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(RtpFileWriterTest, WriteToRtpDumpWithOffset) {
|
||||||
|
Init("test_rtp_file_writer.rtp");
|
||||||
|
WriteRtpPackets(10, 100);
|
||||||
|
CloseOutputFile();
|
||||||
|
VerifyFileContents(10);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
|
Loading…
Reference in a new issue