| OLD | NEW |
| 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 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 namespace media { | 38 namespace media { |
| 39 namespace cast { | 39 namespace cast { |
| 40 | 40 |
| 41 namespace { | 41 namespace { |
| 42 | 42 |
| 43 static const int64 kStartMillisecond = GG_INT64_C(1245); | 43 static const int64 kStartMillisecond = GG_INT64_C(1245); |
| 44 static const int kAudioChannels = 2; | 44 static const int kAudioChannels = 2; |
| 45 static const double kSoundFrequency = 314.15926535897; // Freq of sine wave. | 45 static const double kSoundFrequency = 314.15926535897; // Freq of sine wave. |
| 46 static const float kSoundVolume = 0.5f; | 46 static const float kSoundVolume = 0.5f; |
| 47 static const int kVideoWidth = 1280; | 47 static const int kVideoHdWidth = 1280; |
| 48 static const int kVideoHeight = 720; | 48 static const int kVideoHdHeight = 720; |
| 49 static const int kVideoQcifWidth = 176; |
| 50 static const int kVideoQcifHeight = 144; |
| 49 static const int kCommonRtpHeaderLength = 12; | 51 static const int kCommonRtpHeaderLength = 12; |
| 50 static const uint8 kCastReferenceFrameIdBitReset = 0xDF; // Mask is 0x40. | 52 static const uint8 kCastReferenceFrameIdBitReset = 0xDF; // Mask is 0x40. |
| 51 | 53 |
| 52 // Since the video encoded and decoded an error will be introduced; when | 54 // Since the video encoded and decoded an error will be introduced; when |
| 53 // comparing individual pixels the error can be quite large; we allow a PSNR of | 55 // comparing individual pixels the error can be quite large; we allow a PSNR of |
| 54 // at least |kVideoAcceptedPSNR|. | 56 // at least |kVideoAcceptedPSNR|. |
| 55 static const double kVideoAcceptedPSNR = 38.0; | 57 static const double kVideoAcceptedPSNR = 38.0; |
| 56 | 58 |
| 57 // The tests are commonly implemented with |kFrameTimerMs| RunTask function; | 59 // The tests are commonly implemented with |kFrameTimerMs| RunTask function; |
| 58 // a normal video is 30 fps hence the 33 ms between frames. | 60 // a normal video is 30 fps hence the 33 ms between frames. |
| 59 static const int kFrameTimerMs = 33; | 61 static const int kFrameTimerMs = 33; |
| 60 | 62 |
| 61 // The packets pass through the pacer which can delay the beginning of the | 63 // The packets pass through the pacer which can delay the beginning of the |
| 62 // frame by 10 ms if there is packets belonging to the previous frame being | 64 // frame by 10 ms if there is packets belonging to the previous frame being |
| 63 // retransmitted. | 65 // retransmitted. |
| 64 static const int kTimerErrorMs = 15; | 66 // In addition, audio packets are sent in 10mS intervals in audio_encoder.cc, |
| 67 // although we send an audio frame every 33mS, which adds an extra delay. |
| 68 // A TODO was added in the code to resolve this. |
| 69 static const int kTimerErrorMs = 20; |
| 70 |
| 71 // Start the video synthetic start value to medium range value, to avoid edge |
| 72 // effects cause by encoding and quantization. |
| 73 static const int kVideoStart = 100; |
| 65 | 74 |
| 66 std::string ConvertFromBase16String(const std::string base_16) { | 75 std::string ConvertFromBase16String(const std::string base_16) { |
| 67 std::string compressed; | 76 std::string compressed; |
| 68 DCHECK_EQ(base_16.size() % 2, 0u) << "Must be a multiple of 2"; | 77 DCHECK_EQ(base_16.size() % 2, 0u) << "Must be a multiple of 2"; |
| 69 compressed.reserve(base_16.size() / 2); | 78 compressed.reserve(base_16.size() / 2); |
| 70 | 79 |
| 71 std::vector<uint8> v; | 80 std::vector<uint8> v; |
| 72 if (!base::HexStringToBytes(base_16, &v)) { | 81 if (!base::HexStringToBytes(base_16, &v)) { |
| 73 NOTREACHED(); | 82 NOTREACHED(); |
| 74 } | 83 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 88 typedef struct { | 97 typedef struct { |
| 89 int counter[kNumOfLoggingEvents]; | 98 int counter[kNumOfLoggingEvents]; |
| 90 } LoggingEventCounts; | 99 } LoggingEventCounts; |
| 91 | 100 |
| 92 // Constructs a map from each frame (RTP timestamp) to counts of each event | 101 // Constructs a map from each frame (RTP timestamp) to counts of each event |
| 93 // type logged for that frame. | 102 // type logged for that frame. |
| 94 std::map<RtpTimestamp, LoggingEventCounts> GetEventCountForFrameEvents( | 103 std::map<RtpTimestamp, LoggingEventCounts> GetEventCountForFrameEvents( |
| 95 const std::vector<FrameEvent>& frame_events) { | 104 const std::vector<FrameEvent>& frame_events) { |
| 96 std::map<RtpTimestamp, LoggingEventCounts> event_counter_for_frame; | 105 std::map<RtpTimestamp, LoggingEventCounts> event_counter_for_frame; |
| 97 for (std::vector<FrameEvent>::const_iterator it = frame_events.begin(); | 106 for (std::vector<FrameEvent>::const_iterator it = frame_events.begin(); |
| 98 it != frame_events.end(); ++it) { | 107 it != frame_events.end(); |
| 108 ++it) { |
| 99 std::map<RtpTimestamp, LoggingEventCounts>::iterator map_it = | 109 std::map<RtpTimestamp, LoggingEventCounts>::iterator map_it = |
| 100 event_counter_for_frame.find(it->rtp_timestamp); | 110 event_counter_for_frame.find(it->rtp_timestamp); |
| 101 if (map_it == event_counter_for_frame.end()) { | 111 if (map_it == event_counter_for_frame.end()) { |
| 102 LoggingEventCounts new_counter; | 112 LoggingEventCounts new_counter; |
| 103 memset(&new_counter, 0, sizeof(new_counter)); | 113 memset(&new_counter, 0, sizeof(new_counter)); |
| 104 ++(new_counter.counter[it->type]); | 114 ++(new_counter.counter[it->type]); |
| 105 event_counter_for_frame.insert( | 115 event_counter_for_frame.insert( |
| 106 std::make_pair(it->rtp_timestamp, new_counter)); | 116 std::make_pair(it->rtp_timestamp, new_counter)); |
| 107 } else { | 117 } else { |
| 108 ++(map_it->second.counter[it->type]); | 118 ++(map_it->second.counter[it->type]); |
| 109 } | 119 } |
| 110 } | 120 } |
| 111 return event_counter_for_frame; | 121 return event_counter_for_frame; |
| 112 } | 122 } |
| 113 | 123 |
| 114 // Constructs a map from each packet (Packet ID) to counts of each event | 124 // Constructs a map from each packet (Packet ID) to counts of each event |
| 115 // type logged for that packet. | 125 // type logged for that packet. |
| 116 std::map<uint16, LoggingEventCounts> GetEventCountForPacketEvents( | 126 std::map<uint16, LoggingEventCounts> GetEventCountForPacketEvents( |
| 117 const std::vector<PacketEvent>& packet_events) { | 127 const std::vector<PacketEvent>& packet_events) { |
| 118 std::map<uint16, LoggingEventCounts> event_counter_for_packet; | 128 std::map<uint16, LoggingEventCounts> event_counter_for_packet; |
| 119 for (std::vector<PacketEvent>::const_iterator it = packet_events.begin(); | 129 for (std::vector<PacketEvent>::const_iterator it = packet_events.begin(); |
| 120 it != packet_events.end(); ++it) { | 130 it != packet_events.end(); |
| 131 ++it) { |
| 121 std::map<uint16, LoggingEventCounts>::iterator map_it = | 132 std::map<uint16, LoggingEventCounts>::iterator map_it = |
| 122 event_counter_for_packet.find(it->packet_id); | 133 event_counter_for_packet.find(it->packet_id); |
| 123 if (map_it == event_counter_for_packet.end()) { | 134 if (map_it == event_counter_for_packet.end()) { |
| 124 LoggingEventCounts new_counter; | 135 LoggingEventCounts new_counter; |
| 125 memset(&new_counter, 0, sizeof(new_counter)); | 136 memset(&new_counter, 0, sizeof(new_counter)); |
| 126 ++(new_counter.counter[it->type]); | 137 ++(new_counter.counter[it->type]); |
| 127 event_counter_for_packet.insert( | 138 event_counter_for_packet.insert( |
| 128 std::make_pair(it->packet_id, new_counter)); | 139 std::make_pair(it->packet_id, new_counter)); |
| 129 } else { | 140 } else { |
| 130 ++(map_it->second.counter[it->type]); | 141 ++(map_it->second.counter[it->type]); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 const base::TimeTicks& playout_time) { | 257 const base::TimeTicks& playout_time) { |
| 247 ++num_called_; | 258 ++num_called_; |
| 248 | 259 |
| 249 CheckBasicAudioFrame(audio_frame, playout_time); | 260 CheckBasicAudioFrame(audio_frame, playout_time); |
| 250 ExpectedAudioFrame expected_audio_frame = expected_frame_.front(); | 261 ExpectedAudioFrame expected_audio_frame = expected_frame_.front(); |
| 251 expected_frame_.pop_front(); | 262 expected_frame_.pop_front(); |
| 252 if (audio_frame->samples.size() == 0) | 263 if (audio_frame->samples.size() == 0) |
| 253 return; // No more checks needed. | 264 return; // No more checks needed. |
| 254 | 265 |
| 255 EXPECT_NEAR(CountZeroCrossings(expected_audio_frame.audio_frame.samples), | 266 EXPECT_NEAR(CountZeroCrossings(expected_audio_frame.audio_frame.samples), |
| 256 CountZeroCrossings(audio_frame->samples), 1); | 267 CountZeroCrossings(audio_frame->samples), |
| 268 1); |
| 257 } | 269 } |
| 258 | 270 |
| 259 void CheckCodedPcmAudioFrame( | 271 void CheckCodedPcmAudioFrame( |
| 260 scoped_ptr<transport::EncodedAudioFrame> audio_frame, | 272 scoped_ptr<transport::EncodedAudioFrame> audio_frame, |
| 261 const base::TimeTicks& playout_time) { | 273 const base::TimeTicks& playout_time) { |
| 262 ++num_called_; | 274 ++num_called_; |
| 263 | 275 |
| 264 EXPECT_FALSE(expected_frame_.empty()); // Test for bug in test code. | 276 EXPECT_FALSE(expected_frame_.empty()); // Test for bug in test code. |
| 265 ExpectedAudioFrame expected_audio_frame = expected_frame_.front(); | 277 ExpectedAudioFrame expected_audio_frame = expected_frame_.front(); |
| 266 expected_frame_.pop_front(); | 278 expected_frame_.pop_front(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 284 size_t number_of_samples = audio_frame->data.size() / 2; | 296 size_t number_of_samples = audio_frame->data.size() / 2; |
| 285 | 297 |
| 286 for (size_t i = 0; i < number_of_samples; ++i) { | 298 for (size_t i = 0; i < number_of_samples; ++i) { |
| 287 uint16 sample = | 299 uint16 sample = |
| 288 static_cast<uint8>(audio_frame->data[1 + i * sizeof(uint16)]) + | 300 static_cast<uint8>(audio_frame->data[1 + i * sizeof(uint16)]) + |
| 289 (static_cast<uint16>(audio_frame->data[i * sizeof(uint16)]) << 8); | 301 (static_cast<uint16>(audio_frame->data[i * sizeof(uint16)]) << 8); |
| 290 output_audio_samples.push_back(static_cast<int16>(sample)); | 302 output_audio_samples.push_back(static_cast<int16>(sample)); |
| 291 } | 303 } |
| 292 | 304 |
| 293 EXPECT_NEAR(CountZeroCrossings(expected_audio_frame.audio_frame.samples), | 305 EXPECT_NEAR(CountZeroCrossings(expected_audio_frame.audio_frame.samples), |
| 294 CountZeroCrossings(output_audio_samples), 1); | 306 CountZeroCrossings(output_audio_samples), |
| 307 1); |
| 295 } | 308 } |
| 296 | 309 |
| 297 int number_times_called() const { return num_called_; } | 310 int number_times_called() const { return num_called_; } |
| 298 | 311 |
| 299 protected: | 312 protected: |
| 300 virtual ~TestReceiverAudioCallback() {} | 313 virtual ~TestReceiverAudioCallback() {} |
| 301 | 314 |
| 302 private: | 315 private: |
| 303 friend class base::RefCountedThreadSafe<TestReceiverAudioCallback>; | 316 friend class base::RefCountedThreadSafe<TestReceiverAudioCallback>; |
| 304 | 317 |
| 305 int num_called_; | 318 int num_called_; |
| 306 int expected_sampling_frequency_; | 319 int expected_sampling_frequency_; |
| 307 std::list<ExpectedAudioFrame> expected_frame_; | 320 std::list<ExpectedAudioFrame> expected_frame_; |
| 308 }; | 321 }; |
| 309 | 322 |
| 310 // Class that verifies the video frames coming out of the receiver. | 323 // Class that verifies the video frames coming out of the receiver. |
| 311 class TestReceiverVideoCallback | 324 class TestReceiverVideoCallback |
| 312 : public base::RefCountedThreadSafe<TestReceiverVideoCallback> { | 325 : public base::RefCountedThreadSafe<TestReceiverVideoCallback> { |
| 313 public: | 326 public: |
| 314 struct ExpectedVideoFrame { | 327 struct ExpectedVideoFrame { |
| 315 int start_value; | 328 int start_value; |
| 316 int width; | 329 int width; |
| 317 int height; | 330 int height; |
| 318 base::TimeTicks capture_time; | 331 base::TimeTicks capture_time; |
| 319 }; | 332 }; |
| 320 | 333 |
| 321 TestReceiverVideoCallback() : num_called_(0) {} | 334 TestReceiverVideoCallback() : num_called_(0) {} |
| 322 | 335 |
| 323 void AddExpectedResult(int start_value, int width, int height, | 336 void AddExpectedResult(int start_value, |
| 337 int width, |
| 338 int height, |
| 324 const base::TimeTicks& capture_time) { | 339 const base::TimeTicks& capture_time) { |
| 325 ExpectedVideoFrame expected_video_frame; | 340 ExpectedVideoFrame expected_video_frame; |
| 326 expected_video_frame.start_value = start_value; | 341 expected_video_frame.start_value = start_value; |
| 327 expected_video_frame.capture_time = capture_time; | 342 expected_video_frame.capture_time = capture_time; |
| 328 expected_video_frame.width = width; | 343 expected_video_frame.width = width; |
| 329 expected_video_frame.height = height; | 344 expected_video_frame.height = height; |
| 330 expected_frame_.push_back(expected_video_frame); | 345 expected_frame_.push_back(expected_video_frame); |
| 331 } | 346 } |
| 332 | 347 |
| 333 void CheckVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame, | 348 void CheckVideoFrame(const scoped_refptr<media::VideoFrame>& video_frame, |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 }; | 387 }; |
| 373 | 388 |
| 374 // The actual test class, generate synthetic data for both audio and video and | 389 // The actual test class, generate synthetic data for both audio and video and |
| 375 // send those through the sender and receiver and analyzes the result. | 390 // send those through the sender and receiver and analyzes the result. |
| 376 class End2EndTest : public ::testing::Test { | 391 class End2EndTest : public ::testing::Test { |
| 377 protected: | 392 protected: |
| 378 End2EndTest() | 393 End2EndTest() |
| 379 : start_time_(), | 394 : start_time_(), |
| 380 testing_clock_(new base::SimpleTestTickClock()), | 395 testing_clock_(new base::SimpleTestTickClock()), |
| 381 task_runner_(new test::FakeSingleThreadTaskRunner(testing_clock_)), | 396 task_runner_(new test::FakeSingleThreadTaskRunner(testing_clock_)), |
| 382 transport_task_runner_( | |
| 383 new test::FakeSingleThreadTaskRunner(testing_clock_)), | |
| 384 cast_environment_(new CastEnvironment( | 397 cast_environment_(new CastEnvironment( |
| 385 scoped_ptr<base::TickClock>(testing_clock_).Pass(), | 398 scoped_ptr<base::TickClock>(testing_clock_).Pass(), |
| 386 task_runner_, | 399 task_runner_, |
| 387 task_runner_, | 400 task_runner_, |
| 388 task_runner_, | 401 task_runner_, |
| 389 task_runner_, | 402 task_runner_, |
| 390 task_runner_, | 403 task_runner_, |
| 391 task_runner_, | 404 task_runner_, |
| 392 GetLoggingConfigWithRawEventsAndStatsEnabled())), | 405 GetLoggingConfigWithRawEventsAndStatsEnabled())), |
| 393 receiver_to_sender_(cast_environment_), | 406 receiver_to_sender_(cast_environment_), |
| (...skipping 30 matching lines...) Expand all Loading... |
| 424 audio_receiver_config_.channels = kAudioChannels; | 437 audio_receiver_config_.channels = kAudioChannels; |
| 425 audio_receiver_config_.codec = audio_sender_config_.codec; | 438 audio_receiver_config_.codec = audio_sender_config_.codec; |
| 426 | 439 |
| 427 test_receiver_audio_callback_->SetExpectedSamplingFrequency( | 440 test_receiver_audio_callback_->SetExpectedSamplingFrequency( |
| 428 audio_receiver_config_.frequency); | 441 audio_receiver_config_.frequency); |
| 429 | 442 |
| 430 video_sender_config_.sender_ssrc = 3; | 443 video_sender_config_.sender_ssrc = 3; |
| 431 video_sender_config_.incoming_feedback_ssrc = 4; | 444 video_sender_config_.incoming_feedback_ssrc = 4; |
| 432 video_sender_config_.rtp_config.payload_type = 97; | 445 video_sender_config_.rtp_config.payload_type = 97; |
| 433 video_sender_config_.use_external_encoder = false; | 446 video_sender_config_.use_external_encoder = false; |
| 434 video_sender_config_.width = kVideoWidth; | 447 video_sender_config_.width = kVideoHdWidth; |
| 435 video_sender_config_.height = kVideoHeight; | 448 video_sender_config_.height = kVideoHdHeight; |
| 436 video_sender_config_.max_bitrate = 5000000; | 449 video_sender_config_.max_bitrate = 5000000; |
| 437 video_sender_config_.min_bitrate = 1000000; | 450 video_sender_config_.min_bitrate = 1000000; |
| 438 video_sender_config_.start_bitrate = 5000000; | 451 video_sender_config_.start_bitrate = 5000000; |
| 439 video_sender_config_.max_qp = 30; | 452 video_sender_config_.max_qp = 30; |
| 440 video_sender_config_.min_qp = 4; | 453 video_sender_config_.min_qp = 4; |
| 441 video_sender_config_.max_frame_rate = 30; | 454 video_sender_config_.max_frame_rate = 30; |
| 442 video_sender_config_.max_number_of_video_buffers_used = | 455 video_sender_config_.max_number_of_video_buffers_used = |
| 443 max_number_of_video_buffers_used; | 456 max_number_of_video_buffers_used; |
| 444 video_sender_config_.codec = transport::kVp8; | 457 video_sender_config_.codec = transport::kVp8; |
| 445 video_sender_config_.number_of_cores = 1; | 458 video_sender_config_.number_of_cores = 1; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 465 void Create() { | 478 void Create() { |
| 466 cast_receiver_.reset( | 479 cast_receiver_.reset( |
| 467 CastReceiver::CreateCastReceiver(cast_environment_, | 480 CastReceiver::CreateCastReceiver(cast_environment_, |
| 468 audio_receiver_config_, | 481 audio_receiver_config_, |
| 469 video_receiver_config_, | 482 video_receiver_config_, |
| 470 &receiver_to_sender_)); | 483 &receiver_to_sender_)); |
| 471 transport_sender_.reset(new transport::CastTransportSenderImpl( | 484 transport_sender_.reset(new transport::CastTransportSenderImpl( |
| 472 testing_clock_, | 485 testing_clock_, |
| 473 transport_config_, | 486 transport_config_, |
| 474 base::Bind(&UpdateCastTransportStatus), | 487 base::Bind(&UpdateCastTransportStatus), |
| 475 transport_task_runner_, | 488 task_runner_, |
| 476 &sender_to_receiver_)); | 489 &sender_to_receiver_)); |
| 477 | 490 |
| 478 cast_sender_.reset(CastSender::CreateCastSender( | 491 cast_sender_.reset(CastSender::CreateCastSender( |
| 479 cast_environment_, | 492 cast_environment_, |
| 480 &audio_sender_config_, | 493 &audio_sender_config_, |
| 481 &video_sender_config_, | 494 &video_sender_config_, |
| 482 NULL, | 495 NULL, |
| 483 base::Bind(&End2EndTest::InitializationResult, base::Unretained(this)), | 496 base::Bind(&End2EndTest::InitializationResult, base::Unretained(this)), |
| 484 transport_sender_.get())); | 497 transport_sender_.get())); |
| 485 | 498 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 502 | 515 |
| 503 virtual void TearDown() OVERRIDE { | 516 virtual void TearDown() OVERRIDE { |
| 504 | 517 |
| 505 cast_sender_.reset(); | 518 cast_sender_.reset(); |
| 506 cast_receiver_.reset(); | 519 cast_receiver_.reset(); |
| 507 task_runner_->RunTasks(); | 520 task_runner_->RunTasks(); |
| 508 } | 521 } |
| 509 | 522 |
| 510 void SendVideoFrame(int start_value, const base::TimeTicks& capture_time) { | 523 void SendVideoFrame(int start_value, const base::TimeTicks& capture_time) { |
| 511 if (start_time_.is_null()) | 524 if (start_time_.is_null()) |
| 512 start_time_ = testing_clock_->NowTicks(); | 525 start_time_ = capture_time; |
| 513 start_time_ = testing_clock_->NowTicks(); | 526 base::TimeDelta time_diff = capture_time - start_time_; |
| 514 base::TimeDelta time_diff = testing_clock_->NowTicks() - start_time_; | 527 gfx::Size size(video_sender_config_.width, video_sender_config_.height); |
| 515 gfx::Size size(kVideoWidth, kVideoHeight); | |
| 516 EXPECT_TRUE(VideoFrame::IsValidConfig( | 528 EXPECT_TRUE(VideoFrame::IsValidConfig( |
| 517 VideoFrame::I420, size, gfx::Rect(size), size)); | 529 VideoFrame::I420, size, gfx::Rect(size), size)); |
| 518 scoped_refptr<media::VideoFrame> video_frame = | 530 scoped_refptr<media::VideoFrame> video_frame = |
| 519 media::VideoFrame::CreateFrame( | 531 media::VideoFrame::CreateFrame( |
| 520 VideoFrame::I420, size, gfx::Rect(size), size, time_diff); | 532 VideoFrame::I420, size, gfx::Rect(size), size, time_diff); |
| 521 PopulateVideoFrame(video_frame, start_value); | 533 PopulateVideoFrame(video_frame, start_value); |
| 522 frame_input_->InsertRawVideoFrame(video_frame, capture_time); | 534 frame_input_->InsertRawVideoFrame(video_frame, capture_time); |
| 523 } | 535 } |
| 524 | 536 |
| 525 void RunTasks(int during_ms) { | 537 void RunTasks(int during_ms) { |
| 526 for (int i = 0; i < during_ms; ++i) { | 538 for (int i = 0; i < during_ms; ++i) { |
| 527 // Call process the timers every 1 ms. | 539 // Call process the timers every 1 ms. |
| 528 testing_clock_->Advance(base::TimeDelta::FromMilliseconds(1)); | 540 testing_clock_->Advance(base::TimeDelta::FromMilliseconds(1)); |
| 529 task_runner_->RunTasks(); | 541 task_runner_->RunTasks(); |
| 530 transport_task_runner_->RunTasks(); | |
| 531 } | 542 } |
| 532 } | 543 } |
| 533 | 544 |
| 534 void InitializationResult(CastInitializationStatus result) { | 545 void InitializationResult(CastInitializationStatus result) { |
| 535 EXPECT_EQ(result, STATUS_INITIALIZED); | 546 EXPECT_EQ(result, STATUS_INITIALIZED); |
| 536 } | 547 } |
| 537 | 548 |
| 538 AudioReceiverConfig audio_receiver_config_; | 549 AudioReceiverConfig audio_receiver_config_; |
| 539 VideoReceiverConfig video_receiver_config_; | 550 VideoReceiverConfig video_receiver_config_; |
| 540 AudioSenderConfig audio_sender_config_; | 551 AudioSenderConfig audio_sender_config_; |
| 541 VideoSenderConfig video_sender_config_; | 552 VideoSenderConfig video_sender_config_; |
| 542 transport::CastTransportConfig transport_config_; | 553 transport::CastTransportConfig transport_config_; |
| 543 | 554 |
| 544 base::TimeTicks start_time_; | 555 base::TimeTicks start_time_; |
| 545 base::SimpleTestTickClock* testing_clock_; // Owned by CastEnvironment. | 556 base::SimpleTestTickClock* testing_clock_; |
| 546 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; | 557 scoped_refptr<test::FakeSingleThreadTaskRunner> task_runner_; |
| 547 scoped_refptr<test::FakeSingleThreadTaskRunner> transport_task_runner_; | |
| 548 scoped_refptr<CastEnvironment> cast_environment_; | 558 scoped_refptr<CastEnvironment> cast_environment_; |
| 549 | 559 |
| 550 LoopBackTransport receiver_to_sender_; | 560 LoopBackTransport receiver_to_sender_; |
| 551 LoopBackTransport sender_to_receiver_; | 561 LoopBackTransport sender_to_receiver_; |
| 552 scoped_ptr<transport::CastTransportSenderImpl> transport_sender_; | 562 scoped_ptr<transport::CastTransportSenderImpl> transport_sender_; |
| 553 | 563 |
| 554 scoped_ptr<CastReceiver> cast_receiver_; | 564 scoped_ptr<CastReceiver> cast_receiver_; |
| 555 scoped_ptr<CastSender> cast_sender_; | 565 scoped_ptr<CastSender> cast_sender_; |
| 556 scoped_refptr<FrameInput> frame_input_; | 566 scoped_refptr<FrameInput> frame_input_; |
| 557 scoped_refptr<FrameReceiver> frame_receiver_; | 567 scoped_refptr<FrameReceiver> frame_receiver_; |
| 558 | 568 |
| 559 scoped_refptr<TestReceiverAudioCallback> test_receiver_audio_callback_; | 569 scoped_refptr<TestReceiverAudioCallback> test_receiver_audio_callback_; |
| 560 scoped_refptr<TestReceiverVideoCallback> test_receiver_video_callback_; | 570 scoped_refptr<TestReceiverVideoCallback> test_receiver_video_callback_; |
| 561 | 571 |
| 562 scoped_ptr<TestAudioBusFactory> audio_bus_factory_; | 572 scoped_ptr<TestAudioBusFactory> audio_bus_factory_; |
| 563 | 573 |
| 564 SimpleEventSubscriber event_subscriber_; | 574 SimpleEventSubscriber event_subscriber_; |
| 565 std::vector<FrameEvent> frame_events_; | 575 std::vector<FrameEvent> frame_events_; |
| 566 std::vector<PacketEvent> packet_events_; | 576 std::vector<PacketEvent> packet_events_; |
| 567 std::vector<GenericEvent> generic_events_; | 577 std::vector<GenericEvent> generic_events_; |
| 568 }; | 578 }; |
| 569 | 579 |
| 570 // Audio and video test without packet loss using raw PCM 16 audio "codec"; | 580 #if defined(OS_WIN) |
| 571 // This test is too slow. Disabled for now: crbug.com/329333. | 581 #define MAYBE_LoopNoLossPcm16 DISABLED_LoopNoLossPcm16 |
| 572 TEST_F(End2EndTest, DISABLED_LoopNoLossPcm16) { | 582 #else |
| 583 #define MAYBE_LoopNoLossPcm16 LoopNoLossPcm16 |
| 584 #endif |
| 585 // TODO(mikhal): Crashes in win bots (http://crbug.com/329563) |
| 586 TEST_F(End2EndTest, MAYBE_LoopNoLossPcm16) { |
| 573 SetupConfig(transport::kPcm16, 32000, false, 1); | 587 SetupConfig(transport::kPcm16, 32000, false, 1); |
| 588 // Reduce video resolution to allow processing multiple frames within a |
| 589 // reasonable time frame. |
| 590 video_sender_config_.width = kVideoQcifWidth; |
| 591 video_sender_config_.height = kVideoQcifHeight; |
| 574 Create(); | 592 Create(); |
| 575 | 593 |
| 576 int video_start = 1; | 594 int video_start = kVideoStart; |
| 577 int audio_diff = kFrameTimerMs; | 595 int audio_diff = kFrameTimerMs; |
| 578 int i = 0; | 596 int i = 0; |
| 579 | 597 |
| 580 for (; i < 10; ++i) { | 598 for (; i < 300; ++i) { |
| 581 int num_10ms_blocks = audio_diff / 10; | 599 int num_10ms_blocks = audio_diff / 10; |
| 582 audio_diff -= num_10ms_blocks * 10; | 600 audio_diff -= num_10ms_blocks * 10; |
| 583 base::TimeTicks send_time = testing_clock_->NowTicks(); | |
| 584 | |
| 585 test_receiver_video_callback_->AddExpectedResult( | |
| 586 video_start, | |
| 587 video_sender_config_.width, | |
| 588 video_sender_config_.height, | |
| 589 send_time); | |
| 590 | 601 |
| 591 scoped_ptr<AudioBus> audio_bus(audio_bus_factory_->NextAudioBus( | 602 scoped_ptr<AudioBus> audio_bus(audio_bus_factory_->NextAudioBus( |
| 592 base::TimeDelta::FromMilliseconds(10) * num_10ms_blocks)); | 603 base::TimeDelta::FromMilliseconds(10) * num_10ms_blocks)); |
| 593 | 604 |
| 605 base::TimeTicks send_time = testing_clock_->NowTicks(); |
| 594 if (i != 0) { | 606 if (i != 0) { |
| 595 // Due to the re-sampler and NetEq in the webrtc AudioCodingModule the | 607 // Due to the re-sampler and NetEq in the webrtc AudioCodingModule the |
| 596 // first samples will be 0 and then slowly ramp up to its real amplitude; | 608 // first samples will be 0 and then slowly ramp up to its real |
| 609 // amplitude; |
| 597 // ignore the first frame. | 610 // ignore the first frame. |
| 598 test_receiver_audio_callback_->AddExpectedResult( | 611 test_receiver_audio_callback_->AddExpectedResult( |
| 599 ToPcmAudioFrame(*audio_bus, audio_sender_config_.frequency), | 612 ToPcmAudioFrame(*audio_bus, audio_sender_config_.frequency), |
| 600 num_10ms_blocks, | 613 num_10ms_blocks, |
| 601 send_time); | 614 send_time); |
| 602 } | 615 } |
| 603 | 616 |
| 604 AudioBus* const audio_bus_ptr = audio_bus.get(); | 617 AudioBus* const audio_bus_ptr = audio_bus.get(); |
| 605 frame_input_->InsertAudio( | 618 frame_input_->InsertAudio( |
| 606 audio_bus_ptr, | 619 audio_bus_ptr, |
| 607 send_time, | 620 send_time, |
| 608 base::Bind(&OwnThatAudioBus, base::Passed(&audio_bus))); | 621 base::Bind(&OwnThatAudioBus, base::Passed(&audio_bus))); |
| 609 | 622 |
| 623 test_receiver_video_callback_->AddExpectedResult( |
| 624 video_start, |
| 625 video_sender_config_.width, |
| 626 video_sender_config_.height, |
| 627 send_time); |
| 610 SendVideoFrame(video_start, send_time); | 628 SendVideoFrame(video_start, send_time); |
| 611 | 629 |
| 612 RunTasks(kFrameTimerMs); | |
| 613 audio_diff += kFrameTimerMs; | |
| 614 | |
| 615 if (i == 0) { | 630 if (i == 0) { |
| 616 frame_receiver_->GetRawAudioFrame( | 631 frame_receiver_->GetRawAudioFrame( |
| 617 num_10ms_blocks, | 632 num_10ms_blocks, |
| 618 audio_sender_config_.frequency, | 633 audio_sender_config_.frequency, |
| 619 base::Bind(&TestReceiverAudioCallback::IgnoreAudioFrame, | 634 base::Bind(&TestReceiverAudioCallback::IgnoreAudioFrame, |
| 620 test_receiver_audio_callback_)); | 635 test_receiver_audio_callback_)); |
| 621 } else { | 636 } else { |
| 622 frame_receiver_->GetRawAudioFrame( | 637 frame_receiver_->GetRawAudioFrame( |
| 623 num_10ms_blocks, | 638 num_10ms_blocks, |
| 624 audio_sender_config_.frequency, | 639 audio_sender_config_.frequency, |
| 625 base::Bind(&TestReceiverAudioCallback::CheckPcmAudioFrame, | 640 base::Bind(&TestReceiverAudioCallback::CheckPcmAudioFrame, |
| 626 test_receiver_audio_callback_)); | 641 test_receiver_audio_callback_)); |
| 627 } | 642 } |
| 628 | 643 |
| 629 frame_receiver_->GetRawVideoFrame( | 644 frame_receiver_->GetRawVideoFrame( |
| 630 base::Bind(&TestReceiverVideoCallback::CheckVideoFrame, | 645 base::Bind(&TestReceiverVideoCallback::CheckVideoFrame, |
| 631 test_receiver_video_callback_)); | 646 test_receiver_video_callback_)); |
| 632 | 647 |
| 648 RunTasks(kFrameTimerMs); |
| 649 audio_diff += kFrameTimerMs; |
| 633 video_start++; | 650 video_start++; |
| 634 } | 651 } |
| 635 | 652 |
| 636 RunTasks(2 * kFrameTimerMs + 1); // Empty the receiver pipeline. | 653 RunTasks(2 * kFrameTimerMs + 1); // Empty the receiver pipeline. |
| 637 EXPECT_EQ(i - 1, test_receiver_audio_callback_->number_times_called()); | 654 EXPECT_EQ(i - 1, test_receiver_audio_callback_->number_times_called()); |
| 638 EXPECT_EQ(i, test_receiver_video_callback_->number_times_called()); | 655 EXPECT_EQ(i, test_receiver_video_callback_->number_times_called()); |
| 639 } | 656 } |
| 640 | 657 |
| 641 // TODO(mikhal): Crashes on the Win7 x64 bots. Re-enable. | 658 // TODO(mikhal): Crashes on the Win7 x64 bots. Re-enable. |
| 642 // http://crbug.com/329563 | 659 // http://crbug.com/329563 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 } | 747 } |
| 731 | 748 |
| 732 // This tests start sending audio and video before the receiver is ready. | 749 // This tests start sending audio and video before the receiver is ready. |
| 733 // | 750 // |
| 734 // TODO(miu): Test disabled because of non-determinism. | 751 // TODO(miu): Test disabled because of non-determinism. |
| 735 // http://crbug.com/314233 | 752 // http://crbug.com/314233 |
| 736 TEST_F(End2EndTest, DISABLED_StartSenderBeforeReceiver) { | 753 TEST_F(End2EndTest, DISABLED_StartSenderBeforeReceiver) { |
| 737 SetupConfig(transport::kOpus, kDefaultAudioSamplingRate, false, 1); | 754 SetupConfig(transport::kOpus, kDefaultAudioSamplingRate, false, 1); |
| 738 Create(); | 755 Create(); |
| 739 | 756 |
| 740 int video_start = 1; | 757 int video_start = kVideoStart; |
| 741 int audio_diff = kFrameTimerMs; | 758 int audio_diff = kFrameTimerMs; |
| 742 | 759 |
| 743 sender_to_receiver_.SetSendPackets(false); | 760 sender_to_receiver_.SetSendPackets(false); |
| 744 | 761 |
| 745 for (int i = 0; i < 3; ++i) { | 762 for (int i = 0; i < 3; ++i) { |
| 746 int num_10ms_blocks = audio_diff / 10; | 763 int num_10ms_blocks = audio_diff / 10; |
| 747 audio_diff -= num_10ms_blocks * 10; | 764 audio_diff -= num_10ms_blocks * 10; |
| 748 | 765 |
| 749 base::TimeTicks send_time = testing_clock_->NowTicks(); | 766 base::TimeTicks send_time = testing_clock_->NowTicks(); |
| 750 scoped_ptr<AudioBus> audio_bus(audio_bus_factory_->NextAudioBus( | 767 scoped_ptr<AudioBus> audio_bus(audio_bus_factory_->NextAudioBus( |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 821 EXPECT_EQ(j, test_receiver_video_callback_->number_times_called()); | 838 EXPECT_EQ(j, test_receiver_video_callback_->number_times_called()); |
| 822 } | 839 } |
| 823 | 840 |
| 824 // This tests a network glitch lasting for 10 video frames. | 841 // This tests a network glitch lasting for 10 video frames. |
| 825 TEST_F(End2EndTest, GlitchWith3Buffers) { | 842 TEST_F(End2EndTest, GlitchWith3Buffers) { |
| 826 SetupConfig(transport::kOpus, kDefaultAudioSamplingRate, false, 3); | 843 SetupConfig(transport::kOpus, kDefaultAudioSamplingRate, false, 3); |
| 827 video_sender_config_.rtp_config.max_delay_ms = 67; | 844 video_sender_config_.rtp_config.max_delay_ms = 67; |
| 828 video_receiver_config_.rtp_max_delay_ms = 67; | 845 video_receiver_config_.rtp_max_delay_ms = 67; |
| 829 Create(); | 846 Create(); |
| 830 | 847 |
| 831 int video_start = 50; | 848 int video_start = kVideoStart; |
| 832 base::TimeTicks send_time = testing_clock_->NowTicks(); | 849 base::TimeTicks send_time = testing_clock_->NowTicks(); |
| 833 SendVideoFrame(video_start, send_time); | 850 SendVideoFrame(video_start, send_time); |
| 834 RunTasks(kFrameTimerMs); | 851 RunTasks(kFrameTimerMs); |
| 835 | 852 |
| 836 test_receiver_video_callback_->AddExpectedResult(video_start, | 853 test_receiver_video_callback_->AddExpectedResult(video_start, |
| 837 video_sender_config_.width, | 854 video_sender_config_.width, |
| 838 video_sender_config_.height, | 855 video_sender_config_.height, |
| 839 send_time); | 856 send_time); |
| 840 frame_receiver_->GetRawVideoFrame( | 857 frame_receiver_->GetRawVideoFrame( |
| 841 base::Bind(&TestReceiverVideoCallback::CheckVideoFrame, | 858 base::Bind(&TestReceiverVideoCallback::CheckVideoFrame, |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 877 EXPECT_EQ(2, test_receiver_video_callback_->number_times_called()); | 894 EXPECT_EQ(2, test_receiver_video_callback_->number_times_called()); |
| 878 } | 895 } |
| 879 | 896 |
| 880 TEST_F(End2EndTest, DropEveryOtherFrame3Buffers) { | 897 TEST_F(End2EndTest, DropEveryOtherFrame3Buffers) { |
| 881 SetupConfig(transport::kOpus, kDefaultAudioSamplingRate, false, 3); | 898 SetupConfig(transport::kOpus, kDefaultAudioSamplingRate, false, 3); |
| 882 video_sender_config_.rtp_config.max_delay_ms = 67; | 899 video_sender_config_.rtp_config.max_delay_ms = 67; |
| 883 video_receiver_config_.rtp_max_delay_ms = 67; | 900 video_receiver_config_.rtp_max_delay_ms = 67; |
| 884 Create(); | 901 Create(); |
| 885 sender_to_receiver_.DropAllPacketsBelongingToOddFrames(); | 902 sender_to_receiver_.DropAllPacketsBelongingToOddFrames(); |
| 886 | 903 |
| 887 int video_start = 50; | 904 int video_start = kVideoStart; |
| 888 base::TimeTicks send_time; | 905 base::TimeTicks send_time; |
| 889 | 906 |
| 890 int i = 0; | 907 int i = 0; |
| 891 for (; i < 20; ++i) { | 908 for (; i < 20; ++i) { |
| 892 send_time = testing_clock_->NowTicks(); | 909 send_time = testing_clock_->NowTicks(); |
| 893 SendVideoFrame(video_start, send_time); | 910 SendVideoFrame(video_start, send_time); |
| 894 | 911 |
| 895 if (i % 2 == 0) { | 912 if (i % 2 == 0) { |
| 896 test_receiver_video_callback_->AddExpectedResult( | 913 test_receiver_video_callback_->AddExpectedResult( |
| 897 video_start, | 914 video_start, |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 for (; frames_counter < 3; ++frames_counter) { | 1020 for (; frames_counter < 3; ++frames_counter) { |
| 1004 int num_10ms_blocks = 2; | 1021 int num_10ms_blocks = 2; |
| 1005 | 1022 |
| 1006 const base::TimeTicks send_time = testing_clock_->NowTicks(); | 1023 const base::TimeTicks send_time = testing_clock_->NowTicks(); |
| 1007 | 1024 |
| 1008 scoped_ptr<AudioBus> audio_bus(audio_bus_factory_->NextAudioBus( | 1025 scoped_ptr<AudioBus> audio_bus(audio_bus_factory_->NextAudioBus( |
| 1009 base::TimeDelta::FromMilliseconds(10) * num_10ms_blocks)); | 1026 base::TimeDelta::FromMilliseconds(10) * num_10ms_blocks)); |
| 1010 | 1027 |
| 1011 if (frames_counter != 0) { | 1028 if (frames_counter != 0) { |
| 1012 // Due to the re-sampler and NetEq in the webrtc AudioCodingModule the | 1029 // Due to the re-sampler and NetEq in the webrtc AudioCodingModule the |
| 1013 // first samples will be 0 and then slowly ramp up to its real amplitude; | 1030 // first samples will be 0 and then slowly ramp up to its real |
| 1031 // amplitude; |
| 1014 // ignore the first frame. | 1032 // ignore the first frame. |
| 1015 test_receiver_audio_callback_->AddExpectedResult( | 1033 test_receiver_audio_callback_->AddExpectedResult( |
| 1016 ToPcmAudioFrame(*audio_bus, audio_sender_config_.frequency), | 1034 ToPcmAudioFrame(*audio_bus, audio_sender_config_.frequency), |
| 1017 num_10ms_blocks, | 1035 num_10ms_blocks, |
| 1018 send_time); | 1036 send_time); |
| 1019 } | 1037 } |
| 1020 AudioBus* const audio_bus_ptr = audio_bus.get(); | 1038 AudioBus* const audio_bus_ptr = audio_bus.get(); |
| 1021 frame_input_->InsertAudio( | 1039 frame_input_->InsertAudio( |
| 1022 audio_bus_ptr, | 1040 audio_bus_ptr, |
| 1023 send_time, | 1041 send_time, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1037 32000, | 1055 32000, |
| 1038 base::Bind(&TestReceiverAudioCallback::CheckPcmAudioFrame, | 1056 base::Bind(&TestReceiverAudioCallback::CheckPcmAudioFrame, |
| 1039 test_receiver_audio_callback_)); | 1057 test_receiver_audio_callback_)); |
| 1040 } | 1058 } |
| 1041 } | 1059 } |
| 1042 RunTasks(2 * kFrameTimerMs + 1); // Empty the pipeline. | 1060 RunTasks(2 * kFrameTimerMs + 1); // Empty the pipeline. |
| 1043 EXPECT_EQ(frames_counter - 1, | 1061 EXPECT_EQ(frames_counter - 1, |
| 1044 test_receiver_audio_callback_->number_times_called()); | 1062 test_receiver_audio_callback_->number_times_called()); |
| 1045 } | 1063 } |
| 1046 | 1064 |
| 1047 // Video test without packet loss; This test is targeted at testing the logging | 1065 // Video test without packet loss - tests the logging aspects of the end2end, |
| 1048 // aspects of the end2end, but is basically equivalent to LoopNoLossPcm16. | 1066 // but is basically equivalent to LoopNoLossPcm16. |
| 1049 TEST_F(End2EndTest, VideoLogging) { | 1067 TEST_F(End2EndTest, VideoLogging) { |
| 1050 SetupConfig(transport::kPcm16, 32000, false, 1); | 1068 SetupConfig(transport::kPcm16, 32000, false, 1); |
| 1051 Create(); | 1069 Create(); |
| 1052 | 1070 |
| 1053 int video_start = 1; | 1071 int video_start = kVideoStart; |
| 1054 const int num_frames = 1; | 1072 const int num_frames = 1; |
| 1055 for (int i = 0; i < num_frames; ++i) { | 1073 for (int i = 0; i < num_frames; ++i) { |
| 1056 base::TimeTicks send_time = testing_clock_->NowTicks(); | 1074 base::TimeTicks send_time = testing_clock_->NowTicks(); |
| 1057 test_receiver_video_callback_->AddExpectedResult( | 1075 test_receiver_video_callback_->AddExpectedResult( |
| 1058 video_start, | 1076 video_start, |
| 1059 video_sender_config_.width, | 1077 video_sender_config_.width, |
| 1060 video_sender_config_.height, | 1078 video_sender_config_.height, |
| 1061 send_time); | 1079 send_time); |
| 1062 | 1080 |
| 1063 SendVideoFrame(video_start, send_time); | 1081 SendVideoFrame(video_start, send_time); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1087 // for that frame. | 1105 // for that frame. |
| 1088 std::map<RtpTimestamp, LoggingEventCounts> event_counter_for_frame = | 1106 std::map<RtpTimestamp, LoggingEventCounts> event_counter_for_frame = |
| 1089 GetEventCountForFrameEvents(frame_events_); | 1107 GetEventCountForFrameEvents(frame_events_); |
| 1090 | 1108 |
| 1091 // Verify that there are logs for expected number of frames. | 1109 // Verify that there are logs for expected number of frames. |
| 1092 EXPECT_EQ(num_frames, static_cast<int>(event_counter_for_frame.size())); | 1110 EXPECT_EQ(num_frames, static_cast<int>(event_counter_for_frame.size())); |
| 1093 | 1111 |
| 1094 // Verify that each frame have the expected types of events logged. | 1112 // Verify that each frame have the expected types of events logged. |
| 1095 for (std::map<RtpTimestamp, LoggingEventCounts>::iterator map_it = | 1113 for (std::map<RtpTimestamp, LoggingEventCounts>::iterator map_it = |
| 1096 event_counter_for_frame.begin(); | 1114 event_counter_for_frame.begin(); |
| 1097 map_it != event_counter_for_frame.end(); ++map_it) { | 1115 map_it != event_counter_for_frame.end(); |
| 1116 ++map_it) { |
| 1098 int total_event_count_for_frame = 0; | 1117 int total_event_count_for_frame = 0; |
| 1099 for (int i = 0; i < kNumOfLoggingEvents; ++i) { | 1118 for (int i = 0; i < kNumOfLoggingEvents; ++i) { |
| 1100 total_event_count_for_frame += map_it->second.counter[i]; | 1119 total_event_count_for_frame += map_it->second.counter[i]; |
| 1101 } | 1120 } |
| 1102 | 1121 |
| 1103 int expected_event_count_for_frame = 0; | 1122 int expected_event_count_for_frame = 0; |
| 1104 | 1123 |
| 1105 EXPECT_GT(map_it->second.counter[kVideoFrameSentToEncoder], 0); | 1124 EXPECT_GT(map_it->second.counter[kVideoFrameSentToEncoder], 0); |
| 1106 expected_event_count_for_frame += | 1125 expected_event_count_for_frame += |
| 1107 map_it->second.counter[kVideoFrameSentToEncoder]; | 1126 map_it->second.counter[kVideoFrameSentToEncoder]; |
| 1108 | 1127 |
| 1109 EXPECT_GT(map_it->second.counter[kVideoFrameEncoded], 0); | 1128 EXPECT_GT(map_it->second.counter[kVideoFrameEncoded], 0); |
| 1110 expected_event_count_for_frame += | 1129 expected_event_count_for_frame += |
| 1111 map_it->second.counter[kVideoFrameEncoded]; | 1130 map_it->second.counter[kVideoFrameEncoded]; |
| 1112 | 1131 |
| 1113 EXPECT_GT(map_it->second.counter[kVideoFrameReceived], 0); | 1132 EXPECT_GT(map_it->second.counter[kVideoFrameReceived], 0); |
| 1114 expected_event_count_for_frame += | 1133 expected_event_count_for_frame += |
| 1115 map_it->second.counter[kVideoFrameReceived]; | 1134 map_it->second.counter[kVideoFrameReceived]; |
| 1116 | 1135 |
| 1117 EXPECT_GT(map_it->second.counter[kVideoRenderDelay], 0); | 1136 EXPECT_GT(map_it->second.counter[kVideoRenderDelay], 0); |
| 1118 expected_event_count_for_frame += map_it->second.counter[kVideoRenderDelay]; | 1137 expected_event_count_for_frame += map_it->second.counter[kVideoRenderDelay]; |
| 1119 | 1138 |
| 1120 EXPECT_GT(map_it->second.counter[kVideoFrameDecoded], 0); | 1139 EXPECT_GT(map_it->second.counter[kVideoFrameDecoded], 0); |
| 1121 expected_event_count_for_frame += | 1140 expected_event_count_for_frame += |
| 1122 map_it->second.counter[kVideoFrameDecoded]; | 1141 map_it->second.counter[kVideoFrameDecoded]; |
| 1123 | 1142 |
| 1124 // Verify that there were no other events logged with respect to this frame. | 1143 // Verify that there were no other events logged with respect to this |
| 1144 // frame. |
| 1125 // (i.e. Total event count = expected event count) | 1145 // (i.e. Total event count = expected event count) |
| 1126 EXPECT_EQ(total_event_count_for_frame, expected_event_count_for_frame); | 1146 EXPECT_EQ(total_event_count_for_frame, expected_event_count_for_frame); |
| 1127 } | 1147 } |
| 1128 | 1148 |
| 1129 // Packet logging. | 1149 // Packet logging. |
| 1130 // Verify that all packet related events were logged. | 1150 // Verify that all packet related events were logged. |
| 1131 event_subscriber_.GetPacketEventsAndReset(&packet_events_); | 1151 event_subscriber_.GetPacketEventsAndReset(&packet_events_); |
| 1132 std::map<uint16, LoggingEventCounts> event_count_for_packet = | 1152 std::map<uint16, LoggingEventCounts> event_count_for_packet = |
| 1133 GetEventCountForPacketEvents(packet_events_); | 1153 GetEventCountForPacketEvents(packet_events_); |
| 1134 | 1154 |
| 1135 // Verify that each packet have the expected types of events logged. | 1155 // Verify that each packet have the expected types of events logged. |
| 1136 for (std::map<uint16, LoggingEventCounts>::iterator map_it = | 1156 for (std::map<uint16, LoggingEventCounts>::iterator map_it = |
| 1137 event_count_for_packet.begin(); | 1157 event_count_for_packet.begin(); |
| 1138 map_it != event_count_for_packet.end(); ++map_it) { | 1158 map_it != event_count_for_packet.end(); |
| 1159 ++map_it) { |
| 1139 int total_event_count_for_packet = 0; | 1160 int total_event_count_for_packet = 0; |
| 1140 for (int i = 0; i < kNumOfLoggingEvents; ++i) { | 1161 for (int i = 0; i < kNumOfLoggingEvents; ++i) { |
| 1141 total_event_count_for_packet += map_it->second.counter[i]; | 1162 total_event_count_for_packet += map_it->second.counter[i]; |
| 1142 } | 1163 } |
| 1143 | 1164 |
| 1144 int expected_event_count_for_packet = 0; | 1165 int expected_event_count_for_packet = 0; |
| 1145 EXPECT_GT(map_it->second.counter[kVideoPacketReceived], 0); | 1166 EXPECT_GT(map_it->second.counter[kVideoPacketReceived], 0); |
| 1146 expected_event_count_for_packet += | 1167 expected_event_count_for_packet += |
| 1147 map_it->second.counter[kVideoPacketReceived]; | 1168 map_it->second.counter[kVideoPacketReceived]; |
| 1148 | 1169 |
| 1149 // Verify that there were no other events logged with respect to this | 1170 // Verify that there were no other events logged with respect to this |
| 1150 // packet. (i.e. Total event count = expected event count) | 1171 // packet. (i.e. Total event count = expected event count) |
| 1151 EXPECT_EQ(total_event_count_for_packet, expected_event_count_for_packet); | 1172 EXPECT_EQ(total_event_count_for_packet, expected_event_count_for_packet); |
| 1152 } | 1173 } |
| 1153 } | 1174 } |
| 1154 | 1175 |
| 1155 // TODO(mikhal): Crashes on the bots. Re-enable. http://crbug.com/329563 | 1176 // TODO(mikhal): Crashes on the bots. Re-enable. http://crbug.com/329563 |
| 1156 #if defined(OS_WIN) | 1177 #if defined(OS_WIN) |
| 1157 #define MAYBE_AudioLogging DISABLED_AudioLogging | 1178 #define MAYBE_AudioLogging DISABLED_AudioLogging |
| 1158 #else | 1179 #else |
| 1159 #define MAYBE_AudioLogging AudioLogging | 1180 #define MAYBE_AudioLogging AudioLogging |
| 1160 #endif | 1181 #endif |
| 1161 // Audio test without packet loss; This test is targeted at testing the logging | 1182 // Audio test without packet loss - tests the logging aspects of the end2end, |
| 1162 // aspects of the end2end, but is basically equivalent to LoopNoLossPcm16. | 1183 // but is basically equivalent to LoopNoLossPcm16. |
| 1163 TEST_F(End2EndTest, MAYBE_AudioLogging) { | 1184 TEST_F(End2EndTest, MAYBE_AudioLogging) { |
| 1164 SetupConfig(transport::kPcm16, 32000, false, 1); | 1185 SetupConfig(transport::kPcm16, 32000, false, 1); |
| 1165 Create(); | 1186 Create(); |
| 1166 | 1187 |
| 1167 int audio_diff = kFrameTimerMs; | 1188 int audio_diff = kFrameTimerMs; |
| 1168 const int num_frames = 10; | 1189 const int num_frames = 10; |
| 1169 for (int i = 0; i < num_frames; ++i) { | 1190 for (int i = 0; i < num_frames; ++i) { |
| 1170 int num_10ms_blocks = audio_diff / 10; | 1191 int num_10ms_blocks = audio_diff / 10; |
| 1171 audio_diff -= num_10ms_blocks * 10; | 1192 audio_diff -= num_10ms_blocks * 10; |
| 1172 base::TimeTicks send_time = testing_clock_->NowTicks(); | 1193 base::TimeTicks send_time = testing_clock_->NowTicks(); |
| 1173 | 1194 |
| 1174 scoped_ptr<AudioBus> audio_bus(audio_bus_factory_->NextAudioBus( | 1195 scoped_ptr<AudioBus> audio_bus(audio_bus_factory_->NextAudioBus( |
| 1175 base::TimeDelta::FromMilliseconds(10) * num_10ms_blocks)); | 1196 base::TimeDelta::FromMilliseconds(10) * num_10ms_blocks)); |
| 1176 | 1197 |
| 1177 if (i != 0) { | 1198 if (i != 0) { |
| 1178 // Due to the re-sampler and NetEq in the webrtc AudioCodingModule the | 1199 // Due to the re-sampler and NetEq in the webrtc AudioCodingModule the |
| 1179 // first samples will be 0 and then slowly ramp up to its real amplitude; | 1200 // first samples will be 0 and then slowly ramp up to its real |
| 1201 // amplitude; |
| 1180 // ignore the first frame. | 1202 // ignore the first frame. |
| 1181 test_receiver_audio_callback_->AddExpectedResult( | 1203 test_receiver_audio_callback_->AddExpectedResult( |
| 1182 ToPcmAudioFrame(*audio_bus, audio_sender_config_.frequency), | 1204 ToPcmAudioFrame(*audio_bus, audio_sender_config_.frequency), |
| 1183 num_10ms_blocks, | 1205 num_10ms_blocks, |
| 1184 send_time); | 1206 send_time); |
| 1185 } | 1207 } |
| 1186 | 1208 |
| 1187 AudioBus* const audio_bus_ptr = audio_bus.get(); | 1209 AudioBus* const audio_bus_ptr = audio_bus.get(); |
| 1188 frame_input_->InsertAudio( | 1210 frame_input_->InsertAudio( |
| 1189 audio_bus_ptr, | 1211 audio_bus_ptr, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1222 // type logged for that frame. | 1244 // type logged for that frame. |
| 1223 std::map<RtpTimestamp, LoggingEventCounts> event_counter_for_frame = | 1245 std::map<RtpTimestamp, LoggingEventCounts> event_counter_for_frame = |
| 1224 GetEventCountForFrameEvents(frame_events_); | 1246 GetEventCountForFrameEvents(frame_events_); |
| 1225 | 1247 |
| 1226 // Verify that each frame have the expected types of events logged. | 1248 // Verify that each frame have the expected types of events logged. |
| 1227 std::map<RtpTimestamp, LoggingEventCounts>::iterator map_it = | 1249 std::map<RtpTimestamp, LoggingEventCounts>::iterator map_it = |
| 1228 event_counter_for_frame.begin(); | 1250 event_counter_for_frame.begin(); |
| 1229 | 1251 |
| 1230 // TODO(imcheng): This only checks the first frame. This doesn't work | 1252 // TODO(imcheng): This only checks the first frame. This doesn't work |
| 1231 // properly for all frames for two reasons: | 1253 // properly for all frames for two reasons: |
| 1232 // 1. There is a loopback of kAudioPlayoutDelay and kAudioFrameDecoded events | 1254 // 1. There is a loopback of kAudioPlayoutDelay and kAudioFrameDecoded |
| 1233 // due to shared CastEnvironment between sender and | 1255 // events due to shared CastEnvironment between sender and |
| 1234 // receiver in the test setup. We will need to create separate CastEnvironment | 1256 // receiver in the test setup. We will need to create separate |
| 1235 // once again to fix this. | 1257 // CastEnvironment once again to fix this. |
| 1236 // 2. kAudioPlayoutDelay and kAudioFrameDecoded RTP timestamps aren't exactly | 1258 // 2. kAudioPlayoutDelay and kAudioFrameDecoded RTP timestamps aren't |
| 1237 // aligned with those of kAudioFrameReceived and kAudioFrameEncoded. Note that | 1259 // exactly aligned with those of kAudioFrameReceived and kAudioFrameEncoded. |
| 1238 // these RTP timestamps are output from webrtc::AudioCodingModule which are | 1260 // Note that these RTP timestamps are output from webrtc::AudioCodingModule |
| 1239 // different from RTP timestamps that the cast library generates during the | 1261 // which are different from RTP timestamps that the cast library generates |
| 1240 // encode step (and which are sent to receiver). The first frame just happen | 1262 // during the encode step (and which are sent to receiver). The first frame |
| 1241 // to be aligned. | 1263 // just happen to be aligned. |
| 1242 int total_event_count_for_frame = 0; | 1264 int total_event_count_for_frame = 0; |
| 1243 for (int j = 0; j < kNumOfLoggingEvents; ++j) | 1265 for (int j = 0; j < kNumOfLoggingEvents; ++j) |
| 1244 total_event_count_for_frame += map_it->second.counter[j]; | 1266 total_event_count_for_frame += map_it->second.counter[j]; |
| 1245 | 1267 |
| 1246 | |
| 1247 int expected_event_count_for_frame = 0; | 1268 int expected_event_count_for_frame = 0; |
| 1248 | 1269 |
| 1249 EXPECT_GT(map_it->second.counter[kAudioFrameReceived], 0); | 1270 EXPECT_GT(map_it->second.counter[kAudioFrameReceived], 0); |
| 1250 expected_event_count_for_frame += | 1271 expected_event_count_for_frame += map_it->second.counter[kAudioFrameReceived]; |
| 1251 map_it->second.counter[kAudioFrameReceived]; | |
| 1252 | 1272 |
| 1253 EXPECT_GT(map_it->second.counter[kAudioFrameEncoded], 0); | 1273 EXPECT_GT(map_it->second.counter[kAudioFrameEncoded], 0); |
| 1254 expected_event_count_for_frame += | 1274 expected_event_count_for_frame += map_it->second.counter[kAudioFrameEncoded]; |
| 1255 map_it->second.counter[kAudioFrameEncoded]; | |
| 1256 | 1275 |
| 1257 // Note that this is a big positive number instead of just 1 due to loopback | 1276 // Note that this is a big positive number instead of just 1 due to loopback |
| 1258 // described in TODO above. | 1277 // described in TODO above. |
| 1259 EXPECT_GT(map_it->second.counter[kAudioPlayoutDelay], 0); | 1278 EXPECT_GT(map_it->second.counter[kAudioPlayoutDelay], 0); |
| 1260 expected_event_count_for_frame += | 1279 expected_event_count_for_frame += map_it->second.counter[kAudioPlayoutDelay]; |
| 1261 map_it->second.counter[kAudioPlayoutDelay]; | |
| 1262 EXPECT_GT(map_it->second.counter[kAudioFrameDecoded], 0); | 1280 EXPECT_GT(map_it->second.counter[kAudioFrameDecoded], 0); |
| 1263 expected_event_count_for_frame += | 1281 expected_event_count_for_frame += map_it->second.counter[kAudioFrameDecoded]; |
| 1264 map_it->second.counter[kAudioFrameDecoded]; | |
| 1265 | 1282 |
| 1266 // Verify that there were no other events logged with respect to this frame. | 1283 // Verify that there were no other events logged with respect to this frame. |
| 1267 // (i.e. Total event count = expected event count) | 1284 // (i.e. Total event count = expected event count) |
| 1268 EXPECT_EQ(total_event_count_for_frame, expected_event_count_for_frame); | 1285 EXPECT_EQ(total_event_count_for_frame, expected_event_count_for_frame); |
| 1269 } | 1286 } |
| 1270 | 1287 |
| 1271 // TODO(pwestin): Add repeatable packet loss test. | 1288 // TODO(pwestin): Add repeatable packet loss test. |
| 1272 // TODO(pwestin): Add test for misaligned send get calls. | 1289 // TODO(pwestin): Add test for misaligned send get calls. |
| 1273 // TODO(pwestin): Add more tests that does not resample. | 1290 // TODO(pwestin): Add more tests that does not resample. |
| 1274 // TODO(pwestin): Add test when we have starvation for our RunTask. | 1291 // TODO(pwestin): Add test when we have starvation for our RunTask. |
| 1275 | 1292 |
| 1276 } // namespace cast | 1293 } // namespace cast |
| 1277 } // namespace media | 1294 } // namespace media |
| OLD | NEW |