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

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

Issue 549373003: Binding media stream audio track to speech recognition [browser] Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Introduce SpeechRecognitionAudioReceiver Created 6 years, 2 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
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_recognition_manager_impl.h" 5 #include "content/browser/speech/speech_recognition_manager_impl.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "content/browser/browser_main_loop.h" 8 #include "content/browser/browser_main_loop.h"
9 #include "content/browser/renderer_host/media/media_stream_manager.h" 9 #include "content/browser/renderer_host/media/media_stream_manager.h"
10 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" 10 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 config.url_request_context_getter.get()); 142 config.url_request_context_getter.get());
143 } 143 }
144 144
145 google_remote_engine->SetConfig(remote_engine_config); 145 google_remote_engine->SetConfig(remote_engine_config);
146 146
147 session->recognizer = new SpeechRecognizerImpl( 147 session->recognizer = new SpeechRecognizerImpl(
148 this, 148 this,
149 session_id, 149 session_id,
150 config.continuous, 150 config.continuous,
151 config.interim_results, 151 config.interim_results,
152 config.using_audio_track,
153 config.peer_process_handle,
152 google_remote_engine); 154 google_remote_engine);
153 #else 155 #else
154 session->recognizer = new SpeechRecognizerImplAndroid(this, session_id); 156 session->recognizer = new SpeechRecognizerImplAndroid(this, session_id);
155 #endif 157 #endif
156 return session_id; 158 return session_id;
157 } 159 }
158 160
159 void SpeechRecognitionManagerImpl::StartSession(int session_id) { 161 void SpeechRecognitionManagerImpl::StartSession(int session_id) {
160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 162 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
161 if (!SessionExists(session_id)) 163 if (!SessionExists(session_id))
(...skipping 23 matching lines...) Expand all
185 if (!SessionExists(session_id)) 187 if (!SessionExists(session_id))
186 return; 188 return;
187 189
188 SessionsTable::iterator iter = sessions_.find(session_id); 190 SessionsTable::iterator iter = sessions_.find(session_id);
189 DCHECK(iter != sessions_.end()); 191 DCHECK(iter != sessions_.end());
190 Session* session = iter->second; 192 Session* session = iter->second;
191 193
192 if (session->abort_requested) 194 if (session->abort_requested)
193 return; 195 return;
194 196
195 if (ask_user) { 197 if (ask_user && !session->config.using_audio_track) {
196 SpeechRecognitionSessionContext& context = session->context; 198 SpeechRecognitionSessionContext& context = session->context;
197 context.label = media_stream_manager_->MakeMediaAccessRequest( 199 context.label = media_stream_manager_->MakeMediaAccessRequest(
198 context.render_process_id, 200 context.render_process_id,
199 context.render_frame_id, 201 context.render_frame_id,
200 context.request_id, 202 context.request_id,
201 StreamOptions(true, false), 203 StreamOptions(true, false),
202 GURL(context.context_name), 204 GURL(context.context_name),
203 base::Bind( 205 base::Bind(
204 &SpeechRecognitionManagerImpl::MediaRequestPermissionCallback, 206 &SpeechRecognitionManagerImpl::MediaRequestPermissionCallback,
205 weak_factory_.GetWeakPtr(), session_id)); 207 weak_factory_.GetWeakPtr(), session_id));
206 return; 208 return;
207 } 209 }
208 210
209 if (is_allowed) { 211 if (is_allowed || session->config.using_audio_track) {
210 base::MessageLoop::current()->PostTask( 212 base::MessageLoop::current()->PostTask(
211 FROM_HERE, 213 FROM_HERE,
212 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, 214 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent,
213 weak_factory_.GetWeakPtr(), 215 weak_factory_.GetWeakPtr(),
214 session_id, 216 session_id,
215 EVENT_START)); 217 EVENT_START));
216 } else { 218 } else {
217 OnRecognitionError(session_id, SpeechRecognitionError( 219 OnRecognitionError(session_id, SpeechRecognitionError(
218 SPEECH_RECOGNITION_ERROR_NOT_ALLOWED)); 220 SPEECH_RECOGNITION_ERROR_NOT_ALLOWED));
219 base::MessageLoop::current()->PostTask( 221 base::MessageLoop::current()->PostTask(
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 if (SpeechRecognitionEventListener* listener = GetListener(session_id)) 425 if (SpeechRecognitionEventListener* listener = GetListener(session_id))
424 listener->OnRecognitionEnd(session_id); 426 listener->OnRecognitionEnd(session_id);
425 base::MessageLoop::current()->PostTask( 427 base::MessageLoop::current()->PostTask(
426 FROM_HERE, 428 FROM_HERE,
427 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent, 429 base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent,
428 weak_factory_.GetWeakPtr(), 430 weak_factory_.GetWeakPtr(),
429 session_id, 431 session_id,
430 EVENT_RECOGNITION_ENDED)); 432 EVENT_RECOGNITION_ENDED));
431 } 433 }
432 434
435 void SpeechRecognitionManagerImpl::OnSharedAudioBusReady(
436 int session_id,
437 const media::AudioParameters& params,
438 base::SharedMemoryHandle memory,
439 base::SyncSocket::TransitDescriptor socket) {
440 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
441 if (!SessionExists(session_id))
442 return;
443
444 if (SpeechRecognitionEventListener* listener = GetListener(session_id))
445 listener->OnSharedAudioBusReady(session_id, params, memory, socket);
446 }
447
433 int SpeechRecognitionManagerImpl::GetSession( 448 int SpeechRecognitionManagerImpl::GetSession(
434 int render_process_id, int render_view_id, int request_id) const { 449 int render_process_id, int render_view_id, int request_id) const {
435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 450 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
436 SessionsTable::const_iterator iter; 451 SessionsTable::const_iterator iter;
437 for(iter = sessions_.begin(); iter != sessions_.end(); ++iter) { 452 for (iter = sessions_.begin(); iter != sessions_.end(); ++iter) {
438 const int session_id = iter->first; 453 const int session_id = iter->first;
439 const SpeechRecognitionSessionContext& context = iter->second->context; 454 const SpeechRecognitionSessionContext& context = iter->second->context;
440 if (context.render_process_id == render_process_id && 455 if (context.render_process_id == render_process_id &&
441 context.render_view_id == render_view_id && 456 context.render_view_id == render_view_id &&
442 context.request_id == request_id) { 457 context.request_id == request_id) {
443 return session_id; 458 return session_id;
444 } 459 }
445 } 460 }
446 return kSessionIDInvalid; 461 return kSessionIDInvalid;
447 } 462 }
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 } 591 }
577 592
578 // ----------- Contract for all the FSM evolution functions below ------------- 593 // ----------- Contract for all the FSM evolution functions below -------------
579 // - Are guaranteed to be executed in the IO thread; 594 // - Are guaranteed to be executed in the IO thread;
580 // - Are guaranteed to be not reentrant (themselves and each other); 595 // - Are guaranteed to be not reentrant (themselves and each other);
581 596
582 void SpeechRecognitionManagerImpl::SessionStart(const Session& session) { 597 void SpeechRecognitionManagerImpl::SessionStart(const Session& session) {
583 DCHECK_EQ(primary_session_id_, session.id); 598 DCHECK_EQ(primary_session_id_, session.id);
584 const MediaStreamDevices& devices = session.context.devices; 599 const MediaStreamDevices& devices = session.context.devices;
585 std::string device_id; 600 std::string device_id;
586 if (devices.empty()) { 601 if (!session.config.using_audio_track) {
587 // From the ask_user=false path, use the default device. 602 if (devices.empty()) {
588 // TODO(xians): Abort the session after we do not need to support this path 603 // From the ask_user=false path, use the default device.
589 // anymore. 604 // TODO(xians): Abort the session after we do not need to support this
590 device_id = media::AudioManagerBase::kDefaultDeviceId; 605 // path anymore.
591 } else { 606 device_id = media::AudioManagerBase::kDefaultDeviceId;
592 // From the ask_user=true path, use the selected device. 607 } else {
593 DCHECK_EQ(1u, devices.size()); 608 // From the ask_user=true path, use the selected device.
594 DCHECK_EQ(MEDIA_DEVICE_AUDIO_CAPTURE, devices.front().type); 609 DCHECK_EQ(1u, devices.size());
595 device_id = devices.front().id; 610 DCHECK_EQ(MEDIA_DEVICE_AUDIO_CAPTURE, devices.front().type);
611 device_id = devices.front().id;
612 }
596 } 613 }
597 614
598 session.recognizer->StartRecognition(device_id); 615 session.recognizer->StartRecognition(device_id);
599 } 616 }
600 617
601 void SpeechRecognitionManagerImpl::SessionAbort(const Session& session) { 618 void SpeechRecognitionManagerImpl::SessionAbort(const Session& session) {
602 if (primary_session_id_ == session.id) 619 if (primary_session_id_ == session.id)
603 primary_session_id_ = kSessionIDInvalid; 620 primary_session_id_ = kSessionIDInvalid;
604 DCHECK(session.recognizer.get()); 621 DCHECK(session.recognizer.get());
605 session.recognizer->AbortRecognition(); 622 session.recognizer->AbortRecognition();
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 SpeechRecognitionManagerImpl::Session::Session() 708 SpeechRecognitionManagerImpl::Session::Session()
692 : id(kSessionIDInvalid), 709 : id(kSessionIDInvalid),
693 abort_requested(false), 710 abort_requested(false),
694 listener_is_active(true) { 711 listener_is_active(true) {
695 } 712 }
696 713
697 SpeechRecognitionManagerImpl::Session::~Session() { 714 SpeechRecognitionManagerImpl::Session::~Session() {
698 } 715 }
699 716
700 } // namespace content 717 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698