Commit 750b2ad6 authored by Max Kellermann's avatar Max Kellermann

output/openal: convert to C++

parent 86c276f5
...@@ -844,7 +844,7 @@ endif ...@@ -844,7 +844,7 @@ endif
if HAVE_OPENAL if HAVE_OPENAL
liboutput_plugins_a_SOURCES += \ liboutput_plugins_a_SOURCES += \
src/output/openal_output_plugin.c src/output/openal_output_plugin.h src/output/OpenALOutputPlugin.cxx src/output/OpenALOutputPlugin.hxx
endif endif
if HAVE_OSX if HAVE_OSX
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
#include "output/HttpdOutputPlugin.hxx" #include "output/HttpdOutputPlugin.hxx"
#include "output/JackOutputPlugin.hxx" #include "output/JackOutputPlugin.hxx"
#include "output/NullOutputPlugin.hxx" #include "output/NullOutputPlugin.hxx"
#include "output/openal_output_plugin.h" #include "output/OpenALOutputPlugin.hxx"
#include "output/OssOutputPlugin.hxx" #include "output/OssOutputPlugin.hxx"
#include "output/OSXOutputPlugin.hxx" #include "output/OSXOutputPlugin.hxx"
#include "output/PipeOutputPlugin.hxx" #include "output/PipeOutputPlugin.hxx"
......
/* /*
* 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
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
*/ */
#include "config.h" #include "config.h"
#include "openal_output_plugin.h" #include "OpenALOutputPlugin.hxx"
#include "output_api.h" #include "output_api.h"
#include <glib.h> #include <glib.h>
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
/* should be enough for buffer size = 2048 */ /* should be enough for buffer size = 2048 */
#define NUM_BUFFERS 16 #define NUM_BUFFERS 16
struct openal_data { struct OpenALOutput {
struct audio_output base; struct audio_output base;
const char *device_name; const char *device_name;
...@@ -48,6 +48,15 @@ struct openal_data { ...@@ -48,6 +48,15 @@ struct openal_data {
ALuint source; ALuint source;
ALenum format; ALenum format;
ALuint frequency; ALuint frequency;
bool Initialize(const config_param *param, GError **error_r) {
return ao_base_init(&base, &openal_output_plugin, param,
error_r);
}
void Deinitialize() {
ao_base_finish(&base);
}
}; };
static inline GQuark static inline GQuark
...@@ -83,7 +92,7 @@ openal_audio_format(struct audio_format *audio_format) ...@@ -83,7 +92,7 @@ openal_audio_format(struct audio_format *audio_format)
G_GNUC_PURE G_GNUC_PURE
static inline ALint static inline ALint
openal_get_source_i(const struct openal_data *od, ALenum param) openal_get_source_i(const OpenALOutput *od, ALenum param)
{ {
ALint value; ALint value;
alGetSourcei(od->source, param, &value); alGetSourcei(od->source, param, &value);
...@@ -92,34 +101,34 @@ openal_get_source_i(const struct openal_data *od, ALenum param) ...@@ -92,34 +101,34 @@ openal_get_source_i(const struct openal_data *od, ALenum param)
G_GNUC_PURE G_GNUC_PURE
static inline bool static inline bool
openal_has_processed(const struct openal_data *od) openal_has_processed(const OpenALOutput *od)
{ {
return openal_get_source_i(od, AL_BUFFERS_PROCESSED) > 0; return openal_get_source_i(od, AL_BUFFERS_PROCESSED) > 0;
} }
G_GNUC_PURE G_GNUC_PURE
static inline ALint static inline ALint
openal_is_playing(const struct openal_data *od) openal_is_playing(const OpenALOutput *od)
{ {
return openal_get_source_i(od, AL_SOURCE_STATE) == AL_PLAYING; return openal_get_source_i(od, AL_SOURCE_STATE) == AL_PLAYING;
} }
static bool static bool
openal_setup_context(struct openal_data *od, openal_setup_context(OpenALOutput *od,
GError **error) GError **error)
{ {
od->device = alcOpenDevice(od->device_name); od->device = alcOpenDevice(od->device_name);
if (od->device == NULL) { if (od->device == nullptr) {
g_set_error(error, openal_output_quark(), 0, g_set_error(error, openal_output_quark(), 0,
"Error opening OpenAL device \"%s\"\n", "Error opening OpenAL device \"%s\"\n",
od->device_name); od->device_name);
return false; return false;
} }
od->context = alcCreateContext(od->device, NULL); od->context = alcCreateContext(od->device, nullptr);
if (od->context == NULL) { if (od->context == nullptr) {
g_set_error(error, openal_output_quark(), 0, g_set_error(error, openal_output_quark(), 0,
"Error creating context for \"%s\"\n", "Error creating context for \"%s\"\n",
od->device_name); od->device_name);
...@@ -131,19 +140,18 @@ openal_setup_context(struct openal_data *od, ...@@ -131,19 +140,18 @@ openal_setup_context(struct openal_data *od,
} }
static struct audio_output * static struct audio_output *
openal_init(const struct config_param *param, GError **error_r) openal_init(const config_param *param, GError **error_r)
{ {
const char *device_name = config_get_block_string(param, "device", NULL); const char *device_name = config_get_block_string(param, "device", nullptr);
struct openal_data *od;
if (device_name == NULL) { if (device_name == nullptr) {
device_name = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER); device_name = alcGetString(nullptr, ALC_DEFAULT_DEVICE_SPECIFIER);
} }
od = g_new(struct openal_data, 1); OpenALOutput *od = new OpenALOutput();
if (!ao_base_init(&od->base, &openal_output_plugin, param, error_r)) { if (!od->Initialize(param, error_r)) {
g_free(od); delete od;
return NULL; return nullptr;
} }
od->device_name = device_name; od->device_name = device_name;
...@@ -154,17 +162,17 @@ openal_init(const struct config_param *param, GError **error_r) ...@@ -154,17 +162,17 @@ openal_init(const struct config_param *param, GError **error_r)
static void static void
openal_finish(struct audio_output *ao) openal_finish(struct audio_output *ao)
{ {
struct openal_data *od = (struct openal_data *)ao; OpenALOutput *od = (OpenALOutput *)ao;
ao_base_finish(&od->base); od->Deinitialize();
g_free(od); delete od;
} }
static bool static bool
openal_open(struct audio_output *ao, struct audio_format *audio_format, openal_open(struct audio_output *ao, struct audio_format *audio_format,
GError **error) GError **error)
{ {
struct openal_data *od = (struct openal_data *)ao; OpenALOutput *od = (OpenALOutput *)ao;
od->format = openal_audio_format(audio_format); od->format = openal_audio_format(audio_format);
...@@ -199,7 +207,7 @@ openal_open(struct audio_output *ao, struct audio_format *audio_format, ...@@ -199,7 +207,7 @@ openal_open(struct audio_output *ao, struct audio_format *audio_format,
static void static void
openal_close(struct audio_output *ao) openal_close(struct audio_output *ao)
{ {
struct openal_data *od = (struct openal_data *)ao; OpenALOutput *od = (OpenALOutput *)ao;
alcMakeContextCurrent(od->context); alcMakeContextCurrent(od->context);
alDeleteSources(1, &od->source); alDeleteSources(1, &od->source);
...@@ -211,7 +219,7 @@ openal_close(struct audio_output *ao) ...@@ -211,7 +219,7 @@ openal_close(struct audio_output *ao)
static unsigned static unsigned
openal_delay(struct audio_output *ao) openal_delay(struct audio_output *ao)
{ {
struct openal_data *od = (struct openal_data *)ao; OpenALOutput *od = (OpenALOutput *)ao;
return od->filled < NUM_BUFFERS || openal_has_processed(od) return od->filled < NUM_BUFFERS || openal_has_processed(od)
? 0 ? 0
...@@ -225,7 +233,7 @@ static size_t ...@@ -225,7 +233,7 @@ static size_t
openal_play(struct audio_output *ao, const void *chunk, size_t size, openal_play(struct audio_output *ao, const void *chunk, size_t size,
G_GNUC_UNUSED GError **error) G_GNUC_UNUSED GError **error)
{ {
struct openal_data *od = (struct openal_data *)ao; OpenALOutput *od = (OpenALOutput *)ao;
ALuint buffer; ALuint buffer;
if (alcGetCurrentContext() != od->context) { if (alcGetCurrentContext() != od->context) {
...@@ -256,7 +264,7 @@ openal_play(struct audio_output *ao, const void *chunk, size_t size, ...@@ -256,7 +264,7 @@ openal_play(struct audio_output *ao, const void *chunk, size_t size,
static void static void
openal_cancel(struct audio_output *ao) openal_cancel(struct audio_output *ao)
{ {
struct openal_data *od = (struct openal_data *)ao; OpenALOutput *od = (OpenALOutput *)ao;
od->filled = 0; od->filled = 0;
alcMakeContextCurrent(od->context); alcMakeContextCurrent(od->context);
...@@ -268,12 +276,19 @@ openal_cancel(struct audio_output *ao) ...@@ -268,12 +276,19 @@ openal_cancel(struct audio_output *ao)
} }
const struct audio_output_plugin openal_output_plugin = { const struct audio_output_plugin openal_output_plugin = {
.name = "openal", "openal",
.init = openal_init, nullptr,
.finish = openal_finish, openal_init,
.open = openal_open, openal_finish,
.close = openal_close, nullptr,
.delay = openal_delay, nullptr,
.play = openal_play, openal_open,
.cancel = openal_cancel, openal_close,
openal_delay,
nullptr,
openal_play,
nullptr,
openal_cancel,
nullptr,
nullptr,
}; };
/* /*
* 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 @@ ...@@ -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_OPENAL_OUTPUT_PLUGIN_H #ifndef MPD_OPENAL_OUTPUT_PLUGIN_HXX
#define MPD_OPENAL_OUTPUT_PLUGIN_H #define MPD_OPENAL_OUTPUT_PLUGIN_HXX
extern const struct audio_output_plugin openal_output_plugin; extern const struct audio_output_plugin openal_output_plugin;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment