Commit 1eca0290 authored by Edric Milaret's avatar Edric Milaret

video: rewrite to use smart ptr

Refs #75280

Change-Id: I88318c097712a2d6948494a601cbf3faae3ead64
parent b37aa1fc
......@@ -89,7 +89,7 @@ win32: LIBS += -lole32 -luuid -lshlwapi
INCLUDEPATH += $${RING}/include/libringclient
LIBS += -L$${RING}/lib/ -lringclient
LIBS += -L$${RING}/lib -lringclient
RESOURCES += \
ressources.qrc
......@@ -142,5 +142,3 @@ win32 {
INSTALLS += RINGTONES PACKAGING LICENSE RUNTIME QTRUNTIME QTDEPSRUNTIME \
QTPLUGINIMAGE QTPLATFORMS LIBSTD
}
......@@ -27,7 +27,8 @@
#endif
bool
Utils::CreateStartupLink() {
Utils::CreateStartupLink()
{
#ifdef Q_OS_WIN32
TCHAR szPath[MAX_PATH];
GetModuleFileName(NULL, szPath, MAX_PATH);
......
......@@ -41,4 +41,5 @@ public:
static QString GetRingtonePath();
};
#endif // UTILS_H
......@@ -22,8 +22,6 @@ VideoWidget::VideoWidget(QWidget *parent) :
QWidget(parent)
, previewRenderer_(nullptr)
, renderer_(nullptr)
, previewFrame_(nullptr)
, distantFrame_(nullptr)
{
connect(Video::PreviewManager::instance(),
SIGNAL(previewStarted(Video::Renderer*)),
......@@ -44,58 +42,53 @@ VideoWidget::~VideoWidget()
void
VideoWidget::previewStarted(Video::Renderer *renderer) {
previewRenderer_ = renderer;
connect(previewRenderer_, SIGNAL(frameUpdated()),
this, SLOT(frameFromPreview()));
connect(previewRenderer_, SIGNAL(stopped()),
this, SLOT(previewStopped()));
if (this->isVisible()) {
previewRenderer_ = renderer;
connect(previewRenderer_, SIGNAL(frameUpdated()),
this, SLOT(frameFromPreview()));
connect(previewRenderer_, SIGNAL(stopped()),
this, SLOT(previewStopped()));
}
}
void
VideoWidget::previewStopped() {
QMutexLocker {&lock_};
if (previewFrame_) {
delete previewFrame_;
previewFrame_ = nullptr;
}
disconnect(previewRenderer_, SIGNAL(frameUpdated()),
this, SLOT(frameFromPreview()));
this, SLOT(frameFromPreview()));
disconnect(previewRenderer_, SIGNAL(stopped()),
this, SLOT(renderingStopped()));
this, SLOT(renderingStopped()));
previewRenderer_ = nullptr;
}
void
VideoWidget::frameFromPreview() {
if (previewFrame_) {
delete previewFrame_;
previewFrame_ = nullptr;
}
if (previewRenderer_ && previewRenderer_->isRendering()) {
const QSize size(previewRenderer_->size());
previewFrame_ = new QImage(
(const uchar*)previewRenderer_->currentFrame().constData(),
size.width(), size.height(), QImage::Format_RGBA8888);
currentPreviewFrame_ = previewRenderer_->currentSmartFrame();
update();
}
}
void
VideoWidget::paintEvent(QPaintEvent* evt) {
VideoWidget::paintEvent(QPaintEvent *evt) {
Q_UNUSED(evt)
QMutexLocker {&lock_};
QPainter painter(this);
if (distantFrame_ && renderer_ && renderer_->isRendering()) {
auto scaledDistant = distantFrame_->scaled(size(), Qt::KeepAspectRatio);
if (renderer_ && currentDistantFrame_) {
const QSize imgSize(renderer_->size());
QImage distantFrame(currentDistantFrame_.get()->data(),
imgSize.width(), imgSize.height(), QImage::Format_RGBA8888);
auto scaledDistant = distantFrame.scaled(size(), Qt::KeepAspectRatio);
auto xDiff = (width() - scaledDistant.width()) / 2;
auto yDiff = (height() - scaledDistant.height()) /2;
painter.drawImage(QRect(xDiff,yDiff,scaledDistant.width(),scaledDistant.height()), scaledDistant);
}
if (previewFrame_ && previewRenderer_ && previewRenderer_->isRendering()) {
if (previewRenderer_ && currentPreviewFrame_) {
const QSize imgSize(previewRenderer_->size());
QImage previewFrame(
currentPreviewFrame_.get()->data(),
imgSize.width(), imgSize.height(), QImage::Format_RGBA8888);
auto previewHeight = !renderer_ ? height() : height()/4;
auto previewWidth = !renderer_ ? width() : width()/4;
auto scaledPreview = previewFrame_->scaled(previewWidth, previewHeight, Qt::KeepAspectRatio);
auto scaledPreview = previewFrame.scaled(previewWidth, previewHeight, Qt::KeepAspectRatio);
auto xDiff = (previewWidth - scaledPreview.width()) / 2;
auto yDiff = (previewHeight - scaledPreview.height()) / 2;
auto yPos = !renderer_ ? yDiff : height() - previewHeight - previewMargin_;
......@@ -109,34 +102,24 @@ VideoWidget::paintEvent(QPaintEvent* evt) {
void
VideoWidget::callInitiated(Call* call, Video::Renderer *renderer) {
Q_UNUSED(call)
renderer_ = renderer;
connect(renderer_, SIGNAL(frameUpdated()), this, SLOT(frameFromDistant()));
connect(renderer_, SIGNAL(stopped()),this, SLOT(renderingStopped()),
Qt::ConnectionType::DirectConnection);
if (this->isVisible()) {
renderer_ = renderer;
connect(renderer_, SIGNAL(frameUpdated()), this, SLOT(frameFromDistant()));
connect(renderer_, SIGNAL(stopped()),this, SLOT(renderingStopped()),
Qt::ConnectionType::DirectConnection);
}
}
void
VideoWidget::frameFromDistant() {
if (distantFrame_) {
delete distantFrame_;
distantFrame_ = nullptr;
}
if (renderer_) {
const QSize size(renderer_->size());
distantFrame_ = new QImage(
(const uchar*) renderer_->currentFrame().constData(),
size.width(), size.height(), QImage::Format_RGBA8888);
if (renderer_ && renderer_->isRendering()) {
currentDistantFrame_ = renderer_->currentSmartFrame();
update();
}
}
void
VideoWidget::renderingStopped() {
QMutexLocker {&lock_};
if (distantFrame_) {
delete distantFrame_;
distantFrame_ = nullptr;
}
disconnect(renderer_, SIGNAL(frameUpdated()), this, SLOT(frameFromDistant()));
disconnect(renderer_, SIGNAL(stopped()),this, SLOT(renderingStopped()));
renderer_ = nullptr;
......
......@@ -21,8 +21,8 @@
#include <QWidget>
#include <QPainter>
#include <QMutex>
#include <QPixmap>
#include <memory>
#include "video/renderer.h"
#include "video/previewmanager.h"
......@@ -47,9 +47,8 @@ public slots:
private:
Video::Renderer* previewRenderer_;
Video::Renderer* renderer_;
QImage *previewFrame_;
QImage *distantFrame_;
QMutex lock_;
std::shared_ptr<std::vector<unsigned char> > currentPreviewFrame_;
std::shared_ptr<std::vector<unsigned char> > currentDistantFrame_;
constexpr static int previewMargin_ = 15;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment