Ejemplo n.º 1
0
AudioInjector* AudioInjector::playSound(const QByteArray& buffer, const AudioInjectorOptions options, AbstractAudioInterface* localInterface) {
    AudioInjector* injector = new AudioInjector(buffer, options);
    injector->setLocalAudioInterface(localInterface);
    
    // grab the AudioInjectorManager
    auto injectorManager = DependencyManager::get<AudioInjectorManager>();
    
    // setup parameters required for injection
    injector->setupInjection();
    
    if (options.localOnly) {
        if (injector->injectLocally()) {
            // local injection succeeded, return the pointer to injector
            return injector;
        } else {
            // unable to inject locally, return a nullptr
            return nullptr;
        }
    } else {
        // attempt to thread the new injector
        if (injectorManager->threadInjector(injector)) {
            return injector;
        } else {
            // we failed to thread the new injector (we are at the max number of injector threads)
            return nullptr;
        }
    }
}
Ejemplo n.º 2
0
AudioInjector* AudioInjector::playSound(const QByteArray& buffer, const AudioInjectorOptions options, AbstractAudioInterface* localInterface) {
    QThread* injectorThread = new QThread();
    injectorThread->setObjectName("Audio Injector Thread");

    AudioInjector* injector = new AudioInjector(buffer, options);
    injector->setLocalAudioInterface(localInterface);

    injector->moveToThread(injectorThread);

    // start injecting when the injector thread starts
    connect(injectorThread, &QThread::started, injector, &AudioInjector::injectAudio);

    // connect the right slots and signals for AudioInjector and thread cleanup
    connect(injector, &AudioInjector::destroyed, injectorThread, &QThread::quit);
    connect(injectorThread, &QThread::finished, injectorThread, &QThread::deleteLater);

    injectorThread->start();
    return injector;
}