aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-09-24 22:44:58 +0200
committerMax Kellermann <max@duempel.org>2014-09-24 22:44:58 +0200
commit8a7ff6a6fd70d6a8e7611ffb0f794fb3eab2a462 (patch)
treeb3f616d3c8b4d38254256b8d8c7c38141da49e5e
parent6c48aa5fae5b6f6dda8011b72e646af3ed1d35cd (diff)
downloadmpd-8a7ff6a6fd70d6a8e7611ffb0f794fb3eab2a462.tar.gz
mpd-8a7ff6a6fd70d6a8e7611ffb0f794fb3eab2a462.tar.xz
mpd-8a7ff6a6fd70d6a8e7611ffb0f794fb3eab2a462.zip
decoder/flac: move code to tag/MixRamp.cxx
-rw-r--r--src/decoder/plugins/FlacMetadata.cxx45
-rw-r--r--src/tag/MixRamp.cxx16
-rw-r--r--src/tag/MixRamp.hxx3
3 files changed, 29 insertions, 35 deletions
diff --git a/src/decoder/plugins/FlacMetadata.cxx b/src/decoder/plugins/FlacMetadata.cxx
index 4628ad4a2..f917a8fcc 100644
--- a/src/decoder/plugins/FlacMetadata.cxx
+++ b/src/decoder/plugins/FlacMetadata.cxx
@@ -27,32 +27,11 @@
#include "tag/Tag.hxx"
#include "tag/VorbisComment.hxx"
#include "tag/ReplayGain.hxx"
+#include "tag/MixRamp.hxx"
#include "ReplayGainInfo.hxx"
#include "util/ASCII.hxx"
#include "util/SplitString.hxx"
-#include <string.h>
-
-static const char *
-vorbis_comment_value(const FLAC__StreamMetadata *block,
- const char *name)
-{
- int offset =
- FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0,
- name);
- if (offset < 0)
- return nullptr;
-
- size_t name_length = strlen(name);
-
- const FLAC__StreamMetadata_VorbisComment_Entry &vc =
- block->data.vorbis_comment.comments[offset];
- const char *comment = (const char *)vc.entry;
-
- /* 1 is for '=' */
- return comment + name_length + 1;
-}
-
bool
flac_parse_replay_gain(ReplayGainInfo &rgi,
const FLAC__StreamMetadata_VorbisComment &vc)
@@ -70,23 +49,19 @@ flac_parse_replay_gain(ReplayGainInfo &rgi,
return found;
}
-gcc_pure
-static std::string
-flac_find_string_comment(const FLAC__StreamMetadata *block, const char *cmnt)
-{
- const char *value = vorbis_comment_value(block, cmnt);
- if (value == nullptr)
- return std::string();
-
- return std::string(value);
-}
-
MixRampInfo
flac_parse_mixramp(const FLAC__StreamMetadata *block)
{
+ const FLAC__StreamMetadata_VorbisComment &vc =
+ block->data.vorbis_comment;
+
MixRampInfo mix_ramp;
- mix_ramp.SetStart(flac_find_string_comment(block, "mixramp_start"));
- mix_ramp.SetEnd(flac_find_string_comment(block, "mixramp_end"));
+
+ const auto *comments = vc.comments;
+ for (FLAC__uint32 i = 0, n = vc.num_comments; i < n; ++i)
+ ParseMixRampVorbis(mix_ramp,
+ (const char *)comments[i].entry);
+
return mix_ramp;
}
diff --git a/src/tag/MixRamp.cxx b/src/tag/MixRamp.cxx
index 36cf74c82..e1b6e43c5 100644
--- a/src/tag/MixRamp.cxx
+++ b/src/tag/MixRamp.cxx
@@ -19,6 +19,7 @@
#include "config.h"
#include "MixRamp.hxx"
+#include "VorbisComment.hxx"
#include "MixRampInfo.hxx"
#include "util/ASCII.hxx"
@@ -61,3 +62,18 @@ ParseMixRampTag(MixRampInfo &info, const char *name, const char *value)
return ParseMixRampTagTemplate(info, NameValue{name, value});
}
+
+bool
+ParseMixRampVorbis(MixRampInfo &info, const char *entry)
+{
+ struct VorbisCommentEntry {
+ const char *entry;
+
+ gcc_pure
+ const char *operator[](const char *n) const {
+ return vorbis_comment_value(entry, n);
+ }
+ };
+
+ return ParseMixRampTagTemplate(info, VorbisCommentEntry{entry});
+}
diff --git a/src/tag/MixRamp.hxx b/src/tag/MixRamp.hxx
index 7f384153e..5b4e2dc30 100644
--- a/src/tag/MixRamp.hxx
+++ b/src/tag/MixRamp.hxx
@@ -27,4 +27,7 @@ class MixRampInfo;
bool
ParseMixRampTag(MixRampInfo &info, const char *name, const char *value);
+bool
+ParseMixRampVorbis(MixRampInfo &info, const char *entry);
+
#endif