1 /*
2  * Copyright (C) 2018 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 #include <media/NdkMediaError.h>
18 #include <media/stagefright/MediaErrors.h>
19 #include <utils/Errors.h>
20 #include <utils/Log.h>
21 
22 using namespace android;
23 
translate_error(status_t err)24 media_status_t translate_error(status_t err) {
25 
26     if (err == OK) {
27         return AMEDIA_OK;
28     } else if (err == ERROR_END_OF_STREAM) {
29         return AMEDIA_ERROR_END_OF_STREAM;
30     } else if (err == ERROR_IO) {
31         return AMEDIA_ERROR_IO;
32     } else if (err == ERROR_MALFORMED) {
33         return AMEDIA_ERROR_MALFORMED;
34     } else if (err == INVALID_OPERATION) {
35         return AMEDIA_ERROR_INVALID_OPERATION;
36     } else if (err == UNKNOWN_ERROR) {
37         return AMEDIA_ERROR_UNKNOWN;
38     }
39 
40     ALOGE("sf error code: %d", err);
41     return AMEDIA_ERROR_UNKNOWN;
42 }
43 
reverse_translate_error(media_status_t err)44 status_t reverse_translate_error(media_status_t err) {
45 
46     if (err == AMEDIA_OK) {
47         return OK;
48     } else if (err == AMEDIA_ERROR_END_OF_STREAM) {
49         return ERROR_END_OF_STREAM;
50     } else if (err == AMEDIA_ERROR_IO) {
51         return ERROR_IO;
52     } else if (err == AMEDIA_ERROR_WOULD_BLOCK) {
53         return WOULD_BLOCK;
54     } else if (err == AMEDIA_ERROR_MALFORMED) {
55         return ERROR_MALFORMED;
56     } else if (err == AMEDIA_ERROR_INVALID_OPERATION) {
57         return INVALID_OPERATION;
58     } else if (err == AMEDIA_ERROR_UNKNOWN) {
59         return UNKNOWN_ERROR;
60     }
61 
62     ALOGE("ndk error code: %d", err);
63     return UNKNOWN_ERROR;
64 }
65