diff options
author | Max Kellermann <max@duempel.org> | 2013-01-30 23:28:13 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-01-30 23:28:13 +0100 |
commit | f2a8d4d2891a95a5432cd19250025c5291463738 (patch) | |
tree | 9bbb087832bd4ea859786d050891d5f389afdad3 /src | |
parent | 9ee52d85d7cbff6c70f07503aa4698cbc6fbc00e (diff) | |
download | mpd-f2a8d4d2891a95a5432cd19250025c5291463738.tar.gz mpd-f2a8d4d2891a95a5432cd19250025c5291463738.tar.xz mpd-f2a8d4d2891a95a5432cd19250025c5291463738.zip |
filter/convert: convert to C++
Diffstat (limited to 'src')
-rw-r--r-- | src/OutputInit.cxx | 2 | ||||
-rw-r--r-- | src/OutputThread.cxx | 2 | ||||
-rw-r--r-- | src/filter/AutoConvertFilterPlugin.cxx (renamed from src/filter/autoconvert_filter_plugin.c) | 78 | ||||
-rw-r--r-- | src/filter/AutoConvertFilterPlugin.hxx (renamed from src/filter/autoconvert_filter_plugin.h) | 6 | ||||
-rw-r--r-- | src/filter/ConvertFilterPlugin.cxx (renamed from src/filter/convert_filter_plugin.c) | 42 | ||||
-rw-r--r-- | src/filter/ConvertFilterPlugin.hxx (renamed from src/filter/convert_filter_plugin.h) | 8 |
6 files changed, 71 insertions, 67 deletions
diff --git a/src/OutputInit.cxx b/src/OutputInit.cxx index 0e9f851b2..037f9ea44 100644 --- a/src/OutputInit.cxx +++ b/src/OutputInit.cxx @@ -34,9 +34,9 @@ extern "C" { #include "filter_plugin.h" #include "filter_registry.h" #include "filter/chain_filter_plugin.h" -#include "filter/autoconvert_filter_plugin.h" } +#include "filter/AutoConvertFilterPlugin.hxx" #include "filter/ReplayGainFilterPlugin.hxx" #include <glib.h> diff --git a/src/OutputThread.cxx b/src/OutputThread.cxx index 685475be3..fbbab98ea 100644 --- a/src/OutputThread.cxx +++ b/src/OutputThread.cxx @@ -25,10 +25,10 @@ extern "C" { #include "output_internal.h" #include "pcm_mix.h" #include "filter_plugin.h" -#include "filter/convert_filter_plugin.h" } #include "notify.hxx" +#include "filter/ConvertFilterPlugin.hxx" #include "filter/ReplayGainFilterPlugin.hxx" #include "PlayerControl.hxx" #include "MusicPipe.hxx" diff --git a/src/filter/autoconvert_filter_plugin.c b/src/filter/AutoConvertFilterPlugin.cxx index daa660521..3a8c087ba 100644 --- a/src/filter/autoconvert_filter_plugin.c +++ b/src/filter/AutoConvertFilterPlugin.cxx @@ -18,18 +18,16 @@ */ #include "config.h" -#include "filter/autoconvert_filter_plugin.h" -#include "filter/convert_filter_plugin.h" +#include "AutoConvertFilterPlugin.hxx" +#include "ConvertFilterPlugin.hxx" #include "filter_plugin.h" #include "filter_internal.h" #include "filter_registry.h" #include "audio_format.h" -#include <glib.h> - #include <assert.h> -struct autoconvert_filter { +struct AutoConvertFilter { struct filter base; /** @@ -45,20 +43,27 @@ struct autoconvert_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. */ struct filter *convert; + + AutoConvertFilter(const filter_plugin &plugin, struct filter *_filter) + :filter(_filter) { + filter_init(&base, &plugin); + } + + ~AutoConvertFilter() { + filter_free(filter); + } }; static void autoconvert_filter_finish(struct filter *_filter) { - struct autoconvert_filter *filter = - (struct autoconvert_filter *)_filter; + AutoConvertFilter *filter = (AutoConvertFilter *)_filter; - filter_free(filter->filter); - g_free(filter); + delete filter; } static const struct audio_format * @@ -66,8 +71,7 @@ autoconvert_filter_open(struct filter *_filter, struct audio_format *in_audio_format, GError **error_r) { - struct autoconvert_filter *filter = - (struct autoconvert_filter *)_filter; + AutoConvertFilter *filter = (AutoConvertFilter *)_filter; const struct audio_format *out_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, &filter->in_audio_format, error_r); - if (out_audio_format == NULL) - return NULL; + if (out_audio_format == nullptr) + return nullptr; /* need to convert? */ @@ -88,19 +92,19 @@ autoconvert_filter_open(struct filter *_filter, struct audio_format audio_format2 = *in_audio_format; const struct audio_format *audio_format3; - filter->convert = filter_new(&convert_filter_plugin, NULL, + filter->convert = filter_new(&convert_filter_plugin, nullptr, error_r); - if (filter->convert == NULL) { + if (filter->convert == nullptr) { filter_close(filter->filter); - return NULL; + return nullptr; } audio_format3 = filter_open(filter->convert, &audio_format2, error_r); - if (audio_format3 == NULL) { + if (audio_format3 == nullptr) { filter_free(filter->convert); filter_close(filter->filter); - return NULL; + return nullptr; } 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); } else /* no */ - filter->convert = NULL; + filter->convert = nullptr; return out_audio_format; } @@ -116,10 +120,10 @@ autoconvert_filter_open(struct filter *_filter, static void autoconvert_filter_close(struct filter *_filter) { - struct autoconvert_filter *filter = - (struct autoconvert_filter *)_filter; + AutoConvertFilter *filter = + (AutoConvertFilter *)_filter; - if (filter->convert != NULL) { + if (filter->convert != nullptr) { filter_close(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, GError **error_r) { - struct autoconvert_filter *filter = - (struct autoconvert_filter *)_filter; + AutoConvertFilter *filter = (AutoConvertFilter *)_filter; - if (filter->convert != NULL) { + if (filter->convert != nullptr) { src = filter_filter(filter->convert, src, src_size, &src_size, error_r); - if (src == NULL) - return NULL; + if (src == nullptr) + return nullptr; } 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 = { - .name = "convert", - .finish = autoconvert_filter_finish, - .open = autoconvert_filter_open, - .close = autoconvert_filter_close, - .filter = autoconvert_filter_filter, + "convert", + nullptr, + autoconvert_filter_finish, + autoconvert_filter_open, + autoconvert_filter_close, + autoconvert_filter_filter, }; struct filter * autoconvert_filter_new(struct filter *_filter) { - struct autoconvert_filter *filter = - g_new(struct autoconvert_filter, 1); - - filter_init(&filter->base, &autoconvert_filter_plugin); - filter->filter = _filter; + AutoConvertFilter *filter = + new AutoConvertFilter(autoconvert_filter_plugin, + _filter); return &filter->base; } diff --git a/src/filter/autoconvert_filter_plugin.h b/src/filter/AutoConvertFilterPlugin.hxx index def08ab7e..062efcbd0 100644 --- a/src/filter/autoconvert_filter_plugin.h +++ b/src/filter/AutoConvertFilterPlugin.hxx @@ -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 * * 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. */ -#ifndef AUTOCONVERT_FILTER_PLUGIN_H -#define AUTOCONVERT_FILTER_PLUGIN_H +#ifndef MPD_AUTOCONVERT_FILTER_PLUGIN_HXX +#define MPD_AUTOCONVERT_FILTER_PLUGIN_HXX struct filter; diff --git a/src/filter/convert_filter_plugin.c b/src/filter/ConvertFilterPlugin.cxx index c55b69af2..04f34842d 100644 --- a/src/filter/convert_filter_plugin.c +++ b/src/filter/ConvertFilterPlugin.cxx @@ -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 * * This program is free software; you can redistribute it and/or modify @@ -18,7 +18,7 @@ */ #include "config.h" -#include "filter/convert_filter_plugin.h" +#include "ConvertFilterPlugin.hxx" #include "filter_plugin.h" #include "filter_internal.h" #include "filter_registry.h" @@ -30,7 +30,7 @@ #include <assert.h> #include <string.h> -struct convert_filter { +struct ConvertFilter { struct filter base; /** @@ -52,29 +52,31 @@ struct convert_filter { struct audio_format out_audio_format; struct pcm_convert_state state; + + ConvertFilter() { + filter_init(&base, &convert_filter_plugin); + } }; static struct filter * -convert_filter_init(G_GNUC_UNUSED const struct config_param *param, - G_GNUC_UNUSED GError **error_r) +convert_filter_init(gcc_unused const struct config_param *param, + gcc_unused GError **error_r) { - struct convert_filter *filter = g_new(struct convert_filter, 1); - - filter_init(&filter->base, &convert_filter_plugin); + ConvertFilter *filter = new ConvertFilter(); return &filter->base; } static void convert_filter_finish(struct filter *filter) { - g_free(filter); + delete filter; } static const struct 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)); @@ -87,7 +89,7 @@ convert_filter_open(struct filter *_filter, struct audio_format *audio_format, static void convert_filter_close(struct filter *_filter) { - struct convert_filter *filter = (struct convert_filter *)_filter; + ConvertFilter *filter = (ConvertFilter *)_filter; 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, size_t *dest_size_r, GError **error_r) { - struct convert_filter *filter = (struct convert_filter *)_filter; + ConvertFilter *filter = (ConvertFilter *)_filter; const void *dest; 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 = { - .name = "convert", - .init = convert_filter_init, - .finish = convert_filter_finish, - .open = convert_filter_open, - .close = convert_filter_close, - .filter = convert_filter_filter, + "convert", + convert_filter_init, + convert_filter_finish, + convert_filter_open, + convert_filter_close, + convert_filter_filter, }; void convert_filter_set(struct filter *_filter, const struct audio_format *out_audio_format) { - struct convert_filter *filter = (struct convert_filter *)_filter; + ConvertFilter *filter = (ConvertFilter *)_filter; assert(filter != NULL); assert(audio_format_valid(&filter->in_audio_format)); diff --git a/src/filter/convert_filter_plugin.h b/src/filter/ConvertFilterPlugin.hxx index 156adf8e3..15f0fa92c 100644 --- a/src/filter/convert_filter_plugin.h +++ b/src/filter/ConvertFilterPlugin.hxx @@ -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 * * 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. */ -#ifndef CONVERT_FILTER_PLUGIN_H -#define CONVERT_FILTER_PLUGIN_H +#ifndef MPD_CONVERT_FILTER_PLUGIN_HXX +#define MPD_CONVERT_FILTER_PLUGIN_HXX struct filter; struct audio_format; @@ -31,6 +31,6 @@ struct audio_format; */ void convert_filter_set(struct filter *filter, - const struct audio_format *out_audio_format); + const audio_format *out_audio_format); #endif |