Skip to content

Commit

Permalink
screencast: send crop via pipewire
Browse files Browse the repository at this point in the history
  • Loading branch information
columbarius committed Jul 6, 2021
1 parent 358d051 commit d015d45
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
8 changes: 8 additions & 0 deletions include/screencast_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,21 @@ struct xdpw_frame_damage {
uint32_t height;
};

struct xdpw_frame_crop {
uint32_t x;
uint32_t y;
uint32_t width;
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 xdpw_frame_crop crop;
struct wl_buffer *buffer;
struct pw_buffer *current_pw_buffer;
};
Expand Down
18 changes: 17 additions & 1 deletion src/screencast/pipewire_screencast.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ static void pwr_handle_stream_param_changed(void *data, uint32_t id,
uint8_t params_buffer[1024];
struct spa_pod_builder b =
SPA_POD_BUILDER_INIT(params_buffer, sizeof(params_buffer));
const struct spa_pod *params[3];
const struct spa_pod *params[4];

if (!param || id != SPA_PARAM_Format) {
return;
Expand Down Expand Up @@ -99,6 +99,11 @@ static void pwr_handle_stream_param_changed(void *data, uint32_t id,
SPA_PARAM_META_type, SPA_POD_Id(SPA_META_VideoDamage),
SPA_PARAM_META_size, SPA_POD_Int(sizeof(struct spa_meta_region)));

params[3] = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_ParamMeta, SPA_PARAM_Meta,
SPA_PARAM_META_type, SPA_POD_Id(SPA_META_VideoCrop),
SPA_PARAM_META_size, SPA_POD_Int(sizeof(struct spa_meta_region)));

pw_stream_update_params(stream, params, 2);
}

Expand Down Expand Up @@ -199,6 +204,7 @@ void xdpw_pwr_export_buffer(struct xdpw_screencast_instance *cast) {
struct spa_buffer *spa_buf;
struct spa_meta_header *h;
struct spa_meta_region *damage;
struct spa_meta_region *crop;
struct spa_data *d;

logprint(TRACE, "pipewire: exporting buffer");
Expand Down Expand Up @@ -226,6 +232,13 @@ void xdpw_pwr_export_buffer(struct xdpw_screencast_instance *cast) {
damage->region.size.height = cast->simple_frame.damage.height;
}

if ((crop = spa_buffer_find_meta_data(spa_buf, SPA_META_VideoCrop, sizeof(*crop)))) {
crop->region.position.x = cast->simple_frame.crop.x;
crop->region.position.y = cast->simple_frame.crop.y;
crop->region.size.width = cast->simple_frame.crop.width;
crop->region.size.height = cast->simple_frame.crop.height;
}

if (cast->simple_frame.y_invert) {
//TODO: Flip buffer or set stride negative
}
Expand All @@ -240,6 +253,9 @@ void xdpw_pwr_export_buffer(struct xdpw_screencast_instance *cast) {
logprint(TRACE, "pipewire: damage %d,%d (%dx%d)",
cast->simple_frame.damage.x, cast->simple_frame.damage.y,
cast->simple_frame.damage.width, cast->simple_frame.damage.height);
logprint(TRACE, "pipewire: crop %d,%d (%dx%d)",
cast->simple_frame.crop.x, cast->simple_frame.crop.y,
cast->simple_frame.crop.width, cast->simple_frame.crop.height);
logprint(TRACE, "********************");

pw_stream_queue_buffer(cast->stream, pw_buf);
Expand Down

0 comments on commit d015d45

Please sign in to comment.