OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 <list> | 13 #include <list> |
14 | 14 |
15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "webrtc/base/scoped_ptr.h" | 17 #include "webrtc/base/scoped_ptr.h" |
18 #include "webrtc/modules/rtp_rtcp/include/fec_receiver.h" | 18 #include "webrtc/modules/rtp_rtcp/include/fec_receiver.h" |
19 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" | 19 #include "webrtc/modules/rtp_rtcp/include/rtp_header_parser.h" |
20 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" | 20 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtp_rtcp.h" |
21 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 21 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
22 #include "webrtc/modules/rtp_rtcp/source/fec_test_helper.h" | 22 #include "webrtc/modules/rtp_rtcp/source/fec_test_helper.h" |
23 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" | 23 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" |
24 | 24 |
25 using ::testing::_; | 25 using ::testing::_; |
26 using ::testing::Args; | 26 using ::testing::Args; |
27 using ::testing::ElementsAreArray; | 27 using ::testing::ElementsAreArray; |
28 using ::testing::Return; | 28 using ::testing::Return; |
| 29 using Packet = webrtc::ForwardErrorCorrection::Packet; |
29 | 30 |
30 namespace webrtc { | 31 namespace webrtc { |
31 | 32 |
32 class ReceiverFecTest : public ::testing::Test { | 33 class ReceiverFecTest : public ::testing::Test { |
33 protected: | 34 protected: |
34 virtual void SetUp() { | 35 virtual void SetUp() { |
35 fec_.reset(new ForwardErrorCorrection()); | 36 fec_.reset(new ForwardErrorCorrection()); |
36 receiver_fec_.reset(FecReceiver::Create(&rtp_data_callback_)); | 37 receiver_fec_.reset(FecReceiver::Create(&rtp_data_callback_)); |
37 generator_.reset(new FrameGenerator()); | 38 generator_.reset(new FrameGenerator()); |
38 } | 39 } |
39 | 40 |
40 void GenerateFEC(std::list<Packet*>* media_packets, | 41 void GenerateFEC(std::list<Packet*>* media_packets, |
41 std::list<Packet*>* fec_packets, | 42 std::list<Packet*>* fec_packets, |
42 unsigned int num_fec_packets) { | 43 unsigned int num_fec_packets) { |
43 uint8_t protection_factor = num_fec_packets * 255 / media_packets->size(); | 44 uint8_t protection_factor = num_fec_packets * 255 / media_packets->size(); |
44 EXPECT_EQ(0, fec_->GenerateFEC(*media_packets, protection_factor, | 45 EXPECT_EQ(0, fec_->GenerateFEC(*media_packets, protection_factor, |
45 0, false, kFecMaskBursty, fec_packets)); | 46 0, false, kFecMaskBursty, fec_packets)); |
46 ASSERT_EQ(num_fec_packets, fec_packets->size()); | 47 ASSERT_EQ(num_fec_packets, fec_packets->size()); |
47 } | 48 } |
48 | 49 |
49 void GenerateFrame(int num_media_packets, int frame_offset, | 50 void GenerateFrame(int num_media_packets, |
50 std::list<RtpPacket*>* media_rtp_packets, | 51 int frame_offset, |
| 52 std::list<test::RawRtpPacket*>* media_rtp_packets, |
51 std::list<Packet*>* media_packets) { | 53 std::list<Packet*>* media_packets) { |
52 generator_->NewFrame(num_media_packets); | 54 generator_->NewFrame(num_media_packets); |
53 for (int i = 0; i < num_media_packets; ++i) { | 55 for (int i = 0; i < num_media_packets; ++i) { |
54 media_rtp_packets->push_back( | 56 media_rtp_packets->push_back( |
55 generator_->NextPacket(frame_offset + i, kRtpHeaderSize + 10)); | 57 generator_->NextPacket(frame_offset + i, kRtpHeaderSize + 10)); |
56 media_packets->push_back(media_rtp_packets->back()); | 58 media_packets->push_back(media_rtp_packets->back()); |
57 } | 59 } |
58 } | 60 } |
59 | 61 |
60 void VerifyReconstructedMediaPacket(const RtpPacket* packet, int times) { | 62 void VerifyReconstructedMediaPacket(const test::RawRtpPacket* packet, |
| 63 int times) { |
61 // Verify that the content of the reconstructed packet is equal to the | 64 // Verify that the content of the reconstructed packet is equal to the |
62 // content of |packet|, and that the same content is received |times| number | 65 // content of |packet|, and that the same content is received |times| number |
63 // of times in a row. | 66 // of times in a row. |
64 EXPECT_CALL(rtp_data_callback_, OnRecoveredPacket(_, packet->length)) | 67 EXPECT_CALL(rtp_data_callback_, OnRecoveredPacket(_, packet->length)) |
65 .With(Args<0, 1>(ElementsAreArray(packet->data, | 68 .With(Args<0, 1>(ElementsAreArray(packet->data, |
66 packet->length))) | 69 packet->length))) |
67 .Times(times).WillRepeatedly(Return(true)); | 70 .Times(times).WillRepeatedly(Return(true)); |
68 } | 71 } |
69 | 72 |
70 void BuildAndAddRedMediaPacket(RtpPacket* packet) { | 73 void BuildAndAddRedMediaPacket(test::RawRtpPacket* packet) { |
71 RtpPacket* red_packet = generator_->BuildMediaRedPacket(packet); | 74 test::RawRtpPacket* red_packet = generator_->BuildMediaRedPacket(packet); |
72 EXPECT_EQ(0, receiver_fec_->AddReceivedRedPacket( | 75 EXPECT_EQ(0, receiver_fec_->AddReceivedRedPacket( |
73 red_packet->header.header, red_packet->data, | 76 red_packet->header.header, red_packet->data, |
74 red_packet->length, kFecPayloadType)); | 77 red_packet->length, kFecPayloadType)); |
75 delete red_packet; | 78 delete red_packet; |
76 } | 79 } |
77 | 80 |
78 void BuildAndAddRedFecPacket(Packet* packet) { | 81 void BuildAndAddRedFecPacket(Packet* packet) { |
79 RtpPacket* red_packet = generator_->BuildFecRedPacket(packet); | 82 test::RawRtpPacket* red_packet = generator_->BuildFecRedPacket(packet); |
80 EXPECT_EQ(0, receiver_fec_->AddReceivedRedPacket( | 83 EXPECT_EQ(0, receiver_fec_->AddReceivedRedPacket( |
81 red_packet->header.header, red_packet->data, | 84 red_packet->header.header, red_packet->data, |
82 red_packet->length, kFecPayloadType)); | 85 red_packet->length, kFecPayloadType)); |
83 delete red_packet; | 86 delete red_packet; |
84 } | 87 } |
85 | 88 |
86 void InjectGarbagePacketLength(size_t fec_garbage_offset); | 89 void InjectGarbagePacketLength(size_t fec_garbage_offset); |
87 static void SurvivesMaliciousPacket(const uint8_t* data, | 90 static void SurvivesMaliciousPacket(const uint8_t* data, |
88 size_t length, | 91 size_t length, |
89 uint8_t ulpfec_payload_type); | 92 uint8_t ulpfec_payload_type); |
90 | 93 |
91 MockRtpData rtp_data_callback_; | 94 MockRtpData rtp_data_callback_; |
92 rtc::scoped_ptr<ForwardErrorCorrection> fec_; | 95 rtc::scoped_ptr<ForwardErrorCorrection> fec_; |
93 rtc::scoped_ptr<FecReceiver> receiver_fec_; | 96 rtc::scoped_ptr<FecReceiver> receiver_fec_; |
94 rtc::scoped_ptr<FrameGenerator> generator_; | 97 rtc::scoped_ptr<FrameGenerator> generator_; |
95 }; | 98 }; |
96 | 99 |
97 void DeletePackets(std::list<Packet*>* packets) { | 100 void DeletePackets(std::list<Packet*>* packets) { |
98 while (!packets->empty()) { | 101 while (!packets->empty()) { |
99 delete packets->front(); | 102 delete packets->front(); |
100 packets->pop_front(); | 103 packets->pop_front(); |
101 } | 104 } |
102 } | 105 } |
103 | 106 |
104 TEST_F(ReceiverFecTest, TwoMediaOneFec) { | 107 TEST_F(ReceiverFecTest, TwoMediaOneFec) { |
105 const unsigned int kNumFecPackets = 1u; | 108 const unsigned int kNumFecPackets = 1u; |
106 std::list<RtpPacket*> media_rtp_packets; | 109 std::list<test::RawRtpPacket*> media_rtp_packets; |
107 std::list<Packet*> media_packets; | 110 std::list<Packet*> media_packets; |
108 GenerateFrame(2, 0, &media_rtp_packets, &media_packets); | 111 GenerateFrame(2, 0, &media_rtp_packets, &media_packets); |
109 std::list<Packet*> fec_packets; | 112 std::list<Packet*> fec_packets; |
110 GenerateFEC(&media_packets, &fec_packets, kNumFecPackets); | 113 GenerateFEC(&media_packets, &fec_packets, kNumFecPackets); |
111 | 114 |
112 // Recovery | 115 // Recovery |
113 std::list<RtpPacket*>::iterator it = media_rtp_packets.begin(); | 116 std::list<test::RawRtpPacket*>::iterator it = media_rtp_packets.begin(); |
114 BuildAndAddRedMediaPacket(*it); | 117 BuildAndAddRedMediaPacket(*it); |
115 VerifyReconstructedMediaPacket(*it, 1); | 118 VerifyReconstructedMediaPacket(*it, 1); |
116 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); | 119 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); |
117 // Drop one media packet. | 120 // Drop one media packet. |
118 std::list<Packet*>::iterator fec_it = fec_packets.begin(); | 121 std::list<Packet*>::iterator fec_it = fec_packets.begin(); |
119 BuildAndAddRedFecPacket(*fec_it); | 122 BuildAndAddRedFecPacket(*fec_it); |
120 ++it; | 123 ++it; |
121 VerifyReconstructedMediaPacket(*it, 1); | 124 VerifyReconstructedMediaPacket(*it, 1); |
122 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); | 125 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); |
123 | 126 |
124 FecPacketCounter counter = receiver_fec_->GetPacketCounter(); | 127 FecPacketCounter counter = receiver_fec_->GetPacketCounter(); |
125 EXPECT_EQ(2U, counter.num_packets); | 128 EXPECT_EQ(2U, counter.num_packets); |
126 EXPECT_EQ(1U, counter.num_fec_packets); | 129 EXPECT_EQ(1U, counter.num_fec_packets); |
127 EXPECT_EQ(1U, counter.num_recovered_packets); | 130 EXPECT_EQ(1U, counter.num_recovered_packets); |
128 | 131 |
129 DeletePackets(&media_packets); | 132 DeletePackets(&media_packets); |
130 } | 133 } |
131 | 134 |
132 void ReceiverFecTest::InjectGarbagePacketLength(size_t fec_garbage_offset) { | 135 void ReceiverFecTest::InjectGarbagePacketLength(size_t fec_garbage_offset) { |
133 EXPECT_CALL(rtp_data_callback_, OnRecoveredPacket(_, _)) | 136 EXPECT_CALL(rtp_data_callback_, OnRecoveredPacket(_, _)) |
134 .WillRepeatedly(Return(true)); | 137 .WillRepeatedly(Return(true)); |
135 | 138 |
136 const unsigned int kNumFecPackets = 1u; | 139 const unsigned int kNumFecPackets = 1u; |
137 std::list<RtpPacket*> media_rtp_packets; | 140 std::list<test::RawRtpPacket*> media_rtp_packets; |
138 std::list<Packet*> media_packets; | 141 std::list<Packet*> media_packets; |
139 GenerateFrame(2, 0, &media_rtp_packets, &media_packets); | 142 GenerateFrame(2, 0, &media_rtp_packets, &media_packets); |
140 std::list<Packet*> fec_packets; | 143 std::list<Packet*> fec_packets; |
141 GenerateFEC(&media_packets, &fec_packets, kNumFecPackets); | 144 GenerateFEC(&media_packets, &fec_packets, kNumFecPackets); |
142 ByteWriter<uint16_t>::WriteBigEndian( | 145 ByteWriter<uint16_t>::WriteBigEndian( |
143 &fec_packets.front()->data[fec_garbage_offset], 0x4711); | 146 &fec_packets.front()->data[fec_garbage_offset], 0x4711); |
144 | 147 |
145 // Inject first media packet, then first FEC packet, skipping the second media | 148 // Inject first media packet, then first FEC packet, skipping the second media |
146 // packet to cause a recovery from the FEC packet. | 149 // packet to cause a recovery from the FEC packet. |
147 BuildAndAddRedMediaPacket(media_rtp_packets.front()); | 150 BuildAndAddRedMediaPacket(media_rtp_packets.front()); |
(...skipping 14 matching lines...) Expand all Loading... |
162 } | 165 } |
163 | 166 |
164 TEST_F(ReceiverFecTest, InjectGarbageFecLevelHeaderProtectionLength) { | 167 TEST_F(ReceiverFecTest, InjectGarbageFecLevelHeaderProtectionLength) { |
165 // Byte offset 10 is the 'protection length' field in the first FEC level | 168 // Byte offset 10 is the 'protection length' field in the first FEC level |
166 // header. | 169 // header. |
167 InjectGarbagePacketLength(10); | 170 InjectGarbagePacketLength(10); |
168 } | 171 } |
169 | 172 |
170 TEST_F(ReceiverFecTest, TwoMediaTwoFec) { | 173 TEST_F(ReceiverFecTest, TwoMediaTwoFec) { |
171 const unsigned int kNumFecPackets = 2u; | 174 const unsigned int kNumFecPackets = 2u; |
172 std::list<RtpPacket*> media_rtp_packets; | 175 std::list<test::RawRtpPacket*> media_rtp_packets; |
173 std::list<Packet*> media_packets; | 176 std::list<Packet*> media_packets; |
174 GenerateFrame(2, 0, &media_rtp_packets, &media_packets); | 177 GenerateFrame(2, 0, &media_rtp_packets, &media_packets); |
175 std::list<Packet*> fec_packets; | 178 std::list<Packet*> fec_packets; |
176 GenerateFEC(&media_packets, &fec_packets, kNumFecPackets); | 179 GenerateFEC(&media_packets, &fec_packets, kNumFecPackets); |
177 | 180 |
178 // Recovery | 181 // Recovery |
179 // Drop both media packets. | 182 // Drop both media packets. |
180 std::list<RtpPacket*>::iterator it = media_rtp_packets.begin(); | 183 std::list<test::RawRtpPacket*>::iterator it = media_rtp_packets.begin(); |
181 std::list<Packet*>::iterator fec_it = fec_packets.begin(); | 184 std::list<Packet*>::iterator fec_it = fec_packets.begin(); |
182 BuildAndAddRedFecPacket(*fec_it); | 185 BuildAndAddRedFecPacket(*fec_it); |
183 VerifyReconstructedMediaPacket(*it, 1); | 186 VerifyReconstructedMediaPacket(*it, 1); |
184 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); | 187 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); |
185 ++fec_it; | 188 ++fec_it; |
186 BuildAndAddRedFecPacket(*fec_it); | 189 BuildAndAddRedFecPacket(*fec_it); |
187 ++it; | 190 ++it; |
188 VerifyReconstructedMediaPacket(*it, 1); | 191 VerifyReconstructedMediaPacket(*it, 1); |
189 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); | 192 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); |
190 | 193 |
191 DeletePackets(&media_packets); | 194 DeletePackets(&media_packets); |
192 } | 195 } |
193 | 196 |
194 TEST_F(ReceiverFecTest, TwoFramesOneFec) { | 197 TEST_F(ReceiverFecTest, TwoFramesOneFec) { |
195 const unsigned int kNumFecPackets = 1u; | 198 const unsigned int kNumFecPackets = 1u; |
196 std::list<RtpPacket*> media_rtp_packets; | 199 std::list<test::RawRtpPacket*> media_rtp_packets; |
197 std::list<Packet*> media_packets; | 200 std::list<Packet*> media_packets; |
198 GenerateFrame(1, 0, &media_rtp_packets, &media_packets); | 201 GenerateFrame(1, 0, &media_rtp_packets, &media_packets); |
199 GenerateFrame(1, 1, &media_rtp_packets, &media_packets); | 202 GenerateFrame(1, 1, &media_rtp_packets, &media_packets); |
200 std::list<Packet*> fec_packets; | 203 std::list<Packet*> fec_packets; |
201 GenerateFEC(&media_packets, &fec_packets, kNumFecPackets); | 204 GenerateFEC(&media_packets, &fec_packets, kNumFecPackets); |
202 | 205 |
203 // Recovery | 206 // Recovery |
204 std::list<RtpPacket*>::iterator it = media_rtp_packets.begin(); | 207 std::list<test::RawRtpPacket*>::iterator it = media_rtp_packets.begin(); |
205 BuildAndAddRedMediaPacket(media_rtp_packets.front()); | 208 BuildAndAddRedMediaPacket(media_rtp_packets.front()); |
206 VerifyReconstructedMediaPacket(*it, 1); | 209 VerifyReconstructedMediaPacket(*it, 1); |
207 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); | 210 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); |
208 // Drop one media packet. | 211 // Drop one media packet. |
209 BuildAndAddRedFecPacket(fec_packets.front()); | 212 BuildAndAddRedFecPacket(fec_packets.front()); |
210 ++it; | 213 ++it; |
211 VerifyReconstructedMediaPacket(*it, 1); | 214 VerifyReconstructedMediaPacket(*it, 1); |
212 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); | 215 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); |
213 | 216 |
214 DeletePackets(&media_packets); | 217 DeletePackets(&media_packets); |
215 } | 218 } |
216 | 219 |
217 TEST_F(ReceiverFecTest, OneCompleteOneUnrecoverableFrame) { | 220 TEST_F(ReceiverFecTest, OneCompleteOneUnrecoverableFrame) { |
218 const unsigned int kNumFecPackets = 1u; | 221 const unsigned int kNumFecPackets = 1u; |
219 std::list<RtpPacket*> media_rtp_packets; | 222 std::list<test::RawRtpPacket*> media_rtp_packets; |
220 std::list<Packet*> media_packets; | 223 std::list<Packet*> media_packets; |
221 GenerateFrame(1, 0, &media_rtp_packets, &media_packets); | 224 GenerateFrame(1, 0, &media_rtp_packets, &media_packets); |
222 GenerateFrame(2, 1, &media_rtp_packets, &media_packets); | 225 GenerateFrame(2, 1, &media_rtp_packets, &media_packets); |
223 | 226 |
224 std::list<Packet*> fec_packets; | 227 std::list<Packet*> fec_packets; |
225 GenerateFEC(&media_packets, &fec_packets, kNumFecPackets); | 228 GenerateFEC(&media_packets, &fec_packets, kNumFecPackets); |
226 | 229 |
227 // Recovery | 230 // Recovery |
228 std::list<RtpPacket*>::iterator it = media_rtp_packets.begin(); | 231 std::list<test::RawRtpPacket*>::iterator it = media_rtp_packets.begin(); |
229 BuildAndAddRedMediaPacket(*it); // First frame: one packet. | 232 BuildAndAddRedMediaPacket(*it); // First frame: one packet. |
230 VerifyReconstructedMediaPacket(*it, 1); | 233 VerifyReconstructedMediaPacket(*it, 1); |
231 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); | 234 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); |
232 ++it; | 235 ++it; |
233 BuildAndAddRedMediaPacket(*it); // First packet of second frame. | 236 BuildAndAddRedMediaPacket(*it); // First packet of second frame. |
234 VerifyReconstructedMediaPacket(*it, 1); | 237 VerifyReconstructedMediaPacket(*it, 1); |
235 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); | 238 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); |
236 | 239 |
237 DeletePackets(&media_packets); | 240 DeletePackets(&media_packets); |
238 } | 241 } |
239 | 242 |
240 TEST_F(ReceiverFecTest, MaxFramesOneFec) { | 243 TEST_F(ReceiverFecTest, MaxFramesOneFec) { |
241 const unsigned int kNumFecPackets = 1u; | 244 const unsigned int kNumFecPackets = 1u; |
242 const unsigned int kNumMediaPackets = 48u; | 245 const unsigned int kNumMediaPackets = 48u; |
243 std::list<RtpPacket*> media_rtp_packets; | 246 std::list<test::RawRtpPacket*> media_rtp_packets; |
244 std::list<Packet*> media_packets; | 247 std::list<Packet*> media_packets; |
245 for (unsigned int i = 0; i < kNumMediaPackets; ++i) { | 248 for (unsigned int i = 0; i < kNumMediaPackets; ++i) { |
246 GenerateFrame(1, i, &media_rtp_packets, &media_packets); | 249 GenerateFrame(1, i, &media_rtp_packets, &media_packets); |
247 } | 250 } |
248 std::list<Packet*> fec_packets; | 251 std::list<Packet*> fec_packets; |
249 GenerateFEC(&media_packets, &fec_packets, kNumFecPackets); | 252 GenerateFEC(&media_packets, &fec_packets, kNumFecPackets); |
250 | 253 |
251 // Recovery | 254 // Recovery |
252 std::list<RtpPacket*>::iterator it = media_rtp_packets.begin(); | 255 std::list<test::RawRtpPacket*>::iterator it = media_rtp_packets.begin(); |
253 ++it; // Drop first packet. | 256 ++it; // Drop first packet. |
254 for (; it != media_rtp_packets.end(); ++it) { | 257 for (; it != media_rtp_packets.end(); ++it) { |
255 BuildAndAddRedMediaPacket(*it); | 258 BuildAndAddRedMediaPacket(*it); |
256 VerifyReconstructedMediaPacket(*it, 1); | 259 VerifyReconstructedMediaPacket(*it, 1); |
257 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); | 260 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); |
258 } | 261 } |
259 BuildAndAddRedFecPacket(fec_packets.front()); | 262 BuildAndAddRedFecPacket(fec_packets.front()); |
260 it = media_rtp_packets.begin(); | 263 it = media_rtp_packets.begin(); |
261 VerifyReconstructedMediaPacket(*it, 1); | 264 VerifyReconstructedMediaPacket(*it, 1); |
262 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); | 265 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); |
263 | 266 |
264 DeletePackets(&media_packets); | 267 DeletePackets(&media_packets); |
265 } | 268 } |
266 | 269 |
267 TEST_F(ReceiverFecTest, TooManyFrames) { | 270 TEST_F(ReceiverFecTest, TooManyFrames) { |
268 const unsigned int kNumFecPackets = 1u; | 271 const unsigned int kNumFecPackets = 1u; |
269 const unsigned int kNumMediaPackets = 49u; | 272 const unsigned int kNumMediaPackets = 49u; |
270 std::list<RtpPacket*> media_rtp_packets; | 273 std::list<test::RawRtpPacket*> media_rtp_packets; |
271 std::list<Packet*> media_packets; | 274 std::list<Packet*> media_packets; |
272 for (unsigned int i = 0; i < kNumMediaPackets; ++i) { | 275 for (unsigned int i = 0; i < kNumMediaPackets; ++i) { |
273 GenerateFrame(1, i, &media_rtp_packets, &media_packets); | 276 GenerateFrame(1, i, &media_rtp_packets, &media_packets); |
274 } | 277 } |
275 std::list<Packet*> fec_packets; | 278 std::list<Packet*> fec_packets; |
276 EXPECT_EQ(-1, fec_->GenerateFEC(media_packets, | 279 EXPECT_EQ(-1, fec_->GenerateFEC(media_packets, |
277 kNumFecPackets * 255 / kNumMediaPackets, 0, | 280 kNumFecPackets * 255 / kNumMediaPackets, 0, |
278 false, kFecMaskBursty, &fec_packets)); | 281 false, kFecMaskBursty, &fec_packets)); |
279 | 282 |
280 DeletePackets(&media_packets); | 283 DeletePackets(&media_packets); |
281 } | 284 } |
282 | 285 |
283 TEST_F(ReceiverFecTest, PacketNotDroppedTooEarly) { | 286 TEST_F(ReceiverFecTest, PacketNotDroppedTooEarly) { |
284 // 1 frame with 2 media packets and one FEC packet. One media packet missing. | 287 // 1 frame with 2 media packets and one FEC packet. One media packet missing. |
285 // Delay the FEC packet. | 288 // Delay the FEC packet. |
286 Packet* delayed_fec = NULL; | 289 Packet* delayed_fec = NULL; |
287 const unsigned int kNumFecPacketsBatch1 = 1u; | 290 const unsigned int kNumFecPacketsBatch1 = 1u; |
288 const unsigned int kNumMediaPacketsBatch1 = 2u; | 291 const unsigned int kNumMediaPacketsBatch1 = 2u; |
289 std::list<RtpPacket*> media_rtp_packets_batch1; | 292 std::list<test::RawRtpPacket*> media_rtp_packets_batch1; |
290 std::list<Packet*> media_packets_batch1; | 293 std::list<Packet*> media_packets_batch1; |
291 GenerateFrame(kNumMediaPacketsBatch1, 0, &media_rtp_packets_batch1, | 294 GenerateFrame(kNumMediaPacketsBatch1, 0, &media_rtp_packets_batch1, |
292 &media_packets_batch1); | 295 &media_packets_batch1); |
293 std::list<Packet*> fec_packets; | 296 std::list<Packet*> fec_packets; |
294 GenerateFEC(&media_packets_batch1, &fec_packets, kNumFecPacketsBatch1); | 297 GenerateFEC(&media_packets_batch1, &fec_packets, kNumFecPacketsBatch1); |
295 | 298 |
296 BuildAndAddRedMediaPacket(media_rtp_packets_batch1.front()); | 299 BuildAndAddRedMediaPacket(media_rtp_packets_batch1.front()); |
297 EXPECT_CALL(rtp_data_callback_, OnRecoveredPacket(_, _)) | 300 EXPECT_CALL(rtp_data_callback_, OnRecoveredPacket(_, _)) |
298 .Times(1).WillRepeatedly(Return(true)); | 301 .Times(1).WillRepeatedly(Return(true)); |
299 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); | 302 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); |
300 delayed_fec = fec_packets.front(); | 303 delayed_fec = fec_packets.front(); |
301 | 304 |
302 // Fill the FEC decoder. No packets should be dropped. | 305 // Fill the FEC decoder. No packets should be dropped. |
303 const unsigned int kNumMediaPacketsBatch2 = 46u; | 306 const unsigned int kNumMediaPacketsBatch2 = 46u; |
304 std::list<RtpPacket*> media_rtp_packets_batch2; | 307 std::list<test::RawRtpPacket*> media_rtp_packets_batch2; |
305 std::list<Packet*> media_packets_batch2; | 308 std::list<Packet*> media_packets_batch2; |
306 for (unsigned int i = 0; i < kNumMediaPacketsBatch2; ++i) { | 309 for (unsigned int i = 0; i < kNumMediaPacketsBatch2; ++i) { |
307 GenerateFrame(1, i, &media_rtp_packets_batch2, &media_packets_batch2); | 310 GenerateFrame(1, i, &media_rtp_packets_batch2, &media_packets_batch2); |
308 } | 311 } |
309 for (std::list<RtpPacket*>::iterator it = media_rtp_packets_batch2.begin(); | 312 for (std::list<test::RawRtpPacket*>::iterator it = |
| 313 media_rtp_packets_batch2.begin(); |
310 it != media_rtp_packets_batch2.end(); ++it) { | 314 it != media_rtp_packets_batch2.end(); ++it) { |
311 BuildAndAddRedMediaPacket(*it); | 315 BuildAndAddRedMediaPacket(*it); |
312 EXPECT_CALL(rtp_data_callback_, OnRecoveredPacket(_, _)) | 316 EXPECT_CALL(rtp_data_callback_, OnRecoveredPacket(_, _)) |
313 .Times(1).WillRepeatedly(Return(true)); | 317 .Times(1).WillRepeatedly(Return(true)); |
314 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); | 318 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); |
315 } | 319 } |
316 | 320 |
317 // Add the delayed FEC packet. One packet should be reconstructed. | 321 // Add the delayed FEC packet. One packet should be reconstructed. |
318 BuildAndAddRedFecPacket(delayed_fec); | 322 BuildAndAddRedFecPacket(delayed_fec); |
319 EXPECT_CALL(rtp_data_callback_, OnRecoveredPacket(_, _)) | 323 EXPECT_CALL(rtp_data_callback_, OnRecoveredPacket(_, _)) |
320 .Times(1).WillRepeatedly(Return(true)); | 324 .Times(1).WillRepeatedly(Return(true)); |
321 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); | 325 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); |
322 | 326 |
323 DeletePackets(&media_packets_batch1); | 327 DeletePackets(&media_packets_batch1); |
324 DeletePackets(&media_packets_batch2); | 328 DeletePackets(&media_packets_batch2); |
325 } | 329 } |
326 | 330 |
327 TEST_F(ReceiverFecTest, PacketDroppedWhenTooOld) { | 331 TEST_F(ReceiverFecTest, PacketDroppedWhenTooOld) { |
328 // 1 frame with 2 media packets and one FEC packet. One media packet missing. | 332 // 1 frame with 2 media packets and one FEC packet. One media packet missing. |
329 // Delay the FEC packet. | 333 // Delay the FEC packet. |
330 Packet* delayed_fec = NULL; | 334 Packet* delayed_fec = NULL; |
331 const unsigned int kNumFecPacketsBatch1 = 1u; | 335 const unsigned int kNumFecPacketsBatch1 = 1u; |
332 const unsigned int kNumMediaPacketsBatch1 = 2u; | 336 const unsigned int kNumMediaPacketsBatch1 = 2u; |
333 std::list<RtpPacket*> media_rtp_packets_batch1; | 337 std::list<test::RawRtpPacket*> media_rtp_packets_batch1; |
334 std::list<Packet*> media_packets_batch1; | 338 std::list<Packet*> media_packets_batch1; |
335 GenerateFrame(kNumMediaPacketsBatch1, 0, &media_rtp_packets_batch1, | 339 GenerateFrame(kNumMediaPacketsBatch1, 0, &media_rtp_packets_batch1, |
336 &media_packets_batch1); | 340 &media_packets_batch1); |
337 std::list<Packet*> fec_packets; | 341 std::list<Packet*> fec_packets; |
338 GenerateFEC(&media_packets_batch1, &fec_packets, kNumFecPacketsBatch1); | 342 GenerateFEC(&media_packets_batch1, &fec_packets, kNumFecPacketsBatch1); |
339 | 343 |
340 BuildAndAddRedMediaPacket(media_rtp_packets_batch1.front()); | 344 BuildAndAddRedMediaPacket(media_rtp_packets_batch1.front()); |
341 EXPECT_CALL(rtp_data_callback_, OnRecoveredPacket(_, _)) | 345 EXPECT_CALL(rtp_data_callback_, OnRecoveredPacket(_, _)) |
342 .Times(1).WillRepeatedly(Return(true)); | 346 .Times(1).WillRepeatedly(Return(true)); |
343 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); | 347 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); |
344 delayed_fec = fec_packets.front(); | 348 delayed_fec = fec_packets.front(); |
345 | 349 |
346 // Fill the FEC decoder and force the last packet to be dropped. | 350 // Fill the FEC decoder and force the last packet to be dropped. |
347 const unsigned int kNumMediaPacketsBatch2 = 48u; | 351 const unsigned int kNumMediaPacketsBatch2 = 48u; |
348 std::list<RtpPacket*> media_rtp_packets_batch2; | 352 std::list<test::RawRtpPacket*> media_rtp_packets_batch2; |
349 std::list<Packet*> media_packets_batch2; | 353 std::list<Packet*> media_packets_batch2; |
350 for (unsigned int i = 0; i < kNumMediaPacketsBatch2; ++i) { | 354 for (unsigned int i = 0; i < kNumMediaPacketsBatch2; ++i) { |
351 GenerateFrame(1, i, &media_rtp_packets_batch2, &media_packets_batch2); | 355 GenerateFrame(1, i, &media_rtp_packets_batch2, &media_packets_batch2); |
352 } | 356 } |
353 for (std::list<RtpPacket*>::iterator it = media_rtp_packets_batch2.begin(); | 357 for (std::list<test::RawRtpPacket*>::iterator it = |
| 358 media_rtp_packets_batch2.begin(); |
354 it != media_rtp_packets_batch2.end(); ++it) { | 359 it != media_rtp_packets_batch2.end(); ++it) { |
355 BuildAndAddRedMediaPacket(*it); | 360 BuildAndAddRedMediaPacket(*it); |
356 EXPECT_CALL(rtp_data_callback_, OnRecoveredPacket(_, _)) | 361 EXPECT_CALL(rtp_data_callback_, OnRecoveredPacket(_, _)) |
357 .Times(1).WillRepeatedly(Return(true)); | 362 .Times(1).WillRepeatedly(Return(true)); |
358 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); | 363 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); |
359 } | 364 } |
360 | 365 |
361 // Add the delayed FEC packet. No packet should be reconstructed since the | 366 // Add the delayed FEC packet. No packet should be reconstructed since the |
362 // first media packet of that frame has been dropped due to being too old. | 367 // first media packet of that frame has been dropped due to being too old. |
363 BuildAndAddRedFecPacket(delayed_fec); | 368 BuildAndAddRedFecPacket(delayed_fec); |
364 EXPECT_CALL(rtp_data_callback_, OnRecoveredPacket(_, _)) | 369 EXPECT_CALL(rtp_data_callback_, OnRecoveredPacket(_, _)) |
365 .Times(0); | 370 .Times(0); |
366 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); | 371 EXPECT_EQ(0, receiver_fec_->ProcessReceivedFec()); |
367 | 372 |
368 DeletePackets(&media_packets_batch1); | 373 DeletePackets(&media_packets_batch1); |
369 DeletePackets(&media_packets_batch2); | 374 DeletePackets(&media_packets_batch2); |
370 } | 375 } |
371 | 376 |
372 TEST_F(ReceiverFecTest, OldFecPacketDropped) { | 377 TEST_F(ReceiverFecTest, OldFecPacketDropped) { |
373 // 49 frames with 2 media packets and one FEC packet. All media packets | 378 // 49 frames with 2 media packets and one FEC packet. All media packets |
374 // missing. | 379 // missing. |
375 const unsigned int kNumMediaPackets = 49 * 2; | 380 const unsigned int kNumMediaPackets = 49 * 2; |
376 std::list<RtpPacket*> media_rtp_packets; | 381 std::list<test::RawRtpPacket*> media_rtp_packets; |
377 std::list<Packet*> media_packets; | 382 std::list<Packet*> media_packets; |
378 for (unsigned int i = 0; i < kNumMediaPackets / 2; ++i) { | 383 for (unsigned int i = 0; i < kNumMediaPackets / 2; ++i) { |
379 std::list<RtpPacket*> frame_media_rtp_packets; | 384 std::list<test::RawRtpPacket*> frame_media_rtp_packets; |
380 std::list<Packet*> frame_media_packets; | 385 std::list<Packet*> frame_media_packets; |
381 std::list<Packet*> fec_packets; | 386 std::list<Packet*> fec_packets; |
382 GenerateFrame(2, 0, &frame_media_rtp_packets, &frame_media_packets); | 387 GenerateFrame(2, 0, &frame_media_rtp_packets, &frame_media_packets); |
383 GenerateFEC(&frame_media_packets, &fec_packets, 1); | 388 GenerateFEC(&frame_media_packets, &fec_packets, 1); |
384 for (std::list<Packet*>::iterator it = fec_packets.begin(); | 389 for (std::list<Packet*>::iterator it = fec_packets.begin(); |
385 it != fec_packets.end(); ++it) { | 390 it != fec_packets.end(); ++it) { |
386 // Only FEC packets inserted. No packets recoverable at this time. | 391 // Only FEC packets inserted. No packets recoverable at this time. |
387 BuildAndAddRedFecPacket(*it); | 392 BuildAndAddRedFecPacket(*it); |
388 EXPECT_CALL(rtp_data_callback_, OnRecoveredPacket(_, _)) | 393 EXPECT_CALL(rtp_data_callback_, OnRecoveredPacket(_, _)) |
389 .Times(0); | 394 .Times(0); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 0x27, | 533 0x27, |
529 0xc4, | 534 0xc4, |
530 0x2a, | 535 0x2a, |
531 0x21, | 536 0x21, |
532 0x2a, | 537 0x2a, |
533 0x28}; | 538 0x28}; |
534 SurvivesMaliciousPacket(kPacket, sizeof(kPacket), 100); | 539 SurvivesMaliciousPacket(kPacket, sizeof(kPacket), 100); |
535 } | 540 } |
536 | 541 |
537 } // namespace webrtc | 542 } // namespace webrtc |
OLD | NEW |