output/osx: convert to C++
This commit is contained in:
parent
3dd8beb380
commit
84eb95466b
@ -864,7 +864,8 @@ endif
|
|||||||
|
|
||||||
if HAVE_OSX
|
if HAVE_OSX
|
||||||
liboutput_plugins_a_SOURCES += \
|
liboutput_plugins_a_SOURCES += \
|
||||||
src/output/osx_output_plugin.c src/output/osx_output_plugin.h
|
src/output/OSXOutputPlugin.cxx \
|
||||||
|
src/output/OSXOutputPlugin.hxx
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if HAVE_PULSE
|
if HAVE_PULSE
|
||||||
|
@ -30,7 +30,7 @@
|
|||||||
#include "output/null_output_plugin.h"
|
#include "output/null_output_plugin.h"
|
||||||
#include "output/openal_output_plugin.h"
|
#include "output/openal_output_plugin.h"
|
||||||
#include "output/OssOutputPlugin.hxx"
|
#include "output/OssOutputPlugin.hxx"
|
||||||
#include "output/osx_output_plugin.h"
|
#include "output/OSXOutputPlugin.hxx"
|
||||||
#include "output/pipe_output_plugin.h"
|
#include "output/pipe_output_plugin.h"
|
||||||
#include "output/pulse_output_plugin.h"
|
#include "output/pulse_output_plugin.h"
|
||||||
#include "output/recorder_output_plugin.h"
|
#include "output/recorder_output_plugin.h"
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2003-2012 The Music Player Daemon Project
|
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
||||||
* http://www.musicpd.org
|
* http://www.musicpd.org
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -18,9 +18,11 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "osx_output_plugin.h"
|
#include "OSXOutputPlugin.hxx"
|
||||||
#include "output_api.h"
|
#include "output_api.h"
|
||||||
#include "util/fifo_buffer.h"
|
#include "util/fifo_buffer.h"
|
||||||
|
#include "thread/Mutex.hxx"
|
||||||
|
#include "thread/Cond.hxx"
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <CoreAudio/AudioHardware.h>
|
#include <CoreAudio/AudioHardware.h>
|
||||||
@ -30,7 +32,7 @@
|
|||||||
#undef G_LOG_DOMAIN
|
#undef G_LOG_DOMAIN
|
||||||
#define G_LOG_DOMAIN "osx"
|
#define G_LOG_DOMAIN "osx"
|
||||||
|
|
||||||
struct osx_output {
|
struct OSXOutput {
|
||||||
struct audio_output base;
|
struct audio_output base;
|
||||||
|
|
||||||
/* configuration settings */
|
/* configuration settings */
|
||||||
@ -39,8 +41,8 @@ struct osx_output {
|
|||||||
const char *device_name;
|
const char *device_name;
|
||||||
|
|
||||||
AudioUnit au;
|
AudioUnit au;
|
||||||
GMutex *mutex;
|
Mutex mutex;
|
||||||
GCond *condition;
|
Cond condition;
|
||||||
|
|
||||||
struct fifo_buffer *buffer;
|
struct fifo_buffer *buffer;
|
||||||
};
|
};
|
||||||
@ -63,7 +65,7 @@ osx_output_test_default_device(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
osx_output_configure(struct osx_output *oo, const struct config_param *param)
|
osx_output_configure(OSXOutput *oo, const struct config_param *param)
|
||||||
{
|
{
|
||||||
const char *device = config_get_block_string(param, "device", NULL);
|
const char *device = config_get_block_string(param, "device", NULL);
|
||||||
|
|
||||||
@ -85,15 +87,13 @@ osx_output_configure(struct osx_output *oo, const struct config_param *param)
|
|||||||
static struct audio_output *
|
static struct audio_output *
|
||||||
osx_output_init(const struct config_param *param, GError **error_r)
|
osx_output_init(const struct config_param *param, GError **error_r)
|
||||||
{
|
{
|
||||||
struct osx_output *oo = g_new(struct osx_output, 1);
|
OSXOutput *oo = new OSXOutput();
|
||||||
if (!ao_base_init(&oo->base, &osx_output_plugin, param, error_r)) {
|
if (!ao_base_init(&oo->base, &osx_output_plugin, param, error_r)) {
|
||||||
g_free(oo);
|
delete oo;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
osx_output_configure(oo, param);
|
osx_output_configure(oo, param);
|
||||||
oo->mutex = g_mutex_new();
|
|
||||||
oo->condition = g_cond_new();
|
|
||||||
|
|
||||||
return &oo->base;
|
return &oo->base;
|
||||||
}
|
}
|
||||||
@ -101,15 +101,13 @@ osx_output_init(const struct config_param *param, GError **error_r)
|
|||||||
static void
|
static void
|
||||||
osx_output_finish(struct audio_output *ao)
|
osx_output_finish(struct audio_output *ao)
|
||||||
{
|
{
|
||||||
struct osx_output *od = (struct osx_output *)ao;
|
OSXOutput *oo = (OSXOutput *)ao;
|
||||||
|
|
||||||
g_mutex_free(od->mutex);
|
delete oo;
|
||||||
g_cond_free(od->condition);
|
|
||||||
g_free(od);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
osx_output_set_device(struct osx_output *oo, GError **error)
|
osx_output_set_device(OSXOutput *oo, GError **error)
|
||||||
{
|
{
|
||||||
bool ret = true;
|
bool ret = true;
|
||||||
OSStatus status;
|
OSStatus status;
|
||||||
@ -135,7 +133,7 @@ osx_output_set_device(struct osx_output *oo, GError **error)
|
|||||||
|
|
||||||
/* what are the available audio device IDs? */
|
/* what are the available audio device IDs? */
|
||||||
numdevices = size / sizeof(AudioDeviceID);
|
numdevices = size / sizeof(AudioDeviceID);
|
||||||
deviceids = g_malloc(size);
|
deviceids = new AudioDeviceID[numdevices];
|
||||||
status = AudioHardwareGetProperty(kAudioHardwarePropertyDevices,
|
status = AudioHardwareGetProperty(kAudioHardwarePropertyDevices,
|
||||||
&size,
|
&size,
|
||||||
deviceids);
|
deviceids);
|
||||||
@ -192,8 +190,7 @@ osx_output_set_device(struct osx_output *oo, GError **error)
|
|||||||
(unsigned int) deviceids[i], name);
|
(unsigned int) deviceids[i], name);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (deviceids != NULL)
|
delete[] deviceids;
|
||||||
g_free(deviceids);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,13 +202,13 @@ osx_render(void *vdata,
|
|||||||
G_GNUC_UNUSED UInt32 in_number_frames,
|
G_GNUC_UNUSED UInt32 in_number_frames,
|
||||||
AudioBufferList *buffer_list)
|
AudioBufferList *buffer_list)
|
||||||
{
|
{
|
||||||
struct osx_output *od = (struct osx_output *) vdata;
|
OSXOutput *od = (OSXOutput *) vdata;
|
||||||
AudioBuffer *buffer = &buffer_list->mBuffers[0];
|
AudioBuffer *buffer = &buffer_list->mBuffers[0];
|
||||||
size_t buffer_size = buffer->mDataByteSize;
|
size_t buffer_size = buffer->mDataByteSize;
|
||||||
|
|
||||||
assert(od->buffer != NULL);
|
assert(od->buffer != NULL);
|
||||||
|
|
||||||
g_mutex_lock(od->mutex);
|
od->mutex.lock();
|
||||||
|
|
||||||
size_t nbytes;
|
size_t nbytes;
|
||||||
const void *src = fifo_buffer_read(od->buffer, &nbytes);
|
const void *src = fifo_buffer_read(od->buffer, &nbytes);
|
||||||
@ -225,8 +222,8 @@ osx_render(void *vdata,
|
|||||||
} else
|
} else
|
||||||
nbytes = 0;
|
nbytes = 0;
|
||||||
|
|
||||||
g_cond_signal(od->condition);
|
od->condition.signal();
|
||||||
g_mutex_unlock(od->mutex);
|
od->mutex.unlock();
|
||||||
|
|
||||||
buffer->mDataByteSize = nbytes;
|
buffer->mDataByteSize = nbytes;
|
||||||
|
|
||||||
@ -242,7 +239,7 @@ osx_render(void *vdata,
|
|||||||
static bool
|
static bool
|
||||||
osx_output_enable(struct audio_output *ao, GError **error_r)
|
osx_output_enable(struct audio_output *ao, GError **error_r)
|
||||||
{
|
{
|
||||||
struct osx_output *oo = (struct osx_output *)ao;
|
OSXOutput *oo = (OSXOutput *)ao;
|
||||||
|
|
||||||
ComponentDescription desc;
|
ComponentDescription desc;
|
||||||
desc.componentType = kAudioUnitType_Output;
|
desc.componentType = kAudioUnitType_Output;
|
||||||
@ -293,7 +290,7 @@ osx_output_enable(struct audio_output *ao, GError **error_r)
|
|||||||
static void
|
static void
|
||||||
osx_output_disable(struct audio_output *ao)
|
osx_output_disable(struct audio_output *ao)
|
||||||
{
|
{
|
||||||
struct osx_output *oo = (struct osx_output *)ao;
|
OSXOutput *oo = (OSXOutput *)ao;
|
||||||
|
|
||||||
CloseComponent(oo->au);
|
CloseComponent(oo->au);
|
||||||
}
|
}
|
||||||
@ -301,17 +298,16 @@ osx_output_disable(struct audio_output *ao)
|
|||||||
static void
|
static void
|
||||||
osx_output_cancel(struct audio_output *ao)
|
osx_output_cancel(struct audio_output *ao)
|
||||||
{
|
{
|
||||||
struct osx_output *od = (struct osx_output *)ao;
|
OSXOutput *od = (OSXOutput *)ao;
|
||||||
|
|
||||||
g_mutex_lock(od->mutex);
|
const ScopeLock protect(od->mutex);
|
||||||
fifo_buffer_clear(od->buffer);
|
fifo_buffer_clear(od->buffer);
|
||||||
g_mutex_unlock(od->mutex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
osx_output_close(struct audio_output *ao)
|
osx_output_close(struct audio_output *ao)
|
||||||
{
|
{
|
||||||
struct osx_output *od = (struct osx_output *)ao;
|
OSXOutput *od = (OSXOutput *)ao;
|
||||||
|
|
||||||
AudioOutputUnitStop(od->au);
|
AudioOutputUnitStop(od->au);
|
||||||
AudioUnitUninitialize(od->au);
|
AudioUnitUninitialize(od->au);
|
||||||
@ -322,7 +318,7 @@ osx_output_close(struct audio_output *ao)
|
|||||||
static bool
|
static bool
|
||||||
osx_output_open(struct audio_output *ao, struct audio_format *audio_format, GError **error)
|
osx_output_open(struct audio_output *ao, struct audio_format *audio_format, GError **error)
|
||||||
{
|
{
|
||||||
struct osx_output *od = (struct osx_output *)ao;
|
OSXOutput *od = (OSXOutput *)ao;
|
||||||
|
|
||||||
AudioStreamBasicDescription stream_description;
|
AudioStreamBasicDescription stream_description;
|
||||||
stream_description.mSampleRate = audio_format->sample_rate;
|
stream_description.mSampleRate = audio_format->sample_rate;
|
||||||
@ -397,9 +393,9 @@ static size_t
|
|||||||
osx_output_play(struct audio_output *ao, const void *chunk, size_t size,
|
osx_output_play(struct audio_output *ao, const void *chunk, size_t size,
|
||||||
G_GNUC_UNUSED GError **error)
|
G_GNUC_UNUSED GError **error)
|
||||||
{
|
{
|
||||||
struct osx_output *od = (struct osx_output *)ao;
|
OSXOutput *od = (OSXOutput *)ao;
|
||||||
|
|
||||||
g_mutex_lock(od->mutex);
|
const ScopeLock protect(od->mutex);
|
||||||
|
|
||||||
void *dest;
|
void *dest;
|
||||||
size_t max_length;
|
size_t max_length;
|
||||||
@ -410,7 +406,7 @@ osx_output_play(struct audio_output *ao, const void *chunk, size_t size,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
/* wait for some free space in the buffer */
|
/* wait for some free space in the buffer */
|
||||||
g_cond_wait(od->condition, od->mutex);
|
od->condition.wait(od->mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (size > max_length)
|
if (size > max_length)
|
||||||
@ -419,20 +415,23 @@ osx_output_play(struct audio_output *ao, const void *chunk, size_t size,
|
|||||||
memcpy(dest, chunk, size);
|
memcpy(dest, chunk, size);
|
||||||
fifo_buffer_append(od->buffer, size);
|
fifo_buffer_append(od->buffer, size);
|
||||||
|
|
||||||
g_mutex_unlock(od->mutex);
|
|
||||||
|
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct audio_output_plugin osx_output_plugin = {
|
const struct audio_output_plugin osx_output_plugin = {
|
||||||
.name = "osx",
|
"osx",
|
||||||
.test_default_device = osx_output_test_default_device,
|
osx_output_test_default_device,
|
||||||
.init = osx_output_init,
|
osx_output_init,
|
||||||
.finish = osx_output_finish,
|
osx_output_finish,
|
||||||
.enable = osx_output_enable,
|
osx_output_enable,
|
||||||
.disable = osx_output_disable,
|
osx_output_disable,
|
||||||
.open = osx_output_open,
|
osx_output_open,
|
||||||
.close = osx_output_close,
|
osx_output_close,
|
||||||
.play = osx_output_play,
|
nullptr,
|
||||||
.cancel = osx_output_cancel,
|
nullptr,
|
||||||
|
osx_output_play,
|
||||||
|
nullptr,
|
||||||
|
osx_output_cancel,
|
||||||
|
nullptr,
|
||||||
|
nullptr,
|
||||||
};
|
};
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2003-2011 The Music Player Daemon Project
|
* Copyright (C) 2003-2013 The Music Player Daemon Project
|
||||||
* http://www.musicpd.org
|
* http://www.musicpd.org
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
@ -17,8 +17,8 @@
|
|||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef MPD_OSX_OUTPUT_PLUGIN_H
|
#ifndef MPD_OSX_OUTPUT_PLUGIN_HXX
|
||||||
#define MPD_OSX_OUTPUT_PLUGIN_H
|
#define MPD_OSX_OUTPUT_PLUGIN_HXX
|
||||||
|
|
||||||
extern const struct audio_output_plugin osx_output_plugin;
|
extern const struct audio_output_plugin osx_output_plugin;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user