Add support for camera (yuyv, mjpeg) and multiple capture sources

This commit is contained in:
dec05eba
2025-12-23 18:05:48 +01:00
parent 390f2708f4
commit 62e180903e
30 changed files with 2228 additions and 632 deletions

View File

@@ -12,24 +12,34 @@ typedef struct AVFrame AVFrame;
typedef struct AVMasteringDisplayMetadata AVMasteringDisplayMetadata;
typedef struct AVContentLightMetadata AVContentLightMetadata;
typedef struct gsr_capture gsr_capture;
typedef struct gsr_capture_metadata gsr_capture_metadata;
typedef struct {
// Width and height of the video
int video_width;
int video_height;
// Width and height of the frame at the start of capture, the target size
int recording_width;
int recording_height;
typedef enum {
GSR_CAPTURE_ALIGN_START,
GSR_CAPTURE_ALIGN_CENTER,
GSR_CAPTURE_ALIGN_END
} gsr_capture_alignment;
struct gsr_capture_metadata {
// Size of the video
vec2i video_size;
// The captured output gets scaled to this size. By default this will be the same size as the captured target
vec2i recording_size;
vec2i position;
int fps;
} gsr_capture_metadata;
gsr_capture_alignment halign;
gsr_capture_alignment valign;
gsr_flip flip;
};
struct gsr_capture {
/* These methods should not be called manually. Call gsr_capture_* instead. |capture_metadata->video_width| and |capture_metadata->video_height| should be set by this function */
/* These methods should not be called manually. Call gsr_capture_* instead. |capture_metadata->video_size| should be set by this function */
int (*start)(gsr_capture *cap, gsr_capture_metadata *capture_metadata);
void (*on_event)(gsr_capture *cap, gsr_egl *egl); /* can be NULL */
void (*tick)(gsr_capture *cap); /* can be NULL. If there is an event then |on_event| is called before this */
bool (*should_stop)(gsr_capture *cap, bool *err); /* can be NULL. If NULL, return false */
bool (*capture_has_synchronous_task)(gsr_capture *cap); /* can be NULL. If this returns true then the time spent in |capture| is ignored for video/audio (capture is paused while the synchronous task happens) */
void (*pre_capture)(gsr_capture *cap, gsr_capture_metadata *capture_metadata, gsr_color_conversion *color_conversion); /* can be NULL */
int (*capture)(gsr_capture *cap, gsr_capture_metadata *capture_metadata, gsr_color_conversion *color_conversion); /* Return 0 if the frame was captured */
bool (*uses_external_image)(gsr_capture *cap); /* can be NULL. If NULL, return false */
bool (*set_hdr_metadata)(gsr_capture *cap, AVMasteringDisplayMetadata *mastering_display_metadata, AVContentLightMetadata *light_metadata); /* can be NULL. If NULL, return false */

View File

@@ -2,9 +2,13 @@
#define GSR_CAPTURE_KMS_H
#include "capture.h"
#include "../cursor.h"
#include "../../kms/kms_shared.h"
typedef struct {
gsr_egl *egl;
gsr_cursor *x11_cursor;
gsr_kms_response *kms_response;
const char *display_to_capture; /* A copy is made of this */
bool hdr;
bool record_cursor;

30
include/capture/v4l2.h Normal file
View File

@@ -0,0 +1,30 @@
#ifndef GSR_CAPTURE_V4L2_H
#define GSR_CAPTURE_V4L2_H
#include "capture.h"
typedef enum {
GSR_CAPTURE_V4L2_PIXFMT_AUTO,
GSR_CAPTURE_V4L2_PIXFMT_YUYV,
GSR_CAPTURE_V4L2_PIXFMT_MJPEG
} gsr_capture_v4l2_pixfmt;
typedef struct {
bool yuyv;
bool mjpeg;
} gsr_capture_v4l2_supported_pixfmts;
typedef struct {
gsr_egl *egl;
vec2i output_resolution;
const char *device_path;
gsr_capture_v4l2_pixfmt pixfmt;
int fps;
} gsr_capture_v4l2_params;
gsr_capture* gsr_capture_v4l2_create(const gsr_capture_v4l2_params *params);
typedef void (*v4l2_devices_query_callback)(const char *path, gsr_capture_v4l2_supported_pixfmts supported_pixfmts, vec2i size, void *userdata);
void gsr_capture_v4l2_list_devices(v4l2_devices_query_callback callback, void *userdata);
#endif /* GSR_CAPTURE_V4L2_H */

View File

@@ -3,9 +3,11 @@
#include "capture.h"
#include "../vec2.h"
#include "../cursor.h"
typedef struct {
gsr_egl *egl;
gsr_cursor *cursor;
unsigned long window;
bool follow_focused; /* If this is set then |window| is ignored */
bool record_cursor;

View File

@@ -3,9 +3,11 @@
#include "capture.h"
#include "../vec2.h"
#include "../cursor.h"
typedef struct {
gsr_egl *egl;
gsr_cursor *cursor;
const char *display_to_capture; /* A copy is made of this */
bool record_cursor;
vec2i output_resolution;