Fix build on sid with libav 0.7.1.
authorGabriele Giacone <1o5g4r8o@gmail.com>
Sun, 11 Sep 2011 08:48:42 +0000 (10:48 +0200)
committerGabriele Giacone <1o5g4r8o@gmail.com>
Sun, 11 Sep 2011 08:48:42 +0000 (10:48 +0200)
Patch from http://savannah.gnu.org/bugs/?33696 adapted to support
older versions. Thanks chithead!

libmedia/ffmpeg/AudioDecoderFfmpeg.cpp
libmedia/ffmpeg/AudioResamplerFfmpeg.cpp
libmedia/ffmpeg/MediaParserFfmpeg.cpp
libmedia/ffmpeg/VideoDecoderFfmpeg.cpp

index 2b1ce0e..98a7721 100644 (file)
 
 //#define GNASH_DEBUG_AUDIO_DECODING
 
+#if LIBAVCODEC_VERSION_MAJOR >= 53
+#define AVCODEC_DECODE_AUDIO avcodec_decode_audio3
+#else
 #define AVCODEC_DECODE_AUDIO avcodec_decode_audio2
+#endif
 
 namespace gnash {
 namespace media {
@@ -500,8 +504,18 @@ AudioDecoderFfmpeg::decodeFrame(const boost::uint8_t* input,
 #endif
 
     // older ffmpeg versions didn't accept a const input..
+#if LIBAVCODEC_VERSION_MAJOR >= 53
+    AVPacket pkt;
+    av_init_packet(&pkt);
+    pkt.data = (uint8_t*) input;
+    pkt.size = inputSize;
+#endif
     int tmp = AVCODEC_DECODE_AUDIO(_audioCodecCtx, outPtr, &outSize,
+#if LIBAVCODEC_VERSION_MAJOR >= 53
+                                   &pkt);
+#else
                                    input, inputSize);
+#endif
 
 #ifdef GNASH_DEBUG_AUDIO_DECODING
     log_debug(" avcodec_decode_audio[2](ctx, bufptr, %d, input, %d) "
@@ -609,13 +623,21 @@ AudioDecoderFfmpeg::parseInput(const boost::uint8_t* input,
 {
     if ( _needsParsing )
     {
+#if LIBAVCODEC_VERSION_MAJOR >= 53
+        return av_parser_parse2(_parser, _audioCodecCtx,
+#else
         return av_parser_parse(_parser, _audioCodecCtx,
+#endif
                     // as of 2008-10-28 SVN, ffmpeg doesn't
                     // accept a pointer to pointer to const..
                     const_cast<boost::uint8_t**>(outFrame),
                     outFrameSize,
                     input, inputSize,
+#if LIBAVCODEC_VERSION_MAJOR >= 53
+                    0, 0, AV_NOPTS_VALUE); // pts, dts, pos
+#else
                     0, 0); // pts & dts
+#endif
     }
     else
     {
index 3a43655..dc3f2f3 100644 (file)
@@ -46,8 +46,15 @@ AudioResamplerFfmpeg::init( AVCodecContext* ctx )
 {
   if ( (ctx->sample_rate != 44100) || (ctx->channels != 2) ) {
     if ( ! _context ) {
-      _context = audio_resample_init( 
-               2, ctx->channels, 44100, ctx->sample_rate 
+#if LIBAVCODEC_VERSION_MAJOR >= 53
+      _context = av_audio_resample_init(
+               2, ctx->channels, 44100, ctx->sample_rate,
+               AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16,
+               16, 10, 0, 0.8
+#else
+      _context = audio_resample_init(
+               2, ctx->channels, 44100, ctx->sample_rate
+#endif
        );
     }
 
index 492d26d..be65b5e 100644 (file)
@@ -429,7 +429,11 @@ MediaParserFfmpeg::initializeParser()
            }
            
            switch (enc->codec_type) {
+#if LIBAVCODEC_VERSION_MAJOR >= 53
+            case AVMEDIA_TYPE_AUDIO:
+#else
             case CODEC_TYPE_AUDIO:
+#endif
                 if (_audioStreamIndex < 0) {
                     _audioStreamIndex = i;
                     _audioStream = _formatCtx->streams[i];
@@ -440,7 +444,11 @@ MediaParserFfmpeg::initializeParser()
                 }
                 break;
                
+#if LIBAVCODEC_VERSION_MAJOR >= 53
+            case AVMEDIA_TYPE_VIDEO:
+#else
             case CODEC_TYPE_VIDEO:
+#endif
                 if (_videoStreamIndex < 0) {
                     _videoStreamIndex = i;
                     _videoStream = _formatCtx->streams[i];
index 0ddaf6c..bd3288a 100644 (file)
@@ -356,8 +356,17 @@ VideoDecoderFfmpeg::decode(const boost::uint8_t* input,
 
     int bytes = 0;    
     // no idea why avcodec_decode_video wants a non-const input...
+#if LIBAVCODEC_VERSION_MAJOR >= 53
+    AVPacket pkt;
+    av_init_packet(&pkt);
+    pkt.data = (uint8_t*) input;
+    pkt.size = input_size;
+    avcodec_decode_video2(_videoCodecCtx->getContext(), frame, &bytes,
+            &pkt);
+#else
     avcodec_decode_video(_videoCodecCtx->getContext(), frame, &bytes,
             input, input_size);
+#endif
     
     if (!bytes) {
         log_error("Decoding of a video frame failed");