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

Unified Diff: webrtc/modules/rtp_rtcp/source/fec_test_helper.cc

Issue 2276473002: Rename FrameGenerator -> UlpfecPacketGenerator. (pt. 6b) (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@headers-pt5-add_flexfec
Patch Set: gmock/test paths. Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/rtp_rtcp/source/fec_test_helper.cc
diff --git a/webrtc/modules/rtp_rtcp/source/fec_test_helper.cc b/webrtc/modules/rtp_rtcp/source/fec_test_helper.cc
index 235720d819a8a75b551806092ddec01978b01765..3799c7f0c2dfdf5bf161d4569035fb5e8785ec1e 100644
--- a/webrtc/modules/rtp_rtcp/source/fec_test_helper.cc
+++ b/webrtc/modules/rtp_rtcp/source/fec_test_helper.cc
@@ -26,17 +26,82 @@ constexpr uint8_t kRedPayloadType = 97;
constexpr uint8_t kVp8PayloadType = 120;
} // namespace
-FrameGenerator::FrameGenerator()
+ForwardErrorCorrection::PacketList MediaPacketGenerator::ConstructMediaPackets(
+ int num_media_packets,
+ uint16_t start_seq_num) {
+ RTC_DCHECK_GT(num_media_packets, 0);
+ uint16_t seq_num = start_seq_num;
+ int time_stamp = random_->Rand<int>();
+
+ ForwardErrorCorrection::PacketList media_packets;
+
+ for (int i = 0; i < num_media_packets; ++i) {
+ std::unique_ptr<ForwardErrorCorrection::Packet> media_packet(
+ new ForwardErrorCorrection::Packet());
+ media_packet->length = random_->Rand(min_packet_size_, max_packet_size_);
+
+ // Generate random values for the first 2 bytes
+ media_packet->data[0] = random_->Rand<uint8_t>();
+ media_packet->data[1] = random_->Rand<uint8_t>();
+
+ // The first two bits are assumed to be 10 by the FEC encoder.
+ // In fact the FEC decoder will set the two first bits to 10 regardless of
+ // what they actually were. Set the first two bits to 10 so that a memcmp
+ // can be performed for the whole restored packet.
+ media_packet->data[0] |= 0x80;
+ media_packet->data[0] &= 0xbf;
+
+ // FEC is applied to a whole frame.
+ // A frame is signaled by multiple packets without the marker bit set
+ // followed by the last packet of the frame for which the marker bit is set.
+ // Only push one (fake) frame to the FEC.
+ media_packet->data[1] &= 0x7f;
+
+ webrtc::ByteWriter<uint16_t>::WriteBigEndian(&media_packet->data[2],
+ seq_num);
+ webrtc::ByteWriter<uint32_t>::WriteBigEndian(&media_packet->data[4],
+ time_stamp);
+ webrtc::ByteWriter<uint32_t>::WriteBigEndian(&media_packet->data[8], ssrc_);
+
+ // Generate random values for payload.
+ for (size_t j = 12; j < media_packet->length; ++j) {
+ media_packet->data[j] = random_->Rand<uint8_t>();
+ }
+ seq_num++;
+ media_packets.push_back(std::move(media_packet));
+ }
+ // Last packet, set marker bit.
+ ForwardErrorCorrection::Packet* media_packet = media_packets.back().get();
+ RTC_DCHECK(media_packet);
+ media_packet->data[1] |= 0x80;
+
+ fec_seq_num_ = seq_num;
+
+ return media_packets;
+}
+
+ForwardErrorCorrection::PacketList MediaPacketGenerator::ConstructMediaPackets(
+ int num_media_packets) {
+ return ConstructMediaPackets(num_media_packets, random_->Rand<uint16_t>());
+}
+
+uint16_t MediaPacketGenerator::GetFecSeqNum() {
+ return fec_seq_num_;
+}
+
+UlpfecPacketGenerator::UlpfecPacketGenerator()
: num_packets_(0), seq_num_(0), timestamp_(0) {}
-void FrameGenerator::NewFrame(int num_packets) {
+void UlpfecPacketGenerator::NewFrame(int num_packets) {
num_packets_ = num_packets;
timestamp_ += 3000;
}
-uint16_t FrameGenerator::NextSeqNum() { return ++seq_num_; }
+uint16_t UlpfecPacketGenerator::NextSeqNum() {
+ return ++seq_num_;
+}
-RawRtpPacket* FrameGenerator::NextPacket(int offset, size_t length) {
+RawRtpPacket* UlpfecPacketGenerator::NextPacket(int offset, size_t length) {
RawRtpPacket* rtp_packet = new RawRtpPacket;
for (size_t i = 0; i < length; ++i)
rtp_packet->data[i + kRtpHeaderSize] = offset + i;
@@ -55,7 +120,8 @@ RawRtpPacket* FrameGenerator::NextPacket(int offset, size_t length) {
}
// Creates a new RtpPacket with the RED header added to the packet.
-RawRtpPacket* FrameGenerator::BuildMediaRedPacket(const RawRtpPacket* packet) {
+RawRtpPacket* UlpfecPacketGenerator::BuildMediaRedPacket(
+ const RawRtpPacket* packet) {
const size_t kHeaderLength = packet->header.header.headerLength;
RawRtpPacket* red_packet = new RawRtpPacket;
red_packet->header = packet->header;
@@ -72,7 +138,7 @@ RawRtpPacket* FrameGenerator::BuildMediaRedPacket(const RawRtpPacket* packet) {
// Creates a new RtpPacket with FEC payload and RED header. Does this by
// creating a new fake media RtpPacket, clears the marker bit and adds a RED
// header. Finally replaces the payload with the content of |packet->data|.
-RawRtpPacket* FrameGenerator::BuildFecRedPacket(
+RawRtpPacket* UlpfecPacketGenerator::BuildFecRedPacket(
const ForwardErrorCorrection::Packet* packet) {
// Create a fake media packet to get a correct header. 1 byte RED header.
++num_packets_;
@@ -85,9 +151,10 @@ RawRtpPacket* FrameGenerator::BuildFecRedPacket(
return red_packet;
}
-void FrameGenerator::SetRedHeader(ForwardErrorCorrection::Packet* red_packet,
- uint8_t payload_type,
- size_t header_length) const {
+void UlpfecPacketGenerator::SetRedHeader(
+ ForwardErrorCorrection::Packet* red_packet,
+ uint8_t payload_type,
+ size_t header_length) const {
// Replace pltype.
red_packet->data[1] &= 0x80; // Reset.
red_packet->data[1] += kRedPayloadType; // Replace.
@@ -96,7 +163,8 @@ void FrameGenerator::SetRedHeader(ForwardErrorCorrection::Packet* red_packet,
red_packet->data[header_length] = payload_type;
}
-void FrameGenerator::BuildRtpHeader(uint8_t* data, const RTPHeader* header) {
+void UlpfecPacketGenerator::BuildRtpHeader(uint8_t* data,
+ const RTPHeader* header) {
data[0] = 0x80; // Version 2.
data[1] = header->payloadType;
data[1] |= (header->markerBit ? kRtpMarkerBitMask : 0);
@@ -105,69 +173,6 @@ void FrameGenerator::BuildRtpHeader(uint8_t* data, const RTPHeader* header) {
ByteWriter<uint32_t>::WriteBigEndian(data + 8, header->ssrc);
}
-ForwardErrorCorrection::PacketList MediaPacketGenerator::ConstructMediaPackets(
- int num_media_packets,
- uint16_t start_seq_num) {
- RTC_DCHECK_GT(num_media_packets, 0);
- uint16_t seq_num = start_seq_num;
- int time_stamp = random_->Rand<int>();
-
- ForwardErrorCorrection::PacketList media_packets;
-
- for (int i = 0; i < num_media_packets; ++i) {
- std::unique_ptr<ForwardErrorCorrection::Packet> media_packet(
- new ForwardErrorCorrection::Packet());
- media_packet->length = random_->Rand(min_packet_size_, max_packet_size_);
-
- // Generate random values for the first 2 bytes
- media_packet->data[0] = random_->Rand<uint8_t>();
- media_packet->data[1] = random_->Rand<uint8_t>();
-
- // The first two bits are assumed to be 10 by the FEC encoder.
- // In fact the FEC decoder will set the two first bits to 10 regardless of
- // what they actually were. Set the first two bits to 10 so that a memcmp
- // can be performed for the whole restored packet.
- media_packet->data[0] |= 0x80;
- media_packet->data[0] &= 0xbf;
-
- // FEC is applied to a whole frame.
- // A frame is signaled by multiple packets without the marker bit set
- // followed by the last packet of the frame for which the marker bit is set.
- // Only push one (fake) frame to the FEC.
- media_packet->data[1] &= 0x7f;
-
- webrtc::ByteWriter<uint16_t>::WriteBigEndian(&media_packet->data[2],
- seq_num);
- webrtc::ByteWriter<uint32_t>::WriteBigEndian(&media_packet->data[4],
- time_stamp);
- webrtc::ByteWriter<uint32_t>::WriteBigEndian(&media_packet->data[8], ssrc_);
-
- // Generate random values for payload.
- for (size_t j = 12; j < media_packet->length; ++j) {
- media_packet->data[j] = random_->Rand<uint8_t>();
- }
- seq_num++;
- media_packets.push_back(std::move(media_packet));
- }
- // Last packet, set marker bit.
- ForwardErrorCorrection::Packet* media_packet = media_packets.back().get();
- RTC_DCHECK(media_packet);
- media_packet->data[1] |= 0x80;
-
- fec_seq_num_ = seq_num;
-
- return media_packets;
-}
-
-ForwardErrorCorrection::PacketList MediaPacketGenerator::ConstructMediaPackets(
- int num_media_packets) {
- return ConstructMediaPackets(num_media_packets, random_->Rand<uint16_t>());
-}
-
-uint16_t MediaPacketGenerator::GetFecSeqNum() {
- return fec_seq_num_;
-}
-
} // namespace fec
} // namespace test
} // namespace webrtc
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/fec_test_helper.h ('k') | webrtc/modules/rtp_rtcp/source/producer_fec_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698