1c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev/*
2c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * Copyright (C) Texas Instruments - http://www.ti.com/
3c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev *
4c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * Licensed under the Apache License, Version 2.0 (the "License");
5c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * you may not use this file except in compliance with the License.
6c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * You may obtain a copy of the License at
7c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev *
8c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev *      http://www.apache.org/licenses/LICENSE-2.0
9c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev *
10c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * Unless required by applicable law or agreed to in writing, software
11c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * distributed under the License is distributed on an "AS IS" BASIS,
12c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * See the License for the specific language governing permissions and
14c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * limitations under the License.
15c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev */
16c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
17c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
18c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#include "ErrorUtils.h"
19c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
20c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevnamespace android {
21c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
22c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev/**
23c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev   @brief Method to convert from POSIX to Android errors
24c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
25c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev   @param error Any of the standard POSIX error codes (defined in bionic/libc/kernel/common/asm-generic/errno.h)
26c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev   @return Any of the standard Android error code (defined in frameworks/base/include/utils/Errors.h)
27c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev */
28c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstatus_t ErrorUtils::posixToAndroidError(int error)
29c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{
30c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev    switch(error)
31c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        {
32c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case 0:
33c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev            return NO_ERROR;
34c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case EINVAL:
35c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case EFBIG:
36c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case EMSGSIZE:
37c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case E2BIG:
38c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case EFAULT:
39c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case EILSEQ:
40c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev            return BAD_VALUE;
41c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case ENOSYS:
42c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev            return INVALID_OPERATION;
43c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case EACCES:
44c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case EPERM:
45c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev            return PERMISSION_DENIED;
46c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case EADDRINUSE:
47c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case EAGAIN:
48c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case EALREADY:
49c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case EBUSY:
50c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case EEXIST:
51c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case EINPROGRESS:
52c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev            return ALREADY_EXISTS;
53c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case ENOMEM:
54c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev            return NO_MEMORY;
55c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        default:
56c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev            return UNKNOWN_ERROR;
57c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        };
58c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
59c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev    return NO_ERROR;
60c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev}
61c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
62c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
63c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev/**
64c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev   @brief Method to convert from TI OSAL to Android errors
65c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
66c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev   @param error Any of the standard TI OSAL error codes (defined in
67c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev                                                                                            hardware/ti/omx/ducati/domx/system/mm_osal/inc/timm_osal_error.h)
68c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev   @return Any of the standard Android error code  (defined in frameworks/base/include/utils/Errors.h)
69c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev */
70c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstatus_t ErrorUtils::osalToAndroidError(TIMM_OSAL_ERRORTYPE error)
71c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{
72c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev    switch(error)
73c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev    {
74c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev    case TIMM_OSAL_ERR_NONE:
75c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        return NO_ERROR;
76c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev    case TIMM_OSAL_ERR_ALLOC:
77c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        return NO_MEMORY;
78c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev    default:
79c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        return UNKNOWN_ERROR;
80c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev    }
81c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
82c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev    return NO_ERROR;
83c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev}
84c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
85c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev/**
86c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev   @brief Method to convert from OMX to Android errors
87c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
88c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev   @param error Any of the standard OMX error codes (defined in hardware/ti/omx/ducati/domx/system/omx_core/inc/OMX_Core.h)
89c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev   @return Any of the standard Android error code (defined in frameworks/base/include/utils/Errors.h)
90c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev */
91c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevstatus_t ErrorUtils::omxToAndroidError(OMX_ERRORTYPE error)
92c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev{
93c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev    switch(error)
94c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        {
95c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorNone:
96c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev            return NO_ERROR;
97c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorBadParameter:
98c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorInvalidComponentName:
99c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorUndefined:
100c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorInvalidState:
101c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorStreamCorrupt:
102c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorPortsNotCompatible:
103c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorVersionMismatch:
104c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorMbErrorsInFrame:
105c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev            return BAD_VALUE;
106c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorInsufficientResources:
107c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev            return NO_MEMORY;
108c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorComponentNotFound:
109c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorNotImplemented:
110c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorFormatNotDetected:
111c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorUnsupportedSetting:
112c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev            return NAME_NOT_FOUND;
113c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorUnderflow:
114c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorOverflow:
115c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorUnsupportedIndex:
116c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorBadPortIndex:
117c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev            return BAD_INDEX;
118c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorHardware:
119c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorContentPipeCreationFailed:
120c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorContentPipeOpenFailed:
121c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev            return FAILED_TRANSACTION;
122c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorTimeout:
123c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev           return TIMED_OUT;
124c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorSameState:
125c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorIncorrectStateTransition:
126c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorIncorrectStateOperation:
127c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev           return PERMISSION_DENIED;
128c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        case OMX_ErrorTunnelingUnsupported:
129c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev           return INVALID_OPERATION;
130c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        default:
131c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev            return UNKNOWN_ERROR;
132c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev        }
133c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
134c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev    return NO_ERROR;
135c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev}
136c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
137c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
138c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev};
139c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
140c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
141c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
142