OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 rendering unit utilizing audio output stream provided | 5 // Low-latency audio rendering unit utilizing audio output stream provided |
6 // by browser process through IPC. | 6 // by browser process through IPC. |
7 // | 7 // |
8 // Relationship of classes. | 8 // Relationship of classes. |
9 // | 9 // |
10 // AudioOutputController AudioDevice | 10 // AudioOutputController AudioDevice |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // Methods called on main render thread ------------------------------------- | 81 // Methods called on main render thread ------------------------------------- |
82 AudioDevice(size_t buffer_size, | 82 AudioDevice(size_t buffer_size, |
83 int channels, | 83 int channels, |
84 double sample_rate, | 84 double sample_rate, |
85 RenderCallback* callback); | 85 RenderCallback* callback); |
86 virtual ~AudioDevice(); | 86 virtual ~AudioDevice(); |
87 | 87 |
88 // Starts audio playback. | 88 // Starts audio playback. |
89 void Start(); | 89 void Start(); |
90 | 90 |
91 // Stops audio playback. Returns |true| on success. | 91 // Stops audio playback. |
92 bool Stop(); | 92 void Stop(); |
93 | 93 |
94 // Sets the playback volume, with range [0.0, 1.0] inclusive. | 94 // Sets the playback volume, with range [0.0, 1.0] inclusive. |
95 // Returns |true| on success. | 95 // Returns |true| on success. |
96 bool SetVolume(double volume); | 96 bool SetVolume(double volume); |
97 | 97 |
98 // Gets the playback volume, with range [0.0, 1.0] inclusive. | 98 // Gets the playback volume, with range [0.0, 1.0] inclusive. |
99 void GetVolume(double* volume); | 99 void GetVolume(double* volume); |
100 | 100 |
101 double sample_rate() const { return sample_rate_; } | 101 double sample_rate() const { return sample_rate_; } |
102 size_t buffer_size() const { return buffer_size_; } | 102 size_t buffer_size() const { return buffer_size_; } |
(...skipping 17 matching lines...) Expand all Loading... |
120 void InitializeOnIOThread(const AudioParameters& params); | 120 void InitializeOnIOThread(const AudioParameters& params); |
121 void StartOnIOThread(); | 121 void StartOnIOThread(); |
122 void ShutDownOnIOThread(base::WaitableEvent* completion); | 122 void ShutDownOnIOThread(base::WaitableEvent* completion); |
123 void SetVolumeOnIOThread(double volume); | 123 void SetVolumeOnIOThread(double volume); |
124 | 124 |
125 void Send(IPC::Message* message); | 125 void Send(IPC::Message* message); |
126 | 126 |
127 // Method called on the audio thread (+ one call on the IO thread) ---------- | 127 // Method called on the audio thread (+ one call on the IO thread) ---------- |
128 // Calls the client's callback for rendering audio. There will also be one | 128 // Calls the client's callback for rendering audio. There will also be one |
129 // initial call on the IO thread before the audio thread has been created. | 129 // initial call on the IO thread before the audio thread has been created. |
130 void FireRenderCallback(); | 130 void FireRenderCallback(int16* data); |
131 | 131 |
132 // DelegateSimpleThread::Delegate implementation. | 132 // DelegateSimpleThread::Delegate implementation. |
133 virtual void Run() OVERRIDE; | 133 virtual void Run() OVERRIDE; |
134 | 134 |
135 // Format | 135 // Format |
136 size_t buffer_size_; // in sample-frames | 136 size_t buffer_size_; // in sample-frames |
137 int channels_; | 137 int channels_; |
138 int bits_per_sample_; | 138 int bits_per_sample_; |
139 double sample_rate_; | 139 double sample_rate_; |
140 | 140 |
141 RenderCallback* callback_; | 141 RenderCallback* callback_; |
142 | 142 |
143 // The client callback renders audio into here. | 143 // The client callback renders audio into here. |
144 std::vector<float*> audio_data_; | 144 std::vector<float*> audio_data_; |
145 | 145 |
146 // The client stores the last reported audio delay in this member. | 146 // The client stores the last reported audio delay in this member. |
147 // The delay shall reflect the amount of audio which still resides in | 147 // The delay shall reflect the amount of audio which still resides in |
148 // the output buffer, i.e., the expected audio output delay. | 148 // the output buffer, i.e., the expected audio output delay. |
149 int audio_delay_milliseconds_; | 149 int audio_delay_milliseconds_; |
150 | 150 |
151 // The current volume scaling [0.0, 1.0] of the audio stream. | 151 // The current volume scaling [0.0, 1.0] of the audio stream. |
152 double volume_; | 152 double volume_; |
153 | 153 |
154 // Callbacks for rendering audio occur on this thread. | 154 // Callbacks for rendering audio occur on this thread. |
155 scoped_ptr<base::DelegateSimpleThread> audio_thread_; | 155 scoped_ptr<base::DelegateSimpleThread> audio_thread_; |
156 | 156 |
157 // IPC message stuff. | |
158 base::SharedMemory* shared_memory() { return shared_memory_.get(); } | |
159 base::SyncSocket* socket() { return socket_.get(); } | |
160 void* shared_memory_data() { return shared_memory()->memory(); } | |
161 | |
162 // Cached audio message filter (lives on the main render thread). | 157 // Cached audio message filter (lives on the main render thread). |
163 scoped_refptr<AudioMessageFilter> filter_; | 158 scoped_refptr<AudioMessageFilter> filter_; |
164 | 159 |
165 // Our stream ID on the message filter. Only accessed on the IO thread. | 160 // Our stream ID on the message filter. Only accessed on the IO thread. |
166 int32 stream_id_; | 161 int32 stream_id_; |
167 | 162 |
168 // Data transfer between browser and render process uses a combination | 163 // Data transfer between browser and render process uses a combination |
169 // of sync sockets and shared memory to provide lowest possible latency. | 164 // of sync sockets and shared memory to provide lowest possible latency. |
170 scoped_ptr<base::SharedMemory> shared_memory_; | 165 base::SharedMemoryHandle shared_memory_handle_; |
171 scoped_ptr<base::SyncSocket> socket_; | 166 base::SyncSocket::Handle socket_handle_; |
| 167 int memory_length_; |
172 | 168 |
173 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioDevice); | 169 DISALLOW_IMPLICIT_CONSTRUCTORS(AudioDevice); |
174 }; | 170 }; |
175 | 171 |
176 #endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_H_ | 172 #endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_H_ |
OLD | NEW |