decoder/dsdlib: use decoder_skip()
Reduce duplicate code.
This commit is contained in:
parent
8759bc1b41
commit
552af5455e
@ -66,19 +66,7 @@ dsdlib_skip_to(Decoder *decoder, InputStream &is,
|
|||||||
if (uint64_t(is.GetOffset()) > offset)
|
if (uint64_t(is.GetOffset()) > offset)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
char buffer[8192];
|
return dsdlib_skip(decoder, is, offset - is.GetOffset());
|
||||||
while (uint64_t(is.GetOffset()) < offset) {
|
|
||||||
size_t length = sizeof(buffer);
|
|
||||||
if (offset - is.GetOffset() < (uint64_t)length)
|
|
||||||
length = offset - is.GetOffset();
|
|
||||||
|
|
||||||
size_t nbytes = decoder_read(decoder, is, buffer, length);
|
|
||||||
if (nbytes == 0)
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert(uint64_t(is.GetOffset()) == offset);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,20 +82,12 @@ dsdlib_skip(Decoder *decoder, InputStream &is,
|
|||||||
if (is.IsSeekable())
|
if (is.IsSeekable())
|
||||||
return is.Seek(is.GetOffset() + delta, IgnoreError());
|
return is.Seek(is.GetOffset() + delta, IgnoreError());
|
||||||
|
|
||||||
char buffer[8192];
|
if (delta > 1024 * 1024)
|
||||||
while (delta > 0) {
|
/* don't skip more than one megabyte; it would be too
|
||||||
size_t length = sizeof(buffer);
|
expensive */
|
||||||
if ((uint64_t)length > delta)
|
return false;
|
||||||
length = delta;
|
|
||||||
|
|
||||||
size_t nbytes = decoder_read(decoder, is, buffer, length);
|
return decoder_skip(decoder, is, delta);
|
||||||
if (nbytes == 0)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
delta -= nbytes;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_ID3TAG
|
#ifdef HAVE_ID3TAG
|
||||||
|
Loading…
Reference in New Issue
Block a user