annotate libao2/ao_macosx.c @ 28889:3ec026797553

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