Added support for using libswscale

This commit is contained in:
Robert Osfield
2009-03-04 11:05:55 +00:00
parent 97e987a9d9
commit fb54fd0a69
6 changed files with 99 additions and 34 deletions

View File

@@ -5,12 +5,14 @@
#include <stdexcept>
#include <string.h>
#if 0
extern "C"
{
int img_convert(AVPicture *dst, int dst_pix_fmt, const AVPicture *src,
int src_pix_fmt, int src_width, int src_height);
};
#endif
namespace osgFFmpeg {
@@ -27,7 +29,8 @@ FFmpegDecoderVideo::FFmpegDecoderVideo(PacketQueue & packets, FFmpegClocks & clo
m_packet_pts(AV_NOPTS_VALUE),
m_user_data(0),
m_publish_func(0),
m_exit(false)
m_exit(false),
m_swscale_ctx(0)
{
}
@@ -41,6 +44,12 @@ FFmpegDecoderVideo::~FFmpegDecoderVideo()
m_exit = true;
join();
}
if (m_swscale_ctx)
{
sws_freeContext(m_swscale_ctx);
m_swscale_ctx = 0;
}
}
@@ -210,6 +219,25 @@ void FFmpegDecoderVideo::findAspectRatio()
m_aspect_ratio = ratio;
}
int FFmpegDecoderVideo::convert(AVPicture *dst, int dst_pix_fmt, const AVPicture *src,
int src_pix_fmt, int src_width, int src_height)
{
#ifdef USE_SWSCALE
if (m_swscale_ctx==0)
{
m_swscale_ctx = sws_getContext(src_width, src_height, src_pix_fmt,
src_width, src_height, dst_pix_fmt,
SWS_BILINEAR, NULL, NULL, NULL);
}
return sws_scale(m_swscale_ctx,
src->data, src->linesize, 0, src_height,
dst->data, dst->linesize);
#else
return convert(dst, dst_pix_fmt, src,
src_pix_fmt, src_width, src_height)
#endif
}
void FFmpegDecoderVideo::publishFrame(const double delay)
@@ -230,7 +258,7 @@ void FFmpegDecoderVideo::publishFrame(const double delay)
if (m_context->pix_fmt == PIX_FMT_YUVA420P)
yuva420pToRgba(dst, src, width(), height());
else
img_convert(dst, PIX_FMT_RGB32, src, m_context->pix_fmt, width(), height());
convert(dst, PIX_FMT_RGB32, src, m_context->pix_fmt, width(), height());
// Flip and swap buffer
swapBuffers();
@@ -266,7 +294,7 @@ void FFmpegDecoderVideo::swapBuffers()
void FFmpegDecoderVideo::yuva420pToRgba(AVPicture * const dst, const AVPicture * const src, int width, int height)
{
img_convert(dst, PIX_FMT_RGB32, src, m_context->pix_fmt, width, height);
convert(dst, PIX_FMT_RGB32, src, m_context->pix_fmt, width, height);
const size_t bpp = 4;