screencast: rename xdpw_frame into xdpw_screencopy_frame

This commit is contained in:
columbarius 2021-06-16 02:38:44 +02:00
parent 566fb7c1a0
commit f77b751649
4 changed files with 66 additions and 50 deletions

View File

@ -42,6 +42,17 @@ struct xdpw_frame_damage {
}; };
struct xdpw_frame { struct xdpw_frame {
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 {
uint32_t width; uint32_t width;
uint32_t height; uint32_t height;
uint32_t size; uint32_t size;
@ -83,6 +94,7 @@ struct xdpw_screencast_instance {
uint32_t refcount; uint32_t refcount;
struct xdpw_screencast_context *ctx; struct xdpw_screencast_context *ctx;
bool initialized; bool initialized;
struct xdpw_frame current_frame;
// pipewire // pipewire
struct pw_stream *stream; struct pw_stream *stream;
@ -92,14 +104,13 @@ struct xdpw_screencast_instance {
uint32_t node_id; uint32_t node_id;
bool pwr_stream_state; bool pwr_stream_state;
uint32_t framerate; uint32_t framerate;
struct pw_buffer *current_pw_buffer;
// wlroots // wlroots
struct zwlr_screencopy_frame_v1 *frame_callback; struct zwlr_screencopy_frame_v1 *frame_callback;
struct xdpw_wlr_output *target_output; struct xdpw_wlr_output *target_output;
uint32_t max_framerate; uint32_t max_framerate;
struct zwlr_screencopy_frame_v1 *wlr_frame; struct zwlr_screencopy_frame_v1 *wlr_frame;
struct xdpw_frame simple_frame; struct xdpw_screencopy_frame screencopy_frame;
bool with_cursor; bool with_cursor;
int err; int err;
bool quit; bool quit;

View File

@ -100,8 +100,8 @@ static void pwr_handle_stream_param_changed(void *data, uint32_t id,
SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers, SPA_TYPE_OBJECT_ParamBuffers, SPA_PARAM_Buffers,
SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(XDPW_PWR_BUFFERS, 1, 32), SPA_PARAM_BUFFERS_buffers, SPA_POD_CHOICE_RANGE_Int(XDPW_PWR_BUFFERS, 1, 32),
SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1), SPA_PARAM_BUFFERS_blocks, SPA_POD_Int(1),
SPA_PARAM_BUFFERS_size, SPA_POD_Int(cast->simple_frame.size), SPA_PARAM_BUFFERS_size, SPA_POD_Int(cast->screencopy_frame.size),
SPA_PARAM_BUFFERS_stride, SPA_POD_Int(cast->simple_frame.stride), SPA_PARAM_BUFFERS_stride, SPA_POD_Int(cast->screencopy_frame.stride),
SPA_PARAM_BUFFERS_align, SPA_POD_Int(XDPW_PWR_ALIGN), SPA_PARAM_BUFFERS_align, SPA_POD_Int(XDPW_PWR_ALIGN),
SPA_PARAM_BUFFERS_dataType,SPA_POD_CHOICE_FLAGS_Int(1<<SPA_DATA_MemFd)); SPA_PARAM_BUFFERS_dataType,SPA_POD_CHOICE_FLAGS_Int(1<<SPA_DATA_MemFd));
@ -133,10 +133,10 @@ static void pwr_handle_stream_add_buffer(void *data, struct pw_buffer *buffer) {
logprint(TRACE, "pipewire: selected buffertype %u", d[0].type); logprint(TRACE, "pipewire: selected buffertype %u", d[0].type);
// Prepare buffer for choosen type // Prepare buffer for choosen type
if (d[0].type == SPA_DATA_MemFd) { if (d[0].type == SPA_DATA_MemFd) {
d[0].maxsize = cast->simple_frame.size; d[0].maxsize = cast->screencopy_frame.size;
d[0].mapoffset = 0; d[0].mapoffset = 0;
d[0].chunk->size = cast->simple_frame.size; d[0].chunk->size = cast->screencopy_frame.size;
d[0].chunk->stride = cast->simple_frame.stride; d[0].chunk->stride = cast->screencopy_frame.stride;
d[0].chunk->offset = 0; d[0].chunk->offset = 0;
d[0].flags = 0; d[0].flags = 0;
d[0].fd = anonymous_shm_open(); d[0].fd = anonymous_shm_open();
@ -190,17 +190,22 @@ static const struct pw_stream_events pwr_stream_events = {
void xdpw_pwr_dequeue_buffer(struct xdpw_screencast_instance *cast) { void xdpw_pwr_dequeue_buffer(struct xdpw_screencast_instance *cast) {
logprint(TRACE, "pipewire: dequeueing buffer"); logprint(TRACE, "pipewire: dequeueing buffer");
assert(cast->current_pw_buffer == NULL); assert(cast->current_frame.current_pw_buffer == NULL);
if ((cast->current_pw_buffer = pw_stream_dequeue_buffer(cast->stream)) == NULL) { if ((cast->current_frame.current_pw_buffer = pw_stream_dequeue_buffer(cast->stream)) == NULL) {
logprint(WARN, "pipewire: out of buffers"); logprint(WARN, "pipewire: out of buffers");
return; return;
} }
struct spa_buffer *spa_buf = cast->current_frame.current_pw_buffer->buffer;
struct spa_data *d = spa_buf->datas;
cast->current_frame.size = d[0].chunk->size;
cast->current_frame.stride = d[0].chunk->stride;
} }
void xdpw_pwr_enqueue_buffer(struct xdpw_screencast_instance *cast) { void xdpw_pwr_enqueue_buffer(struct xdpw_screencast_instance *cast) {
logprint(TRACE, "pipewire: exporting buffer"); logprint(TRACE, "pipewire: exporting buffer");
struct pw_buffer *pw_buf = cast->current_pw_buffer; struct pw_buffer *pw_buf = cast->current_frame.current_pw_buffer;
if (!pw_buf) { if (!pw_buf) {
logprint(TRACE, "pipewire: no pipewire buffer to queue"); logprint(TRACE, "pipewire: no pipewire buffer to queue");
@ -221,22 +226,22 @@ void xdpw_pwr_enqueue_buffer(struct xdpw_screencast_instance *cast) {
goto queue; goto queue;
} }
writeFrameData(d[0].data, cast->simple_frame.data, cast->simple_frame.height, writeFrameData(d[0].data, cast->screencopy_frame.data, cast->screencopy_frame.height,
cast->simple_frame.stride, cast->simple_frame.y_invert); cast->screencopy_frame.stride, cast->screencopy_frame.y_invert);
logprint(TRACE, "********************"); logprint(TRACE, "********************");
logprint(TRACE, "pipewire: pointer %p", d[0].data); logprint(TRACE, "pipewire: pointer %p", d[0].data);
logprint(TRACE, "pipewire: size %d", d[0].maxsize); logprint(TRACE, "pipewire: size %d", d[0].maxsize);
logprint(TRACE, "pipewire: stride %d", d[0].chunk->stride); logprint(TRACE, "pipewire: stride %d", d[0].chunk->stride);
logprint(TRACE, "pipewire: width %d", cast->simple_frame.width); logprint(TRACE, "pipewire: width %d", cast->screencopy_frame.width);
logprint(TRACE, "pipewire: height %d", cast->simple_frame.height); logprint(TRACE, "pipewire: height %d", cast->screencopy_frame.height);
logprint(TRACE, "pipewire: y_invert %d", cast->simple_frame.y_invert); logprint(TRACE, "pipewire: y_invert %d", cast->screencopy_frame.y_invert);
logprint(TRACE, "********************"); logprint(TRACE, "********************");
queue: queue:
pw_stream_queue_buffer(cast->stream, pw_buf); pw_stream_queue_buffer(cast->stream, pw_buf);
cast->current_pw_buffer = NULL; cast->current_frame.current_pw_buffer = NULL;
} }
void pwr_update_stream_param(struct xdpw_screencast_instance *cast) { void pwr_update_stream_param(struct xdpw_screencast_instance *cast) {
@ -247,10 +252,10 @@ void pwr_update_stream_param(struct xdpw_screencast_instance *cast) {
SPA_POD_BUILDER_INIT(params_buffer, sizeof(params_buffer)); SPA_POD_BUILDER_INIT(params_buffer, sizeof(params_buffer));
const struct spa_pod *params[1]; const struct spa_pod *params[1];
enum spa_video_format format = xdpw_format_pw_from_wl_shm(cast->simple_frame.format); enum spa_video_format format = xdpw_format_pw_from_wl_shm(cast->screencopy_frame.format);
params[0] = build_format(&b, format, params[0] = build_format(&b, format,
cast->simple_frame.width, cast->simple_frame.height, cast->framerate); cast->screencopy_frame.width, cast->screencopy_frame.height, cast->framerate);
pw_stream_update_params(stream, params, 1); pw_stream_update_params(stream, params, 1);
} }
@ -277,10 +282,10 @@ void xdpw_pwr_stream_create(struct xdpw_screencast_instance *cast) {
} }
cast->pwr_stream_state = false; cast->pwr_stream_state = false;
enum spa_video_format format = xdpw_format_pw_from_wl_shm(cast->simple_frame.format); enum spa_video_format format = xdpw_format_pw_from_wl_shm(cast->screencopy_frame.format);
const struct spa_pod *param = build_format(&b, format, const struct spa_pod *param = build_format(&b, format,
cast->simple_frame.width, cast->simple_frame.height, cast->framerate); cast->screencopy_frame.width, cast->screencopy_frame.height, cast->framerate);
pw_stream_add_listener(cast->stream, &cast->stream_listener, pw_stream_add_listener(cast->stream, &cast->stream_listener,
&pwr_stream_events, cast); &pwr_stream_events, cast);

View File

@ -448,7 +448,7 @@ static int method_screencast_start(sd_bus_message *msg, void *data,
"streams", "a(ua{sv})", 1, "streams", "a(ua{sv})", 1,
cast->node_id, 2, cast->node_id, 2,
"position", "(ii)", 0, 0, "position", "(ii)", 0, 0,
"size", "(ii)", cast->simple_frame.width, cast->simple_frame.height); "size", "(ii)", cast->screencopy_frame.width, cast->screencopy_frame.height);
if (ret < 0) { if (ret < 0) {
return ret; return ret;

View File

@ -24,14 +24,14 @@ static void wlr_frame_buffer_destroy(struct xdpw_screencast_instance *cast) {
// Even though this check may be deemed unnecessary, // Even though this check may be deemed unnecessary,
// this has been found to cause SEGFAULTs, like this one: // this has been found to cause SEGFAULTs, like this one:
// https://github.com/emersion/xdg-desktop-portal-wlr/issues/50 // https://github.com/emersion/xdg-desktop-portal-wlr/issues/50
if (cast->simple_frame.data != NULL) { if (cast->screencopy_frame.data != NULL) {
munmap(cast->simple_frame.data, cast->simple_frame.size); munmap(cast->screencopy_frame.data, cast->screencopy_frame.size);
cast->simple_frame.data = NULL; cast->screencopy_frame.data = NULL;
} }
if (cast->simple_frame.buffer != NULL) { if (cast->screencopy_frame.buffer != NULL) {
wl_buffer_destroy(cast->simple_frame.buffer); wl_buffer_destroy(cast->screencopy_frame.buffer);
cast->simple_frame.buffer = NULL; cast->screencopy_frame.buffer = NULL;
} }
} }
@ -40,7 +40,7 @@ void xdpw_wlr_frame_free(struct xdpw_screencast_instance *cast) {
cast->wlr_frame = NULL; cast->wlr_frame = NULL;
if (cast->quit || cast->err) { if (cast->quit || cast->err) {
wlr_frame_buffer_destroy(cast); wlr_frame_buffer_destroy(cast);
logprint(TRACE, "xdpw: simple_frame buffer destroyed"); logprint(TRACE, "xdpw: screencopy_frame buffer destroyed");
} }
logprint(TRACE, "wlroots: frame destroyed"); logprint(TRACE, "wlroots: frame destroyed");
@ -102,11 +102,11 @@ static struct wl_buffer *create_shm_buffer(struct xdpw_screencast_instance *cast
static void wlr_frame_buffer_chparam(struct xdpw_screencast_instance *cast, static void wlr_frame_buffer_chparam(struct xdpw_screencast_instance *cast,
uint32_t format, uint32_t width, uint32_t height, uint32_t stride) { uint32_t format, uint32_t width, uint32_t height, uint32_t stride) {
logprint(DEBUG, "wlroots: reset buffer"); logprint(DEBUG, "wlroots: reset buffer");
cast->simple_frame.width = width; cast->screencopy_frame.width = width;
cast->simple_frame.height = height; cast->screencopy_frame.height = height;
cast->simple_frame.stride = stride; cast->screencopy_frame.stride = stride;
cast->simple_frame.size = stride * height; cast->screencopy_frame.size = stride * height;
cast->simple_frame.format = format; cast->screencopy_frame.format = format;
wlr_frame_buffer_destroy(cast); wlr_frame_buffer_destroy(cast);
if (cast->pwr_stream_state) { if (cast->pwr_stream_state) {
@ -129,13 +129,13 @@ static void wlr_frame_buffer_done(void *data,
if (!cast->quit && !cast->err && cast->pwr_stream_state) { if (!cast->quit && !cast->err && cast->pwr_stream_state) {
xdpw_pwr_dequeue_buffer(cast); xdpw_pwr_dequeue_buffer(cast);
if (!cast->current_pw_buffer) { if (!cast->current_frame.current_pw_buffer) {
xdpw_wlr_frame_free(cast); xdpw_wlr_frame_free(cast);
return; return;
} }
} }
zwlr_screencopy_frame_v1_copy_with_damage(frame, cast->simple_frame.buffer); zwlr_screencopy_frame_v1_copy_with_damage(frame, cast->screencopy_frame.buffer);
logprint(TRACE, "wlroots: frame copied"); logprint(TRACE, "wlroots: frame copied");
fps_limit_measure_start(&cast->fps_limit, cast->framerate); fps_limit_measure_start(&cast->fps_limit, cast->framerate);
@ -147,23 +147,23 @@ static void wlr_frame_buffer(void *data, struct zwlr_screencopy_frame_v1 *frame,
logprint(TRACE, "wlroots: buffer event handler"); logprint(TRACE, "wlroots: buffer event handler");
cast->wlr_frame = frame; cast->wlr_frame = frame;
if (cast->simple_frame.width != width || if (cast->screencopy_frame.width != width ||
cast->simple_frame.height != height || cast->screencopy_frame.height != height ||
cast->simple_frame.stride != stride || cast->screencopy_frame.stride != stride ||
cast->simple_frame.format != format) { cast->screencopy_frame.format != format) {
logprint(TRACE, "wlroots: buffer properties changed"); logprint(TRACE, "wlroots: buffer properties changed");
wlr_frame_buffer_chparam(cast, format, width, height, stride); wlr_frame_buffer_chparam(cast, format, width, height, stride);
} }
if (cast->simple_frame.buffer == NULL) { if (cast->screencopy_frame.buffer == NULL) {
logprint(DEBUG, "wlroots: create shm buffer"); logprint(DEBUG, "wlroots: create shm buffer");
cast->simple_frame.buffer = create_shm_buffer(cast, format, width, height, cast->screencopy_frame.buffer = create_shm_buffer(cast, format, width, height,
stride, &cast->simple_frame.data); stride, &cast->screencopy_frame.data);
} else { } else {
logprint(TRACE,"wlroots: shm buffer exists"); logprint(TRACE,"wlroots: shm buffer exists");
} }
if (cast->simple_frame.buffer == NULL) { if (cast->screencopy_frame.buffer == NULL) {
logprint(ERROR, "wlroots: failed to create buffer"); logprint(ERROR, "wlroots: failed to create buffer");
abort(); abort();
} }
@ -178,7 +178,7 @@ static void wlr_frame_flags(void *data, struct zwlr_screencopy_frame_v1 *frame,
struct xdpw_screencast_instance *cast = data; struct xdpw_screencast_instance *cast = data;
logprint(TRACE, "wlroots: flags event handler"); logprint(TRACE, "wlroots: flags event handler");
cast->simple_frame.y_invert = flags & ZWLR_SCREENCOPY_FRAME_V1_FLAGS_Y_INVERT; cast->screencopy_frame.y_invert = flags & ZWLR_SCREENCOPY_FRAME_V1_FLAGS_Y_INVERT;
} }
static void wlr_frame_ready(void *data, struct zwlr_screencopy_frame_v1 *frame, static void wlr_frame_ready(void *data, struct zwlr_screencopy_frame_v1 *frame,
@ -187,8 +187,8 @@ static void wlr_frame_ready(void *data, struct zwlr_screencopy_frame_v1 *frame,
logprint(TRACE, "wlroots: ready event handler"); logprint(TRACE, "wlroots: ready event handler");
cast->simple_frame.tv_sec = ((((uint64_t)tv_sec_hi) << 32) | tv_sec_lo); cast->screencopy_frame.tv_sec = ((((uint64_t)tv_sec_hi) << 32) | tv_sec_lo);
cast->simple_frame.tv_nsec = tv_nsec; cast->screencopy_frame.tv_nsec = tv_nsec;
xdpw_pwr_enqueue_buffer(cast); xdpw_pwr_enqueue_buffer(cast);
@ -213,10 +213,10 @@ static void wlr_frame_damage(void *data, struct zwlr_screencopy_frame_v1 *frame,
logprint(TRACE, "wlroots: damage event handler"); logprint(TRACE, "wlroots: damage event handler");
cast->simple_frame.damage.x = x; cast->screencopy_frame.damage.x = x;
cast->simple_frame.damage.y = y; cast->screencopy_frame.damage.y = y;
cast->simple_frame.damage.width = width; cast->screencopy_frame.damage.width = width;
cast->simple_frame.damage.height = height; cast->screencopy_frame.damage.height = height;
} }
static const struct zwlr_screencopy_frame_v1_listener wlr_frame_listener = { static const struct zwlr_screencopy_frame_v1_listener wlr_frame_listener = {