Initial standalone GVFG SDK
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user