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

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

Issue 9861019: Speech refactoring: Turned AudioChunk into a refcounted class (CL1.4) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/bind.h" 7 #include "base/bind.h"
8 #include "base/time.h" 8 #include "base/time.h"
9 #include "content/browser/browser_main_loop.h" 9 #include "content/browser/browser_main_loop.h"
10 #include "content/browser/speech/audio_buffer.h" 10 #include "content/browser/speech/audio_buffer.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 if (!audio_controller_.get()) 204 if (!audio_controller_.get())
205 return; 205 return;
206 206
207 InformErrorAndAbortRecognition(content::SPEECH_RECOGNITION_ERROR_AUDIO); 207 InformErrorAndAbortRecognition(content::SPEECH_RECOGNITION_ERROR_AUDIO);
208 } 208 }
209 209
210 void SpeechRecognizerImpl::OnData(AudioInputController* controller, 210 void SpeechRecognizerImpl::OnData(AudioInputController* controller,
211 const uint8* data, uint32 size) { 211 const uint8* data, uint32 size) {
212 if (size == 0) // This could happen when recording stops and is normal. 212 if (size == 0) // This could happen when recording stops and is normal.
213 return; 213 return;
214 AudioChunk* raw_audio = new AudioChunk(data, static_cast<size_t>(size), 214 scoped_refptr<AudioChunk> raw_audio(
215 kNumBitsPerAudioSample / 8); 215 new AudioChunk(data,
216 static_cast<size_t>(size),
217 kNumBitsPerAudioSample / 8));
216 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 218 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
217 base::Bind(&SpeechRecognizerImpl::HandleOnData, 219 base::Bind(&SpeechRecognizerImpl::HandleOnData,
218 this, raw_audio)); 220 this, raw_audio));
219 } 221 }
220 222
221 void SpeechRecognizerImpl::HandleOnData(AudioChunk* raw_audio) { 223 void SpeechRecognizerImpl::HandleOnData(scoped_refptr<AudioChunk> raw_audio) {
222 scoped_ptr<AudioChunk> free_raw_audio_on_return(raw_audio);
223 // Check if we are still recording and if not discard this buffer, as 224 // Check if we are still recording and if not discard this buffer, as
224 // recording might have been stopped after this buffer was posted to the queue 225 // recording might have been stopped after this buffer was posted to the queue
225 // by |OnData|. 226 // by |OnData|.
226 if (!audio_controller_.get()) 227 if (!audio_controller_.get())
227 return; 228 return;
228 229
229 bool speech_was_heard_before_packet = endpointer_.DidStartReceivingSpeech(); 230 bool speech_was_heard_before_packet = endpointer_.DidStartReceivingSpeech();
230 231
231 float rms; 232 float rms;
232 endpointer_.ProcessAudio(*raw_audio, &rms); 233 endpointer_.ProcessAudio(*raw_audio, &rms);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 return *(recognition_engine_.get()); 348 return *(recognition_engine_.get());
348 } 349 }
349 350
350 void SpeechRecognizerImpl::SetAudioManagerForTesting( 351 void SpeechRecognizerImpl::SetAudioManagerForTesting(
351 AudioManager* audio_manager) { 352 AudioManager* audio_manager) {
352 testing_audio_manager_ = audio_manager; 353 testing_audio_manager_ = audio_manager;
353 } 354 }
354 355
355 356
356 } // namespace speech 357 } // namespace speech
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698