1 /*
2 * Copyright 2019 The libgav1 Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef LIBGAV1_SRC_GAV1_STATUS_CODE_H_
18 #define LIBGAV1_SRC_GAV1_STATUS_CODE_H_
19
20 #include "gav1/symbol_visibility.h"
21
22 // All the declarations in this file are part of the public ABI. This file may
23 // be included by both C and C++ files.
24
25 // The Libgav1StatusCode enum type: A libgav1 function may return
26 // Libgav1StatusCode to indicate success or the reason for failure.
27 typedef enum {
28 // Success.
29 kLibgav1StatusOk = 0,
30
31 // An unknown error. Used as the default error status if error detail is not
32 // available.
33 kLibgav1StatusUnknownError = -1,
34
35 // An invalid function argument.
36 kLibgav1StatusInvalidArgument = -2,
37
38 // Memory allocation failure.
39 kLibgav1StatusOutOfMemory = -3,
40
41 // Ran out of a resource (other than memory).
42 kLibgav1StatusResourceExhausted = -4,
43
44 // The object is not initialized.
45 kLibgav1StatusNotInitialized = -5,
46
47 // An operation that can only be performed once has already been performed.
48 kLibgav1StatusAlready = -6,
49
50 // Not implemented, or not supported.
51 kLibgav1StatusUnimplemented = -7,
52
53 // An internal error in libgav1. Usually this indicates a programming error.
54 kLibgav1StatusInternalError = -8,
55
56 // The bitstream is not encoded correctly or violates a bitstream conformance
57 // requirement.
58 kLibgav1StatusBitstreamError = -9,
59
60 // The operation is not allowed at the moment. This is not a fatal error. Try
61 // again later.
62 kLibgav1StatusTryAgain = -10,
63
64 // Used only by DequeueFrame(). There are no enqueued frames, so there is
65 // nothing to dequeue. This is not a fatal error. Try enqueuing a frame before
66 // trying to dequeue again.
67 kLibgav1StatusNothingToDequeue = -11,
68
69 // An extra enumerator to prevent people from writing code that fails to
70 // compile when a new status code is added.
71 //
72 // Do not reference this enumerator. In particular, if you write code that
73 // switches on Libgav1StatusCode, add a default: case instead of a case that
74 // mentions this enumerator.
75 //
76 // Do not depend on the value (currently -1000) listed here. It may change in
77 // the future.
78 kLibgav1StatusReservedForFutureExpansionUseDefaultInSwitchInstead_ = -1000
79 } Libgav1StatusCode;
80
81 #if defined(__cplusplus)
82 extern "C" {
83 #endif
84
85 // Returns a human readable error string in en-US for the status code |status|.
86 // Always returns a valid (non-NULL) string.
87 LIBGAV1_PUBLIC const char* Libgav1GetErrorString(Libgav1StatusCode status);
88
89 #if defined(__cplusplus)
90 } // extern "C"
91
92 namespace libgav1 {
93
94 // Declare type aliases for C++.
95 using StatusCode = Libgav1StatusCode;
96 constexpr StatusCode kStatusOk = kLibgav1StatusOk;
97 constexpr StatusCode kStatusUnknownError = kLibgav1StatusUnknownError;
98 constexpr StatusCode kStatusInvalidArgument = kLibgav1StatusInvalidArgument;
99 constexpr StatusCode kStatusOutOfMemory = kLibgav1StatusOutOfMemory;
100 constexpr StatusCode kStatusResourceExhausted = kLibgav1StatusResourceExhausted;
101 constexpr StatusCode kStatusNotInitialized = kLibgav1StatusNotInitialized;
102 constexpr StatusCode kStatusAlready = kLibgav1StatusAlready;
103 constexpr StatusCode kStatusUnimplemented = kLibgav1StatusUnimplemented;
104 constexpr StatusCode kStatusInternalError = kLibgav1StatusInternalError;
105 constexpr StatusCode kStatusBitstreamError = kLibgav1StatusBitstreamError;
106 constexpr StatusCode kStatusTryAgain = kLibgav1StatusTryAgain;
107 constexpr StatusCode kStatusNothingToDequeue = kLibgav1StatusNothingToDequeue;
108
109 // Returns a human readable error string in en-US for the status code |status|.
110 // Always returns a valid (non-NULL) string.
GetErrorString(StatusCode status)111 inline const char* GetErrorString(StatusCode status) {
112 return Libgav1GetErrorString(status);
113 }
114
115 } // namespace libgav1
116 #endif // defined(__cplusplus)
117
118 #endif // LIBGAV1_SRC_GAV1_STATUS_CODE_H_
119