DecoderControl: move code/attributes to new class MixRampInfo
This commit is contained in:
@@ -155,6 +155,7 @@ src_mpd_SOURCES = \
|
|||||||
src/GlobalEvents.cxx src/GlobalEvents.hxx \
|
src/GlobalEvents.cxx src/GlobalEvents.hxx \
|
||||||
src/Daemon.cxx src/Daemon.hxx \
|
src/Daemon.cxx src/Daemon.hxx \
|
||||||
src/AudioCompress/compress.c \
|
src/AudioCompress/compress.c \
|
||||||
|
src/MixRampInfo.hxx \
|
||||||
src/MusicBuffer.cxx src/MusicBuffer.hxx \
|
src/MusicBuffer.cxx src/MusicBuffer.hxx \
|
||||||
src/MusicPipe.cxx src/MusicPipe.hxx \
|
src/MusicPipe.cxx src/MusicPipe.hxx \
|
||||||
src/MusicChunk.cxx src/MusicChunk.hxx \
|
src/MusicChunk.cxx src/MusicChunk.hxx \
|
||||||
|
@@ -541,11 +541,9 @@ decoder_replay_gain(Decoder &decoder,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
decoder_mixramp(Decoder &decoder,
|
decoder_mixramp(Decoder &decoder, MixRampInfo &&mix_ramp)
|
||||||
char *mixramp_start, char *mixramp_end)
|
|
||||||
{
|
{
|
||||||
decoder_control &dc = decoder.dc;
|
decoder_control &dc = decoder.dc;
|
||||||
|
|
||||||
dc.MixRampStart(mixramp_start);
|
dc.SetMixRamp(std::move(mix_ramp));
|
||||||
dc.MixRampEnd(mixramp_end);
|
|
||||||
}
|
}
|
||||||
|
@@ -33,6 +33,7 @@
|
|||||||
#include "ReplayGainInfo.hxx"
|
#include "ReplayGainInfo.hxx"
|
||||||
#include "tag/Tag.hxx"
|
#include "tag/Tag.hxx"
|
||||||
#include "AudioFormat.hxx"
|
#include "AudioFormat.hxx"
|
||||||
|
#include "MixRampInfo.hxx"
|
||||||
#include "ConfigData.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
|
* @param mixramp_end the mixramp_end tag; may be nullptr to invalidate
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
decoder_mixramp(Decoder &decoder,
|
decoder_mixramp(Decoder &decoder, MixRampInfo &&mix_ramp);
|
||||||
char *mixramp_start, char *mixramp_end);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -30,9 +30,7 @@ decoder_control::decoder_control()
|
|||||||
:state(DecoderState::STOP),
|
:state(DecoderState::STOP),
|
||||||
command(DecoderCommand::NONE),
|
command(DecoderCommand::NONE),
|
||||||
song(nullptr),
|
song(nullptr),
|
||||||
replay_gain_db(0), replay_gain_prev_db(0),
|
replay_gain_db(0), replay_gain_prev_db(0) {}
|
||||||
mixramp_start(nullptr), mixramp_end(nullptr),
|
|
||||||
mixramp_prev_end(nullptr) {}
|
|
||||||
|
|
||||||
decoder_control::~decoder_control()
|
decoder_control::~decoder_control()
|
||||||
{
|
{
|
||||||
@@ -40,10 +38,6 @@ decoder_control::~decoder_control()
|
|||||||
|
|
||||||
if (song != nullptr)
|
if (song != nullptr)
|
||||||
song->Free();
|
song->Free();
|
||||||
|
|
||||||
g_free(mixramp_start);
|
|
||||||
g_free(mixramp_end);
|
|
||||||
g_free(mixramp_prev_end);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
@@ -129,26 +123,9 @@ decoder_control::Quit()
|
|||||||
thread.Join();
|
thread.Join();
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
void
|
||||||
decoder_control::CycleMixRamp()
|
decoder_control::CycleMixRamp()
|
||||||
{
|
{
|
||||||
g_free(mixramp_start);
|
previous_mix_ramp = std::move(mix_ramp);
|
||||||
mixramp_start = nullptr;
|
mix_ramp.Clear();
|
||||||
g_free(mixramp_prev_end);
|
|
||||||
mixramp_prev_end = mixramp_end;
|
|
||||||
mixramp_end = nullptr;
|
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "DecoderCommand.hxx"
|
#include "DecoderCommand.hxx"
|
||||||
#include "AudioFormat.hxx"
|
#include "AudioFormat.hxx"
|
||||||
|
#include "MixRampInfo.hxx"
|
||||||
#include "thread/Mutex.hxx"
|
#include "thread/Mutex.hxx"
|
||||||
#include "thread/Cond.hxx"
|
#include "thread/Cond.hxx"
|
||||||
#include "thread/Thread.hxx"
|
#include "thread/Thread.hxx"
|
||||||
@@ -139,9 +140,8 @@ struct decoder_control {
|
|||||||
|
|
||||||
float replay_gain_db;
|
float replay_gain_db;
|
||||||
float replay_gain_prev_db;
|
float replay_gain_prev_db;
|
||||||
char *mixramp_start;
|
|
||||||
char *mixramp_end;
|
MixRampInfo mix_ramp, previous_mix_ramp;
|
||||||
char *mixramp_prev_end;
|
|
||||||
|
|
||||||
decoder_control();
|
decoder_control();
|
||||||
~decoder_control();
|
~decoder_control();
|
||||||
@@ -351,19 +351,20 @@ public:
|
|||||||
void Quit();
|
void Quit();
|
||||||
|
|
||||||
const char *GetMixRampStart() const {
|
const char *GetMixRampStart() const {
|
||||||
return mixramp_start;
|
return mix_ramp.GetStart();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *GetMixRampEnd() const {
|
const char *GetMixRampEnd() const {
|
||||||
return mixramp_end;
|
return mix_ramp.GetEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *GetMixRampPreviousEnd() const {
|
const char *GetMixRampPreviousEnd() const {
|
||||||
return mixramp_prev_end;
|
return previous_mix_ramp.GetEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MixRampStart(char *_mixramp_start);
|
void SetMixRamp(MixRampInfo &&new_value) {
|
||||||
void MixRampEnd(char *_mixramp_end);
|
mix_ramp = std::move(new_value);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move mixramp_end to mixramp_prev_end and clear
|
* Move mixramp_end to mixramp_prev_end and clear
|
||||||
|
77
src/MixRampInfo.hxx
Normal file
77
src/MixRampInfo.hxx
Normal file
@@ -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
|
@@ -25,6 +25,7 @@
|
|||||||
#include "FlacCommon.hxx"
|
#include "FlacCommon.hxx"
|
||||||
#include "FlacMetadata.hxx"
|
#include "FlacMetadata.hxx"
|
||||||
#include "FlacPcm.hxx"
|
#include "FlacPcm.hxx"
|
||||||
|
#include "MixRampInfo.hxx"
|
||||||
#include "CheckAudioFormat.hxx"
|
#include "CheckAudioFormat.hxx"
|
||||||
#include "util/Error.hxx"
|
#include "util/Error.hxx"
|
||||||
#include "util/Domain.hxx"
|
#include "util/Domain.hxx"
|
||||||
@@ -94,8 +95,6 @@ void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
ReplayGainInfo rgi;
|
ReplayGainInfo rgi;
|
||||||
char *mixramp_start;
|
|
||||||
char *mixramp_end;
|
|
||||||
|
|
||||||
switch (block->type) {
|
switch (block->type) {
|
||||||
case FLAC__METADATA_TYPE_STREAMINFO:
|
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))
|
if (flac_parse_replay_gain(rgi, block))
|
||||||
decoder_replay_gain(data->decoder, &rgi);
|
decoder_replay_gain(data->decoder, &rgi);
|
||||||
|
|
||||||
if (flac_parse_mixramp(&mixramp_start, &mixramp_end, block))
|
decoder_mixramp(data->decoder, flac_parse_mixramp(block));
|
||||||
decoder_mixramp(data->decoder,
|
|
||||||
mixramp_start, mixramp_end);
|
|
||||||
|
|
||||||
flac_vorbis_comments_to_tag(data->tag,
|
flac_vorbis_comments_to_tag(data->tag,
|
||||||
&block->data.vorbis_comment);
|
&block->data.vorbis_comment);
|
||||||
|
@@ -20,6 +20,7 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "FlacMetadata.hxx"
|
#include "FlacMetadata.hxx"
|
||||||
#include "XiphTags.hxx"
|
#include "XiphTags.hxx"
|
||||||
|
#include "MixRampInfo.hxx"
|
||||||
#include "tag/Tag.hxx"
|
#include "tag/Tag.hxx"
|
||||||
#include "tag/TagHandler.hxx"
|
#include "tag/TagHandler.hxx"
|
||||||
#include "tag/TagTable.hxx"
|
#include "tag/TagTable.hxx"
|
||||||
@@ -83,44 +84,36 @@ flac_parse_replay_gain(ReplayGainInfo &rgi,
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
gcc_pure
|
||||||
flac_find_string_comment(const FLAC__StreamMetadata *block,
|
static std::string
|
||||||
const char *cmnt, char **str)
|
flac_find_string_comment(const FLAC__StreamMetadata *block, const char *cmnt)
|
||||||
{
|
{
|
||||||
int offset;
|
int offset;
|
||||||
size_t pos;
|
size_t pos;
|
||||||
int len;
|
int len;
|
||||||
const unsigned char *p;
|
const unsigned char *p;
|
||||||
|
|
||||||
*str = nullptr;
|
|
||||||
offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0,
|
offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0,
|
||||||
cmnt);
|
cmnt);
|
||||||
if (offset < 0)
|
if (offset < 0)
|
||||||
return false;
|
return std::string();
|
||||||
|
|
||||||
pos = strlen(cmnt) + 1; /* 1 is for '=' */
|
pos = strlen(cmnt) + 1; /* 1 is for '=' */
|
||||||
len = block->data.vorbis_comment.comments[offset].length - pos;
|
len = block->data.vorbis_comment.comments[offset].length - pos;
|
||||||
if (len <= 0)
|
if (len <= 0)
|
||||||
return false;
|
return std::string();
|
||||||
|
|
||||||
p = &block->data.vorbis_comment.comments[offset].entry[pos];
|
p = &block->data.vorbis_comment.comments[offset].entry[pos];
|
||||||
*str = g_strndup((const char *)p, len);
|
return std::string((const char *)p, len);
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
MixRampInfo
|
||||||
flac_parse_mixramp(char **mixramp_start, char **mixramp_end,
|
flac_parse_mixramp(const FLAC__StreamMetadata *block)
|
||||||
const FLAC__StreamMetadata *block)
|
|
||||||
{
|
{
|
||||||
bool found = false;
|
MixRampInfo mix_ramp;
|
||||||
|
mix_ramp.SetStart(flac_find_string_comment(block, "mixramp_start"));
|
||||||
if (flac_find_string_comment(block, "mixramp_start", mixramp_start))
|
mix_ramp.SetEnd(flac_find_string_comment(block, "mixramp_end"));
|
||||||
found = true;
|
return mix_ramp;
|
||||||
if (flac_find_string_comment(block, "mixramp_end", mixramp_end))
|
|
||||||
found = true;
|
|
||||||
|
|
||||||
return found;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
class MixRampInfo;
|
||||||
|
|
||||||
class FlacMetadataChain {
|
class FlacMetadataChain {
|
||||||
FLAC__Metadata_Chain *chain;
|
FLAC__Metadata_Chain *chain;
|
||||||
|
|
||||||
@@ -125,9 +127,8 @@ bool
|
|||||||
flac_parse_replay_gain(ReplayGainInfo &rgi,
|
flac_parse_replay_gain(ReplayGainInfo &rgi,
|
||||||
const FLAC__StreamMetadata *block);
|
const FLAC__StreamMetadata *block);
|
||||||
|
|
||||||
bool
|
MixRampInfo
|
||||||
flac_parse_mixramp(char **mixramp_start, char **mixramp_end,
|
flac_parse_mixramp(const FLAC__StreamMetadata *block);
|
||||||
const FLAC__StreamMetadata *block);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
flac_vorbis_comments_to_tag(Tag &tag,
|
flac_vorbis_comments_to_tag(Tag &tag,
|
||||||
|
@@ -298,18 +298,16 @@ parse_id3_replay_gain_info(ReplayGainInfo &rgi,
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_ID3TAG
|
#ifdef HAVE_ID3TAG
|
||||||
static bool
|
gcc_pure
|
||||||
parse_id3_mixramp(char **mixramp_start, char **mixramp_end,
|
static MixRampInfo
|
||||||
struct id3_tag *tag)
|
parse_id3_mixramp(struct id3_tag *tag)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *key;
|
char *key;
|
||||||
char *value;
|
char *value;
|
||||||
struct id3_frame *frame;
|
struct id3_frame *frame;
|
||||||
bool found = false;
|
|
||||||
|
|
||||||
*mixramp_start = nullptr;
|
MixRampInfo result;
|
||||||
*mixramp_end = nullptr;
|
|
||||||
|
|
||||||
for (i = 0; (frame = id3_tag_findframe(tag, "TXXX", i)); i++) {
|
for (i = 0; (frame = id3_tag_findframe(tag, "TXXX", i)); i++) {
|
||||||
if (frame->nfields < 3)
|
if (frame->nfields < 3)
|
||||||
@@ -323,18 +321,16 @@ parse_id3_mixramp(char **mixramp_start, char **mixramp_end,
|
|||||||
(&frame->fields[2]));
|
(&frame->fields[2]));
|
||||||
|
|
||||||
if (StringEqualsCaseASCII(key, "mixramp_start")) {
|
if (StringEqualsCaseASCII(key, "mixramp_start")) {
|
||||||
*mixramp_start = g_strdup(value);
|
result.SetStart(value);
|
||||||
found = true;
|
|
||||||
} else if (StringEqualsCaseASCII(key, "mixramp_end")) {
|
} else if (StringEqualsCaseASCII(key, "mixramp_end")) {
|
||||||
*mixramp_end = g_strdup(value);
|
result.SetEnd(value);
|
||||||
found = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(key);
|
free(key);
|
||||||
free(value);
|
free(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return found;
|
return result;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -393,16 +389,13 @@ MadDecoder::ParseId3(size_t tagsize, Tag **mpd_tag)
|
|||||||
|
|
||||||
if (decoder != nullptr) {
|
if (decoder != nullptr) {
|
||||||
ReplayGainInfo rgi;
|
ReplayGainInfo rgi;
|
||||||
char *mixramp_start;
|
|
||||||
char *mixramp_end;
|
|
||||||
|
|
||||||
if (parse_id3_replay_gain_info(rgi, id3_tag)) {
|
if (parse_id3_replay_gain_info(rgi, id3_tag)) {
|
||||||
decoder_replay_gain(*decoder, &rgi);
|
decoder_replay_gain(*decoder, &rgi);
|
||||||
found_replay_gain = true;
|
found_replay_gain = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parse_id3_mixramp(&mixramp_start, &mixramp_end, id3_tag))
|
decoder_mixramp(*decoder, parse_id3_mixramp(id3_tag));
|
||||||
decoder_mixramp(*decoder, mixramp_start, mixramp_end);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
id3_tag_delete(id3_tag);
|
id3_tag_delete(id3_tag);
|
||||||
|
@@ -131,11 +131,8 @@ decoder_replay_gain(gcc_unused Decoder &decoder,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
decoder_mixramp(gcc_unused Decoder &decoder,
|
decoder_mixramp(gcc_unused Decoder &decoder, gcc_unused MixRampInfo &&mix_ramp)
|
||||||
char *mixramp_start, char *mixramp_end)
|
|
||||||
{
|
{
|
||||||
g_free(mixramp_start);
|
|
||||||
g_free(mixramp_end);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
@@ -110,11 +110,8 @@ decoder_replay_gain(gcc_unused Decoder &decoder,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
decoder_mixramp(gcc_unused Decoder &decoder,
|
decoder_mixramp(gcc_unused Decoder &decoder, gcc_unused MixRampInfo &&mix_ramp)
|
||||||
char *mixramp_start, char *mixramp_end)
|
|
||||||
{
|
{
|
||||||
g_free(mixramp_start);
|
|
||||||
g_free(mixramp_end);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool empty = true;
|
static bool empty = true;
|
||||||
|
@@ -141,11 +141,8 @@ decoder_replay_gain(gcc_unused Decoder &decoder,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
decoder_mixramp(gcc_unused Decoder &decoder,
|
decoder_mixramp(gcc_unused Decoder &decoder, gcc_unused MixRampInfo &&mix_ramp)
|
||||||
char *mixramp_start, char *mixramp_end)
|
|
||||||
{
|
{
|
||||||
g_free(mixramp_start);
|
|
||||||
g_free(mixramp_end);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
Reference in New Issue
Block a user