Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "media/audio/audio_util.h" | 9 #include "media/audio/audio_util.h" |
| 10 #include "media/audio/mac/audio_manager_mac.h" | 10 #include "media/audio/mac/audio_manager_mac.h" |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 | 38 |
| 39 #if !defined(MAC_OS_X_VERSION_10_6) || \ | 39 #if !defined(MAC_OS_X_VERSION_10_6) || \ |
| 40 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6 | 40 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_6 |
| 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, AudioParameters params) | 47 AudioManagerMac* manager, AudioParameters params) |
| 48 : format_(), | 48 : format_(), |
| 49 audio_queue_(NULL), | 49 audio_queue_(NULL), |
| 50 buffer_(), | 50 buffer_(), |
| 51 source_(NULL), | 51 source_(NULL), |
| 52 manager_(manager), | 52 manager_(manager), |
| 53 silence_bytes_(0), | 53 silence_bytes_(0), |
| 54 volume_(1), | 54 volume_(1), |
| 55 pending_bytes_(0) { | 55 pending_bytes_(0) { |
| 56 // We must have a manager. | 56 // We must have a manager. |
| 57 DCHECK(manager_); | 57 DCHECK(manager_); |
| 58 // A frame is one sample across all channels. In interleaved audio the per | 58 // A frame is one sample across all channels. In interleaved audio the per |
| 59 // frame fields identify the set of n |channels|. In uncompressed audio, a | 59 // frame fields identify the set of n |channels|. In uncompressed audio, a |
| 60 // packet is always one frame. | 60 // packet is always one frame. |
| 61 format_.mSampleRate = params.sample_rate; | 61 format_.mSampleRate = params.sample_rate; |
| 62 format_.mFormatID = kAudioFormatLinearPCM; | 62 format_.mFormatID = kAudioFormatLinearPCM; |
| 63 format_.mFormatFlags = kLinearPCMFormatFlagIsPacked | | 63 format_.mFormatFlags = kLinearPCMFormatFlagIsPacked | |
| 64 kLinearPCMFormatFlagIsSignedInteger; | 64 kLinearPCMFormatFlagIsSignedInteger; |
| 65 format_.mBitsPerChannel = params.bits_per_sample; | 65 format_.mBitsPerChannel = params.bits_per_sample; |
| 66 format_.mChannelsPerFrame = params.channels; | 66 format_.mChannelsPerFrame = params.channels; |
| 67 format_.mFramesPerPacket = 1; | 67 format_.mFramesPerPacket = 1; |
| 68 format_.mBytesPerPacket = (format_.mBitsPerChannel * params.channels) / 8; | 68 format_.mBytesPerPacket = (format_.mBitsPerChannel * params.channels) / 8; |
| 69 format_.mBytesPerFrame = format_.mBytesPerPacket; | 69 format_.mBytesPerFrame = format_.mBytesPerPacket; |
| 70 | 70 |
| 71 packet_size_ = params.samples_per_packet * params.channels * | |
|
scherkus (not reviewing)
2010/11/09 02:28:31
this seems to be duplicated a bit... can packet_si
Sergey Ulanov
2010/11/09 22:29:58
Done.
| |
| 72 params.bits_per_sample / 8; | |
| 73 | |
| 71 // Silence buffer has a duration of 6ms to simulate the behavior of Windows. | 74 // Silence buffer has a duration of 6ms to simulate the behavior of Windows. |
| 72 // This value is choosen by experiments and macs cannot keep up with | 75 // This value is choosen by experiments and macs cannot keep up with |
| 73 // anything less than 6ms. | 76 // anything less than 6ms. |
| 74 silence_bytes_ = format_.mBytesPerFrame * params.sample_rate * 6 / 1000; | 77 silence_bytes_ = format_.mBytesPerFrame * params.sample_rate * 6 / 1000; |
| 75 } | 78 } |
| 76 | 79 |
| 77 PCMQueueOutAudioOutputStream::~PCMQueueOutAudioOutputStream() { | 80 PCMQueueOutAudioOutputStream::~PCMQueueOutAudioOutputStream() { |
| 78 } | 81 } |
| 79 | 82 |
| 80 void PCMQueueOutAudioOutputStream::HandleError(OSStatus err) { | 83 void PCMQueueOutAudioOutputStream::HandleError(OSStatus err) { |
| 81 // source_ can be set to NULL from another thread. We need to cache its | 84 // source_ can be set to NULL from another thread. We need to cache its |
| 82 // pointer while we operate here. Note that does not mean that the source | 85 // pointer while we operate here. Note that does not mean that the source |
| 83 // has been destroyed. | 86 // has been destroyed. |
| 84 AudioSourceCallback* source = source_; | 87 AudioSourceCallback* source = source_; |
| 85 if (source) | 88 if (source) |
| 86 source->OnError(this, static_cast<int>(err)); | 89 source->OnError(this, static_cast<int>(err)); |
| 87 NOTREACHED() << "error code " << err; | 90 NOTREACHED() << "error code " << err; |
| 88 } | 91 } |
| 89 | 92 |
| 90 bool PCMQueueOutAudioOutputStream::Open(uint32 packet_size) { | 93 bool PCMQueueOutAudioOutputStream::Open() { |
| 91 if (0 == packet_size) { | |
| 92 // TODO(cpu) : Impelement default buffer computation. | |
| 93 return false; | |
| 94 } | |
| 95 // Create the actual queue object and let the OS use its own thread to | 94 // Create the actual queue object and let the OS use its own thread to |
| 96 // run its CFRunLoop. | 95 // run its CFRunLoop. |
| 97 OSStatus err = AudioQueueNewOutput(&format_, RenderCallback, this, NULL, | 96 OSStatus err = AudioQueueNewOutput(&format_, RenderCallback, this, NULL, |
| 98 kCFRunLoopCommonModes, 0, &audio_queue_); | 97 kCFRunLoopCommonModes, 0, &audio_queue_); |
| 99 if (err != noErr) { | 98 if (err != noErr) { |
| 100 HandleError(err); | 99 HandleError(err); |
| 101 return false; | 100 return false; |
| 102 } | 101 } |
| 103 // Allocate the hardware-managed buffers. | 102 // Allocate the hardware-managed buffers. |
| 104 for (uint32 ix = 0; ix != kNumBuffers; ++ix) { | 103 for (uint32 ix = 0; ix != kNumBuffers; ++ix) { |
| 105 err = AudioQueueAllocateBuffer(audio_queue_, packet_size, &buffer_[ix]); | 104 err = AudioQueueAllocateBuffer(audio_queue_, packet_size_, &buffer_[ix]); |
| 106 if (err != noErr) { | 105 if (err != noErr) { |
| 107 HandleError(err); | 106 HandleError(err); |
| 108 return false; | 107 return false; |
| 109 } | 108 } |
| 110 // Allocate memory for user data. | 109 // Allocate memory for user data. |
| 111 buffer_[ix]->mUserData = new AudioQueueUserData(); | 110 buffer_[ix]->mUserData = new AudioQueueUserData(); |
| 112 } | 111 } |
| 113 // Set initial volume here. | 112 // Set initial volume here. |
| 114 err = AudioQueueSetParameter(audio_queue_, kAudioQueueParam_Volume, 1.0); | 113 err = AudioQueueSetParameter(audio_queue_, kAudioQueueParam_Volume, 1.0); |
| 115 if (err != noErr) { | 114 if (err != noErr) { |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 HandleError(err); | 287 HandleError(err); |
| 289 return; | 288 return; |
| 290 } | 289 } |
| 291 } | 290 } |
| 292 err = AudioQueueStart(audio_queue_, NULL); | 291 err = AudioQueueStart(audio_queue_, NULL); |
| 293 if (err != noErr) { | 292 if (err != noErr) { |
| 294 HandleError(err); | 293 HandleError(err); |
| 295 return; | 294 return; |
| 296 } | 295 } |
| 297 } | 296 } |
| OLD | NEW |