Hi Tom,
Thanks for raising this, I notice that this is an issue also in the StillsCSharp SDK sample and we will fix in a future release. The actual process to stop, flush and restart stream should be conducted outside of the callback to avoid deadlock.
To resolve:
1. Create EventArgs for change in signal validity, similar to other EventArgs in DeckLinkInputDevice.cs
- Code: Select all
public class DeckLinkInputSignalValidChangedEventArgs : EventArgs
{
public bool SignalValid { get; }
public DeckLinkInputSignalValidChangedEventArgs(bool signalValid)
{
SignalValid = signalValid;
}
}
2. Create EventHandler for signal valid change in DeckLinkInputDevice class:
- Code: Select all
public event EventHandler<DeckLinkInputSignalValidChangedEventArgs> SignalValidChangedHandler;
3. Call event handler from IDeckLinkInputCallback.VideoInputFrameArrived callback when signal valid state changes:
- Code: Select all
// Detect change in input signal, restart stream when valid stream detected
if (inputSignalAbsent != m_prevInputSignalAbsent)
{
SignalValidChangedHandler?.Invoke(this, new DeckLinkInputSignalValidChangedEventArgs(!inputSignalAbsent));
}
m_prevInputSignalAbsent = inputSignalAbsent;
4. Finally register to event handler to process in another thread:
- Code: Select all
m_deckLinkInput.SignalValidChangedHandler += new EventHandler<DeckLinkInputSignalValidChangedEventArgs>((s,e) => this.BeginInvoke((Action)(() => RestartStream()(s,e))));
Then implement RestartStream to call the StopStreams/FlushStreams/StartStreams. Importantly use BeginInvoke (or Tasks) to dispatch the action asynchronously as not to block callback.
As a final note, the reason for adding the StopStreams/FlushStreams/StartStreams code is to ensure that the stream times for incoming video frames and audio packets are aligned after signal discontinuity. Please note this is not a AV sync issue, only that the stream times may have an offset. You can read more at the Desktop Video Developer Support FAQ at
https://www.blackmagicdesign.com/support/faq/59024 under topic
Audio / Video stream time offset when capturing with DeckLink Duo 2 / Quad 2 in Half DuplexIf you are only interested in video frames, not using DeckLink Duo 2/Quad 2 or not concerned with stream time offset, then you can remove this segment of code completely
Regards
Cameron