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

Add unicode font, fix mem corruption

Or at least, make the memory corruption so hard to reproduce that I wasn't able to run into it even after trying really hard.
This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-06-30 02:24:27 +02:00
parent a63da505ec
commit 2efe9ac269
6 changed files with 50 additions and 36 deletions

View File

@ -20,7 +20,7 @@
CData::CData(const QString &data, uint16_t byteSize)
{
cData = new uint8_t[byteSize];
cData = new uint8_t[byteSize+1];
cDataSize = fromString(data, cData);
}

View File

@ -1116,8 +1116,13 @@ void Core::prepareCall(int friendId, int callId, ToxAv* toxav, bool videoEnabled
// Go
/// BUG: TODO: Memory corryption and crashes atexit when playCallAudio is threaded
if (calls[callId].audioOutput != nullptr)
calls[callId].playFuture = QtConcurrent::run(playCallAudio, callId, toxav);
//if (calls[callId].audioOutput != nullptr)
// calls[callId].playFuture = QtConcurrent::run(playCallAudio, callId, toxav);
calls[callId].playAudioTimer.setInterval(5);
calls[callId].playAudioTimer.setSingleShot(true);
connect(&calls[callId].playAudioTimer, &QTimer::timeout, [=](){playCallAudio(callId,toxav);});
calls[callId].playAudioTimer.start();
if (calls[callId].audioInput != nullptr)
calls[callId].recordFuture = QtConcurrent::run(sendCallAudio, callId, toxav);
calls[callId].active = true;
@ -1138,43 +1143,43 @@ void Core::cleanupCall(int callId)
void Core::playCallAudio(int callId, ToxAv* toxav)
{
while (calls[callId].active)
if (!calls[callId].active)
return;
int framesize = (calls[callId].codecSettings.audio_frame_duration * calls[callId].codecSettings.audio_sample_rate) / 1000;
uint8_t buf[framesize*2];
int len = toxav_recv_audio(toxav, callId, framesize, (int16_t*)buf);
if (len < 0)
{
int framesize = (calls[callId].codecSettings.audio_frame_duration * calls[callId].codecSettings.audio_sample_rate) / 1000;
uint8_t buf[framesize*2];
int len = toxav_recv_audio(toxav, callId, framesize, (int16_t*)buf);
if (len < 0)
if (len == -3) // Not in call !
{
if (len == -3) // Not in call !
{
qWarning("Core: Trying to play audio in an inactive call!");
return;
}
qDebug() << QString("Core::playCallAudio: Error receiving audio: %1").arg(len);
QThread::msleep(5);
continue;
qWarning("Core: Trying to play audio in an inactive call!");
return;
}
if (len == 0)
{
QThread::msleep(5); /// BUG: Another thread crashed with corruption while we slept here
continue;
}
//qDebug() << QString("Core: Received %1 bytes, %2 audio bytes free, %3 core buffer size")
// .arg(len*2).arg(calls[callId].audioOutput->bytesFree()).arg(calls[callId].audioBuffer.bufferSize());
calls[callId].audioBuffer.writeData((char*)buf, len*2);
int state = calls[callId].audioOutput->state();
if (state != QAudio::ActiveState)
{
qDebug() << QString("Core: Audio state is %1").arg(state);
if (state == 3)
calls[callId].audioOutput->start(&calls[callId].audioBuffer);
}
int error = calls[callId].audioOutput->error();
if (error != QAudio::NoError)
qWarning() << QString("Core::playCallAudio: Error: %1").arg(error);
QThread::msleep(5);
qDebug() << QString("Core::playCallAudio: Error receiving audio: %1").arg(len);
calls[callId].playAudioTimer.start();
return;
}
if (len == 0)
{
calls[callId].playAudioTimer.start();
return;
}
//qDebug() << QString("Core: Received %1 bytes, %2 audio bytes free, %3 core buffer size")
// .arg(len*2).arg(calls[callId].audioOutput->bytesFree()).arg(calls[callId].audioBuffer.bufferSize());
calls[callId].audioBuffer.writeData((char*)buf, len*2);
int state = calls[callId].audioOutput->state();
if (state != QAudio::ActiveState)
{
qDebug() << QString("Core: Audio state is %1").arg(state);
if (state == 3 && calls[callId].audioBuffer.bytesAvailable() >= framesize*2)
calls[callId].audioOutput->start(&calls[callId].audioBuffer);
}
int error = calls[callId].audioOutput->error();
if (error != QAudio::NoError)
qWarning() << QString("Core::playCallAudio: Error: %1").arg(error);
calls[callId].playAudioTimer.start();
}
void Core::sendCallAudio(int callId, ToxAv* toxav)

1
core.h
View File

@ -93,6 +93,7 @@ public:
QAudioInput* audioInput;
QIODevice* audioInputDevice;
ToxAvCodecSettings codecSettings;
QTimer playAudioTimer, sendAudioTimer;
int callId;
int friendId;
bool videoEnabled;

View File

@ -1,11 +1,16 @@
#include "widget/widget.h"
#include <QApplication>
#include <QFontDatabase>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.setApplicationName("Toxgui");
a.setOrganizationName("Tox");
// install Unicode 6.1 supporting font
QFontDatabase::addApplicationFont("://DejaVuSans.ttf");
Widget* w = Widget::getInstance();
w->show();

View File

@ -2,4 +2,7 @@
<qresource prefix="/conf">
<file alias="settings.ini">res/settings.ini</file>
</qresource>
<qresource prefix="/font">
<file alias="DejaVuSans.ttf">res/DejaVuSans.ttf</file>
</qresource>
</RCC>

BIN
res/DejaVuSans.ttf Normal file

Binary file not shown.