Skip to content

Commit

Permalink
vo: backgroundColor property. do not support x11, xv, VideoOutput
Browse files Browse the repository at this point in the history
  • Loading branch information
wang-bin committed Jan 11, 2016
1 parent a611beb commit 1a970d9
Show file tree
Hide file tree
Showing 21 changed files with 122 additions and 84 deletions.
2 changes: 2 additions & 0 deletions qml/QmlAV/QQuickItemRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class QQuickItemRenderer : public QQuickItem, public VideoRenderer
Q_PROPERTY(qreal sourceAspectRatio READ sourceAspectRatio NOTIFY sourceAspectRatioChanged)
Q_PROPERTY(QSize videoFrameSize READ videoFrameSize NOTIFY videoFrameSizeChanged)
Q_PROPERTY(QSize frameSize READ videoFrameSize NOTIFY videoFrameSizeChanged)
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
Q_ENUMS(FillMode)
public:
enum FillMode {
Expand Down Expand Up @@ -77,6 +78,7 @@ class QQuickItemRenderer : public QQuickItem, public VideoRenderer
void openGLChanged();
void sourceAspectRatioChanged(qreal value) Q_DECL_OVERRIDE;
void videoFrameSizeChanged() Q_DECL_OVERRIDE;
void backgroundColorChanged() Q_DECL_OVERRIDE;
protected:
bool event(QEvent *e) Q_DECL_OVERRIDE;
void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) Q_DECL_OVERRIDE;
Expand Down
2 changes: 2 additions & 0 deletions qml/QmlAV/QuickFBORenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class QuickFBORenderer : public QQuickFramebufferObject, public VideoRenderer
Q_PROPERTY(qreal sourceAspectRatio READ sourceAspectRatio NOTIFY sourceAspectRatioChanged)
Q_PROPERTY(QSize videoFrameSize READ videoFrameSize NOTIFY videoFrameSizeChanged)
Q_PROPERTY(QSize frameSize READ videoFrameSize NOTIFY videoFrameSizeChanged)
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
Q_ENUMS(FillMode)
public:
enum FillMode {
Expand Down Expand Up @@ -78,6 +79,7 @@ class QuickFBORenderer : public QQuickFramebufferObject, public VideoRenderer
void openGLChanged();
void sourceAspectRatioChanged(qreal value) Q_DECL_OVERRIDE;
void videoFrameSizeChanged() Q_DECL_OVERRIDE;
void backgroundColorChanged() Q_DECL_OVERRIDE;
protected:
bool event(QEvent *e) Q_DECL_OVERRIDE;
bool receiveFrame(const VideoFrame &frame) Q_DECL_OVERRIDE;
Expand Down
4 changes: 3 additions & 1 deletion qml/QuickFBORenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ void QuickFBORenderer::renderToFbo()

void QuickFBORenderer::drawBackground()
{
d_func().glv.fill(QColor(Qt::black));
if (backgroundRegion().isEmpty())
return;
d_func().glv.fill(backgroundColor());
}

void QuickFBORenderer::drawFrame()
Expand Down
1 change: 1 addition & 0 deletions qml/Video.qml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ import QtAV 1.5
Item {
id: video

property alias backgroundColor: videoOut.backgroundColor
property alias frameSize: videoOut.frameSize
property alias sourceAspectRatio: videoOut.sourceAspectRatio
property alias opengl: videoOut.opengl
Expand Down
2 changes: 2 additions & 0 deletions qml/plugins.qmltypes
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ Module {
Property { name: "regionOfInterest"; type: "QRectF" }
Property { name: "sourceAspectRatio"; type: "double"; isReadonly: true }
Property { name: "frameSize"; type: "QSize"; isReadonly: true }
Property { name: "backgroundColor"; type: "QColor" }
Signal {
name: "fillModeChanged"
Parameter { type: "QQuickItemRenderer::FillMode" }
Expand Down Expand Up @@ -303,6 +304,7 @@ Module {
Property { name: "regionOfInterest"; type: "QRectF" }
Property { name: "sourceAspectRatio"; type: "double"; isReadonly: true }
Property { name: "frameSize"; type: "QSize"; isReadonly: true }
Property { name: "backgroundColor"; type: "QColor" }
Signal {
name: "fillModeChanged"
Parameter { type: "QuickFBORenderer::FillMode" }
Expand Down
22 changes: 11 additions & 11 deletions src/QtAV/OpenGLRendererBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,26 +46,26 @@ class Q_AV_EXPORT OpenGLRendererBase : public VideoRenderer
DPTR_DECLARE_PRIVATE(OpenGLRendererBase)
public:
virtual ~OpenGLRendererBase();
virtual bool isSupported(VideoFormat::PixelFormat pixfmt) const;
bool isSupported(VideoFormat::PixelFormat pixfmt) const Q_DECL_OVERRIDE;
protected:
virtual bool receiveFrame(const VideoFrame& frame);
virtual bool receiveFrame(const VideoFrame& frame) Q_DECL_OVERRIDE;
//called in paintEvent before drawFrame() when required
virtual void drawBackground();
virtual void drawBackground() Q_DECL_OVERRIDE;
//draw the current frame using the current paint engine. called by paintEvent()
virtual void drawFrame();
virtual void drawFrame() Q_DECL_OVERRIDE;
void onInitializeGL();
void onPaintGL();
void onResizeGL(int w, int h);
void onResizeEvent(int w, int h);
void onShowEvent();
private:
virtual void onSetOutAspectRatioMode(OutAspectRatioMode mode);
virtual void onSetOutAspectRatio(qreal ratio);
virtual bool onSetOrientation(int value);
virtual bool onSetBrightness(qreal b);
virtual bool onSetContrast(qreal c);
virtual bool onSetHue(qreal h);
virtual bool onSetSaturation(qreal s);
void onSetOutAspectRatioMode(OutAspectRatioMode mode) Q_DECL_OVERRIDE;
void onSetOutAspectRatio(qreal ratio) Q_DECL_OVERRIDE;
bool onSetOrientation(int value) Q_DECL_OVERRIDE;
bool onSetBrightness(qreal b) Q_DECL_OVERRIDE;
bool onSetContrast(qreal c) Q_DECL_OVERRIDE;
bool onSetHue(qreal h) Q_DECL_OVERRIDE;
bool onSetSaturation(qreal s) Q_DECL_OVERRIDE;
protected:
OpenGLRendererBase(OpenGLRendererBasePrivate &d);
};
Expand Down
2 changes: 2 additions & 0 deletions src/QtAV/OpenGLWindowRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Q_AV_EXPORT OpenGLWindowRenderer : public QOpenGLWindow, public OpenGLRend
Q_PROPERTY(qreal contrast READ contrast WRITE setContrast NOTIFY contrastChanged)
Q_PROPERTY(qreal hue READ hue WRITE setHue NOTIFY hueChanged)
Q_PROPERTY(qreal saturation READ saturation WRITE setSaturation NOTIFY saturationChanged)
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
Q_PROPERTY(QRectF regionOfInterest READ regionOfInterest WRITE setRegionOfInterest NOTIFY regionOfInterestChanged)
Q_PROPERTY(qreal sourceAspectRatio READ sourceAspectRatio NOTIFY sourceAspectRatioChanged)
Q_PROPERTY(qreal outAspectRatio READ outAspectRatio WRITE setOutAspectRatio NOTIFY outAspectRatioChanged)
Expand All @@ -60,6 +61,7 @@ class Q_AV_EXPORT OpenGLWindowRenderer : public QOpenGLWindow, public OpenGLRend
void contrastChanged(qreal) Q_DECL_OVERRIDE;
void hueChanged(qreal) Q_DECL_OVERRIDE;
void saturationChanged(qreal) Q_DECL_OVERRIDE;
void backgroundColorChanged() Q_DECL_OVERRIDE;
void orientationChanged() Q_DECL_OVERRIDE;
void videoRectChanged() Q_DECL_OVERRIDE;
void videoFrameSizeChanged() Q_DECL_OVERRIDE;
Expand Down
2 changes: 2 additions & 0 deletions src/QtAV/VideoOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Q_AV_EXPORT VideoOutput : public QObject, public VideoRenderer
Q_PROPERTY(qreal contrast READ contrast WRITE setContrast NOTIFY contrastChanged)
Q_PROPERTY(qreal hue READ hue WRITE setHue NOTIFY hueChanged)
Q_PROPERTY(qreal saturation READ saturation WRITE setSaturation NOTIFY saturationChanged)
Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
Q_PROPERTY(QRectF regionOfInterest READ regionOfInterest WRITE setRegionOfInterest NOTIFY regionOfInterestChanged)
Q_PROPERTY(qreal sourceAspectRatio READ sourceAspectRatio NOTIFY sourceAspectRatioChanged)
Q_PROPERTY(qreal outAspectRatio READ outAspectRatio WRITE setOutAspectRatio NOTIFY outAspectRatioChanged)
Expand Down Expand Up @@ -76,6 +77,7 @@ class Q_AV_EXPORT VideoOutput : public QObject, public VideoRenderer
void contrastChanged(qreal) Q_DECL_OVERRIDE;
void hueChanged(qreal) Q_DECL_OVERRIDE;
void saturationChanged(qreal) Q_DECL_OVERRIDE;
void backgroundColorChanged() Q_DECL_OVERRIDE;
void orientationChanged() Q_DECL_OVERRIDE;
void videoRectChanged() Q_DECL_OVERRIDE;
void videoFrameSizeChanged() Q_DECL_OVERRIDE;
Expand Down
8 changes: 6 additions & 2 deletions src/QtAV/VideoRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QtCore/QByteArray>
#include <QtCore/QSize>
#include <QtCore/QRectF>
#include <QtGui/QColor>
#include <QtAV/AVOutput.h>
#include <QtAV/VideoFrame.h>

Expand Down Expand Up @@ -183,7 +184,7 @@ class Q_AV_EXPORT VideoRenderer : public AVOutput
* values range between -1.0 and 1.0, the default is 0.
* value is not changed if does not implementd and onChangingXXX() returns false.
* video widget/item will update after if onChangingXXX/setXXX returns true
* \return \a false if failed (may be onChangingXXX not implemented or return false)
* \return \a false if failed to set (may be onChangingXXX not implemented or return false)
*/
qreal brightness() const;
bool setBrightness(qreal brightness);
Expand All @@ -193,12 +194,14 @@ class Q_AV_EXPORT VideoRenderer : public AVOutput
bool setHue(qreal hue);
qreal saturation() const;
bool setSaturation(qreal saturation);
QColor backgroundColor() const;
void setBackgroundColor(const QColor& c);

protected:
VideoRenderer(VideoRendererPrivate &d);
QRegion backgroundRegion() const;
//TODO: batch drawBackground(color, region)=>loop drawBackground(color,rect)
virtual bool receiveFrame(const VideoFrame& frame) = 0;
QRegion backgroundRegion() const;
QTAV_DEPRECATED virtual bool needUpdateBackground() const;
virtual void drawBackground();
QTAV_DEPRECATED virtual bool needDrawFrame() const; //TODO: no virtual func. it's a solution for temporary
Expand All @@ -222,6 +225,7 @@ class Q_AV_EXPORT VideoRenderer : public AVOutput
virtual void contrastChanged(qreal) {}
virtual void hueChanged(qreal) {}
virtual void saturationChanged(qreal) {}
virtual void backgroundColorChanged() {}
private: // mainly used by VideoOutput class
/*!
* return false if value not changed. default is true
Expand Down
3 changes: 3 additions & 0 deletions src/QtAV/private/VideoRenderer_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <QtCore/QMutex>
#include <QtCore/QRect>
#include <QtAV/VideoFrame.h>
#include <QtGui/QColor>

/*TODO:
* Region of Interest(ROI)
Expand Down Expand Up @@ -58,6 +59,7 @@ class Q_AV_PRIVATE_EXPORT VideoRendererPrivate : public AVOutputPrivate
, contrast(0)
, hue(0)
, saturation(0)
, bg_color(0, 0, 0)
{
//conv.setInFormat(PIX_FMT_YUV420P);
//conv.setOutFormat(PIX_FMT_BGR32); //TODO: why not RGB32?
Expand Down Expand Up @@ -117,6 +119,7 @@ class Q_AV_PRIVATE_EXPORT VideoRendererPrivate : public AVOutputPrivate
bool force_preferred;

qreal brightness, contrast, hue, saturation;
QColor bg_color;
};

} //namespace QtAV
Expand Down
26 changes: 15 additions & 11 deletions src/output/video/Direct2DRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,25 @@ class Direct2DRenderer : public QWidget, public VideoRenderer
DPTR_DECLARE_PRIVATE(Direct2DRenderer)
public:
Direct2DRenderer(QWidget* parent = 0, Qt::WindowFlags f = 0);
virtual VideoRendererId id() const;
virtual bool isSupported(VideoFormat::PixelFormat pixfmt) const;
VideoRendererId id() const Q_DECL_OVERRIDE;
bool isSupported(VideoFormat::PixelFormat pixfmt) const Q_DECL_OVERRIDE;

/* WA_PaintOnScreen: To render outside of Qt's paint system, e.g. If you require
* native painting primitives, you need to reimplement QWidget::paintEngine() to
* return 0 and set this flag
*/
virtual QPaintEngine* paintEngine() const;
virtual QWidget* widget() { return this; }
QPaintEngine* paintEngine() const Q_DECL_OVERRIDE;
QWidget* widget() Q_DECL_OVERRIDE { return this; }
protected:
virtual bool receiveFrame(const VideoFrame& frame);
virtual void drawBackground();
virtual void drawFrame();
bool receiveFrame(const VideoFrame& frame) Q_DECL_OVERRIDE;
void drawBackground() Q_DECL_OVERRIDE;
void drawFrame() Q_DECL_OVERRIDE;
/*usually you don't need to reimplement paintEvent, just drawXXX() is ok. unless you want do all
*things yourself totally*/
virtual void paintEvent(QPaintEvent *);
virtual void resizeEvent(QResizeEvent *);
void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
//stay on top will change parent, hide then show(windows)
virtual void showEvent(QShowEvent *);
void showEvent(QShowEvent *) Q_DECL_OVERRIDE;
};
typedef Direct2DRenderer VideoRendererDirect2D;
extern VideoRendererId VideoRendererId_Direct2D;
Expand Down Expand Up @@ -333,8 +333,12 @@ QPaintEngine* Direct2DRenderer::paintEngine() const

void Direct2DRenderer::drawBackground()
{
const QRegion bgRegion(backgroundRegion());
if (bgRegion.isEmpty())
return;
DPTR_D(Direct2DRenderer);
D2D1_COLOR_F c = {0, 0, 0, 255};
const QColor bc(backgroundColor());
D2D1_COLOR_F c = {bc.red(), bc.green(), bc.blue(), bc.alpha()};
d.render_target->Clear(&c); //const D2D1_COlOR_F&?
//http://msdn.microsoft.com/en-us/library/windows/desktop/dd535473(v=vs.85).aspx
//ID2D1SolidColorBrush *brush;
Expand Down
32 changes: 17 additions & 15 deletions src/output/video/GDIRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,29 @@ class GDIRenderer : public QWidget, public VideoRenderer
DPTR_DECLARE_PRIVATE(GDIRenderer)
public:
GDIRenderer(QWidget* parent = 0, Qt::WindowFlags f = 0); //offscreen?
virtual VideoRendererId id() const;
virtual bool isSupported(VideoFormat::PixelFormat pixfmt) const;
VideoRendererId id() const Q_DECL_OVERRIDE;
bool isSupported(VideoFormat::PixelFormat pixfmt) const Q_DECL_OVERRIDE;
/* WA_PaintOnScreen: To render outside of Qt's paint system, e.g. If you require
* native painting primitives, you need to reimplement QWidget::paintEngine() to
* return 0 and set this flag
*/
virtual QPaintEngine* paintEngine() const;
QPaintEngine* paintEngine() const Q_DECL_OVERRIDE;

/*http://lists.trolltech.com/qt4-preview-feedback/2005-04/thread00609-0.html
* true: paintEngine.getDC(), double buffer is enabled by defalut.
* false: GetDC(winId()), no double buffer, should reimplement paintEngine()
*/
virtual QWidget* widget() { return this; }
QWidget* widget() Q_DECL_OVERRIDE { return this; }
protected:
virtual bool receiveFrame(const VideoFrame& frame);
virtual void drawBackground();
virtual void drawFrame();
bool receiveFrame(const VideoFrame& frame) Q_DECL_OVERRIDE;
void drawBackground() Q_DECL_OVERRIDE;
void drawFrame() Q_DECL_OVERRIDE;
/*usually you don't need to reimplement paintEvent, just drawXXX() is ok. unless you want do all
*things yourself totally*/
virtual void paintEvent(QPaintEvent *);
virtual void resizeEvent(QResizeEvent *);
void paintEvent(QPaintEvent *) Q_DECL_OVERRIDE;
void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
//stay on top will change parent, hide then show(windows). we need GetDC() again
virtual void showEvent(QShowEvent *);
void showEvent(QShowEvent *) Q_DECL_OVERRIDE;
};
typedef GDIRenderer VideoRendererGDI;
extern VideoRendererId VideoRendererId_GDI;
Expand Down Expand Up @@ -230,15 +230,17 @@ bool GDIRenderer::receiveFrame(const VideoFrame& frame)

void GDIRenderer::drawBackground()
{
const QRegion bgRegion(backgroundRegion());
if (bgRegion.isEmpty())
return;
const QColor bc;
DPTR_D(GDIRenderer);
//HDC hdc = d.device_context;
Graphics g(d.device_context);
SolidBrush brush(Color(255, 0, 0, 0)); //argb
SolidBrush brush(Color(bc.alpha(), bc.red(), bc.green(), bc.blue())); //argb
const QVector<QRect> bg(backgroundRegion().rects());
if (!bg.isEmpty()) {
foreach (const QRect& r, bg) {
g.FillRectangle(&brush, r.x(), r.y(), r.width(), r.height());
}
foreach (const QRect& r, bg) {
g.FillRectangle(&brush, r.x(), r.y(), r.width(), r.height());
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/output/video/OpenGLRendererBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ bool OpenGLRendererBase::receiveFrame(const VideoFrame& frame)

void OpenGLRendererBase::drawBackground()
{
d_func().glv.fill(QColor(Qt::black));
const QRegion bgRegion(backgroundRegion());
if (bgRegion.isEmpty())
return;
d_func().glv.fill(backgroundColor());
}

void OpenGLRendererBase::drawFrame()
Expand Down
15 changes: 8 additions & 7 deletions src/output/video/QPainterRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,18 @@ void QPainterRenderer::drawBackground()
DPTR_D(QPainterRenderer);
if (!d.painter)
return;
const QRegion bgRegion(backgroundRegion());
if (bgRegion.isEmpty())
return;
#if 0
d.painter->save();
d.painter->setClipRegion(backgroundRegion());
d.painter->fillRect(QRect(QPoint(), rendererSize()), QColor(0, 0, 0));
d.painter->setClipRegion(bgRegion);
d.painter->fillRect(QRect(QPoint(), rendererSize()), backgroundColor());
d.painter->restore();
#else
const QVector<QRect> bg(backgroundRegion().rects());
if (!bg.isEmpty()) {
foreach (const QRect& r, bg) {
d.painter->fillRect(r, QColor(0, 0, 0));
}
const QVector<QRect> bg(bgRegion.rects());
foreach (const QRect& r, bg) {
d.painter->fillRect(r, backgroundColor());
}
#endif
}
Expand Down
Loading

0 comments on commit 1a970d9

Please sign in to comment.