Improve GVFG audio playback and event shutdown
- Split PCM acquisition from Qt audio playback in the preview sample. - Copy SDK-owned audio frames into a bounded application queue before release. - Track and display dropped audio queue entries. - Add a dedicated stop event for the SDK event-monitor thread. - Replace periodic event-monitor wakeups with an interruptible infinite wait. - Poll public channel events every 200 ms for responsive format and signal updates. - Preserve finite 200 ms video and audio reads for ownership-safe worker shutdown.
This commit is contained in:
@@ -1005,9 +1005,11 @@ namespace gvfg::internal
|
||||
format_change_event_ = CreateEventW(nullptr, FALSE, FALSE, nullptr);
|
||||
plug_in_event_ = CreateEventW(nullptr, FALSE, FALSE, nullptr);
|
||||
plug_out_event_ = CreateEventW(nullptr, FALSE, FALSE, nullptr);
|
||||
monitor_stop_event_ = CreateEventW(nullptr, FALSE, FALSE, nullptr);
|
||||
if (!dma_event_ || !extra_video_event_ ||
|
||||
(audio_enabled_ && (!audio_event_ || !extra_audio_event_)) ||
|
||||
!format_change_event_ || !plug_in_event_ || !plug_out_event_)
|
||||
!format_change_event_ || !plug_in_event_ || !plug_out_event_ ||
|
||||
!monitor_stop_event_)
|
||||
return false;
|
||||
|
||||
if (!register_event(channelIndex, GIGA_IOCTL_EVENT_VIDEO_DMA, dma_event_))
|
||||
@@ -1084,6 +1086,11 @@ namespace gvfg::internal
|
||||
CloseHandle(plug_out_event_);
|
||||
plug_out_event_ = nullptr;
|
||||
}
|
||||
if (monitor_stop_event_)
|
||||
{
|
||||
CloseHandle(monitor_stop_event_);
|
||||
monitor_stop_event_ = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool PcieS2mmCaptureSession::start_event_monitoring()
|
||||
@@ -1128,6 +1135,8 @@ namespace gvfg::internal
|
||||
SetEvent(extra_video_event_);
|
||||
if (extra_audio_event_)
|
||||
SetEvent(extra_audio_event_);
|
||||
if (monitor_stop_event_)
|
||||
SetEvent(monitor_stop_event_);
|
||||
if (capture_thread_.joinable())
|
||||
capture_thread_.join();
|
||||
|
||||
@@ -1162,15 +1171,19 @@ namespace gvfg::internal
|
||||
void PcieS2mmCaptureSession::capture_thread_proc()
|
||||
{
|
||||
const uint32_t channel = active_channel();
|
||||
HANDLE waitHandles[] = {format_change_event_, plug_in_event_, plug_out_event_};
|
||||
constexpr DWORD waitHandleCount = 3;
|
||||
HANDLE waitHandles[] = {
|
||||
monitor_stop_event_,
|
||||
format_change_event_,
|
||||
plug_in_event_,
|
||||
plug_out_event_};
|
||||
constexpr DWORD waitHandleCount = 4;
|
||||
|
||||
while (monitoring_.load(std::memory_order_acquire))
|
||||
{
|
||||
const DWORD waitResult = WaitForMultipleObjects(waitHandleCount,
|
||||
waitHandles,
|
||||
FALSE,
|
||||
1000);
|
||||
INFINITE);
|
||||
if (!monitoring_.load(std::memory_order_acquire))
|
||||
break;
|
||||
if (waitResult == WAIT_TIMEOUT)
|
||||
@@ -1188,14 +1201,16 @@ namespace gvfg::internal
|
||||
switch (waitResult - WAIT_OBJECT_0)
|
||||
{
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
PCIES2MM_LOG("event: FORMAT_CHANGE");
|
||||
handle_format_change_event(channel);
|
||||
break;
|
||||
case 1:
|
||||
case 2:
|
||||
PCIES2MM_LOG("event: PLUG_IN");
|
||||
handle_plugin_event(channel);
|
||||
break;
|
||||
case 2:
|
||||
case 3:
|
||||
PCIES2MM_LOG("event: PLUG_OUT");
|
||||
handle_unplug_event(channel);
|
||||
break;
|
||||
|
||||
@@ -113,6 +113,7 @@ namespace gvfg::internal
|
||||
HANDLE format_change_event_ = nullptr;
|
||||
HANDLE plug_in_event_ = nullptr;
|
||||
HANDLE plug_out_event_ = nullptr;
|
||||
HANDLE monitor_stop_event_ = nullptr;
|
||||
|
||||
pcies2mm_stream_desc_t stream_desc_{};
|
||||
uint32_t stream_bit_depth_ = 8;
|
||||
|
||||
Reference in New Issue
Block a user