2003-05-21 23:15:46 +02:00
|
|
|
/*
|
2009-05-04 16:53:47 +02:00
|
|
|
* CoreAudio audio output driver for Mac OS X
|
2003-05-21 23:15:46 +02:00
|
|
|
*
|
2008-06-06 02:45:35 +02:00
|
|
|
* original copyright (C) Timothy J. Wood - Aug 2000
|
|
|
|
* ported to MPlayer libao2 by Dan Christiansen
|
2003-05-21 23:15:46 +02:00
|
|
|
*
|
2008-06-06 02:45:35 +02:00
|
|
|
* The S/PDIF part of the code is based on the auhal audio output
|
|
|
|
* module from VideoLAN:
|
|
|
|
* Copyright (c) 2006 Derk-Jan Hartman <hartman at videolan dot org>
|
2003-05-21 23:15:46 +02:00
|
|
|
*
|
2008-06-06 02:45:35 +02:00
|
|
|
* This file is part of MPlayer.
|
2007-12-22 18:33:28 +01:00
|
|
|
*
|
2008-06-06 02:45:35 +02:00
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2003-05-21 23:15:46 +02:00
|
|
|
*
|
2008-06-06 02:45:35 +02:00
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2003-05-21 23:15:46 +02:00
|
|
|
*
|
2008-06-06 02:45:35 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* along with MPlayer; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2003-05-21 23:15:46 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The MacOS X CoreAudio framework doesn't mesh as simply as some
|
|
|
|
* simpler frameworks do. This is due to the fact that CoreAudio pulls
|
|
|
|
* audio samples rather than having them pushed at it (which is nice
|
2008-06-06 02:45:35 +02:00
|
|
|
* when you are wanting to do good buffering of audio).
|
2003-05-21 23:15:46 +02:00
|
|
|
*/
|
|
|
|
|
2005-01-12 23:00:02 +01:00
|
|
|
#include "config.h"
|
2012-11-09 01:06:43 +01:00
|
|
|
#include "ao.h"
|
|
|
|
#include "audio/format.h"
|
2013-06-26 08:23:31 +02:00
|
|
|
#include "osdep/timer.h"
|
2012-11-09 01:06:43 +01:00
|
|
|
#include "core/subopt-helper.h"
|
2013-05-23 21:23:32 +02:00
|
|
|
#include "core/mp_ring.h"
|
2013-07-13 09:48:10 +02:00
|
|
|
#include "core/mp_msg.h"
|
|
|
|
#include "audio/out/ao_coreaudio_properties.h"
|
|
|
|
#include "audio/out/ao_coreaudio_utils.h"
|
2013-04-20 10:02:23 +02:00
|
|
|
|
2013-04-19 23:04:11 +02:00
|
|
|
static void audio_pause(struct ao *ao);
|
|
|
|
static void audio_resume(struct ao *ao);
|
|
|
|
static void reset(struct ao *ao);
|
2003-05-22 18:12:54 +02:00
|
|
|
|
2013-05-23 21:23:32 +02:00
|
|
|
static void print_buffer(struct mp_ring *buffer)
|
2013-04-20 10:02:23 +02:00
|
|
|
{
|
|
|
|
void *tctx = talloc_new(NULL);
|
2013-06-18 21:46:32 +02:00
|
|
|
ca_msg(MSGL_V, "%s\n", mp_ring_repr(buffer, tctx));
|
2013-04-20 10:02:23 +02:00
|
|
|
talloc_free(tctx);
|
|
|
|
}
|
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
struct priv_d {
|
2013-06-27 08:29:48 +02:00
|
|
|
// digital render callback
|
|
|
|
AudioDeviceIOProcID render_cb;
|
|
|
|
|
|
|
|
// pid set for hog mode, (-1) means that hog mode on the device was
|
|
|
|
// released. hog mode is exclusive access to a device
|
|
|
|
pid_t hog_pid;
|
|
|
|
|
|
|
|
// stream selected for digital playback by the detection in init
|
|
|
|
AudioStreamID stream;
|
|
|
|
|
|
|
|
// stream index in an AudioBufferList
|
|
|
|
int stream_idx;
|
|
|
|
|
|
|
|
// format we changed the stream to: for the digital case each application
|
|
|
|
// sets the stream format for a device to what it needs
|
|
|
|
AudioStreamBasicDescription stream_asbd;
|
2013-07-15 08:18:50 +02:00
|
|
|
AudioStreamBasicDescription original_asbd;
|
2013-06-27 08:29:48 +02:00
|
|
|
|
|
|
|
bool changed_mixing;
|
|
|
|
int stream_asbd_changed;
|
|
|
|
bool muted;
|
2013-06-23 11:18:54 +02:00
|
|
|
};
|
|
|
|
|
2013-06-27 08:29:48 +02:00
|
|
|
struct priv {
|
|
|
|
AudioDeviceID device; // selected device
|
|
|
|
bool is_digital; // running in digital mode?
|
2013-04-18 21:25:02 +02:00
|
|
|
|
2013-06-27 08:29:48 +02:00
|
|
|
AudioUnit audio_unit; // AudioUnit for lpcm output
|
2013-04-18 21:25:02 +02:00
|
|
|
|
2013-06-26 23:40:35 +02:00
|
|
|
bool paused;
|
2013-04-18 21:25:02 +02:00
|
|
|
|
2013-05-23 21:23:32 +02:00
|
|
|
struct mp_ring *buffer;
|
2013-06-23 11:18:54 +02:00
|
|
|
struct priv_d *digital;
|
2013-04-19 23:04:11 +02:00
|
|
|
};
|
2003-05-21 23:15:46 +02:00
|
|
|
|
2013-06-16 19:25:10 +02:00
|
|
|
static int get_ring_size(struct ao *ao)
|
|
|
|
{
|
|
|
|
return af_fmt_seconds_to_bytes(
|
|
|
|
ao->format, 0.5, ao->channels.num, ao->samplerate);
|
|
|
|
}
|
|
|
|
|
2013-06-17 23:03:19 +02:00
|
|
|
static OSStatus render_cb_lpcm(void *ctx, AudioUnitRenderActionFlags *aflags,
|
|
|
|
const AudioTimeStamp *ts, UInt32 bus,
|
|
|
|
UInt32 frames, AudioBufferList *buffer_list)
|
2003-05-21 23:15:46 +02:00
|
|
|
{
|
2013-06-17 23:03:19 +02:00
|
|
|
struct ao *ao = ctx;
|
|
|
|
struct priv *p = ao->priv;
|
2013-06-27 08:22:52 +02:00
|
|
|
|
2013-06-17 23:03:19 +02:00
|
|
|
AudioBuffer buf = buffer_list->mBuffers[0];
|
2013-06-27 08:22:52 +02:00
|
|
|
int requested = buf.mDataByteSize;
|
2013-04-19 23:04:11 +02:00
|
|
|
|
2013-06-17 23:03:19 +02:00
|
|
|
buf.mDataByteSize = mp_ring_read(p->buffer, buf.mData, requested);
|
2005-06-05 16:47:26 +02:00
|
|
|
|
2013-04-18 21:25:02 +02:00
|
|
|
return noErr;
|
2003-05-21 23:15:46 +02:00
|
|
|
}
|
|
|
|
|
2013-06-20 23:22:56 +02:00
|
|
|
static OSStatus render_cb_digital(
|
|
|
|
AudioDeviceID device, const AudioTimeStamp *ts,
|
|
|
|
const void *in_data, const AudioTimeStamp *in_ts,
|
|
|
|
AudioBufferList *out_data, const AudioTimeStamp *out_ts, void *ctx)
|
|
|
|
{
|
2013-06-23 11:18:54 +02:00
|
|
|
struct ao *ao = ctx;
|
|
|
|
struct priv *p = ao->priv;
|
|
|
|
struct priv_d *d = p->digital;
|
2013-06-27 08:29:48 +02:00
|
|
|
AudioBuffer buf = out_data->mBuffers[d->stream_idx];
|
2013-06-23 11:18:54 +02:00
|
|
|
int requested = buf.mDataByteSize;
|
2013-06-20 23:22:56 +02:00
|
|
|
|
2013-06-27 08:29:48 +02:00
|
|
|
if (d->muted)
|
2013-06-20 23:22:56 +02:00
|
|
|
mp_ring_drain(p->buffer, requested);
|
2013-06-21 13:43:59 +02:00
|
|
|
else
|
|
|
|
mp_ring_read(p->buffer, buf.mData, requested);
|
2013-06-20 23:22:56 +02:00
|
|
|
|
|
|
|
return noErr;
|
|
|
|
}
|
|
|
|
|
2013-04-19 23:04:11 +02:00
|
|
|
static int control(struct ao *ao, enum aocontrol cmd, void *arg)
|
2013-04-18 21:25:02 +02:00
|
|
|
{
|
2013-04-19 23:04:11 +02:00
|
|
|
struct priv *p = ao->priv;
|
2013-04-18 21:25:02 +02:00
|
|
|
ao_control_vol_t *control_vol;
|
|
|
|
OSStatus err;
|
|
|
|
Float32 vol;
|
|
|
|
switch (cmd) {
|
|
|
|
case AOCONTROL_GET_VOLUME:
|
|
|
|
control_vol = (ao_control_vol_t *)arg;
|
2013-06-27 08:29:48 +02:00
|
|
|
if (p->is_digital) {
|
2013-06-23 11:18:54 +02:00
|
|
|
struct priv_d *d = p->digital;
|
2013-04-18 21:25:02 +02:00
|
|
|
// Digital output has no volume adjust.
|
2013-06-27 08:29:48 +02:00
|
|
|
int vol = d->muted ? 0 : 100;
|
2013-04-18 21:25:02 +02:00
|
|
|
*control_vol = (ao_control_vol_t) {
|
|
|
|
.left = vol, .right = vol,
|
|
|
|
};
|
|
|
|
return CONTROL_TRUE;
|
|
|
|
}
|
2013-06-18 23:48:48 +02:00
|
|
|
|
2013-06-27 08:29:48 +02:00
|
|
|
err = AudioUnitGetParameter(p->audio_unit, kHALOutputParam_Volume,
|
2013-04-18 21:25:02 +02:00
|
|
|
kAudioUnitScope_Global, 0, &vol);
|
|
|
|
|
2013-06-18 23:48:48 +02:00
|
|
|
CHECK_CA_ERROR("could not get HAL output volume");
|
2013-07-02 08:07:15 +02:00
|
|
|
control_vol->left = control_vol->right = vol * 100.0;
|
2013-06-18 23:48:48 +02:00
|
|
|
return CONTROL_TRUE;
|
2013-04-18 21:25:02 +02:00
|
|
|
|
|
|
|
case AOCONTROL_SET_VOLUME:
|
|
|
|
control_vol = (ao_control_vol_t *)arg;
|
|
|
|
|
2013-06-27 08:29:48 +02:00
|
|
|
if (p->is_digital) {
|
2013-06-23 11:18:54 +02:00
|
|
|
struct priv_d *d = p->digital;
|
2013-04-18 21:25:02 +02:00
|
|
|
// Digital output can not set volume. Here we have to return true
|
|
|
|
// to make mixer forget it. Else mixer will add a soft filter,
|
|
|
|
// that's not we expected and the filter not support ac3 stream
|
|
|
|
// will cause mplayer die.
|
|
|
|
|
|
|
|
// Although not support set volume, but at least we support mute.
|
|
|
|
// MPlayer set mute by set volume to zero, we handle it.
|
|
|
|
if (control_vol->left == 0 && control_vol->right == 0)
|
2013-06-27 08:29:48 +02:00
|
|
|
d->muted = true;
|
2013-04-18 21:25:02 +02:00
|
|
|
else
|
2013-06-27 08:29:48 +02:00
|
|
|
d->muted = false;
|
2013-04-18 21:25:02 +02:00
|
|
|
return CONTROL_TRUE;
|
|
|
|
}
|
|
|
|
|
2013-07-02 08:07:15 +02:00
|
|
|
vol = (control_vol->left + control_vol->right) / 200.0;
|
2013-06-27 08:29:48 +02:00
|
|
|
err = AudioUnitSetParameter(p->audio_unit, kHALOutputParam_Volume,
|
2013-04-18 21:25:02 +02:00
|
|
|
kAudioUnitScope_Global, 0, vol, 0);
|
2009-05-13 04:58:57 +02:00
|
|
|
|
2013-06-18 23:48:48 +02:00
|
|
|
CHECK_CA_ERROR("could not set HAL output volume");
|
|
|
|
return CONTROL_TRUE;
|
|
|
|
|
|
|
|
} // end switch
|
|
|
|
return CONTROL_UNKNOWN;
|
|
|
|
|
|
|
|
coreaudio_error:
|
|
|
|
return CONTROL_ERROR;
|
2003-05-21 23:15:46 +02:00
|
|
|
}
|
|
|
|
|
2010-07-11 23:08:57 +02:00
|
|
|
static void print_help(void)
|
|
|
|
{
|
2013-07-01 18:47:06 +02:00
|
|
|
char *help = talloc_strdup(NULL,
|
|
|
|
" -ao coreaudio commandline help:\n"
|
2012-10-11 02:04:08 +02:00
|
|
|
"Example: mpv -ao coreaudio:device_id=266\n"
|
2010-07-11 23:08:57 +02:00
|
|
|
" open Core Audio with output device ID 266.\n"
|
|
|
|
"\nOptions:\n"
|
|
|
|
" device_id\n"
|
|
|
|
" ID of output device to use (0 = default device)\n"
|
|
|
|
" help\n"
|
|
|
|
" This help including list of available devices.\n"
|
|
|
|
"\n"
|
|
|
|
"Available output devices:\n");
|
|
|
|
|
2013-06-21 19:46:30 +02:00
|
|
|
AudioDeviceID *devs;
|
2013-07-13 13:01:50 +02:00
|
|
|
size_t n_devs;
|
|
|
|
|
|
|
|
OSStatus err =
|
|
|
|
CA_GET_ARY(kAudioObjectSystemObject, kAudioHardwarePropertyDevices,
|
|
|
|
&devs, &n_devs);
|
2010-07-11 23:08:57 +02:00
|
|
|
|
2013-07-13 13:01:50 +02:00
|
|
|
CHECK_CA_ERROR("Failed to get list of output devices.");
|
2010-07-11 23:08:57 +02:00
|
|
|
|
2013-07-13 13:01:50 +02:00
|
|
|
for (int i = 0; i < n_devs; i++) {
|
2013-06-21 19:46:30 +02:00
|
|
|
char *name;
|
2013-07-13 13:01:50 +02:00
|
|
|
OSStatus err = CA_GET_STR(devs[i], kAudioObjectPropertyName, &name);
|
2010-07-11 23:08:57 +02:00
|
|
|
|
2013-07-15 08:39:55 +02:00
|
|
|
if (err == noErr)
|
|
|
|
talloc_steal(devs, name);
|
|
|
|
else
|
|
|
|
name = "Unknown";
|
|
|
|
|
|
|
|
help = talloc_asprintf_append(
|
|
|
|
help, "%s (id: %" PRIu32 ")\n", name, devs[i]);
|
2010-07-11 23:08:57 +02:00
|
|
|
}
|
|
|
|
|
2013-07-15 08:39:55 +02:00
|
|
|
talloc_free(devs);
|
2013-07-01 18:47:06 +02:00
|
|
|
|
2013-07-13 13:01:50 +02:00
|
|
|
coreaudio_error:
|
2013-07-01 18:47:06 +02:00
|
|
|
ca_msg(MSGL_FATAL, "%s", help);
|
|
|
|
talloc_free(help);
|
2010-07-11 23:08:57 +02:00
|
|
|
}
|
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
static int init_lpcm(struct ao *ao, AudioStreamBasicDescription asbd);
|
|
|
|
static int init_digital(struct ao *ao, AudioStreamBasicDescription asbd);
|
|
|
|
|
2013-04-19 23:04:11 +02:00
|
|
|
static int init(struct ao *ao, char *params)
|
2003-05-21 23:15:46 +02:00
|
|
|
{
|
2013-04-18 21:25:02 +02:00
|
|
|
OSStatus err;
|
2013-06-23 11:18:54 +02:00
|
|
|
int device_opt = -1, help_opt = 0;
|
2010-07-11 23:08:57 +02:00
|
|
|
|
|
|
|
const opt_t subopts[] = {
|
2013-06-23 11:18:54 +02:00
|
|
|
{"device_id", OPT_ARG_INT, &device_opt, NULL},
|
|
|
|
{"help", OPT_ARG_BOOL, &help_opt, NULL},
|
2010-07-11 23:08:57 +02:00
|
|
|
{NULL}
|
|
|
|
};
|
|
|
|
|
2013-06-21 19:46:30 +02:00
|
|
|
if (subopt_parse(params, subopts) != 0) {
|
2010-07-11 23:08:57 +02:00
|
|
|
print_help();
|
2013-06-21 19:46:30 +02:00
|
|
|
return 0;
|
2010-07-11 23:08:57 +02:00
|
|
|
}
|
2007-10-11 04:00:05 +02:00
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
if (help_opt)
|
2013-06-21 19:46:30 +02:00
|
|
|
print_help();
|
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
struct priv *p = talloc_zero(ao, struct priv);
|
|
|
|
*p = (struct priv) {
|
2013-06-27 08:29:48 +02:00
|
|
|
.device = 0,
|
|
|
|
.is_digital = 0,
|
2013-06-23 11:18:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct priv_d *d= talloc_zero(p, struct priv_d);
|
|
|
|
*d = (struct priv_d) {
|
2013-06-27 08:29:48 +02:00
|
|
|
.muted = false,
|
|
|
|
.stream_asbd_changed = 0,
|
|
|
|
.hog_pid = -1,
|
|
|
|
.stream = 0,
|
|
|
|
.stream_idx = -1,
|
2013-06-26 19:24:14 +02:00
|
|
|
.changed_mixing = false,
|
2013-06-23 11:18:54 +02:00
|
|
|
};
|
2005-06-05 16:47:26 +02:00
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
p->digital = d;
|
|
|
|
ao->priv = p;
|
2007-10-11 04:00:05 +02:00
|
|
|
|
2013-04-19 23:04:11 +02:00
|
|
|
ao->per_application_mixer = true;
|
|
|
|
ao->no_persistent_volume = true;
|
2012-01-06 16:25:52 +01:00
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
AudioDeviceID selected_device = 0;
|
|
|
|
if (device_opt < 0) {
|
|
|
|
// device not set by user, get the default one
|
2013-07-13 09:48:10 +02:00
|
|
|
err = CA_GET(kAudioObjectSystemObject,
|
|
|
|
kAudioHardwarePropertyDefaultOutputDevice,
|
|
|
|
&selected_device);
|
2013-06-23 11:18:54 +02:00
|
|
|
CHECK_CA_ERROR("could not get default audio device");
|
2013-04-19 23:04:11 +02:00
|
|
|
} else {
|
2013-06-23 11:18:54 +02:00
|
|
|
selected_device = device_opt;
|
2013-04-19 23:04:11 +02:00
|
|
|
}
|
2007-10-11 04:00:05 +02:00
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
char *device_name;
|
2013-07-13 13:01:50 +02:00
|
|
|
err = CA_GET_STR(selected_device, kAudioObjectPropertyName, &device_name);
|
2013-06-23 11:18:54 +02:00
|
|
|
CHECK_CA_ERROR("could not get selected audio device name");
|
2007-10-11 04:00:05 +02:00
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
ca_msg(MSGL_V,
|
|
|
|
"selected audio output device: %s (%" PRIu32 ")\n",
|
|
|
|
device_name, selected_device);
|
2005-06-05 16:47:26 +02:00
|
|
|
|
2013-07-15 08:39:55 +02:00
|
|
|
talloc_free(device_name);
|
2010-07-11 23:08:57 +02:00
|
|
|
|
|
|
|
// Save selected device id
|
2013-06-27 08:29:48 +02:00
|
|
|
p->device = selected_device;
|
2010-07-11 23:08:57 +02:00
|
|
|
|
2013-07-03 08:17:31 +02:00
|
|
|
bool supports_digital = false;
|
|
|
|
/* Probe whether device support S/PDIF stream output if input is AC3 stream. */
|
|
|
|
if (AF_FORMAT_IS_AC3(ao->format)) {
|
2013-07-13 11:29:12 +02:00
|
|
|
if (ca_device_supports_digital(selected_device))
|
2013-07-03 08:17:31 +02:00
|
|
|
supports_digital = true;
|
|
|
|
}
|
|
|
|
|
2013-07-03 19:00:18 +02:00
|
|
|
if (!supports_digital) {
|
2013-07-10 19:24:28 +02:00
|
|
|
AudioChannelLayout *layouts;
|
|
|
|
size_t n_layouts;
|
|
|
|
err = CA_GET_ARY_O(selected_device,
|
|
|
|
kAudioDevicePropertyPreferredChannelLayout,
|
|
|
|
&layouts, &n_layouts);
|
2013-07-08 22:58:01 +02:00
|
|
|
CHECK_CA_ERROR("could not get audio device prefered layouts");
|
|
|
|
|
2013-07-10 19:24:28 +02:00
|
|
|
uint32_t *bitmaps;
|
|
|
|
size_t n_bitmaps;
|
|
|
|
|
|
|
|
ca_bitmaps_from_layouts(layouts, n_layouts, &bitmaps, &n_bitmaps);
|
2013-07-15 08:39:55 +02:00
|
|
|
talloc_free(layouts);
|
2013-07-08 22:58:01 +02:00
|
|
|
|
2013-07-03 19:00:18 +02:00
|
|
|
struct mp_chmap_sel chmap_sel = {0};
|
2013-07-08 22:58:01 +02:00
|
|
|
|
|
|
|
for (int i=0; i < n_bitmaps; i++) {
|
|
|
|
struct mp_chmap chmap = {0};
|
|
|
|
mp_chmap_from_lavc(&chmap, bitmaps[i]);
|
|
|
|
mp_chmap_sel_add_map(&chmap_sel, &chmap);
|
|
|
|
}
|
|
|
|
|
2013-07-10 19:24:28 +02:00
|
|
|
talloc_free(bitmaps);
|
|
|
|
|
2013-07-09 20:04:49 +02:00
|
|
|
if (ao->channels.num < 3 || n_bitmaps < 1)
|
|
|
|
// If the input is not surround or we could not get any usable
|
|
|
|
// bitmap from the hardware, default to waveext...
|
2013-07-08 22:58:01 +02:00
|
|
|
mp_chmap_sel_add_waveext(&chmap_sel);
|
|
|
|
|
2013-07-03 19:00:18 +02:00
|
|
|
if (!ao_chmap_sel_adjust(ao, &chmap_sel, &ao->channels))
|
|
|
|
goto coreaudio_error;
|
2013-07-08 22:58:01 +02:00
|
|
|
|
|
|
|
} // closes if (!supports_digital)
|
2013-07-03 19:00:18 +02:00
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
// Build ASBD for the input format
|
|
|
|
AudioStreamBasicDescription asbd;
|
|
|
|
asbd.mSampleRate = ao->samplerate;
|
2013-07-03 08:17:31 +02:00
|
|
|
asbd.mFormatID = supports_digital ?
|
2013-06-23 11:18:54 +02:00
|
|
|
kAudioFormat60958AC3 : kAudioFormatLinearPCM;
|
|
|
|
asbd.mChannelsPerFrame = ao->channels.num;
|
|
|
|
asbd.mBitsPerChannel = af_fmt2bits(ao->format);
|
|
|
|
asbd.mFormatFlags = kAudioFormatFlagIsPacked;
|
|
|
|
|
|
|
|
if ((ao->format & AF_FORMAT_POINT_MASK) == AF_FORMAT_F)
|
|
|
|
asbd.mFormatFlags |= kAudioFormatFlagIsFloat;
|
|
|
|
|
|
|
|
if ((ao->format & AF_FORMAT_SIGN_MASK) == AF_FORMAT_SI)
|
|
|
|
asbd.mFormatFlags |= kAudioFormatFlagIsSignedInteger;
|
|
|
|
|
2013-04-19 23:04:11 +02:00
|
|
|
if ((ao->format & AF_FORMAT_END_MASK) == AF_FORMAT_BE)
|
2013-06-23 11:18:54 +02:00
|
|
|
asbd.mFormatFlags |= kAudioFormatFlagIsBigEndian;
|
2010-07-11 23:08:57 +02:00
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
asbd.mFramesPerPacket = 1;
|
2013-06-27 08:22:52 +02:00
|
|
|
asbd.mBytesPerPacket = asbd.mBytesPerFrame =
|
2013-06-23 11:18:54 +02:00
|
|
|
asbd.mFramesPerPacket * asbd.mChannelsPerFrame *
|
|
|
|
(asbd.mBitsPerChannel / 8);
|
2007-10-11 04:00:05 +02:00
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
ca_print_asbd("source format:", &asbd);
|
|
|
|
|
2013-07-03 08:17:31 +02:00
|
|
|
if (supports_digital)
|
2013-06-23 11:18:54 +02:00
|
|
|
return init_digital(ao, asbd);
|
|
|
|
else
|
|
|
|
return init_lpcm(ao, asbd);
|
|
|
|
|
|
|
|
coreaudio_error:
|
2013-07-04 18:51:46 +02:00
|
|
|
return CONTROL_ERROR;
|
2013-06-23 11:18:54 +02:00
|
|
|
}
|
2013-04-18 21:25:02 +02:00
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
static int init_lpcm(struct ao *ao, AudioStreamBasicDescription asbd)
|
|
|
|
{
|
|
|
|
OSStatus err;
|
|
|
|
uint32_t size;
|
|
|
|
struct priv *p = ao->priv;
|
|
|
|
|
|
|
|
AudioComponentDescription desc = (AudioComponentDescription) {
|
|
|
|
.componentType = kAudioUnitType_Output,
|
|
|
|
.componentSubType = kAudioUnitSubType_HALOutput,
|
|
|
|
.componentManufacturer = kAudioUnitManufacturer_Apple,
|
|
|
|
.componentFlags = 0,
|
|
|
|
.componentFlagsMask = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
AudioComponent comp = AudioComponentFindNext(NULL, &desc);
|
2013-04-18 21:25:02 +02:00
|
|
|
if (comp == NULL) {
|
2013-06-23 11:18:54 +02:00
|
|
|
ca_msg(MSGL_ERR, "unable to find audio component\n");
|
|
|
|
goto coreaudio_error;
|
2013-04-18 21:25:02 +02:00
|
|
|
}
|
|
|
|
|
2013-06-27 08:29:48 +02:00
|
|
|
err = AudioComponentInstanceNew(comp, &(p->audio_unit));
|
2013-06-23 11:18:54 +02:00
|
|
|
CHECK_CA_ERROR("unable to open audio component");
|
2013-04-18 21:25:02 +02:00
|
|
|
|
|
|
|
// Initialize AudioUnit
|
2013-06-27 08:29:48 +02:00
|
|
|
err = AudioUnitInitialize(p->audio_unit);
|
2013-06-23 11:18:54 +02:00
|
|
|
CHECK_CA_ERROR_L(coreaudio_error_component,
|
|
|
|
"unable to initialize audio unit");
|
2013-04-18 21:25:02 +02:00
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
size = sizeof(AudioStreamBasicDescription);
|
2013-06-27 08:29:48 +02:00
|
|
|
err = AudioUnitSetProperty(p->audio_unit,
|
2013-04-18 21:25:02 +02:00
|
|
|
kAudioUnitProperty_StreamFormat,
|
2013-06-23 11:18:54 +02:00
|
|
|
kAudioUnitScope_Input, 0, &asbd, size);
|
2013-04-18 21:25:02 +02:00
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
CHECK_CA_ERROR_L(coreaudio_error_audiounit,
|
|
|
|
"unable to set the input format on the audio unit");
|
2013-04-18 21:25:02 +02:00
|
|
|
|
|
|
|
//Set the Current Device to the Default Output Unit.
|
2013-06-27 08:29:48 +02:00
|
|
|
err = AudioUnitSetProperty(p->audio_unit,
|
2013-04-18 21:25:02 +02:00
|
|
|
kAudioOutputUnitProperty_CurrentDevice,
|
2013-06-27 08:29:48 +02:00
|
|
|
kAudioUnitScope_Global, 0, &p->device,
|
|
|
|
sizeof(p->device));
|
2013-07-03 18:49:02 +02:00
|
|
|
CHECK_CA_ERROR_L(coreaudio_error_audiounit,
|
|
|
|
"can't link audio unit to selected device");
|
|
|
|
|
|
|
|
if (ao->channels.num > 2) {
|
|
|
|
// No need to set a channel layout for mono and stereo inputs
|
|
|
|
AudioChannelLayout acl = (AudioChannelLayout) {
|
|
|
|
.mChannelLayoutTag = kAudioChannelLayoutTag_UseChannelBitmap,
|
|
|
|
.mChannelBitmap = mp_chmap_to_waveext(&ao->channels)
|
|
|
|
};
|
|
|
|
|
|
|
|
err = AudioUnitSetProperty(p->audio_unit,
|
|
|
|
kAudioUnitProperty_AudioChannelLayout,
|
|
|
|
kAudioUnitScope_Input, 0, &acl,
|
|
|
|
sizeof(AudioChannelLayout));
|
|
|
|
CHECK_CA_ERROR_L(coreaudio_error_audiounit,
|
|
|
|
"can't set channel layout bitmap into audio unit");
|
|
|
|
}
|
2009-05-13 04:58:57 +02:00
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
p->buffer = mp_ring_new(p, get_ring_size(ao));
|
2013-04-20 10:02:23 +02:00
|
|
|
print_buffer(p->buffer);
|
2005-06-05 16:47:26 +02:00
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
AURenderCallbackStruct render_cb = (AURenderCallbackStruct) {
|
|
|
|
.inputProc = render_cb_lpcm,
|
|
|
|
.inputProcRefCon = ao,
|
|
|
|
};
|
|
|
|
|
2013-06-27 08:29:48 +02:00
|
|
|
err = AudioUnitSetProperty(p->audio_unit,
|
2013-04-18 21:25:02 +02:00
|
|
|
kAudioUnitProperty_SetRenderCallback,
|
2013-06-23 11:18:54 +02:00
|
|
|
kAudioUnitScope_Input, 0, &render_cb,
|
2013-04-18 21:25:02 +02:00
|
|
|
sizeof(AURenderCallbackStruct));
|
2003-05-21 23:15:46 +02:00
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
CHECK_CA_ERROR_L(coreaudio_error_audiounit,
|
|
|
|
"unable to set render callback on audio unit");
|
2009-05-13 04:58:57 +02:00
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
reset(ao);
|
2003-05-21 23:15:46 +02:00
|
|
|
return CONTROL_OK;
|
2007-12-04 13:38:31 +01:00
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
coreaudio_error_audiounit:
|
2013-06-27 08:29:48 +02:00
|
|
|
AudioUnitUninitialize(p->audio_unit);
|
2013-06-23 11:18:54 +02:00
|
|
|
coreaudio_error_component:
|
2013-06-27 08:29:48 +02:00
|
|
|
AudioComponentInstanceDispose(p->audio_unit);
|
2013-06-23 11:18:54 +02:00
|
|
|
coreaudio_error:
|
2013-07-04 18:51:46 +02:00
|
|
|
return CONTROL_ERROR;
|
2003-05-21 23:15:46 +02:00
|
|
|
}
|
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
static int init_digital(struct ao *ao, AudioStreamBasicDescription asbd)
|
2007-10-11 04:00:05 +02:00
|
|
|
{
|
2013-04-19 23:04:11 +02:00
|
|
|
struct priv *p = ao->priv;
|
2013-06-23 11:18:54 +02:00
|
|
|
struct priv_d *d = p->digital;
|
2013-04-18 21:25:02 +02:00
|
|
|
OSStatus err = noErr;
|
2013-06-23 11:18:54 +02:00
|
|
|
|
|
|
|
uint32_t is_alive = 1;
|
2013-07-13 09:48:10 +02:00
|
|
|
err = CA_GET(p->device, kAudioDevicePropertyDeviceIsAlive, &is_alive);
|
2013-07-13 13:01:50 +02:00
|
|
|
CHECK_CA_WARN("could not check whether device is alive");
|
2013-06-23 11:18:54 +02:00
|
|
|
|
|
|
|
if (!is_alive)
|
|
|
|
ca_msg(MSGL_WARN, "device is not alive\n");
|
|
|
|
|
2013-06-27 08:29:48 +02:00
|
|
|
p->is_digital = 1;
|
2007-10-11 04:00:05 +02:00
|
|
|
|
2013-06-27 08:29:48 +02:00
|
|
|
err = ca_lock_device(p->device, &d->hog_pid);
|
2013-06-26 19:24:14 +02:00
|
|
|
CHECK_CA_WARN("failed to set hogmode");
|
2007-10-11 04:00:05 +02:00
|
|
|
|
2013-06-27 08:29:48 +02:00
|
|
|
err = ca_disable_mixing(p->device, &d->changed_mixing);
|
2013-06-26 19:24:14 +02:00
|
|
|
CHECK_CA_WARN("failed to disable mixing");
|
2007-10-11 04:00:05 +02:00
|
|
|
|
2013-07-13 13:01:50 +02:00
|
|
|
AudioStreamID *streams;
|
|
|
|
size_t n_streams;
|
2013-06-23 11:18:54 +02:00
|
|
|
|
2013-07-13 13:01:50 +02:00
|
|
|
/* Get a list of all the streams on this device. */
|
|
|
|
err = CA_GET_ARY_O(p->device, kAudioDevicePropertyStreams,
|
|
|
|
&streams, &n_streams);
|
2007-10-11 04:00:05 +02:00
|
|
|
|
2013-07-13 13:01:50 +02:00
|
|
|
CHECK_CA_ERROR("could not get number of streams");
|
2007-10-11 04:00:05 +02:00
|
|
|
|
2013-07-13 13:01:50 +02:00
|
|
|
for (int i = 0; i < n_streams && d->stream_idx < 0; i++) {
|
2013-07-13 11:29:12 +02:00
|
|
|
bool digital = ca_stream_supports_digital(streams[i]);
|
2007-10-11 04:00:05 +02:00
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
if (digital) {
|
2013-07-15 08:18:50 +02:00
|
|
|
err = CA_GET(streams[i], kAudioStreamPropertyPhysicalFormat,
|
|
|
|
&d->original_asbd);
|
|
|
|
if (!CHECK_CA_WARN("could not get stream's physical format to "
|
|
|
|
"revert to, getting the next one"))
|
|
|
|
continue;
|
|
|
|
|
2013-07-13 13:01:50 +02:00
|
|
|
AudioStreamRangedDescription *formats;
|
|
|
|
size_t n_formats;
|
|
|
|
|
|
|
|
err = CA_GET_ARY(streams[i],
|
|
|
|
kAudioStreamPropertyAvailablePhysicalFormats,
|
|
|
|
&formats, &n_formats);
|
2007-10-11 04:00:05 +02:00
|
|
|
|
2013-07-15 08:18:50 +02:00
|
|
|
if (!CHECK_CA_WARN("could not get number of stream formats"))
|
2013-06-23 11:18:54 +02:00
|
|
|
continue; // try next one
|
2007-10-11 04:00:05 +02:00
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
int req_rate_format = -1;
|
|
|
|
int max_rate_format = -1;
|
|
|
|
|
2013-06-27 08:29:48 +02:00
|
|
|
d->stream = streams[i];
|
|
|
|
d->stream_idx = i;
|
2013-06-23 11:18:54 +02:00
|
|
|
|
2013-07-13 13:01:50 +02:00
|
|
|
for (int j = 0; j < n_formats; j++)
|
2013-07-13 11:29:12 +02:00
|
|
|
if (ca_format_is_digital(formats[j].mFormat)) {
|
2013-06-23 11:18:54 +02:00
|
|
|
// select the digital format that has exactly the same
|
|
|
|
// samplerate. If an exact match cannot be found, select
|
|
|
|
// the format with highest samplerate as backup.
|
2013-07-11 23:53:21 +02:00
|
|
|
if (formats[j].mFormat.mSampleRate == asbd.mSampleRate) {
|
2013-06-23 11:18:54 +02:00
|
|
|
req_rate_format = j;
|
2007-10-11 04:00:05 +02:00
|
|
|
break;
|
2013-06-23 11:18:54 +02:00
|
|
|
} else if (max_rate_format < 0 ||
|
|
|
|
formats[j].mFormat.mSampleRate >
|
|
|
|
formats[max_rate_format].mFormat.mSampleRate)
|
|
|
|
max_rate_format = j;
|
2007-10-11 04:00:05 +02:00
|
|
|
}
|
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
if (req_rate_format >= 0)
|
2013-06-27 08:29:48 +02:00
|
|
|
d->stream_asbd = formats[req_rate_format].mFormat;
|
2013-04-18 21:25:02 +02:00
|
|
|
else
|
2013-06-27 08:29:48 +02:00
|
|
|
d->stream_asbd = formats[max_rate_format].mFormat;
|
2013-06-23 11:18:54 +02:00
|
|
|
|
2013-07-15 08:39:55 +02:00
|
|
|
talloc_free(formats);
|
2007-10-11 04:00:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-15 08:39:55 +02:00
|
|
|
talloc_free(streams);
|
2007-10-11 04:00:05 +02:00
|
|
|
|
2013-06-27 08:29:48 +02:00
|
|
|
if (d->stream_idx < 0) {
|
2013-06-26 08:28:19 +02:00
|
|
|
ca_msg(MSGL_WARN, "can't find any digital output stream format\n");
|
2013-06-23 11:18:54 +02:00
|
|
|
goto coreaudio_error;
|
|
|
|
}
|
2007-10-11 04:00:05 +02:00
|
|
|
|
2013-07-13 11:29:12 +02:00
|
|
|
if (!ca_change_format(d->stream, d->stream_asbd))
|
2013-06-23 11:18:54 +02:00
|
|
|
goto coreaudio_error;
|
2007-10-11 04:00:05 +02:00
|
|
|
|
2013-07-01 19:13:34 +02:00
|
|
|
void *changed = (void *) &(d->stream_asbd_changed);
|
|
|
|
err = ca_enable_device_listener(p->device, changed);
|
2013-06-23 11:18:54 +02:00
|
|
|
CHECK_CA_ERROR("cannot install format change listener during init");
|
2007-10-11 04:00:05 +02:00
|
|
|
|
Remove compile time/runtime CPU detection, and drop some platforms
mplayer had three ways of enabling CPU specific assembler routines:
a) Enable them at compile time; crash if the CPU can't handle it.
b) Enable them at compile time, but let the configure script detect
your CPU. Your binary will only crash if you try to run it on a
different system that has less features than yours.
This was the default, I think.
c) Runtime detection.
The implementation of b) and c) suck. a) is not really feasible (it
sucks for users). Remove all code related to this, and use libav's CPU
detection instead. Now the configure script will always enable CPU
specific features, and disable them at runtime if libav reports them
not as available.
One implication is that now the compiler is always expected to handle
SSE (etc.) inline assembly at runtime, unless it's explicitly disabled.
Only checks for x86 CPU specific features are kept, the rest is either
unused or barely used.
Get rid of all the dump -mpcu, -march etc. flags. Trust the compiler
to select decent settings.
Get rid of support for the following operating systems:
- BSD/OS (some ancient BSD fork)
- QNX (don't care)
- BeOS (dead, Haiku support is still welcome)
- AIX (don't care)
- HP-UX (don't care)
- OS/2 (dead, actual support has been removed a while ago)
Remove the configure code for detecting the endianness. Instead, use
the standard header <endian.h>, which can be used if _GNU_SOURCE or
_BSD_SOURCE is defined. (Maybe these changes should have been in a
separate commit.)
Since this is a quite violent code removal orgy, and I'm testing only
on x86 32 bit Linux, expect regressions.
2012-07-29 17:20:57 +02:00
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
2013-06-27 08:29:48 +02:00
|
|
|
if (!(p->stream_asdb.mFormatFlags & kAudioFormatFlagIsBigEndian))
|
2007-10-11 04:00:05 +02:00
|
|
|
#else
|
2010-10-08 10:56:20 +02:00
|
|
|
/* tell mplayer that we need a byteswap on AC3 streams, */
|
2013-06-27 08:29:48 +02:00
|
|
|
if (d->stream_asbd.mFormatID & kAudioFormat60958AC3)
|
2013-04-19 23:04:11 +02:00
|
|
|
ao->format = AF_FORMAT_AC3_LE;
|
2013-06-27 08:29:48 +02:00
|
|
|
else if (d->stream_asbd.mFormatFlags & kAudioFormatFlagIsBigEndian)
|
2013-06-18 21:46:32 +02:00
|
|
|
ca_msg(MSGL_WARN,
|
2013-06-26 08:28:19 +02:00
|
|
|
"stream has non-native byte order, digital output may fail\n");
|
2013-06-23 11:18:54 +02:00
|
|
|
#endif
|
2013-04-18 21:25:02 +02:00
|
|
|
|
2013-06-27 08:29:48 +02:00
|
|
|
ao->samplerate = d->stream_asbd.mSampleRate;
|
2013-04-19 23:04:11 +02:00
|
|
|
ao->bps = ao->samplerate *
|
2013-06-27 08:29:48 +02:00
|
|
|
(d->stream_asbd.mBytesPerPacket /
|
|
|
|
d->stream_asbd.mFramesPerPacket);
|
2007-10-11 04:00:05 +02:00
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
p->buffer = mp_ring_new(p, get_ring_size(ao));
|
2013-04-20 10:02:23 +02:00
|
|
|
print_buffer(p->buffer);
|
2007-10-11 04:00:05 +02:00
|
|
|
|
2013-06-27 08:29:48 +02:00
|
|
|
err = AudioDeviceCreateIOProcID(p->device,
|
2013-06-20 23:22:56 +02:00
|
|
|
(AudioDeviceIOProc)render_cb_digital,
|
2010-07-11 23:00:37 +02:00
|
|
|
(void *)ao,
|
2013-06-27 08:29:48 +02:00
|
|
|
&d->render_cb);
|
2010-07-11 23:00:37 +02:00
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
CHECK_CA_ERROR("failed to register digital render callback");
|
2007-10-11 04:00:05 +02:00
|
|
|
|
2013-04-19 23:04:11 +02:00
|
|
|
reset(ao);
|
2007-10-11 04:00:05 +02:00
|
|
|
|
|
|
|
return CONTROL_TRUE;
|
2007-12-04 13:38:31 +01:00
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
coreaudio_error:
|
2013-06-27 08:29:48 +02:00
|
|
|
err = ca_unlock_device(p->device, &d->hog_pid);
|
2013-06-25 08:24:14 +02:00
|
|
|
CHECK_CA_WARN("can't release hog mode");
|
2013-07-04 18:51:46 +02:00
|
|
|
return CONTROL_ERROR;
|
2007-10-11 04:00:05 +02:00
|
|
|
}
|
|
|
|
|
2013-04-19 23:04:11 +02:00
|
|
|
static int play(struct ao *ao, void *output_samples, int num_bytes, int flags)
|
2009-05-13 04:58:57 +02:00
|
|
|
{
|
2013-06-26 08:23:31 +02:00
|
|
|
struct priv *p = ao->priv;
|
2013-06-23 11:18:54 +02:00
|
|
|
struct priv_d *d = p->digital;
|
2007-10-11 04:00:05 +02:00
|
|
|
|
|
|
|
// Check whether we need to reset the digital output stream.
|
2013-06-27 08:29:48 +02:00
|
|
|
if (p->is_digital && d->stream_asbd_changed) {
|
|
|
|
d->stream_asbd_changed = 0;
|
2013-07-13 11:29:12 +02:00
|
|
|
if (ca_stream_supports_digital(d->stream)) {
|
|
|
|
if (!ca_change_format(d->stream, d->stream_asbd)) {
|
2013-06-26 08:23:31 +02:00
|
|
|
ca_msg(MSGL_WARN, "can't restore digital output\n");
|
|
|
|
} else {
|
2013-06-26 08:28:19 +02:00
|
|
|
ca_msg(MSGL_WARN, "restoring digital output succeeded.\n");
|
2013-04-19 23:04:11 +02:00
|
|
|
reset(ao);
|
2007-10-11 04:00:05 +02:00
|
|
|
}
|
2013-06-26 08:23:31 +02:00
|
|
|
}
|
2007-10-11 04:00:05 +02:00
|
|
|
}
|
2006-08-18 03:19:19 +02:00
|
|
|
|
2013-06-23 11:18:54 +02:00
|
|
|
int wrote = mp_ring_write(p->buffer, output_samples, num_bytes);
|
2013-04-19 23:04:11 +02:00
|
|
|
audio_resume(ao);
|
2010-07-11 23:14:48 +02:00
|
|
|
|
2007-10-11 04:00:05 +02:00
|
|
|
return wrote;
|
2003-05-21 23:15:46 +02:00
|
|
|
}
|
|
|
|
|
2013-04-19 23:04:11 +02:00
|
|
|
static void reset(struct ao *ao)
|
2003-05-21 23:15:46 +02:00
|
|
|
{
|
2013-04-19 23:04:11 +02:00
|
|
|
struct priv *p = ao->priv;
|
|
|
|
audio_pause(ao);
|
2013-05-23 21:23:32 +02:00
|
|
|
mp_ring_reset(p->buffer);
|
2003-05-21 23:15:46 +02:00
|
|
|
}
|
|
|
|
|
2013-04-19 23:04:11 +02:00
|
|
|
static int get_space(struct ao *ao)
|
2003-05-21 23:15:46 +02:00
|
|
|
{
|
2013-04-19 23:04:11 +02:00
|
|
|
struct priv *p = ao->priv;
|
2013-05-23 21:23:32 +02:00
|
|
|
return mp_ring_available(p->buffer);
|
2003-05-21 23:15:46 +02:00
|
|
|
}
|
|
|
|
|
2013-04-19 23:04:11 +02:00
|
|
|
static float get_delay(struct ao *ao)
|
2003-05-21 23:15:46 +02:00
|
|
|
{
|
2013-06-26 23:40:35 +02:00
|
|
|
// FIXME: should also report the delay of coreaudio itself (hardware +
|
|
|
|
// internal buffers)
|
2013-04-19 23:04:11 +02:00
|
|
|
struct priv *p = ao->priv;
|
2013-05-23 21:23:32 +02:00
|
|
|
return mp_ring_buffered(p->buffer) / (float)ao->bps;
|
2003-05-21 23:15:46 +02:00
|
|
|
}
|
|
|
|
|
2013-04-19 23:04:11 +02:00
|
|
|
static void uninit(struct ao *ao, bool immed)
|
2003-05-21 23:15:46 +02:00
|
|
|
{
|
2013-04-19 23:04:11 +02:00
|
|
|
struct priv *p = ao->priv;
|
2013-04-18 21:25:02 +02:00
|
|
|
OSStatus err = noErr;
|
|
|
|
|
2013-06-26 23:20:36 +02:00
|
|
|
if (!immed)
|
|
|
|
mp_sleep_us(get_delay(ao) * 1000000);
|
2013-04-18 21:25:02 +02:00
|
|
|
|
2013-06-27 08:29:48 +02:00
|
|
|
if (!p->is_digital) {
|
|
|
|
AudioOutputUnitStop(p->audio_unit);
|
|
|
|
AudioUnitUninitialize(p->audio_unit);
|
|
|
|
AudioComponentInstanceDispose(p->audio_unit);
|
2013-04-18 21:25:02 +02:00
|
|
|
} else {
|
2013-06-23 11:18:54 +02:00
|
|
|
struct priv_d *d = p->digital;
|
2013-06-26 23:20:36 +02:00
|
|
|
|
2013-07-01 19:13:34 +02:00
|
|
|
void *changed = (void *) &(d->stream_asbd_changed);
|
|
|
|
err = ca_disable_device_listener(p->device, changed);
|
|
|
|
CHECK_CA_WARN("can't remove device listener, this may cause a crash");
|
|
|
|
|
2013-06-27 08:29:48 +02:00
|
|
|
err = AudioDeviceStop(p->device, d->render_cb);
|
2013-06-26 23:20:36 +02:00
|
|
|
CHECK_CA_WARN("failed to stop audio device");
|
|
|
|
|
2013-06-27 08:29:48 +02:00
|
|
|
err = AudioDeviceDestroyIOProcID(p->device, d->render_cb);
|
2013-06-26 23:20:36 +02:00
|
|
|
CHECK_CA_WARN("failed to remove device render callback");
|
2013-04-18 21:25:02 +02:00
|
|
|
|
2013-07-15 08:18:50 +02:00
|
|
|
if (!ca_change_format(d->stream, d->original_asbd))
|
|
|
|
ca_msg(MSGL_WARN, "can't revert to original device format");
|
|
|
|
|
2013-06-27 08:29:48 +02:00
|
|
|
err = ca_enable_mixing(p->device, d->changed_mixing);
|
2013-06-26 19:24:14 +02:00
|
|
|
CHECK_CA_WARN("can't re-enable mixing");
|
2013-06-25 08:24:14 +02:00
|
|
|
|
2013-06-27 08:29:48 +02:00
|
|
|
err = ca_unlock_device(p->device, &d->hog_pid);
|
2013-06-25 08:24:14 +02:00
|
|
|
CHECK_CA_WARN("can't release hog mode");
|
2013-04-18 21:25:02 +02:00
|
|
|
}
|
2003-05-21 23:15:46 +02:00
|
|
|
}
|
|
|
|
|
2013-04-19 23:04:11 +02:00
|
|
|
static void audio_pause(struct ao *ao)
|
2003-05-21 23:15:46 +02:00
|
|
|
{
|
2013-04-19 23:04:11 +02:00
|
|
|
struct priv *p = ao->priv;
|
2013-04-18 21:25:02 +02:00
|
|
|
OSErr err = noErr;
|
2007-10-11 04:00:05 +02:00
|
|
|
|
2013-06-26 23:40:35 +02:00
|
|
|
if (p->paused)
|
|
|
|
return;
|
|
|
|
|
2013-06-27 08:29:48 +02:00
|
|
|
if (!p->is_digital) {
|
|
|
|
err = AudioOutputUnitStop(p->audio_unit);
|
2013-06-26 23:40:35 +02:00
|
|
|
CHECK_CA_WARN("can't stop audio unit");
|
2013-04-18 21:25:02 +02:00
|
|
|
} else {
|
2013-06-23 11:18:54 +02:00
|
|
|
struct priv_d *d = p->digital;
|
2013-06-27 08:29:48 +02:00
|
|
|
err = AudioDeviceStop(p->device, d->render_cb);
|
2013-06-26 23:40:35 +02:00
|
|
|
CHECK_CA_WARN("can't stop digital device");
|
2007-10-11 04:00:05 +02:00
|
|
|
}
|
2003-05-21 23:15:46 +02:00
|
|
|
|
2013-06-26 23:40:35 +02:00
|
|
|
p->paused = true;
|
|
|
|
}
|
2003-05-21 23:15:46 +02:00
|
|
|
|
2013-04-19 23:04:11 +02:00
|
|
|
static void audio_resume(struct ao *ao)
|
2003-05-21 23:15:46 +02:00
|
|
|
{
|
2013-04-19 23:04:11 +02:00
|
|
|
struct priv *p = ao->priv;
|
2013-04-18 21:25:02 +02:00
|
|
|
OSErr err = noErr;
|
2007-10-11 04:00:05 +02:00
|
|
|
|
2013-04-19 23:04:11 +02:00
|
|
|
if (!p->paused)
|
2007-10-11 04:00:05 +02:00
|
|
|
return;
|
|
|
|
|
2013-06-27 08:29:48 +02:00
|
|
|
if (!p->is_digital) {
|
|
|
|
err = AudioOutputUnitStart(p->audio_unit);
|
2013-06-26 23:40:35 +02:00
|
|
|
CHECK_CA_WARN("can't start audio unit");
|
2013-04-18 21:25:02 +02:00
|
|
|
} else {
|
2013-06-23 11:18:54 +02:00
|
|
|
struct priv_d *d = p->digital;
|
2013-06-27 08:29:48 +02:00
|
|
|
err = AudioDeviceStart(p->device, d->render_cb);
|
2013-06-26 23:40:35 +02:00
|
|
|
CHECK_CA_WARN("can't start digital device");
|
2007-10-11 04:00:05 +02:00
|
|
|
}
|
2013-06-26 23:40:35 +02:00
|
|
|
|
|
|
|
p->paused = false;
|
2007-10-11 04:00:05 +02:00
|
|
|
}
|
|
|
|
|
2013-04-19 23:04:11 +02:00
|
|
|
const struct ao_driver audio_out_coreaudio = {
|
|
|
|
.info = &(const struct ao_info) {
|
2013-06-26 23:40:35 +02:00
|
|
|
"CoreAudio (OS X Audio Output)",
|
2013-04-19 23:04:11 +02:00
|
|
|
"coreaudio",
|
|
|
|
"Timothy J. Wood, Dan Christiansen, Chris Roccati & Stefano Pigozzi",
|
|
|
|
"",
|
|
|
|
},
|
|
|
|
.uninit = uninit,
|
|
|
|
.init = init,
|
|
|
|
.play = play,
|
|
|
|
.control = control,
|
|
|
|
.get_space = get_space,
|
|
|
|
.get_delay = get_delay,
|
|
|
|
.reset = reset,
|
|
|
|
.pause = audio_pause,
|
|
|
|
.resume = audio_resume,
|
|
|
|
};
|