screencast: limit screencast framerate by output framerate

This commit is contained in:
columbarius 2021-06-13 19:04:19 +02:00 committed by Simon Ser
parent 6438edb7b9
commit 976fa8374d
4 changed files with 11 additions and 6 deletions

View file

@ -96,7 +96,7 @@ struct xdpw_screencast_instance {
// wlroots
struct zwlr_screencopy_frame_v1 *frame_callback;
struct xdpw_wlr_output *target_output;
uint32_t framerate;
uint32_t max_framerate;
struct zwlr_screencopy_frame_v1 *wlr_frame;
struct xdpw_frame simple_frame;
bool with_cursor;

View file

@ -189,9 +189,9 @@ void xdpw_pwr_stream_create(struct xdpw_screencast_instance *cast) {
SPA_POD_Fraction(&SPA_FRACTION(0, 1)), 0);
spa_pod_builder_add(&b, SPA_FORMAT_VIDEO_maxFramerate,
SPA_POD_CHOICE_RANGE_Fraction(
&SPA_FRACTION(cast->framerate, 1),
&SPA_FRACTION(cast->max_framerate, 1),
&SPA_FRACTION(1, 1),
&SPA_FRACTION(cast->framerate, 1)),
&SPA_FRACTION(cast->max_framerate, 1)),
0);
const struct spa_pod *param = spa_pod_builder_pop(&b, &f);

View file

@ -50,7 +50,12 @@ void xdpw_screencast_instance_init(struct xdpw_screencast_context *ctx,
cast->ctx = ctx;
cast->target_output = out;
cast->framerate = out->framerate;
if (ctx->state->config->screencast_conf.max_fps > 0) {
cast->max_framerate = ctx->state->config->screencast_conf.max_fps < (uint32_t)out->framerate ?
ctx->state->config->screencast_conf.max_fps : (uint32_t)out->framerate;
} else {
cast->max_framerate = (uint32_t)out->framerate;
}
cast->with_cursor = with_cursor;
cast->refcount = 1;
logprint(INFO, "xdpw: screencast instance %p has %d references", cast, cast->refcount);

View file

@ -52,7 +52,7 @@ void xdpw_wlr_frame_free(struct xdpw_screencast_instance *cast) {
return ;
}
uint64_t delay_ns = fps_limit_measure_end(&cast->fps_limit, cast->ctx->state->config->screencast_conf.max_fps);
uint64_t delay_ns = fps_limit_measure_end(&cast->fps_limit, cast->max_framerate);
if (delay_ns > 0) {
xdpw_add_timer(cast->ctx->state, delay_ns,
(xdpw_event_loop_timer_func_t) xdpw_wlr_register_cb, cast);
@ -144,7 +144,7 @@ static void wlr_frame_buffer_done(void *data,
zwlr_screencopy_frame_v1_copy_with_damage(frame, cast->simple_frame.buffer);
logprint(TRACE, "wlroots: frame copied");
fps_limit_measure_start(&cast->fps_limit, cast->ctx->state->config->screencast_conf.max_fps);
fps_limit_measure_start(&cast->fps_limit, cast->max_framerate);
}
static void wlr_frame_buffer(void *data, struct zwlr_screencopy_frame_v1 *frame,