Commit 85ae7e9c authored by Max Kellermann's avatar Max Kellermann

DecoderControl: move code/attributes to new class MixRampInfo

parent 2098b94b
......@@ -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 \
......
......@@ -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));
}
......@@ -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
......@@ -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();
}
......@@ -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
......
/*
* 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
......@@ -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);
......
......@@ -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;
}
/**
......
......@@ -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,
......
......@@ -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);
......
......@@ -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)
......
......@@ -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;
......
......@@ -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)
......
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