Skip to content

Commit

Permalink
screencast: use the pipewire callback process to start screencast
Browse files Browse the repository at this point in the history
We can trigger that with pw_stream_trigger_process when we are the
driver of the stream. Additionally this let's us run passivly with the
consumer driving the stream.
  • Loading branch information
columbarius committed Nov 6, 2021
1 parent b0f4747 commit 0424e13
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
2 changes: 2 additions & 0 deletions include/pipewire_screencast.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#define XDPW_PWR_BUFFERS 1
#define XDPW_PWR_ALIGN 16

void xdpw_pwr_trigger_process(struct xdpw_screencast_instance *cast);
bool xdpw_pwr_is_driving(struct xdpw_screencast_instance *cast);
void xdpw_pwr_dequeue_buffer(struct xdpw_screencast_instance *cast);
void xdpw_pwr_enqueue_buffer(struct xdpw_screencast_instance *cast);
void pwr_update_stream_param(struct xdpw_screencast_instance *cast);
Expand Down
17 changes: 17 additions & 0 deletions src/screencast/pipewire_screencast.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ static struct spa_pod *build_format(struct spa_pod_builder *b, enum spa_video_fo
return spa_pod_builder_pop(b, &f[0]);
}

static void pwr_handle_stream_process(void *data) {
struct xdpw_screencast_instance *cast = data;

logprint(TRACE, "pipewire: stream process");

xdpw_wlr_frame_start(cast);
}

static void pwr_handle_stream_state_changed(void *data,
enum pw_stream_state old, enum pw_stream_state state, const char *error) {
struct xdpw_screencast_instance *cast = data;
Expand Down Expand Up @@ -174,8 +182,17 @@ static const struct pw_stream_events pwr_stream_events = {
.param_changed = pwr_handle_stream_param_changed,
.add_buffer = pwr_handle_stream_add_buffer,
.remove_buffer = pwr_handle_stream_remove_buffer,
.process = pwr_handle_stream_process,
};

void xdpw_pwr_trigger_process(struct xdpw_screencast_instance *cast) {
pw_stream_trigger_process(cast->stream);
}

bool xdpw_pwr_is_driving(struct xdpw_screencast_instance *cast) {
return pw_stream_is_driving(cast->stream);
}

void xdpw_pwr_dequeue_buffer(struct xdpw_screencast_instance *cast) {
logprint(TRACE, "pipewire: dequeueing buffer");

Expand Down
8 changes: 4 additions & 4 deletions src/screencast/wlr_screencast.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ void xdpw_wlr_frame_finish(struct xdpw_screencast_instance *cast) {
return ;
}

if (cast->pwr_stream_state) {
if (cast->pwr_stream_state && xdpw_pwr_is_driving(cast)) {
if (cast->frame_state == XDPW_FRAME_STATE_SUCCESS) {
uint64_t delay_ns = fps_limit_measure_end(&cast->fps_limit, cast->framerate);
if (delay_ns > 0) {
xdpw_add_timer(cast->ctx->state, delay_ns,
(xdpw_event_loop_timer_func_t) xdpw_wlr_frame_start, cast);
(xdpw_event_loop_timer_func_t) xdpw_pwr_trigger_process, cast);
} else {
xdpw_wlr_frame_start(cast);
xdpw_pwr_trigger_process(cast);
}
} else {
xdpw_wlr_frame_start(cast);
xdpw_pwr_trigger_process(cast);
}
}
}
Expand Down

0 comments on commit 0424e13

Please sign in to comment.