-
Notifications
You must be signed in to change notification settings - Fork 61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve pipewire buffertype handling #61
Conversation
Is there any proper documentation of those flag behaviors for pipewire? Other than reading from the examples/tutorials, I've never found a solid explanation. Anyway, I'd like to comment why we're using certain flags/metadata ao we can keep track of what we're intending. Something like this. These comments are how we determined WebRTC was incorrectly specifying allowed framerates, rather than insisting on variable on purpose. |
I can look up the discussions at #pipewire, but afaik nothing official. I just opened this Draft to discuss this with the ability to point at explicit code parts. |
My bouncer follows #pipewire, I'll go back and take a look. |
src/screencast/pipewire_screencast.c
Outdated
@@ -214,8 +214,7 @@ void xdpw_pwr_stream_init(struct xdpw_screencast_instance *cast) { | |||
pw_stream_connect(cast->stream, | |||
PW_DIRECTION_OUTPUT, | |||
PW_ID_ANY, | |||
(PW_STREAM_FLAG_DRIVER | | |||
PW_STREAM_FLAG_MAP_BUFFERS), | |||
(PW_STREAM_FLAG_DRIVER), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra parens here
src/screencast/pipewire_screencast.c
Outdated
logprint(TRACE, "pipewire: add buffer event handle"); | ||
|
||
d = buffer->buffer->datas; | ||
logprint(TRACE, "pipewire: buffer type %08x",d[0].type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: missing space after comma
src/screencast/pipewire_screencast.c
Outdated
d = buffer->buffer->datas; | ||
logprint(TRACE, "pipewire: buffer type %08x",d[0].type); | ||
if (d[0].type == SPA_DATA_Invalid || ((d[0].type & (1<<SPA_DATA_MemPtr)) == 0)) { | ||
logprint(ERROR, "pipewire: wrong buffer type %08x",d[0].type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: missing space after comma
src/screencast/pipewire_screencast.c
Outdated
} | ||
|
||
static void pwr_handle_stream_remove_buffer(void *data, struct pw_buffer *buffer) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style: extra newline here
I think "Add {add,remove}_buffer handler to pipewire_screencast.c" and "Fix typecheck" can be squashed together? It would be nice to add short explanations of the reason of the changes in each commit message. |
@emersion thanks for the review. |
No problem, let me know when you need a new review. |
231e270
to
1ea7928
Compare
@emersion @danshick
What about opening one port with its format and buffer type for every backend and let pipewire to the negotiation and selection of the correct port and we will just start copying frames if the pipewire stream is used. |
1ea7928
to
99679e0
Compare
084c1bb
to
437d74c
Compare
437d74c
to
7835136
Compare
4772dad
to
e284a2f
Compare
677ef53
to
15faf46
Compare
|
||
if (d[0].fd == -1) { | ||
logprint(ERROR, "pipewire: unable to create anonymous filedescriptor"); | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we set cast->err
for this error condition? (And the next 2 as well)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah sounds good. Don't know if we should check for that before registering the wlroots callback or somewhere else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, yeah we should probably check this as soon as we get the broken buffer from somewhere else, which is probably when sending the screencopy request to the compositor. It's unfortunate that add_buffer
can't return an error.
LGTM apart from the error handling. |
e4c117e
to
e98dc9f
Compare
e98dc9f
to
b7ee68a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
Thanks for merging! |
Updated and rebased and probably rewritten large parts of this MR to work with #141. So there are some old and probably some wrong things in the discussions.
I looked into buffertype handling in pipewire and talked to @wtay at #pipewire about it.
This draft is to show the current state (of at least my understanding).
SPA_PARAM_BUFFERS_dataType should be set by a consumer not by a producer as a bitmap to indicate the supported buffer types.
those callbacks are called, if pipewire adds or removes a new pw_buffer.
If no alloc flag is used to connect to pipewire the pw_buffer is read-only and buffer->datas[].type contains the supported buffer type bitmap from the client or SPA_DATA_Invalid if the client has not specified anything.
If PW_STREAM_FLAG_ALLOC_BUFFERS is used it's to producers duty to read the bitmap and set at least it's used buffer type and maybe other buffer parameters like size, stride, etc (not sure about that).
This flag tells pipewire to mmap in case of dmabuf or memfd the fd to the data pointer. Since we are doing our own fd handling i guess, we don't need that (Will clarify if it does anything in case of SPA_DATA_MemPtr).