From 2a2ac35b986dc5ad25fab763e1553d95ad5f079e Mon Sep 17 00:00:00 2001
From: Max Kellermann <max@musicpd.org>
Date: Fri, 16 Sep 2016 18:38:16 +0200
Subject: [PATCH] decoder/ffmpeg: FfmpegOpenInput() throws exception on error

---
 src/decoder/plugins/FfmpegDecoderPlugin.cxx | 32 ++++++++++-----------
 1 file changed, 15 insertions(+), 17 deletions(-)

diff --git a/src/decoder/plugins/FfmpegDecoderPlugin.cxx b/src/decoder/plugins/FfmpegDecoderPlugin.cxx
index 76e595041..ddc0083d0 100644
--- a/src/decoder/plugins/FfmpegDecoderPlugin.cxx
+++ b/src/decoder/plugins/FfmpegDecoderPlugin.cxx
@@ -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);