diff --git a/src/core/core.cpp b/src/core/core.cpp index 2dd743987..abf81b489 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -61,7 +61,7 @@ Core::Core(Camera* cam, QThread *CoreThread, QString loadPath) : Audio::getInstance(); - videobuf = new uint8_t[videobufsize]; + videobuf = nullptr; for (int i = 0; i < ptCounter; i++) pwsaltedkeys[i] = nullptr; @@ -118,11 +118,8 @@ Core::~Core() deadifyTox(); - if (videobuf) - { - delete[] videobuf; - videobuf=nullptr; - } + delete[] videobuf; + videobuf=nullptr; Audio::closeInput(); Audio::closeOutput(); diff --git a/src/core/core.h b/src/core/core.h index 4d694ead5..c749d9ef2 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -79,7 +79,7 @@ public: VideoSource* getVideoSourceFromCall(int callNumber); ///< Get a call's video source - bool anyActiveCalls(); ///< true is any calls are currently active (note: a call about to start is not yet active) + static bool anyActiveCalls(); ///< true is any calls are currently active (note: a call about to start is not yet active) bool isPasswordSet(PasswordType passtype); bool isReady(); ///< Most of the API shouldn't be used until Core is ready, call start() first diff --git a/src/core/coreav.cpp b/src/core/coreav.cpp index cbdc71184..1306ef1ec 100644 --- a/src/core/coreav.cpp +++ b/src/core/coreav.cpp @@ -44,6 +44,10 @@ bool Core::anyActiveCalls() void Core::prepareCall(uint32_t friendId, int32_t callId, ToxAv* toxav, bool videoEnabled) { qDebug() << QString("Core: preparing call %1").arg(callId); + + if (!videobuf) + videobuf = new uint8_t[videobufsize]; + calls[callId].callId = callId; calls[callId].friendId = friendId; calls[callId].muteMic = false; @@ -228,6 +232,12 @@ void Core::cleanupCall(int32_t callId) Audio::unsuscribeInput(); toxav_kill_transmission(Core::getInstance()->toxav, callId); + + if (!anyActiveCalls()) + { + delete[] videobuf; + videobuf = nullptr; + } } void Core::playCallAudio(void* toxav, int32_t callId, const int16_t *data, uint16_t samples, void *user_data) diff --git a/src/core/coredefines.h b/src/core/coredefines.h index 157e87785..b2dcc3ee7 100644 --- a/src/core/coredefines.h +++ b/src/core/coredefines.h @@ -7,7 +7,7 @@ #define TOXAV_RINGING_TIME 45 // TODO: Put that in the settings -#define TOXAV_MAX_VIDEO_WIDTH 1600 -#define TOXAV_MAX_VIDEO_HEIGHT 1200 +#define TOXAV_MAX_VIDEO_WIDTH 1280 +#define TOXAV_MAX_VIDEO_HEIGHT 720 #endif // COREDEFINES_H diff --git a/src/widget/form/settings/avform.cpp b/src/widget/form/settings/avform.cpp index fe7742fe9..ac4630c81 100644 --- a/src/widget/form/settings/avform.cpp +++ b/src/widget/form/settings/avform.cpp @@ -32,7 +32,8 @@ #endif AVForm::AVForm() : - GenericForm(tr("Audio/Video"), QPixmap(":/img/settings/av.png")) + GenericForm(tr("Audio/Video"), QPixmap(":/img/settings/av.png")), + CamVideoSurface{nullptr} { bodyUI = new Ui::AVSettings; bodyUI->setupUi(this); @@ -70,7 +71,8 @@ void AVForm::present() getAudioOutDevices(); getAudioInDevices(); - bodyUI->CamVideoSurface->setSource(Camera::getInstance()); + createVideoSurface(); + CamVideoSurface->setSource(Camera::getInstance()); Camera::getInstance()->probeProp(Camera::SATURATION); Camera::getInstance()->probeProp(Camera::CONTRAST); @@ -157,12 +159,17 @@ void AVForm::onResProbingFinished(QList res) void AVForm::hideEvent(QHideEvent *) { - bodyUI->CamVideoSurface->setSource(nullptr); + if (CamVideoSurface) + { + CamVideoSurface->setSource(nullptr); + killVideoSurface(); + } } void AVForm::showEvent(QShowEvent *) { - bodyUI->CamVideoSurface->setSource(Camera::getInstance()); + createVideoSurface(); + CamVideoSurface->setSource(Camera::getInstance()); } void AVForm::getAudioInDevices() @@ -285,3 +292,25 @@ bool AVForm::eventFilter(QObject *o, QEvent *e) } return QWidget::eventFilter(o, e); } + +void AVForm::createVideoSurface() +{ + if (CamVideoSurface) + return; + CamVideoSurface = new VideoSurface(bodyUI->CamFrame); + CamVideoSurface->setObjectName(QStringLiteral("CamVideoSurface")); + CamVideoSurface->setMinimumSize(QSize(160, 120)); + bodyUI->gridLayout->addWidget(CamVideoSurface, 0, 0, 1, 1); +} + +void AVForm::killVideoSurface() +{ + if (!CamVideoSurface) + return; + QLayoutItem *child; + while ((child = bodyUI->gridLayout->takeAt(0)) != 0) { + delete child; + } + delete CamVideoSurface; + CamVideoSurface = nullptr; +} diff --git a/src/widget/form/settings/avform.h b/src/widget/form/settings/avform.h index a61831d0b..ff656669e 100644 --- a/src/widget/form/settings/avform.h +++ b/src/widget/form/settings/avform.h @@ -42,6 +42,9 @@ private: void getAudioInDevices(); void getAudioOutDevices(); + void createVideoSurface(); + void killVideoSurface(); + private slots: void on_ContrastSlider_sliderMoved(int position); void on_SaturationSlider_sliderMoved(int position); @@ -72,7 +75,7 @@ protected: private: Ui::AVSettings *bodyUI; - VideoSurface* camView; + VideoSurface* CamVideoSurface; }; #endif diff --git a/src/widget/form/settings/avsettings.ui b/src/widget/form/settings/avsettings.ui index 81cb23026..6a2cb40b3 100644 --- a/src/widget/form/settings/avsettings.ui +++ b/src/widget/form/settings/avsettings.ui @@ -30,8 +30,8 @@ 0 0 - 808 - 618 + 824 + 489 @@ -57,23 +57,23 @@ - - Qt::Horizontal - Use slider to set volume of your speakers. + + Qt::Horizontal + - - Qt::Horizontal - Use slider to set volume of your microphone. WARNING: slider is not supposed to work yet. + + Qt::Horizontal + @@ -105,12 +105,12 @@ WARNING: slider is not supposed to work yet. - - Filter audio - Filter sound from your microphone, so that people hearing you would get better sound. + + Filter audio + @@ -129,9 +129,6 @@ WARNING: slider is not supposed to work yet. - - Resolution - Set resolution of your camera. The higher values, the better video quality your friends may get. @@ -139,6 +136,9 @@ Note though that with better video quality there is needed better internet conne Sometimes your connection may not be good enough to handle higher video quality, which may lead to problems with video calls. + + Resolution + @@ -230,18 +230,7 @@ which may lead to problems with video calls. QFrame::Raised - - - - - - 160 - 120 - - - - - + @@ -253,14 +242,6 @@ which may lead to problems with video calls. - - - VideoSurface - QWidget -
src/widget/videosurface.h
- 1 -
-