| 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 |
| 11 | 11 |
| 12 #include <math.h> | 12 #include <math.h> |
| 13 | 13 |
| 14 #include <list> | 14 #include <list> |
| 15 | 15 |
| 16 #include "base/bind.h" | 16 #include "base/bind.h" |
| 17 #include "base/test/simple_test_tick_clock.h" | 17 #include "base/test/simple_test_tick_clock.h" |
| 18 #include "base/time/tick_clock.h" | 18 #include "base/time/tick_clock.h" |
| 19 #include "media/cast/cast_config.h" | 19 #include "media/cast/cast_config.h" |
| 20 #include "media/cast/cast_environment.h" | 20 #include "media/cast/cast_environment.h" |
| 21 #include "media/cast/cast_receiver.h" | 21 #include "media/cast/cast_receiver.h" |
| 22 #include "media/cast/cast_sender.h" | 22 #include "media/cast/cast_sender.h" |
| 23 #include "media/cast/test/crypto_utility.h" |
| 23 #include "media/cast/test/fake_task_runner.h" | 24 #include "media/cast/test/fake_task_runner.h" |
| 24 #include "media/cast/test/video_utility.h" | 25 #include "media/cast/test/video_utility.h" |
| 25 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 26 | 27 |
| 27 namespace media { | 28 namespace media { |
| 28 namespace cast { | 29 namespace cast { |
| 29 | 30 |
| 30 static const int64 kStartMillisecond = GG_INT64_C(1245); | 31 static const int64 kStartMillisecond = GG_INT64_C(1245); |
| 31 static const int kAudioChannels = 2; | 32 static const int kAudioChannels = 2; |
| 32 static const int kAudioSamplingFrequency = 48000; | 33 static const int kAudioSamplingFrequency = 48000; |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 if (audio_frame->data.size() == 0) return; // No more checks needed. | 278 if (audio_frame->data.size() == 0) return; // No more checks needed. |
| 278 | 279 |
| 279 size_t max_delay = CalculateMaxResamplingDelay(48000, 32000, | 280 size_t max_delay = CalculateMaxResamplingDelay(48000, 32000, |
| 280 expected_audio_frame.audio_frame.channels); | 281 expected_audio_frame.audio_frame.channels); |
| 281 | 282 |
| 282 // We need to convert our "coded" audio frame to our raw format. | 283 // We need to convert our "coded" audio frame to our raw format. |
| 283 std::vector<int16> output_audio_samples; | 284 std::vector<int16> output_audio_samples; |
| 284 size_t number_of_samples = audio_frame->data.size() / 2; | 285 size_t number_of_samples = audio_frame->data.size() / 2; |
| 285 | 286 |
| 286 for (size_t i = 0; i < number_of_samples; ++i) { | 287 for (size_t i = 0; i < number_of_samples; ++i) { |
| 287 uint16 sample = (audio_frame->data[1 + i * sizeof(uint16)]) + | 288 uint16 sample = |
| 288 (static_cast<uint16>(audio_frame->data[i * sizeof(uint16)]) << 8); | 289 static_cast<uint8>(audio_frame->data[1 + i * sizeof(uint16)]) + |
| 290 (static_cast<uint16>(audio_frame->data[i * sizeof(uint16)]) << 8); |
| 289 output_audio_samples.push_back(static_cast<int16>(sample)); | 291 output_audio_samples.push_back(static_cast<int16>(sample)); |
| 290 } | 292 } |
| 291 EXPECT_GE(ComputeBestSNR(expected_audio_frame.audio_frame, | 293 EXPECT_GE(ComputeBestSNR(expected_audio_frame.audio_frame, |
| 292 output_audio_samples, max_delay), | 294 output_audio_samples, max_delay), |
| 293 expected_min_snr_); | 295 expected_min_snr_); |
| 294 } | 296 } |
| 295 | 297 |
| 296 int number_times_called() { | 298 int number_times_called() { |
| 297 EXPECT_GE(avg_snr_, expected_avg_snr_); | 299 EXPECT_GE(avg_snr_, expected_avg_snr_); |
| 298 return num_called_; | 300 return num_called_; |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 855 frame_receiver_->GetRawVideoFrame( | 857 frame_receiver_->GetRawVideoFrame( |
| 856 base::Bind(&TestReceiverVideoCallback::CheckVideoFrame, | 858 base::Bind(&TestReceiverVideoCallback::CheckVideoFrame, |
| 857 test_receiver_video_callback_)); | 859 test_receiver_video_callback_)); |
| 858 RunTasks(kFrameTimerMs); | 860 RunTasks(kFrameTimerMs); |
| 859 } | 861 } |
| 860 RunTasks(2 * kFrameTimerMs + 1); // Empty the pipeline. | 862 RunTasks(2 * kFrameTimerMs + 1); // Empty the pipeline. |
| 861 EXPECT_EQ(frames_counter, | 863 EXPECT_EQ(frames_counter, |
| 862 test_receiver_video_callback_->number_times_called()); | 864 test_receiver_video_callback_->number_times_called()); |
| 863 } | 865 } |
| 864 | 866 |
| 867 TEST_F(End2EndTest, CryptoVideo) { |
| 868 SetupConfig(kPcm16, 32000, false, 1); |
| 869 |
| 870 video_sender_config_.aes_iv_mask = |
| 871 ConvertFromBase16String("1234567890abcdeffedcba0987654321"); |
| 872 video_sender_config_.aes_key = |
| 873 ConvertFromBase16String("deadbeefcafeb0b0b0b0cafedeadbeef"); |
| 874 |
| 875 video_receiver_config_.aes_iv_mask = video_sender_config_.aes_iv_mask; |
| 876 video_receiver_config_.aes_key = video_sender_config_.aes_key; |
| 877 |
| 878 Create(); |
| 879 |
| 880 int frames_counter = 0; |
| 881 for (; frames_counter < 20; ++frames_counter) { |
| 882 const base::TimeTicks send_time = testing_clock_.NowTicks(); |
| 883 |
| 884 SendVideoFrame(frames_counter, send_time); |
| 885 |
| 886 test_receiver_video_callback_->AddExpectedResult(frames_counter, |
| 887 video_sender_config_.width, video_sender_config_.height, send_time); |
| 888 |
| 889 // GetRawVideoFrame will not return the frame until we are close to the |
| 890 // time in which we should render the frame. |
| 891 frame_receiver_->GetRawVideoFrame( |
| 892 base::Bind(&TestReceiverVideoCallback::CheckVideoFrame, |
| 893 test_receiver_video_callback_)); |
| 894 RunTasks(kFrameTimerMs); |
| 895 } |
| 896 RunTasks(2 * kFrameTimerMs + 1); // Empty the pipeline. |
| 897 EXPECT_EQ(frames_counter, |
| 898 test_receiver_video_callback_->number_times_called()); |
| 899 } |
| 900 |
| 901 TEST_F(End2EndTest, CryptoAudio) { |
| 902 SetupConfig(kPcm16, 32000, false, 1); |
| 903 |
| 904 audio_sender_config_.aes_iv_mask = |
| 905 ConvertFromBase16String("abcdeffedcba12345678900987654321"); |
| 906 audio_sender_config_.aes_key = |
| 907 ConvertFromBase16String("deadbeefcafecafedeadbeefb0b0b0b0"); |
| 908 |
| 909 audio_receiver_config_.aes_iv_mask = audio_sender_config_.aes_iv_mask; |
| 910 audio_receiver_config_.aes_key = audio_sender_config_.aes_key; |
| 911 |
| 912 Create(); |
| 913 test_receiver_audio_callback_->SetExpectedResult(32000, 18, 20); |
| 914 |
| 915 int frames_counter = 0; |
| 916 for (; frames_counter < 20; ++frames_counter) { |
| 917 int num_10ms_blocks = 2; |
| 918 |
| 919 const base::TimeTicks send_time = testing_clock_.NowTicks(); |
| 920 |
| 921 PcmAudioFrame* audio_frame = CreateAudioFrame(num_10ms_blocks, |
| 922 kSoundFrequency, 32000); |
| 923 |
| 924 if (frames_counter != 0) { |
| 925 // Due to the re-sampler and NetEq in the webrtc AudioCodingModule the |
| 926 // first samples will be 0 and then slowly ramp up to its real amplitude; |
| 927 // ignore the first frame. |
| 928 test_receiver_audio_callback_->AddExpectedResult(audio_frame, |
| 929 num_10ms_blocks, send_time); |
| 930 } |
| 931 frame_input_->InsertRawAudioFrame(audio_frame, send_time, |
| 932 base::Bind(FrameInput::DeleteAudioFrame, audio_frame)); |
| 933 |
| 934 RunTasks(num_10ms_blocks * 10); |
| 935 |
| 936 if (frames_counter == 0) { |
| 937 frame_receiver_->GetRawAudioFrame(num_10ms_blocks, |
| 938 32000, |
| 939 base::Bind(&TestReceiverAudioCallback::IgnoreAudioFrame, |
| 940 test_receiver_audio_callback_)); |
| 941 } else { |
| 942 frame_receiver_->GetRawAudioFrame(num_10ms_blocks, |
| 943 32000, |
| 944 base::Bind(&TestReceiverAudioCallback::CheckPcmAudioFrame, |
| 945 test_receiver_audio_callback_)); |
| 946 } |
| 947 } |
| 948 RunTasks(2 * kFrameTimerMs + 1); // Empty the pipeline. |
| 949 EXPECT_EQ(frames_counter - 1, |
| 950 test_receiver_audio_callback_->number_times_called()); |
| 951 } |
| 952 |
| 865 // TODO(pwestin): Add repeatable packet loss test. | 953 // TODO(pwestin): Add repeatable packet loss test. |
| 866 // TODO(pwestin): Add test for misaligned send get calls. | 954 // TODO(pwestin): Add test for misaligned send get calls. |
| 867 // TODO(pwestin): Add more tests that does not resample. | 955 // TODO(pwestin): Add more tests that does not resample. |
| 868 // TODO(pwestin): Add test when we have starvation for our RunTask. | 956 // TODO(pwestin): Add test when we have starvation for our RunTask. |
| 869 | 957 |
| 870 } // namespace cast | 958 } // namespace cast |
| 871 } // namespace media | 959 } // namespace media |
| OLD | NEW |