Fix some surface assignment errors.

On destruction and changing sources, make sure we don't clobber the
surface property if it's been changed.

Change-Id: I3080b98a547911543a391c8bc040792d260782fd
Reviewed-by: Dmytro Poplavskiy <dmytro.poplavskiy@nokia.com>
This commit is contained in:
Michael Goddard
2012-01-27 12:38:35 +10:00
committed by Qt by Nokia
parent bad94a5329
commit 88431b2841
2 changed files with 30 additions and 5 deletions

View File

@@ -178,6 +178,11 @@ QDeclarativeVideoOutput::QDeclarativeVideoOutput(QQuickItem *parent) :
QDeclarativeVideoOutput::~QDeclarativeVideoOutput()
{
if (m_source && m_sourceType == VideoSurfaceSource) {
if (m_source.data()->property("videoSurface").value<QAbstractVideoSurface*>() == m_surface)
m_source.data()->setProperty("videoSurface", QVariant::fromValue<QAbstractVideoSurface*>(0));
}
m_source.clear();
_q_updateMediaObject();
delete m_surface;
@@ -209,8 +214,10 @@ void QDeclarativeVideoOutput::setSource(QObject *source)
if (m_source && m_sourceType == MediaObjectSource)
disconnect(0, m_source.data(), SLOT(_q_updateMediaObject()));
if (m_source && m_sourceType == VideoSurfaceSource)
if (m_source && m_sourceType == VideoSurfaceSource) {
if (m_source.data()->property("videoSurface").value<QAbstractVideoSurface*>() == m_surface)
m_source.data()->setProperty("videoSurface", QVariant::fromValue<QAbstractVideoSurface*>(0));
}
m_surface->stop();

View File

@@ -70,6 +70,9 @@ public:
}
void setVideoSurface(QAbstractVideoSurface *surface)
{
if (m_surface != surface && m_surface && m_surface->isActive()) {
m_surface->stop();
}
m_surface = surface;
}
@@ -133,6 +136,9 @@ private slots:
void mappingRect();
void mappingRect_data();
// XXX May be worth adding tests that the surface activeChanged signals are sent appropriately
// to holder?
private:
QDeclarativeEngine m_engine;
QByteArray m_plainQML;
@@ -293,7 +299,6 @@ void tst_QDeclarativeVideoOutput::surfaceSource()
delete videoOutput;
// This should clear the surface
QEXPECT_FAIL("", "Surface not cleared on destruction", Continue);
QCOMPARE(holder.videoSurface(), static_cast<QAbstractVideoSurface*>(0));
// Also, creating two sources, setting them in order, and destroying the first
@@ -324,9 +329,22 @@ void tst_QDeclarativeVideoOutput::surfaceSource()
QCOMPARE(holder.videoSurface(), static_cast<QAbstractVideoSurface*>(0));
QVERIFY(holder2.videoSurface() != 0);
// XXX May be worth adding tests that the surface activeChanged signals are sent appropriately
// to holder?
// Finally a combination - set the same source to two things, then assign a new source
// to the first output - should not reset the first source
videoOutput = component.create();
videoOutput->setProperty("source", QVariant::fromValue(static_cast<QObject*>(&holder2)));
// Both vo and vo2 were pointed to holder2 - setting vo2 should not clear holder2
QVERIFY(holder2.videoSurface() != 0);
QVERIFY(holder.videoSurface() == 0);
videoOutput2->setProperty("source", QVariant::fromValue(static_cast<QObject*>(&holder)));
QVERIFY(holder2.videoSurface() != 0);
QVERIFY(holder.videoSurface() != 0);
// They should also be independent
QVERIFY(holder.videoSurface() != holder2.videoSurface());
delete videoOutput;
delete videoOutput2;
}