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

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

Issue 344583002: Modifies AudioInputCallback::OnData and use media::AudioBus instead of plain byte vector (Relanding) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added extra non-pure OnData API 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();
136 scoped_ptr<uint8[]> audio_buffer(new uint8[buffer_size]); 137 scoped_ptr<uint8[]> audio_buffer(new uint8[buffer_size]);
137 if (fill_with_noise) { 138 if (fill_with_noise) {
138 for (size_t i = 0; i < buffer_size; ++i) 139 for (size_t i = 0; i < buffer_size; ++i)
139 audio_buffer[i] = static_cast<uint8>(127 * sin(i * 3.14F / 140 audio_buffer[i] = static_cast<uint8>(127 * sin(i * 3.14F /
140 (16 * buffer_size))); 141 (16 * buffer_size)));
141 } else { 142 } else {
142 memset(audio_buffer.get(), 0, buffer_size); 143 memset(audio_buffer.get(), 0, buffer_size);
143 } 144 }
144 controller->event_handler()->OnData(controller, 145
145 audio_buffer.get(), 146 scoped_ptr<media::AudioBus> audio_bus =
146 buffer_size); 147 media::AudioBus::Create(audio_params);
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());
147 } 152 }
148 153
149 void FeedAudioController(int duration_ms, bool feed_with_noise) { 154 void FeedAudioController(int duration_ms, bool feed_with_noise) {
150 media::TestAudioInputController* controller = 155 media::TestAudioInputController* controller =
151 test_audio_input_controller_factory_.controller(); 156 test_audio_input_controller_factory_.controller();
152 ASSERT_TRUE(controller); 157 ASSERT_TRUE(controller);
153 const media::AudioParameters& audio_params = controller->audio_parameters(); 158 const media::AudioParameters& audio_params = controller->audio_parameters();
154 const size_t buffer_size = audio_params.GetBytesPerBuffer(); 159 const size_t buffer_size = audio_params.GetBytesPerBuffer();
155 const int ms_per_buffer = audio_params.frames_per_buffer() * 1000 / 160 const int ms_per_buffer = audio_params.frames_per_buffer() * 1000 /
156 audio_params.sample_rate(); 161 audio_params.sample_rate();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 198
194 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, OneShotRecognition) { 199 IN_PROC_BROWSER_TEST_F(SpeechRecognitionBrowserTest, OneShotRecognition) {
195 NavigateToURLBlockUntilNavigationsComplete( 200 NavigateToURLBlockUntilNavigationsComplete(
196 shell(), GetTestUrlFromFragment("oneshot"), 2); 201 shell(), GetTestUrlFromFragment("oneshot"), 2);
197 202
198 EXPECT_EQ(kClientDisconnected, streaming_server_state()); 203 EXPECT_EQ(kClientDisconnected, streaming_server_state());
199 EXPECT_EQ("goodresult1", GetPageFragment()); 204 EXPECT_EQ("goodresult1", GetPageFragment());
200 } 205 }
201 206
202 } // namespace content 207 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/audio_input_sync_writer.cc ('k') | content/browser/speech/speech_recognizer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698