aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/decoder/faad_plugin.c8
-rw-r--r--src/decoder/ffmpeg_plugin.c7
-rw-r--r--src/decoder_buffer.c26
-rw-r--r--src/decoder_buffer.h10
4 files changed, 47 insertions, 4 deletions
diff --git a/src/decoder/faad_plugin.c b/src/decoder/faad_plugin.c
index 1b8b2b784..516f741c7 100644
--- a/src/decoder/faad_plugin.c
+++ b/src/decoder/faad_plugin.c
@@ -162,6 +162,7 @@ faad_song_duration(struct decoder_buffer *buffer, struct input_stream *is)
size_t tagsize;
const unsigned char *data;
size_t length;
+ bool success;
fileread = is->size >= 0 ? is->size : 0;
@@ -179,8 +180,11 @@ faad_song_duration(struct decoder_buffer *buffer, struct input_stream *is)
tagsize += 10;
- decoder_buffer_consume(buffer, tagsize);
- decoder_buffer_fill(buffer);
+ success = decoder_buffer_skip(buffer, tagsize) &&
+ decoder_buffer_fill(buffer);
+ if (!success)
+ return -1;
+
data = decoder_buffer_read(buffer, &length);
if (data == NULL)
return -1;
diff --git a/src/decoder/ffmpeg_plugin.c b/src/decoder/ffmpeg_plugin.c
index e6646f649..6bead85fd 100644
--- a/src/decoder/ffmpeg_plugin.c
+++ b/src/decoder/ffmpeg_plugin.c
@@ -339,7 +339,7 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
}
#if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(31<<8)+0)
-static void
+static bool
ffmpeg_copy_metadata(struct tag *tag, AVMetadata *m,
enum tag_type type, const char *name)
{
@@ -347,6 +347,7 @@ ffmpeg_copy_metadata(struct tag *tag, AVMetadata *m,
while ((mt = av_metadata_get(m, name, mt, 0)) != NULL)
tag_add_item(tag, type, mt->value);
+ return mt != NULL;
}
#endif
@@ -363,7 +364,9 @@ static bool ffmpeg_tag_internal(struct ffmpeg_context *ctx)
av_metadata_conv(f, NULL, f->iformat->metadata_conv);
ffmpeg_copy_metadata(tag, f->metadata, TAG_ITEM_TITLE, "title");
- ffmpeg_copy_metadata(tag, f->metadata, TAG_ITEM_ARTIST, "author");
+ if (!ffmpeg_copy_metadata(tag, f->metadata, TAG_ITEM_ARTIST, "author"))
+ ffmpeg_copy_metadata(tag, f->metadata,
+ TAG_ITEM_ARTIST, "artist");
ffmpeg_copy_metadata(tag, f->metadata, TAG_ITEM_ALBUM, "album");
ffmpeg_copy_metadata(tag, f->metadata, TAG_ITEM_COMMENT, "comment");
ffmpeg_copy_metadata(tag, f->metadata, TAG_ITEM_GENRE, "genre");
diff --git a/src/decoder_buffer.c b/src/decoder_buffer.c
index 76e9126ef..b6fa90004 100644
--- a/src/decoder_buffer.c
+++ b/src/decoder_buffer.c
@@ -138,3 +138,29 @@ decoder_buffer_consume(struct decoder_buffer *buffer, size_t nbytes)
assert(buffer->consumed <= buffer->length);
}
+
+bool
+decoder_buffer_skip(struct decoder_buffer *buffer, size_t nbytes)
+{
+ size_t length;
+ const void *data;
+ bool success;
+
+ /* this could probably be optimized by seeking */
+
+ while (true) {
+ data = decoder_buffer_read(buffer, &length);
+ if (data != NULL) {
+ if (length > nbytes)
+ length = nbytes;
+ decoder_buffer_consume(buffer, length);
+ nbytes -= length;
+ if (nbytes == 0)
+ return true;
+ }
+
+ success = decoder_buffer_fill(buffer);
+ if (!success)
+ return false;
+ }
+}
diff --git a/src/decoder_buffer.h b/src/decoder_buffer.h
index d951a4055..411e3bd88 100644
--- a/src/decoder_buffer.h
+++ b/src/decoder_buffer.h
@@ -93,4 +93,14 @@ decoder_buffer_read(const struct decoder_buffer *buffer, size_t *length_r);
void
decoder_buffer_consume(struct decoder_buffer *buffer, size_t nbytes);
+/**
+ * Skips the specified number of bytes, discarding its data.
+ *
+ * @param buffer the decoder_buffer object
+ * @param nbytes the number of bytes to skip
+ * @return true on success, false on error
+ */
+bool
+decoder_buffer_skip(struct decoder_buffer *buffer, size_t nbytes);
+
#endif