2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2012-04-05 00:45:39 +02:00
|
|
|
* Copyright (C) 2003-2012 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
2005-03-13 20:23:09 +01:00
|
|
|
*
|
|
|
|
* This program 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.
|
|
|
|
*
|
|
|
|
* This program 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.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2005-03-13 20:23:09 +01:00
|
|
|
*/
|
|
|
|
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "config.h"
|
2011-09-17 08:54:28 +02:00
|
|
|
#include "osx_output_plugin.h"
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "output_api.h"
|
2013-01-15 01:00:59 +01:00
|
|
|
#include "util/fifo_buffer.h"
|
2005-03-16 05:46:41 +01:00
|
|
|
|
2008-12-08 23:23:30 +01:00
|
|
|
#include <glib.h>
|
2012-03-21 09:48:28 +01:00
|
|
|
#include <CoreAudio/AudioHardware.h>
|
2008-10-26 21:58:37 +01:00
|
|
|
#include <AudioUnit/AudioUnit.h>
|
2009-09-20 23:30:37 +02:00
|
|
|
#include <CoreServices/CoreServices.h>
|
2008-10-26 21:58:37 +01:00
|
|
|
|
2008-12-08 23:23:30 +01:00
|
|
|
#undef G_LOG_DOMAIN
|
|
|
|
#define G_LOG_DOMAIN "osx"
|
|
|
|
|
2009-02-26 21:03:06 +01:00
|
|
|
struct osx_output {
|
2011-09-16 23:31:48 +02:00
|
|
|
struct audio_output base;
|
|
|
|
|
2010-12-21 04:21:46 +01:00
|
|
|
/* configuration settings */
|
|
|
|
OSType component_subtype;
|
|
|
|
/* only applicable with kAudioUnitSubType_HALOutput */
|
|
|
|
const char *device_name;
|
|
|
|
|
2005-03-16 05:46:41 +01:00
|
|
|
AudioUnit au;
|
2008-12-28 22:09:42 +01:00
|
|
|
GMutex *mutex;
|
|
|
|
GCond *condition;
|
2012-04-05 00:45:39 +02:00
|
|
|
|
|
|
|
struct fifo_buffer *buffer;
|
2009-02-26 21:03:06 +01:00
|
|
|
};
|
2005-03-13 20:23:09 +01:00
|
|
|
|
2009-02-26 22:04:59 +01:00
|
|
|
/**
|
|
|
|
* The quark used for GError.domain.
|
|
|
|
*/
|
|
|
|
static inline GQuark
|
|
|
|
osx_output_quark(void)
|
|
|
|
{
|
|
|
|
return g_quark_from_static_string("osx_output");
|
|
|
|
}
|
|
|
|
|
2009-02-26 21:03:06 +01:00
|
|
|
static bool
|
|
|
|
osx_output_test_default_device(void)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2009-02-26 21:33:13 +01:00
|
|
|
/* on a Mac, this is always the default plugin, if nothing
|
|
|
|
else is configured */
|
2008-10-29 20:40:27 +01:00
|
|
|
return true;
|
2005-03-13 22:33:55 +01:00
|
|
|
}
|
|
|
|
|
2010-12-21 04:21:46 +01:00
|
|
|
static void
|
|
|
|
osx_output_configure(struct osx_output *oo, const struct config_param *param)
|
|
|
|
{
|
|
|
|
const char *device = config_get_block_string(param, "device", NULL);
|
|
|
|
|
|
|
|
if (device == NULL || 0 == strcmp(device, "default")) {
|
|
|
|
oo->component_subtype = kAudioUnitSubType_DefaultOutput;
|
|
|
|
oo->device_name = NULL;
|
|
|
|
}
|
|
|
|
else if (0 == strcmp(device, "system")) {
|
|
|
|
oo->component_subtype = kAudioUnitSubType_SystemOutput;
|
|
|
|
oo->device_name = NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
oo->component_subtype = kAudioUnitSubType_HALOutput;
|
|
|
|
/* XXX am I supposed to g_strdup() this? */
|
|
|
|
oo->device_name = device;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-16 23:31:48 +02:00
|
|
|
static struct audio_output *
|
|
|
|
osx_output_init(const struct config_param *param, GError **error_r)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2009-02-26 21:03:06 +01:00
|
|
|
struct osx_output *oo = g_new(struct osx_output, 1);
|
2011-09-16 23:31:48 +02:00
|
|
|
if (!ao_base_init(&oo->base, &osx_output_plugin, param, error_r)) {
|
|
|
|
g_free(oo);
|
|
|
|
return NULL;
|
|
|
|
}
|
2009-02-26 21:03:06 +01:00
|
|
|
|
2010-12-21 04:21:46 +01:00
|
|
|
osx_output_configure(oo, param);
|
2009-02-26 21:03:06 +01:00
|
|
|
oo->mutex = g_mutex_new();
|
|
|
|
oo->condition = g_cond_new();
|
|
|
|
|
2011-09-16 23:31:48 +02:00
|
|
|
return &oo->base;
|
2005-03-13 20:23:09 +01:00
|
|
|
}
|
|
|
|
|
2011-09-16 23:31:48 +02:00
|
|
|
static void
|
|
|
|
osx_output_finish(struct audio_output *ao)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2011-09-16 23:31:48 +02:00
|
|
|
struct osx_output *od = (struct osx_output *)ao;
|
2009-02-26 21:03:06 +01:00
|
|
|
|
2008-12-28 22:09:42 +01:00
|
|
|
g_mutex_free(od->mutex);
|
|
|
|
g_cond_free(od->condition);
|
2009-01-25 18:47:21 +01:00
|
|
|
g_free(od);
|
2005-03-13 20:23:09 +01:00
|
|
|
}
|
|
|
|
|
2010-12-21 04:21:46 +01:00
|
|
|
static bool
|
|
|
|
osx_output_set_device(struct osx_output *oo, GError **error)
|
|
|
|
{
|
|
|
|
bool ret = true;
|
|
|
|
OSStatus status;
|
|
|
|
UInt32 size, numdevices;
|
|
|
|
AudioDeviceID *deviceids = NULL;
|
|
|
|
char name[256];
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
if (oo->component_subtype != kAudioUnitSubType_HALOutput)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
/* how many audio devices are there? */
|
|
|
|
status = AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices,
|
|
|
|
&size,
|
|
|
|
NULL);
|
|
|
|
if (status != noErr) {
|
2010-12-21 04:21:47 +01:00
|
|
|
g_set_error(error, osx_output_quark(), status,
|
2010-12-21 04:21:46 +01:00
|
|
|
"Unable to determine number of OS X audio devices: %s",
|
|
|
|
GetMacOSStatusCommentString(status));
|
|
|
|
ret = false;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* what are the available audio device IDs? */
|
|
|
|
numdevices = size / sizeof(AudioDeviceID);
|
|
|
|
deviceids = g_malloc(size);
|
|
|
|
status = AudioHardwareGetProperty(kAudioHardwarePropertyDevices,
|
|
|
|
&size,
|
|
|
|
deviceids);
|
|
|
|
if (status != noErr) {
|
2010-12-21 04:21:47 +01:00
|
|
|
g_set_error(error, osx_output_quark(), status,
|
2010-12-21 04:21:46 +01:00
|
|
|
"Unable to determine OS X audio device IDs: %s",
|
|
|
|
GetMacOSStatusCommentString(status));
|
|
|
|
ret = false;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* which audio device matches oo->device_name? */
|
|
|
|
for (i = 0; i < numdevices; i++) {
|
|
|
|
size = sizeof(name);
|
|
|
|
status = AudioDeviceGetProperty(deviceids[i], 0, false,
|
|
|
|
kAudioDevicePropertyDeviceName,
|
|
|
|
&size, name);
|
|
|
|
if (status != noErr) {
|
2010-12-21 04:21:47 +01:00
|
|
|
g_set_error(error, osx_output_quark(), status,
|
2010-12-21 04:21:46 +01:00
|
|
|
"Unable to determine OS X device name "
|
|
|
|
"(device %u): %s",
|
|
|
|
(unsigned int) deviceids[i],
|
|
|
|
GetMacOSStatusCommentString(status));
|
|
|
|
ret = false;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
if (strcmp(oo->device_name, name) == 0) {
|
|
|
|
g_debug("found matching device: ID=%u, name=%s",
|
|
|
|
(unsigned int) deviceids[i], name);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == numdevices) {
|
|
|
|
g_warning("Found no audio device with name '%s' "
|
|
|
|
"(will use default audio device)",
|
|
|
|
oo->device_name);
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = AudioUnitSetProperty(oo->au,
|
|
|
|
kAudioOutputUnitProperty_CurrentDevice,
|
|
|
|
kAudioUnitScope_Global,
|
|
|
|
0,
|
|
|
|
&(deviceids[i]),
|
|
|
|
sizeof(AudioDeviceID));
|
|
|
|
if (status != noErr) {
|
2010-12-21 04:21:47 +01:00
|
|
|
g_set_error(error, osx_output_quark(), status,
|
2010-12-21 04:21:46 +01:00
|
|
|
"Unable to set OS X audio output device: %s",
|
|
|
|
GetMacOSStatusCommentString(status));
|
|
|
|
ret = false;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
g_debug("set OS X audio output device ID=%u, name=%s",
|
|
|
|
(unsigned int) deviceids[i], name);
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (deviceids != NULL)
|
|
|
|
g_free(deviceids);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-12-24 15:55:35 +01:00
|
|
|
static OSStatus
|
|
|
|
osx_render(void *vdata,
|
|
|
|
G_GNUC_UNUSED AudioUnitRenderActionFlags *io_action_flags,
|
|
|
|
G_GNUC_UNUSED const AudioTimeStamp *in_timestamp,
|
|
|
|
G_GNUC_UNUSED UInt32 in_bus_number,
|
|
|
|
G_GNUC_UNUSED UInt32 in_number_frames,
|
|
|
|
AudioBufferList *buffer_list)
|
|
|
|
{
|
|
|
|
struct osx_output *od = (struct osx_output *) vdata;
|
|
|
|
AudioBuffer *buffer = &buffer_list->mBuffers[0];
|
|
|
|
size_t buffer_size = buffer->mDataByteSize;
|
|
|
|
|
2012-04-05 00:45:39 +02:00
|
|
|
assert(od->buffer != NULL);
|
2011-12-24 15:55:35 +01:00
|
|
|
|
2012-04-05 00:45:39 +02:00
|
|
|
g_mutex_lock(od->mutex);
|
2011-12-24 15:55:35 +01:00
|
|
|
|
2012-04-05 00:45:39 +02:00
|
|
|
size_t nbytes;
|
|
|
|
const void *src = fifo_buffer_read(od->buffer, &nbytes);
|
2011-12-24 15:55:35 +01:00
|
|
|
|
2012-04-05 00:45:39 +02:00
|
|
|
if (src != NULL) {
|
|
|
|
if (nbytes > buffer_size)
|
|
|
|
nbytes = buffer_size;
|
2011-12-24 15:55:35 +01:00
|
|
|
|
2012-04-05 00:45:39 +02:00
|
|
|
memcpy(buffer->mData, src, nbytes);
|
|
|
|
fifo_buffer_consume(od->buffer, nbytes);
|
|
|
|
} else
|
|
|
|
nbytes = 0;
|
2011-12-24 15:55:35 +01:00
|
|
|
|
|
|
|
g_cond_signal(od->condition);
|
|
|
|
g_mutex_unlock(od->mutex);
|
|
|
|
|
2012-10-02 17:18:41 +02:00
|
|
|
buffer->mDataByteSize = nbytes;
|
|
|
|
|
|
|
|
unsigned i;
|
|
|
|
for (i = 1; i < buffer_list->mNumberBuffers; ++i) {
|
|
|
|
buffer = &buffer_list->mBuffers[i];
|
|
|
|
buffer->mDataByteSize = 0;
|
|
|
|
}
|
2011-12-24 15:55:35 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-10-29 20:40:27 +01:00
|
|
|
static bool
|
2011-12-24 15:55:35 +01:00
|
|
|
osx_output_enable(struct audio_output *ao, GError **error_r)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2011-12-24 15:55:35 +01:00
|
|
|
struct osx_output *oo = (struct osx_output *)ao;
|
2005-03-16 05:46:41 +01:00
|
|
|
|
2011-12-24 15:55:35 +01:00
|
|
|
ComponentDescription desc;
|
2005-03-16 05:46:41 +01:00
|
|
|
desc.componentType = kAudioUnitType_Output;
|
2011-12-24 15:55:35 +01:00
|
|
|
desc.componentSubType = oo->component_subtype;
|
2005-03-16 05:46:41 +01:00
|
|
|
desc.componentManufacturer = kAudioUnitManufacturer_Apple;
|
|
|
|
desc.componentFlags = 0;
|
|
|
|
desc.componentFlagsMask = 0;
|
|
|
|
|
2011-12-24 15:55:35 +01:00
|
|
|
Component comp = FindNextComponent(NULL, &desc);
|
2006-07-20 18:02:40 +02:00
|
|
|
if (comp == 0) {
|
2011-12-24 15:55:35 +01:00
|
|
|
g_set_error(error_r, osx_output_quark(), 0,
|
2009-02-26 22:04:59 +01:00
|
|
|
"Error finding OS X component");
|
2008-10-29 20:40:27 +01:00
|
|
|
return false;
|
2005-03-14 05:30:32 +01:00
|
|
|
}
|
|
|
|
|
2011-12-24 15:55:35 +01:00
|
|
|
OSStatus status = OpenAComponent(comp, &oo->au);
|
2009-02-26 22:01:42 +01:00
|
|
|
if (status != noErr) {
|
2011-12-24 15:55:35 +01:00
|
|
|
g_set_error(error_r, osx_output_quark(), status,
|
2009-02-26 22:04:59 +01:00
|
|
|
"Unable to open OS X component: %s",
|
|
|
|
GetMacOSStatusCommentString(status));
|
2008-10-29 20:40:27 +01:00
|
|
|
return false;
|
2005-03-14 05:30:32 +01:00
|
|
|
}
|
|
|
|
|
2011-12-24 15:55:35 +01:00
|
|
|
if (!osx_output_set_device(oo, error_r)) {
|
|
|
|
CloseComponent(oo->au);
|
2008-10-29 20:40:27 +01:00
|
|
|
return false;
|
2005-03-16 05:46:41 +01:00
|
|
|
}
|
|
|
|
|
2011-12-24 15:55:35 +01:00
|
|
|
AURenderCallbackStruct callback;
|
2005-03-16 05:46:41 +01:00
|
|
|
callback.inputProc = osx_render;
|
2011-12-24 15:55:35 +01:00
|
|
|
callback.inputProcRefCon = oo;
|
2005-03-16 05:46:41 +01:00
|
|
|
|
2011-12-24 15:55:35 +01:00
|
|
|
ComponentResult result =
|
|
|
|
AudioUnitSetProperty(oo->au,
|
|
|
|
kAudioUnitProperty_SetRenderCallback,
|
|
|
|
kAudioUnitScope_Input, 0,
|
|
|
|
&callback, sizeof(callback));
|
2009-02-26 22:01:42 +01:00
|
|
|
if (result != noErr) {
|
2011-12-26 17:36:59 +01:00
|
|
|
CloseComponent(oo->au);
|
2011-12-24 15:55:35 +01:00
|
|
|
g_set_error(error_r, osx_output_quark(), result,
|
2009-02-26 22:04:59 +01:00
|
|
|
"unable to set callback for OS X audio unit");
|
2008-10-29 20:40:27 +01:00
|
|
|
return false;
|
2005-03-16 05:46:41 +01:00
|
|
|
}
|
2005-03-14 05:30:32 +01:00
|
|
|
|
2011-12-24 15:55:35 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
osx_output_disable(struct audio_output *ao)
|
|
|
|
{
|
|
|
|
struct osx_output *oo = (struct osx_output *)ao;
|
|
|
|
|
|
|
|
CloseComponent(oo->au);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
osx_output_cancel(struct audio_output *ao)
|
|
|
|
{
|
|
|
|
struct osx_output *od = (struct osx_output *)ao;
|
|
|
|
|
|
|
|
g_mutex_lock(od->mutex);
|
2012-04-05 00:45:39 +02:00
|
|
|
fifo_buffer_clear(od->buffer);
|
2011-12-24 15:55:35 +01:00
|
|
|
g_mutex_unlock(od->mutex);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
osx_output_close(struct audio_output *ao)
|
|
|
|
{
|
|
|
|
struct osx_output *od = (struct osx_output *)ao;
|
|
|
|
|
|
|
|
AudioOutputUnitStop(od->au);
|
|
|
|
AudioUnitUninitialize(od->au);
|
2012-04-05 00:45:39 +02:00
|
|
|
|
|
|
|
fifo_buffer_free(od->buffer);
|
2011-12-24 15:55:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool
|
|
|
|
osx_output_open(struct audio_output *ao, struct audio_format *audio_format, GError **error)
|
|
|
|
{
|
|
|
|
struct osx_output *od = (struct osx_output *)ao;
|
|
|
|
|
|
|
|
AudioStreamBasicDescription stream_description;
|
2009-02-26 21:03:06 +01:00
|
|
|
stream_description.mSampleRate = audio_format->sample_rate;
|
|
|
|
stream_description.mFormatID = kAudioFormatLinearPCM;
|
|
|
|
stream_description.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger;
|
2009-11-10 17:11:34 +01:00
|
|
|
|
|
|
|
switch (audio_format->format) {
|
|
|
|
case SAMPLE_FORMAT_S8:
|
|
|
|
stream_description.mBitsPerChannel = 8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SAMPLE_FORMAT_S16:
|
|
|
|
stream_description.mBitsPerChannel = 16;
|
|
|
|
break;
|
|
|
|
|
2011-12-24 18:18:42 +01:00
|
|
|
case SAMPLE_FORMAT_S32:
|
|
|
|
stream_description.mBitsPerChannel = 32;
|
|
|
|
break;
|
|
|
|
|
2009-11-10 17:11:34 +01:00
|
|
|
default:
|
2011-12-24 18:18:42 +01:00
|
|
|
audio_format->format = SAMPLE_FORMAT_S32;
|
|
|
|
stream_description.mBitsPerChannel = 32;
|
2009-11-10 17:11:34 +01:00
|
|
|
break;
|
|
|
|
}
|
2005-03-16 05:46:41 +01:00
|
|
|
|
2011-01-07 17:15:37 +01:00
|
|
|
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
|
|
|
stream_description.mFormatFlags |= kLinearPCMFormatFlagIsBigEndian;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
stream_description.mBytesPerPacket =
|
|
|
|
audio_format_frame_size(audio_format);
|
|
|
|
stream_description.mFramesPerPacket = 1;
|
|
|
|
stream_description.mBytesPerFrame = stream_description.mBytesPerPacket;
|
|
|
|
stream_description.mChannelsPerFrame = audio_format->channels;
|
|
|
|
|
2011-12-24 15:55:35 +01:00
|
|
|
ComponentResult result =
|
|
|
|
AudioUnitSetProperty(od->au, kAudioUnitProperty_StreamFormat,
|
|
|
|
kAudioUnitScope_Input, 0,
|
|
|
|
&stream_description,
|
|
|
|
sizeof(stream_description));
|
2009-02-26 22:01:42 +01:00
|
|
|
if (result != noErr) {
|
2010-12-21 04:21:47 +01:00
|
|
|
g_set_error(error, osx_output_quark(), result,
|
2009-02-26 22:04:59 +01:00
|
|
|
"Unable to set format on OS X device");
|
2008-10-29 20:40:27 +01:00
|
|
|
return false;
|
2005-03-16 05:46:41 +01:00
|
|
|
}
|
|
|
|
|
2011-12-24 15:55:35 +01:00
|
|
|
OSStatus status = AudioUnitInitialize(od->au);
|
|
|
|
if (status != noErr) {
|
|
|
|
g_set_error(error, osx_output_quark(), status,
|
|
|
|
"Unable to initialize OS X audio unit: %s",
|
|
|
|
GetMacOSStatusCommentString(status));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-03-17 04:28:05 +01:00
|
|
|
/* create a buffer of 1s */
|
2012-04-05 00:45:39 +02:00
|
|
|
od->buffer = fifo_buffer_new(audio_format->sample_rate *
|
|
|
|
audio_format_frame_size(audio_format));
|
2005-03-13 20:23:09 +01:00
|
|
|
|
2009-02-26 22:01:42 +01:00
|
|
|
status = AudioOutputUnitStart(od->au);
|
|
|
|
if (status != 0) {
|
2011-12-24 15:55:35 +01:00
|
|
|
AudioUnitUninitialize(od->au);
|
2010-12-21 04:21:47 +01:00
|
|
|
g_set_error(error, osx_output_quark(), status,
|
2009-02-26 22:04:59 +01:00
|
|
|
"unable to start audio output: %s",
|
|
|
|
GetMacOSStatusCommentString(status));
|
2009-02-26 21:40:22 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-10-29 20:40:27 +01:00
|
|
|
return true;
|
2005-03-13 20:23:09 +01:00
|
|
|
}
|
|
|
|
|
2009-02-23 09:29:56 +01:00
|
|
|
static size_t
|
2011-09-16 23:31:48 +02:00
|
|
|
osx_output_play(struct audio_output *ao, const void *chunk, size_t size,
|
2009-02-26 22:04:59 +01:00
|
|
|
G_GNUC_UNUSED GError **error)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2011-09-16 23:31:48 +02:00
|
|
|
struct osx_output *od = (struct osx_output *)ao;
|
2005-03-14 05:30:32 +01:00
|
|
|
|
2008-12-28 22:09:42 +01:00
|
|
|
g_mutex_lock(od->mutex);
|
2005-03-14 05:30:32 +01:00
|
|
|
|
2012-04-05 00:45:39 +02:00
|
|
|
void *dest;
|
|
|
|
size_t max_length;
|
2005-03-24 12:45:39 +01:00
|
|
|
|
2012-04-05 00:45:39 +02:00
|
|
|
while (true) {
|
|
|
|
dest = fifo_buffer_write(od->buffer, &max_length);
|
|
|
|
if (dest != NULL)
|
|
|
|
break;
|
2005-03-14 05:30:32 +01:00
|
|
|
|
2012-04-05 00:45:39 +02:00
|
|
|
/* wait for some free space in the buffer */
|
|
|
|
g_cond_wait(od->condition, od->mutex);
|
|
|
|
}
|
2005-03-16 05:46:41 +01:00
|
|
|
|
2012-04-05 00:45:39 +02:00
|
|
|
if (size > max_length)
|
|
|
|
size = max_length;
|
2005-03-16 05:46:41 +01:00
|
|
|
|
2012-04-05 00:45:39 +02:00
|
|
|
memcpy(dest, chunk, size);
|
|
|
|
fifo_buffer_append(od->buffer, size);
|
2009-02-10 20:57:21 +01:00
|
|
|
|
2008-12-28 22:09:42 +01:00
|
|
|
g_mutex_unlock(od->mutex);
|
2005-03-13 20:23:09 +01:00
|
|
|
|
2012-04-05 00:45:39 +02:00
|
|
|
return size;
|
2005-03-13 20:23:09 +01:00
|
|
|
}
|
|
|
|
|
2011-09-17 20:04:18 +02:00
|
|
|
const struct audio_output_plugin osx_output_plugin = {
|
2008-09-29 15:55:17 +02:00
|
|
|
.name = "osx",
|
2009-02-26 21:03:06 +01:00
|
|
|
.test_default_device = osx_output_test_default_device,
|
|
|
|
.init = osx_output_init,
|
|
|
|
.finish = osx_output_finish,
|
2011-12-24 15:55:35 +01:00
|
|
|
.enable = osx_output_enable,
|
|
|
|
.disable = osx_output_disable,
|
2009-02-26 21:03:06 +01:00
|
|
|
.open = osx_output_open,
|
|
|
|
.close = osx_output_close,
|
|
|
|
.play = osx_output_play,
|
|
|
|
.cancel = osx_output_cancel,
|
2005-03-13 20:23:09 +01:00
|
|
|
};
|