OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "base/logging.h" | |
6 #include "content/renderer/media/webrtc_local_audio_source_provider.h" | |
7 #include "media/audio/audio_parameters.h" | |
8 #include "media/base/audio_bus.h" | |
9 #include "testing/gtest/include/gtest/gtest.h" | |
10 | |
11 namespace content { | |
12 | |
13 class WebRtcLocalAudioSourceProviderTest : public testing::Test { | |
14 protected: | |
15 virtual void SetUp() OVERRIDE { | |
16 source_params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | |
17 media::CHANNEL_LAYOUT_MONO, 1, 0, 48000, 16, 480); | |
18 sink_params_.Reset(media::AudioParameters::AUDIO_PCM_LOW_LATENCY, | |
19 media::CHANNEL_LAYOUT_STEREO, 2, 0, 44100, 16, 128); | |
tommi (sloooow) - chröme
2013/09/12 20:40:55
use the webaudio buffer size constant?
| |
20 source_bus_ = media::AudioBus::Create(source_params_); | |
21 sink_bus_ = media::AudioBus::Create(sink_params_); | |
22 source_provider_.reset(new WebRtcLocalAudioSourceProvider()); | |
23 source_provider_->SetSinkParamsForTesting(sink_params_); | |
24 source_provider_->Initialize(source_params_); | |
25 } | |
26 | |
27 media::AudioParameters source_params_; | |
28 media::AudioParameters sink_params_; | |
29 scoped_ptr<media::AudioBus> source_bus_; | |
30 scoped_ptr<media::AudioBus> sink_bus_; | |
31 scoped_ptr<WebRtcLocalAudioSourceProvider> source_provider_; | |
32 }; | |
33 | |
34 TEST_F(WebRtcLocalAudioSourceProviderTest, VerifyDataFlow) { | |
35 // Point the WebVector into memory owned by |sink_bus_|. | |
36 WebKit::WebVector<float*> audio_data( | |
37 static_cast<size_t>(sink_bus_->channels())); | |
38 for (size_t i = 0; i < audio_data.size(); ++i) | |
39 audio_data[i] = sink_bus_->channel(i); | |
40 | |
41 // Enable the |source_provider_| by asking for data. This will inject | |
42 // source_params_.frames_per_buffer() of zero into the resampler since there | |
43 // no available data in the FIFO. | |
44 source_provider_->provideInput(audio_data, sink_params_.frames_per_buffer()); | |
45 EXPECT_TRUE(sink_bus_->channel(0)[0] == 0); | |
46 | |
47 // Set the value of source data to be 1. | |
48 for (int i = 0; i < source_params_.frames_per_buffer(); ++i) { | |
49 source_bus_->channel(0)[i] = 1; | |
50 } | |
51 | |
52 // Deliver data to |source_provider_|. | |
53 source_provider_->DeliverData(source_bus_.get(), 0, 0, false); | |
54 | |
55 // Consume the first packet in the resampler, which contains only zero. | |
56 // And the consumption of the data will trigger pulling the real packet from | |
57 // the source provider FIFO into th e resampler. | |
tommi (sloooow) - chröme
2013/09/12 20:40:55
the resampler
no longer working on chromium
2013/09/17 13:08:01
Done.
| |
58 // Note that we need to count in the provideInput() call a few lines above. | |
59 for (int i = sink_params_.frames_per_buffer(); | |
60 i < source_params_.frames_per_buffer(); | |
61 i += sink_params_.frames_per_buffer()) { | |
62 sink_bus_->Zero(); | |
63 source_provider_->provideInput(audio_data, | |
64 sink_params_.frames_per_buffer()); | |
65 EXPECT_DOUBLE_EQ(0.0, sink_bus_->channel(0)[0]); | |
66 EXPECT_DOUBLE_EQ(0.0, sink_bus_->channel(1)[0]); | |
67 } | |
68 | |
69 // Prepare the second packet for featching. | |
70 source_provider_->DeliverData(source_bus_.get(), 0, 0, false); | |
71 | |
72 // Verify the packets. | |
73 for (int i = 0; i < source_params_.frames_per_buffer(); | |
74 i += sink_params_.frames_per_buffer()) { | |
75 sink_bus_->Zero(); | |
76 source_provider_->provideInput(audio_data, | |
77 sink_params_.frames_per_buffer()); | |
78 EXPECT_GT(sink_bus_->channel(0)[0], 0); | |
79 EXPECT_GT(sink_bus_->channel(1)[0], 0); | |
80 EXPECT_DOUBLE_EQ(sink_bus_->channel(0)[0], sink_bus_->channel(1)[0]); | |
81 } | |
82 } | |
83 | |
84 TEST_F(WebRtcLocalAudioSourceProviderTest, VerifyAudioProcessingParams) { | |
85 // Point the WebVector into memory owned by |sink_bus_|. | |
86 WebKit::WebVector<float*> audio_data( | |
87 static_cast<size_t>(sink_bus_->channels())); | |
88 for (size_t i = 0; i < audio_data.size(); ++i) | |
89 audio_data[i] = sink_bus_->channel(i); | |
90 | |
91 // Enable the source provider. | |
92 source_provider_->provideInput(audio_data, sink_params_.frames_per_buffer()); | |
93 | |
94 // Deliver data to |source_provider_| with audio processing params. | |
95 int source_delay = 5; | |
96 int source_volume = 255; | |
97 bool source_key_pressed = true; | |
98 source_provider_->DeliverData(source_bus_.get(), source_delay, | |
99 source_volume, source_key_pressed); | |
100 | |
101 int delay = 0, volume = 0; | |
102 bool key_pressed = false; | |
103 source_provider_->GetAudioProcessingParams(&delay, &volume, &key_pressed); | |
104 EXPECT_EQ(volume, source_volume); | |
105 EXPECT_EQ(key_pressed, source_key_pressed); | |
106 int expected_delay = source_delay + static_cast<int>( | |
107 source_bus_->frames() / source_params_.sample_rate() + 0.5); | |
108 EXPECT_GE(delay, expected_delay); | |
109 | |
110 // Sleep a few ms to simulate processing time. This should increase the delay | |
111 // value as time passes. | |
112 int cached_delay = delay; | |
113 const int kSleepMs = 10; | |
114 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(kSleepMs)); | |
115 source_provider_->GetAudioProcessingParams(&delay, &volume, &key_pressed); | |
116 EXPECT_GT(delay, cached_delay); | |
117 } | |
118 | |
119 } // namespace content | |
OLD | NEW |