aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder/ffmpeg_decoder_plugin.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/decoder/ffmpeg_decoder_plugin.c')
-rw-r--r--src/decoder/ffmpeg_decoder_plugin.c135
1 files changed, 21 insertions, 114 deletions
diff --git a/src/decoder/ffmpeg_decoder_plugin.c b/src/decoder/ffmpeg_decoder_plugin.c
index d1e1470ac..b63094404 100644
--- a/src/decoder/ffmpeg_decoder_plugin.c
+++ b/src/decoder/ffmpeg_decoder_plugin.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2010 The Music Player Daemon Project
+ * Copyright (C) 2003-2011 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -20,6 +20,8 @@
#include "config.h"
#include "decoder_api.h"
#include "audio_check.h"
+#include "ffmpeg_metadata.h"
+#include "tag_handler.h"
#include <glib.h>
@@ -32,11 +34,6 @@
#include <sys/stat.h>
#include <unistd.h>
-#ifdef OLD_FFMPEG_INCLUDES
-#include <avcodec.h>
-#include <avformat.h>
-#include <avio.h>
-#else
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavformat/avio.h>
@@ -46,13 +43,10 @@
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,5,0)
#include <libavutil/dict.h>
#endif
-#endif
#undef G_LOG_DOMAIN
#define G_LOG_DOMAIN "ffmpeg"
-#ifndef OLD_FFMPEG_INCLUDES
-
static GLogLevelFlags
level_ffmpeg_to_glib(int level)
{
@@ -84,12 +78,6 @@ mpd_ffmpeg_log_callback(G_GNUC_UNUSED void *ptr, int level,
}
}
-#endif /* !OLD_FFMPEG_INCLUDES */
-
-#ifndef AV_VERSION_INT
-#define AV_VERSION_INT(a, b, c) (a<<16 | b<<8 | c)
-#endif
-
struct mpd_ffmpeg_stream {
struct decoder *decoder;
struct input_stream *input;
@@ -119,7 +107,7 @@ mpd_ffmpeg_stream_seek(void *opaque, int64_t pos, int whence)
if (whence == AVSEEK_SIZE)
return stream->input->size;
- if (!input_stream_seek(stream->input, pos, whence, NULL))
+ if (!input_stream_lock_seek(stream->input, pos, whence, NULL))
return -1;
return stream->input->offset;
@@ -189,9 +177,7 @@ mpd_ffmpeg_stream_close(struct mpd_ffmpeg_stream *stream)
static bool
ffmpeg_init(G_GNUC_UNUSED const struct config_param *param)
{
-#ifndef OLD_FFMPEG_INCLUDES
av_log_set_callback(mpd_ffmpeg_log_callback);
-#endif
av_register_all();
return true;
@@ -369,7 +355,6 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
static enum sample_format
ffmpeg_sample_format(G_GNUC_UNUSED const AVCodecContext *codec_context)
{
-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(51, 41, 0)
switch (codec_context->sample_fmt) {
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 94, 1)
case AV_SAMPLE_FMT_S16:
@@ -390,10 +375,6 @@ ffmpeg_sample_format(G_GNUC_UNUSED const AVCodecContext *codec_context)
codec_context->sample_fmt);
return SAMPLE_FORMAT_UNDEFINED;
}
-#else
- /* XXX fixme 16-bit for older ffmpeg (13 Aug 2007) */
- return SAMPLE_FORMAT_S16;
-#endif
}
static AVInputFormat *
@@ -406,7 +387,8 @@ ffmpeg_probe(struct decoder *decoder, struct input_stream *is)
unsigned char *buffer = g_malloc(BUFFER_SIZE);
size_t nbytes = decoder_read(decoder, is, buffer, BUFFER_SIZE);
- if (nbytes <= PADDING || !input_stream_seek(is, 0, SEEK_SET, NULL)) {
+ if (nbytes <= PADDING ||
+ !input_stream_lock_seek(is, 0, SEEK_SET, NULL)) {
g_free(buffer);
return NULL;
}
@@ -588,72 +570,24 @@ ffmpeg_decode(struct decoder *decoder, struct input_stream *input)
mpd_ffmpeg_stream_close(stream);
}
-#if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(31<<8)+0)
-typedef struct ffmpeg_tag_map {
- enum tag_type type;
- const char *name;
-} ffmpeg_tag_map;
-
-static const ffmpeg_tag_map ffmpeg_tag_maps[] = {
-#if LIBAVFORMAT_VERSION_INT < ((52<<16)+(50<<8))
- { TAG_ARTIST, "author" },
-#endif
- { TAG_DATE, "year" },
- { TAG_ARTIST_SORT, "author-sort" },
- { TAG_ALBUM_ARTIST, "album_artist" },
- { TAG_ALBUM_ARTIST_SORT, "album_artist-sort" },
-
- /* sentinel */
- { TAG_NUM_OF_ITEM_TYPES, NULL }
-};
-
-#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53,1,0)
-#define AVDictionary AVMetadata
-#define AVDictionaryEntry AVMetadataTag
-#define av_dict_get av_metadata_get
-#endif
-
-static void
-ffmpeg_copy_metadata(struct tag *tag, enum tag_type type,
- AVDictionary *m, const char *name)
-{
- AVDictionaryEntry *mt = NULL;
-
- while ((mt = av_dict_get(m, name, mt, 0)) != NULL)
- tag_add_item(tag, type, mt->value);
-}
-
-static void
-ffmpeg_copy_dictionary(struct tag *tag, AVDictionary *dict)
-{
- for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i)
- ffmpeg_copy_metadata(tag, i,
- dict, tag_item_names[i]);
-
- for (const struct ffmpeg_tag_map *i = ffmpeg_tag_maps;
- i->name != NULL; ++i)
- ffmpeg_copy_metadata(tag, i->type, dict, i->name);
-}
-
-#endif
-
//no tag reading in ffmpeg, check if playable
-static struct tag *
-ffmpeg_stream_tag(struct input_stream *is)
+static bool
+ffmpeg_scan_stream(struct input_stream *is,
+ const struct tag_handler *handler, void *handler_ctx)
{
AVInputFormat *input_format = ffmpeg_probe(NULL, is);
if (input_format == NULL)
- return NULL;
+ return false;
struct mpd_ffmpeg_stream *stream = mpd_ffmpeg_stream_open(NULL, is);
if (stream == NULL)
- return NULL;
+ return false;
AVFormatContext *f = NULL;
if (mpd_ffmpeg_open_input(&f, stream->io, is->uri,
input_format) != 0) {
mpd_ffmpeg_stream_close(stream);
- return NULL;
+ return false;
}
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,6,0)
@@ -669,49 +603,22 @@ ffmpeg_stream_tag(struct input_stream *is)
av_close_input_stream(f);
#endif
mpd_ffmpeg_stream_close(stream);
- return NULL;
+ return false;
}
- struct tag *tag = tag_new();
-
- tag->time = f->duration != (int64_t)AV_NOPTS_VALUE
- ? f->duration / AV_TIME_BASE
- : 0;
+ if (f->duration != (int64_t)AV_NOPTS_VALUE)
+ tag_handler_invoke_duration(handler, handler_ctx,
+ f->duration / AV_TIME_BASE);
-#if LIBAVFORMAT_VERSION_INT >= ((52<<16)+(31<<8)+0)
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(52,101,0)
av_metadata_conv(f, NULL, f->iformat->metadata_conv);
#endif
- ffmpeg_copy_dictionary(tag, f->metadata);
+ ffmpeg_scan_dictionary(f->metadata, handler, handler_ctx);
int idx = ffmpeg_find_audio_stream(f);
if (idx >= 0)
- ffmpeg_copy_dictionary(tag, f->streams[idx]->metadata);
-#else
- if (f->author[0])
- tag_add_item(tag, TAG_ARTIST, f->author);
- if (f->title[0])
- tag_add_item(tag, TAG_TITLE, f->title);
- if (f->album[0])
- tag_add_item(tag, TAG_ALBUM, f->album);
-
- if (f->track > 0) {
- char buffer[16];
- snprintf(buffer, sizeof(buffer), "%d", f->track);
- tag_add_item(tag, TAG_TRACK, buffer);
- }
-
- if (f->comment[0])
- tag_add_item(tag, TAG_COMMENT, f->comment);
- if (f->genre[0])
- tag_add_item(tag, TAG_GENRE, f->genre);
- if (f->year > 0) {
- char buffer[16];
- snprintf(buffer, sizeof(buffer), "%d", f->year);
- tag_add_item(tag, TAG_DATE, buffer);
- }
-
-#endif
+ ffmpeg_scan_dictionary(f->streams[idx]->metadata,
+ handler, handler_ctx);
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,17,0)
avformat_close_input(&f);
@@ -720,7 +627,7 @@ ffmpeg_stream_tag(struct input_stream *is)
#endif
mpd_ffmpeg_stream_close(stream);
- return tag;
+ return true;
}
/**
@@ -841,7 +748,7 @@ const struct decoder_plugin ffmpeg_decoder_plugin = {
.name = "ffmpeg",
.init = ffmpeg_init,
.stream_decode = ffmpeg_decode,
- .stream_tag = ffmpeg_stream_tag,
+ .scan_stream = ffmpeg_scan_stream,
.suffixes = ffmpeg_suffixes,
.mime_types = ffmpeg_mime_types
};