Git commit 5b9b3537b658ad342d688fa4f210113a3d066d2a by Johannes Obermayr, o= n behalf of Old=C5=99ich Jedli=C4=8Dka. Committed on 28/07/2016 at 13:51. Pushed by jobermayr into branch '2.0'. Fixed compilation with newer ffmpeg/libav. Signed-off-by: Old=C5=99ich Jedli=C4=8Dka M +54 -10 plugins/decoder/ffmpeg/k3bffmpegwrapper.cpp http://commits.kde.org/k3b/5b9b3537b658ad342d688fa4f210113a3d066d2a diff --git a/plugins/decoder/ffmpeg/k3bffmpegwrapper.cpp b/plugins/decoder/= ffmpeg/k3bffmpegwrapper.cpp index 5451fd3..4398cea 100644 --- a/plugins/decoder/ffmpeg/k3bffmpegwrapper.cpp +++ b/plugins/decoder/ffmpeg/k3bffmpegwrapper.cpp @@ -86,8 +86,12 @@ public: K3b::Msf length; = // for decoding. ffmpeg requires 16-byte alignment. +#ifdef HAVE_FFMPEG_AVCODEC_DECODE_AUDIO4 + ::AVFrame* frame; +#else char outputBuffer[AVCODEC_MAX_AUDIO_FRAME_SIZE + 15]; char* alignedOutputBuffer; +#endif char* outputBufferPos; int outputBufferSize; ::AVPacket packet; @@ -102,14 +106,29 @@ K3bFFMpegFile::K3bFFMpegFile( const QString& filename= ) d =3D new Private; d->formatContext =3D 0; d->codec =3D 0; +#ifdef HAVE_FFMPEG_AVCODEC_DECODE_AUDIO4 +# if LIBAVCODEC_BUILD < AV_VERSION_INT(54,28,0) + d->frame =3D avcodec_alloc_frame(); +# else + d->frame =3D av_frame_alloc(); +# endif +#else int offset =3D 0x10 - (reinterpret_cast(&d->outputBuffer) & = 0xf); d->alignedOutputBuffer =3D &d->outputBuffer[offset]; +#endif } = = K3bFFMpegFile::~K3bFFMpegFile() { close(); +#ifdef HAVE_FFMPEG_AVCODEC_DECODE_AUDIO4 +# if LIBAVCODEC_BUILD < AV_VERSION_INT(54,28,0) + av_free(d->frame); +# else + av_frame_free(&d->frame); +# endif +#endif delete d; } = @@ -326,35 +345,60 @@ int K3bFFMpegFile::fillOutputBuffer() return 0; } = +#ifdef HAVE_FFMPEG_AVCODEC_DECODE_AUDIO4 + int gotFrame =3D 0; + int len =3D ::avcodec_decode_audio4( +#else d->outputBufferPos =3D d->alignedOutputBuffer; d->outputBufferSize =3D AVCODEC_MAX_AUDIO_FRAME_SIZE; - -#ifdef HAVE_FFMPEG_AVCODEC_DECODE_AUDIO3 +# ifdef HAVE_FFMPEG_AVCODEC_DECODE_AUDIO3 int len =3D ::avcodec_decode_audio3( -#else -# ifdef HAVE_FFMPEG_AVCODEC_DECODE_AUDIO2 - int len =3D ::avcodec_decode_audio2( # else +# ifdef HAVE_FFMPEG_AVCODEC_DECODE_AUDIO2 + int len =3D ::avcodec_decode_audio2( +# else int len =3D ::avcodec_decode_audio( +# endif # endif #endif = FFMPEG_CODEC(d->formatContext->streams[0]), +#ifdef HAVE_FFMPEG_AVCODEC_DECODE_AUDIO4 + d->frame, + &gotFrame, + &d->packet ); +#else (short*)d->alignedOutputBuffer, &d->outputBufferSize, -#ifdef HAVE_FFMPEG_AVCODEC_DECODE_AUDIO3 +# ifdef HAVE_FFMPEG_AVCODEC_DECODE_AUDIO3 &d->packet ); -#else +# else d->packetData, d->packetSize ); +# endif #endif = if( d->packetSize <=3D 0 || len < 0 ) +#if LIBAVCODEC_VERSION_MAJOR >=3D 56 + ::av_packet_unref( &d->packet ); +#else ::av_free_packet( &d->packet ); +#endif if( len < 0 ) { kDebug() << "(K3bFFMpegFile) decoding failed for " << m_filena= me; return -1; } = +#ifdef HAVE_FFMPEG_AVCODEC_DECODE_AUDIO4 + if ( gotFrame ) { + d->outputBufferSize =3D ::av_samples_get_buffer_size( + NULL, + FFMPEG_CODEC(d->formatContext->streams[0])->channels, + d->frame->nb_samples, + FFMPEG_CODEC(d->formatContext->streams[0])->sample_fmt, + 1 ); + d->outputBufferPos =3D reinterpret_cast( d->frame->data= [0] ); + } +#endif d->packetSize -=3D len; d->packetData +=3D len; } @@ -420,9 +464,9 @@ K3bFFMpegFile* K3bFFMpegWrapper::open( const QString& f= ilename ) const // mp3 being one of them sadly. Most importantly: allow the libsnd= file decoder to do // its thing. // - if( file->type() =3D=3D CODEC_ID_WMAV1 || - file->type() =3D=3D CODEC_ID_WMAV2 || - file->type() =3D=3D CODEC_ID_AAC ) + if( file->type() =3D=3D AV_CODEC_ID_WMAV1 || + file->type() =3D=3D AV_CODEC_ID_WMAV2 || + file->type() =3D=3D AV_CODEC_ID_AAC ) #endif return file; }