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

Pre-configured decoding calls have their result overwritten #899

Open
ace-n opened this issue Oct 6, 2024 · 2 comments
Open

Pre-configured decoding calls have their result overwritten #899

ace-n opened this issue Oct 6, 2024 · 2 comments

Comments

@ace-n
Copy link

ace-n commented Oct 6, 2024

Summary

When ma_decoder_init_file is provided a decoderConfig with a specific encodingFormat, the "fallback" decoding calls can overwrite the result value from the initial specific-format decoding call.

Example Scenario

Call ma_decoder_init_file with a preconfigured encodingFormat and a bad filepath as shown below:

int CHANNEL_COUNT = 2;
int MAX_FRAMES_READ = 100;

const char *filepath = "BAD PATH";
ma_decoder decoder;

ma_format FORMAT = ma_format_f32;
ma_decoder_config decoderConfig = ma_decoder_config_init(
    FORMAT,
    CHANNEL_COUNT,
    48000);
decoderConfig.encodingFormat = ma_encoding_format_mp3;

ma_result decoderInitResult = ma_decoder_init_file(
    filepath,
    &decoderConfig,
    &decoder);

What happens

  • The initial (MP3-specific) decoding operation returns an MA_INVALID_FILE error code.
  • The fallback decoding calls overwrite that with MA_NO_BACKEND.

In the end, decoderInitResult resolves to MA_NO_BACKEND.

What should happen

Ideally, the MA_INVALID_FILE error would not have been overwritten!

Potential fixes

1) Log format-specific errors

Log the initial error code (in this case, MA_INVALID_FILE) and return the error code from the fallback decoding calls.

2) Preserve format-specific error codes

Preserve (and return) the initial error code while still performing the fallback decoding calls.

Note: returning the initial error code immediately would be a breaking change, as the default decoders would no longer be called if the specified-format decoding call fails.

Of these two options, my preference is for the second.

Next steps

@mackron if you're on board with this, let me know:

  • whether to create a PR
  • if so, which of these approaches you prefer

Thank you! 😃

@mackron
Copy link
Owner

mackron commented Oct 6, 2024

Thanks. I'm going to sit on this for the moment. In the dev-0.12 branch I've actually done a complete overhaul of the decoding backend selection logic and I'm not sure off the top of my head if what you've mentioned still applies. But I'm also not sure if I agree with your suggestions just yet and want to consider it. If you're curious, here's my comment on the changes in dev-0.12: #765 (comment)

@ace-n
Copy link
Author

ace-n commented Oct 6, 2024 via email

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

No branches or pull requests

2 participants