summaryrefslogtreecommitdiffstats
path: root/src/multimediawidgets
diff options
context:
space:
mode:
Diffstat (limited to 'src/multimediawidgets')
-rw-r--r--src/multimediawidgets/qgraphicsvideoitem.cpp20
-rw-r--r--src/multimediawidgets/qgraphicsvideoitem.h2
-rw-r--r--src/multimediawidgets/qpaintervideosurface.cpp109
-rw-r--r--src/multimediawidgets/qpaintervideosurface_p.h13
-rw-r--r--src/multimediawidgets/qvideowidget.cpp65
-rw-r--r--src/multimediawidgets/qvideowidget.h3
-rw-r--r--src/multimediawidgets/qvideowidget_p.h49
7 files changed, 127 insertions, 134 deletions
diff --git a/src/multimediawidgets/qgraphicsvideoitem.cpp b/src/multimediawidgets/qgraphicsvideoitem.cpp
index 2db8987fb..7c0521471 100644
--- a/src/multimediawidgets/qgraphicsvideoitem.cpp
+++ b/src/multimediawidgets/qgraphicsvideoitem.cpp
@@ -49,7 +49,7 @@
#include <QtCore/qpointer.h>
#if QT_CONFIG(opengl)
-#include <QtOpenGL/qgl.h>
+#include <QOpenGLContext>
#endif
QT_BEGIN_NAMESPACE
@@ -232,6 +232,22 @@ QMediaObject *QGraphicsVideoItem::mediaObject() const
}
/*!
+ \since 5.15
+ \property QGraphicsVideoItem::videoSurface
+ \brief Returns the underlying video surface that can render video frames
+ to the current item.
+ This property is never \c nullptr.
+ Example of how to render video frames to QGraphicsVideoItem:
+ \snippet multimedia-snippets/video.cpp GraphicsVideoItem Surface
+ \sa QMediaPlayer::setVideoOutput
+*/
+
+QAbstractVideoSurface *QGraphicsVideoItem::videoSurface() const
+{
+ return d_func()->surface;
+}
+
+/*!
\internal
*/
bool QGraphicsVideoItem::setMediaObject(QMediaObject *object)
@@ -379,7 +395,7 @@ void QGraphicsVideoItem::paint(
if (painter->paintEngine()->type() == QPaintEngine::OpenGL
|| painter->paintEngine()->type() == QPaintEngine::OpenGL2)
{
- d->surface->setGLContext(const_cast<QGLContext *>(QGLContext::currentContext()));
+ d->surface->updateGLContext();
if (d->surface->supportedShaderTypes() & QPainterVideoSurface::GlslShader) {
d->surface->setShaderType(QPainterVideoSurface::GlslShader);
} else {
diff --git a/src/multimediawidgets/qgraphicsvideoitem.h b/src/multimediawidgets/qgraphicsvideoitem.h
index 5aa3bd75c..5c71ee651 100644
--- a/src/multimediawidgets/qgraphicsvideoitem.h
+++ b/src/multimediawidgets/qgraphicsvideoitem.h
@@ -60,11 +60,13 @@ class Q_MULTIMEDIAWIDGETS_EXPORT QGraphicsVideoItem : public QGraphicsObject, pu
Q_PROPERTY(QPointF offset READ offset WRITE setOffset)
Q_PROPERTY(QSizeF size READ size WRITE setSize)
Q_PROPERTY(QSizeF nativeSize READ nativeSize NOTIFY nativeSizeChanged)
+ Q_PROPERTY(QAbstractVideoSurface* videoSurface READ videoSurface CONSTANT)
public:
explicit QGraphicsVideoItem(QGraphicsItem *parent = nullptr);
~QGraphicsVideoItem();
QMediaObject *mediaObject() const override;
+ QAbstractVideoSurface *videoSurface() const;
Qt::AspectRatioMode aspectRatioMode() const;
void setAspectRatioMode(Qt::AspectRatioMode mode);
diff --git a/src/multimediawidgets/qpaintervideosurface.cpp b/src/multimediawidgets/qpaintervideosurface.cpp
index 944ea23a7..5fe76d869 100644
--- a/src/multimediawidgets/qpaintervideosurface.cpp
+++ b/src/multimediawidgets/qpaintervideosurface.cpp
@@ -47,9 +47,9 @@
#include <private/qmediaopenglhelper_p.h>
#if QT_CONFIG(opengl)
-#include <qglshaderprogram.h>
-#include <QtGui/QOpenGLContext>
-#include <QtGui/QOpenGLFunctions>
+#include <QOpenGLContext>
+#include <QOpenGLFunctions>
+#include <QOpenGLShaderProgram>
#include <QtGui/QWindow>
#ifndef GL_CLAMP_TO_EDGE
#define GL_CLAMP_TO_EDGE 0x812F
@@ -57,15 +57,6 @@
#ifndef GL_RGB8
#define GL_RGB8 0x8051
#endif
-
-static void makeCurrent(QGLContext *context)
-{
- context->makeCurrent();
-
- auto handle = context->contextHandle();
- if (handle && QOpenGLContext::currentContext() != handle)
- handle->makeCurrent(handle->surface());
-}
#endif
#include <QtDebug>
@@ -264,7 +255,7 @@ void QVideoSurfaceGenericPainter::updateColors(int, int, int, int)
class QVideoSurfaceGLPainter : public QVideoSurfacePainter, protected QOpenGLFunctions
{
public:
- QVideoSurfaceGLPainter(QGLContext *context);
+ QVideoSurfaceGLPainter(QOpenGLContext *context);
~QVideoSurfaceGLPainter();
QList<QVideoFrame::PixelFormat> supportedPixelFormats(
QAbstractVideoBuffer::HandleType handleType) const override;
@@ -292,17 +283,12 @@ protected:
|| format.pixelFormat() == QVideoFrame::Format_ARGB32);
}
-#if !defined(QT_OPENGL_ES) && !defined(QT_OPENGL_DYNAMIC)
- typedef void (APIENTRY *_glActiveTexture) (GLenum);
- _glActiveTexture glActiveTexture;
-#endif
-
QList<QVideoFrame::PixelFormat> m_imagePixelFormats;
QList<QVideoFrame::PixelFormat> m_glPixelFormats;
QMatrix4x4 m_colorMatrix;
QVideoFrame m_frame;
- QGLContext *m_context;
+ QOpenGLContext *m_context;
QAbstractVideoBuffer::HandleType m_handleType;
QVideoSurfaceFormat::Direction m_scanLineDirection;
bool m_mirrored;
@@ -320,7 +306,7 @@ protected:
bool m_yuv;
};
-QVideoSurfaceGLPainter::QVideoSurfaceGLPainter(QGLContext *context)
+QVideoSurfaceGLPainter::QVideoSurfaceGLPainter(QOpenGLContext *context)
: m_context(context)
, m_handleType(QAbstractVideoBuffer::NoHandle)
, m_scanLineDirection(QVideoSurfaceFormat::TopToBottom)
@@ -332,10 +318,6 @@ QVideoSurfaceGLPainter::QVideoSurfaceGLPainter(QGLContext *context)
, m_textureCount(0)
, m_yuv(false)
{
-#if !defined(QT_OPENGL_ES) && !defined(QT_OPENGL_DYNAMIC)
- glActiveTexture = (_glActiveTexture)m_context->getProcAddress(QLatin1String("glActiveTexture"));
-#endif
-
memset(m_textureIds, 0, sizeof(m_textureIds));
memset(m_textureWidths, 0, sizeof(m_textureWidths));
memset(m_textureHeights, 0, sizeof(m_textureHeights));
@@ -404,8 +386,6 @@ QAbstractVideoSurface::Error QVideoSurfaceGLPainter::setCurrentFrame(const QVide
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
} else if (m_frame.map(QAbstractVideoBuffer::ReadOnly)) {
- makeCurrent(m_context);
-
for (int i = 0; i < m_textureCount; ++i) {
glBindTexture(GL_TEXTURE_2D, m_textureIds[i]);
glTexImage2D(
@@ -680,7 +660,7 @@ static const char *qt_arbfp_ayuvShaderProgram =
class QVideoSurfaceArbFpPainter : public QVideoSurfaceGLPainter
{
public:
- QVideoSurfaceArbFpPainter(QGLContext *context);
+ QVideoSurfaceArbFpPainter(QOpenGLContext *context);
QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format) override;
void stop() override;
@@ -707,20 +687,20 @@ private:
QSize m_frameSize;
};
-QVideoSurfaceArbFpPainter::QVideoSurfaceArbFpPainter(QGLContext *context)
+QVideoSurfaceArbFpPainter::QVideoSurfaceArbFpPainter(QOpenGLContext *context)
: QVideoSurfaceGLPainter(context)
, m_programId(0)
{
glProgramStringARB = (_glProgramStringARB) m_context->getProcAddress(
- QLatin1String("glProgramStringARB"));
+ QByteArray("glProgramStringARB"));
glBindProgramARB = (_glBindProgramARB) m_context->getProcAddress(
- QLatin1String("glBindProgramARB"));
+ QByteArray("glBindProgramARB"));
glDeleteProgramsARB = (_glDeleteProgramsARB) m_context->getProcAddress(
- QLatin1String("glDeleteProgramsARB"));
+ QByteArray("glDeleteProgramsARB"));
glGenProgramsARB = (_glGenProgramsARB) m_context->getProcAddress(
- QLatin1String("glGenProgramsARB"));
+ QByteArray("glGenProgramsARB"));
glProgramLocalParameter4fARB = (_glProgramLocalParameter4fARB) m_context->getProcAddress(
- QLatin1String("glProgramLocalParameter4fARB"));
+ QByteArray("glProgramLocalParameter4fARB"));
m_imagePixelFormats
<< QVideoFrame::Format_RGB32
@@ -746,8 +726,6 @@ QAbstractVideoSurface::Error QVideoSurfaceArbFpPainter::start(const QVideoSurfac
QAbstractVideoSurface::Error error = QAbstractVideoSurface::NoError;
- makeCurrent(m_context);
-
const char *program = 0;
if (format.handleType() == QAbstractVideoBuffer::NoHandle) {
@@ -871,8 +849,6 @@ QAbstractVideoSurface::Error QVideoSurfaceArbFpPainter::start(const QVideoSurfac
void QVideoSurfaceArbFpPainter::stop()
{
if (m_context) {
- makeCurrent(m_context);
-
if (m_handleType != QAbstractVideoBuffer::GLTextureHandle)
glDeleteTextures(m_textureCount, m_textureIds);
glDeleteProgramsARB(1, &m_programId);
@@ -1079,7 +1055,7 @@ static const char *qt_glsl_ayuvShaderProgram =
class QVideoSurfaceGlslPainter : public QVideoSurfaceGLPainter
{
public:
- QVideoSurfaceGlslPainter(QGLContext *context);
+ QVideoSurfaceGlslPainter(QOpenGLContext *context);
QAbstractVideoSurface::Error start(const QVideoSurfaceFormat &format) override;
void stop() override;
@@ -1088,11 +1064,11 @@ public:
const QRectF &target, QPainter *painter, const QRectF &source) override;
private:
- QGLShaderProgram m_program;
+ QOpenGLShaderProgram m_program;
QSize m_frameSize;
};
-QVideoSurfaceGlslPainter::QVideoSurfaceGlslPainter(QGLContext *context)
+QVideoSurfaceGlslPainter::QVideoSurfaceGlslPainter(QOpenGLContext *context)
: QVideoSurfaceGLPainter(context)
, m_program(context)
{
@@ -1100,7 +1076,7 @@ QVideoSurfaceGlslPainter::QVideoSurfaceGlslPainter(QGLContext *context)
<< QVideoFrame::Format_RGB32
<< QVideoFrame::Format_BGR32
<< QVideoFrame::Format_ARGB32;
- if (!context->contextHandle()->isOpenGLES()) {
+ if (!context->isOpenGLES()) {
m_imagePixelFormats
<< QVideoFrame::Format_RGB24
<< QVideoFrame::Format_BGR24;
@@ -1124,8 +1100,6 @@ QAbstractVideoSurface::Error QVideoSurfaceGlslPainter::start(const QVideoSurface
QAbstractVideoSurface::Error error = QAbstractVideoSurface::NoError;
- makeCurrent(m_context);
-
const char *fragmentProgram = 0;
if (format.handleType() == QAbstractVideoBuffer::NoHandle) {
@@ -1143,13 +1117,13 @@ QAbstractVideoSurface::Error QVideoSurfaceGlslPainter::start(const QVideoSurface
fragmentProgram = qt_glsl_argbShaderProgram;
break;
case QVideoFrame::Format_RGB24:
- if (!m_context->contextHandle()->isOpenGLES()) {
+ if (!m_context->isOpenGLES()) {
initRgbTextureInfo(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, format.frameSize());
fragmentProgram = qt_glsl_rgbShaderProgram;
}
break;
case QVideoFrame::Format_BGR24:
- if (!m_context->contextHandle()->isOpenGLES()) {
+ if (!m_context->isOpenGLES()) {
initRgbTextureInfo(GL_RGB8, GL_RGB, GL_UNSIGNED_BYTE, format.frameSize());
fragmentProgram = qt_glsl_argbShaderProgram;
}
@@ -1202,11 +1176,11 @@ QAbstractVideoSurface::Error QVideoSurfaceGlslPainter::start(const QVideoSurface
if (!fragmentProgram) {
error = QAbstractVideoSurface::UnsupportedFormatError;
- } else if (!m_program.addShaderFromSourceCode(QGLShader::Vertex, qt_glsl_vertexShaderProgram)) {
+ } else if (!m_program.addShaderFromSourceCode(QOpenGLShader::Vertex, qt_glsl_vertexShaderProgram)) {
qWarning("QPainterVideoSurface: Vertex shader compile error %s",
qPrintable(m_program.log()));
error = QAbstractVideoSurface::ResourceError;
- } else if (!m_program.addShaderFromSourceCode(QGLShader::Fragment, fragmentProgram)) {
+ } else if (!m_program.addShaderFromSourceCode(QOpenGLShader::Fragment, fragmentProgram)) {
qWarning("QPainterVideoSurface: Shader compile error %s", qPrintable(m_program.log()));
error = QAbstractVideoSurface::ResourceError;
m_program.removeAllShaders();
@@ -1231,8 +1205,6 @@ QAbstractVideoSurface::Error QVideoSurfaceGlslPainter::start(const QVideoSurface
void QVideoSurfaceGlslPainter::stop()
{
if (m_context) {
- makeCurrent(m_context);
-
if (m_handleType != QAbstractVideoBuffer::GLTextureHandle)
glDeleteTextures(m_textureCount, m_textureIds);
}
@@ -1473,29 +1445,28 @@ void QPainterVideoSurface::stop()
bool QPainterVideoSurface::present(const QVideoFrame &frame)
{
if (!m_ready) {
- if (!isActive())
+ if (!isActive()) {
setError(StoppedError);
+ return false;
+ }
} else if (frame.isValid()
&& (frame.pixelFormat() != m_pixelFormat || frame.size() != m_frameSize)) {
setError(IncorrectFormatError);
stop();
+ return false;
} else {
QAbstractVideoSurface::Error error = m_painter->setCurrentFrame(frame);
-
if (error != QAbstractVideoSurface::NoError) {
setError(error);
-
stop();
- } else {
- m_ready = false;
-
- emit frameChanged();
-
- return true;
+ return false;
}
+
+ m_ready = false;
+ emit frameChanged();
}
- return false;
+ return true;
}
/*!
@@ -1612,35 +1583,33 @@ void QPainterVideoSurface::paint(QPainter *painter, const QRectF &target, const
/*!
*/
-const QGLContext *QPainterVideoSurface::glContext() const
+const QOpenGLContext *QPainterVideoSurface::glContext() const
{
return m_glContext;
}
/*!
*/
-void QPainterVideoSurface::setGLContext(QGLContext *context)
+void QPainterVideoSurface::updateGLContext()
{
- if (m_glContext == context)
+ auto oldContext = m_glContext;
+ m_glContext = QOpenGLContext::currentContext();
+ if (oldContext == m_glContext)
return;
- m_glContext = context;
-
m_shaderTypes = NoShaders;
if (m_glContext) {
//Set a dynamic property to access the OpenGL context
- this->setProperty("GLContext", QVariant::fromValue<QObject*>(m_glContext->contextHandle()));
-
- makeCurrent(m_glContext);
+ this->setProperty("GLContext", QVariant::fromValue<QObject *>(m_glContext));
const QByteArray extensions(reinterpret_cast<const char *>(
- context->contextHandle()->functions()->glGetString(GL_EXTENSIONS)));
+ m_glContext->functions()->glGetString(GL_EXTENSIONS)));
#if !defined(QT_OPENGL_ES) && !defined(QT_OPENGL_DYNAMIC)
if (extensions.contains("ARB_fragment_program"))
m_shaderTypes |= FragmentProgramShader;
#endif
- if (QGLShaderProgram::hasOpenGLShaderPrograms(m_glContext)
+ if (QOpenGLShaderProgram::hasOpenGLShaderPrograms(m_glContext)
#if !defined(QT_OPENGL_ES_2) && !defined(QT_OPENGL_DYNAMIC)
&& extensions.contains("ARB_shader_objects")
#endif
@@ -1743,13 +1712,11 @@ void QPainterVideoSurface::createPainter()
#if !defined(QT_OPENGL_ES) && !defined(QT_OPENGL_DYNAMIC)
case FragmentProgramShader:
Q_ASSERT(m_glContext);
- makeCurrent(m_glContext);
m_painter = new QVideoSurfaceArbFpPainter(m_glContext);
break;
#endif // !QT_OPENGL_ES && !QT_OPENGL_DYNAMIC
case GlslShader:
Q_ASSERT(m_glContext);
- makeCurrent(m_glContext);
m_painter = new QVideoSurfaceGlslPainter(m_glContext);
break;
default:
diff --git a/src/multimediawidgets/qpaintervideosurface_p.h b/src/multimediawidgets/qpaintervideosurface_p.h
index 990d20cbe..582d6944c 100644
--- a/src/multimediawidgets/qpaintervideosurface_p.h
+++ b/src/multimediawidgets/qpaintervideosurface_p.h
@@ -59,11 +59,6 @@
#include <qabstractvideosurface.h>
#include <qvideoframe.h>
-QT_BEGIN_NAMESPACE
-
-class QGLContext;
-QT_END_NAMESPACE
-
QT_USE_NAMESPACE
QT_BEGIN_NAMESPACE
@@ -90,7 +85,7 @@ public:
virtual void viewportDestroyed() {}
};
-
+class QOpenGLContext;
class Q_AUTOTEST_EXPORT QPainterVideoSurface : public QAbstractVideoSurface
{
Q_OBJECT
@@ -126,8 +121,8 @@ public:
void paint(QPainter *painter, const QRectF &target, const QRectF &source = QRectF(0, 0, 1, 1));
#if QT_CONFIG(opengl)
- const QGLContext *glContext() const;
- void setGLContext(QGLContext *context);
+ const QOpenGLContext *glContext() const;
+ void updateGLContext();
enum ShaderType
{
@@ -155,7 +150,7 @@ private:
QVideoSurfacePainter *m_painter;
#if QT_CONFIG(opengl)
- QGLContext *m_glContext;
+ QOpenGLContext *m_glContext;
ShaderTypes m_shaderTypes;
ShaderType m_shaderType;
#endif
diff --git a/src/multimediawidgets/qvideowidget.cpp b/src/multimediawidgets/qvideowidget.cpp
index a7d3665f8..5158b2f35 100644
--- a/src/multimediawidgets/qvideowidget.cpp
+++ b/src/multimediawidgets/qvideowidget.cpp
@@ -145,7 +145,8 @@ QRendererVideoWidgetBackend::QRendererVideoWidgetBackend(
connect(m_surface, SIGNAL(surfaceFormatChanged(QVideoSurfaceFormat)),
this, SLOT(formatChanged(QVideoSurfaceFormat)));
- m_rendererControl->setSurface(m_surface);
+ if (m_rendererControl)
+ m_rendererControl->setSurface(m_surface);
}
QRendererVideoWidgetBackend::~QRendererVideoWidgetBackend()
@@ -153,14 +154,21 @@ QRendererVideoWidgetBackend::~QRendererVideoWidgetBackend()
delete m_surface;
}
+QAbstractVideoSurface *QRendererVideoWidgetBackend::videoSurface() const
+{
+ return m_surface;
+}
+
void QRendererVideoWidgetBackend::releaseControl()
{
- m_service->releaseControl(m_rendererControl);
+ if (m_service && m_rendererControl)
+ m_service->releaseControl(m_rendererControl);
}
void QRendererVideoWidgetBackend::clearSurface()
{
- m_rendererControl->setSurface(0);
+ if (m_rendererControl)
+ m_rendererControl->setSurface(0);
}
void QRendererVideoWidgetBackend::setBrightness(int brightness)
@@ -220,7 +228,6 @@ void QRendererVideoWidgetBackend::hideEvent(QHideEvent *)
{
#if QT_CONFIG(opengl)
m_updatePaintDevice = true;
- m_surface->setGLContext(0);
#endif
}
@@ -257,7 +264,7 @@ void QRendererVideoWidgetBackend::paintEvent(QPaintEvent *event)
|| painter.paintEngine()->type() == QPaintEngine::OpenGL2)) {
m_updatePaintDevice = false;
- m_surface->setGLContext(const_cast<QGLContext *>(QGLContext::currentContext()));
+ m_surface->updateGLContext();
if (m_surface->supportedShaderTypes() & QPainterVideoSurface::GlslShader) {
m_surface->setShaderType(QPainterVideoSurface::GlslShader);
} else {
@@ -469,7 +476,7 @@ void QVideoWidgetPrivate::clearService()
delete rendererBackend;
rendererBackend = 0;
- } else {
+ } else if (windowBackend) {
windowBackend->releaseControl();
delete windowBackend;
@@ -515,18 +522,15 @@ bool QVideoWidgetPrivate::createWindowBackend()
bool QVideoWidgetPrivate::createRendererBackend()
{
- if (QMediaControl *control = service->requestControl(QVideoRendererControl_iid)) {
- if (QVideoRendererControl *rendererControl = qobject_cast<QVideoRendererControl *>(control)) {
- rendererBackend = new QRendererVideoWidgetBackend(service, rendererControl, q_func());
- currentBackend = rendererBackend;
-
- setCurrentControl(rendererBackend);
+ QMediaControl *control = service
+ ? service->requestControl(QVideoRendererControl_iid)
+ : nullptr;
+ rendererBackend = new QRendererVideoWidgetBackend(service,
+ qobject_cast<QVideoRendererControl *>(control), q_func());
+ currentBackend = rendererBackend;
+ setCurrentControl(rendererBackend);
- return true;
- }
- service->releaseControl(control);
- }
- return false;
+ return !service || (service && control);
}
void QVideoWidgetPrivate::_q_serviceDestroyed()
@@ -611,7 +615,7 @@ void QVideoWidgetPrivate::_q_dimensionsChanged()
The \a parent is passed to QWidget.
*/
QVideoWidget::QVideoWidget(QWidget *parent)
- : QWidget(parent, 0)
+ : QWidget(parent, {})
, d_ptr(new QVideoWidgetPrivate)
{
d_ptr->q_ptr = this;
@@ -621,7 +625,7 @@ QVideoWidget::QVideoWidget(QWidget *parent)
\internal
*/
QVideoWidget::QVideoWidget(QVideoWidgetPrivate &dd, QWidget *parent)
- : QWidget(parent, 0)
+ : QWidget(parent, {})
, d_ptr(&dd)
{
d_ptr->q_ptr = this;
@@ -696,6 +700,29 @@ bool QVideoWidget::setMediaObject(QMediaObject *object)
}
/*!
+ \since 5.15
+ \property QVideoWidget::videoSurface
+ \brief Returns the underlaying video surface that can render video frames
+ to the current widget.
+ This property is never \c nullptr.
+ Example of how to render video frames to QVideoWidget:
+ \snippet multimedia-snippets/video.cpp Widget Surface
+ \sa QMediaPlayer::setVideoOutput
+*/
+
+QAbstractVideoSurface *QVideoWidget::videoSurface() const
+{
+ auto d = const_cast<QVideoWidgetPrivate *>(d_func());
+
+ if (!d->rendererBackend) {
+ d->clearService();
+ d->createRendererBackend();
+ }
+
+ return d->rendererBackend->videoSurface();
+}
+
+/*!
\property QVideoWidget::aspectRatioMode
\brief how video is scaled with respect to its aspect ratio.
*/
diff --git a/src/multimediawidgets/qvideowidget.h b/src/multimediawidgets/qvideowidget.h
index fff1153ca..fdf93330b 100644
--- a/src/multimediawidgets/qvideowidget.h
+++ b/src/multimediawidgets/qvideowidget.h
@@ -51,6 +51,7 @@ QT_BEGIN_NAMESPACE
class QMediaObject;
class QVideoWidgetPrivate;
+class QAbstractVideoSurface;
class Q_MULTIMEDIAWIDGETS_EXPORT QVideoWidget : public QWidget, public QMediaBindableInterface
{
Q_OBJECT
@@ -62,12 +63,14 @@ class Q_MULTIMEDIAWIDGETS_EXPORT QVideoWidget : public QWidget, public QMediaBin
Q_PROPERTY(int contrast READ contrast WRITE setContrast NOTIFY contrastChanged)
Q_PROPERTY(int hue READ hue WRITE setHue NOTIFY hueChanged)
Q_PROPERTY(int saturation READ saturation WRITE setSaturation NOTIFY saturationChanged)
+ Q_PROPERTY(QAbstractVideoSurface* videoSurface READ videoSurface CONSTANT)
public:
explicit QVideoWidget(QWidget *parent = nullptr);
~QVideoWidget();
QMediaObject *mediaObject() const override;
+ QAbstractVideoSurface *videoSurface() const;
#ifdef Q_QDOC
bool isFullScreen() const;
diff --git a/src/multimediawidgets/qvideowidget_p.h b/src/multimediawidgets/qvideowidget_p.h
index ef417b222..a3e687488 100644
--- a/src/multimediawidgets/qvideowidget_p.h
+++ b/src/multimediawidgets/qvideowidget_p.h
@@ -55,7 +55,7 @@
#include "qvideowidget.h"
#ifndef QT_NO_OPENGL
-#include <QGLWidget>
+#include <QOpenGLWidget>
#endif
#include "qpaintervideosurface_p.h"
@@ -131,6 +131,8 @@ public:
QRendererVideoWidgetBackend(QMediaService *service, QVideoRendererControl *control, QWidget *widget);
~QRendererVideoWidgetBackend();
+ QAbstractVideoSurface *videoSurface() const;
+
void releaseControl();
void clearSurface();
@@ -222,40 +224,21 @@ class QVideoWidgetPrivate
{
Q_DECLARE_PUBLIC(QVideoWidget)
public:
- QVideoWidgetPrivate()
- : q_ptr(0)
- , mediaObject(0)
- , service(0)
- , widgetBackend(0)
- , windowBackend(0)
- , rendererBackend(0)
- , currentControl(0)
- , currentBackend(0)
- , brightness(0)
- , contrast(0)
- , hue(0)
- , saturation(0)
- , aspectRatioMode(Qt::KeepAspectRatio)
- , nonFullScreenFlags(0)
- , wasFullScreen(false)
- {
- }
-
- QVideoWidget *q_ptr;
+ QVideoWidget *q_ptr = nullptr;
QPointer<QMediaObject> mediaObject;
- QMediaService *service;
- QVideoWidgetControlBackend *widgetBackend;
- QWindowVideoWidgetBackend *windowBackend;
- QRendererVideoWidgetBackend *rendererBackend;
- QVideoWidgetControlInterface *currentControl;
- QVideoWidgetBackend *currentBackend;
- int brightness;
- int contrast;
- int hue;
- int saturation;
- Qt::AspectRatioMode aspectRatioMode;
+ QMediaService *service = nullptr;
+ QVideoWidgetControlBackend *widgetBackend = nullptr;
+ QWindowVideoWidgetBackend *windowBackend = nullptr;
+ QRendererVideoWidgetBackend *rendererBackend = nullptr;
+ QVideoWidgetControlInterface *currentControl = nullptr;
+ QVideoWidgetBackend *currentBackend = nullptr;
+ int brightness = 0;
+ int contrast = 0;
+ int hue = 0;
+ int saturation = 0;
+ Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio;
Qt::WindowFlags nonFullScreenFlags;
- bool wasFullScreen;
+ bool wasFullScreen = false;
bool createWidgetBackend();
bool createWindowBackend();