Initial standalone GVFG SDK
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
if (NOT DEFINED GVFG_SDK_VERSION)
|
||||
set(GVFG_SDK_VERSION "0.1.0" CACHE STRING "GVFG SDK version")
|
||||
endif()
|
||||
|
||||
option(GVFG_XDMA_DEBUG_LOG "Enable verbose XDMA flow debug logging in GVFG internal XDMA backend" OFF)
|
||||
|
||||
project(gvfg VERSION ${GVFG_SDK_VERSION} LANGUAGES CXX)
|
||||
|
||||
add_library(gvfg SHARED
|
||||
include/gvfg_capture.h
|
||||
src/backend/xdma/xdma_backend_types.h
|
||||
src/backend/xdma/xdma_capture_session.cpp
|
||||
src/backend/xdma/xdma_capture_session.h
|
||||
src/backend/xdma/xdma_public.h
|
||||
src/gvfg_capture.cpp
|
||||
src/gcapture_log_bridge.cpp
|
||||
${CMAKE_SOURCE_DIR}/sdk/gcapture/src/pipeline/shared_scene_pipeline.cpp
|
||||
)
|
||||
|
||||
set_target_properties(gvfg PROPERTIES
|
||||
AUTOMOC OFF
|
||||
AUTOUIC OFF
|
||||
AUTORCC OFF
|
||||
)
|
||||
|
||||
target_include_directories(gvfg
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/include
|
||||
PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/src/backend/xdma
|
||||
${CMAKE_SOURCE_DIR}/sdk/gdriver_shared/include
|
||||
${CMAKE_SOURCE_DIR}/sdk/gcapture/include
|
||||
${CMAKE_SOURCE_DIR}/sdk/gcapture/src
|
||||
${CMAKE_SOURCE_DIR}/sdk/gcapture/src/pipeline
|
||||
)
|
||||
|
||||
target_compile_definitions(gvfg PRIVATE
|
||||
GVFG_BUILD
|
||||
GVFG_SDK_VERSION="${GVFG_SDK_VERSION}"
|
||||
)
|
||||
|
||||
if (GVFG_XDMA_DEBUG_LOG)
|
||||
target_compile_definitions(gvfg PRIVATE GVFG_XDMA_DEBUG_LOG=1)
|
||||
endif()
|
||||
|
||||
target_link_libraries(gvfg PRIVATE
|
||||
setupapi
|
||||
ole32 user32 windowscodecs
|
||||
dxgi d3d11 d2d1 dwrite D3DCompiler
|
||||
)
|
||||
|
||||
if (MSVC)
|
||||
target_compile_options(gvfg PRIVATE /utf-8 /EHsc)
|
||||
endif()
|
||||
@@ -0,0 +1,458 @@
|
||||
#pragma once
|
||||
|
||||
/*
|
||||
* Customer-facing GVFG capture API.
|
||||
*
|
||||
* Include only this header in customer applications. Do not include internal
|
||||
* backend/gdriver headers; those layers are implementation details behind
|
||||
* gvfg.dll.
|
||||
*
|
||||
* Minimal capture flow:
|
||||
*
|
||||
* gvfg_device_info_t devices[GVFG_MAX_DEVICES] = {};
|
||||
* int count = gvfg_enumerate_devices(devices, GVFG_MAX_DEVICES);
|
||||
*
|
||||
* gvfg_handle h = NULL;
|
||||
* gvfg_create(&h);
|
||||
* gvfg_set_callbacks(h, on_frame, on_error, user);
|
||||
* // Optional: gvfg_set_frame_callback_interval(h, 6); // one callback per 6 frames
|
||||
*
|
||||
* // Optional: let the SDK render preview directly into a native HWND.
|
||||
* gvfg_preview_desc_t preview = {};
|
||||
* preview.hwnd = hwnd;
|
||||
* preview.enable_preview = 1;
|
||||
* preview.swapchain_bitdepth = GVFG_PREVIEW_BITDEPTH_AUTO;
|
||||
* gvfg_set_preview(h, &preview);
|
||||
*
|
||||
* gvfg_open(h, devices[0].index);
|
||||
* gvfg_start(h);
|
||||
*
|
||||
* // Capture is now running. Use callbacks for frames/messages and
|
||||
* // gvfg_get_runtime_info() for status.
|
||||
*
|
||||
* gvfg_stop(h);
|
||||
* gvfg_destroy(h);
|
||||
*
|
||||
* Threading notes:
|
||||
* - Frame and error callbacks are called from an SDK worker thread, not from
|
||||
* the UI thread. UI applications should marshal callback work back to their
|
||||
* UI thread.
|
||||
* - The frame data pointer is valid only during the callback. Copy the data if
|
||||
* it must be used after the callback returns.
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef GVFG_BUILD
|
||||
#define GVFG_API __declspec(dllexport)
|
||||
#else
|
||||
#define GVFG_API __declspec(dllimport)
|
||||
#endif
|
||||
#else
|
||||
#define GVFG_API
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
GVFG_MAX_DEVICES = 16
|
||||
};
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_OK = 0,
|
||||
GVFG_EINVAL = -1, /* Invalid argument, such as NULL handle/output pointer. */
|
||||
GVFG_ENODEV = -2, /* No GVFG device, no signal, or device open failed. */
|
||||
GVFG_ESTATE = -3, /* API was called in the wrong state. */
|
||||
GVFG_EIO = -4, /* Driver/backend I/O failure. */
|
||||
GVFG_ENOTSUP = -5, /* Requested feature or format is not supported. */
|
||||
GVFG_ETIMEOUT = -6 /* Timed out waiting for driver/backend work. */
|
||||
} gvfg_status_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_PREVIEW_BITDEPTH_AUTO = 0, /* Let the SDK choose the best swapchain format. */
|
||||
GVFG_PREVIEW_BITDEPTH_10BIT = 10, /* Prefer a 10-bit preview swapchain when available. */
|
||||
GVFG_PREVIEW_BITDEPTH_8BIT = 8 /* Force an 8-bit preview swapchain. */
|
||||
} gvfg_preview_bitdepth_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int index; /* Device index to pass to gvfg_open(). */
|
||||
char name[128]; /* Display name for UI/logging. UTF-8, null-terminated. */
|
||||
} gvfg_device_info_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
void *hwnd; /* Native Windows HWND that stays alive while capture runs. */
|
||||
int enable_preview; /* Non-zero enables SDK-managed preview rendering. */
|
||||
int swapchain_bitdepth; /* gvfg_preview_bitdepth_t value. */
|
||||
} gvfg_preview_desc_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
uint32_t valid_mask; /* FPGA register read-valid mask: bit0=0x0c, bit1=0x18, bit2=0x1c, bit3=0x180. */
|
||||
int width_valid; /* Non-zero when FPGA 0x10 read succeeded. */
|
||||
int height_valid; /* Non-zero when FPGA 0x14 read succeeded. */
|
||||
uint32_t width_raw; /* Raw FPGA 0x10 width register. */
|
||||
uint32_t height_raw; /* Raw FPGA 0x14 height register. */
|
||||
uint32_t video_format_raw; /* Raw FPGA 0x0c value. */
|
||||
int video_format_valid;
|
||||
int video_format_code; /* 0=yuv422, 1=rgb, 2=yuv444, 3=yuv420 */
|
||||
char video_format[16];
|
||||
|
||||
uint32_t frame_rate_raw; /* Raw FPGA 0x18 value. */
|
||||
int frame_rate_valid;
|
||||
int frame_rate_code; /* FPGA frame-rate code from 0x18 low nibble. */
|
||||
char frame_rate_bits[5]; /* 4-bit binary text, for example "0110". */
|
||||
char frame_rate_name[16]; /* None, 23.98, 24, 47.95, ..., or "--" for unsupported codes. */
|
||||
|
||||
uint32_t bit_depth_raw; /* Raw FPGA 0x1c value. */
|
||||
int bit_depth_valid;
|
||||
int bit_depth; /* 8 or 10 when valid. */
|
||||
|
||||
uint32_t status_raw; /* Raw FPGA 0x180 value. */
|
||||
int status_valid;
|
||||
int sdi_locked; /* FPGA 0x180 bit0 */
|
||||
int sdi_ddr_ok; /* FPGA 0x180 bit1 */
|
||||
int hdmi_locked; /* FPGA 0x180 bit2 */
|
||||
int hdmi_ddr_ok; /* FPGA 0x180 bit3 */
|
||||
} gvfg_fpga_signal_status_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int width; /* Signal width in pixels, from FPGA when available. */
|
||||
int height; /* Signal height in pixels, from FPGA when available. */
|
||||
double fps; /* Legacy field; GVFG leaves this 0. Use fpga.frame_rate_* instead. */
|
||||
int bit_depth; /* Legacy SDK source-buffer bit depth. Prefer fpga.* and runtime delivered_frame. */
|
||||
char pixel_format[32]; /* Legacy SDK source-buffer format. Prefer fpga.* and runtime delivered_frame. */
|
||||
gvfg_fpga_signal_status_t fpga; /* Raw/decoded FPGA signal metadata. */
|
||||
} gvfg_signal_status_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int width; /* Width of frames delivered to the customer callback. */
|
||||
int height; /* Height of frames delivered to the customer callback. */
|
||||
int bit_depth; /* Bit depth of the delivered callback buffer. */
|
||||
char pixel_format[32]; /* Delivered callback buffer format, for example BGRA8. */
|
||||
int valid; /* Non-zero while capture is running after at least one callback frame. */
|
||||
} gvfg_delivered_frame_info_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gvfg_signal_status_t input_signal; /* FPGA-reported signal metadata plus legacy buffer fields. */
|
||||
gvfg_delivered_frame_info_t delivered_frame; /* Frame buffer delivered by gvfg.dll to the app. */
|
||||
double capture_fps; /* Runtime FPS measured from backend frames seen by the SDK worker. */
|
||||
uint64_t delivered_frames; /* Number of frames delivered to the app callback. */
|
||||
} gvfg_runtime_info_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int enabled; /* Non-zero when preview was requested. */
|
||||
int active; /* Non-zero when the preview pipeline is currently active. */
|
||||
int width; /* Preview render width. */
|
||||
int height; /* Preview render height. */
|
||||
int swapchain_bitdepth; /* Actual preview swapchain bit depth, usually 8 or 10. */
|
||||
int swapchain_10bit; /* Non-zero when the active swapchain is 10-bit. */
|
||||
char render_path[128]; /* Human-readable preview pipeline description. */
|
||||
char backbuffer_format[64]; /* DXGI backbuffer format name. */
|
||||
} gvfg_preview_info_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
const void *data; /* Frame pixels. Valid only during the frame callback. */
|
||||
int stride; /* Bytes per row for data. */
|
||||
int width; /* Frame width in pixels. */
|
||||
int height; /* Frame height in pixels. */
|
||||
uint64_t pts_ns; /* Presentation timestamp in nanoseconds. */
|
||||
uint64_t frame_id; /* Monotonic frame identifier from the backend. */
|
||||
} gvfg_frame_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GVFG_EVENT_VIDEO_IRQ = 1,
|
||||
GVFG_EVENT_PLUG_IN = 2,
|
||||
GVFG_EVENT_PLUG_OUT = 3,
|
||||
GVFG_EVENT_CAPTURE_PAUSED = 4,
|
||||
GVFG_EVENT_CAPTURE_RESUMED = 5
|
||||
} gvfg_event_type_t;
|
||||
|
||||
enum
|
||||
{
|
||||
GVFG_EVENT_MASK_VIDEO_IRQ = 1u << 0,
|
||||
GVFG_EVENT_MASK_PLUG_IN = 1u << 1,
|
||||
GVFG_EVENT_MASK_PLUG_OUT = 1u << 2,
|
||||
GVFG_EVENT_MASK_CAPTURE_PAUSED = 1u << 3,
|
||||
GVFG_EVENT_MASK_CAPTURE_RESUMED = 1u << 4,
|
||||
GVFG_EVENT_MASK_HOTPLUG = GVFG_EVENT_MASK_PLUG_IN |
|
||||
GVFG_EVENT_MASK_PLUG_OUT |
|
||||
GVFG_EVENT_MASK_CAPTURE_PAUSED |
|
||||
GVFG_EVENT_MASK_CAPTURE_RESUMED,
|
||||
GVFG_EVENT_MASK_DEFAULT = GVFG_EVENT_MASK_HOTPLUG,
|
||||
GVFG_EVENT_MASK_ALL = GVFG_EVENT_MASK_VIDEO_IRQ | GVFG_EVENT_MASK_HOTPLUG
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
gvfg_event_type_t type;
|
||||
uint32_t irq_bit;
|
||||
uint32_t irq_mask;
|
||||
uint64_t timestamp_ns;
|
||||
} gvfg_event_t;
|
||||
|
||||
/* Opaque session handle created by gvfg_create() and released by gvfg_destroy(). */
|
||||
typedef struct gvfg_handle_t *gvfg_handle;
|
||||
|
||||
/* Called when the SDK provides a frame for application use.
|
||||
* This callback is not required for SDK-managed preview rendering.
|
||||
*/
|
||||
typedef void (*gvfg_on_frame_cb)(const gvfg_frame_t *frame, void *user);
|
||||
|
||||
/* Called for capture events such as PLUG_IN / PLUG_OUT. */
|
||||
typedef void (*gvfg_on_event_cb)(const gvfg_event_t *event, void *user);
|
||||
|
||||
/* Called for asynchronous SDK messages or errors. */
|
||||
typedef void (*gvfg_on_error_cb)(gvfg_status_t status, const char *message, void *user);
|
||||
|
||||
/*
|
||||
* Enumerate GVFG capture devices.
|
||||
*
|
||||
* Parameters:
|
||||
* - out_devices: Output array that receives device entries. Pass NULL to query
|
||||
* the device count only.
|
||||
* - max_devices: Number of entries available in out_devices. Values larger
|
||||
* than GVFG_MAX_DEVICES are clamped. Pass 0 when out_devices is NULL.
|
||||
*
|
||||
* Returns:
|
||||
* - When out_devices is non-NULL, returns the number of entries written.
|
||||
* - When out_devices is NULL or max_devices is 0, returns the number of
|
||||
* available devices.
|
||||
* - Returns <= 0 when no device is available.
|
||||
*/
|
||||
GVFG_API int gvfg_enumerate_devices(gvfg_device_info_t *out_devices, int max_devices);
|
||||
|
||||
/*
|
||||
* Create a GVFG capture session.
|
||||
*
|
||||
* Parameters:
|
||||
* - out_handle: Receives the new session handle. Must not be NULL.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success.
|
||||
* - GVFG_EINVAL if out_handle is NULL.
|
||||
*
|
||||
* The returned handle starts in the closed state. Release it with
|
||||
* gvfg_destroy().
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_create(gvfg_handle *out_handle);
|
||||
|
||||
/*
|
||||
* Destroy a GVFG capture session.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Session handle returned by gvfg_create().
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK.
|
||||
*
|
||||
* If capture is still running, it is stopped first. After this call, the handle
|
||||
* must not be used again.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_destroy(gvfg_handle handle);
|
||||
|
||||
/*
|
||||
* Register frame and error callbacks.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Session handle returned by gvfg_create().
|
||||
* - on_frame: Function called when a frame is available. Pass NULL if frame
|
||||
* callbacks are not needed.
|
||||
* - on_error: Function called for asynchronous SDK messages/errors. Pass NULL
|
||||
* if error callbacks are not needed.
|
||||
* - user: Application-defined pointer passed back to both callbacks.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success.
|
||||
* - GVFG_EINVAL if handle is NULL.
|
||||
*
|
||||
* Callbacks are called from an SDK worker thread. The application must marshal
|
||||
* UI work to its UI thread.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_set_callbacks(gvfg_handle handle,
|
||||
gvfg_on_frame_cb on_frame,
|
||||
gvfg_on_error_cb on_error,
|
||||
void *user);
|
||||
|
||||
/*
|
||||
* Configure frame callback rate.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Session handle returned by gvfg_create().
|
||||
* - frame_interval: 0 or 1 calls on_frame for every delivered frame. N > 1
|
||||
* calls on_frame once for every N delivered backend frames.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success.
|
||||
* - GVFG_EINVAL if handle is NULL.
|
||||
*
|
||||
* This only affects the application frame callback. SDK-managed preview
|
||||
* rendering, gvfg_get_runtime_info(), and capture itself continue at full rate.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_set_frame_callback_interval(gvfg_handle handle,
|
||||
uint32_t frame_interval);
|
||||
|
||||
/*
|
||||
* Register capture event callback.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Session handle returned by gvfg_create().
|
||||
* - on_event: Function called when an enabled capture event occurs. Pass NULL
|
||||
* to disable event callbacks.
|
||||
* - user: Application-defined pointer passed back to the callback.
|
||||
* - event_mask: GVFG_EVENT_MASK_* bits. Pass 0 to use GVFG_EVENT_MASK_DEFAULT.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success.
|
||||
* - GVFG_EINVAL if handle is NULL.
|
||||
*
|
||||
* VIDEO_IRQ is not included in the default mask because it can occur once per
|
||||
* video frame. Enable GVFG_EVENT_MASK_VIDEO_IRQ only for debug or when the
|
||||
* application explicitly needs it.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_set_event_callback(gvfg_handle handle,
|
||||
gvfg_on_event_cb on_event,
|
||||
void *user,
|
||||
uint32_t event_mask);
|
||||
|
||||
/*
|
||||
* Configure SDK-managed preview rendering.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Session handle returned by gvfg_create().
|
||||
* - desc: Preview configuration. Must not be NULL. When preview is enabled,
|
||||
* desc->hwnd must be a valid native Windows HWND.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success.
|
||||
* - GVFG_EINVAL if handle or desc is NULL.
|
||||
*
|
||||
* This API is optional. If enabled, call it before gvfg_start() and keep the
|
||||
* HWND alive while capture is running. Applications that render frames
|
||||
* themselves can skip this API and use the frame callback instead.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_set_preview(gvfg_handle handle, const gvfg_preview_desc_t *desc);
|
||||
|
||||
/*
|
||||
* Open a device by index from gvfg_enumerate_devices().
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Session handle returned by gvfg_create().
|
||||
* - device_index: Device index from gvfg_device_info_t::index.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success.
|
||||
* - GVFG_EINVAL if handle is NULL.
|
||||
* - GVFG_ENODEV if the device cannot be opened.
|
||||
* - GVFG_EIO for driver/backend failures.
|
||||
*
|
||||
* The current implementation selects the SDI input internally.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_open(gvfg_handle handle, int device_index);
|
||||
|
||||
/*
|
||||
* Configure and start capture on an opened device.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Opened session handle.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success, including when capture is already running.
|
||||
* - GVFG_EINVAL if handle is NULL.
|
||||
* - GVFG_ESTATE if no device is open.
|
||||
* - GVFG_EIO or another status code if stream configuration/start fails.
|
||||
*
|
||||
* After success, frames and asynchronous messages are delivered through the
|
||||
* callbacks registered by gvfg_set_callbacks().
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_start(gvfg_handle handle);
|
||||
|
||||
/*
|
||||
* Stop capture.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Session handle returned by gvfg_create().
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success, including when capture is already stopped.
|
||||
* - GVFG_EINVAL if handle is NULL.
|
||||
*
|
||||
* This waits for the SDK capture worker thread to exit.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_stop(gvfg_handle handle);
|
||||
|
||||
/*
|
||||
* Query current signal information and delivered buffer format.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Opened session handle.
|
||||
* - out_status: Receives signal status. Must not be NULL.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success.
|
||||
* - GVFG_EINVAL if handle or out_status is NULL.
|
||||
* - GVFG_ENODEV if no valid signal information is available.
|
||||
*
|
||||
* The FPGA metadata describes the hardware signal. The pixel_format and
|
||||
* bit_depth fields describe the buffer format delivered by the customer API.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_get_signal_status(gvfg_handle handle, gvfg_signal_status_t *out_status);
|
||||
|
||||
/*
|
||||
* Query runtime capture diagnostics.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Opened or running session handle.
|
||||
* - out_info: Receives runtime information. Must not be NULL.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success.
|
||||
* - GVFG_EINVAL if handle or out_info is NULL.
|
||||
*
|
||||
* The result includes current signal status, SDK-measured capture FPS, and the
|
||||
* number of frames delivered by the SDK.
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_get_runtime_info(gvfg_handle handle, gvfg_runtime_info_t *out_info);
|
||||
|
||||
/*
|
||||
* Query SDK-managed preview diagnostics.
|
||||
*
|
||||
* Parameters:
|
||||
* - handle: Session handle returned by gvfg_create().
|
||||
* - out_info: Receives preview information. Must not be NULL.
|
||||
*
|
||||
* Returns:
|
||||
* - GVFG_OK on success.
|
||||
* - GVFG_EINVAL if handle or out_info is NULL.
|
||||
*
|
||||
* This is useful only when the application uses gvfg_set_preview().
|
||||
*/
|
||||
GVFG_API gvfg_status_t gvfg_get_preview_info(gvfg_handle handle, gvfg_preview_info_t *out_info);
|
||||
|
||||
/*
|
||||
* Convert a GVFG status code to a static English error string.
|
||||
*
|
||||
* Parameters:
|
||||
* - status: Status code returned by a GVFG API.
|
||||
*
|
||||
* Returns:
|
||||
* - Static null-terminated English string. The caller must not free it.
|
||||
*/
|
||||
GVFG_API const char *gvfg_strerror(gvfg_status_t status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,118 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include "gdriver_abi.h"
|
||||
|
||||
typedef enum xdma_status_t
|
||||
{
|
||||
XDMA_OK = 0,
|
||||
XDMA_EINVAL,
|
||||
XDMA_ENODEV,
|
||||
XDMA_ESTATE,
|
||||
XDMA_ENOTSUP,
|
||||
XDMA_ETIMEOUT,
|
||||
XDMA_EIO,
|
||||
XDMA_EABI
|
||||
} xdma_status_t;
|
||||
|
||||
typedef struct xdma_device_info_t
|
||||
{
|
||||
char friendly_name[GDRIVER_MAX_FRIENDLY_NAME];
|
||||
char serial_number[GDRIVER_MAX_SERIAL_NUMBER];
|
||||
char firmware_version[GDRIVER_MAX_FIRMWARE_VERSION];
|
||||
char driver_version[GDRIVER_MAX_DRIVER_VERSION];
|
||||
uint32_t supported_inputs_mask;
|
||||
uint32_t supported_pixel_formats_mask;
|
||||
} xdma_device_info_t;
|
||||
|
||||
typedef struct xdma_stream_desc_t
|
||||
{
|
||||
gdriver_input_t input;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
gdriver_pixel_format_t pixel_format;
|
||||
uint32_t buffer_count;
|
||||
gdriver_memory_kind_t memory_kind;
|
||||
uint32_t flags;
|
||||
} xdma_stream_desc_t;
|
||||
|
||||
typedef struct xdma_signal_status_t
|
||||
{
|
||||
int signal_locked;
|
||||
gdriver_input_t input;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
gdriver_pixel_format_t pixel_format;
|
||||
uint32_t bit_depth;
|
||||
uint32_t fpga_valid_mask; /* bit0:0x0c, bit1:0x18, bit2:0x1c, bit3:0x180 */
|
||||
uint32_t fpga_width_valid; /* Non-zero when FPGA 0x10 read succeeded. */
|
||||
uint32_t fpga_height_valid; /* Non-zero when FPGA 0x14 read succeeded. */
|
||||
uint32_t fpga_width_raw; /* Raw FPGA 0x10 width register. */
|
||||
uint32_t fpga_height_raw; /* Raw FPGA 0x14 height register. */
|
||||
uint32_t fpga_video_format_raw; /* 0x0c: 0=yuv422, 1=rgb, 2=yuv444, 3=yuv420 */
|
||||
uint32_t fpga_frame_rate_raw; /* 0x18 low nibble: frame-rate code */
|
||||
uint32_t fpga_bit_depth_raw; /* 0x1c: 8 or 10 */
|
||||
uint32_t fpga_status_raw; /* 0x180: bit0 SDI lock, bit1 SDI DDR, bit2 HDMI lock, bit3 HDMI DDR */
|
||||
} xdma_signal_status_t;
|
||||
|
||||
typedef struct xdma_frame_t
|
||||
{
|
||||
const void *data; /* Valid until the next XdmaCaptureSession::wait_frame() or close(). */
|
||||
size_t data_size_bytes;
|
||||
uint64_t frame_id;
|
||||
uint64_t timestamp_ns;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
gdriver_pixel_format_t pixel_format;
|
||||
uint32_t bit_depth;
|
||||
uint32_t plane_count;
|
||||
uint32_t plane_offset_bytes[GDRIVER_MAX_PLANES];
|
||||
uint32_t plane_stride_bytes[GDRIVER_MAX_PLANES];
|
||||
uint32_t driver_buffer_index;
|
||||
uint32_t flags;
|
||||
} xdma_frame_t;
|
||||
|
||||
typedef struct xdma_stream_stats_t
|
||||
{
|
||||
gdriver_stream_state_t state;
|
||||
uint64_t frames_captured;
|
||||
uint64_t frames_delivered;
|
||||
uint64_t frames_dropped;
|
||||
uint64_t dma_errors;
|
||||
uint64_t interrupt_count;
|
||||
} xdma_stream_stats_t;
|
||||
|
||||
typedef enum xdma_event_type_t
|
||||
{
|
||||
XDMA_EVENT_VIDEO_IRQ = 1,
|
||||
XDMA_EVENT_PLUG_IN = 2,
|
||||
XDMA_EVENT_PLUG_OUT = 3,
|
||||
XDMA_EVENT_CAPTURE_PAUSED = 4,
|
||||
XDMA_EVENT_CAPTURE_RESUMED = 5
|
||||
} xdma_event_type_t;
|
||||
|
||||
enum
|
||||
{
|
||||
XDMA_EVENT_MASK_VIDEO_IRQ = 1u << 0,
|
||||
XDMA_EVENT_MASK_PLUG_IN = 1u << 1,
|
||||
XDMA_EVENT_MASK_PLUG_OUT = 1u << 2,
|
||||
XDMA_EVENT_MASK_CAPTURE_PAUSED = 1u << 3,
|
||||
XDMA_EVENT_MASK_CAPTURE_RESUMED = 1u << 4,
|
||||
XDMA_EVENT_MASK_HOTPLUG = XDMA_EVENT_MASK_PLUG_IN |
|
||||
XDMA_EVENT_MASK_PLUG_OUT |
|
||||
XDMA_EVENT_MASK_CAPTURE_PAUSED |
|
||||
XDMA_EVENT_MASK_CAPTURE_RESUMED,
|
||||
XDMA_EVENT_MASK_DEFAULT = XDMA_EVENT_MASK_HOTPLUG,
|
||||
XDMA_EVENT_MASK_ALL = XDMA_EVENT_MASK_VIDEO_IRQ | XDMA_EVENT_MASK_HOTPLUG
|
||||
};
|
||||
|
||||
typedef struct xdma_event_t
|
||||
{
|
||||
xdma_event_type_t type;
|
||||
uint32_t irq_bit;
|
||||
uint32_t irq_mask;
|
||||
uint64_t timestamp_ns;
|
||||
} xdma_event_t;
|
||||
|
||||
typedef void (*xdma_event_callback_t)(const xdma_event_t *event, void *user);
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,128 @@
|
||||
#pragma once
|
||||
|
||||
#include "xdma_backend_types.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include <atomic>
|
||||
#include <condition_variable>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <vector>
|
||||
|
||||
namespace gvfg::internal
|
||||
{
|
||||
struct XdmaDevice
|
||||
{
|
||||
std::wstring interface_path;
|
||||
std::wstring friendly_name;
|
||||
};
|
||||
|
||||
std::vector<XdmaDevice> enumerate_xdma_devices();
|
||||
|
||||
class XdmaCaptureSession
|
||||
{
|
||||
public:
|
||||
XdmaCaptureSession();
|
||||
XdmaCaptureSession(const XdmaCaptureSession &) = delete;
|
||||
XdmaCaptureSession &operator=(const XdmaCaptureSession &) = delete;
|
||||
~XdmaCaptureSession();
|
||||
|
||||
xdma_status_t open_default();
|
||||
xdma_status_t open_device_index(size_t deviceIndex);
|
||||
xdma_status_t close();
|
||||
|
||||
xdma_status_t set_input(gdriver_input_t input);
|
||||
xdma_status_t get_device_info(xdma_device_info_t &out) const;
|
||||
xdma_status_t get_signal_status(xdma_signal_status_t &out) const;
|
||||
xdma_status_t get_stream_stats(xdma_stream_stats_t &out) const;
|
||||
|
||||
xdma_status_t set_event_callback(xdma_event_callback_t callback, void *user, uint32_t eventMask);
|
||||
xdma_status_t configure_stream(const xdma_stream_desc_t &desc);
|
||||
xdma_status_t start_stream();
|
||||
xdma_status_t stop_stream();
|
||||
xdma_status_t wait_frame(uint32_t timeoutMs, xdma_frame_t &out);
|
||||
xdma_status_t release_frame(const xdma_frame_t &frame);
|
||||
|
||||
const char *last_error() const;
|
||||
|
||||
private:
|
||||
xdma_status_t open_device(const XdmaDevice &device);
|
||||
void close_handles();
|
||||
|
||||
HANDLE open_subdevice(const wchar_t *name) const;
|
||||
int read_device(HANDLE device, long address, DWORD size, uint8_t *buffer) const;
|
||||
int write_device(HANDLE device, long address, DWORD size, const uint8_t *buffer) const;
|
||||
bool read_user_reg(long address, uint32_t &out) const;
|
||||
bool write_user_reg(long address, uint32_t value) const;
|
||||
bool enable_user_event(uint32_t mask);
|
||||
bool disable_user_event(uint32_t mask);
|
||||
|
||||
void event_thread_proc(uint32_t role, uint32_t irqBit);
|
||||
void data_thread_proc();
|
||||
bool start_data_worker();
|
||||
void stop_data_worker();
|
||||
void publish_frame(const uint8_t *data, size_t bytes);
|
||||
void pause_capture_for_plug_out();
|
||||
void resume_capture_after_plug_in();
|
||||
void handle_plug_in_frame_fix(const uint8_t *data, size_t bytes);
|
||||
void pulse_plug_in_frame_fix();
|
||||
void emit_event(xdma_event_type_t type, uint32_t irqBit, uint32_t irqMask) const;
|
||||
|
||||
xdma_status_t fail(xdma_status_t status, const char *where, DWORD winerr = GetLastError()) const;
|
||||
void set_last_error(const std::string &message) const;
|
||||
void clear_last_error() const;
|
||||
|
||||
uint32_t active_input_path() const;
|
||||
uint32_t event_mask(uint32_t role) const;
|
||||
uint32_t video_event_mask() const;
|
||||
uint32_t plug_in_event_mask() const;
|
||||
uint32_t plug_out_event_mask() const;
|
||||
uint32_t active_event_mask() const;
|
||||
long capture_enable_reg() const;
|
||||
size_t frame_size_bytes() const;
|
||||
|
||||
std::wstring base_path_;
|
||||
std::wstring friendly_name_;
|
||||
|
||||
HANDLE user_device_ = INVALID_HANDLE_VALUE;
|
||||
HANDLE c2h_device_[2] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE};
|
||||
HANDLE event_device_[4] = {INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE};
|
||||
|
||||
xdma_stream_desc_t stream_desc_{};
|
||||
uint32_t stream_bit_depth_ = 8;
|
||||
gdriver_input_t input_ = GDRIVER_INPUT_SDI;
|
||||
bool opened_ = false;
|
||||
bool configured_ = false;
|
||||
|
||||
std::atomic<bool> running_{false};
|
||||
std::atomic<bool> capture_active_{false};
|
||||
std::atomic<bool> data_worker_stop_{false};
|
||||
std::atomic<int> save_frames_after_plug_in_{0};
|
||||
std::atomic<bool> fix_pulsed_after_plug_in_{false};
|
||||
std::thread event_thread_[4];
|
||||
std::thread data_thread_;
|
||||
|
||||
mutable std::mutex mutex_;
|
||||
std::mutex worker_mutex_;
|
||||
mutable std::mutex event_callback_mutex_;
|
||||
std::condition_variable frame_cv_;
|
||||
std::condition_variable data_cv_;
|
||||
xdma_event_callback_t event_callback_ = nullptr;
|
||||
void *event_callback_user_ = nullptr;
|
||||
uint32_t event_mask_filter_ = XDMA_EVENT_MASK_DEFAULT;
|
||||
uint32_t pending_events_ = 0;
|
||||
std::vector<uint8_t> dma_buffer_;
|
||||
std::vector<uint8_t> latest_frame_;
|
||||
std::vector<uint8_t> delivery_frame_;
|
||||
uint64_t latest_sequence_ = 0;
|
||||
uint64_t delivered_sequence_ = 0;
|
||||
uint64_t wait_timeout_count_ = 0;
|
||||
bool stream_error_ = false;
|
||||
xdma_stream_stats_t stats_{};
|
||||
mutable std::string last_error_;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* XDMA Driver public API
|
||||
*
|
||||
* This header mirrors the public IOCTL values exposed by the Xilinx XDMA
|
||||
* Windows driver. The values are consumed by the GVFG internal XDMA backend.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <windows.h>
|
||||
|
||||
#define XDMA_MAKE_VERSION(major, minor, patch) (((major) << 24) | ((minor) << 16) | (patch))
|
||||
#define XDMA_VERSION_MAJOR(version) (((uint32_t)(version) >> 24) & 0xff)
|
||||
#define XDMA_VERSION_MINOR(version) (((uint32_t)(version) >> 16) & 0xff)
|
||||
#define XDMA_VERSION_PATCH(version) ((uint32_t)(version) & 0xffff)
|
||||
|
||||
#define XDMA_DRIVER_VERSION XDMA_MAKE_VERSION(1, 0, 0)
|
||||
|
||||
#define XDMA_IOCTL(index) CTL_CODE(FILE_DEVICE_UNKNOWN, index, METHOD_BUFFERED, FILE_ANY_ACCESS)
|
||||
|
||||
#define IOCTL_XDMA_GET_VERSION XDMA_IOCTL(0x0)
|
||||
#define IOCTL_XDMA_PERF_START XDMA_IOCTL(0x1)
|
||||
#define IOCTL_XDMA_PERF_STOP XDMA_IOCTL(0x2)
|
||||
#define IOCTL_XDMA_PERF_GET XDMA_IOCTL(0x3)
|
||||
#define IOCTL_XDMA_USER_INT_ENABLE XDMA_IOCTL(0x4)
|
||||
#define IOCTL_XDMA_USER_INT_DISABLE XDMA_IOCTL(0x5)
|
||||
|
||||
typedef struct XDMA_PERF_DATA
|
||||
{
|
||||
UINT64 clockCycleCount;
|
||||
UINT64 dataCycleCount;
|
||||
UINT64 pendingCount;
|
||||
} XDMA_PERF_DATA;
|
||||
@@ -0,0 +1,62 @@
|
||||
#include "gcapture.h"
|
||||
|
||||
#include <cstdarg>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
namespace gcap
|
||||
{
|
||||
void log_message(gcap_log_level_t, const char *message_utf8)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
const char *msg = message_utf8 ? message_utf8 : "";
|
||||
OutputDebugStringA(msg);
|
||||
const size_t len = std::strlen(msg);
|
||||
if (len == 0 || msg[len - 1] != '\n')
|
||||
OutputDebugStringA("\n");
|
||||
#else
|
||||
(void)message_utf8;
|
||||
#endif
|
||||
}
|
||||
|
||||
void log_message_w(gcap_log_level_t level, const wchar_t *message_wide)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
if (!message_wide)
|
||||
{
|
||||
log_message(level, "");
|
||||
return;
|
||||
}
|
||||
const int needed = WideCharToMultiByte(CP_UTF8, 0, message_wide, -1, nullptr, 0, nullptr, nullptr);
|
||||
if (needed <= 0)
|
||||
return;
|
||||
std::string utf8(static_cast<size_t>(needed - 1), '\0');
|
||||
WideCharToMultiByte(CP_UTF8, 0, message_wide, -1, utf8.data(), needed, nullptr, nullptr);
|
||||
log_message(level, utf8.c_str());
|
||||
#else
|
||||
(void)level;
|
||||
(void)message_wide;
|
||||
#endif
|
||||
}
|
||||
|
||||
void log_printf(gcap_log_level_t level, const char *fmt, ...)
|
||||
{
|
||||
if (!fmt)
|
||||
{
|
||||
log_message(level, "");
|
||||
return;
|
||||
}
|
||||
|
||||
char buf[1024];
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
std::vsnprintf(buf, sizeof(buf), fmt, args);
|
||||
va_end(args);
|
||||
log_message(level, buf);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user