add argument to test_seeking to accept #samples in the input, to better evaluate whether or not seeking near/past end-of-stream

This commit is contained in:
Josh Coalson 2006-11-16 01:22:33 +00:00
parent 036e9fd046
commit f8d544f2b0
2 changed files with 24 additions and 15 deletions

View File

@ -163,7 +163,7 @@ static void error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDeco
* 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)
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;
DecoderClientData decoder_client_data;
@ -219,6 +219,9 @@ static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t fi
#endif
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 */
/* @@@ for is_ogg we should get it from last page's granulepos */
if(n == 0) {
@ -263,12 +266,12 @@ static FLAC__bool seek_barrage(FLAC__bool is_ogg, const char *filename, off_t fi
#endif
fflush(stdout);
if(!FLAC__stream_decoder_seek_absolute(decoder, pos)) {
if(pos < (FLAC__uint64)n && decoder_client_data.total_samples != 0)
return die_s_("FLAC__stream_decoder_seek_absolute() FAILED", decoder);
else if(decoder_client_data.total_samples == 0)
if(pos >= (FLAC__uint64)n)
printf("seek past end failed as expected... ");
else if(decoder_client_data.total_samples == 0 && total_samples <= 0)
printf("seek failed, assuming it was past EOF... ");
else
printf("seek past end failed as expected... ");
return die_s_("FLAC__stream_decoder_seek_absolute() FAILED", decoder);
if(!FLAC__stream_decoder_flush(decoder))
return die_s_("FLAC__stream_decoder_flush() FAILED", decoder);
}
@ -310,11 +313,12 @@ int main(int argc, char *argv[])
{
const char *filename;
unsigned count = 0, read_mode;
FLAC__int64 samples = -1;
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);
return 1;
}
@ -323,6 +327,8 @@ int main(int argc, char *argv[])
if (argc > 2)
count = strtoul(argv[2], 0, 10);
if (argc > 3)
samples = strtoull(argv[3], 0, 10);
if (count < 30)
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[])
FLAC__bool ok;
if (strlen(filename) > 4 && 0 == strcmp(filename+strlen(filename)-4, ".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
fprintf(stderr, "ERROR: Ogg FLAC not supported\n");
ok = false;
#endif
}
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)
return 2;

View File

@ -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=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
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"
fi
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"
fi
@ -106,12 +109,12 @@ for suffix in '' '-s' ; do
fi
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"
fi
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"
fi
done
@ -124,12 +127,12 @@ if [ $has_ogg = "yes" ] ; then
# seek tables are not used in Ogg FLAC
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"
fi
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"
fi