FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
error.c
Go to the documentation of this file.
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 
19 #undef _GNU_SOURCE
20 #define _XOPEN_SOURCE 600 /* XSI-compliant version of strerror_r */
21 #include "avutil.h"
22 #include "avstring.h"
23 #include "common.h"
24 
25 struct error_entry {
26  int num;
27  const char *tag;
28  const char *str;
29 };
30 
31 #define ERROR_TAG(tag) AVERROR_##tag, #tag
32 #define EERROR_TAG(tag) AVERROR(tag), #tag
33 #define AVERROR_INPUT_AND_OUTPUT_CHANGED (AVERROR_INPUT_CHANGED | AVERROR_OUTPUT_CHANGED)
34 static const struct error_entry error_entries[] = {
35  { ERROR_TAG(BSF_NOT_FOUND), "Bitstream filter not found" },
36  { ERROR_TAG(BUG), "Internal bug, should not have happened" },
37  { ERROR_TAG(BUG2), "Internal bug, should not have happened" },
38  { ERROR_TAG(BUFFER_TOO_SMALL), "Buffer too small" },
39  { ERROR_TAG(DECODER_NOT_FOUND), "Decoder not found" },
40  { ERROR_TAG(DEMUXER_NOT_FOUND), "Demuxer not found" },
41  { ERROR_TAG(ENCODER_NOT_FOUND), "Encoder not found" },
42  { ERROR_TAG(EOF), "End of file" },
43  { ERROR_TAG(EXIT), "Immediate exit requested" },
44  { ERROR_TAG(EXTERNAL), "Generic error in an external library" },
45  { ERROR_TAG(FILTER_NOT_FOUND), "Filter not found" },
46  { ERROR_TAG(INPUT_CHANGED), "Input changed" },
47  { ERROR_TAG(INVALIDDATA), "Invalid data found when processing input" },
48  { ERROR_TAG(MUXER_NOT_FOUND), "Muxer not found" },
49  { ERROR_TAG(OPTION_NOT_FOUND), "Option not found" },
50  { ERROR_TAG(OUTPUT_CHANGED), "Output changed" },
51  { ERROR_TAG(PATCHWELCOME), "Not yet implemented in FFmpeg, patches welcome" },
52  { ERROR_TAG(PROTOCOL_NOT_FOUND), "Protocol not found" },
53  { ERROR_TAG(STREAM_NOT_FOUND), "Stream not found" },
54  { ERROR_TAG(UNKNOWN), "Unknown error occurred" },
55  { ERROR_TAG(EXPERIMENTAL), "Experimental feature" },
56  { ERROR_TAG(INPUT_AND_OUTPUT_CHANGED), "Input and output changed" },
57  { ERROR_TAG(HTTP_BAD_REQUEST), "Server returned 400 Bad Request" },
58  { ERROR_TAG(HTTP_UNAUTHORIZED), "Server returned 401 Unauthorized (authorization failed)" },
59  { ERROR_TAG(HTTP_FORBIDDEN), "Server returned 403 Forbidden (access denied)" },
60  { ERROR_TAG(HTTP_NOT_FOUND), "Server returned 404 Not Found" },
61  { ERROR_TAG(HTTP_OTHER_4XX), "Server returned 4XX Client Error, but not one of 40{0,1,3,4}" },
62  { ERROR_TAG(HTTP_SERVER_ERROR), "Server returned 5XX Server Error reply" },
63 #if !HAVE_STRERROR_R
64  { EERROR_TAG(EINVAL), "Invalid argument" },
65 #endif
66 };
67 
68 int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
69 {
70  int ret = 0, i;
71  const struct error_entry *entry = NULL;
72 
73  for (i = 0; i < FF_ARRAY_ELEMS(error_entries); i++) {
74  if (errnum == error_entries[i].num) {
75  entry = &error_entries[i];
76  break;
77  }
78  }
79  if (entry) {
80  av_strlcpy(errbuf, entry->str, errbuf_size);
81  } else {
82 #if HAVE_STRERROR_R
83  ret = AVERROR(strerror_r(AVUNERROR(errnum), errbuf, errbuf_size));
84 #else
85  ret = -1;
86 #endif
87  if (ret < 0)
88  snprintf(errbuf, errbuf_size, "Error number %d occurred", errnum);
89  }
90 
91  return ret;
92 }
93 
94 #ifdef TEST
95 
96 #undef printf
97 
98 int main(void)
99 {
100  int i;
101 
102  for (i = 0; i < FF_ARRAY_ELEMS(error_entries); i++) {
103  const struct error_entry *entry = &error_entries[i];
104  printf("%d: %s [%s]\n", entry->num, av_err2str(entry->num), entry->tag);
105  }
106 
107  for (i = 0; i < 256; i++) {
108  printf("%d: %s\n", -i, av_err2str(-i));
109  }
110 
111  return 0;
112 }
113 
114 #endif /* TEST */
#define NULL
Definition: coverity.c:32
external API header
#define FF_ARRAY_ELEMS(a)
Definition: ftp.c:31
#define EERROR_TAG(tag)
Definition: error.c:32
#define AVERROR(e)
Definition: error.h:43
size_t av_strlcpy(char *dst, const char *src, size_t size)
Copy the string src to dst, but no more than size - 1 bytes, and null-terminate dst.
Definition: avstring.c:83
Definition: error.c:25
ret
Definition: avfilter.c:974
#define av_err2str(errnum)
Convenience macro, the return value should be used only directly in function arguments but never stan...
Definition: error.h:119
const char * tag
Definition: error.c:27
static const struct error_entry error_entries[]
Definition: error.c:34
const char * str
Definition: error.c:28
#define snprintf
Definition: snprintf.h:34
#define ERROR_TAG(tag)
Definition: error.c:31
int num
Definition: error.c:26
int av_strerror(int errnum, char *errbuf, size_t errbuf_size)
Put a description of the AVERROR code errnum in errbuf.
Definition: error.c:68
common internal and external API header
#define AVUNERROR(e)
Definition: error.h:44
int main(int argc, char **argv)
Definition: main.c:22