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

Side by Side Diff: media/audio/mac/audio_low_latency_output_mac.cc

Issue 10832285: Switch OnMoreData() to use AudioBus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase. Comments. Created 8 years, 3 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
« no previous file with comments | « media/audio/mac/audio_low_latency_output_mac.h ('k') | media/audio/mac/audio_output_mac.h » ('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/mac/audio_low_latency_output_mac.h" 5 #include "media/audio/mac/audio_low_latency_output_mac.h"
6 6
7 #include <CoreServices/CoreServices.h> 7 #include <CoreServices/CoreServices.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 // and notify the audio manager, which likely will destroy this object. 46 // and notify the audio manager, which likely will destroy this object.
47 47
48 AUAudioOutputStream::AUAudioOutputStream( 48 AUAudioOutputStream::AUAudioOutputStream(
49 AudioManagerMac* manager, const AudioParameters& params) 49 AudioManagerMac* manager, const AudioParameters& params)
50 : manager_(manager), 50 : manager_(manager),
51 source_(NULL), 51 source_(NULL),
52 output_unit_(0), 52 output_unit_(0),
53 output_device_id_(kAudioObjectUnknown), 53 output_device_id_(kAudioObjectUnknown),
54 volume_(1), 54 volume_(1),
55 hardware_latency_frames_(0), 55 hardware_latency_frames_(0),
56 stopped_(false) { 56 stopped_(false),
57 audio_bus_(AudioBus::Create(params)) {
57 // We must have a manager. 58 // We must have a manager.
58 DCHECK(manager_); 59 DCHECK(manager_);
59 // A frame is one sample across all channels. In interleaved audio the per 60 // A frame is one sample across all channels. In interleaved audio the per
60 // frame fields identify the set of n |channels|. In uncompressed audio, a 61 // frame fields identify the set of n |channels|. In uncompressed audio, a
61 // packet is always one frame. 62 // packet is always one frame.
62 format_.mSampleRate = params.sample_rate(); 63 format_.mSampleRate = params.sample_rate();
63 format_.mFormatID = kAudioFormatLinearPCM; 64 format_.mFormatID = kAudioFormatLinearPCM;
64 format_.mFormatFlags = kLinearPCMFormatFlagIsPacked | 65 format_.mFormatFlags = kLinearPCMFormatFlagIsPacked |
65 kLinearPCMFormatFlagIsSignedInteger; 66 kLinearPCMFormatFlagIsSignedInteger;
66 format_.mBitsPerChannel = params.bits_per_sample(); 67 format_.mBitsPerChannel = params.bits_per_sample();
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 OSStatus AUAudioOutputStream::Render(UInt32 number_of_frames, 220 OSStatus AUAudioOutputStream::Render(UInt32 number_of_frames,
220 AudioBufferList* io_data, 221 AudioBufferList* io_data,
221 const AudioTimeStamp* output_time_stamp) { 222 const AudioTimeStamp* output_time_stamp) {
222 // Update the playout latency. 223 // Update the playout latency.
223 double playout_latency_frames = GetPlayoutLatency(output_time_stamp); 224 double playout_latency_frames = GetPlayoutLatency(output_time_stamp);
224 225
225 AudioBuffer& buffer = io_data->mBuffers[0]; 226 AudioBuffer& buffer = io_data->mBuffers[0];
226 uint8* audio_data = reinterpret_cast<uint8*>(buffer.mData); 227 uint8* audio_data = reinterpret_cast<uint8*>(buffer.mData);
227 uint32 hardware_pending_bytes = static_cast<uint32> 228 uint32 hardware_pending_bytes = static_cast<uint32>
228 ((playout_latency_frames + 0.5) * format_.mBytesPerFrame); 229 ((playout_latency_frames + 0.5) * format_.mBytesPerFrame);
229 uint32 filled = source_->OnMoreData( 230
230 audio_data, buffer.mDataByteSize, 231 DCHECK_EQ(number_of_frames, static_cast<UInt32>(audio_bus_->frames()));
231 AudioBuffersState(0, hardware_pending_bytes)); 232 int frames_filled = source_->OnMoreData(
233 audio_bus_.get(), AudioBuffersState(0, hardware_pending_bytes));
234 // Note: If this ever changes to output raw float the data must be clipped and
235 // sanitized since it may come from an untrusted source such as NaCl.
236 audio_bus_->ToInterleaved(
237 frames_filled, format_.mBitsPerChannel / 8, audio_data);
238 uint32 filled = frames_filled * format_.mBytesPerFrame;
232 239
233 // Handle channel order for 5.1 audio. 240 // Handle channel order for 5.1 audio.
241 // TODO(dalecurtis): Channel downmixing, upmixing, should be done in mixer;
242 // volume adjust should use SSE optimized vector_fmul() prior to interleave.
234 if (format_.mChannelsPerFrame == 6) { 243 if (format_.mChannelsPerFrame == 6) {
235 if (format_.mBitsPerChannel == 8) { 244 if (format_.mBitsPerChannel == 8) {
236 SwizzleCoreAudioLayout5_1(reinterpret_cast<uint8*>(audio_data), filled); 245 SwizzleCoreAudioLayout5_1(reinterpret_cast<uint8*>(audio_data), filled);
237 } else if (format_.mBitsPerChannel == 16) { 246 } else if (format_.mBitsPerChannel == 16) {
238 SwizzleCoreAudioLayout5_1(reinterpret_cast<int16*>(audio_data), filled); 247 SwizzleCoreAudioLayout5_1(reinterpret_cast<int16*>(audio_data), filled);
239 } else if (format_.mBitsPerChannel == 32) { 248 } else if (format_.mBitsPerChannel == 32) {
240 SwizzleCoreAudioLayout5_1(reinterpret_cast<int32*>(audio_data), filled); 249 SwizzleCoreAudioLayout5_1(reinterpret_cast<int32*>(audio_data), filled);
241 } 250 }
242 } 251 }
243 252
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 UInt64 output_time_ns = AudioConvertHostTimeToNanos( 356 UInt64 output_time_ns = AudioConvertHostTimeToNanos(
348 output_time_stamp->mHostTime); 357 output_time_stamp->mHostTime);
349 UInt64 now_ns = AudioConvertHostTimeToNanos(AudioGetCurrentHostTime()); 358 UInt64 now_ns = AudioConvertHostTimeToNanos(AudioGetCurrentHostTime());
350 double delay_frames = static_cast<double> 359 double delay_frames = static_cast<double>
351 (1e-9 * (output_time_ns - now_ns) * format_.mSampleRate); 360 (1e-9 * (output_time_ns - now_ns) * format_.mSampleRate);
352 361
353 return (delay_frames + hardware_latency_frames_); 362 return (delay_frames + hardware_latency_frames_);
354 } 363 }
355 364
356 } // namespace media 365 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/mac/audio_low_latency_output_mac.h ('k') | media/audio/mac/audio_output_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698