Skip to content

Commit

Permalink
Fixed deadlock in audio sampler.
Browse files Browse the repository at this point in the history
  • Loading branch information
gmpreussner committed Nov 5, 2016
1 parent 1bf010b commit 693233d
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions Source/NdiMedia/Private/Player/NdiMediaAudioSampler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,16 @@ void FNdiMediaAudioSampler::Stop()

void FNdiMediaAudioSampler::SampleAudio(uint32 Timeout)
{
NDIlib_audio_frame_t AudioFrame;
{
FScopeLock Lock(&CriticalSection);
void* CurrentReceiverInstance = ReceiverInstance;

if (ReceiverInstance == nullptr)
{
return;
}
if (CurrentReceiverInstance == nullptr)
{
return;
}

// fetch audio frame
NDIlib_audio_frame_t AudioFrame;
{
NDIlib_frame_type_e FrameType = NDIlib_recv_capture(ReceiverInstance, nullptr, &AudioFrame, nullptr, Timeout);

if (FrameType == NDIlib_frame_type_error)
Expand All @@ -87,6 +88,12 @@ void FNdiMediaAudioSampler::SampleAudio(uint32 Timeout)
}
}

SamplesDelegate.ExecuteIfBound(AudioFrame);
NDIlib_recv_free_audio(ReceiverInstance, &AudioFrame);
// forward frame to listener
FScopeLock Lock(&CriticalSection);

if (CurrentReceiverInstance == ReceiverInstance)
{
SamplesDelegate.ExecuteIfBound(AudioFrame);
NDIlib_recv_free_audio(ReceiverInstance, &AudioFrame);
}
}

0 comments on commit 693233d

Please sign in to comment.