Commit b1c3798d authored by Josh Coalson's avatar Josh Coalson
Browse files

add multiple read modes to simulate different seeking/playback patterns

parent f7f7490e
...@@ -154,7 +154,12 @@ static void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDeco ...@@ -154,7 +154,12 @@ static void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDeco
} }
} }
static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t filesize, unsigned count) /* read mode:
* 0 - no read after seek
* 1 - read 2 frames
* 2 - read until end
*/
static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t filesize, unsigned count, unsigned read_mode)
{ {
FLAC__StreamDecoder *decoder; FLAC__StreamDecoder *decoder;
DecoderClientData decoder_client_data; DecoderClientData decoder_client_data;
...@@ -167,7 +172,7 @@ static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t fi ...@@ -167,7 +172,7 @@ static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t fi
decoder_client_data.ignore_errors = false; decoder_client_data.ignore_errors = false;
decoder_client_data.error_occurred = false; decoder_client_data.error_occurred = false;
printf("\n+++ seek test: FLAC__StreamDecoder (%s FLAC)\n\n", is_ogg? "Ogg":"native"); printf("\n+++ seek test: FLAC__StreamDecoder (%s FLAC, read_mode=%u)\n\n", is_ogg? "Ogg":"native", read_mode);
decoder = FLAC__stream_decoder_new(); decoder = FLAC__stream_decoder_new();
if(0 == decoder) if(0 == decoder)
...@@ -255,7 +260,7 @@ static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t fi ...@@ -255,7 +260,7 @@ static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t fi
if(!FLAC__stream_decoder_flush(decoder)) if(!FLAC__stream_decoder_flush(decoder))
return die_s_("FLAC__stream_decoder_flush() FAILED", decoder); return die_s_("FLAC__stream_decoder_flush() FAILED", decoder);
} }
else { else if(read_mode == 1) {
printf("decode_frame... "); printf("decode_frame... ");
fflush(stdout); fflush(stdout);
if(!FLAC__stream_decoder_process_single(decoder)) if(!FLAC__stream_decoder_process_single(decoder))
...@@ -266,6 +271,14 @@ static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t fi ...@@ -266,6 +271,14 @@ static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t fi
if(!FLAC__stream_decoder_process_single(decoder)) if(!FLAC__stream_decoder_process_single(decoder))
return die_s_("FLAC__stream_decoder_process_single() FAILED", decoder); return die_s_("FLAC__stream_decoder_process_single() FAILED", decoder);
} }
else if(read_mode == 2) {
printf("decode_all... ");
fflush(stdout);
decoder_client_data.quiet = true;
if(!FLAC__stream_decoder_process_until_end_of_stream(decoder))
return die_s_("FLAC__stream_decoder_process_until_end_of_stream() FAILED", decoder);
decoder_client_data.quiet = false;
}
printf("OK\n"); printf("OK\n");
fflush(stdout); fflush(stdout);
...@@ -284,7 +297,7 @@ static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t fi ...@@ -284,7 +297,7 @@ static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t fi
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
const char *filename; const char *filename;
unsigned count = 0; unsigned count = 0, read_mode;
off_t filesize; off_t filesize;
static const char * const usage = "usage: test_seeking file.flac [#seeks]\n"; static const char * const usage = "usage: test_seeking file.flac [#seeks]\n";
...@@ -324,19 +337,22 @@ int main(int argc, char *argv[]) ...@@ -324,19 +337,22 @@ int main(int argc, char *argv[])
(void) signal(SIGINT, our_sigint_handler_); (void) signal(SIGINT, our_sigint_handler_);
{ for (read_mode = 0; read_mode <= 2; read_mode++) {
FLAC__bool ok; FLAC__bool ok;
if (strlen(filename) > 4 && 0 == strcmp(filename+strlen(filename)-4, ".ogg")) { if (strlen(filename) > 4 && 0 == strcmp(filename+strlen(filename)-4, ".ogg")) {
#ifdef FLAC__HAS_OGG #ifdef FLAC__HAS_OGG
ok = seek_barrage(/*is_ogg=*/true, filename, filesize, count); ok = seek_barrage(/*is_ogg=*/true, filename, filesize, count, read_mode);
#else #else
fprintf(stderr, "ERROR: Ogg FLAC not supported\n"); fprintf(stderr, "ERROR: Ogg FLAC not supported\n");
ok = false; ok = false;
#endif #endif
} }
else { else {
ok = seek_barrage(/*is_ogg=*/false, filename, filesize, count); ok = seek_barrage(/*is_ogg=*/false, filename, filesize, count, read_mode);
} }
return ok? 0 : 2; if (!ok)
return 2;
} }
return 0;
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment