aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder
diff options
context:
space:
mode:
Diffstat (limited to 'src/decoder')
-rw-r--r--src/decoder/DsdLib.cxx2
-rw-r--r--src/decoder/DsdiffDecoderPlugin.cxx3
-rw-r--r--src/decoder/DsfDecoderPlugin.cxx3
-rw-r--r--src/decoder/FaadDecoderPlugin.cxx169
-rw-r--r--src/decoder/FfmpegDecoderPlugin.cxx1
-rw-r--r--src/decoder/FfmpegMetaData.hxx4
-rw-r--r--src/decoder/FlacCommon.cxx8
-rw-r--r--src/decoder/FlacCommon.hxx1
-rw-r--r--src/decoder/FlacDecoderPlugin.cxx4
-rw-r--r--src/decoder/FlacMetadata.cxx104
-rw-r--r--src/decoder/FlacMetadata.hxx11
-rw-r--r--src/decoder/GmeDecoderPlugin.cxx5
-rw-r--r--src/decoder/MadDecoderPlugin.cxx51
-rw-r--r--src/decoder/MikmodDecoderPlugin.cxx2
-rw-r--r--src/decoder/MpcdecDecoderPlugin.cxx2
-rw-r--r--src/decoder/Mpg123DecoderPlugin.cxx3
-rw-r--r--src/decoder/OggCodec.cxx1
-rw-r--r--src/decoder/OggCodec.hxx3
-rw-r--r--src/decoder/OggFind.hxx1
-rw-r--r--src/decoder/OpusDecoderPlugin.cxx5
-rw-r--r--src/decoder/OpusHead.cxx1
-rw-r--r--src/decoder/PcmDecoderPlugin.cxx2
-rw-r--r--src/decoder/SidplayDecoderPlugin.cxx7
-rw-r--r--src/decoder/VorbisComments.cxx20
-rw-r--r--src/decoder/VorbisComments.hxx2
-rw-r--r--src/decoder/VorbisDecoderPlugin.cxx3
-rw-r--r--src/decoder/VorbisDomain.hxx4
27 files changed, 154 insertions, 268 deletions
diff --git a/src/decoder/DsdLib.cxx b/src/decoder/DsdLib.cxx
index 67cc7e945..b0ba73126 100644
--- a/src/decoder/DsdLib.cxx
+++ b/src/decoder/DsdLib.cxx
@@ -27,8 +27,6 @@
#include "DsdLib.hxx"
#include "DecoderAPI.hxx"
#include "InputStream.hxx"
-#include "util/bit_reverse.h"
-#include "tag/TagHandler.hxx"
#include "tag/TagId3.hxx"
#include "util/Error.hxx"
diff --git a/src/decoder/DsdiffDecoderPlugin.cxx b/src/decoder/DsdiffDecoderPlugin.cxx
index a3c0149b9..bc9fc2353 100644
--- a/src/decoder/DsdiffDecoderPlugin.cxx
+++ b/src/decoder/DsdiffDecoderPlugin.cxx
@@ -38,9 +38,6 @@
#include "DsdLib.hxx"
#include "Log.hxx"
-#include <unistd.h>
-#include <stdio.h> /* for SEEK_SET, SEEK_CUR */
-
struct DsdiffHeader {
DsdId id;
DffDsdUint64 size;
diff --git a/src/decoder/DsfDecoderPlugin.cxx b/src/decoder/DsfDecoderPlugin.cxx
index 5ef94e647..ab96e8ce6 100644
--- a/src/decoder/DsfDecoderPlugin.cxx
+++ b/src/decoder/DsfDecoderPlugin.cxx
@@ -39,9 +39,6 @@
#include "tag/TagHandler.hxx"
#include "Log.hxx"
-#include <unistd.h>
-#include <stdio.h> /* for SEEK_SET, SEEK_CUR */
-
struct DsfMetaData {
unsigned sample_rate, channels;
bool bitreverse;
diff --git a/src/decoder/FaadDecoderPlugin.cxx b/src/decoder/FaadDecoderPlugin.cxx
index 9fd20167d..a37bc88bf 100644
--- a/src/decoder/FaadDecoderPlugin.cxx
+++ b/src/decoder/FaadDecoderPlugin.cxx
@@ -24,6 +24,7 @@
#include "InputStream.hxx"
#include "CheckAudioFormat.hxx"
#include "tag/TagHandler.hxx"
+#include "util/ConstBuffer.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
@@ -66,16 +67,11 @@ adts_check_frame(const unsigned char *data)
static size_t
adts_find_frame(DecoderBuffer *buffer)
{
- size_t length, frame_length;
- bool ret;
-
while (true) {
- const uint8_t *data = (const uint8_t *)
- decoder_buffer_read(buffer, &length);
- if (data == nullptr || length < 8) {
+ auto data = ConstBuffer<uint8_t>::FromVoid(decoder_buffer_read(buffer));
+ if (data.size < 8) {
/* not enough data yet */
- ret = decoder_buffer_fill(buffer);
- if (!ret)
+ if (!decoder_buffer_fill(buffer))
/* failed */
return 0;
@@ -83,21 +79,22 @@ adts_find_frame(DecoderBuffer *buffer)
}
/* find the 0xff marker */
- const uint8_t *p = (const uint8_t *)memchr(data, 0xff, length);
+ const uint8_t *p = (const uint8_t *)
+ memchr(data.data, 0xff, data.size);
if (p == nullptr) {
/* no marker - discard the buffer */
- decoder_buffer_consume(buffer, length);
+ decoder_buffer_clear(buffer);
continue;
}
- if (p > data) {
+ if (p > data.data) {
/* discard data before 0xff */
- decoder_buffer_consume(buffer, p - data);
+ decoder_buffer_consume(buffer, p - data.data);
continue;
}
/* is it a frame? */
- frame_length = adts_check_frame(data);
+ size_t frame_length = adts_check_frame(data.data);
if (frame_length == 0) {
/* it's just some random 0xff byte; discard it
and continue searching */
@@ -105,19 +102,15 @@ adts_find_frame(DecoderBuffer *buffer)
continue;
}
- if (length < frame_length) {
+ if (data.size < frame_length) {
/* available buffer size is smaller than the
frame will be - attempt to read more
data */
- ret = decoder_buffer_fill(buffer);
- if (!ret) {
+ if (!decoder_buffer_fill(buffer)) {
/* not enough data; discard this frame
to prevent a possible buffer
overflow */
- data = (const uint8_t *)
- decoder_buffer_read(buffer, &length);
- if (data != nullptr)
- decoder_buffer_consume(buffer, length);
+ decoder_buffer_clear(buffer);
}
continue;
@@ -131,31 +124,27 @@ adts_find_frame(DecoderBuffer *buffer)
static float
adts_song_duration(DecoderBuffer *buffer)
{
- unsigned int frames, frame_length;
unsigned sample_rate = 0;
- float frames_per_second;
/* Read all frames to ensure correct time and bitrate */
- for (frames = 0;; frames++) {
- frame_length = adts_find_frame(buffer);
+ unsigned frames = 0;
+ for (;; frames++) {
+ unsigned frame_length = adts_find_frame(buffer);
if (frame_length == 0)
break;
-
if (frames == 0) {
- size_t buffer_length;
- const uint8_t *data = (const uint8_t *)
- decoder_buffer_read(buffer, &buffer_length);
- assert(data != nullptr);
- assert(frame_length <= buffer_length);
+ auto data = ConstBuffer<uint8_t>::FromVoid(decoder_buffer_read(buffer));
+ assert(!data.IsEmpty());
+ assert(frame_length <= data.size);
- sample_rate = adts_sample_rates[(data[2] & 0x3c) >> 2];
+ sample_rate = adts_sample_rates[(data.data[2] & 0x3c) >> 2];
}
decoder_buffer_consume(buffer, frame_length);
}
- frames_per_second = (float)sample_rate / 1024.0;
+ float frames_per_second = (float)sample_rate / 1024.0;
if (frames_per_second <= 0)
return -1;
@@ -165,66 +154,58 @@ adts_song_duration(DecoderBuffer *buffer)
static float
faad_song_duration(DecoderBuffer *buffer, InputStream &is)
{
- size_t fileread;
- size_t tagsize;
- size_t length;
- bool success;
-
const auto size = is.GetSize();
- fileread = size >= 0 ? size : 0;
+ const size_t fileread = size >= 0 ? size : 0;
decoder_buffer_fill(buffer);
- const uint8_t *data = (const uint8_t *)
- decoder_buffer_read(buffer, &length);
- if (data == nullptr)
+ auto data = ConstBuffer<uint8_t>::FromVoid(decoder_buffer_read(buffer));
+ if (data.IsEmpty())
return -1;
- tagsize = 0;
- if (length >= 10 && !memcmp(data, "ID3", 3)) {
+ size_t tagsize = 0;
+ if (data.size >= 10 && !memcmp(data.data, "ID3", 3)) {
/* skip the ID3 tag */
- tagsize = (data[6] << 21) | (data[7] << 14) |
- (data[8] << 7) | (data[9] << 0);
+ tagsize = (data.data[6] << 21) | (data.data[7] << 14) |
+ (data.data[8] << 7) | (data.data[9] << 0);
tagsize += 10;
- success = decoder_buffer_skip(buffer, tagsize) &&
+ bool success = decoder_buffer_skip(buffer, tagsize) &&
decoder_buffer_fill(buffer);
if (!success)
return -1;
- data = (const uint8_t *)decoder_buffer_read(buffer, &length);
- if (data == nullptr)
+ data = ConstBuffer<uint8_t>::FromVoid(decoder_buffer_read(buffer));
+ if (data.IsEmpty())
return -1;
}
- if (is.IsSeekable() && length >= 2 &&
- data[0] == 0xFF && ((data[1] & 0xF6) == 0xF0)) {
+ if (is.IsSeekable() && data.size >= 2 &&
+ data.data[0] == 0xFF && ((data.data[1] & 0xF6) == 0xF0)) {
/* obtain the duration from the ADTS header */
float song_length = adts_song_duration(buffer);
is.LockSeek(tagsize, SEEK_SET, IgnoreError());
- data = (const uint8_t *)decoder_buffer_read(buffer, &length);
- if (data != nullptr)
- decoder_buffer_consume(buffer, length);
+ decoder_buffer_clear(buffer);
decoder_buffer_fill(buffer);
return song_length;
- } else if (length >= 5 && memcmp(data, "ADIF", 4) == 0) {
+ } else if (data.size >= 5 && memcmp(data.data, "ADIF", 4) == 0) {
/* obtain the duration from the ADIF header */
unsigned bit_rate;
- size_t skip_size = (data[4] & 0x80) ? 9 : 0;
+ size_t skip_size = (data.data[4] & 0x80) ? 9 : 0;
- if (8 + skip_size > length)
+ if (8 + skip_size > data.size)
/* not enough data yet; skip parsing this
header */
return -1;
- bit_rate = ((data[4 + skip_size] & 0x0F) << 19) |
- (data[5 + skip_size] << 11) |
- (data[6 + skip_size] << 3) |
- (data[7 + skip_size] & 0xE0);
+ bit_rate = ((data.data[4 + skip_size] & 0x0F) << 19) |
+ (data.data[5 + skip_size] << 11) |
+ (data.data[6 + skip_size] << 3) |
+ (data.data[7 + skip_size] & 0xE0);
if (fileread != 0 && bit_rate != 0)
return fileread * 8.0 / bit_rate;
@@ -242,9 +223,7 @@ static bool
faad_decoder_init(NeAACDecHandle decoder, DecoderBuffer *buffer,
AudioFormat &audio_format, Error &error)
{
- int32_t nbytes;
uint32_t sample_rate;
- uint8_t channels;
#ifdef HAVE_FAAD_LONG
/* neaacdec.h declares all arguments as "unsigned long", but
internally expects uint32_t pointers. To avoid gcc
@@ -254,19 +233,18 @@ faad_decoder_init(NeAACDecHandle decoder, DecoderBuffer *buffer,
uint32_t *sample_rate_p = &sample_rate;
#endif
- size_t length;
- const unsigned char *data = (const unsigned char *)
- decoder_buffer_read(buffer, &length);
- if (data == nullptr) {
+ auto data = ConstBuffer<uint8_t>::FromVoid(decoder_buffer_read(buffer));
+ if (data.IsEmpty()) {
error.Set(faad_decoder_domain, "Empty file");
return false;
}
- nbytes = NeAACDecInit(decoder,
- /* deconst hack, libfaad requires this */
- const_cast<unsigned char *>(data),
- length,
- sample_rate_p, &channels);
+ uint8_t channels;
+ int32_t nbytes = NeAACDecInit(decoder,
+ /* deconst hack, libfaad requires this */
+ const_cast<uint8_t *>(data.data),
+ data.size,
+ sample_rate_p, &channels);
if (nbytes < 0) {
error.Set(faad_decoder_domain, "Not an AAC stream");
return false;
@@ -286,16 +264,14 @@ static const void *
faad_decoder_decode(NeAACDecHandle decoder, DecoderBuffer *buffer,
NeAACDecFrameInfo *frame_info)
{
- size_t length;
- const unsigned char *data = (const unsigned char *)
- decoder_buffer_read(buffer, &length);
- if (data == nullptr)
+ auto data = ConstBuffer<uint8_t>::FromVoid(decoder_buffer_read(buffer));
+ if (data.IsEmpty())
return nullptr;
return NeAACDecDecode(decoder, frame_info,
/* deconst hack, libfaad requires this */
- const_cast<unsigned char *>(data),
- length);
+ const_cast<uint8_t *>(data.data),
+ data.size);
}
/**
@@ -306,17 +282,12 @@ faad_decoder_decode(NeAACDecHandle decoder, DecoderBuffer *buffer,
static float
faad_get_file_time_float(InputStream &is)
{
- DecoderBuffer *buffer;
- float length;
-
- buffer = decoder_buffer_new(nullptr, is,
- FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS);
- length = faad_song_duration(buffer, is);
+ DecoderBuffer *buffer =
+ decoder_buffer_new(nullptr, is,
+ FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS);
+ float length = faad_song_duration(buffer, is);
if (length < 0) {
- bool ret;
- AudioFormat audio_format;
-
NeAACDecHandle decoder = NeAACDecOpen();
NeAACDecConfigurationPtr config =
@@ -326,9 +297,9 @@ faad_get_file_time_float(InputStream &is)
decoder_buffer_fill(buffer);
- ret = faad_decoder_init(decoder, buffer, audio_format,
- IgnoreError());
- if (ret)
+ AudioFormat audio_format;
+ if (faad_decoder_init(decoder, buffer, audio_format,
+ IgnoreError()))
length = 0;
NeAACDecClose(decoder);
@@ -359,15 +330,10 @@ faad_get_file_time(InputStream &is)
static void
faad_stream_decode(Decoder &mpd_decoder, InputStream &is)
{
- float total_time = 0;
- AudioFormat audio_format;
- bool ret;
- uint16_t bit_rate = 0;
- DecoderBuffer *buffer;
-
- buffer = decoder_buffer_new(&mpd_decoder, is,
- FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS);
- total_time = faad_song_duration(buffer, is);
+ DecoderBuffer *buffer =
+ decoder_buffer_new(&mpd_decoder, is,
+ FAAD_MIN_STREAMSIZE * AAC_MAX_CHANNELS);
+ const float total_time = faad_song_duration(buffer, is);
/* create the libfaad decoder */
@@ -389,8 +355,8 @@ faad_stream_decode(Decoder &mpd_decoder, InputStream &is)
/* initialize it */
Error error;
- ret = faad_decoder_init(decoder, buffer, audio_format, error);
- if (!ret) {
+ AudioFormat audio_format;
+ if (!faad_decoder_init(decoder, buffer, audio_format, error)) {
LogError(error);
NeAACDecClose(decoder);
decoder_buffer_free(buffer);
@@ -404,6 +370,7 @@ faad_stream_decode(Decoder &mpd_decoder, InputStream &is)
/* the decoder loop */
DecoderCommand cmd;
+ unsigned bit_rate = 0;
do {
size_t frame_size;
const void *decoded;
@@ -483,7 +450,7 @@ static const char *const faad_mime_types[] = {
"audio/aac", "audio/aacp", nullptr
};
-const struct DecoderPlugin faad_decoder_plugin = {
+const DecoderPlugin faad_decoder_plugin = {
"faad",
nullptr,
nullptr,
diff --git a/src/decoder/FfmpegDecoderPlugin.cxx b/src/decoder/FfmpegDecoderPlugin.cxx
index 47e1a3384..01b551bb1 100644
--- a/src/decoder/FfmpegDecoderPlugin.cxx
+++ b/src/decoder/FfmpegDecoderPlugin.cxx
@@ -38,7 +38,6 @@ extern "C" {
#include <libavutil/avutil.h>
#include <libavutil/log.h>
#include <libavutil/mathematics.h>
-#include <libavutil/dict.h>
}
#include <assert.h>
diff --git a/src/decoder/FfmpegMetaData.hxx b/src/decoder/FfmpegMetaData.hxx
index 0fd73df04..998cdf5a8 100644
--- a/src/decoder/FfmpegMetaData.hxx
+++ b/src/decoder/FfmpegMetaData.hxx
@@ -21,8 +21,6 @@
#define MPD_FFMPEG_METADATA_HXX
extern "C" {
-#include <libavformat/avformat.h>
-#include <libavutil/avutil.h>
#include <libavutil/dict.h>
}
@@ -35,6 +33,6 @@ struct tag_handler;
void
ffmpeg_scan_dictionary(AVDictionary *dict,
- const struct tag_handler *handler, void *handler_ctx);
+ const tag_handler *handler, void *handler_ctx);
#endif
diff --git a/src/decoder/FlacCommon.cxx b/src/decoder/FlacCommon.cxx
index e4b906c12..b0921056a 100644
--- a/src/decoder/FlacCommon.cxx
+++ b/src/decoder/FlacCommon.cxx
@@ -25,14 +25,10 @@
#include "FlacCommon.hxx"
#include "FlacMetadata.hxx"
#include "FlacPcm.hxx"
-#include "MixRampInfo.hxx"
#include "CheckAudioFormat.hxx"
#include "util/Error.hxx"
-#include "util/Domain.hxx"
#include "Log.hxx"
-#include <assert.h>
-
flac_data::flac_data(Decoder &_decoder,
InputStream &_input_stream)
:FlacInput(_input_stream, &_decoder),
@@ -107,8 +103,8 @@ void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
decoder_mixramp(data->decoder, flac_parse_mixramp(block));
- flac_vorbis_comments_to_tag(data->tag,
- &block->data.vorbis_comment);
+ data->tag = flac_vorbis_comments_to_tag(&block->data.vorbis_comment);
+ break;
default:
break;
diff --git a/src/decoder/FlacCommon.hxx b/src/decoder/FlacCommon.hxx
index de000dfa1..0f6b09973 100644
--- a/src/decoder/FlacCommon.hxx
+++ b/src/decoder/FlacCommon.hxx
@@ -29,7 +29,6 @@
#include "pcm/PcmBuffer.hxx"
#include <FLAC/stream_decoder.h>
-#include <FLAC/metadata.h>
struct flac_data : public FlacInput {
PcmBuffer buffer;
diff --git a/src/decoder/FlacDecoderPlugin.cxx b/src/decoder/FlacDecoderPlugin.cxx
index 1b5734434..2c811a8e0 100644
--- a/src/decoder/FlacDecoderPlugin.cxx
+++ b/src/decoder/FlacDecoderPlugin.cxx
@@ -26,10 +26,6 @@
#include "util/Error.hxx"
#include "Log.hxx"
-#include <glib.h>
-
-#include <assert.h>
-
#if !defined(FLAC_API_VERSION_CURRENT) || FLAC_API_VERSION_CURRENT <= 7
#error libFLAC is too old
#endif
diff --git a/src/decoder/FlacMetadata.cxx b/src/decoder/FlacMetadata.cxx
index 17cc4cd8d..96dbf2db0 100644
--- a/src/decoder/FlacMetadata.cxx
+++ b/src/decoder/FlacMetadata.cxx
@@ -21,43 +21,45 @@
#include "FlacMetadata.hxx"
#include "XiphTags.hxx"
#include "MixRampInfo.hxx"
-#include "tag/Tag.hxx"
#include "tag/TagHandler.hxx"
#include "tag/TagTable.hxx"
#include "tag/TagBuilder.hxx"
+#include "tag/Tag.hxx"
#include "ReplayGainInfo.hxx"
#include "util/ASCII.hxx"
+#include "util/SplitString.hxx"
-#include <glib.h>
-
-#include <assert.h>
#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;
+}
+
static bool
flac_find_float_comment(const FLAC__StreamMetadata *block,
const char *cmnt, float *fl)
{
- int offset;
- size_t pos;
- int len;
- unsigned char tmp, *p;
-
- offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0,
- cmnt);
- if (offset < 0)
- return false;
-
- pos = strlen(cmnt) + 1; /* 1 is for '=' */
- len = block->data.vorbis_comment.comments[offset].length - pos;
- if (len <= 0)
+ const char *value = vorbis_comment_value(block, cmnt);
+ if (value == nullptr)
return false;
- p = &block->data.vorbis_comment.comments[offset].entry[pos];
- tmp = p[len];
- p[len] = '\0';
- *fl = (float)atof((char *)p);
- p[len] = tmp;
-
+ *fl = (float)atof(value);
return true;
}
@@ -88,23 +90,11 @@ 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;
-
- offset = FLAC__metadata_object_vorbiscomment_find_entry_from(block, 0,
- cmnt);
- if (offset < 0)
+ const char *value = vorbis_comment_value(block, cmnt);
+ if (value == nullptr)
return std::string();
- pos = strlen(cmnt) + 1; /* 1 is for '=' */
- len = block->data.vorbis_comment.comments[offset].length - pos;
- if (len <= 0)
- return std::string();
-
- p = &block->data.vorbis_comment.comments[offset].entry[pos];
- return std::string((const char *)p, len);
+ return std::string(value);
}
MixRampInfo
@@ -118,21 +108,19 @@ flac_parse_mixramp(const FLAC__StreamMetadata *block)
/**
* Checks if the specified name matches the entry's name, and if yes,
- * returns the comment value (not null-temrinated).
+ * returns the comment value;
*/
static const char *
flac_comment_value(const FLAC__StreamMetadata_VorbisComment_Entry *entry,
- const char *name, size_t *length_r)
+ const char *name)
{
size_t name_length = strlen(name);
const char *comment = (const char*)entry->entry;
- if (entry->length <= name_length ||
- !StringEqualsCaseASCII(comment, name, name_length))
+ if (!StringEqualsCaseASCII(comment, name, name_length))
return nullptr;
if (comment[name_length] == '=') {
- *length_r = entry->length - name_length - 1;
return comment + name_length + 1;
}
@@ -148,14 +136,9 @@ flac_copy_comment(const FLAC__StreamMetadata_VorbisComment_Entry *entry,
const char *name, TagType tag_type,
const struct tag_handler *handler, void *handler_ctx)
{
- const char *value;
- size_t value_length;
-
- value = flac_comment_value(entry, name, &value_length);
+ const char *value = flac_comment_value(entry, name);
if (value != nullptr) {
- char *p = g_strndup(value, value_length);
- tag_handler_invoke_tag(handler, handler_ctx, tag_type, p);
- g_free(p);
+ tag_handler_invoke_tag(handler, handler_ctx, tag_type, value);
return true;
}
@@ -167,16 +150,12 @@ flac_scan_comment(const FLAC__StreamMetadata_VorbisComment_Entry *entry,
const struct tag_handler *handler, void *handler_ctx)
{
if (handler->pair != nullptr) {
- char *name = g_strdup((const char*)entry->entry);
- char *value = strchr(name, '=');
-
- if (value != nullptr && value > name) {
- *value++ = 0;
+ const char *comment = (const char *)entry->entry;
+ const SplitString split(comment, '=');
+ if (split.IsDefined() && !split.IsEmpty())
tag_handler_invoke_pair(handler, handler_ctx,
- name, value);
- }
-
- g_free(name);
+ split.GetFirst(),
+ split.GetSecond());
}
for (const struct tag_table *i = xiph_tags; i->name != nullptr; ++i)
@@ -221,13 +200,12 @@ flac_scan_metadata(const FLAC__StreamMetadata *block,
}
}
-void
-flac_vorbis_comments_to_tag(Tag &tag,
- const FLAC__StreamMetadata_VorbisComment *comment)
+Tag
+flac_vorbis_comments_to_tag(const FLAC__StreamMetadata_VorbisComment *comment)
{
TagBuilder tag_builder;
flac_scan_comments(comment, &add_tag_handler, &tag_builder);
- tag_builder.Commit(tag);
+ return tag_builder.Commit();
}
void
diff --git a/src/decoder/FlacMetadata.hxx b/src/decoder/FlacMetadata.hxx
index 96c61b8e6..33ef17e72 100644
--- a/src/decoder/FlacMetadata.hxx
+++ b/src/decoder/FlacMetadata.hxx
@@ -27,6 +27,7 @@
#include <assert.h>
+struct tag_handler;
class MixRampInfo;
class FlacMetadataChain {
@@ -81,7 +82,7 @@ public:
return FLAC__Metadata_ChainStatusString[GetStatus()];
}
- void Scan(const struct tag_handler *handler, void *handler_ctx);
+ void Scan(const tag_handler *handler, void *handler_ctx);
};
class FLACMetadataIterator {
@@ -110,7 +111,6 @@ public:
}
};
-struct tag_handler;
struct Tag;
struct ReplayGainInfo;
@@ -130,12 +130,11 @@ flac_parse_replay_gain(ReplayGainInfo &rgi,
MixRampInfo
flac_parse_mixramp(const FLAC__StreamMetadata *block);
-void
-flac_vorbis_comments_to_tag(Tag &tag,
- const FLAC__StreamMetadata_VorbisComment *comment);
+Tag
+flac_vorbis_comments_to_tag(const FLAC__StreamMetadata_VorbisComment *comment);
void
flac_scan_metadata(const FLAC__StreamMetadata *block,
- const struct tag_handler *handler, void *handler_ctx);
+ const tag_handler *handler, void *handler_ctx);
#endif
diff --git a/src/decoder/GmeDecoderPlugin.cxx b/src/decoder/GmeDecoderPlugin.cxx
index 815fd8d69..aafc8f07d 100644
--- a/src/decoder/GmeDecoderPlugin.cxx
+++ b/src/decoder/GmeDecoderPlugin.cxx
@@ -22,6 +22,7 @@
#include "DecoderAPI.hxx"
#include "CheckAudioFormat.hxx"
#include "tag/TagHandler.hxx"
+#include "util/Alloc.hxx"
#include "util/FormatString.hxx"
#include "util/UriUtil.hxx"
#include "util/Error.hxx"
@@ -53,7 +54,7 @@ static char *
get_container_name(const char *path_fs)
{
const char *subtune_suffix = uri_get_suffix(path_fs);
- char *path_container = g_strdup(path_fs);
+ char *path_container = xstrdup(path_fs);
char pat[64];
snprintf(pat, sizeof(pat), "%s%s",
@@ -137,7 +138,7 @@ gme_file_decode(Decoder &decoder, const char *path_fs)
Music_Emu *emu;
const char *gme_err =
gme_open_file(path_container, &emu, GME_SAMPLE_RATE);
- g_free(path_container);
+ free(path_container);
if (gme_err != nullptr) {
LogWarning(gme_domain, gme_err);
return;
diff --git a/src/decoder/MadDecoderPlugin.cxx b/src/decoder/MadDecoderPlugin.cxx
index 9dd86c55f..76eead96d 100644
--- a/src/decoder/MadDecoderPlugin.cxx
+++ b/src/decoder/MadDecoderPlugin.cxx
@@ -26,23 +26,23 @@
#include "tag/TagRva2.hxx"
#include "tag/TagHandler.hxx"
#include "CheckAudioFormat.hxx"
+#include "util/StringUtil.hxx"
#include "util/ASCII.hxx"
#include "util/Error.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
-#include <assert.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <glib.h>
#include <mad.h>
#ifdef HAVE_ID3TAG
#include <id3tag.h>
#endif
+#include <assert.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
#define FRAMES_CUSHION 2000
#define READ_BUFFER_SIZE 40960
@@ -349,24 +349,14 @@ MadDecoder::ParseId3(size_t tagsize, Tag **mpd_tag)
id3_data = stream.this_frame;
mad_stream_skip(&(stream), tagsize);
} else {
- allocated = (id3_byte_t *)g_malloc(tagsize);
+ allocated = new id3_byte_t[tagsize];
memcpy(allocated, stream.this_frame, count);
mad_stream_skip(&(stream), count);
- while (count < tagsize) {
- size_t len;
-
- len = decoder_read(decoder, input_stream,
- allocated + count, tagsize - count);
- if (len == 0)
- break;
- else
- count += len;
- }
-
- if (count != tagsize) {
+ if (!decoder_read_full(decoder, input_stream,
+ allocated + count, tagsize - count)) {
LogDebug(mad_domain, "error parsing ID3 tag");
- g_free(allocated);
+ delete[] allocated;
return;
}
@@ -375,7 +365,7 @@ MadDecoder::ParseId3(size_t tagsize, Tag **mpd_tag)
id3_tag = id3_tag_parse(id3_data, tagsize);
if (id3_tag == nullptr) {
- g_free(allocated);
+ delete[] allocated;
return;
}
@@ -400,7 +390,7 @@ MadDecoder::ParseId3(size_t tagsize, Tag **mpd_tag)
id3_tag_delete(id3_tag);
- g_free(allocated);
+ delete[] allocated;
#else /* !HAVE_ID3TAG */
(void)mpd_tag;
@@ -413,20 +403,7 @@ MadDecoder::ParseId3(size_t tagsize, Tag **mpd_tag)
mad_stream_skip(&stream, tagsize);
} else {
mad_stream_skip(&stream, count);
-
- while (count < tagsize) {
- size_t len = tagsize - count;
- char ignored[1024];
- if (len > sizeof(ignored))
- len = sizeof(ignored);
-
- len = decoder_read(decoder, input_stream,
- ignored, len);
- if (len == 0)
- break;
- else
- count += len;
- }
+ decoder_skip(decoder, input_stream, tagsize - count);
}
#endif
}
@@ -690,7 +667,7 @@ parse_lame(struct lame *lame, struct mad_bitptr *ptr, int *bitlen)
/* This is technically incorrect, since the encoder might not be lame.
* But there's no other way to determine if this is a lame tag, and we
* wouldn't want to go reading a tag that's not there. */
- if (!g_str_has_prefix(lame->encoder, "LAME"))
+ if (!StringStartsWith(lame->encoder, "LAME"))
return false;
if (sscanf(lame->encoder+4, "%u.%u",
diff --git a/src/decoder/MikmodDecoderPlugin.cxx b/src/decoder/MikmodDecoderPlugin.cxx
index 34381aafa..93a3cc280 100644
--- a/src/decoder/MikmodDecoderPlugin.cxx
+++ b/src/decoder/MikmodDecoderPlugin.cxx
@@ -25,8 +25,8 @@
#include "util/Domain.hxx"
#include "Log.hxx"
-#include <glib.h>
#include <mikmod.h>
+
#include <assert.h>
static constexpr Domain mikmod_domain("mikmod");
diff --git a/src/decoder/MpcdecDecoderPlugin.cxx b/src/decoder/MpcdecDecoderPlugin.cxx
index dc258623c..620bfad30 100644
--- a/src/decoder/MpcdecDecoderPlugin.cxx
+++ b/src/decoder/MpcdecDecoderPlugin.cxx
@@ -30,8 +30,6 @@
#include <mpc/mpcdec.h>
-#include <assert.h>
-#include <unistd.h>
#include <math.h>
struct mpc_decoder_data {
diff --git a/src/decoder/Mpg123DecoderPlugin.cxx b/src/decoder/Mpg123DecoderPlugin.cxx
index df23f7847..895c8b865 100644
--- a/src/decoder/Mpg123DecoderPlugin.cxx
+++ b/src/decoder/Mpg123DecoderPlugin.cxx
@@ -26,9 +26,8 @@
#include "util/Domain.hxx"
#include "Log.hxx"
-#include <glib.h>
-
#include <mpg123.h>
+
#include <stdio.h>
static constexpr Domain mpg123_domain("mpg123");
diff --git a/src/decoder/OggCodec.cxx b/src/decoder/OggCodec.cxx
index 565dbafcf..cc6cd20c0 100644
--- a/src/decoder/OggCodec.cxx
+++ b/src/decoder/OggCodec.cxx
@@ -23,6 +23,7 @@
#include "config.h"
#include "OggCodec.hxx"
+#include "DecoderAPI.hxx"
#include <string.h>
diff --git a/src/decoder/OggCodec.hxx b/src/decoder/OggCodec.hxx
index 857871607..13eab2cdb 100644
--- a/src/decoder/OggCodec.hxx
+++ b/src/decoder/OggCodec.hxx
@@ -24,7 +24,8 @@
#ifndef MPD_OGG_CODEC_HXX
#define MPD_OGG_CODEC_HXX
-#include "DecoderAPI.hxx"
+struct Decoder;
+struct InputStream;
enum ogg_codec {
OGG_CODEC_UNKNOWN,
diff --git a/src/decoder/OggFind.hxx b/src/decoder/OggFind.hxx
index ad51ccdf3..a329e42a4 100644
--- a/src/decoder/OggFind.hxx
+++ b/src/decoder/OggFind.hxx
@@ -25,7 +25,6 @@
#include <ogg/ogg.h>
-struct InputStream;
class OggSyncState;
/**
diff --git a/src/decoder/OpusDecoderPlugin.cxx b/src/decoder/OpusDecoderPlugin.cxx
index f3d7b342e..04f549f4f 100644
--- a/src/decoder/OpusDecoderPlugin.cxx
+++ b/src/decoder/OpusDecoderPlugin.cxx
@@ -22,12 +22,10 @@
#include "OpusDomain.hxx"
#include "OpusHead.hxx"
#include "OpusTags.hxx"
-#include "OggUtil.hxx"
#include "OggFind.hxx"
#include "OggSyncState.hxx"
#include "DecoderAPI.hxx"
#include "OggCodec.hxx"
-#include "CheckAudioFormat.hxx"
#include "tag/TagHandler.hxx"
#include "tag/TagBuilder.hxx"
#include "InputStream.hxx"
@@ -294,8 +292,7 @@ MPDOpusDecoder::HandleTags(const ogg_packet &packet)
!tag_builder.IsEmpty()) {
decoder_replay_gain(decoder, &rgi);
- Tag tag;
- tag_builder.Commit(tag);
+ Tag tag = tag_builder.Commit();
cmd = decoder_tag(decoder, input_stream, std::move(tag));
} else
cmd = decoder_get_command(decoder);
diff --git a/src/decoder/OpusHead.cxx b/src/decoder/OpusHead.cxx
index 0417d3905..dd2b125b0 100644
--- a/src/decoder/OpusHead.cxx
+++ b/src/decoder/OpusHead.cxx
@@ -21,7 +21,6 @@
#include "OpusHead.hxx"
#include <stdint.h>
-#include <string.h>
struct OpusHead {
char signature[8];
diff --git a/src/decoder/PcmDecoderPlugin.cxx b/src/decoder/PcmDecoderPlugin.cxx
index dbc38fb76..0bef8dc69 100644
--- a/src/decoder/PcmDecoderPlugin.cxx
+++ b/src/decoder/PcmDecoderPlugin.cxx
@@ -25,8 +25,6 @@
#include "util/ByteReverse.hxx"
#include "Log.hxx"
-#include <glib.h>
-#include <unistd.h>
#include <string.h>
#include <stdio.h> /* for SEEK_SET */
diff --git a/src/decoder/SidplayDecoderPlugin.cxx b/src/decoder/SidplayDecoderPlugin.cxx
index 160337594..9b3a4ad40 100644
--- a/src/decoder/SidplayDecoderPlugin.cxx
+++ b/src/decoder/SidplayDecoderPlugin.cxx
@@ -21,6 +21,7 @@
#include "SidplayDecoderPlugin.hxx"
#include "../DecoderAPI.hxx"
#include "tag/TagHandler.hxx"
+#include "util/Alloc.hxx"
#include "util/Domain.hxx"
#include "system/ByteOrder.hxx"
#include "Log.hxx"
@@ -121,7 +122,7 @@ sidplay_finish()
static char *
get_container_name(const char *path_fs)
{
- char *path_container=g_strdup(path_fs);
+ char *path_container = strdup(path_fs);
if(!g_pattern_match(path_with_subtune,
strlen(path_container), path_container, nullptr))
@@ -163,9 +164,9 @@ get_song_length(const char *path_fs)
if (songlength_database == nullptr)
return -1;
- gchar *sid_file=get_container_name(path_fs);
+ char *sid_file = get_container_name(path_fs);
SidTuneMod tune(sid_file);
- g_free(sid_file);
+ free(sid_file);
if(!tune) {
LogWarning(sidplay_domain,
"failed to load file for calculating md5 sum");
diff --git a/src/decoder/VorbisComments.cxx b/src/decoder/VorbisComments.cxx
index d4f019b58..e6a99ca6b 100644
--- a/src/decoder/VorbisComments.cxx
+++ b/src/decoder/VorbisComments.cxx
@@ -20,16 +20,13 @@
#include "config.h"
#include "VorbisComments.hxx"
#include "XiphTags.hxx"
-#include "tag/Tag.hxx"
#include "tag/TagTable.hxx"
#include "tag/TagHandler.hxx"
#include "tag/TagBuilder.hxx"
#include "ReplayGainInfo.hxx"
#include "util/ASCII.hxx"
+#include "util/SplitString.hxx"
-#include <glib.h>
-
-#include <assert.h>
#include <stddef.h>
#include <string.h>
#include <stdlib.h>
@@ -104,16 +101,11 @@ vorbis_scan_comment(const char *comment,
const struct tag_handler *handler, void *handler_ctx)
{
if (handler->pair != nullptr) {
- char *name = g_strdup((const char*)comment);
- char *value = strchr(name, '=');
-
- if (value != nullptr && value > name) {
- *value++ = 0;
+ const SplitString split(comment, '=');
+ if (split.IsDefined() && !split.IsEmpty())
tag_handler_invoke_pair(handler, handler_ctx,
- name, value);
- }
-
- g_free(name);
+ split.GetFirst(),
+ split.GetSecond());
}
for (const struct tag_table *i = xiph_tags; i->name != nullptr; ++i)
@@ -145,5 +137,5 @@ vorbis_comments_to_tag(char **comments)
vorbis_comments_scan(comments, &add_tag_handler, &tag_builder);
return tag_builder.IsEmpty()
? nullptr
- : tag_builder.Commit();
+ : tag_builder.CommitNew();
}
diff --git a/src/decoder/VorbisComments.hxx b/src/decoder/VorbisComments.hxx
index e5a48ef6b..f537bf30f 100644
--- a/src/decoder/VorbisComments.hxx
+++ b/src/decoder/VorbisComments.hxx
@@ -31,7 +31,7 @@ vorbis_comments_to_replay_gain(ReplayGainInfo &rgi, char **comments);
void
vorbis_comments_scan(char **comments,
- const struct tag_handler *handler, void *handler_ctx);
+ const tag_handler *handler, void *handler_ctx);
Tag *
vorbis_comments_to_tag(char **comments);
diff --git a/src/decoder/VorbisDecoderPlugin.cxx b/src/decoder/VorbisDecoderPlugin.cxx
index 4d3e48528..a637241b1 100644
--- a/src/decoder/VorbisDecoderPlugin.cxx
+++ b/src/decoder/VorbisDecoderPlugin.cxx
@@ -25,9 +25,7 @@
#include "InputStream.hxx"
#include "OggCodec.hxx"
#include "util/Error.hxx"
-#include "util/UriUtil.hxx"
#include "util/Macros.hxx"
-#include "system/ByteOrder.hxx"
#include "CheckAudioFormat.hxx"
#include "tag/TagHandler.hxx"
#include "Log.hxx"
@@ -48,7 +46,6 @@
#define ov_time_seek_page(VF, S) (ov_time_seek_page(VF, (S)*1000))
#endif /* HAVE_TREMOR */
-#include <assert.h>
#include <errno.h>
struct vorbis_input_stream {
diff --git a/src/decoder/VorbisDomain.hxx b/src/decoder/VorbisDomain.hxx
index a35edd041..7946bf52a 100644
--- a/src/decoder/VorbisDomain.hxx
+++ b/src/decoder/VorbisDomain.hxx
@@ -22,6 +22,8 @@
#include "check.h"
-extern const class Domain vorbis_domain;
+class Domain;
+
+extern const Domain vorbis_domain;
#endif