Simplify GVFG API and frame diagnostics

This commit is contained in:
Mark.lin
2026-07-30 16:43:30 +08:00
parent 9124930e98
commit 2b5e75ade9
20 changed files with 245 additions and 257 deletions
+2 -6
View File
@@ -35,15 +35,11 @@ typedef struct gvfg_convert_frame_t *gvfg_convert_frame;
typedef struct
{
uint32_t struct_size; /* Set to sizeof(gvfg_convert_frame_desc_t) before calling. */
int width; /* Frame width in pixels. Use 0 to size from source during conversion. */
int height; /* Frame height in pixels. Use 0 to size from source during conversion. */
int pixel_format; /* gvfg_convert_format_t destination format. */
int row_bytes; /* Destination row stride in bytes. Use 0 for helper default. */
uint32_t flags; /* Reserved for future conversion options. Must be 0. */
uint32_t reserved0; /* Reserved. Must be 0. */
uint64_t data_size; /* Output buffer size in bytes, filled after create/convert. */
uint64_t reserved[8]; /* Reserved for future helper metadata. Must be ignored. */
} gvfg_convert_frame_desc_t;
GVFG_CONVERT_API gvfg_status_t gvfg_convert_create_frame(
@@ -59,7 +55,7 @@ GVFG_CONVERT_API gvfg_status_t gvfg_convert_frame_from_capture(
GVFG_CONVERT_API gvfg_status_t gvfg_convert_get_frame_desc(
_In_ gvfg_convert_frame frame,
_Inout_ gvfg_convert_frame_desc_t *out_desc);
_Out_ gvfg_convert_frame_desc_t *out_desc);
GVFG_CONVERT_API gvfg_status_t gvfg_convert_get_buffer(
_In_ gvfg_convert_frame frame,
@@ -68,7 +64,7 @@ GVFG_CONVERT_API gvfg_status_t gvfg_convert_get_buffer(
GVFG_CONVERT_API gvfg_status_t gvfg_convert_get_layout(
_In_ gvfg_convert_frame frame,
_Inout_ gvfg_frame_layout_t *out_layout);
_Out_ gvfg_frame_layout_t *out_layout);
GVFG_CONVERT_API const char *gvfg_convert_strerror(
_In_ gvfg_status_t status);
+1 -18
View File
@@ -160,7 +160,6 @@ struct gvfg_convert_frame_t
}
layout = {};
layout.struct_size = sizeof(layout);
layout.plane_count = 1;
layout.plane_data[0] = buffer.data();
layout.plane_stride[0] = actualStride;
@@ -323,17 +322,13 @@ extern "C"
return GVFG_EINVAL;
*out_frame = nullptr;
if (desc->struct_size < sizeof(gvfg_convert_frame_desc_t) ||
desc->flags != 0 ||
desc->reserved0 != 0 ||
convert_format_bytes_per_pixel(desc->pixel_format) <= 0)
if (convert_format_bytes_per_pixel(desc->pixel_format) <= 0)
return GVFG_EINVAL;
if (desc->width < 0 || desc->height < 0 || desc->row_bytes < 0)
return GVFG_EINVAL;
auto frame = std::make_unique<gvfg_convert_frame_t>();
frame->request = {};
frame->request.struct_size = sizeof(gvfg_convert_frame_desc_t);
frame->request.width = desc->width;
frame->request.height = desc->height;
frame->request.pixel_format = desc->pixel_format;
@@ -374,7 +369,6 @@ extern "C"
return cfg;
gvfg_frame_layout_t srcLayout{};
srcLayout.struct_size = sizeof(srcLayout);
const gvfg_status_t layoutStatus = gvfg_get_frame_layout(src, &srcLayout);
if (layoutStatus != GVFG_OK)
return layoutStatus;
@@ -395,13 +389,7 @@ extern "C"
{
if (!frame || !out_desc)
return GVFG_EINVAL;
if (out_desc->struct_size < sizeof(gvfg_convert_frame_desc_t))
return GVFG_EINVAL;
const uint32_t callerSize = out_desc->struct_size;
std::memset(out_desc, 0, sizeof(*out_desc));
*out_desc = frame->desc;
out_desc->struct_size = callerSize;
return GVFG_OK;
}
@@ -421,15 +409,10 @@ extern "C"
{
if (!frame || !out_layout)
return GVFG_EINVAL;
if (out_layout->struct_size < sizeof(gvfg_frame_layout_t))
return GVFG_EINVAL;
if (frame->buffer.empty() || frame->layout.plane_count <= 0)
return GVFG_ESTATE;
const uint32_t callerSize = out_layout->struct_size;
std::memset(out_layout, 0, sizeof(*out_layout));
*out_layout = frame->layout;
out_layout->struct_size = callerSize;
return GVFG_OK;
}
@@ -43,7 +43,6 @@ typedef enum
typedef struct
{
uint32_t struct_size; /* Set to sizeof(gvfg_preview_frame_t). */
const void *data;
uint64_t data_size;
int width;
@@ -74,7 +73,6 @@ typedef struct
*/
typedef struct
{
uint32_t struct_size; /* Set to sizeof(gvfg_preview_stats_t). */
double present_fps;
uint64_t presented_frames;
uint64_t skipped_presents;
+3 -10
View File
@@ -429,8 +429,7 @@ extern "C"
{
if (!handle || !frame)
return GVFG_PREVIEW_EINVAL;
if (frame->struct_size < sizeof(gvfg_preview_frame_t) ||
!frame->data ||
if (!frame->data ||
frame->width <= 0 ||
frame->height <= 0 ||
frame->row_bytes <= 0)
@@ -481,18 +480,12 @@ extern "C"
gvfg_preview_status_t gvfg_preview_get_stats(gvfg_preview_handle handle,
gvfg_preview_stats_t *out_stats)
{
constexpr size_t kMinimumSize =
offsetof(gvfg_preview_stats_t, skipped_presents) +
sizeof(uint64_t);
if (!handle || !out_stats || out_stats->struct_size < kMinimumSize)
if (!handle || !out_stats)
return GVFG_PREVIEW_EINVAL;
const uint32_t callerSize = out_stats->struct_size;
gvfg_preview_stats_t stats{};
stats.struct_size = sizeof(stats);
handle->renderer.getStats(stats);
std::memcpy(out_stats, &stats, (callerSize < sizeof(stats)) ? callerSize : sizeof(stats));
out_stats->struct_size = callerSize;
*out_stats = stats;
return GVFG_PREVIEW_OK;
}