diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/DecoderAPI.cxx | 6 | ||||
-rw-r--r-- | src/DecoderAPI.hxx | 4 | ||||
-rw-r--r-- | src/DecoderControl.cxx | 29 | ||||
-rw-r--r-- | src/DecoderControl.hxx | 17 | ||||
-rw-r--r-- | src/MixRampInfo.hxx | 77 | ||||
-rw-r--r-- | src/decoder/FlacCommon.cxx | 7 | ||||
-rw-r--r-- | src/decoder/FlacMetadata.cxx | 33 | ||||
-rw-r--r-- | src/decoder/FlacMetadata.hxx | 7 | ||||
-rw-r--r-- | src/decoder/MadDecoderPlugin.cxx | 23 |
9 files changed, 120 insertions, 83 deletions
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); |