From 9408807bb0fd7a9a83531241a8e7b8f8d9d76dd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20R=C3=B8dal?= Date: Thu, 14 Mar 2013 10:58:44 +0100 Subject: Made OMX initializing a bit more robust. We should do it on the rendering thread where there's a current context since we're calling glGenTextures() etc. --- src/imports/nativemedia/omxnode.cpp | 36 ++++++++++++++++++++++++++++-------- src/imports/nativemedia/omxnode.h | 3 ++- 2 files changed, 30 insertions(+), 9 deletions(-) (limited to 'src/imports') diff --git a/src/imports/nativemedia/omxnode.cpp b/src/imports/nativemedia/omxnode.cpp index 79eeb16..c333622 100644 --- a/src/imports/nativemedia/omxnode.cpp +++ b/src/imports/nativemedia/omxnode.cpp @@ -2,6 +2,7 @@ #include #include +#include #include @@ -72,11 +73,6 @@ void OmxNode::preprocess() { } -void OmxNode::updateTexture() -{ - printf("OmxNode::updateTexture()\n"); -} - void OmxNode::setRect(const QRectF &rect) { if (m_rect == rect) @@ -93,9 +89,9 @@ OmxItem::OmxItem() : m_player(OmxPlayer::create()) , m_hasFrame(false) , m_initialized(false) + , m_paused(false) , m_sourceWidth(0) , m_sourceHeight(0) - , m_paused(false) { connect(m_player, SIGNAL(frameAvailable()), this, SLOT(triggerRender())); connect(m_player, SIGNAL(videoSize(int, int)), this, SLOT(videoSize(int, int))); @@ -103,6 +99,21 @@ OmxItem::OmxItem() setFlag(ItemHasContents, true); } +void OmxItem::itemChange(ItemChange change, const ItemChangeData &) +{ + if (change == ItemSceneChange) { + QQuickWindow *win = window(); + if (!win) + return; + + // Connect the beforeRendering signal to our paint function. + // Since this call is executed on the rendering thread it must be + // a Qt::DirectConnection + connect(win, SIGNAL(beforeRendering()), this, SLOT(beforeRendering()), Qt::DirectConnection); + } +} + + OmxItem::~OmxItem() { delete m_player; @@ -129,14 +140,23 @@ void OmxItem::setSource(const QString &source) return; m_source = source; + emit sourceChanged(); + update(); +} + +void OmxItem::beforeRendering() +{ + if (m_initialized || m_source.isNull()) + return; m_initialized = m_player->initialize(m_source.toLocal8Bit()); + GLuint tid; + glGenTextures(1, &tid); + // start playing if not paused if (m_initialized && !paused()) m_player->setPaused(false); - - emit sourceChanged(); } QSGNode *OmxItem::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) diff --git a/src/imports/nativemedia/omxnode.h b/src/imports/nativemedia/omxnode.h index 976830c..22bbb4a 100644 --- a/src/imports/nativemedia/omxnode.h +++ b/src/imports/nativemedia/omxnode.h @@ -23,7 +23,6 @@ public: ~OmxNode(); void preprocess(); - void updateTexture(); void setRect(const QRectF &rect); inline void setRect(qreal x, qreal y, qreal w, qreal h) { setRect(QRectF(x, y, w, h)); } @@ -91,10 +90,12 @@ signals: protected: QSGNode *updatePaintNode(QSGNode *, UpdatePaintNodeData *); + void itemChange(ItemChange change, const ItemChangeData &); private slots: void triggerRender(); void videoSize(int w, int h); + void beforeRendering(); private: OmxPlayer *m_player; -- cgit v1.2.3