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

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: style fix 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/threading/thread_checker.h"
12 #include "content/common/content_export.h"
13 #include "content/public/renderer/media_stream_audio_sink.h"
14 #include "media/audio/audio_device_thread.h"
15 #include "media/base/audio_converter.h"
16 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h"
17
18 namespace base {
19 class TimeDelta;
20 }
21
22 namespace media {
23 class AudioBus;
24 class AudioConverter;
25 class AudioFifo;
26 class AudioParameters;
27 }
28
29 namespace content {
30
31 // SpeechRecognitionAudioSourceProvider works as a sink to the
32 // WebRtcLocalAudioTrack and stores the capture data to a FIFO.
33 // When the FIFO has enough buffer, it passes the buffer to
34 // the speech recognizer.
35 //
36 class CONTENT_EXPORT SpeechRecognitionAudioSourceProvider
37 : NON_EXPORTED_BASE(public media::AudioConverter::InputCallback),
38 NON_EXPORTED_BASE(public MediaStreamAudioSink) {
39 public:
40 typedef base::Callback<void()> OnDataCB;
41 typedef base::Callback<void()> OnErrorCB;
42
43 SpeechRecognitionAudioSourceProvider(const blink::WebMediaStreamTrack& track,
44 const media::AudioParameters& params,
45 base::SharedMemoryHandle memory,
46 int memory_length,
47 const OnDataCB& on_data_callback,
48 const OnErrorCB& on_error_callback);
49 virtual ~SpeechRecognitionAudioSourceProvider();
50
51 // MediaStreamAudioSink implementation.
tommi (sloooow) - chröme 2014/08/25 14:38:46 Do these implementations need to be a part of the
burnik 2014/08/29 09:18:16 Done.
52 virtual void OnData(const int16* audio_data,
53 int sample_rate,
54 int number_of_channels,
55 int number_of_frames) OVERRIDE;
56 virtual void OnSetFormat(const media::AudioParameters& params) OVERRIDE;
57 virtual void OnReadyStateChanged(
58 blink::WebMediaStreamSource::ReadyState state) OVERRIDE;
59
60 // media::AudioConverter::Inputcallback implementation.
61 // This function is triggered by provideInput() on the WebAudio audio thread,
62 // so it has been under the protection of |lock_|.
63 virtual double ProvideInput(media::AudioBus* audio_bus,
64 base::TimeDelta buffer_delay) OVERRIDE;
65
66
67 // Called by client when consumed an AudioChunk
68 virtual void NotifyAudioBusConsumed();
tommi (sloooow) - chröme 2014/08/25 14:38:46 OVERRIDE?
burnik 2014/08/29 09:18:16 Removed due to sync_socket. On 2014/08/25 14:38:46
69
70 private:
71 const int kNumberOfBuffersInFifo = 2;
tommi (sloooow) - chröme 2014/08/25 14:38:45 static?
burnik 2014/08/29 09:18:16 Done.
72 int fifo_buffer_size_;
tommi (sloooow) - chröme 2014/08/25 14:38:45 can you add documentation about what this represen
73
74 // Used to DCHECK that some methods are called on the capture audio thread.
75 base::ThreadChecker capture_thread_checker_;
76
77 // The audio track that this source provider is connected to.
78 blink::WebMediaStreamTrack track_;
79
80 base::SharedMemory shared_memory_;
henrika (OOO until Aug 14) 2014/08/25 14:46:00 Could you add more information about what these me
burnik 2014/08/29 09:18:16 Done.
81 scoped_ptr<media::AudioConverter> audio_converter_;
82 scoped_ptr<media::AudioFifo> fifo_;
83 scoped_ptr<media::AudioBus> input_bus_;
84 scoped_ptr<media::AudioBus> output_bus_;
85 media::AudioParameters input_params_;
86 media::AudioParameters output_params_;
87 // used for notifying client to consume audio
88 const OnDataCB on_data_callback_;
89 // used for notifying client of fifo overflow
90 const OnDataCB on_error_callback_;
91 bool attached_converter_;
92 bool track_stopped_;
93 // Used for locking the |unconsumed_audio_buffers_| since OnData is on the
94 // audio capture thread and client notifies back on the render thread
95 base::Lock lock_;
96 // |unconsumed_audio_buffers_| is used to make sure all buffers are
97 // consumed by the client in order via alternating the counter
98 int unconsumed_audio_buffers_;
99
100 DISALLOW_COPY_AND_ASSIGN(SpeechRecognitionAudioSourceProvider);
101 };
102
103 } // namespace content
104
105 #endif // CONTENT_RENDERER_SPEECH_RECOGNITION_AUDIO_SOURCE_PROVIDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698