mirror of https://github.com/xiph/flac
Enable level 0 metadata interface to read Ogg files too
This commit is contained in:
parent
a9306bb390
commit
3adb645559
|
@ -158,6 +158,8 @@ static FLAC__StreamMetadata *get_one_metadata_block_(const char *filename, FLAC_
|
|||
{
|
||||
level0_client_data cd;
|
||||
FLAC__StreamDecoder *decoder;
|
||||
FILE *file;
|
||||
FLAC__bool open_as_ogg = false;
|
||||
|
||||
FLAC__ASSERT(0 != filename);
|
||||
|
||||
|
@ -173,10 +175,29 @@ static FLAC__StreamMetadata *get_one_metadata_block_(const char *filename, FLAC_
|
|||
FLAC__stream_decoder_set_metadata_ignore_all(decoder);
|
||||
FLAC__stream_decoder_set_metadata_respond(decoder, type);
|
||||
|
||||
if(FLAC__stream_decoder_init_file(decoder, filename, write_callback_, metadata_callback_, error_callback_, &cd) != FLAC__STREAM_DECODER_INIT_STATUS_OK || cd.got_error) {
|
||||
(void)FLAC__stream_decoder_finish(decoder);
|
||||
FLAC__stream_decoder_delete(decoder);
|
||||
return 0;
|
||||
/* Try to open the file and determine whether it is Ogg */
|
||||
if(0 != (file = flac_fopen(filename, "rb"))) {
|
||||
FLAC__byte signature[4];
|
||||
if(fread(&signature, 1, 4, file) == 4) {
|
||||
if(memcmp(&signature,"OggS",4) == 0)
|
||||
open_as_ogg = true;
|
||||
}
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
if(!open_as_ogg) {
|
||||
if(FLAC__stream_decoder_init_file(decoder, filename, write_callback_, metadata_callback_, error_callback_, &cd) != FLAC__STREAM_DECODER_INIT_STATUS_OK || cd.got_error) {
|
||||
(void)FLAC__stream_decoder_finish(decoder);
|
||||
FLAC__stream_decoder_delete(decoder);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(FLAC__stream_decoder_init_ogg_file(decoder, filename, write_callback_, metadata_callback_, error_callback_, &cd) != FLAC__STREAM_DECODER_INIT_STATUS_OK || cd.got_error) {
|
||||
(void)FLAC__stream_decoder_finish(decoder);
|
||||
FLAC__stream_decoder_delete(decoder);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder) || cd.got_error) {
|
||||
|
|
Loading…
Reference in New Issue