Skip to content

Commit

Permalink
screencopy: introduce xdpw_frame
Browse files Browse the repository at this point in the history
  • Loading branch information
columbarius committed Jun 16, 2021
1 parent fc79b02 commit 4ac6de2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
13 changes: 12 additions & 1 deletion include/screencast_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ struct xdpw_frame_damage {
uint32_t height;
};

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 height;
Expand Down Expand Up @@ -83,6 +94,7 @@ struct xdpw_screencast_instance {
uint32_t refcount;
struct xdpw_screencast_context *ctx;
bool initialized;
struct xdpw_frame simple_frame;

// pipewire
struct pw_stream *stream;
Expand All @@ -91,7 +103,6 @@ struct xdpw_screencast_instance {
uint32_t seq;
uint32_t node_id;
bool pwr_stream_state;
struct pw_buffer *current_pw_buffer;

// wlroots
struct zwlr_screencopy_frame_v1 *frame_callback;
Expand Down
14 changes: 10 additions & 4 deletions src/screencast/pipewire_screencast.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,22 @@ static const struct pw_stream_events pwr_stream_events = {

void xdpw_pwr_import_buffer(struct xdpw_screencast_instance *cast) {
struct pw_buffer *pw_buf;
struct spa_buffer *spa_buf;
struct spa_data *d;

logprint(TRACE, "pipewire: importing buffer");

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

cast->current_pw_buffer = pw_buf;
spa_buf = pw_buf->buffer;
d = spa_buf->datas;
cast->simple_frame.current_pw_buffer = pw_buf;
cast->simple_frame.size = d[0].chunk->size;
cast->simple_frame.stride = d[0].chunk->stride;
}

void xdpw_pwr_export_buffer(struct xdpw_screencast_instance *cast) {
Expand All @@ -212,7 +218,7 @@ void xdpw_pwr_export_buffer(struct xdpw_screencast_instance *cast) {

logprint(TRACE, "pipewire: exporting buffer");

pw_buf = cast->current_pw_buffer;
pw_buf = cast->simple_frame.current_pw_buffer;

if (!pw_buf) {
logprint(TRACE, "pipewire: no pipewire buffer to queue");
Expand Down Expand Up @@ -247,7 +253,7 @@ void xdpw_pwr_export_buffer(struct xdpw_screencast_instance *cast) {
queue:
pw_stream_queue_buffer(cast->stream, pw_buf);

cast->current_pw_buffer = NULL;
cast->simple_frame.current_pw_buffer = NULL;
}

void pwr_update_stream_param(struct xdpw_screencast_instance *cast) {
Expand Down
2 changes: 1 addition & 1 deletion src/screencast/wlr_screencast.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static void wlr_frame_buffer_done(void *data,

if (!cast->quit && !cast->err && cast->pwr_stream_state) {
xdpw_pwr_import_buffer(cast);
if(!cast->current_pw_buffer) {
if(!cast->simple_frame.current_pw_buffer) {
xdpw_wlr_frame_free(cast);
return;
}
Expand Down

0 comments on commit 4ac6de2

Please sign in to comment.