Redesign audio capture around frame ownership
- Remove the public stream-mask and caller-buffer audio APIs. - Add explicit audio enable, format query, and frame read/release APIs. - Move PCM buffer ownership into the SDK. - Allow each channel to hold at most one audio frame at a time. - Validate the complete audio frame token during release. - Reset the audio frame ID when capture starts. - Invalidate any held audio frame when capture stops. - Migrate the Qt preview sample to the new audio frame API. - Update the README, Customer API guide, API Reference, and giga_ioctl boundary documentation.
This commit is contained in:
@@ -38,11 +38,16 @@ gvfg_enumerate_devices
|
||||
-> gvfg_create
|
||||
-> gvfg_set_channel_zero_copy_enabled (optional, before channel open)
|
||||
-> gvfg_open_channel
|
||||
-> gvfg_set_channel_audio_enabled (optional, before start)
|
||||
-> gvfg_start_channel
|
||||
-> 重複:
|
||||
gvfg_read_channel_frame
|
||||
使用/複製/轉換 frame
|
||||
gvfg_release_channel_frame
|
||||
若已啟用 audio,另一個 worker thread 重複:
|
||||
gvfg_read_channel_audio_frame
|
||||
使用/複製 PCM
|
||||
gvfg_release_channel_audio_frame
|
||||
-> gvfg_stop
|
||||
-> gvfg_destroy
|
||||
```
|
||||
@@ -105,6 +110,18 @@ int main(void)
|
||||
- 同一個 handle 的 lifecycle 操作應由應用程式自行序列化;不要同時 open、
|
||||
start、stop 或 destroy。
|
||||
|
||||
Audio 採用相同的 pull 與 ownership 模型:
|
||||
|
||||
- 建議使用獨立 audio worker thread,避免阻塞 video read 或 UI thread。
|
||||
- `gvfg_audio_frame_t.data` 是 SDK-owned PCM,只在對應的
|
||||
`gvfg_release_channel_audio_frame()` 前有效。
|
||||
- 同一 channel 同時只能持有一個 audio frame;未 release 再 read 會回傳
|
||||
`GVFG_ESTATE`。
|
||||
- release 必須傳回未修改的完整 `gvfg_audio_frame_t` token。
|
||||
- 若播放或錄音需要在 release 後繼續使用 PCM,Application 必須先複製。
|
||||
- SDK 只保有單一交付 buffer,不建立 audio ring;播放排程與 buffering 屬於
|
||||
Application/Qt/WASAPI。
|
||||
|
||||
`timeout_ms` 的共同規則:`0` 表示不等待;`GVFG_TIMEOUT_INFINITE` 表示無限等待;
|
||||
其他值的單位為毫秒。
|
||||
|
||||
@@ -148,6 +165,21 @@ int main(void)
|
||||
- `pixel_format`、`bit_depth`:原生 payload 格式。
|
||||
- `frame_id`:同一次 start/stop session 中單調遞增的識別值。
|
||||
|
||||
### PCM audio
|
||||
|
||||
`gvfg_audio_format_t` 只提供上層實際需要的播放格式:`sample_rate`、
|
||||
`channels`、`bits_per_sample`。Driver frame 大小與 block alignment 是 backend
|
||||
細節,不要求 Application 配置相同大小的 buffer。
|
||||
|
||||
`gvfg_audio_frame_t` 包含:
|
||||
|
||||
- `data`、`data_size`:SDK-owned PCM 與本次有效 byte 數。
|
||||
- `sample_rate`、`channels`、`bits_per_sample`:此 frame 的 PCM 格式。
|
||||
- `frame_id`:同一次 start/stop session 中單調遞增的 audio frame ID。
|
||||
|
||||
目前 audio 僅支援 CH0,且必須與 video 一起啟動;不支援 audio-only。公開
|
||||
audio API 不是 zero-copy,但上層仍使用和 video 相同的 read/release contract。
|
||||
|
||||
## 6. 公開 API
|
||||
|
||||
### 裝置與生命週期
|
||||
@@ -180,6 +212,17 @@ Zero-copy mode 的 driver lifecycle 由 SDK 管理:open 時 enable,每次成
|
||||
zero-copy mode 而定,但 release contract 相同。
|
||||
- `gvfg_release_channel_frame(handle, channel, &frame)`:釋放原 frame token。
|
||||
|
||||
### Audio frame
|
||||
|
||||
- `gvfg_set_channel_audio_enabled(handle, channel, enabled)`:在 start 前啟用或停用
|
||||
audio;video 永遠保留,不需要組合 stream flags。
|
||||
- `gvfg_get_channel_audio_format(handle, channel, &format)`:取得 PCM 播放格式。
|
||||
- `gvfg_read_channel_audio_frame(handle, channel, &frame, timeout_ms)`:取得一個
|
||||
SDK-owned PCM frame。
|
||||
- `gvfg_release_channel_audio_frame(handle, channel, &frame)`:釋放原 audio token。
|
||||
|
||||
成功 read 後,不論 PCM 是送往播放、錄音或被丟棄,都必須正好 release 一次。
|
||||
|
||||
`gvfg_set_channel_video_format()` 只能在指定 stream 尚未開始或已 stop 時呼叫;streaming 中
|
||||
切換會回傳 `GVFG_ESTATE`。應用程式應在 UI 上同步鎖定格式選項。
|
||||
|
||||
|
||||
@@ -100,6 +100,37 @@ register 與 DMA 實作不屬於本文件。
|
||||
|
||||
Caller 不得修改任何欄位再 release。SDK 會將完整 token 與目前 held frame 比對。
|
||||
|
||||
### 1.8a `gvfg_audio_format_t`
|
||||
|
||||
由 `gvfg_get_channel_audio_format()` 填入,只包含 Application 建立播放或錄音
|
||||
格式所需的 PCM metadata。
|
||||
|
||||
| 欄位 | 型別 | 說明 |
|
||||
| --- | --- | --- |
|
||||
| `sample_rate` | `uint32_t` | 每秒 sample 數 |
|
||||
| `channels` | `uint32_t` | interleaved PCM channel 數 |
|
||||
| `bits_per_sample` | `uint32_t` | 每個 PCM sample 的 bit 數 |
|
||||
|
||||
Driver 一次傳回多少 bytes、buffer capacity 與 block alignment 均由 SDK/backend
|
||||
管理,不是公開格式的一部分。
|
||||
|
||||
### 1.8b `gvfg_audio_frame_t`
|
||||
|
||||
由 `gvfg_read_channel_audio_frame()` 填入,也是稍後傳給
|
||||
`gvfg_release_channel_audio_frame()` 的完整 token。
|
||||
|
||||
| 欄位 | 型別 | 說明 |
|
||||
| --- | --- | --- |
|
||||
| `data` | `const void *` | SDK-owned interleaved PCM;release 或 stop 後失效 |
|
||||
| `data_size` | `uint64_t` | 此 frame 的有效 PCM byte 數 |
|
||||
| `sample_rate` | `uint32_t` | 每秒 sample 數 |
|
||||
| `channels` | `uint32_t` | interleaved PCM channel 數 |
|
||||
| `bits_per_sample` | `uint32_t` | 每個 PCM sample 的 bit 數 |
|
||||
| `frame_id` | `uint64_t` | 此次 start/stop run 中單調遞增的 audio frame ID |
|
||||
|
||||
與 video 相同,每個 channel 同時只能持有一個 audio frame,且 caller 不得修改
|
||||
descriptor 後再 release。
|
||||
|
||||
### 1.9 `gvfg_gpu_output_format_t`
|
||||
|
||||
| 成員 | 值 | 說明 |
|
||||
@@ -242,28 +273,36 @@ gvfg_status_t gvfg_set_channel_video_format(gvfg_handle handle,
|
||||
- 同一裝置的 CH0、CH1 不可同時設定 Y210;第二個 Y210 request 回傳
|
||||
`GVFG_ENOTSUP`。
|
||||
|
||||
### 1.19a Audio capture selection and copy-out
|
||||
### 1.19a Audio capture selection and frame ownership
|
||||
|
||||
```c
|
||||
gvfg_status_t gvfg_set_channel_streams(gvfg_handle handle,
|
||||
int channel_index,
|
||||
uint32_t streams);
|
||||
gvfg_status_t gvfg_set_channel_audio_enabled(gvfg_handle handle,
|
||||
int channel_index,
|
||||
int enabled);
|
||||
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_status_t gvfg_read_channel_audio_frame(gvfg_handle handle,
|
||||
int channel_index,
|
||||
gvfg_audio_frame_t *out_frame,
|
||||
uint32_t timeout_ms);
|
||||
gvfg_status_t gvfg_release_channel_audio_frame(gvfg_handle handle,
|
||||
int channel_index,
|
||||
const gvfg_audio_frame_t *frame);
|
||||
```
|
||||
|
||||
- 預設為 `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 數。
|
||||
- 預設只擷取 video。CH0 可在 start 前用 `gvfg_set_channel_audio_enabled()`
|
||||
啟用 audio;audio-only 與 CH1 audio 尚未支援。
|
||||
- `gvfg_start_channel()` 依 audio enabled 狀態選擇 video-only 或 video + audio driver start。
|
||||
- `gvfg_read_channel_audio_frame()` 取得下一個 PCM frame 並交付 SDK-owned
|
||||
descriptor。使用完成後必須呼叫 `gvfg_release_channel_audio_frame()`。
|
||||
- 未 release 前再次 read 會回傳 `GVFG_ESTATE`。
|
||||
- `out_frame` 為 NULL 或 release token 被修改時回傳 `GVFG_EINVAL`。
|
||||
- `timeout_ms` 遵循其他 read API:`0` 不等待,`GVFG_TIMEOUT_INFINITE` 無限等待,
|
||||
超時回傳 `GVFG_ETIMEOUT`。
|
||||
- Video 與 audio 應由不同 worker thread read;同一 channel 不可同時執行兩個
|
||||
audio read。
|
||||
- Stop/close 後 descriptor 立即失效;要跨越 release/stop 保存 PCM 必須先複製。
|
||||
- SDK 不建立 audio ring,也不提供尚未完成的 audio zero-copy。
|
||||
|
||||
### 1.20 `gvfg_start_channel`
|
||||
|
||||
Reference in New Issue
Block a user