DecoderControl: move code/attributes to new class MixRampInfo
This commit is contained in:
@@ -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);
|
||||
|
Reference in New Issue
Block a user