Add CH0 audio capture and customer runtime diagnostics
Extend the internal driver ABI and public GVFG API for combined CH0 video/audio capture, PCM format discovery, blocking copy-out reads, extra-frame wake events, and coordinated teardown of video and audio readers. Update the Qt sample with optional CH0 audio playback on a dedicated thread, customer-visible copy/zero-copy timing telemetry, mutually exclusive CH0/CH1 Y210 selection, and a refresh-safe temporary hide for the unsupported CH1 panel. Harden Win32 error text conversion, document the new stream and ownership contracts, and package giga_ioctl plus the VC143 runtime in customer Debug/Release bundles. Validation: git diff --check passed before commit. No build, package execution, runtime, audio-device, or capture-hardware test was run.
This commit is contained in:
@@ -70,6 +70,12 @@ build/.../bin/gvfg_qt_preview.exe
|
||||
使用 function `0x832` 到 `0x837`。
|
||||
- `IOCTL_PCIES2MM_GET_FRAME` 接受 `frameIndex = MAXULONG`(`0xFFFFFFFF`),
|
||||
由 driver 自行選擇已完成的 frame。
|
||||
- `IOCTL_PCIES2MM_GET_AUDIO_FRAME`(function `0x809`)同樣接受
|
||||
`frameIndex = MAXULONG`。
|
||||
- `IOCTL_GIGA_START_VIDEO_AUDIO`、`IOCTL_GIGA_STOP_VIDEO_AUDIO` 與
|
||||
`IOCTL_GIGA_GET_AUDIO_INFO`(function `0x839` 到 `0x83B`)。
|
||||
- Extra video/audio frame event(event type `5`、`6`)表示 driver 仍有
|
||||
frame 待取;SDK 將它們當成額外的 ready notification。
|
||||
|
||||
SDK 不再呼叫 `IOCTL_PCIES2MM_GET_VIDEO_DONE_INDEX`,也不會在新 IOCTL
|
||||
不支援時退回直接寫入 `VIDEO_DMA_EN_OFFSET`、`VIDEO_EN_OFFSET` 或
|
||||
@@ -105,6 +111,30 @@ Format-change driver event 則依 mask 註冊;關閉它們也會停用對應
|
||||
`gvfg_release_channel_frame()` ownership contract,每次成功 read 都必須 release。
|
||||
SDK 會在 open 時 enable zero-copy,並在 close/destroy 時 disable。
|
||||
|
||||
### Audio capture
|
||||
|
||||
Channel 預設只啟動 video。CH0 可在 start 前改成 video + audio:
|
||||
|
||||
```c
|
||||
gvfg_open_channel(handle, device_index, GVFG_CHANNEL_0);
|
||||
gvfg_set_channel_streams(handle, GVFG_CHANNEL_0,
|
||||
GVFG_STREAM_VIDEO | GVFG_STREAM_AUDIO);
|
||||
|
||||
gvfg_audio_format_t audio = {0};
|
||||
gvfg_get_channel_audio_format(handle, GVFG_CHANNEL_0, &audio);
|
||||
gvfg_start_channel(handle, GVFG_CHANNEL_0);
|
||||
|
||||
uint8_t pcm[8192];
|
||||
uint32_t pcm_bytes = 0;
|
||||
gvfg_read_channel_audio(handle, GVFG_CHANNEL_0,
|
||||
pcm, sizeof(pcm), &pcm_bytes, 1000);
|
||||
```
|
||||
|
||||
Video-only 使用 `IOCTL_GIGA_VIDEO_START/STOP`;video + audio 使用
|
||||
`IOCTL_GIGA_START/STOP_VIDEO_AUDIO`。PCM 由 driver DMA buffer 複製到
|
||||
caller-owned destination,SDK 不建立 audio ring buffer。Audio zero-copy
|
||||
尚未納入,CH1 audio 也尚未正式支援。
|
||||
|
||||
### 同一裝置雙 channel
|
||||
|
||||
同一個 `gvfg_handle` 可對同一個 device index 開啟 CH0、CH1。SDK 只建立一個
|
||||
@@ -126,6 +156,7 @@ gvfg_stop(handle); /* stop both channels */
|
||||
|
||||
兩個 channel 應由不同 worker thread 讀取。所有 stream、frame、event、signal 與
|
||||
runtime API 都明確要求 `channel_index`;不再保留隱含 selected-channel 的舊 API。
|
||||
目前硬體不允許 CH0、CH1 同時使用 Y210;SDK 會拒絕第二個 Y210 設定。
|
||||
|
||||
`gvfg_qt_preview.exe` 只使用 public API,主畫面只顯示 input 與 Preview
|
||||
狀態;CH0、CH1 各自有 Start、Stop 與獨立 Preview 視窗,可單獨測試,
|
||||
|
||||
@@ -77,6 +77,11 @@ register 與 DMA 實作不屬於本文件。
|
||||
| ------------------ | ---------- | ------------------------------------------------------- |
|
||||
| `capture_fps` | `double` | 依 `gvfg_read_channel_frame()` 成功交付時間估算並平滑化的 FPS;尚無足夠 frame 時為 0 |
|
||||
| `delivered_frames` | `uint64_t` | 此次 running session 中成功交付給 caller 的 frame 數 |
|
||||
| `zero_copy_enabled` | `int` | 非零表示目前使用 driver zero-copy frame delivery |
|
||||
| `driver_read_samples` | `uint64_t` | 排除前 30 張 warmup 後的 driver read/acquire timing 樣本數 |
|
||||
| `driver_read_average_us` | `double` | `GET_FRAME` 或 zero-copy acquire 平均時間,單位為微秒 |
|
||||
| `driver_read_max300_us` | `double` | 最近完成的 300-sample window 最大值,單位為微秒 |
|
||||
| `driver_read_max_us` | `double` | 本次 capture lifetime 最大值,單位為微秒 |
|
||||
|
||||
### 1.8 `gvfg_frame_t`
|
||||
|
||||
@@ -234,6 +239,32 @@ gvfg_status_t gvfg_set_channel_video_format(gvfg_handle handle,
|
||||
- Device 必須已 open,且 stream 必須尚未 start 或已 stop。
|
||||
- Streaming 中呼叫回傳 `GVFG_ESTATE`;不支援的 format 回傳 `GVFG_ENOTSUP` 或
|
||||
`GVFG_EINVAL`。
|
||||
- 同一裝置的 CH0、CH1 不可同時設定 Y210;第二個 Y210 request 回傳
|
||||
`GVFG_ENOTSUP`。
|
||||
|
||||
### 1.19a Audio capture selection and copy-out
|
||||
|
||||
```c
|
||||
gvfg_status_t gvfg_set_channel_streams(gvfg_handle handle,
|
||||
int channel_index,
|
||||
uint32_t streams);
|
||||
gvfg_status_t gvfg_get_channel_audio_format(gvfg_handle handle,
|
||||
int channel_index,
|
||||
gvfg_audio_format_t *out_format);
|
||||
gvfg_status_t gvfg_read_channel_audio(gvfg_handle handle,
|
||||
int channel_index,
|
||||
void *destination,
|
||||
uint32_t destination_capacity,
|
||||
uint32_t *out_bytes,
|
||||
uint32_t timeout_ms);
|
||||
```
|
||||
|
||||
- 預設為 `GVFG_STREAM_VIDEO`。CH0 可在 start 前設定為
|
||||
`GVFG_STREAM_VIDEO | GVFG_STREAM_AUDIO`;audio-only 與 CH1 audio 尚未支援。
|
||||
- `gvfg_start_channel()` 依 streams 選擇 video-only 或 video + audio driver start。
|
||||
- `gvfg_read_channel_audio()` 以 `MAXULONG` 取得下一個 PCM frame,並複製到
|
||||
caller-owned destination。`out_bytes` 是 driver 回報的有效 byte 數。
|
||||
- SDK 不建立 audio ring,也不提供尚未完成的 audio zero-copy。
|
||||
|
||||
### 1.20 `gvfg_start_channel`
|
||||
|
||||
|
||||
@@ -34,6 +34,10 @@ if not exist "%SOURCE_BIN%\gvfg.dll" (
|
||||
echo [package] ERROR: gvfg.dll not found.
|
||||
goto fail
|
||||
)
|
||||
if not exist "%SOURCE_BIN%\giga_ioctl.dll" (
|
||||
echo [package] ERROR: giga_ioctl.dll not found.
|
||||
goto fail
|
||||
)
|
||||
if not exist "%SOURCE_BIN%\gvfg_preview.dll" (
|
||||
echo [package] ERROR: gvfg_preview.dll not found.
|
||||
goto fail
|
||||
@@ -50,9 +54,11 @@ mkdir "%STAGE_DIR%" || goto fail
|
||||
echo [package] Copy application files and debug symbols...
|
||||
copy /Y "%SOURCE_BIN%\gvfg_qt_preview.exe" "%STAGE_DIR%\" >nul || goto fail
|
||||
copy /Y "%SOURCE_BIN%\gvfg.dll" "%STAGE_DIR%\" >nul || goto fail
|
||||
copy /Y "%SOURCE_BIN%\giga_ioctl.dll" "%STAGE_DIR%\" >nul || goto fail
|
||||
copy /Y "%SOURCE_BIN%\gvfg_preview.dll" "%STAGE_DIR%\" >nul || goto fail
|
||||
if exist "%SOURCE_BIN%\gvfg_qt_preview.pdb" copy /Y "%SOURCE_BIN%\gvfg_qt_preview.pdb" "%STAGE_DIR%\" >nul || goto fail
|
||||
if exist "%SOURCE_BIN%\gvfg.pdb" copy /Y "%SOURCE_BIN%\gvfg.pdb" "%STAGE_DIR%\" >nul || goto fail
|
||||
if exist "%SOURCE_BIN%\giga_ioctl.pdb" copy /Y "%SOURCE_BIN%\giga_ioctl.pdb" "%STAGE_DIR%\" >nul || goto fail
|
||||
if exist "%SOURCE_BIN%\gvfg_preview.pdb" copy /Y "%SOURCE_BIN%\gvfg_preview.pdb" "%STAGE_DIR%\" >nul || goto fail
|
||||
|
||||
echo [package] Deploy Qt Debug runtime...
|
||||
|
||||
@@ -33,6 +33,10 @@ if not exist "%SOURCE_BIN%\gvfg.dll" (
|
||||
echo [package] ERROR: gvfg.dll not found.
|
||||
goto fail
|
||||
)
|
||||
if not exist "%SOURCE_BIN%\giga_ioctl.dll" (
|
||||
echo [package] ERROR: giga_ioctl.dll not found.
|
||||
goto fail
|
||||
)
|
||||
if not exist "%SOURCE_BIN%\gvfg_preview.dll" (
|
||||
echo [package] ERROR: gvfg_preview.dll not found.
|
||||
goto fail
|
||||
@@ -49,6 +53,7 @@ mkdir "%STAGE_DIR%" || goto fail
|
||||
echo [package] Copy application files...
|
||||
copy /Y "%SOURCE_BIN%\gvfg_qt_preview.exe" "%STAGE_DIR%\" >nul || goto fail
|
||||
copy /Y "%SOURCE_BIN%\gvfg.dll" "%STAGE_DIR%\" >nul || goto fail
|
||||
copy /Y "%SOURCE_BIN%\giga_ioctl.dll" "%STAGE_DIR%\" >nul || goto fail
|
||||
copy /Y "%SOURCE_BIN%\gvfg_preview.dll" "%STAGE_DIR%\" >nul || goto fail
|
||||
|
||||
echo [package] Deploy Qt runtime...
|
||||
@@ -56,6 +61,31 @@ if exist "%VSDEVCMD%" call "%VSDEVCMD%" -arch=x64 >nul || goto fail
|
||||
"%WINDEPLOYQT%" --release --compiler-runtime --force --dir "%STAGE_DIR%" "%STAGE_DIR%\gvfg_qt_preview.exe"
|
||||
if errorlevel 1 goto fail
|
||||
|
||||
echo [package] Deploy MSVC runtime...
|
||||
if not defined VCToolsRedistDir (
|
||||
echo [package] ERROR: VCToolsRedistDir was not set by VsDevCmd.bat.
|
||||
goto fail
|
||||
)
|
||||
set "VC_RUNTIME_DIR=%VCToolsRedistDir%x64\Microsoft.VC143.CRT"
|
||||
if not exist "%VC_RUNTIME_DIR%\msvcp140.dll" (
|
||||
echo [package] ERROR: MSVC runtime not found in "%VC_RUNTIME_DIR%".
|
||||
goto fail
|
||||
)
|
||||
copy /Y "%VC_RUNTIME_DIR%\*.dll" "%STAGE_DIR%\" >nul || goto fail
|
||||
|
||||
if not exist "%STAGE_DIR%\msvcp140.dll" (
|
||||
echo [package] ERROR: msvcp140.dll was not deployed.
|
||||
goto fail
|
||||
)
|
||||
if not exist "%STAGE_DIR%\vcruntime140.dll" (
|
||||
echo [package] ERROR: vcruntime140.dll was not deployed.
|
||||
goto fail
|
||||
)
|
||||
if not exist "%STAGE_DIR%\vcruntime140_1.dll" (
|
||||
echo [package] ERROR: vcruntime140_1.dll was not deployed.
|
||||
goto fail
|
||||
)
|
||||
|
||||
echo [package] Create zip...
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
|
||||
"Compress-Archive -Path '%STAGE_DIR%' -DestinationPath '%ZIP_PATH%' -Force"
|
||||
|
||||
@@ -5,8 +5,8 @@ project(gvfg_qt_preview LANGUAGES CXX)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)
|
||||
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets Multimedia)
|
||||
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets Multimedia)
|
||||
|
||||
set(GVFG_QT_PREVIEW_SOURCES
|
||||
main.cpp
|
||||
@@ -26,6 +26,7 @@ endif()
|
||||
|
||||
target_link_libraries(gvfg_qt_preview PRIVATE
|
||||
Qt${QT_VERSION_MAJOR}::Widgets
|
||||
Qt${QT_VERSION_MAJOR}::Multimedia
|
||||
gvfg
|
||||
gvfg_preview
|
||||
)
|
||||
|
||||
@@ -5,11 +5,16 @@
|
||||
#include <gvfg_debug.h>
|
||||
|
||||
#include <QCloseEvent>
|
||||
#include <QAudioSink>
|
||||
#include <QAudioDevice>
|
||||
#include <QAudioFormat>
|
||||
#include <QIODevice>
|
||||
#include <QMediaDevices>
|
||||
#include <QCoreApplication>
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QIODevice>
|
||||
#include <QMetaObject>
|
||||
#include <QStandardItemModel>
|
||||
#include <QSyntaxHighlighter>
|
||||
#include <QTextCharFormat>
|
||||
#include <QStringList>
|
||||
@@ -17,6 +22,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <vector>
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -193,22 +199,22 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
{ startCapture(GVFG_CHANNEL_1); });
|
||||
connect(ui_->ch0OutputFormatCombo, &QComboBox::currentIndexChanged, this, [this](int)
|
||||
{
|
||||
updateOutputFormatOptions(GVFG_CHANNEL_0);
|
||||
if (channels_[GVFG_CHANNEL_0].opened &&
|
||||
!channels_[GVFG_CHANNEL_0].running.load(std::memory_order_acquire))
|
||||
{
|
||||
applyOutputFormat(GVFG_CHANNEL_0);
|
||||
updateSignalStatus();
|
||||
}
|
||||
});
|
||||
} });
|
||||
connect(ui_->ch1OutputFormatCombo, &QComboBox::currentIndexChanged, this, [this](int)
|
||||
{
|
||||
updateOutputFormatOptions(GVFG_CHANNEL_1);
|
||||
if (channels_[GVFG_CHANNEL_1].opened &&
|
||||
!channels_[GVFG_CHANNEL_1].running.load(std::memory_order_acquire))
|
||||
{
|
||||
applyOutputFormat(GVFG_CHANNEL_1);
|
||||
updateSignalStatus();
|
||||
}
|
||||
});
|
||||
} });
|
||||
connect(ui_->ch0StopButton, &QPushButton::clicked, this, [this]()
|
||||
{ stopCapture(GVFG_CHANNEL_0); });
|
||||
connect(ui_->ch1StopButton, &QPushButton::clicked, this, [this]()
|
||||
@@ -216,9 +222,9 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
connect(runtimeStatusTimer_, &QTimer::timeout, this, [this]()
|
||||
{
|
||||
processPendingEvents();
|
||||
updateSignalStatus(false);
|
||||
});
|
||||
updateSignalStatus(false); });
|
||||
|
||||
updateOutputFormatOptions();
|
||||
updateUiState();
|
||||
appendLog(QStringLiteral("GVFG SDK version | %1")
|
||||
.arg(QString::fromLatin1(gvfg_get_version())));
|
||||
@@ -369,7 +375,8 @@ bool MainWindow::openChannel(int channel)
|
||||
return false;
|
||||
|
||||
appendLog(QStringLiteral("Opened device index %1 CH%2 | mode=%3")
|
||||
.arg(selectedDeviceIndex_).arg(channel)
|
||||
.arg(selectedDeviceIndex_)
|
||||
.arg(channel)
|
||||
.arg(zeroCopyEnabled ? QStringLiteral("zero-copy") : QStringLiteral("copy")));
|
||||
updateSignalStatus();
|
||||
return true;
|
||||
@@ -434,6 +441,37 @@ bool MainWindow::applyOutputFormat(int channel)
|
||||
return true;
|
||||
}
|
||||
|
||||
void MainWindow::updateOutputFormatOptions(int changedChannel)
|
||||
{
|
||||
QComboBox *combos[] = {ui_->ch0OutputFormatCombo, ui_->ch1OutputFormatCombo};
|
||||
constexpr int kY210Index = 1;
|
||||
|
||||
if ((changedChannel == GVFG_CHANNEL_0 || changedChannel == GVFG_CHANNEL_1) &&
|
||||
combos[changedChannel]->currentIndex() == kY210Index)
|
||||
{
|
||||
const int otherChannel = changedChannel == GVFG_CHANNEL_0
|
||||
? GVFG_CHANNEL_1
|
||||
: GVFG_CHANNEL_0;
|
||||
if (combos[otherChannel]->currentIndex() == kY210Index)
|
||||
combos[otherChannel]->setCurrentIndex(0);
|
||||
}
|
||||
|
||||
const bool ch0UsesY210 = combos[GVFG_CHANNEL_0]->currentIndex() == kY210Index;
|
||||
const bool ch1UsesY210 = combos[GVFG_CHANNEL_1]->currentIndex() == kY210Index;
|
||||
const bool y210Enabled[] = {!ch1UsesY210, !ch0UsesY210};
|
||||
|
||||
for (int channel = GVFG_CHANNEL_0; channel <= GVFG_CHANNEL_1; ++channel)
|
||||
{
|
||||
auto *model = qobject_cast<QStandardItemModel *>(combos[channel]->model());
|
||||
if (model && model->item(kY210Index))
|
||||
model->item(kY210Index)->setEnabled(y210Enabled[channel]);
|
||||
|
||||
combos[channel]->setToolTip(y210Enabled[channel]
|
||||
? QStringLiteral("Requested CH%1 capture output format").arg(channel)
|
||||
: QStringLiteral("Y210 is already selected by the other channel"));
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::startCapture(int channelIndex)
|
||||
{
|
||||
ChannelRuntime &channel = channels_[channelIndex];
|
||||
@@ -453,6 +491,39 @@ void MainWindow::startCapture(int channelIndex)
|
||||
return;
|
||||
}
|
||||
|
||||
const bool audioEnabled = channelIndex == GVFG_CHANNEL_0 && ui_->ch0AudioCheckBox->isChecked();
|
||||
gvfg_status_t st = gvfg_set_channel_streams(
|
||||
handle_, channelIndex, GVFG_STREAM_VIDEO | (audioEnabled ? GVFG_STREAM_AUDIO : 0));
|
||||
if (st != GVFG_OK)
|
||||
{
|
||||
showError(QStringLiteral("gvfg_set_channel_streams"), st, channelIndex);
|
||||
return;
|
||||
}
|
||||
channel.audioFormat = {};
|
||||
if (audioEnabled)
|
||||
{
|
||||
st = gvfg_get_channel_audio_format(handle_, channelIndex, &channel.audioFormat);
|
||||
if (st != GVFG_OK)
|
||||
{
|
||||
showError(QStringLiteral("gvfg_get_channel_audio_format"), st, channelIndex);
|
||||
return;
|
||||
}
|
||||
if (channel.audioFormat.frame_bytes == 0 || channel.audioFormat.block_align == 0 ||
|
||||
channel.audioFormat.channels == 0 || channel.audioFormat.sample_rate == 0 ||
|
||||
(channel.audioFormat.bits_per_sample != 8 &&
|
||||
channel.audioFormat.bits_per_sample != 16 &&
|
||||
channel.audioFormat.bits_per_sample != 32))
|
||||
{
|
||||
appendLog(QStringLiteral("CH%1 Audio format unsupported by Qt playback | %2 Hz %3 ch %4-bit frame_bytes=%5")
|
||||
.arg(channelIndex)
|
||||
.arg(channel.audioFormat.sample_rate)
|
||||
.arg(channel.audioFormat.channels)
|
||||
.arg(channel.audioFormat.bits_per_sample)
|
||||
.arg(channel.audioFormat.frame_bytes));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
channel.frameAvailable.store(false, std::memory_order_release);
|
||||
updatePreviewSourceSize(channelIndex, channel.cachedSignalStatus);
|
||||
previewWindows_[channelIndex]->showPreview();
|
||||
@@ -474,7 +545,7 @@ void MainWindow::startCapture(int channelIndex)
|
||||
appendLog(QStringLiteral("FPGA signal before stream start"));
|
||||
#endif
|
||||
|
||||
const gvfg_status_t st = gvfg_start_channel(handle_, channelIndex);
|
||||
st = gvfg_start_channel(handle_, channelIndex);
|
||||
if (st != GVFG_OK)
|
||||
{
|
||||
showError(QStringLiteral("gvfg_start_channel"), st, channelIndex);
|
||||
@@ -493,6 +564,9 @@ void MainWindow::startCapture(int channelIndex)
|
||||
channel.getFrameMaximumMs.store(0.0, std::memory_order_relaxed);
|
||||
channel.getFrameWindowMaximumMs.store(0.0, std::memory_order_relaxed);
|
||||
channel.getFrameSamples.store(0, std::memory_order_relaxed);
|
||||
channel.audioEnabled = audioEnabled;
|
||||
channel.audioFrames.store(0, std::memory_order_relaxed);
|
||||
channel.audioBytes.store(0, std::memory_order_relaxed);
|
||||
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||
channel.haveDebugBaseline = false;
|
||||
channel.lastDebugDmaErrors = 0;
|
||||
@@ -501,8 +575,17 @@ void MainWindow::startCapture(int channelIndex)
|
||||
channel.running.store(true, std::memory_order_release);
|
||||
channel.captureThread = std::thread([this, channelIndex]()
|
||||
{ captureReadLoop(channelIndex); });
|
||||
if (audioEnabled)
|
||||
channel.audioThread = std::thread([this, channelIndex]()
|
||||
{ audioReadLoop(channelIndex); });
|
||||
updateUiState();
|
||||
appendLog(QStringLiteral("CH%1 Started capture").arg(channelIndex));
|
||||
appendLog(audioEnabled
|
||||
? QStringLiteral("CH%1 Started video + audio | %2 Hz %3 ch %4-bit")
|
||||
.arg(channelIndex)
|
||||
.arg(channel.audioFormat.sample_rate)
|
||||
.arg(channel.audioFormat.channels)
|
||||
.arg(channel.audioFormat.bits_per_sample)
|
||||
: QStringLiteral("CH%1 Started video-only").arg(channelIndex));
|
||||
updateSignalStatus(false);
|
||||
}
|
||||
|
||||
@@ -513,9 +596,11 @@ void MainWindow::stopCapture(int channelIndex)
|
||||
{
|
||||
channel.stopRequested.store(true, std::memory_order_release);
|
||||
joinCaptureThread(channelIndex);
|
||||
joinAudioThread(channelIndex);
|
||||
gvfg_stop_channel(handle_, channelIndex);
|
||||
channel.running.store(false, std::memory_order_release);
|
||||
channel.frameAvailable.store(false, std::memory_order_release);
|
||||
channel.audioEnabled = false;
|
||||
if (previewWindows_[channelIndex])
|
||||
previewWindows_[channelIndex]->closePreview();
|
||||
appendLog(QStringLiteral("CH%1 Stopped capture").arg(channelIndex));
|
||||
@@ -541,7 +626,8 @@ bool MainWindow::applyPreview(int channelIndex)
|
||||
if (st != GVFG_PREVIEW_OK || !channel.previewHandle)
|
||||
{
|
||||
appendLog(QStringLiteral("CH%1 Preview setup failed: %2")
|
||||
.arg(channelIndex).arg(QString::fromUtf8(gvfg_preview_strerror(st))));
|
||||
.arg(channelIndex)
|
||||
.arg(QString::fromUtf8(gvfg_preview_strerror(st))));
|
||||
channel.previewHandle = nullptr;
|
||||
return false;
|
||||
}
|
||||
@@ -552,7 +638,8 @@ bool MainWindow::applyPreview(int channelIndex)
|
||||
if (st != GVFG_PREVIEW_OK)
|
||||
{
|
||||
appendLog(QStringLiteral("CH%1 Preview setup failed: %2")
|
||||
.arg(channelIndex).arg(QString::fromUtf8(gvfg_preview_strerror(st))));
|
||||
.arg(channelIndex)
|
||||
.arg(QString::fromUtf8(gvfg_preview_strerror(st))));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -666,10 +753,21 @@ void MainWindow::updateSignalStatus(bool queryHardware)
|
||||
.arg(channel.running.load(std::memory_order_acquire) ? QStringLiteral("Running") : QStringLiteral("Stopped"))
|
||||
.arg(signalFrameText(signal))
|
||||
.arg(zeroCopy ? QStringLiteral("Zero-copy") : QStringLiteral("Copy"));
|
||||
if (channel.audioEnabled)
|
||||
{
|
||||
statusLines << QStringLiteral("CH%1 Audio | %2 Hz %3 ch %4-bit | frames=%5 bytes=%6")
|
||||
.arg(channelIndex)
|
||||
.arg(channel.audioFormat.sample_rate)
|
||||
.arg(channel.audioFormat.channels)
|
||||
.arg(channel.audioFormat.bits_per_sample)
|
||||
.arg(static_cast<qulonglong>(channel.audioFrames.load(std::memory_order_relaxed)))
|
||||
.arg(static_cast<qulonglong>(channel.audioBytes.load(std::memory_order_relaxed)));
|
||||
}
|
||||
statusLines << QStringLiteral("CH%1 Preview | %2 FPS | %3")
|
||||
.arg(channelIndex).arg(previewFps, previewFrame);
|
||||
.arg(channelIndex)
|
||||
.arg(previewFps, previewFrame);
|
||||
const uint64_t readSamples = channel.getFrameSamples.load(std::memory_order_relaxed);
|
||||
statusLines << (readSamples > 0
|
||||
statusLines << (readSamples >= 300
|
||||
? QStringLiteral("CH%1 Read | avg=%2 max300=%3 max=%4 ms samples=%5")
|
||||
.arg(channelIndex)
|
||||
.arg(channel.getFrameAverageMs.load(std::memory_order_relaxed), 0, 'f', 3)
|
||||
@@ -678,21 +776,26 @@ void MainWindow::updateSignalStatus(bool queryHardware)
|
||||
.arg(static_cast<qulonglong>(readSamples))
|
||||
: QStringLiteral("CH%1 Read | measuring").arg(channelIndex));
|
||||
|
||||
gvfg_runtime_info_t runtimeInfo{};
|
||||
if (gvfg_get_channel_runtime_info(handle_, channelIndex, &runtimeInfo) == GVFG_OK)
|
||||
{
|
||||
statusLines << (runtimeInfo.driver_read_samples >= 300
|
||||
? QStringLiteral("CH%1 %2 | avg=%3 max300=%4 max=%5 us samples=%6")
|
||||
.arg(channelIndex)
|
||||
.arg(runtimeInfo.zero_copy_enabled
|
||||
? QStringLiteral("ZeroCopy Acquire")
|
||||
: QStringLiteral("Copy GetFrame"))
|
||||
.arg(runtimeInfo.driver_read_average_us, 0, 'f', 3)
|
||||
.arg(runtimeInfo.driver_read_max300_us, 0, 'f', 3)
|
||||
.arg(runtimeInfo.driver_read_max_us, 0, 'f', 3)
|
||||
.arg(static_cast<qulonglong>(runtimeInfo.driver_read_samples))
|
||||
: QStringLiteral("CH%1 Driver GetFrame | measuring").arg(channelIndex));
|
||||
}
|
||||
|
||||
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||
gvfg_debug_backend_stats_t backendStats{};
|
||||
if (gvfg_debug_get_channel_backend_stats(handle_, channelIndex, &backendStats) == GVFG_OK)
|
||||
{
|
||||
statusLines << (backendStats.get_frame_timing_samples >= 300
|
||||
? QStringLiteral("CH%1 %2 | avg=%3 max300=%4 max=%5 us samples=%6")
|
||||
.arg(channelIndex)
|
||||
.arg(backendStats.get_frame_zero_copy
|
||||
? QStringLiteral("ZeroCopy Acquire")
|
||||
: QStringLiteral("Copy GetFrame"))
|
||||
.arg(backendStats.get_frame_timing_average_us, 0, 'f', 3)
|
||||
.arg(backendStats.get_frame_timing_max300_us, 0, 'f', 3)
|
||||
.arg(backendStats.get_frame_timing_max_us, 0, 'f', 3)
|
||||
.arg(static_cast<qulonglong>(backendStats.get_frame_timing_samples))
|
||||
: QStringLiteral("CH%1 Driver GetFrame | measuring").arg(channelIndex));
|
||||
statusLines << QStringLiteral("CH%1 Capture | status=%2 dma_errors=%3 no_frame_waits=%4")
|
||||
.arg(channelIndex)
|
||||
.arg(captureStatusText(backendStats, signal.connected != 0))
|
||||
@@ -729,6 +832,7 @@ void MainWindow::updateSignalStatus(bool queryHardware)
|
||||
|
||||
void MainWindow::updateUiState()
|
||||
{
|
||||
constexpr bool kChannel1UiVisible = false;
|
||||
const bool deviceOpen = handle_ != nullptr;
|
||||
const bool ch0Running = channels_[0].running.load(std::memory_order_acquire);
|
||||
const bool ch1Running = channels_[1].running.load(std::memory_order_acquire);
|
||||
@@ -750,6 +854,8 @@ void MainWindow::updateUiState()
|
||||
ui_->ch1OutputFormatCombo->setEnabled(!ch1Running);
|
||||
ui_->ch0ZeroCopyCheckBox->setEnabled(!channels_[0].opened);
|
||||
ui_->ch1ZeroCopyCheckBox->setEnabled(!channels_[1].opened);
|
||||
ui_->ch0AudioCheckBox->setEnabled(!ch0Running);
|
||||
ui_->channel1GroupBox->setVisible(kChannel1UiVisible);
|
||||
}
|
||||
|
||||
void MainWindow::showError(const QString &apiName, gvfg_status_t status, int channel)
|
||||
@@ -907,7 +1013,8 @@ void MainWindow::captureReadLoop(int channelIndex)
|
||||
const gvfg_status_t st = gvfg_read_channel_frame(handle_, channelIndex, &frame, 200);
|
||||
const double getFrameElapsedMs =
|
||||
std::chrono::duration<double, std::milli>(
|
||||
std::chrono::steady_clock::now() - getFrameStart).count();
|
||||
std::chrono::steady_clock::now() - getFrameStart)
|
||||
.count();
|
||||
if (st == GVFG_OK)
|
||||
{
|
||||
const bool timingWarmupComplete = ++successfulFrameCount > kTimingWarmupFrames;
|
||||
@@ -940,15 +1047,13 @@ void MainWindow::captureReadLoop(int channelIndex)
|
||||
if (!channel.frameAvailable.exchange(true, std::memory_order_acq_rel))
|
||||
{
|
||||
QMetaObject::invokeMethod(this, [this]()
|
||||
{ updateUiState(); },
|
||||
Qt::QueuedConnection);
|
||||
{ updateUiState(); }, Qt::QueuedConnection);
|
||||
}
|
||||
if (captureStalledLogged)
|
||||
{
|
||||
captureStalledLogged = false;
|
||||
QMetaObject::invokeMethod(this, [this, channelIndex]()
|
||||
{ appendLog(QStringLiteral("CH%1 RECOVERED capture resumed").arg(channelIndex)); },
|
||||
Qt::QueuedConnection);
|
||||
{ appendLog(QStringLiteral("CH%1 RECOVERED capture resumed").arg(channelIndex)); }, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
if (channel.previewHandle)
|
||||
@@ -988,7 +1093,8 @@ void MainWindow::captureReadLoop(int channelIndex)
|
||||
{
|
||||
QMetaObject::invokeMethod(this, [this, channelIndex, failures, previewStatus]()
|
||||
{ appendLog(QStringLiteral("CH%1 preview render failed #%2: %3")
|
||||
.arg(channelIndex).arg(static_cast<qulonglong>(failures))
|
||||
.arg(channelIndex)
|
||||
.arg(static_cast<qulonglong>(failures))
|
||||
.arg(QString::fromUtf8(gvfg_preview_strerror(previewStatus)))); }, Qt::QueuedConnection);
|
||||
}
|
||||
}
|
||||
@@ -1000,7 +1106,8 @@ void MainWindow::captureReadLoop(int channelIndex)
|
||||
channel.previewFailureCount = 0;
|
||||
QMetaObject::invokeMethod(this, [this, channelIndex, failures]()
|
||||
{ appendLog(QStringLiteral("CH%1 preview render recovered after %2 failure(s)")
|
||||
.arg(channelIndex).arg(static_cast<qulonglong>(failures))); }, Qt::QueuedConnection);
|
||||
.arg(channelIndex)
|
||||
.arg(static_cast<qulonglong>(failures))); }, Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
if (timingWarmupComplete)
|
||||
@@ -1034,8 +1141,7 @@ void MainWindow::captureReadLoop(int channelIndex)
|
||||
if (releaseStatus != GVFG_OK)
|
||||
{
|
||||
QMetaObject::invokeMethod(this, [this, channelIndex, releaseStatus]()
|
||||
{ showError(QStringLiteral("gvfg_release_channel_frame"), releaseStatus, channelIndex); },
|
||||
Qt::QueuedConnection);
|
||||
{ showError(QStringLiteral("gvfg_release_channel_frame"), releaseStatus, channelIndex); }, Qt::QueuedConnection);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1059,7 +1165,8 @@ void MainWindow::captureReadLoop(int channelIndex)
|
||||
QMetaObject::invokeMethod(this, [this, channelIndex, elapsedMs]()
|
||||
{
|
||||
appendLog(QStringLiteral("CH%1 ERROR no capture frame for %2 ms")
|
||||
.arg(channelIndex).arg(elapsedMs));
|
||||
.arg(channelIndex)
|
||||
.arg(elapsedMs));
|
||||
#if GVFG_INTERNAL_DIAGNOSTICS
|
||||
updateSignalStatus(false);
|
||||
writeDiagnosticSnapshot(lastSignalStatusText_);
|
||||
@@ -1077,8 +1184,7 @@ void MainWindow::captureReadLoop(int channelIndex)
|
||||
break;
|
||||
|
||||
QMetaObject::invokeMethod(this, [this, channelIndex, st]()
|
||||
{ showError(QStringLiteral("gvfg_read_channel_frame"), st, channelIndex); },
|
||||
Qt::QueuedConnection);
|
||||
{ showError(QStringLiteral("gvfg_read_channel_frame"), st, channelIndex); }, Qt::QueuedConnection);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1088,3 +1194,109 @@ void MainWindow::joinCaptureThread(int channel)
|
||||
if (channels_[channel].captureThread.joinable())
|
||||
channels_[channel].captureThread.join();
|
||||
}
|
||||
|
||||
void MainWindow::audioReadLoop(int channelIndex)
|
||||
{
|
||||
ChannelRuntime &channel = channels_[channelIndex];
|
||||
const gvfg_audio_format_t format = channel.audioFormat;
|
||||
|
||||
QAudioFormat outputFormat;
|
||||
outputFormat.setSampleRate(static_cast<int>(format.sample_rate));
|
||||
outputFormat.setChannelCount(static_cast<int>(format.channels));
|
||||
switch (format.bits_per_sample)
|
||||
{
|
||||
case 8:
|
||||
outputFormat.setSampleFormat(QAudioFormat::UInt8);
|
||||
break;
|
||||
case 16:
|
||||
outputFormat.setSampleFormat(QAudioFormat::Int16);
|
||||
break;
|
||||
case 32:
|
||||
outputFormat.setSampleFormat(QAudioFormat::Int32);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
const QAudioDevice outputDevice = QMediaDevices::defaultAudioOutput();
|
||||
if (outputDevice.isNull() || !outputDevice.isFormatSupported(outputFormat))
|
||||
{
|
||||
QMetaObject::invokeMethod(this, [this, channelIndex, format]()
|
||||
{
|
||||
appendLog(QStringLiteral("CH%1 Audio output does not support %2 Hz %3 ch %4-bit PCM")
|
||||
.arg(channelIndex)
|
||||
.arg(format.sample_rate)
|
||||
.arg(format.channels)
|
||||
.arg(format.bits_per_sample));
|
||||
stopCapture(channelIndex); }, Qt::QueuedConnection);
|
||||
return;
|
||||
}
|
||||
|
||||
QAudioSink audioSink(outputDevice, outputFormat);
|
||||
audioSink.setBufferSize(static_cast<int>(format.frame_bytes * 4u));
|
||||
QIODevice *audioOutput = audioSink.start();
|
||||
if (!audioOutput)
|
||||
{
|
||||
QMetaObject::invokeMethod(this, [this, channelIndex]()
|
||||
{
|
||||
appendLog(QStringLiteral("CH%1 Audio output failed to start").arg(channelIndex));
|
||||
stopCapture(channelIndex); }, Qt::QueuedConnection);
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> audioBuffer(format.frame_bytes);
|
||||
while (!channel.stopRequested.load(std::memory_order_acquire))
|
||||
{
|
||||
uint32_t bytesRead = 0;
|
||||
const gvfg_status_t status = gvfg_read_channel_audio(
|
||||
handle_, channelIndex, audioBuffer.data(),
|
||||
static_cast<uint32_t>(audioBuffer.size()), &bytesRead, 200);
|
||||
if (status == GVFG_ETIMEOUT)
|
||||
continue;
|
||||
if (status != GVFG_OK)
|
||||
{
|
||||
if (!channel.stopRequested.load(std::memory_order_acquire))
|
||||
{
|
||||
QMetaObject::invokeMethod(this, [this, channelIndex, status]()
|
||||
{ showError(QStringLiteral("gvfg_read_channel_audio"), status, channelIndex); }, Qt::QueuedConnection);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
qint64 written = 0;
|
||||
while (written < static_cast<qint64>(bytesRead) &&
|
||||
!channel.stopRequested.load(std::memory_order_acquire))
|
||||
{
|
||||
const qint64 result = audioOutput->write(
|
||||
reinterpret_cast<const char *>(audioBuffer.data()) + written,
|
||||
static_cast<qint64>(bytesRead) - written);
|
||||
if (result < 0)
|
||||
{
|
||||
QMetaObject::invokeMethod(this, [this, channelIndex]()
|
||||
{
|
||||
appendLog(QStringLiteral("CH%1 Audio output write failed").arg(channelIndex));
|
||||
stopCapture(channelIndex); }, Qt::QueuedConnection);
|
||||
audioSink.stop();
|
||||
return;
|
||||
}
|
||||
if (result == 0)
|
||||
{
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||
continue;
|
||||
}
|
||||
written += result;
|
||||
}
|
||||
if (written == static_cast<qint64>(bytesRead))
|
||||
{
|
||||
channel.audioFrames.fetch_add(1, std::memory_order_relaxed);
|
||||
channel.audioBytes.fetch_add(bytesRead, std::memory_order_relaxed);
|
||||
}
|
||||
}
|
||||
audioSink.stop();
|
||||
}
|
||||
|
||||
void MainWindow::joinAudioThread(int channel)
|
||||
{
|
||||
if (channels_[channel].audioThread.joinable())
|
||||
channels_[channel].audioThread.join();
|
||||
}
|
||||
|
||||
@@ -44,6 +44,11 @@ private:
|
||||
std::atomic<bool> stopRequested{false};
|
||||
std::atomic<bool> frameAvailable{false};
|
||||
std::thread captureThread;
|
||||
std::thread audioThread;
|
||||
bool audioEnabled = false;
|
||||
gvfg_audio_format_t audioFormat{};
|
||||
std::atomic<uint64_t> audioFrames{0};
|
||||
std::atomic<uint64_t> audioBytes{0};
|
||||
std::atomic<double> getFrameAverageMs{0.0};
|
||||
std::atomic<double> getFrameMaximumMs{0.0};
|
||||
std::atomic<double> getFrameWindowMaximumMs{0.0};
|
||||
@@ -68,6 +73,7 @@ private:
|
||||
bool openDevice();
|
||||
bool openChannel(int channel);
|
||||
bool applyOutputFormat(int channel);
|
||||
void updateOutputFormatOptions(int changedChannel = -1);
|
||||
void closeDevice();
|
||||
void startCapture(int channel);
|
||||
void stopCapture(int channel);
|
||||
@@ -87,7 +93,9 @@ private:
|
||||
#endif
|
||||
void appendLog(const QString &message);
|
||||
void captureReadLoop(int channel);
|
||||
void audioReadLoop(int channel);
|
||||
void joinCaptureThread(int channel);
|
||||
void joinAudioThread(int channel);
|
||||
|
||||
static constexpr qint64 kMaxLogFileBytes = 20ll * 1024ll * 1024ll;
|
||||
|
||||
|
||||
@@ -58,23 +58,87 @@
|
||||
<layout class="QHBoxLayout" name="channelPanelsLayout" stretch="1,1">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="channel0GroupBox">
|
||||
<property name="title"><string>CH0</string></property>
|
||||
<property name="title">
|
||||
<string>CH0</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="channel0GridLayout">
|
||||
<item row="0" column="0"><widget class="QLabel" name="channel0FormatLabel"><property name="text"><string>Output format:</string></property></widget></item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="ch0OutputFormatCombo">
|
||||
<property name="toolTip"><string>Requested CH0 capture output format</string></property>
|
||||
<item><property name="text"><string>YUY2 (8-bit 4:2:2)</string></property></item>
|
||||
<item><property name="text"><string>Y210 (10-bit 4:2:2)</string></property></item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="channel0FormatLabel">
|
||||
<property name="text">
|
||||
<string>Output format:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2"><widget class="QCheckBox" name="ch0ZeroCopyCheckBox"><property name="toolTip"><string>Must be selected before opening CH0</string></property><property name="text"><string>Zero-copy</string></property></widget></item>
|
||||
<item row="1" column="0" colspan="3">
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="ch0OutputFormatCombo">
|
||||
<property name="toolTip">
|
||||
<string>Requested CH0 capture output format</string>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>YUY2 (8-bit 4:2:2)</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Y210 (10-bit 4:2:2)</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QCheckBox" name="ch0ZeroCopyCheckBox">
|
||||
<property name="toolTip">
|
||||
<string>Must be selected before opening CH0</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Zero-copy</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QCheckBox" name="ch0AudioCheckBox">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Capture and play CH0 PCM audio together with video</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Audio</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="4">
|
||||
<layout class="QHBoxLayout" name="channel0ButtonLayout">
|
||||
<item><widget class="QPushButton" name="ch0StartButton"><property name="text"><string>Start</string></property></widget></item>
|
||||
<item><widget class="QPushButton" name="ch0StopButton"><property name="text"><string>Stop</string></property></widget></item>
|
||||
<item><widget class="QPushButton" name="ch0PreviewButton"><property name="text"><string>Open view</string></property></widget></item>
|
||||
<item><widget class="QPushButton" name="ch0FullscreenButton"><property name="text"><string>Fullscreen</string></property></widget></item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="ch0StartButton">
|
||||
<property name="text">
|
||||
<string>Start</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="ch0StopButton">
|
||||
<property name="text">
|
||||
<string>Stop</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="ch0PreviewButton">
|
||||
<property name="text">
|
||||
<string>Open view</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="ch0FullscreenButton">
|
||||
<property name="text">
|
||||
<string>Fullscreen</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
@@ -82,23 +146,92 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="channel1GroupBox">
|
||||
<property name="title"><string>CH1</string></property>
|
||||
<property name="title">
|
||||
<string>CH1</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="channel1GridLayout">
|
||||
<item row="0" column="0"><widget class="QLabel" name="channel1FormatLabel"><property name="text"><string>Output format:</string></property></widget></item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="channel1FormatLabel">
|
||||
<property name="text">
|
||||
<string>Output format:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QComboBox" name="ch1OutputFormatCombo">
|
||||
<property name="toolTip"><string>Requested CH1 capture output format</string></property>
|
||||
<item><property name="text"><string>YUY2 (8-bit 4:2:2)</string></property></item>
|
||||
<item><property name="text"><string>Y210 (10-bit 4:2:2)</string></property></item>
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Requested CH1 capture output format</string>
|
||||
</property>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>YUY2 (8-bit 4:2:2)</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Y210 (10-bit 4:2:2)</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QCheckBox" name="ch1ZeroCopyCheckBox">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="toolTip">
|
||||
<string>Must be selected before opening CH1</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Zero-copy</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2"><widget class="QCheckBox" name="ch1ZeroCopyCheckBox"><property name="toolTip"><string>Must be selected before opening CH1</string></property><property name="text"><string>Zero-copy</string></property></widget></item>
|
||||
<item row="1" column="0" colspan="3">
|
||||
<layout class="QHBoxLayout" name="channel1ButtonLayout">
|
||||
<item><widget class="QPushButton" name="ch1StartButton"><property name="text"><string>Start</string></property></widget></item>
|
||||
<item><widget class="QPushButton" name="ch1StopButton"><property name="text"><string>Stop</string></property></widget></item>
|
||||
<item><widget class="QPushButton" name="ch1PreviewButton"><property name="text"><string>Open view</string></property></widget></item>
|
||||
<item><widget class="QPushButton" name="ch1FullscreenButton"><property name="text"><string>Fullscreen</string></property></widget></item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="ch1StartButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Start</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="ch1StopButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Stop</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="ch1PreviewButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Open view</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="ch1FullscreenButton">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Fullscreen</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
||||
@@ -14,3 +14,21 @@ When adding a driver operation:
|
||||
for invalid caller output pointers.
|
||||
|
||||
The header is an internal dependency of `gvfg`; it is not a customer SDK API.
|
||||
|
||||
## Current audio ABI
|
||||
|
||||
The implemented audio path is copy-out, not zero-copy:
|
||||
|
||||
- Register `GIGA_IOCTL_EVENT_AUDIO_DMA` and
|
||||
`GIGA_IOCTL_EVENT_EXTRA_AUDIO_FRAME` as wake-up notifications.
|
||||
- Start and stop capture with `giga_ioctl_start_video_audio()` and
|
||||
`giga_ioctl_stop_video_audio()`.
|
||||
- Query the PCM layout and driver frame size with
|
||||
`giga_ioctl_get_audio_info()`.
|
||||
- Read the next available driver frame with `giga_ioctl_get_audio_frame()` and
|
||||
`frame_index == UINT32_MAX`. The returned byte count is the valid copy size.
|
||||
|
||||
The extra-frame events mean that more frames are ready and the consumer should
|
||||
drain promptly. They do not transfer ownership of a frame. Audio zero-copy is a
|
||||
future driver capability and is intentionally not exposed here until its
|
||||
acquire/release ABI is complete.
|
||||
|
||||
@@ -20,9 +20,20 @@ enum giga_ioctl_event_type
|
||||
GIGA_IOCTL_EVENT_VIDEO_FORMAT_CHANGE = 1,
|
||||
GIGA_IOCTL_EVENT_VIDEO_PLUGIN = 2,
|
||||
GIGA_IOCTL_EVENT_VIDEO_UNPLUG = 3,
|
||||
GIGA_IOCTL_EVENT_AUDIO_DMA = 4
|
||||
GIGA_IOCTL_EVENT_AUDIO_DMA = 4,
|
||||
GIGA_IOCTL_EVENT_EXTRA_VIDEO_FRAME = 5,
|
||||
GIGA_IOCTL_EVENT_EXTRA_AUDIO_FRAME = 6
|
||||
};
|
||||
|
||||
typedef struct giga_ioctl_audio_info
|
||||
{
|
||||
uint16_t channels;
|
||||
uint16_t samples_per_second;
|
||||
uint16_t bits_per_sample;
|
||||
uint16_t frames_per_second;
|
||||
uint32_t frame_buffer_size;
|
||||
} giga_ioctl_audio_info;
|
||||
|
||||
GIGA_IOCTL_API BOOL giga_ioctl_read_register(HANDLE device, uint32_t offset, uint32_t *value);
|
||||
GIGA_IOCTL_API BOOL giga_ioctl_write_register(HANDLE device, uint32_t offset, uint32_t value);
|
||||
GIGA_IOCTL_API BOOL giga_ioctl_register_event(HANDLE device, uint32_t channel,
|
||||
@@ -30,8 +41,15 @@ GIGA_IOCTL_API BOOL giga_ioctl_register_event(HANDLE device, uint32_t channel,
|
||||
GIGA_IOCTL_API BOOL giga_ioctl_unregister_event(HANDLE device, uint32_t channel, uint32_t type);
|
||||
GIGA_IOCTL_API BOOL giga_ioctl_get_frame(HANDLE device, uint32_t channel, uint32_t frame_index,
|
||||
void *buffer, uint32_t buffer_size, uint32_t *bytes_returned);
|
||||
GIGA_IOCTL_API BOOL giga_ioctl_get_audio_frame(HANDLE device, uint32_t channel,
|
||||
uint32_t frame_index, void *buffer,
|
||||
uint32_t buffer_size, uint32_t *bytes_returned);
|
||||
GIGA_IOCTL_API BOOL giga_ioctl_video_start(HANDLE device, uint32_t channel);
|
||||
GIGA_IOCTL_API BOOL giga_ioctl_video_stop(HANDLE device, uint32_t channel);
|
||||
GIGA_IOCTL_API BOOL giga_ioctl_start_video_audio(HANDLE device, uint32_t channel);
|
||||
GIGA_IOCTL_API BOOL giga_ioctl_stop_video_audio(HANDLE device, uint32_t channel);
|
||||
GIGA_IOCTL_API BOOL giga_ioctl_get_audio_info(HANDLE device, uint32_t channel,
|
||||
giga_ioctl_audio_info *info);
|
||||
GIGA_IOCTL_API BOOL giga_ioctl_release_video_frame(HANDLE device, uint32_t channel);
|
||||
GIGA_IOCTL_API BOOL giga_ioctl_acquire_video_frame_zerocopy(HANDLE device, uint32_t channel,
|
||||
const void **frame_address);
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#include <limits>
|
||||
|
||||
static_assert(sizeof(GIGA_AUDIO_INFO) == 12, "GIGA_AUDIO_INFO driver ABI size must remain 12 bytes");
|
||||
|
||||
namespace
|
||||
{
|
||||
BOOL send_ioctl(HANDLE device,
|
||||
@@ -84,6 +86,22 @@ extern "C"
|
||||
return ok;
|
||||
}
|
||||
|
||||
BOOL giga_ioctl_get_audio_frame(HANDLE device, uint32_t channel,
|
||||
uint32_t frame_index, void *buffer,
|
||||
uint32_t buffer_size, uint32_t *bytes_returned)
|
||||
{
|
||||
if (!buffer || !bytes_returned)
|
||||
return invalid_output_pointer();
|
||||
|
||||
GIGA_FRAME_REQUEST request{channel, frame_index};
|
||||
DWORD returned = 0;
|
||||
const BOOL ok = send_ioctl(device, IOCTL_PCIES2MM_GET_AUDIO_FRAME,
|
||||
&request, sizeof(request),
|
||||
buffer, buffer_size, &returned);
|
||||
*bytes_returned = returned;
|
||||
return ok;
|
||||
}
|
||||
|
||||
BOOL giga_ioctl_video_start(HANDLE device, uint32_t channel)
|
||||
{
|
||||
return send_channel_ioctl(device, IOCTL_GIGA_VIDEO_START, channel);
|
||||
@@ -94,6 +112,44 @@ extern "C"
|
||||
return send_channel_ioctl(device, IOCTL_GIGA_VIDEO_STOP, channel);
|
||||
}
|
||||
|
||||
BOOL giga_ioctl_start_video_audio(HANDLE device, uint32_t channel)
|
||||
{
|
||||
return send_channel_ioctl(device, IOCTL_GIGA_START_VIDEO_AUDIO, channel);
|
||||
}
|
||||
|
||||
BOOL giga_ioctl_stop_video_audio(HANDLE device, uint32_t channel)
|
||||
{
|
||||
return send_channel_ioctl(device, IOCTL_GIGA_STOP_VIDEO_AUDIO, channel);
|
||||
}
|
||||
|
||||
BOOL giga_ioctl_get_audio_info(HANDLE device, uint32_t channel,
|
||||
giga_ioctl_audio_info *info)
|
||||
{
|
||||
if (!info)
|
||||
return invalid_output_pointer();
|
||||
|
||||
ULONG channel_index = channel;
|
||||
GIGA_AUDIO_INFO driver_info{};
|
||||
DWORD returned = 0;
|
||||
const BOOL ok = send_ioctl(device, IOCTL_GIGA_GET_AUDIO_INFO,
|
||||
&channel_index, sizeof(channel_index),
|
||||
&driver_info, sizeof(driver_info), &returned);
|
||||
if (!ok)
|
||||
return FALSE;
|
||||
if (returned != sizeof(driver_info))
|
||||
{
|
||||
SetLastError(ERROR_INVALID_DATA);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
info->channels = driver_info.Channels;
|
||||
info->samples_per_second = driver_info.SamplesPerSec;
|
||||
info->bits_per_sample = driver_info.BitsPerSample;
|
||||
info->frames_per_second = driver_info.FramesPerSec;
|
||||
info->frame_buffer_size = driver_info.FrameBufSize;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
BOOL giga_ioctl_release_video_frame(HANDLE device, uint32_t channel)
|
||||
{
|
||||
return send_channel_ioctl(device, IOCTL_GIGA_RELEASE_VIDEO_FRAME, channel);
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
#define IOCTL_PCIES2MM_GET_FRAME \
|
||||
GIGA_IOCTL_CODE(0x803, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
|
||||
#define IOCTL_PCIES2MM_UNREGISTER_EVENT GIGA_IOCTL_CODE(0x804, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_PCIES2MM_GET_AUDIO_FRAME \
|
||||
GIGA_IOCTL_CODE(0x809, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS)
|
||||
|
||||
#define IOCTL_GIGA_VIDEO_START GIGA_IOCTL_CODE(0x830, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_GIGA_VIDEO_STOP GIGA_IOCTL_CODE(0x831, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
@@ -18,7 +20,18 @@
|
||||
GIGA_IOCTL_CODE(0x833, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_GIGA_ENABLE_FRAME_ZEROCOPY GIGA_IOCTL_CODE(0x834, METHOD_NEITHER, FILE_ANY_ACCESS)
|
||||
#define IOCTL_GIGA_DISABLE_FRAME_ZEROCOPY GIGA_IOCTL_CODE(0x835, METHOD_NEITHER, FILE_ANY_ACCESS)
|
||||
#define IOCTL_GIGA_START_VIDEO_AUDIO GIGA_IOCTL_CODE(0x839, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_GIGA_STOP_VIDEO_AUDIO GIGA_IOCTL_CODE(0x83A, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
#define IOCTL_GIGA_GET_AUDIO_INFO GIGA_IOCTL_CODE(0x83B, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
struct GIGA_REG_ACCESS { ULONG Offset; ULONG Value; };
|
||||
struct GIGA_EVENT_REG { ULONG Type; ULONG ChannelIndex; HANDLE EventHandle; };
|
||||
struct GIGA_FRAME_REQUEST { ULONG ChannelIndex; ULONG FrameIndex; };
|
||||
struct GIGA_AUDIO_INFO
|
||||
{
|
||||
UINT16 Channels;
|
||||
UINT16 SamplesPerSec;
|
||||
UINT16 BitsPerSample;
|
||||
UINT16 FramesPerSec;
|
||||
UINT32 FrameBufSize;
|
||||
};
|
||||
|
||||
@@ -109,6 +109,22 @@ extern "C"
|
||||
GVFG_CHANNEL_1 = 1
|
||||
} gvfg_channel_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_STREAM_VIDEO = 1u << 0,
|
||||
GVFG_STREAM_AUDIO = 1u << 1
|
||||
} gvfg_stream_flag_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t sample_rate;
|
||||
uint32_t channels;
|
||||
uint32_t bits_per_sample;
|
||||
uint32_t frames_per_second;
|
||||
uint32_t frame_bytes;
|
||||
uint32_t block_align;
|
||||
} gvfg_audio_format_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
char name[128]; /* Display name for UI/logging. UTF-8, null-terminated. */
|
||||
@@ -128,6 +144,12 @@ extern "C"
|
||||
{
|
||||
double capture_fps; /* Runtime FPS measured from frames returned by gvfg_read_channel_frame(). */
|
||||
uint64_t delivered_frames; /* Number of frames returned by gvfg_read_channel_frame(). */
|
||||
int zero_copy_enabled; /* Non-zero when driver zero-copy delivery is selected. */
|
||||
uint32_t reserved;
|
||||
uint64_t driver_read_samples;
|
||||
double driver_read_average_us;
|
||||
double driver_read_max300_us;
|
||||
double driver_read_max_us;
|
||||
} gvfg_runtime_info_t;
|
||||
|
||||
typedef struct
|
||||
@@ -316,6 +338,21 @@ extern "C"
|
||||
_In_ int channel_index,
|
||||
_In_ gvfg_pixel_format_t format);
|
||||
|
||||
/*
|
||||
* Select video-only or combined video+audio capture before starting the
|
||||
* channel. The default is GVFG_STREAM_VIDEO. Audio-only capture is not
|
||||
* supported by the current driver ABI.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_set_channel_streams(
|
||||
_In_ gvfg_handle handle,
|
||||
_In_ int channel_index,
|
||||
_In_ uint32_t streams);
|
||||
|
||||
GVFG_API gvfg_status_t gvfg_get_channel_audio_format(
|
||||
_In_ gvfg_handle handle,
|
||||
_In_ int channel_index,
|
||||
_Out_ gvfg_audio_format_t *out_format);
|
||||
|
||||
/*
|
||||
* Configure and start capture on an opened device.
|
||||
*
|
||||
@@ -384,6 +421,19 @@ extern "C"
|
||||
_In_ int channel_index,
|
||||
_In_ const gvfg_frame_t *frame);
|
||||
|
||||
/*
|
||||
* Copy one PCM frame from the driver into caller-owned memory. The channel
|
||||
* must have been started with GVFG_STREAM_VIDEO | GVFG_STREAM_AUDIO.
|
||||
* out_bytes receives the valid byte count reported by the driver.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_read_channel_audio(
|
||||
_In_ gvfg_handle handle,
|
||||
_In_ int channel_index,
|
||||
_Out_writes_bytes_(destination_capacity) void *destination,
|
||||
_In_ uint32_t destination_capacity,
|
||||
_Out_ uint32_t *out_bytes,
|
||||
_In_ uint32_t timeout_ms);
|
||||
|
||||
/*
|
||||
* Convert a captured YUY2 or Y210 frame with the GPU and copy the result
|
||||
* into caller-owned memory.
|
||||
|
||||
@@ -58,6 +58,16 @@ typedef struct pcies2mm_frame_t
|
||||
uint32_t bit_depth;
|
||||
} pcies2mm_frame_t;
|
||||
|
||||
typedef struct pcies2mm_audio_format_t
|
||||
{
|
||||
uint32_t sample_rate;
|
||||
uint32_t channels;
|
||||
uint32_t bits_per_sample;
|
||||
uint32_t frames_per_second;
|
||||
uint32_t frame_bytes;
|
||||
uint32_t block_align;
|
||||
} pcies2mm_audio_format_t;
|
||||
|
||||
typedef struct pcies2mm_stream_stats_t
|
||||
{
|
||||
pcies2mm_stream_state_t state;
|
||||
|
||||
@@ -61,22 +61,23 @@ namespace
|
||||
|
||||
static std::string win32_error(DWORD err)
|
||||
{
|
||||
char *msg = nullptr;
|
||||
const DWORD len = FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
wchar_t *msg = nullptr;
|
||||
const DWORD len = FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
nullptr,
|
||||
err,
|
||||
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
|
||||
reinterpret_cast<LPSTR>(&msg),
|
||||
reinterpret_cast<LPWSTR>(&msg),
|
||||
0,
|
||||
nullptr);
|
||||
std::string out;
|
||||
if (len && msg)
|
||||
{
|
||||
out.assign(msg, msg + len);
|
||||
while (!out.empty() && (out.back() == '\r' || out.back() == '\n' || out.back() == ' '))
|
||||
out.pop_back();
|
||||
std::wstring wide(msg, msg + len);
|
||||
while (!wide.empty() && (wide.back() == L'\r' || wide.back() == L'\n' || wide.back() == L' '))
|
||||
wide.pop_back();
|
||||
out = wide_to_utf8(wide);
|
||||
}
|
||||
if (msg)
|
||||
LocalFree(msg);
|
||||
@@ -311,6 +312,55 @@ namespace gvfg::internal
|
||||
return PCIES2MM_OK;
|
||||
}
|
||||
|
||||
pcies2mm_status_t PcieS2mmCaptureSession::set_audio_enabled(bool enabled)
|
||||
{
|
||||
if (device_handle() == INVALID_HANDLE_VALUE)
|
||||
return reject(PCIES2MM_ESTATE, "set audio enabled rejected: device is not open");
|
||||
if (running_)
|
||||
return reject(PCIES2MM_ESTATE, "set audio enabled rejected: stream is running");
|
||||
if (enabled && active_channel() != 0)
|
||||
return reject(PCIES2MM_ENOTSUP, "audio capture is currently supported only on channel 0");
|
||||
|
||||
if (audio_enabled_ == enabled)
|
||||
return PCIES2MM_OK;
|
||||
|
||||
// Event handles are created according to audio_enabled_. Rebuild the
|
||||
// registrations when the stopped channel changes between video-only
|
||||
// and video+audio; otherwise the new audio handles remain null.
|
||||
const bool wasMonitoring = monitoring_.load(std::memory_order_acquire);
|
||||
if (wasMonitoring)
|
||||
stop_event_monitoring();
|
||||
audio_enabled_ = enabled;
|
||||
if (wasMonitoring && !start_event_monitoring())
|
||||
return fail(PCIES2MM_EIO, "restart event monitoring after audio stream change");
|
||||
return PCIES2MM_OK;
|
||||
}
|
||||
|
||||
pcies2mm_status_t PcieS2mmCaptureSession::get_audio_format(pcies2mm_audio_format_t &out) const
|
||||
{
|
||||
std::memset(&out, 0, sizeof(out));
|
||||
if (device_handle() == INVALID_HANDLE_VALUE)
|
||||
return reject(PCIES2MM_ESTATE, "get audio format rejected: device is not open");
|
||||
if (active_channel() != 0)
|
||||
return reject(PCIES2MM_ENOTSUP, "audio capture is currently supported only on channel 0");
|
||||
|
||||
giga_ioctl_audio_info info{};
|
||||
if (!giga_ioctl_get_audio_info(device_handle(), active_channel(), &info))
|
||||
return fail(PCIES2MM_EIO, "get audio info");
|
||||
if (info.channels == 0 || info.samples_per_second == 0 ||
|
||||
info.bits_per_sample == 0 || info.frames_per_second == 0 ||
|
||||
info.frame_buffer_size == 0 || (info.bits_per_sample % 8) != 0)
|
||||
return reject(PCIES2MM_EIO, "driver returned an invalid audio format");
|
||||
|
||||
out.sample_rate = info.samples_per_second;
|
||||
out.channels = info.channels;
|
||||
out.bits_per_sample = info.bits_per_sample;
|
||||
out.frames_per_second = info.frames_per_second;
|
||||
out.frame_bytes = info.frame_buffer_size;
|
||||
out.block_align = info.channels * (info.bits_per_sample / 8);
|
||||
return PCIES2MM_OK;
|
||||
}
|
||||
|
||||
pcies2mm_status_t PcieS2mmCaptureSession::get_signal_status(pcies2mm_signal_status_t &out) const
|
||||
{
|
||||
if (device_handle() == INVALID_HANDLE_VALUE)
|
||||
@@ -433,6 +483,7 @@ namespace gvfg::internal
|
||||
held_frame_ = {};
|
||||
frame_held_ = false;
|
||||
read_in_progress_ = false;
|
||||
audio_read_in_progress_ = false;
|
||||
active_delivery_started_ = {};
|
||||
latest_sequence_ = 0;
|
||||
delivered_sequence_ = 0;
|
||||
@@ -490,14 +541,20 @@ namespace gvfg::internal
|
||||
stream_ready_pending_ = false;
|
||||
|
||||
if (device_handle() != INVALID_HANDLE_VALUE)
|
||||
stop_video(active_channel());
|
||||
stop_capture(active_channel());
|
||||
|
||||
if (dma_event_)
|
||||
SetEvent(dma_event_);
|
||||
if (audio_event_)
|
||||
SetEvent(audio_event_);
|
||||
if (extra_video_event_)
|
||||
SetEvent(extra_video_event_);
|
||||
if (extra_audio_event_)
|
||||
SetEvent(extra_audio_event_);
|
||||
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
read_finished_cv_.wait(lock, [this] { return !read_in_progress_; });
|
||||
read_finished_cv_.wait(lock, [this] { return !read_in_progress_ && !audio_read_in_progress_; });
|
||||
}
|
||||
const pcies2mm_status_t releaseStatus = release_all_zero_copy_frames(true);
|
||||
stop_event_monitoring();
|
||||
@@ -506,11 +563,30 @@ namespace gvfg::internal
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
held_frame_ = {};
|
||||
frame_held_ = false;
|
||||
audio_read_in_progress_ = false;
|
||||
stats_.state = configured_ ? PCIES2MM_STREAM_CONFIGURED : PCIES2MM_STREAM_STOPPED;
|
||||
}
|
||||
return releaseStatus;
|
||||
}
|
||||
|
||||
pcies2mm_status_t PcieS2mmCaptureSession::ensure_capture_started()
|
||||
{
|
||||
if (capture_active_.load(std::memory_order_acquire))
|
||||
return PCIES2MM_OK;
|
||||
if (!signal_presence_known_.load(std::memory_order_acquire) ||
|
||||
!signal_present_.load(std::memory_order_acquire))
|
||||
return PCIES2MM_ETIMEOUT;
|
||||
if (!ResetEvent(dma_event_) || !ResetEvent(extra_video_event_) ||
|
||||
(audio_enabled_ &&
|
||||
(!ResetEvent(audio_event_) || !ResetEvent(extra_audio_event_))))
|
||||
return fail(PCIES2MM_EIO, "reset capture event");
|
||||
if (!start_capture(active_channel()))
|
||||
return fail(PCIES2MM_EIO, "enable reader capture");
|
||||
capture_active_.store(true, std::memory_order_release);
|
||||
stream_ready_pending_.store(true, std::memory_order_release);
|
||||
return PCIES2MM_OK;
|
||||
}
|
||||
|
||||
pcies2mm_status_t PcieS2mmCaptureSession::wait_frame(uint32_t timeoutMs, pcies2mm_frame_t &out)
|
||||
{
|
||||
constexpr uint64_t kTimingWarmupFrames = 30;
|
||||
@@ -520,28 +596,9 @@ namespace gvfg::internal
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
if (!running_ || frame_held_ || read_in_progress_)
|
||||
return reject(PCIES2MM_ESTATE, "wait frame rejected: stream state does not allow another read");
|
||||
if (!capture_active_.load(std::memory_order_acquire))
|
||||
{
|
||||
if (!signal_presence_known_.load(std::memory_order_acquire) ||
|
||||
!signal_present_.load(std::memory_order_acquire))
|
||||
return PCIES2MM_ETIMEOUT;
|
||||
if (!ResetEvent(dma_event_))
|
||||
{
|
||||
const DWORD err = GetLastError();
|
||||
++stats_.dma_errors;
|
||||
lock.unlock();
|
||||
return fail(PCIES2MM_EIO, "reset DMA event", err);
|
||||
}
|
||||
if (!start_video(active_channel()))
|
||||
{
|
||||
const DWORD err = GetLastError();
|
||||
++stats_.dma_errors;
|
||||
lock.unlock();
|
||||
return fail(PCIES2MM_EIO, "enable reader capture", err);
|
||||
}
|
||||
capture_active_.store(true, std::memory_order_release);
|
||||
stream_ready_pending_.store(true, std::memory_order_release);
|
||||
}
|
||||
const pcies2mm_status_t startStatus = ensure_capture_started();
|
||||
if (startStatus != PCIES2MM_OK)
|
||||
return startStatus;
|
||||
read_in_progress_ = true;
|
||||
}
|
||||
|
||||
@@ -573,7 +630,8 @@ namespace gvfg::internal
|
||||
}
|
||||
}
|
||||
|
||||
const DWORD waitResult = WaitForSingleObject(dma_event_, waitMs);
|
||||
HANDLE videoReadyEvents[] = {dma_event_, extra_video_event_};
|
||||
const DWORD waitResult = WaitForMultipleObjects(2, videoReadyEvents, FALSE, waitMs);
|
||||
if (waitResult == WAIT_TIMEOUT)
|
||||
{
|
||||
{
|
||||
@@ -583,7 +641,7 @@ namespace gvfg::internal
|
||||
finishRead();
|
||||
return PCIES2MM_ETIMEOUT;
|
||||
}
|
||||
if (waitResult != WAIT_OBJECT_0)
|
||||
if (waitResult != WAIT_OBJECT_0 && waitResult != WAIT_OBJECT_0 + 1)
|
||||
{
|
||||
const DWORD err = GetLastError();
|
||||
finishRead();
|
||||
@@ -678,6 +736,109 @@ namespace gvfg::internal
|
||||
return PCIES2MM_OK;
|
||||
}
|
||||
|
||||
pcies2mm_status_t PcieS2mmCaptureSession::wait_audio(uint32_t timeoutMs,
|
||||
void *destination,
|
||||
uint32_t destinationCapacity,
|
||||
uint32_t &outBytes)
|
||||
{
|
||||
outBytes = 0;
|
||||
if (!destination || destinationCapacity == 0)
|
||||
return reject(PCIES2MM_EINVAL, "wait audio rejected: destination is invalid");
|
||||
|
||||
pcies2mm_audio_format_t format{};
|
||||
const pcies2mm_status_t formatStatus = get_audio_format(format);
|
||||
if (formatStatus != PCIES2MM_OK)
|
||||
return formatStatus;
|
||||
if (destinationCapacity < format.frame_bytes)
|
||||
return reject(PCIES2MM_EINVAL, "wait audio rejected: destination is smaller than the driver frame");
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
if (!running_ || !audio_enabled_ || audio_read_in_progress_)
|
||||
return reject(PCIES2MM_ESTATE, "wait audio rejected: stream state does not allow another audio read");
|
||||
const pcies2mm_status_t startStatus = ensure_capture_started();
|
||||
if (startStatus != PCIES2MM_OK)
|
||||
return startStatus;
|
||||
audio_read_in_progress_ = true;
|
||||
}
|
||||
|
||||
const auto finishRead = [this]() {
|
||||
std::lock_guard<std::mutex> lock(mutex_);
|
||||
audio_read_in_progress_ = false;
|
||||
read_finished_cv_.notify_all();
|
||||
};
|
||||
const bool infiniteWait = timeoutMs == UINT32_MAX;
|
||||
const auto deadline = infiniteWait
|
||||
? (std::chrono::steady_clock::time_point::max)()
|
||||
: std::chrono::steady_clock::now() + std::chrono::milliseconds(timeoutMs);
|
||||
|
||||
for (;;)
|
||||
{
|
||||
DWORD waitMs = INFINITE;
|
||||
if (!infiniteWait)
|
||||
{
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
if (now >= deadline)
|
||||
waitMs = 0;
|
||||
else
|
||||
{
|
||||
const auto remainingUs = std::chrono::duration_cast<std::chrono::microseconds>(deadline - now).count();
|
||||
waitMs = static_cast<DWORD>((remainingUs + 999) / 1000);
|
||||
}
|
||||
}
|
||||
|
||||
HANDLE audioReadyEvents[] = {audio_event_, extra_audio_event_};
|
||||
const DWORD waitResult = WaitForMultipleObjects(2, audioReadyEvents, FALSE, waitMs);
|
||||
if (waitResult == WAIT_TIMEOUT)
|
||||
{
|
||||
finishRead();
|
||||
return PCIES2MM_ETIMEOUT;
|
||||
}
|
||||
if (waitResult != WAIT_OBJECT_0 && waitResult != WAIT_OBJECT_0 + 1)
|
||||
{
|
||||
const DWORD err = GetLastError();
|
||||
finishRead();
|
||||
return fail(PCIES2MM_EIO, "wait audio event", err);
|
||||
}
|
||||
if (!running_.load(std::memory_order_acquire))
|
||||
{
|
||||
finishRead();
|
||||
return PCIES2MM_ESTATE;
|
||||
}
|
||||
if (!capture_active_.load(std::memory_order_acquire))
|
||||
{
|
||||
finishRead();
|
||||
return PCIES2MM_ETIMEOUT;
|
||||
}
|
||||
|
||||
const int ret = get_audio_frame(active_channel(),
|
||||
(std::numeric_limits<uint32_t>::max)(),
|
||||
destination,
|
||||
destinationCapacity);
|
||||
if (ret >= 0)
|
||||
{
|
||||
if (ret == 0 || static_cast<uint32_t>(ret) > format.frame_bytes)
|
||||
{
|
||||
finishRead();
|
||||
return reject(PCIES2MM_EIO, "driver returned an invalid audio byte count");
|
||||
}
|
||||
if (static_cast<uint32_t>(ret) != format.frame_bytes)
|
||||
PCIES2MM_LOG("audio frame size mismatch: expected=%u returned=%d",
|
||||
format.frame_bytes, ret);
|
||||
outBytes = static_cast<uint32_t>(ret);
|
||||
finishRead();
|
||||
return PCIES2MM_OK;
|
||||
}
|
||||
|
||||
const DWORD frameError = GetLastError();
|
||||
if (!is_transient_frame_not_ready_error(frameError))
|
||||
{
|
||||
finishRead();
|
||||
return fail(PCIES2MM_EIO, "copy get audio frame", frameError);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pcies2mm_status_t PcieS2mmCaptureSession::release_frame(const pcies2mm_frame_t &frame)
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
@@ -766,6 +927,20 @@ namespace gvfg::internal
|
||||
return giga_ioctl_video_stop(device_handle(), channelIndex) != FALSE;
|
||||
}
|
||||
|
||||
bool PcieS2mmCaptureSession::start_capture(uint32_t channelIndex) const
|
||||
{
|
||||
return audio_enabled_
|
||||
? giga_ioctl_start_video_audio(device_handle(), channelIndex) != FALSE
|
||||
: start_video(channelIndex);
|
||||
}
|
||||
|
||||
bool PcieS2mmCaptureSession::stop_capture(uint32_t channelIndex) const
|
||||
{
|
||||
return audio_enabled_
|
||||
? giga_ioctl_stop_video_audio(device_handle(), channelIndex) != FALSE
|
||||
: stop_video(channelIndex);
|
||||
}
|
||||
|
||||
bool PcieS2mmCaptureSession::acquire_zero_copy_frame(uint32_t channelIndex,
|
||||
const uint8_t *&outData) const
|
||||
{
|
||||
@@ -821,14 +996,28 @@ namespace gvfg::internal
|
||||
bool PcieS2mmCaptureSession::create_and_register_events(uint32_t channelIndex)
|
||||
{
|
||||
dma_event_ = CreateEventW(nullptr, FALSE, FALSE, nullptr);
|
||||
extra_video_event_ = CreateEventW(nullptr, FALSE, FALSE, nullptr);
|
||||
if (audio_enabled_)
|
||||
{
|
||||
audio_event_ = CreateEventW(nullptr, FALSE, FALSE, nullptr);
|
||||
extra_audio_event_ = CreateEventW(nullptr, FALSE, FALSE, nullptr);
|
||||
}
|
||||
format_change_event_ = CreateEventW(nullptr, FALSE, FALSE, nullptr);
|
||||
plug_in_event_ = CreateEventW(nullptr, FALSE, FALSE, nullptr);
|
||||
plug_out_event_ = CreateEventW(nullptr, FALSE, FALSE, nullptr);
|
||||
if (!dma_event_ || !format_change_event_ || !plug_in_event_ || !plug_out_event_)
|
||||
if (!dma_event_ || !extra_video_event_ ||
|
||||
(audio_enabled_ && (!audio_event_ || !extra_audio_event_)) ||
|
||||
!format_change_event_ || !plug_in_event_ || !plug_out_event_)
|
||||
return false;
|
||||
|
||||
if (!register_event(channelIndex, GIGA_IOCTL_EVENT_VIDEO_DMA, dma_event_))
|
||||
return false;
|
||||
if (!register_event(channelIndex, GIGA_IOCTL_EVENT_EXTRA_VIDEO_FRAME, extra_video_event_))
|
||||
return false;
|
||||
if (audio_enabled_ &&
|
||||
(!register_event(channelIndex, GIGA_IOCTL_EVENT_AUDIO_DMA, audio_event_) ||
|
||||
!register_event(channelIndex, GIGA_IOCTL_EVENT_EXTRA_AUDIO_FRAME, extra_audio_event_)))
|
||||
return false;
|
||||
if ((event_mask_filter_ & PCIES2MM_EVENT_MASK_FORMAT_CHANGE_BEGIN) != 0 &&
|
||||
!register_event(channelIndex, GIGA_IOCTL_EVENT_VIDEO_FORMAT_CHANGE, format_change_event_))
|
||||
return false;
|
||||
@@ -844,6 +1033,12 @@ namespace gvfg::internal
|
||||
void PcieS2mmCaptureSession::unregister_events(uint32_t channelIndex)
|
||||
{
|
||||
unregister_event(channelIndex, GIGA_IOCTL_EVENT_VIDEO_DMA);
|
||||
unregister_event(channelIndex, GIGA_IOCTL_EVENT_EXTRA_VIDEO_FRAME);
|
||||
if (audio_enabled_)
|
||||
{
|
||||
unregister_event(channelIndex, GIGA_IOCTL_EVENT_AUDIO_DMA);
|
||||
unregister_event(channelIndex, GIGA_IOCTL_EVENT_EXTRA_AUDIO_FRAME);
|
||||
}
|
||||
if ((event_mask_filter_ & PCIES2MM_EVENT_MASK_FORMAT_CHANGE_BEGIN) != 0)
|
||||
unregister_event(channelIndex, GIGA_IOCTL_EVENT_VIDEO_FORMAT_CHANGE);
|
||||
if ((event_mask_filter_ & PCIES2MM_EVENT_MASK_PLUG_IN) != 0)
|
||||
@@ -859,6 +1054,21 @@ namespace gvfg::internal
|
||||
CloseHandle(dma_event_);
|
||||
dma_event_ = nullptr;
|
||||
}
|
||||
if (audio_event_)
|
||||
{
|
||||
CloseHandle(audio_event_);
|
||||
audio_event_ = nullptr;
|
||||
}
|
||||
if (extra_video_event_)
|
||||
{
|
||||
CloseHandle(extra_video_event_);
|
||||
extra_video_event_ = nullptr;
|
||||
}
|
||||
if (extra_audio_event_)
|
||||
{
|
||||
CloseHandle(extra_audio_event_);
|
||||
extra_audio_event_ = nullptr;
|
||||
}
|
||||
if (format_change_event_)
|
||||
{
|
||||
CloseHandle(format_change_event_);
|
||||
@@ -912,6 +1122,12 @@ namespace gvfg::internal
|
||||
|
||||
if (dma_event_)
|
||||
SetEvent(dma_event_);
|
||||
if (audio_event_)
|
||||
SetEvent(audio_event_);
|
||||
if (extra_video_event_)
|
||||
SetEvent(extra_video_event_);
|
||||
if (extra_audio_event_)
|
||||
SetEvent(extra_audio_event_);
|
||||
if (capture_thread_.joinable())
|
||||
capture_thread_.join();
|
||||
|
||||
@@ -930,6 +1146,19 @@ namespace gvfg::internal
|
||||
return static_cast<int>(bytesReturned);
|
||||
}
|
||||
|
||||
int PcieS2mmCaptureSession::get_audio_frame(uint32_t channelIndex,
|
||||
uint32_t frameIndex,
|
||||
void *buffer,
|
||||
DWORD bufferSize) const
|
||||
{
|
||||
uint32_t bytesReturned = 0;
|
||||
const BOOL ok = giga_ioctl_get_audio_frame(device_handle(), channelIndex, frameIndex,
|
||||
buffer, bufferSize, &bytesReturned);
|
||||
if (!ok)
|
||||
return -1;
|
||||
return static_cast<int>(bytesReturned);
|
||||
}
|
||||
|
||||
void PcieS2mmCaptureSession::capture_thread_proc()
|
||||
{
|
||||
const uint32_t channel = active_channel();
|
||||
@@ -985,14 +1214,18 @@ namespace gvfg::internal
|
||||
signal_metadata_valid_ = false;
|
||||
}
|
||||
emit_event(PCIES2MM_EVENT_FORMAT_CHANGE_BEGIN);
|
||||
stop_video(channel);
|
||||
stop_capture(channel);
|
||||
capture_active_ = false;
|
||||
stream_ready_pending_ = false;
|
||||
if (dma_event_)
|
||||
SetEvent(dma_event_);
|
||||
if (audio_event_)
|
||||
SetEvent(audio_event_);
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
read_finished_cv_.wait(lock, [this] { return !read_in_progress_ && !frame_held_; });
|
||||
read_finished_cv_.wait(lock, [this] {
|
||||
return !read_in_progress_ && !audio_read_in_progress_ && !frame_held_;
|
||||
});
|
||||
}
|
||||
if (running_.load(std::memory_order_acquire))
|
||||
refresh_stream_from_registers(true);
|
||||
@@ -1006,10 +1239,12 @@ namespace gvfg::internal
|
||||
|
||||
if (capture_active_.exchange(false, std::memory_order_acq_rel))
|
||||
{
|
||||
stop_video(channel);
|
||||
stop_capture(channel);
|
||||
}
|
||||
if (dma_event_)
|
||||
SetEvent(dma_event_);
|
||||
if (audio_event_)
|
||||
SetEvent(audio_event_);
|
||||
signal_probe_active_.store(false, std::memory_order_release);
|
||||
signal_present_.store(true, std::memory_order_release);
|
||||
signal_presence_known_.store(true, std::memory_order_release);
|
||||
@@ -1020,7 +1255,9 @@ namespace gvfg::internal
|
||||
emit_event(PCIES2MM_EVENT_PLUG_IN);
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(mutex_);
|
||||
read_finished_cv_.wait(lock, [this] { return !read_in_progress_ && !frame_held_; });
|
||||
read_finished_cv_.wait(lock, [this] {
|
||||
return !read_in_progress_ && !audio_read_in_progress_ && !frame_held_;
|
||||
});
|
||||
}
|
||||
if (running_.load(std::memory_order_acquire))
|
||||
refresh_stream_from_registers(true);
|
||||
@@ -1032,10 +1269,12 @@ namespace gvfg::internal
|
||||
stream_ready_pending_.store(false, std::memory_order_release);
|
||||
signal_present_.store(false, std::memory_order_release);
|
||||
signal_presence_known_.store(true, std::memory_order_release);
|
||||
stop_video(channel);
|
||||
stop_capture(channel);
|
||||
capture_active_ = false;
|
||||
if (dma_event_)
|
||||
SetEvent(dma_event_);
|
||||
if (audio_event_)
|
||||
SetEvent(audio_event_);
|
||||
emit_event(PCIES2MM_EVENT_PLUG_OUT);
|
||||
|
||||
{
|
||||
|
||||
@@ -41,14 +41,18 @@ namespace gvfg::internal
|
||||
pcies2mm_status_t set_channel(uint32_t channel);
|
||||
pcies2mm_status_t set_zero_copy_enabled(bool enabled);
|
||||
bool zero_copy_enabled() const { return zero_copy_enabled_; }
|
||||
pcies2mm_status_t set_audio_enabled(bool enabled);
|
||||
pcies2mm_status_t set_video_format(pcies2mm_pixel_format_t format);
|
||||
pcies2mm_status_t get_signal_status(pcies2mm_signal_status_t &out) const;
|
||||
pcies2mm_status_t get_audio_format(pcies2mm_audio_format_t &out) const;
|
||||
|
||||
pcies2mm_status_t set_event_callback(pcies2mm_event_callback_t callback, void *user, uint32_t eventMask);
|
||||
pcies2mm_status_t configure_stream(const pcies2mm_stream_desc_t &desc);
|
||||
pcies2mm_status_t start_stream();
|
||||
pcies2mm_status_t stop_stream();
|
||||
pcies2mm_status_t wait_frame(uint32_t timeoutMs, pcies2mm_frame_t &out);
|
||||
pcies2mm_status_t wait_audio(uint32_t timeoutMs, void *destination,
|
||||
uint32_t destinationCapacity, uint32_t &outBytes);
|
||||
pcies2mm_status_t release_frame(const pcies2mm_frame_t &frame);
|
||||
|
||||
void get_debug_stats(pcies2mm_stream_stats_t &outStats,
|
||||
@@ -66,6 +70,8 @@ namespace gvfg::internal
|
||||
bool write_reg(uint32_t offset, uint32_t value) const;
|
||||
bool start_video(uint32_t channelIndex) const;
|
||||
bool stop_video(uint32_t channelIndex) const;
|
||||
bool start_capture(uint32_t channelIndex) const;
|
||||
bool stop_capture(uint32_t channelIndex) const;
|
||||
bool acquire_zero_copy_frame(uint32_t channelIndex, const uint8_t *&outData) const;
|
||||
bool release_zero_copy_frame(uint32_t channelIndex) const;
|
||||
pcies2mm_status_t release_all_zero_copy_frames(bool includeInUse);
|
||||
@@ -77,6 +83,9 @@ namespace gvfg::internal
|
||||
void unregister_events(uint32_t channelIndex);
|
||||
void close_event_handles();
|
||||
int get_frame(uint32_t channelIndex, uint32_t frameIndex, uint8_t *buffer, DWORD bufferSize) const;
|
||||
int get_audio_frame(uint32_t channelIndex, uint32_t frameIndex,
|
||||
void *buffer, DWORD bufferSize) const;
|
||||
pcies2mm_status_t ensure_capture_started();
|
||||
|
||||
void capture_thread_proc();
|
||||
void handle_format_change_event(uint32_t channel);
|
||||
@@ -98,6 +107,9 @@ namespace gvfg::internal
|
||||
ChannelErrorState &error_state_;
|
||||
std::shared_ptr<PcieS2mmDeviceConnection> device_connection_;
|
||||
HANDLE dma_event_ = nullptr;
|
||||
HANDLE audio_event_ = nullptr;
|
||||
HANDLE extra_video_event_ = nullptr;
|
||||
HANDLE extra_audio_event_ = nullptr;
|
||||
HANDLE format_change_event_ = nullptr;
|
||||
HANDLE plug_in_event_ = nullptr;
|
||||
HANDLE plug_out_event_ = nullptr;
|
||||
@@ -107,6 +119,7 @@ namespace gvfg::internal
|
||||
uint32_t channel_ = 0;
|
||||
bool configured_ = false;
|
||||
bool zero_copy_enabled_ = false;
|
||||
bool audio_enabled_ = false;
|
||||
|
||||
std::atomic<bool> running_{false};
|
||||
std::atomic<bool> monitoring_{false};
|
||||
@@ -139,6 +152,7 @@ namespace gvfg::internal
|
||||
pcies2mm_frame_t held_frame_{};
|
||||
bool frame_held_ = false;
|
||||
bool read_in_progress_ = false;
|
||||
bool audio_read_in_progress_ = false;
|
||||
std::chrono::steady_clock::time_point active_delivery_started_{};
|
||||
bool stream_error_ = false;
|
||||
pcies2mm_stream_stats_t stats_{};
|
||||
|
||||
@@ -33,6 +33,8 @@ namespace
|
||||
static_assert(GVFG_EVENT_MASK_FORMAT_CHANGE_BEGIN == PCIES2MM_EVENT_MASK_FORMAT_CHANGE_BEGIN);
|
||||
|
||||
#if INTPTR_MAX == INT64_MAX
|
||||
static_assert(sizeof(gvfg_audio_format_t) == 24, "gvfg_audio_format_t ABI must remain frozen");
|
||||
static_assert(sizeof(gvfg_runtime_info_t) == 56, "gvfg_runtime_info_t x64 ABI must remain frozen");
|
||||
static_assert(std::is_standard_layout_v<gvfg_frame_t>);
|
||||
static_assert(sizeof(gvfg_frame_t) == 48, "gvfg_frame_t x64 ABI must remain frozen");
|
||||
static_assert(offsetof(gvfg_frame_t, data) == 0);
|
||||
@@ -314,6 +316,11 @@ struct gvfg_channel_session_t
|
||||
pcies2mm_debug_state_t debugState{};
|
||||
uint64_t waitTimeouts = 0;
|
||||
backend->get_debug_stats(stats, waitTimeouts, debugState);
|
||||
out.zero_copy_enabled = debugState.get_frame_zero_copy;
|
||||
out.driver_read_samples = debugState.get_frame_timing_samples;
|
||||
out.driver_read_average_us = debugState.get_frame_timing_average_us;
|
||||
out.driver_read_max300_us = debugState.get_frame_timing_max300_us;
|
||||
out.driver_read_max_us = debugState.get_frame_timing_max_us;
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
@@ -666,6 +673,53 @@ struct gvfg_channel_session_t
|
||||
return map_status(status);
|
||||
}
|
||||
|
||||
gvfg_status_t setStreams(uint32_t value)
|
||||
{
|
||||
if (!backend)
|
||||
return reject(GVFG_ESTATE, "gvfg_set_channel_streams rejected: channel is not open");
|
||||
if (running)
|
||||
return reject(GVFG_ESTATE, "gvfg_set_channel_streams rejected: channel is running");
|
||||
const uint32_t supported = GVFG_STREAM_VIDEO | GVFG_STREAM_AUDIO;
|
||||
if ((value & ~supported) != 0 || (value & GVFG_STREAM_VIDEO) == 0)
|
||||
return reject(GVFG_EINVAL, "gvfg_set_channel_streams rejected: use video or video plus audio");
|
||||
|
||||
const bool enableAudio = (value & GVFG_STREAM_AUDIO) != 0;
|
||||
const pcies2mm_status_t status = backend->set_audio_enabled(enableAudio);
|
||||
if (status != PCIES2MM_OK)
|
||||
return map_status(status);
|
||||
streams = value;
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t getAudioFormat(gvfg_audio_format_t &out)
|
||||
{
|
||||
std::memset(&out, 0, sizeof(out));
|
||||
if (!backend)
|
||||
return reject(GVFG_ESTATE, "gvfg_get_channel_audio_format rejected: channel is not open");
|
||||
pcies2mm_audio_format_t format{};
|
||||
const pcies2mm_status_t status = backend->get_audio_format(format);
|
||||
if (status != PCIES2MM_OK)
|
||||
return map_status(status);
|
||||
out.sample_rate = format.sample_rate;
|
||||
out.channels = format.channels;
|
||||
out.bits_per_sample = format.bits_per_sample;
|
||||
out.frames_per_second = format.frames_per_second;
|
||||
out.frame_bytes = format.frame_bytes;
|
||||
out.block_align = format.block_align;
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t readAudio(void *destination, uint32_t destinationCapacity,
|
||||
uint32_t &outBytes, uint32_t timeoutMs)
|
||||
{
|
||||
outBytes = 0;
|
||||
if (!backend)
|
||||
return reject(GVFG_ESTATE, "gvfg_read_channel_audio rejected: channel is not open");
|
||||
if (!running || (streams & GVFG_STREAM_AUDIO) == 0)
|
||||
return reject(GVFG_ESTATE, "gvfg_read_channel_audio rejected: audio capture is not running");
|
||||
return map_status(backend->wait_audio(timeoutMs, destination, destinationCapacity, outBytes));
|
||||
}
|
||||
|
||||
gvfg_status_t debugWriteRegister(uint32_t offset, uint32_t value)
|
||||
{
|
||||
if (!backend)
|
||||
@@ -728,6 +782,7 @@ struct gvfg_channel_session_t
|
||||
int currentIndex = -1;
|
||||
uint32_t selectedChannel = GVFG_CHANNEL_0;
|
||||
bool zeroCopyRequested = false;
|
||||
uint32_t streams = GVFG_STREAM_VIDEO;
|
||||
uint32_t eventMask = GVFG_EVENT_MASK_ALL;
|
||||
|
||||
uint32_t width = 0;
|
||||
@@ -874,6 +929,31 @@ struct gvfg_handle_t
|
||||
return GVFG_OK;
|
||||
}
|
||||
|
||||
gvfg_status_t setChannelVideoFormat(int channelIndex, gvfg_pixel_format_t format)
|
||||
{
|
||||
gvfg_channel_session_t *channel = findChannel(channelIndex);
|
||||
if (!channel)
|
||||
return rejectChannel(channelIndex,
|
||||
GVFG_ESTATE,
|
||||
"gvfg_set_channel_video_format rejected: channel is not open");
|
||||
if (format != GVFG_PIXFMT_YUY2 && format != GVFG_PIXFMT_Y210)
|
||||
return rejectChannel(channelIndex,
|
||||
GVFG_EINVAL,
|
||||
"gvfg_set_channel_video_format rejected: pixel format is invalid");
|
||||
|
||||
const int otherChannel = channelIndex == GVFG_CHANNEL_0 ? GVFG_CHANNEL_1 : GVFG_CHANNEL_0;
|
||||
if (format == GVFG_PIXFMT_Y210 &&
|
||||
requestedFormats[static_cast<size_t>(otherChannel)] == GVFG_PIXFMT_Y210)
|
||||
return rejectChannel(channelIndex,
|
||||
GVFG_ENOTSUP,
|
||||
"both channels cannot use Y210 at the same time");
|
||||
|
||||
const gvfg_status_t status = channel->setVideoFormat(format);
|
||||
if (status == GVFG_OK)
|
||||
requestedFormats[static_cast<size_t>(channelIndex)] = format;
|
||||
return status;
|
||||
}
|
||||
|
||||
gvfg_status_t stopAll()
|
||||
{
|
||||
gvfg_status_t result = GVFG_OK;
|
||||
@@ -910,6 +990,7 @@ struct gvfg_handle_t
|
||||
std::array<uint32_t, 2> eventMasks{GVFG_EVENT_MASK_ALL, GVFG_EVENT_MASK_ALL};
|
||||
int currentIndex = -1;
|
||||
std::array<bool, 2> zeroCopyRequested{false, false};
|
||||
std::array<gvfg_pixel_format_t, 2> requestedFormats{GVFG_PIXFMT_YUY2, GVFG_PIXFMT_YUY2};
|
||||
};
|
||||
|
||||
extern "C"
|
||||
@@ -1025,14 +1106,40 @@ extern "C"
|
||||
gvfg_status_t gvfg_set_channel_video_format(gvfg_handle handle,
|
||||
int channel_index,
|
||||
gvfg_pixel_format_t format)
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_EINVAL;
|
||||
return handle->setChannelVideoFormat(channel_index, format);
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_set_channel_streams(gvfg_handle handle,
|
||||
int channel_index,
|
||||
uint32_t streams)
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_EINVAL;
|
||||
gvfg_channel_session_t *channel = handle->findChannel(channel_index);
|
||||
return channel ? channel->setVideoFormat(format)
|
||||
return channel ? channel->setStreams(streams)
|
||||
: handle->rejectChannel(channel_index,
|
||||
GVFG_ESTATE,
|
||||
"gvfg_set_channel_video_format rejected: channel is not open");
|
||||
"gvfg_set_channel_streams rejected: channel is not open");
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_get_channel_audio_format(gvfg_handle handle,
|
||||
int channel_index,
|
||||
gvfg_audio_format_t *out_format)
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_EINVAL;
|
||||
if (!out_format)
|
||||
return handle->rejectChannel(channel_index,
|
||||
GVFG_EINVAL,
|
||||
"gvfg_get_channel_audio_format rejected: out_format is null");
|
||||
gvfg_channel_session_t *channel = handle->findChannel(channel_index);
|
||||
return channel ? channel->getAudioFormat(*out_format)
|
||||
: handle->rejectChannel(channel_index,
|
||||
GVFG_ESTATE,
|
||||
"gvfg_get_channel_audio_format rejected: channel is not open");
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_read_channel_frame(gvfg_handle handle,
|
||||
@@ -1070,6 +1177,31 @@ extern "C"
|
||||
"gvfg_release_channel_frame rejected: channel is not open");
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_read_channel_audio(gvfg_handle handle,
|
||||
int channel_index,
|
||||
void *destination,
|
||||
uint32_t destination_capacity,
|
||||
uint32_t *out_bytes,
|
||||
uint32_t timeout_ms)
|
||||
{
|
||||
if (!handle)
|
||||
return GVFG_EINVAL;
|
||||
if (out_bytes)
|
||||
*out_bytes = 0;
|
||||
if (!destination || destination_capacity == 0 || !out_bytes)
|
||||
return handle->rejectChannel(channel_index,
|
||||
GVFG_EINVAL,
|
||||
"gvfg_read_channel_audio rejected: output buffer is invalid");
|
||||
gvfg_channel_session_t *channel = handle->findChannel(channel_index);
|
||||
return channel ? channel->readAudio(destination,
|
||||
destination_capacity,
|
||||
*out_bytes,
|
||||
timeout_ms)
|
||||
: handle->rejectChannel(channel_index,
|
||||
GVFG_ESTATE,
|
||||
"gvfg_read_channel_audio rejected: channel is not open");
|
||||
}
|
||||
|
||||
gvfg_status_t gvfg_poll_channel_event(gvfg_handle handle,
|
||||
int channel_index,
|
||||
gvfg_event_t *out_event,
|
||||
|
||||
Reference in New Issue
Block a user