Ejemplo n.º 1
0
void AudioInjector::restart() {
    // grab the AudioInjectorManager
    auto injectorManager = DependencyManager::get<AudioInjectorManager>();

    if (thread() != QThread::currentThread()) {
        QMetaObject::invokeMethod(this, "restart");

        if (!_options.localOnly) {
            // notify the AudioInjectorManager to wake up in case it's waiting for new injectors
            injectorManager->notifyInjectorReadyCondition();
        }

        return;
    }

    // reset the current send offset to zero
    _currentSendOffset = 0;

    // reset state to start sending from beginning again
    _nextFrame = 0;
    if (_frameTimer) {
        _frameTimer->invalidate();
    }
    _hasSentFirstFrame = false;

    // check our state to decide if we need extra handling for the restart request
    if (stateHas(AudioInjectorState::Finished)) {
        // we finished playing, need to reset state so we can get going again
        _hasSetup = false;
        _shouldStop = false;
        _state = AudioInjectorState::NotFinished;

        // call inject audio to start injection over again
        setupInjection();

        // inject locally
        if(injectLocally()) {

            // if not localOnly, wake the AudioInjectorManager back up if it is stuck waiting
            if (!_options.localOnly) {

                if (!injectorManager->restartFinishedInjector(this)) {
                    _state = AudioInjectorState::Finished; // we're not playing, so reset the state used by isPlaying.
                }
            }
        } else {
            _state = AudioInjectorState::Finished; // we failed to play, so we are finished again
        }
    }
}
Ejemplo n.º 2
0
void AudioInjector::restart() {
    // grab the AudioInjectorManager
    auto injectorManager = DependencyManager::get<AudioInjectorManager>();
    
    if (thread() != QThread::currentThread()) {
        QMetaObject::invokeMethod(this, "restart");
        
        if (!_options.localOnly) {
            // notify the AudioInjectorManager to wake up in case it's waiting for new injectors
            injectorManager->notifyInjectorReadyCondition();
        }
        
        return;
    }
    
    // reset the current send offset to zero
    _currentSendOffset = 0;
    
    // check our state to decide if we need extra handling for the restart request
    if (_state == State::Finished) {
        // we finished playing, need to reset state so we can get going again
        _hasSetup = false;
        _shouldStop = false;
        _state = State::NotFinished;
        
        // call inject audio to start injection over again
        setupInjection();
        
        // if we're a local injector call inject locally to start injecting again
        if (_options.localOnly) {
            injectLocally();
        } else {
            // wake the AudioInjectorManager back up if it's stuck waiting
            injectorManager->restartFinishedInjector(this);
        }
    }
}
Ejemplo n.º 3
0
void AudioInjector::injectAudio() {
    if (!_isStarted) {
        _isStarted = true;
        // check if we need to offset the sound by some number of seconds
        if (_options.secondOffset > 0.0f) {

            // convert the offset into a number of bytes
            int byteOffset = (int) floorf(AudioConstants::SAMPLE_RATE * _options.secondOffset * (_options.stereo ? 2.0f : 1.0f));
            byteOffset *= sizeof(int16_t);

            _currentSendOffset = byteOffset;
        } else {
            _currentSendOffset = 0;
        }

        if (_options.localOnly) {
            injectLocally();
        } else {
            injectToMixer();
        }
    } else {
        qCDebug(audio) << "AudioInjector::injectAudio called but already started.";
    }
}