Index: media/cast/test/end2end_unittest.cc |
diff --git a/media/cast/test/end2end_unittest.cc b/media/cast/test/end2end_unittest.cc |
index e9cefaad1522e30486e71682195d8ce8f95c577e..4a13563d844010efb045d730beeb070413c419cf 100644 |
--- a/media/cast/test/end2end_unittest.cc |
+++ b/media/cast/test/end2end_unittest.cc |
@@ -284,8 +284,9 @@ class TestReceiverAudioCallback : |
size_t number_of_samples = audio_frame->data.size() / 2; |
for (size_t i = 0; i < number_of_samples; ++i) { |
- uint16 sample = (audio_frame->data[1 + i * sizeof(uint16)]) + |
- (static_cast<uint16>(audio_frame->data[i * sizeof(uint16)]) << 8); |
+ uint16 sample = |
+ static_cast<uint8>(audio_frame->data[1 + i * sizeof(uint16)]) + |
+ (static_cast<uint16>(audio_frame->data[i * sizeof(uint16)]) << 8); |
output_audio_samples.push_back(static_cast<int16>(sample)); |
} |
EXPECT_GE(ComputeBestSNR(expected_audio_frame.audio_frame, |
@@ -510,6 +511,34 @@ class End2EndTest : public ::testing::Test { |
} |
} |
+ char ConvertFromBase16Char(char base_16) { |
Alpha Left Google
2013/11/08 22:40:02
Can you put this in a helper source file?
pwestin
2013/11/12 22:07:23
Done.
|
+ DCHECK((base_16 >= '0' && base_16 <= '9') || |
+ (base_16 >= 'a' && base_16 <= 'f') || |
+ (base_16 >= 'A' && base_16 <= 'F')); |
+ |
+ if (base_16 >= '0' && base_16 <= '9') { |
+ return base_16 - '0'; |
+ } |
+ if (base_16 >= 'a' && base_16 <= 'f') { |
+ return base_16 - 'a' + 10; |
+ } |
+ return base_16 - 'A' + 10; |
+ } |
+ |
+ std::string ConvertFromBase16String(const std::string base_16) { |
+ std::string compressed; |
+ DCHECK(base_16.size() % 2 == 0) << "Must be a multiple of 2"; |
+ compressed.reserve(base_16.size() / 2); |
+ |
+ for (std::string::const_iterator it = base_16.begin(); it != base_16.end(); |
+ ++it) { |
+ char first_part = ConvertFromBase16Char(*it++); |
+ char second_part = ConvertFromBase16Char(*it); |
+ compressed.push_back((first_part << 4) + second_part); |
+ } |
+ return compressed; |
+ } |
+ |
AudioReceiverConfig audio_receiver_config_; |
VideoReceiverConfig video_receiver_config_; |
AudioSenderConfig audio_sender_config_; |
@@ -541,7 +570,7 @@ TEST_F(End2EndTest, LoopNoLossPcm16) { |
SetupConfig(kPcm16, 32000, false, 1); |
Create(); |
test_receiver_audio_callback_->SetExpectedResult(kAudioSamplingFrequency, 20, |
- 25); |
+ 20); |
int video_start = 1; |
int audio_diff = kFrameTimerMs; |
@@ -862,6 +891,95 @@ TEST_F(End2EndTest, ResetReferenceFrameId) { |
test_receiver_video_callback_->number_times_called()); |
} |
+TEST_F(End2EndTest, CryptoVideo) { |
+ SetupConfig(kPcm16, 32000, false, 1); |
+ |
+ video_sender_config_.aes_iv_mask = |
+ ConvertFromBase16String("1234567890abcdeffedcba0987654321"); |
+ video_sender_config_.aes_key = |
+ ConvertFromBase16String("deadbeefcafeb0b0b0b0cafedeadbeef"); |
+ |
+ video_receiver_config_.aes_iv_mask = video_sender_config_.aes_iv_mask; |
+ video_receiver_config_.aes_key = video_sender_config_.aes_key; |
+ |
+ Create(); |
+ |
+ int frames_counter = 0; |
+ for (; frames_counter < 20; ++frames_counter) { |
+ const base::TimeTicks send_time = testing_clock_.NowTicks(); |
+ |
+ SendVideoFrame(frames_counter, send_time); |
+ |
+ test_receiver_video_callback_->AddExpectedResult(frames_counter, |
+ video_sender_config_.width, video_sender_config_.height, send_time); |
+ |
+ // GetRawVideoFrame will not return the frame until we are close to the |
+ // time in which we should render the frame. |
+ frame_receiver_->GetRawVideoFrame( |
+ base::Bind(&TestReceiverVideoCallback::CheckVideoFrame, |
+ test_receiver_video_callback_)); |
+ RunTasks(kFrameTimerMs); |
+ } |
+ RunTasks(2 * kFrameTimerMs + 1); // Empty the pipeline. |
+ EXPECT_EQ(frames_counter, |
+ test_receiver_video_callback_->number_times_called()); |
+} |
+ |
+ |
+TEST_F(End2EndTest, CryptoAudio) { |
+ SetupConfig(kPcm16, 32000, false, 1); |
+ |
+ audio_sender_config_.aes_iv_mask = |
+ ConvertFromBase16String("abcdeffedcba12345678900987654321"); |
+ audio_sender_config_.aes_key = |
+ ConvertFromBase16String("deadbeefcafecafedeadbeefb0b0b0b0"); |
+ |
+ audio_receiver_config_.aes_iv_mask = audio_sender_config_.aes_iv_mask; |
+ audio_receiver_config_.aes_key = audio_sender_config_.aes_key; |
+ |
+ Create(); |
+ test_receiver_audio_callback_->SetExpectedResult(32000, 18, 20); |
+ |
+ int frames_counter = 0; |
+ for (; frames_counter < 20; ++frames_counter) { |
+ int num_10ms_blocks = 2; |
+ |
+ const base::TimeTicks send_time = testing_clock_.NowTicks(); |
+ |
+ PcmAudioFrame* audio_frame = CreateAudioFrame(num_10ms_blocks, |
+ kSoundFrequency, 32000); |
+ |
+ if (frames_counter != 0) { |
+ // Due to the re-sampler and NetEq in the webrtc AudioCodingModule the |
+ // first samples will be 0 and then slowly ramp up to its real amplitude; |
+ // ignore the first frame. |
+ test_receiver_audio_callback_->AddExpectedResult(audio_frame, |
+ num_10ms_blocks, send_time); |
+ } |
+ frame_input_->InsertRawAudioFrame(audio_frame, send_time, |
+ base::Bind(FrameInput::DeleteAudioFrame, audio_frame)); |
+ |
+ RunTasks(num_10ms_blocks * 10); |
+ |
+ if (frames_counter == 0) { |
+ frame_receiver_->GetRawAudioFrame(num_10ms_blocks, |
+ 32000, |
+ base::Bind(&TestReceiverAudioCallback::IgnoreAudioFrame, |
+ test_receiver_audio_callback_)); |
+ } else { |
+ frame_receiver_->GetRawAudioFrame(num_10ms_blocks, |
+ 32000, |
+ base::Bind(&TestReceiverAudioCallback::CheckPcmAudioFrame, |
+ test_receiver_audio_callback_)); |
+ } |
+ } |
+ RunTasks(2 * kFrameTimerMs + 1); // Empty the pipeline. |
+ EXPECT_EQ(frames_counter - 1, |
+ test_receiver_audio_callback_->number_times_called()); |
+} |
+ |
+ |
+ |
// TODO(pwestin): Add repeatable packet loss test. |
// TODO(pwestin): Add test for misaligned send get calls. |
// TODO(pwestin): Add more tests that does not resample. |