decoder/ffmpeg: move struct AvioStream to FfmpegIo.hxx

This commit is contained in:
Max Kellermann
2014-12-19 10:35:10 +01:00
parent f9abc561fb
commit 46914e486c
4 changed files with 141 additions and 74 deletions

View File

@@ -29,6 +29,7 @@
#include "lib/ffmpeg/Buffer.hxx"
#include "../DecoderAPI.hxx"
#include "FfmpegMetaData.hxx"
#include "FfmpegIo.hxx"
#include "tag/TagBuilder.hxx"
#include "tag/TagHandler.hxx"
#include "tag/ReplayGain.hxx"
@@ -88,80 +89,6 @@ mpd_ffmpeg_log_callback(gcc_unused void *ptr, int level,
}
}
struct AvioStream {
Decoder *const decoder;
InputStream &input;
AVIOContext *io;
unsigned char buffer[8192];
AvioStream(Decoder *_decoder, InputStream &_input)
:decoder(_decoder), input(_input), io(nullptr) {}
~AvioStream() {
av_free(io);
}
bool Open();
};
static int
mpd_ffmpeg_stream_read(void *opaque, uint8_t *buf, int size)
{
AvioStream *stream = (AvioStream *)opaque;
return decoder_read(stream->decoder, stream->input,
(void *)buf, size);
}
static int64_t
mpd_ffmpeg_stream_seek(void *opaque, int64_t pos, int whence)
{
AvioStream *stream = (AvioStream *)opaque;
switch (whence) {
case SEEK_SET:
break;
case SEEK_CUR:
pos += stream->input.GetOffset();
break;
case SEEK_END:
if (!stream->input.KnownSize())
return -1;
pos += stream->input.GetSize();
break;
case AVSEEK_SIZE:
if (!stream->input.KnownSize())
return -1;
return stream->input.GetSize();
default:
return -1;
}
if (!stream->input.LockSeek(pos, IgnoreError()))
return -1;
return stream->input.GetOffset();
}
bool
AvioStream::Open()
{
io = avio_alloc_context(buffer, sizeof(buffer),
false, this,
mpd_ffmpeg_stream_read, nullptr,
input.IsSeekable()
? mpd_ffmpeg_stream_seek : nullptr);
return io != nullptr;
}
/**
* API compatibility wrapper for av_open_input_stream() and
* avformat_open_input().