| 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/mac/audio_output_mac.h" | 5 #include "media/audio/mac/audio_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/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 enum { | 41 enum { |
| 42 kAudioQueueErr_EnqueueDuringReset = -66632 | 42 kAudioQueueErr_EnqueueDuringReset = -66632 |
| 43 }; | 43 }; |
| 44 #endif | 44 #endif |
| 45 | 45 |
| 46 PCMQueueOutAudioOutputStream::PCMQueueOutAudioOutputStream( | 46 PCMQueueOutAudioOutputStream::PCMQueueOutAudioOutputStream( |
| 47 AudioManagerMac* manager, const AudioParameters& params) | 47 AudioManagerMac* manager, const AudioParameters& params) |
| 48 : audio_queue_(NULL), | 48 : audio_queue_(NULL), |
| 49 source_(NULL), | 49 source_(NULL), |
| 50 manager_(manager), | 50 manager_(manager), |
| 51 packet_size_(params.GetPacketSize()), | 51 packet_size_(params.GetBytesPerBuffer()), |
| 52 silence_bytes_(0), | 52 silence_bytes_(0), |
| 53 volume_(1), | 53 volume_(1), |
| 54 pending_bytes_(0), | 54 pending_bytes_(0), |
| 55 num_source_channels_(params.channels), | 55 num_source_channels_(params.channels()), |
| 56 source_layout_(params.channel_layout), | 56 source_layout_(params.channel_layout()), |
| 57 num_core_channels_(0), | 57 num_core_channels_(0), |
| 58 should_swizzle_(false), | 58 should_swizzle_(false), |
| 59 should_down_mix_(false) { | 59 should_down_mix_(false) { |
| 60 // We must have a manager. | 60 // We must have a manager. |
| 61 DCHECK(manager_); | 61 DCHECK(manager_); |
| 62 // A frame is one sample across all channels. In interleaved audio the per | 62 // A frame is one sample across all channels. In interleaved audio the per |
| 63 // frame fields identify the set of n |channels|. In uncompressed audio, a | 63 // frame fields identify the set of n |channels|. In uncompressed audio, a |
| 64 // packet is always one frame. | 64 // packet is always one frame. |
| 65 format_.mSampleRate = params.sample_rate; | 65 format_.mSampleRate = params.sample_rate(); |
| 66 format_.mFormatID = kAudioFormatLinearPCM; | 66 format_.mFormatID = kAudioFormatLinearPCM; |
| 67 format_.mFormatFlags = kLinearPCMFormatFlagIsPacked; | 67 format_.mFormatFlags = kLinearPCMFormatFlagIsPacked; |
| 68 format_.mBitsPerChannel = params.bits_per_sample; | 68 format_.mBitsPerChannel = params.bits_per_sample(); |
| 69 format_.mChannelsPerFrame = params.channels; | 69 format_.mChannelsPerFrame = params.channels(); |
| 70 format_.mFramesPerPacket = 1; | 70 format_.mFramesPerPacket = 1; |
| 71 format_.mBytesPerPacket = (format_.mBitsPerChannel * params.channels) / 8; | 71 format_.mBytesPerPacket = (format_.mBitsPerChannel * params.channels()) / 8; |
| 72 format_.mBytesPerFrame = format_.mBytesPerPacket; | 72 format_.mBytesPerFrame = format_.mBytesPerPacket; |
| 73 format_.mReserved = 0; | 73 format_.mReserved = 0; |
| 74 | 74 |
| 75 memset(buffer_, 0, sizeof(buffer_)); | 75 memset(buffer_, 0, sizeof(buffer_)); |
| 76 memset(core_channel_orderings_, 0, sizeof(core_channel_orderings_)); | 76 memset(core_channel_orderings_, 0, sizeof(core_channel_orderings_)); |
| 77 memset(channel_remap_, 0, sizeof(channel_remap_)); | 77 memset(channel_remap_, 0, sizeof(channel_remap_)); |
| 78 | 78 |
| 79 if (params.bits_per_sample > 8) { | 79 if (params.bits_per_sample() > 8) { |
| 80 format_.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger; | 80 format_.mFormatFlags |= kLinearPCMFormatFlagIsSignedInteger; |
| 81 } | 81 } |
| 82 | 82 |
| 83 // Silence buffer has a duration of 6ms to simulate the behavior of Windows. | 83 // Silence buffer has a duration of 6ms to simulate the behavior of Windows. |
| 84 // This value is choosen by experiments and macs cannot keep up with | 84 // This value is choosen by experiments and macs cannot keep up with |
| 85 // anything less than 6ms. | 85 // anything less than 6ms. |
| 86 silence_bytes_ = format_.mBytesPerFrame * params.sample_rate * 6 / 1000; | 86 silence_bytes_ = format_.mBytesPerFrame * params.sample_rate() * 6 / 1000; |
| 87 } | 87 } |
| 88 | 88 |
| 89 PCMQueueOutAudioOutputStream::~PCMQueueOutAudioOutputStream() { | 89 PCMQueueOutAudioOutputStream::~PCMQueueOutAudioOutputStream() { |
| 90 } | 90 } |
| 91 | 91 |
| 92 void PCMQueueOutAudioOutputStream::HandleError(OSStatus err) { | 92 void PCMQueueOutAudioOutputStream::HandleError(OSStatus err) { |
| 93 // source_ can be set to NULL from another thread. We need to cache its | 93 // source_ can be set to NULL from another thread. We need to cache its |
| 94 // pointer while we operate here. Note that does not mean that the source | 94 // pointer while we operate here. Note that does not mean that the source |
| 95 // has been destroyed. | 95 // has been destroyed. |
| 96 AudioSourceCallback* source = GetSource(); | 96 AudioSourceCallback* source = GetSource(); |
| (...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 void PCMQueueOutAudioOutputStream::SetSource(AudioSourceCallback* source) { | 520 void PCMQueueOutAudioOutputStream::SetSource(AudioSourceCallback* source) { |
| 521 base::AutoLock lock(source_lock_); | 521 base::AutoLock lock(source_lock_); |
| 522 source_ = source; | 522 source_ = source; |
| 523 } | 523 } |
| 524 | 524 |
| 525 AudioOutputStream::AudioSourceCallback* | 525 AudioOutputStream::AudioSourceCallback* |
| 526 PCMQueueOutAudioOutputStream::GetSource() { | 526 PCMQueueOutAudioOutputStream::GetSource() { |
| 527 base::AutoLock lock(source_lock_); | 527 base::AutoLock lock(source_lock_); |
| 528 return source_; | 528 return source_; |
| 529 } | 529 } |
| OLD | NEW |