Merge branch 'v0.21.x' into master
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
size_t
|
||||
decoder_read(DecoderClient *client,
|
||||
InputStream &is,
|
||||
void *buffer, size_t length)
|
||||
void *buffer, size_t length) noexcept
|
||||
{
|
||||
assert(buffer != nullptr);
|
||||
|
||||
@@ -42,9 +42,30 @@ decoder_read(DecoderClient *client,
|
||||
}
|
||||
}
|
||||
|
||||
size_t
|
||||
decoder_read_much(DecoderClient *client, InputStream &is,
|
||||
void *_buffer, size_t size) noexcept
|
||||
{
|
||||
uint8_t *buffer = (uint8_t *)_buffer;
|
||||
|
||||
size_t total = 0;
|
||||
|
||||
while (size > 0 && !is.LockIsEOF()) {
|
||||
size_t nbytes = decoder_read(client, is, buffer, size);
|
||||
if (nbytes == 0)
|
||||
return false;
|
||||
|
||||
total += nbytes;
|
||||
buffer += nbytes;
|
||||
size -= nbytes;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
bool
|
||||
decoder_read_full(DecoderClient *client, InputStream &is,
|
||||
void *_buffer, size_t size)
|
||||
void *_buffer, size_t size) noexcept
|
||||
{
|
||||
auto *buffer = (uint8_t *)_buffer;
|
||||
|
||||
@@ -61,7 +82,7 @@ decoder_read_full(DecoderClient *client, InputStream &is,
|
||||
}
|
||||
|
||||
bool
|
||||
decoder_skip(DecoderClient *client, InputStream &is, size_t size)
|
||||
decoder_skip(DecoderClient *client, InputStream &is, size_t size) noexcept
|
||||
{
|
||||
while (size > 0) {
|
||||
char buffer[1024];
|
||||
|
@@ -63,15 +63,27 @@ class StopDecoder {};
|
||||
*/
|
||||
size_t
|
||||
decoder_read(DecoderClient *decoder, InputStream &is,
|
||||
void *buffer, size_t length);
|
||||
void *buffer, size_t length) noexcept;
|
||||
|
||||
static inline size_t
|
||||
decoder_read(DecoderClient &decoder, InputStream &is,
|
||||
void *buffer, size_t length)
|
||||
void *buffer, size_t length) noexcept
|
||||
{
|
||||
return decoder_read(&decoder, is, buffer, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Blocking read from the input stream. Attempts to fill the buffer
|
||||
* as much as possible, until either end-of-file is reached or an
|
||||
* error occurs.
|
||||
*
|
||||
* @return the number of bytes read, or 0 if one of the following
|
||||
* occurs: end of file; error; command (like SEEK or STOP).
|
||||
*/
|
||||
size_t
|
||||
decoder_read_much(DecoderClient *decoder, InputStream &is,
|
||||
void *buffer, size_t size) noexcept;
|
||||
|
||||
/**
|
||||
* Blocking read from the input stream. Attempts to fill the buffer
|
||||
* completely; there is no partial result.
|
||||
@@ -81,7 +93,7 @@ decoder_read(DecoderClient &decoder, InputStream &is,
|
||||
*/
|
||||
bool
|
||||
decoder_read_full(DecoderClient *decoder, InputStream &is,
|
||||
void *buffer, size_t size);
|
||||
void *buffer, size_t size) noexcept;
|
||||
|
||||
/**
|
||||
* Skip data on the #InputStream.
|
||||
@@ -89,6 +101,6 @@ decoder_read_full(DecoderClient *decoder, InputStream &is,
|
||||
* @return true on success, false on error or command
|
||||
*/
|
||||
bool
|
||||
decoder_skip(DecoderClient *decoder, InputStream &is, size_t size);
|
||||
decoder_skip(DecoderClient *decoder, InputStream &is, size_t size) noexcept;
|
||||
|
||||
#endif
|
||||
|
@@ -47,9 +47,7 @@ struct SndfileInputStream {
|
||||
size_t Read(void *buffer, size_t size) {
|
||||
/* libsndfile chokes on partial reads; therefore
|
||||
always force full reads */
|
||||
return decoder_read_full(client, is, buffer, size)
|
||||
? size
|
||||
: 0;
|
||||
return decoder_read_much(client, is, buffer, size);
|
||||
}
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user