decoder/ffmpeg: move functions into the AvioStream struct

This commit is contained in:
Max Kellermann 2014-12-22 21:58:25 +01:00
parent 373706c92b
commit a2c6d5e148
2 changed files with 37 additions and 20 deletions

View File

@ -31,49 +31,60 @@ AvioStream::~AvioStream()
av_free(io); av_free(io);
} }
static int inline int
mpd_ffmpeg_stream_read(void *opaque, uint8_t *buf, int size) AvioStream::Read(void *dest, int size)
{ {
AvioStream *stream = (AvioStream *)opaque; return decoder_read(decoder, input, dest, size);
return decoder_read(stream->decoder, stream->input,
(void *)buf, size);
} }
static int64_t inline int64_t
mpd_ffmpeg_stream_seek(void *opaque, int64_t pos, int whence) AvioStream::Seek(int64_t pos, int whence)
{ {
AvioStream *stream = (AvioStream *)opaque;
switch (whence) { switch (whence) {
case SEEK_SET: case SEEK_SET:
break; break;
case SEEK_CUR: case SEEK_CUR:
pos += stream->input.GetOffset(); pos += input.GetOffset();
break; break;
case SEEK_END: case SEEK_END:
if (!stream->input.KnownSize()) if (!input.KnownSize())
return -1; return -1;
pos += stream->input.GetSize(); pos += input.GetSize();
break; break;
case AVSEEK_SIZE: case AVSEEK_SIZE:
if (!stream->input.KnownSize()) if (!input.KnownSize())
return -1; return -1;
return stream->input.GetSize(); return input.GetSize();
default: default:
return -1; return -1;
} }
if (!stream->input.LockSeek(pos, IgnoreError())) if (!input.LockSeek(pos, IgnoreError()))
return -1; return -1;
return stream->input.GetOffset(); return input.GetOffset();
}
int
AvioStream::_Read(void *opaque, uint8_t *buf, int size)
{
AvioStream &stream = *(AvioStream *)opaque;
return stream.Read(buf, size);
}
int64_t
AvioStream::_Seek(void *opaque, int64_t pos, int whence)
{
AvioStream &stream = *(AvioStream *)opaque;
return stream.Seek(pos, whence);
} }
bool bool
@ -81,8 +92,7 @@ AvioStream::Open()
{ {
io = avio_alloc_context(buffer, sizeof(buffer), io = avio_alloc_context(buffer, sizeof(buffer),
false, this, false, this,
mpd_ffmpeg_stream_read, nullptr, _Read, nullptr,
input.IsSeekable() input.IsSeekable() ? _Seek : nullptr);
? mpd_ffmpeg_stream_seek : nullptr);
return io != nullptr; return io != nullptr;
} }

View File

@ -45,6 +45,13 @@ struct AvioStream {
~AvioStream(); ~AvioStream();
bool Open(); bool Open();
private:
int Read(void *buffer, int size);
int64_t Seek(int64_t pos, int whence);
static int _Read(void *opaque, uint8_t *buf, int size);
static int64_t _Seek(void *opaque, int64_t pos, int whence);
}; };
#endif #endif