Skip to content

Conversation

@marcin-serwin
Copy link
Contributor

@marcin-serwin marcin-serwin commented Jul 31, 2025

While looking into cubeb_stream_get_current_device I've noticed some issues:

  • It seems like the function is supposed to return strings but src/cubeb_audiounit.cpp returns non-native endian integers. This could crash cubeb-rs since it asserts that the returned value is a valid UTF-8 string.
  • Also in src/cubeb_audiounit.cpp, the function does not free resources in case of errors, e.g., if the call to audiounit_get_default_device_name fails then *device is not freed causing leak.
  • The device_destroy function in cubeb-pulse-rs does not free the allocated strings, it only frees the cubeb_device so it always causes memory leaks.

Instead of fixing this issues one by one I figured that it may be beneficial to simplify the API usage and avoid the leaks by not allocating memory in the first place.

audiounit_stream_get_current_device is removed, it's not implemented in the Rust version so I assume it's not super necessary. Strings and the cubeb_device are returned directly instead of being allocated on the heap. This causes the destroying function to become unnecessary and it is removed in the last commit.

This is an API and ABI break but code changes for clients should be minor, comparable to the ones present in test/test_devices.cpp.

I'm a bit unsure about the removal of the destroying function. It would be a noop in the current backends, however, in the future it may be actually necessary to allocate something for a backend. What do you think?

@padenot
Copy link
Collaborator

padenot commented Aug 1, 2025

This is very edge-casey. The only caller that I know of is in Firefox, and this is used to pan the audio to the right speaker if using the buildint speakers, on macbook pre-2016, to avoid feedback into the microphone. We might be able to remove everything at this point and we'll deal with it using enumaration API.

@padenot
Copy link
Collaborator

padenot commented Aug 1, 2025

@marcin-serwin
Copy link
Contributor Author

The only other caller I know is RPCS3 where it is used to get the name of the default device that supports given stream params. If we want to delete it we should also accommodate for their usecase.

this is used to pan the audio to the right speaker if using the buildint speakers, on macbook pre-2016, to avoid feedback into the microphone.

Is this workaround even functional given that this function is not supported by the current macOS backend?

@padenot
Copy link
Collaborator

padenot commented Aug 1, 2025

The only other caller I know is RPCS3 where it is used to get the name of the default device that supports given stream params. If we want to delete it we should also accommodate for their usecase.

We can send a patch there (same fix, enumerate, find the default device, get the name).

this is used to pan the audio to the right speaker if using the buildint speakers, on macbook pre-2016, to avoid feedback into the microphone.

Is this workaround even functional given that this function is not supported by the current macOS backend?

No it hasn't worked for a long time, and it doesn't matter anymore (Firefox generally uses macOS's system noise suppression and echo cancellation, and Apple have fixed their hardware). We simply didn't remove the code. We can probably just remove everything then.

@marcin-serwin
Copy link
Contributor Author

The only other caller I know is RPCS3 where it is used to get the name of the default device that supports given stream params. If we want to delete it we should also accommodate for their usecase.

We can send a patch there (same fix, enumerate, find the default device, get the name).

They are doing that in the GetDevice function, not sure why they implemented the stream fallback.

Signed-off-by: Marcin Serwin <marcin@serwin.dev>
@marcin-serwin marcin-serwin changed the title Simplify cubeb_stream_get_current_device Remove cubeb_stream_get_current_device Aug 2, 2025
@marcin-serwin
Copy link
Contributor Author

RPCS3 devs are fine with just using enumeration so I guess we can proceed with removal.

marcin-serwin added a commit to marcin-serwin/cubeb-rs that referenced this pull request Aug 2, 2025
Following mozilla/cubeb#822

Signed-off-by: Marcin Serwin <marcin@serwin.dev>
@marcin-serwin
Copy link
Contributor Author

@padenot Any updates regarding this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants