From 28385885677c95e0bec54adad4c94190180b2b3d Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Wed, 13 Feb 2013 21:48:20 +0100 Subject: [PATCH] Revert "Fix build with latest FFmpeg." This reverts commit 63cb1b7678b9fbe7dcbd67004122be6a920735bf. The change broke build with older FFmpeg, see http://www.gnashdev.org:8010/builders/maverick-linux-i386/builds/439/steps/compile/logs/stdio --- libmedia/ffmpeg/AudioDecoderFfmpeg.cpp | 13 ++++++++----- libmedia/ffmpeg/MediaParserFfmpeg.cpp | 34 ++++++++++++++++++++-------------- libmedia/ffmpeg/MediaParserFfmpeg.h | 4 ++-- libmedia/ffmpeg/VideoDecoderFfmpeg.cpp | 4 +++- 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/libmedia/ffmpeg/AudioDecoderFfmpeg.cpp b/libmedia/ffmpeg/AudioDecoderFfmpeg.cpp index 23424f3ff..067e418f4 100644 --- a/libmedia/ffmpeg/AudioDecoderFfmpeg.cpp +++ b/libmedia/ffmpeg/AudioDecoderFfmpeg.cpp @@ -84,7 +84,9 @@ AudioDecoderFfmpeg::~AudioDecoderFfmpeg() void AudioDecoderFfmpeg::setup(SoundInfo& info) { - avcodec_register_all();// change this to only register need codec? no - it is required for initializing the library + // Init the avdecoder-decoder + avcodec_init(); + avcodec_register_all();// change this to only register need codec? enum CodecID codec_id; @@ -156,14 +158,14 @@ void AudioDecoderFfmpeg::setup(SoundInfo& info) case CODEC_ID_PCM_U16LE: _audioCodecCtx->channels = (info.isStereo() ? 2 : 1); _audioCodecCtx->sample_rate = info.getSampleRate(); - _audioCodecCtx->sample_fmt = AV_SAMPLE_FMT_S16; // ?! arbitrary ? + _audioCodecCtx->sample_fmt = SAMPLE_FMT_S16; // ?! arbitrary ? _audioCodecCtx->frame_size = 1; break; default: _audioCodecCtx->channels = (info.isStereo() ? 2 : 1); _audioCodecCtx->sample_rate = info.getSampleRate(); - _audioCodecCtx->sample_fmt = AV_SAMPLE_FMT_S16; // ?! arbitrary ? + _audioCodecCtx->sample_fmt = SAMPLE_FMT_S16; // ?! arbitrary ? break; } } @@ -171,7 +173,8 @@ void AudioDecoderFfmpeg::setup(SoundInfo& info) void AudioDecoderFfmpeg::setup(const AudioInfo& info) { // Init the avdecoder-decoder - avcodec_register_all();// change this to only register need codec? no - it is required for initializing the library + avcodec_init(); + avcodec_register_all();// change this to only register need codec? enum CodecID codec_id = CODEC_ID_NONE; @@ -294,7 +297,7 @@ void AudioDecoderFfmpeg::setup(const AudioInfo& info) _audioCodecCtx->channels = (info.stereo ? 2 : 1); _audioCodecCtx->sample_rate = info.sampleRate; // was commented out (why?): - _audioCodecCtx->sample_fmt = AV_SAMPLE_FMT_S16; + _audioCodecCtx->sample_fmt = SAMPLE_FMT_S16; break; } diff --git a/libmedia/ffmpeg/MediaParserFfmpeg.cpp b/libmedia/ffmpeg/MediaParserFfmpeg.cpp index 6e120e28f..d6e6902c0 100644 --- a/libmedia/ffmpeg/MediaParserFfmpeg.cpp +++ b/libmedia/ffmpeg/MediaParserFfmpeg.cpp @@ -344,6 +344,8 @@ MediaParserFfmpeg::initializeParser() { av_register_all(); // TODO: needs to be invoked only once ? + _byteIOCxt.buffer = NULL; + _inputFmt = probeStream(); #ifdef GNASH_ALLOW_VCODEC_ENV @@ -364,7 +366,7 @@ MediaParserFfmpeg::initializeParser() // which isn't needed. _byteIOBuffer.reset(new unsigned char[byteIOBufferSize]); - _avIOCxt = avio_alloc_context( + init_put_byte(&_byteIOCxt, _byteIOBuffer.get(), // buffer byteIOBufferSize, // buffer size 0, // write flags @@ -374,7 +376,7 @@ MediaParserFfmpeg::initializeParser() MediaParserFfmpeg::seekMediaWrapper // seeker callback ); - _avIOCxt->seekable = 0; + _byteIOCxt.is_streamed = 1; #if !defined(LIBAVCODEC_VERSION_MAJOR) || LIBAVCODEC_VERSION_MAJOR < 52 // Needed for Lenny. @@ -384,9 +386,13 @@ MediaParserFfmpeg::initializeParser() #endif assert(_formatCtx); - _formatCtx->pb = _avIOCxt; - if (avformat_open_input(&_formatCtx, "", _inputFmt, NULL) < 0) + // Otherwise av_open_input_stream will reallocate the context. + AVFormatParameters ap; + std::memset(&ap, 0, sizeof ap); + ap.prealloced_context = 1; + + if (av_open_input_stream(&_formatCtx, &_byteIOCxt, "", _inputFmt, &ap) < 0) { throw IOException("MediaParserFfmpeg couldn't open input stream"); } @@ -394,10 +400,10 @@ MediaParserFfmpeg::initializeParser() #if defined(LIBAVCODEC_VERSION_MAJOR) && LIBAVCODEC_VERSION_MAJOR >= 52 // Note: in at least some versions of ffmpeg, av_open_input_stream does // not parse metadata; not sure why. - AVDictionary* md = _formatCtx->metadata; + AVMetadata* md = _formatCtx->metadata; if (md) { - AVDictionaryEntry* tag = av_dict_get(md, "album", 0, - AV_DICT_MATCH_CASE); + AVMetadataTag* tag = av_metadata_get(md, "album", 0, + AV_METADATA_MATCH_CASE); if (tag && tag->value) { setId3Info(&Id3Info::album, std::string(tag->value), _id3Object); @@ -614,27 +620,27 @@ MediaParserFfmpeg::seekMedia(boost::int64_t offset, int whence) } boost::uint16_t -MediaParserFfmpeg::SampleFormatToSampleSize(AVSampleFormat fmt) +MediaParserFfmpeg::SampleFormatToSampleSize(SampleFormat fmt) { switch (fmt) { - case AV_SAMPLE_FMT_U8: // unsigned 8 bits + case SAMPLE_FMT_U8: // unsigned 8 bits return 1; - case AV_SAMPLE_FMT_S16: // signed 16 bits - case AV_SAMPLE_FMT_FLT: // float + case SAMPLE_FMT_S16: // signed 16 bits + case SAMPLE_FMT_FLT: // float return 2; #if !defined (LIBAVCODEC_VERSION_MAJOR) || LIBAVCODEC_VERSION_MAJOR < 52 // Was dropped for version 52.0.0 - case AV_SAMPLE_FMT_S24: // signed 24 bits + case SAMPLE_FMT_S24: // signed 24 bits return 3; #endif - case AV_SAMPLE_FMT_S32: // signed 32 bits + case SAMPLE_FMT_S32: // signed 32 bits return 4; - case AV_SAMPLE_FMT_NONE: + case SAMPLE_FMT_NONE: default: return 8; // arbitrary value } diff --git a/libmedia/ffmpeg/MediaParserFfmpeg.h b/libmedia/ffmpeg/MediaParserFfmpeg.h index 2d817c890..4e410d8fa 100644 --- a/libmedia/ffmpeg/MediaParserFfmpeg.h +++ b/libmedia/ffmpeg/MediaParserFfmpeg.h @@ -154,7 +154,7 @@ private: AVStream* _audioStream; /// ? - AVIOContext* _avIOCxt; + ByteIOContext _byteIOCxt; /// Size of the ByteIO context buffer // @@ -172,7 +172,7 @@ private: // /// TODO: move somewhere in ffmpeg utils.. /// - boost::uint16_t SampleFormatToSampleSize(AVSampleFormat fmt); + boost::uint16_t SampleFormatToSampleSize(SampleFormat fmt); /// Make an EncodedVideoFrame from an AVPacket and push to buffer // diff --git a/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp b/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp index eb187a0ef..40a5c808b 100644 --- a/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp +++ b/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp @@ -171,7 +171,8 @@ VideoDecoderFfmpeg::init(enum CodecID codecId, int /*width*/, int /*height*/, boost::uint8_t* extradata, int extradataSize) { // Init the avdecoder-decoder - avcodec_register_all();// change this to only register need codec? no - it is required for initializing the library + avcodec_init(); + avcodec_register_all();// change this to only register need codec? _videoCodec = avcodec_find_decoder(codecId); @@ -528,6 +529,7 @@ get_buffer(AVCodecContext* avctx, AVFrame* pic) static unsigned int pic_num = 0; pic->type = FF_BUFFER_TYPE_USER; + pic->age = ++pic_num - surface->getPicNum(); surface->setPicNum(pic_num); return 0; #endif -- 2.11.4.GIT