mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-04-21 21:52:03 +02:00
video: add black background in previewrenderer and flow optimization
Change-Id: I979dcc7d7a65029a1ee361579e51575ea813f0e7
This commit is contained in:
parent
d4b5ec4201
commit
3ade8ee12f
6 changed files with 65 additions and 15 deletions
|
@ -66,13 +66,19 @@ AvAdapter::populateVideoDeviceContextMenuItem()
|
||||||
void
|
void
|
||||||
AvAdapter::onVideoContextMenuDeviceItemClicked(const QString& deviceName)
|
AvAdapter::onVideoContextMenuDeviceItemClicked(const QString& deviceName)
|
||||||
{
|
{
|
||||||
|
auto* convModel = LRCInstance::getCurrentConversationModel();
|
||||||
|
const auto conversation = convModel->getConversationForUID(LRCInstance::getCurrentConvUid());
|
||||||
|
auto call = LRCInstance::getCallInfoForConversation(conversation);
|
||||||
|
if (!call)
|
||||||
|
return;
|
||||||
|
|
||||||
auto deviceId = LRCInstance::avModel().getDeviceIdFromName(deviceName);
|
auto deviceId = LRCInstance::avModel().getDeviceIdFromName(deviceName);
|
||||||
if (deviceId.isEmpty()) {
|
if (deviceId.isEmpty()) {
|
||||||
qWarning() << "Couldn't find device: " << deviceName;
|
qWarning() << "Couldn't find device: " << deviceName;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LRCInstance::avModel().switchInputTo(deviceId);
|
|
||||||
LRCInstance::avModel().setCurrentVideoCaptureDevice(deviceId);
|
LRCInstance::avModel().setCurrentVideoCaptureDevice(deviceId);
|
||||||
|
LRCInstance::avModel().switchInputTo(deviceId, call->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -179,8 +185,9 @@ AvAdapter::slotDeviceEvent()
|
||||||
avModel.switchInputTo({}, callId);
|
avModel.switchInputTo({}, callId);
|
||||||
avModel.stopPreview();
|
avModel.stopPreview();
|
||||||
} else if (deviceEvent == DeviceEvent::RemovedCurrent && currentDeviceListSize > 0) {
|
} else if (deviceEvent == DeviceEvent::RemovedCurrent && currentDeviceListSize > 0) {
|
||||||
avModel.switchInputTo(defaultDevice, callId);
|
avModel.setDefaultDevice(defaultDevice);
|
||||||
avModel.setCurrentVideoCaptureDevice(defaultDevice);
|
avModel.setCurrentVideoCaptureDevice(defaultDevice);
|
||||||
|
avModel.switchInputTo(defaultDevice, callId);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -190,14 +197,18 @@ AvAdapter::slotDeviceEvent()
|
||||||
[cb] { QtConcurrent::run([cb]() { cb(); }); });
|
[cb] { QtConcurrent::run([cb]() { cb(); }); });
|
||||||
} else {
|
} else {
|
||||||
if (deviceEvent == DeviceEvent::Added && currentDeviceListSize == 1) {
|
if (deviceEvent == DeviceEvent::Added && currentDeviceListSize == 1) {
|
||||||
avModel.switchInputTo(defaultDevice, callId);
|
avModel.setDefaultDevice(defaultDevice);
|
||||||
avModel.setCurrentVideoCaptureDevice(defaultDevice);
|
avModel.setCurrentVideoCaptureDevice(defaultDevice);
|
||||||
|
if (callId.isEmpty())
|
||||||
|
LRCInstance::renderer()->startPreviewing();
|
||||||
|
else
|
||||||
|
avModel.switchInputTo(defaultDevice, callId);
|
||||||
} else {
|
} else {
|
||||||
cb();
|
cb();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
emit videoDeviceListChanged();
|
emit videoDeviceListChanged(currentDeviceListSize == 0);
|
||||||
|
|
||||||
deviceListSize_ = currentDeviceListSize;
|
deviceListSize_ = currentDeviceListSize;
|
||||||
}
|
}
|
|
@ -37,7 +37,7 @@ signals:
|
||||||
/*
|
/*
|
||||||
* Emitted when the size of the video capture device list changes.
|
* Emitted when the size of the video capture device list changes.
|
||||||
*/
|
*/
|
||||||
void videoDeviceListChanged();
|
void videoDeviceListChanged(bool listIsEmpty);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void safeInit() override {};
|
void safeInit() override {};
|
||||||
|
|
|
@ -244,6 +244,14 @@ Rectangle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Connections {
|
||||||
|
target: AvAdapter
|
||||||
|
|
||||||
|
function onVideoDeviceListChanged(listIsEmpty) {
|
||||||
|
previewRenderer.visible = !listIsEmpty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
width: Math.max(videoCallPageMainRect.width / 5, JamiTheme.minimumPreviewWidth)
|
width: Math.max(videoCallPageMainRect.width / 5, JamiTheme.minimumPreviewWidth)
|
||||||
x: videoCallPageMainRect.width - previewRenderer.width - previewMargin
|
x: videoCallPageMainRect.width - previewRenderer.width - previewMargin
|
||||||
y: videoCallPageMainRect.height - previewRenderer.height - previewMargin - 56 // Avoid overlay
|
y: videoCallPageMainRect.height - previewRenderer.height - previewMargin - 56 // Avoid overlay
|
||||||
|
|
|
@ -32,11 +32,16 @@ PreviewRenderer::PreviewRenderer(QQuickItem* parent)
|
||||||
previewFrameUpdatedConnection_ = connect(LRCInstance::renderer(),
|
previewFrameUpdatedConnection_ = connect(LRCInstance::renderer(),
|
||||||
&RenderManager::previewFrameUpdated,
|
&RenderManager::previewFrameUpdated,
|
||||||
[this]() { update(QRect(0, 0, width(), height())); });
|
[this]() { update(QRect(0, 0, width(), height())); });
|
||||||
|
|
||||||
|
previewRenderingStopped_ = connect(LRCInstance::renderer(),
|
||||||
|
&RenderManager::previewRenderingStopped,
|
||||||
|
[this]() { update(QRect(0, 0, width(), height())); });
|
||||||
}
|
}
|
||||||
|
|
||||||
PreviewRenderer::~PreviewRenderer()
|
PreviewRenderer::~PreviewRenderer()
|
||||||
{
|
{
|
||||||
disconnect(previewFrameUpdatedConnection_);
|
disconnect(previewFrameUpdatedConnection_);
|
||||||
|
disconnect(previewRenderingStopped_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -63,11 +68,23 @@ PreviewRenderer::paint(QPainter* painter)
|
||||||
scaledPreview = previewImage->scaled(size().toSize(), Qt::KeepAspectRatio);
|
scaledPreview = previewImage->scaled(size().toSize(), Qt::KeepAspectRatio);
|
||||||
painter->drawImage(QRect(0, 0, scaledPreview.width(), scaledPreview.height()),
|
painter->drawImage(QRect(0, 0, scaledPreview.width(), scaledPreview.height()),
|
||||||
scaledPreview);
|
scaledPreview);
|
||||||
|
} else {
|
||||||
|
paintBackground(painter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PreviewRenderer::paintBackground(QPainter* painter)
|
||||||
|
{
|
||||||
|
QBrush brush(Qt::black);
|
||||||
|
QPainterPath path;
|
||||||
|
path.addRect(QRect(0, 0, width(), height()));
|
||||||
|
painter->fillPath(path, brush);
|
||||||
|
}
|
||||||
|
|
||||||
VideoCallPreviewRenderer::VideoCallPreviewRenderer(QQuickItem* parent)
|
VideoCallPreviewRenderer::VideoCallPreviewRenderer(QQuickItem* parent)
|
||||||
: PreviewRenderer(parent) {
|
: PreviewRenderer(parent)
|
||||||
|
{
|
||||||
setProperty("previewImageScalingFactor", 1.0);
|
setProperty("previewImageScalingFactor", 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -79,7 +96,7 @@ VideoCallPreviewRenderer::paint(QPainter* painter)
|
||||||
auto previewImage = LRCInstance::renderer()->getPreviewFrame();
|
auto previewImage = LRCInstance::renderer()->getPreviewFrame();
|
||||||
if (previewImage) {
|
if (previewImage) {
|
||||||
auto scalingFactor = static_cast<qreal>(previewImage->height())
|
auto scalingFactor = static_cast<qreal>(previewImage->height())
|
||||||
/ static_cast<qreal>(previewImage->width());
|
/ static_cast<qreal>(previewImage->width());
|
||||||
setProperty("previewImageScalingFactor", scalingFactor);
|
setProperty("previewImageScalingFactor", scalingFactor);
|
||||||
QImage scaledPreview;
|
QImage scaledPreview;
|
||||||
scaledPreview = previewImage->scaled(size().toSize(), Qt::KeepAspectRatio);
|
scaledPreview = previewImage->scaled(size().toSize(), Qt::KeepAspectRatio);
|
||||||
|
|
|
@ -34,16 +34,18 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void paint(QPainter* painter) override;
|
void paint(QPainter* painter) override;
|
||||||
|
void paintBackground(QPainter* painter);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMetaObject::Connection previewFrameUpdatedConnection_;
|
QMetaObject::Connection previewFrameUpdatedConnection_;
|
||||||
|
QMetaObject::Connection previewRenderingStopped_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class VideoCallPreviewRenderer : public PreviewRenderer
|
class VideoCallPreviewRenderer : public PreviewRenderer
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(qreal previewImageScalingFactor MEMBER previewImageScalingFactor_
|
Q_PROPERTY(qreal previewImageScalingFactor MEMBER previewImageScalingFactor_ NOTIFY
|
||||||
NOTIFY previewImageScalingFactorChanged)
|
previewImageScalingFactorChanged)
|
||||||
public:
|
public:
|
||||||
explicit VideoCallPreviewRenderer(QQuickItem* parent = 0);
|
explicit VideoCallPreviewRenderer(QQuickItem* parent = 0);
|
||||||
virtual ~VideoCallPreviewRenderer();
|
virtual ~VideoCallPreviewRenderer();
|
||||||
|
|
|
@ -49,10 +49,18 @@ ColumnLayout {
|
||||||
function populateVideoSettings() {
|
function populateVideoSettings() {
|
||||||
deviceComboBoxSetting.comboModel.reset()
|
deviceComboBoxSetting.comboModel.reset()
|
||||||
|
|
||||||
var count = deviceComboBoxSetting.comboModel.deviceCount() > 0
|
var count = deviceComboBoxSetting.comboModel.deviceCount()
|
||||||
deviceComboBoxSetting.setEnabled(count)
|
var deviceListIsEmpty = count === 0
|
||||||
resolutionComboBoxSetting.setEnabled(count)
|
|
||||||
fpsComboBoxSetting.setEnabled(count)
|
previewWidget.visible = count > 0
|
||||||
|
deviceComboBoxSetting.setEnabled(count > 0)
|
||||||
|
resolutionComboBoxSetting.setEnabled(count > 0)
|
||||||
|
fpsComboBoxSetting.setEnabled(count > 0)
|
||||||
|
|
||||||
|
if (deviceListIsEmpty) {
|
||||||
|
resolutionComboBoxSetting.comboModel.reset()
|
||||||
|
fpsComboBoxSetting.comboModel.reset()
|
||||||
|
}
|
||||||
|
|
||||||
deviceComboBoxSetting.setCurrentIndex(
|
deviceComboBoxSetting.setCurrentIndex(
|
||||||
deviceComboBoxSetting.comboModel.getCurrentSettingIndex(), true)
|
deviceComboBoxSetting.comboModel.getCurrentSettingIndex(), true)
|
||||||
|
@ -71,8 +79,11 @@ ColumnLayout {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
AVModel.setCurrentVideoCaptureDevice(deviceId)
|
if (AVModel.getCurrentVideoCaptureDevice() !== deviceId) {
|
||||||
AVModel.setDefaultDevice(deviceId)
|
AVModel.setCurrentVideoCaptureDevice(deviceId)
|
||||||
|
AVModel.setDefaultDevice(deviceId)
|
||||||
|
}
|
||||||
|
|
||||||
setFormatListForCurrentDevice()
|
setFormatListForCurrentDevice()
|
||||||
startPreviewing()
|
startPreviewing()
|
||||||
} catch(err){ console.warn(err.message) }
|
} catch(err){ console.warn(err.message) }
|
||||||
|
@ -99,6 +110,7 @@ ColumnLayout {
|
||||||
var resolution
|
var resolution
|
||||||
var rate
|
var rate
|
||||||
if(isResolutionIndex) {
|
if(isResolutionIndex) {
|
||||||
|
fpsComboBoxSetting.comboModel.reset()
|
||||||
resolution = resolutionComboBoxSetting.comboModel.data(
|
resolution = resolutionComboBoxSetting.comboModel.data(
|
||||||
resolutionComboBoxSetting.comboModel.index(index, 0),
|
resolutionComboBoxSetting.comboModel.index(index, 0),
|
||||||
VideoFormatResolutionModel.Resolution)
|
VideoFormatResolutionModel.Resolution)
|
||||||
|
|
Loading…
Add table
Reference in a new issue