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

add argument to test_seeking to accept #samples in the input, to better...

add argument to test_seeking to accept #samples in the input, to better evaluate whether or not seeking near/past end-of-stream
parent 036e9fd0
...@@ -163,7 +163,7 @@ static void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDeco ...@@ -163,7 +163,7 @@ static void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDeco
* 1 - read 2 frames * 1 - read 2 frames
* 2 - read until end * 2 - read until end
*/ */
static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t filesize, unsigned count, unsigned read_mode) static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t filesize, unsigned count, FLAC__int64 total_samples, unsigned read_mode)
{ {
FLAC__StreamDecoder *decoder; FLAC__StreamDecoder *decoder;
DecoderClientData decoder_client_data; DecoderClientData decoder_client_data;
...@@ -219,6 +219,9 @@ static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t fi ...@@ -219,6 +219,9 @@ static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t fi
#endif #endif
n = (long int)decoder_client_data.total_samples; n = (long int)decoder_client_data.total_samples;
if(n == 0 && total_samples >= 0)
n = (long int)total_samples;
/* if we don't have a total samples count, just guess based on the file size */ /* if we don't have a total samples count, just guess based on the file size */
/* @@@ for is_ogg we should get it from last page's granulepos */ /* @@@ for is_ogg we should get it from last page's granulepos */
if(n == 0) { if(n == 0) {
...@@ -263,12 +266,12 @@ static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t fi ...@@ -263,12 +266,12 @@ static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t fi
#endif #endif
fflush(stdout); fflush(stdout);
if(!FLAC__stream_decoder_seek_absolute(decoder, pos)) { if(!FLAC__stream_decoder_seek_absolute(decoder, pos)) {
if(pos < (FLAC__uint64)n && decoder_client_data.total_samples != 0) if(pos >= (FLAC__uint64)n)
return die_s_("FLAC__stream_decoder_seek_absolute() FAILED", decoder); printf("seek past end failed as expected... ");
else if(decoder_client_data.total_samples == 0) else if(decoder_client_data.total_samples == 0 && total_samples <= 0)
printf("seek failed, assuming it was past EOF... "); printf("seek failed, assuming it was past EOF... ");
else else
printf("seek past end failed as expected... "); return die_s_("FLAC__stream_decoder_seek_absolute() FAILED", decoder);
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);
} }
...@@ -310,11 +313,12 @@ int main(int argc, char *argv[]) ...@@ -310,11 +313,12 @@ int main(int argc, char *argv[])
{ {
const char *filename; const char *filename;
unsigned count = 0, read_mode; unsigned count = 0, read_mode;
FLAC__int64 samples = -1;
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] [#samples-in-file.flac]\n";
if (argc < 2 || argc > 3) { if (argc < 2 || argc > 4) {
fprintf(stderr, usage); fprintf(stderr, usage);
return 1; return 1;
} }
...@@ -323,6 +327,8 @@ int main(int argc, char *argv[]) ...@@ -323,6 +327,8 @@ int main(int argc, char *argv[])
if (argc > 2) if (argc > 2)
count = strtoul(argv[2], 0, 10); count = strtoul(argv[2], 0, 10);
if (argc > 3)
samples = strtoull(argv[3], 0, 10);
if (count < 30) if (count < 30)
fprintf(stderr, "WARNING: random seeks don't kick in until after 30 preprogrammed ones\n"); fprintf(stderr, "WARNING: random seeks don't kick in until after 30 preprogrammed ones\n");
...@@ -353,14 +359,14 @@ int main(int argc, char *argv[]) ...@@ -353,14 +359,14 @@ int main(int argc, char *argv[])
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, read_mode); ok = seek_barrage(/*is_ogg=*/true, filename, filesize, count, samples, 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, read_mode); ok = seek_barrage(/*is_ogg=*/false, filename, filesize, count, samples, read_mode);
} }
if (!ok) if (!ok)
return 2; return 2;
......
...@@ -89,14 +89,17 @@ run_flac --verify --force --silent --force-raw-format --endian=big --sign=signed ...@@ -89,14 +89,17 @@ run_flac --verify --force --silent --force-raw-format --endian=big --sign=signed
run_flac --verify --force --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=8 --channels=1 --blocksize=576 -S10x --output-name=tiny-s.flac noise8m32.raw || die "ERROR generating FLAC file" run_flac --verify --force --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=8 --channels=1 --blocksize=576 -S10x --output-name=tiny-s.flac noise8m32.raw || die "ERROR generating FLAC file"
run_flac --verify --force --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=16 --channels=2 --blocksize=576 -S10x --output-name=small-s.flac noise.raw || die "ERROR generating FLAC file" run_flac --verify --force --silent --force-raw-format --endian=big --sign=signed --sample-rate=44100 --bps=16 --channels=2 --blocksize=576 -S10x --output-name=small-s.flac noise.raw || die "ERROR generating FLAC file"
tiny_samples=`metaflac --show-total-samples tiny.flac`
small_samples=`metaflac --show-total-samples small.flac`
for suffix in '' '-s' ; do for suffix in '' '-s' ; do
echo "testing tiny$suffix.flac:" echo "testing tiny$suffix.flac:"
if run_test_seeking tiny$suffix.flac 100 ; then : ; else if run_test_seeking tiny$suffix.flac 100 $tiny_samples ; then : ; else
die "ERROR: during test_seeking" die "ERROR: during test_seeking"
fi fi
echo "testing small$suffix.flac:" echo "testing small$suffix.flac:"
if run_test_seeking small$suffix.flac 1000 ; then : ; else if run_test_seeking small$suffix.flac 1000 $small_samples ; then : ; else
die "ERROR: during test_seeking" die "ERROR: during test_seeking"
fi fi
...@@ -106,12 +109,12 @@ for suffix in '' '-s' ; do ...@@ -106,12 +109,12 @@ for suffix in '' '-s' ; do
fi fi
echo "testing tiny$suffix.flac with total_samples=0:" echo "testing tiny$suffix.flac with total_samples=0:"
if run_test_seeking tiny$suffix.flac 100 ; then : ; else if run_test_seeking tiny$suffix.flac 100 $tiny_samples ; then : ; else
die "ERROR: during test_seeking" die "ERROR: during test_seeking"
fi fi
echo "testing small$suffix.flac with total_samples=0:" echo "testing small$suffix.flac with total_samples=0:"
if run_test_seeking small$suffix.flac 1000 ; then : ; else if run_test_seeking small$suffix.flac 1000 $small_samples ; then : ; else
die "ERROR: during test_seeking" die "ERROR: during test_seeking"
fi fi
done done
...@@ -124,12 +127,12 @@ if [ $has_ogg = "yes" ] ; then ...@@ -124,12 +127,12 @@ if [ $has_ogg = "yes" ] ; then
# seek tables are not used in Ogg FLAC # seek tables are not used in Ogg FLAC
echo "testing tiny.ogg:" echo "testing tiny.ogg:"
if run_test_seeking tiny.ogg 100 ; then : ; else if run_test_seeking tiny.ogg 100 $tiny_samples ; then : ; else
die "ERROR: during test_seeking" die "ERROR: during test_seeking"
fi fi
echo "testing small.ogg:" echo "testing small.ogg:"
if run_test_seeking small.ogg 1000 ; then : ; else if run_test_seeking small.ogg 1000 $small_samples ; then : ; else
die "ERROR: during test_seeking" die "ERROR: during test_seeking"
fi fi
......
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