Skip to content

Commit

Permalink
Add XDPW_INSTANCE_DMABUF2MemPtr instance type
Browse files Browse the repository at this point in the history
  • Loading branch information
columbarius committed Sep 17, 2020
1 parent 2fbd42d commit 4950070
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/screencast_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ enum xdpw_instance_type {
XDPW_INSTANCE_NONE=0,
XDPW_INSTANCE_SCP_SHM,
XDPW_INSTANCE_SCP_DMABUF,
XDPW_INSTANCE_SCP_DMABUF2MemPtr,
};

struct xdpw_simple_frame {
Expand Down
31 changes: 31 additions & 0 deletions src/screencast/pipewire_screencast.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ static void writeFrameData(void *pwFramePointer, void *wlrFramePointer,
return;
}

static void writeDmabufData(void *data, struct xdpw_screencast_instance *cast) {
void *map_data = NULL;
cast->xdpw_frames.screencopy_frame.data = gbm_bo_map(cast->xdpw_frames.screencopy_frame.bo,
0, 0, cast->xdpw_frames.screencopy_frame.width, cast->xdpw_frames.screencopy_frame.height,
GBM_BO_TRANSFER_READ, &cast->xdpw_frames.screencopy_frame.stride, &map_data);
writeFrameData(data, cast->xdpw_frames.screencopy_frame.data, cast->xdpw_frames.screencopy_frame.height,
cast->xdpw_frames.screencopy_frame.stride, cast->xdpw_frames.screencopy_frame.y_invert);
gbm_bo_unmap(cast->xdpw_frames.screencopy_frame.bo, map_data);
}

void pwr_copy_screencast(struct spa_buffer *spa_buf, struct xdpw_screencast_instance *cast) {
struct spa_meta_header *h;
struct spa_data *d;
Expand Down Expand Up @@ -75,6 +85,25 @@ void pwr_copy_screencast(struct spa_buffer *spa_buf, struct xdpw_screencast_inst
logprint(TRACE, "pipewire: width %d", cast->xdpw_frames.screencopy_frame.width);
logprint(TRACE, "pipewire: height %d", cast->xdpw_frames.screencopy_frame.height);
break;
case XDPW_INSTANCE_SCP_DMABUF2MemPtr:
d[0].type = SPA_DATA_MemPtr;
d[0].maxsize = cast->xdpw_frames.screencopy_frame.size;
d[0].mapoffset = 0;
d[0].chunk->size = cast->xdpw_frames.screencopy_frame.size;
d[0].chunk->stride = cast->xdpw_frames.screencopy_frame.stride;
d[0].chunk->offset = 0;
d[0].flags = 0;
d[0].fd = -1;

writeDmabufData(d[0].data, cast);

logprint(TRACE, "pipewire: pointer %p", d[0].data);
logprint(TRACE, "pipewire: size %d", d[0].maxsize);
logprint(TRACE, "pipewire: stride %d", d[0].chunk->stride);
logprint(TRACE, "pipewire: width %d", cast->xdpw_frames.screencopy_frame.width);
logprint(TRACE, "pipewire: height %d", cast->xdpw_frames.screencopy_frame.height);
logprint(TRACE, "pipewire: y_invert %d", cast->xdpw_frames.screencopy_frame.y_invert);
break;
default:
abort();
}
Expand All @@ -97,6 +126,7 @@ static void pwr_on_event(void *data, uint64_t expirations) {
switch (cast->type) {
case XDPW_INSTANCE_SCP_SHM:
case XDPW_INSTANCE_SCP_DMABUF:
case XDPW_INSTANCE_SCP_DMABUF2MemPtr:
pwr_copy_screencast(pw_buf->buffer, cast);
break;
default:
Expand Down Expand Up @@ -208,6 +238,7 @@ void xdpw_pwr_stream_init(struct xdpw_screencast_instance *cast) {
const struct spa_pod *param;
switch (cast->type) {
case XDPW_INSTANCE_SCP_SHM:
case XDPW_INSTANCE_SCP_DMABUF2MemPtr:
param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video),
Expand Down
1 change: 1 addition & 0 deletions src/screencast/screencast_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ enum spa_video_format xdpw_format_pw(
case XDPW_INSTANCE_SCP_SHM:
return xdpw_format_pw_from_wl_shm(cast->xdpw_frames.screencopy_frame.format);
case XDPW_INSTANCE_SCP_DMABUF:
case XDPW_INSTANCE_SCP_DMABUF2MemPtr:
return xdpw_format_pw_from_dmabuf(cast->xdpw_frames.screencopy_frame.fourcc);
default:
abort();
Expand Down
2 changes: 2 additions & 0 deletions src/screencast/wlr_screencast.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void xdpw_wlr_frame_free(struct xdpw_screencast_instance *cast) {
switch (cast->type) {
case XDPW_INSTANCE_SCP_SHM:
case XDPW_INSTANCE_SCP_DMABUF:
case XDPW_INSTANCE_SCP_DMABUF2MemPtr:
xdpw_wlr_screencopy_frame_free(cast);
break;
default:
Expand All @@ -49,6 +50,7 @@ void xdpw_wlr_register_cb(struct xdpw_screencast_instance *cast) {
switch (cast->type) {
case XDPW_INSTANCE_SCP_SHM:
case XDPW_INSTANCE_SCP_DMABUF:
case XDPW_INSTANCE_SCP_DMABUF2MemPtr:
xdpw_wlr_screencopy_register_cb(cast);
break;
default:
Expand Down
4 changes: 4 additions & 0 deletions src/screencast/wlr_screencopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ static void wlr_screencopy_buffer_free(struct xdpw_screencast_instance *cast) {
cast->xdpw_frames.screencopy_frame.size);
break;
case XDPW_INSTANCE_SCP_DMABUF:
case XDPW_INSTANCE_SCP_DMABUF2MemPtr:
wlr_destroy_dmabuf_buffer(cast->xdpw_frames.screencopy_frame.buffer,
cast->xdpw_frames.screencopy_frame.bo);
break;
Expand Down Expand Up @@ -59,6 +60,7 @@ static void wlr_frame_buffer_chparam(struct xdpw_screencast_instance *cast,
cast->xdpw_frames.screencopy_frame.format = format;
break;
case XDPW_INSTANCE_SCP_DMABUF:
case XDPW_INSTANCE_SCP_DMABUF2MemPtr:
cast->xdpw_frames.screencopy_frame.fourcc = format;
break;
default:
Expand All @@ -77,6 +79,7 @@ static void wlr_frame_linux_dmabuf(void *data,
case XDPW_INSTANCE_SCP_SHM:
break;
case XDPW_INSTANCE_SCP_DMABUF:
case XDPW_INSTANCE_SCP_DMABUF2MemPtr:
cast->wlr_frame = frame;
if (cast->xdpw_frames.screencopy_frame.width != width ||
cast->xdpw_frames.screencopy_frame.height != height ||
Expand Down Expand Up @@ -150,6 +153,7 @@ static void wlr_frame_buffer(void *data, struct zwlr_screencopy_frame_v1 *frame,
}
break;
case XDPW_INSTANCE_SCP_DMABUF:
case XDPW_INSTANCE_SCP_DMABUF2MemPtr:
break;
default:
abort();
Expand Down

0 comments on commit 4950070

Please sign in to comment.