input/ffmpeg: use av_strerror()

Generate more detailed error messages.
This commit is contained in:
Max Kellermann 2014-08-18 20:20:51 +02:00
parent 636f5d4a1d
commit e6e9c21275
5 changed files with 80 additions and 4 deletions

View File

@ -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

1
NEWS
View File

@ -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

View File

@ -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;
}

43
src/lib/ffmpeg/Error.cxx Normal file
View File

@ -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 <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);
}

31
src/lib/ffmpeg/Error.hxx Normal file
View File

@ -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