Commit cb336ff6 authored by Max Kellermann's avatar Max Kellermann

DecoderAPI: add function decoder_skip()

Move code from the "mad" plugin.
parent e2e5433b
...@@ -306,6 +306,22 @@ decoder_read(Decoder *decoder, ...@@ -306,6 +306,22 @@ decoder_read(Decoder *decoder,
return nbytes; return nbytes;
} }
bool
decoder_skip(Decoder *decoder, InputStream &is, size_t size)
{
while (size > 0) {
char buffer[1024];
size_t nbytes = decoder_read(decoder, is, buffer,
std::min(sizeof(buffer), size));
if (nbytes == 0)
return false;
size -= nbytes;
}
return true;
}
void void
decoder_timestamp(Decoder &decoder, double t) decoder_timestamp(Decoder &decoder, double t)
{ {
......
...@@ -117,6 +117,14 @@ decoder_read(Decoder &decoder, InputStream &is, ...@@ -117,6 +117,14 @@ decoder_read(Decoder &decoder, InputStream &is,
} }
/** /**
* Skip data on the #InputStream.
*
* @return true on success, false on error or command
*/
bool
decoder_skip(Decoder *decoder, InputStream &is, size_t size);
/**
* Sets the time stamp for the next data chunk [seconds]. The MPD * Sets the time stamp for the next data chunk [seconds]. The MPD
* core automatically counts it up, and a decoder plugin only needs to * core automatically counts it up, and a decoder plugin only needs to
* use this function if it thinks that adding to the time stamp based * use this function if it thinks that adding to the time stamp based
......
...@@ -413,20 +413,7 @@ MadDecoder::ParseId3(size_t tagsize, Tag **mpd_tag) ...@@ -413,20 +413,7 @@ MadDecoder::ParseId3(size_t tagsize, Tag **mpd_tag)
mad_stream_skip(&stream, tagsize); mad_stream_skip(&stream, tagsize);
} else { } else {
mad_stream_skip(&stream, count); mad_stream_skip(&stream, count);
decoder_skip(decoder, input_stream, tagsize - count);
while (count < tagsize) {
size_t len = tagsize - count;
char ignored[1024];
if (len > sizeof(ignored))
len = sizeof(ignored);
len = decoder_read(decoder, input_stream,
ignored, len);
if (len == 0)
break;
else
count += len;
}
} }
#endif #endif
} }
......
...@@ -65,6 +65,22 @@ decoder_read(gcc_unused Decoder *decoder, ...@@ -65,6 +65,22 @@ decoder_read(gcc_unused Decoder *decoder,
return is.LockRead(buffer, length, IgnoreError()); return is.LockRead(buffer, length, IgnoreError());
} }
bool
decoder_skip(Decoder *decoder, InputStream &is, size_t size)
{
while (size > 0) {
char buffer[1024];
size_t nbytes = decoder_read(decoder, is, buffer,
std::min(sizeof(buffer), size));
if (nbytes == 0)
return false;
size -= nbytes;
}
return true;
}
void void
decoder_timestamp(gcc_unused Decoder &decoder, decoder_timestamp(gcc_unused Decoder &decoder,
gcc_unused double t) gcc_unused double t)
......
...@@ -101,6 +101,22 @@ decoder_read(gcc_unused Decoder *decoder, ...@@ -101,6 +101,22 @@ decoder_read(gcc_unused Decoder *decoder,
return is.LockRead(buffer, length, IgnoreError()); return is.LockRead(buffer, length, IgnoreError());
} }
bool
decoder_skip(Decoder *decoder, InputStream &is, size_t size)
{
while (size > 0) {
char buffer[1024];
size_t nbytes = decoder_read(decoder, is, buffer,
std::min(sizeof(buffer), size));
if (nbytes == 0)
return false;
size -= nbytes;
}
return true;
}
void void
decoder_timestamp(gcc_unused Decoder &decoder, decoder_timestamp(gcc_unused Decoder &decoder,
gcc_unused double t) gcc_unused double t)
......
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