1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the 21 ** packaging of this file. Please review the following information to 22 ** ensure the GNU Lesser General Public License version 3 requirements 23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. 24 ** 25 ** GNU General Public License Usage 26 ** Alternatively, this file may be used under the terms of the GNU 27 ** General Public License version 2.0 or (at your option) the GNU General 28 ** Public license version 3 or any later version approved by the KDE Free 29 ** Qt Foundation. The licenses are as published by the Free Software 30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 31 ** included in the packaging of this file. Please review the following 32 ** information to ensure the GNU General Public License requirements will 33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and 34 ** https://www.gnu.org/licenses/gpl-3.0.html. 35 ** 36 ** $QT_END_LICENSE$ 37 ** 38 ****************************************************************************/ 39 40 #ifndef QVIDEOWIDGET_P_H 41 #define QVIDEOWIDGET_P_H 42 43 // 44 // W A R N I N G 45 // ------------- 46 // 47 // This file is not part of the Qt API. It exists purely as an 48 // implementation detail. This header file may change from version to 49 // version without notice, or even be removed. 50 // 51 // We mean it. 52 // 53 54 #include <qtmultimediawidgetdefs.h> 55 #include "qvideowidget.h" 56 57 #ifndef QT_NO_OPENGL 58 #include <QOpenGLWidget> 59 #endif 60 61 #include "qpaintervideosurface_p.h" 62 63 #include <QtCore/qpointer.h> 64 65 QT_BEGIN_NAMESPACE 66 67 68 class QMediaService; 69 70 class QVideoWidgetControlInterface 71 { 72 public: ~QVideoWidgetControlInterface()73 virtual ~QVideoWidgetControlInterface() {} 74 75 virtual void setBrightness(int brightness) = 0; 76 virtual void setContrast(int contrast) = 0; 77 virtual void setHue(int hue) = 0; 78 virtual void setSaturation(int saturation) = 0; 79 80 virtual void setFullScreen(bool fullScreen) = 0; 81 82 virtual Qt::AspectRatioMode aspectRatioMode() const = 0; 83 virtual void setAspectRatioMode(Qt::AspectRatioMode mode) = 0; 84 }; 85 86 class QVideoWidgetBackend : public QObject, public QVideoWidgetControlInterface 87 { 88 Q_OBJECT 89 public: 90 virtual QSize sizeHint() const = 0; 91 92 virtual void showEvent() = 0; 93 virtual void hideEvent(QHideEvent *event) = 0; 94 virtual void resizeEvent(QResizeEvent *event) = 0; 95 virtual void moveEvent(QMoveEvent *event) = 0; 96 virtual void paintEvent(QPaintEvent *event) = 0; 97 }; 98 99 class QVideoWidgetControl; 100 101 class QVideoWidgetControlBackend : public QObject, public QVideoWidgetControlInterface 102 { 103 Q_OBJECT 104 public: 105 QVideoWidgetControlBackend(QMediaService *service, QVideoWidgetControl *control, QWidget *widget); 106 107 void releaseControl(); 108 109 void setBrightness(int brightness) override; 110 void setContrast(int contrast) override; 111 void setHue(int hue) override; 112 void setSaturation(int saturation) override; 113 114 void setFullScreen(bool fullScreen) override; 115 116 Qt::AspectRatioMode aspectRatioMode() const override; 117 void setAspectRatioMode(Qt::AspectRatioMode mode) override; 118 119 private: 120 QMediaService *m_service; 121 QVideoWidgetControl *m_widgetControl; 122 }; 123 124 125 class QVideoRendererControl; 126 127 class QRendererVideoWidgetBackend : public QVideoWidgetBackend 128 { 129 Q_OBJECT 130 public: 131 QRendererVideoWidgetBackend(QMediaService *service, QVideoRendererControl *control, QWidget *widget); 132 ~QRendererVideoWidgetBackend(); 133 134 QAbstractVideoSurface *videoSurface() const; 135 136 void releaseControl(); 137 void clearSurface(); 138 139 void setBrightness(int brightness) override; 140 void setContrast(int contrast) override; 141 void setHue(int hue) override; 142 void setSaturation(int saturation) override; 143 144 void setFullScreen(bool fullScreen) override; 145 146 Qt::AspectRatioMode aspectRatioMode() const override; 147 void setAspectRatioMode(Qt::AspectRatioMode mode) override; 148 149 QSize sizeHint() const override; 150 151 void showEvent() override; 152 void hideEvent(QHideEvent *event) override; 153 void resizeEvent(QResizeEvent *event) override; 154 void moveEvent(QMoveEvent *event) override; 155 void paintEvent(QPaintEvent *event) override; 156 157 Q_SIGNALS: 158 void fullScreenChanged(bool fullScreen); 159 void brightnessChanged(int brightness); 160 void contrastChanged(int contrast); 161 void hueChanged(int hue); 162 void saturationChanged(int saturation); 163 164 private Q_SLOTS: 165 void formatChanged(const QVideoSurfaceFormat &format); 166 void frameChanged(); 167 168 private: 169 void updateRects(); 170 171 QMediaService *m_service; 172 QVideoRendererControl *m_rendererControl; 173 QWidget *m_widget; 174 QPainterVideoSurface *m_surface; 175 Qt::AspectRatioMode m_aspectRatioMode; 176 QRect m_boundingRect; 177 QRectF m_sourceRect; 178 QSize m_nativeSize; 179 bool m_updatePaintDevice; 180 }; 181 182 class QVideoWindowControl; 183 184 class QWindowVideoWidgetBackend : public QVideoWidgetBackend 185 { 186 Q_OBJECT 187 public: 188 QWindowVideoWidgetBackend(QMediaService *service, QVideoWindowControl *control, QWidget *widget); 189 ~QWindowVideoWidgetBackend(); 190 191 void releaseControl(); 192 193 void setBrightness(int brightness) override; 194 void setContrast(int contrast) override; 195 void setHue(int hue) override; 196 void setSaturation(int saturation) override; 197 198 void setFullScreen(bool fullScreen) override; 199 200 Qt::AspectRatioMode aspectRatioMode() const override; 201 void setAspectRatioMode(Qt::AspectRatioMode mode) override; 202 203 QSize sizeHint() const override; 204 205 void showEvent() override; 206 void hideEvent(QHideEvent *event) override; 207 void resizeEvent(QResizeEvent *event) override; 208 void moveEvent(QMoveEvent *event) override; 209 void paintEvent(QPaintEvent *event) override; 210 211 private: 212 void updateDisplayRect(); 213 214 QMediaService *m_service; 215 QVideoWindowControl *m_windowControl; 216 QWidget *m_widget; 217 QSize m_pixelAspectRatio; 218 }; 219 220 class QMediaService; 221 class QVideoOutputControl; 222 223 class QVideoWidgetPrivate 224 { 225 Q_DECLARE_PUBLIC(QVideoWidget) 226 public: 227 QVideoWidget *q_ptr = nullptr; 228 QPointer<QMediaObject> mediaObject; 229 QMediaService *service = nullptr; 230 QVideoWidgetControlBackend *widgetBackend = nullptr; 231 QWindowVideoWidgetBackend *windowBackend = nullptr; 232 QRendererVideoWidgetBackend *rendererBackend = nullptr; 233 QVideoWidgetControlInterface *currentControl = nullptr; 234 QVideoWidgetBackend *currentBackend = nullptr; 235 int brightness = 0; 236 int contrast = 0; 237 int hue = 0; 238 int saturation = 0; 239 Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio; 240 Qt::WindowFlags nonFullScreenFlags; 241 bool wasFullScreen = false; 242 243 bool createWidgetBackend(); 244 bool createWindowBackend(); 245 bool createRendererBackend(); 246 247 void setCurrentControl(QVideoWidgetControlInterface *control); 248 void clearService(); 249 250 void _q_serviceDestroyed(); 251 void _q_brightnessChanged(int brightness); 252 void _q_contrastChanged(int contrast); 253 void _q_hueChanged(int hue); 254 void _q_saturationChanged(int saturation); 255 void _q_fullScreenChanged(bool fullScreen); 256 void _q_dimensionsChanged(); 257 }; 258 259 QT_END_NAMESPACE 260 261 262 #endif 263