RenderHeads / UnityPlugin-AVProDeckLink

AVPro DeckLink is a Unity plugin for broadcast CG using Blackmagic capture hardware
https://renderheads.com/products/avpro-decklink/
9 stars 1 forks source link

Audio input is gone if input is stopped once #75

Open pilzinho opened 8 months ago

pilzinho commented 8 months ago

When stopping an input calling DeckLinkInput.StopInput(), the AudioClip of the AudioSource is destroyed. So when starting the input again by calling Begin() the audio will not start again.

We solved this for now in DeckLinkInput by destroying the whole AudioSource when stopping and moving the creation of the AudioSource from the Awake() to the Begin() method like so:

protected override void BeginDevice()
{
        ...

    if (_device != null)
    {
        _enable3D = _device.Enable3DInput;
        _device.FlipInputX = _flipX;
        _device.FlipInputY = _flipY;
        InitAudio();
        DeckLinkPlugin.FlushAudioBuffer(_deviceIndex);
    }
}

private void InitAudio()
{
    if (_audioSource)
        StopAudio();

    _audioSource = gameObject.AddComponent<AudioSource>();
    _audioSource.hideFlags = HideFlags.HideInInspector;
    _audioSource.loop = true;
}

private void StopAudio()
{
    if (!_audioSource)
        return;

    _audioSource.Stop();
    if (_audioSource.clip != null)
    {
        AudioClip.Destroy(_audioSource.clip);
        _audioSource.clip = null;
    }
    Destroy(_audioSource);
}

StopAudio() is called by the StopInput() and Cleanup() methods.

stale[bot] commented 6 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

RichRH commented 1 day ago

Hi @pilzinho,

Thanks for reporting this (some time ago!) - I've implemented these changes for the next release.

Cheers,