2020-01-24 23:31:01 +01:00
|
|
|
#ifndef SCREENCAST_COMMON_H
|
|
|
|
#define SCREENCAST_COMMON_H
|
|
|
|
|
|
|
|
#include <pipewire/pipewire.h>
|
|
|
|
#include <spa/param/video/format-utils.h>
|
|
|
|
#include <wayland-client-protocol.h>
|
|
|
|
|
2020-12-23 19:47:10 +01:00
|
|
|
#include "fps_limit.h"
|
|
|
|
|
2020-04-16 10:21:55 +02:00
|
|
|
// this seems to be right based on
|
|
|
|
// https://github.com/flatpak/xdg-desktop-portal/blob/309a1fc0cf2fb32cceb91dbc666d20cf0a3202c2/src/screen-cast.c#L955
|
|
|
|
#define XDP_CAST_PROTO_VER 2
|
|
|
|
|
|
|
|
enum cursor_modes {
|
|
|
|
HIDDEN = 1,
|
|
|
|
EMBEDDED = 2,
|
|
|
|
METADATA = 4,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum source_types {
|
|
|
|
MONITOR = 1,
|
|
|
|
WINDOW = 2,
|
|
|
|
};
|
|
|
|
|
2020-10-10 16:20:06 +02:00
|
|
|
enum xdpw_chooser_types {
|
|
|
|
XDPW_CHOOSER_DEFAULT,
|
|
|
|
XDPW_CHOOSER_NONE,
|
|
|
|
XDPW_CHOOSER_SIMPLE,
|
|
|
|
XDPW_CHOOSER_DMENU,
|
|
|
|
};
|
|
|
|
|
2021-08-18 22:33:27 +02:00
|
|
|
enum xdpw_frame_state {
|
|
|
|
XDPW_FRAME_STATE_NONE,
|
|
|
|
XDPW_FRAME_STATE_RENEG,
|
|
|
|
XDPW_FRAME_STATE_FAILED,
|
|
|
|
XDPW_FRAME_STATE_SUCCESS,
|
|
|
|
};
|
|
|
|
|
2020-10-10 16:20:06 +02:00
|
|
|
struct xdpw_output_chooser {
|
|
|
|
enum xdpw_chooser_types type;
|
|
|
|
char *cmd;
|
|
|
|
};
|
|
|
|
|
2020-04-16 10:21:55 +02:00
|
|
|
struct xdpw_frame_damage {
|
2020-01-24 23:31:01 +01:00
|
|
|
uint32_t x;
|
|
|
|
uint32_t y;
|
|
|
|
uint32_t width;
|
|
|
|
uint32_t height;
|
|
|
|
};
|
|
|
|
|
2020-04-16 10:21:55 +02:00
|
|
|
struct xdpw_frame {
|
2021-06-16 02:38:44 +02:00
|
|
|
uint32_t size;
|
|
|
|
uint32_t stride;
|
|
|
|
bool y_invert;
|
|
|
|
uint64_t tv_sec;
|
|
|
|
uint32_t tv_nsec;
|
|
|
|
struct xdpw_frame_damage damage;
|
|
|
|
struct wl_buffer *buffer;
|
|
|
|
struct pw_buffer *current_pw_buffer;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct xdpw_screencopy_frame {
|
2020-01-24 23:31:01 +01:00
|
|
|
uint32_t width;
|
|
|
|
uint32_t height;
|
|
|
|
uint32_t size;
|
|
|
|
uint32_t stride;
|
|
|
|
enum wl_shm_format format;
|
|
|
|
};
|
|
|
|
|
2020-04-16 10:21:55 +02:00
|
|
|
struct xdpw_screencast_context {
|
|
|
|
|
|
|
|
// xdpw
|
|
|
|
struct xdpw_state *state;
|
|
|
|
|
2020-01-24 23:31:01 +01:00
|
|
|
// pipewire
|
2020-03-13 23:19:19 +01:00
|
|
|
struct pw_context *pwr_context;
|
2020-01-24 23:31:01 +01:00
|
|
|
struct pw_core *core;
|
|
|
|
|
|
|
|
// wlroots
|
|
|
|
struct wl_list output_list;
|
|
|
|
struct wl_registry *registry;
|
|
|
|
struct zwlr_screencopy_manager_v1 *screencopy_manager;
|
2020-12-23 19:47:10 +01:00
|
|
|
struct zxdg_output_manager_v1 *xdg_output_manager;
|
2020-01-24 23:31:01 +01:00
|
|
|
struct wl_shm *shm;
|
|
|
|
|
2020-04-16 10:21:55 +02:00
|
|
|
// sessions
|
|
|
|
struct wl_list screencast_instances;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct xdpw_screencast_instance {
|
|
|
|
// list
|
|
|
|
struct wl_list link;
|
|
|
|
|
|
|
|
// xdpw
|
|
|
|
uint32_t refcount;
|
|
|
|
struct xdpw_screencast_context *ctx;
|
|
|
|
bool initialized;
|
2021-06-16 02:38:44 +02:00
|
|
|
struct xdpw_frame current_frame;
|
2021-08-18 22:33:27 +02:00
|
|
|
enum xdpw_frame_state frame_state;
|
2020-04-16 10:21:55 +02:00
|
|
|
|
|
|
|
// pipewire
|
|
|
|
struct pw_stream *stream;
|
|
|
|
struct spa_hook stream_listener;
|
|
|
|
struct spa_video_info_raw pwr_format;
|
|
|
|
uint32_t seq;
|
|
|
|
uint32_t node_id;
|
|
|
|
bool pwr_stream_state;
|
2021-06-13 20:33:34 +02:00
|
|
|
uint32_t framerate;
|
2020-04-16 10:21:55 +02:00
|
|
|
|
|
|
|
// wlroots
|
|
|
|
struct zwlr_screencopy_frame_v1 *frame_callback;
|
|
|
|
struct xdpw_wlr_output *target_output;
|
2021-06-13 19:04:19 +02:00
|
|
|
uint32_t max_framerate;
|
2020-04-16 10:21:55 +02:00
|
|
|
struct zwlr_screencopy_frame_v1 *wlr_frame;
|
2021-06-16 02:38:44 +02:00
|
|
|
struct xdpw_screencopy_frame screencopy_frame;
|
2020-04-16 10:21:55 +02:00
|
|
|
bool with_cursor;
|
2020-01-24 23:31:01 +01:00
|
|
|
int err;
|
|
|
|
bool quit;
|
2020-12-23 19:47:10 +01:00
|
|
|
|
|
|
|
// fps limit
|
|
|
|
struct fps_limit_state fps_limit;
|
2020-01-24 23:31:01 +01:00
|
|
|
};
|
|
|
|
|
2020-04-16 10:21:55 +02:00
|
|
|
struct xdpw_wlr_output {
|
2020-01-24 23:31:01 +01:00
|
|
|
struct wl_list link;
|
|
|
|
uint32_t id;
|
|
|
|
struct wl_output *output;
|
2020-02-19 22:55:51 +01:00
|
|
|
struct zxdg_output_v1 *xdg_output;
|
2020-01-24 23:31:01 +01:00
|
|
|
char *make;
|
|
|
|
char *model;
|
2020-02-19 22:55:51 +01:00
|
|
|
char *name;
|
2020-01-24 23:31:01 +01:00
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
float framerate;
|
|
|
|
};
|
|
|
|
|
2020-04-16 10:21:55 +02:00
|
|
|
void randname(char *buf);
|
2020-10-26 16:22:08 +01:00
|
|
|
int anonymous_shm_open(void);
|
2021-05-27 20:45:19 +02:00
|
|
|
struct wl_buffer *import_wl_shm_buffer(struct xdpw_screencast_instance *cast, int fd,
|
|
|
|
enum wl_shm_format fmt, int width, int height, int stride);
|
2021-06-15 18:04:33 +02:00
|
|
|
enum spa_video_format xdpw_format_pw_from_wl_shm(enum wl_shm_format format);
|
2020-05-03 16:33:45 +02:00
|
|
|
enum spa_video_format xdpw_format_pw_strip_alpha(enum spa_video_format format);
|
2020-01-24 23:31:01 +01:00
|
|
|
|
2020-10-10 16:20:06 +02:00
|
|
|
enum xdpw_chooser_types get_chooser_type(const char *chooser_type);
|
|
|
|
const char *chooser_type_str(enum xdpw_chooser_types chooser_type);
|
2020-01-24 23:31:01 +01:00
|
|
|
#endif /* SCREENCAST_COMMON_H */
|