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