1 /*
2 * Copyright (C) 2009 The Android Open Source Project
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 MEDIA_ERRORS_H_
18
19 #define MEDIA_ERRORS_H_
20
21 #include <utils/Errors.h>
22
23 namespace android {
24
25 enum {
26 // status_t map for errors in the media framework
27 // OK or NO_ERROR or 0 represents no error.
28
29 // See system/core/include/utils/Errors.h
30 // System standard errors from -1 through (possibly) -133
31 //
32 // Errors with special meanings and side effects.
33 // INVALID_OPERATION: Operation attempted in an illegal state (will try to signal to app).
34 // DEAD_OBJECT: Signal from CodecBase to MediaCodec that MediaServer has died.
35 // NAME_NOT_FOUND: Signal from CodecBase to MediaCodec that the component was not found.
36
37 // Media errors
38 MEDIA_ERROR_BASE = -1000,
39
40 ERROR_ALREADY_CONNECTED = MEDIA_ERROR_BASE,
41 ERROR_NOT_CONNECTED = MEDIA_ERROR_BASE - 1,
42 ERROR_UNKNOWN_HOST = MEDIA_ERROR_BASE - 2,
43 ERROR_CANNOT_CONNECT = MEDIA_ERROR_BASE - 3,
44 ERROR_IO = MEDIA_ERROR_BASE - 4,
45 ERROR_CONNECTION_LOST = MEDIA_ERROR_BASE - 5,
46 ERROR_MALFORMED = MEDIA_ERROR_BASE - 7,
47 ERROR_OUT_OF_RANGE = MEDIA_ERROR_BASE - 8,
48 ERROR_BUFFER_TOO_SMALL = MEDIA_ERROR_BASE - 9,
49 ERROR_UNSUPPORTED = MEDIA_ERROR_BASE - 10,
50 ERROR_END_OF_STREAM = MEDIA_ERROR_BASE - 11,
51
52 // Not technically an error.
53 INFO_FORMAT_CHANGED = MEDIA_ERROR_BASE - 12,
54 INFO_DISCONTINUITY = MEDIA_ERROR_BASE - 13,
55 INFO_OUTPUT_BUFFERS_CHANGED = MEDIA_ERROR_BASE - 14,
56
57 // The following constant values should be in sync with
58 // drm/drm_framework_common.h
59 DRM_ERROR_BASE = -2000,
60
61 ERROR_DRM_UNKNOWN = DRM_ERROR_BASE,
62 ERROR_DRM_NO_LICENSE = DRM_ERROR_BASE - 1,
63 ERROR_DRM_LICENSE_EXPIRED = DRM_ERROR_BASE - 2,
64 ERROR_DRM_SESSION_NOT_OPENED = DRM_ERROR_BASE - 3,
65 ERROR_DRM_DECRYPT_UNIT_NOT_INITIALIZED = DRM_ERROR_BASE - 4,
66 ERROR_DRM_DECRYPT = DRM_ERROR_BASE - 5,
67 ERROR_DRM_CANNOT_HANDLE = DRM_ERROR_BASE - 6,
68 ERROR_DRM_TAMPER_DETECTED = DRM_ERROR_BASE - 7,
69 ERROR_DRM_NOT_PROVISIONED = DRM_ERROR_BASE - 8,
70 ERROR_DRM_DEVICE_REVOKED = DRM_ERROR_BASE - 9,
71 ERROR_DRM_RESOURCE_BUSY = DRM_ERROR_BASE - 10,
72 ERROR_DRM_INSUFFICIENT_OUTPUT_PROTECTION = DRM_ERROR_BASE - 11,
73 ERROR_DRM_INSUFFICIENT_SECURITY = DRM_ERROR_BASE - 12,
74 ERROR_DRM_FRAME_TOO_LARGE = DRM_ERROR_BASE - 13,
75 ERROR_DRM_RESOURCE_CONTENTION = DRM_ERROR_BASE - 14,
76 ERROR_DRM_SESSION_LOST_STATE = DRM_ERROR_BASE - 15,
77 ERROR_DRM_INVALID_STATE = DRM_ERROR_BASE - 16,
78
79 // New in S / drm@1.4:
80 ERROR_DRM_CERTIFICATE_MALFORMED = DRM_ERROR_BASE - 17,
81 ERROR_DRM_CERTIFICATE_MISSING = DRM_ERROR_BASE - 18,
82 ERROR_DRM_CRYPTO_LIBRARY = DRM_ERROR_BASE - 19,
83 ERROR_DRM_GENERIC_OEM = DRM_ERROR_BASE - 20,
84 ERROR_DRM_GENERIC_PLUGIN = DRM_ERROR_BASE - 21,
85 ERROR_DRM_INIT_DATA = DRM_ERROR_BASE - 22,
86 ERROR_DRM_KEY_NOT_LOADED = DRM_ERROR_BASE - 23,
87 ERROR_DRM_LICENSE_PARSE = DRM_ERROR_BASE - 24,
88 ERROR_DRM_LICENSE_POLICY = DRM_ERROR_BASE - 25,
89 ERROR_DRM_LICENSE_RELEASE = DRM_ERROR_BASE - 26,
90 ERROR_DRM_LICENSE_REQUEST_REJECTED = DRM_ERROR_BASE - 27,
91 ERROR_DRM_LICENSE_RESTORE = DRM_ERROR_BASE - 28,
92 ERROR_DRM_LICENSE_STATE = DRM_ERROR_BASE - 29,
93 ERROR_DRM_MEDIA_FRAMEWORK = DRM_ERROR_BASE - 30,
94 ERROR_DRM_PROVISIONING_CERTIFICATE = DRM_ERROR_BASE - 31,
95 ERROR_DRM_PROVISIONING_CONFIG = DRM_ERROR_BASE - 32,
96 ERROR_DRM_PROVISIONING_PARSE = DRM_ERROR_BASE - 33,
97 ERROR_DRM_PROVISIONING_REQUEST_REJECTED = DRM_ERROR_BASE - 34,
98 ERROR_DRM_PROVISIONING_RETRY = DRM_ERROR_BASE - 35,
99 ERROR_DRM_SECURE_STOP_RELEASE = DRM_ERROR_BASE - 36,
100 ERROR_DRM_STORAGE_READ = DRM_ERROR_BASE - 37,
101 ERROR_DRM_STORAGE_WRITE = DRM_ERROR_BASE - 38,
102 ERROR_DRM_ZERO_SUBSAMPLES = DRM_ERROR_BASE - 39,
103 ERROR_DRM_LAST_USED_ERRORCODE = ERROR_DRM_ZERO_SUBSAMPLES,
104
105 ERROR_DRM_VENDOR_MAX = DRM_ERROR_BASE - 500,
106 ERROR_DRM_VENDOR_MIN = DRM_ERROR_BASE - 999,
107
108 // Heartbeat Error Codes
109 HEARTBEAT_ERROR_BASE = -3000,
110 ERROR_HEARTBEAT_TERMINATE_REQUESTED = HEARTBEAT_ERROR_BASE,
111
112 // CAS-related error codes
113 CAS_ERROR_BASE = -4000,
114
115 ERROR_CAS_UNKNOWN = CAS_ERROR_BASE,
116 ERROR_CAS_NO_LICENSE = CAS_ERROR_BASE - 1,
117 ERROR_CAS_LICENSE_EXPIRED = CAS_ERROR_BASE - 2,
118 ERROR_CAS_SESSION_NOT_OPENED = CAS_ERROR_BASE - 3,
119 ERROR_CAS_DECRYPT_UNIT_NOT_INITIALIZED = CAS_ERROR_BASE - 4,
120 ERROR_CAS_DECRYPT = CAS_ERROR_BASE - 5,
121 ERROR_CAS_CANNOT_HANDLE = CAS_ERROR_BASE - 6,
122 ERROR_CAS_TAMPER_DETECTED = CAS_ERROR_BASE - 7,
123 ERROR_CAS_NOT_PROVISIONED = CAS_ERROR_BASE - 8,
124 ERROR_CAS_DEVICE_REVOKED = CAS_ERROR_BASE - 9,
125 ERROR_CAS_RESOURCE_BUSY = CAS_ERROR_BASE - 10,
126 ERROR_CAS_INSUFFICIENT_OUTPUT_PROTECTION = CAS_ERROR_BASE - 11,
127 ERROR_CAS_NEED_ACTIVATION = CAS_ERROR_BASE - 12,
128 ERROR_CAS_NEED_PAIRING = CAS_ERROR_BASE - 13,
129 ERROR_CAS_NO_CARD = CAS_ERROR_BASE - 14,
130 ERROR_CAS_CARD_MUTE = CAS_ERROR_BASE - 15,
131 ERROR_CAS_CARD_INVALID = CAS_ERROR_BASE - 16,
132 ERROR_CAS_BLACKOUT = CAS_ERROR_BASE - 17,
133 ERROR_CAS_REBOOTING = CAS_ERROR_BASE - 18,
134 ERROR_CAS_LAST_USED_ERRORCODE = CAS_ERROR_BASE - 18,
135
136 ERROR_CAS_VENDOR_MAX = CAS_ERROR_BASE - 500,
137 ERROR_CAS_VENDOR_MIN = CAS_ERROR_BASE - 999,
138
139 // NDK Error codes
140 // frameworks/av/include/ndk/NdkMediaError.h
141 // from -10000 (0xFFFFD8F0 - 0xFFFFD8EC)
142 // from -20000 (0xFFFFB1E0 - 0xFFFFB1D7)
143
144 // Codec errors are permitted from 0x80001000 through 0x9000FFFF
145 ERROR_CODEC_MAX = (signed)0x9000FFFF,
146 ERROR_CODEC_MIN = (signed)0x80001000,
147
148 // System unknown errors from 0x80000000 - 0x80000007 (INT32_MIN + 7)
149 // See system/core/include/utils/Errors.h
150 };
151
152 // action codes for MediaCodecs that tell the upper layer and application
153 // the severity of any error.
154 enum ActionCode {
155 ACTION_CODE_FATAL,
156 ACTION_CODE_TRANSIENT,
157 ACTION_CODE_RECOVERABLE,
158 };
159
160 // returns true if err is a recognized DRM error code
isCryptoError(status_t err)161 static inline bool isCryptoError(status_t err) {
162 return (ERROR_DRM_LAST_USED_ERRORCODE <= err && err <= ERROR_DRM_UNKNOWN)
163 || (ERROR_DRM_VENDOR_MIN <= err && err <= ERROR_DRM_VENDOR_MAX);
164 }
165
166 #define STATUS_CASE(STATUS) \
167 case STATUS: \
168 return #STATUS
169
StrMediaError(status_t err)170 static inline std::string StrMediaError(status_t err) {
171 switch(err) {
172 STATUS_CASE(ERROR_ALREADY_CONNECTED);
173 STATUS_CASE(ERROR_NOT_CONNECTED);
174 STATUS_CASE(ERROR_UNKNOWN_HOST);
175 STATUS_CASE(ERROR_CANNOT_CONNECT);
176 STATUS_CASE(ERROR_IO);
177 STATUS_CASE(ERROR_CONNECTION_LOST);
178 STATUS_CASE(ERROR_MALFORMED);
179 STATUS_CASE(ERROR_OUT_OF_RANGE);
180 STATUS_CASE(ERROR_BUFFER_TOO_SMALL);
181 STATUS_CASE(ERROR_UNSUPPORTED);
182 STATUS_CASE(ERROR_END_OF_STREAM);
183 }
184 return statusToString(err);
185 }
186
StrCryptoError(status_t err)187 static inline std::string StrCryptoError(status_t err) {
188 switch (err) {
189 STATUS_CASE(ERROR_DRM_UNKNOWN);
190 STATUS_CASE(ERROR_DRM_NO_LICENSE);
191 STATUS_CASE(ERROR_DRM_LICENSE_EXPIRED);
192 STATUS_CASE(ERROR_DRM_SESSION_NOT_OPENED);
193 STATUS_CASE(ERROR_DRM_DECRYPT_UNIT_NOT_INITIALIZED);
194 STATUS_CASE(ERROR_DRM_DECRYPT);
195 STATUS_CASE(ERROR_DRM_CANNOT_HANDLE);
196 STATUS_CASE(ERROR_DRM_TAMPER_DETECTED);
197 STATUS_CASE(ERROR_DRM_NOT_PROVISIONED);
198 STATUS_CASE(ERROR_DRM_DEVICE_REVOKED);
199 STATUS_CASE(ERROR_DRM_RESOURCE_BUSY);
200 STATUS_CASE(ERROR_DRM_INSUFFICIENT_OUTPUT_PROTECTION);
201 STATUS_CASE(ERROR_DRM_INSUFFICIENT_SECURITY);
202 STATUS_CASE(ERROR_DRM_FRAME_TOO_LARGE);
203 STATUS_CASE(ERROR_DRM_RESOURCE_CONTENTION);
204 STATUS_CASE(ERROR_DRM_SESSION_LOST_STATE);
205 STATUS_CASE(ERROR_DRM_INVALID_STATE);
206 STATUS_CASE(ERROR_DRM_CERTIFICATE_MALFORMED);
207 STATUS_CASE(ERROR_DRM_CERTIFICATE_MISSING);
208 STATUS_CASE(ERROR_DRM_CRYPTO_LIBRARY);
209 STATUS_CASE(ERROR_DRM_GENERIC_OEM);
210 STATUS_CASE(ERROR_DRM_GENERIC_PLUGIN);
211 STATUS_CASE(ERROR_DRM_INIT_DATA);
212 STATUS_CASE(ERROR_DRM_KEY_NOT_LOADED);
213 STATUS_CASE(ERROR_DRM_LICENSE_PARSE);
214 STATUS_CASE(ERROR_DRM_LICENSE_POLICY);
215 STATUS_CASE(ERROR_DRM_LICENSE_RELEASE);
216 STATUS_CASE(ERROR_DRM_LICENSE_REQUEST_REJECTED);
217 STATUS_CASE(ERROR_DRM_LICENSE_RESTORE);
218 STATUS_CASE(ERROR_DRM_LICENSE_STATE);
219 STATUS_CASE(ERROR_DRM_MEDIA_FRAMEWORK);
220 STATUS_CASE(ERROR_DRM_PROVISIONING_CERTIFICATE);
221 STATUS_CASE(ERROR_DRM_PROVISIONING_CONFIG);
222 STATUS_CASE(ERROR_DRM_PROVISIONING_PARSE);
223 STATUS_CASE(ERROR_DRM_PROVISIONING_REQUEST_REJECTED);
224 STATUS_CASE(ERROR_DRM_PROVISIONING_RETRY);
225 STATUS_CASE(ERROR_DRM_SECURE_STOP_RELEASE);
226 STATUS_CASE(ERROR_DRM_STORAGE_READ);
227 STATUS_CASE(ERROR_DRM_STORAGE_WRITE);
228 STATUS_CASE(ERROR_DRM_ZERO_SUBSAMPLES);
229 }
230 return statusToString(err);
231 }
232 #undef STATUS_CASE
233
234 } // namespace android
235
236 #endif // MEDIA_ERRORS_H_
237