Skip to content

Commit

Permalink
Seperate the buffer selection into its own function
Browse files Browse the repository at this point in the history
  • Loading branch information
columbarius committed Nov 3, 2020
1 parent ed055c2 commit a00075c
Showing 1 changed file with 36 additions and 30 deletions.
66 changes: 36 additions & 30 deletions src/screencast/pipewire_screencast.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,44 +182,46 @@ static void pwr_handle_stream_param_changed(void *data, uint32_t id,
pw_stream_update_params(stream, params, 2);
}

uint32_t pwr_choose_buffertype(struct xdpw_screencast_instance *cast, uint32_t buffermap) {
uint32_t type = buffermap;

logprint(DEBUG, "pipewire: buffer type %08x", buffermap);

// Select buffer type from negotiation result
if (~buffermap == 0) {
logprint(INFO, "pipewire: no buffer type was defined");
type = SPA_DATA_MemPtr;
return type;
}
if ((buffermap & (1<<SPA_DATA_DmaBuf)) > 0) {
type = SPA_DATA_DmaBuf;
if (cast->type == XDPW_INSTANCE_SCP_DMABUF && cast->pwr_format.modifier > 0) {
return type;
}
}
if ((buffermap & (1<<SPA_DATA_MemPtr)) > 0) {
type = SPA_DATA_MemPtr;
return type;
}

if (type != buffermap) {
return type;
}
type = SPA_DATA_Invalid;
return type;
}

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

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

d = buffer->buffer->datas;
logprint(TRACE, "pipewire: buffer type %08x", d[0].type);

// Select buffer type from negotiation result
if (~d[0].type == 0) {
logprint(INFO, "pipewire: no buffer type was defined");
//either die or guess a reasonable default
//cast->err = 1;
//return;
//default:
switch (cast->type) {
case XDPW_INSTANCE_SCP_SHM:
d[0].type = SPA_DATA_MemPtr;
break;
case XDPW_INSTANCE_SCP_DMABUF:
d[0].type = SPA_DATA_DmaBuf;
break;
default:
abort();
}
d[0].type = SPA_DATA_MemPtr;
} else if ((d[0].type & (1<<SPA_DATA_DmaBuf)) > 0) {
d[0].type = SPA_DATA_DmaBuf;
} else if ((d[0].type & (1<<SPA_DATA_MemPtr)) > 0) {
d[0].type = SPA_DATA_MemPtr;
} else {
logprint(ERROR, "pipewire: unsupported buffer type");
cast->err = 1;
return;
}
d[0].type = pwr_choose_buffertype(cast, d[0].type);

logprint(TRACE, "pipewire: selected buffer type %d", d[0].type);
logprint(DEBUG, "pipewire: buffertype %u", d[0].type);
// Prepare buffer for choosen type
if (d[0].type == SPA_DATA_MemPtr) {
d[0].type = SPA_DATA_MemFd;
Expand Down Expand Up @@ -261,6 +263,10 @@ static void pwr_handle_stream_add_buffer(void *data, struct pw_buffer *buffer) {
logprint(ERROR, "Buffertype dmabuf is not supported");
abort();
}
} else {
logprint(ERROR, "pipewire: unsupported buffer type");
cast->err = 1;
return;
}
}

Expand Down Expand Up @@ -352,7 +358,7 @@ void xdpw_pwr_stream_init(struct xdpw_screencast_instance *cast) {
SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw),
SPA_FORMAT_VIDEO_format, SPA_POD_CHOICE_ENUM_Id(n_formats + 1,
format, format, format_without_alpha),
SPA_FORMAT_VIDEO_modifier, SPA_POD_CHOICE_ENUM_Long(1,cast->xdpw_frames.screencopy_frame.modifier),
SPA_FORMAT_VIDEO_modifier, SPA_POD_CHOICE_ENUM_Long(2,cast->xdpw_frames.screencopy_frame.modifier, 0),
SPA_FORMAT_VIDEO_size, SPA_POD_CHOICE_RANGE_Rectangle(
&SPA_RECTANGLE(cast->xdpw_frames.simple_frame.width, cast->xdpw_frames.simple_frame.height),
&SPA_RECTANGLE(1, 1),
Expand Down

0 comments on commit a00075c

Please sign in to comment.