decoder/Client: new interface which wraps struct Decoder

Prepare for a Decoder API redesign based on an abstract class with
virtual methods.
This commit is contained in:
Max Kellermann
2016-11-18 07:13:35 +01:00
parent 595d1942cb
commit fd77acc217
46 changed files with 460 additions and 407 deletions

View File

@@ -52,7 +52,7 @@ modplug_decoder_init(const ConfigBlock &block)
}
static WritableBuffer<uint8_t>
mod_loadfile(Decoder *decoder, InputStream &is)
mod_loadfile(DecoderClient *client, InputStream &is)
{
//known/unknown size, preallocate array, lets read in chunks
@@ -83,7 +83,7 @@ mod_loadfile(Decoder *decoder, InputStream &is)
uint8_t *p = buffer.begin();
while (true) {
size_t ret = decoder_read(decoder, is, p, end - p);
size_t ret = decoder_read(client, is, p, end - p);
if (ret == 0) {
if (is.LockIsEOF())
/* end of file */
@@ -112,9 +112,9 @@ mod_loadfile(Decoder *decoder, InputStream &is)
}
static ModPlugFile *
LoadModPlugFile(Decoder *decoder, InputStream &is)
LoadModPlugFile(DecoderClient *client, InputStream &is)
{
const auto buffer = mod_loadfile(decoder, is);
const auto buffer = mod_loadfile(client, is);
if (buffer.IsNull()) {
LogWarning(modplug_domain, "could not load stream");
return nullptr;
@@ -126,7 +126,7 @@ LoadModPlugFile(Decoder *decoder, InputStream &is)
}
static void
mod_decode(Decoder &decoder, InputStream &is)
mod_decode(DecoderClient &client, InputStream &is)
{
ModPlug_Settings settings;
int ret;
@@ -142,7 +142,7 @@ mod_decode(Decoder &decoder, InputStream &is)
/* insert more setting changes here */
ModPlug_SetSettings(&settings);
ModPlugFile *f = LoadModPlugFile(&decoder, is);
ModPlugFile *f = LoadModPlugFile(&client, is);
if (f == nullptr) {
LogWarning(modplug_domain, "could not decode stream");
return;
@@ -151,7 +151,7 @@ mod_decode(Decoder &decoder, InputStream &is)
static constexpr AudioFormat audio_format(44100, SampleFormat::S16, 2);
assert(audio_format.IsValid());
decoder_initialized(decoder, audio_format,
decoder_initialized(client, audio_format,
is.IsSeekable(),
SongTime::FromMS(ModPlug_GetLength(f)));
@@ -161,13 +161,13 @@ mod_decode(Decoder &decoder, InputStream &is)
if (ret <= 0)
break;
cmd = decoder_data(decoder, nullptr,
cmd = decoder_data(client, nullptr,
audio_buffer, ret,
0);
if (cmd == DecoderCommand::SEEK) {
ModPlug_Seek(f, decoder_seek_time(decoder).ToMS());
decoder_command_finished(decoder);
ModPlug_Seek(f, decoder_seek_time(client).ToMS());
decoder_command_finished(client);
}
} while (cmd != DecoderCommand::STOP);