1 /******************************************************************************
2     QtAV:  Multimedia framework based on Qt and FFmpeg
3     Copyright (C) 2012-2016 Wang Bin <wbsecg1@gmail.com>
4 
5 *   This file is part of QtAV (from 2014)
6 
7     This library is free software; you can redistribute it and/or
8     modify it under the terms of the GNU Lesser General Public
9     License as published by the Free Software Foundation; either
10     version 2.1 of the License, or (at your option) any later version.
11 
12     This library is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15     Lesser General Public License for more details.
16 
17     You should have received a copy of the GNU Lesser General Public
18     License along with this library; if not, write to the Free Software
19     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
20 ******************************************************************************/
21 
22 #ifndef QTAV_VIDEOOUTPUT_H
23 #define QTAV_VIDEOOUTPUT_H
24 
25 #include <QtCore/QObject>
26 #include <QtAV/VideoRenderer.h>
27 
28 namespace QtAV {
29 
30 class VideoOutputPrivate;
31 /*!
32  * \brief The VideoOutput class
33  * A VideoRenderer wrapper with QObject features. If create VideoOutput without a given renderer id, QtAV will try to create a widget based renderer, and dynamically load QtAVWidgets module if it's not loaded.
34  */
35 class Q_AV_EXPORT VideoOutput : public QObject, public VideoRenderer
36 {
37     DPTR_DECLARE_PRIVATE(VideoOutput)
38     Q_OBJECT
39     Q_PROPERTY(qreal brightness READ brightness WRITE setBrightness NOTIFY brightnessChanged)
40     Q_PROPERTY(qreal contrast READ contrast WRITE setContrast NOTIFY contrastChanged)
41     Q_PROPERTY(qreal hue READ hue WRITE setHue NOTIFY hueChanged)
42     Q_PROPERTY(qreal saturation READ saturation WRITE setSaturation NOTIFY saturationChanged)
43     Q_PROPERTY(QColor backgroundColor READ backgroundColor WRITE setBackgroundColor NOTIFY backgroundColorChanged)
44     Q_PROPERTY(QRectF regionOfInterest READ regionOfInterest WRITE setRegionOfInterest NOTIFY regionOfInterestChanged)
45     Q_PROPERTY(qreal sourceAspectRatio READ sourceAspectRatio NOTIFY sourceAspectRatioChanged)
46     Q_PROPERTY(qreal outAspectRatio READ outAspectRatio WRITE setOutAspectRatio NOTIFY outAspectRatioChanged)
47     //fillMode
48     // TODO: how to use enums in base class as property or Q_ENUM
49     Q_PROPERTY(OutAspectRatioMode outAspectRatioMode READ outAspectRatioMode WRITE setOutAspectRatioMode NOTIFY outAspectRatioModeChanged)
50     Q_ENUMS(OutAspectRatioMode)
51     Q_PROPERTY(int orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
52     Q_PROPERTY(QRect videoRect READ videoRect NOTIFY videoRectChanged)
53     Q_PROPERTY(QSize videoFrameSize READ videoFrameSize NOTIFY videoFrameSizeChanged)
54     Q_ENUMS(Quality)
55 public:
56     /*!
57      * \brief VideoOutput
58      * Create a QWidget based renderer. Result can be a QOpenGLWidget or QGLWidget based renderer if possible. Otherwise fallback to a software renderer
59      */
60     VideoOutput(QObject *parent = 0);
61     /*!
62      * \brief VideoOutput
63      * Create a renderer with given rendererId. MUST check VideoOutput::isAvailable() later!
64      */
65     VideoOutput(VideoRendererId rendererId, QObject *parent = 0);
66     ~VideoOutput();
67     VideoRendererId id() const Q_DECL_OVERRIDE;
68 
69     VideoFormat::PixelFormat preferredPixelFormat() const Q_DECL_OVERRIDE;
70     bool isSupported(VideoFormat::PixelFormat pixfmt) const Q_DECL_OVERRIDE;
71     QWindow* qwindow() Q_DECL_OVERRIDE Q_DECL_FINAL;
72     QWidget* widget() Q_DECL_OVERRIDE Q_DECL_FINAL;
73     QGraphicsItem* graphicsItem() Q_DECL_OVERRIDE Q_DECL_FINAL;
74     OpenGLVideo* opengl() const Q_DECL_OVERRIDE;
75 Q_SIGNALS:
76     void sourceAspectRatioChanged(qreal value) Q_DECL_OVERRIDE Q_DECL_FINAL;
77     void regionOfInterestChanged() Q_DECL_OVERRIDE;
78     void outAspectRatioChanged() Q_DECL_OVERRIDE;
79     void outAspectRatioModeChanged() Q_DECL_OVERRIDE;
80     void brightnessChanged(qreal value) Q_DECL_OVERRIDE;
81     void contrastChanged(qreal) Q_DECL_OVERRIDE;
82     void hueChanged(qreal) Q_DECL_OVERRIDE;
83     void saturationChanged(qreal) Q_DECL_OVERRIDE;
84     void backgroundColorChanged() Q_DECL_OVERRIDE;
85     void orientationChanged() Q_DECL_OVERRIDE;
86     void videoRectChanged() Q_DECL_OVERRIDE;
87     void videoFrameSizeChanged() Q_DECL_OVERRIDE;
88 protected:
89     bool eventFilter(QObject *obj, QEvent *event) Q_DECL_OVERRIDE;
90     bool receiveFrame(const VideoFrame& frame) Q_DECL_OVERRIDE;
91     void drawBackground() Q_DECL_OVERRIDE;
92     void drawFrame() Q_DECL_OVERRIDE;
93     void handlePaintEvent() Q_DECL_OVERRIDE;
94 
95 private:
96     virtual bool onSetPreferredPixelFormat(VideoFormat::PixelFormat pixfmt) Q_DECL_OVERRIDE;
97     virtual bool onForcePreferredPixelFormat(bool force = true) Q_DECL_OVERRIDE;
98     virtual void onSetOutAspectRatioMode(OutAspectRatioMode mode) Q_DECL_OVERRIDE;
99     virtual void onSetOutAspectRatio(qreal ratio) Q_DECL_OVERRIDE;
100     virtual bool onSetQuality(Quality q) Q_DECL_OVERRIDE;
101     virtual bool onSetOrientation(int value) Q_DECL_OVERRIDE;
102     virtual void onResizeRenderer(int width, int height) Q_DECL_OVERRIDE;
103     virtual bool onSetRegionOfInterest(const QRectF& roi) Q_DECL_OVERRIDE;
104     virtual QPointF onMapToFrame(const QPointF& p) const Q_DECL_OVERRIDE;
105     virtual QPointF onMapFromFrame(const QPointF& p) const Q_DECL_OVERRIDE;
106 
107     virtual bool onSetBrightness(qreal brightness) Q_DECL_OVERRIDE;
108     virtual bool onSetContrast(qreal contrast) Q_DECL_OVERRIDE;
109     virtual bool onSetHue(qreal hue) Q_DECL_OVERRIDE;
110     virtual bool onSetSaturation(qreal saturation) Q_DECL_OVERRIDE;
111     virtual void onSetBackgroundColor(const QColor& color) Q_DECL_OVERRIDE;
112     // from AVOutput
113     virtual void setStatistics(Statistics* statistics) Q_DECL_OVERRIDE; //called by friend AVPlayer
114     virtual bool onInstallFilter(Filter *filter, int index) Q_DECL_OVERRIDE;
115     virtual bool onUninstallFilter(Filter *filter) Q_DECL_OVERRIDE;
116     virtual bool onHanlePendingTasks() Q_DECL_OVERRIDE;
117 };
118 
119 } //namespace QtAV
120 
121 #endif // QTAV_VIDEOOUTPUT_H
122