InputStream: use int64_t instead of goffset
Decouple some more from GLib.
This commit is contained in:
parent
24780d99e6
commit
05de2e998c
@ -23,9 +23,8 @@
|
||||
#include "thread/Mutex.hxx"
|
||||
#include "thread/Cond.hxx"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct config_param;
|
||||
struct input_stream;
|
||||
@ -33,6 +32,8 @@ class Error;
|
||||
struct Tag;
|
||||
|
||||
struct InputPlugin {
|
||||
typedef int64_t offset_type;
|
||||
|
||||
const char *name;
|
||||
|
||||
/**
|
||||
@ -85,7 +86,7 @@ struct InputPlugin {
|
||||
size_t (*read)(struct input_stream *is, void *ptr, size_t size,
|
||||
Error &error);
|
||||
bool (*eof)(struct input_stream *is);
|
||||
bool (*seek)(struct input_stream *is, goffset offset, int whence,
|
||||
bool (*seek)(struct input_stream *is, offset_type offset, int whence,
|
||||
Error &error);
|
||||
};
|
||||
|
||||
|
@ -95,7 +95,7 @@ input_stream::CheapSeeking() const
|
||||
}
|
||||
|
||||
bool
|
||||
input_stream::Seek(goffset _offset, int whence, Error &error)
|
||||
input_stream::Seek(offset_type _offset, int whence, Error &error)
|
||||
{
|
||||
if (plugin.seek == nullptr)
|
||||
return false;
|
||||
@ -104,7 +104,7 @@ input_stream::Seek(goffset _offset, int whence, Error &error)
|
||||
}
|
||||
|
||||
bool
|
||||
input_stream::LockSeek(goffset _offset, int whence, Error &error)
|
||||
input_stream::LockSeek(offset_type _offset, int whence, Error &error)
|
||||
{
|
||||
if (plugin.seek == nullptr)
|
||||
return false;
|
||||
|
@ -26,9 +26,8 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
class Cond;
|
||||
class Error;
|
||||
@ -36,6 +35,8 @@ struct Tag;
|
||||
struct InputPlugin;
|
||||
|
||||
struct input_stream {
|
||||
typedef int64_t offset_type;
|
||||
|
||||
/**
|
||||
* the plugin which implements this input stream
|
||||
*/
|
||||
@ -80,12 +81,12 @@ struct input_stream {
|
||||
/**
|
||||
* the size of the resource, or -1 if unknown
|
||||
*/
|
||||
goffset size;
|
||||
offset_type size;
|
||||
|
||||
/**
|
||||
* the current offset within the stream
|
||||
*/
|
||||
goffset offset;
|
||||
offset_type offset;
|
||||
|
||||
/**
|
||||
* the MIME content type of the resource, or empty if unknown.
|
||||
@ -173,14 +174,14 @@ struct input_stream {
|
||||
}
|
||||
|
||||
gcc_pure
|
||||
goffset GetSize() const {
|
||||
offset_type GetSize() const {
|
||||
assert(ready);
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
gcc_pure
|
||||
goffset GetOffset() const {
|
||||
offset_type GetOffset() const {
|
||||
assert(ready);
|
||||
|
||||
return offset;
|
||||
@ -208,13 +209,13 @@ struct input_stream {
|
||||
* @param offset the relative offset
|
||||
* @param whence the base of the seek, one of SEEK_SET, SEEK_CUR, SEEK_END
|
||||
*/
|
||||
bool Seek(goffset offset, int whence, Error &error);
|
||||
bool Seek(offset_type offset, int whence, Error &error);
|
||||
|
||||
/**
|
||||
* Wrapper for Seek() which locks and unlocks the mutex; the
|
||||
* caller must not be holding it already.
|
||||
*/
|
||||
bool LockSeek(goffset offset, int whence, Error &error);
|
||||
bool LockSeek(offset_type offset, int whence, Error &error);
|
||||
|
||||
/**
|
||||
* Returns true if the stream has reached end-of-file.
|
||||
|
@ -36,6 +36,8 @@
|
||||
#include "util/Error.hxx"
|
||||
#include "thread/Cond.hxx"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
void
|
||||
playlist_print_uris(Client *client, const struct playlist *playlist)
|
||||
{
|
||||
|
@ -28,6 +28,8 @@
|
||||
#include "Song.hxx"
|
||||
#include "thread/Cond.hxx"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
enum playlist_result
|
||||
playlist_load_into_queue(const char *uri, SongEnumerator &e,
|
||||
unsigned start_index, unsigned end_index,
|
||||
|
@ -40,6 +40,8 @@
|
||||
#include "system/FatalError.hxx"
|
||||
#include "Log.hxx"
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
@ -178,12 +178,12 @@ zzip_input_eof(struct input_stream *is)
|
||||
{
|
||||
ZzipInputStream *zis = (ZzipInputStream *)is;
|
||||
|
||||
return (goffset)zzip_tell(zis->file) == is->size;
|
||||
return (InputPlugin::offset_type)zzip_tell(zis->file) == is->size;
|
||||
}
|
||||
|
||||
static bool
|
||||
zzip_input_seek(struct input_stream *is,
|
||||
goffset offset, int whence, Error &error)
|
||||
zzip_input_seek(struct input_stream *is, InputPlugin::offset_type offset,
|
||||
int whence, Error &error)
|
||||
{
|
||||
ZzipInputStream *zis = (ZzipInputStream *)is;
|
||||
zzip_off_t ofs = zzip_seek(zis->file, offset, whence);
|
||||
|
@ -63,7 +63,7 @@ dsdlib_read(struct decoder *decoder, struct input_stream *is,
|
||||
*/
|
||||
bool
|
||||
dsdlib_skip_to(struct decoder *decoder, struct input_stream *is,
|
||||
goffset offset)
|
||||
int64_t offset)
|
||||
{
|
||||
if (is->IsSeekable())
|
||||
return is->Seek(offset, SEEK_SET, IgnoreError());
|
||||
@ -74,7 +74,7 @@ dsdlib_skip_to(struct decoder *decoder, struct input_stream *is,
|
||||
char buffer[8192];
|
||||
while (is->GetOffset() < offset) {
|
||||
size_t length = sizeof(buffer);
|
||||
if (offset - is->GetOffset() < (goffset)length)
|
||||
if (offset - is->GetOffset() < (int64_t)length)
|
||||
length = offset - is->GetOffset();
|
||||
|
||||
size_t nbytes = decoder_read(decoder, is, buffer, length);
|
||||
@ -91,7 +91,7 @@ dsdlib_skip_to(struct decoder *decoder, struct input_stream *is,
|
||||
*/
|
||||
bool
|
||||
dsdlib_skip(struct decoder *decoder, struct input_stream *is,
|
||||
goffset delta)
|
||||
int64_t delta)
|
||||
{
|
||||
assert(delta >= 0);
|
||||
|
||||
@ -104,7 +104,7 @@ dsdlib_skip(struct decoder *decoder, struct input_stream *is,
|
||||
char buffer[8192];
|
||||
while (delta > 0) {
|
||||
size_t length = sizeof(buffer);
|
||||
if ((goffset)length > delta)
|
||||
if ((int64_t)length > delta)
|
||||
length = delta;
|
||||
|
||||
size_t nbytes = decoder_read(decoder, is, buffer, length);
|
||||
@ -126,7 +126,7 @@ dsdlib_skip(struct decoder *decoder, struct input_stream *is,
|
||||
void
|
||||
dsdlib_tag_id3(struct input_stream *is,
|
||||
const struct tag_handler *handler,
|
||||
void *handler_ctx, goffset tagoffset)
|
||||
void *handler_ctx, int64_t tagoffset)
|
||||
{
|
||||
assert(tagoffset >= 0);
|
||||
|
||||
@ -140,8 +140,8 @@ dsdlib_tag_id3(struct input_stream *is,
|
||||
id3_length_t count;
|
||||
|
||||
/* Prevent broken files causing problems */
|
||||
const goffset size = is->GetSize();
|
||||
const goffset offset = is->GetOffset();
|
||||
const auto size = is->GetSize();
|
||||
const auto offset = is->GetOffset();
|
||||
if (offset >= size)
|
||||
return;
|
||||
|
||||
|
@ -21,8 +21,7 @@
|
||||
#define MPD_DECODER_DSDLIB_HXX
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <glib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
struct dsdlib_id {
|
||||
char value[4];
|
||||
@ -37,15 +36,15 @@ dsdlib_read(struct decoder *decoder, struct input_stream *is,
|
||||
|
||||
bool
|
||||
dsdlib_skip_to(struct decoder *decoder, struct input_stream *is,
|
||||
goffset offset);
|
||||
int64_t offset);
|
||||
|
||||
bool
|
||||
dsdlib_skip(struct decoder *decoder, struct input_stream *is,
|
||||
goffset delta);
|
||||
int64_t delta);
|
||||
|
||||
void
|
||||
dsdlib_tag_id3(struct input_stream *is,
|
||||
const struct tag_handler *handler,
|
||||
void *handler_ctx, goffset tagoffset);
|
||||
void *handler_ctx, int64_t tagoffset);
|
||||
|
||||
#endif
|
||||
|
@ -72,13 +72,13 @@ struct DsdiffMetaData {
|
||||
bool bitreverse;
|
||||
uint64_t chunk_size;
|
||||
#ifdef HAVE_ID3TAG
|
||||
goffset id3_offset;
|
||||
input_stream::offset_type id3_offset;
|
||||
uint64_t id3_size;
|
||||
#endif
|
||||
/** offset for artist tag */
|
||||
goffset diar_offset;
|
||||
input_stream::offset_type diar_offset;
|
||||
/** offset for title tag */
|
||||
goffset diti_offset;
|
||||
input_stream::offset_type diti_offset;
|
||||
};
|
||||
|
||||
static bool lsbitfirst;
|
||||
@ -123,14 +123,14 @@ dsdiff_read_payload(struct decoder *decoder, struct input_stream *is,
|
||||
static bool
|
||||
dsdiff_read_prop_snd(struct decoder *decoder, struct input_stream *is,
|
||||
DsdiffMetaData *metadata,
|
||||
goffset end_offset)
|
||||
input_stream::offset_type end_offset)
|
||||
{
|
||||
DsdiffChunkHeader header;
|
||||
while ((goffset)(is->GetOffset() + sizeof(header)) <= end_offset) {
|
||||
while ((input_stream::offset_type)(is->GetOffset() + sizeof(header)) <= end_offset) {
|
||||
if (!dsdiff_read_chunk_header(decoder, is, &header))
|
||||
return false;
|
||||
|
||||
goffset chunk_end_offset = is->GetOffset()
|
||||
input_stream::offset_type chunk_end_offset = is->GetOffset()
|
||||
+ header.GetSize();
|
||||
if (chunk_end_offset > end_offset)
|
||||
return false;
|
||||
@ -184,7 +184,7 @@ dsdiff_read_prop(struct decoder *decoder, struct input_stream *is,
|
||||
const DsdiffChunkHeader *prop_header)
|
||||
{
|
||||
uint64_t prop_size = prop_header->GetSize();
|
||||
goffset end_offset = is->GetOffset() + prop_size;
|
||||
input_stream::offset_type end_offset = is->GetOffset() + prop_size;
|
||||
|
||||
struct dsdlib_id prop_id;
|
||||
if (prop_size < sizeof(prop_id) ||
|
||||
@ -201,7 +201,7 @@ dsdiff_read_prop(struct decoder *decoder, struct input_stream *is,
|
||||
static void
|
||||
dsdiff_handle_native_tag(struct input_stream *is,
|
||||
const struct tag_handler *handler,
|
||||
void *handler_ctx, goffset tagoffset,
|
||||
void *handler_ctx, input_stream::offset_type tagoffset,
|
||||
enum tag_type type)
|
||||
{
|
||||
if (!dsdlib_skip_to(nullptr, is, tagoffset))
|
||||
@ -259,7 +259,7 @@ dsdiff_read_metadata_extra(struct decoder *decoder, struct input_stream *is,
|
||||
/* Now process all the remaining chunk headers in the stream
|
||||
and record their position and size */
|
||||
|
||||
const goffset size = is->GetSize();
|
||||
const auto size = is->GetSize();
|
||||
while (is->GetOffset() < size) {
|
||||
uint64_t chunk_size = chunk_header->GetSize();
|
||||
|
||||
@ -351,8 +351,8 @@ dsdiff_read_metadata(struct decoder *decoder, struct input_stream *is,
|
||||
} else {
|
||||
/* ignore unknown chunk */
|
||||
const uint64_t chunk_size = chunk_header->GetSize();
|
||||
goffset chunk_end_offset = is->GetOffset()
|
||||
+ chunk_size;
|
||||
input_stream::offset_type chunk_end_offset =
|
||||
is->GetOffset() + chunk_size;
|
||||
|
||||
if (!dsdlib_skip_to(decoder, is, chunk_end_offset))
|
||||
return false;
|
||||
|
@ -47,7 +47,7 @@ struct DsfMetaData {
|
||||
bool bitreverse;
|
||||
uint64_t chunk_size;
|
||||
#ifdef HAVE_ID3TAG
|
||||
goffset id3_offset;
|
||||
input_stream::offset_type id3_offset;
|
||||
uint64_t id3_size;
|
||||
#endif
|
||||
};
|
||||
@ -176,7 +176,7 @@ dsf_read_metadata(struct decoder *decoder, struct input_stream *is,
|
||||
if (metadata_offset >= size)
|
||||
metadata->id3_offset = 0;
|
||||
else
|
||||
metadata->id3_offset = (goffset) metadata_offset;
|
||||
metadata->id3_offset = (input_stream::offset_type)metadata_offset;
|
||||
#endif
|
||||
/* check bits per sample format, determine if bitreverse is needed */
|
||||
metadata->bitreverse = dsf_fmt_chunk.bitssample == 1;
|
||||
|
@ -170,7 +170,7 @@ faad_song_duration(DecoderBuffer *buffer, struct input_stream *is)
|
||||
size_t length;
|
||||
bool success;
|
||||
|
||||
const goffset size = is->GetSize();
|
||||
const auto size = is->GetSize();
|
||||
fileread = size >= 0 ? size : 0;
|
||||
|
||||
decoder_buffer_fill(buffer);
|
||||
|
@ -152,10 +152,10 @@ struct MadDecoder {
|
||||
enum mp3_action DecodeNextFrame();
|
||||
|
||||
gcc_pure
|
||||
goffset ThisFrameOffset() const;
|
||||
input_stream::offset_type ThisFrameOffset() const;
|
||||
|
||||
gcc_pure
|
||||
goffset RestIncludingThisFrame() const;
|
||||
input_stream::offset_type RestIncludingThisFrame() const;
|
||||
|
||||
/**
|
||||
* Attempt to calulcate the length of the song from filesize
|
||||
@ -776,10 +776,10 @@ mp3_frame_duration(const struct mad_frame *frame)
|
||||
MAD_UNITS_MILLISECONDS) / 1000.0;
|
||||
}
|
||||
|
||||
inline goffset
|
||||
inline input_stream::offset_type
|
||||
MadDecoder::ThisFrameOffset() const
|
||||
{
|
||||
goffset offset = input_stream->GetOffset();
|
||||
auto offset = input_stream->GetOffset();
|
||||
|
||||
if (stream.this_frame != nullptr)
|
||||
offset -= stream.bufend - stream.this_frame;
|
||||
@ -789,7 +789,7 @@ MadDecoder::ThisFrameOffset() const
|
||||
return offset;
|
||||
}
|
||||
|
||||
inline goffset
|
||||
inline input_stream::offset_type
|
||||
MadDecoder::RestIncludingThisFrame() const
|
||||
{
|
||||
return input_stream->GetSize() - ThisFrameOffset();
|
||||
@ -798,7 +798,7 @@ MadDecoder::RestIncludingThisFrame() const
|
||||
inline void
|
||||
MadDecoder::FileSizeToSongLength()
|
||||
{
|
||||
goffset rest = RestIncludingThisFrame();
|
||||
input_stream::offset_type rest = RestIncludingThisFrame();
|
||||
|
||||
if (rest > 0) {
|
||||
float frame_duration = mp3_frame_duration(&frame);
|
||||
|
@ -36,12 +36,12 @@ 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 size_t MODPLUG_READ_BLOCK = 128 * 1024;
|
||||
static constexpr goffset MODPLUG_FILE_LIMIT = 100 * 1024 * 1024;
|
||||
static constexpr input_stream::offset_type MODPLUG_FILE_LIMIT = 100 * 1024 * 1024;
|
||||
|
||||
static GByteArray *
|
||||
mod_loadfile(struct decoder *decoder, struct input_stream *is)
|
||||
{
|
||||
const goffset size = is->GetSize();
|
||||
const input_stream::offset_type size = is->GetSize();
|
||||
|
||||
if (size == 0) {
|
||||
LogWarning(modplug_domain, "file is empty");
|
||||
@ -77,7 +77,7 @@ mod_loadfile(struct decoder *decoder, struct input_stream *is)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (goffset(bdatas->len + ret) > MODPLUG_FILE_LIMIT) {
|
||||
if (input_stream::offset_type(bdatas->len + ret) > MODPLUG_FILE_LIMIT) {
|
||||
LogWarning(modplug_domain, "stream too large");
|
||||
g_free(data);
|
||||
g_byte_array_free(bdatas, TRUE);
|
||||
|
@ -46,7 +46,7 @@ pcm_stream_decode(struct decoder *decoder, struct input_stream *is)
|
||||
const double time_to_size = audio_format.GetTimeToSize();
|
||||
|
||||
float total_time = -1;
|
||||
const goffset size = is->GetSize();
|
||||
const auto size = is->GetSize();
|
||||
if (size >= 0)
|
||||
total_time = size / time_to_size;
|
||||
|
||||
@ -74,8 +74,8 @@ pcm_stream_decode(struct decoder *decoder, struct input_stream *is)
|
||||
buffer, nbytes, 0)
|
||||
: decoder_get_command(decoder);
|
||||
if (cmd == DecoderCommand::SEEK) {
|
||||
goffset offset = (goffset)(time_to_size *
|
||||
decoder_seek_where(decoder));
|
||||
input_stream::offset_type offset(time_to_size *
|
||||
decoder_seek_where(decoder));
|
||||
|
||||
Error error;
|
||||
if (is->LockSeek(offset, SEEK_SET, error)) {
|
||||
|
@ -250,7 +250,7 @@ input_cdio_open(const char *uri,
|
||||
|
||||
static bool
|
||||
input_cdio_seek(struct input_stream *is,
|
||||
goffset offset, int whence, Error &error)
|
||||
InputPlugin::offset_type offset, int whence, Error &error)
|
||||
{
|
||||
CdioParanoiaInputStream *cis = (CdioParanoiaInputStream *)is;
|
||||
|
||||
|
@ -780,7 +780,7 @@ input_curl_read(struct input_stream *is, void *ptr, size_t size,
|
||||
if (c->icy.IsDefined())
|
||||
copy_icy_tag(c);
|
||||
|
||||
is->offset += (goffset)nbytes;
|
||||
is->offset += (InputPlugin::offset_type)nbytes;
|
||||
|
||||
if (c->paused && curl_total_buffer_size(c) < CURL_RESUME_AT) {
|
||||
c->base.mutex.unlock();
|
||||
@ -977,7 +977,8 @@ input_curl_easy_init(struct input_curl *c, Error &error)
|
||||
}
|
||||
|
||||
static bool
|
||||
input_curl_seek(struct input_stream *is, goffset offset, int whence,
|
||||
input_curl_seek(struct input_stream *is, InputPlugin::offset_type offset,
|
||||
int whence,
|
||||
Error &error)
|
||||
{
|
||||
struct input_curl *c = (struct input_curl *)is;
|
||||
@ -1022,7 +1023,7 @@ input_curl_seek(struct input_stream *is, goffset offset, int whence,
|
||||
while (offset > is->offset && !c->buffers.empty()) {
|
||||
auto &buffer = c->buffers.front();
|
||||
size_t length = buffer.Available();
|
||||
if (offset - is->offset < (goffset)length)
|
||||
if (offset - is->offset < (InputPlugin::offset_type)length)
|
||||
length = offset - is->offset;
|
||||
|
||||
const bool empty = !buffer.Consume(length);
|
||||
|
@ -34,6 +34,8 @@ extern "C" {
|
||||
#include <libavformat/avformat.h>
|
||||
}
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
struct FfmpegInputStream {
|
||||
struct input_stream base;
|
||||
|
||||
@ -146,7 +148,8 @@ input_ffmpeg_eof(struct input_stream *is)
|
||||
}
|
||||
|
||||
static bool
|
||||
input_ffmpeg_seek(struct input_stream *is, goffset offset, int whence,
|
||||
input_ffmpeg_seek(struct input_stream *is, InputPlugin::offset_type offset,
|
||||
int whence,
|
||||
Error &error)
|
||||
{
|
||||
FfmpegInputStream *i = (FfmpegInputStream *)is;
|
||||
|
@ -97,12 +97,13 @@ input_file_open(const char *filename,
|
||||
}
|
||||
|
||||
static bool
|
||||
input_file_seek(struct input_stream *is, goffset offset, int whence,
|
||||
input_file_seek(struct input_stream *is, InputPlugin::offset_type offset,
|
||||
int whence,
|
||||
Error &error)
|
||||
{
|
||||
FileInputStream *fis = (FileInputStream *)is;
|
||||
|
||||
offset = (goffset)lseek(fis->fd, (off_t)offset, whence);
|
||||
offset = (InputPlugin::offset_type)lseek(fis->fd, (off_t)offset, whence);
|
||||
if (offset < 0) {
|
||||
error.SetErrno("Failed to seek");
|
||||
return false;
|
||||
|
@ -164,7 +164,7 @@ input_rewind_read(struct input_stream *is, void *ptr, size_t size,
|
||||
|
||||
size_t nbytes = r->input->Read(ptr, size, error);
|
||||
|
||||
if (r->input->offset > (goffset)sizeof(r->buffer))
|
||||
if (r->input->offset > (InputPlugin::offset_type)sizeof(r->buffer))
|
||||
/* disable buffering */
|
||||
r->tail = 0;
|
||||
else if (r->tail == (size_t)is->offset) {
|
||||
@ -191,14 +191,16 @@ input_rewind_eof(struct input_stream *is)
|
||||
}
|
||||
|
||||
static bool
|
||||
input_rewind_seek(struct input_stream *is, goffset offset, int whence,
|
||||
input_rewind_seek(struct input_stream *is, InputPlugin::offset_type offset,
|
||||
int whence,
|
||||
Error &error)
|
||||
{
|
||||
RewindInputStream *r = (RewindInputStream *)is;
|
||||
|
||||
assert(is->ready);
|
||||
|
||||
if (whence == SEEK_SET && r->tail > 0 && offset <= (goffset)r->tail) {
|
||||
if (whence == SEEK_SET && r->tail > 0 &&
|
||||
offset <= (InputPlugin::offset_type)r->tail) {
|
||||
/* buffered seek */
|
||||
|
||||
assert(!r->ReadingFromBuffer() ||
|
||||
|
Loading…
Reference in New Issue
Block a user