-
Notifications
You must be signed in to change notification settings - Fork 22
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
fix pipewire playback on more modern systems #138
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5de3cd1
reduce crackliness by simply not marking gbsplay as realtime
RiedleroD cce4ff4
also check pw_thread_loop_start for errors
RiedleroD 98b131f
proper locking at pause
RiedleroD 8de3604
no waiting for locks that don't exist
RiedleroD 28398dc
triple-buffer pipewire stream
RiedleroD c4369b2
updated licensing
RiedleroD File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
/* | ||
* gbsplay is a Gameboy sound player | ||
* | ||
* 2024 (C) by Christian Garbs <[email protected]> | ||
* 2024-2025 (C) by Christian Garbs <[email protected]> | ||
* Lisa Riedler <[email protected]> | ||
* | ||
* Licensed under GNU GPL v1 or, at your option, any later version. | ||
*/ | ||
|
@@ -32,7 +33,7 @@ static const struct pw_stream_events pipewire_stream_events = { | |
|
||
static long pipewire_open(enum plugout_endian *endian, long rate, long *buffer_bytes, const struct plugout_metadata metadata) | ||
{ | ||
const struct spa_pod *params[1]; | ||
const struct spa_pod *params[2]; | ||
uint8_t buffer[1024]; | ||
struct pw_properties *props; | ||
struct spa_pod_builder pod_builder = SPA_POD_BUILDER_INIT(buffer, sizeof(buffer)); | ||
|
@@ -75,6 +76,10 @@ static long pipewire_open(enum plugout_endian *endian, long rate, long *buffer_b | |
.format = fmt, | ||
.channels = CHANNELS, | ||
.rate = rate)); | ||
// triple-buffer audio | ||
params[1] = spa_pod_builder_add_object(&pod_builder, SPA_TYPE_OBJECT_ParamBuffers, | ||
SPA_PARAM_Buffers, | ||
SPA_PARAM_BUFFERS_buffers, SPA_POD_Int(3)); | ||
|
||
// create stream | ||
pipewire_data.stream = pw_stream_new_simple(pw_thread_loop_get_loop(pipewire_data.loop), | ||
|
@@ -84,29 +89,32 @@ static long pipewire_open(enum plugout_endian *endian, long rate, long *buffer_b | |
&pipewire_data); | ||
|
||
// connect the stream | ||
// TODO: do we need the realtime flag? | ||
if ((err = pw_stream_connect(pipewire_data.stream, | ||
PW_DIRECTION_OUTPUT, | ||
PW_ID_ANY, | ||
PW_STREAM_FLAG_AUTOCONNECT | | ||
PW_STREAM_FLAG_MAP_BUFFERS | | ||
PW_STREAM_FLAG_RT_PROCESS, | ||
params, 1))) { | ||
PW_STREAM_FLAG_MAP_BUFFERS, | ||
params, 2))) { | ||
fprintf(stderr, _("pw_stream_connect failed: %s\n"), spa_strerror(err)); | ||
return -1; | ||
} | ||
|
||
// run the loop | ||
pw_thread_loop_start(pipewire_data.loop); | ||
if ((err = pw_thread_loop_start(pipewire_data.loop) != 0)) { | ||
fprintf(stderr, _("pw_thread_loop_start failed: %s\n"), spa_strerror(err)); | ||
return -1; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
static void pipewire_pause(int pause) | ||
{ | ||
int err; | ||
pw_thread_loop_lock(pipewire_data.loop); | ||
if ((err = pw_stream_set_active(pipewire_data.stream, !pause))) | ||
fprintf(stderr, _("pw_stream_set_active failed: %s\n"), spa_strerror(err)); | ||
pw_thread_loop_unlock(pipewire_data.loop); | ||
} | ||
|
||
static ssize_t pipewire_write(const void *buf, size_t count) | ||
|
@@ -164,8 +172,6 @@ static ssize_t pipewire_write(const void *buf, size_t count) | |
|
||
static void pipewire_close() | ||
{ | ||
pw_thread_loop_wait(pipewire_data.loop); | ||
pw_thread_loop_unlock(pipewire_data.loop); | ||
pw_thread_loop_stop(pipewire_data.loop); | ||
pw_stream_destroy(pipewire_data.stream); | ||
pw_thread_loop_destroy(pipewire_data.loop); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I did not really know what I was doing when writing this code, but at least I was suspicious of this ;-)
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.
I don't know why the tutorials even use it 🤷🏻♀️