From 60706c02b7b465e8bc15d3cd0fc42c9b253e62f7 Mon Sep 17 00:00:00 2001 From: Alexandre Lision <alexandre.lision@savoirfairelinux.com> Date: Mon, 13 Apr 2015 12:06:15 -0400 Subject: [PATCH] video: resynchronize start and stop render signals make sure start and stop decoding are always fired to the client in the same than the daemon as fired them. Refs #70681 --- src/private/videorenderermanager.cpp | 6 ++--- src/qtwrapper/videomanager_wrap.cpp | 33 +++++++++++++++++++++++++--- src/qtwrapper/videomanager_wrap.h | 4 ++++ 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/private/videorenderermanager.cpp b/src/private/videorenderermanager.cpp index 309beb52..f054cb21 100644 --- a/src/private/videorenderermanager.cpp +++ b/src/private/videorenderermanager.cpp @@ -36,7 +36,6 @@ #include <video/resolution.h> #include "private/videorate_p.h" #include "private/call_p.h" -#include "private/videorenderer_p.h" #ifdef ENABLE_LIBWRAP #include "private/directrenderer.h" @@ -205,6 +204,7 @@ void VideoRendererManagerPrivate::startedDecoding(const QString& id, const QStri r = new Video::DirectRenderer(rid, res); qWarning() << "Calling registerFrameListener"; + m_hRenderers[rid] = r; DBus::VideoManager::instance().registerSinkTarget(id, [this, id, width, height] (const unsigned char* frame) { static_cast<Video::DirectRenderer*>(m_hRenderers[id.toLatin1()])->onNewFrame( @@ -215,10 +215,10 @@ void VideoRendererManagerPrivate::startedDecoding(const QString& id, const QStri #else //ENABLE_LIBWRAP r = new Video::ShmRenderer(rid,shmPath,res); + m_hRenderers[rid] = r; #endif - m_hRenderers[rid] = r; QThread* t = new QThread(this); m_hThreads[r] = t; @@ -280,7 +280,7 @@ void VideoRendererManagerPrivate::stoppedDecoding(const QString& id, const QStri //Quit if for some reasons the renderer is not found if ( !r ) { - qWarning() << "Cannot stop renrering, renderer" << id << "not found"; + qWarning() << "Cannot stop rendering, renderer" << id << "not found"; return; } diff --git a/src/qtwrapper/videomanager_wrap.cpp b/src/qtwrapper/videomanager_wrap.cpp index 6cd758ca..aede8dcb 100644 --- a/src/qtwrapper/videomanager_wrap.cpp +++ b/src/qtwrapper/videomanager_wrap.cpp @@ -1,4 +1,22 @@ -#include "videomanager_wrap.h" +/****************************************************************************** + * Copyright (C) 2014 by Savoir-Faire Linux * + * Author : Philippe Groarke <philippe.groarke@savoirfairelinux.com> * + * Author : Alexandre Lision <alexandre.lision@savoirfairelinux.com> * + * * + * This library is free software; you can redistribute it and/or * + * modify it under the terms of the GNU Lesser General Public * + * License as published by the Free Software Foundation; either * + * version 2.1 of the License, or (at your option) any later version. * + * * + * This library is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the Lesser GNU General Public License * + * along with this program. If not, see <http://www.gnu.org/licenses/>. * + *****************************************************************************/ + #include "videomanager_wrap.h" VideoManagerInterface::VideoManagerInterface() { @@ -36,7 +54,8 @@ VideoManagerInterface::~VideoManagerInterface() } -VideoManagerSignalProxy::VideoManagerSignalProxy(VideoManagerInterface* parent) : QObject(parent), m_pParent(parent) +VideoManagerSignalProxy::VideoManagerSignalProxy(VideoManagerInterface* parent) : QObject(parent), +m_pParent(parent), m_pSem(new QSemaphore(3)) {} void VideoManagerSignalProxy::slotDeviceEvent() @@ -49,13 +68,21 @@ void VideoManagerSignalProxy::slotDeviceEvent() void VideoManagerSignalProxy::slotStartedDecoding(const QString &id, const QString &shmPath, int width, int height, bool isMixer) { QTimer::singleShot(0, [=] { - emit m_pParent->startedDecoding(id,shmPath,width,height,isMixer); + if(m_pSem->available() == 3) + emit m_pParent->startedDecoding(id,shmPath,width,height,isMixer); + else { + QTimer::singleShot(0, [=] { + slotStartedDecoding(id,shmPath,width,height,isMixer); + }); + } }); } void VideoManagerSignalProxy::slotStoppedDecoding(const QString &id, const QString &shmPath, bool isMixer) { + m_pSem->acquire(1); QTimer::singleShot(0, [=] { emit m_pParent->stoppedDecoding(id,shmPath,isMixer); + m_pSem->release(1); }); } diff --git a/src/qtwrapper/videomanager_wrap.h b/src/qtwrapper/videomanager_wrap.h index e1056c09..622921c7 100644 --- a/src/qtwrapper/videomanager_wrap.h +++ b/src/qtwrapper/videomanager_wrap.h @@ -29,17 +29,20 @@ #include <QtCore/QThread> #include <QtCore/QList> #include <QtCore/QMap> +#include <QtCore/QSemaphore> #include <QtCore/QString> #include <QtCore/QStringList> #include <QtCore/QVariant> #include <QtCore/QTimer> +// Ring #include <videomanager_interface.h> #include "typedefs.h" #include "conversions_wrap.hpp" class VideoManagerInterface; +class QSemaphore; class VideoManagerSignalProxy : public QObject { @@ -54,6 +57,7 @@ public Q_SLOTS: private: VideoManagerInterface* m_pParent; + QSemaphore* m_pSem; }; class VideoManagerProxySender : public QObject -- GitLab