Skip to content

Commit

Permalink
qml: add VideoOutput(2).contentRect
Browse files Browse the repository at this point in the history
TODO: should be done in VideoRenderer
  • Loading branch information
wang-bin committed Jan 5, 2016
1 parent bff7778 commit aeb54de
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 23 deletions.
26 changes: 22 additions & 4 deletions qml/QQuickItemRenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2013-2015 Wang Bin <[email protected]>
Copyright (C) 2013-2016 Wang Bin <[email protected]>
theoribeiro <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -59,6 +59,8 @@ class QQuickItemRendererPrivate : public VideoRendererPrivate
virtual void setupQuality() {
if (!node)
return;
if (opengl)
return;
if (quality == VideoRenderer::QualityFastest) {
((QSGSimpleTextureNode*)node)->setFiltering(QSGTexture::Nearest);
} else {
Expand Down Expand Up @@ -172,7 +174,12 @@ void QQuickItemRenderer::setFillMode(FillMode mode)
}
//m_geometryDirty = true;
//update();
emit fillModeChanged(mode);
Q_EMIT fillModeChanged(mode);
}

QRectF QQuickItemRenderer::contentRect() const
{
return videoRect();
}

bool QQuickItemRenderer::isOpenGL() const
Expand Down Expand Up @@ -285,7 +292,7 @@ void QQuickItemRenderer::afterRendering()
bool QQuickItemRenderer::onSetRegionOfInterest(const QRectF &roi)
{
Q_UNUSED(roi);
emit regionOfInterestChanged();
Q_EMIT regionOfInterestChanged();
return true;
}

Expand All @@ -296,10 +303,21 @@ bool QQuickItemRenderer::onSetOrientation(int value)
if (value == 90 || value == 270)
return false;
}
emit orientationChanged();
Q_EMIT orientationChanged();
return true;
}

void QQuickItemRenderer::onSetOutAspectRatio(qreal ratio)
{
Q_UNUSED(ratio);
Q_EMIT contentRectChanged();
}

void QQuickItemRenderer::onResizeRenderer(int, int)
{
Q_EMIT contentRectChanged();
}

void QQuickItemRenderer::onFrameSizeChanged(const QSize &size)
{
Q_UNUSED(size);
Expand Down
8 changes: 7 additions & 1 deletion qml/QmlAV/QQuickItemRenderer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2013-2015 Wang Bin <[email protected]>
Copyright (C) 2013-2016 Wang Bin <[email protected]>
theoribeiro <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -37,6 +37,7 @@ class QQuickItemRenderer : public QQuickItem, public VideoRenderer
Q_PROPERTY(QObject* source READ source WRITE setSource NOTIFY sourceChanged)
Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
Q_PROPERTY(int orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
Q_PROPERTY(QRectF contentRect READ contentRect NOTIFY contentRectChanged)
// regionOfInterest > sourceRect
Q_PROPERTY(QRectF regionOfInterest READ regionOfInterest WRITE setRegionOfInterest NOTIFY regionOfInterestChanged)
Q_PROPERTY(qreal sourceAspectRatio READ sourceAspectRatio NOTIFY sourceAspectRatioChanged)
Expand All @@ -59,13 +60,16 @@ class QQuickItemRenderer : public QQuickItem, public VideoRenderer
FillMode fillMode() const;
void setFillMode(FillMode mode);

QRectF contentRect() const;

bool isOpenGL() const;
void setOpenGL(bool o);

Q_SIGNALS:
void sourceChanged();
void fillModeChanged(QQuickItemRenderer::FillMode);
void orientationChanged();
void contentRectChanged();
void regionOfInterestChanged();
void openGLChanged();
void sourceAspectRatioChanged(qreal value) Q_DECL_OVERRIDE;
Expand All @@ -88,6 +92,8 @@ private slots:
private:
bool onSetRegionOfInterest(const QRectF& roi) Q_DECL_OVERRIDE;
bool onSetOrientation(int value) Q_DECL_OVERRIDE;
void onSetOutAspectRatio(qreal ratio) Q_DECL_OVERRIDE;
void onResizeRenderer(int, int) Q_DECL_OVERRIDE;
void onFrameSizeChanged(const QSize& size) Q_DECL_OVERRIDE;
};
typedef QQuickItemRenderer VideoRendererQQuickItem;
Expand Down
31 changes: 18 additions & 13 deletions qml/QmlAV/QuickFBORenderer.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2015 Wang Bin <[email protected]>
Copyright (C) 2015-2016 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -36,6 +36,7 @@ class QuickFBORenderer : public QQuickFramebufferObject, public VideoRenderer
Q_PROPERTY(QObject* source READ source WRITE setSource NOTIFY sourceChanged)
Q_PROPERTY(FillMode fillMode READ fillMode WRITE setFillMode NOTIFY fillModeChanged)
Q_PROPERTY(int orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
Q_PROPERTY(QRectF contentRect READ contentRect NOTIFY contentRectChanged)
// regionOfInterest > sourceRect
Q_PROPERTY(QRectF regionOfInterest READ regionOfInterest WRITE setRegionOfInterest NOTIFY regionOfInterestChanged)
Q_PROPERTY(qreal sourceAspectRatio READ sourceAspectRatio NOTIFY sourceAspectRatioChanged)
Expand All @@ -51,15 +52,17 @@ class QuickFBORenderer : public QQuickFramebufferObject, public VideoRenderer
Renderer *createRenderer() const Q_DECL_OVERRIDE;

explicit QuickFBORenderer(QQuickItem *parent = 0);
virtual VideoRendererId id() const Q_DECL_OVERRIDE;
virtual bool isSupported(VideoFormat::PixelFormat pixfmt) const Q_DECL_OVERRIDE;
VideoRendererId id() const Q_DECL_OVERRIDE;
bool isSupported(VideoFormat::PixelFormat pixfmt) const Q_DECL_OVERRIDE;

QObject *source() const;
void setSource(QObject *source);

FillMode fillMode() const;
void setFillMode(FillMode mode);

QRectF contentRect() const;

bool isOpenGL() const;
void setOpenGL(bool o);
void fboSizeChanged(const QSize& size);
Expand All @@ -68,22 +71,24 @@ class QuickFBORenderer : public QQuickFramebufferObject, public VideoRenderer
void sourceChanged();
void fillModeChanged(QuickFBORenderer::FillMode);
void orientationChanged();
void contentRectChanged();
void regionOfInterestChanged();
void openGLChanged();
void sourceAspectRatioChanged(qreal value) Q_DECL_OVERRIDE;
void frameSizeChanged();
protected:
virtual bool event(QEvent *e) Q_DECL_OVERRIDE;
virtual bool receiveFrame(const VideoFrame &frame) Q_DECL_OVERRIDE;
virtual bool needUpdateBackground() const Q_DECL_OVERRIDE;
virtual void drawBackground() Q_DECL_OVERRIDE;
virtual bool needDrawFrame() const Q_DECL_OVERRIDE;
virtual void drawFrame() Q_DECL_OVERRIDE;
bool event(QEvent *e) Q_DECL_OVERRIDE;
bool receiveFrame(const VideoFrame &frame) Q_DECL_OVERRIDE;
bool needUpdateBackground() const Q_DECL_OVERRIDE;
void drawBackground() Q_DECL_OVERRIDE;
bool needDrawFrame() const Q_DECL_OVERRIDE;
void drawFrame() Q_DECL_OVERRIDE;
private:
virtual bool onSetRegionOfInterest(const QRectF& roi) Q_DECL_OVERRIDE;
virtual bool onSetOrientation(int value) Q_DECL_OVERRIDE;
virtual void onSetOutAspectRatio(qreal ratio) Q_DECL_OVERRIDE;
virtual void onSetOutAspectRatioMode(OutAspectRatioMode mode) Q_DECL_OVERRIDE;
bool onSetRegionOfInterest(const QRectF& roi) Q_DECL_OVERRIDE;
bool onSetOrientation(int value) Q_DECL_OVERRIDE;
void onSetOutAspectRatio(qreal ratio) Q_DECL_OVERRIDE;
void onSetOutAspectRatioMode(OutAspectRatioMode mode) Q_DECL_OVERRIDE;
void onResizeRenderer(int, int) Q_DECL_OVERRIDE;
void onFrameSizeChanged(const QSize& size) Q_DECL_OVERRIDE;
void updateRenderRect();
};
Expand Down
24 changes: 19 additions & 5 deletions qml/QuickFBORenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/******************************************************************************
QtAV: Media play library based on Qt and FFmpeg
Copyright (C) 2015 Wang Bin <[email protected]>
Copyright (C) 2015-2016 Wang Bin <[email protected]>
* This file is part of QtAV
Expand Down Expand Up @@ -166,7 +166,12 @@ void QuickFBORenderer::setFillMode(FillMode mode)
return;
d_func().fill_mode = mode;
updateRenderRect();
emit fillModeChanged(mode);
Q_EMIT fillModeChanged(mode);
}

QRectF QuickFBORenderer::contentRect() const
{
return videoRect();
}

bool QuickFBORenderer::isOpenGL() const
Expand All @@ -180,7 +185,7 @@ void QuickFBORenderer::setOpenGL(bool o)
if (d.opengl == o)
return;
d.opengl = o;
emit openGLChanged();
Q_EMIT openGLChanged();
if (o)
setPreferredPixelFormat(VideoFormat::Format_YUV420P);
else
Expand Down Expand Up @@ -243,14 +248,15 @@ bool QuickFBORenderer::event(QEvent *e)
bool QuickFBORenderer::onSetRegionOfInterest(const QRectF &roi)
{
Q_UNUSED(roi);
emit regionOfInterestChanged();
Q_EMIT regionOfInterestChanged();
return true;
}

bool QuickFBORenderer::onSetOrientation(int value)
{
Q_UNUSED(value);
emit orientationChanged();
Q_EMIT orientationChanged();
// will call onSetOutAspectRatio after out_rect updated. so emit contentChanged there
return true;
}

Expand All @@ -259,19 +265,27 @@ void QuickFBORenderer::onSetOutAspectRatio(qreal ratio)
Q_UNUSED(ratio);
DPTR_D(QuickFBORenderer);
d.setupAspectRatio();
Q_EMIT contentRectChanged();
}

void QuickFBORenderer::onSetOutAspectRatioMode(OutAspectRatioMode mode)
{
Q_UNUSED(mode);
DPTR_D(QuickFBORenderer);
d.setupAspectRatio();
// already called onSetOutAspectRatio, so no contentChanged here
}

void QuickFBORenderer::onResizeRenderer(int, int)
{
Q_EMIT contentRectChanged();
}

void QuickFBORenderer::onFrameSizeChanged(const QSize &size)
{
Q_UNUSED(size);
Q_EMIT frameSizeChanged();
// will call onSetOutAspectRatio after out_rect updated. so emit contentChanged there
}

void QuickFBORenderer::updateRenderRect()
Expand Down
2 changes: 2 additions & 0 deletions qml/plugins.qmltypes
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ Module {
Property { name: "source"; type: "QObject"; isPointer: true }
Property { name: "fillMode"; type: "FillMode" }
Property { name: "orientation"; type: "int" }
Property { name: "contentRect"; type: "QRectF"; isReadonly: true }
Property { name: "regionOfInterest"; type: "QRectF" }
Property { name: "sourceAspectRatio"; type: "double"; isReadonly: true }
Property { name: "frameSize"; type: "QSize"; isReadonly: true }
Expand Down Expand Up @@ -296,6 +297,7 @@ Module {
Property { name: "source"; type: "QObject"; isPointer: true }
Property { name: "fillMode"; type: "FillMode" }
Property { name: "orientation"; type: "int" }
Property { name: "contentRect"; type: "QRectF"; isReadonly: true }
Property { name: "regionOfInterest"; type: "QRectF" }
Property { name: "sourceAspectRatio"; type: "double"; isReadonly: true }
Property { name: "frameSize"; type: "QSize"; isReadonly: true }
Expand Down

0 comments on commit aeb54de

Please sign in to comment.