00001 /* 00002 * This file is part of FFmpeg. 00003 * 00004 * FFmpeg is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * FFmpeg is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with FFmpeg; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00017 */ 00018 00019 #undef _GNU_SOURCE 00020 #include "avutil.h" 00021 #include "avstring.h" 00022 #include "common.h" 00023 00024 struct error_entry { 00025 int num; 00026 const char *tag; 00027 const char *str; 00028 }; 00029 00030 #define ERROR_TAG(tag) AVERROR_##tag, #tag 00031 static const struct error_entry error_entries[] = { 00032 { ERROR_TAG(BSF_NOT_FOUND), "Bitstream filter not found" }, 00033 { ERROR_TAG(BUG), "Internal bug, should not have happened" }, 00034 { ERROR_TAG(BUG2), "Internal bug, should not have happened" }, 00035 { ERROR_TAG(BUFFER_TOO_SMALL), "Buffer too small" }, 00036 { ERROR_TAG(DECODER_NOT_FOUND), "Decoder not found" }, 00037 { ERROR_TAG(DEMUXER_NOT_FOUND), "Demuxer not found" }, 00038 { ERROR_TAG(ENCODER_NOT_FOUND), "Encoder not found" }, 00039 { ERROR_TAG(EOF), "End of file" }, 00040 { ERROR_TAG(EXIT), "Immediate exit requested" }, 00041 { ERROR_TAG(EXTERNAL), "Generic error in an external library" }, 00042 { ERROR_TAG(FILTER_NOT_FOUND), "Filter not found" }, 00043 { ERROR_TAG(INVALIDDATA), "Invalid data found when processing input" }, 00044 { ERROR_TAG(MUXER_NOT_FOUND), "Muxer not found" }, 00045 { ERROR_TAG(OPTION_NOT_FOUND), "Option not found" }, 00046 { ERROR_TAG(PATCHWELCOME), "Not yet implemented in FFmpeg, patches welcome" }, 00047 { ERROR_TAG(PROTOCOL_NOT_FOUND), "Protocol not found" }, 00048 { ERROR_TAG(STREAM_NOT_FOUND), "Stream not found" }, 00049 { ERROR_TAG(UNKNOWN), "Unknown error occurred" }, 00050 }; 00051 00052 int av_strerror(int errnum, char *errbuf, size_t errbuf_size) 00053 { 00054 int ret = 0, i; 00055 const struct error_entry *entry = NULL; 00056 00057 for (i = 0; i < FF_ARRAY_ELEMS(error_entries); i++) { 00058 if (errnum == error_entries[i].num) { 00059 entry = &error_entries[i]; 00060 break; 00061 } 00062 } 00063 if (entry) { 00064 av_strlcpy(errbuf, entry->str, errbuf_size); 00065 } else { 00066 #if HAVE_STRERROR_R 00067 ret = AVERROR(strerror_r(AVUNERROR(errnum), errbuf, errbuf_size)); 00068 #else 00069 ret = -1; 00070 #endif 00071 if (ret < 0) 00072 snprintf(errbuf, errbuf_size, "Error number %d occurred", errnum); 00073 } 00074 00075 return ret; 00076 } 00077 00078 #ifdef TEST 00079 00080 #undef printf 00081 00082 int main(void) 00083 { 00084 int i; 00085 00086 for (i = 0; i < FF_ARRAY_ELEMS(error_entries); i++) { 00087 const struct error_entry *entry = &error_entries[i]; 00088 printf("%d: %s [%s]\n", entry->num, av_err2str(entry->num), entry->tag); 00089 } 00090 00091 for (i = 0; i < 256; i++) { 00092 printf("%d: %s\n", -i, av_err2str(-i)); 00093 } 00094 00095 return 0; 00096 } 00097 00098 #endif /* TEST */