decoder/ffmpeg: require ffmpeg/libav 0.7.6

This is the version present in Ubuntu Oneiric, the oldest distribution
with gcc 4.6.  Debian Squeeze is off target, because it has gcc 4.4,
which is unable to compile MPD anyway.

This commit drops all API compatibility hacks for older versions.
This commit is contained in:
Max Kellermann 2013-01-28 20:53:48 +01:00
parent 88c17926e4
commit 0dd4b52b63
5 changed files with 4 additions and 114 deletions

View File

@ -874,7 +874,7 @@ AM_PATH_FAAD()
AM_CONDITIONAL(HAVE_FAAD, test x$enable_aac = xyes) AM_CONDITIONAL(HAVE_FAAD, test x$enable_aac = xyes)
dnl ---------------------------------- ffmpeg --------------------------------- dnl ---------------------------------- ffmpeg ---------------------------------
MPD_AUTO_PKG(ffmpeg, FFMPEG, [libavformat >= 52.31 libavcodec >= 52.20 libavutil >= 49.15], MPD_AUTO_PKG(ffmpeg, FFMPEG, [libavformat >= 53.2 libavcodec >= 53.5 libavutil >= 51.7],
[ffmpeg decoder library], [libavformat+libavcodec+libavutil not found]) [ffmpeg decoder library], [libavformat+libavcodec+libavutil not found])
if test x$enable_ffmpeg = xyes; then if test x$enable_ffmpeg = xyes; then

View File

@ -49,9 +49,7 @@ extern "C" {
#include <libavutil/avutil.h> #include <libavutil/avutil.h>
#include <libavutil/log.h> #include <libavutil/log.h>
#include <libavutil/mathematics.h> #include <libavutil/mathematics.h>
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,5,0)
#include <libavutil/dict.h> #include <libavutil/dict.h>
#endif
} }
#undef G_LOG_DOMAIN #undef G_LOG_DOMAIN
@ -92,11 +90,8 @@ struct mpd_ffmpeg_stream {
struct decoder *decoder; struct decoder *decoder;
struct input_stream *input; struct input_stream *input;
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,101,0)
AVIOContext *io; AVIOContext *io;
#else
ByteIOContext *io;
#endif
unsigned char buffer[8192]; unsigned char buffer[8192];
}; };
@ -129,19 +124,11 @@ mpd_ffmpeg_stream_open(struct decoder *decoder, struct input_stream *input)
struct mpd_ffmpeg_stream *stream = g_new(struct mpd_ffmpeg_stream, 1); struct mpd_ffmpeg_stream *stream = g_new(struct mpd_ffmpeg_stream, 1);
stream->decoder = decoder; stream->decoder = decoder;
stream->input = input; stream->input = input;
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,101,0)
stream->io = avio_alloc_context(stream->buffer, sizeof(stream->buffer), stream->io = avio_alloc_context(stream->buffer, sizeof(stream->buffer),
false, stream, false, stream,
mpd_ffmpeg_stream_read, NULL, mpd_ffmpeg_stream_read, NULL,
input->seekable input->seekable
? mpd_ffmpeg_stream_seek : NULL); ? mpd_ffmpeg_stream_seek : NULL);
#else
stream->io = av_alloc_put_byte(stream->buffer, sizeof(stream->buffer),
false, stream,
mpd_ffmpeg_stream_read, NULL,
input->seekable
? mpd_ffmpeg_stream_seek : NULL);
#endif
if (stream->io == NULL) { if (stream->io == NULL) {
g_free(stream); g_free(stream);
return NULL; return NULL;
@ -156,15 +143,10 @@ mpd_ffmpeg_stream_open(struct decoder *decoder, struct input_stream *input)
*/ */
static int static int
mpd_ffmpeg_open_input(AVFormatContext **ic_ptr, mpd_ffmpeg_open_input(AVFormatContext **ic_ptr,
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,101,0)
AVIOContext *pb, AVIOContext *pb,
#else
ByteIOContext *pb,
#endif
const char *filename, const char *filename,
AVInputFormat *fmt) AVInputFormat *fmt)
{ {
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,1,3)
AVFormatContext *context = avformat_alloc_context(); AVFormatContext *context = avformat_alloc_context();
if (context == NULL) if (context == NULL)
return AVERROR(ENOMEM); return AVERROR(ENOMEM);
@ -172,9 +154,6 @@ mpd_ffmpeg_open_input(AVFormatContext **ic_ptr,
context->pb = pb; context->pb = pb;
*ic_ptr = context; *ic_ptr = context;
return avformat_open_input(ic_ptr, filename, fmt, NULL); return avformat_open_input(ic_ptr, filename, fmt, NULL);
#else
return av_open_input_stream(ic_ptr, pb, filename, fmt, NULL);
#endif
} }
static void static void
@ -198,11 +177,7 @@ ffmpeg_find_audio_stream(const AVFormatContext *format_context)
{ {
for (unsigned i = 0; i < format_context->nb_streams; ++i) for (unsigned i = 0; i < format_context->nb_streams; ++i)
if (format_context->streams[i]->codec->codec_type == if (format_context->streams[i]->codec->codec_type ==
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 64, 0)
AVMEDIA_TYPE_AUDIO) AVMEDIA_TYPE_AUDIO)
#else
CODEC_TYPE_AUDIO)
#endif
return i; return i;
return -1; return -1;
@ -301,12 +276,7 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
decoder_timestamp(decoder, decoder_timestamp(decoder,
time_from_ffmpeg(packet->pts, *time_base)); time_from_ffmpeg(packet->pts, *time_base));
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52,25,0)
AVPacket packet2 = *packet; AVPacket packet2 = *packet;
#else
const uint8_t *packet_data = packet->data;
int packet_size = packet->size;
#endif
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,25,0) #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,25,0)
uint8_t aligned_buffer[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2 + 16]; uint8_t aligned_buffer[(AVCODEC_MAX_AUDIO_FRAME_SIZE * 3) / 2 + 16];
@ -319,12 +289,7 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
#endif #endif
enum decoder_command cmd = DECODE_COMMAND_NONE; enum decoder_command cmd = DECODE_COMMAND_NONE;
while ( while (packet2.size > 0 &&
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52,25,0)
packet2.size > 0 &&
#else
packet_size > 0 &&
#endif
cmd == DECODE_COMMAND_NONE) { cmd == DECODE_COMMAND_NONE) {
int audio_size = buffer_size; int audio_size = buffer_size;
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,25,0) #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,25,0)
@ -342,14 +307,10 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
len = audio_size; len = audio_size;
} else if (len >= 0) } else if (len >= 0)
len = -1; len = -1;
#elif LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52,25,0) #else
int len = avcodec_decode_audio3(codec_context, int len = avcodec_decode_audio3(codec_context,
aligned_buffer, &audio_size, aligned_buffer, &audio_size,
&packet2); &packet2);
#else
int len = avcodec_decode_audio2(codec_context,
aligned_buffer, &audio_size,
packet_data, packet_size);
#endif #endif
if (len < 0) { if (len < 0) {
@ -358,13 +319,8 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
break; break;
} }
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52,25,0)
packet2.data += len; packet2.data += len;
packet2.size -= len; packet2.size -= len;
#else
packet_data += len;
packet_size -= len;
#endif
if (audio_size <= 0) if (audio_size <= 0)
continue; continue;
@ -376,32 +332,20 @@ ffmpeg_send_packet(struct decoder *decoder, struct input_stream *is,
return cmd; return cmd;
} }
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(52, 94, 1)
#define AVSampleFormat SampleFormat
#endif
G_GNUC_CONST G_GNUC_CONST
static enum sample_format static enum sample_format
ffmpeg_sample_format(enum AVSampleFormat sample_fmt) ffmpeg_sample_format(enum AVSampleFormat sample_fmt)
{ {
switch (sample_fmt) { switch (sample_fmt) {
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 94, 1)
case AV_SAMPLE_FMT_S16: case AV_SAMPLE_FMT_S16:
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,17,0) #if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,17,0)
case AV_SAMPLE_FMT_S16P: case AV_SAMPLE_FMT_S16P:
#endif
#else
case SAMPLE_FMT_S16:
#endif #endif
return SAMPLE_FORMAT_S16; return SAMPLE_FORMAT_S16;
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 94, 1)
case AV_SAMPLE_FMT_S32: case AV_SAMPLE_FMT_S32:
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,17,0) #if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,17,0)
case AV_SAMPLE_FMT_S32P: case AV_SAMPLE_FMT_S32P:
#endif
#else
case SAMPLE_FMT_S32:
#endif #endif
return SAMPLE_FORMAT_S32; return SAMPLE_FORMAT_S32;
@ -414,7 +358,6 @@ ffmpeg_sample_format(enum AVSampleFormat sample_fmt)
break; break;
} }
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 94, 1)
char buffer[64]; char buffer[64];
const char *name = av_get_sample_fmt_string(buffer, sizeof(buffer), const char *name = av_get_sample_fmt_string(buffer, sizeof(buffer),
sample_fmt); sample_fmt);
@ -422,7 +365,6 @@ ffmpeg_sample_format(enum AVSampleFormat sample_fmt)
g_warning("Unsupported libavcodec SampleFormat value: %s (%d)", g_warning("Unsupported libavcodec SampleFormat value: %s (%d)",
name, sample_fmt); name, sample_fmt);
else else
#endif
g_warning("Unsupported libavcodec SampleFormat value: %d", g_warning("Unsupported libavcodec SampleFormat value: %d",
sample_fmt); sample_fmt);
return SAMPLE_FORMAT_UNDEFINED; return SAMPLE_FORMAT_UNDEFINED;
@ -665,10 +607,6 @@ ffmpeg_scan_stream(struct input_stream *is,
tag_handler_invoke_duration(handler, handler_ctx, tag_handler_invoke_duration(handler, handler_ctx,
f->duration / AV_TIME_BASE); f->duration / AV_TIME_BASE);
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(52,101,0)
av_metadata_conv(f, NULL, f->iformat->metadata_conv);
#endif
ffmpeg_scan_dictionary(f->metadata, handler, handler_ctx); ffmpeg_scan_dictionary(f->metadata, handler, handler_ctx);
int idx = ffmpeg_find_audio_stream(f); int idx = ffmpeg_find_audio_stream(f);
if (idx >= 0) if (idx >= 0)

View File

@ -29,9 +29,6 @@
#define G_LOG_DOMAIN "ffmpeg" #define G_LOG_DOMAIN "ffmpeg"
static const struct tag_table ffmpeg_tags[] = { static const struct tag_table ffmpeg_tags[] = {
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(52,50,0)
{ "author", TAG_ARTIST },
#endif
{ "year", TAG_DATE }, { "year", TAG_DATE },
{ "author-sort", TAG_ARTIST_SORT }, { "author-sort", TAG_ARTIST_SORT },
{ "album_artist", TAG_ALBUM_ARTIST }, { "album_artist", TAG_ALBUM_ARTIST },
@ -53,8 +50,6 @@ ffmpeg_copy_metadata(enum tag_type type,
type, mt->value); type, mt->value);
} }
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,5,0)
static void static void
ffmpeg_scan_pairs(AVDictionary *dict, ffmpeg_scan_pairs(AVDictionary *dict,
const struct tag_handler *handler, void *handler_ctx) const struct tag_handler *handler, void *handler_ctx)
@ -66,8 +61,6 @@ ffmpeg_scan_pairs(AVDictionary *dict,
i->key, i->value); i->key, i->value);
} }
#endif
void void
ffmpeg_scan_dictionary(AVDictionary *dict, ffmpeg_scan_dictionary(AVDictionary *dict,
const struct tag_handler *handler, void *handler_ctx) const struct tag_handler *handler, void *handler_ctx)
@ -81,8 +74,6 @@ ffmpeg_scan_dictionary(AVDictionary *dict,
ffmpeg_copy_metadata(i->type, dict, i->name, ffmpeg_copy_metadata(i->type, dict, i->name,
handler, handler_ctx); handler, handler_ctx);
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,5,0)
if (handler->pair != NULL) if (handler->pair != NULL)
ffmpeg_scan_pairs(dict, handler, handler_ctx); ffmpeg_scan_pairs(dict, handler, handler_ctx);
#endif
} }

View File

@ -23,17 +23,9 @@
extern "C" { extern "C" {
#include <libavformat/avformat.h> #include <libavformat/avformat.h>
#include <libavutil/avutil.h> #include <libavutil/avutil.h>
#if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51,5,0)
#include <libavutil/dict.h> #include <libavutil/dict.h>
#endif
} }
#if LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(53,1,0)
#define AVDictionary AVMetadata
#define AVDictionaryEntry AVMetadataTag
#define av_dict_get av_metadata_get
#endif
struct tag_handler; struct tag_handler;
void void

View File

@ -38,11 +38,7 @@ extern "C" {
struct input_ffmpeg { struct input_ffmpeg {
struct input_stream base; struct input_stream base;
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,0,0)
AVIOContext *h; AVIOContext *h;
#else
URLContext *h;
#endif
bool eof; bool eof;
}; };
@ -56,12 +52,8 @@ ffmpeg_quark(void)
static inline bool static inline bool
input_ffmpeg_supported(void) input_ffmpeg_supported(void)
{ {
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,0,0)
void *opaque = nullptr; void *opaque = nullptr;
return avio_enum_protocols(&opaque, 0) != nullptr; return avio_enum_protocols(&opaque, 0) != nullptr;
#else
return av_protocol_next(nullptr) != nullptr;
#endif
} }
static bool static bool
@ -99,13 +91,7 @@ input_ffmpeg_open(const char *uri,
input_stream_init(&i->base, &input_plugin_ffmpeg, uri, input_stream_init(&i->base, &input_plugin_ffmpeg, uri,
mutex, cond); mutex, cond);
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,1,0)
int ret = avio_open(&i->h, uri, AVIO_FLAG_READ); int ret = avio_open(&i->h, uri, AVIO_FLAG_READ);
#elif LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,0,0)
int ret = avio_open(&i->h, uri, AVIO_RDONLY);
#else
int ret = url_open(&i->h, uri, URL_RDONLY);
#endif
if (ret != 0) { if (ret != 0) {
g_free(i); g_free(i);
g_set_error(error_r, ffmpeg_quark(), ret, g_set_error(error_r, ffmpeg_quark(), ret,
@ -116,13 +102,8 @@ input_ffmpeg_open(const char *uri,
i->eof = false; i->eof = false;
i->base.ready = true; i->base.ready = true;
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,0,0)
i->base.seekable = (i->h->seekable & AVIO_SEEKABLE_NORMAL) != 0; i->base.seekable = (i->h->seekable & AVIO_SEEKABLE_NORMAL) != 0;
i->base.size = avio_size(i->h); i->base.size = avio_size(i->h);
#else
i->base.seekable = !i->h->is_streamed;
i->base.size = url_filesize(i->h);
#endif
/* hack to make MPD select the "ffmpeg" decoder plugin - since /* hack to make MPD select the "ffmpeg" decoder plugin - since
avio.h doesn't tell us the MIME type of the resource, we avio.h doesn't tell us the MIME type of the resource, we
@ -139,11 +120,7 @@ input_ffmpeg_read(struct input_stream *is, void *ptr, size_t size,
{ {
struct input_ffmpeg *i = (struct input_ffmpeg *)is; struct input_ffmpeg *i = (struct input_ffmpeg *)is;
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,0,0)
int ret = avio_read(i->h, (unsigned char *)ptr, size); int ret = avio_read(i->h, (unsigned char *)ptr, size);
#else
int ret = url_read(i->h, (unsigned char *)ptr, size);
#endif
if (ret <= 0) { if (ret <= 0) {
if (ret < 0) if (ret < 0)
g_set_error(error_r, ffmpeg_quark(), 0, g_set_error(error_r, ffmpeg_quark(), 0,
@ -162,11 +139,7 @@ input_ffmpeg_close(struct input_stream *is)
{ {
struct input_ffmpeg *i = (struct input_ffmpeg *)is; struct input_ffmpeg *i = (struct input_ffmpeg *)is;
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,0,0)
avio_close(i->h); avio_close(i->h);
#else
url_close(i->h);
#endif
input_stream_deinit(&i->base); input_stream_deinit(&i->base);
g_free(i); g_free(i);
} }
@ -184,11 +157,7 @@ input_ffmpeg_seek(struct input_stream *is, goffset offset, int whence,
G_GNUC_UNUSED GError **error_r) G_GNUC_UNUSED GError **error_r)
{ {
struct input_ffmpeg *i = (struct input_ffmpeg *)is; struct input_ffmpeg *i = (struct input_ffmpeg *)is;
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53,0,0)
int64_t ret = avio_seek(i->h, offset, whence); int64_t ret = avio_seek(i->h, offset, whence);
#else
int64_t ret = url_seek(i->h, offset, whence);
#endif
if (ret >= 0) { if (ret >= 0) {
i->eof = false; i->eof = false;