Skip to content
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

Error when opening default stream on iOS #701

Open
EriKWDev opened this issue Feb 15, 2025 · 17 comments
Open

Error when opening default stream on iOS #701

EriKWDev opened this issue Feb 15, 2025 · 17 comments
Labels

Comments

@EriKWDev
Copy link

EriKWDev commented Feb 15, 2025

Hi!

I've compiled a project for iOS (aarch64-apple-ios) in release mode. It compiles and runs on macOS, and without rodio the app runs fine on both iPhone and iPad. (iOS 18.1.1 and iOS 17.6.1 respectively)

However, even if rodio compiles and links successfully for the iOS target, when I run I get BuildStreamError(StreamConfigNotSupported)

I'm calling

let output = rodio::OutputStreamBuilder::open_default_stream().unwrap();

and using the latest commit on HEAD of the git repo as the version (70d01da)

the project is compiled as a static library and included as a library to link with in Xcode. Initially Xcode complained that it couldn't find some symbols like _AudioComponentFindNext and _AudioUnitUninitialize and some more, but it went away when I explicitly added the AudioToolbox.framework as a linked library as well.

I get the same error in debug mode as well, and also if I try on the simulator with aarch64-apple-ios-sim target

How may I assist in debugging this?

@EriKWDev
Copy link
Author

If it is of any help, I tried separating the from_default_device and open_stream calls, and it is the open_stream call which fails.

// let output = rodio::OutputStreamBuilder::open_default_stream().unwrap();
let b = rodio::OutputStreamBuilder::from_default_device().unwrap();
let output = b.open_stream().unwrap();

@dvdsk
Copy link
Collaborator

dvdsk commented Feb 15, 2025

I took a quick look, StreamConfigNotSupported is only returned when the sample type is not supported by rodio, however all sample types that are common are.

Its quite the list, see

fn init_stream(
)

Can you debug print your variable b? dbg!(b).open_stream().unwrap() should do it.

@EriKWDev
Copy link
Author

Can you debug print your variable b?

I tried but it didn't implement debug 😅 but can make a fork and quickly try

Thanks for having a look so promptly

@dvdsk
Copy link
Collaborator

dvdsk commented Feb 15, 2025

I tried but it didn't implement debug 😅 but can make a fork and quickly try

huuuu thats wierd it should. Its an OutputStreamConfig right?

edit your right!

@EriKWDev
Copy link
Author

No worries! Yeah the config implements Debug but the builder doesn't and the field is private..

Anyway, made a fork and here is the debug:

 OutputStreamConfig {
      channel_count: 2,
      sample_rate: 48000,
      buffer_size: Fixed(
          0,
      ),
      sample_format: F32,
  }

@EriKWDev
Copy link
Author

EriKWDev commented Feb 15, 2025

Fixed(0) looked a little suspicious. When I made it rodio::cpal::BufferSize::Default instead, it worked!

@dvdsk
Copy link
Collaborator

dvdsk commented Feb 15, 2025

No worries! Yeah the config implements Debug but the builder doesn't and the field is private..

fixed that OutputStreamConfig now implements Debug.

Fixed(0) looked a little suspicious. When I made it rodio::cpal::BufferSize::Default instead, it worked!

Thats super useful! thanks for that discovery!

@dvdsk
Copy link
Collaborator

dvdsk commented Feb 15, 2025

I took a quick look, StreamConfigNotSupported is only returned when the sample type is not supported by rodio, however all sample types that are common are.

this is wrong, StreamConfigNotSupported is not a rodio type but from cpal. We probably should not be using it but use our own to prevent this confusion.

@dvdsk dvdsk added the bug label Feb 15, 2025
@dvdsk
Copy link
Collaborator

dvdsk commented Feb 15, 2025

So the question is is this our bug or upstream. I am leaning towards the second. The config is coming from cpal's: Device::default_output_config. Which must be returning a SupportedBufferSize::Range {0,0}.

@EriKWDev could confirm this by dbg printing the config passed to the function: with_supported_config in rodio's OutputStreamBuilder::from_device?

@EriKWDev
Copy link
Author

Can do it later but heading away at the moment. But yeah might be from cpal this is coming from

@PetrGlad
Copy link
Collaborator

PetrGlad commented Feb 15, 2025

BuildStreamError::StreamConfigNotSupported is a cpal error, so it can also be raised there.

I wonder why compiler complains about missing matches in src/stream.rs:440 since it looks like all existing cases are explicitly covered.

I will add an assertion in clamp_supported_buffer_size. Since this is a part of default stream opening helpers maybe we can silently replace Fixed(0) to Default. Or maybe also write a debug message just in case.

@dvdsk
Copy link
Collaborator

dvdsk commented Feb 15, 2025

I will add an assertion in clamp_supported_buffer_size.

good idea

maybe we can silently replace Fixed(0) to Default.

I rather have it fixed in cpal to be honest. That may take a while, we could for now add the workaround in rodio we should document that with a comment linked to a cpal issue.

@PetrGlad
Copy link
Collaborator

@dvdsk We may add a ticket to cpal regarding this. BUt I suspect CPAl may not be able to determine buffer size in some cases, so the defaulting logic has to be somewhere anyway.

@PetrGlad
Copy link
Collaborator

Found it. cpal's SampleFormat is annotated with #[non_exhaustive] that is why a fallback case is required...

@dvdsk
Copy link
Collaborator

dvdsk commented Feb 17, 2025

@dvdsk We may add a ticket to cpal regarding this. But I suspect CPAl may not be able to determine buffer size in some cases, so the defaulting logic has to be somewhere anyway.

Agreed but having that logic in cpal makes more sense since they have a Default bufferlenght right?

Anyway we cant make the issue till we are sure, and I do not have the hardware required. @EriKWDev there is no rush but to solve this correctly we do need your help yet again :)

@EriKWDev
Copy link
Author

EriKWDev commented Feb 17, 2025

I'm more than happy to help out, but won't be back at the mac until later this evening. What are the things you would need debugged?

@dvdsk
Copy link
Collaborator

dvdsk commented Feb 17, 2025

I'm more than happy to help out, but won't be back at the mac until later this evening. What are the things you would need debugged?

Could you check if cpal's beep example works? https://github.com/RustAudio/cpal/blob/master/examples/beep.rs

If it does not then this is a cpal issue. And it would be great if you could then open it there (they might need your help making progress).

If beep does work then.... I will be confused :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants