Skip to content

Commit

Permalink
use ImageConverter and remove useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Jan 15, 2013
1 parent ab2d754 commit d8e13ba
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 61 deletions.
2 changes: 0 additions & 2 deletions src/QtAV/QtAV_Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
#ifndef QTAV_GLOBAL_H
#define QTAV_GLOBAL_H

#define CONFIG_IMAGECONVERTER 1

#include <qglobal.h>
#include <dptr.h>

Expand Down
60 changes: 1 addition & 59 deletions src/VideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@

#include <QtAV/VideoDecoder.h>
#include <private/AVDecoder_p.h>
#include <QtAV/ImageConverterFF.h>
#include <QtAV/Packet.h>
#include <QtAV/QtAV_Compat.h>
#include <QtCore/QSize>

#if CONFIG_IMAGECONVERTER
#include <QtAV/ImageConverterFF.h>
#endif //CONFIG_IMAGECONVERTER

#if CONFIG_EZX
#define PIX_FMT PIX_FMT_BGR565
#else
Expand All @@ -38,7 +35,6 @@ class VideoDecoderPrivate : public AVDecoderPrivate
{
public:
VideoDecoderPrivate():width(0),height(0)
#if CONFIG_IMAGECONVERTER
{
conv = new ImageConverterFF(); //TODO: set in AVPlayer
conv->setOutFormat(PIX_FMT_RGB32);
Expand All @@ -50,19 +46,8 @@ class VideoDecoderPrivate : public AVDecoderPrivate
}
}

#else
,sws_ctx(0),pix_fmt(PIX_FMT){}
#endif //!CONFIG_IMAGECONVERTER

int width, height;

#if CONFIG_IMAGECONVERTER
ImageConverter* conv;
#else
SwsContext *sws_ctx;
enum PixelFormat pix_fmt;
AVPicture picture;
#endif //CONFIG_IMAGECONVERTER
};

VideoDecoder::VideoDecoder()
Expand Down Expand Up @@ -100,38 +85,13 @@ bool VideoDecoder::decode(const QByteArray &encoded)
return false;
resizeVideo(d.codec_ctx->width, d.codec_ctx->height);
}
//d.decoded = QByteArray::fromRawData((char*)d.frame->data[0], d.decoded.size());
//return true;
//If not YUV420P or ImageConverter supported format pair, convert to YUV420P first. or directly convert to RGB?(no hwa)
//TODO: move convertion out. decoder only do some decoding
#if CONFIG_IMAGECONVERTER
//if not yuv420p or conv supported convertion pair(in/out), convert to yuv420p first using ff, then use other yuv2rgb converter
d.conv->setInFormat(d.codec_ctx->pix_fmt);
d.conv->setInSize(d.codec_ctx->width, d.codec_ctx->height);
d.conv->convert(d.frame->data, d.frame->linesize);
d.decoded = d.conv->outData();
#else
d.sws_ctx = sws_getCachedContext(d.sws_ctx
, d.codec_ctx->width, d.codec_ctx->height, d.codec_ctx->pix_fmt
, d.width, d.height, d.pix_fmt
, (d.width == d.codec_ctx->width && d.height == d.codec_ctx->height) ? SWS_POINT : SWS_FAST_BILINEAR //SWS_BICUBIC
, NULL, NULL, NULL
);

int v_scale_result = sws_scale(
d.sws_ctx,
d.frame->data,
d.frame->linesize,
0,
d.codec_ctx->height,
d.picture.data,
d.picture.linesize
);
Q_UNUSED(v_scale_result);
//sws_freeContext(v_sws_ctx);
if (d.frame->interlaced_frame) //?
avpicture_deinterlace(&d.picture, &d.picture, d.pix_fmt, d.width, d.height);
#endif //CONFIG_IMAGECONVERTER
return true;
}

Expand All @@ -144,26 +104,8 @@ void VideoDecoder::resizeVideo(int width, int height)
{
if (width == 0 || height == 0)
return;

DPTR_D(VideoDecoder);

#if CONFIG_IMAGECONVERTER
d.conv->setOutSize(width, height);
#else
int bytes = avpicture_get_size(PIX_FMT, width, height);
if(d.decoded.size() < bytes) {
d.decoded.resize(bytes);
}
//picture的数据按PIX_FMT格式自动"关联"到 data
avpicture_fill(
&d.picture,
reinterpret_cast<uint8_t*>(d.decoded.data()),
d.pix_fmt,
width,
height
);
#endif //CONFIG_IMAGECONVERTER

d.width = width;
d.height = height;
}
Expand Down

0 comments on commit d8e13ba

Please sign in to comment.