Commit e6e9c212 authored by Max Kellermann's avatar Max Kellermann

input/ffmpeg: use av_strerror()

Generate more detailed error messages.
parent 636f5d4a
...@@ -781,6 +781,7 @@ endif ...@@ -781,6 +781,7 @@ endif
if HAVE_FFMPEG if HAVE_FFMPEG
noinst_LIBRARIES += libffmpeg.a noinst_LIBRARIES += libffmpeg.a
libffmpeg_a_SOURCES = \ libffmpeg_a_SOURCES = \
src/lib/ffmpeg/Error.cxx src/lib/ffmpeg/Error.hxx \
src/lib/ffmpeg/Domain.cxx src/lib/ffmpeg/Domain.hxx src/lib/ffmpeg/Domain.cxx src/lib/ffmpeg/Domain.hxx
FFMPEG_LIBS2 = libffmpeg.a $(FFMPEG_LIBS) FFMPEG_LIBS2 = libffmpeg.a $(FFMPEG_LIBS)
endif endif
......
...@@ -31,6 +31,7 @@ ver 0.19 (not yet released) ...@@ -31,6 +31,7 @@ ver 0.19 (not yet released)
- alsa: new input plugin - alsa: new input plugin
- curl: options "verify_peer" and "verify_host" - curl: options "verify_peer" and "verify_host"
- ffmpeg: update offset after seeking - ffmpeg: update offset after seeking
- ffmpeg: improved error messages
- mms: non-blocking I/O - mms: non-blocking I/O
- nfs: new input plugin - nfs: new input plugin
- smbclient: new input plugin - smbclient: new input plugin
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "config.h" #include "config.h"
#include "FfmpegInputPlugin.hxx" #include "FfmpegInputPlugin.hxx"
#include "lib/ffmpeg/Domain.hxx" #include "lib/ffmpeg/Domain.hxx"
#include "lib/ffmpeg/Error.hxx"
#include "../InputStream.hxx" #include "../InputStream.hxx"
#include "../InputPlugin.hxx" #include "../InputPlugin.hxx"
#include "util/StringUtil.hxx" #include "util/StringUtil.hxx"
...@@ -101,8 +102,7 @@ input_ffmpeg_open(const char *uri, ...@@ -101,8 +102,7 @@ input_ffmpeg_open(const char *uri,
AVIOContext *h; AVIOContext *h;
auto result = avio_open(&h, uri, AVIO_FLAG_READ); auto result = avio_open(&h, uri, AVIO_FLAG_READ);
if (result != 0) { if (result != 0) {
error.Set(ffmpeg_domain, result, SetFfmpegError(error, result);
"libavformat failed to open the URI");
return nullptr; return nullptr;
} }
...@@ -115,7 +115,7 @@ FfmpegInputStream::Read(void *ptr, size_t read_size, Error &error) ...@@ -115,7 +115,7 @@ FfmpegInputStream::Read(void *ptr, size_t read_size, Error &error)
auto result = avio_read(h, (unsigned char *)ptr, read_size); auto result = avio_read(h, (unsigned char *)ptr, read_size);
if (result <= 0) { if (result <= 0) {
if (result < 0) if (result < 0)
error.Set(ffmpeg_domain, "avio_read() failed"); SetFfmpegError(error, result, "avio_read() failed");
eof = true; eof = true;
return false; return false;
...@@ -137,7 +137,7 @@ FfmpegInputStream::Seek(offset_type new_offset, Error &error) ...@@ -137,7 +137,7 @@ FfmpegInputStream::Seek(offset_type new_offset, Error &error)
auto result = avio_seek(h, new_offset, SEEK_SET); auto result = avio_seek(h, new_offset, SEEK_SET);
if (result < 0) { if (result < 0) {
error.Set(ffmpeg_domain, "avio_seek() failed"); SetFfmpegError(error, result, "avio_seek() failed");
return false; return false;
} }
......
/*
* 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 <libavutil/error.h>
}
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);
}
/*
* 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment