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

Fix #219, handle av media changes

Can now start or stop video on demand of the peer
This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-08-29 19:20:34 +02:00
parent bd1ca80ffd
commit 3fc9cc0d83
5 changed files with 46 additions and 10 deletions

4
core.h
View File

@ -233,7 +233,7 @@ signals:
void avEnding(int friendId, int callIndex);
void avRequestTimeout(int friendId, int callIndex);
void avPeerTimeout(int friendId, int callIndex);
void avMediaChange(int friendId, int callIndex);
void avMediaChange(int friendId, int callIndex, bool videoEnabled);
void videoFrameReceived(vpx_image* frame);
@ -265,7 +265,7 @@ private:
static void onAvEnding(void* toxav, int32_t call_index, void* core);
static void onAvRequestTimeout(void* toxav, int32_t call_index, void* core);
static void onAvPeerTimeout(void* toxav, int32_t call_index, void* core);
static void onAvMediaChange(void* toxav, int32_t call_index, void* core);
static void onAvMediaChange(void *toxav, int32_t call_index, void* core);
static void prepareCall(int friendId, int callId, ToxAv *toxav, bool videoEnabled);
static void cleanupCall(int callId);

View File

@ -54,19 +54,37 @@ void Core::prepareCall(int friendId, int callId, ToxAv* toxav, bool videoEnabled
calls[callId].sendAudioTimer->setSingleShot(true);
connect(calls[callId].sendAudioTimer, &QTimer::timeout, [=](){sendCallAudio(callId,toxav);});
calls[callId].sendAudioTimer->start();
calls[callId].sendVideoTimer->setInterval(50);
calls[callId].sendVideoTimer->setSingleShot(true);
if (calls[callId].videoEnabled)
{
calls[callId].sendVideoTimer->setInterval(50);
calls[callId].sendVideoTimer->setSingleShot(true);
calls[callId].sendVideoTimer->start();
Widget::getInstance()->getCamera()->suscribe();
}
}
void Core::onAvMediaChange(void*, int32_t, void*)
void Core::onAvMediaChange(void* toxav, int32_t callId, void* core)
{
// HALP, PLS COMPLETE MEH
qWarning() << "If you see this, please complain on GitHub about seeing me! (Don't forget to say what caused me!)";
ToxAvCSettings settings;
toxav_get_peer_csettings((ToxAv*)toxav, callId, 0, &settings);
int friendId = toxav_get_peer_id((ToxAv*)toxav, callId, 0);
qWarning() << "Core: Received media change from friend "<<friendId;
if (settings.call_type == TypeAudio)
{
calls[callId].videoEnabled = false;
calls[callId].sendVideoTimer->stop();
Widget::getInstance()->getCamera()->unsuscribe();
emit ((Core*)core)->avMediaChange(friendId, callId, false);
}
else
{
Widget::getInstance()->getCamera()->suscribe();
calls[callId].videoEnabled = true;
calls[callId].sendVideoTimer->start();
emit ((Core*)core)->avMediaChange(friendId, callId, true);
}
}
void Core::answerCall(int callId)
@ -241,7 +259,9 @@ void Core::sendCallVideo(int callId)
vpx_img_free(&frame);
}
else
{
qDebug("Core::sendCallVideo: Invalid frame (bad camera ?)");
}
calls[callId].sendVideoTimer->start();
}
@ -262,11 +282,11 @@ void Core::micMuteToggle(int callId)
calls[callId].muteMic = !calls[callId].muteMic;
}
void Core::onAvCancel(void* _toxav, int32_t call_index, void* core)
void Core::onAvCancel(void* _toxav, int32_t callId, void* core)
{
ToxAv* toxav = static_cast<ToxAv*>(_toxav);
int friendId = toxav_get_peer_id(toxav, call_index, 0);
int friendId = toxav_get_peer_id(toxav, callId, 0);
if (friendId < 0)
{
qWarning() << "Core: Received invalid AV cancel";
@ -274,7 +294,9 @@ void Core::onAvCancel(void* _toxav, int32_t call_index, void* core)
}
qDebug() << QString("Core: AV cancel from %1").arg(friendId);
emit static_cast<Core*>(core)->avCancel(friendId, call_index);
calls[callId].active = false;
emit static_cast<Core*>(core)->avCancel(friendId, callId);
}
void Core::onAvReject(void*, int32_t, void*)

View File

@ -573,6 +573,18 @@ void ChatForm::onAvPeerTimeout(int FriendId, int)
netcam->hide();
}
void ChatForm::onAvMediaChange(int, int, bool video)
{
if (video)
{
netcam->show();
}
else
{
netcam->hide();
}
}
void ChatForm::onAnswerCallTriggered()
{
audioInputFlag = true;

View File

@ -72,6 +72,7 @@ public slots:
void onAvEnding(int FriendId, int CallId);
void onAvRequestTimeout(int FriendId, int CallId);
void onAvPeerTimeout(int FriendId, int CallId);
void onAvMediaChange(int FriendId, int CallId, bool video);
void onMicMuteToggle();
private slots:

View File

@ -435,6 +435,7 @@ void Widget::addFriend(int friendId, const QString &userId)
connect(core, &Core::avEnding, newfriend->chatForm, &ChatForm::onAvEnding);
connect(core, &Core::avRequestTimeout, newfriend->chatForm, &ChatForm::onAvRequestTimeout);
connect(core, &Core::avPeerTimeout, newfriend->chatForm, &ChatForm::onAvPeerTimeout);
connect(core, &Core::avMediaChange, newfriend->chatForm, &ChatForm::onAvMediaChange);
}
void Widget::addFriendFailed(const QString&)