aboutsummaryrefslogtreecommitdiffstats
path: root/src/decoder
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/decoder/AudiofileDecoderPlugin.cxx28
-rw-r--r--src/decoder/DsdLib.cxx30
-rw-r--r--src/decoder/DsdLib.hxx9
-rw-r--r--src/decoder/DsdiffDecoderPlugin.cxx56
-rw-r--r--src/decoder/DsfDecoderPlugin.cxx14
-rw-r--r--src/decoder/FaadDecoderPlugin.cxx18
-rw-r--r--src/decoder/FfmpegDecoderPlugin.cxx30
-rw-r--r--src/decoder/FlacCommon.cxx4
-rw-r--r--src/decoder/FlacCommon.hxx4
-rw-r--r--src/decoder/FlacDecoderPlugin.cxx16
-rw-r--r--src/decoder/FlacIOHandle.cxx10
-rw-r--r--src/decoder/FlacIOHandle.hxx8
-rw-r--r--src/decoder/FlacInput.cxx16
-rw-r--r--src/decoder/FlacInput.hxx7
-rw-r--r--src/decoder/FlacMetadata.hxx4
-rw-r--r--src/decoder/MadDecoderPlugin.cxx34
-rw-r--r--src/decoder/ModplugDecoderPlugin.cxx16
-rw-r--r--src/decoder/MpcdecDecoderPlugin.cxx29
-rw-r--r--src/decoder/OggCodec.cxx2
-rw-r--r--src/decoder/OggCodec.hxx2
-rw-r--r--src/decoder/OggSyncState.hxx16
-rw-r--r--src/decoder/OggUtil.cxx12
-rw-r--r--src/decoder/OggUtil.hxx16
-rw-r--r--src/decoder/OpusDecoderPlugin.cxx22
-rw-r--r--src/decoder/PcmDecoderPlugin.cxx16
-rw-r--r--src/decoder/SndfileDecoderPlugin.cxx22
-rw-r--r--src/decoder/VorbisDecoderPlugin.cxx18
-rw-r--r--src/decoder/WavpackDecoderPlugin.cxx28
28 files changed, 244 insertions, 243 deletions
diff --git a/src/decoder/AudiofileDecoderPlugin.cxx b/src/decoder/AudiofileDecoderPlugin.cxx
index 5b3ffa642..ab3557e52 100644
--- a/src/decoder/AudiofileDecoderPlugin.cxx
+++ b/src/decoder/AudiofileDecoderPlugin.cxx
@@ -54,10 +54,10 @@ static int audiofile_get_duration(const char *file)
static ssize_t
audiofile_file_read(AFvirtualfile *vfile, void *data, size_t length)
{
- struct input_stream *is = (struct input_stream *) vfile->closure;
+ InputStream &is = *(InputStream *)vfile->closure;
Error error;
- size_t nbytes = is->LockRead(data, length, error);
+ size_t nbytes = is.LockRead(data, length, error);
if (nbytes == 0 && error.IsDefined()) {
LogError(error);
return -1;
@@ -69,15 +69,15 @@ audiofile_file_read(AFvirtualfile *vfile, void *data, size_t length)
static AFfileoffset
audiofile_file_length(AFvirtualfile *vfile)
{
- struct input_stream *is = (struct input_stream *) vfile->closure;
- return is->GetSize();
+ InputStream &is = *(InputStream *)vfile->closure;
+ return is.GetSize();
}
static AFfileoffset
audiofile_file_tell(AFvirtualfile *vfile)
{
- struct input_stream *is = (struct input_stream *) vfile->closure;
- return is->GetOffset();
+ InputStream &is = *(InputStream *)vfile->closure;
+ return is.GetOffset();
}
static void
@@ -91,22 +91,22 @@ audiofile_file_destroy(AFvirtualfile *vfile)
static AFfileoffset
audiofile_file_seek(AFvirtualfile *vfile, AFfileoffset offset, int is_relative)
{
- struct input_stream *is = (struct input_stream *) vfile->closure;
+ InputStream &is = *(InputStream *)vfile->closure;
int whence = (is_relative ? SEEK_CUR : SEEK_SET);
Error error;
- if (is->LockSeek(offset, whence, error)) {
- return is->GetOffset();
+ if (is.LockSeek(offset, whence, error)) {
+ return is.GetOffset();
} else {
return -1;
}
}
static AFvirtualfile *
-setup_virtual_fops(struct input_stream *stream)
+setup_virtual_fops(InputStream &stream)
{
AFvirtualfile *vf = new AFvirtualfile();
- vf->closure = stream;
+ vf->closure = &stream;
vf->write = nullptr;
vf->read = audiofile_file_read;
vf->length = audiofile_file_length;
@@ -157,7 +157,7 @@ audiofile_setup_sample_format(AFfilehandle af_fp)
}
static void
-audiofile_stream_decode(Decoder &decoder, struct input_stream *is)
+audiofile_stream_decode(Decoder &decoder, InputStream &is)
{
AFvirtualfile *vf;
int fs, frame_count;
@@ -168,7 +168,7 @@ audiofile_stream_decode(Decoder &decoder, struct input_stream *is)
int ret;
char chunk[CHUNK_SIZE];
- if (!is->IsSeekable()) {
+ if (!is.IsSeekable()) {
LogWarning(audiofile_domain, "not seekable");
return;
}
@@ -196,7 +196,7 @@ audiofile_stream_decode(Decoder &decoder, struct input_stream *is)
total_time = ((float)frame_count / (float)audio_format.sample_rate);
- bit_rate = (uint16_t)(is->GetSize() * 8.0 / total_time / 1000.0 + 0.5);
+ bit_rate = (uint16_t)(is.GetSize() * 8.0 / total_time / 1000.0 + 0.5);
fs = (int)afGetVirtualFrameSize(af_fp, AF_DEFAULT_TRACK, 1);
diff --git a/src/decoder/DsdLib.cxx b/src/decoder/DsdLib.cxx
index ab1a132fc..81ea9e5e8 100644
--- a/src/decoder/DsdLib.cxx
+++ b/src/decoder/DsdLib.cxx
@@ -51,7 +51,7 @@ dsdlib_id_equals(const struct dsdlib_id *id, const char *s)
}
bool
-dsdlib_read(Decoder *decoder, struct input_stream *is,
+dsdlib_read(Decoder *decoder, InputStream &is,
void *data, size_t length)
{
size_t nbytes = decoder_read(decoder, is, data, length);
@@ -62,27 +62,27 @@ dsdlib_read(Decoder *decoder, struct input_stream *is,
* Skip the #input_stream to the specified offset.
*/
bool
-dsdlib_skip_to(Decoder *decoder, struct input_stream *is,
+dsdlib_skip_to(Decoder *decoder, InputStream &is,
int64_t offset)
{
- if (is->IsSeekable())
- return is->Seek(offset, SEEK_SET, IgnoreError());
+ if (is.IsSeekable())
+ return is.Seek(offset, SEEK_SET, IgnoreError());
- if (is->GetOffset() > offset)
+ if (is.GetOffset() > offset)
return false;
char buffer[8192];
- while (is->GetOffset() < offset) {
+ while (is.GetOffset() < offset) {
size_t length = sizeof(buffer);
- if (offset - is->GetOffset() < (int64_t)length)
- length = offset - is->GetOffset();
+ if (offset - is.GetOffset() < (int64_t)length)
+ length = offset - is.GetOffset();
size_t nbytes = decoder_read(decoder, is, buffer, length);
if (nbytes == 0)
return false;
}
- assert(is->GetOffset() == offset);
+ assert(is.GetOffset() == offset);
return true;
}
@@ -90,7 +90,7 @@ dsdlib_skip_to(Decoder *decoder, struct input_stream *is,
* Skip some bytes from the #input_stream.
*/
bool
-dsdlib_skip(Decoder *decoder, struct input_stream *is,
+dsdlib_skip(Decoder *decoder, InputStream &is,
int64_t delta)
{
assert(delta >= 0);
@@ -98,8 +98,8 @@ dsdlib_skip(Decoder *decoder, struct input_stream *is,
if (delta == 0)
return true;
- if (is->IsSeekable())
- return is->Seek(delta, SEEK_CUR, IgnoreError());
+ if (is.IsSeekable())
+ return is.Seek(delta, SEEK_CUR, IgnoreError());
char buffer[8192];
while (delta > 0) {
@@ -124,7 +124,7 @@ dsdlib_skip(Decoder *decoder, struct input_stream *is,
#ifdef HAVE_ID3TAG
void
-dsdlib_tag_id3(struct input_stream *is,
+dsdlib_tag_id3(InputStream &is,
const struct tag_handler *handler,
void *handler_ctx, int64_t tagoffset)
{
@@ -140,8 +140,8 @@ dsdlib_tag_id3(struct input_stream *is,
id3_length_t count;
/* Prevent broken files causing problems */
- const auto size = is->GetSize();
- const auto offset = is->GetOffset();
+ const auto size = is.GetSize();
+ const auto offset = is.GetOffset();
if (offset >= size)
return;
diff --git a/src/decoder/DsdLib.hxx b/src/decoder/DsdLib.hxx
index 261273091..3e21bffb0 100644
--- a/src/decoder/DsdLib.hxx
+++ b/src/decoder/DsdLib.hxx
@@ -24,6 +24,7 @@
#include <stdint.h>
struct Decoder;
+struct InputStream;
struct dsdlib_id {
char value[4];
@@ -33,19 +34,19 @@ bool
dsdlib_id_equals(const struct dsdlib_id *id, const char *s);
bool
-dsdlib_read(Decoder *decoder, struct input_stream *is,
+dsdlib_read(Decoder *decoder, InputStream &is,
void *data, size_t length);
bool
-dsdlib_skip_to(Decoder *decoder, struct input_stream *is,
+dsdlib_skip_to(Decoder *decoder, InputStream &is,
int64_t offset);
bool
-dsdlib_skip(Decoder *decoder, struct input_stream *is,
+dsdlib_skip(Decoder *decoder, InputStream &is,
int64_t delta);
void
-dsdlib_tag_id3(struct input_stream *is,
+dsdlib_tag_id3(InputStream &is,
const struct tag_handler *handler,
void *handler_ctx, int64_t tagoffset);
diff --git a/src/decoder/DsdiffDecoderPlugin.cxx b/src/decoder/DsdiffDecoderPlugin.cxx
index 3f768f60f..f39679a30 100644
--- a/src/decoder/DsdiffDecoderPlugin.cxx
+++ b/src/decoder/DsdiffDecoderPlugin.cxx
@@ -72,13 +72,13 @@ struct DsdiffMetaData {
bool bitreverse;
uint64_t chunk_size;
#ifdef HAVE_ID3TAG
- input_stream::offset_type id3_offset;
+ InputStream::offset_type id3_offset;
uint64_t id3_size;
#endif
/** offset for artist tag */
- input_stream::offset_type diar_offset;
+ InputStream::offset_type diar_offset;
/** offset for title tag */
- input_stream::offset_type diti_offset;
+ InputStream::offset_type diti_offset;
};
static bool lsbitfirst;
@@ -91,21 +91,21 @@ dsdiff_init(const config_param &param)
}
static bool
-dsdiff_read_id(Decoder *decoder, struct input_stream *is,
+dsdiff_read_id(Decoder *decoder, InputStream &is,
struct dsdlib_id *id)
{
return dsdlib_read(decoder, is, id, sizeof(*id));
}
static bool
-dsdiff_read_chunk_header(Decoder *decoder, struct input_stream *is,
+dsdiff_read_chunk_header(Decoder *decoder, InputStream &is,
DsdiffChunkHeader *header)
{
return dsdlib_read(decoder, is, header, sizeof(*header));
}
static bool
-dsdiff_read_payload(Decoder *decoder, struct input_stream *is,
+dsdiff_read_payload(Decoder *decoder, InputStream &is,
const DsdiffChunkHeader *header,
void *data, size_t length)
{
@@ -121,16 +121,16 @@ dsdiff_read_payload(Decoder *decoder, struct input_stream *is,
* Read and parse a "SND" chunk inside "PROP".
*/
static bool
-dsdiff_read_prop_snd(Decoder *decoder, struct input_stream *is,
+dsdiff_read_prop_snd(Decoder *decoder, InputStream &is,
DsdiffMetaData *metadata,
- input_stream::offset_type end_offset)
+ InputStream::offset_type end_offset)
{
DsdiffChunkHeader header;
- while ((input_stream::offset_type)(is->GetOffset() + sizeof(header)) <= end_offset) {
+ while ((InputStream::offset_type)(is.GetOffset() + sizeof(header)) <= end_offset) {
if (!dsdiff_read_chunk_header(decoder, is, &header))
return false;
- input_stream::offset_type chunk_end_offset = is->GetOffset()
+ InputStream::offset_type chunk_end_offset = is.GetOffset()
+ header.GetSize();
if (chunk_end_offset > end_offset)
return false;
@@ -172,19 +172,19 @@ dsdiff_read_prop_snd(Decoder *decoder, struct input_stream *is,
}
}
- return is->GetOffset() == end_offset;
+ return is.GetOffset() == end_offset;
}
/**
* Read and parse a "PROP" chunk.
*/
static bool
-dsdiff_read_prop(Decoder *decoder, struct input_stream *is,
+dsdiff_read_prop(Decoder *decoder, InputStream &is,
DsdiffMetaData *metadata,
const DsdiffChunkHeader *prop_header)
{
uint64_t prop_size = prop_header->GetSize();
- input_stream::offset_type end_offset = is->GetOffset() + prop_size;
+ InputStream::offset_type end_offset = is.GetOffset() + prop_size;
struct dsdlib_id prop_id;
if (prop_size < sizeof(prop_id) ||
@@ -199,9 +199,9 @@ dsdiff_read_prop(Decoder *decoder, struct input_stream *is,
}
static void
-dsdiff_handle_native_tag(struct input_stream *is,
+dsdiff_handle_native_tag(InputStream &is,
const struct tag_handler *handler,
- void *handler_ctx, input_stream::offset_type tagoffset,
+ void *handler_ctx, InputStream::offset_type tagoffset,
TagType type)
{
if (!dsdlib_skip_to(nullptr, is, tagoffset))
@@ -239,7 +239,7 @@ dsdiff_handle_native_tag(struct input_stream *is,
*/
static bool
-dsdiff_read_metadata_extra(Decoder *decoder, struct input_stream *is,
+dsdiff_read_metadata_extra(Decoder *decoder, InputStream &is,
DsdiffMetaData *metadata,
DsdiffChunkHeader *chunk_header,
const struct tag_handler *handler,
@@ -259,8 +259,8 @@ dsdiff_read_metadata_extra(Decoder *decoder, struct input_stream *is,
/* Now process all the remaining chunk headers in the stream
and record their position and size */
- const auto size = is->GetSize();
- while (is->GetOffset() < size) {
+ const auto size = is.GetSize();
+ while (is.GetOffset() < size) {
uint64_t chunk_size = chunk_header->GetSize();
/* DIIN chunk, is directly followed by other chunks */
@@ -270,19 +270,19 @@ dsdiff_read_metadata_extra(Decoder *decoder, struct input_stream *is,
/* DIAR chunk - DSDIFF native tag for Artist */
if (dsdlib_id_equals(&chunk_header->id, "DIAR")) {
chunk_size = chunk_header->GetSize();
- metadata->diar_offset = is->GetOffset();
+ metadata->diar_offset = is.GetOffset();
}
/* DITI chunk - DSDIFF native tag for Title */
if (dsdlib_id_equals(&chunk_header->id, "DITI")) {
chunk_size = chunk_header->GetSize();
- metadata->diti_offset = is->GetOffset();
+ metadata->diti_offset = is.GetOffset();
}
#ifdef HAVE_ID3TAG
/* 'ID3 ' chunk, offspec. Used by sacdextract */
if (dsdlib_id_equals(&chunk_header->id, "ID3 ")) {
chunk_size = chunk_header->GetSize();
- metadata->id3_offset = is->GetOffset();
+ metadata->id3_offset = is.GetOffset();
metadata->id3_size = chunk_size;
}
#endif
@@ -291,7 +291,7 @@ dsdiff_read_metadata_extra(Decoder *decoder, struct input_stream *is,
break;
}
- if (is->GetOffset() < size) {
+ if (is.GetOffset() < size) {
if (!dsdiff_read_chunk_header(decoder, is, chunk_header))
return false;
}
@@ -325,7 +325,7 @@ dsdiff_read_metadata_extra(Decoder *decoder, struct input_stream *is,
* "chunk_header" parameter.
*/
static bool
-dsdiff_read_metadata(Decoder *decoder, struct input_stream *is,
+dsdiff_read_metadata(Decoder *decoder, InputStream &is,
DsdiffMetaData *metadata,
DsdiffChunkHeader *chunk_header)
{
@@ -351,8 +351,8 @@ dsdiff_read_metadata(Decoder *decoder, struct input_stream *is,
} else {
/* ignore unknown chunk */
const uint64_t chunk_size = chunk_header->GetSize();
- input_stream::offset_type chunk_end_offset =
- is->GetOffset() + chunk_size;
+ InputStream::offset_type chunk_end_offset =
+ is.GetOffset() + chunk_size;
if (!dsdlib_skip_to(decoder, is, chunk_end_offset))
return false;
@@ -371,7 +371,7 @@ bit_reverse_buffer(uint8_t *p, uint8_t *end)
* Decode one "DSD" chunk.
*/
static bool
-dsdiff_decode_chunk(Decoder &decoder, struct input_stream *is,
+dsdiff_decode_chunk(Decoder &decoder, InputStream &is,
unsigned channels,
uint64_t chunk_size)
{
@@ -422,7 +422,7 @@ dsdiff_decode_chunk(Decoder &decoder, struct input_stream *is,
}
static void
-dsdiff_stream_decode(Decoder &decoder, struct input_stream *is)
+dsdiff_stream_decode(Decoder &decoder, InputStream &is)
{
DsdiffMetaData metadata;
@@ -474,7 +474,7 @@ dsdiff_stream_decode(Decoder &decoder, struct input_stream *is)
}
static bool
-dsdiff_scan_stream(struct input_stream *is,
+dsdiff_scan_stream(InputStream &is,
gcc_unused const struct tag_handler *handler,
gcc_unused void *handler_ctx)
{
diff --git a/src/decoder/DsfDecoderPlugin.cxx b/src/decoder/DsfDecoderPlugin.cxx
index 4b848d4a4..10a88d370 100644
--- a/src/decoder/DsfDecoderPlugin.cxx
+++ b/src/decoder/DsfDecoderPlugin.cxx
@@ -47,7 +47,7 @@ struct DsfMetaData {
bool bitreverse;
uint64_t chunk_size;
#ifdef HAVE_ID3TAG
- input_stream::offset_type id3_offset;
+ InputStream::offset_type id3_offset;
uint64_t id3_size;
#endif
};
@@ -99,7 +99,7 @@ struct DsfDataChunk {
* Read and parse all needed metadata chunks for DSF files.
*/
static bool
-dsf_read_metadata(Decoder *decoder, struct input_stream *is,
+dsf_read_metadata(Decoder *decoder, InputStream &is,
DsfMetaData *metadata)
{
uint64_t chunk_size;
@@ -165,7 +165,7 @@ dsf_read_metadata(Decoder *decoder, struct input_stream *is,
metadata->chunk_size = data_size;
/* data_size cannot be bigger or equal to total file size */
- const uint64_t size = (uint64_t)is->GetSize();
+ const uint64_t size = (uint64_t)is.GetSize();
if (data_size >= size)
return false;
@@ -176,7 +176,7 @@ dsf_read_metadata(Decoder *decoder, struct input_stream *is,
if (metadata_offset >= size)
metadata->id3_offset = 0;
else
- metadata->id3_offset = (input_stream::offset_type)metadata_offset;
+ metadata->id3_offset = (InputStream::offset_type)metadata_offset;
#endif
/* check bits per sample format, determine if bitreverse is needed */
metadata->bitreverse = dsf_fmt_chunk.bitssample == 1;
@@ -219,7 +219,7 @@ dsf_to_pcm_order(uint8_t *dest, uint8_t *scratch, size_t nrbytes)
* Decode one complete DSF 'data' chunk i.e. a complete song
*/
static bool
-dsf_decode_chunk(Decoder &decoder, struct input_stream *is,
+dsf_decode_chunk(Decoder &decoder, InputStream &is,
unsigned channels,
uint64_t chunk_size,
bool bitreverse)
@@ -277,7 +277,7 @@ dsf_decode_chunk(Decoder &decoder, struct input_stream *is,
}
static void
-dsf_stream_decode(Decoder &decoder, struct input_stream *is)
+dsf_stream_decode(Decoder &decoder, InputStream &is)
{
/* check if it is a proper DSF file */
DsfMetaData metadata;
@@ -307,7 +307,7 @@ dsf_stream_decode(Decoder &decoder, struct input_stream *is)
}
static bool
-dsf_scan_stream(struct input_stream *is,
+dsf_scan_stream(InputStream &is,
gcc_unused const struct tag_handler *handler,
gcc_unused void *handler_ctx)
{
diff --git a/src/decoder/FaadDecoderPlugin.cxx b/src/decoder/FaadDecoderPlugin.cxx
index 05d929fb4..e8b5ad4a8 100644
--- a/src/decoder/FaadDecoderPlugin.cxx
+++ b/src/decoder/FaadDecoderPlugin.cxx
@@ -163,14 +163,14 @@ adts_song_duration(DecoderBuffer *buffer)
}
static float
-faad_song_duration(DecoderBuffer *buffer, struct input_stream *is)
+faad_song_duration(DecoderBuffer *buffer, InputStream &is)
{
size_t fileread;
size_t tagsize;
size_t length;
bool success;
- const auto size = is->GetSize();
+ const auto size = is.GetSize();
fileread = size >= 0 ? size : 0;
decoder_buffer_fill(buffer);
@@ -198,12 +198,12 @@ faad_song_duration(DecoderBuffer *buffer, struct input_stream *is)
return -1;
}
- if (is->IsSeekable() && length >= 2 &&
+ if (is.IsSeekable() && length >= 2 &&
data[0] == 0xFF && ((data[1] & 0xF6) == 0xF0)) {
/* obtain the duration from the ADTS header */
float song_length = adts_song_duration(buffer);
- is->LockSeek(tagsize, SEEK_SET, IgnoreError());
+ is.LockSeek(tagsize, SEEK_SET, IgnoreError());
data = (const uint8_t *)decoder_buffer_read(buffer, &length);
if (data != nullptr)
@@ -304,7 +304,7 @@ faad_decoder_decode(NeAACDecHandle decoder, DecoderBuffer *buffer,
* file is invalid.
*/
static float
-faad_get_file_time_float(struct input_stream *is)
+faad_get_file_time_float(InputStream &is)
{
DecoderBuffer *buffer;
float length;
@@ -345,7 +345,7 @@ faad_get_file_time_float(struct input_stream *is)
* file is invalid.
*/
static int
-faad_get_file_time(struct input_stream *is)
+faad_get_file_time(InputStream &is)
{
int file_time = -1;
float length;
@@ -357,7 +357,7 @@ faad_get_file_time(struct input_stream *is)
}
static void
-faad_stream_decode(Decoder &mpd_decoder, struct input_stream *is)
+faad_stream_decode(Decoder &mpd_decoder, InputStream &is)
{
float total_time = 0;
AudioFormat audio_format;
@@ -380,7 +380,7 @@ faad_stream_decode(Decoder &mpd_decoder, struct input_stream *is)
config->dontUpSampleImplicitSBR = 0;
NeAACDecSetConfiguration(decoder, config);
- while (!decoder_buffer_is_full(buffer) && !is->LockIsEOF() &&
+ while (!decoder_buffer_is_full(buffer) && !is.LockIsEOF() &&
decoder_get_command(mpd_decoder) == DecoderCommand::NONE) {
adts_find_frame(buffer);
decoder_buffer_fill(buffer);
@@ -464,7 +464,7 @@ faad_stream_decode(Decoder &mpd_decoder, struct input_stream *is)
}
static bool
-faad_scan_stream(struct input_stream *is,
+faad_scan_stream(InputStream &is,
const struct tag_handler *handler, void *handler_ctx)
{
int file_time = faad_get_file_time(is);
diff --git a/src/decoder/FfmpegDecoderPlugin.cxx b/src/decoder/FfmpegDecoderPlugin.cxx
index cba7f5e2d..0d24371d2 100644
--- a/src/decoder/FfmpegDecoderPlugin.cxx
+++ b/src/decoder/FfmpegDecoderPlugin.cxx
@@ -86,13 +86,13 @@ mpd_ffmpeg_log_callback(gcc_unused void *ptr, int level,
struct AvioStream {
Decoder *const decoder;
- struct input_stream *input;
+ InputStream &input;
AVIOContext *io;
unsigned char buffer[8192];
- AvioStream(Decoder *_decoder, input_stream *_input)
+ AvioStream(Decoder *_decoder, InputStream &_input)
:decoder(_decoder), input(_input), io(nullptr) {}
~AvioStream() {
@@ -118,13 +118,13 @@ mpd_ffmpeg_stream_seek(void *opaque, int64_t pos, int whence)
AvioStream *stream = (AvioStream *)opaque;
if (whence == AVSEEK_SIZE)
- return stream->input->size;
+ return stream->input.size;
Error error;
- if (!stream->input->LockSeek(pos, whence, error))
+ if (!stream->input.LockSeek(pos, whence, error))
return -1;
- return stream->input->offset;
+ return stream->input.offset;
}
bool
@@ -133,7 +133,7 @@ AvioStream::Open()
io = avio_alloc_context(buffer, sizeof(buffer),
false, this,
mpd_ffmpeg_stream_read, nullptr,
- input->seekable
+ input.seekable
? mpd_ffmpeg_stream_seek : nullptr);
return io != nullptr;
}
@@ -249,7 +249,7 @@ copy_interleave_frame(const AVCodecContext *codec_context,
}
static DecoderCommand
-ffmpeg_send_packet(Decoder &decoder, struct input_stream *is,
+ffmpeg_send_packet(Decoder &decoder, InputStream &is,
const AVPacket *packet,
AVCodecContext *codec_context,
const AVRational *time_base,
@@ -335,7 +335,7 @@ ffmpeg_sample_format(enum AVSampleFormat sample_fmt)
}
static AVInputFormat *
-ffmpeg_probe(Decoder *decoder, struct input_stream *is)
+ffmpeg_probe(Decoder *decoder, InputStream &is)
{
enum {
BUFFER_SIZE = 16384,
@@ -346,7 +346,7 @@ ffmpeg_probe(Decoder *decoder, struct input_stream *is)
unsigned char buffer[BUFFER_SIZE];
size_t nbytes = decoder_read(decoder, is, buffer, BUFFER_SIZE);
- if (nbytes <= PADDING || !is->LockRewind(error))
+ if (nbytes <= PADDING || !is.LockRewind(error))
return nullptr;
/* some ffmpeg parsers (e.g. ac3_parser.c) read a few bytes
@@ -358,13 +358,13 @@ ffmpeg_probe(Decoder *decoder, struct input_stream *is)
AVProbeData avpd;
avpd.buf = buffer;
avpd.buf_size = nbytes;
- avpd.filename = is->uri.c_str();
+ avpd.filename = is.uri.c_str();
return av_probe_input_format(&avpd, true);
}
static void
-ffmpeg_decode(Decoder &decoder, struct input_stream *input)
+ffmpeg_decode(Decoder &decoder, InputStream &input)
{
AVInputFormat *input_format = ffmpeg_probe(&decoder, input);
if (input_format == nullptr)
@@ -382,7 +382,7 @@ ffmpeg_decode(Decoder &decoder, struct input_stream *input)
//ffmpeg works with ours "fileops" helper
AVFormatContext *format_context = nullptr;
if (mpd_ffmpeg_open_input(&format_context, stream.io,
- input->uri.c_str(),
+ input.uri.c_str(),
input_format) != 0) {
LogError(ffmpeg_domain, "Open failed");
return;
@@ -451,7 +451,7 @@ ffmpeg_decode(Decoder &decoder, struct input_stream *input)
: 0;
decoder_initialized(decoder, audio_format,
- input->seekable, total_time);
+ input.seekable, total_time);
AVFrame *frame = avcodec_alloc_frame();
if (!frame) {
@@ -509,7 +509,7 @@ ffmpeg_decode(Decoder &decoder, struct input_stream *input)
//no tag reading in ffmpeg, check if playable
static bool
-ffmpeg_scan_stream(struct input_stream *is,
+ffmpeg_scan_stream(InputStream &is,
const struct tag_handler *handler, void *handler_ctx)
{
AVInputFormat *input_format = ffmpeg_probe(nullptr, is);
@@ -521,7 +521,7 @@ ffmpeg_scan_stream(struct input_stream *is,
return false;
AVFormatContext *f = nullptr;
- if (mpd_ffmpeg_open_input(&f, stream.io, is->uri.c_str(),
+ if (mpd_ffmpeg_open_input(&f, stream.io, is.uri.c_str(),
input_format) != 0)
return false;
diff --git a/src/decoder/FlacCommon.cxx b/src/decoder/FlacCommon.cxx
index 46fd9fff9..2aa4ce695 100644
--- a/src/decoder/FlacCommon.cxx
+++ b/src/decoder/FlacCommon.cxx
@@ -33,7 +33,7 @@
#include <assert.h>
flac_data::flac_data(Decoder &_decoder,
- struct input_stream *_input_stream)
+ InputStream &_input_stream)
:FlacInput(_input_stream, &_decoder),
initialized(false), unsupported(false),
total_frames(0), first_frame(0), next_frame(0), position(0),
@@ -144,7 +144,7 @@ flac_got_first_frame(struct flac_data *data, const FLAC__FrameHeader *header)
data->frame_size = data->audio_format.GetFrameSize();
decoder_initialized(data->decoder, data->audio_format,
- data->input_stream->seekable,
+ data->input_stream.seekable,
(float)data->total_frames /
(float)data->audio_format.sample_rate);
diff --git a/src/decoder/FlacCommon.hxx b/src/decoder/FlacCommon.hxx
index e35bceb30..65b5defd6 100644
--- a/src/decoder/FlacCommon.hxx
+++ b/src/decoder/FlacCommon.hxx
@@ -76,11 +76,11 @@ struct flac_data : public FlacInput {
FLAC__uint64 position;
Decoder &decoder;
- struct input_stream *input_stream;
+ InputStream &input_stream;
Tag tag;
- flac_data(Decoder &decoder, struct input_stream *input_stream);
+ flac_data(Decoder &decoder, InputStream &input_stream);
};
void flac_metadata_common_cb(const FLAC__StreamMetadata * block,
diff --git a/src/decoder/FlacDecoderPlugin.cxx b/src/decoder/FlacDecoderPlugin.cxx
index 10a052d3d..9390b62ba 100644
--- a/src/decoder/FlacDecoderPlugin.cxx
+++ b/src/decoder/FlacDecoderPlugin.cxx
@@ -99,7 +99,7 @@ flac_scan_file(const char *file,
}
static bool
-flac_scan_stream(struct input_stream *is,
+flac_scan_stream(InputStream &is,
const struct tag_handler *handler, void *handler_ctx)
{
FlacMetadataChain chain;
@@ -148,13 +148,13 @@ flac_decoder_initialize(struct flac_data *data, FLAC__StreamDecoder *sd,
if (data->initialized) {
/* done */
decoder_initialized(data->decoder, data->audio_format,
- data->input_stream->seekable,
+ data->input_stream.seekable,
(float)data->total_frames /
(float)data->audio_format.sample_rate);
return true;
}
- if (data->input_stream->seekable)
+ if (data->input_stream.seekable)
/* allow the workaround below only for nonseekable
streams*/
return false;
@@ -252,7 +252,7 @@ stream_init(FLAC__StreamDecoder *flac_dec, struct flac_data *data, bool is_ogg)
static void
flac_decode_internal(Decoder &decoder,
- struct input_stream *input_stream,
+ InputStream &input_stream,
bool is_ogg)
{
FLAC__StreamDecoder *flac_dec;
@@ -285,7 +285,7 @@ flac_decode_internal(Decoder &decoder,
}
static void
-flac_decode(Decoder &decoder, struct input_stream *input_stream)
+flac_decode(Decoder &decoder, InputStream &input_stream)
{
flac_decode_internal(decoder, input_stream, false);
}
@@ -313,7 +313,7 @@ oggflac_scan_file(const char *file,
}
static bool
-oggflac_scan_stream(struct input_stream *is,
+oggflac_scan_stream(InputStream &is,
const struct tag_handler *handler, void *handler_ctx)
{
FlacMetadataChain chain;
@@ -329,14 +329,14 @@ oggflac_scan_stream(struct input_stream *is,
}
static void
-oggflac_decode(Decoder &decoder, struct input_stream *input_stream)
+oggflac_decode(Decoder &decoder, InputStream &input_stream)
{
if (ogg_codec_detect(&decoder, input_stream) != OGG_CODEC_FLAC)
return;
/* rewind the stream, because ogg_codec_detect() has
moved it */
- input_stream->LockRewind(IgnoreError());
+ input_stream.LockRewind(IgnoreError());
flac_decode_internal(decoder, input_stream, true);
}
diff --git a/src/decoder/FlacIOHandle.cxx b/src/decoder/FlacIOHandle.cxx
index 28ef60006..ff8b5a5bc 100644
--- a/src/decoder/FlacIOHandle.cxx
+++ b/src/decoder/FlacIOHandle.cxx
@@ -27,7 +27,7 @@
static size_t
FlacIORead(void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle)
{
- input_stream *is = (input_stream *)handle;
+ InputStream *is = (InputStream *)handle;
uint8_t *const p0 = (uint8_t *)ptr, *p = p0,
*const end = p0 + size * nmemb;
@@ -64,7 +64,7 @@ FlacIORead(void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle)
static int
FlacIOSeek(FLAC__IOHandle handle, FLAC__int64 offset, int whence)
{
- input_stream *is = (input_stream *)handle;
+ InputStream *is = (InputStream *)handle;
Error error;
return is->LockSeek(offset, whence, error) ? 0 : -1;
@@ -73,7 +73,7 @@ FlacIOSeek(FLAC__IOHandle handle, FLAC__int64 offset, int whence)
static FLAC__int64
FlacIOTell(FLAC__IOHandle handle)
{
- input_stream *is = (input_stream *)handle;
+ InputStream *is = (InputStream *)handle;
return is->offset;
}
@@ -81,7 +81,7 @@ FlacIOTell(FLAC__IOHandle handle)
static int
FlacIOEof(FLAC__IOHandle handle)
{
- input_stream *is = (input_stream *)handle;
+ InputStream *is = (InputStream *)handle;
return is->LockIsEOF();
}
@@ -90,7 +90,7 @@ static int
FlacIOClose(gcc_unused FLAC__IOHandle handle)
{
/* no-op because the libFLAC caller is repsonsible for closing
- the #input_stream */
+ the #InputStream */
return 0;
}
diff --git a/src/decoder/FlacIOHandle.hxx b/src/decoder/FlacIOHandle.hxx
index 996f0d96b..a4c9a6b15 100644
--- a/src/decoder/FlacIOHandle.hxx
+++ b/src/decoder/FlacIOHandle.hxx
@@ -29,15 +29,15 @@ extern const FLAC__IOCallbacks flac_io_callbacks;
extern const FLAC__IOCallbacks flac_io_callbacks_seekable;
static inline FLAC__IOHandle
-ToFlacIOHandle(input_stream *is)
+ToFlacIOHandle(InputStream &is)
{
- return (FLAC__IOHandle)is;
+ return (FLAC__IOHandle)&is;
}
static inline const FLAC__IOCallbacks &
-GetFlacIOCallbacks(const input_stream *is)
+GetFlacIOCallbacks(const InputStream &is)
{
- return is->seekable
+ return is.seekable
? flac_io_callbacks_seekable
: flac_io_callbacks;
}
diff --git a/src/decoder/FlacInput.cxx b/src/decoder/FlacInput.cxx
index 39e323716..71a082db1 100644
--- a/src/decoder/FlacInput.cxx
+++ b/src/decoder/FlacInput.cxx
@@ -33,7 +33,7 @@ FlacInput::Read(FLAC__byte buffer[], size_t *bytes)
*bytes = r;
if (r == 0) {
- if (input_stream->LockIsEOF() ||
+ if (input_stream.LockIsEOF() ||
(decoder != nullptr &&
decoder_get_command(*decoder) != DecoderCommand::NONE))
return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
@@ -47,11 +47,11 @@ FlacInput::Read(FLAC__byte buffer[], size_t *bytes)
FLAC__StreamDecoderSeekStatus
FlacInput::Seek(FLAC__uint64 absolute_byte_offset)
{
- if (!input_stream->seekable)
+ if (!input_stream.seekable)
return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
::Error error;
- if (!input_stream->LockSeek(absolute_byte_offset, SEEK_SET, error)) {
+ if (!input_stream.LockSeek(absolute_byte_offset, SEEK_SET, error)) {
LogError(error);
return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
}
@@ -62,20 +62,20 @@ FlacInput::Seek(FLAC__uint64 absolute_byte_offset)
FLAC__StreamDecoderTellStatus
FlacInput::Tell(FLAC__uint64 *absolute_byte_offset)
{
- if (!input_stream->seekable)
+ if (!input_stream.seekable)
return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
- *absolute_byte_offset = (FLAC__uint64)input_stream->offset;
+ *absolute_byte_offset = (FLAC__uint64)input_stream.offset;
return FLAC__STREAM_DECODER_TELL_STATUS_OK;
}
FLAC__StreamDecoderLengthStatus
FlacInput::Length(FLAC__uint64 *stream_length)
{
- if (input_stream->size < 0)
+ if (input_stream.size < 0)
return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
- *stream_length = (FLAC__uint64)input_stream->size;
+ *stream_length = (FLAC__uint64)input_stream.size;
return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
}
@@ -85,7 +85,7 @@ FlacInput::Eof()
return (decoder != nullptr &&
decoder_get_command(*decoder) != DecoderCommand::NONE &&
decoder_get_command(*decoder) != DecoderCommand::SEEK) ||
- input_stream->LockIsEOF();
+ input_stream.LockIsEOF();
}
void
diff --git a/src/decoder/FlacInput.hxx b/src/decoder/FlacInput.hxx
index 2879f5dd4..ac2b4bd25 100644
--- a/src/decoder/FlacInput.hxx
+++ b/src/decoder/FlacInput.hxx
@@ -23,18 +23,19 @@
#include <FLAC/stream_decoder.h>
struct Decoder;
+struct InputStream;
/**
- * This class wraps an #input_stream in libFLAC stream decoder
+ * This class wraps an #InputStream in libFLAC stream decoder
* callbacks.
*/
class FlacInput {
Decoder *const decoder;
- struct input_stream *input_stream;
+ InputStream &input_stream;
public:
- FlacInput(struct input_stream *_input_stream,
+ FlacInput(InputStream &_input_stream,
Decoder *_decoder=nullptr)
:decoder(_decoder), input_stream(_input_stream) {}
diff --git a/src/decoder/FlacMetadata.hxx b/src/decoder/FlacMetadata.hxx
index 5159a1a41..2b4acad06 100644
--- a/src/decoder/FlacMetadata.hxx
+++ b/src/decoder/FlacMetadata.hxx
@@ -51,7 +51,7 @@ public:
callbacks);
}
- bool Read(input_stream *is) {
+ bool Read(InputStream &is) {
return Read(::ToFlacIOHandle(is), ::GetFlacIOCallbacks(is));
}
@@ -65,7 +65,7 @@ public:
callbacks);
}
- bool ReadOgg(input_stream *is) {
+ bool ReadOgg(InputStream &is) {
return ReadOgg(::ToFlacIOHandle(is), ::GetFlacIOCallbacks(is));
}
diff --git a/src/decoder/MadDecoderPlugin.cxx b/src/decoder/MadDecoderPlugin.cxx
index 4b25ef87b..b59bde8b4 100644
--- a/src/decoder/MadDecoderPlugin.cxx
+++ b/src/decoder/MadDecoderPlugin.cxx
@@ -140,10 +140,10 @@ struct MadDecoder {
bool decoded_first_frame;
unsigned long bit_rate;
Decoder *const decoder;
- struct input_stream *input_stream;
+ InputStream &input_stream;
enum mad_layer layer;
- MadDecoder(Decoder *decoder, struct input_stream *input_stream);
+ MadDecoder(Decoder *decoder, InputStream &input_stream);
~MadDecoder();
bool Seek(long offset);
@@ -153,10 +153,10 @@ struct MadDecoder {
enum mp3_action DecodeNextFrame();
gcc_pure
- input_stream::offset_type ThisFrameOffset() const;
+ InputStream::offset_type ThisFrameOffset() const;
gcc_pure
- input_stream::offset_type RestIncludingThisFrame() const;
+ InputStream::offset_type RestIncludingThisFrame() const;
/**
* Attempt to calulcate the length of the song from filesize
@@ -185,7 +185,7 @@ struct MadDecoder {
};
MadDecoder::MadDecoder(Decoder *_decoder,
- struct input_stream *_input_stream)
+ InputStream &_input_stream)
:mute_frame(MUTEFRAME_NONE),
frame_offsets(nullptr),
times(nullptr),
@@ -208,7 +208,7 @@ inline bool
MadDecoder::Seek(long offset)
{
Error error;
- if (!input_stream->LockSeek(offset, SEEK_SET, error))
+ if (!input_stream.LockSeek(offset, SEEK_SET, error))
return false;
mad_stream_buffer(&stream, input_buffer, 0);
@@ -777,10 +777,10 @@ mp3_frame_duration(const struct mad_frame *frame)
MAD_UNITS_MILLISECONDS) / 1000.0;
}
-inline input_stream::offset_type
+inline InputStream::offset_type
MadDecoder::ThisFrameOffset() const
{
- auto offset = input_stream->GetOffset();
+ auto offset = input_stream.GetOffset();
if (stream.this_frame != nullptr)
offset -= stream.bufend - stream.this_frame;
@@ -790,16 +790,16 @@ MadDecoder::ThisFrameOffset() const
return offset;
}
-inline input_stream::offset_type
+inline InputStream::offset_type
MadDecoder::RestIncludingThisFrame() const
{
- return input_stream->GetSize() - ThisFrameOffset();
+ return input_stream.GetSize() - ThisFrameOffset();
}
inline void
MadDecoder::FileSizeToSongLength()
{
- input_stream::offset_type rest = RestIncludingThisFrame();
+ InputStream::offset_type rest = RestIncludingThisFrame();
if (rest > 0) {
float frame_duration = mp3_frame_duration(&frame);
@@ -861,7 +861,7 @@ MadDecoder::DecodeFirstFrame(Tag **tag)
}
if (parse_lame(&lame, &ptr, &bitlen)) {
- if (gapless_playback && input_stream->IsSeekable()) {
+ if (gapless_playback && input_stream.IsSeekable()) {
drop_start_samples = lame.encoder_delay +
DECODERDELAY;
drop_end_samples = lame.encoder_padding;
@@ -908,7 +908,7 @@ MadDecoder::~MadDecoder()
/* this is primarily used for getting total time for tags */
static int
-mad_decoder_total_file_time(struct input_stream *is)
+mad_decoder_total_file_time(InputStream &is)
{
MadDecoder data(nullptr, is);
return data.DecodeFirstFrame(nullptr)
@@ -1063,7 +1063,7 @@ MadDecoder::Read()
if (cmd == DecoderCommand::SEEK) {
unsigned long j;
- assert(input_stream->IsSeekable());
+ assert(input_stream.IsSeekable());
j = TimeToFrame(decoder_seek_where(*decoder));
if (j < highest_frame) {
@@ -1116,7 +1116,7 @@ MadDecoder::Read()
}
static void
-mp3_decode(Decoder &decoder, struct input_stream *input_stream)
+mp3_decode(Decoder &decoder, InputStream &input_stream)
{
MadDecoder data(&decoder, input_stream);
@@ -1143,7 +1143,7 @@ mp3_decode(Decoder &decoder, struct input_stream *input_stream)
}
decoder_initialized(decoder, audio_format,
- input_stream->IsSeekable(),
+ input_stream.IsSeekable(),
data.total_time);
if (tag != nullptr) {
@@ -1155,7 +1155,7 @@ mp3_decode(Decoder &decoder, struct input_stream *input_stream)
}
static bool
-mad_decoder_scan_stream(struct input_stream *is,
+mad_decoder_scan_stream(InputStream &is,
const struct tag_handler *handler, void *handler_ctx)
{
int total_time;
diff --git a/src/decoder/ModplugDecoderPlugin.cxx b/src/decoder/ModplugDecoderPlugin.cxx
index a86166622..e75f5479c 100644
--- a/src/decoder/ModplugDecoderPlugin.cxx
+++ b/src/decoder/ModplugDecoderPlugin.cxx
@@ -36,7 +36,7 @@ static constexpr Domain modplug_domain("modplug");
static constexpr size_t MODPLUG_FRAME_SIZE = 4096;
static constexpr size_t MODPLUG_PREALLOC_BLOCK = 256 * 1024;
-static constexpr input_stream::offset_type MODPLUG_FILE_LIMIT = 100 * 1024 * 1024;
+static constexpr InputStream::offset_type MODPLUG_FILE_LIMIT = 100 * 1024 * 1024;
static int modplug_loop_count;
@@ -52,9 +52,9 @@ modplug_decoder_init(const config_param &param)
}
static WritableBuffer<uint8_t>
-mod_loadfile(Decoder *decoder, struct input_stream *is)
+mod_loadfile(Decoder *decoder, InputStream &is)
{
- const input_stream::offset_type size = is->GetSize();
+ const InputStream::offset_type size = is.GetSize();
if (size == 0) {
LogWarning(modplug_domain, "file is empty");
@@ -80,7 +80,7 @@ mod_loadfile(Decoder *decoder, struct input_stream *is)
while (true) {
size_t ret = decoder_read(decoder, is, p, end - p);
if (ret == 0) {
- if (is->LockIsEOF())
+ if (is.LockIsEOF())
/* end of file */
break;
@@ -107,7 +107,7 @@ mod_loadfile(Decoder *decoder, struct input_stream *is)
}
static ModPlugFile *
-LoadModPlugFile(Decoder *decoder, struct input_stream *is)
+LoadModPlugFile(Decoder *decoder, InputStream &is)
{
const auto buffer = mod_loadfile(decoder, is);
if (buffer.IsNull()) {
@@ -121,7 +121,7 @@ LoadModPlugFile(Decoder *decoder, struct input_stream *is)
}
static void
-mod_decode(Decoder &decoder, struct input_stream *is)
+mod_decode(Decoder &decoder, InputStream &is)
{
ModPlug_Settings settings;
int ret;
@@ -147,7 +147,7 @@ mod_decode(Decoder &decoder, struct input_stream *is)
assert(audio_format.IsValid());
decoder_initialized(decoder, audio_format,
- is->IsSeekable(),
+ is.IsSeekable(),
ModPlug_GetLength(f) / 1000.0);
DecoderCommand cmd;
@@ -174,7 +174,7 @@ mod_decode(Decoder &decoder, struct input_stream *is)
}
static bool
-modplug_scan_stream(struct input_stream *is,
+modplug_scan_stream(InputStream &is,
const struct tag_handler *handler, void *handler_ctx)
{
ModPlugFile *f = LoadModPlugFile(nullptr, is);
diff --git a/src/decoder/MpcdecDecoderPlugin.cxx b/src/decoder/MpcdecDecoderPlugin.cxx
index 1d38ec23b..feb2caeb4 100644
--- a/src/decoder/MpcdecDecoderPlugin.cxx
+++ b/src/decoder/MpcdecDecoderPlugin.cxx
@@ -35,8 +35,11 @@
#include <math.h>
struct mpc_decoder_data {
- struct input_stream *is;
+ InputStream &is;
Decoder *decoder;
+
+ mpc_decoder_data(InputStream &_is, Decoder *_decoder)
+ :is(_is), decoder(_decoder) {}
};
static constexpr Domain mpcdec_domain("mpcdec");
@@ -56,7 +59,7 @@ mpc_seek_cb(mpc_reader *reader, mpc_int32_t offset)
struct mpc_decoder_data *data =
(struct mpc_decoder_data *)reader->data;
- return data->is->LockSeek(offset, SEEK_SET, IgnoreError());
+ return data->is.LockSeek(offset, SEEK_SET, IgnoreError());
}
static mpc_int32_t
@@ -65,7 +68,7 @@ mpc_tell_cb(mpc_reader *reader)
struct mpc_decoder_data *data =
(struct mpc_decoder_data *)reader->data;
- return (long)data->is->GetOffset();
+ return (long)data->is.GetOffset();
}
static mpc_bool_t
@@ -74,7 +77,7 @@ mpc_canseek_cb(mpc_reader *reader)
struct mpc_decoder_data *data =
(struct mpc_decoder_data *)reader->data;
- return data->is->IsSeekable();
+ return data->is.IsSeekable();
}
static mpc_int32_t
@@ -83,7 +86,7 @@ mpc_getsize_cb(mpc_reader *reader)
struct mpc_decoder_data *data =
(struct mpc_decoder_data *)reader->data;
- return data->is->GetSize();
+ return data->is.GetSize();
}
/* this _looks_ performance-critical, don't de-inline -- eric */
@@ -130,13 +133,11 @@ mpc_to_mpd_buffer(int32_t *dest, const MPC_SAMPLE_FORMAT *src,
}
static void
-mpcdec_decode(Decoder &mpd_decoder, struct input_stream *is)
+mpcdec_decode(Decoder &mpd_decoder, InputStream &is)
{
MPC_SAMPLE_FORMAT sample_buffer[MPC_DECODER_BUFFER_LENGTH];
- struct mpc_decoder_data data;
- data.is = is;
- data.decoder = &mpd_decoder;
+ mpc_decoder_data data(is, &mpd_decoder);
mpc_reader reader;
reader.read = mpc_read_cb;
@@ -177,7 +178,7 @@ mpcdec_decode(Decoder &mpd_decoder, struct input_stream *is)
decoder_replay_gain(mpd_decoder, &replay_gain_info);
decoder_initialized(mpd_decoder, audio_format,
- is->IsSeekable(),
+ is.IsSeekable(),
mpc_streaminfo_get_length(&info));
DecoderCommand cmd = DecoderCommand::NONE;
@@ -227,11 +228,9 @@ mpcdec_decode(Decoder &mpd_decoder, struct input_stream *is)
}
static float
-mpcdec_get_file_duration(struct input_stream *is)
+mpcdec_get_file_duration(InputStream &is)
{
- struct mpc_decoder_data data;
- data.is = is;
- data.decoder = nullptr;
+ mpc_decoder_data data(is, nullptr);
mpc_reader reader;
reader.read = mpc_read_cb;
@@ -253,7 +252,7 @@ mpcdec_get_file_duration(struct input_stream *is)
}
static bool
-mpcdec_scan_stream(struct input_stream *is,
+mpcdec_scan_stream(InputStream &is,
const struct tag_handler *handler, void *handler_ctx)
{
float total_time = mpcdec_get_file_duration(is);
diff --git a/src/decoder/OggCodec.cxx b/src/decoder/OggCodec.cxx
index adc88188e..565dbafcf 100644
--- a/src/decoder/OggCodec.cxx
+++ b/src/decoder/OggCodec.cxx
@@ -27,7 +27,7 @@
#include <string.h>
enum ogg_codec
-ogg_codec_detect(Decoder *decoder, struct input_stream *is)
+ogg_codec_detect(Decoder *decoder, InputStream &is)
{
/* oggflac detection based on code in ogg123 and this post
* http://lists.xiph.org/pipermail/flac/2004-December/000393.html
diff --git a/src/decoder/OggCodec.hxx b/src/decoder/OggCodec.hxx
index b24b4ec5c..857871607 100644
--- a/src/decoder/OggCodec.hxx
+++ b/src/decoder/OggCodec.hxx
@@ -34,6 +34,6 @@ enum ogg_codec {
};
enum ogg_codec
-ogg_codec_detect(Decoder *decoder, struct input_stream *is);
+ogg_codec_detect(Decoder *decoder, InputStream &is);
#endif /* _OGG_COMMON_H */
diff --git a/src/decoder/OggSyncState.hxx b/src/decoder/OggSyncState.hxx
index c85b931bb..5235c1bd8 100644
--- a/src/decoder/OggSyncState.hxx
+++ b/src/decoder/OggSyncState.hxx
@@ -33,11 +33,11 @@
class OggSyncState {
ogg_sync_state oy;
- input_stream &is;
+ InputStream &is;
Decoder *const decoder;
public:
- OggSyncState(input_stream &_is, Decoder *const _decoder=nullptr)
+ OggSyncState(InputStream &_is, Decoder *const _decoder=nullptr)
:is(_is), decoder(_decoder) {
ogg_sync_init(&oy);
}
@@ -51,27 +51,27 @@ public:
}
bool Feed(size_t size) {
- return OggFeed(oy, decoder, &is, size);
+ return OggFeed(oy, decoder, is, size);
}
bool ExpectPage(ogg_page &page) {
- return OggExpectPage(oy, page, decoder, &is);
+ return OggExpectPage(oy, page, decoder, is);
}
bool ExpectFirstPage(ogg_stream_state &os) {
- return OggExpectFirstPage(oy, os, decoder, &is);
+ return OggExpectFirstPage(oy, os, decoder, is);
}
bool ExpectPageIn(ogg_stream_state &os) {
- return OggExpectPageIn(oy, os, decoder, &is);
+ return OggExpectPageIn(oy, os, decoder, is);
}
bool ExpectPageSeek(ogg_page &page) {
- return OggExpectPageSeek(oy, page, decoder, &is);
+ return OggExpectPageSeek(oy, page, decoder, is);
}
bool ExpectPageSeekIn(ogg_stream_state &os) {
- return OggExpectPageSeekIn(oy, os, decoder, &is);
+ return OggExpectPageSeekIn(oy, os, decoder, is);
}
};
diff --git a/src/decoder/OggUtil.cxx b/src/decoder/OggUtil.cxx
index 294a87276..f82d0a082 100644
--- a/src/decoder/OggUtil.cxx
+++ b/src/decoder/OggUtil.cxx
@@ -23,7 +23,7 @@
bool
OggFeed(ogg_sync_state &oy, Decoder *decoder,
- input_stream *input_stream, size_t size)
+ InputStream &input_stream, size_t size)
{
char *buffer = ogg_sync_buffer(&oy, size);
if (buffer == nullptr)
@@ -40,7 +40,7 @@ OggFeed(ogg_sync_state &oy, Decoder *decoder,
bool
OggExpectPage(ogg_sync_state &oy, ogg_page &page,
- Decoder *decoder, input_stream *input_stream)
+ Decoder *decoder, InputStream &input_stream)
{
while (true) {
int r = ogg_sync_pageout(&oy, &page);
@@ -54,7 +54,7 @@ OggExpectPage(ogg_sync_state &oy, ogg_page &page,
bool
OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os,
- Decoder *decoder, input_stream *is)
+ Decoder *decoder, InputStream &is)
{
ogg_page page;
if (!OggExpectPage(oy, page, decoder, is))
@@ -67,7 +67,7 @@ OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os,
bool
OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os,
- Decoder *decoder, input_stream *is)
+ Decoder *decoder, InputStream &is)
{
ogg_page page;
if (!OggExpectPage(oy, page, decoder, is))
@@ -79,7 +79,7 @@ OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os,
bool
OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page,
- Decoder *decoder, input_stream *input_stream)
+ Decoder *decoder, InputStream &input_stream)
{
size_t remaining_skipped = 16384;
@@ -107,7 +107,7 @@ OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page,
bool
OggExpectPageSeekIn(ogg_sync_state &oy, ogg_stream_state &os,
- Decoder *decoder, input_stream *is)
+ Decoder *decoder, InputStream &is)
{
ogg_page page;
if (!OggExpectPageSeek(oy, page, decoder, is))
diff --git a/src/decoder/OggUtil.hxx b/src/decoder/OggUtil.hxx
index 77ec83f2c..d9a54b2cf 100644
--- a/src/decoder/OggUtil.hxx
+++ b/src/decoder/OggUtil.hxx
@@ -26,16 +26,16 @@
#include <stddef.h>
-struct input_stream;
+struct InputStream;
struct Decoder;
/**
- * Feed data from the #input_stream into the #ogg_sync_state.
+ * Feed data from the #InputStream into the #ogg_sync_state.
*
* @return false on error or end-of-file
*/
bool
-OggFeed(ogg_sync_state &oy, Decoder *decoder, input_stream *is,
+OggFeed(ogg_sync_state &oy, Decoder *decoder, InputStream &is,
size_t size);
/**
@@ -46,7 +46,7 @@ OggFeed(ogg_sync_state &oy, Decoder *decoder, input_stream *is,
*/
bool
OggExpectPage(ogg_sync_state &oy, ogg_page &page,
- Decoder *decoder, input_stream *input_stream);
+ Decoder *decoder, InputStream &is);
/**
* Combines OggExpectPage(), ogg_stream_init() and
@@ -57,7 +57,7 @@ OggExpectPage(ogg_sync_state &oy, ogg_page &page,
*/
bool
OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os,
- Decoder *decoder, input_stream *is);
+ Decoder *decoder, InputStream &is);
/**
* Combines OggExpectPage() and ogg_stream_pagein().
@@ -66,14 +66,14 @@ OggExpectFirstPage(ogg_sync_state &oy, ogg_stream_state &os,
*/
bool
OggExpectPageIn(ogg_sync_state &oy, ogg_stream_state &os,
- Decoder *decoder, input_stream *is);
+ Decoder *decoder, InputStream &is);
/**
* Like OggExpectPage(), but allow skipping garbage (after seeking).
*/
bool
OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page,
- Decoder *decoder, input_stream *input_stream);
+ Decoder *decoder, InputStream &is);
/**
* Combines OggExpectPageSeek() and ogg_stream_pagein().
@@ -82,6 +82,6 @@ OggExpectPageSeek(ogg_sync_state &oy, ogg_page &page,
*/
bool
OggExpectPageSeekIn(ogg_sync_state &oy, ogg_stream_state &os,
- Decoder *decoder, input_stream *is);
+ Decoder *decoder, InputStream &is);
#endif
diff --git a/src/decoder/OpusDecoderPlugin.cxx b/src/decoder/OpusDecoderPlugin.cxx
index 1ef4b5f92..ad2ee6297 100644
--- a/src/decoder/OpusDecoderPlugin.cxx
+++ b/src/decoder/OpusDecoderPlugin.cxx
@@ -67,7 +67,7 @@ mpd_opus_init(gcc_unused const config_param &param)
class MPDOpusDecoder {
Decoder &decoder;
- struct input_stream *input_stream;
+ InputStream &input_stream;
ogg_stream_state os;
@@ -84,7 +84,7 @@ class MPDOpusDecoder {
public:
MPDOpusDecoder(Decoder &_decoder,
- struct input_stream *_input_stream)
+ InputStream &_input_stream)
:decoder(_decoder), input_stream(_input_stream),
opus_decoder(nullptr),
output_buffer(nullptr), output_size(0),
@@ -265,17 +265,17 @@ MPDOpusDecoder::HandleAudio(const ogg_packet &packet)
static void
mpd_opus_stream_decode(Decoder &decoder,
- struct input_stream *input_stream)
+ InputStream &input_stream)
{
if (ogg_codec_detect(&decoder, input_stream) != OGG_CODEC_OPUS)
return;
/* rewind the stream, because ogg_codec_detect() has
moved it */
- input_stream->LockRewind(IgnoreError());
+ input_stream.LockRewind(IgnoreError());
MPDOpusDecoder d(decoder, input_stream);
- OggSyncState oy(*input_stream, &decoder);
+ OggSyncState oy(input_stream, &decoder);
if (!d.ReadFirstPage(oy))
return;
@@ -293,27 +293,27 @@ mpd_opus_stream_decode(Decoder &decoder,
static bool
SeekFindEOS(OggSyncState &oy, ogg_stream_state &os, ogg_packet &packet,
- input_stream *is)
+ InputStream &is)
{
- if (is->size > 0 && is->size - is->offset < 65536)
+ if (is.size > 0 && is.size - is.offset < 65536)
return OggFindEOS(oy, os, packet);
- if (!is->CheapSeeking())
+ if (!is.CheapSeeking())
return false;
oy.Reset();
Error error;
- return is->LockSeek(-65536, SEEK_END, error) &&
+ return is.LockSeek(-65536, SEEK_END, error) &&
oy.ExpectPageSeekIn(os) &&
OggFindEOS(oy, os, packet);
}
static bool
-mpd_opus_scan_stream(struct input_stream *is,
+mpd_opus_scan_stream(InputStream &is,
const struct tag_handler *handler, void *handler_ctx)
{
- OggSyncState oy(*is);
+ OggSyncState oy(is);
ogg_stream_state os;
if (!oy.ExpectFirstPage(os))
diff --git a/src/decoder/PcmDecoderPlugin.cxx b/src/decoder/PcmDecoderPlugin.cxx
index 0a19ed59b..dbc38fb76 100644
--- a/src/decoder/PcmDecoderPlugin.cxx
+++ b/src/decoder/PcmDecoderPlugin.cxx
@@ -31,7 +31,7 @@
#include <stdio.h> /* for SEEK_SET */
static void
-pcm_stream_decode(Decoder &decoder, struct input_stream *is)
+pcm_stream_decode(Decoder &decoder, InputStream &is)
{
static constexpr AudioFormat audio_format = {
44100,
@@ -39,19 +39,19 @@ pcm_stream_decode(Decoder &decoder, struct input_stream *is)
2,
};
- const char *const mime = is->GetMimeType();
+ const char *const mime = is.GetMimeType();
const bool reverse_endian = mime != nullptr &&
strcmp(mime, "audio/x-mpd-cdda-pcm-reverse") == 0;
const double time_to_size = audio_format.GetTimeToSize();
float total_time = -1;
- const auto size = is->GetSize();
+ const auto size = is.GetSize();
if (size >= 0)
total_time = size / time_to_size;
decoder_initialized(decoder, audio_format,
- is->IsSeekable(), total_time);
+ is.IsSeekable(), total_time);
DecoderCommand cmd;
do {
@@ -60,7 +60,7 @@ pcm_stream_decode(Decoder &decoder, struct input_stream *is)
size_t nbytes = decoder_read(decoder, is,
buffer, sizeof(buffer));
- if (nbytes == 0 && is->LockIsEOF())
+ if (nbytes == 0 && is.LockIsEOF())
break;
if (reverse_endian)
@@ -74,11 +74,11 @@ pcm_stream_decode(Decoder &decoder, struct input_stream *is)
buffer, nbytes, 0)
: decoder_get_command(decoder);
if (cmd == DecoderCommand::SEEK) {
- input_stream::offset_type offset(time_to_size *
- decoder_seek_where(decoder));
+ InputStream::offset_type offset(time_to_size *
+ decoder_seek_where(decoder));
Error error;
- if (is->LockSeek(offset, SEEK_SET, error)) {
+ if (is.LockSeek(offset, SEEK_SET, error)) {
decoder_command_finished(decoder);
} else {
LogError(error);
diff --git a/src/decoder/SndfileDecoderPlugin.cxx b/src/decoder/SndfileDecoderPlugin.cxx
index 5f5c256e9..3360cd1bf 100644
--- a/src/decoder/SndfileDecoderPlugin.cxx
+++ b/src/decoder/SndfileDecoderPlugin.cxx
@@ -34,29 +34,29 @@ static constexpr Domain sndfile_domain("sndfile");
static sf_count_t
sndfile_vio_get_filelen(void *user_data)
{
- const struct input_stream *is = (const struct input_stream *)user_data;
+ const InputStream &is = *(const InputStream *)user_data;
- return is->GetSize();
+ return is.GetSize();
}
static sf_count_t
sndfile_vio_seek(sf_count_t offset, int whence, void *user_data)
{
- struct input_stream *is = (struct input_stream *)user_data;
+ InputStream &is = *(InputStream *)user_data;
- if (!is->LockSeek(offset, whence, IgnoreError()))
+ if (!is.LockSeek(offset, whence, IgnoreError()))
return -1;
- return is->GetOffset();
+ return is.GetOffset();
}
static sf_count_t
sndfile_vio_read(void *ptr, sf_count_t count, void *user_data)
{
- struct input_stream *is = (struct input_stream *)user_data;
+ InputStream &is = *(InputStream *)user_data;
Error error;
- size_t nbytes = is->LockRead(ptr, count, error);
+ size_t nbytes = is.LockRead(ptr, count, error);
if (nbytes == 0 && error.IsDefined()) {
LogError(error);
return -1;
@@ -77,9 +77,9 @@ sndfile_vio_write(gcc_unused const void *ptr,
static sf_count_t
sndfile_vio_tell(void *user_data)
{
- const struct input_stream *is = (const struct input_stream *)user_data;
+ const InputStream &is = *(const InputStream *)user_data;
- return is->GetOffset();
+ return is.GetOffset();
}
/**
@@ -113,7 +113,7 @@ time_to_frame(float t, const AudioFormat *audio_format)
}
static void
-sndfile_stream_decode(Decoder &decoder, struct input_stream *is)
+sndfile_stream_decode(Decoder &decoder, InputStream &is)
{
SNDFILE *sf;
SF_INFO info;
@@ -123,7 +123,7 @@ sndfile_stream_decode(Decoder &decoder, struct input_stream *is)
info.format = 0;
- sf = sf_open_virtual(&vio, SFM_READ, &info, is);
+ sf = sf_open_virtual(&vio, SFM_READ, &info, &is);
if (sf == nullptr) {
LogWarning(sndfile_domain, "sf_open_virtual() failed");
return;
diff --git a/src/decoder/VorbisDecoderPlugin.cxx b/src/decoder/VorbisDecoderPlugin.cxx
index c1d3566e1..8705d875f 100644
--- a/src/decoder/VorbisDecoderPlugin.cxx
+++ b/src/decoder/VorbisDecoderPlugin.cxx
@@ -54,14 +54,14 @@
struct vorbis_input_stream {
Decoder *decoder;
- struct input_stream *input_stream;
+ InputStream *input_stream;
bool seekable;
};
static size_t ogg_read_cb(void *ptr, size_t size, size_t nmemb, void *data)
{
struct vorbis_input_stream *vis = (struct vorbis_input_stream *)data;
- size_t ret = decoder_read(vis->decoder, vis->input_stream,
+ size_t ret = decoder_read(vis->decoder, *vis->input_stream,
ptr, size * nmemb);
errno = 0;
@@ -127,11 +127,11 @@ vorbis_strerror(int code)
static bool
vorbis_is_open(struct vorbis_input_stream *vis, OggVorbis_File *vf,
- Decoder *decoder, struct input_stream *input_stream)
+ Decoder *decoder, InputStream &input_stream)
{
vis->decoder = decoder;
- vis->input_stream = input_stream;
- vis->seekable = input_stream->CheapSeeking();
+ vis->input_stream = &input_stream;
+ vis->seekable = input_stream.CheapSeeking();
int ret = ov_open_callbacks(vis, vf, NULL, 0, vorbis_is_callbacks);
if (ret < 0) {
@@ -147,7 +147,7 @@ vorbis_is_open(struct vorbis_input_stream *vis, OggVorbis_File *vf,
}
static void
-vorbis_send_comments(Decoder &decoder, struct input_stream *is,
+vorbis_send_comments(Decoder &decoder, InputStream &is,
char **comments)
{
Tag *tag = vorbis_comments_to_tag(comments);
@@ -176,14 +176,14 @@ vorbis_interleave(float *dest, const float *const*src,
/* public */
static void
vorbis_stream_decode(Decoder &decoder,
- struct input_stream *input_stream)
+ InputStream &input_stream)
{
if (ogg_codec_detect(&decoder, input_stream) != OGG_CODEC_VORBIS)
return;
/* rewind the stream, because ogg_codec_detect() has
moved it */
- input_stream->LockRewind(IgnoreError());
+ input_stream.LockRewind(IgnoreError());
struct vorbis_input_stream vis;
OggVorbis_File vf;
@@ -303,7 +303,7 @@ vorbis_stream_decode(Decoder &decoder,
}
static bool
-vorbis_scan_stream(struct input_stream *is,
+vorbis_scan_stream(InputStream &is,
const struct tag_handler *handler, void *handler_ctx)
{
struct vorbis_input_stream vis;
diff --git a/src/decoder/WavpackDecoderPlugin.cxx b/src/decoder/WavpackDecoderPlugin.cxx
index 9805a5f78..3588f0797 100644
--- a/src/decoder/WavpackDecoderPlugin.cxx
+++ b/src/decoder/WavpackDecoderPlugin.cxx
@@ -346,7 +346,7 @@ wavpack_scan_file(const char *fname,
/* This struct is needed for per-stream last_byte storage. */
struct wavpack_input {
Decoder *decoder;
- struct input_stream *is;
+ InputStream *is;
/* Needed for push_back_byte() */
int last_byte;
};
@@ -378,7 +378,7 @@ wavpack_input_read_bytes(void *id, void *data, int32_t bcount)
until the buffer is full */
while (bcount > 0) {
size_t nbytes = decoder_read(
- wpin(id)->decoder, wpin(id)->is, buf, bcount
+ wpin(id)->decoder, *wpin(id)->is, buf, bcount
);
if (nbytes == 0) {
/* EOF, error or a decoder command */
@@ -450,19 +450,19 @@ static WavpackStreamReader mpd_is_reader = {
static void
wavpack_input_init(struct wavpack_input *isp, Decoder &decoder,
- struct input_stream *is)
+ InputStream &is)
{
isp->decoder = &decoder;
- isp->is = is;
+ isp->is = &is;
isp->last_byte = EOF;
}
-static struct input_stream *
+static InputStream *
wavpack_open_wvc(Decoder &decoder, const char *uri,
Mutex &mutex, Cond &cond,
struct wavpack_input *wpi)
{
- struct input_stream *is_wvc;
+ InputStream *is_wvc;
char *wvc_url = nullptr;
char first_byte;
size_t nbytes;
@@ -476,7 +476,7 @@ wavpack_open_wvc(Decoder &decoder, const char *uri,
wvc_url = g_strconcat(uri, "c", nullptr);
- is_wvc = input_stream::Open(wvc_url, mutex, cond, IgnoreError());
+ is_wvc = InputStream::Open(wvc_url, mutex, cond, IgnoreError());
g_free(wvc_url);
if (is_wvc == nullptr)
@@ -487,7 +487,7 @@ wavpack_open_wvc(Decoder &decoder, const char *uri,
* about a possible 404 error.
*/
nbytes = decoder_read(
- decoder, is_wvc, &first_byte, sizeof(first_byte)
+ decoder, *is_wvc, &first_byte, sizeof(first_byte)
);
if (nbytes == 0) {
is_wvc->Close();
@@ -495,7 +495,7 @@ wavpack_open_wvc(Decoder &decoder, const char *uri,
}
/* push it back */
- wavpack_input_init(wpi, decoder, is_wvc);
+ wavpack_input_init(wpi, decoder, *is_wvc);
wpi->last_byte = first_byte;
return is_wvc;
}
@@ -504,17 +504,17 @@ wavpack_open_wvc(Decoder &decoder, const char *uri,
* Decodes a stream.
*/
static void
-wavpack_streamdecode(Decoder & decoder, struct input_stream *is)
+wavpack_streamdecode(Decoder &decoder, InputStream &is)
{
char error[ERRORLEN];
WavpackContext *wpc;
- struct input_stream *is_wvc;
+ InputStream *is_wvc;
int open_flags = OPEN_NORMALIZE;
struct wavpack_input isp, isp_wvc;
- bool can_seek = is->seekable;
+ bool can_seek = is.seekable;
- is_wvc = wavpack_open_wvc(decoder, is->uri.c_str(),
- is->mutex, is->cond,
+ is_wvc = wavpack_open_wvc(decoder, is.uri.c_str(),
+ is.mutex, is.cond,
&isp_wvc);
if (is_wvc != nullptr) {
open_flags |= OPEN_WVC;