AVFoundation: Fix broken requestControl logic
authorAndy Nichols <andy.nichols@digia.com>
Tue, 20 Nov 2012 11:48:09 +0000 (12:48 +0100)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 20 Nov 2012 18:29:27 +0000 (19:29 +0100)
AVFMediaPlayerService::requestControl was returning the video output
control after the video output was created, and this could result in
unexpected behavior, as well as prematurely calling releaseControl on
the video output.  This should fix the "player" example on OS X.

Change-Id: Ie23b1176272a1f9daa5edeec856141ac52a450c7
Reviewed-by: Yoann Lopes <yoann.lopes@digia.com>
src/plugins/avfoundation/mediaplayer/avfmediaplayerservice.mm

index 2ea8475..3b780e3 100644 (file)
@@ -84,18 +84,22 @@ QMediaControl *AVFMediaPlayerService::requestControl(const char *name)
     if (qstrcmp(name, QMetaDataReaderControl_iid) == 0)
         return m_playerMetaDataControl;
 
-    if (!m_videoOutput) {
-        if (qstrcmp(name, QVideoRendererControl_iid) == 0)
+    if (qstrcmp(name, QVideoRendererControl_iid) == 0) {
+        if (!m_videoOutput)
             m_videoOutput = new AVFVideoRendererControl(this);
+
+        m_session->setVideoOutput(qobject_cast<AVFVideoOutput*>(m_videoOutput));
+        return m_videoOutput;
+    }
 #ifndef QT_NO_WIDGETS
-        if (qstrcmp(name, QVideoWidgetControl_iid) == 0)
+    if (qstrcmp(name, QVideoWidgetControl_iid) == 0) {
+        if (!m_videoOutput)
             m_videoOutput = new AVFVideoWidgetControl(this);
-#endif
-    }
-    if (m_videoOutput) {
+
         m_session->setVideoOutput(qobject_cast<AVFVideoOutput*>(m_videoOutput));
         return m_videoOutput;
     }
+#endif
 
     return 0;
 }