Skip to content

Commit

Permalink
names change, warning fix, move some public members to private
Browse files Browse the repository at this point in the history
I think QtAV is not used widely today, so api change does not matter
  • Loading branch information
wang-bin committed Feb 28, 2013
1 parent 1e2c3b4 commit 11e04f5
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 95 deletions.
2 changes: 1 addition & 1 deletion examples/videographicsitem/videoplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ VideoPlayer::VideoPlayer(QWidget *parent)
, videoItem(0)
{
videoItem = new GraphicsItemRenderer;
videoItem->resizeVideo(640, 360);
videoItem->resizeRenderer(640, 360);
videoItem->setOutAspectRatioMode(VideoRenderer::RendererAspectRatio);

QGraphicsScene *scene = new QGraphicsScene(this);
Expand Down
8 changes: 4 additions & 4 deletions src/AVPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ VideoRenderer* AVPlayer::setRenderer(VideoRenderer *r)
if (isPlaying())
stop();
//delete _renderer; //Do not own the ptr
_renderer->resizeVideo(_renderer->videoSize()); //IMPORTANT: the swscaler will resize
_renderer->resizeRenderer(_renderer->rendererSize()); //IMPORTANT: the swscaler will resize
}
return old;
}
Expand Down Expand Up @@ -164,10 +164,10 @@ void AVPlayer::setPlayerEventFilter(QObject *obj)
}

//TODO: remove?
void AVPlayer::resizeVideo(const QSize &size)
void AVPlayer::resizeRenderer(const QSize &size)
{
_renderer->resizeVideo(size); //TODO: deprecate
//video_dec->resizeVideo(size);
_renderer->resizeRenderer(size); //TODO: deprecate
//video_dec->resizeVideoFrame(size);
}
/*
* loaded state is the state of current setted file.
Expand Down
4 changes: 2 additions & 2 deletions src/Direct2DRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class Direct2DRendererPrivate : public VideoRendererPrivate
// change, remoting, removal of video card, etc).
//
//TODO: move to prepare(), or private. how to call less times
D2D1_SIZE_U size = D2D1::SizeU(p.width(), p.height());//d.width, d.height?
D2D1_SIZE_U size = D2D1::SizeU(p.width(), p.height());//d.renderer_width, d.renderer_height?
// Create a Direct2D render target.
HRESULT hr = d2d_factory->CreateHwndRenderTarget(
D2D1::RenderTargetProperties(), //TODO: vlc set properties
Expand Down Expand Up @@ -201,7 +201,7 @@ bool Direct2DRenderer::useQPainter() const

void Direct2DRenderer::resizeEvent(QResizeEvent *e)
{
resizeVideo(e->size());
resizeRenderer(e->size());

DPTR_D(Direct2DRenderer);
if (d.render_target) {
Expand Down
4 changes: 2 additions & 2 deletions src/GDIRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void GDIRenderer::showEvent(QShowEvent *)

void GDIRenderer::resizeEvent(QResizeEvent *e)
{
resizeVideo(e->size());
resizeRenderer(e->size());
update();
}

Expand Down Expand Up @@ -195,7 +195,7 @@ void GDIRenderer::paintEvent(QPaintEvent *)
}
HBITMAP hbmp_old = (HBITMAP)SelectObject(d.off_dc, d.off_bitmap);
// && image.size() != size()
if (d.scale_in_qt || d.src_width != d.width || d.src_height != d.height) { //TODO:rename scale_on_paint
if (d.scale_in_qt || d.src_width != d.renderer_width || d.src_height != d.renderer_height) { //TODO:rename scale_on_paint
StretchBlt(hdc, 0, 0, width(), height(), d.off_dc, 0, 0, d.src_width, d.src_height, SRCCOPY);
} else {
BitBlt(hdc, 0, 0, d.src_width, d.src_height, d.off_dc, 0, 0, SRCCOPY);
Expand Down
8 changes: 4 additions & 4 deletions src/GraphicsItemRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ bool GraphicsItemRenderer::write()

QRectF GraphicsItemRenderer::boundingRect() const
{
return QRectF(0, 0, videoWidth(), videoHeight());
return QRectF(0, 0, rendererWidth(), rendererHeight());
}

void GraphicsItemRenderer::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Expand All @@ -75,11 +75,11 @@ void GraphicsItemRenderer::paint(QPainter *painter, const QStyleOptionGraphicsIt
}
painter->fillRect(boundingRect(), QColor(0, 0, 0));
if (d.image.isNull()) {
//TODO: when setSourceSize()?
d.image = QImage(videoSize(), QImage::Format_RGB32);
//TODO: when setInSize()?
d.image = QImage(rendererSize(), QImage::Format_RGB32);
d.image.fill(Qt::black); //maemo 4.7.0: QImage.fill(uint)
}
if (d.image.size() == QSize(d.width, d.height))
if (d.image.size() == QSize(d.renderer_width, d.renderer_height))
painter->drawImage(d.out_rect.topLeft(), d.image);
else
painter->drawImage(d.out_rect, d.image);
Expand Down
2 changes: 1 addition & 1 deletion src/ImageRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void ImageRenderer::convertData(const QByteArray &data)
//int ss = 4*d.src_width*d.src_height*sizeof(char);
//if (ss != data.size())
// qDebug("src size=%d, data size=%d", ss, data.size());
//if (d.src_width != d.width || d.src_height != d.height)
//if (d.src_width != d.renderer_width || d.src_height != d.renderer_height)
// return;
/*
* QImage constructed from memory do not deep copy the data, data should be available throughout
Expand Down
2 changes: 1 addition & 1 deletion src/QtAV/AVPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public slots:
void updateClock(qint64 msecs); //update AVClock's external clock

protected slots:
void resizeVideo(const QSize& size);
void resizeRenderer(const QSize& size);

protected:
bool loaded;
Expand Down
4 changes: 2 additions & 2 deletions src/QtAV/VideoDecoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class Q_EXPORT VideoDecoder : public AVDecoder
VideoDecoder();
virtual bool decode(const QByteArray &encoded);

void resizeVideo(const QSize& size);
void resizeVideo(int width, int height);
void resizeVideoFrame(const QSize& size);
void resizeVideoFrame(int width, int height);

int width() const;
int height() const;
Expand Down
57 changes: 31 additions & 26 deletions src/QtAV/VideoRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,12 @@
*api:
* inSize: the converted image size
* outSize: the displaying frame size with out borders in renderer
* videoSize: the original video size
*
* rendererSize: the original video size
* outAspectRatio:
* videoAspectRatio:
* rendererAspectRatio:
*
* resizeVideo=>resizeRenderer(), rendererSize(), etc.
* or videoXXX is out(display) XXX, the original XXX is videoOriginalXXX
*/
struct AVCodecContext;
struct AVFrame;
Expand All @@ -52,60 +51,66 @@ class Q_EXPORT VideoRenderer : public AVOutput
{
DPTR_DECLARE_PRIVATE(VideoRenderer)
public:
enum FrameAspectRatioMode {
enum OutAspectRatioMode {
RendererAspectRatio //Use renderer's aspect ratio, i.e. stretch to fit the renderer rect
, VideoAspectRatio //Use video's aspect ratio and align center in renderer.
, CustomAspectRation //Use the ratio set by setOutAspectRatio(qreal). Mode will be set to this if that function is called
//, AspectRatio4_3, AspectRatio16_9
};
enum Quality {

};

VideoRenderer();
virtual ~VideoRenderer() = 0;
//for testing performance
void scaleInQt(bool q);
bool scaleInQt() const;
void scaleInRenderer(bool q);
bool scaleInRenderer() const;

void setOutAspectRatioMode(FrameAspectRatioMode mode);
FrameAspectRatioMode outAspectRatioMode() const;
//If setOutAspectRatio(qreal) is used, then FrameAspectRatioMode is CustomAspectRation
void setOutAspectRatioMode(OutAspectRatioMode mode);
OutAspectRatioMode outAspectRatioMode() const;
//If setOutAspectRatio(qreal) is used, then OutAspectRatioMode is CustomAspectRation
void setOutAspectRatio(qreal ratio);
qreal outAspectRatio() const;//

//the size of image (QByteArray) that decoded
void setSourceSize(const QSize& s); //private? for internal use only, called by VideoThread.
void setSourceSize(int width, int height); //private? for internal use only, called by VideoThread.
//qreal sourceAspectRatio() const;//TODO: from AVCodecContext
//we don't need api like QSize sourceSize() const. you should get them from player or avinfo(not implemented)

//private? for internal use only, called by VideoThread.
QSize lastSize() const;
int lastWidth() const;
int lastHeight() const;

//TODO: unregister
virtual bool open();
virtual bool close();
//virtual QImage currentFrameImage() const = 0; //const QImage& const?
//TODO: resizeRenderer
void resizeVideo(const QSize& size);
void resizeVideo(int width, int height);
QSize videoSize() const;
int videoWidth() const;
int videoHeight() const;
void resizeRenderer(const QSize& size);
void resizeRenderer(int width, int height);
QSize rendererSize() const;
int rendererWidth() const;
int rendererHeight() const;
//The video frame rect in renderer you shoud paint to. e.g. in RendererAspectRatio mode, the rect equals to renderer's
QRect videoRect() const;

protected:
VideoRenderer(VideoRendererPrivate &d);
/*!
* This function is called whenever resizeVideo() is called or aspect ratio is changed?
* This function is called whenever resizeRenderer() is called or aspect ratio is changed?
* You can reimplement it to recreate the offscreen surface.
* The default does nothing.
* NOTE: usually it is thread safe, because it is called in main thread resizeEvent,
* and the surface is only used by painting, which is usually in main thread too.
* If you are doing offscreen painting in other threads, pay attention to thread safe
*/
virtual void resizeFrame(int width, int height);
private:
friend class VideoThread;

//the size of image (QByteArray) that decoded
void setInSize(const QSize& s); //private? for internal use only, called by VideoThread.
void setInSize(int width, int height); //private? for internal use only, called by VideoThread.
//qreal sourceAspectRatio() const;//TODO: from AVCodecContext
//we don't need api like QSize sourceSize() const. you should get them from player or avinfo(not implemented)

//private? for internal use only, called by VideoThread.
QSize lastSize() const;
int lastWidth() const;
int lastHeight() const;

};

} //namespace QtAV
Expand Down
21 changes: 12 additions & 9 deletions src/QtAV/private/VideoRenderer_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,21 @@
#include <QtCore/QMutex>
#include <QtCore/QRect>

/*TODO:
* Region of Interest(ROI)
*/
class QObject;
namespace QtAV {
class Q_EXPORT VideoRendererPrivate : public AVOutputPrivate
{
public:
VideoRendererPrivate():
scale_in_qt(true)
, width(480)
, height(320)
, renderer_width(480)
, renderer_height(320)
, source_aspect_ratio(0)
, src_width(0)
, src_height(0)
, source_aspect_ratio(0)
, aspect_ratio_mode(VideoRenderer::VideoAspectRatio)
, out_aspect_ratio(0)
{
Expand All @@ -51,27 +54,27 @@ class Q_EXPORT VideoRendererPrivate : public AVOutputPrivate
bool scale_in_qt;
// width, height: the renderer's size. i.e. size of video frame with the value with borders
//TODO: rename to renderer_width/height
int width, height;
int renderer_width, renderer_height;
qreal source_aspect_ratio;
int src_width, src_height;
//ImageConverter conv;
QMutex img_mutex;
VideoRenderer::FrameAspectRatioMode aspect_ratio_mode;
VideoRenderer::OutAspectRatioMode aspect_ratio_mode;
qreal out_aspect_ratio;
//out_rect: the displayed video frame out_rect in the renderer
QRect out_rect; //TODO: out_out_rect

void computeOutParameters(qreal rendererAspectRatio, qreal outAspectRatio) {
if (rendererAspectRatio > outAspectRatio) { //equals to original video aspect ratio here, also equals to out ratio
//renderer is too wide, use renderer's height, horizonal align center
int h = height;
int h = renderer_height;
int w = source_aspect_ratio * qreal(h);
out_rect = QRect((width - w)/2, 0, w, h);
out_rect = QRect((renderer_width - w)/2, 0, w, h);
} else if (rendererAspectRatio < outAspectRatio) {
//renderer is too high, use renderer's width
int w = width;
int w = renderer_width;
int h = qreal(w)/source_aspect_ratio;
out_rect = QRect(0, (height - h)/2, w, h);
out_rect = QRect(0, (renderer_height - h)/2, w, h);
}
out_aspect_ratio = outAspectRatio;
}
Expand Down
8 changes: 4 additions & 4 deletions src/VideoDecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ bool VideoDecoder::decode(const QByteArray &encoded)
, d.codec_ctx->width, d.codec_ctx->height);
if (!d.codec_ctx->width || !d.codec_ctx->height)
return false;
resizeVideo(d.codec_ctx->width, d.codec_ctx->height);
resizeVideoFrame(d.codec_ctx->width, d.codec_ctx->height);
}
//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
Expand All @@ -95,12 +95,12 @@ bool VideoDecoder::decode(const QByteArray &encoded)
return true;
}

void VideoDecoder::resizeVideo(const QSize &size)
void VideoDecoder::resizeVideoFrame(const QSize &size)
{
resizeVideo(size.width(), size.height());
resizeVideoFrame(size.width(), size.height());
}

void VideoDecoder::resizeVideo(int width, int height)
void VideoDecoder::resizeVideoFrame(int width, int height)
{
if (width == 0 || height == 0)
return;
Expand Down
Loading

0 comments on commit 11e04f5

Please sign in to comment.