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