aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-10-26 14:19:34 +0200
committerMax Kellermann <max@duempel.org>2013-10-26 14:19:34 +0200
commit85ae7e9c9a8e31359834b3b4da3c358b941e8012 (patch)
treecadafa466a385107ba43f4c60664a064c7617550
parent2098b94b47a60f6265dd5afb61757e9f6b7f9a6e (diff)
downloadmpd-85ae7e9c9a8e31359834b3b4da3c358b941e8012.tar.gz
mpd-85ae7e9c9a8e31359834b3b4da3c358b941e8012.tar.xz
mpd-85ae7e9c9a8e31359834b3b4da3c358b941e8012.zip
DecoderControl: move code/attributes to new class MixRampInfo
Diffstat (limited to '')
-rw-r--r--Makefile.am1
-rw-r--r--src/DecoderAPI.cxx6
-rw-r--r--src/DecoderAPI.hxx4
-rw-r--r--src/DecoderControl.cxx29
-rw-r--r--src/DecoderControl.hxx17
-rw-r--r--src/MixRampInfo.hxx77
-rw-r--r--src/decoder/FlacCommon.cxx7
-rw-r--r--src/decoder/FlacMetadata.cxx33
-rw-r--r--src/decoder/FlacMetadata.hxx7
-rw-r--r--src/decoder/MadDecoderPlugin.cxx23
-rw-r--r--test/dump_playlist.cxx5
-rw-r--r--test/read_tags.cxx5
-rw-r--r--test/run_decoder.cxx5
13 files changed, 124 insertions, 95 deletions
diff --git a/Makefile.am b/Makefile.am
index 48a143f39..771f763db 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -155,6 +155,7 @@ src_mpd_SOURCES = \
src/GlobalEvents.cxx src/GlobalEvents.hxx \
src/Daemon.cxx src/Daemon.hxx \
src/AudioCompress/compress.c \
+ src/MixRampInfo.hxx \
src/MusicBuffer.cxx src/MusicBuffer.hxx \
src/MusicPipe.cxx src/MusicPipe.hxx \
src/MusicChunk.cxx src/MusicChunk.hxx \
diff --git a/src/DecoderAPI.cxx b/src/DecoderAPI.cxx
index f672b1750..1b435c43a 100644
--- a/src/DecoderAPI.cxx
+++ b/src/DecoderAPI.cxx
@@ -541,11 +541,9 @@ decoder_replay_gain(Decoder &decoder,
}
void
-decoder_mixramp(Decoder &decoder,
- char *mixramp_start, char *mixramp_end)
+decoder_mixramp(Decoder &decoder, MixRampInfo &&mix_ramp)
{
decoder_control &dc = decoder.dc;
- dc.MixRampStart(mixramp_start);
- dc.MixRampEnd(mixramp_end);
+ dc.SetMixRamp(std::move(mix_ramp));
}
diff --git a/src/DecoderAPI.hxx b/src/DecoderAPI.hxx
index 0f9dabb4b..2ee42483c 100644
--- a/src/DecoderAPI.hxx
+++ b/src/DecoderAPI.hxx
@@ -33,6 +33,7 @@
#include "ReplayGainInfo.hxx"
#include "tag/Tag.hxx"
#include "AudioFormat.hxx"
+#include "MixRampInfo.hxx"
#include "ConfigData.hxx"
/**
@@ -184,7 +185,6 @@ decoder_replay_gain(Decoder &decoder,
* @param mixramp_end the mixramp_end tag; may be nullptr to invalidate
*/
void
-decoder_mixramp(Decoder &decoder,
- char *mixramp_start, char *mixramp_end);
+decoder_mixramp(Decoder &decoder, MixRampInfo &&mix_ramp);
#endif
diff --git a/src/DecoderControl.cxx b/src/DecoderControl.cxx
index cbe93361e..e3b5f8977 100644
--- a/src/DecoderControl.cxx
+++ b/src/DecoderControl.cxx
@@ -30,9 +30,7 @@ decoder_control::decoder_control()
:state(DecoderState::STOP),
command(DecoderCommand::NONE),
song(nullptr),
- replay_gain_db(0), replay_gain_prev_db(0),
- mixramp_start(nullptr), mixramp_end(nullptr),
- mixramp_prev_end(nullptr) {}
+ replay_gain_db(0), replay_gain_prev_db(0) {}
decoder_control::~decoder_control()
{
@@ -40,10 +38,6 @@ decoder_control::~decoder_control()
if (song != nullptr)
song->Free();
-
- g_free(mixramp_start);
- g_free(mixramp_end);
- g_free(mixramp_prev_end);
}
bool
@@ -130,25 +124,8 @@ decoder_control::Quit()
}
void
-decoder_control::MixRampStart(char *_mixramp_start)
-{
- g_free(mixramp_start);
- mixramp_start = _mixramp_start;
-}
-
-void
-decoder_control::MixRampEnd(char *_mixramp_end)
-{
- g_free(mixramp_end);
- mixramp_end = _mixramp_end;
-}
-
-void
decoder_control::CycleMixRamp()
{
- g_free(mixramp_start);
- mixramp_start = nullptr;
- g_free(mixramp_prev_end);
- mixramp_prev_end = mixramp_end;
- mixramp_end = nullptr;
+ previous_mix_ramp = std::move(mix_ramp);
+ mix_ramp.Clear();
}
diff --git a/src/DecoderControl.hxx b/src/DecoderControl.hxx
index c27177cbd..9a949b2fe 100644
--- a/src/DecoderControl.hxx
+++ b/src/DecoderControl.hxx
@@ -22,6 +22,7 @@
#include "DecoderCommand.hxx"
#include "AudioFormat.hxx"
+#include "MixRampInfo.hxx"
#include "thread/Mutex.hxx"
#include "thread/Cond.hxx"
#include "thread/Thread.hxx"
@@ -139,9 +140,8 @@ struct decoder_control {
float replay_gain_db;
float replay_gain_prev_db;
- char *mixramp_start;
- char *mixramp_end;
- char *mixramp_prev_end;
+
+ MixRampInfo mix_ramp, previous_mix_ramp;
decoder_control();
~decoder_control();
@@ -351,19 +351,20 @@ public:
void Quit();
const char *GetMixRampStart() const {
- return mixramp_start;
+ return mix_ramp.GetStart();
}
const char *GetMixRampEnd() const {
- return mixramp_end;
+ return mix_ramp.GetEnd();
}
const char *GetMixRampPreviousEnd() const {
- return mixramp_prev_end;
+ return previous_mix_ramp.GetEnd();
}
- void MixRampStart(char *_mixramp_start);
- void MixRampEnd(char *_mixramp_end);
+ void SetMixRamp(MixRampInfo &&new_value) {
+ mix_ramp = std::move(new_value);
+ }
/**
* Move mixramp_end to mixramp_prev_end and clear
diff --git a/src/MixRampInfo.hxx b/src/MixRampInfo.hxx
new file mode 100644
index 000000000..9af41b77d
--- /dev/null
+++ b/src/MixRampInfo.hxx
@@ -0,0 +1,77 @@
+/*
+ * 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
+ * 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.
+ *
+ * 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.
+ */
+
+#ifndef MPD_MIX_RAMP_INFO_HXX
+#define MPD_MIX_RAMP_INFO_HXX
+
+#include "check.h"
+#include "Compiler.h"
+
+#include <string>
+
+class MixRampInfo {
+ std::string start, end;
+
+public:
+ MixRampInfo() = default;
+
+ void Clear() {
+ start.clear();
+ end.clear();
+ }
+
+ gcc_pure
+ bool IsDefined() const {
+ return !start.empty() || !end.empty();
+ }
+
+ gcc_pure
+ const char *GetStart() const {
+ return start.empty() ? nullptr : start.c_str();
+ }
+
+ gcc_pure
+ const char *GetEnd() const {
+ return end.empty() ? nullptr : end.c_str();
+ }
+
+ void SetStart(const char *new_value) {
+ if (new_value == nullptr)
+ start.clear();
+ else
+ start = new_value;
+ }
+
+ void SetStart(std::string &&new_value) {
+ start = std::move(new_value);
+ }
+
+ void SetEnd(const char *new_value) {
+ if (new_value == nullptr)
+ end.clear();
+ else
+ end = new_value;
+ }
+
+ void SetEnd(std::string &&new_value) {
+ end = std::move(new_value);
+ }
+};
+
+#endif
diff --git a/src/decoder/FlacCommon.cxx b/src/decoder/FlacCommon.cxx
index 2b2db8066..0a53031d0 100644
--- a/src/decoder/FlacCommon.cxx
+++ b/src/decoder/FlacCommon.cxx
@@ -25,6 +25,7 @@
#include "FlacCommon.hxx"
#include "FlacMetadata.hxx"
#include "FlacPcm.hxx"
+#include "MixRampInfo.hxx"
#include "CheckAudioFormat.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
@@ -94,8 +95,6 @@ void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
return;
ReplayGainInfo rgi;
- char *mixramp_start;
- char *mixramp_end;
switch (block->type) {
case FLAC__METADATA_TYPE_STREAMINFO:
@@ -106,9 +105,7 @@ void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
if (flac_parse_replay_gain(rgi, block))
decoder_replay_gain(data->decoder, &rgi);
- if (flac_parse_mixramp(&mixramp_start, &mixramp_end, block))
- decoder_mixramp(data->decoder,
- mixramp_start, mixramp_end);
+ decoder_mixramp(data->decoder, flac_parse_mixramp(block));
flac_vorbis_comments_to_tag(data->tag,
&block->data.vorbis_comment);
diff --git a/src/decoder/FlacMetadata.cxx b/src/decoder/FlacMetadata.cxx
index 917da7d87..17cc4cd8d 100644
--- a/src/decoder/FlacMetadata.cxx
+++ b/src/decoder/FlacMetadata.cxx
@@ -20,6 +20,7 @@
#include "config.h"
#include "FlacMetadata.hxx"
#include "XiphTags.hxx"
+#include "MixRampInfo.hxx"
#include "tag/Tag.hxx"
#include "tag/TagHandler.hxx"
#include "tag/TagTable.hxx"
@@ -83,44 +84,36 @@ flac_parse_replay_gain(ReplayGainInfo &rgi,
return found;
}
-static bool
-flac_find_string_comment(const FLAC__StreamMetadata *block,
- const char *cmnt, char **str)
+gcc_pure
+static std::string
+flac_find_string_comment(const FLAC__StreamMetadata *block, const char *cmnt)
{
int offset;
size_t pos;
int len;
const unsigned char *p;
- *str = nullptr;
offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0,
cmnt);
if (offset < 0)
- return false;
+ return std::string();
pos = strlen(cmnt) + 1; /* 1 is for '=' */
len = block->data.vorbis_comment.comments[offset].length - pos;
if (len <= 0)
- return false;
+ return std::string();
p = &block->data.vorbis_comment.comments[offset].entry[pos];
- *str = g_strndup((const char *)p, len);
-
- return true;
+ return std::string((const char *)p, len);
}
-bool
-flac_parse_mixramp(char **mixramp_start, char **mixramp_end,
- const FLAC__StreamMetadata *block)
+MixRampInfo
+flac_parse_mixramp(const FLAC__StreamMetadata *block)
{
- bool found = false;
-
- if (flac_find_string_comment(block, "mixramp_start", mixramp_start))
- found = true;
- if (flac_find_string_comment(block, "mixramp_end", mixramp_end))
- found = true;
-
- return found;
+ MixRampInfo mix_ramp;
+ mix_ramp.SetStart(flac_find_string_comment(block, "mixramp_start"));
+ mix_ramp.SetEnd(flac_find_string_comment(block, "mixramp_end"));
+ return mix_ramp;
}
/**
diff --git a/src/decoder/FlacMetadata.hxx b/src/decoder/FlacMetadata.hxx
index 8b050b2f8..def21d0c8 100644
--- a/src/decoder/FlacMetadata.hxx
+++ b/src/decoder/FlacMetadata.hxx
@@ -27,6 +27,8 @@
#include <assert.h>
+class MixRampInfo;
+
class FlacMetadataChain {
FLAC__Metadata_Chain *chain;
@@ -125,9 +127,8 @@ bool
flac_parse_replay_gain(ReplayGainInfo &rgi,
const FLAC__StreamMetadata *block);
-bool
-flac_parse_mixramp(char **mixramp_start, char **mixramp_end,
- const FLAC__StreamMetadata *block);
+MixRampInfo
+flac_parse_mixramp(const FLAC__StreamMetadata *block);
void
flac_vorbis_comments_to_tag(Tag &tag,
diff --git a/src/decoder/MadDecoderPlugin.cxx b/src/decoder/MadDecoderPlugin.cxx
index c7ed8781d..9dd86c55f 100644
--- a/src/decoder/MadDecoderPlugin.cxx
+++ b/src/decoder/MadDecoderPlugin.cxx
@@ -298,18 +298,16 @@ parse_id3_replay_gain_info(ReplayGainInfo &rgi,
#endif
#ifdef HAVE_ID3TAG
-static bool
-parse_id3_mixramp(char **mixramp_start, char **mixramp_end,
- struct id3_tag *tag)
+gcc_pure
+static MixRampInfo
+parse_id3_mixramp(struct id3_tag *tag)
{
int i;
char *key;
char *value;
struct id3_frame *frame;
- bool found = false;
- *mixramp_start = nullptr;
- *mixramp_end = nullptr;
+ MixRampInfo result;
for (i = 0; (frame = id3_tag_findframe(tag, "TXXX", i)); i++) {
if (frame->nfields < 3)
@@ -323,18 +321,16 @@ parse_id3_mixramp(char **mixramp_start, char **mixramp_end,
(&frame->fields[2]));
if (StringEqualsCaseASCII(key, "mixramp_start")) {
- *mixramp_start = g_strdup(value);
- found = true;
+ result.SetStart(value);
} else if (StringEqualsCaseASCII(key, "mixramp_end")) {
- *mixramp_end = g_strdup(value);
- found = true;
+ result.SetEnd(value);
}
free(key);
free(value);
}
- return found;
+ return result;
}
#endif
@@ -393,16 +389,13 @@ MadDecoder::ParseId3(size_t tagsize, Tag **mpd_tag)
if (decoder != nullptr) {
ReplayGainInfo rgi;
- char *mixramp_start;
- char *mixramp_end;
if (parse_id3_replay_gain_info(rgi, id3_tag)) {
decoder_replay_gain(*decoder, &rgi);
found_replay_gain = true;
}
- if (parse_id3_mixramp(&mixramp_start, &mixramp_end, id3_tag))
- decoder_mixramp(*decoder, mixramp_start, mixramp_end);
+ decoder_mixramp(*decoder, parse_id3_mixramp(id3_tag));
}
id3_tag_delete(id3_tag);
diff --git a/test/dump_playlist.cxx b/test/dump_playlist.cxx
index d8a8084b0..d11562930 100644
--- a/test/dump_playlist.cxx
+++ b/test/dump_playlist.cxx
@@ -131,11 +131,8 @@ decoder_replay_gain(gcc_unused Decoder &decoder,
}
void
-decoder_mixramp(gcc_unused Decoder &decoder,
- char *mixramp_start, char *mixramp_end)
+decoder_mixramp(gcc_unused Decoder &decoder, gcc_unused MixRampInfo &&mix_ramp)
{
- g_free(mixramp_start);
- g_free(mixramp_end);
}
int main(int argc, char **argv)
diff --git a/test/read_tags.cxx b/test/read_tags.cxx
index 12cc93aa6..2d25041f5 100644
--- a/test/read_tags.cxx
+++ b/test/read_tags.cxx
@@ -110,11 +110,8 @@ decoder_replay_gain(gcc_unused Decoder &decoder,
}
void
-decoder_mixramp(gcc_unused Decoder &decoder,
- char *mixramp_start, char *mixramp_end)
+decoder_mixramp(gcc_unused Decoder &decoder, gcc_unused MixRampInfo &&mix_ramp)
{
- g_free(mixramp_start);
- g_free(mixramp_end);
}
static bool empty = true;
diff --git a/test/run_decoder.cxx b/test/run_decoder.cxx
index f4662e8af..2f7330a1d 100644
--- a/test/run_decoder.cxx
+++ b/test/run_decoder.cxx
@@ -141,11 +141,8 @@ decoder_replay_gain(gcc_unused Decoder &decoder,
}
void
-decoder_mixramp(gcc_unused Decoder &decoder,
- char *mixramp_start, char *mixramp_end)
+decoder_mixramp(gcc_unused Decoder &decoder, gcc_unused MixRampInfo &&mix_ramp)
{
- g_free(mixramp_start);
- g_free(mixramp_end);
}
int main(int argc, char **argv)