filter/convert: convert to C++

This commit is contained in:
Max Kellermann 2013-01-30 23:28:13 +01:00
parent 9ee52d85d7
commit f2a8d4d289
7 changed files with 75 additions and 71 deletions

View File

@ -59,9 +59,7 @@ mpd_headers = \
src/filter_internal.h \ src/filter_internal.h \
src/filter_plugin.h \ src/filter_plugin.h \
src/filter_registry.h \ src/filter_registry.h \
src/filter/autoconvert_filter_plugin.h \
src/filter/chain_filter_plugin.h \ src/filter/chain_filter_plugin.h \
src/filter/convert_filter_plugin.h \
src/filter/volume_filter_plugin.h \ src/filter/volume_filter_plugin.h \
src/command.h \ src/command.h \
src/conf.h \ src/conf.h \
@ -972,8 +970,10 @@ endif
libfilter_plugins_a_SOURCES = \ libfilter_plugins_a_SOURCES = \
src/filter/null_filter_plugin.c \ src/filter/null_filter_plugin.c \
src/filter/chain_filter_plugin.c \ src/filter/chain_filter_plugin.c \
src/filter/autoconvert_filter_plugin.c \ src/filter/AutoConvertFilterPlugin.cxx \
src/filter/convert_filter_plugin.c \ src/filter/AutoConvertFilterPlugin.hxx \
src/filter/ConvertFilterPlugin.cxx \
src/filter/ConvertFilterPlugin.hxx \
src/filter/route_filter_plugin.c \ src/filter/route_filter_plugin.c \
src/filter/normalize_filter_plugin.c \ src/filter/normalize_filter_plugin.c \
src/filter/ReplayGainFilterPlugin.cxx \ src/filter/ReplayGainFilterPlugin.cxx \

View File

@ -34,9 +34,9 @@ extern "C" {
#include "filter_plugin.h" #include "filter_plugin.h"
#include "filter_registry.h" #include "filter_registry.h"
#include "filter/chain_filter_plugin.h" #include "filter/chain_filter_plugin.h"
#include "filter/autoconvert_filter_plugin.h"
} }
#include "filter/AutoConvertFilterPlugin.hxx"
#include "filter/ReplayGainFilterPlugin.hxx" #include "filter/ReplayGainFilterPlugin.hxx"
#include <glib.h> #include <glib.h>

View File

@ -25,10 +25,10 @@ extern "C" {
#include "output_internal.h" #include "output_internal.h"
#include "pcm_mix.h" #include "pcm_mix.h"
#include "filter_plugin.h" #include "filter_plugin.h"
#include "filter/convert_filter_plugin.h"
} }
#include "notify.hxx" #include "notify.hxx"
#include "filter/ConvertFilterPlugin.hxx"
#include "filter/ReplayGainFilterPlugin.hxx" #include "filter/ReplayGainFilterPlugin.hxx"
#include "PlayerControl.hxx" #include "PlayerControl.hxx"
#include "MusicPipe.hxx" #include "MusicPipe.hxx"

View File

@ -18,18 +18,16 @@
*/ */
#include "config.h" #include "config.h"
#include "filter/autoconvert_filter_plugin.h" #include "AutoConvertFilterPlugin.hxx"
#include "filter/convert_filter_plugin.h" #include "ConvertFilterPlugin.hxx"
#include "filter_plugin.h" #include "filter_plugin.h"
#include "filter_internal.h" #include "filter_internal.h"
#include "filter_registry.h" #include "filter_registry.h"
#include "audio_format.h" #include "audio_format.h"
#include <glib.h>
#include <assert.h> #include <assert.h>
struct autoconvert_filter { struct AutoConvertFilter {
struct filter base; struct filter base;
/** /**
@ -45,20 +43,27 @@ struct autoconvert_filter {
struct filter *filter; struct filter *filter;
/** /**
* A convert_filter, just in case conversion is needed. NULL * A convert_filter, just in case conversion is needed. nullptr
* if unused. * if unused.
*/ */
struct filter *convert; struct filter *convert;
AutoConvertFilter(const filter_plugin &plugin, struct filter *_filter)
:filter(_filter) {
filter_init(&base, &plugin);
}
~AutoConvertFilter() {
filter_free(filter);
}
}; };
static void static void
autoconvert_filter_finish(struct filter *_filter) autoconvert_filter_finish(struct filter *_filter)
{ {
struct autoconvert_filter *filter = AutoConvertFilter *filter = (AutoConvertFilter *)_filter;
(struct autoconvert_filter *)_filter;
filter_free(filter->filter); delete filter;
g_free(filter);
} }
static const struct audio_format * static const struct audio_format *
@ -66,8 +71,7 @@ autoconvert_filter_open(struct filter *_filter,
struct audio_format *in_audio_format, struct audio_format *in_audio_format,
GError **error_r) GError **error_r)
{ {
struct autoconvert_filter *filter = AutoConvertFilter *filter = (AutoConvertFilter *)_filter;
(struct autoconvert_filter *)_filter;
const struct audio_format *out_audio_format; const struct audio_format *out_audio_format;
assert(audio_format_valid(in_audio_format)); assert(audio_format_valid(in_audio_format));
@ -78,8 +82,8 @@ autoconvert_filter_open(struct filter *_filter,
out_audio_format = filter_open(filter->filter, out_audio_format = filter_open(filter->filter,
&filter->in_audio_format, error_r); &filter->in_audio_format, error_r);
if (out_audio_format == NULL) if (out_audio_format == nullptr)
return NULL; return nullptr;
/* need to convert? */ /* need to convert? */
@ -88,19 +92,19 @@ autoconvert_filter_open(struct filter *_filter,
struct audio_format audio_format2 = *in_audio_format; struct audio_format audio_format2 = *in_audio_format;
const struct audio_format *audio_format3; const struct audio_format *audio_format3;
filter->convert = filter_new(&convert_filter_plugin, NULL, filter->convert = filter_new(&convert_filter_plugin, nullptr,
error_r); error_r);
if (filter->convert == NULL) { if (filter->convert == nullptr) {
filter_close(filter->filter); filter_close(filter->filter);
return NULL; return nullptr;
} }
audio_format3 = filter_open(filter->convert, &audio_format2, audio_format3 = filter_open(filter->convert, &audio_format2,
error_r); error_r);
if (audio_format3 == NULL) { if (audio_format3 == nullptr) {
filter_free(filter->convert); filter_free(filter->convert);
filter_close(filter->filter); filter_close(filter->filter);
return NULL; return nullptr;
} }
assert(audio_format_equals(&audio_format2, in_audio_format)); assert(audio_format_equals(&audio_format2, in_audio_format));
@ -108,7 +112,7 @@ autoconvert_filter_open(struct filter *_filter,
convert_filter_set(filter->convert, &filter->in_audio_format); convert_filter_set(filter->convert, &filter->in_audio_format);
} else } else
/* no */ /* no */
filter->convert = NULL; filter->convert = nullptr;
return out_audio_format; return out_audio_format;
} }
@ -116,10 +120,10 @@ autoconvert_filter_open(struct filter *_filter,
static void static void
autoconvert_filter_close(struct filter *_filter) autoconvert_filter_close(struct filter *_filter)
{ {
struct autoconvert_filter *filter = AutoConvertFilter *filter =
(struct autoconvert_filter *)_filter; (AutoConvertFilter *)_filter;
if (filter->convert != NULL) { if (filter->convert != nullptr) {
filter_close(filter->convert); filter_close(filter->convert);
filter_free(filter->convert); filter_free(filter->convert);
} }
@ -132,14 +136,13 @@ autoconvert_filter_filter(struct filter *_filter, const void *src,
size_t src_size, size_t *dest_size_r, size_t src_size, size_t *dest_size_r,
GError **error_r) GError **error_r)
{ {
struct autoconvert_filter *filter = AutoConvertFilter *filter = (AutoConvertFilter *)_filter;
(struct autoconvert_filter *)_filter;
if (filter->convert != NULL) { if (filter->convert != nullptr) {
src = filter_filter(filter->convert, src, src_size, &src_size, src = filter_filter(filter->convert, src, src_size, &src_size,
error_r); error_r);
if (src == NULL) if (src == nullptr)
return NULL; return nullptr;
} }
return filter_filter(filter->filter, src, src_size, dest_size_r, return filter_filter(filter->filter, src, src_size, dest_size_r,
@ -147,21 +150,20 @@ autoconvert_filter_filter(struct filter *_filter, const void *src,
} }
static const struct filter_plugin autoconvert_filter_plugin = { static const struct filter_plugin autoconvert_filter_plugin = {
.name = "convert", "convert",
.finish = autoconvert_filter_finish, nullptr,
.open = autoconvert_filter_open, autoconvert_filter_finish,
.close = autoconvert_filter_close, autoconvert_filter_open,
.filter = autoconvert_filter_filter, autoconvert_filter_close,
autoconvert_filter_filter,
}; };
struct filter * struct filter *
autoconvert_filter_new(struct filter *_filter) autoconvert_filter_new(struct filter *_filter)
{ {
struct autoconvert_filter *filter = AutoConvertFilter *filter =
g_new(struct autoconvert_filter, 1); new AutoConvertFilter(autoconvert_filter_plugin,
_filter);
filter_init(&filter->base, &autoconvert_filter_plugin);
filter->filter = _filter;
return &filter->base; return &filter->base;
} }

View File

@ -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 AUTOCONVERT_FILTER_PLUGIN_H #ifndef MPD_AUTOCONVERT_FILTER_PLUGIN_HXX
#define AUTOCONVERT_FILTER_PLUGIN_H #define MPD_AUTOCONVERT_FILTER_PLUGIN_HXX
struct filter; struct filter;

View File

@ -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
@ -18,7 +18,7 @@
*/ */
#include "config.h" #include "config.h"
#include "filter/convert_filter_plugin.h" #include "ConvertFilterPlugin.hxx"
#include "filter_plugin.h" #include "filter_plugin.h"
#include "filter_internal.h" #include "filter_internal.h"
#include "filter_registry.h" #include "filter_registry.h"
@ -30,7 +30,7 @@
#include <assert.h> #include <assert.h>
#include <string.h> #include <string.h>
struct convert_filter { struct ConvertFilter {
struct filter base; struct filter base;
/** /**
@ -52,29 +52,31 @@ struct convert_filter {
struct audio_format out_audio_format; struct audio_format out_audio_format;
struct pcm_convert_state state; struct pcm_convert_state state;
ConvertFilter() {
filter_init(&base, &convert_filter_plugin);
}
}; };
static struct filter * static struct filter *
convert_filter_init(G_GNUC_UNUSED const struct config_param *param, convert_filter_init(gcc_unused const struct config_param *param,
G_GNUC_UNUSED GError **error_r) gcc_unused GError **error_r)
{ {
struct convert_filter *filter = g_new(struct convert_filter, 1); ConvertFilter *filter = new ConvertFilter();
filter_init(&filter->base, &convert_filter_plugin);
return &filter->base; return &filter->base;
} }
static void static void
convert_filter_finish(struct filter *filter) convert_filter_finish(struct filter *filter)
{ {
g_free(filter); delete filter;
} }
static const struct audio_format * static const struct audio_format *
convert_filter_open(struct filter *_filter, struct audio_format *audio_format, convert_filter_open(struct filter *_filter, struct audio_format *audio_format,
G_GNUC_UNUSED GError **error_r) gcc_unused GError **error_r)
{ {
struct convert_filter *filter = (struct convert_filter *)_filter; ConvertFilter *filter = (ConvertFilter *)_filter;
assert(audio_format_valid(audio_format)); assert(audio_format_valid(audio_format));
@ -87,7 +89,7 @@ convert_filter_open(struct filter *_filter, struct audio_format *audio_format,
static void static void
convert_filter_close(struct filter *_filter) convert_filter_close(struct filter *_filter)
{ {
struct convert_filter *filter = (struct convert_filter *)_filter; ConvertFilter *filter = (ConvertFilter *)_filter;
pcm_convert_deinit(&filter->state); pcm_convert_deinit(&filter->state);
@ -101,7 +103,7 @@ static const void *
convert_filter_filter(struct filter *_filter, const void *src, size_t src_size, convert_filter_filter(struct filter *_filter, const void *src, size_t src_size,
size_t *dest_size_r, GError **error_r) size_t *dest_size_r, GError **error_r)
{ {
struct convert_filter *filter = (struct convert_filter *)_filter; ConvertFilter *filter = (ConvertFilter *)_filter;
const void *dest; const void *dest;
if (audio_format_equals(&filter->in_audio_format, if (audio_format_equals(&filter->in_audio_format,
@ -122,19 +124,19 @@ convert_filter_filter(struct filter *_filter, const void *src, size_t src_size,
} }
const struct filter_plugin convert_filter_plugin = { const struct filter_plugin convert_filter_plugin = {
.name = "convert", "convert",
.init = convert_filter_init, convert_filter_init,
.finish = convert_filter_finish, convert_filter_finish,
.open = convert_filter_open, convert_filter_open,
.close = convert_filter_close, convert_filter_close,
.filter = convert_filter_filter, convert_filter_filter,
}; };
void void
convert_filter_set(struct filter *_filter, convert_filter_set(struct filter *_filter,
const struct audio_format *out_audio_format) const struct audio_format *out_audio_format)
{ {
struct convert_filter *filter = (struct convert_filter *)_filter; ConvertFilter *filter = (ConvertFilter *)_filter;
assert(filter != NULL); assert(filter != NULL);
assert(audio_format_valid(&filter->in_audio_format)); assert(audio_format_valid(&filter->in_audio_format));

View File

@ -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 CONVERT_FILTER_PLUGIN_H #ifndef MPD_CONVERT_FILTER_PLUGIN_HXX
#define CONVERT_FILTER_PLUGIN_H #define MPD_CONVERT_FILTER_PLUGIN_HXX
struct filter; struct filter;
struct audio_format; struct audio_format;
@ -31,6 +31,6 @@ struct audio_format;
*/ */
void void
convert_filter_set(struct filter *filter, convert_filter_set(struct filter *filter,
const struct audio_format *out_audio_format); const audio_format *out_audio_format);
#endif #endif