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

Side by Side Diff: media/audio/audio_input_device.h

Issue 12440027: Do not pass the string device_id via IPC message to create an audio input stream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ready for review Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Low-latency audio capturing class utilizing audio input stream provided 5 // Low-latency audio capturing class utilizing audio input stream provided
6 // by a server (browser) process by use of an IPC interface. 6 // by a server (browser) process by use of an IPC interface.
7 // 7 //
8 // Relationship of classes: 8 // Relationship of classes:
9 // 9 //
10 // AudioInputController AudioInputDevice 10 // AudioInputController AudioInputDevice
11 // ^ ^ 11 // ^ ^
12 // | | 12 // | |
13 // v IPC v 13 // v IPC v
14 // AudioInputRendererHost <---------> AudioInputIPCDelegate 14 // AudioInputRendererHost <---------> AudioInputIPCDelegate
15 // ^ (impl in AudioInputMessageFilter) 15 // ^ (impl in AudioInputMessageFilter)
16 // | 16 // |
17 // v 17 // v
18 // AudioInputDeviceManager 18 // AudioInputDeviceManager
19 // 19 //
20 // Transportation of audio samples from the browser to the render process 20 // Transportation of audio samples from the browser to the render process
21 // is done by using shared memory in combination with a SyncSocket. 21 // is done by using shared memory in combination with a SyncSocket.
22 // The AudioInputDevice user registers an AudioInputDevice::CaptureCallback by 22 // The AudioInputDevice user registers an AudioInputDevice::CaptureCallback by
23 // calling Initialize(). The callback will be called with recorded audio from 23 // calling Initialize(). The callback will be called with recorded audio from
24 // the underlying audio layers. 24 // the underlying audio layers.
25 // The session ID is used by the AudioInputRendererHost to start the device 25 // The session ID is used by the AudioInputRendererHost to start the device
26 // referenced by this ID. 26 // referenced by this ID.
27 // 27 //
28 // State sequences: 28 // State sequences:
29 // 29 //
30 // Sequence where session_id has not been set using SetDevice():
31 // ('<-' signifies callbacks, -> signifies calls made by AudioInputDevice)
32 // Start -> InitializeOnIOThread -> CreateStream -> 30 // Start -> InitializeOnIOThread -> CreateStream ->
33 // <- OnStreamCreated <- 31 // <- OnStreamCreated <-
34 // -> StartOnIOThread -> PlayStream -> 32 // -> StartOnIOThread -> PlayStream ->
35 // 33 //
36 // Sequence where session_id has been set using SetDevice():
37 // Start -> InitializeOnIOThread -> StartDevice ->
38 // <- OnDeviceReady <-
39 // -> CreateStream ->
40 // <- OnStreamCreated <-
41 // -> StartOnIOThread -> PlayStream ->
42 // 34 //
43 // AudioInputDevice::Capture => low latency audio transport on audio thread => 35 // AudioInputDevice::Capture => low latency audio transport on audio thread =>
44 // | 36 // |
45 // Stop --> ShutDownOnIOThread ------> CloseStream -> Close 37 // Stop --> ShutDownOnIOThread ------> CloseStream -> Close
46 // 38 //
47 // This class depends on two threads to function: 39 // This class depends on two threads to function:
48 // 40 //
49 // 1. An IO thread. 41 // 1. An IO thread.
50 // This thread is used to asynchronously process Start/Stop etc operations 42 // This thread is used to asynchronously process Start/Stop etc operations
51 // that are available via the public interface. The public methods are 43 // that are available via the public interface. The public methods are
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 : NON_EXPORTED_BASE(public AudioCapturerSource), 78 : NON_EXPORTED_BASE(public AudioCapturerSource),
87 NON_EXPORTED_BASE(public AudioInputIPCDelegate), 79 NON_EXPORTED_BASE(public AudioInputIPCDelegate),
88 NON_EXPORTED_BASE(public ScopedLoopObserver) { 80 NON_EXPORTED_BASE(public ScopedLoopObserver) {
89 public: 81 public:
90 AudioInputDevice(AudioInputIPC* ipc, 82 AudioInputDevice(AudioInputIPC* ipc,
91 const scoped_refptr<base::MessageLoopProxy>& io_loop); 83 const scoped_refptr<base::MessageLoopProxy>& io_loop);
92 84
93 // AudioCapturerSource implementation. 85 // AudioCapturerSource implementation.
94 virtual void Initialize(const AudioParameters& params, 86 virtual void Initialize(const AudioParameters& params,
95 CaptureCallback* callback, 87 CaptureCallback* callback,
96 CaptureEventHandler* event_handler) OVERRIDE; 88 int session_id) OVERRIDE;
97 virtual void Start() OVERRIDE; 89 virtual void Start() OVERRIDE;
98 virtual void Stop() OVERRIDE; 90 virtual void Stop() OVERRIDE;
99 virtual void SetVolume(double volume) OVERRIDE; 91 virtual void SetVolume(double volume) OVERRIDE;
100 virtual void SetDevice(int session_id) OVERRIDE;
101 virtual void SetAutomaticGainControl(bool enabled) OVERRIDE; 92 virtual void SetAutomaticGainControl(bool enabled) OVERRIDE;
102 93
103 protected: 94 protected:
104 // Methods called on IO thread ---------------------------------------------- 95 // Methods called on IO thread ----------------------------------------------
105 // AudioInputIPCDelegate implementation. 96 // AudioInputIPCDelegate implementation.
106 virtual void OnStreamCreated(base::SharedMemoryHandle handle, 97 virtual void OnStreamCreated(base::SharedMemoryHandle handle,
107 base::SyncSocket::Handle socket_handle, 98 base::SyncSocket::Handle socket_handle,
108 int length) OVERRIDE; 99 int length) OVERRIDE;
109 virtual void OnVolume(double volume) OVERRIDE; 100 virtual void OnVolume(double volume) OVERRIDE;
110 virtual void OnStateChanged( 101 virtual void OnStateChanged(
111 AudioInputIPCDelegate::State state) OVERRIDE; 102 AudioInputIPCDelegate::State state) OVERRIDE;
112 virtual void OnDeviceReady(const std::string& device_id) OVERRIDE;
113 virtual void OnIPCClosed() OVERRIDE; 103 virtual void OnIPCClosed() OVERRIDE;
114 104
115 friend class base::RefCountedThreadSafe<AudioInputDevice>; 105 friend class base::RefCountedThreadSafe<AudioInputDevice>;
116 virtual ~AudioInputDevice(); 106 virtual ~AudioInputDevice();
117 107
118 private: 108 private:
119 // Methods called on IO thread ---------------------------------------------- 109 // Methods called on IO thread ----------------------------------------------
120 // The following methods are tasks posted on the IO thread that needs to 110 // The following methods are tasks posted on the IO thread that needs to
121 // be executed on that thread. They interact with AudioInputMessageFilter and 111 // be executed on that thread. They interact with AudioInputMessageFilter and
122 // sends IPC messages on that thread. 112 // sends IPC messages on that thread.
123 void InitializeOnIOThread(); 113 void InitializeOnIOThread();
124 void SetSessionIdOnIOThread(int session_id);
125 void StartOnIOThread(); 114 void StartOnIOThread();
126 void ShutDownOnIOThread(); 115 void ShutDownOnIOThread();
127 void SetVolumeOnIOThread(double volume); 116 void SetVolumeOnIOThread(double volume);
128 void SetAutomaticGainControlOnIOThread(bool enabled); 117 void SetAutomaticGainControlOnIOThread(bool enabled);
129 118
130 // MessageLoop::DestructionObserver implementation for the IO loop. 119 // MessageLoop::DestructionObserver implementation for the IO loop.
131 // If the IO loop dies before we do, we shut down the audio thread from here. 120 // If the IO loop dies before we do, we shut down the audio thread from here.
132 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; 121 virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
133 122
134 AudioParameters audio_parameters_; 123 AudioParameters audio_parameters_;
135 124
136 CaptureCallback* callback_; 125 CaptureCallback* callback_;
137 CaptureEventHandler* event_handler_;
138 126
139 AudioInputIPC* ipc_; 127 AudioInputIPC* ipc_;
140 128
141 // Our stream ID on the message filter. Only modified on the IO thread. 129 // Our stream ID on the message filter. Only modified on the IO thread.
142 int stream_id_; 130 int stream_id_;
143 131
144 // The media session ID used to identify which input device to be started. 132 // The media session ID used to identify which input device to be started.
145 // Only modified on the IO thread. 133 // Only modified in Initialize() and ShutDownOnIOThread().
146 int session_id_; 134 int session_id_;
147 135
148 // State variable used to indicate it is waiting for a OnDeviceReady()
149 // callback. Only modified on the IO thread.
150 bool pending_device_ready_;
151
152 // Stores the Automatic Gain Control state. Default is false. 136 // Stores the Automatic Gain Control state. Default is false.
153 // Only modified on the IO thread. 137 // Only modified on the IO thread.
154 bool agc_is_enabled_; 138 bool agc_is_enabled_;
155 139
156 // Our audio thread callback class. See source file for details. 140 // Our audio thread callback class. See source file for details.
157 class AudioThreadCallback; 141 class AudioThreadCallback;
158 142
159 // In order to avoid a race between OnStreamCreated and Stop(), we use this 143 // In order to avoid a race between OnStreamCreated and Stop(), we use this
160 // guard to control stopping and starting the audio thread. 144 // guard to control stopping and starting the audio thread.
161 base::Lock audio_thread_lock_; 145 base::Lock audio_thread_lock_;
162 AudioDeviceThread audio_thread_; 146 AudioDeviceThread audio_thread_;
163 scoped_ptr<AudioInputDevice::AudioThreadCallback> audio_callback_; 147 scoped_ptr<AudioInputDevice::AudioThreadCallback> audio_callback_;
164 148
165 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice); 149 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice);
166 }; 150 };
167 151
168 } // namespace media 152 } // namespace media
169 153
170 #endif // MEDIA_AUDIO_AUDIO_INPUT_DEVICE_H_ 154 #endif // MEDIA_AUDIO_AUDIO_INPUT_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698