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

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: addressed palmer's comments 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, 99 int length,
109 int total_segments) OVERRIDE; 100 int total_segments) OVERRIDE;
110 virtual void OnVolume(double volume) OVERRIDE; 101 virtual void OnVolume(double volume) OVERRIDE;
111 virtual void OnStateChanged( 102 virtual void OnStateChanged(
112 AudioInputIPCDelegate::State state) OVERRIDE; 103 AudioInputIPCDelegate::State state) OVERRIDE;
113 virtual void OnDeviceReady(const std::string& device_id) OVERRIDE;
114 virtual void OnIPCClosed() OVERRIDE; 104 virtual void OnIPCClosed() OVERRIDE;
115 105
116 friend class base::RefCountedThreadSafe<AudioInputDevice>; 106 friend class base::RefCountedThreadSafe<AudioInputDevice>;
117 virtual ~AudioInputDevice(); 107 virtual ~AudioInputDevice();
118 108
119 private: 109 private:
120 // Methods called on IO thread ---------------------------------------------- 110 // Methods called on IO thread ----------------------------------------------
121 // The following methods are tasks posted on the IO thread that needs to 111 // The following methods are tasks posted on the IO thread that needs to
122 // be executed on that thread. They interact with AudioInputMessageFilter and 112 // be executed on that thread. They interact with AudioInputMessageFilter and
123 // sends IPC messages on that thread. 113 // sends IPC messages on that thread.
124 void InitializeOnIOThread(); 114 void InitializeOnIOThread();
125 void SetSessionIdOnIOThread(int session_id);
126 void StartOnIOThread(); 115 void StartOnIOThread();
127 void ShutDownOnIOThread(); 116 void ShutDownOnIOThread();
128 void SetVolumeOnIOThread(double volume); 117 void SetVolumeOnIOThread(double volume);
129 void SetAutomaticGainControlOnIOThread(bool enabled); 118 void SetAutomaticGainControlOnIOThread(bool enabled);
130 119
131 // MessageLoop::DestructionObserver implementation for the IO loop. 120 // MessageLoop::DestructionObserver implementation for the IO loop.
132 // If the IO loop dies before we do, we shut down the audio thread from here. 121 // If the IO loop dies before we do, we shut down the audio thread from here.
133 virtual void WillDestroyCurrentMessageLoop() OVERRIDE; 122 virtual void WillDestroyCurrentMessageLoop() OVERRIDE;
134 123
135 AudioParameters audio_parameters_; 124 AudioParameters audio_parameters_;
136 125
137 CaptureCallback* callback_; 126 CaptureCallback* callback_;
138 CaptureEventHandler* event_handler_;
139 127
140 AudioInputIPC* ipc_; 128 AudioInputIPC* ipc_;
141 129
142 // Our stream ID on the message filter. Only modified on the IO thread. 130 // Our stream ID on the message filter. Only modified on the IO thread.
143 int stream_id_; 131 int stream_id_;
144 132
145 // The media session ID used to identify which input device to be started. 133 // The media session ID used to identify which input device to be started.
146 // Only modified on the IO thread. 134 // Only modified in Initialize() and ShutDownOnIOThread().
147 int session_id_; 135 int session_id_;
148 136
149 // State variable used to indicate it is waiting for a OnDeviceReady()
150 // callback. Only modified on the IO thread.
151 bool pending_device_ready_;
152
153 // Stores the Automatic Gain Control state. Default is false. 137 // Stores the Automatic Gain Control state. Default is false.
154 // Only modified on the IO thread. 138 // Only modified on the IO thread.
155 bool agc_is_enabled_; 139 bool agc_is_enabled_;
156 140
157 // Our audio thread callback class. See source file for details. 141 // Our audio thread callback class. See source file for details.
158 class AudioThreadCallback; 142 class AudioThreadCallback;
159 143
160 // In order to avoid a race between OnStreamCreated and Stop(), we use this 144 // In order to avoid a race between OnStreamCreated and Stop(), we use this
161 // guard to control stopping and starting the audio thread. 145 // guard to control stopping and starting the audio thread.
162 base::Lock audio_thread_lock_; 146 base::Lock audio_thread_lock_;
163 AudioDeviceThread audio_thread_; 147 AudioDeviceThread audio_thread_;
164 scoped_ptr<AudioInputDevice::AudioThreadCallback> audio_callback_; 148 scoped_ptr<AudioInputDevice::AudioThreadCallback> audio_callback_;
165 149
166 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice); 150 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioInputDevice);
167 }; 151 };
168 152
169 } // namespace media 153 } // namespace media
170 154
171 #endif // MEDIA_AUDIO_AUDIO_INPUT_DEVICE_H_ 155 #endif // MEDIA_AUDIO_AUDIO_INPUT_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698