diff options
author | Alexey Yakovenko <wakeroid@gmail.com> | 2009-07-19 13:50:36 +0200 |
---|---|---|
committer | Alexey Yakovenko <wakeroid@gmail.com> | 2009-07-19 13:50:36 +0200 |
commit | e89e2345859798fa596e01bd9460a63c92785f49 (patch) | |
tree | bf1f0c36b9ded842a43e6fb09a764dce9ce0311b /cflac.c | |
parent | b41446ad033a52ed24176f9ba01362e3648e97ee (diff) |
better format checking before adding to playlist,
more file types supported,
bad files are skipped when attempted to be played
Diffstat (limited to 'cflac.c')
-rw-r--r-- | cflac.c | 51 |
1 files changed, 49 insertions, 2 deletions
@@ -61,6 +61,9 @@ cflac_error_callback(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErro fprintf(stderr, "cflac: got error callback: %s\n", FLAC__StreamDecoderErrorStatusString[status]); } +void +cflac_free (void); + int cflac_init (const char *fname, int track, float start, float end) { FLAC__StreamDecoderInitStatus status; @@ -71,7 +74,19 @@ cflac_init (const char *fname, int track, float start, float end) { } FLAC__stream_decoder_set_md5_checking(decoder, 0); status = FLAC__stream_decoder_init_file(decoder, fname, cflac_write_callback, cflac_metadata_callback, cflac_error_callback, NULL); - FLAC__stream_decoder_process_until_end_of_metadata (decoder); + if (status != FLAC__STREAM_DECODER_INIT_STATUS_OK) { + cflac_free (); + return -1; + } + cflac.info.samplesPerSecond = -1; + if (!FLAC__stream_decoder_process_until_end_of_metadata (decoder)) { + cflac_free (); + return -1; + } + if (cflac.info.samplesPerSecond == -1) { // not a FLAC stream + cflac_free (); + return -1; + } timestart = start; timeend = end; if (timeend > timestart || timeend < 0) { @@ -171,6 +186,28 @@ cflac_add (const char *fname) { } } + FLAC__StreamDecoderInitStatus status; + decoder = FLAC__stream_decoder_new(); + if (!decoder) { + printf ("FLAC__stream_decoder_new failed\n"); + return -1; + } + FLAC__stream_decoder_set_md5_checking(decoder, 0); + status = FLAC__stream_decoder_init_file(decoder, fname, cflac_write_callback, cflac_metadata_callback, cflac_error_callback, NULL); + if (status != FLAC__STREAM_DECODER_INIT_STATUS_OK) { + cflac_free (); + return -1; + } + cflac.info.samplesPerSecond = -1; + if (!FLAC__stream_decoder_process_until_end_of_metadata (decoder)) { + cflac_free (); + return -1; + } + if (cflac.info.samplesPerSecond == -1) { // not a FLAC stream + cflac_free (); + return -1; + } + cflac_free (); playItem_t *it = malloc (sizeof (playItem_t)); memset (it, 0, sizeof (playItem_t)); it->codec = &cflac; @@ -183,10 +220,20 @@ cflac_add (const char *fname) { return 0; } +static const char * exts[]= +{ + "flac","ogg",NULL +}; + +const char **cflac_getexts (void) { + return exts; +} + codec_t cflac = { .init = cflac_init, .free = cflac_free, .read = cflac_read, .seek = cflac_seek, - .add = cflac_add + .add = cflac_add, + .getexts = cflac_getexts }; |