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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
156 // Release the reference for the thread. Note that after this, the Thread | 156 // Release the reference for the thread. Note that after this, the Thread |
157 // instance will most likely be deleted. | 157 // instance will most likely be deleted. |
158 Release(); | 158 Release(); |
159 } | 159 } |
160 | 160 |
161 void AudioDeviceThread::Thread::Run() { | 161 void AudioDeviceThread::Thread::Run() { |
162 while (true) { | 162 while (true) { |
163 int pending_data = 0; | 163 int pending_data = 0; |
164 size_t bytes_read = socket_.Receive(&pending_data, sizeof(pending_data)); | 164 size_t bytes_read = socket_.Receive(&pending_data, sizeof(pending_data)); |
165 if (bytes_read != sizeof(pending_data)) { | 165 if (bytes_read != sizeof(pending_data)) { |
166 DCHECK_EQ(bytes_read, 0U); | 166 DCHECK_EQ(0U, bytes_read); |
DaleCurtis
2013/03/07 02:04:37
/shakes fist! :) nooooo!
| |
167 break; | 167 break; |
168 } | 168 } |
169 | 169 |
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), |
188 CHECK_NE(bytes_per_ms_, 0); // Catch division by zero early. | 190 total_segments_(total_segments) { |
189 CHECK_NE(samples_per_ms_, 0); | 191 CHECK_NE(0, bytes_per_ms_); // Catch division by zero early. |
DaleCurtis
2013/03/07 02:04:37
:head explodes:
| |
192 CHECK_NE(0, samples_per_ms_); | |
193 CHECK_LT(0, total_segments_); | |
194 CHECK_EQ(0, memory_length_ % total_segments_); | |
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 |