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

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

Issue 4661001: Simplified AudioOutputStream interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: - Created 10 years, 1 month 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_output_mac.h ('k') | media/audio/mac/audio_output_mac_unittest.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) 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
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.GetPacketSize();
72
71 // Silence buffer has a duration of 6ms to simulate the behavior of Windows. 73 // 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 74 // This value is choosen by experiments and macs cannot keep up with
73 // anything less than 6ms. 75 // anything less than 6ms.
74 silence_bytes_ = format_.mBytesPerFrame * params.sample_rate * 6 / 1000; 76 silence_bytes_ = format_.mBytesPerFrame * params.sample_rate * 6 / 1000;
75 } 77 }
76 78
77 PCMQueueOutAudioOutputStream::~PCMQueueOutAudioOutputStream() { 79 PCMQueueOutAudioOutputStream::~PCMQueueOutAudioOutputStream() {
78 } 80 }
79 81
80 void PCMQueueOutAudioOutputStream::HandleError(OSStatus err) { 82 void PCMQueueOutAudioOutputStream::HandleError(OSStatus err) {
81 // source_ can be set to NULL from another thread. We need to cache its 83 // 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 84 // pointer while we operate here. Note that does not mean that the source
83 // has been destroyed. 85 // has been destroyed.
84 AudioSourceCallback* source = source_; 86 AudioSourceCallback* source = source_;
85 if (source) 87 if (source)
86 source->OnError(this, static_cast<int>(err)); 88 source->OnError(this, static_cast<int>(err));
87 NOTREACHED() << "error code " << err; 89 NOTREACHED() << "error code " << err;
88 } 90 }
89 91
90 bool PCMQueueOutAudioOutputStream::Open(uint32 packet_size) { 92 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 93 // Create the actual queue object and let the OS use its own thread to
96 // run its CFRunLoop. 94 // run its CFRunLoop.
97 OSStatus err = AudioQueueNewOutput(&format_, RenderCallback, this, NULL, 95 OSStatus err = AudioQueueNewOutput(&format_, RenderCallback, this, NULL,
98 kCFRunLoopCommonModes, 0, &audio_queue_); 96 kCFRunLoopCommonModes, 0, &audio_queue_);
99 if (err != noErr) { 97 if (err != noErr) {
100 HandleError(err); 98 HandleError(err);
101 return false; 99 return false;
102 } 100 }
103 // Allocate the hardware-managed buffers. 101 // Allocate the hardware-managed buffers.
104 for (uint32 ix = 0; ix != kNumBuffers; ++ix) { 102 for (uint32 ix = 0; ix != kNumBuffers; ++ix) {
105 err = AudioQueueAllocateBuffer(audio_queue_, packet_size, &buffer_[ix]); 103 err = AudioQueueAllocateBuffer(audio_queue_, packet_size_, &buffer_[ix]);
106 if (err != noErr) { 104 if (err != noErr) {
107 HandleError(err); 105 HandleError(err);
108 return false; 106 return false;
109 } 107 }
110 // Allocate memory for user data. 108 // Allocate memory for user data.
111 buffer_[ix]->mUserData = new AudioQueueUserData(); 109 buffer_[ix]->mUserData = new AudioQueueUserData();
112 } 110 }
113 // Set initial volume here. 111 // Set initial volume here.
114 err = AudioQueueSetParameter(audio_queue_, kAudioQueueParam_Volume, 1.0); 112 err = AudioQueueSetParameter(audio_queue_, kAudioQueueParam_Volume, 1.0);
115 if (err != noErr) { 113 if (err != noErr) {
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 HandleError(err); 286 HandleError(err);
289 return; 287 return;
290 } 288 }
291 } 289 }
292 err = AudioQueueStart(audio_queue_, NULL); 290 err = AudioQueueStart(audio_queue_, NULL);
293 if (err != noErr) { 291 if (err != noErr) {
294 HandleError(err); 292 HandleError(err);
295 return; 293 return;
296 } 294 }
297 } 295 }
OLDNEW
« no previous file with comments | « media/audio/mac/audio_output_mac.h ('k') | media/audio/mac/audio_output_mac_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698