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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
534 }; | 536 }; |
535 | 537 |
536 // Audio and video test without packet loss using raw PCM 16 audio "codec"; | 538 // Audio and video test without packet loss using raw PCM 16 audio "codec"; |
537 // note: even though the audio is not coded it is still re-sampled between | 539 // note: even though the audio is not coded it is still re-sampled between |
538 // 48 and 32 KHz. | 540 // 48 and 32 KHz. |
539 TEST_F(End2EndTest, LoopNoLossPcm16) { | 541 TEST_F(End2EndTest, LoopNoLossPcm16) { |
540 // Note running codec in different sampling frequency. | 542 // Note running codec in different sampling frequency. |
541 SetupConfig(kPcm16, 32000, false, 1); | 543 SetupConfig(kPcm16, 32000, false, 1); |
542 Create(); | 544 Create(); |
543 test_receiver_audio_callback_->SetExpectedResult(kAudioSamplingFrequency, 20, | 545 test_receiver_audio_callback_->SetExpectedResult(kAudioSamplingFrequency, 20, |
544 25); | 546 20); |
wtc
2013/11/13 20:57:17
Is this an unrelated change? Just curious.
pwestin
2013/11/15 19:38:17
Removed should not changed; at least not in this c
| |
545 | 547 |
546 int video_start = 1; | 548 int video_start = 1; |
547 int audio_diff = kFrameTimerMs; | 549 int audio_diff = kFrameTimerMs; |
548 int i = 0; | 550 int i = 0; |
549 | 551 |
550 std::cout << "Progress "; | 552 std::cout << "Progress "; |
551 for (; i < 100; ++i) { | 553 for (; i < 100; ++i) { |
552 int num_10ms_blocks = audio_diff / 10; | 554 int num_10ms_blocks = audio_diff / 10; |
553 audio_diff -= num_10ms_blocks * 10; | 555 audio_diff -= num_10ms_blocks * 10; |
554 base::TimeTicks send_time = testing_clock_.NowTicks(); | 556 base::TimeTicks send_time = testing_clock_.NowTicks(); |
(...skipping 300 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 | |
902 TEST_F(End2EndTest, CryptoAudio) { | |
903 SetupConfig(kPcm16, 32000, false, 1); | |
904 | |
905 audio_sender_config_.aes_iv_mask = | |
906 ConvertFromBase16String("abcdeffedcba12345678900987654321"); | |
907 audio_sender_config_.aes_key = | |
908 ConvertFromBase16String("deadbeefcafecafedeadbeefb0b0b0b0"); | |
909 | |
910 audio_receiver_config_.aes_iv_mask = audio_sender_config_.aes_iv_mask; | |
911 audio_receiver_config_.aes_key = audio_sender_config_.aes_key; | |
912 | |
913 Create(); | |
914 test_receiver_audio_callback_->SetExpectedResult(32000, 18, 20); | |
915 | |
916 int frames_counter = 0; | |
917 for (; frames_counter < 20; ++frames_counter) { | |
918 int num_10ms_blocks = 2; | |
919 | |
920 const base::TimeTicks send_time = testing_clock_.NowTicks(); | |
921 | |
922 PcmAudioFrame* audio_frame = CreateAudioFrame(num_10ms_blocks, | |
923 kSoundFrequency, 32000); | |
924 | |
925 if (frames_counter != 0) { | |
926 // Due to the re-sampler and NetEq in the webrtc AudioCodingModule the | |
927 // first samples will be 0 and then slowly ramp up to its real amplitude; | |
928 // ignore the first frame. | |
929 test_receiver_audio_callback_->AddExpectedResult(audio_frame, | |
930 num_10ms_blocks, send_time); | |
931 } | |
932 frame_input_->InsertRawAudioFrame(audio_frame, send_time, | |
933 base::Bind(FrameInput::DeleteAudioFrame, audio_frame)); | |
934 | |
935 RunTasks(num_10ms_blocks * 10); | |
936 | |
937 if (frames_counter == 0) { | |
938 frame_receiver_->GetRawAudioFrame(num_10ms_blocks, | |
939 32000, | |
940 base::Bind(&TestReceiverAudioCallback::IgnoreAudioFrame, | |
941 test_receiver_audio_callback_)); | |
942 } else { | |
943 frame_receiver_->GetRawAudioFrame(num_10ms_blocks, | |
944 32000, | |
945 base::Bind(&TestReceiverAudioCallback::CheckPcmAudioFrame, | |
946 test_receiver_audio_callback_)); | |
947 } | |
948 } | |
949 RunTasks(2 * kFrameTimerMs + 1); // Empty the pipeline. | |
950 EXPECT_EQ(frames_counter - 1, | |
951 test_receiver_audio_callback_->number_times_called()); | |
952 } | |
953 | |
954 | |
955 | |
wtc
2013/11/13 20:57:17
Nit: use only one blank line here and on line 900
pwestin
2013/11/15 19:38:17
Done.
| |
865 // TODO(pwestin): Add repeatable packet loss test. | 956 // TODO(pwestin): Add repeatable packet loss test. |
866 // TODO(pwestin): Add test for misaligned send get calls. | 957 // TODO(pwestin): Add test for misaligned send get calls. |
867 // TODO(pwestin): Add more tests that does not resample. | 958 // TODO(pwestin): Add more tests that does not resample. |
868 // TODO(pwestin): Add test when we have starvation for our RunTask. | 959 // TODO(pwestin): Add test when we have starvation for our RunTask. |
869 | 960 |
870 } // namespace cast | 961 } // namespace cast |
871 } // namespace media | 962 } // namespace media |
OLD | NEW |