Description: Fixes build and ffmpeg decoding with recent ffmpeg/libav
 versions. For instance yt movies play with libav wheezy version.
Author: Alexis Ballier <aballier@gentoo.org>
Origin: http://git.savannah.gnu.org/gitweb/?p=gnash.git;a=commit;h=4b3dae970549d42723c2528c250a1f95248145c7

--- a/libmedia/ffmpeg/AudioDecoderFfmpeg.cpp
+++ b/libmedia/ffmpeg/AudioDecoderFfmpeg.cpp
@@ -84,8 +84,6 @@ AudioDecoderFfmpeg::~AudioDecoderFfmpeg(
 
 void AudioDecoderFfmpeg::setup(SoundInfo& info)
 {
-    // Init the avdecoder-decoder
-    avcodec_init();
     avcodec_register_all();// change this to only register need codec?
 
     enum CodecID codec_id;
@@ -158,22 +156,20 @@ void AudioDecoderFfmpeg::setup(SoundInfo
             case CODEC_ID_PCM_U16LE:
                 _audioCodecCtx->channels = (info.isStereo() ? 2 : 1);
                 _audioCodecCtx->sample_rate = info.getSampleRate();
-                _audioCodecCtx->sample_fmt = SAMPLE_FMT_S16; // ?! arbitrary ?
+                _audioCodecCtx->sample_fmt = AV_SAMPLE_FMT_S16; // ?! arbitrary ?
                 _audioCodecCtx->frame_size = 1; 
                 break;
 
             default:
                 _audioCodecCtx->channels = (info.isStereo() ? 2 : 1);
                 _audioCodecCtx->sample_rate = info.getSampleRate();
-                _audioCodecCtx->sample_fmt = SAMPLE_FMT_S16; // ?! arbitrary ?
+                _audioCodecCtx->sample_fmt = AV_SAMPLE_FMT_S16; // ?! arbitrary ?
                 break;
     }
 }
 
 void AudioDecoderFfmpeg::setup(const AudioInfo& info)
 {
-    // Init the avdecoder-decoder
-    avcodec_init();
     avcodec_register_all();// change this to only register need codec?
 
     enum CodecID codec_id = CODEC_ID_NONE;
@@ -297,7 +293,7 @@ void AudioDecoderFfmpeg::setup(const Aud
                 _audioCodecCtx->channels = (info.stereo ? 2 : 1);
                 _audioCodecCtx->sample_rate = info.sampleRate;
                 // was commented out (why?):
-                _audioCodecCtx->sample_fmt = SAMPLE_FMT_S16; 
+                _audioCodecCtx->sample_fmt = AV_SAMPLE_FMT_S16;
                 break;
     }
 
--- a/libmedia/ffmpeg/MediaParserFfmpeg.cpp
+++ b/libmedia/ffmpeg/MediaParserFfmpeg.cpp
@@ -344,8 +344,6 @@ MediaParserFfmpeg::initializeParser()
 {
     av_register_all(); // TODO: needs to be invoked only once ?
 
-    _byteIOCxt.buffer = NULL;
-    
     _inputFmt = probeStream();
 
 #ifdef GNASH_ALLOW_VCODEC_ENV	
@@ -366,7 +364,7 @@ MediaParserFfmpeg::initializeParser()
     // which isn't needed.
     _byteIOBuffer.reset(new unsigned char[byteIOBufferSize]);
 
-    init_put_byte(&_byteIOCxt,
+    _avIOCxt = avio_alloc_context(
 		  _byteIOBuffer.get(), // buffer
 		  byteIOBufferSize, // buffer size
 		  0, // write flags
@@ -376,7 +374,7 @@ MediaParserFfmpeg::initializeParser()
 		  MediaParserFfmpeg::seekMediaWrapper // seeker callback
 		  );
     
-    _byteIOCxt.is_streamed = 1;
+    _avIOCxt->seekable = 0;
 
 #if !defined(LIBAVCODEC_VERSION_MAJOR) || LIBAVCODEC_VERSION_MAJOR < 52
     // Needed for Lenny.
@@ -387,12 +385,9 @@ MediaParserFfmpeg::initializeParser()
 
     assert(_formatCtx);
 
-    // Otherwise av_open_input_stream will reallocate the context.
-    AVFormatParameters ap;
-    std::memset(&ap, 0, sizeof ap);
-    ap.prealloced_context = 1;
+    _formatCtx->pb = _avIOCxt;
 
-    if (av_open_input_stream(&_formatCtx, &_byteIOCxt, "", _inputFmt, &ap) < 0)
+    if (avformat_open_input(&_formatCtx, "", _inputFmt, NULL) < 0)
     {
         throw IOException("MediaParserFfmpeg couldn't open input stream");
     }
@@ -400,10 +395,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.
-    AVMetadata* md = _formatCtx->metadata;
+    AVDictionary* md = _formatCtx->metadata;
     if (md) {
-        AVMetadataTag* tag = av_metadata_get(md, "album", 0,
-                AV_METADATA_MATCH_CASE);
+        AVDictionaryEntry* tag = av_dict_get(md, "album", 0,
+                AV_DICT_MATCH_CASE);
         if (tag && tag->value) {
             setId3Info(&Id3Info::album, std::string(tag->value),
                     _id3Object);
@@ -620,27 +615,27 @@ MediaParserFfmpeg::seekMedia(boost::int6
 }
 
 boost::uint16_t
-MediaParserFfmpeg::SampleFormatToSampleSize(SampleFormat fmt)
+MediaParserFfmpeg::SampleFormatToSampleSize(AVSampleFormat fmt)
 {
 	switch (fmt)
 	{
-		case SAMPLE_FMT_U8: // unsigned 8 bits
+		case AV_SAMPLE_FMT_U8: // unsigned 8 bits
 			return 1;
 
-		case SAMPLE_FMT_S16: // signed 16 bits
-		case SAMPLE_FMT_FLT: // float
+		case AV_SAMPLE_FMT_S16: // signed 16 bits
+		case AV_SAMPLE_FMT_FLT: // float
 			return 2;
 
 #if !defined (LIBAVCODEC_VERSION_MAJOR) || LIBAVCODEC_VERSION_MAJOR < 52
 // Was dropped for version 52.0.0
-		case SAMPLE_FMT_S24: // signed 24 bits
+		case AV_SAMPLE_FMT_S24: // signed 24 bits
 			return 3;
 #endif
 
-		case SAMPLE_FMT_S32: // signed 32 bits
+		case AV_SAMPLE_FMT_S32: // signed 32 bits
 			return 4;
 
-		case SAMPLE_FMT_NONE:
+		case AV_SAMPLE_FMT_NONE:
 		default:
 			return 8; // arbitrary value
 	}
--- a/libmedia/ffmpeg/MediaParserFfmpeg.h
+++ b/libmedia/ffmpeg/MediaParserFfmpeg.h
@@ -154,7 +154,7 @@ private:
 	AVStream* _audioStream;
 
 	/// ?
-	ByteIOContext _byteIOCxt;
+	AVIOContext* _avIOCxt;
 
 	/// Size of the ByteIO context buffer
 	//
@@ -172,7 +172,7 @@ private:
 	//
 	/// TODO: move somewhere in ffmpeg utils..
 	///
-	boost::uint16_t SampleFormatToSampleSize(SampleFormat fmt);
+	boost::uint16_t SampleFormatToSampleSize(AVSampleFormat fmt);
 
 	/// Make an EncodedVideoFrame from an AVPacket and push to buffer
 	//
--- a/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp
+++ b/libmedia/ffmpeg/VideoDecoderFfmpeg.cpp
@@ -170,8 +170,6 @@ void
 VideoDecoderFfmpeg::init(enum CodecID codecId, int /*width*/, int /*height*/,
         boost::uint8_t* extradata, int extradataSize)
 {
-    // Init the avdecoder-decoder
-    avcodec_init();
     avcodec_register_all();// change this to only register need codec?
 
     _videoCodec = avcodec_find_decoder(codecId); 
