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