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

Fix some A/V bugs

This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-06-30 23:48:12 +02:00
parent 58cfae38ab
commit 73e3afe932
2 changed files with 13 additions and 10 deletions

View File

@ -37,7 +37,6 @@ ToxCall Core::calls[TOXAV_MAX_CALLS];
Core::Core(Camera* cam) : Core::Core(Camera* cam) :
tox(nullptr), camera(cam) tox(nullptr), camera(cam)
{ {
qDebug() << "A NEW CORE HAS STARTED !";
toxTimer = new QTimer(this); toxTimer = new QTimer(this);
toxTimer->setSingleShot(true); toxTimer->setSingleShot(true);
saveTimer = new QTimer(this); saveTimer = new QTimer(this);
@ -1185,22 +1184,26 @@ void Core::cleanupCall(int callId)
{ {
qDebug() << QString("Core: cleaning up call %1").arg(callId); qDebug() << QString("Core: cleaning up call %1").arg(callId);
calls[callId].active = false; calls[callId].active = false;
disconnect(&calls[callId].playAudioTimer,0,0,0);
disconnect(&calls[callId].sendAudioTimer,0,0,0);
disconnect(&calls[callId].playVideoTimer,0,0,0);
disconnect(&calls[callId].sendVideoTimer,0,0,0);
calls[callId].playAudioTimer.stop();
calls[callId].sendAudioTimer.stop();
calls[callId].playVideoTimer.stop();
calls[callId].sendVideoTimer.stop();
if (calls[callId].audioOutput != nullptr) if (calls[callId].audioOutput != nullptr)
{ {
delete calls[callId].audioOutput; delete calls[callId].audioOutput;
calls[callId].audioOutput = nullptr; calls[callId].audioOutput = nullptr;
disconnect(&calls[callId].playAudioTimer,0,0,0);
} }
if (calls[callId].audioInput != nullptr) if (calls[callId].audioInput != nullptr)
{ {
delete calls[callId].audioInput; delete calls[callId].audioInput;
calls[callId].audioInput = nullptr; calls[callId].audioInput = nullptr;
disconnect(&calls[callId].sendAudioTimer,0,0,0);
} }
if (calls[callId].videoEnabled) if (calls[callId].videoEnabled)
Widget::getInstance()->getCamera()->unsuscribe(); Widget::getInstance()->getCamera()->unsuscribe();
disconnect(&calls[callId].playVideoTimer,0,0,0);
disconnect(&calls[callId].sendVideoTimer,0,0,0);
calls[callId].audioBuffer.clear(); calls[callId].audioBuffer.clear();
} }
@ -1224,13 +1227,12 @@ void Core::playCallAudio(int callId, ToxAv* toxav)
} }
if (len == 0) if (len == 0)
{ {
if (calls[callId].audioBuffer.bufferSize() >= framesize*2) calls[callId].playAudioTimer.start();
calls[callId].playAudioTimer.start();
return; return;
} }
//qDebug() << QString("Core: Received %1 bytes, %2 audio bytes free, %3 core buffer size") //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()); // .arg(len*2).arg(calls[callId].audioOutput->bytesFree()).arg(calls[callId].audioBuffer.bufferSize());
calls[callId].audioBuffer.writeData((char*)buf, len*2); calls[callId].audioBuffer.write((char*)buf, len*2);
int state = calls[callId].audioOutput->state(); int state = calls[callId].audioOutput->state();
if (state != QAudio::ActiveState) if (state != QAudio::ActiveState)
{ {
@ -1242,7 +1244,6 @@ void Core::playCallAudio(int callId, ToxAv* toxav)
if (error != QAudio::NoError) if (error != QAudio::NoError)
qWarning() << QString("Core::playCallAudio: Error: %1").arg(error); qWarning() << QString("Core::playCallAudio: Error: %1").arg(error);
calls[callId].playAudioTimer.start(); calls[callId].playAudioTimer.start();
} }

View File

@ -177,10 +177,12 @@ QImage Camera::getLastImage()
vpx_image Camera::getLastVPXImage() vpx_image Camera::getLastVPXImage()
{ {
vpx_image img;
if (!lastFrame.isValid())
return img;
lastFrame.map(QAbstractVideoBuffer::ReadOnly); lastFrame.map(QAbstractVideoBuffer::ReadOnly);
int w = lastFrame.width(), h = lastFrame.height(); int w = lastFrame.width(), h = lastFrame.height();
int bpl = lastFrame.bytesPerLine(); int bpl = lastFrame.bytesPerLine();
vpx_image img;
vpx_img_alloc(&img, VPX_IMG_FMT_I420, w, h, 1); // I420 == YUV420P, same as YV12 with U and V switched vpx_img_alloc(&img, VPX_IMG_FMT_I420, w, h, 1); // I420 == YUV420P, same as YV12 with U and V switched
if (frameFormat == QVideoFrame::Format_YUV420P) if (frameFormat == QVideoFrame::Format_YUV420P)