annotate libao2/ao_coreaudio.c @ 36060:edd8b2707e03

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