$OpenBSD: patch-plugins_decoder_ffmpeg_k3bffmpegwrapper_cpp,v 1.2 2014/07/11 21:02:05 zhuk Exp $
Fixed compilation with new FFMPEG.
Upstream commits:
  2f845b34badb614882b7e38ac38b00041ac2832d
  6f34e14b28d2f9103151c6ba08b3bb40448ffe46
(last one via Debian)
--- plugins/decoder/ffmpeg/k3bffmpegwrapper.cpp.orig	Sat Jan 15 21:47:29 2011
+++ plugins/decoder/ffmpeg/k3bffmpegwrapper.cpp	Fri Jul 11 20:24:07 2014
@@ -33,6 +33,11 @@ extern "C" {
 #endif
 }
 
+// XXX avcodec_decode_audio3() will deprecate soon, too...
+#ifndef AVCODEC_MAX_AUDIO_FRAME_SIZE
+#define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000
+#endif
+
 #include <string.h>
 
 #include <klocale.h>
@@ -88,7 +93,11 @@ bool K3bFFMpegFile::open()
     close();
 
     // open the file
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,2,0)
+    int err = ::avformat_open_input( &d->formatContext, m_filename.toLocal8Bit(), 0, 0 );
+#else
     int err = ::av_open_input_file( &d->formatContext, m_filename.toLocal8Bit(), 0, 0, 0 );
+#endif
     if( err < 0 ) {
         kDebug() << "(K3bFFMpegFile) unable to open " << m_filename << " with error " << err;
         return false;
@@ -109,7 +118,13 @@ bool K3bFFMpegFile::open()
 #else
     ::AVCodecContext* codecContext =  d->formatContext->streams[0]->codec;
 #endif
-    if( codecContext->codec_type != CODEC_TYPE_AUDIO ) {
+    if( codecContext->codec_type != 
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 64, 0)
+        AVMEDIA_TYPE_AUDIO)
+#else
+        CODEC_TYPE_AUDIO)
+#endif
+    {
         kDebug() << "(K3bFFMpegFile) not a simple audio stream: " << m_filename;
         return false;
     }
@@ -123,7 +138,11 @@ bool K3bFFMpegFile::open()
 
     // open the codec on our context
     kDebug() << "(K3bFFMpegFile) found codec for " << m_filename;
+#if LIBAVCODEC_VERSION_MAJOR >= 55
+    if( ::avcodec_open2( codecContext, d->codec, NULL ) < 0 ) {
+#else
     if( ::avcodec_open( codecContext, d->codec ) < 0 ) {
+#endif
         kDebug() << "(K3bFFMpegDecoderFactory) could not open codec.";
         return false;
     }
@@ -137,7 +156,11 @@ bool K3bFFMpegFile::open()
     }
 
     // dump some debugging info
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,2,0)
+    ::av_dump_format( d->formatContext, 0, m_filename.toLocal8Bit(), 0 );
+#else
     ::dump_format( d->formatContext, 0, m_filename.toLocal8Bit(), 0 );
+#endif
 
     return true;
 }
@@ -225,8 +248,11 @@ QString K3bFFMpegFile::typeComment() const
 QString K3bFFMpegFile::title() const
 {
     // FIXME: is this UTF8 or something??
-    if( d->formatContext->title[0] != '\0' )
-        return QString::fromLocal8Bit( d->formatContext->title );
+    AVDictionaryEntry *ade = av_dict_get( d->formatContext->metadata, "TITLE", NULL, 0 );
+    if( ade == NULL )
+        return QString();
+    if( ade->value != '\0' )
+        return QString::fromLocal8Bit( ade->value );
     else
         return QString();
 }
@@ -235,8 +261,11 @@ QString K3bFFMpegFile::title() const
 QString K3bFFMpegFile::author() const
 {
     // FIXME: is this UTF8 or something??
-    if( d->formatContext->author[0] != '\0' )
-        return QString::fromLocal8Bit( d->formatContext->author );
+    AVDictionaryEntry *ade = av_dict_get( d->formatContext->metadata, "ARTIST", NULL, 0 );
+    if( ade == NULL )
+        return QString();
+    if( ade->value != '\0' )
+        return QString::fromLocal8Bit( ade->value );
     else
         return QString();
 }
@@ -245,8 +274,11 @@ QString K3bFFMpegFile::author() const
 QString K3bFFMpegFile::comment() const
 {
     // FIXME: is this UTF8 or something??
-    if( d->formatContext->comment[0] != '\0' )
-        return QString::fromLocal8Bit( d->formatContext->comment );
+    AVDictionaryEntry *ade = av_dict_get( d->formatContext->metadata, "COMMENT", NULL, 0 );
+    if( ade == NULL )
+        return QString();
+    if( ade->value != '\0' )
+        return QString::fromLocal8Bit( ade->value );
     else
         return QString();
 }
@@ -309,8 +341,13 @@ int K3bFFMpegFile::fillOutputBuffer()
 #if LIBAVCODEC_VERSION_MAJOR < 52
         int len = ::avcodec_decode_audio(
 #else
+   #if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 64, 0)
+        int len = ::avcodec_decode_audio3(
+   #else
         int len = ::avcodec_decode_audio2(
+   #endif
 #endif
+
 #ifdef FFMPEG_BUILD_PRE_4629
             &d->formatContext->streams[0]->codec,
 #else
@@ -318,7 +355,11 @@ int K3bFFMpegFile::fillOutputBuffer()
 #endif
             (short*)d->alignedOutputBuffer,
             &d->outputBufferSize,
+#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 64, 0)
+            &d->packet );
+#else
             d->packetData, d->packetSize );
+#endif
 
         if( d->packetSize <= 0 || len < 0 )
             ::av_free_packet( &d->packet );
