| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 |
| 11 #include <string.h> | 11 #include <string.h> |
| 12 | 12 |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <utility> | 14 #include <utility> |
| 15 | 15 |
| 16 #include "webrtc/test/gtest.h" | |
| 17 #include "webrtc/base/basictypes.h" | 16 #include "webrtc/base/basictypes.h" |
| 18 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
| 19 #include "webrtc/base/random.h" | 18 #include "webrtc/base/random.h" |
| 20 #include "webrtc/base/scoped_ref_ptr.h" | 19 #include "webrtc/base/scoped_ref_ptr.h" |
| 21 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 20 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
| 22 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" | 21 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" |
| 23 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction_internal.h" | 22 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction_internal.h" |
| 24 #include "webrtc/modules/rtp_rtcp/source/ulpfec_header_reader_writer.h" | 23 #include "webrtc/modules/rtp_rtcp/source/ulpfec_header_reader_writer.h" |
| 24 #include "webrtc/test/gtest.h" |
| 25 | 25 |
| 26 namespace webrtc { | 26 namespace webrtc { |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 using Packet = ::webrtc::ForwardErrorCorrection::Packet; | 30 using Packet = ::webrtc::ForwardErrorCorrection::Packet; |
| 31 using ReceivedFecPacket = ::webrtc::ForwardErrorCorrection::ReceivedFecPacket; | 31 using ReceivedFecPacket = ::webrtc::ForwardErrorCorrection::ReceivedFecPacket; |
| 32 | 32 |
| 33 constexpr uint32_t kMediaSsrc = 1254983; | 33 constexpr uint32_t kMediaSsrc = 1254983; |
| 34 constexpr uint16_t kMediaStartSeqNum = 825; | 34 constexpr uint16_t kMediaStartSeqNum = 825; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 49 } | 49 } |
| 50 | 50 |
| 51 std::unique_ptr<Packet> WriteHeader(const uint8_t* packet_mask, | 51 std::unique_ptr<Packet> WriteHeader(const uint8_t* packet_mask, |
| 52 size_t packet_mask_size) { | 52 size_t packet_mask_size) { |
| 53 UlpfecHeaderWriter writer; | 53 UlpfecHeaderWriter writer; |
| 54 std::unique_ptr<Packet> written_packet(new Packet()); | 54 std::unique_ptr<Packet> written_packet(new Packet()); |
| 55 written_packet->length = kMediaPacketLength; | 55 written_packet->length = kMediaPacketLength; |
| 56 for (size_t i = 0; i < written_packet->length; ++i) { | 56 for (size_t i = 0; i < written_packet->length; ++i) { |
| 57 written_packet->data[i] = i; // Actual content doesn't matter. | 57 written_packet->data[i] = i; // Actual content doesn't matter. |
| 58 } | 58 } |
| 59 writer.FinalizeFecHeader(kMediaStartSeqNum, packet_mask, packet_mask_size, | 59 writer.FinalizeFecHeader(kMediaSsrc, kMediaStartSeqNum, packet_mask, |
| 60 written_packet.get()); | 60 packet_mask_size, written_packet.get()); |
| 61 return written_packet; | 61 return written_packet; |
| 62 } | 62 } |
| 63 | 63 |
| 64 std::unique_ptr<ReceivedFecPacket> ReadHeader(const Packet& written_packet) { | 64 std::unique_ptr<ReceivedFecPacket> ReadHeader(const Packet& written_packet) { |
| 65 UlpfecHeaderReader reader; | 65 UlpfecHeaderReader reader; |
| 66 std::unique_ptr<ReceivedFecPacket> read_packet(new ReceivedFecPacket()); | 66 std::unique_ptr<ReceivedFecPacket> read_packet(new ReceivedFecPacket()); |
| 67 read_packet->ssrc = kMediaSsrc; | 67 read_packet->ssrc = kMediaSsrc; |
| 68 read_packet->pkt = rtc::scoped_refptr<Packet>(new Packet()); | 68 read_packet->pkt = rtc::scoped_refptr<Packet>(new Packet()); |
| 69 memcpy(read_packet->pkt->data, written_packet.data, written_packet.length); | 69 memcpy(read_packet->pkt->data, written_packet.data, written_packet.length); |
| 70 read_packet->pkt->length = written_packet.length; | 70 read_packet->pkt->length = written_packet.length; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 TEST(UlpfecHeaderWriterTest, FinalizesSmallHeader) { | 148 TEST(UlpfecHeaderWriterTest, FinalizesSmallHeader) { |
| 149 const size_t packet_mask_size = kUlpfecPacketMaskSizeLBitClear; | 149 const size_t packet_mask_size = kUlpfecPacketMaskSizeLBitClear; |
| 150 auto packet_mask = GeneratePacketMask(packet_mask_size, 0xabcd); | 150 auto packet_mask = GeneratePacketMask(packet_mask_size, 0xabcd); |
| 151 Packet written_packet; | 151 Packet written_packet; |
| 152 written_packet.length = kMediaPacketLength; | 152 written_packet.length = kMediaPacketLength; |
| 153 for (size_t i = 0; i < written_packet.length; ++i) { | 153 for (size_t i = 0; i < written_packet.length; ++i) { |
| 154 written_packet.data[i] = i; | 154 written_packet.data[i] = i; |
| 155 } | 155 } |
| 156 | 156 |
| 157 UlpfecHeaderWriter writer; | 157 UlpfecHeaderWriter writer; |
| 158 writer.FinalizeFecHeader(kMediaStartSeqNum, packet_mask.get(), | 158 writer.FinalizeFecHeader(kMediaSsrc, kMediaStartSeqNum, packet_mask.get(), |
| 159 packet_mask_size, &written_packet); | 159 packet_mask_size, &written_packet); |
| 160 | 160 |
| 161 const uint8_t* packet = written_packet.data; | 161 const uint8_t* packet = written_packet.data; |
| 162 EXPECT_EQ(0x00, packet[0] & 0x80); // E bit. | 162 EXPECT_EQ(0x00, packet[0] & 0x80); // E bit. |
| 163 EXPECT_EQ(0x00, packet[0] & 0x40); // L bit. | 163 EXPECT_EQ(0x00, packet[0] & 0x40); // L bit. |
| 164 EXPECT_EQ(kMediaStartSeqNum, ByteReader<uint16_t>::ReadBigEndian(packet + 2)); | 164 EXPECT_EQ(kMediaStartSeqNum, ByteReader<uint16_t>::ReadBigEndian(packet + 2)); |
| 165 EXPECT_EQ( | 165 EXPECT_EQ( |
| 166 static_cast<uint16_t>(kMediaPacketLength - kUlpfecHeaderSizeLBitClear), | 166 static_cast<uint16_t>(kMediaPacketLength - kUlpfecHeaderSizeLBitClear), |
| 167 ByteReader<uint16_t>::ReadBigEndian(packet + 10)); | 167 ByteReader<uint16_t>::ReadBigEndian(packet + 10)); |
| 168 EXPECT_EQ(0, memcmp(packet + kUlpfecPacketMaskOffset, packet_mask.get(), | 168 EXPECT_EQ(0, memcmp(packet + kUlpfecPacketMaskOffset, packet_mask.get(), |
| 169 packet_mask_size)); | 169 packet_mask_size)); |
| 170 } | 170 } |
| 171 | 171 |
| 172 TEST(UlpfecHeaderWriterTest, FinalizesLargeHeader) { | 172 TEST(UlpfecHeaderWriterTest, FinalizesLargeHeader) { |
| 173 const size_t packet_mask_size = kUlpfecPacketMaskSizeLBitSet; | 173 const size_t packet_mask_size = kUlpfecPacketMaskSizeLBitSet; |
| 174 auto packet_mask = GeneratePacketMask(packet_mask_size, 0xabcd); | 174 auto packet_mask = GeneratePacketMask(packet_mask_size, 0xabcd); |
| 175 Packet written_packet; | 175 Packet written_packet; |
| 176 written_packet.length = kMediaPacketLength; | 176 written_packet.length = kMediaPacketLength; |
| 177 for (size_t i = 0; i < written_packet.length; ++i) { | 177 for (size_t i = 0; i < written_packet.length; ++i) { |
| 178 written_packet.data[i] = i; | 178 written_packet.data[i] = i; |
| 179 } | 179 } |
| 180 | 180 |
| 181 UlpfecHeaderWriter writer; | 181 UlpfecHeaderWriter writer; |
| 182 writer.FinalizeFecHeader(kMediaStartSeqNum, packet_mask.get(), | 182 writer.FinalizeFecHeader(kMediaSsrc, kMediaStartSeqNum, packet_mask.get(), |
| 183 packet_mask_size, &written_packet); | 183 packet_mask_size, &written_packet); |
| 184 | 184 |
| 185 const uint8_t* packet = written_packet.data; | 185 const uint8_t* packet = written_packet.data; |
| 186 EXPECT_EQ(0x00, packet[0] & 0x80); // E bit. | 186 EXPECT_EQ(0x00, packet[0] & 0x80); // E bit. |
| 187 EXPECT_EQ(0x40, packet[0] & 0x40); // L bit. | 187 EXPECT_EQ(0x40, packet[0] & 0x40); // L bit. |
| 188 EXPECT_EQ(kMediaStartSeqNum, ByteReader<uint16_t>::ReadBigEndian(packet + 2)); | 188 EXPECT_EQ(kMediaStartSeqNum, ByteReader<uint16_t>::ReadBigEndian(packet + 2)); |
| 189 EXPECT_EQ( | 189 EXPECT_EQ( |
| 190 static_cast<uint16_t>(kMediaPacketLength - kUlpfecHeaderSizeLBitSet), | 190 static_cast<uint16_t>(kMediaPacketLength - kUlpfecHeaderSizeLBitSet), |
| 191 ByteReader<uint16_t>::ReadBigEndian(packet + 10)); | 191 ByteReader<uint16_t>::ReadBigEndian(packet + 10)); |
| 192 EXPECT_EQ(0, memcmp(packet + kUlpfecPacketMaskOffset, packet_mask.get(), | 192 EXPECT_EQ(0, memcmp(packet + kUlpfecPacketMaskOffset, packet_mask.get(), |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 auto packet_mask = GeneratePacketMask(packet_mask_size, 0xabcd); | 235 auto packet_mask = GeneratePacketMask(packet_mask_size, 0xabcd); |
| 236 | 236 |
| 237 auto written_packet = WriteHeader(packet_mask.get(), packet_mask_size); | 237 auto written_packet = WriteHeader(packet_mask.get(), packet_mask_size); |
| 238 auto read_packet = ReadHeader(*written_packet); | 238 auto read_packet = ReadHeader(*written_packet); |
| 239 | 239 |
| 240 VerifyHeaders(kUlpfecHeaderSizeLBitSet, packet_mask.get(), packet_mask_size, | 240 VerifyHeaders(kUlpfecHeaderSizeLBitSet, packet_mask.get(), packet_mask_size, |
| 241 *written_packet, *read_packet); | 241 *written_packet, *read_packet); |
| 242 } | 242 } |
| 243 | 243 |
| 244 } // namespace webrtc | 244 } // namespace webrtc |
| OLD | NEW |