Shayne Wissler <wissler at gmail.com> wrote:> I have a program that is given a random file and needs to determine > whether it is Vorbis or FLAC. For Vorbis, there are various places > where I can infer that I have a bad stream. But for FLAC, when I call > either FLAC__stream_decoder_process_until_end_of_metadata or > FLAC__stream_decoder_process_single, it searches the entire file > before giving up. I'd like it to stop searching as soon as it loses > sync, or find some better way to detect the file type without scanning > the whole file. Any tips on the best way to do that?Perhaps I have misunderstood your problem, but is this not what magic numbers are for? For Ogg Vorbis and Ogg FLAC, see: http://wiki.xiph.org/index.php/MIMETypesCodecs#Codecs_Parameter For Native FLAC, see: http://flac.sourceforge.net/documentation_format_overview.html Regards, Martin -- Martin J Leese E-mail: martin.leese stanfordalumni.org Web: http://members.tripod.com/martin_leese/
On Tue, Oct 6, 2009 at 1:57 PM, Martin Leese <martin.leese at stanfordalumni.org> wrote:> Perhaps I have misunderstood your problem, > but is this not what magic numbers are for?I know there is a "fLaC" at the beginning of the FLAC file, and I can easily look for that, but my design sense was that it's better to have the FLAC API vet the file type rather than having my code do it.> For Ogg Vorbis and Ogg FLAC, see: > http://wiki.xiph.org/index.php/MIMETypesCodecs#Codecs_ParameterIsn't this meta information used in e.g. email and HTML? I don't think it will help vet a standalone file. In any case, I already have a solution with the OGG API's. Shayne
On Tue, Oct 6, 2009 at 2:11 PM, Shayne Wissler <wissler at gmail.com> wrote:> On Tue, Oct 6, 2009 at 1:57 PM, Martin Leese > <martin.leese at stanfordalumni.org> wrote:...>> For Ogg Vorbis and Ogg FLAC, see: >> http://wiki.xiph.org/index.php/MIMETypesCodecs#Codecs_Parameter > > Isn't this meta information used in e.g. email and HTML? I don't think > it will help vet a standalone file. In any case, I already have a > solution with the OGG API's.I was pointing you towards the Codec Identifier column (which are stream magic numbers). Regards, Martin -- Martin J Leese E-mail: martin.leese stanfordalumni.org Web: http://members.tripod.com/martin_leese/
I had the same issue, and decided to just write my own code. If you're really set on using the API, then perhaps you should take a look around. The source code is available, and maybe you can find the routine where the magic number is checked. I have a bad feeling that this might not be a public API, once you find it, but there's a chance. Besides, at least you can model you own code after the official code if there isn't a public API. In any event, I don't suggest calling an undocumented API entry point, even if you find it. Sorry for the non-answer, especially since I never looked into this myself, but you do have more options with open-source API than you do with other API. Brian Willoughby Sound Consulting On Oct 6, 2009, at 13:11, Shayne Wissler wrote:> I know there is a "fLaC" at the beginning of the FLAC file, and I can > easily look for that, but my design sense was that it's better to have > the FLAC API vet the file type rather than having my code do it.