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

@@ -40,13 +40,13 @@ sndfile_init(gcc_unused const ConfigBlock &block)
}
struct SndfileInputStream {
Decoder *const decoder;
DecoderClient *const client;
InputStream &is;
size_t Read(void *buffer, size_t size) {
/* libsndfile chokes on partial reads; therefore
always force full reads */
return decoder_read_full(decoder, is, buffer, size)
return decoder_read_full(client, is, buffer, size)
? size
: 0;
}
@@ -186,13 +186,13 @@ sndfile_read_frames(SNDFILE *sf, SampleFormat format,
}
static void
sndfile_stream_decode(Decoder &decoder, InputStream &is)
sndfile_stream_decode(DecoderClient &client, InputStream &is)
{
SF_INFO info;
info.format = 0;
SndfileInputStream sis{&decoder, is};
SndfileInputStream sis{&client, is};
SNDFILE *const sf = sf_open_virtual(&vio, SFM_READ, &info, &sis);
if (sf == nullptr) {
FormatWarning(sndfile_domain, "sf_open_virtual() failed: %s",
@@ -205,7 +205,7 @@ sndfile_stream_decode(Decoder &decoder, InputStream &is)
sndfile_sample_format(info),
info.channels);
decoder_initialized(decoder, audio_format, info.seekable,
decoder_initialized(client, audio_format, info.seekable,
sndfile_duration(info));
char buffer[16384];
@@ -222,16 +222,16 @@ sndfile_stream_decode(Decoder &decoder, InputStream &is)
if (num_frames <= 0)
break;
cmd = decoder_data(decoder, is,
cmd = decoder_data(client, is,
buffer, num_frames * frame_size,
0);
if (cmd == DecoderCommand::SEEK) {
sf_count_t c = decoder_seek_where_frame(decoder);
sf_count_t c = decoder_seek_where_frame(client);
c = sf_seek(sf, c, SEEK_SET);
if (c < 0)
decoder_seek_error(decoder);
decoder_seek_error(client);
else
decoder_command_finished(decoder);
decoder_command_finished(client);
cmd = DecoderCommand::NONE;
}
} while (cmd == DecoderCommand::NONE);