diff --git a/Makefile.am b/Makefile.am index dbf8fb738..42db5520a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -781,6 +781,7 @@ endif if HAVE_FFMPEG noinst_LIBRARIES += libffmpeg.a libffmpeg_a_SOURCES = \ + src/lib/ffmpeg/Error.cxx src/lib/ffmpeg/Error.hxx \ src/lib/ffmpeg/Domain.cxx src/lib/ffmpeg/Domain.hxx FFMPEG_LIBS2 = libffmpeg.a $(FFMPEG_LIBS) endif diff --git a/NEWS b/NEWS index 8c1b9904a..6cf8956cc 100644 --- a/NEWS +++ b/NEWS @@ -31,6 +31,7 @@ ver 0.19 (not yet released) - alsa: new input plugin - curl: options "verify_peer" and "verify_host" - ffmpeg: update offset after seeking + - ffmpeg: improved error messages - mms: non-blocking I/O - nfs: new input plugin - smbclient: new input plugin 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