decoder/ffmpeg: FfmpegOpenInput() throws exception on error

This commit is contained in:
Max Kellermann 2016-09-16 18:38:16 +02:00
parent 8c744efd56
commit 2a2ac35b98

View File

@ -60,22 +60,18 @@ extern "C" {
static AVFormatContext *
FfmpegOpenInput(AVIOContext *pb,
const char *filename,
AVInputFormat *fmt,
Error &error)
AVInputFormat *fmt)
{
AVFormatContext *context = avformat_alloc_context();
if (context == nullptr) {
error.Set(ffmpeg_domain, "Out of memory");
return nullptr;
}
if (context == nullptr)
throw std::runtime_error("avformat_alloc_context() failed");
context->pb = pb;
int err = avformat_open_input(&context, filename, fmt, nullptr);
if (err < 0) {
avformat_free_context(context);
SetFfmpegError(error, err, "avformat_open_input() failed");
return nullptr;
throw MakeFfmpegError(err, "avformat_open_input() failed");
}
return context;
@ -797,11 +793,12 @@ ffmpeg_decode(Decoder &decoder, InputStream &input)
return;
}
Error error;
AVFormatContext *format_context =
FfmpegOpenInput(stream.io, input.GetURI(), input_format, error);
if (format_context == nullptr) {
LogError(error);
AVFormatContext *format_context;
try {
format_context =FfmpegOpenInput(stream.io, input.GetURI(),
input_format);
} catch (const std::runtime_error &e) {
LogError(e);
return;
}
@ -848,11 +845,12 @@ ffmpeg_scan_stream(InputStream &is,
if (!stream.Open())
return false;
AVFormatContext *f =
FfmpegOpenInput(stream.io, is.GetURI(), input_format,
IgnoreError());
if (f == nullptr)
AVFormatContext *f;
try {
f = FfmpegOpenInput(stream.io, is.GetURI(), input_format);
} catch (const std::runtime_error &) {
return false;
}
AtScopeExit(&f) {
avformat_close_input(&f);