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

Side by Side Diff: content/renderer/media/webrtc_local_audio_source_provider_unittest.cc

Issue 23691038: Switch LiveAudio to source provider solution. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixed the android bot Created 7 years, 3 months 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 | Annotate | Revision Log
OLDNEW
(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(
19 media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
20 media::CHANNEL_LAYOUT_STEREO, 2, 0, 44100, 16,
21 WebRtcLocalAudioSourceProvider::kWebAudioRenderBufferSize);
22 source_bus_ = media::AudioBus::Create(source_params_);
23 sink_bus_ = media::AudioBus::Create(sink_params_);
24 source_provider_.reset(new WebRtcLocalAudioSourceProvider());
25 source_provider_->SetSinkParamsForTesting(sink_params_);
26 source_provider_->Initialize(source_params_);
27 }
28
29 media::AudioParameters source_params_;
30 media::AudioParameters sink_params_;
31 scoped_ptr<media::AudioBus> source_bus_;
32 scoped_ptr<media::AudioBus> sink_bus_;
33 scoped_ptr<WebRtcLocalAudioSourceProvider> source_provider_;
34 };
35
36 TEST_F(WebRtcLocalAudioSourceProviderTest, VerifyDataFlow) {
37 // Point the WebVector into memory owned by |sink_bus_|.
38 WebKit::WebVector<float*> audio_data(
39 static_cast<size_t>(sink_bus_->channels()));
40 for (size_t i = 0; i < audio_data.size(); ++i)
41 audio_data[i] = sink_bus_->channel(i);
42
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
45 // no available data in the FIFO.
46 source_provider_->provideInput(audio_data, sink_params_.frames_per_buffer());
47 EXPECT_TRUE(sink_bus_->channel(0)[0] == 0);
48
49 // Set the value of source data to be 1.
50 for (int i = 0; i < source_params_.frames_per_buffer(); ++i) {
51 source_bus_->channel(0)[i] = 1;
52 }
53
54 // Deliver data to |source_provider_|.
55 source_provider_->DeliverData(source_bus_.get(), 0, 0, false);
56
57 // Consume the first packet in the resampler, which contains only zero.
58 // And the consumption of the data will trigger pulling the real packet from
59 // the source provider FIFO into the resampler.
60 // Note that we need to count in the provideInput() call a few lines above.
61 for (int i = sink_params_.frames_per_buffer();
62 i < source_params_.frames_per_buffer();
63 i += sink_params_.frames_per_buffer()) {
64 sink_bus_->Zero();
65 source_provider_->provideInput(audio_data,
66 sink_params_.frames_per_buffer());
67 EXPECT_DOUBLE_EQ(0.0, sink_bus_->channel(0)[0]);
68 EXPECT_DOUBLE_EQ(0.0, sink_bus_->channel(1)[0]);
69 }
70
71 // Prepare the second packet for featching.
72 source_provider_->DeliverData(source_bus_.get(), 0, 0, false);
73
74 // Verify the packets.
75 for (int i = 0; i < source_params_.frames_per_buffer();
76 i += sink_params_.frames_per_buffer()) {
77 sink_bus_->Zero();
78 source_provider_->provideInput(audio_data,
79 sink_params_.frames_per_buffer());
80 EXPECT_GT(sink_bus_->channel(0)[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]);
83 }
84 }
85
86 TEST_F(WebRtcLocalAudioSourceProviderTest, VerifyAudioProcessingParams) {
87 // Point the WebVector into memory owned by |sink_bus_|.
88 WebKit::WebVector<float*> audio_data(
89 static_cast<size_t>(sink_bus_->channels()));
90 for (size_t i = 0; i < audio_data.size(); ++i)
91 audio_data[i] = sink_bus_->channel(i);
92
93 // Enable the source provider.
94 source_provider_->provideInput(audio_data, sink_params_.frames_per_buffer());
95
96 // Deliver data to |source_provider_| with audio processing params.
97 int source_delay = 5;
98 int source_volume = 255;
99 bool source_key_pressed = true;
100 source_provider_->DeliverData(source_bus_.get(), source_delay,
101 source_volume, source_key_pressed);
102
103 int delay = 0, volume = 0;
104 bool key_pressed = false;
105 source_provider_->GetAudioProcessingParams(&delay, &volume, &key_pressed);
106 EXPECT_EQ(volume, source_volume);
107 EXPECT_EQ(key_pressed, source_key_pressed);
108 int expected_delay = source_delay + static_cast<int>(
109 source_bus_->frames() / source_params_.sample_rate() + 0.5);
110 EXPECT_GE(delay, expected_delay);
111
112 // Sleep a few ms to simulate processing time. This should increase the delay
113 // value as time passes.
114 int cached_delay = delay;
115 const int kSleepMs = 10;
116 base::PlatformThread::Sleep(base::TimeDelta::FromSeconds(kSleepMs));
117 source_provider_->GetAudioProcessingParams(&delay, &volume, &key_pressed);
118 EXPECT_GT(delay, cached_delay);
119 }
120
121 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/webrtc_local_audio_source_provider.cc ('k') | content/renderer/media/webrtc_local_audio_track.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698