plugins/ffmpeg_decoder: Add support for older FFmpeg API.

Signed-off-by: Slávek Banko <slavek.banko@axis.cz>
(cherry picked from commit d4affcc0cb)
r14.0.x
Slávek Banko 3 years ago committed by Michele Calgaro
parent 9655286dc7
commit baa3aed9e1
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -18,6 +18,8 @@
Boston, MA 02110-1301, USA. Boston, MA 02110-1301, USA.
*/ */
#define __STDC_CONSTANT_MACROS
#include "akodelib.h" #include "akodelib.h"
// #ifdef HAVE_FFMPEG // #ifdef HAVE_FFMPEG
@ -236,7 +238,11 @@ void FFMPEGDecoder::closeFile() {
#endif #endif
} }
if( d->packetSize > 0 ) { if( d->packetSize > 0 ) {
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 7, 0)
av_free_packet(&d->packet);
#else
av_packet_unref( &d->packet ); av_packet_unref( &d->packet );
#endif
d->packetSize = 0; d->packetSize = 0;
} }
@ -259,7 +265,11 @@ bool FFMPEGDecoder::readPacket() {
do { do {
av_init_packet(&d->packet); av_init_packet(&d->packet);
if ( av_read_frame(d->ic, &d->packet) < 0 ) { if ( av_read_frame(d->ic, &d->packet) < 0 ) {
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 7, 0)
av_free_packet(&d->packet);
#else
av_packet_unref( &d->packet ); av_packet_unref( &d->packet );
#endif
d->packetSize = 0; d->packetSize = 0;
d->packetData = 0; d->packetData = 0;
return false; return false;
@ -269,7 +279,11 @@ bool FFMPEGDecoder::readPacket() {
d->packetData = d->packet.data; d->packetData = d->packet.data;
return true; return true;
} }
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 7, 0)
av_free_packet(&d->packet);
#else
av_packet_unref(&d->packet); av_packet_unref(&d->packet);
#endif
} while (true); } while (true);
return false; return false;
@ -313,7 +327,11 @@ bool FFMPEGDecoder::readFrame(AudioFrame* frame)
assert(d->packet.stream_index == d->audioStream); assert(d->packet.stream_index == d->audioStream);
retry: retry:
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55, 45, 101)
AVFrame *decodeFrame = avcodec_alloc_frame();
#else
AVFrame *decodeFrame = av_frame_alloc(); AVFrame *decodeFrame = av_frame_alloc();
#endif
if (!decodeFrame) { if (!decodeFrame) {
return false; return false;
} }
@ -363,12 +381,24 @@ retry:
default: default:
assert(false); assert(false);
} }
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(54, 28, 0)
av_free(decodeFrame);
#elif LIBAVCODEC_VERSION_INT < AV_VERSION_INT(55, 45, 101)
avcodec_free_frame(&decodeFrame);
#else
av_frame_free(&decodeFrame); av_frame_free(&decodeFrame);
#endif
if (length == 0) return readFrame(frame); if (length == 0) return readFrame(frame);
// std::cout << "akode: FFMPEG: Frame length: " << length << "\n"; // std::cout << "akode: FFMPEG: Frame length: " << length << "\n";
if( d->packetSize <= 0 ) if( d->packetSize <= 0 )
{
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(57, 7, 0)
av_free_packet(&d->packet);
#else
av_packet_unref( &d->packet ); av_packet_unref( &d->packet );
#endif
}
frame->pos = (d->position*1000)/d->config.sample_rate; frame->pos = (d->position*1000)/d->config.sample_rate;
d->position += length; d->position += length;

Loading…
Cancel
Save