error.c 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #include "avutil.h"
  20. #include "avstring.h"
  21. #include "common.h"
  22. struct error_entry {
  23. int num;
  24. const char *tag;
  25. const char *str;
  26. };
  27. #define ERROR_TAG(tag) AVERROR_##tag, #tag
  28. static const struct error_entry error_entries[] = {
  29. { ERROR_TAG(BSF_NOT_FOUND), "Bitstream filter not found" },
  30. { ERROR_TAG(BUG), "Internal bug, should not have happened" },
  31. { ERROR_TAG(BUG2), "Internal bug, should not have happened" },
  32. { ERROR_TAG(BUFFER_TOO_SMALL), "Buffer too small" },
  33. { ERROR_TAG(DECODER_NOT_FOUND), "Decoder not found" },
  34. { ERROR_TAG(DEMUXER_NOT_FOUND), "Demuxer not found" },
  35. { ERROR_TAG(ENCODER_NOT_FOUND), "Encoder not found" },
  36. { ERROR_TAG(EOF), "End of file" },
  37. { ERROR_TAG(EXIT), "Immediate exit requested" },
  38. { ERROR_TAG(EXTERNAL), "Generic error in an external library" },
  39. { ERROR_TAG(FILTER_NOT_FOUND), "Filter not found" },
  40. { ERROR_TAG(INVALIDDATA), "Invalid data found when processing input" },
  41. { ERROR_TAG(MUXER_NOT_FOUND), "Muxer not found" },
  42. { ERROR_TAG(OPTION_NOT_FOUND), "Option not found" },
  43. { ERROR_TAG(PATCHWELCOME), "Not yet implemented in FFmpeg, patches welcome" },
  44. { ERROR_TAG(PROTOCOL_NOT_FOUND), "Protocol not found" },
  45. { ERROR_TAG(STREAM_NOT_FOUND), "Stream not found" },
  46. { ERROR_TAG(UNKNOWN), "Unknown error occurred" },
  47. };
  48. int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
  49. {
  50. int ret = 0, i;
  51. const struct error_entry *entry = NULL;
  52. for (i = 0; i < FF_ARRAY_ELEMS(error_entries); i++) {
  53. if (errnum == error_entries[i].num) {
  54. entry = &error_entries[i];
  55. break;
  56. }
  57. }
  58. if (entry) {
  59. av_strlcpy(errbuf, entry->str, errbuf_size);
  60. } else {
  61. #if HAVE_STRERROR_R
  62. ret = AVERROR(strerror_r(AVUNERROR(errnum), errbuf, errbuf_size));
  63. #else
  64. ret = -1;
  65. #endif
  66. if (ret < 0)
  67. snprintf(errbuf, errbuf_size, "Error number %d occurred", errnum);
  68. }
  69. return ret;
  70. }
  71. #ifdef TEST
  72. #undef printf
  73. int main(void)
  74. {
  75. int i;
  76. for (i = 0; i < FF_ARRAY_ELEMS(error_entries); i++) {
  77. const struct error_entry *entry = &error_entries[i];
  78. printf("%d: %s [%s]\n", entry->num, av_err2str(entry->num), entry->tag);
  79. }
  80. for (i = 0; i < 256; i++) {
  81. printf("%d: %s\n", -i, av_err2str(-i));
  82. }
  83. return 0;
  84. }
  85. #endif /* TEST */