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 #include "base/logging.h" | 5 #include "base/logging.h" |
6 #include "content/renderer/media/webrtc_local_audio_source_provider.h" | 6 #include "content/renderer/media/webrtc_local_audio_source_provider.h" |
7 #include "media/audio/audio_parameters.h" | 7 #include "media/audio/audio_parameters.h" |
8 #include "media/base/audio_bus.h" | 8 #include "media/base/audio_bus.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 media::AudioParameters source_params_; | 29 media::AudioParameters source_params_; |
30 media::AudioParameters sink_params_; | 30 media::AudioParameters sink_params_; |
31 scoped_ptr<media::AudioBus> source_bus_; | 31 scoped_ptr<media::AudioBus> source_bus_; |
32 scoped_ptr<media::AudioBus> sink_bus_; | 32 scoped_ptr<media::AudioBus> sink_bus_; |
33 scoped_ptr<WebRtcLocalAudioSourceProvider> source_provider_; | 33 scoped_ptr<WebRtcLocalAudioSourceProvider> source_provider_; |
34 }; | 34 }; |
35 | 35 |
36 TEST_F(WebRtcLocalAudioSourceProviderTest, VerifyDataFlow) { | 36 TEST_F(WebRtcLocalAudioSourceProviderTest, VerifyDataFlow) { |
37 // Point the WebVector into memory owned by |sink_bus_|. | 37 // Point the WebVector into memory owned by |sink_bus_|. |
38 WebKit::WebVector<float*> audio_data( | 38 blink::WebVector<float*> audio_data( |
39 static_cast<size_t>(sink_bus_->channels())); | 39 static_cast<size_t>(sink_bus_->channels())); |
40 for (size_t i = 0; i < audio_data.size(); ++i) | 40 for (size_t i = 0; i < audio_data.size(); ++i) |
41 audio_data[i] = sink_bus_->channel(i); | 41 audio_data[i] = sink_bus_->channel(i); |
42 | 42 |
43 // Enable the |source_provider_| by asking for data. This will inject | 43 // Enable the |source_provider_| by asking for data. This will inject |
44 // source_params_.frames_per_buffer() of zero into the resampler since there | 44 // source_params_.frames_per_buffer() of zero into the resampler since there |
45 // no available data in the FIFO. | 45 // no available data in the FIFO. |
46 source_provider_->provideInput(audio_data, sink_params_.frames_per_buffer()); | 46 source_provider_->provideInput(audio_data, sink_params_.frames_per_buffer()); |
47 EXPECT_TRUE(sink_bus_->channel(0)[0] == 0); | 47 EXPECT_TRUE(sink_bus_->channel(0)[0] == 0); |
48 | 48 |
(...skipping 29 matching lines...) Expand all Loading... |
78 source_provider_->provideInput(audio_data, | 78 source_provider_->provideInput(audio_data, |
79 sink_params_.frames_per_buffer()); | 79 sink_params_.frames_per_buffer()); |
80 EXPECT_GT(sink_bus_->channel(0)[0], 0); | 80 EXPECT_GT(sink_bus_->channel(0)[0], 0); |
81 EXPECT_GT(sink_bus_->channel(1)[0], 0); | 81 EXPECT_GT(sink_bus_->channel(1)[0], 0); |
82 EXPECT_DOUBLE_EQ(sink_bus_->channel(0)[0], sink_bus_->channel(1)[0]); | 82 EXPECT_DOUBLE_EQ(sink_bus_->channel(0)[0], sink_bus_->channel(1)[0]); |
83 } | 83 } |
84 } | 84 } |
85 | 85 |
86 TEST_F(WebRtcLocalAudioSourceProviderTest, VerifyAudioProcessingParams) { | 86 TEST_F(WebRtcLocalAudioSourceProviderTest, VerifyAudioProcessingParams) { |
87 // Point the WebVector into memory owned by |sink_bus_|. | 87 // Point the WebVector into memory owned by |sink_bus_|. |
88 WebKit::WebVector<float*> audio_data( | 88 blink::WebVector<float*> audio_data( |
89 static_cast<size_t>(sink_bus_->channels())); | 89 static_cast<size_t>(sink_bus_->channels())); |
90 for (size_t i = 0; i < audio_data.size(); ++i) | 90 for (size_t i = 0; i < audio_data.size(); ++i) |
91 audio_data[i] = sink_bus_->channel(i); | 91 audio_data[i] = sink_bus_->channel(i); |
92 | 92 |
93 // Enable the source provider. | 93 // Enable the source provider. |
94 source_provider_->provideInput(audio_data, sink_params_.frames_per_buffer()); | 94 source_provider_->provideInput(audio_data, sink_params_.frames_per_buffer()); |
95 | 95 |
96 // Deliver data to |source_provider_| with audio processing params. | 96 // Deliver data to |source_provider_| with audio processing params. |
97 int source_delay = 5; | 97 int source_delay = 5; |
98 int source_volume = 255; | 98 int source_volume = 255; |
(...skipping 13 matching lines...) Expand all Loading... |
112 // Sleep a few ms to simulate processing time. This should increase the delay | 112 // Sleep a few ms to simulate processing time. This should increase the delay |
113 // value as time passes. | 113 // value as time passes. |
114 int cached_delay = delay; | 114 int cached_delay = delay; |
115 const int kSleepMs = 10; | 115 const int kSleepMs = 10; |
116 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(kSleepMs)); | 116 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(kSleepMs)); |
117 source_provider_->GetAudioProcessingParams(&delay, &volume, &key_pressed); | 117 source_provider_->GetAudioProcessingParams(&delay, &volume, &key_pressed); |
118 EXPECT_GT(delay, cached_delay); | 118 EXPECT_GT(delay, cached_delay); |
119 } | 119 } |
120 | 120 |
121 } // namespace content | 121 } // namespace content |
OLD | NEW |