InputStream: "protect" attributes

This commit is contained in:
Max Kellermann
2014-05-11 18:34:09 +02:00
parent e138e2c880
commit 0b4fa41aff
14 changed files with 53 additions and 37 deletions

View File

@@ -121,12 +121,12 @@ 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.GetSize();
if (!stream->input.LockSeek(pos, whence, IgnoreError()))
return -1;
return stream->input.offset;
return stream->input.GetOffset();
}
bool
@@ -135,7 +135,7 @@ AvioStream::Open()
io = avio_alloc_context(buffer, sizeof(buffer),
false, this,
mpd_ffmpeg_stream_read, nullptr,
input.seekable
input.IsSeekable()
? mpd_ffmpeg_stream_seek : nullptr);
return io != nullptr;
}
@@ -481,7 +481,7 @@ ffmpeg_decode(Decoder &decoder, InputStream &input)
: 0;
decoder_initialized(decoder, audio_format,
input.seekable, total_time);
input.IsSeekable(), total_time);
#if LIBAVUTIL_VERSION_MAJOR >= 53
AVFrame *frame = av_frame_alloc();

View File

@@ -137,7 +137,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.IsSeekable(),
(float)data->total_frames /
(float)data->audio_format.sample_rate);

View File

@@ -145,13 +145,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.IsSeekable(),
(float)data->total_frames /
(float)data->audio_format.sample_rate);
return true;
}
if (data->input_stream.seekable)
if (data->input_stream.IsSeekable())
/* allow the workaround below only for nonseekable
streams*/
return false;

View File

@@ -75,7 +75,7 @@ FlacIOTell(FLAC__IOHandle handle)
{
InputStream *is = (InputStream *)handle;
return is->offset;
return is->GetOffset();
}
static int

View File

@@ -37,7 +37,7 @@ ToFlacIOHandle(InputStream &is)
static inline const FLAC__IOCallbacks &
GetFlacIOCallbacks(const InputStream &is)
{
return is.seekable
return is.IsSeekable()
? flac_io_callbacks_seekable
: flac_io_callbacks;
}

View File

@@ -47,7 +47,7 @@ FlacInput::Read(FLAC__byte buffer[], size_t *bytes)
FLAC__StreamDecoderSeekStatus
FlacInput::Seek(FLAC__uint64 absolute_byte_offset)
{
if (!input_stream.seekable)
if (!input_stream.IsSeekable())
return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
::Error 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.IsSeekable())
return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
*absolute_byte_offset = (FLAC__uint64)input_stream.offset;
*absolute_byte_offset = (FLAC__uint64)input_stream.GetOffset();
return FLAC__STREAM_DECODER_TELL_STATUS_OK;
}
FLAC__StreamDecoderLengthStatus
FlacInput::Length(FLAC__uint64 *stream_length)
{
if (input_stream.size < 0)
if (!input_stream.KnownSize())
return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
*stream_length = (FLAC__uint64)input_stream.size;
*stream_length = (FLAC__uint64)input_stream.GetSize();
return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
}

View File

@@ -57,7 +57,7 @@ bool
OggSeekFindEOS(OggSyncState &oy, ogg_stream_state &os, ogg_packet &packet,
InputStream &is)
{
if (is.size > 0 && is.size - is.offset < 65536)
if (is.KnownSize() && is.GetRest() < 65536)
return OggFindEOS(oy, os, packet);
if (!is.CheapSeeking())

View File

@@ -185,7 +185,7 @@ LoadEOSPacket(InputStream &is, Decoder *decoder, int serialno,
troubl */
return -1;
const auto old_offset = is.offset;
const auto old_offset = is.GetOffset();
if (old_offset < 0)
return -1;
@@ -332,16 +332,16 @@ bool
MPDOpusDecoder::Seek(OggSyncState &oy, double where_s)
{
assert(eos_granulepos > 0);
assert(input_stream.seekable);
assert(input_stream.size > 0);
assert(input_stream.offset >= 0);
assert(input_stream.IsSeekable());
assert(input_stream.KnownSize());
assert(input_stream.GetOffset() >= 0);
const ogg_int64_t where_granulepos(where_s * opus_sample_rate);
/* interpolate the file offset where we expect to find the
given granule position */
/* TODO: implement binary search */
InputStream::offset_type offset(where_granulepos * input_stream.size
InputStream::offset_type offset(where_granulepos * input_stream.GetSize()
/ eos_granulepos);
if (!OggSeekPageAtOffset(oy, os, input_stream, offset, SEEK_SET))

View File

@@ -88,7 +88,7 @@ static long ogg_tell_cb(void *data)
{
struct vorbis_input_stream *vis = (struct vorbis_input_stream *)data;
return (long)vis->input_stream->offset;
return (long)vis->input_stream->GetOffset();
}
static const ov_callbacks vorbis_is_callbacks = {

View File

@@ -377,7 +377,7 @@ wavpack_input_read_bytes(void *id, void *data, int32_t bcount)
static uint32_t
wavpack_input_get_pos(void *id)
{
return wpin(id)->is->offset;
return wpin(id)->is->GetOffset();
}
static int
@@ -406,16 +406,16 @@ wavpack_input_push_back_byte(void *id, int c)
static uint32_t
wavpack_input_get_length(void *id)
{
if (wpin(id)->is->size < 0)
if (!wpin(id)->is->KnownSize())
return 0;
return wpin(id)->is->size;
return wpin(id)->is->GetSize();
}
static int
wavpack_input_can_seek(void *id)
{
return wpin(id)->is->seekable;
return wpin(id)->is->IsSeekable();
}
static WavpackStreamReader mpd_is_reader = {
@@ -484,7 +484,7 @@ static void
wavpack_streamdecode(Decoder &decoder, InputStream &is)
{
int open_flags = OPEN_NORMALIZE;
bool can_seek = is.seekable;
bool can_seek = is.IsSeekable();
wavpack_input isp_wvc;
InputStream *is_wvc = wavpack_open_wvc(decoder, is.GetURI(),
@@ -492,7 +492,7 @@ wavpack_streamdecode(Decoder &decoder, InputStream &is)
&isp_wvc);
if (is_wvc != nullptr) {
open_flags |= OPEN_WVC;
can_seek &= is_wvc->seekable;
can_seek &= is_wvc->IsSeekable();
}
if (!can_seek) {