Skip to content
Snippets Groups Projects
Commit 64496d22 authored by Emmanuel Lepage Vallee's avatar Emmanuel Lepage Vallee
Browse files

video: Cosmetic

Refs #70057
parent 7005452a
No related branches found
No related tags found
No related merge requests found
...@@ -85,7 +85,7 @@ void Video::DirectRenderer::onNewFrame(const QByteArray& frame) ...@@ -85,7 +85,7 @@ void Video::DirectRenderer::onNewFrame(const QByteArray& frame)
return; return;
} }
Video::Renderer::d_ptr->m_framePtr = const_cast<char*>(frame.data()); Video::Renderer::d_ptr->m_pFrame = const_cast<char*>(frame.data());
emit frameUpdated(); emit frameUpdated();
} }
......
...@@ -54,17 +54,17 @@ ...@@ -54,17 +54,17 @@
*/ */
struct SHMHeader { struct SHMHeader {
sem_t mutex; // Lock it before any operations on following fields. sem_t mutex ; /*!< Lock it before any operations on following fields. */
sem_t frameGenMutex; // unlocked by producer when frameGen modified sem_t frameGenMutex; /*!< unlocked by producer when frameGen modified */
unsigned frameGen; // monotonically incremented when a producer changes readOffset unsigned frameGen ; /*!< monotonically incremented when a producer changes readOffset */
unsigned frameSize; // size in bytes of 1 frame unsigned frameSize ; /*!< size in bytes of 1 frame */
unsigned mapSize; // size to map if you need to see all data unsigned mapSize ; /*!< size to map if you need to see all data */
unsigned readOffset; // offset of readable frame in data unsigned readOffset ; /*!< offset of readable frame in data */
unsigned writeOffset; // offset of writable frame in data unsigned writeOffset ; /*!< offset of writable frame in data */
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-pedantic" #pragma GCC diagnostic ignored "-pedantic"
char data[]; // the whole shared memory char data[]; /*!< the whole shared memory */
#pragma GCC diagnostic pop #pragma GCC diagnostic pop
}; };
...@@ -77,6 +77,9 @@ class ShmRendererPrivate : public QObject ...@@ -77,6 +77,9 @@ class ShmRendererPrivate : public QObject
public: public:
ShmRendererPrivate(ShmRenderer* parent); ShmRendererPrivate(ShmRenderer* parent);
//Types
using TimePoint = std::chrono::time_point<std::chrono::system_clock>;
// Attributes // Attributes
QString m_ShmPath ; QString m_ShmPath ;
int m_fd ; int m_fd ;
...@@ -86,11 +89,11 @@ class ShmRendererPrivate : public QObject ...@@ -86,11 +89,11 @@ class ShmRendererPrivate : public QObject
QTimer* m_pTimer ; QTimer* m_pTimer ;
int m_fpsC ; int m_fpsC ;
int m_Fps ; int m_Fps ;
std::chrono::time_point<std::chrono::system_clock> m_lastFrameDebug; TimePoint m_lastFrameDebug;
// Constants // Constants
static const int FPS_RATE_SEC = 1; constexpr static const int FPS_RATE_SEC = 1 ;
static const int FRAME_CHECK_RATE_HZ = 120; constexpr static const int FRAME_CHECK_RATE_HZ = 120;
// Helpers // Helpers
timespec createTimeout( ); timespec createTimeout( );
...@@ -121,8 +124,7 @@ ShmRendererPrivate::ShmRendererPrivate(ShmRenderer* parent) ...@@ -121,8 +124,7 @@ ShmRendererPrivate::ShmRendererPrivate(ShmRenderer* parent)
} }
/// Constructor /// Constructor
ShmRenderer::ShmRenderer(const QByteArray& id, const QString& shmPath, ShmRenderer::ShmRenderer(const QByteArray& id, const QString& shmPath, const QSize& res)
const QSize& res)
: Renderer(id, res) : Renderer(id, res)
, d_ptr(new ShmRendererPrivate(this)) , d_ptr(new ShmRendererPrivate(this))
{ {
...@@ -155,6 +157,7 @@ bool ShmRendererPrivate::getNewFrame(bool wait) ...@@ -155,6 +157,7 @@ bool ShmRendererPrivate::getNewFrame(bool wait)
if (!shmLock()) if (!shmLock())
return false; return false;
} }
// valid frame to render (daemon may have stopped)? // valid frame to render (daemon may have stopped)?
...@@ -169,7 +172,7 @@ bool ShmRendererPrivate::getNewFrame(bool wait) ...@@ -169,7 +172,7 @@ bool ShmRendererPrivate::getNewFrame(bool wait)
return false; return false;
} }
q_ptr->Video::Renderer::d_ptr->m_framePtr = (char*)(m_pShmArea->data + m_pShmArea->readOffset); q_ptr->Video::Renderer::d_ptr->m_pFrame = (char*)(m_pShmArea->data + m_pShmArea->readOffset);
m_FrameGen = m_pShmArea->frameGen; m_FrameGen = m_pShmArea->frameGen;
q_ptr->Video::Renderer::d_ptr->m_FrameSize = m_pShmArea->frameSize; q_ptr->Video::Renderer::d_ptr->m_FrameSize = m_pShmArea->frameSize;
...@@ -210,6 +213,7 @@ bool ShmRendererPrivate::remapShm() ...@@ -210,6 +213,7 @@ bool ShmRendererPrivate::remapShm()
m_pShmArea = (SHMHeader*) ::mmap(nullptr, mapSize, PROT_READ | PROT_WRITE, m_pShmArea = (SHMHeader*) ::mmap(nullptr, mapSize, PROT_READ | PROT_WRITE,
MAP_SHARED, m_fd, 0); MAP_SHARED, m_fd, 0);
if (m_pShmArea == MAP_FAILED) { if (m_pShmArea == MAP_FAILED) {
qDebug() << "Could not remap shared area: " << strerror(errno); qDebug() << "Could not remap shared area: " << strerror(errno);
return false; return false;
...@@ -233,6 +237,7 @@ bool ShmRenderer::startShm() ...@@ -233,6 +237,7 @@ bool ShmRenderer::startShm()
} }
d_ptr->m_fd = ::shm_open(d_ptr->m_ShmPath.toLatin1(), O_RDWR, 0); d_ptr->m_fd = ::shm_open(d_ptr->m_ShmPath.toLatin1(), O_RDWR, 0);
if (d_ptr->m_fd < 0) { if (d_ptr->m_fd < 0) {
qDebug() << "could not open shm area" << d_ptr->m_ShmPath qDebug() << "could not open shm area" << d_ptr->m_ShmPath
<< ", shm_open failed:" << strerror(errno); << ", shm_open failed:" << strerror(errno);
...@@ -243,7 +248,9 @@ bool ShmRenderer::startShm() ...@@ -243,7 +248,9 @@ bool ShmRenderer::startShm()
const auto mapSize = sizeof(SHMHeader); const auto mapSize = sizeof(SHMHeader);
d_ptr->m_pShmArea = (SHMHeader*) ::mmap(nullptr, mapSize, d_ptr->m_pShmArea = (SHMHeader*) ::mmap(nullptr, mapSize,
PROT_READ | PROT_WRITE, PROT_READ | PROT_WRITE,
MAP_SHARED, d_ptr->m_fd, 0); MAP_SHARED, d_ptr->m_fd, 0
);
if (d_ptr->m_pShmArea == MAP_FAILED) { if (d_ptr->m_pShmArea == MAP_FAILED) {
qDebug() << "Could not remap shared area"; qDebug() << "Could not remap shared area";
return false; return false;
...@@ -326,7 +333,7 @@ int ShmRenderer::fps() const ...@@ -326,7 +333,7 @@ int ShmRenderer::fps() const
const QByteArray& ShmRenderer::currentFrame() const const QByteArray& ShmRenderer::currentFrame() const
{ {
if (!isRendering()) if (!isRendering())
return {}; return Renderer::currentFrame();
QMutexLocker lk {mutex()}; QMutexLocker lk {mutex()};
d_ptr->getNewFrame(false); d_ptr->getNewFrame(false);
......
...@@ -41,7 +41,7 @@ public: ...@@ -41,7 +41,7 @@ public:
QMutex* m_pMutex ; QMutex* m_pMutex ;
QString m_Id ; QString m_Id ;
QSize m_pSize ; QSize m_pSize ;
char* m_framePtr ; char* m_pFrame ;
QByteArray m_Content ; QByteArray m_Content ;
unsigned int m_FrameSize ; unsigned int m_FrameSize ;
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
Video::RendererPrivate::RendererPrivate(Video::Renderer* parent) Video::RendererPrivate::RendererPrivate(Video::Renderer* parent)
: QObject(parent), q_ptr(parent) : QObject(parent), q_ptr(parent)
, m_pMutex(new QMutex()),m_framePtr(nullptr),m_FrameSize(0) , m_pMutex(new QMutex()),m_pFrame(nullptr),m_FrameSize(0),m_isRendering(false)
{ {
} }
...@@ -68,8 +68,8 @@ QSize Video::Renderer::size() const ...@@ -68,8 +68,8 @@ QSize Video::Renderer::size() const
const QByteArray& Video::Renderer::currentFrame() const const QByteArray& Video::Renderer::currentFrame() const
{ {
if (d_ptr->m_framePtr && d_ptr->m_FrameSize) if (d_ptr->m_pFrame && d_ptr->m_FrameSize)
d_ptr->m_Content.setRawData(d_ptr->m_framePtr,d_ptr->m_FrameSize); d_ptr->m_Content.setRawData(d_ptr->m_pFrame,d_ptr->m_FrameSize);
return d_ptr->m_Content; return d_ptr->m_Content;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment