Commit 37157b39 authored by Edric Milaret's avatar Edric Milaret Committed by Guillaume Roguez

video: adapt to new LRC renderer API

Issue: #81542
Change-Id: I4e1e62e137bc4865942e4b3546a1008a049724f9
parent edb4eb01
......@@ -22,8 +22,6 @@ VideoWidget::VideoWidget(QWidget *parent) :
QWidget(parent)
, previewRenderer_(nullptr)
, renderer_(nullptr)
, currentDistantFrame_(nullptr)
, currentPreviewFrame_(nullptr)
{
connect(Video::PreviewManager::instance(),
SIGNAL(previewStarted(Video::Renderer*)),
......@@ -61,24 +59,18 @@ VideoWidget::previewStopped() {
disconnect(previewRenderer_, SIGNAL(stopped()),
this, SLOT(renderingStopped()));
previewRenderer_ = nullptr;
if (currentPreviewFrame_) {
delete currentPreviewFrame_;
currentPreviewFrame_ = nullptr;
}
}
void
VideoWidget::frameFromPreview() {
if (previewRenderer_ && previewRenderer_->isRendering()) {
if (currentPreviewFrame_) {
delete currentPreviewFrame_;
currentPreviewFrame_ = nullptr;
{
QMutexLocker lock(&mutex_);
auto tmp = previewRenderer_->currentFrame();
if (tmp.storage.size())
currentPreviewFrame_ = tmp;
}
const QSize size(previewRenderer_->size());
currentPreviewFrame_ = new QImage(
(const uchar*)previewRenderer_->currentFrame().constData(),
size.width(), size.height(), QImage::Format_ARGB32_Premultiplied);
repaint();
update();
}
}
......@@ -86,22 +78,48 @@ void
VideoWidget::paintEvent(QPaintEvent *evt) {
Q_UNUSED(evt)
QPainter painter(this);
if (renderer_ && currentDistantFrame_) {
auto scaledDistant = currentDistantFrame_->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 (renderer_) {
{
QMutexLocker lock(&mutex_);
if (currentDistantFrame_.storage.size() != 0) {
frameDistant_ = std::move(currentDistantFrame_.storage);
distantImage_.reset(new QImage((uchar*)frameDistant_.data(),
renderer_->size().width(),
renderer_->size().height(),
QImage::Format_ARGB32_Premultiplied));
}
}
if (distantImage_) {
auto scaledDistant = distantImage_->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 (previewRenderer_ && currentPreviewFrame_) {
auto previewHeight = !renderer_ ? height() : height()/4;
auto previewWidth = !renderer_ ? width() : width()/4;
auto scaledPreview = currentPreviewFrame_->scaled(previewWidth, previewHeight, Qt::KeepAspectRatio);
auto xDiff = (previewWidth - scaledPreview.width()) / 2;
auto yDiff = (previewHeight - scaledPreview.height()) / 2;
auto yPos = !renderer_ ? yDiff : height() - previewHeight - previewMargin_;
auto xPos = !renderer_ ? xDiff : width() - scaledPreview.width() - previewMargin_;
painter.drawImage(QRect(xPos,yPos,scaledPreview.width(),scaledPreview.height()),
scaledPreview);
if (previewRenderer_) {
{
QMutexLocker lock(&mutex_);
if (currentPreviewFrame_.storage.size() != 0) {
framePreview_ = std::move(currentPreviewFrame_.storage);
previewImage_.reset(new QImage((uchar*)framePreview_.data(),
previewRenderer_->size().width(),
previewRenderer_->size().height(),
QImage::Format_ARGB32_Premultiplied));
}
}
if (previewImage_) {
auto previewHeight = !renderer_ ? height() : height()/4;
auto previewWidth = !renderer_ ? width() : width()/4;
auto scaledPreview = previewImage_->scaled(previewWidth, previewHeight, Qt::KeepAspectRatio);
auto xDiff = (previewWidth - scaledPreview.width()) / 2;
auto yDiff = (previewHeight - scaledPreview.height()) / 2;
auto yPos = !renderer_ ? yDiff : height() - previewHeight - previewMargin_;
auto xPos = !renderer_ ? xDiff : width() - scaledPreview.width() - previewMargin_;
painter.drawImage(QRect(xPos,yPos,scaledPreview.width(),scaledPreview.height()),
scaledPreview);
}
}
painter.end();
}
......@@ -121,15 +139,14 @@ VideoWidget::callInitiated(Call* call, Video::Renderer *renderer) {
void
VideoWidget::frameFromDistant() {
if (renderer_ && renderer_->isRendering()) {
if (currentDistantFrame_) {
delete currentDistantFrame_;
currentDistantFrame_ = nullptr;
{
QMutexLocker lock(&mutex_);
auto tmp = renderer_->currentFrame();
if (tmp.storage.size())
currentDistantFrame_ = tmp;
}
const QSize size(renderer_->size());
currentDistantFrame_ = new QImage(
(const uchar*)renderer_->currentFrame().constData(),
size.width(), size.height(), QImage::Format_ARGB32_Premultiplied);
repaint();
update();
}
}
......@@ -138,8 +155,4 @@ VideoWidget::renderingStopped() {
disconnect(renderer_, SIGNAL(frameUpdated()), this, SLOT(frameFromDistant()));
disconnect(renderer_, SIGNAL(stopped()),this, SLOT(renderingStopped()));
renderer_ = nullptr;
if (currentDistantFrame_) {
delete currentDistantFrame_;
currentDistantFrame_ = nullptr;
}
}
......@@ -46,8 +46,14 @@ public slots:
private:
Video::Renderer* previewRenderer_;
Video::Renderer* renderer_;
QImage* currentPreviewFrame_;
QImage* currentDistantFrame_;
Video::Frame currentPreviewFrame_;
Video::Frame currentDistantFrame_;
QMutex mutex_;
std::unique_ptr<QImage> distantImage_;
std::unique_ptr<QImage> previewImage_;
std::vector<uint8_t> frameDistant_;
std::vector<uint8_t> framePreview_;
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