From e6e9c21275e2c2cf8be2f46f801bfc0de8f24718 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 18 Aug 2014 20:20:51 +0200 Subject: input/ffmpeg: use av_strerror() Generate more detailed error messages. --- src/input/plugins/FfmpegInputPlugin.cxx | 8 +++--- src/lib/ffmpeg/Error.cxx | 43 +++++++++++++++++++++++++++++++++ src/lib/ffmpeg/Error.hxx | 31 ++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 src/lib/ffmpeg/Error.cxx create mode 100644 src/lib/ffmpeg/Error.hxx (limited to 'src') diff --git a/src/input/plugins/FfmpegInputPlugin.cxx b/src/input/plugins/FfmpegInputPlugin.cxx index 130521ca2..669f8d403 100644 --- a/src/input/plugins/FfmpegInputPlugin.cxx +++ b/src/input/plugins/FfmpegInputPlugin.cxx @@ -23,6 +23,7 @@ #include "config.h" #include "FfmpegInputPlugin.hxx" #include "lib/ffmpeg/Domain.hxx" +#include "lib/ffmpeg/Error.hxx" #include "../InputStream.hxx" #include "../InputPlugin.hxx" #include "util/StringUtil.hxx" @@ -101,8 +102,7 @@ input_ffmpeg_open(const char *uri, AVIOContext *h; auto result = avio_open(&h, uri, AVIO_FLAG_READ); if (result != 0) { - error.Set(ffmpeg_domain, result, - "libavformat failed to open the URI"); + SetFfmpegError(error, result); return nullptr; } @@ -115,7 +115,7 @@ FfmpegInputStream::Read(void *ptr, size_t read_size, Error &error) auto result = avio_read(h, (unsigned char *)ptr, read_size); if (result <= 0) { if (result < 0) - error.Set(ffmpeg_domain, "avio_read() failed"); + SetFfmpegError(error, result, "avio_read() failed"); eof = true; return false; @@ -137,7 +137,7 @@ FfmpegInputStream::Seek(offset_type new_offset, Error &error) auto result = avio_seek(h, new_offset, SEEK_SET); if (result < 0) { - error.Set(ffmpeg_domain, "avio_seek() failed"); + SetFfmpegError(error, result, "avio_seek() failed"); return false; } diff --git a/src/lib/ffmpeg/Error.cxx b/src/lib/ffmpeg/Error.cxx new file mode 100644 index 000000000..bcc12fb1d --- /dev/null +++ b/src/lib/ffmpeg/Error.cxx @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2003-2014 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" +#include "Error.hxx" +#include "Domain.hxx" +#include "util/Error.hxx" + +extern "C" { +#include +} + +void +SetFfmpegError(Error &error, int errnum) +{ + char msg[256]; + av_strerror(errnum, msg, sizeof(msg)); + error.Set(ffmpeg_domain, errnum, msg); +} + +void +SetFfmpegError(Error &error, int errnum, const char *prefix) +{ + char msg[256]; + av_strerror(errnum, msg, sizeof(msg)); + error.Format(ffmpeg_domain, errnum, "%s: %s", prefix, msg); +} diff --git a/src/lib/ffmpeg/Error.hxx b/src/lib/ffmpeg/Error.hxx new file mode 100644 index 000000000..943dca6ce --- /dev/null +++ b/src/lib/ffmpeg/Error.hxx @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2003-2014 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPD_FFMPEG_ERROR_HXX +#define MPD_FFMPEG_ERROR_HXX + +class Error; + +void +SetFfmpegError(Error &error, int errnum); + +void +SetFfmpegError(Error &error, int errnum, const char *prefix); + +#endif -- cgit v1.2.3