Mercurial > mplayer.hg
annotate libao2/ao_macosx.c @ 25385:52f6c42c43bb
Fix indentation
author | reimar |
---|---|
date | Sat, 15 Dec 2007 17:07:40 +0000 |
parents | 2502d1944968 |
children | 57dc7e8e7e82 |
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; | |
299 AudioDeviceID devid_def = 0; | |
300 int b_alive; | |
14317 | 301 |
24734 | 302 ao_msg(MSGT_AO,MSGL_V, "init([%dHz][%dch][%s][%d])\n", rate, channels, af_fmt2str_short(format), flags); |
303 | |
25290
2502d1944968
Remove useless variable aoIsCreated since we took good care of init failure.
ulion
parents:
25265
diff
changeset
|
304 ao = calloc(1, sizeof(ao_macosx_t)); |
24734 | 305 |
306 ao->i_selected_dev = 0; | |
307 ao->b_supports_digital = 0; | |
308 ao->b_digital = 0; | |
24990 | 309 ao->b_muted = 0; |
24734 | 310 ao->b_stream_format_changed = 0; |
311 ao->i_hog_pid = -1; | |
312 ao->i_stream_id = 0; | |
313 ao->i_stream_index = -1; | |
314 ao->b_revert = 0; | |
315 ao->b_changed_mixing = 0; | |
316 | |
317 /* Probe whether device support S/PDIF stream output if input is AC3 stream. */ | |
318 if ((format & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_AC3) | |
319 { | |
320 /* Find the ID of the default Device. */ | |
321 i_param_size = sizeof(AudioDeviceID); | |
322 err = AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, | |
323 &i_param_size, &devid_def); | |
324 if (err != noErr) | |
325 { | |
326 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
|
327 goto err_out; |
24734 | 328 } |
329 | |
330 /* Retrieve the length of the device name. */ | |
331 i_param_size = 0; | |
332 err = AudioDeviceGetPropertyInfo(devid_def, 0, 0, | |
333 kAudioDevicePropertyDeviceName, | |
334 &i_param_size, NULL); | |
335 if (err != noErr) | |
336 { | |
337 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
|
338 goto err_out; |
24734 | 339 } |
340 | |
341 /* Retrieve the name of the device. */ | |
342 psz_name = (char *)malloc(i_param_size); | |
343 err = AudioDeviceGetProperty(devid_def, 0, 0, | |
344 kAudioDevicePropertyDeviceName, | |
345 &i_param_size, psz_name); | |
346 if (err != noErr) | |
347 { | |
348 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
|
349 free( psz_name); |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
350 goto err_out; |
24734 | 351 } |
352 | |
353 ao_msg(MSGT_AO,MSGL_V, "got default audio output device ID: %#lx Name: %s\n", devid_def, psz_name ); | |
354 | |
355 if (AudioDeviceSupportsDigital(devid_def)) | |
356 { | |
357 ao->b_supports_digital = 1; | |
358 ao->i_selected_dev = devid_def; | |
359 } | |
360 ao_msg(MSGT_AO,MSGL_V, "probe default audio output device whether support digital s/pdif output:%d\n", ao->b_supports_digital ); | |
361 | |
362 free( psz_name); | |
363 } | |
14290 | 364 |
15646
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
365 // 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
|
366 inDesc.mSampleRate=rate; |
24734 | 367 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
|
368 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
|
369 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
|
370 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
|
371 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
|
372 break; |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
373 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
|
374 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
|
375 break; |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
376 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
|
377 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
|
378 break; |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
379 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
|
380 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
|
381 break; |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
382 default: |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
383 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
|
384 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
|
385 } |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
386 |
15646
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
387 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
|
388 // float |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
389 inDesc.mFormatFlags = kAudioFormatFlagIsFloat|kAudioFormatFlagIsPacked; |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
390 } |
15646
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
391 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
|
392 // 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
|
393 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
|
394 } |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
395 else { |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
396 // 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
|
397 inDesc.mFormatFlags = kAudioFormatFlagIsPacked; |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
398 } |
24734 | 399 if ((format & AF_FORMAT_SPECIAL_MASK) == AF_FORMAT_AC3) { |
400 // Currently ac3 input (comes from hwac3) is always in native byte-order. | |
401 #ifdef WORDS_BIGENDIAN | |
402 inDesc.mFormatFlags |= kAudioFormatFlagIsBigEndian; | |
403 #endif | |
404 } | |
405 else if ((format & AF_FORMAT_END_MASK) == AF_FORMAT_BE) | |
406 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
|
407 |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
408 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
|
409 ao->packetSize = inDesc.mBytesPerPacket = inDesc.mBytesPerFrame = inDesc.mFramesPerPacket*channels*(inDesc.mBitsPerChannel/8); |
24734 | 410 print_format(MSGL_V, "source:",&inDesc); |
411 | |
412 if (ao->b_supports_digital) | |
413 { | |
414 b_alive = 1; | |
415 i_param_size = sizeof(b_alive); | |
416 err = AudioDeviceGetProperty(ao->i_selected_dev, 0, FALSE, | |
417 kAudioDevicePropertyDeviceIsAlive, | |
418 &i_param_size, &b_alive); | |
419 if (err != noErr) | |
420 ao_msg(MSGT_AO, MSGL_WARN, "could not check whether device is alive: [%4.4s]\n", (char *)&err); | |
421 if (!b_alive) | |
422 ao_msg(MSGT_AO, MSGL_WARN, "device is not alive\n" ); | |
423 /* S/PDIF output need device in HogMode. */ | |
424 i_param_size = sizeof(ao->i_hog_pid); | |
425 err = AudioDeviceGetProperty(ao->i_selected_dev, 0, FALSE, | |
426 kAudioDevicePropertyHogMode, | |
427 &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
|
428 |
24734 | 429 if (err != noErr) |
430 { | |
431 /* This is not a fatal error. Some drivers simply don't support this property. */ | |
432 ao_msg(MSGT_AO, MSGL_WARN, "could not check whether device is hogged: [%4.4s]\n", | |
433 (char *)&err); | |
434 ao->i_hog_pid = -1; | |
435 } | |
436 | |
437 if (ao->i_hog_pid != -1 && ao->i_hog_pid != getpid()) | |
438 { | |
439 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
|
440 goto err_out; |
24734 | 441 } |
442 ao->stream_format = inDesc; | |
443 return OpenSPDIF(); | |
444 } | |
445 | |
446 /* 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
|
447 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
|
448 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
|
449 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
|
450 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
|
451 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
|
452 |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
453 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
|
454 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
|
455 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
|
456 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
|
457 } |
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 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
|
460 if (err) { |
24734 | 461 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
|
462 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
|
463 } |
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 // 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
|
466 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
|
467 if (err) { |
24734 | 468 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
|
469 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
|
470 } |
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 size = sizeof(AudioStreamBasicDescription); |
15722
b53c4b26dc96
removes the use of AudioConverters. patch by Alexander Strange <alexander.strange@ithinksw.com>
nplourde
parents:
15646
diff
changeset
|
473 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
|
474 |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
475 if (err) { |
24734 | 476 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
|
477 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
|
478 } |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
479 |
16014 | 480 size = sizeof(UInt32); |
481 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
|
482 |
16014 | 483 if (err) |
484 { | |
24734 | 485 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
|
486 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
|
487 } |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
488 |
16014 | 489 ao->chunk_size = maxFrames;//*inDesc.mBytesPerFrame; |
490 | |
19427
ada359817b61
fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
18915
diff
changeset
|
491 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
|
492 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
|
493 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
|
494 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
|
495 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
|
496 |
ada359817b61
fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
18915
diff
changeset
|
497 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
|
498 ao->buffer_len = (ao->num_chunks + 1) * ao->chunk_size; |
25290
2502d1944968
Remove useless variable aoIsCreated since we took good care of init failure.
ulion
parents:
25265
diff
changeset
|
499 ao->buffer = 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
|
500 |
19427
ada359817b61
fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
18915
diff
changeset
|
501 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
|
502 |
15646
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
503 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
|
504 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
|
505 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
|
506 if (err) { |
24734 | 507 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
|
508 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
|
509 } |
f46eae5e271b
Mac OS X Audio with AudioUnits and AudioToolbox format converters, Patch by Chris Roccati<roccati@pobox.com
nplourde
parents:
15486
diff
changeset
|
510 |
19427
ada359817b61
fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
18915
diff
changeset
|
511 reset(); |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
512 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
513 return CONTROL_OK; |
25265
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
514 |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
515 err_out2: |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
516 AudioUnitUninitialize(ao->theOutputUnit); |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
517 err_out1: |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
518 CloseComponent(ao->theOutputUnit); |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
519 err_out: |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
520 free(ao->buffer); |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
521 free(ao); |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
522 ao = NULL; |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
523 return CONTROL_FALSE; |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
524 } |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
525 |
24734 | 526 /***************************************************************************** |
527 * Setup a encoded digital stream (SPDIF) | |
528 *****************************************************************************/ | |
529 static int OpenSPDIF() | |
530 { | |
531 OSStatus err = noErr; | |
532 UInt32 i_param_size, b_mix = 0; | |
533 Boolean b_writeable = 0; | |
534 AudioStreamID *p_streams = NULL; | |
535 int i, i_streams = 0; | |
536 | |
537 /* Start doing the SPDIF setup process. */ | |
538 ao->b_digital = 1; | |
539 | |
540 /* Hog the device. */ | |
541 i_param_size = sizeof(ao->i_hog_pid); | |
542 ao->i_hog_pid = getpid() ; | |
543 | |
544 err = AudioDeviceSetProperty(ao->i_selected_dev, 0, 0, FALSE, | |
545 kAudioDevicePropertyHogMode, i_param_size, &ao->i_hog_pid); | |
546 | |
547 if (err != noErr) | |
548 { | |
549 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
|
550 ao->i_hog_pid = -1; |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
551 goto err_out; |
24734 | 552 } |
553 | |
554 /* Set mixable to false if we are allowed to. */ | |
555 err = AudioDeviceGetPropertyInfo(ao->i_selected_dev, 0, FALSE, | |
556 kAudioDevicePropertySupportsMixing, | |
557 &i_param_size, &b_writeable); | |
558 err = AudioDeviceGetProperty(ao->i_selected_dev, 0, FALSE, | |
559 kAudioDevicePropertySupportsMixing, | |
560 &i_param_size, &b_mix); | |
561 if (err != noErr && b_writeable) | |
562 { | |
563 b_mix = 0; | |
564 err = AudioDeviceSetProperty(ao->i_selected_dev, 0, 0, FALSE, | |
565 kAudioDevicePropertySupportsMixing, | |
566 i_param_size, &b_mix); | |
567 ao->b_changed_mixing = 1; | |
568 } | |
569 if (err != noErr) | |
570 { | |
571 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
|
572 goto err_out; |
24734 | 573 } |
574 | |
575 /* Get a list of all the streams on this device. */ | |
576 err = AudioDeviceGetPropertyInfo(ao->i_selected_dev, 0, FALSE, | |
577 kAudioDevicePropertyStreams, | |
578 &i_param_size, NULL); | |
579 if (err != noErr) | |
580 { | |
581 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
|
582 goto err_out; |
24734 | 583 } |
584 | |
585 i_streams = i_param_size / sizeof(AudioStreamID); | |
586 p_streams = (AudioStreamID *)malloc(i_param_size); | |
587 if (p_streams == NULL) | |
588 { | |
589 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
|
590 goto err_out; |
24734 | 591 } |
592 | |
593 err = AudioDeviceGetProperty(ao->i_selected_dev, 0, FALSE, | |
594 kAudioDevicePropertyStreams, | |
595 &i_param_size, p_streams); | |
596 if (err != noErr) | |
597 { | |
598 ao_msg(MSGT_AO, MSGL_WARN, "could not get number of streams: [%4.4s]\n", (char *)&err); | |
599 if (p_streams) free(p_streams); | |
25265
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
600 goto err_out; |
24734 | 601 } |
602 | |
603 ao_msg(MSGT_AO, MSGL_V, "current device stream number: %d\n", i_streams); | |
604 | |
605 for (i = 0; i < i_streams && ao->i_stream_index < 0; ++i) | |
606 { | |
607 /* Find a stream with a cac3 stream. */ | |
608 AudioStreamBasicDescription *p_format_list = NULL; | |
609 int i_formats = 0, j = 0, b_digital = 0; | |
610 | |
611 /* Retrieve all the stream formats supported by each output stream. */ | |
612 err = AudioStreamGetPropertyInfo(p_streams[i], 0, | |
613 kAudioStreamPropertyPhysicalFormats, | |
614 &i_param_size, NULL); | |
615 if (err != noErr) | |
616 { | |
617 ao_msg(MSGT_AO, MSGL_WARN, "could not get number of streamformats: [%4.4s]\n", (char *)&err); | |
618 continue; | |
619 } | |
620 | |
621 i_formats = i_param_size / sizeof(AudioStreamBasicDescription); | |
622 p_format_list = (AudioStreamBasicDescription *)malloc(i_param_size); | |
623 if (p_format_list == NULL) | |
624 { | |
625 ao_msg(MSGT_AO, MSGL_WARN, "could not malloc the memory\n" ); | |
626 continue; | |
627 } | |
628 | |
629 err = AudioStreamGetProperty(p_streams[i], 0, | |
630 kAudioStreamPropertyPhysicalFormats, | |
631 &i_param_size, p_format_list); | |
632 if (err != noErr) | |
633 { | |
634 ao_msg(MSGT_AO, MSGL_WARN, "could not get the list of streamformats: [%4.4s]\n", (char *)&err); | |
635 if (p_format_list) free(p_format_list); | |
636 continue; | |
637 } | |
638 | |
639 /* Check if one of the supported formats is a digital format. */ | |
640 for (j = 0; j < i_formats; ++j) | |
641 { | |
642 if (p_format_list[j].mFormatID == 'IAC3' || | |
643 p_format_list[j].mFormatID == kAudioFormat60958AC3) | |
644 { | |
645 b_digital = 1; | |
646 break; | |
647 } | |
648 } | |
649 | |
650 if (b_digital) | |
651 { | |
652 /* If this stream supports a digital (cac3) format, then set it. */ | |
653 int i_requested_rate_format = -1; | |
654 int i_current_rate_format = -1; | |
655 int i_backup_rate_format = -1; | |
656 | |
657 ao->i_stream_id = p_streams[i]; | |
658 ao->i_stream_index = i; | |
659 | |
660 if (ao->b_revert == 0) | |
661 { | |
662 /* Retrieve the original format of this stream first if not done so already. */ | |
663 i_param_size = sizeof(ao->sfmt_revert); | |
664 err = AudioStreamGetProperty(ao->i_stream_id, 0, | |
665 kAudioStreamPropertyPhysicalFormat, | |
666 &i_param_size, | |
667 &ao->sfmt_revert); | |
668 if (err != noErr) | |
669 { | |
670 ao_msg(MSGT_AO, MSGL_WARN, "could not retrieve the original streamformat: [%4.4s]\n", (char *)&err); | |
671 if (p_format_list) free(p_format_list); | |
672 continue; | |
673 } | |
674 ao->b_revert = 1; | |
675 } | |
676 | |
677 for (j = 0; j < i_formats; ++j) | |
678 if (p_format_list[j].mFormatID == 'IAC3' || | |
679 p_format_list[j].mFormatID == kAudioFormat60958AC3) | |
680 { | |
681 if (p_format_list[j].mSampleRate == ao->stream_format.mSampleRate) | |
682 { | |
683 i_requested_rate_format = j; | |
684 break; | |
685 } | |
686 if (p_format_list[j].mSampleRate == ao->sfmt_revert.mSampleRate) | |
687 i_current_rate_format = j; | |
688 else if (i_backup_rate_format < 0 || p_format_list[j].mSampleRate > p_format_list[i_backup_rate_format].mSampleRate) | |
689 i_backup_rate_format = j; | |
690 } | |
691 | |
692 if (i_requested_rate_format >= 0) /* We prefer to output at the samplerate of the original audio. */ | |
693 ao->stream_format = p_format_list[i_requested_rate_format]; | |
694 else if (i_current_rate_format >= 0) /* If not possible, we will try to use the current samplerate of the device. */ | |
695 ao->stream_format = p_format_list[i_current_rate_format]; | |
696 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). */ | |
697 } | |
698 if (p_format_list) free(p_format_list); | |
699 } | |
700 if (p_streams) free(p_streams); | |
701 | |
702 if (ao->i_stream_index < 0) | |
703 { | |
704 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
|
705 goto err_out; |
24734 | 706 } |
707 | |
708 print_format(MSGL_V, "original stream format:", &ao->sfmt_revert); | |
709 | |
710 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
|
711 goto err_out; |
24734 | 712 |
713 err = AudioDeviceAddPropertyListener(ao->i_selected_dev, | |
714 kAudioPropertyWildcardChannel, | |
715 0, | |
716 kAudioDevicePropertyDeviceHasChanged, | |
717 DeviceListener, | |
718 NULL); | |
719 if (err != noErr) | |
720 ao_msg(MSGT_AO, MSGL_WARN, "AudioDeviceAddPropertyListener for kAudioDevicePropertyDeviceHasChanged failed: [%4.4s]\n", (char *)&err); | |
721 | |
722 | |
723 /* FIXME: If output stream is not native byte-order, we need change endian somewhere. */ | |
724 /* Although there's no such case reported. */ | |
725 #ifdef WORDS_BIGENDIAN | |
726 if (!(ao->stream_format.mFormatFlags & kAudioFormatFlagIsBigEndian)) | |
727 #else | |
728 if (ao->stream_format.mFormatFlags & kAudioFormatFlagIsBigEndian) | |
729 #endif | |
24741
5ce7bc88eb0c
bugfix for ao_macosx last dts passthrough patch, patch by Ulion, ulion2002 gmail com
nplourde
parents:
24734
diff
changeset
|
730 ao_msg(MSGT_AO, MSGL_WARN, "output stream has a no-native byte-order, digital output may failed.\n"); |
24734 | 731 |
732 /* For ac3/dts, just use packet size 6144 bytes as chunk size. */ | |
733 ao->chunk_size = ao->stream_format.mBytesPerPacket; | |
734 | |
735 ao_data.samplerate = ao->stream_format.mSampleRate; | |
736 ao_data.channels = ao->stream_format.mChannelsPerFrame; | |
737 ao_data.bps = ao_data.samplerate * (ao->stream_format.mBytesPerPacket/ao->stream_format.mFramesPerPacket); | |
738 ao_data.outburst = ao->chunk_size; | |
739 ao_data.buffersize = ao_data.bps; | |
740 | |
741 ao->num_chunks = (ao_data.bps+ao->chunk_size-1)/ao->chunk_size; | |
742 ao->buffer_len = (ao->num_chunks + 1) * ao->chunk_size; | |
25290
2502d1944968
Remove useless variable aoIsCreated since we took good care of init failure.
ulion
parents:
25265
diff
changeset
|
743 ao->buffer = calloc(ao->num_chunks + 1, ao->chunk_size); |
24734 | 744 |
745 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); | |
746 | |
747 | |
748 /* Add IOProc callback. */ | |
749 err = AudioDeviceAddIOProc(ao->i_selected_dev, | |
750 (AudioDeviceIOProc)RenderCallbackSPDIF, | |
751 (void *)ao); | |
752 if (err != noErr) | |
753 { | |
754 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
|
755 goto err_out1; |
24734 | 756 } |
757 | |
758 reset(); | |
759 | |
760 return CONTROL_TRUE; | |
25265
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
761 |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
762 err_out1: |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
763 if (ao->b_revert) |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
764 AudioStreamChangeFormat(ao->i_stream_id, ao->sfmt_revert); |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
765 err_out: |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
766 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
|
767 { |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
768 int b_mix = 1; |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
769 err = AudioDeviceSetProperty(ao->i_selected_dev, 0, 0, FALSE, |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
770 kAudioDevicePropertySupportsMixing, |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
771 i_param_size, &b_mix); |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
772 if (err != noErr) |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
773 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
|
774 (char *)&err); |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
775 } |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
776 if (ao->i_hog_pid == getpid()) |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
777 { |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
778 ao->i_hog_pid = -1; |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
779 i_param_size = sizeof(ao->i_hog_pid); |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
780 err = AudioDeviceSetProperty(ao->i_selected_dev, 0, 0, FALSE, |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
781 kAudioDevicePropertyHogMode, |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
782 i_param_size, &ao->i_hog_pid); |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
783 if (err != noErr) |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
784 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
|
785 (char *)&err); |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
786 } |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
787 free(ao->buffer); |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
788 free(ao); |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
789 ao = NULL; |
7055944e3ce9
Add cleanup codes for init() failure to prevent leak.
ulion
parents:
25007
diff
changeset
|
790 return CONTROL_FALSE; |
24734 | 791 } |
792 | |
793 /***************************************************************************** | |
794 * AudioDeviceSupportsDigital: Check i_dev_id for digital stream support. | |
795 *****************************************************************************/ | |
796 static int AudioDeviceSupportsDigital( AudioDeviceID i_dev_id ) | |
797 { | |
798 OSStatus err = noErr; | |
799 UInt32 i_param_size = 0; | |
800 AudioStreamID *p_streams = NULL; | |
801 int i = 0, i_streams = 0; | |
802 int b_return = CONTROL_FALSE; | |
803 | |
804 /* Retrieve all the output streams. */ | |
805 err = AudioDeviceGetPropertyInfo(i_dev_id, 0, FALSE, | |
806 kAudioDevicePropertyStreams, | |
807 &i_param_size, NULL); | |
808 if (err != noErr) | |
809 { | |
810 ao_msg(MSGT_AO,MSGL_V, "could not get number of streams: [%4.4s]\n", (char *)&err); | |
811 return CONTROL_FALSE; | |
812 } | |
813 | |
814 i_streams = i_param_size / sizeof(AudioStreamID); | |
815 p_streams = (AudioStreamID *)malloc(i_param_size); | |
816 if (p_streams == NULL) | |
817 { | |
818 ao_msg(MSGT_AO,MSGL_V, "out of memory\n"); | |
819 return CONTROL_FALSE; | |
820 } | |
821 | |
822 err = AudioDeviceGetProperty(i_dev_id, 0, FALSE, | |
823 kAudioDevicePropertyStreams, | |
824 &i_param_size, p_streams); | |
825 | |
826 if (err != noErr) | |
827 { | |
828 ao_msg(MSGT_AO,MSGL_V, "could not get number of streams: [%4.4s]\n", (char *)&err); | |
829 free(p_streams); | |
830 return CONTROL_FALSE; | |
831 } | |
832 | |
833 for (i = 0; i < i_streams; ++i) | |
834 { | |
835 if (AudioStreamSupportsDigital(p_streams[i])) | |
836 b_return = CONTROL_OK; | |
837 } | |
838 | |
839 free(p_streams); | |
840 return b_return; | |
841 } | |
842 | |
843 /***************************************************************************** | |
844 * AudioStreamSupportsDigital: Check i_stream_id for digital stream support. | |
845 *****************************************************************************/ | |
846 static int AudioStreamSupportsDigital( AudioStreamID i_stream_id ) | |
847 { | |
848 OSStatus err = noErr; | |
849 UInt32 i_param_size; | |
850 AudioStreamBasicDescription *p_format_list = NULL; | |
851 int i, i_formats, b_return = CONTROL_FALSE; | |
852 | |
853 /* Retrieve all the stream formats supported by each output stream. */ | |
854 err = AudioStreamGetPropertyInfo(i_stream_id, 0, | |
855 kAudioStreamPropertyPhysicalFormats, | |
856 &i_param_size, NULL); | |
857 if (err != noErr) | |
858 { | |
859 ao_msg(MSGT_AO,MSGL_V, "could not get number of streamformats: [%4.4s]\n", (char *)&err); | |
860 return CONTROL_FALSE; | |
861 } | |
862 | |
863 i_formats = i_param_size / sizeof(AudioStreamBasicDescription); | |
864 p_format_list = (AudioStreamBasicDescription *)malloc(i_param_size); | |
865 if (p_format_list == NULL) | |
866 { | |
867 ao_msg(MSGT_AO,MSGL_V, "could not malloc the memory\n" ); | |
868 return CONTROL_FALSE; | |
869 } | |
870 | |
871 err = AudioStreamGetProperty(i_stream_id, 0, | |
872 kAudioStreamPropertyPhysicalFormats, | |
873 &i_param_size, p_format_list); | |
874 if (err != noErr) | |
875 { | |
876 ao_msg(MSGT_AO,MSGL_V, "could not get the list of streamformats: [%4.4s]\n", (char *)&err); | |
877 free(p_format_list); | |
878 return CONTROL_FALSE; | |
879 } | |
880 | |
881 for (i = 0; i < i_formats; ++i) | |
882 { | |
883 print_format(MSGL_V, "supported format:", &p_format_list[i]); | |
884 | |
885 if (p_format_list[i].mFormatID == 'IAC3' || | |
886 p_format_list[i].mFormatID == kAudioFormat60958AC3) | |
887 b_return = CONTROL_OK; | |
888 } | |
889 | |
890 free(p_format_list); | |
891 return b_return; | |
892 } | |
893 | |
894 /***************************************************************************** | |
895 * AudioStreamChangeFormat: Change i_stream_id to change_format | |
896 *****************************************************************************/ | |
897 static int AudioStreamChangeFormat( AudioStreamID i_stream_id, AudioStreamBasicDescription change_format ) | |
898 { | |
899 OSStatus err = noErr; | |
900 UInt32 i_param_size = 0; | |
901 int i; | |
902 | |
24980
19e208a0296d
Fix dead lock when changing and restoring stream format for digital output,
ulion
parents:
24942
diff
changeset
|
903 static volatile int stream_format_changed; |
19e208a0296d
Fix dead lock when changing and restoring stream format for digital output,
ulion
parents:
24942
diff
changeset
|
904 stream_format_changed = 0; |
24734 | 905 |
906 print_format(MSGL_V, "setting stream format:", &change_format); | |
907 | |
908 /* Install the callback. */ | |
909 err = AudioStreamAddPropertyListener(i_stream_id, 0, | |
910 kAudioStreamPropertyPhysicalFormat, | |
24980
19e208a0296d
Fix dead lock when changing and restoring stream format for digital output,
ulion
parents:
24942
diff
changeset
|
911 StreamListener, |
19e208a0296d
Fix dead lock when changing and restoring stream format for digital output,
ulion
parents:
24942
diff
changeset
|
912 (void *)&stream_format_changed); |
24734 | 913 if (err != noErr) |
914 { | |
915 ao_msg(MSGT_AO, MSGL_WARN, "AudioStreamAddPropertyListener failed: [%4.4s]\n", (char *)&err); | |
916 return CONTROL_FALSE; | |
917 } | |
918 | |
919 /* Change the format. */ | |
920 err = AudioStreamSetProperty(i_stream_id, 0, 0, | |
921 kAudioStreamPropertyPhysicalFormat, | |
922 sizeof(AudioStreamBasicDescription), | |
923 &change_format); | |
924 if (err != noErr) | |
925 { | |
926 ao_msg(MSGT_AO, MSGL_WARN, "could not set the stream format: [%4.4s]\n", (char *)&err); | |
927 return CONTROL_FALSE; | |
928 } | |
929 | |
24980
19e208a0296d
Fix dead lock when changing and restoring stream format for digital output,
ulion
parents:
24942
diff
changeset
|
930 /* The AudioStreamSetProperty is not only asynchronious, |
24734 | 931 * it is also not Atomic, in its behaviour. |
932 * Therefore we check 5 times before we really give up. | |
933 * FIXME: failing isn't actually implemented yet. */ | |
934 for (i = 0; i < 5; ++i) | |
935 { | |
936 AudioStreamBasicDescription actual_format; | |
24980
19e208a0296d
Fix dead lock when changing and restoring stream format for digital output,
ulion
parents:
24942
diff
changeset
|
937 int j; |
19e208a0296d
Fix dead lock when changing and restoring stream format for digital output,
ulion
parents:
24942
diff
changeset
|
938 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
|
939 usec_sleep(10000); |
19e208a0296d
Fix dead lock when changing and restoring stream format for digital output,
ulion
parents:
24942
diff
changeset
|
940 if (stream_format_changed) |
19e208a0296d
Fix dead lock when changing and restoring stream format for digital output,
ulion
parents:
24942
diff
changeset
|
941 stream_format_changed = 0; |
19e208a0296d
Fix dead lock when changing and restoring stream format for digital output,
ulion
parents:
24942
diff
changeset
|
942 else |
24734 | 943 ao_msg(MSGT_AO, MSGL_V, "reached timeout\n" ); |
944 | |
945 i_param_size = sizeof(AudioStreamBasicDescription); | |
946 err = AudioStreamGetProperty(i_stream_id, 0, | |
947 kAudioStreamPropertyPhysicalFormat, | |
948 &i_param_size, | |
949 &actual_format); | |
950 | |
951 print_format(MSGL_V, "actual format in use:", &actual_format); | |
952 if (actual_format.mSampleRate == change_format.mSampleRate && | |
953 actual_format.mFormatID == change_format.mFormatID && | |
954 actual_format.mFramesPerPacket == change_format.mFramesPerPacket) | |
955 { | |
956 /* The right format is now active. */ | |
957 break; | |
958 } | |
959 /* We need to check again. */ | |
960 } | |
961 | |
962 /* Removing the property listener. */ | |
963 err = AudioStreamRemovePropertyListener(i_stream_id, 0, | |
964 kAudioStreamPropertyPhysicalFormat, | |
965 StreamListener); | |
966 if (err != noErr) | |
967 { | |
968 ao_msg(MSGT_AO, MSGL_WARN, "AudioStreamRemovePropertyListener failed: [%4.4s]\n", (char *)&err); | |
969 return CONTROL_FALSE; | |
970 } | |
971 | |
972 return CONTROL_TRUE; | |
973 } | |
974 | |
975 /***************************************************************************** | |
976 * RenderCallbackSPDIF: callback for SPDIF audio output | |
977 *****************************************************************************/ | |
978 static OSStatus RenderCallbackSPDIF( AudioDeviceID inDevice, | |
979 const AudioTimeStamp * inNow, | |
980 const void * inInputData, | |
981 const AudioTimeStamp * inInputTime, | |
982 AudioBufferList * outOutputData, | |
983 const AudioTimeStamp * inOutputTime, | |
984 void * threadGlobals ) | |
985 { | |
986 int amt = buf_used(); | |
987 int req = outOutputData->mBuffers[ao->i_stream_index].mDataByteSize; | |
988 | |
989 if (amt > req) | |
990 amt = req; | |
991 if (amt) | |
24990 | 992 read_buffer(ao->b_muted ? NULL : (unsigned char *)outOutputData->mBuffers[ao->i_stream_index].mData, amt); |
24734 | 993 |
994 return noErr; | |
995 } | |
996 | |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
997 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
998 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
|
999 { |
24734 | 1000 int wrote, b_digital; |
1001 | |
1002 // Check whether we need to reset the digital output stream. | |
1003 if (ao->b_digital && ao->b_stream_format_changed) | |
1004 { | |
1005 ao->b_stream_format_changed = 0; | |
1006 b_digital = AudioStreamSupportsDigital(ao->i_stream_id); | |
1007 if (b_digital) | |
1008 { | |
1009 /* Current stream support digital format output, let's set it. */ | |
1010 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
|
1011 |
24734 | 1012 if (!AudioStreamChangeFormat(ao->i_stream_id, ao->stream_format)) |
1013 { | |
1014 ao_msg(MSGT_AO, MSGL_WARN, "restore digital output failed.\n"); | |
1015 } | |
1016 else | |
1017 { | |
1018 ao_msg(MSGT_AO, MSGL_WARN, "restore digital output succeed.\n"); | |
1019 reset(); | |
1020 } | |
1021 } | |
1022 else | |
1023 ao_msg(MSGT_AO, MSGL_V, "detected current stream do not support digital.\n"); | |
1024 } | |
1025 | |
1026 wrote=write_buffer(output_samples, num_bytes); | |
1027 audio_resume(); | |
1028 return wrote; | |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1029 } |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1030 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1031 /* set variables and buffer to initial state */ |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
18885
diff
changeset
|
1032 static void reset(void) |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1033 { |
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
|
1034 audio_pause(); |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1035 /* reset ring-buffer state */ |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1036 ao->buf_read_pos=0; |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1037 ao->buf_write_pos=0; |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1038 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1039 return; |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1040 } |
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 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1043 /* return available space */ |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
18885
diff
changeset
|
1044 static int get_space(void) |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1045 { |
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
|
1046 return buf_free(); |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1047 } |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1048 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1049 |
10152 | 1050 /* return delay until audio is played */ |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
18885
diff
changeset
|
1051 static float get_delay(void) |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1052 { |
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
|
1053 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
|
1054 // 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
|
1055 return (float)(buffered)/(float)ao_data.bps; |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1056 } |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1057 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1058 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1059 /* unload plugin and deregister from coreaudio */ |
12145 | 1060 static void uninit(int immed) |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1061 { |
24734 | 1062 OSStatus err = noErr; |
1063 UInt32 i_param_size = 0; | |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1064 |
19427
ada359817b61
fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
18915
diff
changeset
|
1065 if (!immed) { |
ada359817b61
fix buffering issues with short audio samples on macosx. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents:
18915
diff
changeset
|
1066 long long timeleft=(1000000LL*buf_used())/ao_data.bps; |
24734 | 1067 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
|
1068 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
|
1069 } |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1070 |
24734 | 1071 if (!ao->b_digital) { |
1072 AudioOutputUnitStop(ao->theOutputUnit); | |
1073 AudioUnitUninitialize(ao->theOutputUnit); | |
1074 CloseComponent(ao->theOutputUnit); | |
1075 } | |
1076 else { | |
1077 /* Stop device. */ | |
1078 err = AudioDeviceStop(ao->i_selected_dev, | |
1079 (AudioDeviceIOProc)RenderCallbackSPDIF); | |
1080 if (err != noErr) | |
1081 ao_msg(MSGT_AO, MSGL_WARN, "AudioDeviceStop failed: [%4.4s]\n", (char *)&err); | |
1082 | |
1083 /* Remove IOProc callback. */ | |
1084 err = AudioDeviceRemoveIOProc(ao->i_selected_dev, | |
1085 (AudioDeviceIOProc)RenderCallbackSPDIF); | |
1086 if (err != noErr) | |
1087 ao_msg(MSGT_AO, MSGL_WARN, "AudioDeviceRemoveIOProc failed: [%4.4s]\n", (char *)&err); | |
1088 | |
1089 if (ao->b_revert) | |
1090 AudioStreamChangeFormat(ao->i_stream_id, ao->sfmt_revert); | |
1091 | |
1092 if (ao->b_changed_mixing && ao->sfmt_revert.mFormatID != kAudioFormat60958AC3) | |
1093 { | |
1094 int b_mix; | |
1095 Boolean b_writeable; | |
1096 /* Revert mixable to true if we are allowed to. */ | |
1097 err = AudioDeviceGetPropertyInfo(ao->i_selected_dev, 0, FALSE, kAudioDevicePropertySupportsMixing, | |
1098 &i_param_size, &b_writeable); | |
1099 err = AudioDeviceGetProperty(ao->i_selected_dev, 0, FALSE, kAudioDevicePropertySupportsMixing, | |
1100 &i_param_size, &b_mix); | |
1101 if (err != noErr && b_writeable) | |
1102 { | |
1103 b_mix = 1; | |
1104 err = AudioDeviceSetProperty(ao->i_selected_dev, 0, 0, FALSE, | |
1105 kAudioDevicePropertySupportsMixing, i_param_size, &b_mix); | |
1106 } | |
1107 if (err != noErr) | |
1108 ao_msg(MSGT_AO, MSGL_WARN, "failed to set mixmode: [%4.4s]\n", (char *)&err); | |
1109 } | |
1110 if (ao->i_hog_pid == getpid()) | |
1111 { | |
1112 ao->i_hog_pid = -1; | |
1113 i_param_size = sizeof(ao->i_hog_pid); | |
1114 err = AudioDeviceSetProperty(ao->i_selected_dev, 0, 0, FALSE, | |
1115 kAudioDevicePropertyHogMode, i_param_size, &ao->i_hog_pid); | |
1116 if (err != noErr) ao_msg(MSGT_AO, MSGL_WARN, "Could not release hogmode: [%4.4s]\n", (char *)&err); | |
1117 } | |
1118 } | |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1119 |
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
|
1120 free(ao->buffer); |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1121 free(ao); |
15853
6e994905f77b
more general ao_macosx cleanup. Patch by Alexander Strange <astrange@ithinksw.com>
nplourde
parents:
15722
diff
changeset
|
1122 ao = NULL; |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1123 } |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1124 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1125 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1126 /* stop playing, keep buffers (for pause) */ |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
18885
diff
changeset
|
1127 static void audio_pause(void) |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1128 { |
24734 | 1129 OSErr err=noErr; |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1130 |
24734 | 1131 /* Stop callback. */ |
1132 if (!ao->b_digital) | |
1133 { | |
1134 err=AudioOutputUnitStop(ao->theOutputUnit); | |
1135 if (err != noErr) | |
1136 ao_msg(MSGT_AO,MSGL_WARN, "AudioOutputUnitStop returned [%4.4s]\n", (char *)&err); | |
1137 } | |
1138 else | |
1139 { | |
1140 err = AudioDeviceStop(ao->i_selected_dev, (AudioDeviceIOProc)RenderCallbackSPDIF); | |
1141 if (err != noErr) | |
1142 ao_msg(MSGT_AO, MSGL_WARN, "AudioDeviceStop failed: [%4.4s]\n", (char *)&err); | |
1143 } | |
1144 ao->paused = 1; | |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1145 } |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1146 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1147 |
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1148 /* resume playing, after audio_pause() */ |
18915
99e20a22d5d0
modifies function declarations without parameters from ()
reynaldo
parents:
18885
diff
changeset
|
1149 static void audio_resume(void) |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1150 { |
24734 | 1151 OSErr err=noErr; |
1152 | |
1153 if (!ao->paused) | |
1154 return; | |
1155 | |
1156 /* Start callback. */ | |
1157 if (!ao->b_digital) | |
1158 { | |
1159 err = AudioOutputUnitStart(ao->theOutputUnit); | |
1160 if (err != noErr) | |
1161 ao_msg(MSGT_AO,MSGL_WARN, "AudioOutputUnitStart returned [%4.4s]\n", (char *)&err); | |
1162 } | |
1163 else | |
1164 { | |
1165 err = AudioDeviceStart(ao->i_selected_dev, (AudioDeviceIOProc)RenderCallbackSPDIF); | |
1166 if (err != noErr) | |
1167 ao_msg(MSGT_AO, MSGL_WARN, "AudioDeviceStart failed: [%4.4s]\n", (char *)&err); | |
1168 } | |
1169 ao->paused = 0; | |
10147
f2725d6717bd
Native MacOSX audio output by Dan Christiansen <danchr@daimi.au.dk>
alex
parents:
diff
changeset
|
1170 } |
24734 | 1171 |
1172 /***************************************************************************** | |
1173 * StreamListener | |
1174 *****************************************************************************/ | |
1175 static OSStatus StreamListener( AudioStreamID inStream, | |
1176 UInt32 inChannel, | |
1177 AudioDevicePropertyID inPropertyID, | |
1178 void * inClientData ) | |
1179 { | |
1180 switch (inPropertyID) | |
1181 { | |
1182 case kAudioStreamPropertyPhysicalFormat: | |
24980
19e208a0296d
Fix dead lock when changing and restoring stream format for digital output,
ulion
parents:
24942
diff
changeset
|
1183 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
|
1184 if (inClientData) |
19e208a0296d
Fix dead lock when changing and restoring stream format for digital output,
ulion
parents:
24942
diff
changeset
|
1185 *(volatile int *)inClientData = 1; |
24734 | 1186 default: |
1187 break; | |
1188 } | |
1189 return noErr; | |
1190 } | |
1191 | |
1192 static OSStatus DeviceListener( AudioDeviceID inDevice, | |
1193 UInt32 inChannel, | |
1194 Boolean isInput, | |
1195 AudioDevicePropertyID inPropertyID, | |
1196 void* inClientData ) | |
1197 { | |
1198 switch (inPropertyID) | |
1199 { | |
1200 case kAudioDevicePropertyDeviceHasChanged: | |
1201 ao_msg(MSGT_AO, MSGL_WARN, "got notify kAudioDevicePropertyDeviceHasChanged.\n"); | |
1202 ao->b_stream_format_changed = 1; | |
1203 default: | |
1204 break; | |
1205 } | |
1206 return noErr; | |
1207 } |