error.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #undef _GNU_SOURCE
  19. #define _XOPEN_SOURCE 600 /* XSI-compliant version of strerror_r */
  20. #include "avutil.h"
  21. #include "avstring.h"
  22. #include "common.h"
  23. struct error_entry {
  24. int num;
  25. const char *tag;
  26. const char *str;
  27. };
  28. #define ERROR_TAG(tag) AVERROR_##tag, #tag
  29. #define AVERROR_INPUT_AND_OUTPUT_CHANGED (AVERROR_INPUT_CHANGED | AVERROR_OUTPUT_CHANGED)
  30. static const struct error_entry error_entries[] = {
  31. { ERROR_TAG(BSF_NOT_FOUND), "Bitstream filter not found" },
  32. { ERROR_TAG(BUG), "Internal bug, should not have happened" },
  33. { ERROR_TAG(BUG2), "Internal bug, should not have happened" },
  34. { ERROR_TAG(BUFFER_TOO_SMALL), "Buffer too small" },
  35. { ERROR_TAG(DECODER_NOT_FOUND), "Decoder not found" },
  36. { ERROR_TAG(DEMUXER_NOT_FOUND), "Demuxer not found" },
  37. { ERROR_TAG(ENCODER_NOT_FOUND), "Encoder not found" },
  38. { ERROR_TAG(EOF), "End of file" },
  39. { ERROR_TAG(EXIT), "Immediate exit requested" },
  40. { ERROR_TAG(EXTERNAL), "Generic error in an external library" },
  41. { ERROR_TAG(FILTER_NOT_FOUND), "Filter not found" },
  42. { ERROR_TAG(INPUT_CHANGED), "Input changed" },
  43. { ERROR_TAG(INVALIDDATA), "Invalid data found when processing input" },
  44. { ERROR_TAG(MUXER_NOT_FOUND), "Muxer not found" },
  45. { ERROR_TAG(OPTION_NOT_FOUND), "Option not found" },
  46. { ERROR_TAG(OUTPUT_CHANGED), "Output changed" },
  47. { ERROR_TAG(PATCHWELCOME), "Not yet implemented in FFmpeg, patches welcome" },
  48. { ERROR_TAG(PROTOCOL_NOT_FOUND), "Protocol not found" },
  49. { ERROR_TAG(STREAM_NOT_FOUND), "Stream not found" },
  50. { ERROR_TAG(UNKNOWN), "Unknown error occurred" },
  51. { ERROR_TAG(EXPERIMENTAL), "Experimental feature" },
  52. { ERROR_TAG(INPUT_AND_OUTPUT_CHANGED), "Input and output changed" },
  53. { ERROR_TAG(HTTP_BAD_REQUEST), "Server returned 400 Bad Request" },
  54. { ERROR_TAG(HTTP_UNAUTHORIZED), "Server returned 401 Unauthorized (authorization failed)" },
  55. { ERROR_TAG(HTTP_FORBIDDEN), "Server returned 403 Forbidden (access denied)" },
  56. { ERROR_TAG(HTTP_NOT_FOUND), "Server returned 404 Not Found" },
  57. { ERROR_TAG(HTTP_OTHER_4XX), "Server returned 4XX Client Error, but not one of 40{0,1,3,4}" },
  58. { ERROR_TAG(HTTP_SERVER_ERROR), "Server returned 5XX Server Error reply" },
  59. };
  60. int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
  61. {
  62. int ret = 0, i;
  63. const struct error_entry *entry = NULL;
  64. for (i = 0; i < FF_ARRAY_ELEMS(error_entries); i++) {
  65. if (errnum == error_entries[i].num) {
  66. entry = &error_entries[i];
  67. break;
  68. }
  69. }
  70. if (entry) {
  71. av_strlcpy(errbuf, entry->str, errbuf_size);
  72. } else {
  73. #if HAVE_STRERROR_R
  74. ret = AVERROR(strerror_r(AVUNERROR(errnum), errbuf, errbuf_size));
  75. #else
  76. ret = -1;
  77. #endif
  78. if (ret < 0)
  79. snprintf(errbuf, errbuf_size, "Error number %d occurred", errnum);
  80. }
  81. return ret;
  82. }
  83. #ifdef TEST
  84. #undef printf
  85. int main(void)
  86. {
  87. int i;
  88. for (i = 0; i < FF_ARRAY_ELEMS(error_entries); i++) {
  89. const struct error_entry *entry = &error_entries[i];
  90. printf("%d: %s [%s]\n", entry->num, av_err2str(entry->num), entry->tag);
  91. }
  92. for (i = 0; i < 256; i++) {
  93. printf("%d: %s\n", -i, av_err2str(-i));
  94. }
  95. return 0;
  96. }
  97. #endif /* TEST */