Add HDMI audio input queries and split OSD into a helper in GVFG SDK 3.2

- Expose HDMI audio input information through the capture API and refresh the bundled Gigabyte library.
- Move OSD rendering into gvfg_osd.dll, connect channel OSD through the capture frame processor, and remove the experimental in-place zero-copy OSD path.
- Update playback integration, the customer API documentation, and the internal build guide.

Validation: git diff --cached --check passed. The MSVC Release SDK build passed. Capture hardware and runtime behavior were not tested.
This commit is contained in:
2026-11-25 09:35:49 +08:00
parent 7a7027391e
commit a47ab190bc
26 changed files with 1080 additions and 867 deletions
+85 -290
View File
@@ -6,8 +6,7 @@
#include "gvfg_debug.h"
#include "gigabyte_capture_session.h"
#include "gpu/gvfg_gpu_osd.h"
#include "gvfg_osd.h"
#include "gvfg_frame_processor.h"
#include "gvfgframework.h"
#include <algorithm>
@@ -199,7 +198,8 @@ struct gvfg_channel_session_t
return cfg;
if (audioEnabled)
{
const gvfg_status_t audioStatus = session->get_audio_format(cachedAudioFormat);
GigabyteAudioInfo format{};
const gvfg_status_t audioStatus = session->get_audio_format(format);
if (audioStatus != GVFG_OK)
return audioStatus;
}
@@ -315,13 +315,13 @@ struct gvfg_channel_session_t
eventCv.notify_one();
}
gvfg_status_t querySignal()
gvfg_status_t querySignal(bool verifyRequestedFormat = false)
{
if (!session)
return GVFG_ESTATE;
gvfg_signal_status_t sig{};
const gvfg_status_t status = session->get_signal_status(sig);
const gvfg_status_t status = session->get_signal_status(sig, verifyRequestedFormat);
std::lock_guard<std::mutex> lock(stateMutex);
width = status == GVFG_OK ? sig.width : 0;
@@ -341,7 +341,7 @@ struct gvfg_channel_session_t
return GVFG_ESTATE;
gvfg_signal_status_t sig{};
session->get_cached_signal_status(sig);
const gvfg_status_t status = session->get_cached_signal_status(sig);
std::lock_guard<std::mutex> lock(stateMutex);
width = sig.width > 0 ? static_cast<uint32_t>(sig.width) : 0;
@@ -350,7 +350,7 @@ struct gvfg_channel_session_t
pixelFormat = static_cast<gvfg_pixel_format_t>(sig.pixel_format);
videoInterface = sig.video_interface;
signalConnected = sig.connected != 0;
return GVFG_OK;
return status;
}
gvfg_status_t configureStream()
@@ -358,7 +358,7 @@ struct gvfg_channel_session_t
if (!session)
return reject(GVFG_ESTATE, "configure stream rejected: channel is not open");
const gvfg_status_t signalStatus = querySignal();
const gvfg_status_t signalStatus = querySignal(true);
if (signalStatus != GVFG_OK)
return signalStatus;
{
@@ -430,28 +430,23 @@ struct gvfg_channel_session_t
}
bool osdApplied = false;
int processedStride = 0;
// This capability comes from the backend, never from const_cast of a
// public frame pointer. Driver storage is excluded by default; only
// the explicit unsafe build option below can admit it for experiments.
uint8_t *writableSource = session->writable_copy_frame_data(frame);
bool experimentalZeroCopy = false;
bool inPlaceApplied = false;
uint32_t experimentFlags = 0;
gvfg_debug_osd_page_check_t pageCheck{};
#ifdef GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE
experimentFlags = GVFG_DEBUG_OSD_EXPERIMENT_ENABLED;
if (!writableSource)
gvfg_frame_t processedFrame{};
const gvfg_frame_processor *processor = nullptr;
void *processorContext = nullptr;
{
writableSource = session->experimental_zero_copy_frame_data(frame);
experimentalZeroCopy = writableSource != nullptr;
std::lock_guard<std::mutex> lock(processorMutex);
processor = frameProcessor.ops;
processorContext = frameProcessor.context;
}
#endif
// Only SDK-owned copy-mode buffers are available for in-place writes.
uint8_t *writableSource = processor ? session->writable_copy_frame_data(frame) : nullptr;
bool inPlaceApplied = false;
const uint64_t processBeginNs = timing ? now_ns() : 0;
const gvfg_status_t osdStatus =
osdProcessor.process(frame, processedVideoBuffer, processedStride, osdApplied, timing,
writableSource, experimentalZeroCopy, &inPlaceApplied, &experimentFlags, &pageCheck);
if (timing)
const gvfg_status_t osdStatus = processor
? processor->process(processorContext, frame, processedFrame, osdApplied, timing,
writableSource, &inPlaceApplied)
: GVFG_OK;
if (timing && processor)
timing->stage_ms[GVFG_DEBUG_OSD_PROCESS_TOTAL] = static_cast<double>(now_ns() - processBeginNs) / 1e6;
if (osdStatus != GVFG_OK)
{
@@ -477,9 +472,9 @@ struct gvfg_channel_session_t
return releaseStatus;
}
backendFrameHeld = false;
frame.data = processedVideoBuffer.data();
frame.data_size = static_cast<uint64_t>(processedVideoBuffer.size());
frame.row_stride_bytes = processedStride;
frame.data = processedFrame.data;
frame.data_size = processedFrame.data_size;
frame.row_stride_bytes = processedFrame.row_stride_bytes;
}
bool stoppedWhileWaiting = false;
@@ -494,8 +489,6 @@ struct gvfg_channel_session_t
{
frame.frame_id = ++videoFrameId;
heldSessionFrame = frame;
heldOsdExperimentFlags = experimentFlags;
heldOsdPageCheck = pageCheck;
heldFrameNeedsBackendRelease = backendFrameHeld;
readInProgress = false;
frameHeld = true;
@@ -526,31 +519,6 @@ struct gvfg_channel_session_t
return GVFG_OK;
}
gvfg_status_t osdExperimentFlags(uint64_t frameId, uint32_t &flags)
{
flags = 0;
#ifdef GVFG_EXPERIMENTAL_ZERO_COPY_OSD_INPLACE
flags = GVFG_DEBUG_OSD_EXPERIMENT_ENABLED;
#endif
if (frameId == 0)
return GVFG_OK;
std::lock_guard<std::mutex> lock(frameMutex);
if (!frameHeld || heldSessionFrame.frame_id != frameId)
return GVFG_ESTATE;
flags = heldOsdExperimentFlags;
return GVFG_OK;
}
gvfg_status_t osdPageCheck(uint64_t frameId, gvfg_debug_osd_page_check_t &check)
{
check = {};
std::lock_guard<std::mutex> lock(frameMutex);
if (!frameId || !frameHeld || heldSessionFrame.frame_id != frameId)
return GVFG_ESTATE;
check = heldOsdPageCheck;
return GVFG_OK;
}
gvfg_status_t releaseFrame(const gvfg_frame_t &frameToken)
{
if (!session)
@@ -684,31 +652,28 @@ struct gvfg_channel_session_t
return session->set_video_format(format);
}
gvfg_status_t setOsd(uint32_t index, const gvfg_channel_osd_config_t &config)
gvfg_status_t controlFrameProcessor(const gvfg_frame_processor *processor, bool create,
gvfg_frame_processor_control control, const void *argument,
const char *error)
{
if (!session)
return reject(GVFG_ESTATE, "gvfg_set_channel_osd rejected: channel is not open");
const gvfg_status_t status = osdProcessor.configure(index, config);
return status == GVFG_OK
? GVFG_OK
: reject(status, status == GVFG_EINVAL
? "gvfg_set_channel_osd rejected: configuration is invalid"
: "gvfg_set_channel_osd failed to store configuration");
}
return reject(GVFG_ESTATE, "Frame processor channel is not open");
gvfg_status_t clearOsd(uint32_t index)
{
if (!session)
return reject(GVFG_ESTATE, "gvfg_clear_channel_osd rejected: channel is not open");
return osdProcessor.clear(index);
}
std::lock_guard<std::mutex> lock(processorMutex);
if (!frameProcessor.ops)
{
if (!create)
return GVFG_OK;
const auto status = processor->create(&frameProcessor.context);
if (status != GVFG_OK)
return reject(status, error);
frameProcessor.ops = processor;
}
if (frameProcessor.ops != processor)
return reject(GVFG_ESTATE, "A different frame processor is already attached");
gvfg_status_t setOsdVisible(uint32_t index, int visible)
{
if (!session)
return reject(GVFG_ESTATE, "OSD visibility rejected: channel is not open");
const gvfg_status_t status = osdProcessor.setVisible(index, visible);
return status == GVFG_OK ? status : reject(status, "OSD visibility rejected: invalid slot, visibility, or no saved configuration");
const auto status = control(frameProcessor.context, argument);
return status == GVFG_OK ? status : reject(status, error);
}
gvfg_status_t setAudioEnabled(bool enabled)
@@ -740,7 +705,6 @@ struct gvfg_channel_session_t
const gvfg_status_t status = session->get_audio_format(format);
if (status != GVFG_OK)
return status;
cachedAudioFormat = format;
out.sample_rate = format.sample_rate;
out.channels = format.channels;
out.bits_per_sample = format.bits_per_sample;
@@ -764,26 +728,19 @@ struct gvfg_channel_session_t
audioReadInProgress = true;
}
const GigabyteAudioInfo format = cachedAudioFormat;
gvfg_status_t status = format.frame_bytes != 0 ? GVFG_OK : GVFG_ESTATE;
uint32_t bytes = 0;
if (status == GVFG_OK)
{
audioBuffer.resize(format.frame_bytes);
status = session->wait_audio(timeoutMs, audioBuffer.data(),
static_cast<uint32_t>(audioBuffer.size()), bytes);
}
GigabyteAudioInfo format{};
const gvfg_status_t status = session->wait_audio(timeoutMs, audioBuffer, format);
{
std::lock_guard<std::mutex> lock(audioMutex);
audioReadInProgress = false;
if (status != GVFG_OK)
return status;
if (!running.load(std::memory_order_acquire) || bytes == 0 || bytes > audioBuffer.size())
if (!running.load(std::memory_order_acquire))
return reject(GVFG_ESTATE, "gvfg_read_channel_audio_frame completed after capture stopped or returned invalid data");
audioFrameHeld = true;
out.data = audioBuffer.data();
out.data_size = bytes;
out.data_size = format.frame_bytes;
out.sample_rate = format.sample_rate;
out.channels = format.channels;
out.bits_per_sample = format.bits_per_sample;
@@ -871,7 +828,6 @@ struct gvfg_channel_session_t
uint32_t selectedChannel = GVFG_CHANNEL_0;
bool zeroCopyRequested = false;
bool audioEnabled = false;
GigabyteAudioInfo cachedAudioFormat{};
uint32_t width = 0;
uint32_t height = 0;
@@ -892,14 +848,22 @@ struct gvfg_channel_session_t
std::atomic<bool> running{false};
std::mutex frameMutex;
bool readInProgress = false;
uint32_t heldOsdExperimentFlags = 0;
gvfg_debug_osd_page_check_t heldOsdPageCheck{};
bool frameHeld = false;
bool heldFrameNeedsBackendRelease = false;
uint64_t videoFrameId = 0;
gvfg_frame_t heldSessionFrame{};
gvfg::internal::GpuOsdProcessor osdProcessor;
std::vector<uint8_t> processedVideoBuffer;
std::mutex processorMutex;
struct FrameProcessorState
{
const gvfg_frame_processor *ops = nullptr;
void *context = nullptr;
~FrameProcessorState()
{
if (ops)
ops->destroy(context);
}
} frameProcessor;
std::mutex audioMutex;
std::vector<uint8_t> audioBuffer;
bool audioReadInProgress = false;
@@ -1212,179 +1176,18 @@ extern "C"
return handle->setChannelVideoFormat(channel_index, format);
}
gvfg_status_t gvfg_get_osd_fonts(gvfg_osd_font_list_t *out_list)
{
if (!out_list)
return GVFG_EINVAL;
*out_list = {};
const auto status = gvfg_osd_get_fonts(&out_list->count, &out_list->names);
return status == GVFG_OSD_OK ? GVFG_OK : GVFG_EIO;
}
gvfg_status_t gvfg_measure_osd_text(const gvfg_channel_osd_config_t *config,
uint32_t *out_width, uint32_t *out_height)
{
if (out_width) *out_width = 0;
if (out_height) *out_height = 0;
if (!config || !config->text || !out_width || !out_height)
return GVFG_EINVAL;
const size_t length = strnlen_s(config->text, GVFG_OSD_MAX_TEXT_CHARACTERS + 1u);
if (length == 0 || length > GVFG_OSD_MAX_TEXT_CHARACTERS)
return GVFG_EINVAL;
try
{
gvfg_osd_handle rawHandle = nullptr;
if (gvfg_osd_create(&rawHandle) != GVFG_OSD_OK)
return GVFG_EIO;
const std::unique_ptr<void, decltype(&gvfg_osd_destroy)> helper(rawHandle, &gvfg_osd_destroy);
const auto status = gvfg_osd_measure(helper.get(), config->text,
static_cast<uint32_t>(length), config->font_size_px, config->font_family,
out_width, out_height);
return status == GVFG_OSD_OK ? GVFG_OK :
status == GVFG_OSD_EINVAL ? GVFG_EINVAL : GVFG_EIO;
}
catch (...) { return GVFG_EIO; }
}
static gvfg_status_t renderOsdBgraTile(const gvfg_channel_osd_config_t *config,
gvfg_osd_bitmap_t *out_bitmap,
std::vector<uint8_t> &pixels)
{
if (!config || !config->text)
return GVFG_EINVAL;
const size_t length = strnlen_s(config->text, GVFG_OSD_MAX_TEXT_CHARACTERS + 1u);
if (length == 0 || length > GVFG_OSD_MAX_TEXT_CHARACTERS)
return GVFG_EINVAL;
try
{
gvfg_osd_handle rawHandle = nullptr;
if (gvfg_osd_create(&rawHandle) != GVFG_OSD_OK)
return GVFG_EIO;
const std::unique_ptr<void, decltype(&gvfg_osd_destroy)> helper(rawHandle, &gvfg_osd_destroy);
uint32_t width = 0, height = 0;
auto status = gvfg_osd_measure(helper.get(), config->text,
static_cast<uint32_t>(length), config->font_size_px, config->font_family,
&width, &height);
if (status != GVFG_OSD_OK)
return status == GVFG_OSD_EINVAL ? GVFG_EINVAL : GVFG_EIO;
const uint64_t stride = static_cast<uint64_t>(width) * 4u;
// WIC GetDataPointer reports its byte count as UINT.
if (width > INT_MAX || height > INT_MAX || stride > UINT_MAX ||
stride * height > UINT_MAX ||
stride * height > (std::numeric_limits<size_t>::max)())
return GVFG_EINVAL;
pixels.resize(static_cast<size_t>(stride * height));
gvfg_osd_config_t render{};
render.struct_size = sizeof(render);
render.width = width;
render.height = height;
render.text = config->text;
render.font_family = config->font_family;
render.text_length = static_cast<uint32_t>(length);
render.font_size_px = config->font_size_px;
render.color_rgb = config->color_rgb;
status = gvfg_osd_render_bgra(helper.get(), &render, pixels.data(), pixels.size(),
static_cast<uint32_t>(stride));
if (status != GVFG_OSD_OK)
return status == GVFG_OSD_EINVAL ? GVFG_EINVAL : GVFG_EIO;
out_bitmap->data = pixels.data();
out_bitmap->data_size = pixels.size();
out_bitmap->width = width;
out_bitmap->height = height;
out_bitmap->stride = static_cast<uint32_t>(stride);
return GVFG_OK;
}
catch (...) { return GVFG_EIO; }
}
gvfg_status_t gvfg_render_osd_frame_bgra(uint32_t video_width, uint32_t video_height,
const gvfg_channel_osd_config_t *slot0,
const gvfg_channel_osd_config_t *slot1,
gvfg_osd_bitmap_t *out_bitmap)
{
thread_local std::vector<uint8_t> frame;
frame.clear();
if (!out_bitmap)
return GVFG_EINVAL;
*out_bitmap = {};
const uint64_t stride = static_cast<uint64_t>(video_width) * 4u;
if (!video_width || !video_height || stride > UINT32_MAX ||
stride * video_height > UINT32_MAX ||
stride * video_height > (std::numeric_limits<size_t>::max)())
return GVFG_EINVAL;
try
{
frame.assign(static_cast<size_t>(stride * video_height), 0);
std::vector<uint8_t> tilePixels;
for (const auto *slot : {slot0, slot1})
{
if (!slot)
continue;
gvfg_osd_bitmap_t tile{};
const auto status = renderOsdBgraTile(slot, &tile, tilePixels);
if (status != GVFG_OK)
return status;
if (tile.width > video_width || tile.height > video_height)
continue;
const size_t x = std::clamp<int64_t>(slot->x, 0, video_width - tile.width);
const size_t y = std::clamp<int64_t>(slot->y, 0, video_height - tile.height);
for (uint32_t row = 0; row < tile.height; ++row)
{
const auto *src = tile.data + static_cast<size_t>(row) * tile.stride;
auto *dst = frame.data() + (y + row) * static_cast<size_t>(stride) + x * 4u;
for (uint32_t col = 0; col < tile.width; ++col, src += 4, dst += 4)
{
if (!src[3])
continue;
// Both layers are premultiplied, including at glyph edges.
const unsigned remaining = 255u - src[3];
for (unsigned c = 0; c < 4; ++c)
dst[c] = static_cast<uint8_t>(src[c] + (dst[c] * remaining + 127u) / 255u);
}
}
}
*out_bitmap = {frame.data(), frame.size(), video_width, video_height,
static_cast<uint32_t>(stride)};
return GVFG_OK;
}
catch (...) { return GVFG_EIO; }
}
gvfg_status_t gvfg_set_channel_osd(gvfg_handle handle, int channel_index,
uint32_t osd_index, const gvfg_channel_osd_config_t *config)
gvfg_status_t gvfg_control_frame_processor(
gvfg_handle handle, int channel_index, const gvfg_frame_processor *processor,
bool create, gvfg_frame_processor_control control, const void *argument,
const char *error)
{
if (!handle)
return GVFG_EINVAL;
if (!config || osd_index >= GVFG_OSD_SLOT_COUNT)
return handle->rejectChannel(channel_index, GVFG_EINVAL, "OSD config or index is invalid");
if (!control)
return handle->rejectChannel(channel_index, GVFG_EINVAL, error);
auto *channel = handle->findChannel(channel_index);
return channel ? channel->setOsd(osd_index, *config)
: handle->rejectChannel(channel_index, GVFG_ESTATE, "OSD channel is not open");
}
gvfg_status_t gvfg_set_channel_osd_visible(gvfg_handle handle, int channel_index,
uint32_t osd_index, int visible)
{
if (!handle)
return GVFG_EINVAL;
if (osd_index >= GVFG_OSD_SLOT_COUNT || (visible != 0 && visible != 1))
return handle->rejectChannel(channel_index, GVFG_EINVAL, "OSD index or visibility is invalid");
auto *channel = handle->findChannel(channel_index);
return channel ? channel->setOsdVisible(osd_index, visible)
: handle->rejectChannel(channel_index, GVFG_ESTATE, "OSD channel is not open");
}
gvfg_status_t gvfg_clear_channel_osd(gvfg_handle handle, int channel_index, uint32_t osd_index)
{
if (!handle)
return GVFG_EINVAL;
if (osd_index >= GVFG_OSD_SLOT_COUNT)
return handle->rejectChannel(channel_index, GVFG_EINVAL, "OSD index is invalid");
auto *channel = handle->findChannel(channel_index);
return channel ? channel->clearOsd(osd_index)
: handle->rejectChannel(channel_index, GVFG_ESTATE, "OSD channel is not open");
return channel ? channel->controlFrameProcessor(processor, create, control, argument, error)
: handle->rejectChannel(channel_index, GVFG_ESTATE, "Frame processor channel is not open");
}
gvfg_status_t gvfg_set_channel_audio_enabled(gvfg_handle handle,
@@ -1467,32 +1270,6 @@ extern "C"
"gvfg_debug_read_channel_frame_profiled rejected: channel is not open");
}
gvfg_status_t gvfg_debug_get_channel_osd_experiment_flags(gvfg_handle handle,
int channel_index,
uint64_t frame_id,
uint32_t *out_flags)
{
if (out_flags)
*out_flags = 0;
if (!handle || !out_flags)
return GVFG_EINVAL;
gvfg_channel_session_t *channel = handle->findChannel(channel_index);
return channel ? channel->osdExperimentFlags(frame_id, *out_flags) : GVFG_ESTATE;
}
gvfg_status_t gvfg_debug_get_channel_osd_page_check(gvfg_handle handle,
int channel_index,
uint64_t frame_id,
gvfg_debug_osd_page_check_t *out_check)
{
if (out_check)
*out_check = {};
if (!handle || !out_check)
return GVFG_EINVAL;
gvfg_channel_session_t *channel = handle->findChannel(channel_index);
return channel ? channel->osdPageCheck(frame_id, *out_check) : GVFG_ESTATE;
}
gvfg_status_t gvfg_release_channel_frame(gvfg_handle handle,
int channel_index,
const gvfg_frame_t *frame)
@@ -1654,6 +1431,24 @@ extern "C"
return channel->session->get_hdmi_info(*out_info);
}
gvfg_status_t gvfg_get_channel_hdmi_audio_info(
gvfg_handle handle, int channel_index, gvfg_hdmi_audio_info_t *out_info)
{
if (!handle || (channel_index != GVFG_CHANNEL_0 && channel_index != GVFG_CHANNEL_1))
return GVFG_EINVAL;
if (!out_info)
return handle->rejectChannel(
channel_index, GVFG_EINVAL,
"gvfg_get_channel_hdmi_audio_info rejected: out_info is null");
*out_info = {};
auto *channel = handle->findChannel(channel_index);
if (!channel || !channel->session)
return handle->rejectChannel(
channel_index, GVFG_ESTATE,
"gvfg_get_channel_hdmi_audio_info rejected: channel is not open");
return channel->session->get_hdmi_audio_info(*out_info);
}
gvfg_status_t gvfg_get_chip_info(gvfg_handle handle, gvfg_chip_info_t *out_info)
{
if (!handle)