aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefano Sabatini <stefasab@gmail.com>2012-02-06 14:16:33 +0100
committerStefano Sabatini <stefasab@gmail.com>2012-06-11 23:35:32 +0200
commit4299fd23d3f6cbd8f74be4d1eca0c3e3f46d23be (patch)
tree89e01d86e2310e61bf60d1123ecba7f180072b45
parent3ecaba677ed1f725043bed3b19198b2a8bf8c729 (diff)
downloadffmpeg-4299fd23d3f6cbd8f74be4d1eca0c3e3f46d23be.tar.gz
lavu/error: use a table to store error codes and strings, add test
The table is mostly useful to enumerate the available AVERROR* in the test output.
-rw-r--r--libavutil/Makefile1
-rw-r--r--libavutil/error.c86
2 files changed, 62 insertions, 25 deletions
diff --git a/libavutil/Makefile b/libavutil/Makefile
index 43c6177733..3dfe2fd29e 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -95,6 +95,7 @@ TESTPROGS = adler32 \
cpu \
crc \
des \
+ error \
eval \
file \
fifo \
diff --git a/libavutil/error.c b/libavutil/error.c
index 8f725d75c7..78bceb4b07 100644
--- a/libavutil/error.c
+++ b/libavutil/error.c
@@ -20,34 +20,45 @@
#include "avutil.h"
#include "avstring.h"
+struct error_entry {
+ int num;
+ const char *tag;
+ const char *str;
+};
+
+#define ERROR_TAG(tag) AVERROR_##tag, #tag
+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(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(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" },
+};
+
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_BUG2:
- case AVERROR_BUG: errstr = "Internal bug, should not have happened" ; 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 FFmpeg, 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_UNKNOWN: errstr = "Unknown error occurred" ; break;
- case AVERROR(EINVAL): errstr = "Invalid argument" ; break;
- case 0: errstr = "Success" ; break;
- }
+ int ret = 0, i;
+ 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);
@@ -60,3 +71,28 @@ int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
return ret;
}
+
+#ifdef TEST
+
+#undef printf
+
+int main(void)
+{
+ int i;
+ char errbuf[256];
+
+ for (i = 0; i < FF_ARRAY_ELEMS(error_entries); i++) {
+ struct error_entry *entry = &error_entries[i];
+ av_strerror(entry->num, errbuf, sizeof(errbuf));
+ printf("%d: %s [%s]\n", entry->num, errbuf, entry->tag);
+ }
+
+ for (i = 0; i < 256; i++) {
+ av_strerror(-i, errbuf, sizeof(errbuf));
+ printf("%d: %s\n", -i, errbuf);
+ }
+
+ return 0;
+}
+
+#endif /* TEST */