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

Side by Side Diff: trunk/src/content/browser/speech/speech_recognition_browsertest.cc

Issue 335343004: Revert 277794 "Modifies AudioInputCallback::OnData and use media..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 6 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
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 <list> 5 #include <list>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 test_audio_input_controller_factory_.set_delegate(NULL); 126 test_audio_input_controller_factory_.set_delegate(NULL);
127 mock_streaming_server_.reset(); 127 mock_streaming_server_.reset();
128 } 128 }
129 129
130 private: 130 private:
131 static void FeedSingleBufferToAudioController( 131 static void FeedSingleBufferToAudioController(
132 scoped_refptr<media::TestAudioInputController> controller, 132 scoped_refptr<media::TestAudioInputController> controller,
133 size_t buffer_size, 133 size_t buffer_size,
134 bool fill_with_noise) { 134 bool fill_with_noise) {
135 DCHECK(controller.get()); 135 DCHECK(controller.get());
136 const media::AudioParameters& audio_params = controller->audio_parameters();
137 scoped_ptr<uint8[]> audio_buffer(new uint8[buffer_size]); 136 scoped_ptr<uint8[]> audio_buffer(new uint8[buffer_size]);
138 if (fill_with_noise) { 137 if (fill_with_noise) {
139 for (size_t i = 0; i < buffer_size; ++i) 138 for (size_t i = 0; i < buffer_size; ++i)
140 audio_buffer[i] = static_cast<uint8>(127 * sin(i * 3.14F / 139 audio_buffer[i] = static_cast<uint8>(127 * sin(i * 3.14F /
141 (16 * buffer_size))); 140 (16 * buffer_size)));
142 } else { 141 } else {
143 memset(audio_buffer.get(), 0, buffer_size); 142 memset(audio_buffer.get(), 0, buffer_size);
144 } 143 }
145 144 controller->event_handler()->OnData(controller,
146 scoped_ptr<media::AudioBus> audio_bus = 145 audio_buffer.get(),
147 media::AudioBus::Create(audio_params); 146 buffer_size);
148 audio_bus->FromInterleaved(&audio_buffer.get()[0],
149 audio_bus->frames(),
150 audio_params.bits_per_sample() / 8);
151 controller->event_handler()->OnData(controller, audio_bus.get());
152 } 147 }
153 148
154 void FeedAudioController(int duration_ms, bool feed_with_noise) { 149 void FeedAudioController(int duration_ms, bool feed_with_noise) {
155 media::TestAudioInputController* controller = 150 media::TestAudioInputController* controller =
156 test_audio_input_controller_factory_.controller(); 151 test_audio_input_controller_factory_.controller();
157 ASSERT_TRUE(controller); 152 ASSERT_TRUE(controller);
158 const media::AudioParameters& audio_params = controller->audio_parameters(); 153 const media::AudioParameters& audio_params = controller->audio_parameters();
159 const size_t buffer_size = audio_params.GetBytesPerBuffer(); 154 const size_t buffer_size = audio_params.GetBytesPerBuffer();
160 const int ms_per_buffer = audio_params.frames_per_buffer() * 1000 / 155 const int ms_per_buffer = audio_params.frames_per_buffer() * 1000 /
161 audio_params.sample_rate(); 156 audio_params.sample_rate();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 193
199 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, OneShotRecognition) { 194 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, OneShotRecognition) {
200 NavigateToURLBlockUntilNavigationsComplete( 195 NavigateToURLBlockUntilNavigationsComplete(
201 shell(), GetTestUrlFromFragment("oneshot"), 2); 196 shell(), GetTestUrlFromFragment("oneshot"), 2);
202 197
203 EXPECT_EQ(kClientDisconnected, streaming_server_state()); 198 EXPECT_EQ(kClientDisconnected, streaming_server_state());
204 EXPECT_EQ("goodresult1", GetPageFragment()); 199 EXPECT_EQ("goodresult1", GetPageFragment());
205 } 200 }
206 201
207 } // namespace content 202 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698