mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
Merge pull request #167 from dubslow/master
Randomized the bootstrap table, to distribute load away from the first 5
This commit is contained in:
commit
9ff1a5510b
91
core.cpp
91
core.cpp
|
@ -108,6 +108,8 @@ void Core::start()
|
|||
return;
|
||||
}
|
||||
|
||||
qsrand(time(nullptr));
|
||||
|
||||
loadConfiguration();
|
||||
|
||||
tox_callback_friend_request(tox, onFriendRequest, this);
|
||||
|
@ -675,9 +677,9 @@ void Core::bootstrapDht()
|
|||
const Settings& s = Settings::getInstance();
|
||||
QList<Settings::DhtServer> dhtServerList = s.getDhtServerList();
|
||||
|
||||
static int j = 0;
|
||||
int i=0;
|
||||
int listSize = dhtServerList.size();
|
||||
static int j = qrand() % listSize;
|
||||
int i=0;
|
||||
while (i<5)
|
||||
{
|
||||
const Settings::DhtServer& dhtServer = dhtServerList[j % listSize];
|
||||
|
@ -1001,8 +1003,16 @@ void Core::onAvInvite(void* _toxav, int32_t call_index, void* core)
|
|||
return;
|
||||
}
|
||||
|
||||
int transType = toxav_get_peer_transmission_type(toxav, call_index, 0);
|
||||
if (transType == TypeVideo)
|
||||
ToxAvCSettings* transSettings = new ToxAvCSettings;
|
||||
int err = toxav_get_peer_csettings(toxav, call_index, 0, transSettings);
|
||||
if (err != ErrorNone)
|
||||
{
|
||||
qWarning() << "Core::onAvInvite: error getting call type";
|
||||
delete transSettings;
|
||||
return;
|
||||
}
|
||||
|
||||
if (transSettings->call_type == TypeVideo)
|
||||
{
|
||||
qDebug() << QString("Core: AV invite from %1 with video").arg(friendId);
|
||||
emit static_cast<Core*>(core)->avInvite(friendId, call_index, true);
|
||||
|
@ -1012,6 +1022,8 @@ void Core::onAvInvite(void* _toxav, int32_t call_index, void* core)
|
|||
qDebug() << QString("Core: AV invite from %1 without video").arg(friendId);
|
||||
emit static_cast<Core*>(core)->avInvite(friendId, call_index, false);
|
||||
}
|
||||
|
||||
delete transSettings;
|
||||
}
|
||||
|
||||
void Core::onAvStart(void* _toxav, int32_t call_index, void* core)
|
||||
|
@ -1025,8 +1037,16 @@ void Core::onAvStart(void* _toxav, int32_t call_index, void* core)
|
|||
return;
|
||||
}
|
||||
|
||||
int transType = toxav_get_peer_transmission_type(toxav, call_index, 0);
|
||||
if (transType == TypeVideo)
|
||||
ToxAvCSettings* transSettings = new ToxAvCSettings;
|
||||
int err = toxav_get_peer_csettings(toxav, call_index, 0, transSettings);
|
||||
if (err != ErrorNone)
|
||||
{
|
||||
qWarning() << "Core::onAvStart: error getting call type";
|
||||
delete transSettings;
|
||||
return;
|
||||
}
|
||||
|
||||
if (transSettings->call_type == TypeVideo)
|
||||
{
|
||||
qDebug() << QString("Core: AV start from %1 with video").arg(friendId);
|
||||
prepareCall(friendId, call_index, toxav, true);
|
||||
|
@ -1038,6 +1058,8 @@ void Core::onAvStart(void* _toxav, int32_t call_index, void* core)
|
|||
prepareCall(friendId, call_index, toxav, false);
|
||||
emit static_cast<Core*>(core)->avStart(friendId, call_index, false);
|
||||
}
|
||||
|
||||
delete transSettings;
|
||||
}
|
||||
|
||||
void Core::onAvCancel(void* _toxav, int32_t call_index, void* core)
|
||||
|
@ -1110,8 +1132,17 @@ void Core::onAvStarting(void* _toxav, int32_t call_index, void* core)
|
|||
qWarning() << "Core: Received invalid AV starting";
|
||||
return;
|
||||
}
|
||||
int transType = toxav_get_peer_transmission_type(toxav, call_index, 0);
|
||||
if (transType == TypeVideo)
|
||||
|
||||
ToxAvCSettings* transSettings = new ToxAvCSettings;
|
||||
int err = toxav_get_peer_csettings(toxav, call_index, 0, transSettings);
|
||||
if (err != ErrorNone)
|
||||
{
|
||||
qWarning() << "Core::onAvStarting: error getting call type";
|
||||
delete transSettings;
|
||||
return;
|
||||
}
|
||||
|
||||
if (transSettings->call_type == TypeVideo)
|
||||
{
|
||||
qDebug() << QString("Core: AV starting from %1 with video").arg(friendId);
|
||||
prepareCall(friendId, call_index, toxav, true);
|
||||
|
@ -1123,6 +1154,8 @@ void Core::onAvStarting(void* _toxav, int32_t call_index, void* core)
|
|||
prepareCall(friendId, call_index, toxav, false);
|
||||
emit static_cast<Core*>(core)->avStarting(friendId, call_index, false);
|
||||
}
|
||||
|
||||
delete transSettings;
|
||||
}
|
||||
|
||||
void Core::onAvEnding(void* _toxav, int32_t call_index, void* core)
|
||||
|
@ -1179,6 +1212,7 @@ void Core::onAvPeerTimeout(void* _toxav, int32_t call_index, void* core)
|
|||
void Core::onAvMediaChange(void*, int32_t, void*)
|
||||
{
|
||||
// HALP, PLS COMPLETE MEH
|
||||
qWarning() << "If you see this, please complain on GitHub about seeing me! (Don't forget to say what caused me!)";
|
||||
}
|
||||
|
||||
void Core::answerCall(int callId)
|
||||
|
@ -1189,17 +1223,28 @@ void Core::answerCall(int callId)
|
|||
qWarning() << "Core: Received invalid AV answer peer ID";
|
||||
return;
|
||||
}
|
||||
int transType = toxav_get_peer_transmission_type(toxav, callId, 0);
|
||||
if (transType == TypeVideo)
|
||||
|
||||
ToxAvCSettings* transSettings = new ToxAvCSettings;
|
||||
int err = toxav_get_peer_csettings(toxav, callId, 0, transSettings);
|
||||
if (err != ErrorNone)
|
||||
{
|
||||
qWarning() << "Core::answerCall: error getting call settings";
|
||||
delete transSettings;
|
||||
return;
|
||||
}
|
||||
|
||||
if (transSettings->call_type == TypeVideo)
|
||||
{
|
||||
qDebug() << QString("Core: answering call %1 with video").arg(callId);
|
||||
toxav_answer(toxav, callId, TypeVideo);
|
||||
toxav_answer(toxav, callId, transSettings);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << QString("Core: answering call %1 without video").arg(callId);
|
||||
toxav_answer(toxav, callId, TypeAudio);
|
||||
toxav_answer(toxav, callId, transSettings);
|
||||
}
|
||||
|
||||
delete transSettings;
|
||||
}
|
||||
|
||||
void Core::hangupCall(int callId)
|
||||
|
@ -1212,16 +1257,21 @@ void Core::hangupCall(int callId)
|
|||
void Core::startCall(int friendId, bool video)
|
||||
{
|
||||
int callId;
|
||||
ToxAvCSettings cSettings = av_DefaultSettings;
|
||||
cSettings.max_video_width = TOXAV_MAX_VIDEO_WIDTH;
|
||||
cSettings.max_video_height = TOXAV_MAX_VIDEO_HEIGHT;
|
||||
if (video)
|
||||
{
|
||||
qDebug() << QString("Core: Starting new call with %1 with video").arg(friendId);
|
||||
toxav_call(toxav, &callId, friendId, TypeVideo, TOXAV_RINGING_TIME);
|
||||
cSettings.call_type = TypeVideo;
|
||||
toxav_call(toxav, &callId, friendId, &cSettings, TOXAV_RINGING_TIME);
|
||||
calls[callId].videoEnabled=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug() << QString("Core: Starting new call with %1 without video").arg(friendId);
|
||||
toxav_call(toxav, &callId, friendId, TypeAudio, TOXAV_RINGING_TIME);
|
||||
cSettings.call_type = TypeAudio;
|
||||
toxav_call(toxav, &callId, friendId, &cSettings, TOXAV_RINGING_TIME);
|
||||
calls[callId].videoEnabled=false;
|
||||
}
|
||||
}
|
||||
|
@ -1238,11 +1288,13 @@ void Core::prepareCall(int friendId, int callId, ToxAv* toxav, bool videoEnabled
|
|||
qDebug() << QString("Core: preparing call %1").arg(callId);
|
||||
calls[callId].callId = callId;
|
||||
calls[callId].friendId = friendId;
|
||||
// the following three lines are also now redundant from startCall, but are
|
||||
// necessary there for outbound and here for inbound
|
||||
calls[callId].codecSettings = av_DefaultSettings;
|
||||
calls[callId].codecSettings.max_video_width = TOXAV_MAX_VIDEO_WIDTH;
|
||||
calls[callId].codecSettings.max_video_height = TOXAV_MAX_VIDEO_HEIGHT;
|
||||
calls[callId].videoEnabled = videoEnabled;
|
||||
toxav_prepare_transmission(toxav, callId, &calls[callId].codecSettings, videoEnabled);
|
||||
toxav_prepare_transmission(toxav, callId, av_jbufdc, av_VADd, videoEnabled);
|
||||
|
||||
// Prepare output
|
||||
QAudioFormat format;
|
||||
|
@ -1300,6 +1352,11 @@ void Core::prepareCall(int friendId, int callId, ToxAv* toxav, bool videoEnabled
|
|||
|
||||
Widget::getInstance()->getCamera()->suscribe();
|
||||
}
|
||||
else if (calls[callId].audioInput == nullptr && calls[callId].audioOutput == nullptr)
|
||||
{
|
||||
qWarning() << "Audio only call can neither play nor record audio, killing call";
|
||||
toxav_hangup(toxav, callId);
|
||||
}
|
||||
}
|
||||
|
||||
void Core::cleanupCall(int callId)
|
||||
|
@ -1324,7 +1381,7 @@ void Core::cleanupCall(int callId)
|
|||
|
||||
void Core::playCallAudio(ToxAv*, int32_t callId, int16_t *data, int length)
|
||||
{
|
||||
if (!calls[callId].active)
|
||||
if (!calls[callId].active || calls[callId].audioOutput == nullptr)
|
||||
return;
|
||||
calls[callId].audioBuffer.write((char*)data, length*2);
|
||||
int state = calls[callId].audioOutput->state();
|
||||
|
@ -1340,7 +1397,7 @@ void Core::playCallAudio(ToxAv*, int32_t callId, int16_t *data, int length)
|
|||
|
||||
void Core::sendCallAudio(int callId, ToxAv* toxav)
|
||||
{
|
||||
if (!calls[callId].active)
|
||||
if (!calls[callId].active || calls[callId].audioInput == nullptr)
|
||||
return;
|
||||
int framesize = (calls[callId].codecSettings.audio_frame_duration * calls[callId].codecSettings.audio_sample_rate) / 1000;
|
||||
uint8_t buf[framesize*2], dest[framesize*2];
|
||||
|
|
2
core.h
2
core.h
|
@ -100,7 +100,7 @@ public:
|
|||
QAudioOutput* audioOutput;
|
||||
QAudioInput* audioInput;
|
||||
QIODevice* audioInputDevice;
|
||||
ToxAvCodecSettings codecSettings;
|
||||
ToxAvCSettings codecSettings;
|
||||
QTimer *sendAudioTimer, *sendVideoTimer;
|
||||
int callId;
|
||||
int friendId;
|
||||
|
|
|
@ -48,6 +48,7 @@ SettingsForm::SettingsForm()
|
|||
useTranslations.setChecked(Settings::getInstance().getUseTranslations());
|
||||
makeToxPortable.setText(tr("Make Tox portable","Text on a checkbox to make qTox a portable application"));
|
||||
makeToxPortable.setChecked(Settings::getInstance().getMakeToxPortable());
|
||||
makeToxPortable.setToolTip(tr("Save settings to the working directory instead of the usual conf dir","describes makeToxPortable checkbox"));
|
||||
|
||||
main->setLayout(&layout);
|
||||
layout.addWidget(&nameLabel);
|
||||
|
|
Loading…
Reference in New Issue
Block a user