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

Side by Side Diff: media/cast/test/end2end_unittest.cc

Issue 250363002: [Cast] Clean-up RtpCastHeader and RtpParser, removing the last WebRTC dependency. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 // 4 //
5 // This test generate synthetic data. For audio it's a sinusoid waveform with 5 // This test generate synthetic data. For audio it's a sinusoid waveform with
6 // frequency kSoundFrequency and different amplitudes. For video it's a pattern 6 // frequency kSoundFrequency and different amplitudes. For video it's a pattern
7 // that is shifting by one pixel per frame, each pixels neighbors right and down 7 // that is shifting by one pixel per frame, each pixels neighbors right and down
8 // is this pixels value +1, since the pixel value is 8 bit it will wrap 8 // is this pixels value +1, since the pixel value is 8 bit it will wrap
9 // frequently within the image. Visually this will create diagonally color bands 9 // frequently within the image. Visually this will create diagonally color bands
10 // that moves across the screen 10 // that moves across the screen
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 namespace { 47 namespace {
48 48
49 static const int64 kStartMillisecond = INT64_C(1245); 49 static const int64 kStartMillisecond = INT64_C(1245);
50 static const int kAudioChannels = 2; 50 static const int kAudioChannels = 2;
51 static const double kSoundFrequency = 314.15926535897; // Freq of sine wave. 51 static const double kSoundFrequency = 314.15926535897; // Freq of sine wave.
52 static const float kSoundVolume = 0.5f; 52 static const float kSoundVolume = 0.5f;
53 static const int kVideoHdWidth = 1280; 53 static const int kVideoHdWidth = 1280;
54 static const int kVideoHdHeight = 720; 54 static const int kVideoHdHeight = 720;
55 static const int kVideoQcifWidth = 176; 55 static const int kVideoQcifWidth = 176;
56 static const int kVideoQcifHeight = 144; 56 static const int kVideoQcifHeight = 144;
57 static const int kCommonRtpHeaderLength = 12;
58 static const uint8 kCastReferenceFrameIdBitReset = 0xDF; // Mask is 0x40.
59 57
60 // Since the video encoded and decoded an error will be introduced; when 58 // Since the video encoded and decoded an error will be introduced; when
61 // comparing individual pixels the error can be quite large; we allow a PSNR of 59 // comparing individual pixels the error can be quite large; we allow a PSNR of
62 // at least |kVideoAcceptedPSNR|. 60 // at least |kVideoAcceptedPSNR|.
63 static const double kVideoAcceptedPSNR = 38.0; 61 static const double kVideoAcceptedPSNR = 38.0;
64 62
65 // The tests are commonly implemented with |kFrameTimerMs| RunTask function; 63 // The tests are commonly implemented with |kFrameTimerMs| RunTask function;
66 // a normal video is 30 fps hence the 33 ms between frames. 64 // a normal video is 30 fps hence the 33 ms between frames.
67 static const int kFrameTimerMs = 33; 65 static const int kFrameTimerMs = 33;
68 66
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 transport::PacketReceiverCallback packet_receiver_; 182 transport::PacketReceiverCallback packet_receiver_;
185 }; 183 };
186 184
187 // Class that sends the packet direct from sender into the receiver with the 185 // Class that sends the packet direct from sender into the receiver with the
188 // ability to drop packets between the two. 186 // ability to drop packets between the two.
189 class LoopBackTransport : public transport::PacketSender { 187 class LoopBackTransport : public transport::PacketSender {
190 public: 188 public:
191 explicit LoopBackTransport(scoped_refptr<CastEnvironment> cast_environment) 189 explicit LoopBackTransport(scoped_refptr<CastEnvironment> cast_environment)
192 : send_packets_(true), 190 : send_packets_(true),
193 drop_packets_belonging_to_odd_frames_(false), 191 drop_packets_belonging_to_odd_frames_(false),
194 reset_reference_frame_id_(false),
195 cast_environment_(cast_environment) {} 192 cast_environment_(cast_environment) {}
196 193
197 void SetPacketReceiver( 194 void SetPacketReceiver(
198 const transport::PacketReceiverCallback& packet_receiver) { 195 const transport::PacketReceiverCallback& packet_receiver) {
199 scoped_ptr<test::PacketPipe> loopback_pipe( 196 scoped_ptr<test::PacketPipe> loopback_pipe(
200 new LoopBackPacketPipe(packet_receiver)); 197 new LoopBackPacketPipe(packet_receiver));
201 if (packet_pipe_) { 198 if (packet_pipe_) {
202 packet_pipe_->AppendToPipe(loopback_pipe.Pass()); 199 packet_pipe_->AppendToPipe(loopback_pipe.Pass());
203 } else { 200 } else {
204 packet_pipe_ = loopback_pipe.Pass(); 201 packet_pipe_ = loopback_pipe.Pass();
205 } 202 }
206 } 203 }
207 204
208 virtual bool SendPacket(transport::PacketRef packet, 205 virtual bool SendPacket(transport::PacketRef packet,
209 const base::Closure& cb) OVERRIDE { 206 const base::Closure& cb) OVERRIDE {
210 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN)); 207 DCHECK(cast_environment_->CurrentlyOn(CastEnvironment::MAIN));
211 if (!send_packets_) 208 if (!send_packets_)
212 return false; 209 return false;
213 210
214 if (drop_packets_belonging_to_odd_frames_) { 211 if (drop_packets_belonging_to_odd_frames_) {
215 uint32 frame_id = packet->data[13]; 212 uint32 frame_id = packet->data[13];
216 if (frame_id % 2 == 1) 213 if (frame_id % 2 == 1)
217 return true; 214 return true;
218 } 215 }
219 216
220 scoped_ptr<Packet> packet_copy(new Packet(packet->data)); 217 scoped_ptr<Packet> packet_copy(new Packet(packet->data));
221 if (reset_reference_frame_id_) {
222 // Reset the is_reference bit in the cast header.
223 (*packet_copy)[kCommonRtpHeaderLength] &= kCastReferenceFrameIdBitReset;
224 }
225 packet_pipe_->Send(packet_copy.Pass()); 218 packet_pipe_->Send(packet_copy.Pass());
226 return true; 219 return true;
227 } 220 }
228 221
229 void SetSendPackets(bool send_packets) { send_packets_ = send_packets; } 222 void SetSendPackets(bool send_packets) { send_packets_ = send_packets; }
230 223
231 void DropAllPacketsBelongingToOddFrames() { 224 void DropAllPacketsBelongingToOddFrames() {
232 drop_packets_belonging_to_odd_frames_ = true; 225 drop_packets_belonging_to_odd_frames_ = true;
233 } 226 }
234 227
235 void AlwaysResetReferenceFrameId() { reset_reference_frame_id_ = true; }
236
237 void SetPacketPipe(scoped_ptr<test::PacketPipe> pipe) { 228 void SetPacketPipe(scoped_ptr<test::PacketPipe> pipe) {
238 // Append the loopback pipe to the end. 229 // Append the loopback pipe to the end.
239 pipe->AppendToPipe(packet_pipe_.Pass()); 230 pipe->AppendToPipe(packet_pipe_.Pass());
240 packet_pipe_ = pipe.Pass(); 231 packet_pipe_ = pipe.Pass();
241 } 232 }
242 233
243 private: 234 private:
244 bool send_packets_; 235 bool send_packets_;
245 bool drop_packets_belonging_to_odd_frames_; 236 bool drop_packets_belonging_to_odd_frames_;
246 bool reset_reference_frame_id_;
247 scoped_refptr<CastEnvironment> cast_environment_; 237 scoped_refptr<CastEnvironment> cast_environment_;
248 scoped_ptr<test::PacketPipe> packet_pipe_; 238 scoped_ptr<test::PacketPipe> packet_pipe_;
249 }; 239 };
250 240
251 // Class that verifies the audio frames coming out of the receiver. 241 // Class that verifies the audio frames coming out of the receiver.
252 class TestReceiverAudioCallback 242 class TestReceiverAudioCallback
253 : public base::RefCountedThreadSafe<TestReceiverAudioCallback> { 243 : public base::RefCountedThreadSafe<TestReceiverAudioCallback> {
254 public: 244 public:
255 struct ExpectedAudioFrame { 245 struct ExpectedAudioFrame {
256 scoped_ptr<AudioBus> audio_bus; 246 scoped_ptr<AudioBus> audio_bus;
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after
982 test_receiver_video_callback_)); 972 test_receiver_video_callback_));
983 } 973 }
984 RunTasks(kFrameTimerMs); 974 RunTasks(kFrameTimerMs);
985 video_start++; 975 video_start++;
986 } 976 }
987 977
988 RunTasks(2 * kFrameTimerMs + 1); // Empty the pipeline. 978 RunTasks(2 * kFrameTimerMs + 1); // Empty the pipeline.
989 EXPECT_EQ(i / 2, test_receiver_video_callback_->number_times_called()); 979 EXPECT_EQ(i / 2, test_receiver_video_callback_->number_times_called());
990 } 980 }
991 981
992 TEST_F(End2EndTest, ResetReferenceFrameId) {
miu 2014/04/23 23:41:58 I removed this test because it's not a good test:
993 Configure(transport::kVp8, transport::kOpus, kDefaultAudioSamplingRate,
994 false, 3);
995 video_sender_config_.rtp_config.max_delay_ms = 67;
996 video_receiver_config_.rtp_max_delay_ms = 67;
997 Create();
998 sender_to_receiver_.AlwaysResetReferenceFrameId();
999
1000 int frames_counter = 0;
1001 for (; frames_counter < 10; ++frames_counter) {
1002 const base::TimeTicks send_time = testing_clock_sender_->NowTicks();
1003 SendVideoFrame(frames_counter, send_time);
1004
1005 test_receiver_video_callback_->AddExpectedResult(
1006 frames_counter,
1007 video_sender_config_.width,
1008 video_sender_config_.height,
1009 send_time,
1010 true);
1011
1012 // GetRawVideoFrame will not return the frame until we are close to the
1013 // time in which we should render the frame.
1014 frame_receiver_->GetRawVideoFrame(
1015 base::Bind(&TestReceiverVideoCallback::CheckVideoFrame,
1016 test_receiver_video_callback_));
1017 RunTasks(kFrameTimerMs);
1018 }
1019 RunTasks(2 * kFrameTimerMs + 1); // Empty the pipeline.
1020 EXPECT_EQ(frames_counter,
1021 test_receiver_video_callback_->number_times_called());
1022 }
1023
1024 TEST_F(End2EndTest, CryptoVideo) { 982 TEST_F(End2EndTest, CryptoVideo) {
1025 Configure(transport::kVp8, transport::kPcm16, 32000, false, 1); 983 Configure(transport::kVp8, transport::kPcm16, 32000, false, 1);
1026 984
1027 transport_video_config_.base.aes_iv_mask = 985 transport_video_config_.base.aes_iv_mask =
1028 ConvertFromBase16String("1234567890abcdeffedcba0987654321"); 986 ConvertFromBase16String("1234567890abcdeffedcba0987654321");
1029 transport_video_config_.base.aes_key = 987 transport_video_config_.base.aes_key =
1030 ConvertFromBase16String("deadbeefcafeb0b0b0b0cafedeadbeef"); 988 ConvertFromBase16String("deadbeefcafeb0b0b0b0cafedeadbeef");
1031 989
1032 video_receiver_config_.aes_iv_mask = transport_video_config_.base.aes_iv_mask; 990 video_receiver_config_.aes_iv_mask = transport_video_config_.base.aes_iv_mask;
1033 video_receiver_config_.aes_key = transport_video_config_.base.aes_key; 991 video_receiver_config_.aes_key = transport_video_config_.base.aes_key;
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1253 event_counter_for_frame.begin(); 1211 event_counter_for_frame.begin();
1254 it != event_counter_for_frame.end(); 1212 it != event_counter_for_frame.end();
1255 ++it) { 1213 ++it) {
1256 received_count += it->second.counter[kAudioFrameReceived]; 1214 received_count += it->second.counter[kAudioFrameReceived];
1257 encoded_count += it->second.counter[kAudioFrameEncoded]; 1215 encoded_count += it->second.counter[kAudioFrameEncoded];
1258 } 1216 }
1259 1217
1260 EXPECT_EQ(num_audio_frames_requested, received_count); 1218 EXPECT_EQ(num_audio_frames_requested, received_count);
1261 EXPECT_EQ(num_audio_frames_requested, encoded_count); 1219 EXPECT_EQ(num_audio_frames_requested, encoded_count);
1262 1220
1263 std::map<RtpTimestamp, LoggingEventCounts>::iterator map_it = 1221 // Verify that each frame have the expected types of events logged.
1264 event_counter_for_frame.begin(); 1222 for (std::map<RtpTimestamp, LoggingEventCounts>::const_iterator map_it =
1223 event_counter_for_frame.begin();
1224 map_it != event_counter_for_frame.end(); ++map_it) {
1225 int total_event_count_for_frame = 0;
1226 for (int j = 0; j < kNumOfLoggingEvents; ++j)
1227 total_event_count_for_frame += map_it->second.counter[j];
1265 1228
1266 // Verify that each frame have the expected types of events logged. 1229 int expected_event_count_for_frame = 0;
miu 2014/04/23 23:41:58 imcheng: Looks like this isn't broken anymore. In
1267 // TODO(imcheng): This only checks the first frame. This doesn't work
1268 // properly for all frames because:
1269 // 1. kAudioPlayoutDelay and kAudioFrameDecoded RTP timestamps aren't
1270 // exactly aligned with those of kAudioFrameReceived and kAudioFrameEncoded.
1271 // Note that these RTP timestamps are output from webrtc::AudioCodingModule
1272 // which are different from RTP timestamps that the cast library generates
1273 // during the encode step (and which are sent to receiver). The first frame
1274 // just happen to be aligned.
1275 // 2. Currently, kAudioFrameDecoded and kAudioPlayoutDelay are logged per
1276 // audio bus.
1277 // Both 1 and 2 may change since we are currently refactoring audio_decoder.
1278 // 3. There is no guarantee that exactly one kAudioAckSent is sent per frame.
1279 int total_event_count_for_frame = 0;
1280 for (int j = 0; j < kNumOfLoggingEvents; ++j)
1281 total_event_count_for_frame += map_it->second.counter[j];
1282 1230
1283 int expected_event_count_for_frame = 0; 1231 EXPECT_EQ(1, map_it->second.counter[kAudioFrameReceived]);
1232 expected_event_count_for_frame +=
1233 map_it->second.counter[kAudioFrameReceived];
1284 1234
1285 EXPECT_EQ(1, map_it->second.counter[kAudioFrameReceived]); 1235 EXPECT_EQ(1, map_it->second.counter[kAudioFrameEncoded]);
1286 expected_event_count_for_frame += map_it->second.counter[kAudioFrameReceived]; 1236 expected_event_count_for_frame +=
1237 map_it->second.counter[kAudioFrameEncoded];
1287 1238
1288 EXPECT_EQ(1, map_it->second.counter[kAudioFrameEncoded]); 1239 EXPECT_EQ(1, map_it->second.counter[kAudioPlayoutDelay]);
1289 expected_event_count_for_frame += map_it->second.counter[kAudioFrameEncoded]; 1240 expected_event_count_for_frame +=
1241 map_it->second.counter[kAudioPlayoutDelay];
1290 1242
1291 EXPECT_EQ(1, map_it->second.counter[kAudioPlayoutDelay]); 1243 EXPECT_EQ(1, map_it->second.counter[kAudioFrameDecoded]);
1292 expected_event_count_for_frame += map_it->second.counter[kAudioPlayoutDelay]; 1244 expected_event_count_for_frame +=
1245 map_it->second.counter[kAudioFrameDecoded];
1293 1246
1294 EXPECT_EQ(1, map_it->second.counter[kAudioFrameDecoded]); 1247 EXPECT_GT(map_it->second.counter[kAudioAckSent], 0);
1295 expected_event_count_for_frame += map_it->second.counter[kAudioFrameDecoded]; 1248 expected_event_count_for_frame += map_it->second.counter[kAudioAckSent];
1296 1249
1297 EXPECT_GT(map_it->second.counter[kAudioAckSent], 0); 1250 // Verify that there were no other events logged with respect to this frame.
1298 expected_event_count_for_frame += map_it->second.counter[kAudioAckSent]; 1251 // (i.e. Total event count = expected event count)
1299 1252 EXPECT_EQ(total_event_count_for_frame, expected_event_count_for_frame);
1300 // Verify that there were no other events logged with respect to this frame. 1253 }
1301 // (i.e. Total event count = expected event count)
1302 EXPECT_EQ(total_event_count_for_frame, expected_event_count_for_frame);
1303 } 1254 }
1304 1255
1305 TEST_F(End2EndTest, BasicFakeSoftwareVideo) { 1256 TEST_F(End2EndTest, BasicFakeSoftwareVideo) {
1306 Configure(transport::kFakeSoftwareVideo, transport::kPcm16, 32000, false, 1); 1257 Configure(transport::kFakeSoftwareVideo, transport::kPcm16, 32000, false, 1);
1307 Create(); 1258 Create();
1308 1259
1309 int frames_counter = 0; 1260 int frames_counter = 0;
1310 int received_counter = 0; 1261 int received_counter = 0;
1311 for (; frames_counter < 1000; ++frames_counter) { 1262 for (; frames_counter < 1000; ++frames_counter) {
1312 SendFakeVideoFrame(testing_clock_sender_->NowTicks()); 1263 SendFakeVideoFrame(testing_clock_sender_->NowTicks());
1313 frame_receiver_->GetRawVideoFrame( 1264 frame_receiver_->GetRawVideoFrame(
1314 base::Bind(&CountVideoFrame, &received_counter)); 1265 base::Bind(&CountVideoFrame, &received_counter));
1315 RunTasks(kFrameTimerMs); 1266 RunTasks(kFrameTimerMs);
1316 } 1267 }
1317 RunTasks(2 * kFrameTimerMs + 1); // Empty the pipeline. 1268 RunTasks(2 * kFrameTimerMs + 1); // Empty the pipeline.
1318 EXPECT_EQ(1000, received_counter); 1269 EXPECT_EQ(1000, received_counter);
1319 } 1270 }
1320 1271
1321 // TODO(pwestin): Add repeatable packet loss test. 1272 // TODO(pwestin): Add repeatable packet loss test.
1322 // TODO(pwestin): Add test for misaligned send get calls. 1273 // TODO(pwestin): Add test for misaligned send get calls.
1323 // TODO(pwestin): Add more tests that does not resample. 1274 // TODO(pwestin): Add more tests that does not resample.
1324 // TODO(pwestin): Add test when we have starvation for our RunTask. 1275 // TODO(pwestin): Add test when we have starvation for our RunTask.
1325 1276
1326 } // namespace cast 1277 } // namespace cast
1327 } // namespace media 1278 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698