Streamline GigabyteLib capture control and diagnostics
Compared with d652f15:
- set the SDK release version to 1.0.0 for the new GigabyteLib backend and its required matching driver
- preserve GigabyteLib result codes and event names through the public SDK instead of translating vendor semantics
- expose cached Lib signal, SDI string fields, ErrorCount, and separate video/audio event counters for direct diagnostics
- serialize GigabyteLib capture calls and recover an active stream internally after a video input plugin event
- keep the SDK frame lifetime fence while following the current zero-copy contract without a vendor release call
- separate Sample logging and presentation counters from capture control, and report Lib-owned fields with explicit source names
- remove the manual Open Device control so Start lazily opens the selected device and revalidates VideoSignalLock once per request
- keep format selection side-effect free until Start opens the channel, then apply the selected output depth through GigabyteLib
- update the public API, diagnostics, architecture, error-handling, and build documentation for the simplified ownership model
This commit is contained in:
@@ -83,6 +83,8 @@ set(GVFG_QT_PREVIEW_SOURCES
|
||||
main.cpp
|
||||
capture_controller.cpp
|
||||
capture_controller.h
|
||||
sample_log.cpp
|
||||
sample_log.h
|
||||
mainwindow.cpp
|
||||
mainwindow.h
|
||||
mainwindow.ui
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
- `[SDK]`/`[SDK API]`:SDK read 邊界或 API 回傳的現象。
|
||||
- `[APP]`:Preview、audio output 或 Sample 自身核對的現象。
|
||||
- 累計數字最多每 5 秒彙整一次;Stop 會補記尚未輸出的變化。
|
||||
- Stop 不列印正常統計摘要。只有資料去向核對不一致時才印 `[APP] ERROR accounting mismatch`。正常停止清掉的待處理資料不算運行錯誤。
|
||||
- Stop 不列印正常統計摘要;只有實際 API、preview 或 audio output 錯誤才記錄。
|
||||
|
||||
## 拿到 Log 後怎麼處理
|
||||
|
||||
@@ -14,7 +14,7 @@ Log 只標示觀測層、現象與數值。Video/audio `frame_id` 是 SDK 每次
|
||||
|
||||
預覽使用 Present(0, 0),讓 DXGI 等待呈現相依條件,不做外部重試。SyncInterval 仍為 0,並非每張都保證顯示。預覽改成 FIFO,最多保留 3 張待處理影像(包含正在上傳的容量保留),另有 1 個處理中槽位,共 4 個 GPU 槽。60 FPS 下 3 張約 50 ms;這不是刻意等滿 50 ms 才顯示。從上傳完成入列開始計時,等待超過 50 ms 的影像才丟棄(expired);容量滿時跳過新影像(busy),不替換仍在期限內的舊影像。50 ms 是開始處理前的等待期限,不含 GPU 執行/DXGI Present 等待,不保證端到端延遲或實體螢幕逐張呈現。Stop/關閉/鎖等待只處理 Windows 同步送達的視窗訊息,避免 DXGI 等待 UI 而 UI 又等待 worker;不處理一般排隊輸入或 Qt callbacks。
|
||||
|
||||
Audio 保留原本最多 10 個 PCM 區塊的播放佇列(`kMaxQueuedAudioFrames`);滿時丟掉最舊區塊,再加入新區塊。丟棄區塊、停滯與收音間隔仍保留為內部診斷計數,但不顯示在一般 Log;audio frame 不保證與 video frame 等長。
|
||||
Audio 保留原本最多 10 個 PCM 區塊的播放佇列(`kMaxQueuedAudioFrames`);滿時丟掉最舊區塊,再加入新區塊。Sample 不統計輸出、丟棄或取消數量;audio frame 不保證與 video frame 等長。
|
||||
|
||||
播放 write 失敗,或持續回傳 0、兩秒沒有進展,會記錄原因並停止通道;檢查音效裝置後重新 Start。此檢查無法中斷本身永不返回的 write 呼叫。
|
||||
|
||||
|
||||
@@ -2,10 +2,6 @@
|
||||
#include <QAudioDevice>
|
||||
#include <QAudioFormat>
|
||||
#include <QAudioSink>
|
||||
#include <QCoreApplication>
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QIODevice>
|
||||
#include <QMediaDevices>
|
||||
#include <QMetaObject>
|
||||
#include <QStringList>
|
||||
@@ -26,15 +22,6 @@ namespace
|
||||
{
|
||||
constexpr size_t kMaxQueuedAudioFrames = 10;
|
||||
|
||||
QString logFilePrefix()
|
||||
{
|
||||
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||
return QStringLiteral("gvfg_qt_preview_debug");
|
||||
#else
|
||||
return QStringLiteral("gvfg_qt_preview");
|
||||
#endif
|
||||
}
|
||||
|
||||
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||
QString boolText(int value) { return value ? QStringLiteral("yes") : QStringLiteral("no"); }
|
||||
|
||||
@@ -71,10 +58,9 @@ namespace
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case GVFG_EVENT_SIGNAL_CONNECTED: return QStringLiteral("SIGNAL_CONNECTED");
|
||||
case GVFG_EVENT_SIGNAL_DISCONNECTED: return QStringLiteral("SIGNAL_DISCONNECTED");
|
||||
case GVFG_EVENT_STREAM_READY: return QStringLiteral("STREAM_READY");
|
||||
case GVFG_EVENT_FORMAT_CHANGE_BEGIN: return QStringLiteral("FORMAT_CHANGE_BEGIN");
|
||||
case GVFG_EVENT_VIDEO_FORMAT_CHANGED: return QStringLiteral("VIDEO_FORMAT_CHANGED");
|
||||
case GVFG_EVENT_VIDEO_INPUT_PLUGIN: return QStringLiteral("VIDEO_INPUT_PLUGIN");
|
||||
case GVFG_EVENT_VIDEO_INPUT_UNPLUG: return QStringLiteral("VIDEO_INPUT_UNPLUG");
|
||||
default: return QStringLiteral("UNKNOWN");
|
||||
}
|
||||
}
|
||||
@@ -87,7 +73,6 @@ CaptureController::CaptureController(QObject *parent) : QObject(parent)
|
||||
processPendingEvents();
|
||||
updateSignalStatus(false);
|
||||
});
|
||||
openLogFile();
|
||||
}
|
||||
|
||||
CaptureController::~CaptureController()
|
||||
@@ -154,19 +139,6 @@ QString CaptureController::sdkVersion() const
|
||||
return QString::fromLatin1(gvfg_get_version());
|
||||
}
|
||||
|
||||
void CaptureController::logStartupInfo()
|
||||
{
|
||||
appendLog(QStringLiteral("GVFG SDK version | %1").arg(sdkVersion()));
|
||||
appendLog(logFile_.isOpen()
|
||||
? QStringLiteral("Log file | %1").arg(logFilePath_)
|
||||
: QStringLiteral("Log file unavailable | %1").arg(logFilePath_));
|
||||
}
|
||||
|
||||
void CaptureController::logUiMessage(const QString &message)
|
||||
{
|
||||
appendLog(message);
|
||||
}
|
||||
|
||||
void CaptureController::refreshDevices()
|
||||
{
|
||||
if (handle_ != nullptr)
|
||||
@@ -227,33 +199,48 @@ bool CaptureController::openDevice()
|
||||
bool CaptureController::openChannel(int channel)
|
||||
{
|
||||
ChannelRuntime &runtime = channels_[channel];
|
||||
if (runtime.opened)
|
||||
return applyOutputFormat(channel);
|
||||
if (handle_ == nullptr && !openDevice())
|
||||
return false;
|
||||
|
||||
const bool newlyOpened = !runtime.opened;
|
||||
const bool zeroCopyEnabled = runtime.zeroCopy;
|
||||
gvfg_status_t status = gvfg_set_channel_zero_copy_enabled(handle_, channel, zeroCopyEnabled ? 1 : 0);
|
||||
gvfg_status_t status = GVFG_OK;
|
||||
if (newlyOpened)
|
||||
{
|
||||
status = gvfg_set_channel_zero_copy_enabled(handle_, channel, zeroCopyEnabled ? 1 : 0);
|
||||
if (status != GVFG_OK)
|
||||
{
|
||||
reportError(QStringLiteral("gvfg_set_channel_zero_copy_enabled"), status, channel);
|
||||
return false;
|
||||
}
|
||||
status = gvfg_open_channel(handle_, selectedDeviceIndex_, channel);
|
||||
if (status != GVFG_OK)
|
||||
{
|
||||
reportError(QStringLiteral("gvfg_open_channel"), status, channel);
|
||||
return false;
|
||||
}
|
||||
runtime.opened = true;
|
||||
}
|
||||
|
||||
status = gvfg_set_channel_audio_enabled(
|
||||
handle_, channel, runtime.requestedAudio ? 1 : 0);
|
||||
if (status != GVFG_OK)
|
||||
{
|
||||
reportError(QStringLiteral("gvfg_set_channel_zero_copy_enabled"), status, channel);
|
||||
reportError(QStringLiteral("gvfg_set_channel_audio_enabled"), status, channel);
|
||||
return false;
|
||||
}
|
||||
status = gvfg_open_channel(handle_, selectedDeviceIndex_, channel);
|
||||
if (status != GVFG_OK)
|
||||
{
|
||||
reportError(QStringLiteral("gvfg_open_channel"), status, channel);
|
||||
return false;
|
||||
}
|
||||
runtime.opened = true;
|
||||
if (!applyOutputFormat(channel))
|
||||
return false;
|
||||
|
||||
appendLog(QStringLiteral("Opened device index %1 CH%2 | mode=%3")
|
||||
.arg(selectedDeviceIndex_)
|
||||
.arg(channel)
|
||||
.arg(zeroCopyEnabled ? QStringLiteral("zero-copy") : QStringLiteral("copy")));
|
||||
updateSignalStatus();
|
||||
if (newlyOpened)
|
||||
{
|
||||
refreshSdiInfo(channel);
|
||||
appendLog(QStringLiteral("Opened device index %1 CH%2 | mode=%3")
|
||||
.arg(selectedDeviceIndex_)
|
||||
.arg(channel)
|
||||
.arg(zeroCopyEnabled ? QStringLiteral("zero-copy") : QStringLiteral("copy")));
|
||||
updateSignalStatus();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -270,7 +257,7 @@ bool CaptureController::applyOutputFormat(int channel)
|
||||
reportError(QStringLiteral("gvfg_set_channel_video_format"), status, channel);
|
||||
return false;
|
||||
}
|
||||
appendLog(QStringLiteral("CH%1 Output format | %2 (GigabyteLib extension)")
|
||||
appendLog(QStringLiteral("CH%1 Output format | %2")
|
||||
.arg(channel)
|
||||
.arg(format == GVFG_PIXFMT_Y210 ? QStringLiteral("Y210") : QStringLiteral("YUY2")));
|
||||
return true;
|
||||
@@ -300,12 +287,14 @@ void CaptureController::closeDevice()
|
||||
|
||||
emit statusChanged(QStringLiteral("Idle"));
|
||||
lastSignalStatusText_.clear();
|
||||
emit sdiInfoChanged(QStringLiteral("SDI Info: --"));
|
||||
selectedDeviceIndex_ = -1;
|
||||
for (ChannelRuntime &channel : channels_)
|
||||
{
|
||||
channel.opened = false;
|
||||
channel.cachedSignalStatus = {};
|
||||
channel.haveCachedSignalStatus = false;
|
||||
channel.cachedSdiInfoText.clear();
|
||||
channel.lastLoggedInputStatus.clear();
|
||||
}
|
||||
emit stateChanged();
|
||||
@@ -320,10 +309,10 @@ void CaptureController::startCapture(int channelIndex)
|
||||
if (!openChannel(channelIndex))
|
||||
return;
|
||||
|
||||
// Consume queued signal events first. gvfg_start_channel() performs the
|
||||
// single authoritative hardware revalidation; preview setup reuses the
|
||||
// most recent UI cache instead of issuing another register query here.
|
||||
// Consume queued events, then query the current Lib signal state once for
|
||||
// this explicit Start request. The periodic UI update only uses the cache.
|
||||
processPendingEvents();
|
||||
updateSignalStatus();
|
||||
if (!channel.haveCachedSignalStatus || !channel.cachedSignalStatus.connected)
|
||||
{
|
||||
appendLog(QStringLiteral("CH%1 [LIB] No input signal; start skipped").arg(channelIndex));
|
||||
@@ -331,19 +320,14 @@ void CaptureController::startCapture(int channelIndex)
|
||||
}
|
||||
|
||||
const bool audioEnabled = channel.requestedAudio;
|
||||
gvfg_status_t st = gvfg_set_channel_audio_enabled(handle_, channelIndex, audioEnabled ? 1 : 0);
|
||||
if (st != GVFG_OK)
|
||||
{
|
||||
reportError(QStringLiteral("gvfg_set_channel_audio_enabled"), st, channelIndex);
|
||||
return;
|
||||
}
|
||||
channel.audioFormat = {};
|
||||
if (audioEnabled)
|
||||
{
|
||||
st = gvfg_get_channel_audio_format(handle_, channelIndex, &channel.audioFormat);
|
||||
if (st != GVFG_OK)
|
||||
const gvfg_status_t audioStatus =
|
||||
gvfg_get_channel_audio_format(handle_, channelIndex, &channel.audioFormat);
|
||||
if (audioStatus != GVFG_OK)
|
||||
{
|
||||
reportError(QStringLiteral("gvfg_get_channel_audio_format"), st, channelIndex);
|
||||
reportError(QStringLiteral("gvfg_get_channel_audio_format"), audioStatus, channelIndex);
|
||||
return;
|
||||
}
|
||||
if (channel.audioFormat.channels == 0 || channel.audioFormat.sample_rate == 0 ||
|
||||
@@ -388,7 +372,7 @@ void CaptureController::startCapture(int channelIndex)
|
||||
return;
|
||||
}
|
||||
channel.startupStartTime = std::chrono::steady_clock::now();
|
||||
st = gvfg_start_channel(handle_, channelIndex);
|
||||
const gvfg_status_t st = gvfg_start_channel(handle_, channelIndex);
|
||||
const auto startupStartCallEnd = std::chrono::steady_clock::now();
|
||||
channel.startupStartCallMs =
|
||||
std::chrono::duration<double, std::milli>(
|
||||
@@ -409,8 +393,7 @@ void CaptureController::startCapture(int channelIndex)
|
||||
channel.getFrameWindowMaximumMs.store(0.0, std::memory_order_relaxed);
|
||||
channel.getFrameSamples.store(0, std::memory_order_relaxed);
|
||||
channel.audioEnabled = audioEnabled;
|
||||
channel.videoReceived = 0; channel.videoSubmitted = 0;
|
||||
channel.videoSkipped = 0; channel.videoFailed = 0;
|
||||
channel.videoReceived = 0; channel.videoFailed = 0;
|
||||
channel.lastLoggedPreviewFailures = 0;
|
||||
channel.lastLoggedAudioReleaseFailures = channel.lastLoggedAudioOutputFailures = 0;
|
||||
channel.lastDeliveryLogMs = 0;
|
||||
@@ -421,8 +404,7 @@ void CaptureController::startCapture(int channelIndex)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(channel.audioQueueMutex);
|
||||
channel.audioQueue.clear();
|
||||
channel.audioReceivedFrames = channel.audioOutputFrames = 0;
|
||||
channel.audioDroppedFrames = channel.audioCancelledFrames = 0;
|
||||
channel.audioReceivedFrames = 0;
|
||||
channel.audioReleaseFailedFrames = channel.audioOutputFailedFrames = 0;
|
||||
}
|
||||
channel.signalConnected.store(channel.cachedSignalStatus.connected != 0,
|
||||
@@ -529,31 +511,63 @@ void CaptureController::processPendingEvents()
|
||||
while (gvfg_poll_channel_event(handle_, channel, &event, 0) == GVFG_OK)
|
||||
{
|
||||
const auto eventType = static_cast<gvfg_event_type_t>(event.type);
|
||||
if (eventType != GVFG_EVENT_STREAM_READY)
|
||||
appendLog(QStringLiteral("CH%1 [LIB] Event | %2").arg(channel).arg(eventTypeText(eventType)));
|
||||
appendLog(QStringLiteral("CH%1 [LIB] Event | %2").arg(channel).arg(eventTypeText(eventType)));
|
||||
|
||||
if (eventType == GVFG_EVENT_SIGNAL_CONNECTED ||
|
||||
eventType == GVFG_EVENT_SIGNAL_DISCONNECTED ||
|
||||
eventType == GVFG_EVENT_FORMAT_CHANGE_BEGIN ||
|
||||
eventType == GVFG_EVENT_STREAM_READY)
|
||||
if (eventType == GVFG_EVENT_VIDEO_FORMAT_CHANGED ||
|
||||
eventType == GVFG_EVENT_VIDEO_INPUT_PLUGIN ||
|
||||
eventType == GVFG_EVENT_VIDEO_INPUT_UNPLUG)
|
||||
updateSignalStatus();
|
||||
|
||||
if (eventType == GVFG_EVENT_SIGNAL_DISCONNECTED)
|
||||
if (eventType == GVFG_EVENT_VIDEO_INPUT_UNPLUG)
|
||||
{
|
||||
channels_[channel].signalConnected.store(false, std::memory_order_release);
|
||||
else if (eventType == GVFG_EVENT_SIGNAL_CONNECTED ||
|
||||
eventType == GVFG_EVENT_STREAM_READY)
|
||||
}
|
||||
else if (eventType == GVFG_EVENT_VIDEO_INPUT_PLUGIN)
|
||||
{
|
||||
channels_[channel].signalConnected.store(true, std::memory_order_release);
|
||||
channels_[channel].signalReady.notify_all();
|
||||
}
|
||||
|
||||
if (eventType == GVFG_EVENT_SIGNAL_DISCONNECTED && channels_[channel].previewHandle)
|
||||
if (eventType == GVFG_EVENT_VIDEO_INPUT_PLUGIN ||
|
||||
eventType == GVFG_EVENT_VIDEO_INPUT_UNPLUG ||
|
||||
eventType == GVFG_EVENT_VIDEO_FORMAT_CHANGED)
|
||||
refreshSdiInfo(channel);
|
||||
|
||||
if (eventType == GVFG_EVENT_VIDEO_INPUT_UNPLUG && channels_[channel].previewHandle)
|
||||
gvfg_preview_clear(channels_[channel].previewHandle);
|
||||
|
||||
event = {};
|
||||
event.struct_size = sizeof(event);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CaptureController::refreshSdiInfo(int channel)
|
||||
{
|
||||
gvfg_sdi_info_t info{};
|
||||
if (gvfg_get_channel_sdi_info(handle_, channel, &info) != GVFG_OK)
|
||||
return;
|
||||
|
||||
const QString text = QStringLiteral("CH%1 SDI Info | %2 | %3 | %4 | %5 | %6 | %7 | %8 | %9 | %10 | ErrorCount=%11")
|
||||
.arg(channel)
|
||||
.arg(QString::fromUtf8(info.signal_lock_name))
|
||||
.arg(QString::fromUtf8(info.mode_name))
|
||||
.arg(QString::fromUtf8(info.resolution_name))
|
||||
.arg(QString::fromUtf8(info.fps_name))
|
||||
.arg(QString::fromUtf8(info.scan_name))
|
||||
.arg(QString::fromUtf8(info.st352_format_name))
|
||||
.arg(QString::fromUtf8(info.st352_fps_name))
|
||||
.arg(QString::fromUtf8(info.st352_chroma_name))
|
||||
.arg(QString::fromUtf8(info.st352_bit_depth_name))
|
||||
.arg(info.error_count);
|
||||
|
||||
ChannelRuntime &runtime = channels_[channel];
|
||||
if (runtime.cachedSdiInfoText == text)
|
||||
return;
|
||||
runtime.cachedSdiInfoText = text;
|
||||
if (channel == GVFG_CHANNEL_0)
|
||||
emit sdiInfoChanged(text);
|
||||
}
|
||||
|
||||
void CaptureController::updateSignalStatus(bool queryHardware)
|
||||
@@ -593,11 +607,14 @@ void CaptureController::updateSignalStatus(bool queryHardware)
|
||||
|
||||
const gvfg_signal_status_t &signal = channel.cachedSignalStatus;
|
||||
const QString inputStatus = signal.connected
|
||||
? QStringLiteral("CH%1 Connected | %2").arg(channelIndex).arg(signalFrameText(signal))
|
||||
: QStringLiteral("CH%1 No signal").arg(channelIndex);
|
||||
? QStringLiteral("CH%1 [LIB] GVFG_VIDEO_INFO.VideoSignalLock=1 | Video Locked | %2")
|
||||
.arg(channelIndex)
|
||||
.arg(signalFrameText(signal))
|
||||
: QStringLiteral("CH%1 [LIB] GVFG_VIDEO_INFO.VideoSignalLock=0 | Video Undetected")
|
||||
.arg(channelIndex);
|
||||
if (inputStatus != channel.lastLoggedInputStatus)
|
||||
{
|
||||
appendLog(QStringLiteral("[LIB] Input status | %1").arg(inputStatus));
|
||||
appendLog(inputStatus);
|
||||
channel.lastLoggedInputStatus = inputStatus;
|
||||
}
|
||||
if (channel.previewVisible.load(std::memory_order_acquire) && signal.width > 0 && signal.height > 0)
|
||||
@@ -610,9 +627,6 @@ void CaptureController::updateSignalStatus(bool queryHardware)
|
||||
gvfg_preview_stats_t previewStats{};
|
||||
const bool previewStatsOk = channel.previewHandle &&
|
||||
gvfg_preview_get_stats(channel.previewHandle, &previewStats) == GVFG_PREVIEW_OK;
|
||||
gvfg_preview_delivery_stats_t previewDelivery{};
|
||||
const bool previewDeliveryOk = channel.previewHandle &&
|
||||
gvfg_preview_get_delivery_stats(channel.previewHandle, &previewDelivery) == GVFG_PREVIEW_OK;
|
||||
const QString previewFps = previewStatsOk && previewStats.present_fps > 0.0
|
||||
? QString::number(previewStats.present_fps, 'f', 2)
|
||||
: QStringLiteral("--");
|
||||
@@ -641,21 +655,15 @@ void CaptureController::updateSignalStatus(bool queryHardware)
|
||||
.arg(channel.audioFormat.bits_per_sample)
|
||||
.arg(static_cast<qulonglong>(receivedFrames));
|
||||
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||
uint64_t appOutputFrames = 0;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(channel.audioQueueMutex);
|
||||
appOutputFrames = channel.audioOutputFrames;
|
||||
}
|
||||
gvfg_debug_backend_stats_t audioStats{};
|
||||
if (gvfg_debug_get_channel_backend_stats(handle_, channelIndex, &audioStats) == GVFG_OK)
|
||||
{
|
||||
statusLines << QStringLiteral("CH%1 Audio Debug | LIB events DMA=%2 Extra=%3 | LIB->SDK %4 frames | SDK->APP %5 frames | APP->Output %6 frames")
|
||||
statusLines << QStringLiteral("CH%1 Audio Debug | LIB events DMA=%2 Extra=%3 | LIB->SDK %4 frames | SDK->APP %5 frames")
|
||||
.arg(channelIndex)
|
||||
.arg(static_cast<qulonglong>(audioStats.audio_dma_event_wakes - channel.backendBaseline.audio_dma_event_wakes))
|
||||
.arg(static_cast<qulonglong>(audioStats.extra_audio_event_wakes - channel.backendBaseline.extra_audio_event_wakes))
|
||||
.arg(static_cast<qulonglong>(audioStats.audio_frames_from_lib - channel.backendBaseline.audio_frames_from_lib))
|
||||
.arg(static_cast<qulonglong>(receivedFrames))
|
||||
.arg(static_cast<qulonglong>(appOutputFrames));
|
||||
.arg(static_cast<qulonglong>(receivedFrames));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -688,14 +696,12 @@ void CaptureController::updateSignalStatus(bool queryHardware)
|
||||
.arg(channelStats.get_frame_timing_max_us, 0, 'f', 3)
|
||||
.arg(static_cast<qulonglong>(channelStats.get_frame_timing_samples))
|
||||
: QStringLiteral("CH%1 [LIB] GetVideoFrame | measuring").arg(channelIndex));
|
||||
statusLines << QStringLiteral("CH%1 Video Debug | LIB events=%2 | LIB->SDK %3 frames | SDK->APP %4 frames | APP->Preview %5 frames | Preview->DXGI %6 frames")
|
||||
statusLines << QStringLiteral("CH%1 Video Debug | LIB events DMA=%2 Extra=%3 | LIB->SDK %4 frames | SDK->APP %5 frames")
|
||||
.arg(channelIndex)
|
||||
.arg(static_cast<qulonglong>(channelStats.video_event_wakes - channel.backendBaseline.video_event_wakes))
|
||||
.arg(static_cast<qulonglong>(channelStats.video_dma_event_wakes - channel.backendBaseline.video_dma_event_wakes))
|
||||
.arg(static_cast<qulonglong>(channelStats.extra_video_event_wakes - channel.backendBaseline.extra_video_event_wakes))
|
||||
.arg(static_cast<qulonglong>(channelStats.video_frames_from_lib - channel.backendBaseline.video_frames_from_lib))
|
||||
.arg(static_cast<qulonglong>(channel.videoReceived.load()))
|
||||
.arg(static_cast<qulonglong>(channel.videoSubmitted.load()))
|
||||
.arg(static_cast<qulonglong>(previewDeliveryOk
|
||||
? previewDelivery.presented - channel.previewBaseline.presented : 0));
|
||||
.arg(static_cast<qulonglong>(channel.videoReceived.load()));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -717,10 +723,11 @@ void CaptureController::reportError(const QString &apiName, gvfg_status_t status
|
||||
.arg(apiName, QString::fromUtf8(gvfg_strerror(status)));
|
||||
if (channel == GVFG_CHANNEL_0 || channel == GVFG_CHANNEL_1)
|
||||
message.prepend(QStringLiteral("CH%1 ").arg(channel));
|
||||
if (handle_ != nullptr && (channel == GVFG_CHANNEL_0 || channel == GVFG_CHANNEL_1))
|
||||
if (status < 0 && handle_ != nullptr &&
|
||||
(channel == GVFG_CHANNEL_0 || channel == GVFG_CHANNEL_1))
|
||||
{
|
||||
char detail[512] = {};
|
||||
if (gvfg_get_channel_last_error_detail(handle_, channel, detail, sizeof(detail)) == GVFG_OK &&
|
||||
if (gvfg_get_channel_last_sdk_error_detail(handle_, channel, detail, sizeof(detail)) == GVFG_OK &&
|
||||
detail[0] != '\0')
|
||||
message += QStringLiteral(" | %1").arg(QString::fromUtf8(detail));
|
||||
}
|
||||
@@ -729,116 +736,13 @@ void CaptureController::reportError(const QString &apiName, gvfg_status_t status
|
||||
|
||||
void CaptureController::appendLog(const QString &message)
|
||||
{
|
||||
const QString timestamp = QDateTime::currentDateTime().toString(QStringLiteral("HH:mm:ss.zzz"));
|
||||
const QStringList lines = message.split(QLatin1Char('\n'));
|
||||
for (int i = 0; i < lines.size(); ++i)
|
||||
{
|
||||
const QString line = QStringLiteral("[%1] %2%3")
|
||||
.arg(timestamp, i == 0 ? QString() : QStringLiteral(" "), lines.at(i));
|
||||
writeLogFileLine(line);
|
||||
emit logMessage(line);
|
||||
}
|
||||
}
|
||||
|
||||
void CaptureController::openLogFile()
|
||||
{
|
||||
logSessionStamp_ = QDateTime::currentDateTime().toString(QStringLiteral("yyyyMMdd_HHmmss"));
|
||||
logPartIndex_ = 1;
|
||||
logDirPath_ = QCoreApplication::applicationDirPath() + QStringLiteral("/logs");
|
||||
if (!QDir().mkpath(logDirPath_))
|
||||
{
|
||||
logFilePath_ = logDirPath_;
|
||||
return;
|
||||
}
|
||||
|
||||
openLogFilePart();
|
||||
}
|
||||
|
||||
bool CaptureController::openLogFilePart()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logFileMutex_);
|
||||
if (logFile_.isOpen())
|
||||
logFile_.close();
|
||||
|
||||
logFilePath_ = QStringLiteral("%1/%2_%3_part%4.log")
|
||||
.arg(logDirPath_, logFilePrefix(), logSessionStamp_)
|
||||
.arg(logPartIndex_, 2, 10, QLatin1Char('0'));
|
||||
logFile_.setFileName(logFilePath_);
|
||||
if (!logFile_.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
|
||||
return false;
|
||||
|
||||
const QString header = QStringLiteral("\n==== %1 session %2 part %3 ====\n")
|
||||
.arg(logFilePrefix(),
|
||||
QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-dd HH:mm:ss.zzz")))
|
||||
.arg(logPartIndex_);
|
||||
logFile_.write(header.toUtf8());
|
||||
logFile_.flush();
|
||||
return true;
|
||||
}
|
||||
|
||||
void CaptureController::rotateLogFileIfNeeded()
|
||||
{
|
||||
if (!logFile_.isOpen() || logFile_.size() < kMaxLogFileBytes)
|
||||
return;
|
||||
|
||||
const QString footer = QStringLiteral("==== log rotated at %1 ====\n")
|
||||
.arg(QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-dd HH:mm:ss.zzz")));
|
||||
logFile_.write(footer.toUtf8());
|
||||
logFile_.flush();
|
||||
++logPartIndex_;
|
||||
openLogFilePart();
|
||||
}
|
||||
|
||||
void CaptureController::writeLogFileLine(const QString &line)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(logFileMutex_);
|
||||
if (!logFile_.isOpen())
|
||||
return;
|
||||
|
||||
if (logFile_.size() >= kMaxLogFileBytes)
|
||||
{
|
||||
const QString footer = QStringLiteral("==== log rotated at %1 ====\n")
|
||||
.arg(QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-dd HH:mm:ss.zzz")));
|
||||
logFile_.write(footer.toUtf8());
|
||||
logFile_.flush();
|
||||
++logPartIndex_;
|
||||
if (logFile_.isOpen())
|
||||
logFile_.close();
|
||||
logFilePath_ = QStringLiteral("%1/%2_%3_part%4.log")
|
||||
.arg(logDirPath_, logFilePrefix(), logSessionStamp_)
|
||||
.arg(logPartIndex_, 2, 10, QLatin1Char('0'));
|
||||
logFile_.setFileName(logFilePath_);
|
||||
if (logFile_.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text))
|
||||
{
|
||||
const QString header = QStringLiteral("\n==== %1 session %2 part %3 ====\n")
|
||||
.arg(logFilePrefix(),
|
||||
QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-dd HH:mm:ss.zzz")))
|
||||
.arg(logPartIndex_);
|
||||
logFile_.write(header.toUtf8());
|
||||
}
|
||||
}
|
||||
|
||||
if (!logFile_.isOpen())
|
||||
return;
|
||||
|
||||
logFile_.write(line.toUtf8());
|
||||
logFile_.write("\n");
|
||||
logFile_.flush();
|
||||
emit logMessage(message);
|
||||
}
|
||||
|
||||
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||
void CaptureController::writeDiagnosticSnapshot(const QString &statusText)
|
||||
{
|
||||
const QString timestamp = QDateTime::currentDateTime().toString(QStringLiteral("HH:mm:ss.zzz"));
|
||||
const QStringList lines = statusText.split(QLatin1Char('\n'));
|
||||
for (int i = 0; i < lines.size(); ++i)
|
||||
{
|
||||
const QString line = QStringLiteral("[%1] %2%3")
|
||||
.arg(timestamp,
|
||||
i == 0 ? QStringLiteral("Diagnostic | ") : QStringLiteral(" "),
|
||||
lines.at(i));
|
||||
writeLogFileLine(line);
|
||||
}
|
||||
emit diagnosticMessage(statusText);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -860,25 +764,10 @@ void CaptureController::logDeliveryStatus(int channelIndex, bool finalSnapshot)
|
||||
const auto &b = c.previewBaseline;
|
||||
const uint64_t failed = (previewOk ? p.failed - b.failed : 0) + c.videoFailed.load();
|
||||
uint64_t audioReleaseFailed, audioOutputFailed;
|
||||
bool audioAccounted;
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(c.audioQueueMutex);
|
||||
audioReleaseFailed = c.audioReleaseFailedFrames;
|
||||
audioOutputFailed = c.audioOutputFailedFrames;
|
||||
audioAccounted = c.audioQueue.empty() && c.audioReceivedFrames ==
|
||||
c.audioOutputFrames + c.audioDroppedFrames + c.audioCancelledFrames +
|
||||
c.audioReleaseFailedFrames + c.audioOutputFailedFrames;
|
||||
}
|
||||
if (finalSnapshot)
|
||||
{
|
||||
const bool videoAccounted = previewOk && c.videoReceived.load() ==
|
||||
c.videoSubmitted.load() + c.videoSkipped.load() + c.videoFailed.load() &&
|
||||
c.videoSubmitted.load() == p.submitted - b.submitted;
|
||||
if (!videoAccounted || !audioAccounted)
|
||||
appendLog(QStringLiteral("CH%1 [APP] ERROR accounting mismatch | video=%2 audio=%3")
|
||||
.arg(QString::number(channelIndex),
|
||||
videoAccounted ? QStringLiteral("OK") : QStringLiteral("MISMATCH"),
|
||||
audioAccounted ? QStringLiteral("OK") : QStringLiteral("MISMATCH")));
|
||||
}
|
||||
// Also flush any changes since the last aggregate when stopping.
|
||||
if (failed != c.lastLoggedPreviewFailures)
|
||||
@@ -1029,7 +918,6 @@ void CaptureController::captureReadLoop(int channelIndex)
|
||||
}
|
||||
else
|
||||
{
|
||||
++channel.videoSubmitted;
|
||||
if (!startupLatencyLogged)
|
||||
{
|
||||
startupLatencyLogged = true;
|
||||
@@ -1073,8 +961,6 @@ void CaptureController::captureReadLoop(int channelIndex)
|
||||
}
|
||||
if (!channel.previewHandle)
|
||||
++channel.videoFailed;
|
||||
else if (!attemptedPreview)
|
||||
++channel.videoSkipped;
|
||||
const gvfg_status_t releaseStatus = gvfg_release_channel_frame(handle_, channelIndex, &frame);
|
||||
if (releaseStatus != GVFG_OK)
|
||||
{
|
||||
@@ -1194,15 +1080,9 @@ void CaptureController::audioReadLoop(int channelIndex)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(channel.audioQueueMutex);
|
||||
if (channel.stopRequested.load(std::memory_order_acquire))
|
||||
{
|
||||
++channel.audioCancelledFrames;
|
||||
break;
|
||||
}
|
||||
if (channel.audioQueue.size() >= kMaxQueuedAudioFrames)
|
||||
{
|
||||
++channel.audioDroppedFrames;
|
||||
channel.audioQueue.pop_front();
|
||||
}
|
||||
channel.audioQueue.push_back({std::move(pcm)});
|
||||
}
|
||||
channel.audioQueueReady.notify_one();
|
||||
@@ -1247,10 +1127,7 @@ void CaptureController::audioPlaybackLoop(int channelIndex)
|
||||
recovering = true;
|
||||
std::unique_lock<std::mutex> lock(channel.audioQueueMutex);
|
||||
while (!channel.audioQueue.empty())
|
||||
{
|
||||
++channel.audioDroppedFrames;
|
||||
channel.audioQueue.pop_front();
|
||||
}
|
||||
channel.audioQueueReady.wait_for(lock, std::chrono::milliseconds(500), [&channel]() {
|
||||
return channel.stopRequested.load(std::memory_order_acquire);
|
||||
});
|
||||
@@ -1268,10 +1145,7 @@ void CaptureController::audioPlaybackLoop(int channelIndex)
|
||||
recovering = true;
|
||||
std::unique_lock<std::mutex> lock(channel.audioQueueMutex);
|
||||
while (!channel.audioQueue.empty())
|
||||
{
|
||||
++channel.audioDroppedFrames;
|
||||
channel.audioQueue.pop_front();
|
||||
}
|
||||
channel.audioQueueReady.wait_for(lock, std::chrono::milliseconds(500), [&channel]() {
|
||||
return channel.stopRequested.load(std::memory_order_acquire);
|
||||
});
|
||||
@@ -1331,16 +1205,6 @@ void CaptureController::audioPlaybackLoop(int channelIndex)
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
}
|
||||
if (written != static_cast<qint64>(pcm.size()) && !restartPlayback)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(channel.audioQueueMutex);
|
||||
++channel.audioCancelledFrames;
|
||||
}
|
||||
else if (written == static_cast<qint64>(pcm.size()))
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(channel.audioQueueMutex);
|
||||
++channel.audioOutputFrames;
|
||||
}
|
||||
}
|
||||
audioSink.stop();
|
||||
if (restartPlayback)
|
||||
@@ -1348,10 +1212,7 @@ void CaptureController::audioPlaybackLoop(int channelIndex)
|
||||
recovering = true;
|
||||
std::unique_lock<std::mutex> lock(channel.audioQueueMutex);
|
||||
while (!channel.audioQueue.empty())
|
||||
{
|
||||
++channel.audioDroppedFrames;
|
||||
channel.audioQueue.pop_front();
|
||||
}
|
||||
channel.audioQueueReady.wait_for(lock, std::chrono::milliseconds(500), [&channel]() {
|
||||
return channel.stopRequested.load(std::memory_order_acquire);
|
||||
});
|
||||
@@ -1367,6 +1228,5 @@ void CaptureController::joinAudioThread(int channel)
|
||||
if (channels_[channel].audioPlaybackThread.joinable())
|
||||
channels_[channel].audioPlaybackThread.join();
|
||||
std::lock_guard<std::mutex> lock(channels_[channel].audioQueueMutex);
|
||||
channels_[channel].audioCancelledFrames += channels_[channel].audioQueue.size();
|
||||
channels_[channel].audioQueue.clear();
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <gvfg_debug.h>
|
||||
#include <gvfg_preview.h>
|
||||
|
||||
#include <QFile>
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
|
||||
@@ -40,14 +39,10 @@ public:
|
||||
bool frameAvailable(int channel) const;
|
||||
bool cachedSignalStatus(int channel, gvfg_signal_status_t *status) const;
|
||||
QString sdkVersion() const;
|
||||
void logStartupInfo();
|
||||
void logUiMessage(const QString &message);
|
||||
|
||||
public slots:
|
||||
void refreshDevices();
|
||||
bool openDevice();
|
||||
void closeDevice();
|
||||
bool applyOutputFormat(int channel);
|
||||
void startCapture(int channel);
|
||||
void stopCapture(int channel);
|
||||
void stopAllCaptures();
|
||||
@@ -59,12 +54,17 @@ signals:
|
||||
void devicesChanged(const QStringList &names);
|
||||
void stateChanged();
|
||||
void statusChanged(const QString &text);
|
||||
void sdiInfoChanged(const QString &text);
|
||||
void logMessage(const QString &message);
|
||||
void diagnosticMessage(const QString &message);
|
||||
void previewSourceSizeChanged(int channel, int width, int height);
|
||||
void previewShowRequested(int channel);
|
||||
void previewCloseRequested(int channel);
|
||||
|
||||
private:
|
||||
bool openDevice();
|
||||
bool applyOutputFormat(int channel);
|
||||
|
||||
struct ChannelRuntime
|
||||
{
|
||||
struct AudioPacket { std::vector<uint8_t> pcm; };
|
||||
@@ -84,10 +84,9 @@ private:
|
||||
std::deque<AudioPacket> audioQueue;
|
||||
bool audioEnabled = false;
|
||||
gvfg_audio_format_t audioFormat{};
|
||||
uint64_t audioReceivedFrames = 0, audioOutputFrames = 0;
|
||||
uint64_t audioDroppedFrames = 0, audioCancelledFrames = 0;
|
||||
uint64_t audioReceivedFrames = 0;
|
||||
uint64_t audioReleaseFailedFrames = 0, audioOutputFailedFrames = 0;
|
||||
std::atomic<uint64_t> videoReceived{0}, videoSubmitted{0}, videoSkipped{0}, videoFailed{0};
|
||||
std::atomic<uint64_t> videoReceived{0}, videoFailed{0};
|
||||
gvfg_preview_delivery_stats_t previewBaseline{};
|
||||
gvfg_debug_backend_stats_t backendBaseline{};
|
||||
std::chrono::steady_clock::time_point startupStartTime{};
|
||||
@@ -100,16 +99,14 @@ private:
|
||||
uint64_t previewFailureCount = 0;
|
||||
gvfg_signal_status_t cachedSignalStatus{};
|
||||
bool haveCachedSignalStatus = false;
|
||||
QString cachedSdiInfoText;
|
||||
QString lastLoggedInputStatus;
|
||||
};
|
||||
|
||||
void reportError(const QString &apiName, gvfg_status_t status, int channel = -1);
|
||||
void appendLog(const QString &message);
|
||||
bool openChannel(int channel);
|
||||
void openLogFile();
|
||||
bool openLogFilePart();
|
||||
void rotateLogFileIfNeeded();
|
||||
void writeLogFileLine(const QString &line);
|
||||
void refreshSdiInfo(int channel);
|
||||
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||
void writeDiagnosticSnapshot(const QString &statusText);
|
||||
#endif
|
||||
@@ -120,7 +117,6 @@ private:
|
||||
void joinAudioThread(int channel);
|
||||
void logDeliveryStatus(int channel, bool finalSnapshot = false);
|
||||
|
||||
static constexpr qint64 kMaxLogFileBytes = 20ll * 1024ll * 1024ll;
|
||||
std::array<gvfg_device_info_t, GVFG_MAX_DEVICES> devices_{};
|
||||
int deviceCount_ = 0;
|
||||
gvfg_handle handle_ = nullptr;
|
||||
@@ -129,8 +125,4 @@ private:
|
||||
std::array<bool, 2> channelStatusVisible_{{true, true}};
|
||||
QTimer *runtimeStatusTimer_ = nullptr;
|
||||
QString lastSignalStatusText_;
|
||||
QFile logFile_;
|
||||
std::mutex logFileMutex_;
|
||||
QString logDirPath_, logFilePath_, logSessionStamp_;
|
||||
int logPartIndex_ = 1;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "mainwindow.h"
|
||||
#include "capture_controller.h"
|
||||
#include "previewwindow.h"
|
||||
#include "sample_log.h"
|
||||
#include "ui_mainwindow.h"
|
||||
|
||||
#include <QCloseEvent>
|
||||
@@ -24,14 +25,15 @@ public:
|
||||
protected:
|
||||
void highlightBlock(const QString &text) override
|
||||
{
|
||||
if (text.contains(QStringLiteral("SIGNAL_DISCONNECTED")) ||
|
||||
if (text.contains(QStringLiteral("VIDEO_INPUT_UNPLUG")) ||
|
||||
text.contains(QStringLiteral("No signal"), Qt::CaseInsensitive) ||
|
||||
text.contains(QStringLiteral("Video Undetected"), Qt::CaseInsensitive) ||
|
||||
text.contains(QStringLiteral("failed"), Qt::CaseInsensitive) ||
|
||||
text.contains(QStringLiteral("error"), Qt::CaseInsensitive))
|
||||
setFormat(0, text.size(), error_);
|
||||
else if (text.contains(QStringLiteral("warning"), Qt::CaseInsensitive))
|
||||
setFormat(0, text.size(), warning_);
|
||||
else if (text.contains(QStringLiteral("SIGNAL_CONNECTED")) ||
|
||||
else if (text.contains(QStringLiteral("VIDEO_INPUT_PLUGIN")) ||
|
||||
text.contains(QStringLiteral("recovered"), Qt::CaseInsensitive))
|
||||
setFormat(0, text.size(), recovery_);
|
||||
}
|
||||
@@ -41,7 +43,8 @@ private:
|
||||
}
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent)
|
||||
: QWidget(parent), ui_(new Ui::MainWindow), controller_(new CaptureController(this))
|
||||
: QWidget(parent), ui_(new Ui::MainWindow), controller_(new CaptureController(this)),
|
||||
log_(new SampleLog(this))
|
||||
{
|
||||
ui_->setupUi(this);
|
||||
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||
@@ -71,7 +74,11 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
});
|
||||
connect(controller_, &CaptureController::stateChanged, this, &MainWindow::updateUiState);
|
||||
connect(controller_, &CaptureController::statusChanged, ui_->statusLabel, &QLabel::setText);
|
||||
connect(controller_, &CaptureController::logMessage, this, &MainWindow::appendLogLine);
|
||||
connect(controller_, &CaptureController::sdiInfoChanged, ui_->sdiInfoLabel, &QLabel::setText);
|
||||
connect(controller_, &CaptureController::logMessage, log_, &SampleLog::append, Qt::QueuedConnection);
|
||||
connect(controller_, &CaptureController::diagnosticMessage, log_, &SampleLog::appendDiagnostic,
|
||||
Qt::QueuedConnection);
|
||||
connect(log_, &SampleLog::lineReady, this, &MainWindow::appendLogLine);
|
||||
connect(controller_, &CaptureController::previewSourceSizeChanged, this,
|
||||
[this](int channel, int width, int height) {
|
||||
if (width > 0 && height > 0) previewWindows_[channel]->setSourceSize(width, height);
|
||||
@@ -85,14 +92,12 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
[this](int channel) { previewWindows_[channel]->closePreview(); });
|
||||
|
||||
connect(ui_->refreshButton, &QPushButton::clicked, controller_, &CaptureController::refreshDevices);
|
||||
connect(ui_->openButton, &QPushButton::clicked, this, [this] {
|
||||
if (controller_->deviceOpen()) controller_->closeDevice();
|
||||
else {
|
||||
syncControllerOptions(GVFG_CHANNEL_0);
|
||||
syncControllerOptions(GVFG_CHANNEL_1);
|
||||
controller_->setSelectedDeviceIndex(ui_->deviceCombo->currentData().toInt());
|
||||
controller_->openDevice();
|
||||
}
|
||||
connect(ui_->deviceCombo, &QComboBox::currentIndexChanged, this, [this](int) {
|
||||
const int selectedDevice = ui_->deviceCombo->currentData().toInt();
|
||||
if (controller_->deviceOpen())
|
||||
controller_->closeDevice();
|
||||
controller_->setSelectedDeviceIndex(selectedDevice);
|
||||
updateUiState();
|
||||
});
|
||||
connect(ui_->ch0StartButton, &QPushButton::clicked, this, [this] { syncControllerOptions(0); controller_->startCapture(0); });
|
||||
connect(ui_->ch1StartButton, &QPushButton::clicked, this, [this] { syncControllerOptions(1); controller_->startCapture(1); });
|
||||
@@ -106,24 +111,33 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
auto formatChanged = [this](int channel) {
|
||||
updateOutputFormatOptions(channel);
|
||||
syncControllerOptions(channel);
|
||||
if (controller_->channelOpened(channel) && !controller_->channelRunning(channel))
|
||||
{ controller_->applyOutputFormat(channel); controller_->updateSignalStatus(); }
|
||||
};
|
||||
connect(ui_->ch0OutputFormatCombo, &QComboBox::currentIndexChanged, this, [formatChanged](int) { formatChanged(0); });
|
||||
connect(ui_->ch1OutputFormatCombo, &QComboBox::currentIndexChanged, this, [formatChanged](int) { formatChanged(1); });
|
||||
|
||||
connect(ui_->ch0ZeroCopyCheckBox, &QCheckBox::toggled, this, [this](bool) {
|
||||
syncControllerOptions(GVFG_CHANNEL_0);
|
||||
if (controller_->deviceOpen()) controller_->updateSignalStatus(false);
|
||||
if (controller_->deviceOpen()) {
|
||||
const int selectedDevice = ui_->deviceCombo->currentData().toInt();
|
||||
controller_->closeDevice();
|
||||
controller_->setSelectedDeviceIndex(selectedDevice);
|
||||
}
|
||||
});
|
||||
connect(ui_->ch1ZeroCopyCheckBox, &QCheckBox::toggled, this, [this](bool) {
|
||||
syncControllerOptions(GVFG_CHANNEL_1);
|
||||
if (controller_->deviceOpen()) controller_->updateSignalStatus(false);
|
||||
if (controller_->deviceOpen()) {
|
||||
const int selectedDevice = ui_->deviceCombo->currentData().toInt();
|
||||
controller_->closeDevice();
|
||||
controller_->setSelectedDeviceIndex(selectedDevice);
|
||||
}
|
||||
});
|
||||
|
||||
updateOutputFormatOptions();
|
||||
updateUiState();
|
||||
controller_->logStartupInfo();
|
||||
log_->append(QStringLiteral("GVFG SDK version | %1").arg(controller_->sdkVersion()));
|
||||
log_->append(log_->fileAvailable()
|
||||
? QStringLiteral("Log file | %1").arg(log_->filePath())
|
||||
: QStringLiteral("Log file unavailable | %1").arg(log_->filePath()));
|
||||
controller_->refreshDevices();
|
||||
}
|
||||
|
||||
@@ -166,7 +180,7 @@ void MainWindow::showPreviewWindow(int channel, bool fullscreen)
|
||||
else previewWindows_[channel]->showPreview();
|
||||
controller_->setPreviewTarget(channel, previewWindows_[channel]->nativePreviewHandle());
|
||||
if (!controller_->applyPreview(channel))
|
||||
controller_->logUiMessage(
|
||||
log_->append(
|
||||
fullscreen
|
||||
? QStringLiteral("CH%1 [APP] Fullscreen preview failed | window update").arg(channel)
|
||||
: QStringLiteral("CH%1 [APP] Show preview failed | window update").arg(channel));
|
||||
@@ -188,20 +202,17 @@ void MainWindow::updateOutputFormatOptions(int changedChannel)
|
||||
if (model && model->item(y210)) model->item(y210)->setEnabled(enabled[channel]);
|
||||
combos[channel]->setToolTip(
|
||||
enabled[channel]
|
||||
? QStringLiteral("Requested CH%1 capture output format (GigabyteLib extension)").arg(channel)
|
||||
? QStringLiteral("Requested CH%1 capture output format").arg(channel)
|
||||
: QStringLiteral("Y210 is already selected by the other channel"));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::updateUiState()
|
||||
{
|
||||
const bool open = controller_->deviceOpen();
|
||||
const bool running[] = {controller_->channelRunning(0), controller_->channelRunning(1)};
|
||||
const bool anyRunning = running[0] || running[1];
|
||||
const bool selected = ui_->deviceCombo->currentData().toInt() >= 0;
|
||||
ui_->openButton->setText(open ? QStringLiteral("Close Device") : QStringLiteral("Open Device"));
|
||||
ui_->openButton->setEnabled(!anyRunning);
|
||||
ui_->refreshButton->setEnabled(!open); ui_->deviceCombo->setEnabled(!open);
|
||||
ui_->refreshButton->setEnabled(!anyRunning); ui_->deviceCombo->setEnabled(!anyRunning);
|
||||
ui_->ch0StartButton->setEnabled(selected && !running[0]); ui_->ch1StartButton->setEnabled(selected && !running[1]);
|
||||
ui_->ch0StopButton->setEnabled(running[0]); ui_->ch1StopButton->setEnabled(running[1]);
|
||||
ui_->ch0PreviewButton->setEnabled(running[0] && controller_->frameAvailable(0));
|
||||
@@ -209,8 +220,8 @@ void MainWindow::updateUiState()
|
||||
ui_->ch0FullscreenButton->setEnabled(ui_->ch0PreviewButton->isEnabled());
|
||||
ui_->ch1FullscreenButton->setEnabled(ui_->ch1PreviewButton->isEnabled());
|
||||
ui_->ch0OutputFormatCombo->setEnabled(!running[0]); ui_->ch1OutputFormatCombo->setEnabled(!running[1]);
|
||||
ui_->ch0ZeroCopyCheckBox->setEnabled(!controller_->channelOpened(0));
|
||||
ui_->ch1ZeroCopyCheckBox->setEnabled(!controller_->channelOpened(1));
|
||||
ui_->ch0ZeroCopyCheckBox->setEnabled(!anyRunning);
|
||||
ui_->ch1ZeroCopyCheckBox->setEnabled(!anyRunning);
|
||||
ui_->ch0AudioCheckBox->setEnabled(!running[0]);
|
||||
ui_->channel1GroupBox->setVisible(kChannel1UiVisible);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
class CaptureController;
|
||||
class QCloseEvent;
|
||||
class PreviewWindow;
|
||||
class SampleLog;
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
namespace Ui { class MainWindow; }
|
||||
@@ -33,6 +34,7 @@ private:
|
||||
|
||||
Ui::MainWindow *ui_ = nullptr;
|
||||
CaptureController *controller_ = nullptr;
|
||||
SampleLog *log_ = nullptr;
|
||||
std::array<PreviewWindow *, 2> previewWindows_{};
|
||||
};
|
||||
|
||||
|
||||
@@ -45,16 +45,19 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="openButton">
|
||||
<property name="text">
|
||||
<string>Open Device</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="sdiInfoLabel">
|
||||
<property name="text">
|
||||
<string>SDI Info: --</string>
|
||||
</property>
|
||||
<property name="wordWrap">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<layout class="QHBoxLayout" name="channelPanelsLayout" stretch="1,1">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="channel0GroupBox">
|
||||
@@ -219,14 +222,14 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="statusLabel">
|
||||
<property name="text">
|
||||
<string>Idle</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<item row="4" column="0">
|
||||
<widget class="QPlainTextEdit" name="logEdit">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
#include "sample_log.h"
|
||||
|
||||
#include <QCoreApplication>
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QStringList>
|
||||
|
||||
namespace
|
||||
{
|
||||
QString filePrefix()
|
||||
{
|
||||
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||
return QStringLiteral("gvfg_qt_preview_debug");
|
||||
#else
|
||||
return QStringLiteral("gvfg_qt_preview");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
SampleLog::SampleLog(QObject *parent) : QObject(parent)
|
||||
{
|
||||
sessionStamp_ = QDateTime::currentDateTime().toString(QStringLiteral("yyyyMMdd_HHmmss"));
|
||||
directoryPath_ = QCoreApplication::applicationDirPath() + QStringLiteral("/logs");
|
||||
if (QDir().mkpath(directoryPath_)) openPart();
|
||||
else filePath_ = directoryPath_;
|
||||
}
|
||||
|
||||
void SampleLog::append(const QString &message)
|
||||
{
|
||||
const QString timestamp = QDateTime::currentDateTime().toString(QStringLiteral("HH:mm:ss.zzz"));
|
||||
const QStringList lines = message.split(QLatin1Char('\n'));
|
||||
for (int i = 0; i < lines.size(); ++i)
|
||||
{
|
||||
const QString line = QStringLiteral("[%1] %2%3")
|
||||
.arg(timestamp, i == 0 ? QString() : QStringLiteral(" "), lines.at(i));
|
||||
writeLine(line);
|
||||
emit lineReady(line);
|
||||
}
|
||||
}
|
||||
|
||||
void SampleLog::appendDiagnostic(const QString &message)
|
||||
{
|
||||
const QString timestamp = QDateTime::currentDateTime().toString(QStringLiteral("HH:mm:ss.zzz"));
|
||||
const QStringList lines = message.split(QLatin1Char('\n'));
|
||||
for (int i = 0; i < lines.size(); ++i)
|
||||
writeLine(QStringLiteral("[%1] %2%3").arg(
|
||||
timestamp, i == 0 ? QStringLiteral("Diagnostic | ") : QStringLiteral(" "), lines.at(i)));
|
||||
}
|
||||
|
||||
bool SampleLog::openPart()
|
||||
{
|
||||
if (file_.isOpen()) file_.close();
|
||||
filePath_ = QStringLiteral("%1/%2_%3_part%4.log")
|
||||
.arg(directoryPath_, filePrefix(), sessionStamp_).arg(partIndex_, 2, 10, QLatin1Char('0'));
|
||||
file_.setFileName(filePath_);
|
||||
if (!file_.open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text)) return false;
|
||||
file_.write(QStringLiteral("\n==== %1 session %2 part %3 ====\n")
|
||||
.arg(filePrefix(), QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-dd HH:mm:ss.zzz")))
|
||||
.arg(partIndex_).toUtf8());
|
||||
file_.flush();
|
||||
return true;
|
||||
}
|
||||
|
||||
void SampleLog::writeLine(const QString &line)
|
||||
{
|
||||
if (!file_.isOpen()) return;
|
||||
if (file_.size() >= kMaxFileBytes)
|
||||
{
|
||||
file_.write(QStringLiteral("==== log rotated at %1 ====\n")
|
||||
.arg(QDateTime::currentDateTime().toString(QStringLiteral("yyyy-MM-dd HH:mm:ss.zzz"))).toUtf8());
|
||||
file_.flush();
|
||||
++partIndex_;
|
||||
if (!openPart()) return;
|
||||
}
|
||||
file_.write(line.toUtf8());
|
||||
file_.write("\n");
|
||||
file_.flush();
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
#pragma once
|
||||
|
||||
#include <QFile>
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
|
||||
class SampleLog final : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SampleLog(QObject *parent = nullptr);
|
||||
QString filePath() const { return filePath_; }
|
||||
bool fileAvailable() const { return file_.isOpen(); }
|
||||
|
||||
public slots:
|
||||
void append(const QString &message);
|
||||
void appendDiagnostic(const QString &message);
|
||||
|
||||
signals:
|
||||
void lineReady(const QString &line);
|
||||
|
||||
private:
|
||||
bool openPart();
|
||||
void writeLine(const QString &line);
|
||||
|
||||
static constexpr qint64 kMaxFileBytes = 20ll * 1024ll * 1024ll;
|
||||
QFile file_;
|
||||
QString directoryPath_, filePath_, sessionStamp_;
|
||||
int partIndex_ = 1;
|
||||
};
|
||||
Reference in New Issue
Block a user