SFML community forums

Help => Audio => Topic started by: jamiltron on June 16, 2017, 08:12:03 am

Title: Loading certain ogg files in SFML 2.4.2 causes program to hang forever.
Post by: jamiltron on June 16, 2017, 08:12:03 am
Hello,

I am updating an application that uses sfml-audio from 2.1 to 2.4.2 that consistently hangs forever when loading certain ogg files. These files did not hang in 2.1, and it is only specific files that cause this.

Here is a link to one of the ogg files that causes our program to hang: https://www.dropbox.com/s/1gxh56ym6kk2nla/hangs_forever.ogg?dl=0

Here is a link to a minimal example showing the error, assuming the above ogg file is downloaded into the working directory: https://gist.github.com/jamiltron/ada86682674717ab0bd9e0f2f90343dc

The above fails if you remove the stream and change the .openFromStream(stream) to .openFromFile("hangs_forever.ogg"). This file plays fine in every media player I've tried, and also loads and plays using another client solution.

This happens on Windows 10 with both the 32-bit Visual Studio 2015 prebuilt, as well as a version built from source containing the following patch to libvorbis: https://trac.xiph.org/ticket/2327

Any help is greatly appreciated!
Title: Re: Loading certain ogg files in SFML 2.4.2 causes program to hang forever.
Post by: eXpl0it3r on June 16, 2017, 08:33:46 am
The above fails if you remove the stream and change the .openFromStream(stream) to .openFromFile("hangs_forever.ogg").
I can't confirm this. It plays fine when I open it with sf::Music directly (using MinGW).

creating stream from ./hangs_forever.ogg
opening from stream
playing...
done playing ./hangs_forever.ogg

Quickly firing up the debugger and stepping through the SFML code, it seems like the OGG file is for some reason throwing off the FLAC decoder. The way SFML has implemented the audio format detection is that it would pass it to the various decoder libraries and let them judge whether it's a format they can read.
For some reason FLAC__stream_decoder_process_until_end_of_metadata never returns when you pass it your stream.

Currently I've something I need to take care of, so I can't further debug the issue, but I think it should be fairly easy to pick up where I left off and dig down where in your stream class starts to hang.
And/or what the FLAC decoder expects the stream to return.
Title: Re: Loading certain ogg files in SFML 2.4.2 causes program to hang forever.
Post by: jamiltron on June 16, 2017, 08:48:43 am
Thanks for taking a look at this!

I can't confirm this. It plays fine when I open it with sf::Music directly (using MinGW).

Well its failing using sf::Music openFromFile (everything related to streams and anything else having to do with the file nixed right out) on the 32bit version of Visual Studio 2015, using the version downloaded from the SFML page in Windows 10, with the libs/includes/dlls all set up pretty standard, nothing fancy or custom.

Quickly firing up the debugger and stepping through the SFML code, it seems like the OGG file is for some reason throwing off the FLAC decoder.

Why would it throw off the FLAC decoder when my file is encoded via vorbis?

$ oggz codecs hangs_forever.ogg
> vorbis

The way SFML has implemented the audio format detection is that it would pass it to the various decoder libraries and let them judge whether it's a format they can read.

Is there an easy way I can override this and force it to use vorbis?
Title: Re: Loading certain ogg files in SFML 2.4.2 causes program to hang forever.
Post by: eXpl0it3r on June 16, 2017, 09:05:40 am
If you have just data (stream), then you can't tell what codec has been used, so you'll need to test all the different decoders and see if one of them detects the format of the data.
SFML simply iterates (https://github.com/SFML/SFML/blob/master/src/SFML/Audio/SoundFileFactory.cpp#L79) through all sound readers and does a call to the check function.

If you want to "force" vorbis, you could change the registered reader order or remove all readers from registering. But that's just a workaround not a solution.
Title: Re: Loading certain ogg files in SFML 2.4.2 causes program to hang forever.
Post by: jamiltron on June 16, 2017, 09:39:01 am
Ok, I'll try stepping through this to see why the Flac decoder is getting hung up and see if there's something I can do with my InputStream to ensure that its correctly identified as Vorbis. Thanks for the help!