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

Side by Side Diff: content/renderer/speech_recognition_audio_source_provider.h

Issue 499233003: Binding media stream audio track to speech recognition [renderer] (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactoring on callbacks and error states Created 6 years, 3 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
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CONTENT_RENDERER_SPEECH_RECOGNITION_AUDIO_SOURCE_PROVIDER_H_
6 #define CONTENT_RENDERER_SPEECH_RECOGNITION_AUDIO_SOURCE_PROVIDER_H_
7
8 #include "base/callback.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/memory/shared_memory.h"
11 #include "base/sync_socket.h"
12 #include "base/threading/thread_checker.h"
13 #include "base/threading/thread_restrictions.h"
no longer working on chromium 2014/09/16 12:44:06 I might just miss some code, why this thread_restr
burnik 2014/09/16 19:10:23 Legacy from tests. Removed. On 2014/09/16 12:44:06
14 #include "content/common/content_export.h"
15 #include "content/public/renderer/media_stream_audio_sink.h"
16 #include "content/renderer/media/media_stream_audio_source.h"
17 #include "media/audio/audio_device_thread.h"
no longer working on chromium 2014/09/16 12:44:06 same question for this audio_device_thread.h
burnik 2014/09/16 19:10:23 Done.
18 #include "media/audio/audio_parameters.h"
no longer working on chromium 2014/09/16 12:44:06 you are forward declare the AudioParameters in lin
burnik 2014/09/16 19:10:23 Done.
19 #include "media/base/audio_converter.h"
20 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
21
22 namespace media {
23 class AudioBus;
24 class AudioConverter;
no longer working on chromium 2014/09/16 12:44:06 you include the audio_converter.h, so you don't ne
burnik 2014/09/16 19:10:23 Done.
25 class AudioFifo;
26 class AudioParameters;
27 }
28
29 namespace content {
30
31 // SpeechRecognitionAudioSourceProvider works as an audio sink to the
32 // WebRtcLocalAudioTrack. It stores the capture data into a FIFO.
33 // When the FIFO has enough data for resampling, it converts it,
34 // passes the buffer to the |WebSpeechRecognizer| via SharedMemory
35 // and notifies it via SyncSocket followed by incrementing the |buffer_index_|.
36 // |WebSpeechRecognizer| increments the shared buffer index to synchronize.
37 class CONTENT_EXPORT SpeechRecognitionAudioSourceProvider
38 : NON_EXPORTED_BASE(public media::AudioConverter::InputCallback),
39 NON_EXPORTED_BASE(public MediaStreamAudioSink) {
40 public:
41
42 typedef base::Callback<void()> OnStoppedCB;
43
44 SpeechRecognitionAudioSourceProvider(const blink::WebMediaStreamTrack& track,
45 const media::AudioParameters& params,
46 const base::SharedMemoryHandle memory,
47 base::SyncSocket* socket,
48 OnStoppedCB on_error_cb);
49
50 virtual ~SpeechRecognitionAudioSourceProvider();
51
52 // Returns whether the provided track is allowed based on current policy.
53 static bool IsAllowedAudioTrack(const blink::WebMediaStreamTrack& track);
54
55 protected:
56 // content::MediaStreamAudioSink implementation.
no longer working on chromium 2014/09/16 12:44:06 these implementation of interfaces all can be priv
burnik 2014/09/16 19:10:23 Done.
57 virtual void OnReadyStateChanged(
58 blink::WebMediaStreamSource::ReadyState state) OVERRIDE;
59
60 virtual void OnData(const int16* audio_data, int sample_rate,
61 int number_of_channels, int number_of_frames) OVERRIDE;
62 virtual void OnSetFormat(const media::AudioParameters& params) OVERRIDE;
63
64 // media::AudioConverter::Inputcallback implementation.
65 virtual double ProvideInput(media::AudioBus* audio_bus,
66 base::TimeDelta buffer_delay) OVERRIDE;
67
68 private:
69 // Number of frames per buffer in FIFO. When the buffer is full we convert and
70 // consume it on the |output_bus_|. Size of the buffer depends on the
71 // resampler. Example: for 44.1 to 16.0 conversion, it should be 4100 frames.
72 int fifo_buffer_size_;
73
74 // Used to DCHECK that some methods are called on the main render thread.
75 base::ThreadChecker main_render_thread_checker_;
76
77 // Used to DCHECK that some methods are called on the capture audio thread.
78 base::ThreadChecker capture_thread_checker_;
79
80 // The audio track that this source provider is connected to.
81 const blink::WebMediaStreamTrack track_;
82
83 // Shared memory used by audio buses on both browser and renderer processes.
84 base::SharedMemory shared_memory_;
85
86 // Socket for syncronization of audio bus reads/writes.
87 base::SyncSocket* socket_;
88
89 // Used as a resampler to deliver appropriate format to speech recognition.
90 scoped_ptr<media::AudioConverter> audio_converter_;
91
92 // FIFO is used for queueing audio frames before we resample.
93 scoped_ptr<media::AudioFifo> fifo_;
94
95 // Audio delivered from source.
96 scoped_ptr<media::AudioBus> input_bus_;
97
98 // Audio bus shared with the browser process via |shared_memory_|.
99 scoped_ptr<media::AudioBus> output_bus_;
100
101 // Params of the source audio. Can change when |OnSetFormat| occurs.
102 media::AudioParameters input_params_;
103
104 // Params used by speech recognition.
105 const media::AudioParameters output_params_;
106
107 // Whether the track has been stopped.
108 bool track_stopped_;
109
110 // Local counter of audio buffers for synchronization.
111 uint32 buffer_index_;
112
113 // Peer's counter of audio buffers for synchronization.
114 const uint32* peer_buffer_index_;
no longer working on chromium 2014/09/16 12:44:06 you don't need this member variable, use a local v
burnik 2014/09/16 19:10:23 I must disagree. This would mean I should keep the
115
116 // Callback for the renderer client. Called when the audio track was stopped.
117 const OnStoppedCB on_stopped_cb_;
118
119 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionAudioSourceProvider);
120 };
121
122 } // namespace content
123
124 #endif // CONTENT_RENDERER_SPEECH_RECOGNITION_AUDIO_SOURCE_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698