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

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

Issue 62843002: Cast: Added support for AES-CTR crypto. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync TOT Created 7 years, 1 month 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
« no previous file with comments | « media/cast/test/crypto_utility.cc ('k') | media/cast/video_receiver/codecs/vp8/vp8_decoder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
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/bind_helpers.h" 17 #include "base/bind_helpers.h"
18 #include "base/test/simple_test_tick_clock.h" 18 #include "base/test/simple_test_tick_clock.h"
19 #include "base/time/tick_clock.h" 19 #include "base/time/tick_clock.h"
20 #include "media/cast/cast_config.h" 20 #include "media/cast/cast_config.h"
21 #include "media/cast/cast_environment.h" 21 #include "media/cast/cast_environment.h"
22 #include "media/cast/cast_receiver.h" 22 #include "media/cast/cast_receiver.h"
23 #include "media/cast/cast_sender.h" 23 #include "media/cast/cast_sender.h"
24 #include "media/cast/test/audio_utility.h" 24 #include "media/cast/test/audio_utility.h"
25 #include "media/cast/test/crypto_utility.h"
25 #include "media/cast/test/fake_task_runner.h" 26 #include "media/cast/test/fake_task_runner.h"
26 #include "media/cast/test/video_utility.h" 27 #include "media/cast/test/video_utility.h"
27 #include "testing/gtest/include/gtest/gtest.h" 28 #include "testing/gtest/include/gtest/gtest.h"
28 29
29 namespace media { 30 namespace media {
30 namespace cast { 31 namespace cast {
31 32
32 static const int64 kStartMillisecond = GG_INT64_C(1245); 33 static const int64 kStartMillisecond = GG_INT64_C(1245);
33 static const int kAudioChannels = 2; 34 static const int kAudioChannels = 2;
34 static const double kSoundFrequency = 314.15926535897; // Freq of sine wave. 35 static const double kSoundFrequency = 314.15926535897; // Freq of sine wave.
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 kDefaultRtpMaxDelayMs + kTimerErrorMs)); 220 kDefaultRtpMaxDelayMs + kTimerErrorMs));
220 221
221 EXPECT_LT(expected_audio_frame.record_time, playout_time); 222 EXPECT_LT(expected_audio_frame.record_time, playout_time);
222 if (audio_frame->data.size() == 0) return; // No more checks needed. 223 if (audio_frame->data.size() == 0) return; // No more checks needed.
223 224
224 // We need to convert our "coded" audio frame to our raw format. 225 // We need to convert our "coded" audio frame to our raw format.
225 std::vector<int16> output_audio_samples; 226 std::vector<int16> output_audio_samples;
226 size_t number_of_samples = audio_frame->data.size() / 2; 227 size_t number_of_samples = audio_frame->data.size() / 2;
227 228
228 for (size_t i = 0; i < number_of_samples; ++i) { 229 for (size_t i = 0; i < number_of_samples; ++i) {
229 uint16 sample = (audio_frame->data[1 + i * sizeof(uint16)]) + 230 uint16 sample =
230 (static_cast<uint16>(audio_frame->data[i * sizeof(uint16)]) << 8); 231 static_cast<uint8>(audio_frame->data[1 + i * sizeof(uint16)]) +
232 (static_cast<uint16>(audio_frame->data[i * sizeof(uint16)]) << 8);
231 output_audio_samples.push_back(static_cast<int16>(sample)); 233 output_audio_samples.push_back(static_cast<int16>(sample));
232 } 234 }
233 235
234 EXPECT_NEAR(CountZeroCrossings(expected_audio_frame.audio_frame.samples), 236 EXPECT_NEAR(CountZeroCrossings(expected_audio_frame.audio_frame.samples),
235 CountZeroCrossings(output_audio_samples), 237 CountZeroCrossings(output_audio_samples),
236 1); 238 1);
237 } 239 }
238 240
239 int number_times_called() const { 241 int number_times_called() const {
240 return num_called_; 242 return num_called_;
(...skipping 535 matching lines...) Expand 10 before | Expand all | Expand 10 after
776 frame_receiver_->GetRawVideoFrame( 778 frame_receiver_->GetRawVideoFrame(
777 base::Bind(&TestReceiverVideoCallback::CheckVideoFrame, 779 base::Bind(&TestReceiverVideoCallback::CheckVideoFrame,
778 test_receiver_video_callback_)); 780 test_receiver_video_callback_));
779 RunTasks(kFrameTimerMs); 781 RunTasks(kFrameTimerMs);
780 } 782 }
781 RunTasks(2 * kFrameTimerMs + 1); // Empty the pipeline. 783 RunTasks(2 * kFrameTimerMs + 1); // Empty the pipeline.
782 EXPECT_EQ(frames_counter, 784 EXPECT_EQ(frames_counter,
783 test_receiver_video_callback_->number_times_called()); 785 test_receiver_video_callback_->number_times_called());
784 } 786 }
785 787
788 TEST_F(End2EndTest, CryptoVideo) {
789 SetupConfig(kPcm16, 32000, false, 1);
790
791 video_sender_config_.aes_iv_mask =
792 ConvertFromBase16String("1234567890abcdeffedcba0987654321");
793 video_sender_config_.aes_key =
794 ConvertFromBase16String("deadbeefcafeb0b0b0b0cafedeadbeef");
795
796 video_receiver_config_.aes_iv_mask = video_sender_config_.aes_iv_mask;
797 video_receiver_config_.aes_key = video_sender_config_.aes_key;
798
799 Create();
800
801 int frames_counter = 0;
802 for (; frames_counter < 20; ++frames_counter) {
803 const base::TimeTicks send_time = testing_clock_.NowTicks();
804
805 SendVideoFrame(frames_counter, send_time);
806
807 test_receiver_video_callback_->AddExpectedResult(frames_counter,
808 video_sender_config_.width, video_sender_config_.height, send_time);
809
810 // GetRawVideoFrame will not return the frame until we are close to the
811 // time in which we should render the frame.
812 frame_receiver_->GetRawVideoFrame(
813 base::Bind(&TestReceiverVideoCallback::CheckVideoFrame,
814 test_receiver_video_callback_));
815 RunTasks(kFrameTimerMs);
816 }
817 RunTasks(2 * kFrameTimerMs + 1); // Empty the pipeline.
818 EXPECT_EQ(frames_counter,
819 test_receiver_video_callback_->number_times_called());
820 }
821
822 TEST_F(End2EndTest, CryptoAudio) {
823 SetupConfig(kPcm16, 32000, false, 1);
824
825 audio_sender_config_.aes_iv_mask =
826 ConvertFromBase16String("abcdeffedcba12345678900987654321");
827 audio_sender_config_.aes_key =
828 ConvertFromBase16String("deadbeefcafecafedeadbeefb0b0b0b0");
829
830 audio_receiver_config_.aes_iv_mask = audio_sender_config_.aes_iv_mask;
831 audio_receiver_config_.aes_key = audio_sender_config_.aes_key;
832
833 Create();
834
835 int frames_counter = 0;
836 for (; frames_counter < 20; ++frames_counter) {
837 int num_10ms_blocks = 2;
838
839 const base::TimeTicks send_time = testing_clock_.NowTicks();
840
841 scoped_ptr<AudioBus> audio_bus(audio_bus_factory_->NextAudioBus(
842 base::TimeDelta::FromMilliseconds(10) * num_10ms_blocks));
843
844 if (frames_counter != 0) {
845 // Due to the re-sampler and NetEq in the webrtc AudioCodingModule the
846 // first samples will be 0 and then slowly ramp up to its real amplitude;
847 // ignore the first frame.
848 test_receiver_audio_callback_->AddExpectedResult(
849 ToPcmAudioFrame(*audio_bus, audio_sender_config_.frequency),
850 num_10ms_blocks, send_time);
851 }
852 AudioBus* const audio_bus_ptr = audio_bus.get();
853 frame_input_->InsertAudio(audio_bus_ptr, send_time,
854 base::Bind(&OwnThatAudioBus, base::Passed(&audio_bus)));
855
856 RunTasks(num_10ms_blocks * 10);
857
858 if (frames_counter == 0) {
859 frame_receiver_->GetRawAudioFrame(num_10ms_blocks,
860 32000,
861 base::Bind(&TestReceiverAudioCallback::IgnoreAudioFrame,
862 test_receiver_audio_callback_));
863 } else {
864 frame_receiver_->GetRawAudioFrame(num_10ms_blocks,
865 32000,
866 base::Bind(&TestReceiverAudioCallback::CheckPcmAudioFrame,
867 test_receiver_audio_callback_));
868 }
869 }
870 RunTasks(2 * kFrameTimerMs + 1); // Empty the pipeline.
871 EXPECT_EQ(frames_counter - 1,
872 test_receiver_audio_callback_->number_times_called());
873 }
874
786 // TODO(pwestin): Add repeatable packet loss test. 875 // TODO(pwestin): Add repeatable packet loss test.
787 // TODO(pwestin): Add test for misaligned send get calls. 876 // TODO(pwestin): Add test for misaligned send get calls.
788 // TODO(pwestin): Add more tests that does not resample. 877 // TODO(pwestin): Add more tests that does not resample.
789 // TODO(pwestin): Add test when we have starvation for our RunTask. 878 // TODO(pwestin): Add test when we have starvation for our RunTask.
790 879
791 } // namespace cast 880 } // namespace cast
792 } // namespace media 881 } // namespace media
OLDNEW
« no previous file with comments | « media/cast/test/crypto_utility.cc ('k') | media/cast/video_receiver/codecs/vp8/vp8_decoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698