DecoderAPI: add function decoder_read_full()
Move code from the "mad" plugin.
This commit is contained in:
parent
bf7417981f
commit
0759421d11
@ -292,6 +292,24 @@ decoder_read(Decoder *decoder,
|
|||||||
return nbytes;
|
return nbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
decoder_read_full(Decoder *decoder, InputStream &is,
|
||||||
|
void *_buffer, size_t size)
|
||||||
|
{
|
||||||
|
uint8_t *buffer = (uint8_t *)_buffer;
|
||||||
|
|
||||||
|
while (size > 0) {
|
||||||
|
size_t nbytes = decoder_read(decoder, is, buffer, size);
|
||||||
|
if (nbytes == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
buffer += nbytes;
|
||||||
|
size -= nbytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
decoder_skip(Decoder *decoder, InputStream &is, size_t size)
|
decoder_skip(Decoder *decoder, InputStream &is, size_t size)
|
||||||
{
|
{
|
||||||
|
@ -112,6 +112,17 @@ decoder_read(Decoder &decoder, InputStream &is,
|
|||||||
return decoder_read(&decoder, is, buffer, length);
|
return decoder_read(&decoder, is, buffer, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Blocking read from the input stream. Attempts to fill the buffer
|
||||||
|
* completely; there is no partial result.
|
||||||
|
*
|
||||||
|
* @return true on success, false on error or command or not enough
|
||||||
|
* data
|
||||||
|
*/
|
||||||
|
bool
|
||||||
|
decoder_read_full(Decoder *decoder, InputStream &is,
|
||||||
|
void *buffer, size_t size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Skip data on the #InputStream.
|
* Skip data on the #InputStream.
|
||||||
*
|
*
|
||||||
|
@ -353,18 +353,8 @@ MadDecoder::ParseId3(size_t tagsize, Tag **mpd_tag)
|
|||||||
memcpy(allocated, stream.this_frame, count);
|
memcpy(allocated, stream.this_frame, count);
|
||||||
mad_stream_skip(&(stream), count);
|
mad_stream_skip(&(stream), count);
|
||||||
|
|
||||||
while (count < tagsize) {
|
if (!decoder_read_full(decoder, input_stream,
|
||||||
size_t len;
|
allocated + count, tagsize - count)) {
|
||||||
|
|
||||||
len = decoder_read(decoder, input_stream,
|
|
||||||
allocated + count, tagsize - count);
|
|
||||||
if (len == 0)
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
count += len;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count != tagsize) {
|
|
||||||
LogDebug(mad_domain, "error parsing ID3 tag");
|
LogDebug(mad_domain, "error parsing ID3 tag");
|
||||||
g_free(allocated);
|
g_free(allocated);
|
||||||
return;
|
return;
|
||||||
|
@ -65,6 +65,24 @@ decoder_read(gcc_unused Decoder *decoder,
|
|||||||
return is.LockRead(buffer, length, IgnoreError());
|
return is.LockRead(buffer, length, IgnoreError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
decoder_read_full(Decoder *decoder, InputStream &is,
|
||||||
|
void *_buffer, size_t size)
|
||||||
|
{
|
||||||
|
uint8_t *buffer = (uint8_t *)_buffer;
|
||||||
|
|
||||||
|
while (size > 0) {
|
||||||
|
size_t nbytes = decoder_read(decoder, is, buffer, size);
|
||||||
|
if (nbytes == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
buffer += nbytes;
|
||||||
|
size -= nbytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
decoder_skip(Decoder *decoder, InputStream &is, size_t size)
|
decoder_skip(Decoder *decoder, InputStream &is, size_t size)
|
||||||
{
|
{
|
||||||
|
@ -101,6 +101,24 @@ decoder_read(gcc_unused Decoder *decoder,
|
|||||||
return is.LockRead(buffer, length, IgnoreError());
|
return is.LockRead(buffer, length, IgnoreError());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
decoder_read_full(Decoder *decoder, InputStream &is,
|
||||||
|
void *_buffer, size_t size)
|
||||||
|
{
|
||||||
|
uint8_t *buffer = (uint8_t *)_buffer;
|
||||||
|
|
||||||
|
while (size > 0) {
|
||||||
|
size_t nbytes = decoder_read(decoder, is, buffer, size);
|
||||||
|
if (nbytes == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
buffer += nbytes;
|
||||||
|
size -= nbytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
decoder_skip(Decoder *decoder, InputStream &is, size_t size)
|
decoder_skip(Decoder *decoder, InputStream &is, size_t size)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user