Fix crash when img_convert unavailable

pull/1/head
Timothy Pearson 10 years ago
parent 18d94a8600
commit effa31d902

@ -93,6 +93,9 @@
/* Define if you have the strlcpy prototype */
#undef HAVE_STRLCPY_PROTO
/* swscale support */
#undef HAVE_SWSCALE
/* Define to 1 if you have the <sys/bitypes.h> header file. */
#undef HAVE_SYS_BITYPES_H
@ -127,6 +130,9 @@
/* No openGL support */
#undef NO_OPENGL
/* No swscale support */
#undef NO_SWSCALE
/* old ffmpeg */
#undef OLD_FFMPEG

@ -73,3 +73,8 @@ CXXFLAGS="$cxx_flags_safe"
CFLAGS="$cflags_safe"
AC_LANG_RESTORE
have_swscale=no
AC_CHECK_HEADER([libswscale/swscale.h], \
[AC_DEFINE(HAVE_SWSCALE, 1, [swscale support]) have_swscale=yes], \
[AC_DEFINE(NO_SWSCALE, 1, [No swscale support])])

@ -35,6 +35,7 @@
void *CodecHandle=0;
void *FormatHandle=0;
void *UtilHandle=0;
void *SwscaleHandle=0;
int glibref=0;
#ifdef NEW_FFMPEG
@ -49,12 +50,22 @@ void av_free_packet(AVPacket *pkt)
#endif
#endif
#ifdef HAVE_SWSCALE
#include "libswscale/swscale.h"
static int sws_flags = SWS_BICUBIC;
#endif
k9AviDecode::k9AviDecode(TQObject *parent, const char *name)
: TQObject(parent, 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);
# ifdef HAVE_SWSCALE
SwscaleHandle=dlopen("libswscale.so",RTLD_LAZY);
if (SwscaleHandle==0)
SwscaleHandle=dlopen("libswscale.so.2",RTLD_LAZY);
# endif
}
if (!CodecHandle) {
m_error =i18n("Cannot open then library %1").arg("libavcodec");
@ -69,6 +80,11 @@ k9AviDecode::k9AviDecode(TQObject *parent, const char *name)
m_error =i18n("Cannot open then library %1").arg("libavutil");
return;
}
# endif
# ifdef HAVE_SWSCALE
if (!SwscaleHandle) {
m_error =i18n("Cannot open the library %1").arg("libswscale");
}
# endif
m_error="";
av_register_all = (av_register_all_t)dlsym(FormatHandle,"av_register_all");
@ -98,7 +114,12 @@ k9AviDecode::k9AviDecode(TQObject *parent, const char *name)
# else
avcodec_decode_video = (avcodec_decode_video_t)dlsym(CodecHandle,"avcodec_decode_video");
# endif
# ifndef HAVE_SWSCALE
img_convert = (img_convert_t)dlsym(CodecHandle,"img_convert");
//if img_convert is null (deprecated in ffmpeg), we need libswscale
if (!img_convert)
errs << i18n("Cannot open the library %1").arg("libswscale");
# endif
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)
@ -109,6 +130,11 @@ k9AviDecode::k9AviDecode(TQObject *parent, const char *name)
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");
# ifdef HAVE_SWSCALE
sws_freeContext= (sws_freeContext_t)dlsym(SwscaleHandle,"sws_freeContext");
sws_getContext=(sws_getContext_t)dlsym(SwscaleHandle,"sws_getContext");
sws_scale= (sws_scale_t)dlsym(SwscaleHandle,"sws_scale");
# endif
# if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51, 33, 0)
av_gettime=(av_gettime_t)dlsym(UtilHandle,"av_gettime");
@ -139,6 +165,11 @@ k9AviDecode::~k9AviDecode() {
if(UtilHandle) {
dlclose(UtilHandle);
}
# ifdef HAVE_SWSCALE
if (SwscaleHandle) {
dlclose(CodecHandle);
}
# endif
}
}
@ -257,6 +288,9 @@ void k9AviDecode::readFrame(double _seconds) {
int frameFinished=0;
AVPacket packet;
# ifdef HAVE_SWSCALE
struct SwsContext *toRGB_convert_ctx;
# endif
bool bFound=false;
while (av_read_frame(m_FormatCtx, &packet)>=0 && !bFound) {
// Is this a packet from the video stream?
@ -281,6 +315,7 @@ void k9AviDecode::readFrame(double _seconds) {
# endif
if (cur_dts >=fspos) {
bFound=true;
# ifndef HAVE_SWSCALE
// Convert the image from its native format to RGB
img_convert((AVPicture *)m_FrameRGB, PIX_FMT_RGB24,
(AVPicture*)m_Frame, m_CodecCtx->pix_fmt,
@ -289,6 +324,14 @@ void k9AviDecode::readFrame(double _seconds) {
// convert frame to TQImage
SaveFrame(m_FrameRGB, m_CodecCtx->width,
m_CodecCtx->height);
# else
toRGB_convert_ctx=sws_getContext(m_CodecCtx->width, m_CodecCtx->height, m_CodecCtx->pix_fmt, m_CodecCtx->width, m_CodecCtx->height, PIX_FMT_RGB24, sws_flags,NULL,NULL,NULL);
sws_scale(toRGB_convert_ctx, m_Frame->data, m_Frame->linesize, 0, m_CodecCtx->height, m_FrameRGB->data,m_FrameRGB->linesize);
// convert frame to QImage
SaveFrame(m_FrameRGB, m_CodecCtx->width,
m_CodecCtx->height);
sws_freeContext(toRGB_convert_ctx);
# endif
}
}
}

@ -22,6 +22,9 @@
#include <libavutil/avutil.h>
#endif
#ifdef HAVE_SWSCALE
#include <libswscale/swscale.h>
#endif
#include <tqimage.h>
@ -76,7 +79,11 @@ typedef void (*av_close_input_file_t)(AVFormatContext *);
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 *);
#ifdef HAVE_SWSCALE
typedef void (*sws_freeContext_t)(struct SwsContext *swsContext);
typedef struct SwsContext* (*sws_getContext_t)(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat, int flags, SwsFilter *srcFilter, SwsFilter *dstFilter, double *param);
typedef int (*sws_scale_t)(struct SwsContext *context, uint8_t* src[], int srcStride[], int srcSliceY,int srcSliceH, uint8_t* dst[], int dstStride[]);
#endif
class k9AviDecode : public TQObject
@ -138,6 +145,11 @@ private:
av_rescale_q_t av_rescale_q;
av_gettime_t av_gettime;
avcodec_flush_buffers_t avcodec_flush_buffers;
# ifdef HAVE_SWSCALE
sws_freeContext_t sws_freeContext;
sws_getContext_t sws_getContext;
sws_scale_t sws_scale;
# endif
AVFormatContext *m_FormatCtx;

Loading…
Cancel
Save