2003-05-21 21:15:46 +00:00
|
|
|
/*
|
2009-05-04 14:53:47 +00:00
|
|
|
* CoreAudio audio output driver for Mac OS X
|
2003-05-21 21:15:46 +00:00
|
|
|
*
|
2008-06-06 00:45:35 +00:00
|
|
|
* original copyright (C) Timothy J. Wood - Aug 2000
|
|
|
|
* ported to MPlayer libao2 by Dan Christiansen
|
2003-05-21 21:15:46 +00:00
|
|
|
*
|
2013-10-23 17:07:27 +00:00
|
|
|
* Chris Roccati
|
|
|
|
* Stefano Pigozzi
|
|
|
|
*
|
2008-06-06 00:45:35 +00: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 21:15:46 +00:00
|
|
|
*
|
2008-06-06 00:45:35 +00:00
|
|
|
* This file is part of MPlayer.
|
2007-12-22 17:33:28 +00:00
|
|
|
*
|
2008-06-06 00:45:35 +00: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 21:15:46 +00:00
|
|
|
*
|
2008-06-06 00:45:35 +00: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 21:15:46 +00:00
|
|
|
*
|
2008-06-06 00:45:35 +00: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 21:15:46 +00: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 00:45:35 +00:00
|
|
|
* when you are wanting to do good buffering of audio).
|
2003-05-21 21:15:46 +00:00
|
|
|
*/
|
|
|
|
|
2005-01-12 22:00:02 +00:00
|
|
|
#include "config.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "ao.h"
|
2014-03-07 14:24:32 +00:00
|
|
|
#include "internal.h"
|
2012-11-09 00:06:43 +00:00
|
|
|
#include "audio/format.h"
|
2013-06-26 06:23:31 +00:00
|
|
|
#include "osdep/timer.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/m_option.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "misc/ring.h"
|
|
|
|
#include "common/msg.h"
|
2013-07-13 07:48:10 +00:00
|
|
|
#include "audio/out/ao_coreaudio_properties.h"
|
|
|
|
#include "audio/out/ao_coreaudio_utils.h"
|
2013-04-20 08:02:23 +00:00
|
|
|
|
2013-04-19 21:04:11 +00:00
|
|
|
static void audio_pause(struct ao *ao);
|
|
|
|
static void audio_resume(struct ao *ao);
|
|
|
|
static void reset(struct ao *ao);
|
2003-05-22 16:12:54 +00:00
|
|
|
|
2013-08-01 14:47:36 +00:00
|
|
|
static void print_buffer(struct ao *ao, struct mp_ring *buffer)
|
2013-04-20 08:02:23 +00:00
|
|
|
{
|
|
|
|
void *tctx = talloc_new(NULL);
|
2013-08-01 14:47:36 +00:00
|
|
|
MP_VERBOSE(ao, "%s\n", mp_ring_repr(buffer, tctx));
|
2013-04-20 08:02:23 +00:00
|
|
|
talloc_free(tctx);
|
|
|
|
}
|
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
struct priv_d {
|
2013-06-27 06:29:48 +00: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 06:18:50 +00:00
|
|
|
AudioStreamBasicDescription original_asbd;
|
2013-06-27 06:29:48 +00:00
|
|
|
|
|
|
|
bool changed_mixing;
|
|
|
|
int stream_asbd_changed;
|
|
|
|
bool muted;
|
2013-06-23 09:18:54 +00:00
|
|
|
};
|
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
struct priv {
|
|
|
|
AudioDeviceID device; // selected device
|
|
|
|
bool is_digital; // running in digital mode?
|
2013-04-18 19:25:02 +00:00
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
AudioUnit audio_unit; // AudioUnit for lpcm output
|
2013-04-18 19:25:02 +00:00
|
|
|
|
2013-06-26 21:40:35 +00:00
|
|
|
bool paused;
|
2013-04-18 19:25:02 +00:00
|
|
|
|
2013-05-23 19:23:32 +00:00
|
|
|
struct mp_ring *buffer;
|
2013-06-23 09:18:54 +00:00
|
|
|
struct priv_d *digital;
|
2013-07-22 20:27:08 +00:00
|
|
|
|
|
|
|
// options
|
|
|
|
int opt_device_id;
|
|
|
|
int opt_list;
|
2013-04-19 21:04:11 +00:00
|
|
|
};
|
2003-05-21 21:15:46 +00:00
|
|
|
|
2013-06-16 17:25:10 +00: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 21:03:19 +00:00
|
|
|
static OSStatus render_cb_lpcm(void *ctx, AudioUnitRenderActionFlags *aflags,
|
|
|
|
const AudioTimeStamp *ts, UInt32 bus,
|
|
|
|
UInt32 frames, AudioBufferList *buffer_list)
|
2003-05-21 21:15:46 +00:00
|
|
|
{
|
2013-06-17 21:03:19 +00:00
|
|
|
struct ao *ao = ctx;
|
|
|
|
struct priv *p = ao->priv;
|
2013-06-27 06:22:52 +00:00
|
|
|
|
2013-06-17 21:03:19 +00:00
|
|
|
AudioBuffer buf = buffer_list->mBuffers[0];
|
2013-06-27 06:22:52 +00:00
|
|
|
int requested = buf.mDataByteSize;
|
2013-04-19 21:04:11 +00:00
|
|
|
|
2013-07-28 09:21:03 +00:00
|
|
|
if (mp_ring_buffered(p->buffer) < requested) {
|
2013-08-01 14:47:36 +00:00
|
|
|
MP_VERBOSE(ao, "buffer underrun\n");
|
2013-07-28 09:21:03 +00:00
|
|
|
audio_pause(ao);
|
2013-10-03 21:38:19 +00:00
|
|
|
memset(buf.mData, 0, requested);
|
2013-07-28 09:21:03 +00:00
|
|
|
} else {
|
|
|
|
mp_ring_read(p->buffer, buf.mData, requested);
|
|
|
|
}
|
2005-06-05 14:47:26 +00:00
|
|
|
|
2013-04-18 19:25:02 +00:00
|
|
|
return noErr;
|
2003-05-21 21:15:46 +00:00
|
|
|
}
|
|
|
|
|
2013-06-20 21:22:56 +00: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 09:18:54 +00:00
|
|
|
struct ao *ao = ctx;
|
|
|
|
struct priv *p = ao->priv;
|
|
|
|
struct priv_d *d = p->digital;
|
2013-06-27 06:29:48 +00:00
|
|
|
AudioBuffer buf = out_data->mBuffers[d->stream_idx];
|
2013-06-23 09:18:54 +00:00
|
|
|
int requested = buf.mDataByteSize;
|
2013-06-20 21:22:56 +00:00
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
if (d->muted)
|
2013-06-20 21:22:56 +00:00
|
|
|
mp_ring_drain(p->buffer, requested);
|
2013-06-21 11:43:59 +00:00
|
|
|
else
|
|
|
|
mp_ring_read(p->buffer, buf.mData, requested);
|
2013-06-20 21:22:56 +00:00
|
|
|
|
|
|
|
return noErr;
|
|
|
|
}
|
|
|
|
|
2013-04-19 21:04:11 +00:00
|
|
|
static int control(struct ao *ao, enum aocontrol cmd, void *arg)
|
2013-04-18 19:25:02 +00:00
|
|
|
{
|
2013-04-19 21:04:11 +00:00
|
|
|
struct priv *p = ao->priv;
|
2013-04-18 19:25:02 +00: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 06:29:48 +00:00
|
|
|
if (p->is_digital) {
|
2013-06-23 09:18:54 +00:00
|
|
|
struct priv_d *d = p->digital;
|
2013-04-18 19:25:02 +00:00
|
|
|
// Digital output has no volume adjust.
|
2013-11-04 07:11:32 +00:00
|
|
|
int digitalvol = d->muted ? 0 : 100;
|
2013-04-18 19:25:02 +00:00
|
|
|
*control_vol = (ao_control_vol_t) {
|
2013-11-04 07:11:32 +00:00
|
|
|
.left = digitalvol, .right = digitalvol,
|
2013-04-18 19:25:02 +00:00
|
|
|
};
|
|
|
|
return CONTROL_TRUE;
|
|
|
|
}
|
2013-06-18 21:48:48 +00:00
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
err = AudioUnitGetParameter(p->audio_unit, kHALOutputParam_Volume,
|
2013-04-18 19:25:02 +00:00
|
|
|
kAudioUnitScope_Global, 0, &vol);
|
|
|
|
|
2013-06-18 21:48:48 +00:00
|
|
|
CHECK_CA_ERROR("could not get HAL output volume");
|
2013-07-02 06:07:15 +00:00
|
|
|
control_vol->left = control_vol->right = vol * 100.0;
|
2013-06-18 21:48:48 +00:00
|
|
|
return CONTROL_TRUE;
|
2013-04-18 19:25:02 +00:00
|
|
|
|
|
|
|
case AOCONTROL_SET_VOLUME:
|
|
|
|
control_vol = (ao_control_vol_t *)arg;
|
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
if (p->is_digital) {
|
2013-06-23 09:18:54 +00:00
|
|
|
struct priv_d *d = p->digital;
|
2013-04-18 19:25:02 +00: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 06:29:48 +00:00
|
|
|
d->muted = true;
|
2013-04-18 19:25:02 +00:00
|
|
|
else
|
2013-06-27 06:29:48 +00:00
|
|
|
d->muted = false;
|
2013-04-18 19:25:02 +00:00
|
|
|
return CONTROL_TRUE;
|
|
|
|
}
|
|
|
|
|
2013-07-02 06:07:15 +00:00
|
|
|
vol = (control_vol->left + control_vol->right) / 200.0;
|
2013-06-27 06:29:48 +00:00
|
|
|
err = AudioUnitSetParameter(p->audio_unit, kHALOutputParam_Volume,
|
2013-04-18 19:25:02 +00:00
|
|
|
kAudioUnitScope_Global, 0, vol, 0);
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2013-06-18 21:48:48 +00: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 21:15:46 +00:00
|
|
|
}
|
|
|
|
|
2013-08-01 14:47:36 +00:00
|
|
|
static void print_list(struct ao *ao)
|
2010-07-11 21:08:57 +00:00
|
|
|
{
|
2013-07-22 20:27:08 +00:00
|
|
|
char *help = talloc_strdup(NULL, "Available output devices:\n");
|
2010-07-11 21:08:57 +00:00
|
|
|
|
2013-06-21 17:46:30 +00:00
|
|
|
AudioDeviceID *devs;
|
2013-07-13 11:01:50 +00:00
|
|
|
size_t n_devs;
|
|
|
|
|
|
|
|
OSStatus err =
|
|
|
|
CA_GET_ARY(kAudioObjectSystemObject, kAudioHardwarePropertyDevices,
|
|
|
|
&devs, &n_devs);
|
2010-07-11 21:08:57 +00:00
|
|
|
|
2013-07-13 11:01:50 +00:00
|
|
|
CHECK_CA_ERROR("Failed to get list of output devices.");
|
2010-07-11 21:08:57 +00:00
|
|
|
|
2013-07-13 11:01:50 +00:00
|
|
|
for (int i = 0; i < n_devs; i++) {
|
2013-06-21 17:46:30 +00:00
|
|
|
char *name;
|
2013-11-04 07:11:32 +00:00
|
|
|
err = CA_GET_STR(devs[i], kAudioObjectPropertyName, &name);
|
2010-07-11 21:08:57 +00:00
|
|
|
|
2013-07-15 06:39:55 +00:00
|
|
|
if (err == noErr)
|
|
|
|
talloc_steal(devs, name);
|
|
|
|
else
|
|
|
|
name = "Unknown";
|
|
|
|
|
|
|
|
help = talloc_asprintf_append(
|
2013-07-22 20:27:08 +00:00
|
|
|
help, " * %s (id: %" PRIu32 ")\n", name, devs[i]);
|
2010-07-11 21:08:57 +00:00
|
|
|
}
|
|
|
|
|
2013-07-15 06:39:55 +00:00
|
|
|
talloc_free(devs);
|
2013-07-01 16:47:06 +00:00
|
|
|
|
2013-07-13 11:01:50 +00:00
|
|
|
coreaudio_error:
|
2013-08-01 14:47:36 +00:00
|
|
|
MP_INFO(ao, "%s", help);
|
2013-07-01 16:47:06 +00:00
|
|
|
talloc_free(help);
|
2010-07-11 21:08:57 +00:00
|
|
|
}
|
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
static int init_lpcm(struct ao *ao, AudioStreamBasicDescription asbd);
|
|
|
|
static int init_digital(struct ao *ao, AudioStreamBasicDescription asbd);
|
|
|
|
|
2013-07-22 20:57:51 +00:00
|
|
|
static int init(struct ao *ao)
|
2003-05-21 21:15:46 +00:00
|
|
|
{
|
2013-04-18 19:25:02 +00:00
|
|
|
OSStatus err;
|
2013-07-22 20:27:08 +00:00
|
|
|
struct priv *p = ao->priv;
|
2007-10-11 02:00:05 +00:00
|
|
|
|
2013-08-01 14:47:36 +00:00
|
|
|
if (p->opt_list) print_list(ao);
|
2013-06-21 17:46:30 +00:00
|
|
|
|
2013-07-22 20:27:08 +00:00
|
|
|
struct priv_d *d = talloc_zero(p, struct priv_d);
|
2013-06-23 09:18:54 +00:00
|
|
|
|
|
|
|
*d = (struct priv_d) {
|
2013-06-27 06:29:48 +00:00
|
|
|
.muted = false,
|
|
|
|
.stream_asbd_changed = 0,
|
|
|
|
.hog_pid = -1,
|
|
|
|
.stream = 0,
|
|
|
|
.stream_idx = -1,
|
2013-06-26 17:24:14 +00:00
|
|
|
.changed_mixing = false,
|
2013-06-23 09:18:54 +00:00
|
|
|
};
|
2005-06-05 14:47:26 +00:00
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
p->digital = d;
|
2007-10-11 02:00:05 +00:00
|
|
|
|
2013-04-19 21:04:11 +00:00
|
|
|
ao->per_application_mixer = true;
|
|
|
|
ao->no_persistent_volume = true;
|
2012-01-06 15:25:52 +00:00
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
AudioDeviceID selected_device = 0;
|
2013-07-22 20:27:08 +00:00
|
|
|
if (p->opt_device_id < 0) {
|
2013-06-23 09:18:54 +00:00
|
|
|
// device not set by user, get the default one
|
2013-07-13 07:48:10 +00:00
|
|
|
err = CA_GET(kAudioObjectSystemObject,
|
|
|
|
kAudioHardwarePropertyDefaultOutputDevice,
|
|
|
|
&selected_device);
|
2013-06-23 09:18:54 +00:00
|
|
|
CHECK_CA_ERROR("could not get default audio device");
|
2013-04-19 21:04:11 +00:00
|
|
|
} else {
|
2013-07-22 20:27:08 +00:00
|
|
|
selected_device = p->opt_device_id;
|
2013-04-19 21:04:11 +00:00
|
|
|
}
|
2007-10-11 02:00:05 +00:00
|
|
|
|
2013-12-21 20:49:13 +00:00
|
|
|
if (mp_msg_test(ao->log, MSGL_V)) {
|
2013-10-01 09:00:43 +00:00
|
|
|
char *name;
|
|
|
|
err = CA_GET_STR(selected_device, kAudioObjectPropertyName, &name);
|
|
|
|
CHECK_CA_ERROR("could not get selected audio device name");
|
2007-10-11 02:00:05 +00:00
|
|
|
|
2013-10-01 09:00:43 +00:00
|
|
|
MP_VERBOSE(ao, "selected audio output device: %s (%" PRIu32 ")\n",
|
|
|
|
name, selected_device);
|
2005-06-05 14:47:26 +00:00
|
|
|
|
2013-10-01 09:00:43 +00:00
|
|
|
talloc_free(name);
|
|
|
|
}
|
2010-07-11 21:08:57 +00:00
|
|
|
|
|
|
|
// Save selected device id
|
2013-06-27 06:29:48 +00:00
|
|
|
p->device = selected_device;
|
2010-07-11 21:08:57 +00:00
|
|
|
|
2013-11-10 22:15:02 +00:00
|
|
|
ao->format = af_fmt_from_planar(ao->format);
|
|
|
|
|
2013-07-03 06:17:31 +00: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-08-01 14:47:36 +00:00
|
|
|
if (ca_device_supports_digital(ao, selected_device))
|
2013-07-03 06:17:31 +00:00
|
|
|
supports_digital = true;
|
|
|
|
}
|
|
|
|
|
2013-07-03 17:00:18 +00:00
|
|
|
if (!supports_digital) {
|
2013-07-10 17:24:28 +00:00
|
|
|
AudioChannelLayout *layouts;
|
|
|
|
size_t n_layouts;
|
|
|
|
err = CA_GET_ARY_O(selected_device,
|
|
|
|
kAudioDevicePropertyPreferredChannelLayout,
|
|
|
|
&layouts, &n_layouts);
|
2013-07-08 20:58:01 +00:00
|
|
|
CHECK_CA_ERROR("could not get audio device prefered layouts");
|
|
|
|
|
2013-07-03 17:00:18 +00:00
|
|
|
struct mp_chmap_sel chmap_sel = {0};
|
2014-05-01 16:36:52 +00:00
|
|
|
for (int i = 0; i < n_layouts; i++) {
|
2013-07-08 20:58:01 +00:00
|
|
|
struct mp_chmap chmap = {0};
|
2014-05-01 16:36:52 +00:00
|
|
|
if (ca_layout_to_mp_chmap(ao, &layouts[i], &chmap))
|
|
|
|
mp_chmap_sel_add_map(&chmap_sel, &chmap);
|
2013-07-08 20:58:01 +00:00
|
|
|
}
|
|
|
|
|
2014-05-01 16:36:52 +00:00
|
|
|
talloc_free(layouts);
|
2013-07-10 17:24:28 +00:00
|
|
|
|
2014-05-08 06:06:10 +00:00
|
|
|
if (ao->channels.num < 3) {
|
|
|
|
struct mp_chmap chmap;
|
|
|
|
mp_chmap_from_channels(&chmap, ao->channels.num);
|
|
|
|
mp_chmap_sel_add_map(&chmap_sel, &chmap);
|
|
|
|
}
|
2013-07-08 20:58:01 +00:00
|
|
|
|
2014-05-10 10:30:08 +00:00
|
|
|
if (!ao_chmap_sel_adjust(ao, &chmap_sel, &ao->channels)) {
|
|
|
|
MP_ERR(ao, "could not select a suitable channel map among the "
|
|
|
|
"hardware supported ones. Make sure to configure your "
|
|
|
|
"output device correctly in 'Audio MIDI Setup.app'\n");
|
2013-07-03 17:00:18 +00:00
|
|
|
goto coreaudio_error;
|
2014-05-10 10:30:08 +00:00
|
|
|
}
|
2013-07-08 20:58:01 +00:00
|
|
|
|
|
|
|
} // closes if (!supports_digital)
|
2013-07-03 17:00:18 +00:00
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
// Build ASBD for the input format
|
|
|
|
AudioStreamBasicDescription asbd;
|
|
|
|
asbd.mSampleRate = ao->samplerate;
|
2013-07-03 06:17:31 +00:00
|
|
|
asbd.mFormatID = supports_digital ?
|
2013-06-23 09:18:54 +00: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 21:04:11 +00:00
|
|
|
if ((ao->format & AF_FORMAT_END_MASK) == AF_FORMAT_BE)
|
2013-06-23 09:18:54 +00:00
|
|
|
asbd.mFormatFlags |= kAudioFormatFlagIsBigEndian;
|
2010-07-11 21:08:57 +00:00
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
asbd.mFramesPerPacket = 1;
|
2013-06-27 06:22:52 +00:00
|
|
|
asbd.mBytesPerPacket = asbd.mBytesPerFrame =
|
2013-06-23 09:18:54 +00:00
|
|
|
asbd.mFramesPerPacket * asbd.mChannelsPerFrame *
|
|
|
|
(asbd.mBitsPerChannel / 8);
|
2007-10-11 02:00:05 +00:00
|
|
|
|
2013-08-01 14:47:36 +00:00
|
|
|
ca_print_asbd(ao, "source format:", &asbd);
|
2013-06-23 09:18:54 +00:00
|
|
|
|
2013-07-03 06:17:31 +00:00
|
|
|
if (supports_digital)
|
2013-06-23 09:18:54 +00:00
|
|
|
return init_digital(ao, asbd);
|
|
|
|
else
|
|
|
|
return init_lpcm(ao, asbd);
|
|
|
|
|
|
|
|
coreaudio_error:
|
2013-07-04 16:51:46 +00:00
|
|
|
return CONTROL_ERROR;
|
2013-06-23 09:18:54 +00:00
|
|
|
}
|
2013-04-18 19:25:02 +00:00
|
|
|
|
2013-06-23 09:18:54 +00: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,
|
2013-07-29 06:22:33 +00:00
|
|
|
.componentSubType = (p->opt_device_id < 0) ?
|
|
|
|
kAudioUnitSubType_DefaultOutput :
|
|
|
|
kAudioUnitSubType_HALOutput,
|
2013-06-23 09:18:54 +00:00
|
|
|
.componentManufacturer = kAudioUnitManufacturer_Apple,
|
|
|
|
.componentFlags = 0,
|
|
|
|
.componentFlagsMask = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
AudioComponent comp = AudioComponentFindNext(NULL, &desc);
|
2013-04-18 19:25:02 +00:00
|
|
|
if (comp == NULL) {
|
2013-08-01 14:47:36 +00:00
|
|
|
MP_ERR(ao, "unable to find audio component\n");
|
2013-06-23 09:18:54 +00:00
|
|
|
goto coreaudio_error;
|
2013-04-18 19:25:02 +00:00
|
|
|
}
|
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
err = AudioComponentInstanceNew(comp, &(p->audio_unit));
|
2013-06-23 09:18:54 +00:00
|
|
|
CHECK_CA_ERROR("unable to open audio component");
|
2013-04-18 19:25:02 +00:00
|
|
|
|
|
|
|
// Initialize AudioUnit
|
2013-06-27 06:29:48 +00:00
|
|
|
err = AudioUnitInitialize(p->audio_unit);
|
2013-06-23 09:18:54 +00:00
|
|
|
CHECK_CA_ERROR_L(coreaudio_error_component,
|
|
|
|
"unable to initialize audio unit");
|
2013-04-18 19:25:02 +00:00
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
size = sizeof(AudioStreamBasicDescription);
|
2013-06-27 06:29:48 +00:00
|
|
|
err = AudioUnitSetProperty(p->audio_unit,
|
2013-04-18 19:25:02 +00:00
|
|
|
kAudioUnitProperty_StreamFormat,
|
2013-06-23 09:18:54 +00:00
|
|
|
kAudioUnitScope_Input, 0, &asbd, size);
|
2013-04-18 19:25:02 +00:00
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
CHECK_CA_ERROR_L(coreaudio_error_audiounit,
|
|
|
|
"unable to set the input format on the audio unit");
|
2013-04-18 19:25:02 +00:00
|
|
|
|
|
|
|
//Set the Current Device to the Default Output Unit.
|
2013-06-27 06:29:48 +00:00
|
|
|
err = AudioUnitSetProperty(p->audio_unit,
|
2013-04-18 19:25:02 +00:00
|
|
|
kAudioOutputUnitProperty_CurrentDevice,
|
2013-06-27 06:29:48 +00:00
|
|
|
kAudioUnitScope_Global, 0, &p->device,
|
|
|
|
sizeof(p->device));
|
2013-07-03 16:49:02 +00:00
|
|
|
CHECK_CA_ERROR_L(coreaudio_error_audiounit,
|
|
|
|
"can't link audio unit to selected device");
|
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
p->buffer = mp_ring_new(p, get_ring_size(ao));
|
2013-08-01 14:47:36 +00:00
|
|
|
print_buffer(ao, p->buffer);
|
2005-06-05 14:47:26 +00:00
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
AURenderCallbackStruct render_cb = (AURenderCallbackStruct) {
|
|
|
|
.inputProc = render_cb_lpcm,
|
|
|
|
.inputProcRefCon = ao,
|
|
|
|
};
|
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
err = AudioUnitSetProperty(p->audio_unit,
|
2013-04-18 19:25:02 +00:00
|
|
|
kAudioUnitProperty_SetRenderCallback,
|
2013-06-23 09:18:54 +00:00
|
|
|
kAudioUnitScope_Input, 0, &render_cb,
|
2013-04-18 19:25:02 +00:00
|
|
|
sizeof(AURenderCallbackStruct));
|
2003-05-21 21:15:46 +00:00
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
CHECK_CA_ERROR_L(coreaudio_error_audiounit,
|
|
|
|
"unable to set render callback on audio unit");
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
reset(ao);
|
2003-05-21 21:15:46 +00:00
|
|
|
return CONTROL_OK;
|
2007-12-04 12:38:31 +00:00
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
coreaudio_error_audiounit:
|
2013-06-27 06:29:48 +00:00
|
|
|
AudioUnitUninitialize(p->audio_unit);
|
2013-06-23 09:18:54 +00:00
|
|
|
coreaudio_error_component:
|
2013-06-27 06:29:48 +00:00
|
|
|
AudioComponentInstanceDispose(p->audio_unit);
|
2013-06-23 09:18:54 +00:00
|
|
|
coreaudio_error:
|
2013-07-04 16:51:46 +00:00
|
|
|
return CONTROL_ERROR;
|
2003-05-21 21:15:46 +00:00
|
|
|
}
|
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
static int init_digital(struct ao *ao, AudioStreamBasicDescription asbd)
|
2007-10-11 02:00:05 +00:00
|
|
|
{
|
2013-04-19 21:04:11 +00:00
|
|
|
struct priv *p = ao->priv;
|
2013-06-23 09:18:54 +00:00
|
|
|
struct priv_d *d = p->digital;
|
2013-04-18 19:25:02 +00:00
|
|
|
OSStatus err = noErr;
|
2013-06-23 09:18:54 +00:00
|
|
|
|
|
|
|
uint32_t is_alive = 1;
|
2013-07-13 07:48:10 +00:00
|
|
|
err = CA_GET(p->device, kAudioDevicePropertyDeviceIsAlive, &is_alive);
|
2013-07-13 11:01:50 +00:00
|
|
|
CHECK_CA_WARN("could not check whether device is alive");
|
2013-06-23 09:18:54 +00:00
|
|
|
|
|
|
|
if (!is_alive)
|
2013-08-01 14:47:36 +00:00
|
|
|
MP_WARN(ao , "device is not alive\n");
|
2013-06-23 09:18:54 +00:00
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
p->is_digital = 1;
|
2007-10-11 02:00:05 +00:00
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
err = ca_lock_device(p->device, &d->hog_pid);
|
2013-06-26 17:24:14 +00:00
|
|
|
CHECK_CA_WARN("failed to set hogmode");
|
2007-10-11 02:00:05 +00:00
|
|
|
|
2013-08-01 14:47:36 +00:00
|
|
|
err = ca_disable_mixing(ao, p->device, &d->changed_mixing);
|
2013-06-26 17:24:14 +00:00
|
|
|
CHECK_CA_WARN("failed to disable mixing");
|
2007-10-11 02:00:05 +00:00
|
|
|
|
2013-07-13 11:01:50 +00:00
|
|
|
AudioStreamID *streams;
|
|
|
|
size_t n_streams;
|
2013-06-23 09:18:54 +00:00
|
|
|
|
2013-07-13 11:01:50 +00: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 02:00:05 +00:00
|
|
|
|
2013-07-13 11:01:50 +00:00
|
|
|
CHECK_CA_ERROR("could not get number of streams");
|
2007-10-11 02:00:05 +00:00
|
|
|
|
2013-07-13 11:01:50 +00:00
|
|
|
for (int i = 0; i < n_streams && d->stream_idx < 0; i++) {
|
2013-08-01 14:47:36 +00:00
|
|
|
bool digital = ca_stream_supports_digital(ao, streams[i]);
|
2007-10-11 02:00:05 +00:00
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
if (digital) {
|
2013-07-15 06:18:50 +00: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 11:01:50 +00:00
|
|
|
AudioStreamRangedDescription *formats;
|
|
|
|
size_t n_formats;
|
|
|
|
|
|
|
|
err = CA_GET_ARY(streams[i],
|
|
|
|
kAudioStreamPropertyAvailablePhysicalFormats,
|
|
|
|
&formats, &n_formats);
|
2007-10-11 02:00:05 +00:00
|
|
|
|
2013-07-15 06:18:50 +00:00
|
|
|
if (!CHECK_CA_WARN("could not get number of stream formats"))
|
2013-06-23 09:18:54 +00:00
|
|
|
continue; // try next one
|
2007-10-11 02:00:05 +00:00
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
int req_rate_format = -1;
|
|
|
|
int max_rate_format = -1;
|
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
d->stream = streams[i];
|
|
|
|
d->stream_idx = i;
|
2013-06-23 09:18:54 +00:00
|
|
|
|
2013-07-13 11:01:50 +00:00
|
|
|
for (int j = 0; j < n_formats; j++)
|
2013-07-13 09:29:12 +00:00
|
|
|
if (ca_format_is_digital(formats[j].mFormat)) {
|
2013-06-23 09:18:54 +00: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 21:53:21 +00:00
|
|
|
if (formats[j].mFormat.mSampleRate == asbd.mSampleRate) {
|
2013-06-23 09:18:54 +00:00
|
|
|
req_rate_format = j;
|
2007-10-11 02:00:05 +00:00
|
|
|
break;
|
2013-06-23 09:18:54 +00:00
|
|
|
} else if (max_rate_format < 0 ||
|
|
|
|
formats[j].mFormat.mSampleRate >
|
|
|
|
formats[max_rate_format].mFormat.mSampleRate)
|
|
|
|
max_rate_format = j;
|
2007-10-11 02:00:05 +00:00
|
|
|
}
|
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
if (req_rate_format >= 0)
|
2013-06-27 06:29:48 +00:00
|
|
|
d->stream_asbd = formats[req_rate_format].mFormat;
|
2013-04-18 19:25:02 +00:00
|
|
|
else
|
2013-06-27 06:29:48 +00:00
|
|
|
d->stream_asbd = formats[max_rate_format].mFormat;
|
2013-06-23 09:18:54 +00:00
|
|
|
|
2013-07-15 06:39:55 +00:00
|
|
|
talloc_free(formats);
|
2007-10-11 02:00:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-15 06:39:55 +00:00
|
|
|
talloc_free(streams);
|
2007-10-11 02:00:05 +00:00
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
if (d->stream_idx < 0) {
|
2013-08-01 14:47:36 +00:00
|
|
|
MP_WARN(ao , "can't find any digital output stream format\n");
|
2013-06-23 09:18:54 +00:00
|
|
|
goto coreaudio_error;
|
|
|
|
}
|
2007-10-11 02:00:05 +00:00
|
|
|
|
2013-08-01 14:47:36 +00:00
|
|
|
if (!ca_change_format(ao, d->stream, d->stream_asbd))
|
2013-06-23 09:18:54 +00:00
|
|
|
goto coreaudio_error;
|
2007-10-11 02:00:05 +00:00
|
|
|
|
2013-07-01 17:13:34 +00:00
|
|
|
void *changed = (void *) &(d->stream_asbd_changed);
|
|
|
|
err = ca_enable_device_listener(p->device, changed);
|
2013-06-23 09:18:54 +00:00
|
|
|
CHECK_CA_ERROR("cannot install format change listener during init");
|
2007-10-11 02:00:05 +00: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 15:20:57 +00:00
|
|
|
#if BYTE_ORDER == BIG_ENDIAN
|
2013-06-27 06:29:48 +00:00
|
|
|
if (!(p->stream_asdb.mFormatFlags & kAudioFormatFlagIsBigEndian))
|
2007-10-11 02:00:05 +00:00
|
|
|
#else
|
2010-10-08 08:56:20 +00:00
|
|
|
/* tell mplayer that we need a byteswap on AC3 streams, */
|
2013-06-27 06:29:48 +00:00
|
|
|
if (d->stream_asbd.mFormatID & kAudioFormat60958AC3)
|
2013-04-19 21:04:11 +00:00
|
|
|
ao->format = AF_FORMAT_AC3_LE;
|
2013-06-27 06:29:48 +00:00
|
|
|
else if (d->stream_asbd.mFormatFlags & kAudioFormatFlagIsBigEndian)
|
2013-07-22 20:34:21 +00:00
|
|
|
#endif
|
2013-08-01 14:47:36 +00:00
|
|
|
MP_WARN(ao, "stream has non-native byte order, output may fail\n");
|
2013-04-18 19:25:02 +00:00
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
ao->samplerate = d->stream_asbd.mSampleRate;
|
2013-04-19 21:04:11 +00:00
|
|
|
ao->bps = ao->samplerate *
|
2013-06-27 06:29:48 +00:00
|
|
|
(d->stream_asbd.mBytesPerPacket /
|
|
|
|
d->stream_asbd.mFramesPerPacket);
|
2007-10-11 02:00:05 +00:00
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
p->buffer = mp_ring_new(p, get_ring_size(ao));
|
2013-08-01 14:47:36 +00:00
|
|
|
print_buffer(ao, p->buffer);
|
2007-10-11 02:00:05 +00:00
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
err = AudioDeviceCreateIOProcID(p->device,
|
2013-06-20 21:22:56 +00:00
|
|
|
(AudioDeviceIOProc)render_cb_digital,
|
2010-07-11 21:00:37 +00:00
|
|
|
(void *)ao,
|
2013-06-27 06:29:48 +00:00
|
|
|
&d->render_cb);
|
2010-07-11 21:00:37 +00:00
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
CHECK_CA_ERROR("failed to register digital render callback");
|
2007-10-11 02:00:05 +00:00
|
|
|
|
2013-04-19 21:04:11 +00:00
|
|
|
reset(ao);
|
2007-10-11 02:00:05 +00:00
|
|
|
|
|
|
|
return CONTROL_TRUE;
|
2007-12-04 12:38:31 +00:00
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
coreaudio_error:
|
2013-06-27 06:29:48 +00:00
|
|
|
err = ca_unlock_device(p->device, &d->hog_pid);
|
2013-06-25 06:24:14 +00:00
|
|
|
CHECK_CA_WARN("can't release hog mode");
|
2013-07-04 16:51:46 +00:00
|
|
|
return CONTROL_ERROR;
|
2007-10-11 02:00:05 +00:00
|
|
|
}
|
|
|
|
|
2013-11-10 22:24:21 +00:00
|
|
|
static int play(struct ao *ao, void **data, int samples, int flags)
|
2009-05-13 02:58:57 +00:00
|
|
|
{
|
2013-06-26 06:23:31 +00:00
|
|
|
struct priv *p = ao->priv;
|
2013-06-23 09:18:54 +00:00
|
|
|
struct priv_d *d = p->digital;
|
2013-11-10 22:24:21 +00:00
|
|
|
void *output_samples = data[0];
|
|
|
|
int num_bytes = samples * ao->sstride;
|
2007-10-11 02:00:05 +00:00
|
|
|
|
|
|
|
// Check whether we need to reset the digital output stream.
|
2013-06-27 06:29:48 +00:00
|
|
|
if (p->is_digital && d->stream_asbd_changed) {
|
|
|
|
d->stream_asbd_changed = 0;
|
2013-08-01 14:47:36 +00:00
|
|
|
if (ca_stream_supports_digital(ao, d->stream)) {
|
|
|
|
if (!ca_change_format(ao, d->stream, d->stream_asbd)) {
|
|
|
|
MP_WARN(ao , "can't restore digital output\n");
|
2013-06-26 06:23:31 +00:00
|
|
|
} else {
|
2013-08-01 14:47:36 +00:00
|
|
|
MP_WARN(ao, "restoring digital output succeeded.\n");
|
2013-04-19 21:04:11 +00:00
|
|
|
reset(ao);
|
2007-10-11 02:00:05 +00:00
|
|
|
}
|
2013-06-26 06:23:31 +00:00
|
|
|
}
|
2007-10-11 02:00:05 +00:00
|
|
|
}
|
2006-08-18 01:19:19 +00:00
|
|
|
|
2013-06-23 09:18:54 +00:00
|
|
|
int wrote = mp_ring_write(p->buffer, output_samples, num_bytes);
|
2013-04-19 21:04:11 +00:00
|
|
|
audio_resume(ao);
|
2010-07-11 21:14:48 +00:00
|
|
|
|
2013-11-10 22:24:21 +00:00
|
|
|
return wrote / ao->sstride;
|
2003-05-21 21:15:46 +00:00
|
|
|
}
|
|
|
|
|
2013-04-19 21:04:11 +00:00
|
|
|
static void reset(struct ao *ao)
|
2003-05-21 21:15:46 +00:00
|
|
|
{
|
2013-04-19 21:04:11 +00:00
|
|
|
struct priv *p = ao->priv;
|
|
|
|
audio_pause(ao);
|
2013-05-23 19:23:32 +00:00
|
|
|
mp_ring_reset(p->buffer);
|
2003-05-21 21:15:46 +00:00
|
|
|
}
|
|
|
|
|
2013-04-19 21:04:11 +00:00
|
|
|
static int get_space(struct ao *ao)
|
2003-05-21 21:15:46 +00:00
|
|
|
{
|
2013-04-19 21:04:11 +00:00
|
|
|
struct priv *p = ao->priv;
|
2013-11-10 22:24:21 +00:00
|
|
|
return mp_ring_available(p->buffer) / ao->sstride;
|
2003-05-21 21:15:46 +00:00
|
|
|
}
|
|
|
|
|
2013-04-19 21:04:11 +00:00
|
|
|
static float get_delay(struct ao *ao)
|
2003-05-21 21:15:46 +00:00
|
|
|
{
|
2013-06-26 21:40:35 +00:00
|
|
|
// FIXME: should also report the delay of coreaudio itself (hardware +
|
|
|
|
// internal buffers)
|
2013-04-19 21:04:11 +00:00
|
|
|
struct priv *p = ao->priv;
|
2013-05-23 19:23:32 +00:00
|
|
|
return mp_ring_buffered(p->buffer) / (float)ao->bps;
|
2003-05-21 21:15:46 +00:00
|
|
|
}
|
|
|
|
|
2014-03-08 23:49:39 +00:00
|
|
|
static void uninit(struct ao *ao)
|
2003-05-21 21:15:46 +00:00
|
|
|
{
|
2013-04-19 21:04:11 +00:00
|
|
|
struct priv *p = ao->priv;
|
2013-04-18 19:25:02 +00:00
|
|
|
OSStatus err = noErr;
|
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
if (!p->is_digital) {
|
|
|
|
AudioOutputUnitStop(p->audio_unit);
|
|
|
|
AudioUnitUninitialize(p->audio_unit);
|
|
|
|
AudioComponentInstanceDispose(p->audio_unit);
|
2013-04-18 19:25:02 +00:00
|
|
|
} else {
|
2013-06-23 09:18:54 +00:00
|
|
|
struct priv_d *d = p->digital;
|
2013-06-26 21:20:36 +00:00
|
|
|
|
2013-07-01 17:13:34 +00: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 06:29:48 +00:00
|
|
|
err = AudioDeviceStop(p->device, d->render_cb);
|
2013-06-26 21:20:36 +00:00
|
|
|
CHECK_CA_WARN("failed to stop audio device");
|
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
err = AudioDeviceDestroyIOProcID(p->device, d->render_cb);
|
2013-06-26 21:20:36 +00:00
|
|
|
CHECK_CA_WARN("failed to remove device render callback");
|
2013-04-18 19:25:02 +00:00
|
|
|
|
2013-08-01 14:47:36 +00:00
|
|
|
if (!ca_change_format(ao, d->stream, d->original_asbd))
|
|
|
|
MP_WARN(ao, "can't revert to original device format");
|
2013-07-15 06:18:50 +00:00
|
|
|
|
2013-08-01 14:47:36 +00:00
|
|
|
err = ca_enable_mixing(ao, p->device, d->changed_mixing);
|
2013-06-26 17:24:14 +00:00
|
|
|
CHECK_CA_WARN("can't re-enable mixing");
|
2013-06-25 06:24:14 +00:00
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
err = ca_unlock_device(p->device, &d->hog_pid);
|
2013-06-25 06:24:14 +00:00
|
|
|
CHECK_CA_WARN("can't release hog mode");
|
2013-04-18 19:25:02 +00:00
|
|
|
}
|
2003-05-21 21:15:46 +00:00
|
|
|
}
|
|
|
|
|
2013-04-19 21:04:11 +00:00
|
|
|
static void audio_pause(struct ao *ao)
|
2003-05-21 21:15:46 +00:00
|
|
|
{
|
2013-04-19 21:04:11 +00:00
|
|
|
struct priv *p = ao->priv;
|
2013-04-18 19:25:02 +00:00
|
|
|
OSErr err = noErr;
|
2007-10-11 02:00:05 +00:00
|
|
|
|
2013-06-26 21:40:35 +00:00
|
|
|
if (p->paused)
|
|
|
|
return;
|
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
if (!p->is_digital) {
|
|
|
|
err = AudioOutputUnitStop(p->audio_unit);
|
2013-06-26 21:40:35 +00:00
|
|
|
CHECK_CA_WARN("can't stop audio unit");
|
2013-04-18 19:25:02 +00:00
|
|
|
} else {
|
2013-06-23 09:18:54 +00:00
|
|
|
struct priv_d *d = p->digital;
|
2013-06-27 06:29:48 +00:00
|
|
|
err = AudioDeviceStop(p->device, d->render_cb);
|
2013-06-26 21:40:35 +00:00
|
|
|
CHECK_CA_WARN("can't stop digital device");
|
2007-10-11 02:00:05 +00:00
|
|
|
}
|
2003-05-21 21:15:46 +00:00
|
|
|
|
2013-06-26 21:40:35 +00:00
|
|
|
p->paused = true;
|
|
|
|
}
|
2003-05-21 21:15:46 +00:00
|
|
|
|
2013-04-19 21:04:11 +00:00
|
|
|
static void audio_resume(struct ao *ao)
|
2003-05-21 21:15:46 +00:00
|
|
|
{
|
2013-04-19 21:04:11 +00:00
|
|
|
struct priv *p = ao->priv;
|
2013-04-18 19:25:02 +00:00
|
|
|
OSErr err = noErr;
|
2007-10-11 02:00:05 +00:00
|
|
|
|
2013-04-19 21:04:11 +00:00
|
|
|
if (!p->paused)
|
2007-10-11 02:00:05 +00:00
|
|
|
return;
|
|
|
|
|
2013-06-27 06:29:48 +00:00
|
|
|
if (!p->is_digital) {
|
|
|
|
err = AudioOutputUnitStart(p->audio_unit);
|
2013-06-26 21:40:35 +00:00
|
|
|
CHECK_CA_WARN("can't start audio unit");
|
2013-04-18 19:25:02 +00:00
|
|
|
} else {
|
2013-06-23 09:18:54 +00:00
|
|
|
struct priv_d *d = p->digital;
|
2013-06-27 06:29:48 +00:00
|
|
|
err = AudioDeviceStart(p->device, d->render_cb);
|
2013-06-26 21:40:35 +00:00
|
|
|
CHECK_CA_WARN("can't start digital device");
|
2007-10-11 02:00:05 +00:00
|
|
|
}
|
2013-06-26 21:40:35 +00:00
|
|
|
|
|
|
|
p->paused = false;
|
2007-10-11 02:00:05 +00:00
|
|
|
}
|
|
|
|
|
2013-07-22 20:27:08 +00:00
|
|
|
#define OPT_BASE_STRUCT struct priv
|
|
|
|
|
2013-04-19 21:04:11 +00:00
|
|
|
const struct ao_driver audio_out_coreaudio = {
|
2013-10-23 17:07:27 +00:00
|
|
|
.description = "CoreAudio (OS X Audio Output)",
|
|
|
|
.name = "coreaudio",
|
2013-04-19 21:04:11 +00:00
|
|
|
.uninit = uninit,
|
|
|
|
.init = init,
|
|
|
|
.play = play,
|
|
|
|
.control = control,
|
|
|
|
.get_space = get_space,
|
|
|
|
.get_delay = get_delay,
|
|
|
|
.reset = reset,
|
|
|
|
.pause = audio_pause,
|
|
|
|
.resume = audio_resume,
|
2013-07-22 20:27:08 +00:00
|
|
|
.priv_size = sizeof(struct priv),
|
|
|
|
.options = (const struct m_option[]) {
|
|
|
|
OPT_INT("device_id", opt_device_id, 0, OPTDEF_INT(-1)),
|
|
|
|
OPT_FLAG("list", opt_list, 0),
|
|
|
|
{0}
|
|
|
|
},
|
2013-04-19 21:04:11 +00:00
|
|
|
};
|