Implement kms vaapi capture
This commit is contained in:
18
include/capture/kms_vaapi.h
Normal file
18
include/capture/kms_vaapi.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#ifndef GSR_CAPTURE_KMS_VAAPI_H
|
||||
#define GSR_CAPTURE_KMS_VAAPI_H
|
||||
|
||||
#include "capture.h"
|
||||
#include "../vec2.h"
|
||||
#include <X11/X.h>
|
||||
|
||||
typedef struct _XDisplay Display;
|
||||
|
||||
typedef struct {
|
||||
Display *dpy;
|
||||
const char *display_to_capture; /* if this is "screen", then the entire x11 screen is captured (all displays). A copy is made of this */
|
||||
const char *program_dir; /* ref */
|
||||
} gsr_capture_kms_vaapi_params;
|
||||
|
||||
gsr_capture* gsr_capture_kms_vaapi_create(const gsr_capture_kms_vaapi_params *params);
|
||||
|
||||
#endif /* GSR_CAPTURE_KMS_VAAPI_H */
|
||||
21
include/kms/kms_client.h
Normal file
21
include/kms/kms_client.h
Normal file
@@ -0,0 +1,21 @@
|
||||
#ifndef GSR_KMS_CLIENT_H
|
||||
#define GSR_KMS_CLIENT_H
|
||||
|
||||
#include "kms_shared.h"
|
||||
#include <sys/types.h>
|
||||
|
||||
typedef struct {
|
||||
pid_t kms_server_pid;
|
||||
int socket_fd;
|
||||
int client_fd;
|
||||
char socket_path[27];
|
||||
char *card_path;
|
||||
} gsr_kms_client;
|
||||
|
||||
/* |card_path| should be a path to card, for example /dev/dri/card0 */
|
||||
int gsr_kms_client_init(gsr_kms_client *self, const char *card_path, const char *program_dir);
|
||||
void gsr_kms_client_deinit(gsr_kms_client *self);
|
||||
|
||||
int gsr_kms_client_get_kms(gsr_kms_client *self, gsr_kms_response *response);
|
||||
|
||||
#endif /* #define GSR_KMS_CLIENT_H */
|
||||
45
include/kms/kms_shared.h
Normal file
45
include/kms/kms_shared.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef GSR_KMS_SHARED_H
|
||||
#define GSR_KMS_SHARED_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef enum {
|
||||
KMS_REQUEST_TYPE_GET_KMS
|
||||
} gsr_kms_request_type;
|
||||
|
||||
typedef enum {
|
||||
KMS_RESULT_OK,
|
||||
KMS_RESULT_INVALID_REQUEST,
|
||||
KMS_RESULT_FAILED_TO_OPEN_CARD,
|
||||
KMS_RESULT_INSUFFICIENT_PERMISSIONS,
|
||||
KMS_RESULT_FAILED_TO_GET_KMS,
|
||||
KMS_RESULT_NO_KMS_AVAILABLE,
|
||||
KMS_RESULT_FAILED_TO_SEND
|
||||
} gsr_kms_result;
|
||||
|
||||
typedef struct {
|
||||
int type; /* gsr_kms_request_type */
|
||||
union {
|
||||
char card_path[255];
|
||||
} data;
|
||||
} gsr_kms_request;
|
||||
|
||||
typedef struct {
|
||||
int fd;
|
||||
uint32_t width;
|
||||
uint32_t height;
|
||||
uint32_t pitch;
|
||||
uint32_t offset;
|
||||
uint32_t pixel_format;
|
||||
uint64_t modifier;
|
||||
} gsr_kms_response_fd;
|
||||
|
||||
typedef struct {
|
||||
int result; /* gsr_kms_result */
|
||||
union {
|
||||
char err_msg[128];
|
||||
gsr_kms_response_fd fd;
|
||||
} data;
|
||||
} gsr_kms_response;
|
||||
|
||||
#endif /* #define GSR_KMS_SHARED_H */
|
||||
@@ -1,42 +1,17 @@
|
||||
#ifndef GSR_LIBRARY_LOADER_H
|
||||
#define GSR_LIBRARY_LOADER_H
|
||||
|
||||
#include <dlfcn.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
|
||||
typedef struct {
|
||||
void **func;
|
||||
const char *name;
|
||||
} dlsym_assign;
|
||||
|
||||
static void* dlsym_print_fail(void *handle, const char *name, bool required) {
|
||||
dlerror();
|
||||
void *sym = dlsym(handle, name);
|
||||
char *err_str = dlerror();
|
||||
|
||||
if(!sym)
|
||||
fprintf(stderr, "%s: dlsym(handle, \"%s\") failed, error: %s\n", required ? "error" : "warning", name, err_str ? err_str : "(null)");
|
||||
|
||||
return sym;
|
||||
}
|
||||
|
||||
void* dlsym_print_fail(void *handle, const char *name, bool required);
|
||||
/* |dlsyms| should be null terminated */
|
||||
static bool dlsym_load_list(void *handle, const dlsym_assign *dlsyms) {
|
||||
bool success = true;
|
||||
for(int i = 0; dlsyms[i].func; ++i) {
|
||||
*dlsyms[i].func = dlsym_print_fail(handle, dlsyms[i].name, true);
|
||||
if(!*dlsyms[i].func)
|
||||
success = false;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
bool dlsym_load_list(void *handle, const dlsym_assign *dlsyms);
|
||||
/* |dlsyms| should be null terminated */
|
||||
static void dlsym_load_list_optional(void *handle, const dlsym_assign *dlsyms) {
|
||||
for(int i = 0; dlsyms[i].func; ++i) {
|
||||
*dlsyms[i].func = dlsym_print_fail(handle, dlsyms[i].name, false);
|
||||
}
|
||||
}
|
||||
void dlsym_load_list_optional(void *handle, const dlsym_assign *dlsyms);
|
||||
|
||||
#endif /* GSR_LIBRARY_LOADER_H */
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
#ifndef GSR_TIME_H
|
||||
#define GSR_TIME_H
|
||||
|
||||
double clock_get_monotonic_seconds();
|
||||
|
||||
#endif /* GSR_TIME_H */
|
||||
26
include/utils.h
Normal file
26
include/utils.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef GSR_UTILS_H
|
||||
#define GSR_UTILS_H
|
||||
|
||||
#include "vec2.h"
|
||||
#include <stdbool.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
|
||||
typedef struct {
|
||||
vec2i pos;
|
||||
vec2i size;
|
||||
} gsr_monitor;
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
int name_len;
|
||||
gsr_monitor *monitor;
|
||||
bool found_monitor;
|
||||
} get_monitor_by_name_userdata;
|
||||
|
||||
double clock_get_monotonic_seconds(void);
|
||||
|
||||
typedef void (*active_monitor_callback)(const XRROutputInfo *output_info, const XRRCrtcInfo *crt_info, const XRRModeInfo *mode_info, void *userdata);
|
||||
void for_each_active_monitor_output(Display *display, active_monitor_callback callback, void *userdata);
|
||||
bool get_monitor_by_name(Display *display, const char *name, gsr_monitor *monitor);
|
||||
|
||||
#endif /* GSR_UTILS_H */
|
||||
Reference in New Issue
Block a user