Browse Source

Save memory with lazy loading

Load the setting's cameria preview opengl context lazily and destroy it when done. Only preallocte Core's video buffer if we have any calls active, free up when all calls are done
pull/1602/head
tux3 10 years ago
parent
commit
67e09de085
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
  1. 9
      src/core/core.cpp
  2. 2
      src/core/core.h
  3. 10
      src/core/coreav.cpp
  4. 4
      src/core/coredefines.h
  5. 37
      src/widget/form/settings/avform.cpp
  6. 5
      src/widget/form/settings/avform.h
  7. 49
      src/widget/form/settings/avsettings.ui

9
src/core/core.cpp

@ -61,7 +61,7 @@ Core::Core(Camera* cam, QThread *CoreThread, QString loadPath) :
Audio::getInstance(); Audio::getInstance();
videobuf = new uint8_t[videobufsize]; videobuf = nullptr;
for (int i = 0; i < ptCounter; i++) for (int i = 0; i < ptCounter; i++)
pwsaltedkeys[i] = nullptr; pwsaltedkeys[i] = nullptr;
@ -118,11 +118,8 @@ Core::~Core()
deadifyTox(); deadifyTox();
if (videobuf) delete[] videobuf;
{ videobuf=nullptr;
delete[] videobuf;
videobuf=nullptr;
}
Audio::closeInput(); Audio::closeInput();
Audio::closeOutput(); Audio::closeOutput();

2
src/core/core.h

@ -79,7 +79,7 @@ public:
VideoSource* getVideoSourceFromCall(int callNumber); ///< Get a call's video source 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 isPasswordSet(PasswordType passtype);
bool isReady(); ///< Most of the API shouldn't be used until Core is ready, call start() first bool isReady(); ///< Most of the API shouldn't be used until Core is ready, call start() first

10
src/core/coreav.cpp

@ -44,6 +44,10 @@ bool Core::anyActiveCalls()
void Core::prepareCall(uint32_t friendId, int32_t callId, ToxAv* toxav, bool videoEnabled) void Core::prepareCall(uint32_t friendId, int32_t callId, ToxAv* toxav, bool videoEnabled)
{ {
qDebug() << QString("Core: preparing call %1").arg(callId); qDebug() << QString("Core: preparing call %1").arg(callId);
if (!videobuf)
videobuf = new uint8_t[videobufsize];
calls[callId].callId = callId; calls[callId].callId = callId;
calls[callId].friendId = friendId; calls[callId].friendId = friendId;
calls[callId].muteMic = false; calls[callId].muteMic = false;
@ -228,6 +232,12 @@ void Core::cleanupCall(int32_t callId)
Audio::unsuscribeInput(); Audio::unsuscribeInput();
toxav_kill_transmission(Core::getInstance()->toxav, callId); 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) void Core::playCallAudio(void* toxav, int32_t callId, const int16_t *data, uint16_t samples, void *user_data)

4
src/core/coredefines.h

@ -7,7 +7,7 @@
#define TOXAV_RINGING_TIME 45 #define TOXAV_RINGING_TIME 45
// TODO: Put that in the settings // TODO: Put that in the settings
#define TOXAV_MAX_VIDEO_WIDTH 1600 #define TOXAV_MAX_VIDEO_WIDTH 1280
#define TOXAV_MAX_VIDEO_HEIGHT 1200 #define TOXAV_MAX_VIDEO_HEIGHT 720
#endif // COREDEFINES_H #endif // COREDEFINES_H

37
src/widget/form/settings/avform.cpp

@ -32,7 +32,8 @@
#endif #endif
AVForm::AVForm() : 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 = new Ui::AVSettings;
bodyUI->setupUi(this); bodyUI->setupUi(this);
@ -70,7 +71,8 @@ void AVForm::present()
getAudioOutDevices(); getAudioOutDevices();
getAudioInDevices(); getAudioInDevices();
bodyUI->CamVideoSurface->setSource(Camera::getInstance()); createVideoSurface();
CamVideoSurface->setSource(Camera::getInstance());
Camera::getInstance()->probeProp(Camera::SATURATION); Camera::getInstance()->probeProp(Camera::SATURATION);
Camera::getInstance()->probeProp(Camera::CONTRAST); Camera::getInstance()->probeProp(Camera::CONTRAST);
@ -157,12 +159,17 @@ void AVForm::onResProbingFinished(QList<QSize> res)
void AVForm::hideEvent(QHideEvent *) void AVForm::hideEvent(QHideEvent *)
{ {
bodyUI->CamVideoSurface->setSource(nullptr); if (CamVideoSurface)
{
CamVideoSurface->setSource(nullptr);
killVideoSurface();
}
} }
void AVForm::showEvent(QShowEvent *) void AVForm::showEvent(QShowEvent *)
{ {
bodyUI->CamVideoSurface->setSource(Camera::getInstance()); createVideoSurface();
CamVideoSurface->setSource(Camera::getInstance());
} }
void AVForm::getAudioInDevices() void AVForm::getAudioInDevices()
@ -285,3 +292,25 @@ bool AVForm::eventFilter(QObject *o, QEvent *e)
} }
return QWidget::eventFilter(o, 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;
}

5
src/widget/form/settings/avform.h

@ -42,6 +42,9 @@ private:
void getAudioInDevices(); void getAudioInDevices();
void getAudioOutDevices(); void getAudioOutDevices();
void createVideoSurface();
void killVideoSurface();
private slots: private slots:
void on_ContrastSlider_sliderMoved(int position); void on_ContrastSlider_sliderMoved(int position);
void on_SaturationSlider_sliderMoved(int position); void on_SaturationSlider_sliderMoved(int position);
@ -72,7 +75,7 @@ protected:
private: private:
Ui::AVSettings *bodyUI; Ui::AVSettings *bodyUI;
VideoSurface* camView; VideoSurface* CamVideoSurface;
}; };
#endif #endif

49
src/widget/form/settings/avsettings.ui

@ -30,8 +30,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>808</width> <width>824</width>
<height>618</height> <height>489</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout_5"> <layout class="QVBoxLayout" name="verticalLayout_5">
@ -57,23 +57,23 @@
</item> </item>
<item row="2" column="1"> <item row="2" column="1">
<widget class="QSlider" name="playbackSlider"> <widget class="QSlider" name="playbackSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="toolTip"> <property name="toolTip">
<string>Use slider to set volume of your speakers.</string> <string>Use slider to set volume of your speakers.</string>
</property> </property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget> </widget>
</item> </item>
<item row="7" column="1"> <item row="7" column="1">
<widget class="QSlider" name="microphoneSlider"> <widget class="QSlider" name="microphoneSlider">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="toolTip"> <property name="toolTip">
<string>Use slider to set volume of your microphone. <string>Use slider to set volume of your microphone.
WARNING: slider is not supposed to work yet.</string> WARNING: slider is not supposed to work yet.</string>
</property> </property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item row="1" column="0">
@ -105,12 +105,12 @@ WARNING: slider is not supposed to work yet.</string>
</item> </item>
<item row="8" column="0"> <item row="8" column="0">
<widget class="QCheckBox" name="filterAudio"> <widget class="QCheckBox" name="filterAudio">
<property name="text">
<string>Filter audio</string>
</property>
<property name="toolTip"> <property name="toolTip">
<string>Filter sound from your microphone, so that people hearing you would get better sound.</string> <string>Filter sound from your microphone, so that people hearing you would get better sound.</string>
</property> </property>
<property name="text">
<string>Filter audio</string>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -129,9 +129,6 @@ WARNING: slider is not supposed to work yet.</string>
</property> </property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="resolutionLabel"> <widget class="QLabel" name="resolutionLabel">
<property name="text">
<string>Resolution</string>
</property>
<property name="toolTip"> <property name="toolTip">
<string>Set resolution of your camera. <string>Set resolution of your camera.
The higher values, the better video quality your friends may get. 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, Sometimes your connection may not be good enough to handle higher video quality,
which may lead to problems with video calls.</string> which may lead to problems with video calls.</string>
</property> </property>
<property name="text">
<string>Resolution</string>
</property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
@ -230,18 +230,7 @@ which may lead to problems with video calls.</string>
<property name="frameShadow"> <property name="frameShadow">
<enum>QFrame::Raised</enum> <enum>QFrame::Raised</enum>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout"/>
<item row="0" column="0">
<widget class="VideoSurface" name="CamVideoSurface" native="true">
<property name="minimumSize">
<size>
<width>160</width>
<height>120</height>
</size>
</property>
</widget>
</item>
</layout>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -253,14 +242,6 @@ which may lead to problems with video calls.</string>
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>VideoSurface</class>
<extends>QWidget</extends>
<header>src/widget/videosurface.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

Loading…
Cancel
Save