summaryrefslogtreecommitdiffstats
path: root/tests/manual/sharedtexture
diff options
context:
space:
mode:
authorPaul Lemire <paul.lemire@kdab.com>2019-10-28 10:02:00 +0100
committerPaul Lemire <paul.lemire@kdab.com>2019-10-31 12:04:49 +0100
commitfae98c57264e78e62c5955559c7e513969462a79 (patch)
tree6db9e5978a4dae1dcf42a71d696906c40e3ccbf4 /tests/manual/sharedtexture
parentdb9f0721c4406843766aab66d1cae170e76a237d (diff)
Fix SharedTexture manual tests
Remove VideoPlayer thread, not needed and could yield to asserts if QOpenGLContext::makeCurrent is called from another thread than the one it was created with, depending on platforms and QApplication flags being set. Change-Id: Ic5d1858e5356b16293ee6298558dd7c60f3c86dd Reviewed-by: Mike Krus <mike.krus@kdab.com>
Diffstat (limited to 'tests/manual/sharedtexture')
-rw-r--r--tests/manual/sharedtexture/main.cpp3
-rw-r--r--tests/manual/sharedtexture/videoplayer.cpp28
-rw-r--r--tests/manual/sharedtexture/videoplayer.h10
3 files changed, 11 insertions, 30 deletions
diff --git a/tests/manual/sharedtexture/main.cpp b/tests/manual/sharedtexture/main.cpp
index a85f90ee6..6f2ef42f2 100644
--- a/tests/manual/sharedtexture/main.cpp
+++ b/tests/manual/sharedtexture/main.cpp
@@ -137,8 +137,7 @@ int main(int argc, char* argv[])
// Multimedia player
TextureWidget textureWidget;
- VideoPlayerThread *videoPlayer = new VideoPlayerThread(&textureWidget);
- videoPlayer->start();
+ VideoPlayer *videoPlayer = new VideoPlayer(&textureWidget);
textureWidget.resize(800, 600);
textureWidget.show();
diff --git a/tests/manual/sharedtexture/videoplayer.cpp b/tests/manual/sharedtexture/videoplayer.cpp
index f970116b5..2e52b85e0 100644
--- a/tests/manual/sharedtexture/videoplayer.cpp
+++ b/tests/manual/sharedtexture/videoplayer.cpp
@@ -57,8 +57,6 @@ TextureWidget::TextureWidget(QWidget *parent)
: QOpenGLWidget(parent)
, m_texture(QOpenGLTexture::Target2D)
{
- // Lock mutex so that we never process a frame until we have been initialized
- m_mutex.lock();
}
// Main thread
@@ -104,14 +102,11 @@ void TextureWidget::initializeGL()
qDebug() << Q_FUNC_INFO << context()->shareContext();
m_vao.create();
- // Allow rendering/frame acquisition to go on
- m_mutex.unlock();
}
// Main thread
void TextureWidget::paintGL()
{
- QMutexLocker lock(&m_mutex);
glViewport(0, 0, width(), height());
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
@@ -131,12 +126,8 @@ void TextureWidget::paintGL()
m_shader.release();
}
-// Video Player thread
void TextureWidget::setVideoFrame(const QVideoFrame &frame)
{
- // Ensure we won't be rendering while we are processing the frame
- QMutexLocker lock(&m_mutex);
-
QVideoFrame f = frame;
// Map frame
@@ -194,16 +185,14 @@ bool GLVideoSurface::present(const QVideoFrame &frame)
return true;
}
-VideoPlayerThread::VideoPlayerThread(TextureWidget *textureWidget)
- : QThread(textureWidget)
+VideoPlayer::VideoPlayer(TextureWidget *textureWidget)
+ : QObject(textureWidget)
, m_player(new QMediaPlayer(nullptr, QMediaPlayer::VideoSurface))
, m_surface(new GLVideoSurface())
{
- m_player->moveToThread(this);
- m_player->setMedia(QUrl("https://www.sample-videos.com/video/mp4/720/big_buck_bunny_720p_1mb.mp4"));
+ m_player->setMedia(QUrl("https://www.sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4"));
// Tell player to render on GLVideoSurface
- m_surface->moveToThread(this);
m_player->setVideoOutput(m_surface.get());
// Display errors
@@ -218,16 +207,13 @@ VideoPlayerThread::VideoPlayerThread(TextureWidget *textureWidget)
m_player->play();
});
- // Start playing when thread starts
- QObject::connect(this, &QThread::started, this, [this] { m_player->play(); });
-
- // Direct connection between 2 objects living in different threads
QObject::connect(m_surface.get(), &GLVideoSurface::onNewFrame,
textureWidget, &TextureWidget::setVideoFrame, Qt::DirectConnection);
+
+ // Start playing
+ m_player->play();
}
-VideoPlayerThread::~VideoPlayerThread()
+VideoPlayer::~VideoPlayer()
{
- exit(0);
- wait();
}
diff --git a/tests/manual/sharedtexture/videoplayer.h b/tests/manual/sharedtexture/videoplayer.h
index 377ea57fe..a96cb16b1 100644
--- a/tests/manual/sharedtexture/videoplayer.h
+++ b/tests/manual/sharedtexture/videoplayer.h
@@ -48,9 +48,6 @@
**
****************************************************************************/
-#include <QThread>
-#include <QMutex>
-
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QOpenGLVertexArrayObject>
@@ -90,7 +87,6 @@ private:
QOpenGLVertexArrayObject m_vao;
QOpenGLShaderProgram m_shader;
QOpenGLTexture m_texture;
- QMutex m_mutex;
};
@@ -108,12 +104,12 @@ Q_SIGNALS:
};
-class VideoPlayerThread : public QThread
+class VideoPlayer : public QObject
{
Q_OBJECT
public:
- VideoPlayerThread(TextureWidget *textureWidget);
- ~VideoPlayerThread();
+ VideoPlayer(TextureWidget *textureWidget);
+ ~VideoPlayer();
private:
TextureWidget *m_textureWidget;