Skip to content

Commit

Permalink
fix(Settings): Use the actual resolution when drawing grid for ROI demo
Browse files Browse the repository at this point in the history
The optimization of downscaling the video for ROI/self view was causing the
grid to be drawn with much larger squares than they actually were. This commit
makes the grid use the real resolution, giving more control to user in grid
drawing mode.
  • Loading branch information
jrsnen committed Mar 16, 2023
1 parent f275988 commit 6ad44e7
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 39 deletions.
19 changes: 11 additions & 8 deletions src/ui/gui/conferenceview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,16 +327,19 @@ void ConferenceView::callStarted(uint32_t sessionID, QWidget* video,
{
if (video != nullptr)
{
activeViews_[sessionID]->video = video;
updateSessionState(VIEW_VIDEO, video, sessionID);
if (activeViews_[sessionID]->state != VIEW_VIDEO)
{
activeViews_[sessionID]->video = video;
updateSessionState(VIEW_VIDEO, video, sessionID);

// signals for double click attach/detach
QObject::connect(video, SIGNAL(reattach(uint32_t)),
this, SLOT(reattachWidget(uint32_t)));
QObject::connect(video, SIGNAL(detach(uint32_t)),
this, SLOT(detachWidget(uint32_t)));
// signals for double click attach/detach
QObject::connect(video, SIGNAL(reattach(uint32_t)),
this, SLOT(reattachWidget(uint32_t)));
QObject::connect(video, SIGNAL(detach(uint32_t)),
this, SLOT(detachWidget(uint32_t)));

video->show();
video->show();
}
}
else
{
Expand Down
15 changes: 9 additions & 6 deletions src/ui/gui/videodrawhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ VideoDrawHelper::VideoDrawHelper(uint32_t sessionID, uint8_t borderSize):
roiQP_(22),
backgroundQP_(47),
brushSize_(2),
videoResolution_(QSize(0,0)),
showGrid_(false),
pixelBasedDrawing_(false),
micIcon_(QString("icons/mic_off.svg")),
Expand Down Expand Up @@ -72,10 +73,12 @@ void VideoDrawHelper::setDrawMicOff(bool state)


void VideoDrawHelper::enableOverlay(int roiQP, int backgroundQP,
int brushSize, bool showGrid, bool pixelBased)
int brushSize, bool showGrid, bool pixelBased,
QSize videoResolution)
{
roiMutex_.lock();

videoResolution_ = videoResolution;
drawOverlay_ = true;

roiQP_ = roiQP;
Expand Down Expand Up @@ -344,8 +347,8 @@ void VideoDrawHelper::addPointToOverlay(const QPointF& position, bool addPoint,
}
else
{
QSizeF viewMultiplier = getSizeMultipliers(previousSize_.width(),
previousSize_.height());
QSizeF viewMultiplier = getSizeMultipliers(videoResolution_.width(),
videoResolution_.height());
QPointF viewCTUSize = {CTU_SIZE*viewMultiplier.width(), CTU_SIZE*viewMultiplier.height()};
QPointF viewPosition = (position - imageRect_.topLeft());

Expand Down Expand Up @@ -427,13 +430,13 @@ void VideoDrawHelper::drawGrid()

if (showGrid_)
{
QSizeF multiplier = getSizeMultipliers(previousSize_.width(), previousSize_.height());
QSizeF multiplier = getSizeMultipliers(videoResolution_.width(), videoResolution_.height());

// first we generate the lines for drawing
QVector<QLine> lines;

// specify vertical lines
for (unsigned int i = 0; i < previousSize_.width(); ++i)
for (unsigned int i = 0; i < videoResolution_.width(); ++i)
{
if (i%64 == 0 || i%64 == 63)
{
Expand All @@ -447,7 +450,7 @@ void VideoDrawHelper::drawGrid()
}

// specify horizontal lines
for (unsigned int j = 0; j < previousSize_.height(); ++j)
for (unsigned int j = 0; j < videoResolution_.height(); ++j)
{
if (j%CTU_SIZE == 0 || j%CTU_SIZE == 63)
{
Expand Down
5 changes: 4 additions & 1 deletion src/ui/gui/videodrawhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ class VideoDrawHelper : public QObject

void initWidget(QWidget* widget);

void enableOverlay(int roiQP, int backgroundQP, int brushSize, bool showGrid, bool pixelBased);
void enableOverlay(int roiQP, int backgroundQP, int brushSize, bool showGrid, bool pixelBased,
QSize videoResolution);
void resetOverlay();
void updateROIMask();

Expand Down Expand Up @@ -127,6 +128,8 @@ class VideoDrawHelper : public QObject
int backgroundQP_;
int brushSize_;

QSize videoResolution_;

bool showGrid_;
bool pixelBasedDrawing_;

Expand Down
4 changes: 2 additions & 2 deletions src/ui/gui/videoglwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ void VideoGLWidget::drawMicOffIcon(bool status)


void VideoGLWidget::enableOverlay(int roiQP, int backgroundQP,
int brushSize, bool showGrid, bool pixelBased)
int brushSize, bool showGrid, bool pixelBased, QSize videoResolution)
{
helper_.enableOverlay(roiQP, backgroundQP, brushSize, showGrid, pixelBased);
helper_.enableOverlay(roiQP, backgroundQP, brushSize, showGrid, pixelBased, videoResolution);
}


Expand Down
4 changes: 2 additions & 2 deletions src/ui/gui/videoglwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class VideoGLWidget : public QOpenGLWidget, public VideoInterface

virtual void drawMicOffIcon(bool status);

virtual void enableOverlay(int roiQP, int backgroundQP, int brushSize,
bool showGrid, bool pixelBased);
virtual void enableOverlay(int roiQP, int backgroundQP, int brushSize,
bool showGrid, bool pixelBased, QSize videoResolution);
virtual void resetOverlay();

virtual VideoFormat supportedFormat()
Expand Down
2 changes: 1 addition & 1 deletion src/ui/gui/videointerface.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class VideoInterface
virtual void drawMicOffIcon(bool status) = 0;

virtual void enableOverlay(int goodQP, int badQP, int brushSize,
bool showGrid, bool pixelBased) = 0;
bool showGrid, bool pixelBased, QSize videoResolution) = 0;
virtual void resetOverlay() = 0;

virtual std::unique_ptr<int8_t[]> getRoiMask(int& width, int& height, int qp,
Expand Down
4 changes: 2 additions & 2 deletions src/ui/gui/videowidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ void VideoWidget::drawMicOffIcon(bool status)


void VideoWidget::enableOverlay(int roiQP, int backgroundQP,
int brushSize, bool showGrid, bool pixelBased)
int brushSize, bool showGrid, bool pixelBased, QSize videoResolution)
{
helper_.enableOverlay(roiQP, backgroundQP, brushSize, showGrid, pixelBased);
helper_.enableOverlay(roiQP, backgroundQP, brushSize, showGrid, pixelBased, videoResolution);
}


Expand Down
4 changes: 2 additions & 2 deletions src/ui/gui/videowidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class VideoWidget : public QWidget, public VideoInterface

virtual void drawMicOffIcon(bool status);

virtual void enableOverlay(int roiQP, int backgroundQP, int brushSize,
bool showGrid, bool pixelBased);
virtual void enableOverlay(int roiQP, int backgroundQP, int brushSize,
bool showGrid, bool pixelBased, QSize videoResolution);
virtual void resetOverlay();

virtual std::unique_ptr<int8_t[]> getRoiMask(int& width, int& height, int qp, bool scaleToInput);
Expand Down
4 changes: 2 additions & 2 deletions src/ui/gui/videoyuvwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ void VideoYUVWidget::drawMicOffIcon(bool status)
}

void VideoYUVWidget::enableOverlay(int roiQP, int backgroundQP, int brushSize,
bool showGrid, bool pixelBased)
bool showGrid, bool pixelBased, QSize videoResolution)
{
helper_.enableOverlay(roiQP, backgroundQP, brushSize, showGrid, pixelBased);
helper_.enableOverlay(roiQP, backgroundQP, brushSize, showGrid, pixelBased, videoResolution);
}


Expand Down
4 changes: 2 additions & 2 deletions src/ui/gui/videoyuvwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ class VideoYUVWidget : public QOpenGLWidget, public VideoInterface, protected QO

virtual void drawMicOffIcon(bool status);

virtual void enableOverlay(int roiQP, int backgroundQP, int brushSize,
bool showGrid, bool pixelBased);
virtual void enableOverlay(int roiQP, int backgroundQP, int brushSize,
bool showGrid, bool pixelBased, QSize videoResolution);
virtual void resetOverlay();

virtual std::unique_ptr<int8_t[]> getRoiMask(int& width, int& height, int qp, bool scaleToInput);
Expand Down
33 changes: 22 additions & 11 deletions src/ui/settings/automaticsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,16 @@ AutomaticSettings::AutomaticSettings(QWidget *parent):
this, &AutomaticSettings::updateConfig);

QObject::connect(ui_->ctu_based, &QCheckBox::stateChanged,
this, &AutomaticSettings::updateConfigAndReset);
this, &AutomaticSettings::updateConfigAndReset);

settings_.setValue(SettingsKey::manualROIStatus, "0");

ui_->roi_surface->enableOverlay(ui_->roi_qp->value(),
ui_->background_qp->value(),
ui_->brush_size->value(),
ui_->show_grid->isChecked(),
!ui_->ctu_based->isChecked());
!ui_->ctu_based->isChecked(),
getSettingsResolution());
}


Expand All @@ -56,27 +57,28 @@ AutomaticSettings::~AutomaticSettings()
delete ui_;
}


void AutomaticSettings::updateConfigAndReset(int i)
void AutomaticSettings::updateVideoConfig()
{
ui_->roi_surface->enableOverlay(ui_->roi_qp->value(),
ui_->background_qp->value(),
ui_->brush_size->value(),
ui_->show_grid->isChecked(),
!ui_->ctu_based->isChecked());
updateConfig(0);

// reset the whole ROI map because changing config benefits from it
ui_->roi_surface->resetOverlay();
}


void AutomaticSettings::updateConfigAndReset(int i)
{
updateVideoConfig();
}

void AutomaticSettings::updateConfig(int i)
{
ui_->roi_surface->enableOverlay(ui_->roi_qp->value(),
ui_->background_qp->value(),
ui_->brush_size->value(),
ui_->show_grid->isChecked(),
!ui_->ctu_based->isChecked());
!ui_->ctu_based->isChecked(),
getSettingsResolution());
}


Expand Down Expand Up @@ -123,7 +125,6 @@ void AutomaticSettings::reset()
}



void AutomaticSettings::tabChanged(int index)
{
// disable the last tab
Expand Down Expand Up @@ -182,3 +183,13 @@ VideoWidget* AutomaticSettings::getRoiSelfView()
{
return ui_->roi_surface;
}


QSize AutomaticSettings::getSettingsResolution()
{
QSize resolution;
resolution.setWidth(settings_.value(SettingsKey::videoResultionWidth).toInt());
resolution.setHeight(settings_.value(SettingsKey::videoResultionHeight).toInt());

return resolution;
}
2 changes: 2 additions & 0 deletions src/ui/settings/automaticsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public slots:

void reset();

void updateVideoConfig();
void updateConfigAndReset(int i);
void updateConfig(int i);

Expand All @@ -43,6 +44,7 @@ public slots:
void closeEvent(QCloseEvent *event);

private:
QSize getSettingsResolution();

void activateROI();
void disableROI();
Expand Down
3 changes: 3 additions & 0 deletions src/ui/settings/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ void Settings::init()
//QObject::connect(basicUI_->close, &QPushButton::clicked, this, &Settings::on_cancel_clicked);

// video settings
QObject::connect(&videoSettings_, &VideoSettings::updateVideoSettings,
&autoSettings_, &AutomaticSettings::updateVideoConfig);
QObject::connect(&videoSettings_, &VideoSettings::updateVideoSettings,
this, &Settings::updateVideoSettings);
QObject::connect(&videoSettings_, &VideoSettings::hidden, this, &Settings::show);
Expand Down Expand Up @@ -290,6 +292,7 @@ void Settings::on_save_clicked()
saveSettings();
setScreenShareState(settingEnabled(SettingsKey::screenShareStatus));

autoSettings_.updateVideoConfig();
emit updateCallSettings();
emit updateVideoSettings();
emit updateAudioSettings();
Expand Down

0 comments on commit 6ad44e7

Please sign in to comment.