summaryrefslogtreecommitdiff
path: root/libavutil/error.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavutil/error.c')
-rw-r--r--libavutil/error.c95
1 files changed, 67 insertions, 28 deletions
diff --git a/libavutil/error.c b/libavutil/error.c
index 6803d2d4cd..bd66354df2 100644
--- a/libavutil/error.c
+++ b/libavutil/error.c
@@ -1,54 +1,71 @@
/*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#undef _GNU_SOURCE
#include "avutil.h"
#include "avstring.h"
#include "common.h"
+struct error_entry {
+ int num;
+ const char *tag;
+ const char *str;
+};
+
+#define ERROR_TAG(tag) AVERROR_##tag, #tag
+static const struct error_entry error_entries[] = {
+ { ERROR_TAG(BSF_NOT_FOUND), "Bitstream filter not found" },
+ { ERROR_TAG(BUG), "Internal bug, should not have happened" },
+ { ERROR_TAG(BUG2), "Internal bug, should not have happened" },
+ { ERROR_TAG(BUFFER_TOO_SMALL), "Buffer too small" },
+ { ERROR_TAG(DECODER_NOT_FOUND), "Decoder not found" },
+ { ERROR_TAG(DEMUXER_NOT_FOUND), "Demuxer not found" },
+ { ERROR_TAG(ENCODER_NOT_FOUND), "Encoder not found" },
+ { ERROR_TAG(EOF), "End of file" },
+ { ERROR_TAG(EXIT), "Immediate exit requested" },
+ { ERROR_TAG(EXTERNAL), "Generic error in an external library" },
+ { ERROR_TAG(FILTER_NOT_FOUND), "Filter not found" },
+ { ERROR_TAG(INVALIDDATA), "Invalid data found when processing input" },
+ { ERROR_TAG(MUXER_NOT_FOUND), "Muxer not found" },
+ { ERROR_TAG(OPTION_NOT_FOUND), "Option not found" },
+ { ERROR_TAG(PATCHWELCOME), "Not yet implemented in FFmpeg, patches welcome" },
+ { ERROR_TAG(PROTOCOL_NOT_FOUND), "Protocol not found" },
+ { ERROR_TAG(STREAM_NOT_FOUND), "Stream not found" },
+ { ERROR_TAG(UNKNOWN), "Unknown error occurred" },
+ { ERROR_TAG(EXPERIMENTAL), "Experimental feature" },
+};
+
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
{
- int ret = 0;
- const char *errstr = NULL;
-
- switch (errnum) {
- case AVERROR_BSF_NOT_FOUND: errstr = "Bitstream filter not found" ; break;
- case AVERROR_DECODER_NOT_FOUND: errstr = "Decoder not found" ; break;
- case AVERROR_DEMUXER_NOT_FOUND: errstr = "Demuxer not found" ; break;
- case AVERROR_ENCODER_NOT_FOUND: errstr = "Encoder not found" ; break;
- case AVERROR_EOF: errstr = "End of file" ; break;
- case AVERROR_EXIT: errstr = "Immediate exit requested" ; break;
- case AVERROR_FILTER_NOT_FOUND: errstr = "Filter not found" ; break;
- case AVERROR_INVALIDDATA: errstr = "Invalid data found when processing input" ; break;
- case AVERROR_MUXER_NOT_FOUND: errstr = "Muxer not found" ; break;
- case AVERROR_OPTION_NOT_FOUND: errstr = "Option not found" ; break;
- case AVERROR_PATCHWELCOME: errstr = "Not yet implemented in Libav, patches welcome"; break;
- case AVERROR_PROTOCOL_NOT_FOUND:errstr = "Protocol not found" ; break;
- case AVERROR_STREAM_NOT_FOUND: errstr = "Stream not found" ; break;
- case AVERROR_BUG: errstr = "Bug detected, please report the issue" ; break;
- case AVERROR_UNKNOWN: errstr = "Unknown error occurred" ; break;
- case AVERROR_EXPERIMENTAL: errstr = "Experimental feature" ; break;
- }
+ int ret = 0, i;
+ const struct error_entry *entry = NULL;
- if (errstr) {
- av_strlcpy(errbuf, errstr, errbuf_size);
+ for (i = 0; i < FF_ARRAY_ELEMS(error_entries); i++) {
+ if (errnum == error_entries[i].num) {
+ entry = &error_entries[i];
+ break;
+ }
+ }
+ if (entry) {
+ av_strlcpy(errbuf, entry->str, errbuf_size);
} else {
#if HAVE_STRERROR_R
- ret = strerror_r(AVUNERROR(errnum), errbuf, errbuf_size);
+ ret = AVERROR(strerror_r(AVUNERROR(errnum), errbuf, errbuf_size));
#else
ret = -1;
#endif
@@ -58,3 +75,25 @@ int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
return ret;
}
+
+#ifdef TEST
+
+#undef printf
+
+int main(void)
+{
+ int i;
+
+ for (i = 0; i < FF_ARRAY_ELEMS(error_entries); i++) {
+ const struct error_entry *entry = &error_entries[i];
+ printf("%d: %s [%s]\n", entry->num, av_err2str(entry->num), entry->tag);
+ }
+
+ for (i = 0; i < 256; i++) {
+ printf("%d: %s\n", -i, av_err2str(-i));
+ }
+
+ return 0;
+}
+
+#endif /* TEST */