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

Side by Side Diff: media/audio/audio_device_thread.cc

Issue 1687213002: Express audio delay more precisely in frames rather than milliseconds. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 10 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
« no previous file with comments | « media/audio/audio_device_thread.h ('k') | media/audio/audio_input_device.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "media/audio/audio_device_thread.h" 5 #include "media/audio/audio_device_thread.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 ++buffer_index; 203 ++buffer_index;
204 size_t bytes_sent = socket_.Send(&buffer_index, sizeof(buffer_index)); 204 size_t bytes_sent = socket_.Send(&buffer_index, sizeof(buffer_index));
205 if (bytes_sent != sizeof(buffer_index)) 205 if (bytes_sent != sizeof(buffer_index))
206 break; 206 break;
207 } 207 }
208 } 208 }
209 } 209 }
210 210
211 // AudioDeviceThread::Callback implementation 211 // AudioDeviceThread::Callback implementation
212 212
213 AudioDeviceThread::Callback::Callback( 213 AudioDeviceThread::Callback::Callback(const AudioParameters& audio_parameters,
214 const AudioParameters& audio_parameters, 214 base::SharedMemoryHandle memory,
215 base::SharedMemoryHandle memory, 215 int memory_length,
216 int memory_length, 216 int total_segments)
217 int total_segments)
218 : audio_parameters_(audio_parameters), 217 : audio_parameters_(audio_parameters),
219 samples_per_ms_(audio_parameters.sample_rate() / 1000), 218 samples_per_ms_(static_cast<double>(audio_parameters.sample_rate()) /
219 base::Time::kMillisecondsPerSecond),
220 bytes_per_ms_(audio_parameters.channels() * 220 bytes_per_ms_(audio_parameters.channels() *
221 (audio_parameters_.bits_per_sample() / 8) * 221 (audio_parameters_.bits_per_sample() / 8) *
222 samples_per_ms_), 222 samples_per_ms_),
223 bytes_per_frame_(audio_parameters.GetBytesPerFrame()),
223 shared_memory_(memory, false), 224 shared_memory_(memory, false),
224 memory_length_(memory_length), 225 memory_length_(memory_length),
225 total_segments_(total_segments) { 226 total_segments_(total_segments) {
226 CHECK_NE(bytes_per_ms_, 0); // Catch division by zero early. 227 CHECK_NE(bytes_per_ms_, 0.0); // Catch division by zero early.
227 CHECK_NE(samples_per_ms_, 0); 228 CHECK_NE(samples_per_ms_, 0.0);
229 CHECK_NE(bytes_per_frame_, 0u);
228 CHECK_GT(total_segments_, 0); 230 CHECK_GT(total_segments_, 0);
229 CHECK_EQ(memory_length_ % total_segments_, 0); 231 CHECK_EQ(memory_length_ % total_segments_, 0);
230 segment_length_ = memory_length_ / total_segments_; 232 segment_length_ = memory_length_ / total_segments_;
231 } 233 }
232 234
233 AudioDeviceThread::Callback::~Callback() {} 235 AudioDeviceThread::Callback::~Callback() {}
234 236
235 void AudioDeviceThread::Callback::InitializeOnAudioThread() { 237 void AudioDeviceThread::Callback::InitializeOnAudioThread() {
236 MapSharedMemory(); 238 MapSharedMemory();
237 CHECK(shared_memory_.memory()); 239 CHECK(shared_memory_.memory());
238 } 240 }
239 241
240 } // namespace media. 242 } // namespace media.
OLDNEW
« no previous file with comments | « media/audio/audio_device_thread.h ('k') | media/audio/audio_input_device.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698