Chromium Code Reviews| Index: content/browser/speech/speech_recognizer_impl.h |
| diff --git a/content/browser/speech/speech_recognizer_impl.h b/content/browser/speech/speech_recognizer_impl.h |
| index bd869ee570799fb86ad45c16b463c96e7106e4c9..76c82bfa476e5e8426c365897a2ae635051a1ae8 100644 |
| --- a/content/browser/speech/speech_recognizer_impl.h |
| +++ b/content/browser/speech/speech_recognizer_impl.h |
| @@ -7,6 +7,10 @@ |
| #include "base/basictypes.h" |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/memory/shared_memory.h" |
| +#include "base/process/process_handle.h" |
| +#include "base/sync_socket.h" |
| +#include "base/threading/thread.h" |
| #include "content/browser/speech/endpointer/endpointer.h" |
| #include "content/browser/speech/speech_recognition_engine.h" |
| #include "content/browser/speech/speech_recognizer.h" |
| @@ -19,6 +23,7 @@ |
| namespace media { |
| class AudioBus; |
| class AudioManager; |
| +class AudioParameters; |
| } |
| namespace content { |
| @@ -40,11 +45,11 @@ class CONTENT_EXPORT SpeechRecognizerImpl |
| static const int kEndpointerEstimationTimeMs; |
| static void SetAudioManagerForTesting(media::AudioManager* audio_manager); |
| - |
| - SpeechRecognizerImpl(SpeechRecognitionEventListener* listener, |
| - int session_id, |
| - bool continuous, |
| - bool provisional_results, |
| + // TODO(burnik): abstract out the process_handle. Pass differently. |
| + SpeechRecognizerImpl(SpeechRecognitionEventListener* listener, int session_id, |
| + bool continuous, bool provisional_results, |
| + bool using_audio_track, |
| + base::ProcessHandle process_handle, |
| SpeechRecognitionEngine* engine); |
| virtual void StartRecognition(const std::string& device_id) OVERRIDE; |
| @@ -54,6 +59,11 @@ class CONTENT_EXPORT SpeechRecognizerImpl |
| virtual bool IsCapturingAudio() const OVERRIDE; |
| const SpeechRecognitionEngine& recognition_engine() const; |
| + // Whether to use an audio track from the renderer as the input source. |
| + void set_using_audio_track(bool using_audio_track) { |
|
tommi (sloooow) - chröme
2014/10/02 11:23:19
thread check?
(and move to cc file)
burnik
2014/10/02 16:04:12
Done.
|
| + using_audio_track_ = using_audio_track; |
| + } |
| + |
| private: |
| friend class SpeechRecognizerTest; |
| @@ -116,6 +126,9 @@ class CONTENT_EXPORT SpeechRecognizerImpl |
| FSMState DoNothing(const FSMEventArgs& event_args) const; |
| FSMState NotFeasible(const FSMEventArgs& event_args); |
| + // Called from |StartRecording()| when using audio track from renderer. |
| + bool StartRecordingUsingAudioTrack(const media::AudioParameters& params); |
| + |
| // Returns the time span of captured audio samples since the start of capture. |
| int GetElapsedTimeMs() const; |
| @@ -154,8 +167,15 @@ class CONTENT_EXPORT SpeechRecognizerImpl |
| float audio_level_; |
| bool is_dispatching_event_; |
| bool provisional_results_; |
| + bool using_audio_track_; |
| + base::ProcessHandle peer_process_handle_; |
| FSMState state_; |
| std::string device_id_; |
| + scoped_ptr<base::CancelableSyncSocket> audio_sync_socket_; |
| + scoped_ptr<base::CancelableSyncSocket> foreign_sync_socket_; |
| + |
| + // Runs on separate |audio_sync_thread_| when receiving audio from renderer. |
| + virtual void OnAudioTrackData(); |
| class OnDataConverter; |
| @@ -163,6 +183,21 @@ class CONTENT_EXPORT SpeechRecognizerImpl |
| // output format. |
| scoped_ptr<SpeechRecognizerImpl::OnDataConverter> audio_converter_; |
| + // Shared memory for passing audio data from renderer to the browser. |
| + scoped_ptr<base::SharedMemory> shared_memory_; |
| + |
| + // Audio bus wrapping the shared memory from the renderer. |
| + scoped_ptr<media::AudioBus> audio_track_bus_; |
| + |
| + // Used for synchronization when consuming audio on the |audio_track_bus_|. |
| + uint32* buffer_index_; |
| + |
| + // Thread for receiving audio chunks from the renderer. |
| + scoped_ptr<base::Thread> audio_sync_thread_; |
| + |
| + // Used to check if |OnAudioTrackData()| is executed on |audio_sync_thread_|. |
| + base::ThreadChecker audio_sync_thread_checker_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(SpeechRecognizerImpl); |
| }; |