Skip to content
Snippets Groups Projects
Commit b65b4ced authored by Alexandre Lision's avatar Alexandre Lision
Browse files

osx: add functionnal direct renderer

Video is correctly received and send to the client

Refs #66887
parent ed4b639e
Branches
Tags
No related merge requests found
...@@ -21,7 +21,9 @@ ...@@ -21,7 +21,9 @@
#include <QtCore/QMutex> #include <QtCore/QMutex>
#include <QtCore/QThread> #include <QtCore/QThread>
#include <QtCore/QTime> #include <QtCore/QTime>
#include <QtCore/QTimer>
#include <cstring>
#ifndef CLOCK_REALTIME #ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 0 #define CLOCK_REALTIME 0
...@@ -48,8 +50,6 @@ private: ...@@ -48,8 +50,6 @@ private:
} }
Video::DirectRendererPrivate::DirectRendererPrivate(Video::DirectRenderer* parent) : QObject(parent), q_ptr(parent) Video::DirectRendererPrivate::DirectRendererPrivate(Video::DirectRenderer* parent) : QObject(parent), q_ptr(parent)
{ {
} }
...@@ -58,12 +58,6 @@ Video::DirectRendererPrivate::DirectRendererPrivate(Video::DirectRenderer* paren ...@@ -58,12 +58,6 @@ Video::DirectRendererPrivate::DirectRendererPrivate(Video::DirectRenderer* paren
Video::DirectRenderer::DirectRenderer(const QByteArray& id, const QSize& res): Renderer(id, res), d_ptr(new DirectRendererPrivate(this)) Video::DirectRenderer::DirectRenderer(const QByteArray& id, const QSize& res): Renderer(id, res), d_ptr(new DirectRendererPrivate(this))
{ {
setObjectName("Video::DirectRenderer:"+id); setObjectName("Video::DirectRenderer:"+id);
//DBusVideoManager::instance().registerFrameListener("local", [this] {
// qDebug() << "RECEIVED FRAME";
// });
} }
///Destructor ///Destructor
...@@ -74,10 +68,28 @@ Video::DirectRenderer::~DirectRenderer() ...@@ -74,10 +68,28 @@ Video::DirectRenderer::~DirectRenderer()
void Video::DirectRenderer::startRendering() void Video::DirectRenderer::startRendering()
{ {
qWarning() << "STARTING RENDERING";
setRendering(true);
emit started();
} }
void Video::DirectRenderer::stopRendering () void Video::DirectRenderer::stopRendering ()
{ {
qWarning() << "STOPPING RENDERING";
setRendering(false);
emit stopped();
}
void Video::DirectRenderer::onNewFrame(const QByteArray& frame)
{
// qDebug("Frame received by DirectRenderer, size: w %d, h %d", size().width(), size().height());
if (!isRendering()) {
return;
}
if (static_cast<Video::Renderer*>(this)->d_ptr->otherFrame().size() != (size().height() * size().width()))
static_cast<Video::Renderer*>(this)->d_ptr->otherFrame().resize(size().height() * size().width()*4);
::memcpy(static_cast<Video::Renderer*>(this)->d_ptr->otherFrame().data(),frame,static_cast<Video::Renderer*>(this)->d_ptr->otherFrame().size());
static_cast<Video::Renderer*>(this)->d_ptr->updateFrameIndex();
emit frameUpdated();
} }
#include <directrenderer.moc> #include <directrenderer.moc>
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
//Qt //Qt
class QMutex; class QMutex;
class QTimer;
class QThread;
//Ring //Ring
#include "video/device.h" #include "video/device.h"
...@@ -41,10 +43,14 @@ class LIB_EXPORT DirectRenderer : public Renderer { ...@@ -41,10 +43,14 @@ class LIB_EXPORT DirectRenderer : public Renderer {
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
public: public:
//Constructor //Constructor
DirectRenderer (const QByteArray& id, const QSize& res); DirectRenderer (const QByteArray& id, const QSize& res);
virtual ~DirectRenderer(); virtual ~DirectRenderer();
void onNewFrame(const QByteArray& frame);
public Q_SLOTS:
virtual void startRendering() override; virtual void startRendering() override;
virtual void stopRendering () override; virtual void stopRendering () override;
......
...@@ -45,7 +45,7 @@ public: ...@@ -45,7 +45,7 @@ public:
QSize m_pSize ; QSize m_pSize ;
//Helpers //Helpers
QByteArray& otherFrame () const; QByteArray& otherFrame () ;
void updateFrameIndex () ; void updateFrameIndex () ;
private: private:
......
...@@ -18,6 +18,9 @@ ...@@ -18,6 +18,9 @@
***************************************************************************/ ***************************************************************************/
#include "videorenderermanager.h" #include "videorenderermanager.h"
#include <vector>
//Qt //Qt
#include <QtCore/QMutex> #include <QtCore/QMutex>
...@@ -58,7 +61,7 @@ public: ...@@ -58,7 +61,7 @@ public:
private: private:
VideoRendererManager* q_ptr; VideoRendererManager* q_ptr;
private Q_SLOTS: public Q_SLOTS:
void startedDecoding(const QString& id, const QString& shmPath, int width, int height); void startedDecoding(const QString& id, const QString& shmPath, int width, int height);
void stoppedDecoding(const QString& id, const QString& shmPath); void stoppedDecoding(const QString& id, const QString& shmPath);
void deviceEvent(); void deviceEvent();
...@@ -124,6 +127,7 @@ Video::Renderer* VideoRendererManager::previewRenderer() ...@@ -124,6 +127,7 @@ Video::Renderer* VideoRendererManager::previewRenderer()
///Stop video preview ///Stop video preview
void VideoRendererManager::stopPreview() void VideoRendererManager::stopPreview()
{ {
//d_ptr->stoppedDecoding("local","");
VideoManagerInterface& interface = DBus::VideoManager::instance(); VideoManagerInterface& interface = DBus::VideoManager::instance();
interface.stopCamera(); interface.stopCamera();
d_ptr->m_PreviewState = false; d_ptr->m_PreviewState = false;
...@@ -132,6 +136,9 @@ void VideoRendererManager::stopPreview() ...@@ -132,6 +136,9 @@ void VideoRendererManager::stopPreview()
///Start video preview ///Start video preview
void VideoRendererManager::startPreview() void VideoRendererManager::startPreview()
{ {
qWarning() << "STARTING PREVIEW";
// d_ptr->startedDecoding("local","",500,500);
if (d_ptr->m_PreviewState) return; if (d_ptr->m_PreviewState) return;
VideoManagerInterface& interface = DBus::VideoManager::instance(); VideoManagerInterface& interface = DBus::VideoManager::instance();
interface.startCamera(); interface.startCamera();
...@@ -159,13 +166,18 @@ void VideoRendererManagerPrivate::deviceEvent() ...@@ -159,13 +166,18 @@ void VideoRendererManagerPrivate::deviceEvent()
///A video is not being rendered ///A video is not being rendered
void VideoRendererManagerPrivate::startedDecoding(const QString& id, const QString& shmPath, int width, int height) void VideoRendererManagerPrivate::startedDecoding(const QString& id, const QString& shmPath, int width, int height)
{ {
const QSize res = QSize(width,height); const QSize res = QSize(width,height);
const QByteArray rid = id.toLatin1(); const QByteArray rid = id.toLatin1();
qWarning() << "startedDecoding for sink id: " << id;
if (m_lRenderers[rid] == nullptr ) { if (m_lRenderers[rid] == nullptr ) {
#if defined(Q_OS_DARWIN) #if defined(Q_OS_DARWIN)
m_lRenderers[rid] = new Video::DirectRenderer(rid, res); m_lRenderers[rid] = new Video::DirectRenderer(rid, res);
qWarning() << "Calling registerFrameListener";
DBus::VideoManager::instance().registerSinkTarget(id, [this, id, width, height] (const unsigned char* frame) {
static_cast<Video::DirectRenderer*>(m_lRenderers[id.toLatin1()])->onNewFrame(
QByteArray::fromRawData(reinterpret_cast<const char *>(frame), width*height));
});
#else #else
m_lRenderers[rid] = new Video::ShmRenderer(rid,shmPath,res); m_lRenderers[rid] = new Video::ShmRenderer(rid,shmPath,res);
#endif #endif
...@@ -174,9 +186,12 @@ void VideoRendererManagerPrivate::startedDecoding(const QString& id, const QStri ...@@ -174,9 +186,12 @@ void VideoRendererManagerPrivate::startedDecoding(const QString& id, const QStri
q_ptr->start(); q_ptr->start();
} }
else { else {
// Video::Renderer* Renderer = m_lRenderers[rid];
//TODO: do direct renderer stuff here
m_lRenderers[rid]->setSize(res); m_lRenderers[rid]->setSize(res);
DBus::VideoManager::instance().registerSinkTarget(id, [this, id, width, height] (const unsigned char* frame) {
static_cast<Video::DirectRenderer*>(m_lRenderers[id.toLatin1()])->onNewFrame(
QByteArray::fromRawData(reinterpret_cast<const char *>(frame), width*height));
});
#if !defined(Q_OS_DARWIN) #if !defined(Q_OS_DARWIN)
static_cast<Video::ShmRenderer*>(m_lRenderers[rid])->setShmPath(shmPath); static_cast<Video::ShmRenderer*>(m_lRenderers[rid])->setShmPath(shmPath);
#endif #endif
......
...@@ -10,6 +10,10 @@ SET(ENABLE_LIBWRAP true) ...@@ -10,6 +10,10 @@ SET(ENABLE_LIBWRAP true)
ADD_DEFINITIONS(-DENABLE_LIBWRAP=true) ADD_DEFINITIONS(-DENABLE_LIBWRAP=true)
ADD_DEFINITIONS("-std=c++0x") ADD_DEFINITIONS("-std=c++0x")
MESSAGE("VIDEO enabled")
ADD_DEFINITIONS(-DENABLE_VIDEO=true)
SET(ENABLE_VIDEO 1 CACHE BOOLEAN "Enable video")
SET(LOCAL_CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../../cmake/) SET(LOCAL_CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/../../cmake/)
SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LOCAL_CMAKE_MODULE_PATH}) SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LOCAL_CMAKE_MODULE_PATH})
......
...@@ -55,7 +55,7 @@ InstanceInterface::InstanceInterface() : m_pTimer(nullptr) ...@@ -55,7 +55,7 @@ InstanceInterface::InstanceInterface() : m_pTimer(nullptr)
registerCallHandlers(DBus::CallManager::instance().callHandlers); registerCallHandlers(DBus::CallManager::instance().callHandlers);
registerConfHandlers(DBus::ConfigurationManager::instance().confHandlers); registerConfHandlers(DBus::ConfigurationManager::instance().confHandlers);
registerPresHandlers(DBus::PresenceManager::instance().presHandlers); registerPresHandlers(DBus::PresenceManager::instance().presHandlers);
#ifdef RING_VIDEO #ifdef ENABLE_VIDEO
registerVideoHandlers(DBus::VideoManager::instance().videoHandlers); registerVideoHandlers(DBus::VideoManager::instance().videoHandlers);
#endif #endif
......
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
#ifndef VIDEO_DBUS_INTERFACE_H #ifndef VIDEO_DBUS_INTERFACE_H
#define VIDEO_DBUS_INTERFACE_H #define VIDEO_DBUS_INTERFACE_H
// libstdc++
#include <functional>
// Qt
#include <QtCore/QObject> #include <QtCore/QObject>
#include <QtCore/QCoreApplication> #include <QtCore/QCoreApplication>
#include <QtCore/QByteArray> #include <QtCore/QByteArray>
...@@ -88,10 +92,6 @@ private: ...@@ -88,10 +92,6 @@ private:
VideoManagerSignalProxy* proxy; VideoManagerSignalProxy* proxy;
VideoManagerProxySender* sender; VideoManagerProxySender* sender;
#ifdef ENABLE_VIDEO
std::map<std::string, std::shared_ptr<DRing::CallbackWrapperBase>> videoHandlers;
#endif
public Q_SLOTS: // METHODS public Q_SLOTS: // METHODS
void applySettings(const QString &name, MapStringString settings) void applySettings(const QString &name, MapStringString settings)
{ {
...@@ -192,17 +192,27 @@ public Q_SLOTS: // METHODS ...@@ -192,17 +192,27 @@ public Q_SLOTS: // METHODS
#endif #endif
} }
void registerSinkTarget(const QString &sinkID, std::function<void(uint8_t*)>&& cb)
{
#ifdef ENABLE_VIDEO
DRing::registerSinkTarget(sinkID.toStdString(), std::move(cb));
#endif
}
void registerSinkTarget(const QString &sinkID, std::function<void(uint8_t*)>& cb)
{
#ifdef ENABLE_VIDEO
DRing::registerSinkTarget(sinkID.toStdString(), std::move(cb));
#endif
}
Q_SIGNALS: // SIGNALS Q_SIGNALS: // SIGNALS
void deviceEvent(); void deviceEvent();
void startedDecoding(const QString &id, const QString &shmPath, int width, int height, bool isMixer); void startedDecoding(const QString &id, const QString &shmPath, int width, int height, bool isMixer);
void stoppedDecoding(const QString &id, const QString &shmPath, bool isMixer); void stoppedDecoding(const QString &id, const QString &shmPath, bool isMixer);
}; };
namespace org { namespace org { namespace ring { namespace Ring {
namespace ring {
namespace Ring {
typedef ::VideoManagerInterface VideoManager; typedef ::VideoManagerInterface VideoManager;
} }}} // namesapce org::ring::Ring
}
}
#endif #endif
...@@ -49,10 +49,10 @@ bool Video::Renderer::isRendering() const ...@@ -49,10 +49,10 @@ bool Video::Renderer::isRendering() const
return d_ptr->m_isRendering; return d_ptr->m_isRendering;
} }
QByteArray& Video::RendererPrivate::otherFrame() const QByteArray& Video::RendererPrivate::otherFrame()
{ {
static QByteArray empty; static QByteArray empty;
return q_ptr->isRendering()?const_cast<Video::RendererPrivate*>(this)->m_Frame[!m_FrameIdx]:empty; return q_ptr->isRendering()?m_Frame[!m_FrameIdx]:empty;
} }
///Return the current framerate ///Return the current framerate
......
...@@ -34,6 +34,7 @@ namespace Video { ...@@ -34,6 +34,7 @@ namespace Video {
class RendererPrivate; class RendererPrivate;
class ShmRendererPrivate; class ShmRendererPrivate;
class DirectRendererPrivate; class DirectRendererPrivate;
class DirectRenderer;
/** /**
* This class provide a rendering object to be used by clients * This class provide a rendering object to be used by clients
...@@ -50,6 +51,7 @@ Q_OBJECT ...@@ -50,6 +51,7 @@ Q_OBJECT
friend class Video::ShmRendererPrivate; friend class Video::ShmRendererPrivate;
friend class Video::DirectRendererPrivate; friend class Video::DirectRendererPrivate;
friend class Video::DirectRenderer;
public: public:
//Constructor //Constructor
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment