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