Example #1
0
Core::Core(Camera* cam, QThread *coreThread) :
    tox(nullptr), camera(cam)
{
    videobuf = new uint8_t[videobufsize];
    videoBusyness=0;

    toxTimer = new QTimer(this);
    toxTimer->setSingleShot(true);
    //saveTimer = new QTimer(this);
    //saveTimer->start(TOX_SAVE_INTERVAL);
    bootstrapTimer = new QTimer(this);
    bootstrapTimer->start(TOX_BOOTSTRAP_INTERVAL);
    connect(toxTimer, &QTimer::timeout, this, &Core::process);
    //connect(saveTimer, &QTimer::timeout, this, &Core::saveConfiguration); //Disable save timer in favor of saving on events
    //connect(fileTimer, &QTimer::timeout, this, &Core::fileHeartbeat);
    connect(bootstrapTimer, &QTimer::timeout, this, &Core::onBootstrapTimer);
    connect(&Settings::getInstance(), &Settings::dhtServerListChanged, this, &Core::bootstrapDht);
    connect(this, SIGNAL(fileTransferFinished(ToxFile)), this, SLOT(onFileTransferFinished(ToxFile)));

    for (int i=0; i<TOXAV_MAX_CALLS;i++)
    {
        calls[i].sendAudioTimer = new QTimer();
        calls[i].sendVideoTimer = new QTimer();
        calls[i].sendAudioTimer->moveToThread(coreThread);
        calls[i].sendVideoTimer->moveToThread(coreThread);
        connect(calls[i].sendVideoTimer, &QTimer::timeout, [this,i](){sendCallVideo(i);});
    }

    // OpenAL init
    alOutDev = alcOpenDevice(nullptr);
    if (!alOutDev)
    {
        qWarning() << "Core: Cannot open output audio device";
    }
    else
    {
        alContext=alcCreateContext(alOutDev,nullptr);
        if (!alcMakeContextCurrent(alContext))
        {
            qWarning() << "Core: Cannot create output audio context";
            alcCloseDevice(alOutDev);
        }
        else
            alGenSources(1, &alMainSource);
    }
    alInDev = alcCaptureOpenDevice(NULL,av_DefaultSettings.audio_sample_rate, AL_FORMAT_MONO16,
                                   (av_DefaultSettings.audio_frame_duration * av_DefaultSettings.audio_sample_rate * 4) / 1000);
    if (!alInDev)
        qWarning() << "Core: Cannot open input audio device";
}
Example #2
0
Core::Core(Camera* cam, QThread *CoreThread, QString loadPath) :
    tox(nullptr), toxav(nullptr), camera(cam), loadPath(loadPath), ready{false}
{
    qDebug() << "Core: loading Tox from" << loadPath;

    coreThread = CoreThread;

    Audio::getInstance();

    videobuf = new uint8_t[videobufsize];

    for (int i = 0; i < ptCounter; i++)
        pwsaltedkeys[i] = nullptr;

    toxTimer = new QTimer(this);
    toxTimer->setSingleShot(true);
    connect(toxTimer, &QTimer::timeout, this, &Core::process);
    connect(&Settings::getInstance(), &Settings::dhtServerListChanged, this, &Core::process);

    for (int i=0; i<TOXAV_MAX_CALLS;i++)
    {
        calls[i].active = false;
        calls[i].alSource = 0;
        calls[i].sendAudioTimer = new QTimer();
        calls[i].sendVideoTimer = new QTimer();
        calls[i].sendAudioTimer->moveToThread(coreThread);
        calls[i].sendVideoTimer->moveToThread(coreThread);
        connect(calls[i].sendVideoTimer, &QTimer::timeout, [this,i](){sendCallVideo(i);});
    }

    // OpenAL init
    QString outDevDescr = Settings::getInstance().getOutDev();
    Audio::openOutput(outDevDescr);
    QString inDevDescr = Settings::getInstance().getInDev();
    Audio::openInput(inDevDescr);
}