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