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

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

Issue 10068037: RefCounted types should not have public destructors, content/browser part 1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: MSVC fixes 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
« no previous file with comments | « content/browser/speech/speech_recognizer_impl.h ('k') | content/browser/trace_message_filter.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/bind.h" 8 #include "base/bind.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "content/browser/browser_main_loop.h" 10 #include "content/browser/browser_main_loop.h"
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 DCHECK(recognition_engine_ != NULL); 123 DCHECK(recognition_engine_ != NULL);
124 endpointer_.set_speech_input_complete_silence_length( 124 endpointer_.set_speech_input_complete_silence_length(
125 base::Time::kMicrosecondsPerSecond / 2); 125 base::Time::kMicrosecondsPerSecond / 2);
126 endpointer_.set_long_speech_input_complete_silence_length( 126 endpointer_.set_long_speech_input_complete_silence_length(
127 base::Time::kMicrosecondsPerSecond); 127 base::Time::kMicrosecondsPerSecond);
128 endpointer_.set_long_speech_length(3 * base::Time::kMicrosecondsPerSecond); 128 endpointer_.set_long_speech_length(3 * base::Time::kMicrosecondsPerSecond);
129 endpointer_.StartSession(); 129 endpointer_.StartSession();
130 recognition_engine_->set_delegate(this); 130 recognition_engine_->set_delegate(this);
131 } 131 }
132 132
133 SpeechRecognizerImpl::~SpeechRecognizerImpl() {
134 endpointer_.EndSession();
135 }
136
137 // ------- Methods that trigger Finite State Machine (FSM) events ------------ 133 // ------- Methods that trigger Finite State Machine (FSM) events ------------
138 134
139 // NOTE:all the external events and requests should be enqueued (PostTask), even 135 // NOTE:all the external events and requests should be enqueued (PostTask), even
140 // if they come from the same (IO) thread, in order to preserve the relationship 136 // if they come from the same (IO) thread, in order to preserve the relationship
141 // of causality between events and avoid interleaved event processing due to 137 // of causality between events and avoid interleaved event processing due to
142 // synchronous callbacks. 138 // synchronous callbacks.
143 139
144 void SpeechRecognizerImpl::StartRecognition() { 140 void SpeechRecognizerImpl::StartRecognition() {
145 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 141 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
146 base::Bind(&SpeechRecognizerImpl::DispatchEvent, 142 base::Bind(&SpeechRecognizerImpl::DispatchEvent,
(...skipping 21 matching lines...) Expand all
168 164
169 bool SpeechRecognizerImpl::IsCapturingAudio() const { 165 bool SpeechRecognizerImpl::IsCapturingAudio() const {
170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); // See IsActive(). 166 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); // See IsActive().
171 const bool is_capturing_audio = state_ >= STATE_STARTING && 167 const bool is_capturing_audio = state_ >= STATE_STARTING &&
172 state_ <= STATE_RECOGNIZING; 168 state_ <= STATE_RECOGNIZING;
173 DCHECK((is_capturing_audio && (audio_controller_.get() != NULL)) || 169 DCHECK((is_capturing_audio && (audio_controller_.get() != NULL)) ||
174 (!is_capturing_audio && audio_controller_.get() == NULL)); 170 (!is_capturing_audio && audio_controller_.get() == NULL));
175 return is_capturing_audio; 171 return is_capturing_audio;
176 } 172 }
177 173
174 const SpeechRecognitionEngine&
175 SpeechRecognizerImpl::recognition_engine() const {
176 return *(recognition_engine_.get());
177 }
178
179 SpeechRecognizerImpl::~SpeechRecognizerImpl() {
180 endpointer_.EndSession();
181 }
182
178 // Invoked in the audio thread. 183 // Invoked in the audio thread.
179 void SpeechRecognizerImpl::OnError(AudioInputController* controller, 184 void SpeechRecognizerImpl::OnError(AudioInputController* controller,
180 int error_code) { 185 int error_code) {
181 FSMEventArgs event_args(EVENT_AUDIO_ERROR); 186 FSMEventArgs event_args(EVENT_AUDIO_ERROR);
182 event_args.audio_error_code = error_code; 187 event_args.audio_error_code = error_code;
183 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 188 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
184 base::Bind(&SpeechRecognizerImpl::DispatchEvent, 189 base::Bind(&SpeechRecognizerImpl::DispatchEvent,
185 this, event_args)); 190 this, event_args));
186 } 191 }
187 192
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 620
616 float noise_level = (endpointer_.NoiseLevelDb() - kAudioMeterMinDb) / 621 float noise_level = (endpointer_.NoiseLevelDb() - kAudioMeterMinDb) /
617 (kAudioMeterDbRange / kAudioMeterRangeMaxUnclipped); 622 (kAudioMeterDbRange / kAudioMeterRangeMaxUnclipped);
618 noise_level = std::min(std::max(0.0f, noise_level), 623 noise_level = std::min(std::max(0.0f, noise_level),
619 kAudioMeterRangeMaxUnclipped); 624 kAudioMeterRangeMaxUnclipped);
620 625
621 listener_->OnAudioLevelsChange( 626 listener_->OnAudioLevelsChange(
622 session_id_, clip_detected ? 1.0f : audio_level_, noise_level); 627 session_id_, clip_detected ? 1.0f : audio_level_, noise_level);
623 } 628 }
624 629
625 const SpeechRecognitionEngine&
626 SpeechRecognizerImpl::recognition_engine() const {
627 return *(recognition_engine_.get());
628 }
629
630 void SpeechRecognizerImpl::SetAudioManagerForTesting( 630 void SpeechRecognizerImpl::SetAudioManagerForTesting(
631 AudioManager* audio_manager) { 631 AudioManager* audio_manager) {
632 testing_audio_manager_ = audio_manager; 632 testing_audio_manager_ = audio_manager;
633 } 633 }
634 634
635 SpeechRecognizerImpl::FSMEventArgs::FSMEventArgs(FSMEvent event_value) 635 SpeechRecognizerImpl::FSMEventArgs::FSMEventArgs(FSMEvent event_value)
636 : event(event_value), 636 : event(event_value),
637 audio_error_code(0), 637 audio_error_code(0),
638 audio_data(NULL), 638 audio_data(NULL),
639 engine_error(content::SPEECH_RECOGNITION_ERROR_NONE) { 639 engine_error(content::SPEECH_RECOGNITION_ERROR_NONE) {
640 } 640 }
641 641
642 SpeechRecognizerImpl::FSMEventArgs::~FSMEventArgs() { 642 SpeechRecognizerImpl::FSMEventArgs::~FSMEventArgs() {
643 } 643 }
644 644
645 } // namespace speech 645 } // namespace speech
OLDNEW
« no previous file with comments | « content/browser/speech/speech_recognizer_impl.h ('k') | content/browser/trace_message_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698