Skip to content

Commit

Permalink
screencast: pipewire try no to die on changed dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
columbarius committed May 28, 2021
1 parent 8ffcef5 commit 080f41b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions include/pipewire_screencast.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

void xdpw_pwr_import_buffer(struct xdpw_screencast_instance *cast);
void xdpw_pwr_export_buffer(struct xdpw_screencast_instance *cast);
void xdpw_pwr_destroy_shm_buffer(struct xdpw_screencast_instance *cast,
struct pw_buffer *buffer);
void pwr_update_stream_param(struct xdpw_screencast_instance *cast);
void xdpw_pwr_stream_create(struct xdpw_screencast_instance *cast);
void xdpw_pwr_stream_destroy(struct xdpw_screencast_instance *cast);
Expand Down
24 changes: 21 additions & 3 deletions src/screencast/pipewire_screencast.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,19 @@ static void pwr_handle_stream_add_buffer(void *data, struct pw_buffer *buffer) {
}

static void pwr_handle_stream_remove_buffer(void *data, struct pw_buffer *buffer) {
struct xdpw_screencast_instance *cast = data;
struct spa_data *d;

logprint(TRACE, "pipewire: remove buffer event handle");

d = buffer->buffer->datas;
if (buffer == cast->current_pw_buffer) {
logprint(TRACE, "pipewire: can't remove buffer. still in use");
return;
}
switch (d[0].type) {
case SPA_DATA_MemFd:
wl_buffer_destroy(d[0].data);
close(d[0].fd);
xdpw_pwr_destroy_shm_buffer(cast, buffer);
break;
default:
break;
Expand All @@ -179,6 +183,7 @@ void xdpw_pwr_import_buffer(struct xdpw_screencast_instance *cast) {

if ((pw_buf = pw_stream_dequeue_buffer(cast->stream)) == NULL) {
logprint(WARN, "pipewire: out of buffers");
cast->simple_frame.buffer = NULL;
return;
}

Expand Down Expand Up @@ -225,11 +230,24 @@ void xdpw_pwr_export_buffer(struct xdpw_screencast_instance *cast) {
logprint(TRACE, "pipewire: y_invert %d", cast->simple_frame.y_invert);
logprint(TRACE, "********************");

pw_stream_queue_buffer(cast->stream, pw_buf);
if (cast->current_pw_buffer) {
pw_stream_queue_buffer(cast->stream, pw_buf);
} else {
xdpw_pwr_destroy_shm_buffer(cast, pw_buf);
}

cast->current_pw_buffer = NULL;
}

void xdpw_pwr_destroy_shm_buffer(struct xdpw_screencast_instance *cast, struct pw_buffer *buffer) {
struct spa_data *d;

d = buffer->buffer->datas;
wl_buffer_destroy(d[0].data);
d[0].data = NULL;
close(d[0].fd);
}

void pwr_update_stream_param(struct xdpw_screencast_instance *cast) {
logprint(TRACE, "pipewire: stream update parameters");
struct pw_stream *stream = cast->stream;
Expand Down

0 comments on commit 080f41b

Please sign in to comment.