| OLD | NEW |
| 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" |
| 11 #include "content/browser/speech/google_one_shot_remote_engine.h" | 11 #include "content/browser/speech/google_one_shot_remote_engine.h" |
| 12 #include "content/browser/speech/google_streaming_remote_engine.h" | 12 #include "content/browser/speech/google_streaming_remote_engine.h" |
| 13 #include "content/browser/speech/speech_recognition_engine.h" | 13 #include "content/browser/speech/speech_recognition_engine.h" |
| 14 #include "content/browser/speech/speech_recognizer_impl.h" | 14 #include "content/browser/speech/speech_recognizer_impl.h" |
| 15 #include "content/public/browser/browser_thread.h" | 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/content_browser_client.h" | 16 #include "content/public/browser/content_browser_client.h" |
| 17 #include "content/public/browser/resource_context.h" | 17 #include "content/public/browser/resource_context.h" |
| 18 #include "content/public/browser/speech_recognition_event_listener.h" | 18 #include "content/public/browser/speech_recognition_event_listener.h" |
| 19 #include "content/public/browser/speech_recognition_manager_delegate.h" | 19 #include "content/public/browser/speech_recognition_manager_delegate.h" |
| 20 #include "content/public/browser/speech_recognition_session_config.h" | 20 #include "content/public/browser/speech_recognition_session_config.h" |
| 21 #include "content/public/browser/speech_recognition_session_context.h" | 21 #include "content/public/browser/speech_recognition_session_context.h" |
| 22 #include "content/public/common/speech_recognition_error.h" | 22 #include "content/public/common/speech_recognition_error.h" |
| 23 #include "content/public/common/speech_recognition_result.h" | 23 #include "content/public/common/speech_recognition_result.h" |
| 24 #include "media/audio/audio_manager.h" | 24 #include "media/audio/audio_manager.h" |
| 25 #include "media/audio/audio_manager_base.h" |
| 25 | 26 |
| 26 #if defined(OS_ANDROID) | 27 #if defined(OS_ANDROID) |
| 27 #include "content/browser/speech/speech_recognizer_impl_android.h" | 28 #include "content/browser/speech/speech_recognizer_impl_android.h" |
| 28 #endif | 29 #endif |
| 29 | 30 |
| 30 using base::Callback; | 31 using base::Callback; |
| 31 | 32 |
| 32 namespace content { | 33 namespace content { |
| 33 | 34 |
| 34 SpeechRecognitionManager* SpeechRecognitionManager::manager_for_tests_; | 35 SpeechRecognitionManager* SpeechRecognitionManager::manager_for_tests_; |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 561 return SESSION_STATE_WAITING_FOR_RESULT; | 562 return SESSION_STATE_WAITING_FOR_RESULT; |
| 562 } | 563 } |
| 563 | 564 |
| 564 // ----------- Contract for all the FSM evolution functions below ------------- | 565 // ----------- Contract for all the FSM evolution functions below ------------- |
| 565 // - Are guaranteed to be executed in the IO thread; | 566 // - Are guaranteed to be executed in the IO thread; |
| 566 // - Are guaranteed to be not reentrant (themselves and each other); | 567 // - Are guaranteed to be not reentrant (themselves and each other); |
| 567 | 568 |
| 568 void SpeechRecognitionManagerImpl::SessionStart(const Session& session) { | 569 void SpeechRecognitionManagerImpl::SessionStart(const Session& session) { |
| 569 DCHECK_EQ(primary_session_id_, session.id); | 570 DCHECK_EQ(primary_session_id_, session.id); |
| 570 const MediaStreamDevices& devices = session.context.devices; | 571 const MediaStreamDevices& devices = session.context.devices; |
| 571 DCHECK_EQ(1u, devices.size()); | 572 std::string device_id; |
| 572 DCHECK_EQ(MEDIA_DEVICE_AUDIO_CAPTURE, devices.front().type); | 573 if (devices.empty()) { |
| 574 // From the ask_user=false path, use the default device. |
| 575 // TODO(xians): Abort the session after we do not need to support this path |
| 576 // anymore. |
| 577 device_id = media::AudioManagerBase::kDefaultDeviceId; |
| 578 } else { |
| 579 // From the ask_user=true path, use the selected device. |
| 580 DCHECK_EQ(1u, devices.size()); |
| 581 DCHECK_EQ(MEDIA_DEVICE_AUDIO_CAPTURE, devices.front().type); |
| 582 device_id = devices.front().id; |
| 583 } |
| 573 | 584 |
| 574 session.recognizer->StartRecognition(devices.front().id); | 585 session.recognizer->StartRecognition(device_id); |
| 575 } | 586 } |
| 576 | 587 |
| 577 void SpeechRecognitionManagerImpl::SessionAbort(const Session& session) { | 588 void SpeechRecognitionManagerImpl::SessionAbort(const Session& session) { |
| 578 if (primary_session_id_ == session.id) | 589 if (primary_session_id_ == session.id) |
| 579 primary_session_id_ = kSessionIDInvalid; | 590 primary_session_id_ = kSessionIDInvalid; |
| 580 DCHECK(session.recognizer.get()); | 591 DCHECK(session.recognizer.get()); |
| 581 session.recognizer->AbortRecognition(); | 592 session.recognizer->AbortRecognition(); |
| 582 } | 593 } |
| 583 | 594 |
| 584 void SpeechRecognitionManagerImpl::SessionStopAudioCapture( | 595 void SpeechRecognitionManagerImpl::SessionStopAudioCapture( |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 | 673 |
| 663 SpeechRecognitionManagerImpl::Session::Session() | 674 SpeechRecognitionManagerImpl::Session::Session() |
| 664 : id(kSessionIDInvalid), | 675 : id(kSessionIDInvalid), |
| 665 listener_is_active(true) { | 676 listener_is_active(true) { |
| 666 } | 677 } |
| 667 | 678 |
| 668 SpeechRecognitionManagerImpl::Session::~Session() { | 679 SpeechRecognitionManagerImpl::Session::~Session() { |
| 669 } | 680 } |
| 670 | 681 |
| 671 } // namespace content | 682 } // namespace content |
| OLD | NEW |