diff --git a/README.md b/README.md index 45a5cf6..0fe2047 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ the GVFG source directly. - `sdk/gvfg`: GVFG public C API and internal XDMA backend. - `sdk/gdriver_shared/include`: shared driver ABI headers required by the backend. -- `sdk/gcapture`: minimal shared render/logging code currently required by GVFG preview. +- `sdk/gvfg/src/render`: GVFG internal D3D preview/render pipeline. - `samples/gvfg_qt_preview`: customer-facing Qt preview sample. - `docs`: API and integration notes. @@ -53,3 +53,4 @@ bin/gvfg.dll The XDMA backend and driver ABI headers are implementation details and should not be included by customer applications. + diff --git a/sdk/gcapture/include/gcap_audio.h b/sdk/gcapture/include/gcap_audio.h deleted file mode 100644 index b8c1d03..0000000 --- a/sdk/gcapture/include/gcap_audio.h +++ /dev/null @@ -1,97 +0,0 @@ -#pragma once - -/* - gcapture audio helper API - - Normal recording users should use: - - gcap_audio_device_count() - - gcap_audio_enum_devices() - - gcap_set_recording_audio_device() from gcapture.h - - The low-level gcap_start_audio_capture()/gcap_stop_audio_capture() APIs run - a simple WASAPI preview monitor from a capture endpoint to the default - speaker. They are independent from the recording path. -*/ - -#ifdef __cplusplus -extern "C" -{ -#endif - -#ifdef _WIN32 -#ifdef GCAPTURE_BUILD -#define GCAP_API __declspec(dllexport) -#else -#define GCAP_API __declspec(dllimport) -#endif -#else -#define GCAP_API -#endif - -#define GCAP_AUDIO_ID_MAX 256 -#define GCAP_AUDIO_NAME_MAX 256 - - /** WASAPI capture endpoint information. */ - typedef struct gcap_audio_device_t - { - char id[GCAP_AUDIO_ID_MAX]; /** Opaque WASAPI endpoint id, UTF-8. Use with gcap_set_recording_audio_device(). */ - char name[GCAP_AUDIO_NAME_MAX]; /** Friendly endpoint name, UTF-8. */ - - int channels; /** Channel count when known: 1, 2, 6, etc. 0 means unknown. */ - int sample_rate; /** Preferred/current sample rate when known, e.g. 48000. 0 means unknown. */ - int bits_per_sample; /** 16 / 24 / 32 when known. 0 means unknown. */ - int is_float; /** 1 = IEEE float, 0 = PCM or unknown. */ - int is_default; /** 1 = system default capture endpoint. */ - } gcap_audio_device_t; - - /** Return number of active WASAPI capture endpoints. */ - GCAP_API int gcap_audio_device_count(void); - - /** - * Enumerate active WASAPI capture endpoints. - * - * Parameters: - * out - Output array. If null, the function returns total count. - * max_count - Number of entries available in out. - * - * Return: - * Number of entries written, or total count when out is null/max_count <= 0. - */ - GCAP_API int gcap_audio_enum_devices( - gcap_audio_device_t *out, - int max_count); - - /** Legacy alias for gcap_audio_device_count(). Kept for source/binary compatibility. */ - GCAP_API int gcap_get_audio_device_count(void); - - /** Legacy alias for gcap_audio_enum_devices(). Kept for source/binary compatibility. */ - GCAP_API int gcap_enum_audio_devices( - gcap_audio_device_t *out, - int max_count); - - /** - * Best-effort match from a video capture device friendly name to a WASAPI - * capture endpoint. Returns 1 and writes out when a likely endpoint is found. - */ - GCAP_API int gcap_audio_find_device_for_capture( - const char *capture_device_name_utf8, - gcap_audio_device_t *out); - - /** Experimental low-level audio capture configuration. Prefer gcap_set_recording_audio_device() for recording. */ - typedef struct gcap_audio_capture_config_t - { - const char *device_id; /** Endpoint id from gcap_audio_enum_devices(). null/empty may mean default. */ - int sample_rate; /** Requested sample rate, commonly 48000. */ - int channels; /** Requested channels, commonly 1 or 2. */ - } gcap_audio_capture_config_t; - - /** Start low-level WASAPI audio preview/capture from cfg->device_id to the default speaker. */ - GCAP_API int gcap_start_audio_capture( - const gcap_audio_capture_config_t *cfg); - - /** Stop low-level WASAPI audio preview/capture if it was started. */ - GCAP_API void gcap_stop_audio_capture(void); - -#ifdef __cplusplus -} -#endif diff --git a/sdk/gcapture/include/gcapture.h b/sdk/gcapture/include/gcapture.h deleted file mode 100644 index 7ad46bb..0000000 --- a/sdk/gcapture/include/gcapture.h +++ /dev/null @@ -1,871 +0,0 @@ -#pragma once -#include -#include -#include "gcap_audio.h" - -/* - gcapture public C API - - This header is the SDK boundary. It intentionally uses C-compatible types, - fixed-size UTF-8 strings, and opaque handles so applications can use the SDK - from Qt, Win32/MFC, C#, Python wrappers, or other UI frameworks. - - Typical lifecycle: - 1. gcap_enumerate() - 2. gcap_create() + gcap_open2(), or gcap_open() - 3. Optional: gcap_set_backend(), gcap_set_profile(), gcap_set_processing() - 4. Optional preview: gcap_set_preview() - 5. Optional callbacks: gcap_set_callbacks(), gcap_set_frame_packet_callback() - 6. gcap_start() - 7. Optional runtime operations: snapshot, recording, signal/runtime queries - 8. gcap_stop() - 9. gcap_close() - - Thread-safety notes: - - A single gcap_handle should normally be controlled from one application - thread, except frame/error callbacks which are invoked from SDK/backend - worker threads. - - Callback pointers are only valid during the callback call. Copy data you - need before returning. - - Do not call blocking UI code directly inside callbacks. Marshal to your - UI thread. - - Unless a function explicitly says otherwise, do not call it concurrently - with gcap_close() on the same handle. - - String notes: - - Public string parameters and string fields are UTF-8 unless documented - otherwise. - - Fixed-size output buffers are always intended to be NUL-terminated by the - SDK on success. -*/ - -#ifdef _WIN32 -#ifdef GCAPTURE_BUILD -#define GCAP_API __declspec(dllexport) -#else -#define GCAP_API __declspec(dllimport) -#endif -#else -#define GCAP_API -#endif - -#ifdef __cplusplus -extern "C" -{ -#endif - - /** Capture backend selection. */ - typedef enum - { - /** Media Foundation CPU readback path. */ - GCAP_BACKEND_WINMF_CPU = 0, - /** Media Foundation GPU/DXGI path. Recommended for WinMF preview when supported. */ - GCAP_BACKEND_WINMF_GPU = 1, - /** DirectShow raw-sink path. Recommended for DShow capture devices. */ - GCAP_BACKEND_DSHOW = 2, - /** SDK chooses an available backend. Actual backend can be queried by gcap_get_active_backend(). */ - GCAP_BACKEND_AUTO = 3 - } gcap_backend_t; - - /** Profile negotiation mode. */ - enum gcap_profile_mode_t - { - /** Let the device/backend choose its default format. */ - GCAP_PROFILE_DEVICE_DEFAULT = 0, - /** Use width/height/fps/format from gcap_profile_t where supported. */ - GCAP_PROFILE_CUSTOM - }; - - - /** SDK log level passed to gcap_log_callback_t. */ - typedef enum - { - GCAP_LOG_TRACE = 0, - GCAP_LOG_DEBUG = 1, - GCAP_LOG_INFO = 2, - GCAP_LOG_WARN = 3, - GCAP_LOG_ERROR = 4 - } gcap_log_level_t; - - /** - * SDK log callback. - * - * The callback may be invoked from SDK/backend worker threads. Do not touch - * UI objects directly; marshal the message to your UI/log thread. - * message_utf8 is valid only during the callback call. Copy it if needed. - */ - typedef void (*gcap_log_callback_t)(gcap_log_level_t level, const char *message_utf8, void *user); - - /** SDK status code returned by most high-level APIs. */ - typedef enum - { - GCAP_OK = 0, - /** Invalid argument, null pointer, invalid state-independent parameter, or insufficient buffer. */ - GCAP_EINVAL, - /** Device not found, removed, or unavailable. */ - GCAP_ENODEV, - /** Operation is not valid in the current handle state. */ - GCAP_ESTATE, - /** I/O, backend, driver, media, or file operation failed. */ - GCAP_EIO, - /** Requested backend/format/operation is not supported. */ - GCAP_ENOTSUP - } gcap_status_t; - - /** Pixel format used by capability, negotiated status, callbacks, and recording helpers. */ - typedef enum - { - GCAP_FMT_NV12, /** 8-bit YUV 4:2:0, two planes: Y + interleaved UV. */ - GCAP_FMT_YUY2, /** 8-bit YUV 4:2:2 packed. */ - GCAP_FMT_ARGB, /** 8-bit packed 32-bit RGB-like surface. In callbacks it is treated as BGRA/ARGB-compatible 4 bytes per pixel. */ - GCAP_FMT_P010, /** 10-bit YUV 4:2:0 in 16-bit containers, two planes. */ - GCAP_FMT_Y210, /** 10-bit YUV 4:2:2 packed in 16-bit containers. */ - GCAP_FMT_V210, /** 10-bit packed 4:2:2. Capability placeholder; conversion support may be limited. */ - GCAP_FMT_R210 /** 10-bit packed RGB. Capability placeholder; conversion support may be limited. */ - } gcap_pixfmt_t; - - /** Device enumeration result. */ - typedef struct - { - int index; /** Device index accepted by gcap_open() / gcap_open2(). */ - char name[128]; /** Friendly device name, UTF-8. */ - char symbolic_link[256]; /** Backend/device symbolic link when available, UTF-8. */ - unsigned caps; /** Reserved bitmask. Current convention: 1<<0 HDMI, 1<<1 SDI, 1<<2 10-bit capable. */ - } gcap_device_info_t; - - typedef enum - { - GCAP_INPUT_UNKNOWN = 0, - GCAP_INPUT_HDMI = 1, - GCAP_INPUT_SDI = 2 - } gcap_input_t; - - typedef enum - { - GCAP_RANGE_UNKNOWN = 0, - GCAP_RANGE_LIMITED = 1, - GCAP_RANGE_FULL = 2 - } gcap_range_t; - - typedef enum - { - GCAP_CSP_UNKNOWN = 0, - GCAP_CSP_BT601 = 1, - GCAP_CSP_BT709 = 2, - GCAP_CSP_BT2020 = 3 - } gcap_colorspace_t; - - /** Best-effort static device properties. Empty/zero/-1 fields mean unknown or not reported by the driver. */ - typedef struct - { - char driver_version[64]; - char firmware_version[64]; - char serial_number[64]; - gcap_input_t input; - int pcie_gen; /** 2/3/4/5, or 0 if unknown. */ - int pcie_lanes; /** 1/4/8/16, or 0 if unknown. */ - int hdcp; /** 0 = no, 1 = yes, -1 = unknown. */ - } gcap_device_props_t; - - /** Signal/media-type status. Used for input probe, negotiated format, and runtime info. */ - typedef struct - { - int width, height; - int fps_num, fps_den; /** FPS numerator/denominator. 0 means unknown. */ - gcap_pixfmt_t pixfmt; - int bit_depth; /** 8/10/12, or 0 if unknown. */ - gcap_colorspace_t csp; - gcap_range_t range; - int hdr; /** 0 = SDR/unknown-not-HDR, 1 = HDR, -1 = unknown. */ - } gcap_signal_status_t; - - /** One video capability entry reported or inferred for a device/backend. */ - typedef struct - { - int width; - int height; - int fps_num; - int fps_den; - gcap_pixfmt_t pixfmt; - int bit_depth; - char subtype_name[32]; /** Backend/native media subtype name, e.g. HDYC/UYVY/v210/ARGB32. May be empty. */ - } gcap_video_cap_t; - - /** DirectShow property page descriptor. */ - typedef struct - { - char page_name[128]; /** Vendor/driver page name, UTF-8 when conversion succeeds. */ - int capture_pin; /** 0 = filter property page, 1 = capture-pin property page. */ - } gcap_property_page_t; - - /** Runtime information for UI/status display and diagnostics. */ - typedef struct - { - gcap_signal_status_t signal; /** Best-effort input signal shown to UI. */ - gcap_signal_status_t signal_probe; /** Raw probe/fallback result, for example DShow IAMStreamConfig::GetFormat(). */ - gcap_signal_status_t negotiated; /** Media type actually negotiated/delivered by the backend. */ - double runtime_fps; /** Measured delivered-frame FPS. 0 means unknown/not running yet. */ - int active_backend; /** gcap_backend_t value actually in use. */ - char backend_name[32]; /** Display string, e.g. WinMF GPU / WinMF CPU / DShow Raw. */ - char frame_source[32]; /** Display string, e.g. DXGI / CPU / RawSink. */ - char path_name[64]; /** Display string describing active preview/capture path. */ - char source_format[32]; /** Legacy display field: negotiated media subtype name. */ - char render_format[32]; /** Display field: canvas / scene processing format. */ - char input_signal_desc[64]; /** Display field: RGB/YUV, color space, bit depth, may be inferred. */ - char input_signal_note[32]; /** Display field: Inferred / Driver / Unknown. */ - char negotiated_desc[32]; /** Display field: RGB24 / NV12 / YUY2 / ARGB32 / etc. */ - char selectable_caps_inline[512]; /** Active open-graph selectable modes summary after SDK filtering/policy. */ - char selectable_caps_tooltip[2048];/** Full active open-graph selectable modes after SDK filtering/policy. */ - } gcap_runtime_info_t; - - /** Human-readable recording configuration currently selected by the SDK. */ - typedef struct - { - char mode_name[64]; /** e.g. DShow + FFmpeg MP4 / Media Foundation Sink Writer. */ - char encoder_name[160]; /** e.g. FFmpeg HEVC / H.265 Main10. */ - char input_format[32]; /** SDK pixel format name. */ - char output_format[32]; /** Encoder/muxer output pixel/codec description. */ - int input_bit_depth; - int output_bit_depth; - int output_fps_num; - int output_fps_den; - int video_only; /** 1 = current recorder writes video only; 0 = audio may be included when configured/supported. */ - } gcap_recording_info_t; - - /** Snapshot export flags. If desc->flags is 0, SDK exports RAW_ALL + TIFF + STATS + PNG. */ - typedef enum - { - GCAP_EXPORT_RAW_NATIVE = 1 << 0, /** Native readback RAW: 10-bit source -> *_abgr2101010.raw; 8-bit source -> *_bgra8.raw. */ - GCAP_EXPORT_RAW_RGB10_U16 = 1 << 1, /** 10-bit RGB values stored in uint16 containers: *_rgb10.raw. */ - GCAP_EXPORT_RAW_RGBA16 = 1 << 2, /** 10-bit values expanded to 16-bit RGBA: *_rgba16_expanded.raw. */ - GCAP_EXPORT_TIFF = 1 << 3, /** WIC TIFF export: *.tiff. */ - GCAP_EXPORT_STATS = 1 << 4, /** Text statistics: *.stats.txt. */ - GCAP_EXPORT_PNG = 1 << 5, /** WIC PNG preview/export image: *.png. */ - GCAP_EXPORT_RAW_GIGABYTE_HEADER = 1 << 6, /** Additional RAW copies with 128-byte GIGABYTE RAW header: *_gigabyte_*.raw. */ - GCAP_EXPORT_RAW_RGBA8 = 1 << 7, /** 8-bit hex-editor-friendly RGBA dump: *_rgba8.raw, bytes are R G B A per pixel. */ - GCAP_EXPORT_RAW_ALL = GCAP_EXPORT_RAW_NATIVE | GCAP_EXPORT_RAW_RGB10_U16 | GCAP_EXPORT_RAW_RGBA16 - } gcap_export_flags_t; - -#define GCAP_GIGABYTE_RAW_HEADER_SIZE 128 - - /* - * GIGABYTE RAW header is a 128-byte ASCII header before the RAW payload: - * GIGABYTE_RAW - * header_size=128 - * Width= - * Height= - * Format= - * SourceBitDepth= - */ - - /** Snapshot export request. */ - typedef struct - { - const char *base_path_utf8; /** Base path without SDK suffix. Must not be null/empty. UTF-8. */ - int flags; /** Bitwise OR of gcap_export_flags_t. 0 means default full export. */ - } gcap_snapshot_export_desc_t; - - /** Snapshot export result. Empty path means that file type was not requested or not generated for the source format. */ - typedef struct - { - char native_raw_path[512]; /** *_abgr2101010.raw for 10-bit sources, or *_bgra8.raw for 8-bit sources. */ - char fp16_raw_path[512]; /** *_fp16_rgba16f.raw, generated for 10-bit/FP16 scene readback when RAW export is requested. */ - char rgb10_u16_path[512]; /** *_rgb10.raw, generated for 10-bit sources when RGB10 RAW export is requested. */ - char rgba16_path[512]; /** *_rgba16_expanded.raw, generated for 10-bit sources when RAW export is requested. */ - char rgba8_path[512]; /** *_rgba8.raw, generated for 8-bit hex-editor-friendly R8 G8 B8 A8 inspection. */ - char gigabyte_native_raw_path[512]; /** Headered mirror: *_gigabyte_abgr2101010.raw or *_gigabyte_bgra8.raw. */ - char gigabyte_fp16_raw_path[512]; /** Reserved legacy field. Current snapshot export leaves this empty. */ - char gigabyte_rgb10_u16_path[512]; /** Reserved legacy field. Current snapshot export leaves this empty. */ - char gigabyte_rgba16_path[512]; /** Reserved legacy field. Current snapshot export leaves this empty. */ - char tiff_path[512]; /** *.tiff when TIFF export is requested. */ - char stats_path[512]; /** *.stats.txt when STATS export is requested. */ - char png_path[512]; /** *.png when PNG export is requested. */ - int width; - int height; - gcap_pixfmt_t source_format; - int source_bit_depth; - int generated_flags; /** Bitwise OR of actually generated gcap_export_flags_t values. */ - } gcap_snapshot_export_result_t; - - /** Recording statistics collected by the active recorder/backend. Unsupported fields remain 0. */ - typedef struct - { - uint64_t frames_written; - uint64_t frames_dropped; - uint64_t frames_duplicated; - uint64_t input_frames; - uint64_t unsupported_frames; - uint64_t overwritten_frames; - int width; - int height; - int fps_num; - int fps_den; - gcap_pixfmt_t input_pixfmt; - int output_bit_depth; - char encoder_name[128]; - char muxer_name[64]; - double avg_encode_fps; - double avg_bitrate_kbps; - } gcap_recording_stats_t; - - - /** - * Ramp-pattern validation status for gcap_tiff_analysis_t. - * - * Important: ramp validation is only meaningful for generated monotonic ramp test - * images. A real camera/HDMI frame usually returns GCAP_TIFF_RAMP_NOT_APPLICABLE; - * that does not mean the TIFF is 8-bit or invalid. Use likely_ten_bit_content, - * min/max, unique_value_count, and effective_bit_depth as the general bit-depth - * evidence for arbitrary images. - */ - typedef enum - { - GCAP_TIFF_RAMP_NOT_CHECKED = 0, - GCAP_TIFF_RAMP_NOT_APPLICABLE = 1, - GCAP_TIFF_RAMP_DETECTED_VALID = 2, - GCAP_TIFF_RAMP_DETECTED_INVALID = 3 - } gcap_tiff_ramp_status_t; - - /** TIFF bit-depth / optional ramp-pattern analysis result. Fixed-size C struct for SDK clients. */ - typedef struct - { - int ok; /** 1 = analysis succeeded, 0 = failed. */ - char path[512]; /** Input TIFF path, UTF-8 when available. */ - char error[512]; /** Failure reason, UTF-8. Empty on success. */ - - int width; - int height; - int channels; - int bits_per_sample; - int samples_per_pixel; - int stored_bit_depth; - int effective_bit_depth; - - char pixel_format_name[96]; - char photometric[64]; - - uint64_t min_value; - uint64_t max_value; - uint64_t unique_value_count; - - int likely_ten_bit_ramp; /** Backward-compatible alias: 1 only when ramp_status == GCAP_TIFF_RAMP_DETECTED_VALID. */ - int strict_ten_bit_ramp; /** Strict monotonic ramp and likely 10-bit content. */ - int visual_ten_bit_ramp_candidate; /** A monotonic visual ramp pattern was detected, regardless of bit-depth validity. */ - int likely_ten_bit_content; /** General bit-depth evidence for arbitrary images; does not require a ramp pattern. */ - int values_look_shifted_10bit; - int values_look_8bit_expanded; - int ramp_status; /** gcap_tiff_ramp_status_t. Non-ramp images should be NOT_APPLICABLE, not failed. */ - - char ramp_reason[512]; - char strict_ramp_reason[512]; - char visual_ramp_reason[512]; - char ramp_note[512]; /** Human-readable explanation of ramp_status. */ - - int sampled_row_y; - char sampled_row_source[96]; - char sampled_row_logical10_rule[192]; - char sampled_row_raw16_csv[4096]; - char sampled_row_logical10_csv[4096]; - - int preview_stride_bytes; /** RGBA64 preview stride. Use gcap_read_tiff_preview_rgba64() to read data. */ - size_t preview_size_bytes; /** Required RGBA64 preview buffer size. */ - } gcap_tiff_analysis_t; - - typedef enum - { - GCAP_DEINT_AUTO = 0, - GCAP_DEINT_OFF, - GCAP_DEINT_WEAVE, - GCAP_DEINT_BOB - } gcap_deinterlace_t; - - /** Optional processing preferences. Unsupported options are ignored or return GCAP_ENOTSUP depending on backend. */ - typedef struct - { - gcap_pixfmt_t preferred_pixfmt; /** Preferred capture format. Use backend capability APIs to discover support. */ - gcap_deinterlace_t deinterlace; - gcap_range_t force_range; /** GCAP_RANGE_UNKNOWN = auto. */ - } gcap_processing_opts_t; - - /** ProcAmp settings. SDK UI scale is 0..255, where 128 is neutral. */ - typedef struct - { - int brightness; - int contrast; - int hue; - int saturation; - int sharpness; - } gcap_procamp_t; - - /** One ProcAmp control range in SDK UI units. */ - typedef struct - { - int supported; /** Non-zero if this control is supported by the active backend/path. */ - int min_value; /** Minimum accepted value. */ - int max_value; /** Maximum accepted value. */ - int step; /** Recommended slider step. */ - int default_value; /** Recommended neutral/default value. */ - int current_value; /** Current value if available; otherwise default_value. */ - } gcap_procamp_range_t; - - /** ProcAmp capability block for Brightness/Contrast/Hue/Saturation/Sharpness. */ - typedef struct - { - gcap_procamp_range_t brightness; - gcap_procamp_range_t contrast; - gcap_procamp_range_t hue; - gcap_procamp_range_t saturation; - gcap_procamp_range_t sharpness; - } gcap_procamp_caps_t; - - /** Requested capture profile. For GCAP_PROFILE_CUSTOM, set width/height/fps/format. */ - typedef struct - { - int width, height; - int fps_num, fps_den; - gcap_pixfmt_t format; - gcap_profile_mode_t mode; - } gcap_profile_t; - - /** Legacy frame callback payload. Prefer gcap_frame_packet_t for SDK clients that need backend/source metadata. */ - typedef struct - { - const void *data[3]; /** Plane pointers. Valid only during callback. */ - int stride[3]; /** Bytes per row for each plane. */ - int plane_count; - int width, height; - gcap_pixfmt_t format; - uint64_t pts_ns; - uint64_t frame_id; - } gcap_frame_t; - - typedef enum - { - GCAP_SOURCE_UNKNOWN = 0, - GCAP_SOURCE_WINMF_GPU = 1, - GCAP_SOURCE_WINMF_CPU = 2, - GCAP_SOURCE_DSHOW_RAWSINK = 3, - GCAP_SOURCE_DSHOW_RENDERER = 4 /** Legacy/debug renderer path. Prefer GCAP_SOURCE_DSHOW_RAWSINK for SDK clients. */ - } gcap_frame_source_kind_t; - - /** Preferred raw frame callback payload. Plane pointers are valid only during callback. */ - typedef struct - { - int width, height; - gcap_pixfmt_t format; - int plane_count; - const void *data[3]; /** Plane pointers. Do not retain after callback returns. */ - int stride[3]; /** Bytes per row for each plane. */ - uint64_t pts_ns; - uint64_t frame_id; - int backend; /** gcap_backend_t value. */ - int source_kind; /** gcap_frame_source_kind_t value. */ - int gpu_backed; /** 1 when frame originated from GPU-backed path; callback data is still CPU-readable. */ - } gcap_frame_packet_t; - - typedef enum - { - GCAP_PREVIEW_BITDEPTH_8BIT = 0, - GCAP_PREVIEW_BITDEPTH_10BIT = 1, - GCAP_PREVIEW_BITDEPTH_AUTO = 2 - } gcap_preview_bitdepth_t; - - /** Native preview target. The SDK renders into the supplied HWND. */ - typedef struct - { - void *hwnd; /** Native HWND. Required when enable_preview is non-zero. */ - int enable_preview; /** 0 = disable preview, 1 = enable preview. */ - int use_fp16_pipeline; /** 1 = use FP16 scene pipeline when available. Recommended for 10-bit/HDR-oriented paths. */ - int swapchain_10bit; /** 0 = force 8-bit BGRA, 1 = prefer/force 10-bit RGB10A2, 2 = auto try 10-bit then fallback 8-bit. */ - } gcap_preview_desc_t; - - typedef void (*gcap_on_video_cb)(const gcap_frame_t *frame, void *user); - typedef void (*gcap_on_frame_packet_cb)(const gcap_frame_packet_t *pkt, void *user); - typedef void (*gcap_on_error_cb)(gcap_status_t code, const char *msg, void *user); - - typedef struct gcap_handle_t *gcap_handle; - - /** - * Installs a process-wide SDK log callback. - * - * This is intended for SDK clients to receive WinMF/DShow/snapshot/recording - * diagnostics in their own logging system. Passing cb = NULL disables the - * callback. The callback may be invoked from SDK/backend worker threads. - * The SDK may still also send messages to OutputDebugString on Windows as - * a fallback. - */ - GCAP_API void gcap_set_log_callback(gcap_log_callback_t cb, void *user); - - /** - * Enumerate capture devices. - * - * Parameters: - * out - Output array. Must not be null in the current implementation. - * max - Number of entries available in out. - * count - Receives total/actual count when non-null. - * - * Return: - * GCAP_OK on success. GCAP_EINVAL for invalid output array/max. - * - * Thread-safety: - * Safe to call before any handle is created. Avoid calling repeatedly from - * a real-time callback thread because device enumeration can touch OS/driver APIs. - */ - GCAP_API gcap_status_t gcap_enumerate(gcap_device_info_t *out, int max, int *count); - - /** Create an unopened handle. Use gcap_open2() before gcap_start(). */ - GCAP_API gcap_status_t gcap_create(gcap_handle *out); - - /** Convenience API: create and open a device in one call. Close with gcap_close(). */ - GCAP_API gcap_status_t gcap_open(int device_index, gcap_handle *out); - - /** Open an existing handle created by gcap_create(). Must be called before gcap_start(). */ - GCAP_API gcap_status_t gcap_open2(gcap_handle h, int device_index); - - /** - * Set requested capture profile. - * - * Call state: - * Recommended after open and before start. Changing profile while running - * may return GCAP_ESTATE or may require stop/start depending on backend. - * - * Notes: - * Use gcap_enum_video_caps_ex() / gcap_get_recommended_profile() to find - * supported values. The driver may still negotiate a different final format; - * query gcap_get_runtime_info() after start to verify. - */ - GCAP_API gcap_status_t gcap_set_profile(gcap_handle h, const gcap_profile_t *prof); - - /** Configure SDK buffering hints. Call before gcap_start(). Backend may ignore unsupported hints. */ - GCAP_API gcap_status_t gcap_set_buffers(gcap_handle h, int count, size_t bytes_hint); - - /** - * Set legacy video/error callbacks. - * - * Callback lifetime: - * Frame data is valid only during the callback. Copy before returning. - * Passing null callbacks disables that callback type. - */ - GCAP_API gcap_status_t gcap_set_callbacks(gcap_handle h, gcap_on_video_cb vcb, gcap_on_error_cb ecb, void *user); - - /** - * Set preferred frame packet callback. - * - * Call state: - * Usually configured before gcap_start(); can be cleared before/after stop. - * - * Thread-safety: - * Invoked from SDK/backend worker thread. Do not block for long periods. - */ - GCAP_API gcap_status_t gcap_set_frame_packet_callback(gcap_handle h, gcap_on_frame_packet_cb cb, void *user); - - /** Start capture/preview/callback delivery. Requires an opened handle. */ - GCAP_API gcap_status_t gcap_start(gcap_handle h); - - /** - * Start recording to an output path. - * - * Call state: - * Requires an opened and normally running capture session. If called before - * capture is started, backend support is not guaranteed. - * - * Parameters: - * path_utf8 - Output file path, UTF-8. MP4 is the intended container for - * current FFmpeg/MF recorder paths. - * - * Notes: - * Use gcap_get_recording_info() after profile/backend selection to show the - * selected encoder/mode to the user. Use gcap_get_recording_stats() after or - * during recording to inspect counters supported by the active backend. - */ - GCAP_API gcap_status_t gcap_start_recording(gcap_handle h, const char *path_utf8); - - /** Stop active recording. Safe to call when recording is not active; backend may return GCAP_ESTATE. */ - GCAP_API gcap_status_t gcap_stop_recording(gcap_handle h); - - /** Stop capture/preview/callback delivery. Recording should be stopped first. */ - GCAP_API gcap_status_t gcap_stop(gcap_handle h); - - /** - * Enumerate WASAPI capture endpoints. - * - * Legacy status-code API. New clients may prefer gcap_audio_device_count() - * and gcap_audio_enum_devices(). - */ - GCAP_API gcap_status_t gcap_enumerate_audio_devices(gcap_audio_device_t *out, int max, int *count); - - /** - * Select WASAPI capture endpoint for recording. - * - * Call state: - * Call before gcap_start_recording(). If changed while recording, behavior is - * backend-dependent and not recommended. - * - * Parameters: - * device_id_utf8 - Endpoint id from audio enumeration. null or empty string - * means system default capture endpoint. - */ - GCAP_API gcap_status_t gcap_set_recording_audio_device(gcap_handle h, const char *device_id_utf8); - - /** Close and destroy a handle. Do not use the handle after this call. */ - GCAP_API gcap_status_t gcap_close(gcap_handle h); - - /** Set global preferred backend for subsequently opened sessions. Not per-handle. */ - GCAP_API void gcap_set_backend(int backend); - - /** Select D3D11 adapter index for GPU/DXGI processing. -1 means system default adapter. */ - GCAP_API void gcap_set_d3d_adapter(int adapter_index); - - /** Query actual backend currently used by an opened/running handle. Returns -1 for invalid handle. */ - GCAP_API int gcap_get_active_backend(gcap_handle h); - - /** - * Legacy snapshot helper. - * - * Prefer gcap_export_snapshot() for new SDK clients because it returns the - * generated paths and flags. This helper uses base_path_utf8 plus SDK-defined - * suffixes and writes requested RAW/TIFF/STATS outputs. - */ - GCAP_API gcap_status_t gcap_export_preview_scene_rgb10(gcap_handle h, const char *base_path_utf8, - int export_raw, int export_tiff, int export_stats); - - /** - * Export a snapshot from the current preview scene/readback path. - * - * Call state: - * Requires a valid opened handle and a capture/preview scene that has already - * produced at least one frame. In normal use, call after gcap_start() and - * after frames are visible/delivered. It does not require the caller to have - * a frame callback. A preview HWND is strongly recommended because the export - * currently reads from the SDK preview/scene pipeline. - * - * Recording interaction: - * Intended to be callable while recording, but it may briefly contend with - * GPU/readback/file I/O. Avoid calling it from frame callbacks or timing- - * critical threads. - * - * Output naming: - * Given base_path_utf8 = "C:/cap/snapshot_001", generated paths are: - * 10-bit source RAW: - * C:/cap/snapshot_001_abgr2101010.raw - * C:/cap/snapshot_001_fp16_rgba16f.raw - * C:/cap/snapshot_001_rgb10.raw - * C:/cap/snapshot_001_rgba16_expanded.raw - * 8-bit source RAW: - * C:/cap/snapshot_001_bgra8.raw - * TIFF: - * C:/cap/snapshot_001.tiff - * STATS: - * C:/cap/snapshot_001.stats.txt - * PNG: - * C:/cap/snapshot_001.png - * - * Parameters: - * h - Opened capture handle. - * desc - Export request. desc->base_path_utf8 must not be null/empty. - * desc->flags == 0 means RAW_ALL | TIFF | STATS | PNG. - * out - Optional result. If non-null, SDK clears it to zero before writing. - * - * Return: - * GCAP_OK on success. On failure, no guarantee is made that partial files were - * not written; callers may delete files using the expected suffixes if needed. - */ - GCAP_API gcap_status_t gcap_export_snapshot(gcap_handle h, const gcap_snapshot_export_desc_t *desc, - gcap_snapshot_export_result_t *out); - - /** Query best-effort static device properties. Can be called after open; values may be unknown. */ - GCAP_API gcap_status_t gcap_get_device_props(gcap_handle h, gcap_device_props_t *out); - - /** Query current/best-effort input signal. Can be called after open/start. */ - GCAP_API gcap_status_t gcap_get_signal_status(gcap_handle h, gcap_signal_status_t *out); - - /** Query combined runtime status. Most useful after gcap_start(). */ - GCAP_API gcap_status_t gcap_get_runtime_info(gcap_handle h, gcap_runtime_info_t *out); - - /** Set processing preferences such as preferred format, deinterlace, or forced range. Prefer calling before start. */ - GCAP_API gcap_status_t gcap_set_processing(gcap_handle h, const gcap_processing_opts_t *opts); - - /** - * Query current ProcAmp values from the active backend/path. - * - * Can be called after gcap_open(). If the active backend/path does not - * support SDK ProcAmp, returns GCAP_ENOTSUP. - */ - GCAP_API gcap_status_t gcap_get_procamp(gcap_handle h, gcap_procamp_t *out); - - /** - * Query ProcAmp control ranges/capabilities. - * - * The current implementation exposes SDK-side preview/conversion ProcAmp - * controls in 0..255 units, default 128. These are not necessarily the - * hardware driver's IAMVideoProcAmp ranges. Unsupported controls are marked - * supported = 0. - */ - GCAP_API gcap_status_t gcap_get_procamp_caps(gcap_handle h, gcap_procamp_caps_t *out); - - /** Apply ProcAmp settings on supported CPU/GPU preview/conversion paths. Passing null resets to neutral. */ - GCAP_API gcap_status_t gcap_set_procamp(gcap_handle h, const gcap_procamp_t *p); - - /** Reset ProcAmp settings to backend defaults/neutral values. */ - GCAP_API gcap_status_t gcap_reset_procamp(gcap_handle h); - - /** Legacy audio count helper. Prefer gcap_audio_device_count() for new code. */ - GCAP_API int gcap_get_audio_device_count(void); - - /** Legacy audio enumeration helper. Prefer gcap_audio_enum_devices() for new code. Returns number written, or total if out_devices is null. */ - GCAP_API int gcap_enum_audio_devices(gcap_audio_device_t *out_devices, int max_devices); - - /** Return number of active WASAPI capture devices. */ - GCAP_API int gcap_audio_device_count(void); - - /** Enumerate active WASAPI capture devices. Returns number written, or total if out_devices is null or max_devices <= 0. */ - GCAP_API int gcap_audio_enum_devices(gcap_audio_device_t *out_devices, int max_devices); - - /** Best-effort match from the selected video capture device name to a WASAPI capture endpoint. */ - GCAP_API int gcap_audio_find_device_for_capture(const char *capture_device_name_utf8, gcap_audio_device_t *out_device); - - /** Return stable SDK pixel format display name. Never returns null. */ - GCAP_API const char *gcap_pixfmt_name(gcap_pixfmt_t fmt); - - /** Return gcapture SDK version string, for example "1.0.0". Never returns null. */ - GCAP_API const char *gcap_version_string(void); - - /** Return nominal bit depth for a pixel format, or 0 if unknown/unsupported. */ - GCAP_API int gcap_pixfmt_bit_depth(gcap_pixfmt_t fmt); - - /** Return non-zero if the pixel format is treated as 10-bit by SDK helpers. */ - GCAP_API int gcap_pixfmt_is_10bit(gcap_pixfmt_t fmt); - - /** Return non-zero if the pixel format is YUV-family. */ - GCAP_API int gcap_pixfmt_is_yuv(gcap_pixfmt_t fmt); - - /** Return default stride in bytes for a single row/primary plane at the given width, or 0 if unknown. */ - GCAP_API int gcap_pixfmt_default_stride(int width, gcap_pixfmt_t fmt); - - /** Return stable backend display name. Never returns null. */ - GCAP_API const char *gcap_backend_name(int backend); - - /** Return stable frame source display name. Never returns null. */ - GCAP_API const char *gcap_source_kind_name(int source_kind); - - /** Return non-zero when the recording helper would choose HEVC/H.265 Main10 for the input format. */ - GCAP_API int gcap_recording_uses_hevc_main10(gcap_pixfmt_t fmt); - - /** Return human-readable recording mode name for a backend. Never returns null. */ - GCAP_API const char *gcap_recording_mode_name(int backend); - - /** - * Query current recording mode/encoder information. - * - * Call state: - * Can be called after open/profile selection, before or during recording. - * The result is based on current backend and negotiated/requested format; - * after gcap_start(), it is more accurate. - */ - GCAP_API gcap_status_t gcap_get_recording_info(gcap_handle h, gcap_recording_info_t *out); - - /** - * Query recording counters/statistics. - * - * Call state: - * Can be called during recording or after gcap_stop_recording() while the - * handle is still valid. Unsupported counters remain 0. - */ - GCAP_API gcap_status_t gcap_get_recording_stats(gcap_handle h, gcap_recording_stats_t *out); - - /** - * Convert callback frame packet to packed BGRA8. - * - * Parameters: - * src - Frame packet received from gcap_on_frame_packet_cb. - * dst - Destination buffer. - * dst_stride - Destination bytes per row. Must be >= src->width * 4. - * - * Supported input formats: - * GCAP_FMT_ARGB, GCAP_FMT_NV12, GCAP_FMT_YUY2, GCAP_FMT_Y210. - * - * Thread-safety: - * Stateless helper. It may be called from inside the frame callback if the - * destination buffer is caller-owned and conversion cost is acceptable. - */ - GCAP_API gcap_status_t gcap_frame_to_bgra8(const gcap_frame_packet_t *src, void *dst, int dst_stride); - - - /** - * Analyze a TIFF file written by SDK snapshot export or any WIC-readable TIFF. - * - * The analysis uses Windows Imaging Component on Windows and reports stored - * bit depth, effective bit depth heuristics, min/max/unique values, and - * optional ramp-pattern validation. Ramp validation is only meaningful for - * generated monotonic ramp test images; normal camera/HDMI content commonly - * reports GCAP_TIFF_RAMP_NOT_APPLICABLE. That is not a failure and does not - * imply 8-bit content. Use likely_ten_bit_content and the value statistics - * as the general bit-depth evidence for arbitrary images. - * - * It does not allocate memory for the caller. - */ - GCAP_API gcap_status_t gcap_analyze_tiff(const char *path_utf8, gcap_tiff_analysis_t *out); - - /** - * Decode the first TIFF frame into RGBA64 little-endian pixels for preview. - * - * Pass dst = NULL or dst_size = 0 to query required_size/width/height/stride. - * The destination buffer must be at least required_size bytes. - */ - GCAP_API gcap_status_t gcap_read_tiff_preview_rgba64(const char *path_utf8, - void *dst, - size_t dst_size, - int *width, - int *height, - int *stride_bytes, - size_t *required_size); - - /** Return human-readable status string. Never returns null. */ - GCAP_API const char *gcap_strerror(gcap_status_t); - - /** - * Configure native HWND preview. - * - * Call state: - * Recommended after open and before start. Some backends may allow changing - * preview target while stopped only. To disable preview, pass enable_preview=0. - * - * Notes: - * The SDK does not own the HWND. The application must keep it valid while - * preview is enabled/running. - */ - GCAP_API gcap_status_t gcap_set_preview(gcap_handle h, const gcap_preview_desc_t *desc); - - /** - * Enumerate DirectShow video format capabilities for a device index. - * - * Return: - * Number of entries written. Passing null or max_caps <= 0 returns supported - * count when available. - * - * Notes: - * DShow-specific legacy helper. New code can use gcap_enum_video_caps_ex(). - */ - GCAP_API int gcap_enum_video_caps(int device_index, gcap_video_cap_t *out_caps, int max_caps); - - /** Backend-aware capability enumeration helper. Returns number written, or count when out_caps is null/max_caps <= 0. */ - GCAP_API int gcap_enum_video_caps_ex(int backend, int device_index, gcap_video_cap_t *out_caps, int max_caps); - - /** Return SDK-recommended profile for backend/device based on current format priority and capabilities. */ - GCAP_API gcap_status_t gcap_get_recommended_profile(int backend, int device_index, gcap_profile_t *out_profile); - - /** Enumerate unique pixel formats supported by a device/backend. Returns number written, or count when out_formats is null/max_formats <= 0. */ - GCAP_API int gcap_enum_supported_pixel_formats(int backend, int device_index, gcap_pixfmt_t *out_formats, int max_formats); - - /** Enumerate available DirectShow property pages for a device. Returns number written, or count when out_pages is null/max_pages <= 0. */ - GCAP_API int gcap_enum_property_pages(int device_index, gcap_property_page_t *out_pages, int max_pages); - - /** Open a device-specific vendor DShow property page. Debug/test helper; not required for generic capture flow. */ - GCAP_API int gcap_open_vendor_property_page(int device_index); - - /** Open a named DirectShow property page. page_name_utf8 must match a name returned by gcap_enum_property_pages(). */ - GCAP_API int gcap_open_named_property_page(int device_index, const char *page_name_utf8, int capture_pin); - -#ifdef __cplusplus -} -#endif diff --git a/sdk/gcapture/src/core/logging.h b/sdk/gcapture/src/core/logging.h deleted file mode 100644 index e93cea9..0000000 --- a/sdk/gcapture/src/core/logging.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include "gcapture.h" -#include - - -namespace gcap -{ - void log_message(gcap_log_level_t level, const char *message_utf8); - void log_message_w(gcap_log_level_t level, const wchar_t *message_wide); - void log_printf(gcap_log_level_t level, const char *fmt, ...); -} - -inline void gcap_log_trace(const char *message_utf8) { gcap::log_message(GCAP_LOG_TRACE, message_utf8); } -inline void gcap_log_debug(const char *message_utf8) { gcap::log_message(GCAP_LOG_DEBUG, message_utf8); } -inline void gcap_log_info(const char *message_utf8) { gcap::log_message(GCAP_LOG_INFO, message_utf8); } -inline void gcap_log_warn(const char *message_utf8) { gcap::log_message(GCAP_LOG_WARN, message_utf8); } -inline void gcap_log_error(const char *message_utf8) { gcap::log_message(GCAP_LOG_ERROR, message_utf8); } -inline void gcap_log_debug_w(const wchar_t *message_wide) { gcap::log_message_w(GCAP_LOG_DEBUG, message_wide); } diff --git a/sdk/gvfg/CMakeLists.txt b/sdk/gvfg/CMakeLists.txt index 020cee9..b4c7570 100644 --- a/sdk/gvfg/CMakeLists.txt +++ b/sdk/gvfg/CMakeLists.txt @@ -13,8 +13,8 @@ add_library(gvfg SHARED 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 + src/gvfg_log_bridge.cpp + src/render/shared_scene_pipeline.cpp ) set_target_properties(gvfg PROPERTIES @@ -29,9 +29,8 @@ target_include_directories(gvfg 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 + ${CMAKE_CURRENT_SOURCE_DIR}/src/internal + ${CMAKE_CURRENT_SOURCE_DIR}/src/render ) target_compile_definitions(gvfg PRIVATE @@ -52,3 +51,5 @@ target_link_libraries(gvfg PRIVATE if (MSVC) target_compile_options(gvfg PRIVATE /utf-8 /EHsc) endif() + + diff --git a/sdk/gvfg/src/gvfg_capture.cpp b/sdk/gvfg/src/gvfg_capture.cpp index 1230e46..39ce125 100644 --- a/sdk/gvfg/src/gvfg_capture.cpp +++ b/sdk/gvfg/src/gvfg_capture.cpp @@ -1,7 +1,7 @@ #include "gvfg_capture.h" -#include "gcapture.h" -#include "pipeline/shared_scene_pipeline.h" +#include "gvfg_render_types.h" +#include "shared_scene_pipeline.h" #include "xdma_capture_session.h" #include @@ -21,6 +21,7 @@ #include using Microsoft::WRL::ComPtr; +using namespace gvfg::internal; namespace { @@ -364,7 +365,7 @@ struct gvfg_handle_t previewDesc = desc; previewHwnd = desc.enable_preview ? desc.hwnd : nullptr; if (pipeline) - pipeline->configurePreview(toGcapPreviewDesc()); + pipeline->configurePreview(toRenderPreviewDesc()); if (previewHwnd && width > 0 && height > 0) createRenderPipeline(); return GVFG_OK; @@ -598,23 +599,23 @@ struct gvfg_handle_t return GVFG_OK; } - gcap_preview_desc_t toGcapPreviewDesc() const + gvfg_render_preview_desc_t toRenderPreviewDesc() const { - gcap_preview_desc_t desc{}; + gvfg_render_preview_desc_t desc{}; desc.hwnd = previewHwnd; desc.enable_preview = previewHwnd ? 1 : 0; desc.use_fp16_pipeline = 1; switch (previewDesc.swapchain_bitdepth) { case GVFG_PREVIEW_BITDEPTH_8BIT: - desc.swapchain_10bit = GCAP_PREVIEW_BITDEPTH_8BIT; + desc.swapchain_10bit = GVFG_RENDER_PREVIEW_BITDEPTH_8BIT; break; case GVFG_PREVIEW_BITDEPTH_10BIT: - desc.swapchain_10bit = GCAP_PREVIEW_BITDEPTH_10BIT; + desc.swapchain_10bit = GVFG_RENDER_PREVIEW_BITDEPTH_10BIT; break; case GVFG_PREVIEW_BITDEPTH_AUTO: default: - desc.swapchain_10bit = GCAP_PREVIEW_BITDEPTH_AUTO; + desc.swapchain_10bit = GVFG_RENDER_PREVIEW_BITDEPTH_AUTO; break; } return desc; @@ -674,7 +675,7 @@ struct gvfg_handle_t if (!pipeline->initialize(d3d.Get(), ctx.Get(), d2dCtx.Get(), dwrite.Get(), d2dWhite.Get(), d2dBlack.Get())) return false; - pipeline->configurePreview(toGcapPreviewDesc()); + pipeline->configurePreview(toRenderPreviewDesc()); pipeline->set_source_bit_depth(static_cast(bitDepth ? bitDepth : 8)); return pipeline->ensure_rt_and_pipeline(static_cast(width), static_cast(height)) && pipeline->ensure_preview_swapchain(static_cast(width), static_cast(height)); @@ -743,7 +744,7 @@ struct gvfg_handle_t pipeline->set_source_bit_depth(static_cast(frame.bit_depth ? frame.bit_depth : fallbackBitDepth)); const auto *base = static_cast(frame.data); - gcap_pixfmt_t renderFmt = GCAP_FMT_YUY2; + gvfg_render_pixfmt_t renderFmt = GVFG_RENDER_FMT_YUY2; bool uploaded = false; switch (frame.pixel_format) @@ -753,7 +754,7 @@ struct gvfg_handle_t const int stride = frame.plane_stride_bytes[0] ? static_cast(frame.plane_stride_bytes[0]) : w * 2; if (stride < w * 2) return false; - renderFmt = GCAP_FMT_YUY2; + renderFmt = GVFG_RENDER_FMT_YUY2; uploaded = pipeline->upload_yuy2_frame(base + frame.plane_offset_bytes[0], stride, w, h); break; } @@ -762,7 +763,7 @@ struct gvfg_handle_t const int stride = frame.plane_stride_bytes[0] ? static_cast(frame.plane_stride_bytes[0]) : w * 4; if (stride < w * 4) return false; - renderFmt = GCAP_FMT_Y210; + renderFmt = GVFG_RENDER_FMT_Y210; uploaded = pipeline->upload_y210_frame(base + frame.plane_offset_bytes[0], stride, w, h); break; } @@ -772,7 +773,7 @@ struct gvfg_handle_t return false; const int strideY = frame.plane_stride_bytes[0] ? static_cast(frame.plane_stride_bytes[0]) : w; const int strideUV = frame.plane_stride_bytes[1] ? static_cast(frame.plane_stride_bytes[1]) : strideY; - renderFmt = GCAP_FMT_NV12; + renderFmt = GVFG_RENDER_FMT_NV12; uploaded = pipeline->upload_nv12_frame(base + frame.plane_offset_bytes[0], strideY, base + frame.plane_offset_bytes[1], strideUV, w, h); break; @@ -783,7 +784,7 @@ struct gvfg_handle_t return false; const int strideY = frame.plane_stride_bytes[0] ? static_cast(frame.plane_stride_bytes[0]) : w * 2; const int strideUV = frame.plane_stride_bytes[1] ? static_cast(frame.plane_stride_bytes[1]) : strideY; - renderFmt = GCAP_FMT_P010; + renderFmt = GVFG_RENDER_FMT_P010; uploaded = pipeline->upload_p010_frame(base + frame.plane_offset_bytes[0], strideY, base + frame.plane_offset_bytes[1], strideUV, w, h); break; @@ -817,7 +818,7 @@ struct gvfg_handle_t if (!pipeline->blit_fp16_to_rgba8(w, h)) return; - gcap_frame_t readback{}; + gvfg_render_frame_t readback{}; if (pipeline->readback_to_frame(w, h, frame.timestamp_ns ? frame.timestamp_ns : now_ns(), frame.frame_id, &readback)) { gvfg_frame_t out{}; @@ -1143,3 +1144,6 @@ extern "C" } } } + + + diff --git a/sdk/gvfg/src/gcapture_log_bridge.cpp b/sdk/gvfg/src/gvfg_log_bridge.cpp similarity index 83% rename from sdk/gvfg/src/gcapture_log_bridge.cpp rename to sdk/gvfg/src/gvfg_log_bridge.cpp index d659419..ac0c993 100644 --- a/sdk/gvfg/src/gcapture_log_bridge.cpp +++ b/sdk/gvfg/src/gvfg_log_bridge.cpp @@ -1,4 +1,4 @@ -#include "gcapture.h" +#include "gvfg_logging.h" #include #include @@ -9,9 +9,9 @@ #include #endif -namespace gcap +namespace gvfg::internal { - void log_message(gcap_log_level_t, const char *message_utf8) + void log_message(gvfg_log_level_t, const char *message_utf8) { #ifdef _WIN32 const char *msg = message_utf8 ? message_utf8 : ""; @@ -24,7 +24,7 @@ namespace gcap #endif } - void log_message_w(gcap_log_level_t level, const wchar_t *message_wide) + void log_message_w(gvfg_log_level_t level, const wchar_t *message_wide) { #ifdef _WIN32 if (!message_wide) @@ -44,7 +44,7 @@ namespace gcap #endif } - void log_printf(gcap_log_level_t level, const char *fmt, ...) + void log_printf(gvfg_log_level_t level, const char *fmt, ...) { if (!fmt) { @@ -60,3 +60,4 @@ namespace gcap log_message(level, buf); } } + diff --git a/sdk/gvfg/src/internal/gvfg_logging.h b/sdk/gvfg/src/internal/gvfg_logging.h new file mode 100644 index 0000000..80b559c --- /dev/null +++ b/sdk/gvfg/src/internal/gvfg_logging.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +namespace gvfg::internal +{ + typedef enum + { + GVFG_LOG_TRACE = 0, + GVFG_LOG_DEBUG = 1, + GVFG_LOG_INFO = 2, + GVFG_LOG_WARN = 3, + GVFG_LOG_ERROR = 4 + } gvfg_log_level_t; + + void log_message(gvfg_log_level_t level, const char *message_utf8); + void log_message_w(gvfg_log_level_t level, const wchar_t *message_wide); + void log_printf(gvfg_log_level_t level, const char *fmt, ...); +} + +inline void gvfg_log_trace(const char *message_utf8) { gvfg::internal::log_message(gvfg::internal::GVFG_LOG_TRACE, message_utf8); } +inline void gvfg_log_debug(const char *message_utf8) { gvfg::internal::log_message(gvfg::internal::GVFG_LOG_DEBUG, message_utf8); } +inline void gvfg_log_info(const char *message_utf8) { gvfg::internal::log_message(gvfg::internal::GVFG_LOG_INFO, message_utf8); } +inline void gvfg_log_warn(const char *message_utf8) { gvfg::internal::log_message(gvfg::internal::GVFG_LOG_WARN, message_utf8); } +inline void gvfg_log_error(const char *message_utf8) { gvfg::internal::log_message(gvfg::internal::GVFG_LOG_ERROR, message_utf8); } +inline void gvfg_log_debug_w(const wchar_t *message_wide) { gvfg::internal::log_message_w(gvfg::internal::GVFG_LOG_DEBUG, message_wide); } diff --git a/sdk/gvfg/src/internal/gvfg_render_types.h b/sdk/gvfg/src/internal/gvfg_render_types.h new file mode 100644 index 0000000..aea904d --- /dev/null +++ b/sdk/gvfg/src/internal/gvfg_render_types.h @@ -0,0 +1,59 @@ +#pragma once + +#include + +namespace gvfg::internal +{ + typedef enum + { + GVFG_RENDER_FMT_NV12, + GVFG_RENDER_FMT_YUY2, + GVFG_RENDER_FMT_ARGB, + GVFG_RENDER_FMT_P010, + GVFG_RENDER_FMT_Y210, + GVFG_RENDER_FMT_V210, + GVFG_RENDER_FMT_R210 + } gvfg_render_pixfmt_t; + + typedef struct + { + const void *data[3]; + int stride[3]; + int plane_count; + int width; + int height; + gvfg_render_pixfmt_t format; + uint64_t pts_ns; + uint64_t frame_id; + } gvfg_render_frame_t; + + typedef enum + { + GVFG_RENDER_PREVIEW_BITDEPTH_8BIT = 0, + GVFG_RENDER_PREVIEW_BITDEPTH_10BIT = 1, + GVFG_RENDER_PREVIEW_BITDEPTH_AUTO = 2 + } gvfg_render_preview_bitdepth_t; + + typedef struct + { + void *hwnd; + int enable_preview; + int use_fp16_pipeline; + int swapchain_10bit; + } gvfg_render_preview_desc_t; + + typedef enum + { + GVFG_RENDER_EXPORT_RAW_NATIVE = 1 << 0, + GVFG_RENDER_EXPORT_RAW_RGB10_U16 = 1 << 1, + GVFG_RENDER_EXPORT_RAW_RGBA16 = 1 << 2, + GVFG_RENDER_EXPORT_TIFF = 1 << 3, + GVFG_RENDER_EXPORT_STATS = 1 << 4, + GVFG_RENDER_EXPORT_PNG = 1 << 5, + GVFG_RENDER_EXPORT_RAW_GIGABYTE_HEADER = 1 << 6, + GVFG_RENDER_EXPORT_RAW_RGBA8 = 1 << 7, + GVFG_RENDER_EXPORT_RAW_ALL = GVFG_RENDER_EXPORT_RAW_NATIVE | GVFG_RENDER_EXPORT_RAW_RGB10_U16 | GVFG_RENDER_EXPORT_RAW_RGBA16 + } gvfg_render_export_flags_t; + + enum { GVFG_RENDER_GIGABYTE_RAW_HEADER_SIZE = 128 }; +} diff --git a/sdk/gcapture/src/pipeline/shared_scene_pipeline.cpp b/sdk/gvfg/src/render/shared_scene_pipeline.cpp similarity index 97% rename from sdk/gcapture/src/pipeline/shared_scene_pipeline.cpp rename to sdk/gvfg/src/render/shared_scene_pipeline.cpp index 85bcaad..c74bf4b 100644 --- a/sdk/gcapture/src/pipeline/shared_scene_pipeline.cpp +++ b/sdk/gvfg/src/render/shared_scene_pipeline.cpp @@ -1,11 +1,13 @@ #include -#include "../core/logging.h" +#include "../internal/gvfg_logging.h" #ifndef NOMINMAX #define NOMINMAX #endif #include "shared_scene_pipeline.h" +using namespace gvfg::internal; + #include #include #include @@ -26,7 +28,7 @@ static void SSP_DBG(const char *stage, HRESULT hr) char buf[256] = {}; std::snprintf(buf, sizeof(buf), "[SharedScene] %s : hr=0x%lx\n", stage ? stage : "(null)", (unsigned long)hr); - gcap_log_debug(buf); + gvfg_log_debug(buf); } using Microsoft::WRL::ComPtr; @@ -68,8 +70,8 @@ static void ssp_log_text(const char *msg) { if (!msg) return; - gcap_log_debug(msg); - gcap_log_debug("\n"); + gvfg_log_debug(msg); + gvfg_log_debug("\n"); } static ComPtr createSRV_NV12(ID3D11Device *dev, ID3D11Texture2D *tex, bool uv) @@ -296,8 +298,8 @@ float4 main(float4 pos:SV_Position, float2 uv:TEXCOORD0) : SV_Target } )"; -// YUY2(4:2:2 packed): -// 我們把每兩個像素打包成一個 RGBA8_UINT texel: +// YUY2??:2:2 packed??? +// ?????????????????????RGBA8_UINT texel?? // R=Y0, G=U, B=Y1, A=V // texture width = ceil(w/2) static const char *g_ps_yuy2 = R"( @@ -406,10 +408,10 @@ float4 main(float4 pos:SV_Position, float2 uv:TEXCOORD0) : SV_Target } )"; -// NV12 → RGBA 的 Compute Shader 版本 +// NV12 ??RGBA ??Compute Shader ??? -// Y210(4:2:2 packed, 10-bit in 16-bit container): -// 每個 texel 打包 2 個像素:R=Y0, G=U, B=Y1, A=V +// Y210??:2:2 packed, 10-bit in 16-bit container??? +// ????texel ??? 2 ??????R=Y0, G=U, B=Y1, A=V // texture width = ceil(w/2), format = R16G16B16A16_UINT static const char *g_ps_y210 = R"( Texture2D texP : register(t0); @@ -714,14 +716,14 @@ void SharedScenePipeline::shutdown() d2d_ctx_ = nullptr; } -bool SharedScenePipeline::configurePreview(const gcap_preview_desc_t &desc) +bool SharedScenePipeline::configurePreview(const gvfg_render_preview_desc_t &desc) { int requestedMode = desc.swapchain_10bit; - if (requestedMode != GCAP_PREVIEW_BITDEPTH_8BIT && - requestedMode != GCAP_PREVIEW_BITDEPTH_10BIT && - requestedMode != GCAP_PREVIEW_BITDEPTH_AUTO) + if (requestedMode != GVFG_RENDER_PREVIEW_BITDEPTH_8BIT && + requestedMode != GVFG_RENDER_PREVIEW_BITDEPTH_10BIT && + requestedMode != GVFG_RENDER_PREVIEW_BITDEPTH_AUTO) { - requestedMode = GCAP_PREVIEW_BITDEPTH_AUTO; + requestedMode = GVFG_RENDER_PREVIEW_BITDEPTH_AUTO; } const bool modeChanged = (preview_swapchain_mode_ != requestedMode); @@ -744,11 +746,11 @@ void SharedScenePipeline::set_source_bit_depth(int bits) if (bits != 8 && bits != 10 && bits != 12 && bits != 16) bits = 0; - const int oldEffectiveMode = (preview_swapchain_mode_ == GCAP_PREVIEW_BITDEPTH_AUTO) - ? ((preview_source_bit_depth_ >= 10) ? GCAP_PREVIEW_BITDEPTH_10BIT : GCAP_PREVIEW_BITDEPTH_8BIT) + const int oldEffectiveMode = (preview_swapchain_mode_ == GVFG_RENDER_PREVIEW_BITDEPTH_AUTO) + ? ((preview_source_bit_depth_ >= 10) ? GVFG_RENDER_PREVIEW_BITDEPTH_10BIT : GVFG_RENDER_PREVIEW_BITDEPTH_8BIT) : preview_swapchain_mode_; - const int newEffectiveMode = (preview_swapchain_mode_ == GCAP_PREVIEW_BITDEPTH_AUTO) - ? ((bits >= 10) ? GCAP_PREVIEW_BITDEPTH_10BIT : GCAP_PREVIEW_BITDEPTH_8BIT) + const int newEffectiveMode = (preview_swapchain_mode_ == GVFG_RENDER_PREVIEW_BITDEPTH_AUTO) + ? ((bits >= 10) ? GVFG_RENDER_PREVIEW_BITDEPTH_10BIT : GVFG_RENDER_PREVIEW_BITDEPTH_8BIT) : preview_swapchain_mode_; preview_source_bit_depth_ = bits; @@ -930,7 +932,7 @@ bool SharedScenePipeline::ensure_rt_and_pipeline(int w, int h) if (FAILED(d3d_->CreateShaderResourceView(rt_fp16_.Get(), nullptr, &srv_fp16_))) return false; - // rt 尺寸/格式若重建,compute path 的 UAV 也要跟著重建 + // rt ???/?????????compute path ??UAV ????????? rt_uav_.Reset(); // 2) Composited FP16 scene target (base FP16 + overlay) @@ -1539,14 +1541,14 @@ bool SharedScenePipeline::upload_v210_frame(const uint8_t *data, int src_stride, return true; } -bool SharedScenePipeline::render_uploaded_yuv_to_fp16(gcap_pixfmt_t fmt, int frame_w, int frame_h) +bool SharedScenePipeline::render_uploaded_yuv_to_fp16(gvfg_render_pixfmt_t fmt, int frame_w, int frame_h) { if (!ctx_ || !vs_ || !il_ || !vb_ || !rtv_fp16_ || !rt_fp16_ || frame_w <= 0 || frame_h <= 0) return false; ID3D11PixelShader *ps = nullptr; ComPtr srv0, srv1; - if (fmt == GCAP_FMT_NV12) + if (fmt == GVFG_RENDER_FMT_NV12) { if (!upload_nv12_) return false; @@ -1556,7 +1558,7 @@ bool SharedScenePipeline::render_uploaded_yuv_to_fp16(gcap_pixfmt_t fmt, int fra if (!srv0 || !srv1 || !ps) return false; } - else if (fmt == GCAP_FMT_P010) + else if (fmt == GVFG_RENDER_FMT_P010) { if (!upload_nv12_) return false; @@ -1566,7 +1568,7 @@ bool SharedScenePipeline::render_uploaded_yuv_to_fp16(gcap_pixfmt_t fmt, int fra if (!srv0 || !srv1 || !ps) return false; } - else if (fmt == GCAP_FMT_YUY2) + else if (fmt == GVFG_RENDER_FMT_YUY2) { if (!upload_yuy2_packed_) return false; @@ -1580,7 +1582,7 @@ bool SharedScenePipeline::render_uploaded_yuv_to_fp16(gcap_pixfmt_t fmt, int fra if (!ps) return false; } - else if (fmt == GCAP_FMT_Y210) + else if (fmt == GVFG_RENDER_FMT_Y210) { if (!upload_y210_packed_) return false; @@ -1659,7 +1661,7 @@ bool SharedScenePipeline::render_uploaded_yuv_to_fp16(gcap_pixfmt_t fmt, int fra const float clear[4] = {0, 0, 0, 1}; ctx_->ClearRenderTargetView(rtv_fp16_.Get(), clear); - if (fmt == GCAP_FMT_NV12 || fmt == GCAP_FMT_P010) + if (fmt == GVFG_RENDER_FMT_NV12 || fmt == GVFG_RENDER_FMT_P010) { ID3D11ShaderResourceView *srvs[2] = {srv0.Get(), srv1.Get()}; ctx_->PSSetShaderResources(0, 2, srvs); @@ -1676,7 +1678,7 @@ bool SharedScenePipeline::render_uploaded_yuv_to_fp16(gcap_pixfmt_t fmt, int fra ctx_->PSSetSamplers(0, 1, &ss); ctx_->Draw(6, 0); - if (fmt == GCAP_FMT_NV12 || fmt == GCAP_FMT_P010) + if (fmt == GVFG_RENDER_FMT_NV12 || fmt == GVFG_RENDER_FMT_P010) { ID3D11ShaderResourceView *nulls[2] = {nullptr, nullptr}; ctx_->PSSetShaderResources(0, 2, nulls); @@ -1728,7 +1730,7 @@ namespace if (path.empty() || !format || !*format || !payload || payloadBytes == 0) return false; - char header[GCAP_GIGABYTE_RAW_HEADER_SIZE] = {}; + char header[GVFG_RENDER_GIGABYTE_RAW_HEADER_SIZE] = {}; std::snprintf(header, sizeof(header), "GIGABYTE_RAW\n" "header_size=%d\n" @@ -1736,7 +1738,7 @@ namespace "Height=%d\n" "Format=%s\n" "SourceBitDepth=%d\n", - GCAP_GIGABYTE_RAW_HEADER_SIZE, + GVFG_RENDER_GIGABYTE_RAW_HEADER_SIZE, w, h, format, @@ -2075,7 +2077,7 @@ bool SharedScenePipeline::copy_fp16_to_scene() } bool SharedScenePipeline::readback_to_frame(int frame_w, int frame_h, uint64_t pts_ns, uint64_t frame_id, - gcap_frame_t *out) + gvfg_render_frame_t *out) { if (!out || !ctx_ || !rt_stage_ || !rt_rgba_) return false; @@ -2091,7 +2093,7 @@ bool SharedScenePipeline::readback_to_frame(int frame_w, int frame_h, uint64_t p out->plane_count = 1; out->width = frame_w; out->height = frame_h; - out->format = GCAP_FMT_ARGB; + out->format = GVFG_RENDER_FMT_ARGB; out->pts_ns = pts_ns; out->frame_id = frame_id; return true; @@ -2158,11 +2160,11 @@ bool SharedScenePipeline::export_scene_rgb10(const wchar_t *base_path, int raw_f } ctx_->Unmap(rt_scene_stage_fp16_.Get(), 0); - const bool exportNativeRaw = (raw_flags & GCAP_EXPORT_RAW_NATIVE) != 0; - const bool exportRgb10Raw = (raw_flags & GCAP_EXPORT_RAW_RGB10_U16) != 0; - const bool exportRgba16Raw = (raw_flags & GCAP_EXPORT_RAW_RGBA16) != 0; - const bool exportRgba8Raw = (raw_flags & GCAP_EXPORT_RAW_RGBA8) != 0; - const bool exportFp16Raw = sourceIs10Bit && (raw_flags & GCAP_EXPORT_RAW_ALL) == GCAP_EXPORT_RAW_ALL; + const bool exportNativeRaw = (raw_flags & GVFG_RENDER_EXPORT_RAW_NATIVE) != 0; + const bool exportRgb10Raw = (raw_flags & GVFG_RENDER_EXPORT_RAW_RGB10_U16) != 0; + const bool exportRgba16Raw = (raw_flags & GVFG_RENDER_EXPORT_RAW_RGBA16) != 0; + const bool exportRgba8Raw = (raw_flags & GVFG_RENDER_EXPORT_RAW_RGBA8) != 0; + const bool exportFp16Raw = sourceIs10Bit && (raw_flags & GVFG_RENDER_EXPORT_RAW_ALL) == GVFG_RENDER_EXPORT_RAW_ALL; const std::wstring base(base_path); bool ok = true; if (raw_flags != 0) @@ -2262,10 +2264,10 @@ bool SharedScenePipeline::ensure_preview_swapchain(int w, int h) !factory) return false; - const int effectiveMode = (preview_swapchain_mode_ == GCAP_PREVIEW_BITDEPTH_AUTO) - ? ((preview_source_bit_depth_ >= 10) ? GCAP_PREVIEW_BITDEPTH_10BIT : GCAP_PREVIEW_BITDEPTH_8BIT) + const int effectiveMode = (preview_swapchain_mode_ == GVFG_RENDER_PREVIEW_BITDEPTH_AUTO) + ? ((preview_source_bit_depth_ >= 10) ? GVFG_RENDER_PREVIEW_BITDEPTH_10BIT : GVFG_RENDER_PREVIEW_BITDEPTH_8BIT) : preview_swapchain_mode_; - const DXGI_FORMAT desiredFormat = (effectiveMode == GCAP_PREVIEW_BITDEPTH_8BIT) + const DXGI_FORMAT desiredFormat = (effectiveMode == GVFG_RENDER_PREVIEW_BITDEPTH_8BIT) ? DXGI_FORMAT_B8G8R8A8_UNORM : DXGI_FORMAT_R10G10B10A2_UNORM; @@ -2517,3 +2519,4 @@ DXGI_FORMAT SharedScenePipeline::linear_fp16_texture_format() const rt_fp16_->GetDesc(&d); return d.Format; } + diff --git a/sdk/gcapture/src/pipeline/shared_scene_pipeline.h b/sdk/gvfg/src/render/shared_scene_pipeline.h similarity index 94% rename from sdk/gcapture/src/pipeline/shared_scene_pipeline.h rename to sdk/gvfg/src/render/shared_scene_pipeline.h index 9dc84c7..7a19153 100644 --- a/sdk/gcapture/src/pipeline/shared_scene_pipeline.h +++ b/sdk/gvfg/src/render/shared_scene_pipeline.h @@ -1,6 +1,6 @@ #pragma once -#include "gcapture.h" +#include "../internal/gvfg_render_types.h" #include #include @@ -8,6 +8,9 @@ #include #include +namespace gvfg::internal +{ + class SharedScenePipeline { public: @@ -22,7 +25,7 @@ public: ID2D1SolidColorBrush *black = nullptr); void shutdown(); - bool configurePreview(const gcap_preview_desc_t &desc); + bool configurePreview(const gvfg_render_preview_desc_t &desc); void set_source_bit_depth(int bits); int source_bit_depth() const { return preview_source_bit_depth_; } void release_preview_swapchain(); @@ -51,10 +54,10 @@ public: bool upload_yuy2_frame(const uint8_t *data, int src_stride, int frame_w, int frame_h); bool upload_y210_frame(const uint8_t *data, int src_stride, int frame_w, int frame_h); bool upload_v210_frame(const uint8_t *data, int src_stride, int frame_w, int frame_h); - bool render_uploaded_yuv_to_fp16(gcap_pixfmt_t fmt, int frame_w, int frame_h); + bool render_uploaded_yuv_to_fp16(gvfg_render_pixfmt_t fmt, int frame_w, int frame_h); bool copy_fp16_to_scene(); bool readback_to_frame(int frame_w, int frame_h, uint64_t pts_ns, uint64_t frame_id, - gcap_frame_t *out); + gvfg_render_frame_t *out); bool export_scene_rgb10(const wchar_t *base_path, int raw_flags, bool export_tiff, bool export_stats, bool export_gigabyte_raw); ID3D11Device *d3d_ = nullptr; @@ -107,7 +110,7 @@ public: void *preview_hwnd_ = nullptr; bool preview_enabled_ = false; bool preview_use_fp16_ = false; - int preview_swapchain_mode_ = GCAP_PREVIEW_BITDEPTH_10BIT; + int preview_swapchain_mode_ = GVFG_RENDER_PREVIEW_BITDEPTH_10BIT; int preview_source_bit_depth_ = 0; bool preview_swapchain_10bit_ = false; DXGI_FORMAT preview_swapchain_format_ = DXGI_FORMAT_UNKNOWN; @@ -127,3 +130,7 @@ public: Microsoft::WRL::ComPtr preview_backbuf_; Microsoft::WRL::ComPtr preview_rtv_; }; + + +} +