Skip to content

Commit

Permalink
Advertise format with alpha channel stripped
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion authored and danshick committed May 5, 2020
1 parent 3b56140 commit 26b6bf6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
4 changes: 3 additions & 1 deletion include/screencast_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ struct xdpw_wlr_output {
};

void randname(char *buf);
uint32_t xdpw_format_pw_from_wl_shm(void *data);
enum spa_video_format xdpw_format_pw_from_wl_shm(
struct xdpw_screencast_instance *cast);
enum spa_video_format xdpw_format_pw_strip_alpha(enum spa_video_format format);

#endif /* SCREENCAST_COMMON_H */
16 changes: 12 additions & 4 deletions src/screencast/pipewire_screencast.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ void xdpw_pwr_stream_init(struct xdpw_screencast_instance *cast) {

pw_loop_enter(state->pw_loop);

const struct spa_pod *params[1];
uint8_t buffer[1024];
struct spa_pod_builder b = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer));

Expand All @@ -163,11 +162,20 @@ void xdpw_pwr_stream_init(struct xdpw_screencast_instance *cast) {
pw_loop_add_event(state->pw_loop, pwr_on_event, cast);
logprint(DEBUG, "pipewire: registered event %p", cast->event);

params[0] = spa_pod_builder_add_object(&b,
enum spa_video_format format = xdpw_format_pw_from_wl_shm(cast);
enum spa_video_format format_without_alpha =
xdpw_format_pw_strip_alpha(format);
uint32_t n_formats = 1;
if (format_without_alpha != SPA_VIDEO_FORMAT_UNKNOWN) {
n_formats++;
}

const struct spa_pod *param = spa_pod_builder_add_object(&b,
SPA_TYPE_OBJECT_Format, SPA_PARAM_EnumFormat,
SPA_FORMAT_mediaType, SPA_POD_Id(SPA_MEDIA_TYPE_video),
SPA_FORMAT_mediaSubtype, SPA_POD_Id(SPA_MEDIA_SUBTYPE_raw),
SPA_FORMAT_VIDEO_format, SPA_POD_Id(xdpw_format_pw_from_wl_shm(cast)),
SPA_FORMAT_VIDEO_format, SPA_POD_CHOICE_ENUM_Id(n_formats + 1,
format, format, format_without_alpha),
SPA_FORMAT_VIDEO_size, SPA_POD_CHOICE_RANGE_Rectangle(
&SPA_RECTANGLE(cast->simple_frame.width, cast->simple_frame.height),
&SPA_RECTANGLE(1, 1),
Expand All @@ -187,7 +195,7 @@ void xdpw_pwr_stream_init(struct xdpw_screencast_instance *cast) {
PW_ID_ANY,
(PW_STREAM_FLAG_DRIVER |
PW_STREAM_FLAG_MAP_BUFFERS),
params, 1);
&param, 1);

}

Expand Down
20 changes: 17 additions & 3 deletions src/screencast/screencast_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ void randname(char *buf) {
}
}

enum spa_video_format xdpw_format_pw_from_wl_shm(void *data) {
struct xdpw_screencast_instance *cast = data;

enum spa_video_format xdpw_format_pw_from_wl_shm(
struct xdpw_screencast_instance *cast) {
if (cast->ctx->forced_pixelformat) {
if (strcmp(cast->ctx->forced_pixelformat, "BGRx") == 0) {
return SPA_VIDEO_FORMAT_BGRx;
Expand Down Expand Up @@ -47,3 +46,18 @@ enum spa_video_format xdpw_format_pw_from_wl_shm(void *data) {
abort();
}
}

enum spa_video_format xdpw_format_pw_strip_alpha(enum spa_video_format format) {
switch (format) {
case SPA_VIDEO_FORMAT_BGRA:
return SPA_VIDEO_FORMAT_BGRx;
case SPA_VIDEO_FORMAT_ABGR:
return SPA_VIDEO_FORMAT_xBGR;
case SPA_VIDEO_FORMAT_RGBA:
return SPA_VIDEO_FORMAT_RGBx;
case SPA_VIDEO_FORMAT_ARGB:
return SPA_VIDEO_FORMAT_xRGB;
default:
return SPA_VIDEO_FORMAT_UNKNOWN;
}
}

0 comments on commit 26b6bf6

Please sign in to comment.