summaryrefslogtreecommitdiffstats
path: root/src/imports
diff options
context:
space:
mode:
authorSamuel Rødal <samuel.rodal@digia.com>2013-03-14 10:58:44 +0100
committerSamuel Rødal <samuel.rodal@digia.com>2013-03-14 10:58:44 +0100
commit9408807bb0fd7a9a83531241a8e7b8f8d9d76dd1 (patch)
treebff12408f5bc6c3cf0849b8f683e0380c51139d1 /src/imports
parent1d5cbee9ef561634dcf55208ec135c6f61c66bb2 (diff)
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.
Diffstat (limited to 'src/imports')
-rw-r--r--src/imports/nativemedia/omxnode.cpp36
-rw-r--r--src/imports/nativemedia/omxnode.h3
2 files changed, 30 insertions, 9 deletions
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 <QtGui/QOpenGLContext>
#include <QtQuick/qsgtexture.h>
+#include <QtQuick/qquickwindow.h>
#include <QTimer>
@@ -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;