OLD | NEW |
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 #include "media/audio/audio_device_thread.h" | 5 #include "media/audio/audio_device_thread.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 base::AutoLock auto_lock(callback_lock_); | 170 base::AutoLock auto_lock(callback_lock_); |
171 if (callback_) | 171 if (callback_) |
172 callback_->Process(pending_data); | 172 callback_->Process(pending_data); |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 // AudioDeviceThread::Callback implementation | 176 // AudioDeviceThread::Callback implementation |
177 | 177 |
178 AudioDeviceThread::Callback::Callback( | 178 AudioDeviceThread::Callback::Callback( |
179 const AudioParameters& audio_parameters, | 179 const AudioParameters& audio_parameters, |
180 base::SharedMemoryHandle memory, int memory_length) | 180 base::SharedMemoryHandle memory, |
| 181 int memory_length, |
| 182 int total_segments) |
181 : audio_parameters_(audio_parameters), | 183 : audio_parameters_(audio_parameters), |
182 samples_per_ms_(audio_parameters.sample_rate() / 1000), | 184 samples_per_ms_(audio_parameters.sample_rate() / 1000), |
183 bytes_per_ms_(audio_parameters.channels() * | 185 bytes_per_ms_(audio_parameters.channels() * |
184 (audio_parameters_.bits_per_sample() / 8) * | 186 (audio_parameters_.bits_per_sample() / 8) * |
185 samples_per_ms_), | 187 samples_per_ms_), |
186 shared_memory_(memory, false), | 188 shared_memory_(memory, false), |
187 memory_length_(memory_length) { | 189 memory_length_(memory_length), |
| 190 total_segments_(total_segments) { |
188 CHECK_NE(bytes_per_ms_, 0); // Catch division by zero early. | 191 CHECK_NE(bytes_per_ms_, 0); // Catch division by zero early. |
189 CHECK_NE(samples_per_ms_, 0); | 192 CHECK_NE(samples_per_ms_, 0); |
| 193 CHECK_GT(total_segments_, 0); |
| 194 CHECK_EQ(memory_length_ % total_segments_, 0); |
| 195 segment_length_ = memory_length_ / total_segments_; |
190 } | 196 } |
191 | 197 |
192 AudioDeviceThread::Callback::~Callback() {} | 198 AudioDeviceThread::Callback::~Callback() {} |
193 | 199 |
194 void AudioDeviceThread::Callback::InitializeOnAudioThread() { | 200 void AudioDeviceThread::Callback::InitializeOnAudioThread() { |
195 MapSharedMemory(); | 201 MapSharedMemory(); |
196 CHECK(shared_memory_.memory()); | 202 CHECK(shared_memory_.memory()); |
197 } | 203 } |
198 | 204 |
199 } // namespace media. | 205 } // namespace media. |
OLD | NEW |