OLD | NEW |
---|---|
(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_ | |
no longer working on chromium
2014/09/23 10:09:12
update this macro, you have moved the code to medi
burnik
2014/09/23 12:39:20
Done. It is
CONTENT_RENDERER_MEDIA_SPEECH_RECOGNIT
| |
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 "content/common/content_export.h" | |
14 #include "content/public/renderer/media_stream_audio_sink.h" | |
15 #include "content/renderer/media/media_stream_audio_source.h" | |
16 #include "media/audio/audio_parameters.h" | |
17 #include "media/base/audio_converter.h" | |
18 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | |
19 | |
20 namespace media { | |
21 class AudioBus; | |
22 class AudioFifo; | |
23 class AudioParameters; | |
no longer working on chromium
2014/09/23 10:09:13
remove this forward declaration.
burnik
2014/09/23 12:39:20
Done.
| |
24 } | |
25 | |
26 namespace content { | |
27 | |
28 // SpeechRecognitionAudioSourceProvider works as an audio sink to the | |
29 // WebRtcLocalAudioTrack. It stores the capture data into a FIFO. | |
30 // When the FIFO has enough data for resampling, it converts it, | |
31 // passes the buffer to the |WebSpeechRecognizer| via SharedMemory | |
32 // and notifies it via SyncSocket followed by incrementing the |buffer_index_|. | |
33 // |WebSpeechRecognizer| increments the shared buffer index to synchronize. | |
34 class CONTENT_EXPORT SpeechRecognitionAudioSourceProvider | |
35 : NON_EXPORTED_BASE(public media::AudioConverter::InputCallback), | |
36 NON_EXPORTED_BASE(public MediaStreamAudioSink) { | |
37 public: | |
38 | |
39 typedef base::Callback<void()> OnStoppedCB; | |
40 | |
41 SpeechRecognitionAudioSourceProvider(const blink::WebMediaStreamTrack& track, | |
42 const media::AudioParameters& params, | |
43 const base::SharedMemoryHandle memory, | |
44 base::SyncSocket* socket, | |
45 OnStoppedCB on_error_cb); | |
46 | |
47 virtual ~SpeechRecognitionAudioSourceProvider(); | |
48 | |
49 // Returns whether the provided track is supported. | |
50 static bool IsSupportedTrack(const blink::WebMediaStreamTrack& track); | |
51 | |
52 private: | |
53 // content::MediaStreamAudioSink implementation. | |
54 virtual void OnReadyStateChanged( | |
55 blink::WebMediaStreamSource::ReadyState state) OVERRIDE; | |
56 | |
57 virtual void OnData(const int16* audio_data, int sample_rate, | |
58 int number_of_channels, int number_of_frames) OVERRIDE; | |
59 virtual void OnSetFormat(const media::AudioParameters& params) OVERRIDE; | |
60 | |
61 // media::AudioConverter::Inputcallback implementation. | |
62 virtual double ProvideInput(media::AudioBus* audio_bus, | |
63 base::TimeDelta buffer_delay) OVERRIDE; | |
64 | |
65 // Number of frames per buffer in FIFO. When the buffer is full we convert and | |
66 // consume it on the |output_bus_|. Size of the buffer depends on the | |
67 // resampler. Example: for 44.1 to 16.0 conversion, it should be 4100 frames. | |
68 int fifo_buffer_size_; | |
69 | |
70 // Used to DCHECK that some methods are called on the main render thread. | |
71 base::ThreadChecker main_render_thread_checker_; | |
72 | |
73 // Used to DCHECK that some methods are called on the capture audio thread. | |
74 base::ThreadChecker capture_thread_checker_; | |
75 | |
76 // The audio track that this source provider is connected to. | |
77 const blink::WebMediaStreamTrack track_; | |
78 | |
79 // Shared memory used by audio buses on both browser and renderer processes. | |
80 base::SharedMemory shared_memory_; | |
81 | |
82 // Socket for syncronization of audio bus reads/writes. | |
83 // Created on the renderer client and passed here. Accessed on capture thread. | |
84 scoped_ptr<base::SyncSocket> socket_; | |
no longer working on chromium
2014/09/23 10:09:12
You should use base::CancelableSyncSocket socket_
burnik
2014/09/23 12:39:20
Ok. Let's say I pass in a CancelableSyncSocket fro
| |
85 | |
86 // Used as a resampler to deliver appropriate format to speech recognition. | |
87 scoped_ptr<media::AudioConverter> audio_converter_; | |
88 | |
89 // FIFO is used for queueing audio frames before we resample. | |
90 scoped_ptr<media::AudioFifo> fifo_; | |
91 | |
92 // Audio delivered from source. | |
93 scoped_ptr<media::AudioBus> input_bus_; | |
94 | |
95 // Audio bus shared with the browser process via |shared_memory_|. | |
96 scoped_ptr<media::AudioBus> output_bus_; | |
97 | |
98 // Params of the source audio. Can change when |OnSetFormat| occurs. | |
no longer working on chromium
2014/09/23 10:09:12
nit, s/|OnSetFormat|/OnSetFormat()/g
burnik
2014/09/23 12:39:20
Done.
| |
99 media::AudioParameters input_params_; | |
100 | |
101 // Params used by speech recognition. | |
102 const media::AudioParameters output_params_; | |
103 | |
104 // Whether the track has been stopped. | |
105 bool track_stopped_; | |
106 | |
107 // Local counter of audio buffers for synchronization. | |
108 uint32 buffer_index_; | |
109 | |
110 // Peer's counter of audio buffers for synchronization. | |
111 const uint32* peer_buffer_index_; | |
112 | |
113 // Callback for the renderer client. Called when the audio track was stopped. | |
114 const OnStoppedCB on_stopped_cb_; | |
115 | |
116 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionAudioSourceProvider); | |
117 }; | |
118 | |
119 } // namespace content | |
120 | |
121 #endif // CONTENT_RENDERER_SPEECH_RECOGNITION_AUDIO_SOURCE_PROVIDER_H_ | |
OLD | NEW |