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

Side by Side Diff: trunk/src/content/browser/speech/speech_recognizer_impl.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 (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "content/browser/speech/speech_recognizer_impl.h" 5 #include "content/browser/speech/speech_recognizer_impl.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/time/time.h" 9 #include "base/time/time.h"
10 #include "content/browser/browser_main_loop.h" 10 #include "content/browser/browser_main_loop.h"
(...skipping 19 matching lines...) Expand all
30 // Private class which encapsulates the audio converter and the 30 // Private class which encapsulates the audio converter and the
31 // AudioConverter::InputCallback. It handles resampling, buffering and 31 // AudioConverter::InputCallback. It handles resampling, buffering and
32 // channel mixing between input and output parameters. 32 // channel mixing between input and output parameters.
33 class SpeechRecognizerImpl::OnDataConverter 33 class SpeechRecognizerImpl::OnDataConverter
34 : public media::AudioConverter::InputCallback { 34 : public media::AudioConverter::InputCallback {
35 public: 35 public:
36 OnDataConverter(const AudioParameters& input_params, 36 OnDataConverter(const AudioParameters& input_params,
37 const AudioParameters& output_params); 37 const AudioParameters& output_params);
38 virtual ~OnDataConverter(); 38 virtual ~OnDataConverter();
39 39
40 // Converts input audio |data| bus into an AudioChunk where the input format 40 // Converts input |data| buffer into an AudioChunk where the input format
41 // is given by |input_parameters_| and the output format by 41 // is given by |input_parameters_| and the output format by
42 // |output_parameters_|. 42 // |output_parameters_|.
43 scoped_refptr<AudioChunk> Convert(const AudioBus* data); 43 scoped_refptr<AudioChunk> Convert(const uint8* data, size_t size);
44 44
45 private: 45 private:
46 // media::AudioConverter::InputCallback implementation. 46 // media::AudioConverter::InputCallback implementation.
47 virtual double ProvideInput(AudioBus* dest, 47 virtual double ProvideInput(AudioBus* dest,
48 base::TimeDelta buffer_delay) OVERRIDE; 48 base::TimeDelta buffer_delay) OVERRIDE;
49 49
50 // Handles resampling, buffering, and channel mixing between input and output 50 // Handles resampling, buffering, and channel mixing between input and output
51 // parameters. 51 // parameters.
52 AudioConverter audio_converter_; 52 AudioConverter audio_converter_;
53 53
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 audio_converter_.AddInput(this); 125 audio_converter_.AddInput(this);
126 } 126 }
127 127
128 SpeechRecognizerImpl::OnDataConverter::~OnDataConverter() { 128 SpeechRecognizerImpl::OnDataConverter::~OnDataConverter() {
129 // It should now be safe to unregister the converter since no more OnData() 129 // It should now be safe to unregister the converter since no more OnData()
130 // callbacks are outstanding at this point. 130 // callbacks are outstanding at this point.
131 audio_converter_.RemoveInput(this); 131 audio_converter_.RemoveInput(this);
132 } 132 }
133 133
134 scoped_refptr<AudioChunk> SpeechRecognizerImpl::OnDataConverter::Convert( 134 scoped_refptr<AudioChunk> SpeechRecognizerImpl::OnDataConverter::Convert(
135 const AudioBus* data) { 135 const uint8* data, size_t size) {
136 CHECK_EQ(data->frames(), input_parameters_.frames_per_buffer()); 136 CHECK_EQ(size, static_cast<size_t>(input_parameters_.GetBytesPerBuffer()));
137 137
138 data->CopyTo(input_bus_.get()); 138 input_bus_->FromInterleaved(
139 data, input_bus_->frames(), input_parameters_.bits_per_sample() / 8);
139 140
140 waiting_for_input_ = true; 141 waiting_for_input_ = true;
141 audio_converter_.Convert(output_bus_.get()); 142 audio_converter_.Convert(output_bus_.get());
142 143
143 output_bus_->ToInterleaved( 144 output_bus_->ToInterleaved(
144 output_bus_->frames(), output_parameters_.bits_per_sample() / 8, 145 output_bus_->frames(), output_parameters_.bits_per_sample() / 8,
145 converted_data_.get()); 146 converted_data_.get());
146 147
147 // TODO(primiano): Refactor AudioChunk to avoid the extra-copy here 148 // TODO(primiano): Refactor AudioChunk to avoid the extra-copy here
148 // (see http://crbug.com/249316 for details). 149 // (see http://crbug.com/249316 for details).
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 // Invoked in the audio thread. 265 // Invoked in the audio thread.
265 void SpeechRecognizerImpl::OnError(AudioInputController* controller, 266 void SpeechRecognizerImpl::OnError(AudioInputController* controller,
266 media::AudioInputController::ErrorCode error_code) { 267 media::AudioInputController::ErrorCode error_code) {
267 FSMEventArgs event_args(EVENT_AUDIO_ERROR); 268 FSMEventArgs event_args(EVENT_AUDIO_ERROR);
268 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 269 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
269 base::Bind(&SpeechRecognizerImpl::DispatchEvent, 270 base::Bind(&SpeechRecognizerImpl::DispatchEvent,
270 this, event_args)); 271 this, event_args));
271 } 272 }
272 273
273 void SpeechRecognizerImpl::OnData(AudioInputController* controller, 274 void SpeechRecognizerImpl::OnData(AudioInputController* controller,
274 const AudioBus* data) { 275 const uint8* data, uint32 size) {
276 if (size == 0) // This could happen when audio capture stops and is normal.
277 return;
278
275 // Convert audio from native format to fixed format used by WebSpeech. 279 // Convert audio from native format to fixed format used by WebSpeech.
276 FSMEventArgs event_args(EVENT_AUDIO_DATA); 280 FSMEventArgs event_args(EVENT_AUDIO_DATA);
277 event_args.audio_data = audio_converter_->Convert(data); 281 event_args.audio_data = audio_converter_->Convert(data, size);
278 282
279 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 283 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
280 base::Bind(&SpeechRecognizerImpl::DispatchEvent, 284 base::Bind(&SpeechRecognizerImpl::DispatchEvent,
281 this, event_args)); 285 this, event_args));
282 } 286 }
283 287
284 void SpeechRecognizerImpl::OnAudioClosed(AudioInputController*) {} 288 void SpeechRecognizerImpl::OnAudioClosed(AudioInputController*) {}
285 289
286 void SpeechRecognizerImpl::OnSpeechRecognitionEngineResults( 290 void SpeechRecognizerImpl::OnSpeechRecognitionEngineResults(
287 const SpeechRecognitionResults& results) { 291 const SpeechRecognitionResults& results) {
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 SpeechRecognizerImpl::FSMEventArgs::FSMEventArgs(FSMEvent event_value) 812 SpeechRecognizerImpl::FSMEventArgs::FSMEventArgs(FSMEvent event_value)
809 : event(event_value), 813 : event(event_value),
810 audio_data(NULL), 814 audio_data(NULL),
811 engine_error(SPEECH_RECOGNITION_ERROR_NONE) { 815 engine_error(SPEECH_RECOGNITION_ERROR_NONE) {
812 } 816 }
813 817
814 SpeechRecognizerImpl::FSMEventArgs::~FSMEventArgs() { 818 SpeechRecognizerImpl::FSMEventArgs::~FSMEventArgs() {
815 } 819 }
816 820
817 } // namespace content 821 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698