Fix build failures against ffmpeg up to version 0.11

(cherry picked from commit 86848f246d)
v3.5.13-sru
Slávek Banko 12 years ago
parent 518645565b
commit eb9983a2a2

@ -17,6 +17,7 @@
#ifdef NEW_FFMPEG
#include <libavcodec/avcodec.h>
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
#endif
// This is probably the incorrect revision for when CODEC_TYPE_VIDEO was removed
@ -33,6 +34,7 @@
void *CodecHandle=0;
void *FormatHandle=0;
void *UtilHandle=0;
int glibref=0;
#ifdef NEW_FFMPEG
@ -52,6 +54,7 @@ k9AviDecode::k9AviDecode(TQObject *parent, const char *name)
if (glibref==0) {
CodecHandle=dlopen("libavcodec.so",RTLD_LAZY | RTLD_GLOBAL);
FormatHandle=dlopen("libavformat.so",RTLD_LAZY | RTLD_GLOBAL);
UtilHandle=dlopen("libavutil.so",RTLD_LAZY | RTLD_GLOBAL);
}
if (!CodecHandle) {
m_error =i18n("Cannot open then library %1").arg("libavcodec");
@ -61,27 +64,57 @@ k9AviDecode::k9AviDecode(TQObject *parent, const char *name)
m_error =i18n("Cannot open then library %1").arg("libavformat");
return;
}
# if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51, 33, 0)
if (!UtilHandle) {
m_error =i18n("Cannot open then library %1").arg("libavutil");
return;
}
# endif
m_error="";
av_register_all = (av_register_all_t)dlsym(FormatHandle,"av_register_all");
# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 2, 0)
avformat_open_input = (avformat_open_input_t)dlsym(FormatHandle,"avformat_open_input");
# else
av_open_input_file = (av_open_input_file_t)dlsym(FormatHandle,"av_open_input_file");
# endif
# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 6, 0)
avformat_find_stream_info = (avformat_find_stream_info_t)dlsym(FormatHandle,"avformat_find_stream_info");
# else
av_find_stream_info = (av_find_stream_info_t)dlsym(FormatHandle,"av_find_stream_info");
# endif
avcodec_find_decoder =(avcodec_find_decoder_t) dlsym(CodecHandle,"avcodec_find_decoder");
# if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53, 8, 0)
avcodec_open2 = (avcodec_open2_t)dlsym(CodecHandle,"avcodec_open2");
# else
avcodec_open = (avcodec_open_t)dlsym(CodecHandle,"avcodec_open");
# endif
avcodec_alloc_frame = (avcodec_alloc_frame_t)dlsym(CodecHandle,"avcodec_alloc_frame");
avpicture_get_size = (avpicture_get_size_t)dlsym(CodecHandle,"avpicture_get_size");
av_malloc = (av_malloc_t)dlsym(CodecHandle,"av_malloc");
avpicture_fill = (avpicture_fill_t)dlsym(CodecHandle,"avpicture_fill");
av_read_frame = (av_read_frame_t)dlsym(FormatHandle,"av_read_frame");
# if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 23, 0)
avcodec_decode_video2 = (avcodec_decode_video2_t)dlsym(CodecHandle,"avcodec_decode_video2");
# else
avcodec_decode_video = (avcodec_decode_video_t)dlsym(CodecHandle,"avcodec_decode_video");
# endif
img_convert = (img_convert_t)dlsym(CodecHandle,"img_convert");
av_free = (av_free_t)dlsym(CodecHandle,"av_free");
avcodec_close = (avcodec_close_t)dlsym(FormatHandle,"avcodec_close");
# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 17, 0)
avformat_close_input = (avformat_close_input_t)dlsym(FormatHandle,"avformat_close_input");
# else
av_close_input_file = (av_close_input_file_t)dlsym(FormatHandle,"av_close_input_file");
# endif
av_seek_frame=(av_seek_frame_t)dlsym(FormatHandle,"av_seek_frame");
av_rescale_q=(av_rescale_q_t)dlsym(FormatHandle,"av_rescale_q");
avcodec_flush_buffers=(avcodec_flush_buffers_t)dlsym(CodecHandle,"avcodec_flush_buffers");
# if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51, 33, 0)
av_gettime=(av_gettime_t)dlsym(UtilHandle,"av_gettime");
# else
av_gettime=(av_gettime_t)dlsym(FormatHandle,"av_gettime");
# endif
av_register_all();
m_opened=false;
@ -96,6 +129,9 @@ k9AviDecode::~k9AviDecode() {
if (glibref==0) {
dlclose(FormatHandle);
dlclose(CodecHandle);
if(UtilHandle) {
dlclose(UtilHandle);
}
}
}
@ -110,12 +146,24 @@ bool k9AviDecode::open(const TQString & _fileName) {
close();
// Open video file
if (av_open_input_file(&m_FormatCtx, _fileName.utf8(), NULL, 0, NULL)!=0) {
if (
# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 2, 0)
avformat_open_input(&m_FormatCtx, _fileName.utf8(), 0, 0)!=0
# else
av_open_input_file(&m_FormatCtx, _fileName.utf8(), NULL, 0, NULL)!=0
# endif
) {
m_error=i18n("Couldn't open the file %1").arg(_fileName);
return false; // Couldn't open file}
}
// Retrieve stream information
if (av_find_stream_info(m_FormatCtx)<0) {
if (
# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 6, 0)
avformat_find_stream_info(m_FormatCtx, NULL)<0
# else
av_find_stream_info(m_FormatCtx)<0
# endif
) {
m_error =i18n("Couldn't find stream information");
return false; // Couldn't find stream information
}
@ -144,7 +192,13 @@ bool k9AviDecode::open(const TQString & _fileName) {
return false; // Codec not found
}
// Open codec
if (avcodec_open(m_CodecCtx, m_Codec)<0) {
if (
# if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53, 8, 0)
avcodec_open2(m_CodecCtx, m_Codec, NULL)<0
# else
avcodec_open(m_CodecCtx, m_Codec)<0
# endif
) {
m_error =i18n("Could'nt open the codec");
return false; // Could not open codec
}
@ -201,15 +255,23 @@ void k9AviDecode::readFrame(double _seconds) {
// Is this a packet from the video stream?
if (packet.stream_index==m_videoStream) {
// Decode video frame
# if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 23, 0)
avcodec_decode_video2(m_CodecCtx, m_Frame, &frameFinished, &packet);
# else
avcodec_decode_video(m_CodecCtx, m_Frame, &frameFinished,
packet.data, packet.size);
# endif
// Did we get a video frame?
if (frameFinished) {
// if (m_Frame->pts >=fspos)
int64_t cur_dts=fspos;
# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(54, 2, 0)
cur_dts= packet.dts;
# else
if (m_FormatCtx->cur_st)
cur_dts= m_FormatCtx->cur_st->cur_dts;
# endif
if (cur_dts >=fspos) {
bFound=true;
// Convert the image from its native format to RGB
@ -258,7 +320,11 @@ void k9AviDecode::close() {
avcodec_close(m_CodecCtx);
// Close the video file
# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 17, 0)
avformat_close_input(&m_FormatCtx);
# else
av_close_input_file(m_FormatCtx);
# endif
m_opened=false;
}
}

@ -19,6 +19,7 @@
#endif
#ifdef NEW_FFMPEG
#include <libavformat/avformat.h>
#include <libavutil/avutil.h>
#endif
@ -32,10 +33,22 @@
//typedef dvd_file_t * (*DVDOpenFile_t) ( dvd_reader_t *, int, dvd_read_domain_t );
typedef void (*av_register_all_t) (void);
typedef int64_t (*av_gettime_t) (void);
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 2, 0)
typedef int (*avformat_open_input_t)(AVFormatContext **, const char *, AVInputFormat *, AVDictionary **);
#else
typedef int (*av_open_input_file_t)(AVFormatContext **, const char *,AVInputFormat *,int, AVFormatParameters *);
#endif
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 6, 0)
typedef int (*avformat_find_stream_info_t)(AVFormatContext *, AVDictionary **);
#else
typedef int (*av_find_stream_info_t)(AVFormatContext *);
#endif
typedef AVCodec* (*avcodec_find_decoder_t)(enum CodecID);
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53, 8, 0)
typedef int (*avcodec_open2_t)(AVCodecContext *, AVCodec *, AVDictionary **);
#else
typedef int (*avcodec_open_t)(AVCodecContext *, AVCodec *);
#endif
typedef AVFrame * (*avcodec_alloc_frame_t)(void);
typedef int (*avpicture_get_size_t)(int , int , int );
@ -43,11 +56,19 @@ typedef void * (*av_malloc_t)(unsigned int );
typedef int (*avpicture_fill_t)(AVPicture *, uint8_t *,int , int , int);
typedef int (*av_read_frame_t)(AVFormatContext *, AVPacket *);
#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 23, 0)
typedef int (*avcodec_decode_video2_t)(AVCodecContext *, AVFrame *, int *, AVPacket *);
#else
typedef int (*avcodec_decode_video_t)(AVCodecContext *, AVFrame *,int *, uint8_t *, int );
#endif
typedef int (*img_convert_t)(AVPicture *, int , const AVPicture *, int ,int, int);
typedef void (*av_free_t)(void *);
typedef int (*avcodec_close_t)(AVCodecContext *);
#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 17, 0)
typedef void (*avformat_close_input_t)(AVFormatContext **);
#else
typedef void (*av_close_input_file_t)(AVFormatContext *);
#endif
typedef int (*av_seek_frame_t)(AVFormatContext *,int,int64_t timestamp,int flags); typedef int64_t (*av_rescale_q_t)(int64_t , AVRational , AVRational ) ;
typedef void (*avcodec_flush_buffers_t)(AVCodecContext *);
@ -75,21 +96,41 @@ public:
private:
av_register_all_t av_register_all;
# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 2, 0)
avformat_open_input_t avformat_open_input;
# else
av_open_input_file_t av_open_input_file;
# endif
# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 6, 0)
avformat_find_stream_info_t avformat_find_stream_info;
# else
av_find_stream_info_t av_find_stream_info;
# endif
avcodec_find_decoder_t avcodec_find_decoder;
# if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53, 8, 0)
avcodec_open2_t avcodec_open2;
# else
avcodec_open_t avcodec_open;
# endif
avcodec_alloc_frame_t avcodec_alloc_frame;
av_seek_frame_t av_seek_frame;
avpicture_get_size_t avpicture_get_size;
av_malloc_t av_malloc;
avpicture_fill_t avpicture_fill;
av_read_frame_t av_read_frame;
# if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52, 23, 0)
avcodec_decode_video2_t avcodec_decode_video2;
# else
avcodec_decode_video_t avcodec_decode_video;
# endif
img_convert_t img_convert;
av_free_t av_free;
avcodec_close_t avcodec_close;
# if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(53, 17, 0)
avformat_close_input_t avformat_close_input;
# else
av_close_input_file_t av_close_input_file;
# endif
av_rescale_q_t av_rescale_q;
av_gettime_t av_gettime;
avcodec_flush_buffers_t avcodec_flush_buffers;

Loading…
Cancel
Save