1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

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
This commit is contained in:
tux3 2015-05-10 00:03:05 +02:00
parent 1f926b3e6c
commit 67e09de085
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
7 changed files with 68 additions and 48 deletions

View File

@ -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();

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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<QSize> 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;
}

View File

@ -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

View File

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