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

Unified 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: Wait with no timeout Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/speech/speech_recognition_manager_impl.cc
diff --git a/content/browser/speech/speech_recognition_manager_impl.cc b/content/browser/speech/speech_recognition_manager_impl.cc
index 1a054204c4477a7e6c4c09abfd11a54aeea7443c..2a944b10eb4fd2b51540bb05a3ee1ff06929f386 100644
--- a/content/browser/speech/speech_recognition_manager_impl.cc
+++ b/content/browser/speech/speech_recognition_manager_impl.cc
@@ -5,6 +5,7 @@
#include "content/browser/speech/speech_recognition_manager_impl.h"
#include "base/bind.h"
+#include "base/sync_socket.h"
#include "content/browser/browser_main_loop.h"
#include "content/browser/renderer_host/media/media_stream_manager.h"
#include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
@@ -23,6 +24,7 @@
#include "content/public/common/speech_recognition_result.h"
#include "media/audio/audio_manager.h"
#include "media/audio/audio_manager_base.h"
+#include "media/audio/audio_parameters.h"
#if defined(OS_ANDROID)
#include "content/browser/speech/speech_recognizer_impl_android.h"
@@ -149,6 +151,8 @@ int SpeechRecognitionManagerImpl::CreateSession(
session_id,
config.continuous,
config.interim_results,
+ config.using_audio_track,
+ config.peer_process_handle,
google_remote_engine);
#else
session->recognizer = new SpeechRecognizerImplAndroid(this, session_id);
@@ -192,7 +196,7 @@ void SpeechRecognitionManagerImpl::RecognitionAllowedCallback(int session_id,
if (session->abort_requested)
return;
- if (ask_user) {
+ if (ask_user && !session->config.using_audio_track) {
SpeechRecognitionSessionContext& context = session->context;
context.label = media_stream_manager_->MakeMediaAccessRequest(
context.render_process_id,
@@ -206,7 +210,7 @@ void SpeechRecognitionManagerImpl::RecognitionAllowedCallback(int session_id,
return;
}
- if (is_allowed) {
+ if (is_allowed || session->config.using_audio_track) {
base::MessageLoop::current()->PostTask(
FROM_HERE,
base::Bind(&SpeechRecognitionManagerImpl::DispatchEvent,
@@ -430,11 +434,24 @@ void SpeechRecognitionManagerImpl::OnRecognitionEnd(int session_id) {
EVENT_RECOGNITION_ENDED));
}
+void SpeechRecognitionManagerImpl::OnAudioReceiverReady(
+ int session_id,
+ const media::AudioParameters& params,
+ const base::SharedMemoryHandle memory,
+ const base::SyncSocket::TransitDescriptor socket) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
+ if (!SessionExists(session_id))
+ return;
+
+ if (SpeechRecognitionEventListener* listener = GetListener(session_id))
+ listener->OnAudioReceiverReady(session_id, params, memory, socket);
+}
+
int SpeechRecognitionManagerImpl::GetSession(
int render_process_id, int render_view_id, int request_id) const {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
SessionsTable::const_iterator iter;
- for(iter = sessions_.begin(); iter != sessions_.end(); ++iter) {
+ for (iter = sessions_.begin(); iter != sessions_.end(); ++iter) {
const int session_id = iter->first;
const SpeechRecognitionSessionContext& context = iter->second->context;
if (context.render_process_id == render_process_id &&
@@ -583,16 +600,18 @@ void SpeechRecognitionManagerImpl::SessionStart(const Session& session) {
DCHECK_EQ(primary_session_id_, session.id);
const MediaStreamDevices& devices = session.context.devices;
std::string device_id;
- if (devices.empty()) {
- // From the ask_user=false path, use the default device.
- // TODO(xians): Abort the session after we do not need to support this path
- // anymore.
- device_id = media::AudioManagerBase::kDefaultDeviceId;
- } else {
- // From the ask_user=true path, use the selected device.
- DCHECK_EQ(1u, devices.size());
- DCHECK_EQ(MEDIA_DEVICE_AUDIO_CAPTURE, devices.front().type);
- device_id = devices.front().id;
+ if (!session.config.using_audio_track) {
+ if (devices.empty()) {
+ // From the ask_user=false path, use the default device.
+ // TODO(xians): Abort the session after we do not need to support this
+ // path anymore.
+ device_id = media::AudioManagerBase::kDefaultDeviceId;
+ } else {
+ // From the ask_user=true path, use the selected device.
+ DCHECK_EQ(1u, devices.size());
+ DCHECK_EQ(MEDIA_DEVICE_AUDIO_CAPTURE, devices.front().type);
+ device_id = devices.front().id;
+ }
}
session.recognizer->StartRecognition(device_id);
« no previous file with comments | « content/browser/speech/speech_recognition_manager_impl.h ('k') | content/browser/speech/speech_recognizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698