annotate libao2/ao_coreaudio.c @ 29946:54bacf6a38ca

Update the SuperH VEU vidix driver with code that calls fsync() after each frame to make sure the frame is flushed in case of deferred io. Patch by Magnus Damm, damm opensource se
author cehoyos
date Thu, 10 Dec 2009 23:16:08 +0000
parents 02dec439f717
children 9d09ff127c25
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29209
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1 /*
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
2 * CoreAudio audio output driver for Mac OS X
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
3 *
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
4 * original copyright (C) Timothy J. Wood - Aug 2000
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
5 * ported to MPlayer libao2 by Dan Christiansen
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
6 *
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
7 * The S/PDIF part of the code is based on the auhal audio output
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
8 * module from VideoLAN:
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
9 * Copyright (c) 2006 Derk-Jan Hartman <hartman at videolan dot org>
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
10 *
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
11 * This file is part of MPlayer.
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
12 *
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
13 * MPlayer is free software; you can redistribute it and/or modify
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
14 * it under the terms of the GNU General Public License as published by
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
15 * the Free Software Foundation; either version 2 of the License, or
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
16 * (at your option) any later version.
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
17 *
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
18 * MPlayer is distributed in the hope that it will be useful,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
21 * GNU General Public License for more details.
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
22 *
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
23 * You should have received a copy of the GNU General Public License along
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
24 * along with MPlayer; if not, write to the Free Software
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
26 */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
27
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
28 /*
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
29 * The MacOS X CoreAudio framework doesn't mesh as simply as some
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
30 * simpler frameworks do. This is due to the fact that CoreAudio pulls
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
31 * audio samples rather than having them pushed at it (which is nice
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
32 * when you are wanting to do good buffering of audio).
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
33 *
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
34 * AC-3 and MPEG audio passthrough is possible, but has never been tested
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
35 * due to lack of a soundcard that supports it.
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
36 */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
37
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
38 #include <CoreServices/CoreServices.h>
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
39 #include <AudioUnit/AudioUnit.h>
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
40 #include <AudioToolbox/AudioToolbox.h>
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
41 #include <stdio.h>
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
42 #include <string.h>
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
43 #include <stdlib.h>
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
44 #include <inttypes.h>
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
45 #include <sys/types.h>
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
46 #include <unistd.h>
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
47
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
48 #include "config.h"
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
49 #include "mp_msg.h"
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
50
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
51 #include "audio_out.h"
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
52 #include "audio_out_internal.h"
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
53 #include "libaf/af_format.h"
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
54 #include "osdep/timer.h"
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
55 #include "libavutil/fifo.h"
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
56
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
57 static const ao_info_t info =
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
58 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
59 "Darwin/Mac OS X native audio output",
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
60 "coreaudio",
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
61 "Timothy J. Wood & Dan Christiansen & Chris Roccati",
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
62 ""
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
63 };
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
64
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
65 LIBAO_EXTERN(coreaudio)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
66
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
67 /* Prefix for all mp_msg() calls */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
68 #define ao_msg(a, b, c...) mp_msg(a, b, "AO: [coreaudio] " c)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
69
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
70 typedef struct ao_coreaudio_s
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
71 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
72 AudioDeviceID i_selected_dev; /* Keeps DeviceID of the selected device. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
73 int b_supports_digital; /* Does the currently selected device support digital mode? */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
74 int b_digital; /* Are we running in digital mode? */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
75 int b_muted; /* Are we muted in digital mode? */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
76
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
77 /* AudioUnit */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
78 AudioUnit theOutputUnit;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
79
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
80 /* CoreAudio SPDIF mode specific */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
81 pid_t i_hog_pid; /* Keeps the pid of our hog status. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
82 AudioStreamID i_stream_id; /* The StreamID that has a cac3 streamformat */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
83 int i_stream_index; /* The index of i_stream_id in an AudioBufferList */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
84 AudioStreamBasicDescription stream_format;/* The format we changed the stream to */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
85 AudioStreamBasicDescription sfmt_revert; /* The original format of the stream */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
86 int b_revert; /* Whether we need to revert the stream format */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
87 int b_changed_mixing; /* Whether we need to set the mixing mode back */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
88 int b_stream_format_changed; /* Flag for main thread to reset stream's format to digital and reset buffer */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
89
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
90 /* Original common part */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
91 int packetSize;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
92 int paused;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
93
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
94 /* Ring-buffer */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
95 AVFifoBuffer *buffer;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
96 unsigned int buffer_len; ///< must always be num_chunks * chunk_size
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
97 unsigned int num_chunks;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
98 unsigned int chunk_size;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
99 } ao_coreaudio_t;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
100
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
101 static ao_coreaudio_t *ao = NULL;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
102
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
103 /**
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
104 * \brief add data to ringbuffer
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
105 */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
106 static int write_buffer(unsigned char* data, int len){
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
107 int free = ao->buffer_len - av_fifo_size(ao->buffer);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
108 if (len > free) len = free;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
109 return av_fifo_generic_write(ao->buffer, data, len, NULL);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
110 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
111
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
112 /**
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
113 * \brief remove data from ringbuffer
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
114 */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
115 static int read_buffer(unsigned char* data,int len){
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
116 int buffered = av_fifo_size(ao->buffer);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
117 if (len > buffered) len = buffered;
29439
02dec439f717 100l, av_fifo_generic_read does not return anything useful, so ignore its
reimar
parents: 29401
diff changeset
118 av_fifo_generic_read(ao->buffer, data, len, NULL);
02dec439f717 100l, av_fifo_generic_read does not return anything useful, so ignore its
reimar
parents: 29401
diff changeset
119 return len;
29209
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
120 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
121
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
122 OSStatus theRenderProc(void *inRefCon, AudioUnitRenderActionFlags *inActionFlags, const AudioTimeStamp *inTimeStamp, UInt32 inBusNumber, UInt32 inNumFrames, AudioBufferList *ioData)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
123 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
124 int amt=av_fifo_size(ao->buffer);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
125 int req=(inNumFrames)*ao->packetSize;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
126
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
127 if(amt>req)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
128 amt=req;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
129
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
130 if(amt)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
131 read_buffer((unsigned char *)ioData->mBuffers[0].mData, amt);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
132 else audio_pause();
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
133 ioData->mBuffers[0].mDataByteSize = amt;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
134
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
135 return noErr;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
136 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
137
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
138 static int control(int cmd,void *arg){
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
139 ao_control_vol_t *control_vol;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
140 OSStatus err;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
141 Float32 vol;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
142 switch (cmd) {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
143 case AOCONTROL_GET_VOLUME:
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
144 control_vol = (ao_control_vol_t*)arg;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
145 if (ao->b_digital) {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
146 // Digital output has no volume adjust.
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
147 return CONTROL_FALSE;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
148 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
149 err = AudioUnitGetParameter(ao->theOutputUnit, kHALOutputParam_Volume, kAudioUnitScope_Global, 0, &vol);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
150
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
151 if(err==0) {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
152 // printf("GET VOL=%f\n", vol);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
153 control_vol->left=control_vol->right=vol*100.0/4.0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
154 return CONTROL_TRUE;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
155 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
156 else {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
157 ao_msg(MSGT_AO, MSGL_WARN, "could not get HAL output volume: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
158 return CONTROL_FALSE;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
159 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
160
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
161 case AOCONTROL_SET_VOLUME:
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
162 control_vol = (ao_control_vol_t*)arg;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
163
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
164 if (ao->b_digital) {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
165 // Digital output can not set volume. Here we have to return true
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
166 // to make mixer forget it. Else mixer will add a soft filter,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
167 // that's not we expected and the filter not support ac3 stream
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
168 // will cause mplayer die.
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
169
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
170 // Although not support set volume, but at least we support mute.
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
171 // MPlayer set mute by set volume to zero, we handle it.
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
172 if (control_vol->left == 0 && control_vol->right == 0)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
173 ao->b_muted = 1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
174 else
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
175 ao->b_muted = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
176 return CONTROL_TRUE;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
177 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29212
diff changeset
178
29209
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
179 vol=(control_vol->left+control_vol->right)*4.0/200.0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
180 err = AudioUnitSetParameter(ao->theOutputUnit, kHALOutputParam_Volume, kAudioUnitScope_Global, 0, vol, 0);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
181 if(err==0) {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
182 // printf("SET VOL=%f\n", vol);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
183 return CONTROL_TRUE;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
184 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
185 else {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
186 ao_msg(MSGT_AO, MSGL_WARN, "could not set HAL output volume: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
187 return CONTROL_FALSE;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
188 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
189 /* Everything is currently unimplemented */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
190 default:
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
191 return CONTROL_FALSE;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
192 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29212
diff changeset
193
29209
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
194 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
195
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
196
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
197 static void print_format(int lev, const char* str, const AudioStreamBasicDescription *f){
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
198 uint32_t flags=(uint32_t) f->mFormatFlags;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
199 ao_msg(MSGT_AO,lev, "%s %7.1fHz %lubit [%c%c%c%c][%lu][%lu][%lu][%lu][%lu] %s %s %s%s%s%s\n",
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
200 str, f->mSampleRate, f->mBitsPerChannel,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
201 (int)(f->mFormatID & 0xff000000) >> 24,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
202 (int)(f->mFormatID & 0x00ff0000) >> 16,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
203 (int)(f->mFormatID & 0x0000ff00) >> 8,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
204 (int)(f->mFormatID & 0x000000ff) >> 0,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
205 f->mFormatFlags, f->mBytesPerPacket,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
206 f->mFramesPerPacket, f->mBytesPerFrame,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
207 f->mChannelsPerFrame,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
208 (flags&kAudioFormatFlagIsFloat) ? "float" : "int",
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
209 (flags&kAudioFormatFlagIsBigEndian) ? "BE" : "LE",
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
210 (flags&kAudioFormatFlagIsSignedInteger) ? "S" : "U",
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
211 (flags&kAudioFormatFlagIsPacked) ? " packed" : "",
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
212 (flags&kAudioFormatFlagIsAlignedHigh) ? " aligned" : "",
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
213 (flags&kAudioFormatFlagIsNonInterleaved) ? " ni" : "" );
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
214 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
215
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
216
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
217 static int AudioDeviceSupportsDigital( AudioDeviceID i_dev_id );
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
218 static int AudioStreamSupportsDigital( AudioStreamID i_stream_id );
29212
eda346733b8c Add missing 'void' to parameterless function declarations.
diego
parents: 29209
diff changeset
219 static int OpenSPDIF(void);
29209
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
220 static int AudioStreamChangeFormat( AudioStreamID i_stream_id, AudioStreamBasicDescription change_format );
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
221 static OSStatus RenderCallbackSPDIF( AudioDeviceID inDevice,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
222 const AudioTimeStamp * inNow,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
223 const void * inInputData,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
224 const AudioTimeStamp * inInputTime,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
225 AudioBufferList * outOutputData,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
226 const AudioTimeStamp * inOutputTime,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
227 void * threadGlobals );
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
228 static OSStatus StreamListener( AudioStreamID inStream,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
229 UInt32 inChannel,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
230 AudioDevicePropertyID inPropertyID,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
231 void * inClientData );
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
232 static OSStatus DeviceListener( AudioDeviceID inDevice,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
233 UInt32 inChannel,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
234 Boolean isInput,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
235 AudioDevicePropertyID inPropertyID,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
236 void* inClientData );
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
237
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
238 static int init(int rate,int channels,int format,int flags)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
239 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
240 AudioStreamBasicDescription inDesc;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29212
diff changeset
241 ComponentDescription desc;
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29212
diff changeset
242 Component comp;
29209
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
243 AURenderCallbackStruct renderCallback;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
244 OSStatus err;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
245 UInt32 size, maxFrames, i_param_size;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
246 char *psz_name;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
247 AudioDeviceID devid_def = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
248 int b_alive;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
249
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
250 ao_msg(MSGT_AO,MSGL_V, "init([%dHz][%dch][%s][%d])\n", rate, channels, af_fmt2str_short(format), flags);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
251
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
252 ao = calloc(1, sizeof(ao_coreaudio_t));
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
253
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
254 ao->i_selected_dev = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
255 ao->b_supports_digital = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
256 ao->b_digital = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
257 ao->b_muted = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
258 ao->b_stream_format_changed = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
259 ao->i_hog_pid = -1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
260 ao->i_stream_id = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
261 ao->i_stream_index = -1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
262 ao->b_revert = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
263 ao->b_changed_mixing = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
264
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
265 /* Probe whether device support S/PDIF stream output if input is AC3 stream. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
266 if ((format & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_AC3)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
267 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
268 /* Find the ID of the default Device. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
269 i_param_size = sizeof(AudioDeviceID);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
270 err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
271 &i_param_size, &devid_def);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
272 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
273 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
274 ao_msg(MSGT_AO, MSGL_WARN, "could not get default audio device: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
275 goto err_out;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
276 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
277
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
278 /* Retrieve the length of the device name. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
279 i_param_size = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
280 err = AudioDeviceGetPropertyInfo(devid_def, 0, 0,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
281 kAudioDevicePropertyDeviceName,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
282 &i_param_size, NULL);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
283 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
284 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
285 ao_msg(MSGT_AO, MSGL_WARN, "could not get default audio device name length: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
286 goto err_out;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
287 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
288
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
289 /* Retrieve the name of the device. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
290 psz_name = (char *)malloc(i_param_size);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
291 err = AudioDeviceGetProperty(devid_def, 0, 0,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
292 kAudioDevicePropertyDeviceName,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
293 &i_param_size, psz_name);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
294 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
295 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
296 ao_msg(MSGT_AO, MSGL_WARN, "could not get default audio device name: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
297 free( psz_name);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
298 goto err_out;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
299 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
300
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
301 ao_msg(MSGT_AO,MSGL_V, "got default audio output device ID: %#lx Name: %s\n", devid_def, psz_name );
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
302
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
303 if (AudioDeviceSupportsDigital(devid_def))
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
304 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
305 ao->b_supports_digital = 1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
306 ao->i_selected_dev = devid_def;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
307 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
308 ao_msg(MSGT_AO,MSGL_V, "probe default audio output device whether support digital s/pdif output:%d\n", ao->b_supports_digital );
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
309
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
310 free( psz_name);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
311 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
312
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
313 // Build Description for the input format
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
314 inDesc.mSampleRate=rate;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
315 inDesc.mFormatID=ao->b_supports_digital ? kAudioFormat60958AC3 : kAudioFormatLinearPCM;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
316 inDesc.mChannelsPerFrame=channels;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
317 switch(format&AF_FORMAT_BITS_MASK){
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
318 case AF_FORMAT_8BIT:
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
319 inDesc.mBitsPerChannel=8;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
320 break;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
321 case AF_FORMAT_16BIT:
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
322 inDesc.mBitsPerChannel=16;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
323 break;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
324 case AF_FORMAT_24BIT:
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
325 inDesc.mBitsPerChannel=24;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
326 break;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
327 case AF_FORMAT_32BIT:
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
328 inDesc.mBitsPerChannel=32;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
329 break;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
330 default:
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
331 ao_msg(MSGT_AO, MSGL_WARN, "Unsupported format (0x%08x)\n", format);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
332 goto err_out;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
333 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
334
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
335 if((format&AF_FORMAT_POINT_MASK)==AF_FORMAT_F) {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
336 // float
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
337 inDesc.mFormatFlags = kAudioFormatFlagIsFloat|kAudioFormatFlagIsPacked;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
338 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
339 else if((format&AF_FORMAT_SIGN_MASK)==AF_FORMAT_SI) {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
340 // signed int
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
341 inDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger|kAudioFormatFlagIsPacked;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
342 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
343 else {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
344 // unsigned int
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
345 inDesc.mFormatFlags = kAudioFormatFlagIsPacked;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
346 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
347 if ((format & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_AC3) {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
348 // Currently ac3 input (comes from hwac3) is always in native byte-order.
29401
f01023c524c3 Replace WORDS_BIGENDIAN by HAVE_BIGENDIAN in all internal code.
diego
parents: 29263
diff changeset
349 #if HAVE_BIGENDIAN
29209
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
350 inDesc.mFormatFlags |= kAudioFormatFlagIsBigEndian;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
351 #endif
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
352 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
353 else if ((format & AF_FORMAT_END_MASK) == AF_FORMAT_BE)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
354 inDesc.mFormatFlags |= kAudioFormatFlagIsBigEndian;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
355
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
356 inDesc.mFramesPerPacket = 1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
357 ao->packetSize = inDesc.mBytesPerPacket = inDesc.mBytesPerFrame = inDesc.mFramesPerPacket*channels*(inDesc.mBitsPerChannel/8);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
358 print_format(MSGL_V, "source:",&inDesc);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
359
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
360 if (ao->b_supports_digital)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
361 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
362 b_alive = 1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
363 i_param_size = sizeof(b_alive);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
364 err = AudioDeviceGetProperty(ao->i_selected_dev, 0, FALSE,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
365 kAudioDevicePropertyDeviceIsAlive,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
366 &i_param_size, &b_alive);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
367 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
368 ao_msg(MSGT_AO, MSGL_WARN, "could not check whether device is alive: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
369 if (!b_alive)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
370 ao_msg(MSGT_AO, MSGL_WARN, "device is not alive\n" );
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
371 /* S/PDIF output need device in HogMode. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
372 i_param_size = sizeof(ao->i_hog_pid);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
373 err = AudioDeviceGetProperty(ao->i_selected_dev, 0, FALSE,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
374 kAudioDevicePropertyHogMode,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
375 &i_param_size, &ao->i_hog_pid);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
376
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
377 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
378 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
379 /* This is not a fatal error. Some drivers simply don't support this property. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
380 ao_msg(MSGT_AO, MSGL_WARN, "could not check whether device is hogged: [%4.4s]\n",
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
381 (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
382 ao->i_hog_pid = -1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
383 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
384
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
385 if (ao->i_hog_pid != -1 && ao->i_hog_pid != getpid())
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
386 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
387 ao_msg(MSGT_AO, MSGL_WARN, "Selected audio device is exclusively in use by another program.\n" );
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
388 goto err_out;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
389 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
390 ao->stream_format = inDesc;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
391 return OpenSPDIF();
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
392 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
393
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
394 /* original analog output code */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
395 desc.componentType = kAudioUnitType_Output;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
396 desc.componentSubType = kAudioUnitSubType_DefaultOutput;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
397 desc.componentManufacturer = kAudioUnitManufacturer_Apple;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
398 desc.componentFlags = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
399 desc.componentFlagsMask = 0;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29212
diff changeset
400
29209
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
401 comp = FindNextComponent(NULL, &desc); //Finds an component that meets the desc spec's
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
402 if (comp == NULL) {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
403 ao_msg(MSGT_AO, MSGL_WARN, "Unable to find Output Unit component\n");
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
404 goto err_out;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
405 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29212
diff changeset
406
29209
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
407 err = OpenAComponent(comp, &(ao->theOutputUnit)); //gains access to the services provided by the component
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
408 if (err) {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
409 ao_msg(MSGT_AO, MSGL_WARN, "Unable to open Output Unit component: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
410 goto err_out;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
411 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
412
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29212
diff changeset
413 // Initialize AudioUnit
29209
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
414 err = AudioUnitInitialize(ao->theOutputUnit);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
415 if (err) {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
416 ao_msg(MSGT_AO, MSGL_WARN, "Unable to initialize Output Unit component: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
417 goto err_out1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
418 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
419
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
420 size = sizeof(AudioStreamBasicDescription);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
421 err = AudioUnitSetProperty(ao->theOutputUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &inDesc, size);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
422
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
423 if (err) {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
424 ao_msg(MSGT_AO, MSGL_WARN, "Unable to set the input format: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
425 goto err_out2;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
426 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
427
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
428 size = sizeof(UInt32);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
429 err = AudioUnitGetProperty(ao->theOutputUnit, kAudioDevicePropertyBufferSize, kAudioUnitScope_Input, 0, &maxFrames, &size);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29212
diff changeset
430
29209
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
431 if (err)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
432 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
433 ao_msg(MSGT_AO,MSGL_WARN, "AudioUnitGetProperty returned [%4.4s] when getting kAudioDevicePropertyBufferSize\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
434 goto err_out2;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
435 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
436
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
437 ao->chunk_size = maxFrames;//*inDesc.mBytesPerFrame;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29212
diff changeset
438
29209
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
439 ao_data.samplerate = inDesc.mSampleRate;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
440 ao_data.channels = inDesc.mChannelsPerFrame;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
441 ao_data.bps = ao_data.samplerate * inDesc.mBytesPerFrame;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
442 ao_data.outburst = ao->chunk_size;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
443 ao_data.buffersize = ao_data.bps;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
444
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
445 ao->num_chunks = (ao_data.bps+ao->chunk_size-1)/ao->chunk_size;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
446 ao->buffer_len = ao->num_chunks * ao->chunk_size;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
447 ao->buffer = av_fifo_alloc(ao->buffer_len);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29212
diff changeset
448
29209
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
449 ao_msg(MSGT_AO,MSGL_V, "using %5d chunks of %d bytes (buffer len %d bytes)\n", (int)ao->num_chunks, (int)ao->chunk_size, (int)ao->buffer_len);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
450
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
451 renderCallback.inputProc = theRenderProc;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
452 renderCallback.inputProcRefCon = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
453 err = AudioUnitSetProperty(ao->theOutputUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &renderCallback, sizeof(AURenderCallbackStruct));
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
454 if (err) {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
455 ao_msg(MSGT_AO, MSGL_WARN, "Unable to set the render callback: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
456 goto err_out2;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
457 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
458
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
459 reset();
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29212
diff changeset
460
29209
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
461 return CONTROL_OK;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
462
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
463 err_out2:
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
464 AudioUnitUninitialize(ao->theOutputUnit);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
465 err_out1:
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
466 CloseComponent(ao->theOutputUnit);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
467 err_out:
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
468 av_fifo_free(ao->buffer);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
469 free(ao);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
470 ao = NULL;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29212
diff changeset
471 return CONTROL_FALSE;
29209
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
472 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
473
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
474 /*****************************************************************************
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
475 * Setup a encoded digital stream (SPDIF)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
476 *****************************************************************************/
29212
eda346733b8c Add missing 'void' to parameterless function declarations.
diego
parents: 29209
diff changeset
477 static int OpenSPDIF(void)
29209
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
478 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
479 OSStatus err = noErr;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
480 UInt32 i_param_size, b_mix = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
481 Boolean b_writeable = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
482 AudioStreamID *p_streams = NULL;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
483 int i, i_streams = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
484
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
485 /* Start doing the SPDIF setup process. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
486 ao->b_digital = 1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
487
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
488 /* Hog the device. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
489 i_param_size = sizeof(ao->i_hog_pid);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
490 ao->i_hog_pid = getpid() ;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
491
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
492 err = AudioDeviceSetProperty(ao->i_selected_dev, 0, 0, FALSE,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
493 kAudioDevicePropertyHogMode, i_param_size, &ao->i_hog_pid);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
494
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
495 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
496 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
497 ao_msg(MSGT_AO, MSGL_WARN, "failed to set hogmode: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
498 ao->i_hog_pid = -1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
499 goto err_out;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
500 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
501
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
502 /* Set mixable to false if we are allowed to. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
503 err = AudioDeviceGetPropertyInfo(ao->i_selected_dev, 0, FALSE,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
504 kAudioDevicePropertySupportsMixing,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
505 &i_param_size, &b_writeable);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
506 err = AudioDeviceGetProperty(ao->i_selected_dev, 0, FALSE,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
507 kAudioDevicePropertySupportsMixing,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
508 &i_param_size, &b_mix);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
509 if (err != noErr && b_writeable)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
510 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
511 b_mix = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
512 err = AudioDeviceSetProperty(ao->i_selected_dev, 0, 0, FALSE,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
513 kAudioDevicePropertySupportsMixing,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
514 i_param_size, &b_mix);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
515 ao->b_changed_mixing = 1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
516 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
517 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
518 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
519 ao_msg(MSGT_AO, MSGL_WARN, "failed to set mixmode: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
520 goto err_out;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
521 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
522
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
523 /* Get a list of all the streams on this device. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
524 err = AudioDeviceGetPropertyInfo(ao->i_selected_dev, 0, FALSE,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
525 kAudioDevicePropertyStreams,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
526 &i_param_size, NULL);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
527 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
528 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
529 ao_msg(MSGT_AO, MSGL_WARN, "could not get number of streams: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
530 goto err_out;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
531 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
532
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
533 i_streams = i_param_size / sizeof(AudioStreamID);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
534 p_streams = (AudioStreamID *)malloc(i_param_size);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
535 if (p_streams == NULL)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
536 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
537 ao_msg(MSGT_AO, MSGL_WARN, "out of memory\n" );
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
538 goto err_out;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
539 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
540
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
541 err = AudioDeviceGetProperty(ao->i_selected_dev, 0, FALSE,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
542 kAudioDevicePropertyStreams,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
543 &i_param_size, p_streams);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
544 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
545 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
546 ao_msg(MSGT_AO, MSGL_WARN, "could not get number of streams: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
547 if (p_streams) free(p_streams);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
548 goto err_out;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
549 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
550
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
551 ao_msg(MSGT_AO, MSGL_V, "current device stream number: %d\n", i_streams);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
552
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
553 for (i = 0; i < i_streams && ao->i_stream_index < 0; ++i)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
554 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
555 /* Find a stream with a cac3 stream. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
556 AudioStreamBasicDescription *p_format_list = NULL;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
557 int i_formats = 0, j = 0, b_digital = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
558
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
559 /* Retrieve all the stream formats supported by each output stream. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
560 err = AudioStreamGetPropertyInfo(p_streams[i], 0,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
561 kAudioStreamPropertyPhysicalFormats,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
562 &i_param_size, NULL);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
563 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
564 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
565 ao_msg(MSGT_AO, MSGL_WARN, "could not get number of streamformats: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
566 continue;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
567 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
568
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
569 i_formats = i_param_size / sizeof(AudioStreamBasicDescription);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
570 p_format_list = (AudioStreamBasicDescription *)malloc(i_param_size);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
571 if (p_format_list == NULL)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
572 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
573 ao_msg(MSGT_AO, MSGL_WARN, "could not malloc the memory\n" );
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
574 continue;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
575 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
576
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
577 err = AudioStreamGetProperty(p_streams[i], 0,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
578 kAudioStreamPropertyPhysicalFormats,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
579 &i_param_size, p_format_list);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
580 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
581 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
582 ao_msg(MSGT_AO, MSGL_WARN, "could not get the list of streamformats: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
583 if (p_format_list) free(p_format_list);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
584 continue;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
585 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
586
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
587 /* Check if one of the supported formats is a digital format. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
588 for (j = 0; j < i_formats; ++j)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
589 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
590 if (p_format_list[j].mFormatID == 'IAC3' ||
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
591 p_format_list[j].mFormatID == kAudioFormat60958AC3)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
592 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
593 b_digital = 1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
594 break;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
595 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
596 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
597
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
598 if (b_digital)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
599 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
600 /* If this stream supports a digital (cac3) format, then set it. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
601 int i_requested_rate_format = -1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
602 int i_current_rate_format = -1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
603 int i_backup_rate_format = -1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
604
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
605 ao->i_stream_id = p_streams[i];
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
606 ao->i_stream_index = i;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
607
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
608 if (ao->b_revert == 0)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
609 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
610 /* Retrieve the original format of this stream first if not done so already. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
611 i_param_size = sizeof(ao->sfmt_revert);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
612 err = AudioStreamGetProperty(ao->i_stream_id, 0,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
613 kAudioStreamPropertyPhysicalFormat,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
614 &i_param_size,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
615 &ao->sfmt_revert);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
616 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
617 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
618 ao_msg(MSGT_AO, MSGL_WARN, "could not retrieve the original streamformat: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
619 if (p_format_list) free(p_format_list);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
620 continue;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
621 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
622 ao->b_revert = 1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
623 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
624
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
625 for (j = 0; j < i_formats; ++j)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
626 if (p_format_list[j].mFormatID == 'IAC3' ||
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
627 p_format_list[j].mFormatID == kAudioFormat60958AC3)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
628 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
629 if (p_format_list[j].mSampleRate == ao->stream_format.mSampleRate)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
630 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
631 i_requested_rate_format = j;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
632 break;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
633 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
634 if (p_format_list[j].mSampleRate == ao->sfmt_revert.mSampleRate)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
635 i_current_rate_format = j;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
636 else if (i_backup_rate_format < 0 || p_format_list[j].mSampleRate > p_format_list[i_backup_rate_format].mSampleRate)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
637 i_backup_rate_format = j;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
638 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
639
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
640 if (i_requested_rate_format >= 0) /* We prefer to output at the samplerate of the original audio. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
641 ao->stream_format = p_format_list[i_requested_rate_format];
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
642 else if (i_current_rate_format >= 0) /* If not possible, we will try to use the current samplerate of the device. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
643 ao->stream_format = p_format_list[i_current_rate_format];
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
644 else ao->stream_format = p_format_list[i_backup_rate_format]; /* And if we have to, any digital format will be just fine (highest rate possible). */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
645 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
646 if (p_format_list) free(p_format_list);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
647 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
648 if (p_streams) free(p_streams);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
649
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
650 if (ao->i_stream_index < 0)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
651 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
652 ao_msg(MSGT_AO, MSGL_WARN, "can not find any digital output stream format when OpenSPDIF().\n");
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
653 goto err_out;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
654 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
655
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
656 print_format(MSGL_V, "original stream format:", &ao->sfmt_revert);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
657
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
658 if (!AudioStreamChangeFormat(ao->i_stream_id, ao->stream_format))
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
659 goto err_out;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
660
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
661 err = AudioDeviceAddPropertyListener(ao->i_selected_dev,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
662 kAudioPropertyWildcardChannel,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
663 0,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
664 kAudioDevicePropertyDeviceHasChanged,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
665 DeviceListener,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
666 NULL);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
667 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
668 ao_msg(MSGT_AO, MSGL_WARN, "AudioDeviceAddPropertyListener for kAudioDevicePropertyDeviceHasChanged failed: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
669
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
670
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
671 /* FIXME: If output stream is not native byte-order, we need change endian somewhere. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
672 /* Although there's no such case reported. */
29401
f01023c524c3 Replace WORDS_BIGENDIAN by HAVE_BIGENDIAN in all internal code.
diego
parents: 29263
diff changeset
673 #if HAVE_BIGENDIAN
29209
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
674 if (!(ao->stream_format.mFormatFlags & kAudioFormatFlagIsBigEndian))
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
675 #else
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
676 if (ao->stream_format.mFormatFlags & kAudioFormatFlagIsBigEndian)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
677 #endif
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
678 ao_msg(MSGT_AO, MSGL_WARN, "output stream has a no-native byte-order, digital output may failed.\n");
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
679
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
680 /* For ac3/dts, just use packet size 6144 bytes as chunk size. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
681 ao->chunk_size = ao->stream_format.mBytesPerPacket;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
682
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
683 ao_data.samplerate = ao->stream_format.mSampleRate;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
684 ao_data.channels = ao->stream_format.mChannelsPerFrame;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
685 ao_data.bps = ao_data.samplerate * (ao->stream_format.mBytesPerPacket/ao->stream_format.mFramesPerPacket);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
686 ao_data.outburst = ao->chunk_size;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
687 ao_data.buffersize = ao_data.bps;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
688
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
689 ao->num_chunks = (ao_data.bps+ao->chunk_size-1)/ao->chunk_size;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
690 ao->buffer_len = ao->num_chunks * ao->chunk_size;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
691 ao->buffer = av_fifo_alloc(ao->buffer_len);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
692
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
693 ao_msg(MSGT_AO,MSGL_V, "using %5d chunks of %d bytes (buffer len %d bytes)\n", (int)ao->num_chunks, (int)ao->chunk_size, (int)ao->buffer_len);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
694
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
695
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
696 /* Add IOProc callback. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
697 err = AudioDeviceAddIOProc(ao->i_selected_dev,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
698 (AudioDeviceIOProc)RenderCallbackSPDIF,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
699 (void *)ao);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
700 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
701 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
702 ao_msg(MSGT_AO, MSGL_WARN, "AudioDeviceAddIOProc failed: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
703 goto err_out1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
704 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
705
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
706 reset();
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
707
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
708 return CONTROL_TRUE;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
709
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
710 err_out1:
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
711 if (ao->b_revert)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
712 AudioStreamChangeFormat(ao->i_stream_id, ao->sfmt_revert);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
713 err_out:
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
714 if (ao->b_changed_mixing && ao->sfmt_revert.mFormatID != kAudioFormat60958AC3)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
715 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
716 int b_mix = 1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
717 err = AudioDeviceSetProperty(ao->i_selected_dev, 0, 0, FALSE,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
718 kAudioDevicePropertySupportsMixing,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
719 i_param_size, &b_mix);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
720 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
721 ao_msg(MSGT_AO, MSGL_WARN, "failed to set mixmode: [%4.4s]\n",
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
722 (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
723 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
724 if (ao->i_hog_pid == getpid())
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
725 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
726 ao->i_hog_pid = -1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
727 i_param_size = sizeof(ao->i_hog_pid);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
728 err = AudioDeviceSetProperty(ao->i_selected_dev, 0, 0, FALSE,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
729 kAudioDevicePropertyHogMode,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
730 i_param_size, &ao->i_hog_pid);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
731 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
732 ao_msg(MSGT_AO, MSGL_WARN, "Could not release hogmode: [%4.4s]\n",
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
733 (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
734 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
735 av_fifo_free(ao->buffer);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
736 free(ao);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
737 ao = NULL;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29212
diff changeset
738 return CONTROL_FALSE;
29209
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
739 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
740
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
741 /*****************************************************************************
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
742 * AudioDeviceSupportsDigital: Check i_dev_id for digital stream support.
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
743 *****************************************************************************/
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
744 static int AudioDeviceSupportsDigital( AudioDeviceID i_dev_id )
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
745 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
746 OSStatus err = noErr;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
747 UInt32 i_param_size = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
748 AudioStreamID *p_streams = NULL;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
749 int i = 0, i_streams = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
750 int b_return = CONTROL_FALSE;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
751
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
752 /* Retrieve all the output streams. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
753 err = AudioDeviceGetPropertyInfo(i_dev_id, 0, FALSE,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
754 kAudioDevicePropertyStreams,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
755 &i_param_size, NULL);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
756 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
757 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
758 ao_msg(MSGT_AO,MSGL_V, "could not get number of streams: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
759 return CONTROL_FALSE;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
760 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
761
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
762 i_streams = i_param_size / sizeof(AudioStreamID);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
763 p_streams = (AudioStreamID *)malloc(i_param_size);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
764 if (p_streams == NULL)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
765 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
766 ao_msg(MSGT_AO,MSGL_V, "out of memory\n");
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
767 return CONTROL_FALSE;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
768 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
769
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
770 err = AudioDeviceGetProperty(i_dev_id, 0, FALSE,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
771 kAudioDevicePropertyStreams,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
772 &i_param_size, p_streams);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
773
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
774 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
775 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
776 ao_msg(MSGT_AO,MSGL_V, "could not get number of streams: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
777 free(p_streams);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
778 return CONTROL_FALSE;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
779 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
780
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
781 for (i = 0; i < i_streams; ++i)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
782 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
783 if (AudioStreamSupportsDigital(p_streams[i]))
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
784 b_return = CONTROL_OK;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
785 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
786
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
787 free(p_streams);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
788 return b_return;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
789 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
790
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
791 /*****************************************************************************
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
792 * AudioStreamSupportsDigital: Check i_stream_id for digital stream support.
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
793 *****************************************************************************/
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
794 static int AudioStreamSupportsDigital( AudioStreamID i_stream_id )
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
795 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
796 OSStatus err = noErr;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
797 UInt32 i_param_size;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
798 AudioStreamBasicDescription *p_format_list = NULL;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
799 int i, i_formats, b_return = CONTROL_FALSE;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
800
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
801 /* Retrieve all the stream formats supported by each output stream. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
802 err = AudioStreamGetPropertyInfo(i_stream_id, 0,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
803 kAudioStreamPropertyPhysicalFormats,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
804 &i_param_size, NULL);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
805 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
806 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
807 ao_msg(MSGT_AO,MSGL_V, "could not get number of streamformats: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
808 return CONTROL_FALSE;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
809 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
810
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
811 i_formats = i_param_size / sizeof(AudioStreamBasicDescription);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
812 p_format_list = (AudioStreamBasicDescription *)malloc(i_param_size);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
813 if (p_format_list == NULL)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
814 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
815 ao_msg(MSGT_AO,MSGL_V, "could not malloc the memory\n" );
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
816 return CONTROL_FALSE;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
817 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
818
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
819 err = AudioStreamGetProperty(i_stream_id, 0,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
820 kAudioStreamPropertyPhysicalFormats,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
821 &i_param_size, p_format_list);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
822 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
823 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
824 ao_msg(MSGT_AO,MSGL_V, "could not get the list of streamformats: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
825 free(p_format_list);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
826 return CONTROL_FALSE;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
827 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
828
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
829 for (i = 0; i < i_formats; ++i)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
830 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
831 print_format(MSGL_V, "supported format:", &p_format_list[i]);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
832
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
833 if (p_format_list[i].mFormatID == 'IAC3' ||
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
834 p_format_list[i].mFormatID == kAudioFormat60958AC3)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
835 b_return = CONTROL_OK;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
836 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
837
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
838 free(p_format_list);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
839 return b_return;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
840 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
841
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
842 /*****************************************************************************
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
843 * AudioStreamChangeFormat: Change i_stream_id to change_format
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
844 *****************************************************************************/
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
845 static int AudioStreamChangeFormat( AudioStreamID i_stream_id, AudioStreamBasicDescription change_format )
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
846 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
847 OSStatus err = noErr;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
848 UInt32 i_param_size = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
849 int i;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
850
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
851 static volatile int stream_format_changed;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
852 stream_format_changed = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
853
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
854 print_format(MSGL_V, "setting stream format:", &change_format);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
855
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
856 /* Install the callback. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
857 err = AudioStreamAddPropertyListener(i_stream_id, 0,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
858 kAudioStreamPropertyPhysicalFormat,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
859 StreamListener,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
860 (void *)&stream_format_changed);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
861 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
862 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
863 ao_msg(MSGT_AO, MSGL_WARN, "AudioStreamAddPropertyListener failed: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
864 return CONTROL_FALSE;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
865 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
866
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
867 /* Change the format. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
868 err = AudioStreamSetProperty(i_stream_id, 0, 0,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
869 kAudioStreamPropertyPhysicalFormat,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
870 sizeof(AudioStreamBasicDescription),
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
871 &change_format);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
872 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
873 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
874 ao_msg(MSGT_AO, MSGL_WARN, "could not set the stream format: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
875 return CONTROL_FALSE;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
876 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
877
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
878 /* The AudioStreamSetProperty is not only asynchronious,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
879 * it is also not Atomic, in its behaviour.
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
880 * Therefore we check 5 times before we really give up.
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
881 * FIXME: failing isn't actually implemented yet. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
882 for (i = 0; i < 5; ++i)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
883 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
884 AudioStreamBasicDescription actual_format;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
885 int j;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
886 for (j = 0; !stream_format_changed && j < 50; ++j)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
887 usec_sleep(10000);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
888 if (stream_format_changed)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
889 stream_format_changed = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
890 else
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
891 ao_msg(MSGT_AO, MSGL_V, "reached timeout\n" );
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
892
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
893 i_param_size = sizeof(AudioStreamBasicDescription);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
894 err = AudioStreamGetProperty(i_stream_id, 0,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
895 kAudioStreamPropertyPhysicalFormat,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
896 &i_param_size,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
897 &actual_format);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
898
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
899 print_format(MSGL_V, "actual format in use:", &actual_format);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
900 if (actual_format.mSampleRate == change_format.mSampleRate &&
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
901 actual_format.mFormatID == change_format.mFormatID &&
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
902 actual_format.mFramesPerPacket == change_format.mFramesPerPacket)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
903 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
904 /* The right format is now active. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
905 break;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
906 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
907 /* We need to check again. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
908 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
909
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
910 /* Removing the property listener. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
911 err = AudioStreamRemovePropertyListener(i_stream_id, 0,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
912 kAudioStreamPropertyPhysicalFormat,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
913 StreamListener);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
914 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
915 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
916 ao_msg(MSGT_AO, MSGL_WARN, "AudioStreamRemovePropertyListener failed: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
917 return CONTROL_FALSE;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
918 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
919
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
920 return CONTROL_TRUE;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
921 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
922
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
923 /*****************************************************************************
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
924 * RenderCallbackSPDIF: callback for SPDIF audio output
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
925 *****************************************************************************/
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
926 static OSStatus RenderCallbackSPDIF( AudioDeviceID inDevice,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
927 const AudioTimeStamp * inNow,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
928 const void * inInputData,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
929 const AudioTimeStamp * inInputTime,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
930 AudioBufferList * outOutputData,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
931 const AudioTimeStamp * inOutputTime,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
932 void * threadGlobals )
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
933 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
934 int amt = av_fifo_size(ao->buffer);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
935 int req = outOutputData->mBuffers[ao->i_stream_index].mDataByteSize;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
936
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
937 if (amt > req)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
938 amt = req;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
939 if (amt)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
940 read_buffer(ao->b_muted ? NULL : (unsigned char *)outOutputData->mBuffers[ao->i_stream_index].mData, amt);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
941
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
942 return noErr;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
943 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
944
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
945
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
946 static int play(void* output_samples,int num_bytes,int flags)
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 29212
diff changeset
947 {
29209
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
948 int wrote, b_digital;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
949
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
950 // Check whether we need to reset the digital output stream.
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
951 if (ao->b_digital && ao->b_stream_format_changed)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
952 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
953 ao->b_stream_format_changed = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
954 b_digital = AudioStreamSupportsDigital(ao->i_stream_id);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
955 if (b_digital)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
956 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
957 /* Current stream support digital format output, let's set it. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
958 ao_msg(MSGT_AO, MSGL_V, "detected current stream support digital, try to restore digital output...\n");
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
959
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
960 if (!AudioStreamChangeFormat(ao->i_stream_id, ao->stream_format))
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
961 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
962 ao_msg(MSGT_AO, MSGL_WARN, "restore digital output failed.\n");
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
963 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
964 else
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
965 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
966 ao_msg(MSGT_AO, MSGL_WARN, "restore digital output succeed.\n");
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
967 reset();
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
968 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
969 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
970 else
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
971 ao_msg(MSGT_AO, MSGL_V, "detected current stream do not support digital.\n");
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
972 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
973
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
974 wrote=write_buffer(output_samples, num_bytes);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
975 audio_resume();
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
976 return wrote;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
977 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
978
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
979 /* set variables and buffer to initial state */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
980 static void reset(void)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
981 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
982 audio_pause();
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
983 av_fifo_reset(ao->buffer);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
984 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
985
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
986
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
987 /* return available space */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
988 static int get_space(void)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
989 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
990 return ao->buffer_len - av_fifo_size(ao->buffer);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
991 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
992
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
993
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
994 /* return delay until audio is played */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
995 static float get_delay(void)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
996 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
997 // inaccurate, should also contain the data buffered e.g. by the OS
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
998 return (float)av_fifo_size(ao->buffer)/(float)ao_data.bps;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
999 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1000
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1001
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1002 /* unload plugin and deregister from coreaudio */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1003 static void uninit(int immed)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1004 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1005 OSStatus err = noErr;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1006 UInt32 i_param_size = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1007
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1008 if (!immed) {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1009 long long timeleft=(1000000LL*av_fifo_size(ao->buffer))/ao_data.bps;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1010 ao_msg(MSGT_AO,MSGL_DBG2, "%d bytes left @%d bps (%d usec)\n", av_fifo_size(ao->buffer), ao_data.bps, (int)timeleft);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1011 usec_sleep((int)timeleft);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1012 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1013
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1014 if (!ao->b_digital) {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1015 AudioOutputUnitStop(ao->theOutputUnit);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1016 AudioUnitUninitialize(ao->theOutputUnit);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1017 CloseComponent(ao->theOutputUnit);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1018 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1019 else {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1020 /* Stop device. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1021 err = AudioDeviceStop(ao->i_selected_dev,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1022 (AudioDeviceIOProc)RenderCallbackSPDIF);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1023 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1024 ao_msg(MSGT_AO, MSGL_WARN, "AudioDeviceStop failed: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1025
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1026 /* Remove IOProc callback. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1027 err = AudioDeviceRemoveIOProc(ao->i_selected_dev,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1028 (AudioDeviceIOProc)RenderCallbackSPDIF);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1029 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1030 ao_msg(MSGT_AO, MSGL_WARN, "AudioDeviceRemoveIOProc failed: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1031
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1032 if (ao->b_revert)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1033 AudioStreamChangeFormat(ao->i_stream_id, ao->sfmt_revert);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1034
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1035 if (ao->b_changed_mixing && ao->sfmt_revert.mFormatID != kAudioFormat60958AC3)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1036 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1037 int b_mix;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1038 Boolean b_writeable;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1039 /* Revert mixable to true if we are allowed to. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1040 err = AudioDeviceGetPropertyInfo(ao->i_selected_dev, 0, FALSE, kAudioDevicePropertySupportsMixing,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1041 &i_param_size, &b_writeable);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1042 err = AudioDeviceGetProperty(ao->i_selected_dev, 0, FALSE, kAudioDevicePropertySupportsMixing,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1043 &i_param_size, &b_mix);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1044 if (err != noErr && b_writeable)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1045 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1046 b_mix = 1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1047 err = AudioDeviceSetProperty(ao->i_selected_dev, 0, 0, FALSE,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1048 kAudioDevicePropertySupportsMixing, i_param_size, &b_mix);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1049 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1050 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1051 ao_msg(MSGT_AO, MSGL_WARN, "failed to set mixmode: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1052 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1053 if (ao->i_hog_pid == getpid())
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1054 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1055 ao->i_hog_pid = -1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1056 i_param_size = sizeof(ao->i_hog_pid);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1057 err = AudioDeviceSetProperty(ao->i_selected_dev, 0, 0, FALSE,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1058 kAudioDevicePropertyHogMode, i_param_size, &ao->i_hog_pid);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1059 if (err != noErr) ao_msg(MSGT_AO, MSGL_WARN, "Could not release hogmode: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1060 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1061 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1062
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1063 av_fifo_free(ao->buffer);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1064 free(ao);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1065 ao = NULL;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1066 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1067
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1068
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1069 /* stop playing, keep buffers (for pause) */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1070 static void audio_pause(void)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1071 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1072 OSErr err=noErr;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1073
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1074 /* Stop callback. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1075 if (!ao->b_digital)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1076 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1077 err=AudioOutputUnitStop(ao->theOutputUnit);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1078 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1079 ao_msg(MSGT_AO,MSGL_WARN, "AudioOutputUnitStop returned [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1080 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1081 else
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1082 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1083 err = AudioDeviceStop(ao->i_selected_dev, (AudioDeviceIOProc)RenderCallbackSPDIF);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1084 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1085 ao_msg(MSGT_AO, MSGL_WARN, "AudioDeviceStop failed: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1086 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1087 ao->paused = 1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1088 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1089
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1090
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1091 /* resume playing, after audio_pause() */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1092 static void audio_resume(void)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1093 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1094 OSErr err=noErr;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1095
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1096 if (!ao->paused)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1097 return;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1098
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1099 /* Start callback. */
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1100 if (!ao->b_digital)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1101 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1102 err = AudioOutputUnitStart(ao->theOutputUnit);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1103 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1104 ao_msg(MSGT_AO,MSGL_WARN, "AudioOutputUnitStart returned [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1105 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1106 else
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1107 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1108 err = AudioDeviceStart(ao->i_selected_dev, (AudioDeviceIOProc)RenderCallbackSPDIF);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1109 if (err != noErr)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1110 ao_msg(MSGT_AO, MSGL_WARN, "AudioDeviceStart failed: [%4.4s]\n", (char *)&err);
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1111 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1112 ao->paused = 0;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1113 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1114
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1115 /*****************************************************************************
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1116 * StreamListener
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1117 *****************************************************************************/
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1118 static OSStatus StreamListener( AudioStreamID inStream,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1119 UInt32 inChannel,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1120 AudioDevicePropertyID inPropertyID,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1121 void * inClientData )
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1122 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1123 switch (inPropertyID)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1124 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1125 case kAudioStreamPropertyPhysicalFormat:
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1126 ao_msg(MSGT_AO, MSGL_V, "got notify kAudioStreamPropertyPhysicalFormat changed.\n");
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1127 if (inClientData)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1128 *(volatile int *)inClientData = 1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1129 default:
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1130 break;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1131 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1132 return noErr;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1133 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1134
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1135 static OSStatus DeviceListener( AudioDeviceID inDevice,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1136 UInt32 inChannel,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1137 Boolean isInput,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1138 AudioDevicePropertyID inPropertyID,
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1139 void* inClientData )
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1140 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1141 switch (inPropertyID)
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1142 {
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1143 case kAudioDevicePropertyDeviceHasChanged:
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1144 ao_msg(MSGT_AO, MSGL_WARN, "got notify kAudioDevicePropertyDeviceHasChanged.\n");
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1145 ao->b_stream_format_changed = 1;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1146 default:
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1147 break;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1148 }
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1149 return noErr;
631aac106b7a Rename macosx audio output driver to coreaudio.
diego
parents:
diff changeset
1150 }