diff options
author | Andrew F. Davis | 2019-07-22 12:51:14 -0500 |
---|---|---|
committer | Andrew F. Davis | 2019-07-22 13:55:56 -0500 |
commit | 2e76aaed9b8570602a9819ccd0f3351e7a359cb5 (patch) | |
tree | fdc08abf9a8649a43d1fb624d6ee50752140ce83 | |
parent | fcfc15b439d45f4c30943354f57bac70cc3b6807 (diff) | |
download | hardware-ti-am57x-2e76aaed9b8570602a9819ccd0f3351e7a359cb5.tar.gz hardware-ti-am57x-2e76aaed9b8570602a9819ccd0f3351e7a359cb5.tar.xz hardware-ti-am57x-2e76aaed9b8570602a9819ccd0f3351e7a359cb5.zip |
libstagefrighthw: Add hardware accelerated multimedia supportdev/multimedia
Signed-off-by: Andrew F. Davis <afd@ti.com>
51 files changed, 17038 insertions, 0 deletions
diff --git a/libstagefrighthw/Android.bp b/libstagefrighthw/Android.bp new file mode 100644 index 0000000..2460ea2 --- /dev/null +++ b/libstagefrighthw/Android.bp | |||
@@ -0,0 +1,24 @@ | |||
1 | cc_library_shared { | ||
2 | |||
3 | name: "libstagefrighthw", | ||
4 | vendor: true, | ||
5 | |||
6 | srcs: ["TIOMXPlugin.cpp"], | ||
7 | |||
8 | include_dirs: [ | ||
9 | "frameworks/native/include/media/openmax", | ||
10 | "frameworks/native/include/media/hardware", | ||
11 | ], | ||
12 | |||
13 | header_libs: ["media_plugin_headers"], | ||
14 | |||
15 | shared_libs: [ | ||
16 | "libbinder", | ||
17 | "libcutils", | ||
18 | "libdl", | ||
19 | "liblog", | ||
20 | "libui", | ||
21 | "libutils", | ||
22 | ], | ||
23 | |||
24 | } | ||
diff --git a/libstagefrighthw/TIOMXPlugin.cpp b/libstagefrighthw/TIOMXPlugin.cpp new file mode 100644 index 0000000..a69bbe8 --- /dev/null +++ b/libstagefrighthw/TIOMXPlugin.cpp | |||
@@ -0,0 +1,148 @@ | |||
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 | #include "TIOMXPlugin.h" | ||
18 | |||
19 | #include <dlfcn.h> | ||
20 | |||
21 | #include <HardwareAPI.h> | ||
22 | |||
23 | namespace android { | ||
24 | |||
25 | extern "C" OMXPluginBase *createOMXPlugin() | ||
26 | { | ||
27 | return new TIOMXPlugin; | ||
28 | } | ||
29 | |||
30 | extern "C" void destroyOMXPlugin(OMXPluginBase *plugin) | ||
31 | { | ||
32 | delete plugin; | ||
33 | } | ||
34 | |||
35 | #define LIBOMX "libOMX.ti.ducati.core.so" | ||
36 | |||
37 | TIOMXPlugin::TIOMXPlugin() | ||
38 | : mLibHandle(dlopen(LIBOMX, RTLD_NOW)), | ||
39 | mInit(NULL), | ||
40 | mDeinit(NULL), | ||
41 | mComponentNameEnum(NULL), | ||
42 | mGetHandle(NULL), | ||
43 | mFreeHandle(NULL), | ||
44 | mGetRolesOfComponentHandle(NULL) | ||
45 | { | ||
46 | if (mLibHandle != NULL) { | ||
47 | mInit = (InitFunc)dlsym(mLibHandle, "OMX_Init"); | ||
48 | mDeinit = (DeinitFunc)dlsym(mLibHandle, "OMX_Deinit"); | ||
49 | mComponentNameEnum = (ComponentNameEnumFunc)dlsym(mLibHandle, "OMX_ComponentNameEnum"); | ||
50 | mGetHandle = (GetHandleFunc)dlsym(mLibHandle, "OMX_GetHandle"); | ||
51 | mFreeHandle = (FreeHandleFunc)dlsym(mLibHandle, "OMX_FreeHandle"); | ||
52 | mGetRolesOfComponentHandle = (GetRolesOfComponentFunc)dlsym(mLibHandle, "OMX_GetRolesOfComponent"); | ||
53 | |||
54 | (*mInit)(); | ||
55 | } | ||
56 | else { | ||
57 | char const *err_str = dlerror(); | ||
58 | ALOGE("failed to load %s, with error[%s]", LIBOMX, err_str ? err_str : "unknown"); | ||
59 | } | ||
60 | } | ||
61 | |||
62 | TIOMXPlugin::~TIOMXPlugin() | ||
63 | { | ||
64 | if (mLibHandle != NULL) { | ||
65 | (*mDeinit)(); | ||
66 | |||
67 | dlclose(mLibHandle); | ||
68 | mLibHandle = NULL; | ||
69 | } | ||
70 | } | ||
71 | |||
72 | OMX_ERRORTYPE TIOMXPlugin::makeComponentInstance( | ||
73 | const char *name, | ||
74 | const OMX_CALLBACKTYPE *callbacks, | ||
75 | OMX_PTR appData, | ||
76 | OMX_COMPONENTTYPE **component) { | ||
77 | if (mLibHandle == NULL) { | ||
78 | return OMX_ErrorUndefined; | ||
79 | } | ||
80 | |||
81 | return (*mGetHandle)( | ||
82 | reinterpret_cast<OMX_HANDLETYPE *>(component), | ||
83 | const_cast<char *>(name), | ||
84 | appData, const_cast<OMX_CALLBACKTYPE *>(callbacks)); | ||
85 | } | ||
86 | |||
87 | OMX_ERRORTYPE TIOMXPlugin::destroyComponentInstance(OMX_COMPONENTTYPE *component) | ||
88 | { | ||
89 | if (mLibHandle == NULL) { | ||
90 | return OMX_ErrorUndefined; | ||
91 | } | ||
92 | |||
93 | return (*mFreeHandle)(reinterpret_cast<OMX_HANDLETYPE *>(component)); | ||
94 | } | ||
95 | |||
96 | OMX_ERRORTYPE TIOMXPlugin::enumerateComponents(OMX_STRING name, size_t size, OMX_U32 index) | ||
97 | { | ||
98 | if (mLibHandle == NULL) { | ||
99 | ALOGE("mLibHandle is NULL!"); | ||
100 | return OMX_ErrorUndefined; | ||
101 | } | ||
102 | |||
103 | return (*mComponentNameEnum)(name, size, index); | ||
104 | } | ||
105 | |||
106 | OMX_ERRORTYPE TIOMXPlugin::getRolesOfComponent(const char *name, Vector<String8> *roles) | ||
107 | { | ||
108 | roles->clear(); | ||
109 | |||
110 | if (mLibHandle == NULL) { | ||
111 | return OMX_ErrorUndefined; | ||
112 | } | ||
113 | |||
114 | OMX_U32 numRoles; | ||
115 | OMX_ERRORTYPE err = (*mGetRolesOfComponentHandle)( | ||
116 | const_cast<OMX_STRING>(name), &numRoles, NULL); | ||
117 | |||
118 | if (err != OMX_ErrorNone) { | ||
119 | return err; | ||
120 | } | ||
121 | |||
122 | if (numRoles > 0) { | ||
123 | OMX_U8 **array = new OMX_U8 *[numRoles]; | ||
124 | for (OMX_U32 i = 0; i < numRoles; ++i) { | ||
125 | array[i] = new OMX_U8[OMX_MAX_STRINGNAME_SIZE]; | ||
126 | } | ||
127 | |||
128 | err = (*mGetRolesOfComponentHandle)( | ||
129 | const_cast<OMX_STRING>(name), &numRoles, array); | ||
130 | |||
131 | for (OMX_U32 i = 0; i < numRoles; ++i) { | ||
132 | if (err == OMX_ErrorNone) { | ||
133 | String8 s((const char *)array[i]); | ||
134 | roles->push(s); | ||
135 | } | ||
136 | |||
137 | delete[] array[i]; | ||
138 | array[i] = NULL; | ||
139 | } | ||
140 | |||
141 | delete[] array; | ||
142 | array = NULL; | ||
143 | } | ||
144 | |||
145 | return err; | ||
146 | } | ||
147 | |||
148 | } // namespace android | ||
diff --git a/libstagefrighthw/TIOMXPlugin.h b/libstagefrighthw/TIOMXPlugin.h new file mode 100644 index 0000000..afbfb9c --- /dev/null +++ b/libstagefrighthw/TIOMXPlugin.h | |||
@@ -0,0 +1,70 @@ | |||
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 TI_OMX_PLUGIN_H_ | ||
18 | |||
19 | #define TI_OMX_PLUGIN_H_ | ||
20 | |||
21 | #include <OMXPluginBase.h> | ||
22 | |||
23 | namespace android { | ||
24 | |||
25 | struct TIOMXPlugin : public OMXPluginBase { | ||
26 | TIOMXPlugin(); | ||
27 | virtual ~TIOMXPlugin(); | ||
28 | |||
29 | virtual OMX_ERRORTYPE makeComponentInstance( | ||
30 | const char *name, | ||
31 | const OMX_CALLBACKTYPE *callbacks, | ||
32 | OMX_PTR appData, | ||
33 | OMX_COMPONENTTYPE **component); | ||
34 | |||
35 | virtual OMX_ERRORTYPE destroyComponentInstance( | ||
36 | OMX_COMPONENTTYPE *component); | ||
37 | |||
38 | virtual OMX_ERRORTYPE enumerateComponents( | ||
39 | OMX_STRING name, | ||
40 | size_t size, | ||
41 | OMX_U32 index); | ||
42 | |||
43 | virtual OMX_ERRORTYPE getRolesOfComponent( | ||
44 | const char *name, | ||
45 | Vector<String8> *roles); | ||
46 | |||
47 | private: | ||
48 | void *mLibHandle; | ||
49 | |||
50 | typedef OMX_ERRORTYPE (*InitFunc)(); | ||
51 | typedef OMX_ERRORTYPE (*DeinitFunc)(); | ||
52 | typedef OMX_ERRORTYPE (*ComponentNameEnumFunc)(OMX_STRING, OMX_U32, OMX_U32); | ||
53 | typedef OMX_ERRORTYPE (*GetHandleFunc)(OMX_HANDLETYPE *, OMX_STRING, OMX_PTR, OMX_CALLBACKTYPE *); | ||
54 | typedef OMX_ERRORTYPE (*FreeHandleFunc)(OMX_HANDLETYPE *); | ||
55 | typedef OMX_ERRORTYPE (*GetRolesOfComponentFunc)(OMX_STRING, OMX_U32 *, OMX_U8 **); | ||
56 | |||
57 | InitFunc mInit; | ||
58 | DeinitFunc mDeinit; | ||
59 | ComponentNameEnumFunc mComponentNameEnum; | ||
60 | GetHandleFunc mGetHandle; | ||
61 | FreeHandleFunc mFreeHandle; | ||
62 | GetRolesOfComponentFunc mGetRolesOfComponentHandle; | ||
63 | |||
64 | TIOMXPlugin(const TIOMXPlugin &); | ||
65 | TIOMXPlugin &operator=(const TIOMXPlugin &); | ||
66 | }; | ||
67 | |||
68 | } // namespace android | ||
69 | |||
70 | #endif // TI_OMX_PLUGIN_H_ | ||
diff --git a/libstagefrighthw/omx/Android.bp b/libstagefrighthw/omx/Android.bp new file mode 100644 index 0000000..798454d --- /dev/null +++ b/libstagefrighthw/omx/Android.bp | |||
@@ -0,0 +1,26 @@ | |||
1 | // OMX Ducati Core Library | ||
2 | |||
3 | cc_library_shared { | ||
4 | |||
5 | name: "libOMX.ti.ducati.core", | ||
6 | vendor: true, | ||
7 | |||
8 | srcs: ["OMX_Core.c"], | ||
9 | |||
10 | shared_libs: [ | ||
11 | "libdce", | ||
12 | "libdl", | ||
13 | "liblog", | ||
14 | "libosal", | ||
15 | "libutils", | ||
16 | ], | ||
17 | |||
18 | header_libs: ["media_plugin_headers"], | ||
19 | |||
20 | cflags: [ | ||
21 | "-DBUILDOS_ANDROID", | ||
22 | "-DSTATIC_TABLE", | ||
23 | "-Wno-unused", | ||
24 | ], | ||
25 | |||
26 | } | ||
diff --git a/libstagefrighthw/omx/OMX_Core.c b/libstagefrighthw/omx/OMX_Core.c new file mode 100644 index 0000000..9c8170f --- /dev/null +++ b/libstagefrighthw/omx/OMX_Core.c | |||
@@ -0,0 +1,570 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 | #define LOG_TAG "OMX_CORE" | ||
18 | |||
19 | #include <dlfcn.h> | ||
20 | #include <stdio.h> | ||
21 | #include <string.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <pthread.h> | ||
24 | |||
25 | #include <OMX_Component.h> | ||
26 | #include <OMX_Core.h> | ||
27 | |||
28 | #include <memplugin.h> | ||
29 | |||
30 | #include "osal_error.h" | ||
31 | #include "osal_trace.h" | ||
32 | #include "osal_mutex.h" | ||
33 | |||
34 | #define MAX_ROLES 20 | ||
35 | |||
36 | typedef struct _ComponentTable { | ||
37 | OMX_STRING name; | ||
38 | OMX_U16 nRoles; | ||
39 | OMX_STRING pRoleArray[MAX_ROLES]; | ||
40 | }ComponentTable; | ||
41 | |||
42 | /** size for the array of allocated components. Sets the maximum | ||
43 | * number of components that can be allocated at once | ||
44 | */ | ||
45 | #define MAXCOMP (50) | ||
46 | #define MAXNAMESIZE (128) | ||
47 | |||
48 | /** Determine the number of elements in an array */ | ||
49 | #define COUNTOF(x) (sizeof(x) / sizeof(x[0])) | ||
50 | |||
51 | /** Array to hold the DLL pointers for each allocated component */ | ||
52 | static void *pModules[MAXCOMP] = { 0 }; | ||
53 | |||
54 | /** Array to hold the component handles for each allocated component */ | ||
55 | static void *pComponents[COUNTOF(pModules)] = { 0 }; | ||
56 | |||
57 | /* count for call OMX_Init() */ | ||
58 | int count = 0; | ||
59 | |||
60 | pthread_mutex_t mutex; | ||
61 | void *pCoreInitMutex = NULL; | ||
62 | |||
63 | ComponentTable componentTable[] = | ||
64 | { | ||
65 | { | ||
66 | .name = "OMX.ti.ducati.video.decoder", | ||
67 | .nRoles = 4, | ||
68 | .pRoleArray = { | ||
69 | "video_decoder.mpeg4", | ||
70 | "video_decoder.avc", | ||
71 | "video_decoder.h263", | ||
72 | "video_decoder.mpeg2", | ||
73 | }, | ||
74 | }, | ||
75 | { | ||
76 | .name = "OMX.ti.ducati.video.encoder", | ||
77 | .nRoles = 1, | ||
78 | .pRoleArray = { | ||
79 | "video_encoder.avc", | ||
80 | }, | ||
81 | }, | ||
82 | }; | ||
83 | |||
84 | #define MAX_CONCURRENT_INSTANCES 5 // aligned with IPUMM definitions | ||
85 | int concurrent_instances = 0; | ||
86 | |||
87 | #define CORE_assert(C, V, S) \ | ||
88 | do { \ | ||
89 | if(!(C)) { \ | ||
90 | eError = V; \ | ||
91 | OSAL_ErrorTrace("failed check: " # C); \ | ||
92 | OSAL_ErrorTrace(" - returning error: " # V); \ | ||
93 | if( S ) { \ | ||
94 | OSAL_ErrorTrace(" - %s", S); \ | ||
95 | }\ | ||
96 | goto EXIT; \ | ||
97 | }\ | ||
98 | } while( 0 ) | ||
99 | |||
100 | static void OMX_PrintComponentTable() | ||
101 | { | ||
102 | OSAL_Info("--------Component Table:: %d Components found-------------", COUNTOF(componentTable)); | ||
103 | |||
104 | for( size_t i = 0; i < COUNTOF(componentTable); i++ ) { | ||
105 | OSAL_Info("%i:: %s", i, componentTable[i].name); | ||
106 | |||
107 | for( int j = 0; j < componentTable[i].nRoles; j++ ) { | ||
108 | OSAL_Info("\t%s", componentTable[i].pRoleArray[j]); | ||
109 | } | ||
110 | } | ||
111 | |||
112 | OSAL_Info("-----------------End Component Table ------------------"); | ||
113 | } | ||
114 | |||
115 | /* | ||
116 | * OMX_Init() | ||
117 | * | ||
118 | * Description:This method will initialize the OMX Core. It is the | ||
119 | * responsibility of the application to call OMX_Init to ensure the proper | ||
120 | * set up of core resources. | ||
121 | * | ||
122 | * Returns: OMX_NOERROR Successful | ||
123 | */ | ||
124 | OMX_ERRORTYPE OMX_Init() | ||
125 | { | ||
126 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
127 | OSAL_ERROR eOsalError = OSAL_ErrNone; | ||
128 | |||
129 | eOsalError = OSAL_ObtainMutex(pCoreInitMutex, OSAL_SUSPEND); | ||
130 | CORE_assert(eOsalError == OSAL_ErrNone, OMX_ErrorInsufficientResources, "Mutex lock failed"); | ||
131 | count++; | ||
132 | if( count == 1 ) { | ||
133 | pthread_mutex_init(&mutex, NULL); | ||
134 | memplugin_open(); | ||
135 | OMX_PrintComponentTable(); | ||
136 | } | ||
137 | |||
138 | eOsalError = OSAL_ReleaseMutex(pCoreInitMutex); | ||
139 | CORE_assert(eOsalError == OSAL_ErrNone, OMX_ErrorInsufficientResources, "Mutex release failed"); | ||
140 | EXIT: | ||
141 | return (eError); | ||
142 | } | ||
143 | |||
144 | /* | ||
145 | * OMX_GetHandle | ||
146 | * | ||
147 | * Description: This method will create the handle of the COMPONENTTYPE | ||
148 | * If the component is currently loaded, this method will reutrn the | ||
149 | * handle of existing component or create a new instance of the component. | ||
150 | * It will call the OMX_ComponentInit function and then the setcallback | ||
151 | * method to initialize the callback functions | ||
152 | * Parameters: | ||
153 | * @param[out] pHandle Handle of the loaded components | ||
154 | * @param[in] cComponentName Name of the component to load | ||
155 | * @param[in] pAppData Used to identify the callbacks of component | ||
156 | * @param[in] pCallBacks Application callbacks | ||
157 | * | ||
158 | * @retval OMX_ErrorUndefined | ||
159 | * @retval OMX_ErrorInvalidComponentName | ||
160 | * @retval OMX_ErrorInvalidComponent | ||
161 | * @retval OMX_ErrorInsufficientResources | ||
162 | * @retval OMX_NOERROR Successful | ||
163 | */ | ||
164 | OMX_ERRORTYPE OMX_GetHandle(OMX_HANDLETYPE *pHandle, | ||
165 | OMX_STRING cComponentName, | ||
166 | OMX_PTR pAppData, | ||
167 | OMX_CALLBACKTYPE *pCallBacks) | ||
168 | { | ||
169 | static const char prefix[] = "lib"; | ||
170 | static const char postfix[] = ".so"; | ||
171 | |||
172 | OMX_ERRORTYPE (*pComponentInit)(OMX_HANDLETYPE *); | ||
173 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
174 | OMX_COMPONENTTYPE *componentType; | ||
175 | int i; | ||
176 | char buf[sizeof(prefix) + MAXNAMESIZE + sizeof(postfix)]; | ||
177 | const char *pErr = dlerror(); | ||
178 | char *dlError = NULL; | ||
179 | if (pthread_mutex_lock(&mutex) != 0) { | ||
180 | OSAL_ErrorTrace("Core: Error in Mutex lock"); | ||
181 | } | ||
182 | |||
183 | CORE_assert(NULL != cComponentName, OMX_ErrorBadParameter, NULL); | ||
184 | CORE_assert(NULL != pHandle, OMX_ErrorBadParameter, NULL); | ||
185 | CORE_assert(NULL != pCallBacks, OMX_ErrorBadParameter, NULL); | ||
186 | CORE_assert(count > 0, OMX_ErrorUndefined, "OMX_GetHandle called without calling OMX_Init first"); | ||
187 | CORE_assert(concurrent_instances < MAX_CONCURRENT_INSTANCES, OMX_ErrorInsufficientResources, "Max Concurrent Instances reached"); | ||
188 | |||
189 | concurrent_instances++; | ||
190 | |||
191 | /* Verify that the name is not too long and could cause a crash. Notice | ||
192 | * that the comparison is a greater than or equals. This is to make | ||
193 | * sure that there is room for the terminating NULL at the end of the | ||
194 | * name. */ | ||
195 | CORE_assert(strlen(cComponentName) < MAXNAMESIZE, OMX_ErrorInvalidComponentName, NULL); | ||
196 | |||
197 | /* Locate the first empty slot for a component. If no slots | ||
198 | * are available, error out */ | ||
199 | for (i = 0; i < (int) COUNTOF(pModules); i++) { | ||
200 | if (pModules[i] == NULL) { | ||
201 | break; | ||
202 | } | ||
203 | } | ||
204 | |||
205 | CORE_assert(i != COUNTOF(pModules), OMX_ErrorInsufficientResources, NULL); | ||
206 | |||
207 | strcpy(buf, prefix); /* the lengths are defined herein or have been */ | ||
208 | strcat(buf, cComponentName); /* checked already, so strcpy and strcat are */ | ||
209 | strcat(buf, postfix); /* are safe to use in this context. */ | ||
210 | |||
211 | pModules[i] = dlopen(buf, RTLD_LAZY | RTLD_GLOBAL); | ||
212 | if (pModules[i] == NULL) { | ||
213 | dlError = (char *) dlerror(); | ||
214 | OSAL_ErrorTrace("Failed because %s", dlError); | ||
215 | eError = OMX_ErrorComponentNotFound; | ||
216 | goto EXIT; | ||
217 | } | ||
218 | |||
219 | pComponentInit = dlsym(pModules[i], "OMX_ComponentInit"); | ||
220 | pErr = dlerror(); | ||
221 | CORE_assert(((pErr == NULL) && (pComponentInit != NULL)), OMX_ErrorInvalidComponent, NULL); | ||
222 | |||
223 | /* We now can access the library. So, we need to call the "OMX_ComponentInit" | ||
224 | * method to load up the "handle" (which is just a list of functions to | ||
225 | * call) and we should be all set. | ||
226 | */ | ||
227 | *pHandle = malloc(sizeof(OMX_COMPONENTTYPE)); | ||
228 | CORE_assert((*pHandle != NULL), OMX_ErrorInsufficientResources, "Malloc of pHandle* failed"); | ||
229 | |||
230 | pComponents[i] = *pHandle; | ||
231 | componentType = (OMX_COMPONENTTYPE *) *pHandle; | ||
232 | componentType->nSize = sizeof(OMX_COMPONENTTYPE); | ||
233 | |||
234 | componentType->nVersion.s.nVersionMajor = 1; | ||
235 | componentType->nVersion.s.nVersionMinor = 1; | ||
236 | componentType->nVersion.s.nRevision = 0; | ||
237 | componentType->nVersion.s.nStep = 0; | ||
238 | |||
239 | eError = (*pComponentInit)(*pHandle); | ||
240 | if (OMX_ErrorNone == eError) { | ||
241 | eError = (componentType->SetCallbacks)(*pHandle, pCallBacks, pAppData); | ||
242 | CORE_assert(eError == OMX_ErrorNone, eError, "Core: Error returned from component SetCallBack"); | ||
243 | } else { | ||
244 | /* when the component fails to initialize, release the | ||
245 | component handle structure */ | ||
246 | free(*pHandle); | ||
247 | /* mark the component handle as NULL to prevent the caller from | ||
248 | actually trying to access the component with it, should they | ||
249 | ignore the return code */ | ||
250 | *pHandle = NULL; | ||
251 | pComponents[i] = NULL; | ||
252 | dlclose(pModules[i]); | ||
253 | pModules[i] = NULL; | ||
254 | goto EXIT; | ||
255 | } | ||
256 | |||
257 | EXIT: | ||
258 | if (pthread_mutex_unlock(&mutex) != 0) { | ||
259 | OSAL_ErrorTrace("Core: Error in Mutex unlock"); | ||
260 | } | ||
261 | return (eError); | ||
262 | } | ||
263 | |||
264 | /* | ||
265 | * OMX_FreeHandle() | ||
266 | * | ||
267 | * Description:This method will unload the OMX component pointed by | ||
268 | * OMX_HANDLETYPE. It is the responsibility of the calling method to ensure that | ||
269 | * the Deinit method of the component has been called prior to unloading component | ||
270 | * | ||
271 | * Parameters: | ||
272 | * @param[in] hComponent the component to unload | ||
273 | * | ||
274 | * Returns: OMX_NOERROR Successful | ||
275 | */ | ||
276 | OMX_ERRORTYPE OMX_FreeHandle(OMX_HANDLETYPE hComponent) | ||
277 | { | ||
278 | OMX_ERRORTYPE eError = OMX_ErrorUndefined; | ||
279 | int i; | ||
280 | |||
281 | if (pthread_mutex_lock(&mutex) != 0) { | ||
282 | OSAL_ErrorTrace("Core: Error in Mutex lock"); | ||
283 | } | ||
284 | |||
285 | CORE_assert(hComponent != NULL, OMX_ErrorBadParameter, NULL); | ||
286 | CORE_assert(count > 0, OMX_ErrorUndefined, "OMX_FreeHandle called without calling OMX_Init first"); | ||
287 | |||
288 | /* Locate the component handle in the array of handles */ | ||
289 | for (i = 0; i < (int) COUNTOF(pModules); i++) { | ||
290 | if (pComponents[i] == hComponent) { | ||
291 | break; | ||
292 | } | ||
293 | } | ||
294 | CORE_assert(i != COUNTOF(pModules), OMX_ErrorBadParameter, NULL); | ||
295 | |||
296 | OMX_COMPONENTTYPE *pHandle = (OMX_COMPONENTTYPE *) hComponent; | ||
297 | eError = pHandle->ComponentDeInit(hComponent); | ||
298 | if (eError != OMX_ErrorNone) { | ||
299 | OSAL_ErrorTrace("Error From ComponentDeInit.."); | ||
300 | } | ||
301 | |||
302 | /* release the component and the component handle */ | ||
303 | dlclose(pModules[i]); | ||
304 | pModules[i] = NULL; | ||
305 | free(pComponents[i]); | ||
306 | |||
307 | pComponents[i] = NULL; | ||
308 | |||
309 | concurrent_instances--; | ||
310 | eError = OMX_ErrorNone; | ||
311 | |||
312 | EXIT: | ||
313 | /* The unload is now complete, so set the error code to pass and exit */ | ||
314 | if (pthread_mutex_unlock(&mutex) != 0) { | ||
315 | OSAL_ErrorTrace("Core: Error in Mutex unlock"); | ||
316 | } | ||
317 | |||
318 | return (eError); | ||
319 | } | ||
320 | |||
321 | /* | ||
322 | * OMX_DeInit() | ||
323 | * | ||
324 | * Description: This method will release the resources of the OMX Core. It is the | ||
325 | * responsibility of the application to call OMX_DeInit to ensure the clean up of these | ||
326 | * resources. | ||
327 | * | ||
328 | * Returns: OMX_NOERROR Successful | ||
329 | */ | ||
330 | OMX_ERRORTYPE OMX_Deinit() | ||
331 | { | ||
332 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
333 | OSAL_ERROR eOsalError = OSAL_ErrNone; | ||
334 | |||
335 | eOsalError = OSAL_ObtainMutex(pCoreInitMutex, OSAL_SUSPEND); | ||
336 | if (eOsalError != OSAL_ErrNone) { | ||
337 | OSAL_ErrorTrace("Mutex lock failed"); | ||
338 | } | ||
339 | /*Returning error none because of OMX spec limitation on error codes that | ||
340 | can be returned by OMX_Deinit */ | ||
341 | CORE_assert(count > 0, OMX_ErrorNone, "OMX_Deinit being called without a corresponding OMX_Init"); | ||
342 | count--; | ||
343 | |||
344 | if (pthread_mutex_lock(&mutex) != 0) { | ||
345 | OSAL_ErrorTrace("Core: Error in Mutex lock"); | ||
346 | } | ||
347 | |||
348 | if (count == 0) { | ||
349 | memplugin_close(); | ||
350 | if (pthread_mutex_unlock(&mutex) != 0) { | ||
351 | OSAL_ErrorTrace("Core: Error in Mutex unlock"); | ||
352 | } | ||
353 | if (pthread_mutex_destroy(&mutex) != 0) { | ||
354 | OSAL_ErrorTrace("%d :: Core: Error in Mutex destroy\n", __LINE__); | ||
355 | } | ||
356 | } else { | ||
357 | if (pthread_mutex_unlock(&mutex) != 0) { | ||
358 | OSAL_ErrorTrace("Core: Error in Mutex unlock"); | ||
359 | } | ||
360 | } | ||
361 | |||
362 | EXIT: | ||
363 | eOsalError = OSAL_ReleaseMutex(pCoreInitMutex); | ||
364 | if (eOsalError != OSAL_ErrNone) { | ||
365 | OSAL_ErrorTrace("Mutex release failed"); | ||
366 | } | ||
367 | return (eError); | ||
368 | } | ||
369 | |||
370 | /* | ||
371 | * OMX_SetupTunnel() | ||
372 | * | ||
373 | * Description: Setup the specified tunnel the two components | ||
374 | * | ||
375 | * Parameters: | ||
376 | * @param[in] hOutput Handle of the component to be accessed | ||
377 | * @param[in] nPortOutput Source port used in the tunnel | ||
378 | * @param[in] hInput Component to setup the tunnel with. | ||
379 | * @param[in] nPortInput Destination port used in the tunnel | ||
380 | * | ||
381 | * Returns: OMX_NOERROR Successful | ||
382 | */ | ||
383 | OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_SetupTunnel(OMX_IN OMX_HANDLETYPE hOutput, | ||
384 | OMX_IN OMX_U32 nPortOutput, | ||
385 | OMX_IN OMX_HANDLETYPE hInput, | ||
386 | OMX_IN OMX_U32 nPortInput) | ||
387 | { | ||
388 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
389 | OMX_COMPONENTTYPE *pCompOut = (OMX_COMPONENTTYPE *) hOutput; | ||
390 | OMX_COMPONENTTYPE *pCompIn = (OMX_COMPONENTTYPE *) hInput; | ||
391 | OMX_TUNNELSETUPTYPE oTunnelSetup; | ||
392 | |||
393 | if (hOutput == NULL && hInput == NULL) { | ||
394 | return (OMX_ErrorBadParameter); | ||
395 | } | ||
396 | |||
397 | oTunnelSetup.nTunnelFlags = 0; | ||
398 | oTunnelSetup.eSupplier = OMX_BufferSupplyUnspecified; | ||
399 | |||
400 | if (hOutput) { | ||
401 | eError = pCompOut->ComponentTunnelRequest(hOutput, nPortOutput, hInput, nPortInput, &oTunnelSetup); | ||
402 | if (eError != OMX_ErrorNone) | ||
403 | return eError; | ||
404 | } | ||
405 | |||
406 | if (hInput) { | ||
407 | eError = pCompIn->ComponentTunnelRequest(hInput, nPortInput, hOutput, nPortOutput, &oTunnelSetup); | ||
408 | if (eError != OMX_ErrorNone && hOutput) { | ||
409 | /* cancel tunnel request on output port since input port failed */ | ||
410 | pCompOut->ComponentTunnelRequest(hOutput, nPortOutput, NULL, 0, NULL); | ||
411 | } | ||
412 | } | ||
413 | return (eError); | ||
414 | } | ||
415 | |||
416 | /* | ||
417 | * OMX_ComponentNameEnum() | ||
418 | * | ||
419 | * Description: This method will provide the name of the component at the given nIndex | ||
420 | * | ||
421 | * Parameters: | ||
422 | * @param[out] cComponentName The name of the component at nIndex | ||
423 | * @param[in] nNameLength The length of the component name | ||
424 | * @param[in] nIndex The index number of the component | ||
425 | * | ||
426 | * Returns: OMX_NOERROR Successful | ||
427 | */ | ||
428 | OMX_API OMX_ERRORTYPE OMX_APIENTRY OMX_ComponentNameEnum(OMX_OUT OMX_STRING cComponentName, | ||
429 | OMX_IN OMX_U32 nNameLength, | ||
430 | OMX_IN OMX_U32 nIndex) | ||
431 | { | ||
432 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
433 | |||
434 | CORE_assert(cComponentName != NULL, OMX_ErrorBadParameter, NULL); | ||
435 | CORE_assert(count > 0, OMX_ErrorUndefined, "OMX_GetHandle called without calling OMX_Init first"); | ||
436 | |||
437 | if (nIndex >= (OMX_U32) COUNTOF(componentTable)) { | ||
438 | eError = OMX_ErrorNoMore; | ||
439 | } else if (strlen(componentTable[nIndex].name) >= nNameLength) { | ||
440 | eError = OMX_ErrorBadParameter; | ||
441 | } else { | ||
442 | strcpy(cComponentName, componentTable[nIndex].name); | ||
443 | } | ||
444 | |||
445 | EXIT: | ||
446 | return (eError); | ||
447 | } | ||
448 | |||
449 | /* | ||
450 | * OMX_GetRolesOfComponent() | ||
451 | * | ||
452 | * Description: This method will query the component for its supported roles | ||
453 | * | ||
454 | * Parameters: | ||
455 | * @param[in] cComponentName The name of the component to query | ||
456 | * @param[in] pNumRoles The number of roles supported by the component | ||
457 | * @param[in] roles The roles of the component | ||
458 | * | ||
459 | * Returns: OMX_NOERROR Successful | ||
460 | * OMX_ErrorBadParameter Failure due to a bad input parameter | ||
461 | */ | ||
462 | OMX_API OMX_ERRORTYPE OMX_GetRolesOfComponent(OMX_IN OMX_STRING cComponentName, | ||
463 | OMX_INOUT OMX_U32 *pNumRoles, | ||
464 | OMX_OUT OMX_U8 **roles) | ||
465 | { | ||
466 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
467 | OMX_BOOL bFound = OMX_FALSE; | ||
468 | OMX_U32 index = 0; | ||
469 | |||
470 | CORE_assert(cComponentName != NULL, OMX_ErrorBadParameter, NULL); | ||
471 | CORE_assert(pNumRoles != NULL, OMX_ErrorBadParameter, NULL); | ||
472 | CORE_assert(strlen(cComponentName) < MAXNAMESIZE, OMX_ErrorInvalidComponentName, NULL); | ||
473 | CORE_assert(count > 0, OMX_ErrorUndefined, "OMX_GetHandle called without calling OMX_Init first"); | ||
474 | |||
475 | /* Locate the component in the component table */ | ||
476 | for (index = 0; index < (OMX_U32) COUNTOF(componentTable); index++) { | ||
477 | if (strcmp(cComponentName, componentTable[index].name) == 0) { | ||
478 | break; | ||
479 | } | ||
480 | } | ||
481 | CORE_assert(index != COUNTOF(componentTable), OMX_ErrorComponentNotFound, NULL); | ||
482 | |||
483 | // just getting component's role count this call | ||
484 | if (roles == NULL) { | ||
485 | *pNumRoles = componentTable[index].nRoles; | ||
486 | goto EXIT; | ||
487 | } | ||
488 | |||
489 | // requested too many roles from this component | ||
490 | if (*pNumRoles > componentTable[index].nRoles) { | ||
491 | eError = OMX_ErrorBadParameter; | ||
492 | goto EXIT; | ||
493 | } | ||
494 | |||
495 | for (size_t j = 0; j < *pNumRoles; j++) { | ||
496 | strcpy((OMX_STRING) roles[j], componentTable[index].pRoleArray[j]); | ||
497 | } | ||
498 | |||
499 | EXIT: | ||
500 | return (eError); | ||
501 | } | ||
502 | |||
503 | /* | ||
504 | * OMX_GetComponentsOfRole() | ||
505 | * | ||
506 | * Description: This method will query the component for its supported roles | ||
507 | * | ||
508 | * Parameters: | ||
509 | * @param[in] role The role name to query for | ||
510 | * @param[in] pNumComps The number of components supporting the given role | ||
511 | * @param[in] compNames The names of the components supporting the given role | ||
512 | * | ||
513 | * Returns: OMX_NOERROR Successful | ||
514 | */ | ||
515 | OMX_API OMX_ERRORTYPE OMX_GetComponentsOfRole(OMX_IN OMX_STRING role, | ||
516 | OMX_INOUT OMX_U32 *pNumComps, | ||
517 | OMX_INOUT OMX_U8 **compNames) | ||
518 | { | ||
519 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
520 | |||
521 | CORE_assert(role != NULL, OMX_ErrorBadParameter, NULL); | ||
522 | CORE_assert(pNumComps != NULL, OMX_ErrorBadParameter, NULL); | ||
523 | CORE_assert(count > 0, OMX_ErrorUndefined, "OMX_GetHandle called without calling OMX_Init first"); | ||
524 | |||
525 | *pNumComps = 0; | ||
526 | |||
527 | for (size_t i = 0; i < (OMX_U32) COUNTOF(componentTable); i++) { | ||
528 | for (size_t j = 0; j < componentTable[i].nRoles; j++) { | ||
529 | if (strcmp(componentTable[i].pRoleArray[j], role) == 0) { | ||
530 | /* the first call to this function should only count the number | ||
531 | of roles so that for the second call compNames can be allocated | ||
532 | with the proper size for that number of roles */ | ||
533 | if (compNames != NULL) { | ||
534 | strncpy((OMX_STRING) (compNames[*pNumComps]), (OMX_STRING) componentTable[i].name, MAXNAMESIZE); | ||
535 | } | ||
536 | (*pNumComps)++; | ||
537 | } | ||
538 | } | ||
539 | } | ||
540 | |||
541 | EXIT: | ||
542 | return (eError); | ||
543 | } | ||
544 | |||
545 | /* | ||
546 | * @fn Core_Setup : This function is called when the the OMX Core library is | ||
547 | * loaded. It creates a mutex, which is used during OMX_Init() | ||
548 | */ | ||
549 | void __attribute__ ((constructor)) Core_Setup(void) | ||
550 | { | ||
551 | OSAL_ERROR eError = OSAL_ErrNone; | ||
552 | eError = OSAL_CreateMutex(&pCoreInitMutex); | ||
553 | if( eError != OSAL_ErrNone ) { | ||
554 | OSAL_ErrorTrace("Creation of default mutex failed"); | ||
555 | } | ||
556 | } | ||
557 | |||
558 | /* | ||
559 | * @fn Core_Destroy : This function is called when the the OMX Core library is | ||
560 | * unloaded. It destroys the mutex which was created by | ||
561 | * Core_Setup(). | ||
562 | */ | ||
563 | void __attribute__ ((destructor)) Core_Destroy(void) | ||
564 | { | ||
565 | OSAL_ERROR eError = OSAL_ErrNone; | ||
566 | eError = OSAL_DeleteMutex(pCoreInitMutex); | ||
567 | if( eError != OSAL_ErrNone ) { | ||
568 | OSAL_ErrorTrace("Destruction of default mutex failed"); | ||
569 | } | ||
570 | } | ||
diff --git a/libstagefrighthw/omx/base/Android.bp b/libstagefrighthw/omx/base/Android.bp new file mode 100644 index 0000000..898ddde --- /dev/null +++ b/libstagefrighthw/omx/base/Android.bp | |||
@@ -0,0 +1,32 @@ | |||
1 | // OMX Ducati Common Base Library | ||
2 | |||
3 | cc_library_shared { | ||
4 | |||
5 | name: "libOMX.ti.ducati.base", | ||
6 | vendor: true, | ||
7 | |||
8 | srcs: [ | ||
9 | "OMX_Base.c", | ||
10 | "OMX_BaseCallbacks.c", | ||
11 | "OMX_BaseInternal.c", | ||
12 | "OMX_BaseProcess.c", | ||
13 | "OMX_BaseDIO.c", | ||
14 | "OMX_BaseDIOTable.c", | ||
15 | "OMX_BaseDIONonTunnel.c", | ||
16 | ], | ||
17 | |||
18 | export_include_dirs: ["."], | ||
19 | header_libs: ["media_plugin_headers"], | ||
20 | |||
21 | shared_libs: [ | ||
22 | "libosal", | ||
23 | "libc", | ||
24 | "liblog", | ||
25 | "libcutils", | ||
26 | "libutils", | ||
27 | "libdce", | ||
28 | ], | ||
29 | |||
30 | cflags: ["-DBUILDOS_ANDROID"], | ||
31 | |||
32 | } | ||
diff --git a/libstagefrighthw/omx/base/OMX_Base.c b/libstagefrighthw/omx/base/OMX_Base.c new file mode 100644 index 0000000..658da36 --- /dev/null +++ b/libstagefrighthw/omx/base/OMX_Base.c | |||
@@ -0,0 +1,1273 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 | #define LOG_TAG "OMX_BASE" | ||
18 | |||
19 | #include <string.h> | ||
20 | |||
21 | #include <OMX_Core.h> | ||
22 | #include <OMX_Component.h> | ||
23 | #include <OMX_Base.h> | ||
24 | #include <OMX_TI_Custom.h> | ||
25 | |||
26 | /** | ||
27 | * OMX BaseComponent Init | ||
28 | */ | ||
29 | OMX_ERRORTYPE OMXBase_ComponentInit(OMX_IN OMX_HANDLETYPE hComponent) | ||
30 | { | ||
31 | OMX_ERRORTYPE eError = OMX_ErrorNone, eTmpError = OMX_ErrorNone; | ||
32 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
33 | OMX_COMPONENTTYPE *pComp = NULL; | ||
34 | OMXBaseComp *pBaseComp = NULL; | ||
35 | |||
36 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
37 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
38 | pBaseComp = (OMXBaseComp*)pComp->pComponentPrivate; | ||
39 | OMX_CHECK(pBaseComp != NULL, OMX_ErrorBadParameter); | ||
40 | |||
41 | /* populate component specific function pointers */ | ||
42 | pComp->GetComponentVersion = OMXBase_GetComponentVersion; | ||
43 | pComp->SendCommand = OMXBase_SendCommand; | ||
44 | pComp->GetParameter = OMXBase_GetParameter; | ||
45 | pComp->SetParameter = OMXBase_SetParameter; | ||
46 | pComp->GetConfig = OMXBase_GetConfig; | ||
47 | pComp->SetConfig = OMXBase_SetConfig; | ||
48 | pComp->GetExtensionIndex = OMXBase_GetExtensionIndex; | ||
49 | pComp->GetState = OMXBase_GetState; | ||
50 | pComp->ComponentTunnelRequest = NULL; | ||
51 | pComp->UseBuffer = OMXBase_UseBuffer; | ||
52 | pComp->AllocateBuffer = OMXBase_AllocateBuffer; | ||
53 | pComp->FreeBuffer = OMXBase_FreeBuffer; | ||
54 | pComp->EmptyThisBuffer = OMXBase_EmptyThisBuffer; | ||
55 | pComp->FillThisBuffer = OMXBase_FillThisBuffer; | ||
56 | pComp->SetCallbacks = OMXBase_SetCallbacks; | ||
57 | pComp->ComponentDeInit = OMXBase_ComponentDeinit; | ||
58 | pComp->UseEGLImage = OMXBase_UseEGLImage; | ||
59 | pComp->ComponentRoleEnum = OMXBase_ComponentRoleEnum; | ||
60 | |||
61 | pBaseComp->fpReturnEventNotify = OMXBase_CB_ReturnEventNotify; | ||
62 | |||
63 | /* create a mutex to handle race conditions */ | ||
64 | tStatus = OSAL_CreateMutex(&(pBaseComp->pMutex)); | ||
65 | if(OSAL_ErrNone != tStatus) { | ||
66 | return OMX_ErrorInsufficientResources; | ||
67 | } | ||
68 | |||
69 | /* Allocate internal area for Base component */ | ||
70 | pBaseComp->pPvtData = (OMXBaseComp_Pvt*)OSAL_Malloc(sizeof(OMXBaseComp_Pvt)); | ||
71 | OMX_CHECK(pBaseComp->pPvtData != NULL, OMX_ErrorInsufficientResources); | ||
72 | |||
73 | OSAL_Memset(pBaseComp->pPvtData, 0, sizeof(OMXBaseComp_Pvt)); | ||
74 | eError = OMXBase_PrivateInit(hComponent); | ||
75 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
76 | |||
77 | /* Initialize ports */ | ||
78 | eError = OMXBase_InitializePorts(hComponent); | ||
79 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
80 | |||
81 | /* Component is initialized successfully, set the | ||
82 | * component to loaded state */ | ||
83 | pBaseComp->tCurState = OMX_StateLoaded; | ||
84 | pBaseComp->tNewState = OMX_StateMax; | ||
85 | |||
86 | |||
87 | EXIT: | ||
88 | /* incase of an error, deinitialize the component */ | ||
89 | if((OMX_ErrorNone != eError) && (pComp != NULL)) { | ||
90 | eTmpError = eError; | ||
91 | eError = pComp->ComponentDeInit(hComponent); | ||
92 | eError = eTmpError; | ||
93 | } | ||
94 | return (eError); | ||
95 | } | ||
96 | |||
97 | /* | ||
98 | * SetCallbacks | ||
99 | */ | ||
100 | OMX_ERRORTYPE OMXBase_SetCallbacks(OMX_HANDLETYPE hComponent, | ||
101 | OMX_CALLBACKTYPE *pCallbacks, | ||
102 | OMX_PTR pAppData) | ||
103 | { | ||
104 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
105 | OMX_COMPONENTTYPE *pComp = NULL; | ||
106 | OMXBaseComp *pBaseComp = NULL; | ||
107 | OMXBaseComp_Pvt *pBaseCompPvt = NULL; | ||
108 | OMX_U32 i = 0; | ||
109 | |||
110 | OMX_CHECK((hComponent != NULL) && | ||
111 | (pCallbacks != NULL), OMX_ErrorBadParameter); | ||
112 | |||
113 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
114 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
115 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
116 | |||
117 | pComp->pApplicationPrivate = pAppData; | ||
118 | pBaseCompPvt->sAppCallbacks = *pCallbacks; | ||
119 | |||
120 | for( i = 0; i < pBaseComp->nNumPorts; i++ ) { | ||
121 | pBaseComp->pPorts[i]->bIsBufferAllocator = OMX_FALSE; | ||
122 | } | ||
123 | |||
124 | EXIT: | ||
125 | return (eError); | ||
126 | } | ||
127 | |||
128 | /* | ||
129 | * GetComponent Version | ||
130 | */ | ||
131 | OMX_ERRORTYPE OMXBase_GetComponentVersion(OMX_HANDLETYPE hComponent, | ||
132 | OMX_STRING pComponentName, | ||
133 | OMX_VERSIONTYPE *pComponentVersion, | ||
134 | OMX_VERSIONTYPE *pSpecVersion, | ||
135 | OMX_UUIDTYPE *pComponentUUID) | ||
136 | { | ||
137 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
138 | OMX_COMPONENTTYPE *pComp = NULL; | ||
139 | OMXBaseComp *pBaseComp = NULL; | ||
140 | (void)pComponentUUID; | ||
141 | |||
142 | OMX_CHECK((hComponent != NULL) && | ||
143 | (pComponentName != NULL) && | ||
144 | (pComponentVersion != NULL) && | ||
145 | (pSpecVersion != NULL), OMX_ErrorBadParameter); | ||
146 | |||
147 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
148 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
149 | |||
150 | /*Can't be invoked when the comp is in invalid state*/ | ||
151 | OMX_CHECK(OMX_StateInvalid != pBaseComp->tCurState, OMX_ErrorInvalidState); | ||
152 | |||
153 | OSAL_Memcpy(pComponentName, pBaseComp->cComponentName, OMX_MAX_STRINGNAME_SIZE); | ||
154 | |||
155 | *pComponentVersion = pBaseComp->nComponentVersion; | ||
156 | *pSpecVersion = pComp->nVersion; | ||
157 | |||
158 | EXIT: | ||
159 | return (eError); | ||
160 | } | ||
161 | |||
162 | /* | ||
163 | * GetState | ||
164 | */ | ||
165 | OMX_ERRORTYPE OMXBase_GetState(OMX_HANDLETYPE hComponent, | ||
166 | OMX_STATETYPE *pState) | ||
167 | { | ||
168 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
169 | OMX_COMPONENTTYPE *pComp = NULL; | ||
170 | OMXBaseComp *pBaseComp = NULL; | ||
171 | |||
172 | OMX_CHECK((hComponent != NULL) && | ||
173 | (pState != NULL), OMX_ErrorBadParameter); | ||
174 | |||
175 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
176 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
177 | |||
178 | *pState = pBaseComp->tCurState; | ||
179 | |||
180 | EXIT: | ||
181 | return (eError); | ||
182 | } | ||
183 | |||
184 | /* | ||
185 | * Base Component DeInit | ||
186 | */ | ||
187 | OMX_ERRORTYPE OMXBase_ComponentDeinit(OMX_HANDLETYPE hComponent) | ||
188 | { | ||
189 | OMX_ERRORTYPE eError = OMX_ErrorNone, eTmpError = OMX_ErrorNone; | ||
190 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
191 | OMX_COMPONENTTYPE *pComp = NULL; | ||
192 | OMXBaseComp *pBaseComp = NULL; | ||
193 | OMXBaseComp_Pvt *pBaseCompPvt = NULL; | ||
194 | OMXBase_Port *pPort = NULL; | ||
195 | OMX_U32 i = 0; | ||
196 | |||
197 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
198 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
199 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
200 | OMX_CHECK(pBaseComp != NULL, OMX_ErrorBadParameter); | ||
201 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
202 | |||
203 | OSAL_ObtainMutex(pBaseComp->pMutex, OSAL_SUSPEND); | ||
204 | |||
205 | /*If component transitioned to invalid state suddenly then dio close and | ||
206 | deinit might have not been called - in that case calle them now */ | ||
207 | if( pBaseComp->tCurState != OMX_StateLoaded ) { | ||
208 | for( i=0; i < pBaseComp->nNumPorts; i++ ) { | ||
209 | pPort = pBaseComp->pPorts[i]; | ||
210 | if( pPort != NULL ) { | ||
211 | if( pPort->hDIO != NULL ) { | ||
212 | eTmpError = OMXBase_DIO_Close(hComponent, | ||
213 | (i + pBaseComp->nMinStartPortIndex)); | ||
214 | if( eTmpError != OMX_ErrorNone ) { | ||
215 | eError = eTmpError; | ||
216 | } | ||
217 | eTmpError = OMXBase_DIO_Deinit(hComponent, | ||
218 | (i + pBaseComp->nMinStartPortIndex)); | ||
219 | if( eTmpError != OMX_ErrorNone ) { | ||
220 | eError = eTmpError; | ||
221 | } | ||
222 | } | ||
223 | } | ||
224 | } | ||
225 | } | ||
226 | |||
227 | /* deinitialize ports and freeup the memory */ | ||
228 | eTmpError = OMXBase_DeinitializePorts(hComponent); | ||
229 | if( eTmpError != OMX_ErrorNone ) { | ||
230 | eError = eTmpError; | ||
231 | } | ||
232 | |||
233 | OSAL_ReleaseMutex(pBaseComp->pMutex); | ||
234 | |||
235 | if (pBaseCompPvt) { | ||
236 | OMXBase_PrivateDeInit(hComponent); | ||
237 | } | ||
238 | |||
239 | tStatus = OSAL_DeleteMutex(pBaseComp->pMutex); | ||
240 | if( tStatus != OSAL_ErrNone ) { | ||
241 | eError = OMX_ErrorUndefined; | ||
242 | } | ||
243 | pBaseComp->pMutex = NULL; | ||
244 | |||
245 | OSAL_Free(pBaseCompPvt); | ||
246 | pBaseCompPvt = NULL; | ||
247 | |||
248 | EXIT: | ||
249 | return (eError); | ||
250 | } | ||
251 | |||
252 | /* | ||
253 | * OMXBase SendCommand | ||
254 | */ | ||
255 | OMX_ERRORTYPE OMXBase_SendCommand(OMX_HANDLETYPE hComponent, | ||
256 | OMX_COMMANDTYPE Cmd, | ||
257 | OMX_U32 nParam1, | ||
258 | OMX_PTR pCmdData) | ||
259 | { | ||
260 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
261 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
262 | OMX_COMPONENTTYPE *pComp = NULL; | ||
263 | OMXBaseComp *pBaseComp = NULL; | ||
264 | OMXBaseComp_Pvt *pBaseCompPvt = NULL; | ||
265 | OMXBase_Port *pPort = NULL; | ||
266 | OMXBase_CmdParams sCmdParams, sErrorCmdParams; | ||
267 | OMX_U32 nPorts, nStartPortNumber, nIndex; | ||
268 | OMX_PTR pLocalCmdData = NULL; | ||
269 | OMX_BOOL bFreeCmdDataIfError = OMX_TRUE; | ||
270 | OMX_U32 i = 0; | ||
271 | uint32_t nActualSize = 0, nCmdCount = 0; | ||
272 | |||
273 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
274 | if( OMX_CommandMarkBuffer == Cmd ) { | ||
275 | OMX_CHECK(pCmdData != NULL, OMX_ErrorBadParameter); | ||
276 | } | ||
277 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
278 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
279 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
280 | |||
281 | nPorts = pBaseComp->nNumPorts; | ||
282 | nStartPortNumber = pBaseComp->nMinStartPortIndex; | ||
283 | |||
284 | /*Can't be invoked when the comp is in invalid state*/ | ||
285 | OMX_CHECK(OMX_StateInvalid != pBaseComp->tCurState, OMX_ErrorInvalidState); | ||
286 | |||
287 | switch( Cmd ) { | ||
288 | case OMX_CommandStateSet : | ||
289 | /*Return error if unknown state is provided*/ | ||
290 | OMX_CHECK(((OMX_STATETYPE)nParam1 <= | ||
291 | OMX_StateWaitForResources), OMX_ErrorBadParameter); | ||
292 | |||
293 | /*Mutex protection is for multiple SendCommands on the same | ||
294 | component parallely. This can especially happen in error handling | ||
295 | scenarios. Mutex protection ensure that the NewState variable is not | ||
296 | overwritten.*/ | ||
297 | OSAL_ObtainMutex(pBaseCompPvt->pNewStateMutex, | ||
298 | OSAL_SUSPEND); | ||
299 | /*Multiple state transitions at the same time is not allowed. | ||
300 | Though it is allowed by the spec, we prohibit it in our | ||
301 | implementation*/ | ||
302 | if( OMX_StateMax != pBaseComp->tNewState ) { | ||
303 | eError = OMX_ErrorIncorrectStateTransition; | ||
304 | OSAL_ReleaseMutex(pBaseCompPvt->pNewStateMutex); | ||
305 | goto EXIT; | ||
306 | } | ||
307 | pBaseComp->tNewState = (OMX_STATETYPE)nParam1; | ||
308 | OSAL_ReleaseMutex(pBaseCompPvt->pNewStateMutex); | ||
309 | break; | ||
310 | |||
311 | case OMX_CommandPortDisable : | ||
312 | /* Index of the port to disable should be less than | ||
313 | * no of ports or equal to OMX_ALL */ | ||
314 | OMX_CHECK((nParam1 < (nStartPortNumber + nPorts)) || | ||
315 | (nParam1 == OMX_ALL), OMX_ErrorBadPortIndex); | ||
316 | if( OMX_ALL == nParam1 ) { | ||
317 | /*Dont want to return same port state error if it never enters | ||
318 | the for loop*/ | ||
319 | if( nPorts > 0 ) { | ||
320 | eError = (OMX_ERRORTYPE)OMX_ErrorNone; | ||
321 | } | ||
322 | |||
323 | for( nIndex = 0; nIndex < nPorts; nIndex++ ) { | ||
324 | pPort = pBaseComp->pPorts[nIndex]; | ||
325 | /*Atleast 1 port is enabled - dont send same port state error*/ | ||
326 | if( pPort->sPortDef.bEnabled ) { | ||
327 | pPort->sPortDef.bEnabled = OMX_FALSE; | ||
328 | pPort->bIsInTransition = OMX_TRUE; | ||
329 | eError = OMX_ErrorNone; | ||
330 | } | ||
331 | } | ||
332 | } else { | ||
333 | nIndex = nParam1 - nStartPortNumber; | ||
334 | pPort = pBaseComp->pPorts[nIndex]; | ||
335 | if( pPort->sPortDef.bEnabled ) { | ||
336 | pPort->sPortDef.bEnabled = OMX_FALSE; | ||
337 | pPort->bIsInTransition = OMX_TRUE; | ||
338 | } else { | ||
339 | eError = (OMX_ERRORTYPE)OMX_ErrorNone; | ||
340 | } | ||
341 | } | ||
342 | break; | ||
343 | |||
344 | case OMX_CommandPortEnable : | ||
345 | /* Index of the port to enable should be less than | ||
346 | * no of ports or equal to OMX_ALL */ | ||
347 | OMX_CHECK((nParam1 < (nStartPortNumber + nPorts)) || | ||
348 | (nParam1 == OMX_ALL), OMX_ErrorBadPortIndex); | ||
349 | if( OMX_ALL == nParam1 ) { | ||
350 | /*Dont want to return same port state error if it never enters | ||
351 | the for loop*/ | ||
352 | if( nPorts > 0 ) { | ||
353 | eError = (OMX_ERRORTYPE)OMX_ErrorNone; | ||
354 | } | ||
355 | |||
356 | for( nIndex = 0; nIndex < nPorts; nIndex++ ) { | ||
357 | pPort = pBaseComp->pPorts[nIndex]; | ||
358 | /*Atleast 1 port is disabled - dont send same port state error*/ | ||
359 | if( !pPort->sPortDef.bEnabled ) { | ||
360 | eError = OMX_ErrorNone; | ||
361 | pPort->sPortDef.bEnabled = OMX_TRUE; | ||
362 | pPort->bIsInTransition = OMX_TRUE; | ||
363 | } | ||
364 | } | ||
365 | } else { | ||
366 | nIndex = nParam1 - nStartPortNumber; | ||
367 | pPort = pBaseComp->pPorts[nIndex]; | ||
368 | if( !pPort->sPortDef.bEnabled ) { | ||
369 | pPort->sPortDef.bEnabled = OMX_TRUE; | ||
370 | pPort->bIsInTransition = OMX_TRUE; | ||
371 | } else { | ||
372 | eError = (OMX_ERRORTYPE)OMX_ErrorNone; | ||
373 | } | ||
374 | } | ||
375 | break; | ||
376 | |||
377 | case OMX_CommandMarkBuffer : | ||
378 | /*For mark buffer pCmdData points to a structure of type OMX_MARKTYPE. | ||
379 | This may not be valid once send commmand returns so allocate memory and | ||
380 | copy this info there. This memory will be freed up during the command | ||
381 | complete callback for mark buffer.*/ | ||
382 | OMX_CHECK((nParam1 < (nStartPortNumber + nPorts)) || | ||
383 | (nParam1 == OMX_ALL), OMX_ErrorBadPortIndex); | ||
384 | pLocalCmdData = OSAL_Malloc(sizeof(OMX_MARKTYPE)); | ||
385 | OMX_CHECK(pLocalCmdData != NULL, OMX_ErrorInsufficientResources); | ||
386 | OSAL_Memcpy(pLocalCmdData, pCmdData, sizeof(OMX_MARKTYPE)); | ||
387 | break; | ||
388 | |||
389 | case OMX_CommandFlush : | ||
390 | OMX_CHECK((nParam1 < (nStartPortNumber + nPorts)) || | ||
391 | (nParam1 == OMX_ALL), OMX_ErrorBadPortIndex); | ||
392 | break; | ||
393 | |||
394 | default : | ||
395 | OMX_CHECK(OMX_FALSE, OMX_ErrorBadParameter); | ||
396 | } | ||
397 | |||
398 | /*Return error if port enable/disable command is sent on an already | ||
399 | enabled/disabled port*/ | ||
400 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
401 | /*For mark buffer store pCmdData in a separate pipe - to be freed up during | ||
402 | command complete callback*/ | ||
403 | if( Cmd == OMX_CommandMarkBuffer ) { | ||
404 | /*If pipe is full, return error - thus a limitation that currently | ||
405 | cannot queue up more than OMXBase_MAXCMDS mark buffer commands*/ | ||
406 | tStatus = OSAL_WriteToPipe(pBaseCompPvt->pCmdDataPipe, | ||
407 | &pLocalCmdData, sizeof(OMX_PTR), OSAL_NO_SUSPEND); | ||
408 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorInsufficientResources); | ||
409 | } | ||
410 | /*Obtain mutex for writing to command pipe*/ | ||
411 | tStatus = OSAL_ObtainMutex(pBaseCompPvt->pCmdPipeMutex, OSAL_SUSPEND); | ||
412 | if((tStatus != OSAL_ErrNone) && (Cmd == OMX_CommandMarkBuffer)) { | ||
413 | bFreeCmdDataIfError = OMX_FALSE; | ||
414 | } | ||
415 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorUndefined); | ||
416 | |||
417 | /* keep this info, and process later */ | ||
418 | sCmdParams.eCmd = Cmd; | ||
419 | sCmdParams.unParam = nParam1; | ||
420 | if( Cmd == OMX_CommandMarkBuffer ) { | ||
421 | sCmdParams.pCmdData = pLocalCmdData; | ||
422 | } else { | ||
423 | sCmdParams.pCmdData = pCmdData; | ||
424 | } | ||
425 | tStatus = OSAL_WriteToPipe(pBaseCompPvt->pCmdPipe, &sCmdParams, | ||
426 | sizeof(sCmdParams), OSAL_SUSPEND); | ||
427 | if( tStatus != OSAL_ErrNone ) { | ||
428 | /*Do not free pLocalCmdData in this case since it has been pushed to | ||
429 | pipe and will now be freed during deinit when pipe is deleted*/ | ||
430 | if( Cmd == OMX_CommandMarkBuffer ) { | ||
431 | bFreeCmdDataIfError = OMX_FALSE; | ||
432 | } | ||
433 | /*Release the locked mutex and exit with error*/ | ||
434 | eError = OMX_ErrorInsufficientResources; | ||
435 | tStatus = OSAL_ReleaseMutex(pBaseCompPvt->pCmdPipeMutex); | ||
436 | goto EXIT; | ||
437 | } | ||
438 | /* This call invokes the process function directly incase if comp | ||
439 | * does process in client context, otherwise triggers compo thread */ | ||
440 | eError = pBaseCompPvt->fpInvokeProcessFunction(hComponent, CMDEVENT); | ||
441 | if( eError != OMX_ErrorNone ) { | ||
442 | if( Cmd == OMX_CommandMarkBuffer ) { | ||
443 | /*Do not free pLocalCmdData in this case since it has been pushed to | ||
444 | pipe and will now be freed during deinit when pipe is deleted*/ | ||
445 | bFreeCmdDataIfError = OMX_FALSE; | ||
446 | } | ||
447 | /*Get the count in cmd pipe - this is to be used for popping the | ||
448 | recently added cmd to the pipe since that is no longer valid*/ | ||
449 | tStatus = OSAL_GetPipeReadyMessageCount(pBaseCompPvt->pCmdPipe, | ||
450 | &nCmdCount); | ||
451 | if( tStatus != OSAL_ErrNone ) { | ||
452 | /*Release mutex and return error*/ | ||
453 | eError = OMX_ErrorUndefined; | ||
454 | tStatus = OSAL_ReleaseMutex(pBaseCompPvt->pCmdPipeMutex); | ||
455 | goto EXIT; | ||
456 | } | ||
457 | |||
458 | for( i = 0; i < nCmdCount; i++ ) { | ||
459 | /*Clear the last command from pipe since error has occured*/ | ||
460 | tStatus = OSAL_ReadFromPipe(pBaseCompPvt->pCmdPipe, &sErrorCmdParams, | ||
461 | sizeof(sErrorCmdParams), &nActualSize, | ||
462 | OSAL_SUSPEND); | ||
463 | if( tStatus != OSAL_ErrNone ) { | ||
464 | eError = OMX_ErrorUndefined; | ||
465 | break; | ||
466 | } | ||
467 | if( OSAL_Memcmp(&sErrorCmdParams, &sCmdParams, sizeof(OMXBase_CmdParams)) == 0 ) { | ||
468 | OSAL_ErrorTrace("Found the command to discard"); | ||
469 | break; | ||
470 | } else { | ||
471 | /* This is not the command to be discarded - write it back to pipe */ | ||
472 | tStatus = OSAL_WriteToPipe(pBaseCompPvt->pCmdPipe, | ||
473 | &sErrorCmdParams, sizeof(sErrorCmdParams), | ||
474 | OSAL_SUSPEND); | ||
475 | if( tStatus != OSAL_ErrNone ) { | ||
476 | OSAL_ErrorTrace("Write to pipe failed"); | ||
477 | eError = OMX_ErrorUndefined; | ||
478 | break; | ||
479 | } | ||
480 | } | ||
481 | } | ||
482 | |||
483 | if( i == nCmdCount ) { | ||
484 | /*The command to discard was not found even after going through the | ||
485 | pipe*/ | ||
486 | OSAL_ErrorTrace("Command to be discarded not found in pipe"); | ||
487 | eError = OMX_ErrorUndefined; | ||
488 | } | ||
489 | } | ||
490 | tStatus = OSAL_ReleaseMutex(pBaseCompPvt->pCmdPipeMutex); | ||
491 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorUndefined); | ||
492 | |||
493 | EXIT: | ||
494 | if( eError != OMX_ErrorNone ) { | ||
495 | if( pLocalCmdData && bFreeCmdDataIfError ) { | ||
496 | OSAL_Free(pLocalCmdData); | ||
497 | pLocalCmdData = NULL; | ||
498 | } | ||
499 | } | ||
500 | return (eError); | ||
501 | } | ||
502 | |||
503 | /* | ||
504 | * OMX Base Get Parameter | ||
505 | */ | ||
506 | OMX_ERRORTYPE OMXBase_GetParameter(OMX_HANDLETYPE hComponent, | ||
507 | OMX_INDEXTYPE nParamIndex, | ||
508 | OMX_PTR pParamStruct) | ||
509 | { | ||
510 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
511 | OMX_COMPONENTTYPE *pComp = NULL; | ||
512 | OMXBaseComp *pBaseComp = NULL; | ||
513 | OMXBaseComp_Pvt *pBaseCompPvt = NULL; | ||
514 | OMXBase_Port *pPort = NULL; | ||
515 | OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL; | ||
516 | OMX_PRIORITYMGMTTYPE *pPriorityMgmt = NULL; | ||
517 | OMX_PARAM_BUFFERSUPPLIERTYPE *pBufSupplier = NULL; | ||
518 | OMX_U32 nStartPortNumber, nPorts, nPortIndex; | ||
519 | |||
520 | |||
521 | OMX_CHECK((hComponent != NULL) && (pParamStruct != NULL), OMX_ErrorBadParameter); | ||
522 | |||
523 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
524 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
525 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
526 | |||
527 | nPorts = pBaseComp->nNumPorts; | ||
528 | nStartPortNumber = pBaseComp->nMinStartPortIndex; | ||
529 | |||
530 | /*Can't be invoked when the comp is in invalid state*/ | ||
531 | OMX_CHECK(OMX_StateInvalid != pBaseComp->tCurState, OMX_ErrorInvalidState); | ||
532 | |||
533 | switch( nParamIndex ) { | ||
534 | case OMX_IndexParamAudioInit : | ||
535 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_PORT_PARAM_TYPE, eError); | ||
536 | if( pBaseComp->pAudioPortParams == NULL ) { | ||
537 | OMX_BASE_INIT_STRUCT_PTR((OMX_PORT_PARAM_TYPE *)(pParamStruct), | ||
538 | OMX_PORT_PARAM_TYPE); | ||
539 | ((OMX_PORT_PARAM_TYPE *)pParamStruct)->nPorts = 0; | ||
540 | ((OMX_PORT_PARAM_TYPE *)pParamStruct)->nStartPortNumber = 0; | ||
541 | break; | ||
542 | } | ||
543 | *(OMX_PORT_PARAM_TYPE *)pParamStruct = *(pBaseComp->pAudioPortParams); | ||
544 | break; | ||
545 | |||
546 | case OMX_IndexParamImageInit : | ||
547 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_PORT_PARAM_TYPE, eError); | ||
548 | if( pBaseComp->pImagePortParams == NULL ) { | ||
549 | OMX_BASE_INIT_STRUCT_PTR((OMX_PORT_PARAM_TYPE *)(pParamStruct), | ||
550 | OMX_PORT_PARAM_TYPE); | ||
551 | ((OMX_PORT_PARAM_TYPE *)pParamStruct)->nPorts = 0; | ||
552 | ((OMX_PORT_PARAM_TYPE *)pParamStruct)->nStartPortNumber = 0; | ||
553 | break; | ||
554 | } | ||
555 | *(OMX_PORT_PARAM_TYPE *)pParamStruct = *(pBaseComp->pImagePortParams); | ||
556 | break; | ||
557 | |||
558 | case OMX_IndexParamVideoInit : | ||
559 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_PORT_PARAM_TYPE, eError); | ||
560 | if( pBaseComp->pVideoPortParams == NULL ) { | ||
561 | OMX_BASE_INIT_STRUCT_PTR((OMX_PORT_PARAM_TYPE *)(pParamStruct), | ||
562 | OMX_PORT_PARAM_TYPE); | ||
563 | ((OMX_PORT_PARAM_TYPE *)pParamStruct)->nPorts = 0; | ||
564 | ((OMX_PORT_PARAM_TYPE *)pParamStruct)->nStartPortNumber = 0; | ||
565 | break; | ||
566 | } | ||
567 | *(OMX_PORT_PARAM_TYPE *)pParamStruct = | ||
568 | *(pBaseComp->pVideoPortParams); | ||
569 | break; | ||
570 | |||
571 | case OMX_IndexParamOtherInit : | ||
572 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_PORT_PARAM_TYPE, eError); | ||
573 | if( pBaseComp->pOtherPortParams == NULL ) { | ||
574 | OMX_BASE_INIT_STRUCT_PTR((OMX_PORT_PARAM_TYPE *)(pParamStruct), | ||
575 | OMX_PORT_PARAM_TYPE); | ||
576 | ((OMX_PORT_PARAM_TYPE *)pParamStruct)->nPorts = 0; | ||
577 | ((OMX_PORT_PARAM_TYPE *)pParamStruct)->nStartPortNumber = 0; | ||
578 | break; | ||
579 | } | ||
580 | *(OMX_PORT_PARAM_TYPE *)pParamStruct = *(pBaseComp->pOtherPortParams); | ||
581 | break; | ||
582 | |||
583 | case OMX_IndexParamPortDefinition : | ||
584 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_PARAM_PORTDEFINITIONTYPE, | ||
585 | eError); | ||
586 | pPortDef = (OMX_PARAM_PORTDEFINITIONTYPE *)pParamStruct; | ||
587 | nPortIndex = pPortDef->nPortIndex - nStartPortNumber; | ||
588 | /* check for valid port index */ | ||
589 | OMX_CHECK(nPortIndex < nPorts, OMX_ErrorBadPortIndex); | ||
590 | *pPortDef = pBaseComp->pPorts[nPortIndex]->sPortDef; | ||
591 | |||
592 | break; | ||
593 | |||
594 | case OMX_IndexParamCompBufferSupplier : | ||
595 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_PARAM_BUFFERSUPPLIERTYPE, eError); | ||
596 | pBufSupplier = (OMX_PARAM_BUFFERSUPPLIERTYPE *)pParamStruct; | ||
597 | nPortIndex = pBufSupplier->nPortIndex - nStartPortNumber; | ||
598 | /* check for valid port index */ | ||
599 | OMX_CHECK(nPortIndex < nPorts, OMX_ErrorBadPortIndex); | ||
600 | pPort = pBaseComp->pPorts[nPortIndex]; | ||
601 | pBufSupplier->eBufferSupplier = 0x0; | ||
602 | break; | ||
603 | |||
604 | case OMX_IndexParamPriorityMgmt : | ||
605 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_PRIORITYMGMTTYPE, eError); | ||
606 | pPriorityMgmt = (OMX_PRIORITYMGMTTYPE *)pParamStruct; | ||
607 | break; | ||
608 | |||
609 | default : | ||
610 | OSAL_ErrorTrace("Unknown Index received "); | ||
611 | eError = OMX_ErrorUnsupportedIndex; | ||
612 | break; | ||
613 | } | ||
614 | |||
615 | EXIT: | ||
616 | return (eError); | ||
617 | } | ||
618 | |||
619 | /* | ||
620 | * OMX Base SetParameter | ||
621 | */ | ||
622 | OMX_ERRORTYPE OMXBase_SetParameter(OMX_HANDLETYPE hComponent, | ||
623 | OMX_INDEXTYPE nIndex, | ||
624 | OMX_PTR pParamStruct) | ||
625 | { | ||
626 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
627 | OMX_COMPONENTTYPE *pComp = NULL; | ||
628 | OMXBaseComp *pBaseComp = NULL; | ||
629 | OMXBaseComp_Pvt *pBaseCompPvt = NULL; | ||
630 | OMXBase_Port *pPort = NULL; | ||
631 | OMX_PRIORITYMGMTTYPE *pPriorityMgmt = NULL; | ||
632 | OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL; | ||
633 | OMX_PARAM_PORTDEFINITIONTYPE *pLocalPortDef; | ||
634 | // OMX_PARAM_BUFFERSUPPLIERTYPE *pBufSupplier = NULL; | ||
635 | OMX_U32 nStartPortNumber, nPorts, nPortIndex; | ||
636 | // OMX_PARAM_BUFFERSUPPLIERTYPE sTunBufSupplier; | ||
637 | OMX_TI_PARAMUSENATIVEBUFFER *pParamNativeBuffer = NULL; | ||
638 | |||
639 | OMX_CHECK((hComponent != NULL) && | ||
640 | (pParamStruct != NULL), OMX_ErrorBadParameter); | ||
641 | |||
642 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
643 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
644 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
645 | nPorts = pBaseComp->nNumPorts; | ||
646 | nStartPortNumber = pBaseComp->nMinStartPortIndex; | ||
647 | |||
648 | /*Can't be invoked when the comp is in invalid state*/ | ||
649 | OMX_CHECK(OMX_StateInvalid != pBaseComp->tCurState, | ||
650 | OMX_ErrorInvalidState); | ||
651 | /* This method is not allowed when the component is not in the loaded | ||
652 | * state or the the port is not disabled */ | ||
653 | if((OMX_IndexParamPriorityMgmt == nIndex | ||
654 | || OMX_IndexParamAudioInit == nIndex | ||
655 | || OMX_IndexParamVideoInit == nIndex | ||
656 | || OMX_IndexParamImageInit == nIndex | ||
657 | || OMX_IndexParamOtherInit == nIndex) | ||
658 | && (pBaseComp->tCurState != OMX_StateLoaded)) { | ||
659 | eError = OMX_ErrorIncorrectStateOperation; | ||
660 | goto EXIT; | ||
661 | } | ||
662 | |||
663 | switch( (int) nIndex ) { | ||
664 | case OMX_IndexParamPriorityMgmt : | ||
665 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_PRIORITYMGMTTYPE, eError); | ||
666 | pPriorityMgmt = (OMX_PRIORITYMGMTTYPE *)pParamStruct; | ||
667 | break; | ||
668 | |||
669 | case OMX_IndexParamPortDefinition : | ||
670 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_PARAM_PORTDEFINITIONTYPE, | ||
671 | eError); | ||
672 | pPortDef = (OMX_PARAM_PORTDEFINITIONTYPE *)pParamStruct; | ||
673 | |||
674 | nPortIndex = pPortDef->nPortIndex - nStartPortNumber; | ||
675 | /* check for valid port index */ | ||
676 | OMX_CHECK(nPortIndex < nPorts, OMX_ErrorBadPortIndex); | ||
677 | pPort = pBaseComp->pPorts[nPortIndex]; | ||
678 | /* successfully only when the comp is in loaded or disabled port */ | ||
679 | OMX_CHECK((pBaseComp->tCurState == OMX_StateLoaded) || | ||
680 | (pPort->sPortDef.bEnabled == OMX_FALSE), | ||
681 | OMX_ErrorIncorrectStateOperation); | ||
682 | |||
683 | pLocalPortDef = (OMX_PARAM_PORTDEFINITIONTYPE *)pParamStruct; | ||
684 | /*Copying only the modifiabke fields. Rest are all read only fields*/ | ||
685 | pBaseComp->pPorts[nPortIndex]->sPortDef.nBufferCountActual = | ||
686 | pLocalPortDef->nBufferCountActual; | ||
687 | pBaseComp->pPorts[nPortIndex]->sPortDef.format = pLocalPortDef->format; | ||
688 | break; | ||
689 | |||
690 | /*These are compulsory parameters hence being supported by base*/ | ||
691 | case OMX_IndexParamAudioInit : | ||
692 | case OMX_IndexParamVideoInit : | ||
693 | case OMX_IndexParamImageInit : | ||
694 | case OMX_IndexParamOtherInit : | ||
695 | /*All fields of OMX_PORT_PARAM_TYPE are read only so SetParam will just | ||
696 | return and not overwrite anything*/ | ||
697 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_PORT_PARAM_TYPE, eError); | ||
698 | break; | ||
699 | |||
700 | case OMX_TI_IndexUseNativeBuffers: | ||
701 | pParamNativeBuffer = (OMX_TI_PARAMUSENATIVEBUFFER* )pParamStruct; | ||
702 | if(pParamNativeBuffer->bEnable == OMX_TRUE) { | ||
703 | pBaseComp->pPorts[pParamNativeBuffer->nPortIndex - nStartPortNumber]->sProps.eBufMemoryType = MEM_GRALLOC; | ||
704 | } else { | ||
705 | pBaseComp->pPorts[pParamNativeBuffer->nPortIndex - nStartPortNumber]->sProps.eBufMemoryType = MEM_CARVEOUT; | ||
706 | } | ||
707 | break; | ||
708 | |||
709 | default : | ||
710 | eError = OMX_ErrorUnsupportedIndex; | ||
711 | break; | ||
712 | } | ||
713 | |||
714 | EXIT: | ||
715 | return (eError); | ||
716 | } | ||
717 | |||
718 | /* | ||
719 | * OMX Base AllocatBuffer | ||
720 | */ | ||
721 | OMX_ERRORTYPE OMXBase_AllocateBuffer(OMX_HANDLETYPE hComponent, | ||
722 | OMX_BUFFERHEADERTYPE * *ppBufferHdr, | ||
723 | OMX_U32 nPortIndex, | ||
724 | OMX_PTR pAppPrivate, | ||
725 | OMX_U32 nSizeBytes) | ||
726 | { | ||
727 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
728 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
729 | OMX_COMPONENTTYPE *pComp = NULL; | ||
730 | OMXBaseComp *pBaseComp = NULL; | ||
731 | OMXBaseComp_Pvt *pBaseCompPvt = NULL; | ||
732 | OMXBase_Port *pPort = NULL; | ||
733 | OMX_DIO_CreateParams sDIOCreateParams; | ||
734 | OMX_DIO_OpenParams sDIOOpenParams; | ||
735 | OMX_U32 nStartPortNumber = 0, nPorts = 0; | ||
736 | |||
737 | OMX_CHECK((hComponent != NULL) && (nSizeBytes > 0), OMX_ErrorBadParameter); | ||
738 | |||
739 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
740 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
741 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
742 | |||
743 | OSAL_ObtainMutex(pBaseCompPvt->pPortDisableMutex, OSAL_SUSPEND); | ||
744 | |||
745 | nStartPortNumber = pBaseComp->nMinStartPortIndex; | ||
746 | nPorts = pBaseComp->nNumPorts; | ||
747 | OMX_CHECK(nPortIndex >= nStartPortNumber && nPortIndex < nPorts, | ||
748 | OMX_ErrorBadPortIndex); | ||
749 | /*Can't be invoked when the comp is in invalid state*/ | ||
750 | OMX_CHECK(OMX_StateInvalid != pBaseComp->tCurState, | ||
751 | OMX_ErrorInvalidState); | ||
752 | |||
753 | pPort = pBaseComp->pPorts[nPortIndex - nStartPortNumber]; | ||
754 | |||
755 | /*Buffer size should be >= the minimum buffer size specified in | ||
756 | port definition*/ | ||
757 | OMX_CHECK(nSizeBytes >= pPort->sPortDef.nBufferSize, | ||
758 | OMX_ErrorBadParameter); | ||
759 | if((pBaseComp->tCurState == OMX_StateLoaded || | ||
760 | pBaseComp->tCurState == OMX_StateWaitForResources) && | ||
761 | (pBaseComp->tNewState == OMX_StateIdle) && | ||
762 | (pPort->sPortDef.bEnabled)) { | ||
763 | /*Allowed during loaded/waitforresources --> idle transition if port is | ||
764 | enabled*/ | ||
765 | } else if((pPort->bIsInTransition) && | ||
766 | (pBaseComp->tCurState != OMX_StateLoaded) && | ||
767 | (pBaseComp->tCurState != OMX_StateWaitForResources)) { | ||
768 | /*Allowed when port is transitioning to enabled if current state is not | ||
769 | loaded/waitforresources*/ | ||
770 | } else { | ||
771 | eError = OMX_ErrorIncorrectStateOperation; | ||
772 | goto EXIT; | ||
773 | } | ||
774 | /*Port should not be already populated*/ | ||
775 | OMX_CHECK(pPort->sPortDef.bPopulated == OMX_FALSE, | ||
776 | OMX_ErrorBadParameter); | ||
777 | if( pPort->nBufferCnt == 0 ) { | ||
778 | /* Initialize DIO and open as a supplier */ | ||
779 | pPort->bIsBufferAllocator = OMX_TRUE; | ||
780 | sDIOCreateParams.hComponent = hComponent; | ||
781 | sDIOCreateParams.nPortIndex = pPort->sPortDef.nPortIndex; | ||
782 | sDIOCreateParams.pAppCallbacks = &(pBaseCompPvt->sAppCallbacks); | ||
783 | if( pPort->sPortDef.eDir == OMX_DirOutput ) { | ||
784 | sDIOOpenParams.nMode = OMX_DIO_WRITER; | ||
785 | } else { | ||
786 | sDIOOpenParams.nMode = OMX_DIO_READER; | ||
787 | } | ||
788 | |||
789 | sDIOOpenParams.nBufSize = nSizeBytes; | ||
790 | eError = OMXBase_DIO_Init(hComponent, nPortIndex, "OMX.DIO.NONTUNNEL", | ||
791 | &sDIOCreateParams); | ||
792 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
793 | eError = OMXBase_DIO_Open(hComponent, nPortIndex, &sDIOOpenParams); | ||
794 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
795 | } | ||
796 | /*update buffer header from buffer list */ | ||
797 | *ppBufferHdr = pPort->pBufferlist[pPort->nBufferCnt]; | ||
798 | if( pPort->sPortDef.eDir == OMX_DirInput ) { | ||
799 | (*ppBufferHdr)->nInputPortIndex = pPort->sPortDef.nPortIndex; | ||
800 | (*ppBufferHdr)->nOutputPortIndex = OMX_NOPORT; | ||
801 | } else if( pPort->sPortDef.eDir == OMX_DirOutput ) { | ||
802 | (*ppBufferHdr)->nOutputPortIndex = pPort->sPortDef.nPortIndex; | ||
803 | (*ppBufferHdr)->nInputPortIndex = OMX_NOPORT; | ||
804 | } | ||
805 | (*ppBufferHdr)->pAppPrivate = pAppPrivate; | ||
806 | (*ppBufferHdr)->nAllocLen = nSizeBytes; | ||
807 | |||
808 | pPort->nBufferCnt++; | ||
809 | if( pPort->sPortDef.nBufferCountActual == pPort->nBufferCnt ) { | ||
810 | pPort->sPortDef.bPopulated = OMX_TRUE; | ||
811 | tStatus = OSAL_SetEvent(pPort->pBufAllocFreeEvent, BUF_ALLOC_EVENT, | ||
812 | OSAL_EVENT_OR); | ||
813 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorInsufficientResources); | ||
814 | } | ||
815 | |||
816 | EXIT: | ||
817 | if ((hComponent != NULL) && (nSizeBytes > 0)) { | ||
818 | OSAL_ReleaseMutex(pBaseCompPvt->pPortDisableMutex); | ||
819 | } | ||
820 | return (eError); | ||
821 | } | ||
822 | |||
823 | /* | ||
824 | * OMX Base UseBuffer | ||
825 | */ | ||
826 | OMX_ERRORTYPE OMXBase_UseBuffer(OMX_HANDLETYPE hComponent, | ||
827 | OMX_BUFFERHEADERTYPE * *ppBufferHdr, | ||
828 | OMX_U32 nPortIndex, | ||
829 | OMX_PTR pAppPrivate, | ||
830 | OMX_U32 nSizeBytes, | ||
831 | OMX_U8 *pBuffer) | ||
832 | { | ||
833 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
834 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
835 | OMX_COMPONENTTYPE *pComp = NULL; | ||
836 | OMXBaseComp *pBaseComp = NULL; | ||
837 | OMXBaseComp_Pvt *pBaseCompPvt = NULL; | ||
838 | OMXBase_Port *pPort = NULL; | ||
839 | OMX_DIO_CreateParams sDIOCreateParams; | ||
840 | OMX_DIO_OpenParams sDIOOpenParams; | ||
841 | OMX_U32 nStartPortNumber = 0, nPorts = 0; | ||
842 | |||
843 | OMX_CHECK((hComponent != NULL), OMX_ErrorBadParameter); | ||
844 | |||
845 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
846 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
847 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
848 | |||
849 | OSAL_ObtainMutex(pBaseCompPvt->pPortDisableMutex, OSAL_SUSPEND); | ||
850 | |||
851 | nStartPortNumber = pBaseComp->nMinStartPortIndex; | ||
852 | nPorts = pBaseComp->nNumPorts; | ||
853 | OMX_CHECK(nPortIndex >= nStartPortNumber && nPortIndex < nPorts, | ||
854 | OMX_ErrorBadPortIndex); | ||
855 | /*Can't be invoked when the comp is in invalid state*/ | ||
856 | OMX_CHECK(OMX_StateInvalid != pBaseComp->tCurState, | ||
857 | OMX_ErrorInvalidState); | ||
858 | |||
859 | pPort = pBaseComp->pPorts[nPortIndex - nStartPortNumber]; | ||
860 | |||
861 | if((pBaseComp->tCurState == OMX_StateLoaded || | ||
862 | pBaseComp->tCurState == OMX_StateWaitForResources) && | ||
863 | (pBaseComp->tNewState == OMX_StateIdle) && | ||
864 | (pPort->sPortDef.bEnabled)) { | ||
865 | /*Allowed during loaded/waitforresources --> idle transition if port is | ||
866 | enabled*/ | ||
867 | } else if((pPort->bIsInTransition) && | ||
868 | (pBaseComp->tCurState != OMX_StateLoaded) && | ||
869 | (pBaseComp->tCurState != OMX_StateWaitForResources)) { | ||
870 | /*Allowed when port is transitioning to enabled if current state is not | ||
871 | loaded/waitforresources*/ | ||
872 | } else { | ||
873 | eError = OMX_ErrorIncorrectStateOperation; | ||
874 | goto EXIT; | ||
875 | } | ||
876 | OMX_CHECK(pPort->sPortDef.bPopulated == OMX_FALSE, | ||
877 | OMX_ErrorBadParameter); | ||
878 | |||
879 | if( pPort->nBufferCnt == 0 ) { | ||
880 | /* Initialize DIO if not initialized and open as a non supplier */ | ||
881 | pPort->bIsBufferAllocator = OMX_FALSE; | ||
882 | if( pPort->hDIO == NULL) { | ||
883 | sDIOCreateParams.hComponent = hComponent; | ||
884 | sDIOCreateParams.nPortIndex = pPort->sPortDef.nPortIndex; | ||
885 | sDIOCreateParams.pAppCallbacks = &(pBaseCompPvt->sAppCallbacks); | ||
886 | |||
887 | if( pPort->sPortDef.eDir == OMX_DirOutput ) { | ||
888 | sDIOOpenParams.nMode = OMX_DIO_WRITER; | ||
889 | } else { | ||
890 | sDIOOpenParams.nMode = OMX_DIO_READER; | ||
891 | } | ||
892 | |||
893 | sDIOOpenParams.nBufSize = nSizeBytes; | ||
894 | eError = OMXBase_DIO_Init(hComponent, nPortIndex, | ||
895 | "OMX.DIO.NONTUNNEL", &sDIOCreateParams); | ||
896 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
897 | eError = OMXBase_DIO_Open(hComponent, nPortIndex, &sDIOOpenParams); | ||
898 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
899 | } | ||
900 | } | ||
901 | /*update buffer header from buffer list */ | ||
902 | pPort->pBufferlist[pPort->nBufferCnt]->pBuffer = pBuffer; | ||
903 | *ppBufferHdr = pPort->pBufferlist[pPort->nBufferCnt]; | ||
904 | if( pPort->sPortDef.eDir == OMX_DirInput ) { | ||
905 | (*ppBufferHdr)->nInputPortIndex = pPort->sPortDef.nPortIndex; | ||
906 | (*ppBufferHdr)->nOutputPortIndex = OMX_NOPORT; | ||
907 | } else if( pPort->sPortDef.eDir == OMX_DirOutput ) { | ||
908 | (*ppBufferHdr)->nOutputPortIndex = pPort->sPortDef.nPortIndex; | ||
909 | (*ppBufferHdr)->nInputPortIndex = OMX_NOPORT; | ||
910 | } | ||
911 | (*ppBufferHdr)->pAppPrivate = pAppPrivate; | ||
912 | (*ppBufferHdr)->nAllocLen = nSizeBytes; | ||
913 | |||
914 | if (pBaseComp->fpXlateBuffHandle != NULL) { | ||
915 | eError = pBaseComp->fpXlateBuffHandle(hComponent, (OMX_PTR)(*ppBufferHdr), OMX_TRUE); | ||
916 | } | ||
917 | |||
918 | pPort->nBufferCnt++; | ||
919 | if( pPort->sPortDef.nBufferCountActual == pPort->nBufferCnt ) { | ||
920 | pPort->sPortDef.bPopulated = OMX_TRUE; | ||
921 | tStatus = OSAL_SetEvent(pPort->pBufAllocFreeEvent, BUF_ALLOC_EVENT, | ||
922 | OSAL_EVENT_OR); | ||
923 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorInsufficientResources); | ||
924 | } | ||
925 | EXIT: | ||
926 | if (hComponent != NULL) { | ||
927 | OSAL_ReleaseMutex(pBaseCompPvt->pPortDisableMutex); | ||
928 | } | ||
929 | return (eError); | ||
930 | } | ||
931 | |||
932 | /* | ||
933 | * OMX Base FreeBuffer | ||
934 | */ | ||
935 | OMX_ERRORTYPE OMXBase_FreeBuffer(OMX_HANDLETYPE hComponent, | ||
936 | OMX_U32 nPortIndex, | ||
937 | OMX_BUFFERHEADERTYPE *pBuffHeader) | ||
938 | { | ||
939 | OMX_ERRORTYPE eError = OMX_ErrorNone, eTmpError = OMX_ErrorNone; | ||
940 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
941 | OMX_COMPONENTTYPE *pComp = NULL; | ||
942 | OMXBaseComp *pBaseComp = NULL; | ||
943 | OMXBaseComp_Pvt *pBaseCompPvt = NULL; | ||
944 | OMXBase_Port *pPort = NULL; | ||
945 | OMX_U32 nStartPortNumber = 0, nPorts = 0; | ||
946 | |||
947 | OMX_CHECK((hComponent != NULL) && | ||
948 | (pBuffHeader != NULL), OMX_ErrorBadParameter); | ||
949 | |||
950 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
951 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
952 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
953 | nStartPortNumber = pBaseComp->nMinStartPortIndex; | ||
954 | nPorts = pBaseComp->nNumPorts; | ||
955 | OMX_CHECK(nPortIndex >= nStartPortNumber && nPortIndex < nPorts, | ||
956 | OMX_ErrorBadPortIndex); | ||
957 | |||
958 | pPort = pBaseComp->pPorts[nPortIndex - nStartPortNumber]; | ||
959 | |||
960 | OMX_BASE_CHK_VERSION(pBuffHeader, OMX_BUFFERHEADERTYPE, eError); | ||
961 | /*Free buffer should not be called on a port after all buffers have been | ||
962 | freed*/ | ||
963 | OMX_CHECK(pPort->nBufferCnt != 0, OMX_ErrorBadParameter); | ||
964 | |||
965 | /* unregister the buffer with decoder for non-allocator port*/ | ||
966 | if (!pPort->bIsBufferAllocator && pBaseComp->fpXlateBuffHandle != NULL) { | ||
967 | eError = pBaseComp->fpXlateBuffHandle(hComponent, (OMX_PTR)(pBuffHeader), OMX_FALSE); | ||
968 | } | ||
969 | |||
970 | /* Just decrement the buffer count and unpopulate the port, | ||
971 | * buffer header pool is freed up once all the buffers are received */ | ||
972 | pPort->nBufferCnt--; | ||
973 | pPort->sPortDef.bPopulated = OMX_FALSE; | ||
974 | if( pBaseComp->tCurState == OMX_StateIdle && | ||
975 | pBaseComp->tNewState == OMX_StateLoaded && pPort->sPortDef.bEnabled ) { | ||
976 | /*Allowed on idle --> loaded transition if port is enabled*/ | ||
977 | } else if((pPort->bIsInTransition) && | ||
978 | (pBaseComp->tCurState != OMX_StateLoaded) && | ||
979 | (pBaseComp->tCurState != OMX_StateWaitForResources)) { | ||
980 | /*Allowed during port disable if current state is not | ||
981 | loaded/waitforresources*/ | ||
982 | } else { | ||
983 | eError = pBaseCompPvt->sAppCallbacks.EventHandler(hComponent, | ||
984 | pComp->pApplicationPrivate, | ||
985 | OMX_EventError, (OMX_U32)OMX_ErrorPortUnpopulated, | ||
986 | nPortIndex, " PortUnpopulated "); | ||
987 | /*Ideally callback should never return error*/ | ||
988 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
989 | } | ||
990 | if( pPort->nBufferCnt == 0 ) { | ||
991 | tStatus = OSAL_SetEvent(pPort->pBufAllocFreeEvent, BUF_FREE_EVENT, | ||
992 | OSAL_EVENT_OR); | ||
993 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorUndefined); | ||
994 | } | ||
995 | |||
996 | EXIT: | ||
997 | if((eTmpError != OMX_ErrorNone) && (eError == OMX_ErrorNone)) { | ||
998 | /*An error occured earlier but we still continued cleanup to avoid leaks. | ||
999 | Setting the return value to the error code now*/ | ||
1000 | eError = eTmpError; | ||
1001 | } | ||
1002 | return (eError); | ||
1003 | } | ||
1004 | |||
1005 | /* | ||
1006 | * Empty This Buffer | ||
1007 | */ | ||
1008 | OMX_ERRORTYPE OMXBase_EmptyThisBuffer(OMX_HANDLETYPE hComponent, | ||
1009 | OMX_BUFFERHEADERTYPE *pBuffer) | ||
1010 | { | ||
1011 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
1012 | OMX_COMPONENTTYPE *pComp = NULL; | ||
1013 | OMXBaseComp *pBaseComp = NULL; | ||
1014 | OMXBaseComp_Pvt *pBaseCompPvt = NULL; | ||
1015 | OMXBase_Port *pPort = NULL; | ||
1016 | OMX_U32 nPorts, nStartPortNumber; | ||
1017 | |||
1018 | OMX_CHECK((hComponent != NULL) && | ||
1019 | (pBuffer != NULL), OMX_ErrorBadParameter); | ||
1020 | |||
1021 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
1022 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
1023 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
1024 | nPorts = pBaseComp->nNumPorts; | ||
1025 | nStartPortNumber = pBaseComp->nMinStartPortIndex; | ||
1026 | |||
1027 | /*Can't be invoked when the comp is in invalid state*/ | ||
1028 | OMX_CHECK(OMX_StateInvalid != pBaseComp->tCurState, OMX_ErrorInvalidState); | ||
1029 | /* check for valid port index */ | ||
1030 | OMX_CHECK(pBuffer->nInputPortIndex < (nPorts + nStartPortNumber), OMX_ErrorBadPortIndex); | ||
1031 | |||
1032 | pPort = pBaseComp->pPorts[pBuffer->nInputPortIndex - nStartPortNumber]; | ||
1033 | if( pPort->sPortDef.eDir != OMX_DirInput ) { | ||
1034 | eError = OMX_ErrorIncorrectStateOperation; | ||
1035 | goto EXIT; | ||
1036 | } | ||
1037 | |||
1038 | /* This method is allowed only when the comp is in or a transition | ||
1039 | * to executing or pause state */ | ||
1040 | OMX_CHECK((pBaseComp->tCurState == OMX_StateIdle && | ||
1041 | pBaseComp->tNewState == OMX_StateExecuting) || | ||
1042 | (pBaseComp->tCurState == OMX_StateExecuting || | ||
1043 | pBaseComp->tCurState == OMX_StatePause), | ||
1044 | OMX_ErrorIncorrectStateOperation); | ||
1045 | |||
1046 | /*Following two checks are based on the 1.1.2 AppNote*/ | ||
1047 | /*Supplier ports can accept buffers even if current state is disabled | ||
1048 | if they are transitioning from port enable to disable*/ | ||
1049 | if( pPort->sPortDef.bEnabled != OMX_TRUE ) { | ||
1050 | if((!pPort->bIsInTransition) || (!pPort->bIsBufferAllocator)) { | ||
1051 | eError = OMX_ErrorIncorrectStateOperation; | ||
1052 | goto EXIT; | ||
1053 | } | ||
1054 | } | ||
1055 | /*Non-supplier ports can't accept buffers when transitioning to Idle | ||
1056 | or when port is being transitioned to disabled*/ | ||
1057 | if( !pPort->bIsBufferAllocator) { | ||
1058 | if((pBaseComp->tNewState == OMX_StateIdle) || (pPort->bIsInTransition)) { | ||
1059 | eError = OMX_ErrorIncorrectStateOperation; | ||
1060 | goto EXIT; | ||
1061 | } | ||
1062 | } | ||
1063 | eError = OMXBase_DIO_Queue(hComponent, pBuffer->nInputPortIndex, pBuffer); | ||
1064 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1065 | ((OMXBase_BufHdrPvtData *)(pBuffer->pPlatformPrivate))->bufSt = OWNED_BY_US; | ||
1066 | |||
1067 | /*If another buffer comes after eos then reset the variable that causes | ||
1068 | watermark to become meaningless on this port*/ | ||
1069 | if( pPort->bEosRecd == OMX_TRUE ) { | ||
1070 | pPort->bEosRecd = OMX_FALSE; | ||
1071 | } | ||
1072 | /*If EOS buffer or CodecConfig buffer then force notify to derived component*/ | ||
1073 | if( pBuffer->nFlags & OMX_BUFFERFLAG_EOS ) { | ||
1074 | pPort->bEosRecd = OMX_TRUE; | ||
1075 | } | ||
1076 | eError = pBaseCompPvt->fpInvokeProcessFunction(hComponent, DATAEVENT); | ||
1077 | |||
1078 | EXIT: | ||
1079 | return (eError); | ||
1080 | } | ||
1081 | |||
1082 | /* | ||
1083 | * OMX Base FillThisBuffer | ||
1084 | */ | ||
1085 | OMX_ERRORTYPE OMXBase_FillThisBuffer(OMX_HANDLETYPE hComponent, | ||
1086 | OMX_BUFFERHEADERTYPE *pBuffer) | ||
1087 | { | ||
1088 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
1089 | OMX_COMPONENTTYPE *pComp = NULL; | ||
1090 | OMXBaseComp *pBaseComp = NULL; | ||
1091 | OMXBaseComp_Pvt *pBaseCompPvt = NULL; | ||
1092 | OMXBase_Port *pPort = NULL; | ||
1093 | OMX_U32 nPorts, nStartPortNumber; | ||
1094 | |||
1095 | OMX_CHECK((hComponent != NULL) && (pBuffer != NULL), OMX_ErrorBadParameter); | ||
1096 | OMX_CHECK(pBuffer->pBuffer != NULL, OMX_ErrorBadParameter); | ||
1097 | |||
1098 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
1099 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
1100 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
1101 | nPorts = pBaseComp->nNumPorts; | ||
1102 | nStartPortNumber = pBaseComp->nMinStartPortIndex; | ||
1103 | |||
1104 | /*Can't be invoked when the comp is in invalid state*/ | ||
1105 | OMX_CHECK(OMX_StateInvalid != pBaseComp->tCurState, | ||
1106 | OMX_ErrorInvalidState); | ||
1107 | |||
1108 | /* check for valid port index */ | ||
1109 | OMX_CHECK(pBuffer->nOutputPortIndex < (nPorts + | ||
1110 | nStartPortNumber), OMX_ErrorBadPortIndex); | ||
1111 | |||
1112 | pPort = pBaseComp->pPorts[pBuffer->nOutputPortIndex - nStartPortNumber]; | ||
1113 | if( pPort->sPortDef.eDir != OMX_DirOutput ) { | ||
1114 | eError = OMX_ErrorIncorrectStateOperation; | ||
1115 | goto EXIT; | ||
1116 | } | ||
1117 | |||
1118 | /* This method is allowed only when the comp is in or a transition | ||
1119 | * to executing or pause state */ | ||
1120 | OMX_CHECK((pBaseComp->tCurState == OMX_StateIdle && | ||
1121 | pBaseComp->tNewState == OMX_StateExecuting) || | ||
1122 | (pBaseComp->tCurState == OMX_StateExecuting || | ||
1123 | pBaseComp->tCurState == OMX_StatePause), | ||
1124 | OMX_ErrorIncorrectStateOperation); | ||
1125 | /*Following two checks are based on the 1.1.2 AppNote*/ | ||
1126 | /*Supplier ports can accept buffers even if current state is disabled | ||
1127 | if they are transitioning from port enable to disable*/ | ||
1128 | if( pPort->sPortDef.bEnabled != OMX_TRUE ) { | ||
1129 | if((!pPort->bIsInTransition) || (!pPort->bIsBufferAllocator)) { | ||
1130 | eError = OMX_ErrorIncorrectStateOperation; | ||
1131 | goto EXIT; | ||
1132 | } | ||
1133 | } | ||
1134 | /*Non-supplier ports can't accept buffers when transitioning to Idle | ||
1135 | or when port is being transitioned to disabled*/ | ||
1136 | if( !pPort->bIsBufferAllocator) { | ||
1137 | if((pBaseComp->tNewState == OMX_StateIdle) || | ||
1138 | (pPort->bIsInTransition)) { | ||
1139 | eError = OMX_ErrorIncorrectStateOperation; | ||
1140 | goto EXIT; | ||
1141 | } | ||
1142 | } | ||
1143 | eError = OMXBase_DIO_Queue(hComponent, pBuffer->nOutputPortIndex, pBuffer); | ||
1144 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1145 | ((OMXBase_BufHdrPvtData *)(pBuffer->pPlatformPrivate))->bufSt = OWNED_BY_US; | ||
1146 | eError = pBaseCompPvt->fpInvokeProcessFunction(hComponent, DATAEVENT); | ||
1147 | |||
1148 | EXIT: | ||
1149 | return (eError); | ||
1150 | } | ||
1151 | |||
1152 | /* | ||
1153 | * OMX Base SetConfig | ||
1154 | */ | ||
1155 | OMX_ERRORTYPE OMXBase_SetConfig(OMX_HANDLETYPE hComponent, | ||
1156 | OMX_INDEXTYPE nIndex, | ||
1157 | OMX_PTR pComponentConfigStructure) | ||
1158 | { | ||
1159 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
1160 | // OSAL_ERROR tStatus = OSAL_ErrNone; | ||
1161 | OMX_COMPONENTTYPE *pComp = NULL; | ||
1162 | OMXBaseComp *pBaseComp = NULL; | ||
1163 | OMXBaseComp_Pvt *pBaseCompPvt = NULL; | ||
1164 | // OMXBase_Port *pPort = NULL; | ||
1165 | OMX_U32 nStartPortNumber, nPorts; | ||
1166 | // OMX_U32 nPortIndex; | ||
1167 | |||
1168 | OMX_CHECK((hComponent != NULL) && | ||
1169 | (pComponentConfigStructure != NULL), OMX_ErrorBadParameter); | ||
1170 | |||
1171 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
1172 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
1173 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
1174 | nStartPortNumber = pBaseComp->nMinStartPortIndex; | ||
1175 | nPorts = pBaseComp->nNumPorts; | ||
1176 | |||
1177 | /*Can't be invoked when the comp is in invalid state*/ | ||
1178 | OMX_CHECK(OMX_StateInvalid != pBaseComp->tCurState, | ||
1179 | OMX_ErrorInvalidState); | ||
1180 | |||
1181 | switch( nIndex ) { | ||
1182 | default : | ||
1183 | eError = OMX_ErrorUnsupportedIndex; | ||
1184 | break; | ||
1185 | } | ||
1186 | |||
1187 | EXIT: | ||
1188 | return (eError); | ||
1189 | } | ||
1190 | |||
1191 | /* | ||
1192 | * OMX Base GetConfig | ||
1193 | */ | ||
1194 | OMX_ERRORTYPE OMXBase_GetConfig(OMX_HANDLETYPE hComponent, | ||
1195 | OMX_INDEXTYPE nIndex, | ||
1196 | OMX_PTR pComponentConfigStructure) | ||
1197 | { | ||
1198 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
1199 | OMX_COMPONENTTYPE *pComp = NULL; | ||
1200 | OMXBaseComp *pBaseComp = NULL; | ||
1201 | OMXBaseComp_Pvt *pBaseCompPvt = NULL; | ||
1202 | // OMXBase_Port *pPort = NULL; | ||
1203 | OMX_U32 nStartPortNumber, nPorts; | ||
1204 | // OMX_U32 nPortIndex; | ||
1205 | |||
1206 | OMX_CHECK((hComponent != NULL) && | ||
1207 | (pComponentConfigStructure != NULL), OMX_ErrorBadParameter); | ||
1208 | |||
1209 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
1210 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
1211 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
1212 | nStartPortNumber = pBaseComp->nMinStartPortIndex; | ||
1213 | nPorts = pBaseComp->nNumPorts; | ||
1214 | |||
1215 | /*Can't be invoked when the comp is in invalid state*/ | ||
1216 | OMX_CHECK(OMX_StateInvalid != pBaseComp->tCurState, OMX_ErrorInvalidState); | ||
1217 | |||
1218 | switch( nIndex ) { | ||
1219 | default : | ||
1220 | eError = OMX_ErrorUnsupportedIndex; | ||
1221 | break; | ||
1222 | } | ||
1223 | |||
1224 | EXIT: | ||
1225 | return (eError); | ||
1226 | } | ||
1227 | |||
1228 | /* | ||
1229 | * OMX Base UseEGLImage | ||
1230 | */ | ||
1231 | OMX_ERRORTYPE OMXBase_UseEGLImage(OMX_HANDLETYPE hComponent, | ||
1232 | OMX_BUFFERHEADERTYPE * *ppBufferHdr, | ||
1233 | OMX_U32 nPortIndex, | ||
1234 | OMX_PTR pAppPrivate, | ||
1235 | void *eglImage) | ||
1236 | { | ||
1237 | (void)hComponent; | ||
1238 | (void)ppBufferHdr; | ||
1239 | (void)nPortIndex; | ||
1240 | (void)pAppPrivate; | ||
1241 | (void)eglImage; | ||
1242 | |||
1243 | return (OMX_ErrorNotImplemented); | ||
1244 | } | ||
1245 | |||
1246 | /* | ||
1247 | * OMX Base GetExtentionIndex | ||
1248 | */ | ||
1249 | OMX_ERRORTYPE OMXBase_GetExtensionIndex(OMX_HANDLETYPE hComponent, | ||
1250 | OMX_STRING cParameterName, | ||
1251 | OMX_INDEXTYPE *pIndexType) | ||
1252 | { | ||
1253 | (void)hComponent; | ||
1254 | (void)cParameterName; | ||
1255 | (void)pIndexType; | ||
1256 | |||
1257 | return (OMX_ErrorNotImplemented); | ||
1258 | } | ||
1259 | |||
1260 | /* | ||
1261 | * OMX Base ComponentRoleEnum | ||
1262 | */ | ||
1263 | OMX_ERRORTYPE OMXBase_ComponentRoleEnum(OMX_HANDLETYPE hComponent, | ||
1264 | OMX_U8 *cRole, | ||
1265 | OMX_U32 nIndex) | ||
1266 | { | ||
1267 | (void)hComponent; | ||
1268 | (void)cRole; | ||
1269 | (void)nIndex; | ||
1270 | |||
1271 | return (OMX_ErrorNotImplemented); | ||
1272 | } | ||
1273 | |||
diff --git a/libstagefrighthw/omx/base/OMX_Base.h b/libstagefrighthw/omx/base/OMX_Base.h new file mode 100644 index 0000000..3c7cc3e --- /dev/null +++ b/libstagefrighthw/omx/base/OMX_Base.h | |||
@@ -0,0 +1,221 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 _D_OMX_BASE_H_ | ||
18 | #define _D_OMX_BASE_H_ | ||
19 | |||
20 | #ifdef __cplusplus | ||
21 | extern "C" { | ||
22 | #endif | ||
23 | |||
24 | #include <stdio.h> | ||
25 | #include <string.h> | ||
26 | #include <stdlib.h> | ||
27 | |||
28 | #include <OMX_Core.h> | ||
29 | #include <OMX_Component.h> | ||
30 | #include <OMX_BaseInternal.h> | ||
31 | #include <OMX_BaseUtils.h> | ||
32 | |||
33 | #include <osal_error.h> | ||
34 | #include <osal_mutex.h> | ||
35 | #include <osal_memory.h> | ||
36 | #include <osal_pipes.h> | ||
37 | #include <osal_events.h> | ||
38 | #include <osal_task.h> | ||
39 | |||
40 | #include <memplugin.h> | ||
41 | |||
42 | #define OMX_NOPORT 0xFFFFFFFE | ||
43 | #define OMX_BASE_INPUT_PORT 0 | ||
44 | #define OMX_BASE_OUTPUT_PORT 1 | ||
45 | #define OMX_BASE_NUM_OF_PORTS 2 | ||
46 | #define OMX_BASE_DEFAULT_START_PORT_NUM 0 | ||
47 | #define DEFAULT_COMPOENENT 0 | ||
48 | #define MAX_PLANES_PER_BUFFER 3 | ||
49 | |||
50 | |||
51 | /* | ||
52 | * buffer life cycle | ||
53 | */ | ||
54 | typedef enum OMXBase_BufferStatus{ | ||
55 | OWNED_BY_US, | ||
56 | OWNED_BY_CLIENT, | ||
57 | OWNED_BY_CODEC | ||
58 | }OMXBase_BufStatus; | ||
59 | |||
60 | /** Platform private buffer header | ||
61 | */ | ||
62 | typedef struct OMXBase_BufHdrPrivateData { | ||
63 | MemHeader sMemHdr[MAX_PLANES_PER_BUFFER]; | ||
64 | OMXBase_BufStatus bufSt; | ||
65 | OMX_BOOL bIsLocked; | ||
66 | }OMXBase_BufHdrPvtData; | ||
67 | |||
68 | typedef struct OMXBase_CodecConfigBuffer { | ||
69 | MemHeader *sBuffer; | ||
70 | } OMXBase_CodecConfigBuf; | ||
71 | |||
72 | /** Port properties. | ||
73 | */ | ||
74 | typedef struct OMXBase_PortProperties { | ||
75 | OMX_U32 nWatermark; | ||
76 | BufAccessMode eDataAccessMode; | ||
77 | MemRegion eBufMemoryType; | ||
78 | OMX_U32 nNumComponentBuffers; | ||
79 | OMX_U32 nTimeoutForDequeue; | ||
80 | }OMXBase_PortProps; | ||
81 | |||
82 | /** Base port definition | ||
83 | */ | ||
84 | typedef struct OMXBase_Port{ | ||
85 | OMX_PARAM_PORTDEFINITIONTYPE sPortDef; | ||
86 | OMX_BUFFERHEADERTYPE **pBufferlist; | ||
87 | OMXBase_PortProps sProps; | ||
88 | OMX_BOOL bIsBufferAllocator; | ||
89 | OMX_BOOL bIsInTransition; | ||
90 | OMX_BOOL bIsFlushingBuffers; | ||
91 | OMX_BOOL bEosRecd; | ||
92 | OMX_U32 nBufferCnt; | ||
93 | OMX_PTR pBufAllocFreeEvent; | ||
94 | OMX_PTR pDioOpenCloseSem; | ||
95 | OMX_PTR hDIO; | ||
96 | OMX_U32 nCachedBufferCnt; | ||
97 | }OMXBase_Port; | ||
98 | |||
99 | /* OMX base component structure | ||
100 | */ | ||
101 | typedef struct OMXBaseComp | ||
102 | { | ||
103 | OMX_STRING cComponentName; | ||
104 | OMX_VERSIONTYPE nComponentVersion; | ||
105 | OMX_PORT_PARAM_TYPE *pAudioPortParams; | ||
106 | OMX_PORT_PARAM_TYPE *pVideoPortParams; | ||
107 | OMX_PORT_PARAM_TYPE *pImagePortParams; | ||
108 | OMX_PORT_PARAM_TYPE *pOtherPortParams; | ||
109 | OMX_U32 nNumPorts; | ||
110 | OMX_U32 nMinStartPortIndex; | ||
111 | OMXBase_Port **pPorts; | ||
112 | OMX_BOOL bNotifyForAnyPort; | ||
113 | OMXBaseComp_Pvt *pPvtData; | ||
114 | OMX_STATETYPE tCurState; | ||
115 | OMX_STATETYPE tNewState; | ||
116 | OMX_PTR pMutex; | ||
117 | |||
118 | OMX_ERRORTYPE (*fpCommandNotify)(OMX_HANDLETYPE hComponent, OMX_COMMANDTYPE Cmd, | ||
119 | OMX_U32 nParam, OMX_PTR pCmdData); | ||
120 | |||
121 | OMX_ERRORTYPE (*fpDataNotify)(OMX_HANDLETYPE hComponent); | ||
122 | |||
123 | |||
124 | OMX_ERRORTYPE (*fpReturnEventNotify)(OMX_HANDLETYPE hComponent, OMX_EVENTTYPE eEvent, | ||
125 | OMX_U32 nEventData1, OMX_U32 nEventData2, OMX_PTR pEventData); | ||
126 | |||
127 | OMX_ERRORTYPE (*fpXlateBuffHandle)(OMX_HANDLETYPE hComponent, OMX_PTR pBufferHdr, OMX_BOOL bRegister); | ||
128 | |||
129 | }OMXBaseComp; | ||
130 | |||
131 | |||
132 | OMX_ERRORTYPE OMXBase_ComponentInit(OMX_IN OMX_HANDLETYPE hComponent); | ||
133 | |||
134 | OMX_ERRORTYPE OMXBase_SetCallbacks(OMX_IN OMX_HANDLETYPE hComponent, | ||
135 | OMX_IN OMX_CALLBACKTYPE *pCallbacks, | ||
136 | OMX_IN OMX_PTR pAppData); | ||
137 | |||
138 | OMX_ERRORTYPE OMXBase_GetComponentVersion(OMX_IN OMX_HANDLETYPE hComponent, | ||
139 | OMX_OUT OMX_STRING pComponentName, | ||
140 | OMX_OUT OMX_VERSIONTYPE *pComponentVersion, | ||
141 | OMX_OUT OMX_VERSIONTYPE *pSpecVersion, | ||
142 | OMX_OUT OMX_UUIDTYPE *pComponentUUID); | ||
143 | |||
144 | OMX_ERRORTYPE OMXBase_SendCommand(OMX_IN OMX_HANDLETYPE hComponent, | ||
145 | OMX_IN OMX_COMMANDTYPE Cmd, | ||
146 | OMX_IN OMX_U32 nParam1, | ||
147 | OMX_IN OMX_PTR pCmdData); | ||
148 | |||
149 | OMX_ERRORTYPE OMXBase_GetParameter(OMX_IN OMX_HANDLETYPE hComponent, | ||
150 | OMX_IN OMX_INDEXTYPE nParamIndex, | ||
151 | OMX_INOUT OMX_PTR pParamStruct); | ||
152 | |||
153 | OMX_ERRORTYPE OMXBase_SetParameter(OMX_IN OMX_HANDLETYPE hComponent, | ||
154 | OMX_IN OMX_INDEXTYPE nIndex, | ||
155 | OMX_IN OMX_PTR pParamStruct); | ||
156 | |||
157 | |||
158 | OMX_ERRORTYPE OMXBase_GetConfig(OMX_IN OMX_HANDLETYPE hComponent, | ||
159 | OMX_IN OMX_INDEXTYPE nIndex, | ||
160 | OMX_INOUT OMX_PTR pComponentConfigStructure); | ||
161 | |||
162 | |||
163 | OMX_ERRORTYPE OMXBase_SetConfig(OMX_IN OMX_HANDLETYPE hComponent, | ||
164 | OMX_IN OMX_INDEXTYPE nIndex, | ||
165 | OMX_IN OMX_PTR pComponentConfigStructure); | ||
166 | |||
167 | OMX_ERRORTYPE OMXBase_GetExtensionIndex(OMX_IN OMX_HANDLETYPE hComponent, | ||
168 | OMX_IN OMX_STRING cParameterName, | ||
169 | OMX_OUT OMX_INDEXTYPE *pIndexType); | ||
170 | |||
171 | |||
172 | OMX_ERRORTYPE OMXBase_GetState(OMX_IN OMX_HANDLETYPE hComponent, | ||
173 | OMX_OUT OMX_STATETYPE *pState); | ||
174 | |||
175 | |||
176 | OMX_ERRORTYPE OMXBase_UseBuffer(OMX_IN OMX_HANDLETYPE hComponent, | ||
177 | OMX_INOUT OMX_BUFFERHEADERTYPE * *ppBufferHdr, | ||
178 | OMX_IN OMX_U32 nPortIndex, | ||
179 | OMX_IN OMX_PTR pAppPrivate, | ||
180 | OMX_IN OMX_U32 nSizeBytes, | ||
181 | OMX_IN OMX_U8 *pBuffer); | ||
182 | |||
183 | OMX_ERRORTYPE OMXBase_AllocateBuffer(OMX_IN OMX_HANDLETYPE hComponent, | ||
184 | OMX_INOUT OMX_BUFFERHEADERTYPE * *ppBuffer, | ||
185 | OMX_IN OMX_U32 nPortIndex, | ||
186 | OMX_IN OMX_PTR pAppPrivate, | ||
187 | OMX_IN OMX_U32 nSizeBytes); | ||
188 | |||
189 | |||
190 | OMX_ERRORTYPE OMXBase_FreeBuffer(OMX_IN OMX_HANDLETYPE hComponent, | ||
191 | OMX_IN OMX_U32 nPortIndex, | ||
192 | OMX_IN OMX_BUFFERHEADERTYPE *pBuffer); | ||
193 | |||
194 | |||
195 | OMX_ERRORTYPE OMXBase_EmptyThisBuffer(OMX_IN OMX_HANDLETYPE hComponent, | ||
196 | OMX_IN OMX_BUFFERHEADERTYPE *pBuffer); | ||
197 | |||
198 | |||
199 | OMX_ERRORTYPE OMXBase_FillThisBuffer(OMX_IN OMX_HANDLETYPE hComponent, | ||
200 | OMX_IN OMX_BUFFERHEADERTYPE *pBuffer); | ||
201 | |||
202 | |||
203 | OMX_ERRORTYPE OMXBase_ComponentDeinit(OMX_IN OMX_HANDLETYPE hComponent); | ||
204 | |||
205 | |||
206 | OMX_ERRORTYPE OMXBase_UseEGLImage(OMX_IN OMX_HANDLETYPE hComponent, | ||
207 | OMX_INOUT OMX_BUFFERHEADERTYPE * *ppBufferHdr, | ||
208 | OMX_IN OMX_U32 nPortIndex, | ||
209 | OMX_IN OMX_PTR pAppPrivate, | ||
210 | OMX_IN void *eglImage); | ||
211 | |||
212 | OMX_ERRORTYPE OMXBase_ComponentRoleEnum(OMX_IN OMX_HANDLETYPE hComponent, | ||
213 | OMX_OUT OMX_U8 *cRole, | ||
214 | OMX_IN OMX_U32 nIndex); | ||
215 | |||
216 | #ifdef __cplusplus | ||
217 | } | ||
218 | #endif | ||
219 | |||
220 | #endif /* _OMX_BASE_H_ */ | ||
221 | |||
diff --git a/libstagefrighthw/omx/base/OMX_BaseCallbacks.c b/libstagefrighthw/omx/base/OMX_BaseCallbacks.c new file mode 100644 index 0000000..efe62b8 --- /dev/null +++ b/libstagefrighthw/omx/base/OMX_BaseCallbacks.c | |||
@@ -0,0 +1,136 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 | #define LOG_TAG "OMX_BASE_CALLBACKS" | ||
18 | |||
19 | #include <OMX_Core.h> | ||
20 | #include <OMX_Base.h> | ||
21 | |||
22 | /* | ||
23 | * OMX Base callback ReturnEventNotify | ||
24 | */ | ||
25 | OMX_ERRORTYPE OMXBase_CB_ReturnEventNotify(OMX_HANDLETYPE hComponent, | ||
26 | OMX_EVENTTYPE eEvent, | ||
27 | OMX_U32 nData1, OMX_U32 nData2, | ||
28 | OMX_PTR pEventData) | ||
29 | { | ||
30 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
31 | OMX_COMPONENTTYPE *pComp = NULL; | ||
32 | OMXBaseComp *pBaseComp = NULL; | ||
33 | OMXBaseComp_Pvt *pBaseCompPvt = NULL; | ||
34 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
35 | uint32_t nActualSize = 0; | ||
36 | OMX_PTR pCmdData = NULL; | ||
37 | |||
38 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
39 | |||
40 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
41 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
42 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
43 | |||
44 | switch( eEvent ) { | ||
45 | case OMX_EventCmdComplete : | ||
46 | if((OMX_COMMANDTYPE)nData1 == OMX_CommandStateSet ) { | ||
47 | OSAL_SetEvent(pBaseCompPvt->pCmdCompleteEvent, | ||
48 | OMXBase_CmdStateSet, OSAL_EVENT_OR); | ||
49 | } else if((OMX_COMMANDTYPE)nData1 == OMX_CommandPortEnable ) { | ||
50 | OSAL_SetEvent(pBaseCompPvt->pCmdCompleteEvent, | ||
51 | OMXBase_CmdPortEnable, OSAL_EVENT_OR); | ||
52 | } else if((OMX_COMMANDTYPE)nData1 == OMX_CommandPortDisable ) { | ||
53 | OSAL_SetEvent(pBaseCompPvt->pCmdCompleteEvent, | ||
54 | OMXBase_CmdPortDisable, OSAL_EVENT_OR); | ||
55 | } else if((OMX_COMMANDTYPE)nData1 == OMX_CommandFlush ) { | ||
56 | OSAL_SetEvent(pBaseCompPvt->pCmdCompleteEvent, | ||
57 | OMXBase_CmdFlush, OSAL_EVENT_OR); | ||
58 | } else if((OMX_COMMANDTYPE)nData1 == OMX_CommandMarkBuffer ) { | ||
59 | /*The derived component has completed the mark buffer command so | ||
60 | the memory allocated for pCmdData is no longer needed - it can | ||
61 | be freed up*/ | ||
62 | tStatus = OSAL_ReadFromPipe(pBaseCompPvt->pCmdDataPipe, | ||
63 | &pCmdData, sizeof(OMX_PTR), &nActualSize, | ||
64 | OSAL_NO_SUSPEND); | ||
65 | /*Read from pipe should return immediately with valid value - if | ||
66 | it does not, return error callback to the client*/ | ||
67 | if( OSAL_ErrNone != tStatus ) { | ||
68 | OSAL_ErrorTrace("pCmdData not available to freed up at mark \ | ||
69 | buffer command completion. Returning error event."); | ||
70 | pBaseCompPvt->sAppCallbacks.EventHandler(hComponent, | ||
71 | pComp->pApplicationPrivate, OMX_EventError, | ||
72 | (OMX_U32)OMX_ErrorInsufficientResources, 0, NULL); | ||
73 | goto EXIT; | ||
74 | } | ||
75 | OSAL_Free(pCmdData); | ||
76 | /*For mark buffer cmd complete, directly send callback to the | ||
77 | client. This callback is not being handled in | ||
78 | OMXBase_EventNotifyToClient since this can happen much later | ||
79 | than the time when the mark comand was received*/ | ||
80 | pBaseCompPvt->sAppCallbacks.EventHandler(hComponent, | ||
81 | pComp->pApplicationPrivate, eEvent, nData1, nData2, | ||
82 | pEventData); | ||
83 | } | ||
84 | break; | ||
85 | |||
86 | case OMX_EventError : | ||
87 | pBaseCompPvt->sAppCallbacks.EventHandler(hComponent, | ||
88 | pComp->pApplicationPrivate, eEvent, nData1, nData2, pEventData); | ||
89 | break; | ||
90 | |||
91 | case OMX_EventMark : | ||
92 | pBaseCompPvt->sAppCallbacks.EventHandler(hComponent, | ||
93 | pComp->pApplicationPrivate, eEvent, nData1, nData2, pEventData); | ||
94 | break; | ||
95 | |||
96 | case OMX_EventPortSettingsChanged : | ||
97 | pBaseCompPvt->sAppCallbacks.EventHandler(hComponent, | ||
98 | pComp->pApplicationPrivate, eEvent, nData1, nData2, pEventData); | ||
99 | break; | ||
100 | |||
101 | case OMX_EventBufferFlag : | ||
102 | pBaseCompPvt->sAppCallbacks.EventHandler(hComponent, | ||
103 | pComp->pApplicationPrivate, eEvent, nData1, nData2, pEventData); | ||
104 | break; | ||
105 | |||
106 | case OMX_EventResourcesAcquired : | ||
107 | pBaseCompPvt->sAppCallbacks.EventHandler(hComponent, | ||
108 | pComp->pApplicationPrivate, eEvent, nData1, nData2, pEventData); | ||
109 | break; | ||
110 | |||
111 | case OMX_EventComponentResumed : | ||
112 | pBaseCompPvt->sAppCallbacks.EventHandler(hComponent, | ||
113 | pComp->pApplicationPrivate, eEvent, nData1, nData2, pEventData); | ||
114 | break; | ||
115 | |||
116 | case OMX_EventDynamicResourcesAvailable : | ||
117 | pBaseCompPvt->sAppCallbacks.EventHandler(hComponent, | ||
118 | pComp->pApplicationPrivate, eEvent, nData1, nData2, pEventData); | ||
119 | break; | ||
120 | |||
121 | case OMX_EventPortFormatDetected : | ||
122 | pBaseCompPvt->sAppCallbacks.EventHandler(hComponent, | ||
123 | pComp->pApplicationPrivate, eEvent, nData1, nData2, pEventData); | ||
124 | break; | ||
125 | |||
126 | default : | ||
127 | OSAL_ErrorTrace("Unknown event received - still making callback"); | ||
128 | pBaseCompPvt->sAppCallbacks.EventHandler(hComponent, | ||
129 | pComp->pApplicationPrivate, eEvent, nData1, nData2, pEventData); | ||
130 | break; | ||
131 | } | ||
132 | |||
133 | EXIT: | ||
134 | return (eError); | ||
135 | } | ||
136 | |||
diff --git a/libstagefrighthw/omx/base/OMX_BaseDIO.c b/libstagefrighthw/omx/base/OMX_BaseDIO.c new file mode 100644 index 0000000..47110fe --- /dev/null +++ b/libstagefrighthw/omx/base/OMX_BaseDIO.c | |||
@@ -0,0 +1,312 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 | #define LOG_TAG "OMX_BASE_DIO" | ||
17 | |||
18 | #include <string.h> | ||
19 | |||
20 | #include <OMX_Base.h> | ||
21 | |||
22 | static OMX_PTR OMXBase_DIO_GetPort(OMX_HANDLETYPE hComponent, | ||
23 | OMX_U32 nPortIndex); | ||
24 | /* | ||
25 | * OMXBase DIO Init | ||
26 | */ | ||
27 | OMX_ERRORTYPE OMXBase_DIO_Init (OMX_HANDLETYPE hComponent, | ||
28 | OMX_U32 nPortIndex, | ||
29 | OMX_STRING cChannelType, | ||
30 | OMX_PTR pCreateParams) | ||
31 | { | ||
32 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
33 | OMX_DIO_Object *hDIO = NULL; | ||
34 | OMXBase_Port *pPort = NULL; | ||
35 | OMX_BOOL bFound = OMX_FALSE; | ||
36 | OMX_U32 i = 0; | ||
37 | |||
38 | // OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
39 | // OMXBaseComp *pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
40 | |||
41 | OMX_CHECK(NULL != cChannelType, OMX_ErrorBadParameter); | ||
42 | |||
43 | pPort = OMXBase_DIO_GetPort(hComponent, nPortIndex); | ||
44 | OMX_CHECK(pPort != NULL, OMX_ErrorBadParameter); | ||
45 | |||
46 | while( NULL != OMX_DIO_Registered[i].cChannelType ) { | ||
47 | if( strcmp(cChannelType, OMX_DIO_Registered[i].cChannelType) == 0 ) { | ||
48 | bFound = OMX_TRUE; | ||
49 | break; | ||
50 | } | ||
51 | i++; | ||
52 | } | ||
53 | |||
54 | if( bFound ) { | ||
55 | hDIO = (OMX_DIO_Object *) OSAL_Malloc(sizeof(OMX_DIO_Object)); | ||
56 | OMX_CHECK(NULL != hDIO, OMX_ErrorInsufficientResources); | ||
57 | OSAL_Memset(hDIO, 0x0, sizeof(OMX_DIO_Object)); | ||
58 | |||
59 | /* Initialize the DIO object depending on the ChannelType */ | ||
60 | eError = OMX_DIO_Registered[i].pInitialize(hDIO, pCreateParams); | ||
61 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
62 | |||
63 | /* Assign DIO handle to port */ | ||
64 | pPort->hDIO = hDIO; | ||
65 | } else { | ||
66 | OMX_CHECK(OMX_FALSE, OMX_ErrorUndefined); | ||
67 | } | ||
68 | |||
69 | EXIT: | ||
70 | return (eError); | ||
71 | } | ||
72 | |||
73 | /* | ||
74 | * OMXBase DIO DeInit | ||
75 | */ | ||
76 | OMX_ERRORTYPE OMXBase_DIO_Deinit (OMX_HANDLETYPE hComponent, | ||
77 | OMX_U32 nPortIndex) | ||
78 | { | ||
79 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
80 | OMX_DIO_Object *hDIO = NULL; | ||
81 | OMXBase_Port *pPort = NULL; | ||
82 | |||
83 | pPort = OMXBase_DIO_GetPort(hComponent, nPortIndex); | ||
84 | OMX_CHECK(pPort != NULL, OMX_ErrorBadParameter); | ||
85 | |||
86 | hDIO = (OMX_DIO_Object *)pPort->hDIO; | ||
87 | OMX_CHECK(hDIO != NULL, OMX_ErrorBadParameter); | ||
88 | |||
89 | eError = hDIO->deinit(hDIO); | ||
90 | |||
91 | OSAL_Free(pPort->hDIO); | ||
92 | pPort->hDIO = NULL; | ||
93 | |||
94 | EXIT: | ||
95 | return (eError); | ||
96 | } | ||
97 | |||
98 | /* | ||
99 | * OMXBase DIO Open | ||
100 | */ | ||
101 | OMX_ERRORTYPE OMXBase_DIO_Open (OMX_HANDLETYPE hComponent, | ||
102 | OMX_U32 nPortIndex, | ||
103 | OMX_PTR pOpenParams) | ||
104 | { | ||
105 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
106 | OMX_DIO_Object *hDIO = NULL; | ||
107 | OMXBase_Port *pPort = NULL; | ||
108 | |||
109 | pPort = OMXBase_DIO_GetPort(hComponent, nPortIndex); | ||
110 | OMX_CHECK(pPort != NULL, OMX_ErrorBadParameter); | ||
111 | |||
112 | hDIO = (OMX_DIO_Object *)pPort->hDIO; | ||
113 | OMX_CHECK(hDIO != NULL, OMX_ErrorBadParameter); | ||
114 | |||
115 | eError = hDIO->open(hDIO, (OMX_DIO_OpenParams *)pOpenParams); | ||
116 | |||
117 | EXIT: | ||
118 | if( eError == OMX_ErrorNone ) { | ||
119 | hDIO->bOpened = OMX_TRUE; | ||
120 | } | ||
121 | return (eError); | ||
122 | } | ||
123 | |||
124 | /* | ||
125 | * OMX Base DIO close | ||
126 | */ | ||
127 | OMX_ERRORTYPE OMXBase_DIO_Close (OMX_HANDLETYPE hComponent, | ||
128 | OMX_U32 nPortIndex) | ||
129 | { | ||
130 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
131 | OMX_DIO_Object *hDIO = NULL; | ||
132 | OMXBase_Port *pPort = NULL; | ||
133 | |||
134 | pPort = OMXBase_DIO_GetPort(hComponent, nPortIndex); | ||
135 | OMX_CHECK(pPort != NULL, OMX_ErrorBadParameter); | ||
136 | |||
137 | hDIO = (OMX_DIO_Object *)pPort->hDIO; | ||
138 | OMX_CHECK(hDIO != NULL, OMX_ErrorBadParameter); | ||
139 | |||
140 | hDIO->bOpened = OMX_FALSE; | ||
141 | eError = hDIO->close(hDIO); | ||
142 | |||
143 | EXIT: | ||
144 | return (eError); | ||
145 | } | ||
146 | |||
147 | /* | ||
148 | * OMX Base DIO Queue | ||
149 | */ | ||
150 | OMX_ERRORTYPE OMXBase_DIO_Queue (OMX_HANDLETYPE hComponent, | ||
151 | OMX_U32 nPortIndex, | ||
152 | OMX_PTR pBuffHeader) | ||
153 | { | ||
154 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
155 | OMX_DIO_Object *hDIO = NULL; | ||
156 | OMXBase_Port *pPort = NULL; | ||
157 | |||
158 | pPort = OMXBase_DIO_GetPort(hComponent, nPortIndex); | ||
159 | OMX_CHECK(pPort != NULL, OMX_ErrorBadParameter); | ||
160 | |||
161 | hDIO = (OMX_DIO_Object *)pPort->hDIO; | ||
162 | OMX_CHECK(hDIO != NULL, OMX_ErrorBadParameter); | ||
163 | |||
164 | eError = hDIO->queue(hDIO, pBuffHeader); | ||
165 | |||
166 | EXIT: | ||
167 | return (eError); | ||
168 | } | ||
169 | |||
170 | /* | ||
171 | * OMXBase DIO Dequeue | ||
172 | */ | ||
173 | OMX_ERRORTYPE OMXBase_DIO_Dequeue (OMX_HANDLETYPE hComponent, | ||
174 | OMX_U32 nPortIndex, | ||
175 | OMX_PTR *pBuffHeader) | ||
176 | { | ||
177 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
178 | OMX_DIO_Object *hDIO = NULL; | ||
179 | OMXBase_Port *pPort = NULL; | ||
180 | |||
181 | pPort = OMXBase_DIO_GetPort(hComponent, nPortIndex); | ||
182 | OMX_CHECK(pPort != NULL, OMX_ErrorBadParameter); | ||
183 | |||
184 | hDIO = (OMX_DIO_Object *)pPort->hDIO; | ||
185 | OMX_CHECK(hDIO != NULL, OMX_ErrorBadParameter); | ||
186 | |||
187 | eError = hDIO->dequeue(hDIO, pBuffHeader); | ||
188 | |||
189 | EXIT: | ||
190 | return (eError); | ||
191 | } | ||
192 | |||
193 | /* | ||
194 | * OMXBase DIO Send | ||
195 | */ | ||
196 | OMX_ERRORTYPE OMXBase_DIO_Send (OMX_HANDLETYPE hComponent, | ||
197 | OMX_U32 nPortIndex, | ||
198 | OMX_PTR pBuffHeader) | ||
199 | { | ||
200 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
201 | OMX_DIO_Object *hDIO = NULL; | ||
202 | OMXBase_Port *pPort = NULL; | ||
203 | |||
204 | pPort = OMXBase_DIO_GetPort(hComponent, nPortIndex); | ||
205 | OMX_CHECK(pPort != NULL, OMX_ErrorBadParameter); | ||
206 | |||
207 | hDIO = (OMX_DIO_Object *)pPort->hDIO; | ||
208 | OMX_CHECK(hDIO != NULL, OMX_ErrorBadParameter); | ||
209 | |||
210 | eError = hDIO->send(hDIO, pBuffHeader); | ||
211 | |||
212 | EXIT: | ||
213 | return (eError); | ||
214 | } | ||
215 | |||
216 | /* | ||
217 | * OMXBase DIO Cancel | ||
218 | */ | ||
219 | OMX_ERRORTYPE OMXBase_DIO_Cancel (OMX_HANDLETYPE hComponent, | ||
220 | OMX_U32 nPortIndex, | ||
221 | OMX_PTR pBuffHeader) | ||
222 | { | ||
223 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
224 | OMX_DIO_Object *hDIO = NULL; | ||
225 | OMXBase_Port *pPort = NULL; | ||
226 | |||
227 | pPort = OMXBase_DIO_GetPort(hComponent, nPortIndex); | ||
228 | OMX_CHECK(pPort != NULL, OMX_ErrorBadParameter); | ||
229 | |||
230 | hDIO = (OMX_DIO_Object *)pPort->hDIO; | ||
231 | OMX_CHECK(hDIO != NULL, OMX_ErrorBadParameter); | ||
232 | |||
233 | eError = hDIO->cancel(hDIO, pBuffHeader); | ||
234 | |||
235 | EXIT: | ||
236 | return (eError); | ||
237 | } | ||
238 | |||
239 | /* | ||
240 | * OMXBase DIO Control | ||
241 | */ | ||
242 | OMX_ERRORTYPE OMXBase_DIO_Control (OMX_HANDLETYPE hComponent, | ||
243 | OMX_U32 nPortIndex, | ||
244 | OMX_DIO_CtrlCmdType nCmdType, | ||
245 | OMX_PTR pParams) | ||
246 | { | ||
247 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
248 | OMX_DIO_Object *hDIO = NULL; | ||
249 | OMXBase_Port *pPort = NULL; | ||
250 | |||
251 | pPort = OMXBase_DIO_GetPort(hComponent, nPortIndex); | ||
252 | OMX_CHECK(pPort != NULL, OMX_ErrorBadParameter); | ||
253 | |||
254 | hDIO = (OMX_DIO_Object *)pPort->hDIO; | ||
255 | OMX_CHECK(hDIO != NULL, OMX_ErrorBadParameter); | ||
256 | |||
257 | eError = hDIO->control(hDIO, nCmdType, pParams); | ||
258 | |||
259 | EXIT: | ||
260 | return (eError); | ||
261 | } | ||
262 | |||
263 | /* | ||
264 | * OMX Base DIO GetCount | ||
265 | */ | ||
266 | OMX_ERRORTYPE OMXBase_DIO_GetCount (OMX_HANDLETYPE hComponent, | ||
267 | OMX_U32 nPortIndex, | ||
268 | OMX_U32 *pCount) | ||
269 | { | ||
270 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
271 | OMX_DIO_Object *hDIO = NULL; | ||
272 | OMXBase_Port *pPort = NULL; | ||
273 | |||
274 | /*Resetting count to 0 initially*/ | ||
275 | *pCount = 0; | ||
276 | pPort = OMXBase_DIO_GetPort(hComponent, nPortIndex); | ||
277 | OMX_CHECK(pPort != NULL, OMX_ErrorBadParameter); | ||
278 | |||
279 | hDIO = (OMX_DIO_Object *)pPort->hDIO; | ||
280 | OMX_CHECK(hDIO != NULL, OMX_ErrorBadParameter); | ||
281 | |||
282 | eError = hDIO->getcount(hDIO, pCount); | ||
283 | |||
284 | EXIT: | ||
285 | return (eError); | ||
286 | } | ||
287 | |||
288 | |||
289 | /* | ||
290 | * OMX Base DIO GetPort from the PortIndex | ||
291 | */ | ||
292 | static OMX_PTR OMXBase_DIO_GetPort(OMX_HANDLETYPE hComponent, OMX_U32 nPortIndex) | ||
293 | { | ||
294 | OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
295 | OMXBaseComp *pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
296 | OMXBase_Port *pPort = NULL; | ||
297 | OMX_U32 nStartPortNumber = 0; | ||
298 | |||
299 | nStartPortNumber = pBaseComp->nMinStartPortIndex; | ||
300 | if( pBaseComp->pPorts == NULL ) { | ||
301 | pPort = NULL; | ||
302 | goto EXIT; | ||
303 | } | ||
304 | pPort = (OMXBase_Port *)pBaseComp->pPorts[nPortIndex - nStartPortNumber]; | ||
305 | |||
306 | EXIT: | ||
307 | return (pPort); | ||
308 | } | ||
309 | |||
310 | |||
311 | |||
312 | |||
diff --git a/libstagefrighthw/omx/base/OMX_BaseDIONonTunnel.c b/libstagefrighthw/omx/base/OMX_BaseDIONonTunnel.c new file mode 100644 index 0000000..dc61ed9 --- /dev/null +++ b/libstagefrighthw/omx/base/OMX_BaseDIONonTunnel.c | |||
@@ -0,0 +1,648 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 | #define LOG_TAG "OMX_BASE_DIO_NONTUNNEL" | ||
18 | |||
19 | #include <OMX_Base.h> | ||
20 | #include <OMX_TI_Custom.h> | ||
21 | |||
22 | #include <memplugin.h> | ||
23 | |||
24 | typedef struct DIO_NonTunnel_Attrs { | ||
25 | OMX_DIO_CreateParams sCreateParams; | ||
26 | OMX_U32 nFlags; | ||
27 | OMX_PTR pPipeHandle; | ||
28 | OMX_PTR pHdrPool; | ||
29 | OMX_PTR pPlatformPrivatePool; | ||
30 | }DIO_NonTunnel_Attrs; | ||
31 | |||
32 | |||
33 | static OMX_ERRORTYPE OMX_DIO_NonTunnel_Open (OMX_HANDLETYPE handle, | ||
34 | OMX_DIO_OpenParams *pParams); | ||
35 | |||
36 | static OMX_ERRORTYPE OMX_DIO_NonTunnel_Close (OMX_HANDLETYPE handle); | ||
37 | |||
38 | static OMX_ERRORTYPE OMX_DIO_NonTunnel_Queue (OMX_HANDLETYPE handle, | ||
39 | OMX_PTR pBuffHeader); | ||
40 | |||
41 | static OMX_ERRORTYPE OMX_DIO_NonTunnel_Dequeue (OMX_HANDLETYPE handle, | ||
42 | OMX_PTR *pBuffHeader); | ||
43 | |||
44 | static OMX_ERRORTYPE OMX_DIO_NonTunnel_Send (OMX_HANDLETYPE handle, | ||
45 | OMX_PTR pBuffHeader); | ||
46 | |||
47 | static OMX_ERRORTYPE OMX_DIO_NonTunnel_Cancel (OMX_HANDLETYPE handle, | ||
48 | OMX_PTR pBuffHeader); | ||
49 | |||
50 | static OMX_ERRORTYPE OMX_DIO_NonTunnel_Control (OMX_HANDLETYPE handle, | ||
51 | OMX_DIO_CtrlCmdType nCmdType, | ||
52 | OMX_PTR pParams); | ||
53 | |||
54 | static OMX_ERRORTYPE OMX_DIO_NonTunnel_Getcount (OMX_HANDLETYPE handle, | ||
55 | OMX_U32 *pCount); | ||
56 | |||
57 | static OMX_ERRORTYPE OMX_DIO_NonTunnel_Deinit (OMX_HANDLETYPE handle); | ||
58 | |||
59 | /* | ||
60 | * _DIO_GetPort from Port Index | ||
61 | */ | ||
62 | static OMX_PTR _DIO_GetPort(OMX_HANDLETYPE handle, OMX_U32 nPortIndex) | ||
63 | { | ||
64 | OMX_COMPONENTTYPE *pComp; | ||
65 | OMXBaseComp *pBaseComp; | ||
66 | OMXBase_Port *pPort = NULL; | ||
67 | OMX_U32 nStartPortNumber = 0; | ||
68 | OMX_DIO_Object *hDIO = (OMX_DIO_Object *)handle; | ||
69 | DIO_NonTunnel_Attrs *pContext = NULL; | ||
70 | pContext = (DIO_NonTunnel_Attrs *)hDIO->pContext; | ||
71 | |||
72 | pComp = (OMX_COMPONENTTYPE *)(pContext->sCreateParams.hComponent); | ||
73 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
74 | |||
75 | nStartPortNumber = pBaseComp->nMinStartPortIndex; | ||
76 | if( pBaseComp->pPorts == NULL ) { | ||
77 | pPort = NULL; | ||
78 | goto EXIT; | ||
79 | } | ||
80 | |||
81 | pPort = (OMXBase_Port *)pBaseComp->pPorts[nPortIndex - nStartPortNumber]; | ||
82 | |||
83 | EXIT: | ||
84 | return (pPort); | ||
85 | } | ||
86 | |||
87 | /* | ||
88 | * DIO NoneTunnel Init | ||
89 | */ | ||
90 | OMX_ERRORTYPE OMX_DIO_NonTunnel_Init(OMX_HANDLETYPE handle, | ||
91 | OMX_PTR pCreateParams) | ||
92 | { | ||
93 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
94 | OMX_DIO_Object *hDIO = (OMX_DIO_Object *)handle; | ||
95 | DIO_NonTunnel_Attrs *pContext = NULL; | ||
96 | |||
97 | // OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)(((OMX_DIO_CreateParams *)(pCreateParams))->hComponent); | ||
98 | // OMXBaseComp *pBaseComPvt = (OMXBaseComp *)pComp->pComponentPrivate; | ||
99 | |||
100 | /* creating memory for DIO object private area */ | ||
101 | hDIO->pContext = OSAL_Malloc(sizeof(DIO_NonTunnel_Attrs)); | ||
102 | OMX_CHECK(NULL != hDIO->pContext, OMX_ErrorInsufficientResources); | ||
103 | |||
104 | OSAL_Memset(hDIO->pContext, 0x0, sizeof(DIO_NonTunnel_Attrs)); | ||
105 | |||
106 | hDIO->open = OMX_DIO_NonTunnel_Open; | ||
107 | hDIO->close = OMX_DIO_NonTunnel_Close; | ||
108 | hDIO->queue = OMX_DIO_NonTunnel_Queue; | ||
109 | hDIO->dequeue = OMX_DIO_NonTunnel_Dequeue; | ||
110 | hDIO->send = OMX_DIO_NonTunnel_Send; | ||
111 | hDIO->cancel = OMX_DIO_NonTunnel_Cancel; | ||
112 | hDIO->control = OMX_DIO_NonTunnel_Control; | ||
113 | hDIO->getcount = OMX_DIO_NonTunnel_Getcount; | ||
114 | hDIO->deinit = OMX_DIO_NonTunnel_Deinit; | ||
115 | |||
116 | pContext = hDIO->pContext; | ||
117 | /* Initialize private data */ | ||
118 | pContext->sCreateParams = *(OMX_DIO_CreateParams *)pCreateParams; | ||
119 | |||
120 | EXIT: | ||
121 | return (eError); | ||
122 | } | ||
123 | |||
124 | /* | ||
125 | * DIO NonTunnel DeInit | ||
126 | */ | ||
127 | static OMX_ERRORTYPE OMX_DIO_NonTunnel_Deinit (OMX_HANDLETYPE handle) | ||
128 | { | ||
129 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
130 | OMX_DIO_Object *hDIO = (OMX_DIO_Object *)handle; | ||
131 | DIO_NonTunnel_Attrs *pContext = NULL; | ||
132 | |||
133 | pContext = (DIO_NonTunnel_Attrs *)hDIO->pContext; | ||
134 | if( NULL != pContext ) { | ||
135 | OSAL_Free(pContext); | ||
136 | pContext = NULL; | ||
137 | } | ||
138 | |||
139 | return (eError); | ||
140 | } | ||
141 | |||
142 | /* | ||
143 | * DIO NonTunnel Open | ||
144 | */ | ||
145 | static OMX_ERRORTYPE OMX_DIO_NonTunnel_Open (OMX_HANDLETYPE handle, | ||
146 | OMX_DIO_OpenParams *pParams) | ||
147 | { | ||
148 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
149 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
150 | OMX_DIO_Object *hDIO = (OMX_DIO_Object *)handle; | ||
151 | DIO_NonTunnel_Attrs *pContext = NULL; | ||
152 | OMXBase_Port *pPort = NULL; | ||
153 | OMX_U32 i = 0; | ||
154 | OMX_U32 nPortIndex = 0; | ||
155 | OMX_U32 nStartPortNumber = 0; | ||
156 | // OMX_U8 *pTmpBuffer = NULL; | ||
157 | OMX_U32 nLocalComBuffers = 0; | ||
158 | OMX_PTR *pBufArr = NULL; | ||
159 | |||
160 | OMX_COMPONENTTYPE *pComp = NULL; | ||
161 | OMXBaseComp *pBaseComp = NULL; | ||
162 | |||
163 | pContext = (DIO_NonTunnel_Attrs *)hDIO->pContext; | ||
164 | pPort = (OMXBase_Port *)_DIO_GetPort(handle, pContext->sCreateParams.nPortIndex); | ||
165 | pComp = (OMX_COMPONENTTYPE *)(pContext->sCreateParams.hComponent); | ||
166 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
167 | nStartPortNumber = pBaseComp->nMinStartPortIndex; | ||
168 | nPortIndex = pContext->sCreateParams.nPortIndex; | ||
169 | |||
170 | /* supplier should allocate both the buffer and buffer headers | ||
171 | non supplier should allocate only the buffer headers */ | ||
172 | pPort->pBufferlist = (OMX_BUFFERHEADERTYPE * *)OSAL_Malloc( | ||
173 | (pPort->sPortDef.nBufferCountActual * sizeof(OMX_BUFFERHEADERTYPE *))); | ||
174 | |||
175 | OMX_CHECK(NULL != pPort->pBufferlist, OMX_ErrorInsufficientResources); | ||
176 | OSAL_Memset(pPort->pBufferlist, 0, (pPort->sPortDef.nBufferCountActual | ||
177 | * sizeof(OMX_BUFFERHEADERTYPE *))); | ||
178 | /* create a buffer header pool */ | ||
179 | pContext->pHdrPool = (OMX_PTR)OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE) | ||
180 | * (pPort->sPortDef.nBufferCountActual)); | ||
181 | OMX_CHECK(NULL != pContext->pHdrPool, OMX_ErrorInsufficientResources); | ||
182 | OSAL_Memset(pContext->pHdrPool, 0, sizeof(OMX_BUFFERHEADERTYPE) * | ||
183 | (pPort->sPortDef.nBufferCountActual)); | ||
184 | |||
185 | pContext->pPlatformPrivatePool = (OMX_PTR)OSAL_Malloc(pPort->sPortDef.nBufferCountActual | ||
186 | * sizeof(OMXBase_BufHdrPvtData)); | ||
187 | OMX_CHECK(NULL != pContext->pPlatformPrivatePool, OMX_ErrorInsufficientResources); | ||
188 | |||
189 | /*Setting platform port pvt pool to 0*/ | ||
190 | OSAL_Memset(pContext->pPlatformPrivatePool, 0, | ||
191 | pPort->sPortDef.nBufferCountActual * | ||
192 | sizeof(OMXBase_BufHdrPvtData)); | ||
193 | |||
194 | if( pPort->bIsBufferAllocator) { | ||
195 | //Setting up fields for calling configure | ||
196 | nLocalComBuffers = pBaseComp->pPorts[nPortIndex - nStartPortNumber]->sProps. | ||
197 | nNumComponentBuffers; | ||
198 | if( nLocalComBuffers != 1 && pBaseComp-> | ||
199 | pPorts[nPortIndex - nStartPortNumber]->sProps.eBufMemoryType != | ||
200 | MEM_TILER8_2D ) { | ||
201 | //For non 2D buffers multiple component buffers not supported | ||
202 | OMX_CHECK(OMX_FALSE, OMX_ErrorBadParameter); | ||
203 | } | ||
204 | |||
205 | pBufArr = OSAL_Malloc(sizeof(OMX_PTR) * nLocalComBuffers); | ||
206 | OMX_CHECK(NULL != pBufArr, OMX_ErrorInsufficientResources); | ||
207 | } | ||
208 | |||
209 | /* update buffer list with buffer and buffer headers */ | ||
210 | for( i = 0; i < pPort->sPortDef.nBufferCountActual; i++ ) { | ||
211 | pPort->pBufferlist[i] = (OMX_BUFFERHEADERTYPE *)(pContext->pHdrPool) + i; | ||
212 | OMX_BASE_INIT_STRUCT_PTR(pPort->pBufferlist[i], OMX_BUFFERHEADERTYPE); | ||
213 | pPort->pBufferlist[i]->pPlatformPrivate = | ||
214 | (OMXBase_BufHdrPvtData *)(pContext->pPlatformPrivatePool) + i; | ||
215 | |||
216 | ((OMXBase_BufHdrPvtData *)(pPort->pBufferlist[i]->pPlatformPrivate))->bufSt = OWNED_BY_CLIENT; | ||
217 | ((OMXBase_BufHdrPvtData *)(pPort->pBufferlist[i]->pPlatformPrivate))->bIsLocked = OMX_FALSE; | ||
218 | |||
219 | if( pPort->bIsBufferAllocator) { | ||
220 | MemHeader *h = &(((OMXBase_BufHdrPvtData *)(pPort->pBufferlist[i]->pPlatformPrivate))->sMemHdr[0]); | ||
221 | pPort->pBufferlist[i]->pBuffer = memplugin_alloc_noheader(h, pParams->nBufSize, 1, MEM_CARVEOUT, 0, 0); | ||
222 | if( nLocalComBuffers == 2 ) { | ||
223 | OMX_CHECK(OMX_FALSE, OMX_ErrorNotImplemented); | ||
224 | } | ||
225 | } | ||
226 | } | ||
227 | |||
228 | /* create a fixed size OS pipe */ | ||
229 | tStatus = OSAL_CreatePipe(&pContext->pPipeHandle, | ||
230 | (sizeof(OMX_BUFFERHEADERTYPE *) * | ||
231 | pPort->sPortDef.nBufferCountActual), | ||
232 | sizeof(OMX_BUFFERHEADERTYPE *), 1); | ||
233 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorInsufficientResources); | ||
234 | pPort->nCachedBufferCnt = pPort->sPortDef.nBufferCountActual; | ||
235 | |||
236 | |||
237 | EXIT: | ||
238 | if( pBufArr != NULL ) { | ||
239 | OSAL_Free(pBufArr); | ||
240 | pBufArr = NULL; | ||
241 | } | ||
242 | if( OMX_ErrorNone != eError ) { | ||
243 | OMX_DIO_NonTunnel_Close(handle); | ||
244 | } | ||
245 | return (eError); | ||
246 | } | ||
247 | |||
248 | /* | ||
249 | * DIO NonTunnel Close | ||
250 | */ | ||
251 | static OMX_ERRORTYPE OMX_DIO_NonTunnel_Close(OMX_HANDLETYPE handle) | ||
252 | { | ||
253 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
254 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
255 | OMX_DIO_Object *hDIO = (OMX_DIO_Object *)handle; | ||
256 | DIO_NonTunnel_Attrs *pContext = NULL; | ||
257 | OMXBase_Port *pPort = NULL; | ||
258 | OMX_U32 i = 0, nPortIndex = 0, nStartPortNumber = 0, nCompBufs = 0; | ||
259 | // OMX_PTR pTmpBuffer = NULL; | ||
260 | OMX_COMPONENTTYPE *pComp = NULL; | ||
261 | OMXBaseComp *pBaseComp = NULL; | ||
262 | |||
263 | pContext = (DIO_NonTunnel_Attrs *)hDIO->pContext; | ||
264 | OMX_CHECK(pContext != NULL, OMX_ErrorNone); | ||
265 | |||
266 | pPort = (OMXBase_Port *)_DIO_GetPort(handle, pContext->sCreateParams.nPortIndex); | ||
267 | if( pPort ) { | ||
268 | pComp = (OMX_COMPONENTTYPE *)(pContext->sCreateParams.hComponent); | ||
269 | if( pComp ) { | ||
270 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
271 | } | ||
272 | if( pBaseComp ) { | ||
273 | nStartPortNumber = pBaseComp->nMinStartPortIndex; | ||
274 | nPortIndex = pPort->sPortDef.nPortIndex; | ||
275 | nCompBufs = pBaseComp->pPorts[nPortIndex - nStartPortNumber]->sProps.nNumComponentBuffers; | ||
276 | } | ||
277 | if( pPort->pBufferlist ) { | ||
278 | for( i = 0; i < pPort->nCachedBufferCnt; i++ ) { | ||
279 | if( pPort->pBufferlist[i] ) { | ||
280 | if( pPort->bIsBufferAllocator) { | ||
281 | MemHeader *h = &(((OMXBase_BufHdrPvtData *)(pPort->pBufferlist[i]->pPlatformPrivate))->sMemHdr[0]); | ||
282 | memplugin_free_noheader(h); | ||
283 | if( nCompBufs == 2 ) { | ||
284 | OMX_CHECK(OMX_FALSE, OMX_ErrorNotImplemented); | ||
285 | } | ||
286 | } | ||
287 | } | ||
288 | } | ||
289 | /* freeup the buffer list */ | ||
290 | OSAL_Free(pPort->pBufferlist); | ||
291 | pPort->pBufferlist = NULL; | ||
292 | pPort->nCachedBufferCnt = 0; | ||
293 | } | ||
294 | } | ||
295 | |||
296 | if( pContext->pPlatformPrivatePool ) { | ||
297 | OSAL_Free(pContext->pPlatformPrivatePool); | ||
298 | } | ||
299 | pContext->pPlatformPrivatePool = NULL; | ||
300 | if( pContext->pHdrPool ) { | ||
301 | OSAL_Free(pContext->pHdrPool); | ||
302 | } | ||
303 | pContext->pHdrPool = NULL; | ||
304 | /* delete a OS pipe */ | ||
305 | if( pContext->pPipeHandle != NULL ) { | ||
306 | tStatus = OSAL_DeletePipe(pContext->pPipeHandle); | ||
307 | if( tStatus != OSAL_ErrNone ) { | ||
308 | eError = OMX_ErrorUndefined; | ||
309 | } | ||
310 | pContext->pPipeHandle = NULL; | ||
311 | } | ||
312 | |||
313 | EXIT: | ||
314 | return (eError); | ||
315 | } | ||
316 | |||
317 | /* | ||
318 | * DIO NonTunnel Queue | ||
319 | */ | ||
320 | static OMX_ERRORTYPE OMX_DIO_NonTunnel_Queue (OMX_HANDLETYPE handle, | ||
321 | OMX_PTR pBuffHeader) | ||
322 | { | ||
323 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
324 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
325 | OMX_DIO_Object *hDIO = (OMX_DIO_Object *)handle; | ||
326 | DIO_NonTunnel_Attrs *pContext = NULL; | ||
327 | OMX_BUFFERHEADERTYPE *pOMXBufHeader; | ||
328 | OMXBase_Port *pPort; | ||
329 | |||
330 | pOMXBufHeader = (OMX_BUFFERHEADERTYPE *) pBuffHeader; | ||
331 | pContext = (DIO_NonTunnel_Attrs *)hDIO->pContext; | ||
332 | |||
333 | pPort = (OMXBase_Port *)_DIO_GetPort(handle, pContext->sCreateParams.nPortIndex); | ||
334 | tStatus = OSAL_WriteToPipe(pContext->pPipeHandle, &pOMXBufHeader, | ||
335 | sizeof(pOMXBufHeader), OSAL_SUSPEND); | ||
336 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorUndefined); | ||
337 | |||
338 | EXIT: | ||
339 | return (eError); | ||
340 | } | ||
341 | |||
342 | /* | ||
343 | * DIO NonTunnel Dequeue | ||
344 | */ | ||
345 | static OMX_ERRORTYPE OMX_DIO_NonTunnel_Dequeue (OMX_HANDLETYPE handle, | ||
346 | OMX_PTR *pBuffHeader) | ||
347 | { | ||
348 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
349 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
350 | OMX_DIO_Object *hDIO = (OMX_DIO_Object *)handle; | ||
351 | DIO_NonTunnel_Attrs *pContext = NULL; | ||
352 | OMXBase_Port *pPort; | ||
353 | uint32_t actualSize = 0; | ||
354 | OMX_BUFFERHEADERTYPE *pOrigOMXBufHeader = NULL; | ||
355 | OMX_COMPONENTTYPE *pComp = NULL; | ||
356 | OMXBaseComp *pBaseComp = NULL; | ||
357 | OMX_U32 nPortIndex, nTimeout; | ||
358 | |||
359 | pContext = (DIO_NonTunnel_Attrs *)hDIO->pContext; | ||
360 | pPort = (OMXBase_Port *)_DIO_GetPort(handle, pContext->sCreateParams.nPortIndex); | ||
361 | pComp = (OMX_COMPONENTTYPE *)pContext->sCreateParams.hComponent; | ||
362 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
363 | nPortIndex = pPort->sPortDef.nPortIndex; | ||
364 | nTimeout = pBaseComp->pPorts[nPortIndex]->sProps.nTimeoutForDequeue; | ||
365 | /* dequeue the buffer from the data pipe */ | ||
366 | tStatus = OSAL_ReadFromPipe(pContext->pPipeHandle, &pOrigOMXBufHeader, | ||
367 | sizeof(pOrigOMXBufHeader), &actualSize, nTimeout); | ||
368 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorUndefined); | ||
369 | |||
370 | /*Cancel the buffer and return warning so that derived component may call | ||
371 | GetAttribute*/ | ||
372 | if( pOrigOMXBufHeader->nFlags & OMX_BUFFERFLAG_CODECCONFIG ) { | ||
373 | /*Reset codec config flag on o/p port*/ | ||
374 | if( OMX_DirOutput == pPort->sPortDef.eDir ) { | ||
375 | pOrigOMXBufHeader->nFlags &= (~OMX_BUFFERFLAG_CODECCONFIG); | ||
376 | } else { | ||
377 | tStatus = OSAL_WriteToFrontOfPipe(pContext->pPipeHandle, &pOrigOMXBufHeader, | ||
378 | sizeof(pOrigOMXBufHeader), OSAL_NO_SUSPEND); | ||
379 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorUndefined); | ||
380 | eError = (OMX_ERRORTYPE)OMX_TI_WarningAttributePending; | ||
381 | goto EXIT; | ||
382 | } | ||
383 | } | ||
384 | *pBuffHeader = (OMX_PTR)pOrigOMXBufHeader; | ||
385 | |||
386 | EXIT: | ||
387 | return (eError); | ||
388 | } | ||
389 | |||
390 | /* | ||
391 | * DIO NonTunnel Send | ||
392 | */ | ||
393 | static OMX_ERRORTYPE OMX_DIO_NonTunnel_Send (OMX_HANDLETYPE handle, | ||
394 | OMX_PTR pBuffHeader) | ||
395 | { | ||
396 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
397 | OMX_DIO_Object *hDIO = (OMX_DIO_Object *)handle; | ||
398 | DIO_NonTunnel_Attrs *pContext = NULL; | ||
399 | OMXBase_Port *pPort = NULL; | ||
400 | OMX_COMPONENTTYPE *pComp = NULL; | ||
401 | OMXBaseComp *pBaseComp = NULL; | ||
402 | OMX_CALLBACKTYPE *pAppCallbacks = NULL; | ||
403 | OMX_BUFFERHEADERTYPE *pOMXBufHeader; | ||
404 | |||
405 | pOMXBufHeader = (OMX_BUFFERHEADERTYPE *) pBuffHeader; | ||
406 | |||
407 | pContext = (DIO_NonTunnel_Attrs *)hDIO->pContext; | ||
408 | pPort = (OMXBase_Port *)_DIO_GetPort(handle, pContext->sCreateParams.nPortIndex); | ||
409 | pComp = (OMX_COMPONENTTYPE *)pContext->sCreateParams.hComponent; | ||
410 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
411 | pAppCallbacks = (OMX_CALLBACKTYPE *)pContext->sCreateParams.pAppCallbacks; | ||
412 | |||
413 | /* return the buffer back to the Application using EBD or FBD | ||
414 | * depending on the direction of the port (input or output) */ | ||
415 | if (((OMXBase_BufHdrPvtData *)(pOMXBufHeader->pPlatformPrivate))->bufSt != OWNED_BY_CLIENT) { | ||
416 | ((OMXBase_BufHdrPvtData *)(pOMXBufHeader->pPlatformPrivate))->bufSt = OWNED_BY_CLIENT; | ||
417 | if( OMX_DirInput == pPort->sPortDef.eDir ) { | ||
418 | eError = pAppCallbacks->EmptyBufferDone(pComp, | ||
419 | pComp->pApplicationPrivate, pOMXBufHeader); | ||
420 | } else if( OMX_DirOutput == pPort->sPortDef.eDir ) { | ||
421 | eError = pAppCallbacks->FillBufferDone(pComp, | ||
422 | pComp->pApplicationPrivate, pOMXBufHeader); | ||
423 | } | ||
424 | } | ||
425 | |||
426 | return (eError); | ||
427 | } | ||
428 | |||
429 | /* | ||
430 | * DIO NonTunnel Cancel | ||
431 | */ | ||
432 | static OMX_ERRORTYPE OMX_DIO_NonTunnel_Cancel (OMX_HANDLETYPE handle, | ||
433 | OMX_PTR pBuffHeader) | ||
434 | { | ||
435 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
436 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
437 | OMX_DIO_Object *hDIO = (OMX_DIO_Object *)handle; | ||
438 | DIO_NonTunnel_Attrs *pContext = NULL; | ||
439 | OMXBase_Port *pPort = NULL; | ||
440 | OMX_BUFFERHEADERTYPE *pOMXBufHeader; | ||
441 | OMX_COMPONENTTYPE *pComp; | ||
442 | OMXBaseComp *pBaseComp; | ||
443 | OMXBaseComp_Pvt *pBaseCompPvt; | ||
444 | OMX_BOOL bCallProcess = OMX_FALSE; | ||
445 | |||
446 | pOMXBufHeader = (OMX_BUFFERHEADERTYPE *) pBuffHeader; | ||
447 | |||
448 | pContext = (DIO_NonTunnel_Attrs *)hDIO->pContext; | ||
449 | pPort = (OMXBase_Port*)_DIO_GetPort(handle, pContext->sCreateParams.nPortIndex); | ||
450 | |||
451 | pComp = (OMX_COMPONENTTYPE *)pContext->sCreateParams.hComponent; | ||
452 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
453 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
454 | |||
455 | tStatus = OSAL_WriteToFrontOfPipe(pContext->pPipeHandle, &pOMXBufHeader, | ||
456 | sizeof(pOMXBufHeader), OSAL_NO_SUSPEND); | ||
457 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorUndefined); | ||
458 | |||
459 | if( bCallProcess ) { | ||
460 | /*Calling process fn so that event to process the buffer can be generated*/ | ||
461 | pBaseCompPvt->fpInvokeProcessFunction(pComp, DATAEVENT); | ||
462 | } | ||
463 | |||
464 | EXIT: | ||
465 | return (eError); | ||
466 | } | ||
467 | |||
468 | |||
469 | /* | ||
470 | * DIO NonTunnel Control | ||
471 | */ | ||
472 | static OMX_ERRORTYPE OMX_DIO_NonTunnel_Control (OMX_HANDLETYPE handle, | ||
473 | OMX_DIO_CtrlCmdType nCmdType, | ||
474 | OMX_PTR pParams) | ||
475 | { | ||
476 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
477 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
478 | OMX_DIO_Object *hDIO = (OMX_DIO_Object *)handle; | ||
479 | DIO_NonTunnel_Attrs *pContext = NULL; | ||
480 | OMXBase_Port *pPort = NULL; | ||
481 | OMX_COMPONENTTYPE *pComp = NULL; | ||
482 | OMXBaseComp *pBaseComp = NULL; | ||
483 | OMXBaseComp_Pvt *pBaseCompPvt = NULL; | ||
484 | OMX_CALLBACKTYPE *pAppCallbacks = NULL; | ||
485 | OMX_BUFFERHEADERTYPE *pBuffHeader = NULL; | ||
486 | MemHeader *pAttrDesc = NULL; | ||
487 | uint32_t elementsInpipe = 0; | ||
488 | uint32_t actualSize = 0; | ||
489 | |||
490 | pContext = (DIO_NonTunnel_Attrs *)hDIO->pContext; | ||
491 | pComp = (OMX_COMPONENTTYPE *)pContext->sCreateParams.hComponent; | ||
492 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
493 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
494 | pPort = (OMXBase_Port *)_DIO_GetPort(handle, pContext->sCreateParams.nPortIndex); | ||
495 | pAppCallbacks = (OMX_CALLBACKTYPE *)pContext->sCreateParams.pAppCallbacks; | ||
496 | |||
497 | switch( nCmdType ) { | ||
498 | /* Flush the queues or buffers on a port. Both Flush and Stop perform | ||
499 | the same operation i.e. send all the buffers back to the client */ | ||
500 | case OMX_DIO_CtrlCmd_Stop : | ||
501 | case OMX_DIO_CtrlCmd_Flush : | ||
502 | /* return all buffers to the IL client using EBD/FBD depending | ||
503 | * on the direction(input or output) of port */ | ||
504 | |||
505 | OSAL_GetPipeReadyMessageCount(pContext->pPipeHandle, &elementsInpipe); | ||
506 | |||
507 | while( elementsInpipe ) { | ||
508 | OSAL_ReadFromPipe(pContext->pPipeHandle, &pBuffHeader, | ||
509 | sizeof(pBuffHeader), &actualSize, OSAL_NO_SUSPEND); | ||
510 | elementsInpipe--; | ||
511 | if (((OMXBase_BufHdrPvtData *)(pBuffHeader->pPlatformPrivate))->bufSt != OWNED_BY_CLIENT) { | ||
512 | ((OMXBase_BufHdrPvtData *)(pBuffHeader->pPlatformPrivate))->bufSt = OWNED_BY_CLIENT; | ||
513 | if( OMX_DirInput == pPort->sPortDef.eDir ) { | ||
514 | eError = pAppCallbacks->EmptyBufferDone(pComp, | ||
515 | pComp->pApplicationPrivate, pBuffHeader); | ||
516 | } else if( OMX_DirOutput == pPort->sPortDef.eDir ) { | ||
517 | pBuffHeader->nFilledLen = 0; | ||
518 | eError = pAppCallbacks->FillBufferDone(pComp, | ||
519 | pComp->pApplicationPrivate, pBuffHeader); | ||
520 | } | ||
521 | } | ||
522 | } | ||
523 | break; | ||
524 | |||
525 | case OMX_DIO_CtrlCmd_Start : | ||
526 | /*If there are buffers in the pipe in case of pause to executing | ||
527 | then start processing them*/ | ||
528 | OSAL_GetPipeReadyMessageCount(pContext->pPipeHandle, &elementsInpipe); | ||
529 | if( elementsInpipe ) { | ||
530 | pBaseCompPvt->fpInvokeProcessFunction(pComp, DATAEVENT); | ||
531 | } else { | ||
532 | OSAL_ErrorTrace(" Nothing to do "); | ||
533 | } | ||
534 | break; | ||
535 | |||
536 | case OMX_DIO_CtrlCmd_GetCtrlAttribute : | ||
537 | /*Buffer should be available when calling GetAttribute*/ | ||
538 | tStatus = OSAL_IsPipeReady(pContext->pPipeHandle); | ||
539 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorUndefined); | ||
540 | |||
541 | tStatus = OSAL_ReadFromPipe(pContext->pPipeHandle, &pBuffHeader, | ||
542 | sizeof(pBuffHeader), &actualSize, OSAL_NO_SUSPEND); | ||
543 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorUndefined); | ||
544 | if( !(pBuffHeader->nFlags & OMX_BUFFERFLAG_CODECCONFIG)) { | ||
545 | /*This buffer does not contain codec config*/ | ||
546 | eError = OMX_ErrorUndefined; | ||
547 | /*Write the buffer back to front of pipe*/ | ||
548 | OSAL_WriteToFrontOfPipe(pContext->pPipeHandle, &pBuffHeader, | ||
549 | sizeof(pBuffHeader), OSAL_SUSPEND); | ||
550 | goto EXIT; | ||
551 | } | ||
552 | pAttrDesc = ((OMXBase_CodecConfigBuf*)pParams)->sBuffer; | ||
553 | if( pAttrDesc->size < pBuffHeader->nFilledLen ) { | ||
554 | tStatus = OSAL_WriteToFrontOfPipe(pContext->pPipeHandle, | ||
555 | &pBuffHeader, sizeof(pBuffHeader), OSAL_SUSPEND); | ||
556 | pAttrDesc->size = pBuffHeader->nFilledLen; | ||
557 | |||
558 | eError = (OMX_ERRORTYPE)OMX_TI_WarningInsufficientAttributeSize; | ||
559 | goto EXIT; | ||
560 | } | ||
561 | pAttrDesc->size = pBuffHeader->nFilledLen; | ||
562 | OSAL_Memcpy(H2P(pAttrDesc), pBuffHeader->pBuffer + pBuffHeader->nOffset, | ||
563 | pAttrDesc->size); | ||
564 | |||
565 | /*Send the buffer back*/ | ||
566 | pBuffHeader->nFlags &= (~OMX_BUFFERFLAG_CODECCONFIG); | ||
567 | if (((OMXBase_BufHdrPvtData *)(pBuffHeader->pPlatformPrivate))->bufSt != OWNED_BY_CLIENT) { | ||
568 | ((OMXBase_BufHdrPvtData *)(pBuffHeader->pPlatformPrivate))->bufSt = OWNED_BY_CLIENT; | ||
569 | if( OMX_DirInput == pPort->sPortDef.eDir ) { | ||
570 | eError = pAppCallbacks->EmptyBufferDone(pComp, | ||
571 | pComp->pApplicationPrivate, pBuffHeader); | ||
572 | } else if( OMX_DirOutput == pPort->sPortDef.eDir ) { | ||
573 | /*So that the other port does not try to interpret any garbage | ||
574 | data that may be present*/ | ||
575 | pBuffHeader->nFilledLen = 0; | ||
576 | eError = pAppCallbacks->FillBufferDone(pComp, | ||
577 | pComp->pApplicationPrivate, pBuffHeader); | ||
578 | } | ||
579 | } | ||
580 | break; | ||
581 | |||
582 | case OMX_DIO_CtrlCmd_SetCtrlAttribute : | ||
583 | /*Buffer should be available when calling SetAttribute*/ | ||
584 | tStatus = OSAL_IsPipeReady(pContext->pPipeHandle); | ||
585 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorUndefined); | ||
586 | |||
587 | tStatus = OSAL_ReadFromPipe(pContext->pPipeHandle, &pBuffHeader, | ||
588 | sizeof(pBuffHeader), &actualSize, OSAL_NO_SUSPEND); | ||
589 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorUndefined); | ||
590 | |||
591 | pBuffHeader->nFlags |= OMX_BUFFERFLAG_CODECCONFIG; | ||
592 | pAttrDesc = ((OMXBase_CodecConfigBuf *)pParams)->sBuffer; | ||
593 | if( pBuffHeader->nAllocLen < pAttrDesc->size ) { | ||
594 | OSAL_ErrorTrace("Cannot send attribute data, size is too large"); | ||
595 | tStatus = OSAL_WriteToFrontOfPipe(pContext->pPipeHandle, | ||
596 | &pBuffHeader, sizeof(pBuffHeader), OSAL_SUSPEND); | ||
597 | eError = OMX_ErrorInsufficientResources; | ||
598 | goto EXIT; | ||
599 | } | ||
600 | pBuffHeader->nFilledLen = pAttrDesc->size; | ||
601 | OSAL_Memcpy(pBuffHeader->pBuffer, pAttrDesc->ptr, pAttrDesc->size); | ||
602 | if (((OMXBase_BufHdrPvtData *)(pBuffHeader->pPlatformPrivate))->bufSt != OWNED_BY_CLIENT) { | ||
603 | ((OMXBase_BufHdrPvtData *)(pBuffHeader->pPlatformPrivate))->bufSt = OWNED_BY_CLIENT; | ||
604 | /*Send the buffer*/ | ||
605 | if( OMX_DirInput == pPort->sPortDef.eDir ) { | ||
606 | eError = pAppCallbacks->EmptyBufferDone(pComp, | ||
607 | pComp->pApplicationPrivate, pBuffHeader); | ||
608 | } else if( OMX_DirOutput == pPort->sPortDef.eDir ) { | ||
609 | eError = pAppCallbacks->FillBufferDone(pComp, | ||
610 | pComp->pApplicationPrivate, pBuffHeader); | ||
611 | } | ||
612 | } | ||
613 | break; | ||
614 | |||
615 | default : | ||
616 | OSAL_ErrorTrace(" Invalid Command received \n"); | ||
617 | eError = OMX_ErrorUnsupportedIndex; | ||
618 | break; | ||
619 | } | ||
620 | |||
621 | EXIT: | ||
622 | return (eError); | ||
623 | } | ||
624 | |||
625 | |||
626 | /* | ||
627 | * DIO Non Tunnel GEtCount | ||
628 | */ | ||
629 | static OMX_ERRORTYPE OMX_DIO_NonTunnel_Getcount (OMX_HANDLETYPE handle, | ||
630 | OMX_U32 *pCount) | ||
631 | { | ||
632 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
633 | OMX_DIO_Object *hDIO = (OMX_DIO_Object *)handle; | ||
634 | DIO_NonTunnel_Attrs *pContext = NULL; | ||
635 | OMXBase_Port *pPort = NULL; | ||
636 | |||
637 | pContext = (DIO_NonTunnel_Attrs *)hDIO->pContext; | ||
638 | pPort = (OMXBase_Port *)_DIO_GetPort(handle, pContext->sCreateParams.nPortIndex); | ||
639 | if( pPort->bEosRecd && pPort->sPortDef.eDir == OMX_DirInput ) { | ||
640 | eError = (OMX_ERRORTYPE)OMX_TI_WarningEosReceived; | ||
641 | } | ||
642 | |||
643 | OSAL_GetPipeReadyMessageCount(pContext->pPipeHandle, (uint32_t*)pCount); | ||
644 | |||
645 | return (eError); | ||
646 | } | ||
647 | |||
648 | |||
diff --git a/libstagefrighthw/omx/base/OMX_BaseDIOPlugin.h b/libstagefrighthw/omx/base/OMX_BaseDIOPlugin.h new file mode 100644 index 0000000..3059afe --- /dev/null +++ b/libstagefrighthw/omx/base/OMX_BaseDIOPlugin.h | |||
@@ -0,0 +1,181 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 _OMX_BASE_DIO_PLUGIN_H | ||
18 | #define _OMX_BASE_DIO_PLUGIN_H | ||
19 | |||
20 | #ifdef _cplusplus | ||
21 | extern "C" { | ||
22 | #endif | ||
23 | |||
24 | #include <OMX_Core.h> | ||
25 | #include <OMX_Component.h> | ||
26 | |||
27 | #define OMX_BASE_MAXNAMELEN OMX_MAX_STRINGNAME_SIZE | ||
28 | |||
29 | /* The OMX_DIO_OpenMode enumeration is used to | ||
30 | * sepcify the open mode type i.e reader or writer | ||
31 | */ | ||
32 | typedef enum OMX_DIO_OpenMode { | ||
33 | OMX_DIO_READER = 0x0, | ||
34 | OMX_DIO_WRITER = 0x1 | ||
35 | }OMX_DIO_OpenMode; | ||
36 | |||
37 | /** OMX_DIO_CreateParams : | ||
38 | * This structure contains the parameters required to | ||
39 | * create DIO object | ||
40 | * | ||
41 | * @param cChannelName : channel name | ||
42 | * @param hComponent : Handle of Component | ||
43 | * @param nPortIndex : Index of the port | ||
44 | * @param pAppCallbacks : Application callbacks | ||
45 | */ | ||
46 | typedef struct OMX_DIO_CreateParams { | ||
47 | char cChannelName[OMX_BASE_MAXNAMELEN]; | ||
48 | OMX_HANDLETYPE hComponent; | ||
49 | OMX_U8 nPortIndex; | ||
50 | OMX_CALLBACKTYPE *pAppCallbacks; | ||
51 | }OMX_DIO_CreateParams; | ||
52 | |||
53 | |||
54 | /** OMX_DIO_OpenParams : | ||
55 | * This structure contains the open parameters for DIO object | ||
56 | * @param nMode : open mode reader or writer | ||
57 | * @param bCacheFlag : cache access flag - true if buffer is accessed via | ||
58 | * processor/cache | ||
59 | * @param nBufSize : used by non-tunnel open as allocate buffer call | ||
60 | * can specify a different size | ||
61 | */ | ||
62 | typedef struct OMX_DIO_OpenParams { | ||
63 | OMX_U32 nMode; | ||
64 | OMX_BOOL bCacheFlag; | ||
65 | OMX_U32 nBufSize; | ||
66 | }OMX_DIO_OpenParams; | ||
67 | |||
68 | typedef OMX_ERRORTYPE (*OMX_DIO_Init)(OMX_IN OMX_HANDLETYPE hComponent, | ||
69 | OMX_IN OMX_PTR pCreateParams); | ||
70 | |||
71 | /* OMX_DIO_Register : | ||
72 | * This structure contains the params used to register the DIO object | ||
73 | * @param pChannelName : Channel Name | ||
74 | * @param pInitialize : DIO instace initialization function | ||
75 | */ | ||
76 | typedef struct OMX_DIO_Register { | ||
77 | const char *cChannelType; | ||
78 | OMX_DIO_Init pInitialize; | ||
79 | }OMX_DIO_Register; | ||
80 | |||
81 | extern OMX_DIO_Register OMX_DIO_Registered[2]; | ||
82 | /* | ||
83 | * The OMX_DIO_CtrlCmd_TYPE : This enumeration is used to | ||
84 | * specify the action in the | ||
85 | * OMX_DIO_Control Macro. | ||
86 | * | ||
87 | * @ param OMX_DIO_CtrlCmd_Flush : Flush the buffers on this port. | ||
88 | * This command is used only by | ||
89 | * omx_base for now. | ||
90 | * @ param OMX_DIO_CtrlCmd_Start : Start buffer processing on this | ||
91 | * port. This command is used only by | ||
92 | * omx_base for now. | ||
93 | * @ param OMX_DIO_CtrlCmd_Stop : Stop buffer processing on this | ||
94 | * port. This command is used only by | ||
95 | * omx_base for now. | ||
96 | * @ param OMX_DIO_CtrlCmd_GetCtrlAttribute : To get the attribute pending | ||
97 | * on this port. A pointer to structure | ||
98 | * of type | ||
99 | * OMXBase_CodecConfig is | ||
100 | * passed as the parameter to the | ||
101 | * control command. This should be used | ||
102 | * if dio_dequeue returns | ||
103 | * OMX_WarningAttributePending | ||
104 | * indicating that an attribute buffer | ||
105 | * is pending. | ||
106 | * @ param OMX_DIO_CtrlCmd_SetCtrlAttribute : To send some attribute on | ||
107 | * this port. A pointer to structure of | ||
108 | * type OMXBase_CodecConfig | ||
109 | * is passed as the parameter to the | ||
110 | * control command. | ||
111 | * @ param OMX_DIO_CtrlCmd_ExtnStart : If some specific DIO | ||
112 | * implementation wants to have control | ||
113 | * commands specific for that DIO then | ||
114 | * these extended commands can be added | ||
115 | * after this. | ||
116 | */ | ||
117 | typedef enum OMX_DIO_CtrlCmdType { | ||
118 | OMX_DIO_CtrlCmd_Flush = 0x1, | ||
119 | OMX_DIO_CtrlCmd_Start = 0x2, | ||
120 | OMX_DIO_CtrlCmd_Stop = 0x3, | ||
121 | OMX_DIO_CtrlCmd_GetCtrlAttribute = 0x4, | ||
122 | OMX_DIO_CtrlCmd_SetCtrlAttribute = 0x5, | ||
123 | OMX_DIO_CtrlCmd_ExtnStart = 0xA | ||
124 | }OMX_DIO_CtrlCmdType; | ||
125 | |||
126 | |||
127 | /** OMX_DIO_Object : | ||
128 | * This structure contains the params and interface to access the DIO object | ||
129 | * | ||
130 | * @param pContext : pointer to the DIO private data area | ||
131 | * @param (*open) : DIO object open Implementation | ||
132 | * @param (*close) : DIO object close Implementation | ||
133 | * @param (*queue) : DIO object queue Implementation | ||
134 | * @param (*dequeue) : DIO object dequeu Implementation | ||
135 | * @param (*send) : DIO object send Implementation | ||
136 | * @param (*cancel) : DIO object cancel Implementation | ||
137 | * @param (*control) : DIO object control Implementation | ||
138 | * @param (*getcount) : DIO object getcount Implementation | ||
139 | * @param (*deinit) : DIO object deinit Implementation | ||
140 | * @param bOpened : Indicates whether DIO has been opened on this port | ||
141 | */ | ||
142 | typedef struct OMX_DIO_Object { | ||
143 | |||
144 | OMX_PTR pContext; | ||
145 | |||
146 | OMX_ERRORTYPE (*open)(OMX_HANDLETYPE handle, | ||
147 | OMX_DIO_OpenParams *pParams); | ||
148 | |||
149 | OMX_ERRORTYPE (*close)(OMX_HANDLETYPE handle); | ||
150 | |||
151 | OMX_ERRORTYPE (*queue)(OMX_HANDLETYPE handle, | ||
152 | OMX_PTR pBuffHeader); | ||
153 | |||
154 | OMX_ERRORTYPE (*dequeue)(OMX_HANDLETYPE handle, | ||
155 | OMX_PTR *pBuffHeader); | ||
156 | |||
157 | OMX_ERRORTYPE (*send)(OMX_HANDLETYPE handle, | ||
158 | OMX_PTR pBuffHeader); | ||
159 | |||
160 | OMX_ERRORTYPE (*cancel)(OMX_HANDLETYPE handle, | ||
161 | OMX_PTR pBuffHeader); | ||
162 | |||
163 | OMX_ERRORTYPE (*control)(OMX_HANDLETYPE handle, | ||
164 | OMX_DIO_CtrlCmdType nCmdType, | ||
165 | OMX_PTR pParams); | ||
166 | |||
167 | OMX_ERRORTYPE (*getcount)(OMX_HANDLETYPE handle, | ||
168 | OMX_U32 *pCount); | ||
169 | |||
170 | OMX_ERRORTYPE (*deinit)(OMX_HANDLETYPE handle); | ||
171 | |||
172 | OMX_BOOL bOpened; | ||
173 | |||
174 | }OMX_DIO_Object; | ||
175 | |||
176 | #ifdef __cplusplus | ||
177 | } | ||
178 | #endif | ||
179 | |||
180 | #endif | ||
181 | |||
diff --git a/libstagefrighthw/omx/base/OMX_BaseDIOTable.c b/libstagefrighthw/omx/base/OMX_BaseDIOTable.c new file mode 100644 index 0000000..d0747a4 --- /dev/null +++ b/libstagefrighthw/omx/base/OMX_BaseDIOTable.c | |||
@@ -0,0 +1,28 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 <string.h> | ||
18 | |||
19 | #include <OMX_BaseInternal.h> | ||
20 | #include <OMX_BaseDIOPlugin.h> | ||
21 | |||
22 | extern OMX_ERRORTYPE OMX_DIO_NonTunnel_Init(OMX_HANDLETYPE handle, OMX_PTR pCreateParams); | ||
23 | |||
24 | OMX_DIO_Register OMX_DIO_Registered[] = | ||
25 | { | ||
26 | { "OMX.DIO.NONTUNNEL", &OMX_DIO_NonTunnel_Init }, | ||
27 | { NULL, NULL } | ||
28 | }; | ||
diff --git a/libstagefrighthw/omx/base/OMX_BaseInternal.c b/libstagefrighthw/omx/base/OMX_BaseInternal.c new file mode 100644 index 0000000..ef1f97e --- /dev/null +++ b/libstagefrighthw/omx/base/OMX_BaseInternal.c | |||
@@ -0,0 +1,1588 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 | #define LOG_TAG "OMX_BASE_INTERNAL" | ||
18 | |||
19 | #include <string.h> | ||
20 | |||
21 | #include <OMX_Core.h> | ||
22 | #include <OMX_Component.h> | ||
23 | #include <OMX_Base.h> | ||
24 | #include <OMX_BaseDIOPlugin.h> | ||
25 | |||
26 | #include <osal_semaphores.h> | ||
27 | |||
28 | #define OMXBase_TASKDEL_TRIES 1000 | ||
29 | #define OMXBase_TASKDEL_SLEEP 2 | ||
30 | #define BUFFER_ALLOC_FREE_TIMEOUT 900 //900ms | ||
31 | |||
32 | #define OMX_BASE_HANDLE_IDLE_TO_LOADED_TRANSITION() do { \ | ||
33 | for( i=0; i < pBaseComp->nNumPorts; i++ ) \ | ||
34 | { \ | ||
35 | pPort = pBaseComp->pPorts[i]; \ | ||
36 | if( pPort->pBufAllocFreeEvent ) \ | ||
37 | { \ | ||
38 | tStatus = OSAL_SetEvent(pPort->pBufAllocFreeEvent, \ | ||
39 | BUF_FAIL_EVENT, OSAL_EVENT_OR); \ | ||
40 | if( tStatus != OSAL_ErrNone ) { \ | ||
41 | eError = OMX_ErrorUndefined; } \ | ||
42 | } \ | ||
43 | } \ | ||
44 | retEvents = 0; \ | ||
45 | tStatus = OSAL_RetrieveEvent( \ | ||
46 | pBaseCompPvt->pErrorCmdcompleteEvent, \ | ||
47 | ERROR_EVENT, OSAL_EVENT_OR_CONSUME, &retEvents, \ | ||
48 | STATE_TRANSITION_LONG_TIMEOUT); \ | ||
49 | OMX_CHECK(tStatus == OSAL_ErrNone, \ | ||
50 | OMX_ErrorUndefined); \ | ||
51 | } while( 0 ) | ||
52 | |||
53 | |||
54 | /* | ||
55 | * OMX Base Private Init | ||
56 | */ | ||
57 | OMX_ERRORTYPE OMXBase_PrivateInit(OMX_HANDLETYPE hComponent) | ||
58 | { | ||
59 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
60 | // OMX_ERRORTYPE eTmpError = OMX_ErrorNone; | ||
61 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
62 | OMX_COMPONENTTYPE *pComp = NULL; | ||
63 | OMXBaseComp *pBaseComp = NULL; | ||
64 | |||
65 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
66 | |||
67 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
68 | pBaseComp = (OMXBaseComp*)pComp->pComponentPrivate; | ||
69 | OMX_CHECK(pBaseComp != NULL, OMX_ErrorBadParameter); | ||
70 | OMXBaseComp_Pvt *pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
71 | /*Create the new state mutex*/ | ||
72 | tStatus = OSAL_CreateMutex(&(pBaseCompPvt->pNewStateMutex)); | ||
73 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorInsufficientResources); | ||
74 | |||
75 | /* create a fixed size command pipe to queueup commands */ | ||
76 | tStatus = OSAL_CreatePipe(&(pBaseCompPvt->pCmdPipe), | ||
77 | OMXBase_MAXCMDS * sizeof(OMXBase_CmdParams), | ||
78 | sizeof(OMXBase_CmdParams), 1); | ||
79 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorInsufficientResources); | ||
80 | |||
81 | |||
82 | /* create a fixed size pipe to queueup command data pointers */ | ||
83 | tStatus = OSAL_CreatePipe(&(pBaseCompPvt->pCmdDataPipe), | ||
84 | OMXBase_MAXCMDS * sizeof(OMX_PTR), | ||
85 | sizeof(OMX_PTR), 1); | ||
86 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorInsufficientResources); | ||
87 | |||
88 | /*create an Event for Command completion to be set by Dervived Component */ | ||
89 | tStatus = OSAL_CreateEvent(&(pBaseCompPvt->pCmdCompleteEvent)); | ||
90 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorInsufficientResources); | ||
91 | |||
92 | /*create an Event for state transition notifications for complete tear down of compoenent */ | ||
93 | tStatus = OSAL_CreateEvent(&(pBaseCompPvt->pErrorCmdcompleteEvent)); | ||
94 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorInsufficientResources); | ||
95 | |||
96 | /*Create mutex for cmd pipe*/ | ||
97 | tStatus = OSAL_CreateMutex(&(pBaseCompPvt->pCmdPipeMutex)); | ||
98 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorInsufficientResources); | ||
99 | |||
100 | pBaseCompPvt->fpInvokeProcessFunction = OMXBase_ProcessEvents; | ||
101 | |||
102 | tStatus = OSAL_CreateEvent(&(pBaseCompPvt->pTriggerEvent)); | ||
103 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorInsufficientResources); | ||
104 | |||
105 | /*Create mutex for port disable*/ | ||
106 | tStatus = OSAL_CreateMutex(&(pBaseCompPvt->pPortDisableMutex)); | ||
107 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorInsufficientResources); | ||
108 | |||
109 | OSAL_Memcpy(pBaseCompPvt->cTaskName, pBaseComp->cComponentName, strlen(pBaseComp->cComponentName)); | ||
110 | pBaseCompPvt->nStackSize = OMX_BASE_THREAD_STACKSIZE; | ||
111 | pBaseCompPvt->nPrioirty = OMX_BASE_THREAD_PRIORITY; | ||
112 | |||
113 | tStatus = OSAL_CreateTask(&pBaseCompPvt->pThreadId, | ||
114 | (OSAL_TaskProc)OMXBase_CompThreadEntry, 0, | ||
115 | (void *)hComponent, | ||
116 | pBaseCompPvt->nStackSize, | ||
117 | pBaseCompPvt->nPrioirty, | ||
118 | (OMX_S8 *)pBaseCompPvt->cTaskName); | ||
119 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorInsufficientResources); | ||
120 | |||
121 | pBaseCompPvt->fpInvokeProcessFunction = OMXBase_ProcessTriggerEvent; | ||
122 | |||
123 | /* Set hooks from Derived to Base communicattion */ | ||
124 | pBaseCompPvt->fpDioGetCount = OMXBase_DIO_GetCount; | ||
125 | pBaseCompPvt->fpDioQueue = OMXBase_DIO_Queue; | ||
126 | pBaseCompPvt->fpDioDequeue = OMXBase_DIO_Dequeue; | ||
127 | pBaseCompPvt->fpDioSend = OMXBase_DIO_Send; | ||
128 | pBaseCompPvt->fpDioCancel = OMXBase_DIO_Cancel; | ||
129 | pBaseCompPvt->fpDioControl = OMXBase_DIO_Control; | ||
130 | |||
131 | EXIT: | ||
132 | return eError; | ||
133 | } | ||
134 | |||
135 | /* | ||
136 | * OMX Base Private DeInit | ||
137 | */ | ||
138 | |||
139 | OMX_ERRORTYPE OMXBase_PrivateDeInit(OMX_HANDLETYPE hComponent) | ||
140 | { | ||
141 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
142 | // OMX_ERRORTYPE eTmpError = OMX_ErrorNone; | ||
143 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
144 | OMX_COMPONENTTYPE *pComp = NULL; | ||
145 | OMXBaseComp *pBaseComp = NULL; | ||
146 | OMXBaseComp_Pvt *pBaseCompPvt = NULL; | ||
147 | OMX_U32 nTries = 0; | ||
148 | uint32_t nCount = 0; | ||
149 | OMX_PTR pData = NULL; | ||
150 | uint32_t nActualSize = 0; | ||
151 | |||
152 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
153 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
154 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
155 | OMX_CHECK(pBaseComp != NULL, OMX_ErrorBadParameter); | ||
156 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
157 | |||
158 | /* set an ENDEVENT before destroying thread */ | ||
159 | pBaseCompPvt->fpInvokeProcessFunction(hComponent, ENDEVENT); | ||
160 | tStatus = OSAL_DeleteTask(pBaseCompPvt->pThreadId); | ||
161 | |||
162 | while( tStatus == OSAL_ErrNotReady && | ||
163 | nTries < OMXBase_TASKDEL_TRIES ) { | ||
164 | //Wait for some time and try again | ||
165 | OSAL_SleepTask(OMXBase_TASKDEL_SLEEP); | ||
166 | nTries++; | ||
167 | tStatus = OSAL_DeleteTask(pBaseCompPvt->pThreadId); | ||
168 | } | ||
169 | |||
170 | /* | ||
171 | * Obtain the mutex after deleting the task. The task may be | ||
172 | * currently executing and may need access to the mutex to | ||
173 | * properly exit | ||
174 | */ | ||
175 | OSAL_ObtainMutex(pBaseCompPvt->pNewStateMutex, OSAL_SUSPEND); | ||
176 | |||
177 | if( tStatus != OSAL_ErrNone ) { | ||
178 | eError = OMX_ErrorTimeout; | ||
179 | OSAL_ErrorTrace("Error while deleting task"); | ||
180 | } | ||
181 | if( pBaseCompPvt->pTriggerEvent ) { | ||
182 | tStatus = OSAL_DeleteEvent(pBaseCompPvt->pTriggerEvent); | ||
183 | if( tStatus != OSAL_ErrNone ) { | ||
184 | eError = OMX_ErrorUndefined; | ||
185 | } | ||
186 | pBaseCompPvt->pTriggerEvent = NULL; | ||
187 | } | ||
188 | |||
189 | if( pBaseCompPvt->pCmdCompleteEvent ) { | ||
190 | tStatus = OSAL_DeleteEvent(pBaseCompPvt->pCmdCompleteEvent); | ||
191 | if( tStatus != OSAL_ErrNone ) { | ||
192 | eError = OMX_ErrorUndefined; | ||
193 | } | ||
194 | pBaseCompPvt->pCmdCompleteEvent = NULL; | ||
195 | } | ||
196 | if( pBaseCompPvt->pErrorCmdcompleteEvent ) { | ||
197 | tStatus = OSAL_DeleteEvent(pBaseCompPvt->pErrorCmdcompleteEvent); | ||
198 | if( tStatus != OSAL_ErrNone ) { | ||
199 | eError = OMX_ErrorUndefined; | ||
200 | } | ||
201 | pBaseCompPvt->pErrorCmdcompleteEvent = NULL; | ||
202 | } | ||
203 | if( pBaseCompPvt->pCmdPipe ) { | ||
204 | tStatus = OSAL_DeletePipe(pBaseCompPvt->pCmdPipe); | ||
205 | if( tStatus != OSAL_ErrNone ) { | ||
206 | eError = OMX_ErrorUndefined; | ||
207 | } | ||
208 | pBaseCompPvt->pCmdPipe = NULL; | ||
209 | } | ||
210 | if( pBaseCompPvt->pCmdDataPipe ) { | ||
211 | /*If pipe still has some data then empty the data and free the memory*/ | ||
212 | tStatus = OSAL_GetPipeReadyMessageCount(pBaseCompPvt->pCmdDataPipe, | ||
213 | &nCount); | ||
214 | if( tStatus != OSAL_ErrNone ) { | ||
215 | eError = OMX_ErrorUndefined; | ||
216 | } else { | ||
217 | while( nCount > 0 ) { | ||
218 | tStatus = OSAL_ReadFromPipe(pBaseCompPvt->pCmdDataPipe, | ||
219 | pData, sizeof(OMX_PTR), &nActualSize, OSAL_NO_SUSPEND); | ||
220 | if( tStatus != OSAL_ErrNone ) { | ||
221 | eError = OMX_ErrorUndefined; | ||
222 | break; | ||
223 | } | ||
224 | OSAL_Free(pData); | ||
225 | nCount--; | ||
226 | } | ||
227 | } | ||
228 | tStatus = OSAL_DeletePipe(pBaseCompPvt->pCmdDataPipe); | ||
229 | if( tStatus != OSAL_ErrNone ) { | ||
230 | eError = OMX_ErrorUndefined; | ||
231 | } | ||
232 | pBaseCompPvt->pCmdDataPipe = NULL; | ||
233 | } | ||
234 | if( pBaseCompPvt->pCmdPipeMutex ) { | ||
235 | tStatus = OSAL_DeleteMutex(pBaseCompPvt->pCmdPipeMutex); | ||
236 | if( tStatus != OSAL_ErrNone ) { | ||
237 | eError = OMX_ErrorUndefined; | ||
238 | } | ||
239 | pBaseCompPvt->pCmdPipeMutex = NULL; | ||
240 | } | ||
241 | if (pBaseCompPvt->pPortDisableMutex) { | ||
242 | tStatus = OSAL_DeleteMutex(pBaseCompPvt->pPortDisableMutex); | ||
243 | if( tStatus != OSAL_ErrNone ) { | ||
244 | eError = OMX_ErrorUndefined; | ||
245 | } | ||
246 | pBaseCompPvt->pPortDisableMutex = NULL; | ||
247 | } | ||
248 | |||
249 | OSAL_ReleaseMutex(pBaseCompPvt->pNewStateMutex); | ||
250 | |||
251 | if( pBaseCompPvt->pNewStateMutex ) { | ||
252 | tStatus = OSAL_DeleteMutex(pBaseCompPvt->pNewStateMutex); | ||
253 | if( tStatus != OSAL_ErrNone ) { | ||
254 | eError = OMX_ErrorUndefined; | ||
255 | } | ||
256 | pBaseCompPvt->pNewStateMutex = NULL; | ||
257 | } | ||
258 | |||
259 | EXIT: | ||
260 | return (eError); | ||
261 | } | ||
262 | |||
263 | /* | ||
264 | * OMX Base InitializePorts | ||
265 | */ | ||
266 | OMX_ERRORTYPE OMXBase_InitializePorts(OMX_HANDLETYPE hComponent) | ||
267 | { | ||
268 | OMX_COMPONENTTYPE *pComp = NULL; | ||
269 | OMXBaseComp *pBaseComp = NULL; | ||
270 | OMX_ERRORTYPE eError = OMX_ErrorNone, eTmpError = OMX_ErrorNone; | ||
271 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
272 | OMX_U32 i = 0; | ||
273 | |||
274 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
275 | |||
276 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
277 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
278 | |||
279 | pBaseComp->pPorts = (OMXBase_Port **)OSAL_Malloc(sizeof(OMXBase_Port *) * | ||
280 | pBaseComp->nNumPorts); | ||
281 | OMX_CHECK(pBaseComp->pPorts != NULL, OMX_ErrorInsufficientResources); | ||
282 | OSAL_Memset(pBaseComp->pPorts, 0, sizeof(OMXBase_Port *) * | ||
283 | pBaseComp->nNumPorts); | ||
284 | |||
285 | for( i = 0; i < pBaseComp->nNumPorts; i++ ) { | ||
286 | pBaseComp->pPorts[i] = (OMXBase_Port *)OSAL_Malloc(sizeof(OMXBase_Port)); | ||
287 | OMX_CHECK(pBaseComp->pPorts[i] != NULL, OMX_ErrorInsufficientResources); | ||
288 | OSAL_Memset(pBaseComp->pPorts[i], 0x0, sizeof(OMXBase_Port)); | ||
289 | |||
290 | OMX_BASE_INIT_STRUCT_PTR(&(pBaseComp->pPorts[i]->sPortDef), | ||
291 | OMX_PARAM_PORTDEFINITIONTYPE); | ||
292 | pBaseComp->pPorts[i]->sPortDef.nPortIndex = i; | ||
293 | |||
294 | tStatus = OSAL_CreateEvent(&(pBaseComp->pPorts[i]->pBufAllocFreeEvent)); | ||
295 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorInsufficientResources); | ||
296 | tStatus = OSAL_CreateSemaphore(&(pBaseComp->pPorts[i]->pDioOpenCloseSem), 0); | ||
297 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorInsufficientResources); | ||
298 | } | ||
299 | |||
300 | EXIT: | ||
301 | if( OMX_ErrorNone != eError ) { | ||
302 | eTmpError = eError; | ||
303 | eError = OMXBase_DeinitializePorts(hComponent); | ||
304 | eError = eTmpError; | ||
305 | } | ||
306 | return (eError); | ||
307 | } | ||
308 | |||
309 | /* | ||
310 | * OMX Base DeInitialize Ports | ||
311 | */ | ||
312 | OMX_ERRORTYPE OMXBase_DeinitializePorts(OMX_HANDLETYPE hComponent) | ||
313 | { | ||
314 | OMX_COMPONENTTYPE *pComp = NULL; | ||
315 | OMXBaseComp *pBaseComp = NULL; | ||
316 | OMXBase_Port *pPort = NULL; | ||
317 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
318 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
319 | OMX_U32 i = 0; | ||
320 | |||
321 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
322 | |||
323 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
324 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
325 | OMX_CHECK(pBaseComp != NULL, eError); | ||
326 | |||
327 | for( i=0; i < pBaseComp->nNumPorts; i++ ) { | ||
328 | if( !(pBaseComp->pPorts)) { | ||
329 | break; | ||
330 | } | ||
331 | pPort = pBaseComp->pPorts[i]; | ||
332 | if( pPort == NULL ) { | ||
333 | continue; | ||
334 | } | ||
335 | if( pPort->pDioOpenCloseSem ) { | ||
336 | tStatus = OSAL_DeleteSemaphore(pPort->pDioOpenCloseSem); | ||
337 | if( tStatus != OSAL_ErrNone ) { | ||
338 | eError = OMX_ErrorUndefined; | ||
339 | } | ||
340 | } | ||
341 | /*If any tasks are waiting on this event then send fail event to | ||
342 | indicate that component is being unloaded*/ | ||
343 | if( pPort->pBufAllocFreeEvent ) { | ||
344 | tStatus = OSAL_SetEvent(pPort->pBufAllocFreeEvent, | ||
345 | BUF_FAIL_EVENT, OSAL_EVENT_OR); | ||
346 | if( tStatus != OSAL_ErrNone ) { | ||
347 | eError = OMX_ErrorUndefined; | ||
348 | } | ||
349 | tStatus = OSAL_DeleteEvent(pPort->pBufAllocFreeEvent); | ||
350 | if( tStatus != OSAL_ErrNone ) { | ||
351 | eError = OMX_ErrorUndefined; | ||
352 | } | ||
353 | } | ||
354 | OSAL_Free(pPort); | ||
355 | pPort = NULL; | ||
356 | } | ||
357 | |||
358 | if( pBaseComp->pPorts ) { | ||
359 | OSAL_Free(pBaseComp->pPorts); | ||
360 | pBaseComp->pPorts = NULL; | ||
361 | } | ||
362 | |||
363 | EXIT: | ||
364 | return (eError); | ||
365 | } | ||
366 | |||
367 | |||
368 | /* | ||
369 | * OMX Base SetDefault Properties | ||
370 | */ | ||
371 | OMX_ERRORTYPE OMXBase_SetDefaultProperties(OMX_HANDLETYPE hComponent) | ||
372 | { | ||
373 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
374 | OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
375 | OMXBaseComp *pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
376 | OMX_U32 nIndx = 0; | ||
377 | |||
378 | for( nIndx = 0; nIndx < (pBaseComp->nNumPorts); nIndx++ ) { | ||
379 | pBaseComp->pPorts[nIndx]->sProps.nWatermark = 1; | ||
380 | /*Frame mode is the default mode*/ | ||
381 | pBaseComp->pPorts[nIndx]->sProps.eDataAccessMode = MemAccess_8Bit; | ||
382 | |||
383 | /*Buffer allocation type is set to default*/ | ||
384 | pBaseComp->pPorts[nIndx]->sProps.eBufMemoryType = MEM_CARVEOUT; | ||
385 | /*Number of component buffers set to 1*/ | ||
386 | pBaseComp->pPorts[nIndx]->sProps.nNumComponentBuffers = 1; | ||
387 | /*No bufefr params by default. To be used in case of 2D buffers*/ | ||
388 | // pBaseComp->pPortProperties[nIndx]->pBufParams = NULL; | ||
389 | pBaseComp->pPorts[nIndx]->sProps.nTimeoutForDequeue = OSAL_SUSPEND; | ||
390 | } | ||
391 | |||
392 | pBaseComp->bNotifyForAnyPort = OMX_TRUE; | ||
393 | |||
394 | return (eError); | ||
395 | } | ||
396 | |||
397 | |||
398 | /* | ||
399 | * OMX Base ThreadEntry | ||
400 | */ | ||
401 | void OMXBase_CompThreadEntry(void *arg) | ||
402 | { | ||
403 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
404 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
405 | OMXBaseComp *pBaseComp = NULL; | ||
406 | OMXBaseComp_Pvt *pBaseCompPvt = NULL; | ||
407 | OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)arg; | ||
408 | uint32_t retrievedEvents = 0; | ||
409 | |||
410 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
411 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
412 | |||
413 | while( 1 ) { | ||
414 | /* wait for Any of the event/s to process */ | ||
415 | tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pTriggerEvent, | ||
416 | (CMDEVENT | DATAEVENT | ENDEVENT), | ||
417 | OSAL_EVENT_OR_CONSUME, | ||
418 | &retrievedEvents, OSAL_SUSPEND); | ||
419 | OMX_CHECK(tStatus == OSAL_ErrNone, OMX_ErrorInsufficientResources); | ||
420 | /* terminate the process when it acquires an ENDEVENT */ | ||
421 | if( retrievedEvents & ENDEVENT ) { | ||
422 | break; | ||
423 | } | ||
424 | /* Process Event that has retrieved */ | ||
425 | if( retrievedEvents & CMDEVENT ) { | ||
426 | while( OSAL_IsPipeReady(pBaseCompPvt->pCmdPipe) == | ||
427 | OSAL_ErrNone ) { | ||
428 | eError = OMXBase_ProcessEvents(pComp, retrievedEvents); | ||
429 | /*Callback for error will be sent in the above function*/ | ||
430 | eError = OMX_ErrorNone; | ||
431 | } | ||
432 | retrievedEvents &= ~CMDEVENT; | ||
433 | } | ||
434 | if( retrievedEvents & DATAEVENT ) { | ||
435 | eError = OMXBase_ProcessEvents(pComp, retrievedEvents); | ||
436 | /*Callback for error will be sent in the above function*/ | ||
437 | eError = OMX_ErrorNone; | ||
438 | } | ||
439 | } | ||
440 | |||
441 | EXIT: | ||
442 | if( OMX_ErrorNone != eError ) { | ||
443 | pBaseCompPvt->sAppCallbacks.EventHandler((OMX_HANDLETYPE)pComp, | ||
444 | pComp->pApplicationPrivate, | ||
445 | OMX_EventError, eError, | ||
446 | 0, NULL); | ||
447 | } | ||
448 | } | ||
449 | |||
450 | |||
451 | /* | ||
452 | * OMX Base Disable Port | ||
453 | */ | ||
454 | OMX_ERRORTYPE OMXBase_DisablePort(OMX_HANDLETYPE hComponent, | ||
455 | OMX_U32 nParam) | ||
456 | { | ||
457 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
458 | OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
459 | OMXBaseComp *pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
460 | OMXBase_Port *pPort = NULL; | ||
461 | OMX_U32 nStartPortNum; | ||
462 | |||
463 | nStartPortNum = pBaseComp->nMinStartPortIndex; | ||
464 | |||
465 | pPort = pBaseComp->pPorts[nParam - nStartPortNum]; | ||
466 | /* If comp is in loaded state, then there wont be any buffers to free up */ | ||
467 | if((pBaseComp->tCurState == OMX_StateLoaded) | ||
468 | || (pBaseComp->tCurState == OMX_StateWaitForResources)) { | ||
469 | goto EXIT; | ||
470 | } | ||
471 | eError = OMXBase_DIO_Control(hComponent, nParam, | ||
472 | OMX_DIO_CtrlCmd_Stop, NULL); | ||
473 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
474 | |||
475 | EXIT: | ||
476 | return (eError); | ||
477 | |||
478 | } | ||
479 | |||
480 | /* | ||
481 | * OMX Base EnablePort | ||
482 | */ | ||
483 | OMX_ERRORTYPE OMXBase_EnablePort(OMX_HANDLETYPE hComponent, | ||
484 | OMX_U32 nParam) | ||
485 | { | ||
486 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
487 | OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
488 | OMXBaseComp *pBaseComp = (OMXBaseComp *) pComp->pComponentPrivate; | ||
489 | OMXBase_Port *pPort = NULL; | ||
490 | OMX_U32 nStartPortNum = 0; | ||
491 | OMX_DIO_OpenParams sDIOParams; | ||
492 | |||
493 | nStartPortNum = pBaseComp->nMinStartPortIndex; | ||
494 | |||
495 | pPort = pBaseComp->pPorts[nParam - nStartPortNum]; | ||
496 | if( pBaseComp->tCurState != OMX_StateLoaded && | ||
497 | pBaseComp->tCurState != OMX_StateWaitForResources ) { | ||
498 | if( pPort->sPortDef.eDir == OMX_DirOutput ) { | ||
499 | sDIOParams.nMode = OMX_DIO_WRITER; | ||
500 | } else { | ||
501 | sDIOParams.nMode = OMX_DIO_READER; | ||
502 | } | ||
503 | } | ||
504 | |||
505 | return (eError); | ||
506 | } | ||
507 | |||
508 | /* | ||
509 | * OMX Base Flush Buffers | ||
510 | */ | ||
511 | OMX_ERRORTYPE OMXBase_FlushBuffers(OMX_HANDLETYPE hComponent, | ||
512 | OMX_U32 nParam) | ||
513 | { | ||
514 | return(OMXBase_DIO_Control(hComponent, nParam, OMX_DIO_CtrlCmd_Flush, | ||
515 | NULL)); | ||
516 | } | ||
517 | |||
518 | |||
519 | /* | ||
520 | * OMX Base Handle Transition | ||
521 | */ | ||
522 | OMX_ERRORTYPE OMXBase_HandleStateTransition(OMX_HANDLETYPE hComponent, | ||
523 | OMX_U32 nParam) | ||
524 | { | ||
525 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
526 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
527 | OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
528 | OMXBaseComp *pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
529 | OMXBaseComp_Pvt *pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
530 | OMXBase_Port *pPort = NULL; | ||
531 | OMX_U32 i = 0, nStartPortNum = 0, nPorts = 0; | ||
532 | uint32_t retEvents = 0; | ||
533 | OMX_DIO_OpenParams sDIOParams; | ||
534 | |||
535 | nPorts = pBaseComp->nNumPorts; | ||
536 | nStartPortNum = pBaseComp->nMinStartPortIndex; | ||
537 | |||
538 | /* currnet and new state should not be same */ | ||
539 | OMX_CHECK(pBaseComp->tCurState != pBaseComp->tNewState, OMX_ErrorSameState); | ||
540 | /* Transition to invaild state by IL client is disallowed */ | ||
541 | if( pBaseComp->tNewState == OMX_StateInvalid ) { | ||
542 | /* Notify to Derived Component */ | ||
543 | pBaseComp->fpCommandNotify(hComponent, OMX_CommandStateSet, nParam, NULL); | ||
544 | /*Derived component has returned*/ | ||
545 | tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pCmdCompleteEvent, | ||
546 | OMXBase_CmdStateSet, OSAL_EVENT_OR_CONSUME, | ||
547 | &retEvents, OSAL_SUSPEND); | ||
548 | OMX_CHECK(tStatus == OSAL_ErrNone, OMX_ErrorInsufficientResources); | ||
549 | |||
550 | /* | ||
551 | For this case we wont go through OMXBase_EventNotifyToClient function | ||
552 | The state will be set here and error callback will be made by | ||
553 | OMXBase_ProcessEvents function | ||
554 | */ | ||
555 | pBaseComp->tCurState = pBaseComp->tNewState; | ||
556 | eError = OMX_ErrorInvalidState; | ||
557 | goto EXIT; | ||
558 | } | ||
559 | |||
560 | switch( pBaseComp->tCurState ) { | ||
561 | case OMX_StateLoaded : | ||
562 | if( pBaseComp->tNewState == OMX_StateIdle ) { | ||
563 | /* Notify to Derived Component */ | ||
564 | eError = pBaseComp->fpCommandNotify(hComponent, | ||
565 | OMX_CommandStateSet, nParam, NULL); | ||
566 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
567 | tStatus = OSAL_RetrieveEvent( | ||
568 | pBaseCompPvt->pCmdCompleteEvent, | ||
569 | OMXBase_CmdStateSet, OSAL_EVENT_OR_CONSUME, | ||
570 | &retEvents, OSAL_SUSPEND); | ||
571 | OMX_CHECK(tStatus == OSAL_ErrNone, | ||
572 | OMX_ErrorInsufficientResources); | ||
573 | |||
574 | for( i = nStartPortNum; i < (nStartPortNum + nPorts); i++ ) { | ||
575 | pPort = (OMXBase_Port *)pBaseComp->pPorts[i - nStartPortNum]; | ||
576 | /*If port is disabled then nothing needs to be done*/ | ||
577 | if( pPort->sPortDef.bEnabled == OMX_FALSE ) { | ||
578 | continue; | ||
579 | } | ||
580 | if( pPort->sPortDef.eDir == OMX_DirOutput ) { | ||
581 | sDIOParams.nMode = OMX_DIO_WRITER; | ||
582 | } else { | ||
583 | sDIOParams.nMode = OMX_DIO_READER; | ||
584 | } | ||
585 | } | ||
586 | } else if( pBaseComp->tNewState == OMX_StateWaitForResources ) { | ||
587 | /* Notify to Derived Component */ | ||
588 | eError = pBaseComp->fpCommandNotify(hComponent, | ||
589 | OMX_CommandStateSet, nParam, NULL); | ||
590 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
591 | tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pCmdCompleteEvent, OMXBase_CmdStateSet, | ||
592 | OSAL_EVENT_OR_CONSUME, &retEvents, OSAL_SUSPEND); | ||
593 | OMX_CHECK(tStatus == OSAL_ErrNone, OMX_ErrorUndefined); | ||
594 | } else { | ||
595 | eError = OMX_ErrorIncorrectStateTransition; | ||
596 | goto EXIT; | ||
597 | } | ||
598 | break; | ||
599 | |||
600 | case OMX_StateIdle : | ||
601 | if( pBaseComp->tNewState == OMX_StateLoaded ) { | ||
602 | /* Notify to Derived Component */ | ||
603 | eError = pBaseComp->fpCommandNotify(hComponent, | ||
604 | OMX_CommandStateSet, nParam, NULL); | ||
605 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
606 | tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pCmdCompleteEvent, OMXBase_CmdStateSet, | ||
607 | OSAL_EVENT_OR_CONSUME, &retEvents, OSAL_SUSPEND); | ||
608 | OMX_CHECK(tStatus == OSAL_ErrNone, OMX_ErrorUndefined); | ||
609 | } else if( pBaseComp->tNewState == OMX_StateExecuting ) { | ||
610 | /* Notify to Derived Component */ | ||
611 | eError = pBaseComp->fpCommandNotify(hComponent, | ||
612 | OMX_CommandStateSet, nParam, NULL); | ||
613 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
614 | tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pCmdCompleteEvent, OMXBase_CmdStateSet, | ||
615 | OSAL_EVENT_OR_CONSUME, &retEvents, OSAL_SUSPEND); | ||
616 | OMX_CHECK(tStatus == OSAL_ErrNone, OMX_ErrorUndefined); | ||
617 | } else if( pBaseComp->tNewState == OMX_StatePause ) { | ||
618 | /* Notify to Derived Component */ | ||
619 | eError = pBaseComp->fpCommandNotify(hComponent, | ||
620 | OMX_CommandStateSet, nParam, NULL); | ||
621 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
622 | tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pCmdCompleteEvent, OMXBase_CmdStateSet, | ||
623 | OSAL_EVENT_OR_CONSUME, &retEvents, OSAL_SUSPEND); | ||
624 | OMX_CHECK(tStatus == OSAL_ErrNone, OMX_ErrorUndefined); | ||
625 | } else { | ||
626 | eError = OMX_ErrorIncorrectStateTransition; | ||
627 | goto EXIT; | ||
628 | } | ||
629 | break; | ||
630 | |||
631 | case OMX_StateExecuting : | ||
632 | if( pBaseComp->tNewState == OMX_StateIdle ) { | ||
633 | /* Notify to Derived Component */ | ||
634 | eError = pBaseComp->fpCommandNotify(hComponent, | ||
635 | OMX_CommandStateSet, nParam, NULL); | ||
636 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
637 | tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pCmdCompleteEvent, OMXBase_CmdStateSet, | ||
638 | OSAL_EVENT_OR_CONSUME, &retEvents, OSAL_SUSPEND); | ||
639 | OMX_CHECK(tStatus == OSAL_ErrNone, OMX_ErrorUndefined); | ||
640 | |||
641 | for( i = nStartPortNum; i < (nStartPortNum + nPorts); i++ ) { | ||
642 | pPort = (OMXBase_Port *)pBaseComp->pPorts[i - nStartPortNum]; | ||
643 | if( pPort->hDIO != NULL ) { | ||
644 | eError = OMXBase_DIO_Control(hComponent, i, | ||
645 | OMX_DIO_CtrlCmd_Stop, NULL); | ||
646 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
647 | } | ||
648 | } | ||
649 | } else if( pBaseComp->tNewState == OMX_StatePause ) { | ||
650 | /* Notify to Derived Component */ | ||
651 | eError = pBaseComp->fpCommandNotify(hComponent, | ||
652 | OMX_CommandStateSet, nParam, NULL); | ||
653 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
654 | tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pCmdCompleteEvent, OMXBase_CmdStateSet, | ||
655 | OSAL_EVENT_OR_CONSUME, &retEvents, OSAL_SUSPEND); | ||
656 | OMX_CHECK(tStatus == OSAL_ErrNone, OMX_ErrorUndefined); | ||
657 | } else { | ||
658 | eError = OMX_ErrorIncorrectStateTransition; | ||
659 | goto EXIT; | ||
660 | } | ||
661 | break; | ||
662 | |||
663 | case OMX_StatePause : | ||
664 | if( pBaseComp->tNewState == OMX_StateExecuting ) { | ||
665 | /* Notify to Derived Component */ | ||
666 | eError = pBaseComp->fpCommandNotify(hComponent, | ||
667 | OMX_CommandStateSet, nParam, NULL); | ||
668 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
669 | tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pCmdCompleteEvent, OMXBase_CmdStateSet, | ||
670 | OSAL_EVENT_OR_CONSUME, &retEvents, OSAL_SUSPEND); | ||
671 | OMX_CHECK(tStatus == OSAL_ErrNone, OMX_ErrorUndefined); | ||
672 | |||
673 | /*Pause to Executing so start processing buffers*/ | ||
674 | pBaseCompPvt->fpInvokeProcessFunction(pComp, DATAEVENT); | ||
675 | } else if( pBaseComp->tNewState == OMX_StateIdle ) { | ||
676 | /* Notify to Derived Component */ | ||
677 | eError = pBaseComp->fpCommandNotify(hComponent, | ||
678 | OMX_CommandStateSet, nParam, NULL); | ||
679 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
680 | tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pCmdCompleteEvent, OMXBase_CmdStateSet, | ||
681 | OSAL_EVENT_OR_CONSUME, &retEvents, OSAL_SUSPEND); | ||
682 | OMX_CHECK(tStatus == OSAL_ErrNone, OMX_ErrorUndefined); | ||
683 | |||
684 | for( i = nStartPortNum; i < (nStartPortNum + nPorts); i++ ) { | ||
685 | pPort = (OMXBase_Port *)pBaseComp->pPorts[i - nStartPortNum]; | ||
686 | if( pPort->hDIO != NULL ) { | ||
687 | eError = OMXBase_DIO_Control(hComponent, i, | ||
688 | OMX_DIO_CtrlCmd_Stop, NULL); | ||
689 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
690 | } | ||
691 | } | ||
692 | } else { | ||
693 | eError = OMX_ErrorIncorrectStateTransition; | ||
694 | goto EXIT; | ||
695 | } | ||
696 | break; | ||
697 | |||
698 | case OMX_StateWaitForResources : | ||
699 | if( pBaseComp->tNewState == OMX_StateLoaded ) { | ||
700 | /* Notify to Derived Component */ | ||
701 | eError = pBaseComp->fpCommandNotify(hComponent, | ||
702 | OMX_CommandStateSet, nParam, NULL); | ||
703 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
704 | tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pCmdCompleteEvent, OMXBase_CmdStateSet, | ||
705 | OSAL_EVENT_OR_CONSUME, &retEvents, OSAL_SUSPEND); | ||
706 | OMX_CHECK(tStatus == OSAL_ErrNone, OMX_ErrorUndefined); | ||
707 | } else if( pBaseComp->tNewState == OMX_StateIdle ) { | ||
708 | /* Notify to Derived Component */ | ||
709 | eError = pBaseComp->fpCommandNotify(hComponent, | ||
710 | OMX_CommandStateSet, nParam, NULL); | ||
711 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
712 | tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pCmdCompleteEvent, OMXBase_CmdStateSet, | ||
713 | OSAL_EVENT_OR_CONSUME, &retEvents, OSAL_SUSPEND); | ||
714 | OMX_CHECK(tStatus == OSAL_ErrNone, OMX_ErrorUndefined); | ||
715 | |||
716 | for( i = nStartPortNum; i < (nStartPortNum + nPorts); i++ ) { | ||
717 | pPort = (OMXBase_Port *)pBaseComp->pPorts[i - nStartPortNum]; | ||
718 | /*If port is disabled then nothing needs to be done*/ | ||
719 | if( pPort->sPortDef.bEnabled == OMX_FALSE ) { | ||
720 | continue; | ||
721 | } | ||
722 | if( pPort->sPortDef.eDir == OMX_DirOutput ) { | ||
723 | sDIOParams.nMode = OMX_DIO_WRITER; | ||
724 | } else { | ||
725 | sDIOParams.nMode = OMX_DIO_READER; | ||
726 | } | ||
727 | } | ||
728 | } else { | ||
729 | eError = OMX_ErrorIncorrectStateTransition; | ||
730 | goto EXIT; | ||
731 | } | ||
732 | break; | ||
733 | |||
734 | default : | ||
735 | OSAL_ErrorTrace(" unknown command "); | ||
736 | break; | ||
737 | } | ||
738 | |||
739 | EXIT: | ||
740 | if( eError != OMX_ErrorNone ) { | ||
741 | /* Since no state transition is in progress put the new state again to OMX_StateMax */ | ||
742 | pBaseComp->tNewState = OMX_StateMax; | ||
743 | } | ||
744 | return (eError); | ||
745 | } | ||
746 | |||
747 | /* | ||
748 | * OMX Base Event Notufy to Client | ||
749 | */ | ||
750 | OMX_ERRORTYPE OMXBase_EventNotifyToClient(OMX_HANDLETYPE hComponent, | ||
751 | OMX_COMMANDTYPE Cmd, | ||
752 | OMX_U32 nParam, | ||
753 | OMX_PTR pCmdData) | ||
754 | { | ||
755 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
756 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
757 | OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
758 | OMXBaseComp *pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
759 | OMXBaseComp_Pvt *pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
760 | OMXBase_Port *pPort = NULL; | ||
761 | uint32_t retEvents = 0; | ||
762 | OMX_U32 i, nStartPortNum, nPorts; | ||
763 | OMX_BOOL bStartFlag = OMX_FALSE; | ||
764 | (void)pCmdData; | ||
765 | |||
766 | nPorts = pBaseComp->nNumPorts; | ||
767 | nStartPortNum = pBaseComp->nMinStartPortIndex; | ||
768 | |||
769 | switch( Cmd ) { | ||
770 | case OMX_CommandStateSet : | ||
771 | if(((pBaseComp->tCurState == OMX_StateLoaded || | ||
772 | pBaseComp->tCurState == OMX_StateWaitForResources) && | ||
773 | pBaseComp->tNewState == OMX_StateIdle) || | ||
774 | (pBaseComp->tCurState == OMX_StateIdle && | ||
775 | pBaseComp->tNewState == OMX_StateLoaded)) { | ||
776 | /* Incase of loaded to idle and idle to loaded state transition, comp | ||
777 | * should wait for buffers to be allocated/freed for enabled ports */ | ||
778 | for( i = nStartPortNum; i < (nStartPortNum + nPorts); i++ ) { | ||
779 | pPort = pBaseComp->pPorts[i - nStartPortNum]; | ||
780 | if( pPort->sPortDef.bEnabled == OMX_TRUE ) { | ||
781 | retEvents = 0; | ||
782 | tStatus = OSAL_RetrieveEvent(pPort->pBufAllocFreeEvent, | ||
783 | (BUF_ALLOC_EVENT | BUF_FREE_EVENT | | ||
784 | BUF_FAIL_EVENT), | ||
785 | OSAL_EVENT_OR_CONSUME, &retEvents, | ||
786 | BUFFER_ALLOC_FREE_TIMEOUT); | ||
787 | |||
788 | if (tStatus == OSAL_ErrTimeOut) { | ||
789 | tStatus = OSAL_ErrNone; | ||
790 | retEvents = BUF_FAIL_EVENT; | ||
791 | } | ||
792 | |||
793 | OMX_CHECK(tStatus == OSAL_ErrNone, OMX_ErrorUndefined); | ||
794 | if( retEvents & BUF_FAIL_EVENT ) { | ||
795 | /*Fail event so free up all DIO resources and move | ||
796 | back to loaded state*/ | ||
797 | OMXBase_HandleFailEvent(hComponent, Cmd, nParam); | ||
798 | if( pBaseComp->tCurState == OMX_StateIdle && | ||
799 | pBaseComp->tNewState == OMX_StateLoaded ) { | ||
800 | eError = OMX_ErrorPortUnresponsiveDuringDeallocation; | ||
801 | } else { | ||
802 | eError = OMX_ErrorPortUnresponsiveDuringAllocation; | ||
803 | } | ||
804 | goto EXIT; | ||
805 | } | ||
806 | /* free up the pool incase if idle to loaded */ | ||
807 | if( pBaseComp->tCurState == OMX_StateIdle && | ||
808 | pBaseComp->tNewState == OMX_StateLoaded ) { | ||
809 | eError = OMXBase_DIO_Close(hComponent, i); | ||
810 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
811 | eError = OMXBase_DIO_Deinit(hComponent, i); | ||
812 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
813 | } | ||
814 | } | ||
815 | } | ||
816 | } else if( pBaseComp->tCurState == OMX_StateIdle && | ||
817 | (pBaseComp->tNewState == OMX_StatePause || | ||
818 | pBaseComp->tNewState == OMX_StateExecuting)) { | ||
819 | bStartFlag = OMX_TRUE; | ||
820 | } | ||
821 | OSAL_ObtainMutex(pBaseCompPvt->pNewStateMutex, OSAL_SUSPEND); | ||
822 | |||
823 | pBaseComp->tCurState = pBaseComp->tNewState; | ||
824 | pBaseComp->tNewState = OMX_StateMax; | ||
825 | /* Notify Completion to the Client */ | ||
826 | pBaseCompPvt->sAppCallbacks.EventHandler(hComponent, | ||
827 | pComp->pApplicationPrivate, | ||
828 | OMX_EventCmdComplete, OMX_CommandStateSet, | ||
829 | nParam, NULL); | ||
830 | if( bStartFlag ) { | ||
831 | for( i = nStartPortNum; i < (nStartPortNum + nPorts); i++ ) { | ||
832 | pPort = (OMXBase_Port *)pBaseComp->pPorts[i - nStartPortNum]; | ||
833 | if( pPort->hDIO != NULL ) { | ||
834 | eError = OMXBase_DIO_Control(hComponent, i, | ||
835 | OMX_DIO_CtrlCmd_Start, NULL); | ||
836 | if( OMX_ErrorNone != eError ) { | ||
837 | OSAL_ReleaseMutex(pBaseCompPvt->pNewStateMutex); | ||
838 | goto EXIT; | ||
839 | } | ||
840 | } | ||
841 | } | ||
842 | } | ||
843 | OSAL_ReleaseMutex(pBaseCompPvt->pNewStateMutex); | ||
844 | break; | ||
845 | |||
846 | case OMX_CommandPortEnable : | ||
847 | if( OMX_ALL == nParam ) { | ||
848 | for( i = nStartPortNum; i < (nStartPortNum + nPorts); i++ ) { | ||
849 | pPort = pBaseComp->pPorts[i - nStartPortNum]; | ||
850 | if( pBaseComp->tCurState != OMX_StateLoaded ) { | ||
851 | retEvents = 0; | ||
852 | tStatus = OSAL_RetrieveEvent(pPort->pBufAllocFreeEvent, | ||
853 | (BUF_ALLOC_EVENT | BUF_FAIL_EVENT), | ||
854 | OSAL_EVENT_OR_CONSUME, &retEvents, | ||
855 | BUFFER_ALLOC_FREE_TIMEOUT); | ||
856 | if (tStatus == OSAL_ErrTimeOut) { | ||
857 | tStatus = OSAL_ErrNone; | ||
858 | retEvents = BUF_FAIL_EVENT; | ||
859 | } | ||
860 | |||
861 | OMX_CHECK(tStatus == OSAL_ErrNone, OMX_ErrorUndefined); | ||
862 | if( retEvents & BUF_FAIL_EVENT ) { | ||
863 | /*Fail event so free up all DIO resources and move | ||
864 | back to port in disabled state*/ | ||
865 | OMXBase_HandleFailEvent(hComponent, Cmd, nParam); | ||
866 | eError = OMX_ErrorPortUnresponsiveDuringAllocation; | ||
867 | |||
868 | for( i = 0; i < pBaseComp->nNumPorts; i++ ) { | ||
869 | pPort = pBaseComp->pPorts[i]; | ||
870 | pPort->bIsInTransition = OMX_FALSE; | ||
871 | pPort->sPortDef.bEnabled = OMX_FALSE; | ||
872 | } | ||
873 | goto EXIT; | ||
874 | } | ||
875 | } | ||
876 | pPort->bIsInTransition = OMX_FALSE; | ||
877 | /* Notify Completion to the Client */ | ||
878 | pBaseCompPvt->sAppCallbacks.EventHandler(hComponent, | ||
879 | pComp->pApplicationPrivate, | ||
880 | OMX_EventCmdComplete, OMX_CommandPortEnable, | ||
881 | i, NULL); | ||
882 | /*If current state is executing, start buffer transfer*/ | ||
883 | if( pBaseComp->tCurState == OMX_StateExecuting ) { | ||
884 | eError = OMXBase_DIO_Control(hComponent, i, | ||
885 | OMX_DIO_CtrlCmd_Start, NULL); | ||
886 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
887 | } | ||
888 | } | ||
889 | } else { | ||
890 | pPort = pBaseComp->pPorts[nParam - nStartPortNum]; | ||
891 | if( pBaseComp->tCurState != OMX_StateLoaded ) { | ||
892 | retEvents = 0; | ||
893 | tStatus = OSAL_RetrieveEvent(pPort->pBufAllocFreeEvent, | ||
894 | (BUF_ALLOC_EVENT | BUF_FAIL_EVENT), | ||
895 | OSAL_EVENT_OR_CONSUME, &retEvents, | ||
896 | BUFFER_ALLOC_FREE_TIMEOUT); | ||
897 | if (tStatus == OSAL_ErrTimeOut) { | ||
898 | tStatus = OSAL_ErrNone; | ||
899 | retEvents = BUF_FAIL_EVENT; | ||
900 | } | ||
901 | |||
902 | OMX_CHECK(tStatus == OSAL_ErrNone, | ||
903 | tStatus != OSAL_ErrTimeOut ? | ||
904 | OMX_ErrorUndefined : OMX_ErrorPortUnresponsiveDuringAllocation); | ||
905 | |||
906 | if( retEvents & BUF_FAIL_EVENT ) { | ||
907 | /*Fail event so free up all DIO resources and move | ||
908 | back to port in disabled state*/ | ||
909 | OMXBase_HandleFailEvent(hComponent, Cmd, nParam); | ||
910 | eError = OMX_ErrorPortUnresponsiveDuringAllocation; | ||
911 | pPort->bIsInTransition = OMX_FALSE; | ||
912 | pPort->sPortDef.bEnabled = OMX_FALSE; | ||
913 | goto EXIT; | ||
914 | } | ||
915 | } | ||
916 | pPort->bIsInTransition = OMX_FALSE; | ||
917 | |||
918 | /* Notify Completion to the Client */ | ||
919 | pBaseCompPvt->sAppCallbacks.EventHandler(hComponent, | ||
920 | pComp->pApplicationPrivate, | ||
921 | OMX_EventCmdComplete, OMX_CommandPortEnable, | ||
922 | nParam, NULL); | ||
923 | /*If current state is executing, start buffer transfer*/ | ||
924 | if( pBaseComp->tCurState == OMX_StateExecuting ) { | ||
925 | eError = OMXBase_DIO_Control(hComponent, nParam, | ||
926 | OMX_DIO_CtrlCmd_Start, NULL); | ||
927 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
928 | } | ||
929 | } | ||
930 | break; | ||
931 | |||
932 | case OMX_CommandPortDisable : | ||
933 | if( OMX_ALL == nParam ) { | ||
934 | for( i = nStartPortNum; i < (nStartPortNum + nPorts); i++ ) { | ||
935 | pPort = pBaseComp->pPorts[i - nStartPortNum]; | ||
936 | if( pBaseComp->tCurState != OMX_StateLoaded ) { | ||
937 | retEvents = 0; | ||
938 | tStatus = OSAL_RetrieveEvent(pPort->pBufAllocFreeEvent, | ||
939 | (BUF_FREE_EVENT | BUF_FAIL_EVENT), | ||
940 | OSAL_EVENT_OR_CONSUME, &retEvents, | ||
941 | BUFFER_ALLOC_FREE_TIMEOUT); | ||
942 | |||
943 | if (tStatus == OSAL_ErrTimeOut) { | ||
944 | tStatus = OSAL_ErrNone; | ||
945 | retEvents = BUF_FAIL_EVENT; | ||
946 | } | ||
947 | |||
948 | OMX_CHECK(tStatus == OSAL_ErrNone, OMX_ErrorUndefined); | ||
949 | if( retEvents & BUF_FAIL_EVENT ) { | ||
950 | /*Fail event so free up all DIO resources and move | ||
951 | port to disabled state*/ | ||
952 | OMXBase_HandleFailEvent(hComponent, Cmd, nParam); | ||
953 | eError = OMX_ErrorPortUnresponsiveDuringDeallocation; | ||
954 | |||
955 | for( i = 0; i < pBaseComp->nNumPorts; i++ ) { | ||
956 | pPort = pBaseComp->pPorts[i]; | ||
957 | pPort->bIsInTransition = OMX_FALSE; | ||
958 | } | ||
959 | goto EXIT; | ||
960 | } | ||
961 | eError = OMXBase_DIO_Close(hComponent, i); | ||
962 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
963 | eError = OMXBase_DIO_Deinit(hComponent, i); | ||
964 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
965 | } | ||
966 | pPort->bIsInTransition = OMX_FALSE; | ||
967 | /* Notify Completion to the Client */ | ||
968 | pBaseCompPvt->sAppCallbacks.EventHandler(hComponent, | ||
969 | pComp->pApplicationPrivate, | ||
970 | OMX_EventCmdComplete, OMX_CommandPortDisable, | ||
971 | i, NULL); | ||
972 | } | ||
973 | } else { | ||
974 | pPort = pBaseComp->pPorts[nParam - nStartPortNum]; | ||
975 | if( pBaseComp->tCurState != OMX_StateLoaded ) { | ||
976 | retEvents = 0; | ||
977 | tStatus = OSAL_RetrieveEvent(pPort->pBufAllocFreeEvent, | ||
978 | (BUF_FREE_EVENT | BUF_FAIL_EVENT), | ||
979 | OSAL_EVENT_OR_CONSUME, &retEvents, | ||
980 | BUFFER_ALLOC_FREE_TIMEOUT); | ||
981 | |||
982 | if (tStatus == OSAL_ErrTimeOut) { | ||
983 | tStatus = OSAL_ErrNone; | ||
984 | retEvents = BUF_FAIL_EVENT; | ||
985 | } | ||
986 | |||
987 | OMX_CHECK(tStatus == OSAL_ErrNone, OMX_ErrorUndefined); | ||
988 | if( retEvents & BUF_FAIL_EVENT ) { | ||
989 | /*Fail event so free up all DIO resources and move | ||
990 | back to port in disabled state*/ | ||
991 | OMXBase_HandleFailEvent(hComponent, Cmd, nParam); | ||
992 | eError = OMX_ErrorPortUnresponsiveDuringDeallocation; | ||
993 | pPort->bIsInTransition = OMX_FALSE; | ||
994 | goto EXIT; | ||
995 | } | ||
996 | eError = OMXBase_DIO_Close(hComponent, nParam); | ||
997 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
998 | eError = OMXBase_DIO_Deinit(hComponent, nParam); | ||
999 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
1000 | } | ||
1001 | pPort->bIsInTransition = OMX_FALSE; | ||
1002 | /* Notify Completion to the Client */ | ||
1003 | pBaseCompPvt->sAppCallbacks.EventHandler(hComponent, | ||
1004 | pComp->pApplicationPrivate, | ||
1005 | OMX_EventCmdComplete, OMX_CommandPortDisable, | ||
1006 | nParam, NULL); | ||
1007 | } | ||
1008 | break; | ||
1009 | |||
1010 | case OMX_CommandFlush : | ||
1011 | if( nParam == OMX_ALL ) { | ||
1012 | for( i = nStartPortNum; i < (nStartPortNum + nPorts); i++ ) { | ||
1013 | pPort = pBaseComp->pPorts[i - nStartPortNum]; | ||
1014 | /* Notify Completion to the Client */ | ||
1015 | pBaseCompPvt->sAppCallbacks.EventHandler(hComponent, | ||
1016 | pComp->pApplicationPrivate, | ||
1017 | OMX_EventCmdComplete, OMX_CommandFlush, | ||
1018 | i, NULL); | ||
1019 | } | ||
1020 | } else { | ||
1021 | /* Notify Completion to the Client */ | ||
1022 | pBaseCompPvt->sAppCallbacks.EventHandler(hComponent, | ||
1023 | pComp->pApplicationPrivate, | ||
1024 | OMX_EventCmdComplete, OMX_CommandFlush, | ||
1025 | nParam, NULL); | ||
1026 | } | ||
1027 | break; | ||
1028 | |||
1029 | case OMX_CommandMarkBuffer : | ||
1030 | |||
1031 | break; | ||
1032 | |||
1033 | default : | ||
1034 | OSAL_ErrorTrace("InValid command"); | ||
1035 | } | ||
1036 | |||
1037 | EXIT: | ||
1038 | return (eError); | ||
1039 | } | ||
1040 | |||
1041 | /* | ||
1042 | * OMX Base IsCmdPending | ||
1043 | */ | ||
1044 | OMX_BOOL OMXBase_IsCmdPending (OMX_HANDLETYPE hComponent) | ||
1045 | { | ||
1046 | OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
1047 | OMXBaseComp *pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
1048 | OMXBaseComp_Pvt *pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
1049 | OMX_BOOL bRetVal = OMX_FALSE; | ||
1050 | |||
1051 | if( OSAL_IsPipeReady(pBaseCompPvt->pCmdPipe) == OSAL_ErrNone ) { | ||
1052 | /*Set data event so that derived component can get data notification | ||
1053 | after it processes the pending command*/ | ||
1054 | pBaseCompPvt->bForceNotifyOnce = OMX_TRUE; | ||
1055 | pBaseCompPvt->fpInvokeProcessFunction(hComponent, DATAEVENT); | ||
1056 | bRetVal = OMX_TRUE; | ||
1057 | } | ||
1058 | |||
1059 | return (bRetVal); | ||
1060 | } | ||
1061 | |||
1062 | |||
1063 | /* | ||
1064 | * OMX Base Is DIO Ready | ||
1065 | */ | ||
1066 | OMX_BOOL OMXBase_IsDioReady(OMX_HANDLETYPE hComponent, OMX_U32 nPortIndex) | ||
1067 | { | ||
1068 | OMX_BOOL bRet = OMX_TRUE; | ||
1069 | OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
1070 | OMXBaseComp *pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
1071 | OMXBaseComp_Pvt *pBaseCompPvt = NULL; | ||
1072 | OMXBase_Port *pPort = NULL; | ||
1073 | OMX_U32 nStartPortNumber = 0; | ||
1074 | |||
1075 | if( pBaseComp == NULL ) { | ||
1076 | OSAL_ErrorTrace("Pvt structure is NULL - DIO cannot be used"); | ||
1077 | bRet = OMX_FALSE; | ||
1078 | goto EXIT; | ||
1079 | } | ||
1080 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
1081 | if( pBaseCompPvt == NULL ) { | ||
1082 | OSAL_ErrorTrace("Base internal structure is NULL - DIO cannot be used"); | ||
1083 | bRet = OMX_FALSE; | ||
1084 | goto EXIT; | ||
1085 | } | ||
1086 | if( pBaseComp->pPorts == NULL ) { | ||
1087 | OSAL_ErrorTrace("No port has been initialized - DIO cannot be used"); | ||
1088 | bRet = OMX_FALSE; | ||
1089 | goto EXIT; | ||
1090 | } | ||
1091 | nStartPortNumber = pBaseComp->nMinStartPortIndex; | ||
1092 | pPort = (OMXBase_Port *) | ||
1093 | pBaseComp->pPorts[nPortIndex - nStartPortNumber]; | ||
1094 | if( pPort == NULL ) { | ||
1095 | OSAL_ErrorTrace("This port is not initialized - DIO cannot be used"); | ||
1096 | bRet = OMX_FALSE; | ||
1097 | goto EXIT; | ||
1098 | } | ||
1099 | if( pPort->hDIO == NULL ) { | ||
1100 | OSAL_ErrorTrace("DIO handle is NULL - DIO cannot be used"); | ||
1101 | bRet = OMX_FALSE; | ||
1102 | goto EXIT; | ||
1103 | } | ||
1104 | if( !(((OMX_DIO_Object *)pPort->hDIO)->bOpened)) { | ||
1105 | OSAL_ErrorTrace("DIO has not yet been opened"); | ||
1106 | bRet = OMX_FALSE; | ||
1107 | goto EXIT; | ||
1108 | } | ||
1109 | |||
1110 | EXIT: | ||
1111 | return (bRet); | ||
1112 | } | ||
1113 | |||
1114 | /* | ||
1115 | * OMX Base Get UV Buffer shared fd | ||
1116 | */ | ||
1117 | OMX_ERRORTYPE OMXBase_GetUVBuffer(OMX_HANDLETYPE hComponent, | ||
1118 | OMX_U32 nPortIndex, | ||
1119 | OMX_PTR pBufHdr, OMX_PTR *pUVBuffer) | ||
1120 | { | ||
1121 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
1122 | (void)hComponent; | ||
1123 | (void)nPortIndex; | ||
1124 | |||
1125 | OMX_CHECK(pBufHdr != NULL, OMX_ErrorBadParameter); | ||
1126 | OMX_CHECK(((OMX_BUFFERHEADERTYPE *)pBufHdr)->pPlatformPrivate != | ||
1127 | NULL, OMX_ErrorBadParameter); | ||
1128 | |||
1129 | *pUVBuffer = (void*)((OMXBase_BufHdrPvtData *)((OMX_BUFFERHEADERTYPE *)pBufHdr)-> | ||
1130 | pPlatformPrivate)->sMemHdr[1].dma_buf_fd; | ||
1131 | |||
1132 | EXIT: | ||
1133 | return (eError); | ||
1134 | } | ||
1135 | |||
1136 | |||
1137 | /* | ||
1138 | * OMXBase Error Handling for WaitForResource State | ||
1139 | */ | ||
1140 | OMX_ERRORTYPE OMXBase_Error_HandleWFRState(OMX_HANDLETYPE hComponent) | ||
1141 | { | ||
1142 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
1143 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
1144 | OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
1145 | OMXBaseComp *pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
1146 | OMXBaseComp_Pvt *pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
1147 | uint32_t retEvents = 0; | ||
1148 | |||
1149 | eError = OMXBase_SendCommand(hComponent, OMX_CommandStateSet, OMX_StateLoaded, NULL); | ||
1150 | |||
1151 | //Wait for WaitForResources state transition to complete. | ||
1152 | retEvents = 0; | ||
1153 | tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pErrorCmdcompleteEvent, | ||
1154 | (STATE_LOADED_EVENT), | ||
1155 | OSAL_EVENT_OR_CONSUME, &retEvents, | ||
1156 | STATE_TRANSITION_LONG_TIMEOUT); | ||
1157 | OMX_CHECK(tStatus == OSAL_ErrNone, OMX_ErrorUndefined); | ||
1158 | |||
1159 | EXIT: | ||
1160 | return (eError); | ||
1161 | } | ||
1162 | |||
1163 | /* | ||
1164 | * OMX Base Error handling for Idle State | ||
1165 | */ | ||
1166 | OMX_ERRORTYPE OMXBase_Error_HandleIdleState(OMX_HANDLETYPE hComponent) | ||
1167 | { | ||
1168 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
1169 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
1170 | OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
1171 | OMXBaseComp *pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
1172 | OMXBaseComp_Pvt *pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
1173 | OMXBase_Port *pPort = NULL; | ||
1174 | OMX_U32 i = 0, j = 0; | ||
1175 | uint32_t retEvents = 0; | ||
1176 | |||
1177 | eError = OMXBase_SendCommand(hComponent, OMX_CommandStateSet, OMX_StateLoaded, NULL); | ||
1178 | |||
1179 | //Send free buffers to complete the Idle transition. | ||
1180 | for( i=0; i < pBaseComp->nNumPorts; i++ ) { | ||
1181 | pPort = pBaseComp->pPorts[i]; | ||
1182 | if( pPort->sPortDef.bEnabled == OMX_TRUE ) { | ||
1183 | for( j=0; j < pPort->sPortDef.nBufferCountActual; j++ ) { | ||
1184 | OMXBase_FreeBuffer(hComponent, | ||
1185 | i + pBaseComp->nMinStartPortIndex, | ||
1186 | pPort->pBufferlist[j]); | ||
1187 | } | ||
1188 | } | ||
1189 | } | ||
1190 | |||
1191 | //Wait for Idle state transition to complete. | ||
1192 | retEvents = 0; | ||
1193 | tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pErrorCmdcompleteEvent, | ||
1194 | (STATE_LOADED_EVENT), | ||
1195 | OSAL_EVENT_OR_CONSUME, &retEvents, | ||
1196 | STATE_TRANSITION_LONG_TIMEOUT); | ||
1197 | OMX_CHECK(tStatus == OSAL_ErrNone, OMX_ErrorUndefined); | ||
1198 | |||
1199 | EXIT: | ||
1200 | return (eError); | ||
1201 | } | ||
1202 | |||
1203 | /* | ||
1204 | * OMX Base UtilCleanup On Error | ||
1205 | */ | ||
1206 | OMX_ERRORTYPE OMXBase_UtilCleanupIfError(OMX_HANDLETYPE hComponent) | ||
1207 | { | ||
1208 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
1209 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
1210 | OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
1211 | OMXBaseComp *pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
1212 | OMXBaseComp_Pvt *pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
1213 | OMXBase_Port *pPort = NULL; | ||
1214 | OMX_U32 i = 0; | ||
1215 | uint32_t retEvents = 0; | ||
1216 | OMX_BOOL bPortTransitioning = OMX_FALSE; | ||
1217 | |||
1218 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
1219 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
1220 | |||
1221 | if((pBaseComp->tCurState == OMX_StateLoaded) && (pBaseComp->tNewState == OMX_StateMax)) { | ||
1222 | for( i=0; i < pBaseComp->nNumPorts; i++ ) { | ||
1223 | pPort = pBaseComp->pPorts[i]; | ||
1224 | if( pPort->bIsInTransition) { | ||
1225 | bPortTransitioning = OMX_TRUE; | ||
1226 | break; | ||
1227 | } | ||
1228 | } | ||
1229 | |||
1230 | if( bPortTransitioning == OMX_FALSE ) { | ||
1231 | goto EXIT; | ||
1232 | } | ||
1233 | } | ||
1234 | pBaseCompPvt->sAppCallbacks.EventHandler = OMXBase_Error_EventHandler; | ||
1235 | pBaseCompPvt->sAppCallbacks.EmptyBufferDone = OMXBase_Error_EmptyBufferDone; | ||
1236 | pBaseCompPvt->sAppCallbacks.FillBufferDone = OMXBase_Error_FillBufferDone; | ||
1237 | |||
1238 | if((pBaseComp->tCurState == OMX_StateWaitForResources) && (pBaseComp->tNewState == OMX_StateMax)) { | ||
1239 | for( i=0; i < pBaseComp->nNumPorts; i++ ) { | ||
1240 | pPort = pBaseComp->pPorts[i]; | ||
1241 | if( pPort->bIsInTransition) { | ||
1242 | bPortTransitioning = OMX_TRUE; | ||
1243 | break; | ||
1244 | } | ||
1245 | } | ||
1246 | |||
1247 | if( bPortTransitioning == OMX_FALSE ) { | ||
1248 | OSAL_ErrorTrace("Free Handle called in WaitForResources state, attempting a transition to LOADED state"); | ||
1249 | eError = OMXBase_Error_HandleWFRState(pComp); | ||
1250 | if( eError != OMX_ErrorNone ) { | ||
1251 | OSAL_ErrorTrace("Error occured. Cleanup might not be complete"); | ||
1252 | } else { | ||
1253 | OSAL_ErrorTrace("Cleanup from WaitForResources state is successful"); | ||
1254 | } | ||
1255 | goto EXIT; | ||
1256 | } | ||
1257 | } | ||
1258 | //Wait for timeout to let any pending send commands complete. | ||
1259 | retEvents = 0; | ||
1260 | tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pErrorCmdcompleteEvent, | ||
1261 | (STATE_LOADED_EVENT | STATE_IDLE_EVENT | ||
1262 | | STATE_EXEC_EVENT | STATE_PAUSE_EVENT | ||
1263 | | ERROR_EVENT), | ||
1264 | OSAL_EVENT_OR_CONSUME, &retEvents, | ||
1265 | STATE_TRANSITION_TIMEOUT); | ||
1266 | if( tStatus != OSAL_ErrNone && tStatus != OSAL_ErrTimeOut ) { | ||
1267 | eError = OMX_ErrorUndefined; | ||
1268 | OSAL_ErrorTrace("Error occured. Cleanup might not be complete"); | ||
1269 | } | ||
1270 | //Clear any port disable/enable events which are pending. | ||
1271 | retEvents = 0; | ||
1272 | tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pErrorCmdcompleteEvent, | ||
1273 | (PORT_ENABLE_EVENT | PORT_DISABLE_EVENT), | ||
1274 | OSAL_EVENT_OR_CONSUME, &retEvents, | ||
1275 | OSAL_NO_SUSPEND); | ||
1276 | if( tStatus != OSAL_ErrNone && tStatus != OSAL_ErrTimeOut ) { | ||
1277 | eError = OMX_ErrorUndefined; | ||
1278 | OSAL_ErrorTrace("Error occured. Cleanup might not be complete"); | ||
1279 | } | ||
1280 | |||
1281 | //This is for the condition if freehandle is being sent while port enable/disable is ongoing. | ||
1282 | for( i=0; i < pBaseComp->nNumPorts; i++ ) { | ||
1283 | pPort = pBaseComp->pPorts[i]; | ||
1284 | if( pPort->bIsInTransition) { | ||
1285 | tStatus = OSAL_SetEvent(pPort->pBufAllocFreeEvent, | ||
1286 | BUF_FAIL_EVENT, OSAL_EVENT_OR); | ||
1287 | if( tStatus != OSAL_ErrNone ) { | ||
1288 | eError = OMX_ErrorUndefined; | ||
1289 | } | ||
1290 | //Wait for port to transition to disable. | ||
1291 | retEvents = 0; | ||
1292 | tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pErrorCmdcompleteEvent, | ||
1293 | ERROR_EVENT, OSAL_EVENT_OR_CONSUME, &retEvents, | ||
1294 | STATE_TRANSITION_TIMEOUT); | ||
1295 | if( tStatus != OSAL_ErrNone ) { | ||
1296 | eError = OMX_ErrorUndefined; | ||
1297 | OSAL_ErrorTrace("Error occured. Cleanup might not be complete"); | ||
1298 | } | ||
1299 | if( pPort->bIsInTransition) { | ||
1300 | pPort->bIsInTransition = OMX_FALSE; | ||
1301 | } | ||
1302 | } | ||
1303 | } | ||
1304 | |||
1305 | if( pBaseComp->tCurState == OMX_StateLoaded && pBaseComp->tNewState == OMX_StateMax ) { | ||
1306 | goto EXIT; | ||
1307 | } | ||
1308 | |||
1309 | switch( pBaseComp->tCurState ) { | ||
1310 | case OMX_StateLoaded : | ||
1311 | OMX_BASE_HANDLE_IDLE_TO_LOADED_TRANSITION(); | ||
1312 | break; | ||
1313 | |||
1314 | case OMX_StateWaitForResources : | ||
1315 | // Since BUFFER FAIL done in cleanup utility happened successfully, all that is required is switch to LOADED state. | ||
1316 | if( pBaseComp->tCurState == OMX_StateWaitForResources && pBaseComp->tNewState == OMX_StateMax ) { | ||
1317 | eError = OMXBase_Error_HandleWFRState(hComponent); | ||
1318 | } else { | ||
1319 | OSAL_ErrorTrace("Error occured. Cleanup might not be complete"); | ||
1320 | } | ||
1321 | break; | ||
1322 | |||
1323 | case OMX_StateIdle : | ||
1324 | if( pBaseComp->tCurState == OMX_StateIdle && pBaseComp->tNewState == OMX_StateMax ) { | ||
1325 | eError = OMXBase_Error_HandleIdleState(hComponent); | ||
1326 | } else { // This is to handle scenerio if there is a crash in Idle to Loaded transition | ||
1327 | OMX_BASE_HANDLE_IDLE_TO_LOADED_TRANSITION(); | ||
1328 | } | ||
1329 | break; | ||
1330 | |||
1331 | case OMX_StateExecuting : | ||
1332 | // Move the component to Idle State. | ||
1333 | OMXBase_SendCommand(hComponent, OMX_CommandStateSet, OMX_StateIdle, NULL); | ||
1334 | retEvents = 0; | ||
1335 | tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pErrorCmdcompleteEvent, | ||
1336 | STATE_IDLE_EVENT, | ||
1337 | OSAL_EVENT_OR_CONSUME, &retEvents, | ||
1338 | STATE_TRANSITION_LONG_TIMEOUT); | ||
1339 | if( tStatus != OSAL_ErrNone ) { | ||
1340 | eError = OMX_ErrorUndefined; | ||
1341 | OSAL_ErrorTrace("I am here b'cs of TIMEOUT in ER"); | ||
1342 | } | ||
1343 | eError = OMXBase_Error_HandleIdleState(hComponent); | ||
1344 | break; | ||
1345 | |||
1346 | case OMX_StatePause : | ||
1347 | // Move the component to Idle State. | ||
1348 | OMXBase_SendCommand(hComponent, OMX_CommandStateSet, OMX_StateIdle, NULL); | ||
1349 | retEvents = 0; | ||
1350 | tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pErrorCmdcompleteEvent, | ||
1351 | (STATE_IDLE_EVENT), | ||
1352 | OSAL_EVENT_OR_CONSUME, &retEvents, | ||
1353 | STATE_TRANSITION_LONG_TIMEOUT); | ||
1354 | if( tStatus != OSAL_ErrNone ) { | ||
1355 | eError = OMX_ErrorUndefined; | ||
1356 | OSAL_ErrorTrace("I am here b'cs of TIMEOUT in ER"); | ||
1357 | } | ||
1358 | eError = OMXBase_Error_HandleIdleState(hComponent); | ||
1359 | break; | ||
1360 | |||
1361 | default : | ||
1362 | OSAL_ErrorTrace("Invalid state requested"); | ||
1363 | } | ||
1364 | |||
1365 | EXIT: | ||
1366 | return (eError); | ||
1367 | } | ||
1368 | |||
1369 | /* | ||
1370 | * OMX Base Error handling for Empty Buffer Done | ||
1371 | */ | ||
1372 | OMX_ERRORTYPE OMXBase_Error_EmptyBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, | ||
1373 | OMX_BUFFERHEADERTYPE *pBuffer) | ||
1374 | { | ||
1375 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
1376 | (void)hComponent; | ||
1377 | (void)pAppData; | ||
1378 | (void)pBuffer; | ||
1379 | |||
1380 | return (eError); | ||
1381 | } | ||
1382 | |||
1383 | /* | ||
1384 | * OMX Base Error Handling for FillBufferDone | ||
1385 | */ | ||
1386 | OMX_ERRORTYPE OMXBase_Error_FillBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, | ||
1387 | OMX_BUFFERHEADERTYPE *pBuffer) | ||
1388 | { | ||
1389 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
1390 | (void)hComponent; | ||
1391 | (void)pAppData; | ||
1392 | (void)pBuffer; | ||
1393 | |||
1394 | return (eError); | ||
1395 | } | ||
1396 | |||
1397 | /* | ||
1398 | * OMX Base Error Handling for EventHandler | ||
1399 | */ | ||
1400 | OMX_ERRORTYPE OMXBase_Error_EventHandler(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, | ||
1401 | OMX_EVENTTYPE eEvent, OMX_U32 nData1, | ||
1402 | OMX_U32 nData2, OMX_PTR pEventData) | ||
1403 | { | ||
1404 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
1405 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
1406 | OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
1407 | OMXBaseComp *pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
1408 | OMXBaseComp_Pvt *pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
1409 | (void)pAppData; | ||
1410 | (void)pEventData; | ||
1411 | |||
1412 | if( eEvent == OMX_EventCmdComplete ) { | ||
1413 | if((OMX_COMMANDTYPE)nData1 == OMX_CommandPortEnable ) { | ||
1414 | tStatus = OSAL_SetEvent(pBaseCompPvt->pErrorCmdcompleteEvent, | ||
1415 | PORT_ENABLE_EVENT, OSAL_EVENT_OR); | ||
1416 | if( tStatus != OSAL_ErrNone ) { | ||
1417 | eError = OMX_ErrorUndefined; | ||
1418 | } | ||
1419 | } else if((OMX_COMMANDTYPE)nData1 == OMX_CommandPortEnable ) { | ||
1420 | tStatus = OSAL_SetEvent(pBaseCompPvt->pErrorCmdcompleteEvent, | ||
1421 | PORT_DISABLE_EVENT, OSAL_EVENT_OR); | ||
1422 | if( tStatus != OSAL_ErrNone ) { | ||
1423 | eError = OMX_ErrorUndefined; | ||
1424 | } | ||
1425 | } else if((OMX_COMMANDTYPE)nData1 == OMX_CommandStateSet ) { | ||
1426 | switch((OMX_STATETYPE) nData2 ) { | ||
1427 | case OMX_StateLoaded : | ||
1428 | tStatus = OSAL_SetEvent(pBaseCompPvt->pErrorCmdcompleteEvent, | ||
1429 | STATE_LOADED_EVENT, OSAL_EVENT_OR); | ||
1430 | if( tStatus != OSAL_ErrNone ) { | ||
1431 | eError = OMX_ErrorUndefined; | ||
1432 | } | ||
1433 | break; | ||
1434 | |||
1435 | case OMX_StateIdle : | ||
1436 | tStatus = OSAL_SetEvent(pBaseCompPvt->pErrorCmdcompleteEvent, | ||
1437 | STATE_IDLE_EVENT, OSAL_EVENT_OR); | ||
1438 | if( tStatus != OSAL_ErrNone ) { | ||
1439 | eError = OMX_ErrorUndefined; | ||
1440 | } | ||
1441 | break; | ||
1442 | |||
1443 | case OMX_StateExecuting : | ||
1444 | tStatus = OSAL_SetEvent(pBaseCompPvt->pErrorCmdcompleteEvent, | ||
1445 | STATE_EXEC_EVENT, OSAL_EVENT_OR); | ||
1446 | if( tStatus != OSAL_ErrNone ) { | ||
1447 | eError = OMX_ErrorUndefined; | ||
1448 | } | ||
1449 | break; | ||
1450 | |||
1451 | case OMX_StatePause : | ||
1452 | tStatus = OSAL_SetEvent(pBaseCompPvt->pErrorCmdcompleteEvent, | ||
1453 | STATE_PAUSE_EVENT, OSAL_EVENT_OR); | ||
1454 | if( tStatus != OSAL_ErrNone ) { | ||
1455 | eError = OMX_ErrorUndefined; | ||
1456 | } | ||
1457 | break; | ||
1458 | |||
1459 | default: | ||
1460 | OSAL_ErrorTrace("Invalid command"); | ||
1461 | } | ||
1462 | } | ||
1463 | } else if( eEvent == OMX_EventError ) { | ||
1464 | if(((OMX_ERRORTYPE)nData1 == OMX_ErrorPortUnresponsiveDuringDeallocation) || | ||
1465 | ((OMX_ERRORTYPE)nData1 == OMX_ErrorPortUnresponsiveDuringAllocation)) { | ||
1466 | tStatus = OSAL_SetEvent(pBaseCompPvt->pErrorCmdcompleteEvent, | ||
1467 | ERROR_EVENT, OSAL_EVENT_OR); | ||
1468 | } | ||
1469 | } | ||
1470 | return (eError); | ||
1471 | } | ||
1472 | |||
1473 | /* | ||
1474 | * OMX Base Handle Fail Event | ||
1475 | */ | ||
1476 | void OMXBase_HandleFailEvent(OMX_HANDLETYPE hComponent, OMX_COMMANDTYPE eCmd, | ||
1477 | OMX_U32 nPortIndex) | ||
1478 | { | ||
1479 | OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
1480 | OMXBaseComp *pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
1481 | OMXBaseComp_Pvt *pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
1482 | OMXBase_Port *pPort = NULL; | ||
1483 | // OSAL_ERROR retval = OSAL_ErrNone; | ||
1484 | OMX_U32 i = 0; | ||
1485 | uint32_t retEvents = 0; | ||
1486 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
1487 | |||
1488 | switch( eCmd ) { | ||
1489 | case OMX_CommandStateSet : | ||
1490 | OSAL_ObtainMutex(pBaseCompPvt->pNewStateMutex, OSAL_SUSPEND); | ||
1491 | if(((pBaseComp->tCurState == OMX_StateLoaded || | ||
1492 | pBaseComp->tCurState == OMX_StateWaitForResources) && | ||
1493 | pBaseComp->tNewState == OMX_StateIdle) || | ||
1494 | (pBaseComp->tCurState == OMX_StateIdle && | ||
1495 | pBaseComp->tNewState == OMX_StateLoaded)) { | ||
1496 | /*Failure in L --> I transition. First step is to tell the derived component | ||
1497 | to revert back to loaded state*/ | ||
1498 | if(((pBaseComp->tCurState == OMX_StateLoaded) || | ||
1499 | (pBaseComp->tCurState == OMX_StateWaitForResources)) && | ||
1500 | (pBaseComp->tNewState == OMX_StateIdle)) { | ||
1501 | /*Force setting states*/ | ||
1502 | pBaseComp->tCurState = OMX_StateIdle; | ||
1503 | pBaseComp->tNewState = OMX_StateLoaded; | ||
1504 | /*Return error values dont matter here since this is cleanup*/ | ||
1505 | eError = pBaseComp->fpCommandNotify(hComponent, | ||
1506 | OMX_CommandStateSet, OMX_StateLoaded, NULL); | ||
1507 | if( eError == OMX_ErrorNone ) { | ||
1508 | OSAL_RetrieveEvent(pBaseCompPvt->pCmdCompleteEvent, | ||
1509 | OMXBase_CmdStateSet, OSAL_EVENT_OR_CONSUME, &retEvents, | ||
1510 | OSAL_SUSPEND); | ||
1511 | } | ||
1512 | } | ||
1513 | |||
1514 | /*If DIO for any port is open close those*/ | ||
1515 | for( i = 0; i < pBaseComp->nNumPorts; i++ ) { | ||
1516 | pPort = pBaseComp->pPorts[i]; | ||
1517 | if( pPort != NULL ) { | ||
1518 | if( pPort->hDIO != NULL ) { | ||
1519 | OMXBase_DIO_Close(hComponent, | ||
1520 | (i + pBaseComp->nMinStartPortIndex)); | ||
1521 | |||
1522 | OMXBase_DIO_Deinit(hComponent, | ||
1523 | (i + pBaseComp->nMinStartPortIndex)); | ||
1524 | } | ||
1525 | } | ||
1526 | } | ||
1527 | /*Force setting states*/ | ||
1528 | pBaseComp->tCurState = OMX_StateLoaded; | ||
1529 | pBaseComp->tNewState = OMX_StateMax; | ||
1530 | } | ||
1531 | OSAL_ReleaseMutex(pBaseCompPvt->pNewStateMutex); | ||
1532 | break; | ||
1533 | |||
1534 | case OMX_CommandPortEnable : | ||
1535 | /*Tell derived comp to move back to disabled state*/ | ||
1536 | pBaseComp->fpCommandNotify(hComponent, | ||
1537 | OMX_CommandPortDisable, nPortIndex, NULL); | ||
1538 | |||
1539 | OSAL_RetrieveEvent(pBaseCompPvt->pCmdCompleteEvent, | ||
1540 | OMXBase_CmdPortDisable, OSAL_EVENT_OR_CONSUME, &retEvents, | ||
1541 | OSAL_SUSPEND); | ||
1542 | if( nPortIndex == OMX_ALL ) { | ||
1543 | for( i = 0; i < pBaseComp->nNumPorts; i++ ) { | ||
1544 | pPort = pBaseComp->pPorts[i]; | ||
1545 | pPort->bIsInTransition = OMX_FALSE; | ||
1546 | } | ||
1547 | } else { | ||
1548 | pPort = pBaseComp->pPorts[ | ||
1549 | nPortIndex - pBaseComp->nMinStartPortIndex]; | ||
1550 | pPort->bIsInTransition = OMX_FALSE; | ||
1551 | } | ||
1552 | /*NO break to OMX_CommandPortEnable case :::Intention is to have a fall through logic to the port disable*/ | ||
1553 | |||
1554 | case OMX_CommandPortDisable : | ||
1555 | /*Close DIO on the relevant ports for both enable as well as disable | ||
1556 | commands*/ | ||
1557 | OSAL_ObtainMutex(pBaseCompPvt->pPortDisableMutex, OSAL_SUSPEND); | ||
1558 | if( nPortIndex == OMX_ALL ) { | ||
1559 | for( i = 0; i < pBaseComp->nNumPorts; i++ ) { | ||
1560 | pPort = pBaseComp->pPorts[i]; | ||
1561 | if( pPort != NULL ) { | ||
1562 | if( pPort->hDIO != NULL ) { | ||
1563 | OMXBase_DIO_Close(hComponent, (i + pBaseComp->nMinStartPortIndex)); | ||
1564 | |||
1565 | OMXBase_DIO_Deinit(hComponent, (i + pBaseComp->nMinStartPortIndex)); | ||
1566 | } | ||
1567 | } | ||
1568 | } | ||
1569 | } else { | ||
1570 | pPort = pBaseComp->pPorts[nPortIndex - pBaseComp->nMinStartPortIndex]; | ||
1571 | if( pPort != NULL ) { | ||
1572 | if( pPort->hDIO != NULL ) { | ||
1573 | OMXBase_DIO_Close(hComponent, nPortIndex); | ||
1574 | OMXBase_DIO_Deinit(hComponent, nPortIndex); | ||
1575 | } | ||
1576 | } | ||
1577 | } | ||
1578 | OSAL_ReleaseMutex(pBaseCompPvt->pPortDisableMutex); | ||
1579 | break; | ||
1580 | |||
1581 | default : | ||
1582 | OSAL_ErrorTrace("Invalid Command"); | ||
1583 | } | ||
1584 | |||
1585 | return; | ||
1586 | } | ||
1587 | |||
1588 | |||
diff --git a/libstagefrighthw/omx/base/OMX_BaseInternal.h b/libstagefrighthw/omx/base/OMX_BaseInternal.h new file mode 100644 index 0000000..6f765d1 --- /dev/null +++ b/libstagefrighthw/omx/base/OMX_BaseInternal.h | |||
@@ -0,0 +1,232 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 _OMX_BASE_INTERNAL_H_ | ||
18 | #define _OMX_BASE_INTERNAL_H_ | ||
19 | |||
20 | #ifdef __cplusplus | ||
21 | extern "C" { | ||
22 | #endif | ||
23 | |||
24 | #include <OMX_Core.h> | ||
25 | #include <OMX_Component.h> | ||
26 | #include <OMX_BaseDIOPlugin.h> | ||
27 | |||
28 | #define CMDEVENT (0x00000100) | ||
29 | |||
30 | #define DATAEVENT (0x00000200) | ||
31 | |||
32 | #define ENDEVENT (0x00f00000) | ||
33 | |||
34 | #define OMXBase_CmdStateSet (0x00001000) | ||
35 | |||
36 | #define OMXBase_CmdPortEnable (0x00002000) | ||
37 | |||
38 | #define OMXBase_CmdPortDisable (0x00003000) | ||
39 | |||
40 | #define OMXBase_CmdFlush (0x00004000) | ||
41 | |||
42 | #define OMXBase_CmdMarkBuffer (0x00005000) | ||
43 | |||
44 | #define OMXBase_MAXCMDS 10 | ||
45 | |||
46 | #define BUF_ALLOC_EVENT (0x00000001) | ||
47 | |||
48 | #define BUF_FREE_EVENT (0x00000002) | ||
49 | |||
50 | #define BUF_FAIL_EVENT (0x00000004) | ||
51 | |||
52 | #define STATE_LOADED_EVENT (0x00000001) | ||
53 | #define STATE_IDLE_EVENT (0x00000002) | ||
54 | #define STATE_EXEC_EVENT (0x00000004) | ||
55 | #define STATE_PAUSE_EVENT (0x00000008) | ||
56 | #define ERROR_EVENT (0x00000010) | ||
57 | #define PORT_ENABLE_EVENT (0x00000020) | ||
58 | #define PORT_DISABLE_EVENT (0x00000040) | ||
59 | |||
60 | #define STATE_TRANSITION_TIMEOUT 500 | ||
61 | #define STATE_TRANSITION_LONG_TIMEOUT 5000 | ||
62 | |||
63 | /** Priority of the Component thread */ | ||
64 | #define OMX_BASE_THREAD_PRIORITY (10) | ||
65 | |||
66 | /** Stack Size of the Comp thread*/ | ||
67 | #define OMX_BASE_THREAD_STACKSIZE (50 * 1024) | ||
68 | |||
69 | |||
70 | /** OMX Base Command params | ||
71 | * This structure contains the params required to execute command | ||
72 | * @param cmd : command to execute | ||
73 | * @param nParam : parameter for the command to be executed | ||
74 | * @param pCmdData : pointer to the command data | ||
75 | */ | ||
76 | typedef struct OMXBase_CmdParams { | ||
77 | OMX_COMMANDTYPE eCmd; | ||
78 | OMX_U32 unParam; | ||
79 | OMX_PTR pCmdData; | ||
80 | }OMXBase_CmdParams; | ||
81 | |||
82 | /** OMX Base component private structure | ||
83 | */ | ||
84 | typedef struct OMXBaseComp_Private { | ||
85 | OMX_U8 cTaskName[OMX_BASE_MAXNAMELEN]; | ||
86 | OMX_U32 nStackSize; | ||
87 | OMX_U32 nPrioirty; | ||
88 | OMX_PTR pThreadId; | ||
89 | OMX_CALLBACKTYPE sAppCallbacks; | ||
90 | OMX_BOOL bForceNotifyOnce; | ||
91 | OMX_PTR pCmdPipe; | ||
92 | OMX_PTR pCmdDataPipe; | ||
93 | OMX_PTR pTriggerEvent; | ||
94 | OMX_PTR pCmdCompleteEvent; | ||
95 | OMX_PTR pErrorCmdcompleteEvent; | ||
96 | OMX_PTR pCmdPipeMutex; | ||
97 | OMX_PTR pNewStateMutex; | ||
98 | OMX_PTR pPortDisableMutex; | ||
99 | OMX_ERRORTYPE (*fpInvokeProcessFunction)(OMX_HANDLETYPE hComponent, | ||
100 | OMX_U32 retEvent); | ||
101 | |||
102 | OMX_ERRORTYPE (*fpDioGetCount)(OMX_HANDLETYPE hComponent, OMX_U32 nPortIndex, OMX_U32 *pCount); | ||
103 | |||
104 | OMX_ERRORTYPE (*fpDioQueue)(OMX_HANDLETYPE hComponent, OMX_U32 nPortIndex, OMX_PTR pBuffHeader); | ||
105 | |||
106 | OMX_ERRORTYPE (*fpDioDequeue)(OMX_HANDLETYPE hComponent, OMX_U32 nPortIndex, OMX_PTR *pBuffHeader); | ||
107 | |||
108 | OMX_ERRORTYPE (*fpDioSend)(OMX_HANDLETYPE hComponent, OMX_U32 nPortIndex, OMX_PTR pBuffHeader); | ||
109 | |||
110 | OMX_ERRORTYPE (*fpDioCancel)(OMX_HANDLETYPE hComponent, OMX_U32 nPortIndex, OMX_PTR pBuffHeader); | ||
111 | |||
112 | OMX_ERRORTYPE (*fpDioControl)(OMX_HANDLETYPE hComponent, OMX_U32 nPortIndex, | ||
113 | OMX_DIO_CtrlCmdType nCmdType, OMX_PTR pParams); | ||
114 | }OMXBaseComp_Pvt; | ||
115 | |||
116 | /* Initialization and control functions */ | ||
117 | OMX_ERRORTYPE OMXBase_PrivateInit(OMX_HANDLETYPE hComponent); | ||
118 | |||
119 | OMX_ERRORTYPE OMXBase_PrivateDeInit(OMX_HANDLETYPE hComponent); | ||
120 | |||
121 | OMX_ERRORTYPE OMXBase_SetDefaultProperties(OMX_HANDLETYPE hComponent); | ||
122 | |||
123 | void OMXBase_CompThreadEntry(void *arg); | ||
124 | |||
125 | OMX_ERRORTYPE OMXBase_InitializePorts(OMX_HANDLETYPE hComponent); | ||
126 | |||
127 | OMX_ERRORTYPE OMXBase_DeinitializePorts(OMX_HANDLETYPE hComponent); | ||
128 | |||
129 | OMX_ERRORTYPE OMXBase_DisablePort(OMX_HANDLETYPE hComponent, | ||
130 | OMX_U32 nParam); | ||
131 | |||
132 | OMX_ERRORTYPE OMXBase_EnablePort(OMX_HANDLETYPE hComponent, | ||
133 | OMX_U32 nParam); | ||
134 | |||
135 | OMX_ERRORTYPE OMXBase_FlushBuffers(OMX_HANDLETYPE hComponent, | ||
136 | OMX_U32 nParam); | ||
137 | |||
138 | OMX_ERRORTYPE OMXBase_HandleStateTransition(OMX_HANDLETYPE hComponent, | ||
139 | OMX_U32 nParam); | ||
140 | |||
141 | |||
142 | /* Event processing */ | ||
143 | OMX_ERRORTYPE OMXBase_EventNotifyToClient(OMX_HANDLETYPE hComponent, | ||
144 | OMX_COMMANDTYPE Cmd, | ||
145 | OMX_U32 nParam, | ||
146 | OMX_PTR pCmdData); | ||
147 | OMX_BOOL OMXBase_IsCmdPending (OMX_HANDLETYPE hComponent); | ||
148 | |||
149 | OMX_ERRORTYPE OMXBase_ProcessEvents(OMX_HANDLETYPE hComponent, | ||
150 | OMX_U32 retEvent); | ||
151 | |||
152 | OMX_ERRORTYPE OMXBase_ProcessTriggerEvent(OMX_HANDLETYPE hComponent, | ||
153 | OMX_U32 EventToSet); | ||
154 | |||
155 | OMX_ERRORTYPE OMXBase_CB_ReturnEventNotify(OMX_HANDLETYPE hComponent, | ||
156 | OMX_EVENTTYPE eEvent, | ||
157 | OMX_U32 nData1, OMX_U32 nData2, | ||
158 | OMX_PTR pEventData); | ||
159 | |||
160 | /* DIO functions */ | ||
161 | OMX_BOOL OMXBase_IsDioReady(OMX_HANDLETYPE hComponent, OMX_U32 nPortIndex); | ||
162 | |||
163 | OMX_ERRORTYPE OMXBase_DIO_Init (OMX_HANDLETYPE hComponent, | ||
164 | OMX_U32 nPortIndex, | ||
165 | OMX_STRING cChannelType, | ||
166 | OMX_PTR pCreateParams); | ||
167 | |||
168 | OMX_ERRORTYPE OMXBase_DIO_Open (OMX_HANDLETYPE hComponent, | ||
169 | OMX_U32 nPortIndex, | ||
170 | OMX_PTR pOpenParams); | ||
171 | |||
172 | OMX_ERRORTYPE OMXBase_DIO_Close (OMX_HANDLETYPE hComponent, | ||
173 | OMX_U32 nPortIndex); | ||
174 | |||
175 | OMX_ERRORTYPE OMXBase_DIO_Queue (OMX_HANDLETYPE hComponent, | ||
176 | OMX_U32 nPortIndex, | ||
177 | OMX_PTR pBuffHeader); | ||
178 | |||
179 | OMX_ERRORTYPE OMXBase_DIO_Dequeue (OMX_HANDLETYPE hComponent, | ||
180 | OMX_U32 nPortIndex, | ||
181 | OMX_PTR *pBuffHeader); | ||
182 | |||
183 | OMX_ERRORTYPE OMXBase_DIO_Send (OMX_HANDLETYPE hComponent, | ||
184 | OMX_U32 nPortIndex, | ||
185 | OMX_PTR pBuffHeader); | ||
186 | |||
187 | OMX_ERRORTYPE OMXBase_DIO_Cancel (OMX_HANDLETYPE hComponent, | ||
188 | OMX_U32 nPortIndex, | ||
189 | OMX_PTR pBuffHeader); | ||
190 | |||
191 | OMX_ERRORTYPE OMXBase_DIO_Control (OMX_HANDLETYPE hComponent, | ||
192 | OMX_U32 nPortIndex, | ||
193 | OMX_DIO_CtrlCmdType nCmdType, | ||
194 | OMX_PTR pParams); | ||
195 | |||
196 | OMX_ERRORTYPE OMXBase_DIO_GetCount (OMX_HANDLETYPE hComponent, | ||
197 | OMX_U32 nPortIndex, | ||
198 | OMX_U32 *pCount); | ||
199 | |||
200 | OMX_ERRORTYPE OMXBase_DIO_Deinit (OMX_HANDLETYPE hComponent, | ||
201 | OMX_U32 nPortIndex); | ||
202 | |||
203 | /* Error Handling */ | ||
204 | |||
205 | OMX_ERRORTYPE OMXBase_Error_EventHandler(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, | ||
206 | OMX_EVENTTYPE eEvent, OMX_U32 nData1, | ||
207 | OMX_U32 nData2, OMX_PTR pEventData); | ||
208 | |||
209 | OMX_ERRORTYPE OMXBase_Error_FillBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, | ||
210 | OMX_BUFFERHEADERTYPE *pBuffer); | ||
211 | |||
212 | OMX_ERRORTYPE OMXBase_Error_EmptyBufferDone(OMX_HANDLETYPE hComponent, OMX_PTR pAppData, | ||
213 | OMX_BUFFERHEADERTYPE *pBuffer); | ||
214 | |||
215 | void OMXBase_HandleFailEvent(OMX_HANDLETYPE hComponent, OMX_COMMANDTYPE eCmd, | ||
216 | OMX_U32 nPortIndex); | ||
217 | OMX_ERRORTYPE OMXBase_UtilCleanupIfError(OMX_HANDLETYPE hComponent); | ||
218 | |||
219 | /* Miscellaneous */ | ||
220 | |||
221 | OMX_ERRORTYPE OMXBase_GetUVBuffer(OMX_HANDLETYPE hComponent, | ||
222 | OMX_U32 nPortIndex, | ||
223 | OMX_PTR pBufHdr, OMX_PTR *pUVBuffer); | ||
224 | |||
225 | |||
226 | |||
227 | #ifdef __cplusplus | ||
228 | } | ||
229 | #endif | ||
230 | |||
231 | #endif /* _OMX_BASE_INTERNAL_H_ */ | ||
232 | |||
diff --git a/libstagefrighthw/omx/base/OMX_BaseProcess.c b/libstagefrighthw/omx/base/OMX_BaseProcess.c new file mode 100644 index 0000000..af1ac90 --- /dev/null +++ b/libstagefrighthw/omx/base/OMX_BaseProcess.c | |||
@@ -0,0 +1,355 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 | #define LOG_TAG "OMX_BASE_PROCESS" | ||
18 | |||
19 | #include <OMX_Core.h> | ||
20 | #include <OMX_Component.h> | ||
21 | #include <OMX_Base.h> | ||
22 | #include <OMX_TI_Custom.h> | ||
23 | |||
24 | static OMX_ERRORTYPE OMXBase_ProcessDataEvent(OMX_HANDLETYPE hComponent); | ||
25 | |||
26 | static OMX_ERRORTYPE OMXBase_ProcessCmdEvent(OMX_HANDLETYPE hComponent, | ||
27 | OMX_COMMANDTYPE Cmd, | ||
28 | OMX_U32 nParam, | ||
29 | OMX_PTR pCmdData); | ||
30 | |||
31 | |||
32 | /* | ||
33 | * OMX Base ProcessTrigger Event | ||
34 | */ | ||
35 | OMX_ERRORTYPE OMXBase_ProcessTriggerEvent(OMX_HANDLETYPE hComponent, | ||
36 | OMX_U32 EventToSet) | ||
37 | { | ||
38 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
39 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
40 | OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
41 | OMXBaseComp *pBaseComp = NULL; | ||
42 | OMXBaseComp_Pvt *pBaseCompPvt = NULL; | ||
43 | OMXBase_Port *pPort = NULL; | ||
44 | OMX_U32 i, nStartPort, nCount = 0; | ||
45 | OMX_BOOL bNotify = OMX_TRUE; | ||
46 | |||
47 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
48 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
49 | nStartPort = pBaseComp->nMinStartPortIndex; | ||
50 | if( EventToSet == DATAEVENT ) { | ||
51 | /*This var mey be accessed by multiple threads but it need not be mutex | ||
52 | protected*/ | ||
53 | if( pBaseCompPvt->bForceNotifyOnce ) { | ||
54 | pBaseCompPvt->bForceNotifyOnce = OMX_FALSE; | ||
55 | bNotify = OMX_TRUE; | ||
56 | goto EXIT; | ||
57 | } | ||
58 | |||
59 | for( i = 0; i < (pBaseComp->nNumPorts); i++ ) { | ||
60 | pPort = pBaseComp->pPorts[i]; | ||
61 | /*If port is disabled then move on*/ | ||
62 | if( !pPort->sPortDef.bEnabled ) { | ||
63 | continue; | ||
64 | } | ||
65 | /*If EOS has been recd. on any one port then always send notification*/ | ||
66 | if( pPort->sPortDef.eDir == OMX_DirInput && pPort->bEosRecd ) { | ||
67 | bNotify = OMX_TRUE; | ||
68 | goto EXIT; | ||
69 | } | ||
70 | } | ||
71 | |||
72 | if( pBaseComp->bNotifyForAnyPort == OMX_TRUE ) { | ||
73 | bNotify = OMX_FALSE; | ||
74 | for( i = 0; i < (pBaseComp->nNumPorts); i++ ) { | ||
75 | pPort = pBaseComp->pPorts[i]; | ||
76 | /*If port is disabled then move on*/ | ||
77 | if( !pPort->sPortDef.bEnabled || | ||
78 | pPort->bIsInTransition) { | ||
79 | continue; | ||
80 | } | ||
81 | eError = pBaseCompPvt->fpDioGetCount(hComponent, nStartPort + i, | ||
82 | &nCount); | ||
83 | OMX_CHECK((eError == OMX_ErrorNone || eError == | ||
84 | (OMX_ERRORTYPE)OMX_TI_WarningEosReceived), eError); | ||
85 | /*Resetting to ErrorNone in case EOS warning is recd.*/ | ||
86 | eError = OMX_ErrorNone; | ||
87 | if((nCount >= pBaseComp->pPorts[i]->sProps.nWatermark)) { | ||
88 | bNotify = OMX_TRUE; | ||
89 | break; | ||
90 | } | ||
91 | } | ||
92 | } else { | ||
93 | for( i = 0; i < (pBaseComp->nNumPorts); i++ ) { | ||
94 | pPort = pBaseComp->pPorts[i]; | ||
95 | /*If port is disabled then move on*/ | ||
96 | if( !pPort->sPortDef.bEnabled || | ||
97 | pPort->bIsInTransition) { | ||
98 | continue; | ||
99 | } | ||
100 | eError = pBaseCompPvt->fpDioGetCount(hComponent, nStartPort + i, | ||
101 | &nCount); | ||
102 | OMX_CHECK((eError == OMX_ErrorNone || eError == | ||
103 | (OMX_ERRORTYPE)OMX_TI_WarningEosReceived), eError); | ||
104 | /*Resetting to ErrorNone in case EOS warning is recd.*/ | ||
105 | eError = OMX_ErrorNone; | ||
106 | if((nCount < pBaseComp->pPorts[i]->sProps.nWatermark)) { | ||
107 | bNotify = OMX_FALSE; | ||
108 | break; | ||
109 | } | ||
110 | } | ||
111 | } | ||
112 | } | ||
113 | |||
114 | EXIT: | ||
115 | if( bNotify == OMX_TRUE && eError == OMX_ErrorNone ) { | ||
116 | tStatus = OSAL_SetEvent(pBaseCompPvt->pTriggerEvent, EventToSet, | ||
117 | OSAL_EVENT_OR); | ||
118 | if( tStatus != OSAL_ErrNone ) { | ||
119 | eError = OMX_ErrorUndefined; | ||
120 | } | ||
121 | } | ||
122 | return (eError); | ||
123 | } | ||
124 | |||
125 | /* | ||
126 | * OMX Base ProcessDataNotify | ||
127 | */ | ||
128 | OMX_ERRORTYPE OMXBase_ProcessDataNotify(OMX_HANDLETYPE hComponent) | ||
129 | { | ||
130 | OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
131 | OMXBaseComp *pBaseComp = NULL; | ||
132 | OMXBaseComp_Pvt *pBaseCompPvt = NULL; | ||
133 | |||
134 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
135 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
136 | pBaseCompPvt->bForceNotifyOnce = OMX_FALSE; | ||
137 | return (OMXBase_ProcessTriggerEvent(hComponent, DATAEVENT)); | ||
138 | } | ||
139 | |||
140 | /* | ||
141 | * OMXBase Process Events | ||
142 | */ | ||
143 | OMX_ERRORTYPE OMXBase_ProcessEvents(OMX_HANDLETYPE hComponent, | ||
144 | OMX_U32 retEvent) | ||
145 | { | ||
146 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
147 | OMX_ERRORTYPE eErrorAux = OMX_ErrorNone; | ||
148 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
149 | OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
150 | OMXBaseComp *pBaseComp = NULL; | ||
151 | OMXBaseComp_Pvt *pBaseCompPvt = NULL; | ||
152 | OMXBase_CmdParams sCmdParams; | ||
153 | uint32_t actualSize = 0; | ||
154 | OMX_BOOL bHandleFailEvent = OMX_FALSE; | ||
155 | |||
156 | |||
157 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
158 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
159 | if( retEvent & CMDEVENT ) { | ||
160 | tStatus = OSAL_ObtainMutex(pBaseCompPvt->pCmdPipeMutex, | ||
161 | OSAL_SUSPEND); | ||
162 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorUndefined); | ||
163 | /* process command event */ | ||
164 | tStatus = OSAL_IsPipeReady(pBaseCompPvt->pCmdPipe); | ||
165 | if( tStatus != OSAL_ErrNone ) { | ||
166 | /*No command in pipe - return*/ | ||
167 | tStatus = OSAL_ReleaseMutex(pBaseCompPvt->pCmdPipeMutex); | ||
168 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorUndefined); | ||
169 | goto EXIT; | ||
170 | } | ||
171 | tStatus = OSAL_ReadFromPipe(pBaseCompPvt->pCmdPipe, &sCmdParams, | ||
172 | sizeof(OMXBase_CmdParams), &actualSize, OSAL_NO_SUSPEND); | ||
173 | if( OSAL_ErrNone != tStatus ) { | ||
174 | eError = OMX_ErrorUndefined; | ||
175 | } | ||
176 | tStatus = OSAL_ReleaseMutex(pBaseCompPvt->pCmdPipeMutex); | ||
177 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorUndefined); | ||
178 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
179 | |||
180 | eError = OMXBase_ProcessCmdEvent(hComponent, sCmdParams.eCmd, | ||
181 | sCmdParams.unParam, sCmdParams.pCmdData); | ||
182 | if( OMX_ErrorNone != eError ) { | ||
183 | bHandleFailEvent = OMX_TRUE; | ||
184 | goto EXIT; | ||
185 | } | ||
186 | } else if( retEvent & DATAEVENT ) { | ||
187 | /* process data Event */ | ||
188 | eError = OMXBase_ProcessDataEvent(hComponent); | ||
189 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
190 | } | ||
191 | EXIT: | ||
192 | if( OMX_ErrorNone != eError ) { | ||
193 | if(eError != OMX_ErrorDynamicResourcesUnavailable) { | ||
194 | eErrorAux = pBaseCompPvt->sAppCallbacks.EventHandler(hComponent, | ||
195 | pComp->pApplicationPrivate, | ||
196 | OMX_EventError, eError, | ||
197 | OMX_StateInvalid, NULL); | ||
198 | } else { | ||
199 | eErrorAux = pBaseCompPvt->sAppCallbacks.EventHandler(hComponent, | ||
200 | pComp->pApplicationPrivate, | ||
201 | OMX_EventError, eError, | ||
202 | OMX_StateLoaded, NULL); | ||
203 | } | ||
204 | /*Component can do nothing if callback returns error*/ | ||
205 | /*Just calling OMXBase_HandleFailEvent for SetState since it was the | ||
206 | * the intention. When Allocation fails while Dynamic Resources Allocation | ||
207 | * we are experiencing hang waiting forever for PortDisable event completion | ||
208 | * after attempted an unsuccessful PortEnable. | ||
209 | */ | ||
210 | if( bHandleFailEvent && (eError != OMX_ErrorDynamicResourcesUnavailable) ) { | ||
211 | OMXBase_HandleFailEvent(hComponent, sCmdParams.eCmd, sCmdParams.unParam); | ||
212 | } | ||
213 | } | ||
214 | if( (OMX_ErrorNone != eError) && (eError != OMX_ErrorDynamicResourcesUnavailable) ) { | ||
215 | return (eError); //return actual error if any | ||
216 | } | ||
217 | |||
218 | return (eErrorAux); | ||
219 | } | ||
220 | |||
221 | /* | ||
222 | * OMX Base Process Command Event | ||
223 | */ | ||
224 | static OMX_ERRORTYPE OMXBase_ProcessCmdEvent(OMX_HANDLETYPE hComponent, | ||
225 | OMX_COMMANDTYPE Cmd, | ||
226 | OMX_U32 nParam, | ||
227 | OMX_PTR pCmdData) | ||
228 | { | ||
229 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
230 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
231 | OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
232 | OMXBaseComp *pBaseComp = NULL; | ||
233 | OMXBaseComp_Pvt *pBaseCompPvt = NULL; | ||
234 | OMX_U32 i, nPorts, nStartPortNum; | ||
235 | uint32_t retEvents = 0; | ||
236 | |||
237 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
238 | pBaseCompPvt = (OMXBaseComp_Pvt *)pBaseComp->pPvtData; | ||
239 | nPorts = pBaseComp->nNumPorts; | ||
240 | nStartPortNum = pBaseComp->nMinStartPortIndex; | ||
241 | |||
242 | switch( Cmd ) { | ||
243 | case OMX_CommandStateSet : | ||
244 | eError = OMXBase_HandleStateTransition(hComponent, nParam); | ||
245 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
246 | break; | ||
247 | |||
248 | case OMX_CommandPortDisable : | ||
249 | /* Notify to Derived Component here so that derived component | ||
250 | receives correct param - ALL or specific port no. */ | ||
251 | eError = pBaseComp->fpCommandNotify(hComponent, | ||
252 | OMX_CommandPortDisable, nParam, pCmdData); | ||
253 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
254 | |||
255 | tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pCmdCompleteEvent, | ||
256 | OMXBase_CmdPortDisable, OSAL_EVENT_OR_CONSUME, | ||
257 | &retEvents, OSAL_SUSPEND); | ||
258 | OMX_CHECK(OSAL_ErrNone == tStatus, | ||
259 | OMX_ErrorInsufficientResources); | ||
260 | if( nParam == OMX_ALL ) { | ||
261 | for( i = nStartPortNum; i < nPorts; i++ ) { | ||
262 | eError = OMXBase_DisablePort(hComponent, i); | ||
263 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
264 | } | ||
265 | } else { | ||
266 | eError = OMXBase_DisablePort(hComponent, nParam); | ||
267 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
268 | } | ||
269 | break; | ||
270 | |||
271 | case OMX_CommandPortEnable : | ||
272 | /* Notify to Derived Component here so that derived component | ||
273 | receives correct param - ALL or specific port no. */ | ||
274 | eError = pBaseComp->fpCommandNotify(hComponent, | ||
275 | OMX_CommandPortEnable, nParam, pCmdData); | ||
276 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
277 | tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pCmdCompleteEvent, | ||
278 | OMXBase_CmdPortEnable, OSAL_EVENT_OR_CONSUME, | ||
279 | &retEvents, OSAL_SUSPEND); | ||
280 | OMX_CHECK(OSAL_ErrNone == tStatus, | ||
281 | OMX_ErrorInsufficientResources); | ||
282 | if( nParam == OMX_ALL ) { | ||
283 | for( i = nStartPortNum; i < nPorts; i++ ) { | ||
284 | eError = OMXBase_EnablePort(hComponent, i); | ||
285 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
286 | } | ||
287 | } else { | ||
288 | eError = OMXBase_EnablePort(hComponent, nParam); | ||
289 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
290 | } | ||
291 | break; | ||
292 | |||
293 | case OMX_CommandFlush : | ||
294 | if( pBaseComp->tCurState == OMX_StateLoaded || | ||
295 | pBaseComp->tCurState == OMX_StateWaitForResources ) { | ||
296 | } else if((nParam != OMX_ALL) && (pBaseComp->pPorts | ||
297 | [nParam - nStartPortNum]->sPortDef.bEnabled == OMX_FALSE)) { | ||
298 | /*Nothing to be done for disabled port, just exit*/ | ||
299 | } else { | ||
300 | /* Notify to Derived Component here so that derived component | ||
301 | receives correct param - ALL or specific port no. */ | ||
302 | eError = pBaseComp->fpCommandNotify(hComponent, | ||
303 | OMX_CommandFlush, nParam, pCmdData); | ||
304 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
305 | tStatus = OSAL_RetrieveEvent(pBaseCompPvt->pCmdCompleteEvent, | ||
306 | OMXBase_CmdFlush, OSAL_EVENT_OR_CONSUME, | ||
307 | &retEvents, OSAL_SUSPEND); | ||
308 | OMX_CHECK(OSAL_ErrNone == tStatus, OMX_ErrorInsufficientResources); | ||
309 | if( nParam == OMX_ALL ) { | ||
310 | for( i = nStartPortNum; i < nPorts; i++ ) { | ||
311 | eError = OMXBase_FlushBuffers(hComponent, i); | ||
312 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
313 | } | ||
314 | } else { | ||
315 | eError = OMXBase_FlushBuffers(hComponent, nParam); | ||
316 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
317 | } | ||
318 | } | ||
319 | break; | ||
320 | |||
321 | case OMX_CommandMarkBuffer : | ||
322 | eError = pBaseComp->fpCommandNotify(hComponent, Cmd, | ||
323 | nParam, pCmdData); | ||
324 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
325 | break; | ||
326 | |||
327 | default : | ||
328 | OSAL_ErrorTrace(" unknown command received "); | ||
329 | break; | ||
330 | } | ||
331 | |||
332 | eError = OMXBase_EventNotifyToClient(hComponent, Cmd, nParam, pCmdData); | ||
333 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
334 | |||
335 | EXIT: | ||
336 | return (eError); | ||
337 | } | ||
338 | |||
339 | /* | ||
340 | * OMX Base Process Data Event | ||
341 | */ | ||
342 | static OMX_ERRORTYPE OMXBase_ProcessDataEvent(OMX_HANDLETYPE hComponent) | ||
343 | { | ||
344 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
345 | OMX_COMPONENTTYPE *pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
346 | OMXBaseComp *pBaseComp = NULL; | ||
347 | |||
348 | pBaseComp = (OMXBaseComp *)pComp->pComponentPrivate; | ||
349 | eError = pBaseComp->fpDataNotify(hComponent); | ||
350 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
351 | |||
352 | EXIT: | ||
353 | return (eError); | ||
354 | } | ||
355 | |||
diff --git a/libstagefrighthw/omx/base/OMX_BaseUtils.h b/libstagefrighthw/omx/base/OMX_BaseUtils.h new file mode 100644 index 0000000..6b4d890 --- /dev/null +++ b/libstagefrighthw/omx/base/OMX_BaseUtils.h | |||
@@ -0,0 +1,60 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 _OMX_BASE_UTILS_H_ | ||
18 | #define _OMX_BASE_UTILS_H_ | ||
19 | |||
20 | #ifdef __cplusplus | ||
21 | extern "C" { | ||
22 | #endif | ||
23 | |||
24 | #include <osal_trace.h> | ||
25 | |||
26 | #define OMX_CHECK(_COND_, _ERRORCODE_) do { \ | ||
27 | if( !(_COND_)) { eError = _ERRORCODE_; \ | ||
28 | OSAL_ErrorTrace("Failed check: " # _COND_); \ | ||
29 | OSAL_ErrorTrace("Returning error: " # _ERRORCODE_); \ | ||
30 | goto EXIT; } \ | ||
31 | } while( 0 ) | ||
32 | |||
33 | #define OMX_BASE_CHK_VERSION(_pStruct_, _sName_, _e_) do { \ | ||
34 | if(((_sName_ *)_pStruct_)->nSize != sizeof(_sName_)) { \ | ||
35 | _e_ = OMX_ErrorBadParameter; \ | ||
36 | OSAL_ErrorTrace("Incorrect 'nSize' field. Returning OMX_ErrorBadParameter"); \ | ||
37 | goto EXIT; } \ | ||
38 | if((((_sName_ *)_pStruct_)->nVersion.s.nVersionMajor != 0x1) || \ | ||
39 | ((((_sName_ *)_pStruct_)->nVersion.s.nVersionMinor != 0x1) && \ | ||
40 | ((_sName_ *)_pStruct_)->nVersion.s.nVersionMinor != 0x0 )) { \ | ||
41 | _e_ = OMX_ErrorVersionMismatch; \ | ||
42 | OSAL_ErrorTrace("Version mismatch. Returning OMX_ErrorVersionMismatch"); \ | ||
43 | goto EXIT; } \ | ||
44 | } while( 0 ) | ||
45 | |||
46 | #define OMX_BASE_INIT_STRUCT_PTR(_pStruct_, _sName_) do { \ | ||
47 | OSAL_Memset((_pStruct_), 0x0, sizeof(_sName_)); \ | ||
48 | (_pStruct_)->nSize = sizeof(_sName_); \ | ||
49 | (_pStruct_)->nVersion.s.nVersionMajor = 0x1; \ | ||
50 | (_pStruct_)->nVersion.s.nVersionMinor = 0x1; \ | ||
51 | (_pStruct_)->nVersion.s.nRevision = 0x2; \ | ||
52 | (_pStruct_)->nVersion.s.nStep = 0x0; \ | ||
53 | } while( 0 ) | ||
54 | |||
55 | #ifdef __cplusplus | ||
56 | } | ||
57 | #endif | ||
58 | |||
59 | #endif /* _OMX_BASE_UTILS_H_ */ | ||
60 | |||
diff --git a/libstagefrighthw/omx/base/OMX_TI_Custom.h b/libstagefrighthw/omx/base/OMX_TI_Custom.h new file mode 100644 index 0000000..7fbe9e5 --- /dev/null +++ b/libstagefrighthw/omx/base/OMX_TI_Custom.h | |||
@@ -0,0 +1,109 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 OMX_TI_Custom_H | ||
18 | #define OMX_TI_Custom_H | ||
19 | |||
20 | #ifdef __cplusplus | ||
21 | extern "C" { | ||
22 | #endif | ||
23 | |||
24 | #include <OMX_IVCommon.h> | ||
25 | |||
26 | /** | ||
27 | * A pointer to this struct is passed to the OMX_SetParameter when the extension | ||
28 | * index for the 'OMX.google.android.index.enableAndroidNativeBuffers' extension | ||
29 | * is given. | ||
30 | * The corresponding extension Index is OMX_TI_IndexUseNativeBuffers. | ||
31 | * This will be used to inform OMX about the presence of gralloc pointers instead | ||
32 | * of virtual pointers | ||
33 | */ | ||
34 | typedef struct OMX_TI_PARAMUSENATIVEBUFFER { | ||
35 | OMX_U32 nSize; | ||
36 | OMX_VERSIONTYPE nVersion; | ||
37 | OMX_U32 nPortIndex; | ||
38 | OMX_BOOL bEnable; | ||
39 | } OMX_TI_PARAMUSENATIVEBUFFER; | ||
40 | |||
41 | /** | ||
42 | * A pointer to this struct is passed to OMX_GetParameter when the extension | ||
43 | * index for the 'OMX.google.android.index.getAndroidNativeBufferUsage' | ||
44 | * extension is given. | ||
45 | * The corresponding extension Index is OMX_TI_IndexAndroidNativeBufferUsage. | ||
46 | * The usage bits returned from this query will be used to allocate the Gralloc | ||
47 | * buffers that get passed to the useAndroidNativeBuffer command. | ||
48 | */ | ||
49 | typedef struct OMX_TI_PARAMNATIVEBUFFERUSAGE { | ||
50 | OMX_U32 nSize; | ||
51 | OMX_VERSIONTYPE nVersion; | ||
52 | OMX_U32 nPortIndex; | ||
53 | OMX_U32 nUsage; | ||
54 | } OMX_TI_PARAMNATIVEBUFFERUSAGE; | ||
55 | |||
56 | typedef enum OMX_TI_INDEXTYPE { | ||
57 | OMX_TI_IndexUseNativeBuffers = ((OMX_INDEXTYPE)OMX_IndexVendorStartUnused + 1), | ||
58 | OMX_TI_IndexAndroidNativeBufferUsage, | ||
59 | OMX_TI_IndexParamTimeStampInDecodeOrder, | ||
60 | OMX_TI_IndexEncoderReceiveMetadataBuffers, | ||
61 | OMX_TI_IndexDescribeColorFormat, | ||
62 | OMX_TI_IndexEnableDecoderZeroDisplayDelayMode, | ||
63 | OMX_TI_IndexPrepareForAdaptivePlayback | ||
64 | } OMX_TI_INDEXTYPE; | ||
65 | |||
66 | typedef enum OMX_TI_ERRORTYPE | ||
67 | { | ||
68 | /*Control attribute is pending - Dio_Dequeue will not work until attribute | ||
69 | is retreived*/ | ||
70 | OMX_TI_WarningAttributePending = (OMX_S32)((OMX_ERRORTYPE)OMX_ErrorVendorStartUnused + 1), | ||
71 | /*Attribute buffer size is insufficient - reallocate the attribute buffer*/ | ||
72 | OMX_TI_WarningInsufficientAttributeSize, | ||
73 | /*EOS buffer has been received*/ | ||
74 | OMX_TI_WarningEosReceived, | ||
75 | /*Port enable is called on an already enabled port*/ | ||
76 | OMX_TI_ErrorPortIsAlreadyEnabled, | ||
77 | /*Port disable is called on an already disabled port*/ | ||
78 | OMX_TI_ErrorPortIsAlreadyDisabled | ||
79 | } OMX_TI_ERRORTYPE; | ||
80 | |||
81 | |||
82 | /** | ||
83 | * OMX_TI_VIDEO_CONFIG_AVC_LTRP_INTERVAL : Structure to enable timestamps in decode order | ||
84 | * at i/p of decoders. | ||
85 | */ | ||
86 | typedef struct OMX_TI_PARAM_TIMESTAMP_IN_DECODE_ORDER { | ||
87 | OMX_U32 nSize; | ||
88 | OMX_VERSIONTYPE nVersion; | ||
89 | OMX_BOOL bEnabled; | ||
90 | } OMX_TI_PARAM_TIMESTAMP_IN_DECODE_ORDER; | ||
91 | |||
92 | |||
93 | /** | ||
94 | * OMX_TI_ENABLE_DECODER_ZERODISPLAYDELAY_MODE : Structure to enable Decoder zero display delay mode | ||
95 | * | ||
96 | */ | ||
97 | typedef struct OMX_TI_ENABLE_DECODER_ZERODISPLAYDELAY_MODE { | ||
98 | OMX_U32 nSize; | ||
99 | OMX_VERSIONTYPE nVersion; | ||
100 | OMX_U32 nPortIndex; | ||
101 | OMX_BOOL bEnabled; | ||
102 | } OMX_TI_ENABLE_DECODER_ZERODISPLAYDELAY_MODE; | ||
103 | |||
104 | #ifdef __cplusplus | ||
105 | } | ||
106 | #endif | ||
107 | |||
108 | #endif | ||
109 | |||
diff --git a/libstagefrighthw/omx/osal/Android.bp b/libstagefrighthw/omx/osal/Android.bp new file mode 100644 index 0000000..99a4dc7 --- /dev/null +++ b/libstagefrighthw/omx/osal/Android.bp | |||
@@ -0,0 +1,27 @@ | |||
1 | // OSAL library | ||
2 | |||
3 | cc_library_shared { | ||
4 | |||
5 | name: "libosal", | ||
6 | vendor: true, | ||
7 | |||
8 | srcs: [ | ||
9 | "src/osal_events.c", | ||
10 | "src/osal_memory.c", | ||
11 | "src/osal_mutex.c", | ||
12 | "src/osal_pipes.c", | ||
13 | "src/osal_semaphores.c", | ||
14 | "src/osal_task.c", | ||
15 | ], | ||
16 | |||
17 | local_include_dirs: ["inc"], | ||
18 | |||
19 | export_include_dirs: ["inc"], | ||
20 | |||
21 | shared_libs: [ | ||
22 | "libc", | ||
23 | "libutils", | ||
24 | "liblog", | ||
25 | ], | ||
26 | |||
27 | } | ||
diff --git a/libstagefrighthw/omx/osal/inc/osal_error.h b/libstagefrighthw/omx/osal/inc/osal_error.h new file mode 100755 index 0000000..1d25b04 --- /dev/null +++ b/libstagefrighthw/omx/osal/inc/osal_error.h | |||
@@ -0,0 +1,83 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 _OSAL_ERROR_H_ | ||
18 | #define _OSAL_ERROR_H_ | ||
19 | |||
20 | #ifdef __cplusplus | ||
21 | extern "C" | ||
22 | { | ||
23 | #endif | ||
24 | |||
25 | #define OSAL_TRUE 1 | ||
26 | #define OSAL_FALSE 0 | ||
27 | |||
28 | #define SUCCESS 0 | ||
29 | #define NO_SUCCESS -1 | ||
30 | |||
31 | #define OSAL_SUSPEND 0xFFFFFFFFUL | ||
32 | #define OSAL_NO_SUSPEND 0x0 | ||
33 | #define OSAL_TIMED_OUT 0x7FFFFFFFUL | ||
34 | |||
35 | typedef enum osal_error { | ||
36 | OSAL_ErrNone = 0, | ||
37 | /* General module error list */ | ||
38 | OSAL_ErrNoPermissions = -1, | ||
39 | OSAL_ErrNotSupported = -2, | ||
40 | OSAL_ErrAlloc = -3, | ||
41 | OSAL_ErrOutOfResource = -4, | ||
42 | OSAL_ErrTimeOut = -5, | ||
43 | OSAL_ErrParameter = -6, | ||
44 | /* Pipe Module error list */ | ||
45 | OSAL_ErrNotReady = -11, | ||
46 | OSAL_ErrPipeFull = -12, | ||
47 | OSAL_ErrPipeEmpty = -13, | ||
48 | OSAL_ErrPipeDeleted = -14, | ||
49 | OSAL_ErrPipeReset = -15, | ||
50 | OSAL_ErrPipeClose = -16, | ||
51 | OSAL_ErrPipeWrite = -17, | ||
52 | OSAL_ErrPipeRead = -18, | ||
53 | /* Semaphore module error list */ | ||
54 | OSAL_ErrSemCreate = -20, | ||
55 | OSAL_ErrSemDelete = -21, | ||
56 | OSAL_ErrSemPost = -22, | ||
57 | OSAL_ErrSemGetValue = -23, | ||
58 | /* message queue module error list */ | ||
59 | OSAL_ErrMsgSzieMismatch = -30, | ||
60 | OSAL_ErrMsgTypeNotFound = -31, | ||
61 | OSAL_ErrUnKnown = -32, | ||
62 | /* Mutex module error list */ | ||
63 | OSAL_ErrMutexCreate = -40, | ||
64 | OSAL_ErrMutexDestroy = -41, | ||
65 | OSAL_ErrMutexLock = -42, | ||
66 | OSAL_ErrMutexUnlock = -43, | ||
67 | /* Events module error list */ | ||
68 | OSAL_ErrEventCreate = -50, | ||
69 | OSAL_ErrEventDestroy = -51, | ||
70 | OSAL_ErrSetEvent = -52, | ||
71 | OSAL_ErrRetrieve = -53, | ||
72 | OSAL_ErrEventSignal = -54, | ||
73 | /* Thread module error list */ | ||
74 | OSAL_ErrThreadCreate = -60, | ||
75 | OSAL_ErrThreadDestroy = -61, | ||
76 | } OSAL_ERROR; | ||
77 | |||
78 | |||
79 | #ifdef __cplusplus | ||
80 | } | ||
81 | #endif | ||
82 | |||
83 | #endif /*_OSAL_ERROR_H_*/ | ||
diff --git a/libstagefrighthw/omx/osal/inc/osal_events.h b/libstagefrighthw/omx/osal/inc/osal_events.h new file mode 100755 index 0000000..d6248c1 --- /dev/null +++ b/libstagefrighthw/omx/osal/inc/osal_events.h | |||
@@ -0,0 +1,47 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 _OSAL_EVENTS_H_ | ||
18 | #define _OSAL_EVENTS_H_ | ||
19 | |||
20 | #ifdef __cplusplus | ||
21 | extern "C" | ||
22 | { | ||
23 | #endif | ||
24 | |||
25 | #include "osal_error.h" | ||
26 | |||
27 | /* | ||
28 | * OSAL EVENT Operations list | ||
29 | */ | ||
30 | typedef enum osal_event_op | ||
31 | { | ||
32 | OSAL_EVENT_AND, | ||
33 | OSAL_EVENT_AND_CONSUME, | ||
34 | OSAL_EVENT_OR, | ||
35 | OSAL_EVENT_OR_CONSUME | ||
36 | } OSAL_EventOp; | ||
37 | |||
38 | OSAL_ERROR OSAL_CreateEvent(void **pEvents); | ||
39 | OSAL_ERROR OSAL_DeleteEvent(void *pEvents); | ||
40 | OSAL_ERROR OSAL_SetEvent(void *pEvents, uint32_t uEventFlag, OSAL_EventOp eOperation); | ||
41 | OSAL_ERROR OSAL_RetrieveEvent(void *pEvents, uint32_t uRequestedEvents, OSAL_EventOp eOperation, uint32_t *pRetrievedEvents, uint32_t uTimeOut); | ||
42 | |||
43 | #ifdef __cplusplus | ||
44 | } | ||
45 | #endif | ||
46 | |||
47 | #endif /* _OSAL_EVENTS_H_ */ | ||
diff --git a/libstagefrighthw/omx/osal/inc/osal_memory.h b/libstagefrighthw/omx/osal/inc/osal_memory.h new file mode 100755 index 0000000..462cba9 --- /dev/null +++ b/libstagefrighthw/omx/osal/inc/osal_memory.h | |||
@@ -0,0 +1,37 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 _OSAL_MEMORY_H_ | ||
18 | #define _OSAL_MEMORY_H_ | ||
19 | |||
20 | #ifdef __cplusplus | ||
21 | extern "C" | ||
22 | { | ||
23 | #endif | ||
24 | |||
25 | #include "osal_error.h" | ||
26 | |||
27 | void *OSAL_Malloc(uint32_t size); | ||
28 | void OSAL_Free(void *pData); | ||
29 | OSAL_ERROR OSAL_Memset(void *pBuffer, uint8_t uValue, uint32_t uSize); | ||
30 | int32_t OSAL_Memcmp(void *pBuffer1, void *pBuffer2, uint32_t uSize); | ||
31 | OSAL_ERROR OSAL_Memcpy(void *pBufDst, void *pBufSrc, uint32_t uSize); | ||
32 | |||
33 | #ifdef __cplusplus | ||
34 | } | ||
35 | #endif | ||
36 | |||
37 | #endif /* _OSAL_DEFINES_H_ */ | ||
diff --git a/libstagefrighthw/omx/osal/inc/osal_mutex.h b/libstagefrighthw/omx/osal/inc/osal_mutex.h new file mode 100755 index 0000000..21adf13 --- /dev/null +++ b/libstagefrighthw/omx/osal/inc/osal_mutex.h | |||
@@ -0,0 +1,36 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 _OSAL_MUTEX_H_ | ||
18 | #define _OSAL_MUTEX_H_ | ||
19 | |||
20 | #ifdef __cplusplus | ||
21 | extern "C" | ||
22 | { | ||
23 | #endif | ||
24 | |||
25 | #include "osal_error.h" | ||
26 | |||
27 | OSAL_ERROR OSAL_CreateMutex(void **pMutex); | ||
28 | OSAL_ERROR OSAL_DeleteMutex(void *pMutex); | ||
29 | OSAL_ERROR OSAL_ObtainMutex(void *pMutex, uint32_t uTimeOut); | ||
30 | OSAL_ERROR OSAL_ReleaseMutex(void *pMutex); | ||
31 | |||
32 | #ifdef __cplusplus | ||
33 | } | ||
34 | #endif | ||
35 | |||
36 | #endif /* _OSAL_MUTEX_H_ */ | ||
diff --git a/libstagefrighthw/omx/osal/inc/osal_pipes.h b/libstagefrighthw/omx/osal/inc/osal_pipes.h new file mode 100755 index 0000000..0405ce2 --- /dev/null +++ b/libstagefrighthw/omx/osal/inc/osal_pipes.h | |||
@@ -0,0 +1,40 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 _OSAL_PIPES_H_ | ||
18 | #define _OSAL_PIPES_H_ | ||
19 | |||
20 | #ifdef __cplusplus | ||
21 | extern "C" | ||
22 | { | ||
23 | #endif | ||
24 | |||
25 | #include "osal_error.h" | ||
26 | |||
27 | OSAL_ERROR OSAL_CreatePipe(void **pPipe, uint32_t pipeSize, uint32_t messageSize, uint8_t isFixedMessage); | ||
28 | OSAL_ERROR OSAL_DeletePipe(void *pPipe); | ||
29 | OSAL_ERROR OSAL_WriteToPipe(void *pPipe, void *pMessage, uint32_t size, int32_t timeout); | ||
30 | OSAL_ERROR OSAL_WriteToFrontOfPipe(void *pPipe, void *pMessage, uint32_t, int32_t timeout); | ||
31 | OSAL_ERROR OSAL_ReadFromPipe(void *pPipe, void *pMessage, uint32_t size, uint32_t *actualSize, int32_t timeout); | ||
32 | OSAL_ERROR OSAL_ClearPipe(void *pPipe); | ||
33 | OSAL_ERROR OSAL_IsPipeReady(void *pPipe); | ||
34 | OSAL_ERROR OSAL_GetPipeReadyMessageCount(void *pPipe, uint32_t *count); | ||
35 | |||
36 | #ifdef __cplusplus | ||
37 | } | ||
38 | #endif | ||
39 | |||
40 | #endif /* _OSAL_PIPES_H_ */ | ||
diff --git a/libstagefrighthw/omx/osal/inc/osal_semaphores.h b/libstagefrighthw/omx/osal/inc/osal_semaphores.h new file mode 100755 index 0000000..5a43f9f --- /dev/null +++ b/libstagefrighthw/omx/osal/inc/osal_semaphores.h | |||
@@ -0,0 +1,38 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 _OSAL_SEMAPHORE_H_ | ||
18 | #define _OSAL_SEMAPHORE_H_ | ||
19 | |||
20 | #ifdef __cplusplus | ||
21 | extern "C" | ||
22 | { | ||
23 | #endif | ||
24 | |||
25 | #include "osal_error.h" | ||
26 | |||
27 | OSAL_ERROR OSAL_CreateSemaphore(void **pSemaphore, uint32_t uInitCount); | ||
28 | OSAL_ERROR OSAL_DeleteSemaphore(void *pSemaphore); | ||
29 | OSAL_ERROR OSAL_ObtainSemaphore(void *pSemaphore, uint32_t uTimeOut); | ||
30 | OSAL_ERROR OSAL_ReleaseSemaphore(void *pSemaphore); | ||
31 | OSAL_ERROR OSAL_ResetSemaphore(void *pSemaphore, uint32_t uInitCount); | ||
32 | OSAL_ERROR OSAL_GetSemaphoreCount(void *pSemaphore, uint32_t *count); | ||
33 | |||
34 | #ifdef __cplusplus | ||
35 | } | ||
36 | #endif | ||
37 | |||
38 | #endif /* _OSAL_SEMAPHORE_H_ */ | ||
diff --git a/libstagefrighthw/omx/osal/inc/osal_task.h b/libstagefrighthw/omx/osal/inc/osal_task.h new file mode 100755 index 0000000..da9bcdb --- /dev/null +++ b/libstagefrighthw/omx/osal/inc/osal_task.h | |||
@@ -0,0 +1,37 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 _OSAL_TASK_H_ | ||
18 | #define _OSAL_TASK_H_ | ||
19 | |||
20 | #ifdef __cplusplus | ||
21 | extern "C" | ||
22 | { | ||
23 | #endif | ||
24 | |||
25 | #include "osal_error.h" | ||
26 | |||
27 | typedef void *(*OSAL_TaskProc) (void *arg); | ||
28 | |||
29 | OSAL_ERROR OSAL_CreateTask(void **pTask, OSAL_TaskProc pFunc, uint32_t uArgc, void *pArgv, uint32_t uStackSize, uint32_t uPriority, int8_t * pName); | ||
30 | OSAL_ERROR OSAL_DeleteTask(void *pTask); | ||
31 | OSAL_ERROR OSAL_SleepTask(uint32_t mSec); | ||
32 | |||
33 | #ifdef __cplusplus | ||
34 | } | ||
35 | #endif | ||
36 | |||
37 | #endif /* _OSAL_TASK_H_ */ | ||
diff --git a/libstagefrighthw/omx/osal/inc/osal_trace.h b/libstagefrighthw/omx/osal/inc/osal_trace.h new file mode 100755 index 0000000..cd9213a --- /dev/null +++ b/libstagefrighthw/omx/osal/inc/osal_trace.h | |||
@@ -0,0 +1,37 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 _OSAL_TRACES_H_ | ||
18 | #define _OSAL_TRACES_H_ | ||
19 | |||
20 | #ifdef __cplusplus | ||
21 | extern "C" | ||
22 | { | ||
23 | #endif | ||
24 | |||
25 | #include <utils/Log.h> | ||
26 | |||
27 | #define OSAL_ErrorTrace(fmt,...) ALOGE(fmt,##__VA_ARGS__); | ||
28 | #define OSAL_WarningTrace(fmt,...) ALOGE(fmt,##__VA_ARGS__); | ||
29 | #define OSAL_Info(fmt,...) ALOGD(fmt,##__VA_ARGS__); | ||
30 | #define OSAL_Entering(fmt,...) ALOGD(fmt,##__VA_ARGS__); | ||
31 | #define OSAL_Exiting(fmt,...) ALOGD(fmt,##__VA_ARGS__); | ||
32 | |||
33 | #ifdef __cplusplus | ||
34 | } | ||
35 | #endif | ||
36 | |||
37 | #endif /* _OSAL_TRACES_H_ */ | ||
diff --git a/libstagefrighthw/omx/osal/src/osal_events.c b/libstagefrighthw/omx/osal/src/osal_events.c new file mode 100755 index 0000000..c8486fc --- /dev/null +++ b/libstagefrighthw/omx/osal/src/osal_events.c | |||
@@ -0,0 +1,275 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 <stdio.h> | ||
18 | #include <pthread.h> /*for POSIX calls */ | ||
19 | #include <sys/time.h> | ||
20 | #include <errno.h> | ||
21 | |||
22 | #include "osal_trace.h" | ||
23 | #include "osal_error.h" | ||
24 | #include "osal_memory.h" | ||
25 | #include "osal_events.h" | ||
26 | |||
27 | /* | ||
28 | * Thread event internal structure | ||
29 | */ | ||
30 | typedef struct | ||
31 | { | ||
32 | uint8_t bSignaled; | ||
33 | uint32_t eFlags; | ||
34 | pthread_mutex_t mutex; | ||
35 | pthread_cond_t condition; | ||
36 | } OSAL_ThreadEvent; | ||
37 | |||
38 | /* Event Create Method */ | ||
39 | OSAL_ERROR OSAL_CreateEvent(void **pEvents) | ||
40 | { | ||
41 | OSAL_ERROR bRet = OSAL_ErrUnKnown; | ||
42 | OSAL_ThreadEvent *plEvent = (OSAL_ThreadEvent *) OSAL_Malloc(sizeof(OSAL_ThreadEvent)); | ||
43 | if (NULL == plEvent) { | ||
44 | bRet = OSAL_ErrAlloc; | ||
45 | goto EXIT; | ||
46 | } | ||
47 | plEvent->bSignaled = OSAL_FALSE; | ||
48 | plEvent->eFlags = 0; | ||
49 | |||
50 | if (SUCCESS != pthread_mutex_init(&(plEvent->mutex), NULL)) { | ||
51 | OSAL_ErrorTrace("Event Create:Mutex Init failed !"); | ||
52 | bRet = OSAL_ErrMutexCreate; | ||
53 | goto EXIT; | ||
54 | } | ||
55 | |||
56 | if (SUCCESS != pthread_cond_init(&(plEvent->condition), NULL)) { | ||
57 | OSAL_ErrorTrace("Event Create:Conditional Variable Init failed !"); | ||
58 | pthread_mutex_destroy(&(plEvent->mutex)); | ||
59 | bRet = OSAL_ErrEventCreate; | ||
60 | } else { | ||
61 | *pEvents = (void *) plEvent; | ||
62 | bRet = OSAL_ErrNone; | ||
63 | } | ||
64 | EXIT: | ||
65 | if ((OSAL_ErrNone != bRet) && (NULL != plEvent)) { | ||
66 | OSAL_Free(plEvent); | ||
67 | } | ||
68 | return bRet; | ||
69 | } | ||
70 | |||
71 | /* | ||
72 | * Method to delete the event | ||
73 | */ | ||
74 | OSAL_ERROR OSAL_DeleteEvent(void *pEvents) | ||
75 | { | ||
76 | OSAL_ERROR bRet = OSAL_ErrNone; | ||
77 | OSAL_ThreadEvent *plEvent = (OSAL_ThreadEvent*) pEvents; | ||
78 | if (NULL == plEvent) { | ||
79 | bRet = OSAL_ErrParameter; | ||
80 | goto EXIT; | ||
81 | } | ||
82 | |||
83 | if (SUCCESS != pthread_mutex_lock(&(plEvent->mutex))) { | ||
84 | OSAL_ErrorTrace("Event Delete: Mutex Lock failed !"); | ||
85 | bRet = OSAL_ErrMutexLock; | ||
86 | } | ||
87 | if (SUCCESS != pthread_cond_destroy(&(plEvent->condition))) { | ||
88 | OSAL_ErrorTrace("Event Delete: Conditional Variable Destroy failed !"); | ||
89 | bRet = OSAL_ErrEventDestroy; | ||
90 | } | ||
91 | if (SUCCESS != pthread_mutex_unlock(&(plEvent->mutex))) { | ||
92 | OSAL_ErrorTrace("Event Delete: Mutex Unlock failed !"); | ||
93 | bRet = OSAL_ErrMutexUnlock; | ||
94 | } | ||
95 | if (SUCCESS != pthread_mutex_destroy(&(plEvent->mutex))) { | ||
96 | OSAL_ErrorTrace("Event Delete: Mutex Destory failed !"); | ||
97 | bRet = OSAL_ErrMutexDestroy; | ||
98 | } | ||
99 | OSAL_Free(plEvent); | ||
100 | EXIT: | ||
101 | return bRet; | ||
102 | } | ||
103 | |||
104 | /* | ||
105 | * Method to set event operation | ||
106 | */ | ||
107 | OSAL_ERROR OSAL_SetEvent(void *pEvents, uint32_t uEventFlags, OSAL_EventOp eOperation) | ||
108 | { | ||
109 | OSAL_ThreadEvent *plEvent = (OSAL_ThreadEvent*) pEvents; | ||
110 | if (NULL == plEvent) { | ||
111 | return OSAL_ErrParameter; | ||
112 | } | ||
113 | if (SUCCESS != pthread_mutex_lock(&(plEvent->mutex))) { | ||
114 | OSAL_ErrorTrace("Event Set: Mutex Lock failed !"); | ||
115 | return OSAL_ErrMutexLock; | ||
116 | } | ||
117 | |||
118 | switch (eOperation) { | ||
119 | case OSAL_EVENT_AND: | ||
120 | plEvent->eFlags = plEvent->eFlags & uEventFlags; | ||
121 | break; | ||
122 | case OSAL_EVENT_OR: | ||
123 | plEvent->eFlags = plEvent->eFlags | uEventFlags; | ||
124 | break; | ||
125 | default: | ||
126 | OSAL_ErrorTrace("Event Set: Bad eOperation !"); | ||
127 | pthread_mutex_unlock(&plEvent->mutex); | ||
128 | return OSAL_ErrMutexUnlock; | ||
129 | }; | ||
130 | |||
131 | plEvent->bSignaled = OSAL_TRUE; | ||
132 | if (SUCCESS != pthread_cond_signal(&plEvent->condition)) { | ||
133 | OSAL_ErrorTrace("Event Set: Condition Variable Signal failed !"); | ||
134 | pthread_mutex_unlock(&plEvent->mutex); | ||
135 | return OSAL_ErrEventSignal; | ||
136 | } | ||
137 | |||
138 | if (SUCCESS != pthread_mutex_unlock(&plEvent->mutex)) { | ||
139 | OSAL_ErrorTrace("Event Set: Mutex Unlock failed !"); | ||
140 | return OSAL_ErrMutexUnlock; | ||
141 | } | ||
142 | return OSAL_ErrNone; | ||
143 | } | ||
144 | |||
145 | /* | ||
146 | * @fn OSAL_RetrieveEvent | ||
147 | * Spurious wakeups from the pthread_cond_timedwait() or pthread_cond_wait() functions may occur. | ||
148 | * A representative sequence for using condition variables is shown below | ||
149 | * | ||
150 | * Thread A (Retrieve Events) |Thread B (Set Events) | ||
151 | *------------------------------------------------------------------------------------------------------------ | ||
152 | *1) Do work up to the point where a certain condition must occur |1)Do work | ||
153 | * (such as "count" value) | ||
154 | 2) Lock associated mutex and check value of a global variable |2)Lock associated mutex | ||
155 | *3) Call pthread_cond_wait() to perform a blocking wait |3)Change the value of the global variable | ||
156 | * for signal from Thread-B. Note that a call to that Thread-A is waiting upon. | ||
157 | * pthread_cond_wait() automatically and atomically | ||
158 | * unlocks the associated mutex variable so that it can | ||
159 | * be used by Thread-B. | ||
160 | *4) When signalled, wake up. Mutex is automatically and |4)Check value of the global Thread-A wait | ||
161 | * atomically locked. variable. If it fulfills the desired | ||
162 | * condition, signal Thread-A. | ||
163 | *5) Explicitly unlock mutex |5) Unlock Mutex. | ||
164 | *6) Continue |6) Continue | ||
165 | */ | ||
166 | |||
167 | OSAL_ERROR OSAL_RetrieveEvent(void *pEvents, uint32_t uRequestedEvents, | ||
168 | OSAL_EventOp eOperation, uint32_t *pRetrievedEvents, uint32_t uTimeOutMsec) | ||
169 | { | ||
170 | OSAL_ERROR bRet = OSAL_ErrUnKnown; | ||
171 | struct timespec timeout; | ||
172 | struct timeval now; | ||
173 | uint32_t timeout_us; | ||
174 | uint32_t isolatedFlags; | ||
175 | int status = -1; | ||
176 | int and_operation; | ||
177 | OSAL_ThreadEvent *plEvent = (OSAL_ThreadEvent *) pEvents; | ||
178 | if (NULL == plEvent) { | ||
179 | return OSAL_ErrParameter; | ||
180 | } | ||
181 | |||
182 | /* Lock the mutex for access to the eFlags global variable */ | ||
183 | if (SUCCESS != pthread_mutex_lock(&(plEvent->mutex))) { | ||
184 | OSAL_ErrorTrace("Event Retrieve: Mutex Lock failed !"); | ||
185 | bRet = OSAL_ErrMutexLock; | ||
186 | goto EXIT; | ||
187 | } | ||
188 | |||
189 | /*Check the eOperation and put it in a variable */ | ||
190 | and_operation = (OSAL_EVENT_AND == eOperation || OSAL_EVENT_AND_CONSUME == eOperation); | ||
191 | /* Isolate the flags. The & operation is suffice for an TIMM_OSAL_EVENT_OR eOperation */ | ||
192 | isolatedFlags = plEvent->eFlags & uRequestedEvents; | ||
193 | /*Check if it is the AND operation. If yes then, all the flags must match */ | ||
194 | if (and_operation) { | ||
195 | isolatedFlags = (isolatedFlags == uRequestedEvents); | ||
196 | } | ||
197 | if (isolatedFlags) { | ||
198 | /*We have got required combination of the eFlags bits and will return it back */ | ||
199 | *pRetrievedEvents = plEvent->eFlags; | ||
200 | bRet = OSAL_ErrNone; | ||
201 | } else { | ||
202 | /*Required combination of bits is not yet available */ | ||
203 | if (OSAL_NO_SUSPEND == uTimeOutMsec) { | ||
204 | *pRetrievedEvents = 0; | ||
205 | bRet = OSAL_ErrNone; | ||
206 | } else if (OSAL_SUSPEND == uTimeOutMsec) { | ||
207 | /*Wait till we get the required combination of bits. We we get the required | ||
208 | *bits then we go out of the while loop | ||
209 | */ | ||
210 | while (!isolatedFlags) { | ||
211 | /*Wait on the conditional variable for another thread to set the eFlags and signal */ | ||
212 | pthread_cond_wait(&(plEvent->condition), &(plEvent->mutex)); | ||
213 | /* eFlags set by some thread. Now, isolate the flags. | ||
214 | * The & operation is suffice for an TIMM_OSAL_EVENT_OR eOperation | ||
215 | */ | ||
216 | isolatedFlags = plEvent->eFlags & uRequestedEvents; | ||
217 | /*Check if it is the AND operation. If yes then, all the flags must match */ | ||
218 | if (and_operation) { | ||
219 | isolatedFlags = (isolatedFlags == uRequestedEvents); | ||
220 | } | ||
221 | } | ||
222 | |||
223 | /* Obtained the requested combination of bits on eFlags */ | ||
224 | *pRetrievedEvents = plEvent->eFlags; | ||
225 | bRet = OSAL_ErrNone; | ||
226 | } else { | ||
227 | /* Calculate uTimeOutMsec in terms of the absolute time. uTimeOutMsec is in milliseconds */ | ||
228 | gettimeofday(&now, NULL); | ||
229 | timeout_us = now.tv_usec + 1000 * uTimeOutMsec; | ||
230 | timeout.tv_sec = now.tv_sec + timeout_us / 1000000; | ||
231 | timeout.tv_nsec = (timeout_us % 1000000) * 1000; | ||
232 | |||
233 | while (!isolatedFlags) { | ||
234 | /* Wait till uTimeOutMsec for a thread to signal on the conditional variable */ | ||
235 | status = pthread_cond_timedwait(&(plEvent->condition), &(plEvent->mutex), &timeout); | ||
236 | /*Timedout or error and returned without being signalled */ | ||
237 | if (SUCCESS != status) { | ||
238 | if (ETIMEDOUT == status) | ||
239 | bRet = OSAL_ErrTimeOut; | ||
240 | *pRetrievedEvents = 0; | ||
241 | break; | ||
242 | } | ||
243 | |||
244 | /* eFlags set by some thread. Now, isolate the flags. | ||
245 | * The & operation is suffice for an TIMM_OSAL_EVENT_OR eOperation | ||
246 | */ | ||
247 | isolatedFlags = plEvent->eFlags & uRequestedEvents; | ||
248 | |||
249 | /*Check if it is the AND operation. If yes then, all the flags must match */ | ||
250 | if (and_operation) { | ||
251 | isolatedFlags = (isolatedFlags == uRequestedEvents); | ||
252 | } | ||
253 | } | ||
254 | } | ||
255 | } | ||
256 | |||
257 | /*If we have got the required combination of bits, we will have to reset the eFlags if CONSUME is mentioned | ||
258 | *in the eOperations | ||
259 | */ | ||
260 | if (isolatedFlags && ((eOperation == OSAL_EVENT_AND_CONSUME) || | ||
261 | (eOperation == OSAL_EVENT_OR_CONSUME))) { | ||
262 | plEvent->eFlags = 0; | ||
263 | bRet = OSAL_ErrNone; | ||
264 | } | ||
265 | |||
266 | /*unlock the mutex */ | ||
267 | if (SUCCESS != pthread_mutex_unlock(&(plEvent->mutex))) { | ||
268 | OSAL_ErrorTrace("Event Retrieve: Mutex Unlock failed !"); | ||
269 | bRet = OSAL_ErrNone; | ||
270 | } | ||
271 | |||
272 | EXIT: | ||
273 | return bRet; | ||
274 | } | ||
275 | |||
diff --git a/libstagefrighthw/omx/osal/src/osal_memory.c b/libstagefrighthw/omx/osal/src/osal_memory.c new file mode 100755 index 0000000..d8759f7 --- /dev/null +++ b/libstagefrighthw/omx/osal/src/osal_memory.c | |||
@@ -0,0 +1,73 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 <string.h> | ||
18 | #include <malloc.h> | ||
19 | #include <stdint.h> | ||
20 | |||
21 | #include "osal_trace.h" | ||
22 | #include "osal_error.h" | ||
23 | #include "osal_memory.h" | ||
24 | |||
25 | void* OSAL_Malloc(size_t size) | ||
26 | { | ||
27 | void* pData = NULL; | ||
28 | pData = malloc((size_t) size); | ||
29 | return pData; | ||
30 | } | ||
31 | |||
32 | void OSAL_Free(void *pData) | ||
33 | { | ||
34 | if (NULL == pData) { | ||
35 | OSAL_WarningTrace("TIMM_OSAL_Free called on NULL pointer"); | ||
36 | return; | ||
37 | } | ||
38 | |||
39 | free(pData); | ||
40 | pData = NULL; | ||
41 | } | ||
42 | |||
43 | OSAL_ERROR OSAL_Memset(void *pBuffer, uint8_t uValue, uint32_t uSize) | ||
44 | { | ||
45 | if (NULL == pBuffer || uSize == 0) { | ||
46 | OSAL_WarningTrace("OSAL_Memset is called on NULL pointer"); | ||
47 | return OSAL_ErrParameter; | ||
48 | } | ||
49 | |||
50 | memset((void *)pBuffer, (int)uValue, (size_t) uSize); | ||
51 | return OSAL_ErrNone; | ||
52 | } | ||
53 | |||
54 | int32_t OSAL_Memcmp(void *pBuffer1, void *pBuffer2, uint32_t uSize) | ||
55 | { | ||
56 | if (NULL == pBuffer1 || NULL == pBuffer2) { | ||
57 | OSAL_WarningTrace("OSAL_MemCmp called with null buffers"); | ||
58 | return OSAL_ErrParameter; | ||
59 | } | ||
60 | |||
61 | int32_t result = memcmp(pBuffer1, pBuffer2, uSize); | ||
62 | return (result == 0) ? result : ((result > 0) ? 1 : -1); | ||
63 | } | ||
64 | |||
65 | OSAL_ERROR OSAL_Memcpy(void *pBufDst, void *pBufSrc, uint32_t uSize) | ||
66 | { | ||
67 | if (NULL == pBufDst || NULL == pBufSrc) { | ||
68 | OSAL_WarningTrace("OSAL_Memcpy called with null buffers"); | ||
69 | return OSAL_ErrParameter; | ||
70 | } | ||
71 | memcpy(pBufDst, pBufSrc, uSize); | ||
72 | return OSAL_ErrNone; | ||
73 | } | ||
diff --git a/libstagefrighthw/omx/osal/src/osal_mutex.c b/libstagefrighthw/omx/osal/src/osal_mutex.c new file mode 100755 index 0000000..e4aae80 --- /dev/null +++ b/libstagefrighthw/omx/osal/src/osal_mutex.c | |||
@@ -0,0 +1,107 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 <errno.h> | ||
18 | #include <pthread.h> | ||
19 | #include <sys/time.h> | ||
20 | |||
21 | #include "osal_trace.h" | ||
22 | #include "osal_error.h" | ||
23 | #include "osal_memory.h" | ||
24 | #include "osal_semaphores.h" | ||
25 | |||
26 | OSAL_ERROR OSAL_CreateMutex(void **pMutex) | ||
27 | { | ||
28 | pthread_mutex_t *plMutex = (pthread_mutex_t *)OSAL_Malloc(sizeof(pthread_mutex_t)); | ||
29 | if (NULL == plMutex) { | ||
30 | return OSAL_ErrAlloc; | ||
31 | } | ||
32 | |||
33 | if (SUCCESS != pthread_mutex_init(plMutex, NULL)) { | ||
34 | OSAL_Free(plMutex); | ||
35 | return OSAL_ErrMutexCreate; | ||
36 | } | ||
37 | |||
38 | *pMutex = (void*) plMutex; | ||
39 | return OSAL_ErrNone; | ||
40 | } | ||
41 | |||
42 | OSAL_ERROR OSAL_DeleteMutex(void *pMutex) | ||
43 | { | ||
44 | pthread_mutex_t *plMutex = (pthread_mutex_t *) pMutex; | ||
45 | if (NULL == plMutex) { | ||
46 | return OSAL_ErrParameter; | ||
47 | } | ||
48 | |||
49 | /*can we do away with if or with switch case */ | ||
50 | if (SUCCESS != pthread_mutex_destroy(plMutex)) { | ||
51 | OSAL_ErrorTrace("Delete Mutex failed !"); | ||
52 | return OSAL_ErrMutexDestroy; | ||
53 | } | ||
54 | |||
55 | OSAL_Free(plMutex); | ||
56 | return OSAL_ErrNone; | ||
57 | } | ||
58 | |||
59 | |||
60 | OSAL_ERROR OSAL_ObtainMutex(void *pMutex, uint32_t uTimeOut) | ||
61 | { | ||
62 | struct timespec abs_timeout; | ||
63 | struct timeval ltime_now; | ||
64 | uint32_t ltimenow_us; | ||
65 | pthread_mutex_t *plMutex = (pthread_mutex_t *) pMutex; | ||
66 | if (plMutex == NULL) { | ||
67 | return OSAL_ErrParameter; | ||
68 | } | ||
69 | |||
70 | if (OSAL_SUSPEND == uTimeOut) { | ||
71 | if (SUCCESS != pthread_mutex_lock(plMutex)) { | ||
72 | OSAL_ErrorTrace("Lock Mutex failed !"); | ||
73 | return OSAL_ErrMutexLock; | ||
74 | } | ||
75 | } else if (OSAL_NO_SUSPEND == uTimeOut) { | ||
76 | if (SUCCESS != pthread_mutex_trylock(plMutex)) { | ||
77 | OSAL_ErrorTrace("Lock Mutex failed !"); | ||
78 | return OSAL_ErrMutexLock; | ||
79 | } | ||
80 | } else { | ||
81 | gettimeofday(<ime_now, NULL); | ||
82 | /*uTimeOut is assumed to be in milliseconds */ | ||
83 | ltimenow_us = ltime_now.tv_usec + 1000 * uTimeOut; | ||
84 | abs_timeout.tv_sec = ltime_now.tv_sec + uTimeOut / 1000; | ||
85 | abs_timeout.tv_nsec = (ltimenow_us % 1000000) * 1000; | ||
86 | if (SUCCESS != pthread_mutex_lock(plMutex)) { | ||
87 | OSAL_ErrorTrace("Lock Mutex failed !"); | ||
88 | return OSAL_ErrMutexLock; | ||
89 | } | ||
90 | } | ||
91 | return OSAL_ErrNone; | ||
92 | } | ||
93 | |||
94 | |||
95 | OSAL_ERROR OSAL_ReleaseMutex(void *pMutex) | ||
96 | { | ||
97 | pthread_mutex_t *plMutex = (pthread_mutex_t *) pMutex; | ||
98 | if (NULL == plMutex) { | ||
99 | return OSAL_ErrParameter; | ||
100 | } | ||
101 | |||
102 | if (SUCCESS != pthread_mutex_unlock(plMutex)) { | ||
103 | OSAL_ErrorTrace("Unlock Mutex failed !"); | ||
104 | return OSAL_ErrMutexUnlock; | ||
105 | } | ||
106 | return OSAL_ErrNone; | ||
107 | } | ||
diff --git a/libstagefrighthw/omx/osal/src/osal_pipes.c b/libstagefrighthw/omx/osal/src/osal_pipes.c new file mode 100755 index 0000000..bfb0e16 --- /dev/null +++ b/libstagefrighthw/omx/osal/src/osal_pipes.c | |||
@@ -0,0 +1,346 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 <unistd.h> | ||
18 | #include <stdio.h> | ||
19 | #include <unistd.h> | ||
20 | #include <errno.h> | ||
21 | #include <pthread.h> | ||
22 | #include <string.h> | ||
23 | |||
24 | #include "osal_error.h" | ||
25 | #include "osal_memory.h" | ||
26 | #include "osal_trace.h" | ||
27 | |||
28 | /** | ||
29 | * structure definition for the OSAL pipe | ||
30 | */ | ||
31 | typedef struct timm_osal_pipe | ||
32 | { | ||
33 | int pfd[2]; | ||
34 | uint32_t pipeSize; | ||
35 | uint32_t messageSize; | ||
36 | uint8_t isFixedMessage; | ||
37 | int messageCount; | ||
38 | int totalBytesInPipe; | ||
39 | pthread_mutex_t mutex; | ||
40 | } OSAL_Pipe; | ||
41 | |||
42 | typedef enum | ||
43 | { | ||
44 | PIPE_RESET, | ||
45 | PIPE_INCREMENT, | ||
46 | PIPE_DECREMENT, | ||
47 | }PIPE_UPDATE; | ||
48 | |||
49 | static inline int UpdatePipe(void *pPipe, uint32_t msgCnt, uint32_t size, PIPE_UPDATE updateMode) | ||
50 | { | ||
51 | OSAL_Pipe *pHandle = (OSAL_Pipe*)pPipe; | ||
52 | |||
53 | switch(updateMode) { | ||
54 | case PIPE_RESET: | ||
55 | pHandle->messageCount = msgCnt; | ||
56 | pHandle->totalBytesInPipe = size; | ||
57 | break; | ||
58 | |||
59 | case PIPE_INCREMENT: | ||
60 | pHandle->messageCount += msgCnt; | ||
61 | pHandle->totalBytesInPipe += size; | ||
62 | break; | ||
63 | |||
64 | case PIPE_DECREMENT: | ||
65 | pHandle->messageCount -= msgCnt; | ||
66 | pHandle->totalBytesInPipe -= size; | ||
67 | break; | ||
68 | |||
69 | default: | ||
70 | OSAL_ErrorTrace("InValid Pipe update Mode"); | ||
71 | } | ||
72 | |||
73 | return OSAL_ErrNone; | ||
74 | } | ||
75 | |||
76 | OSAL_ERROR OSAL_CreatePipe(void **pPipe, uint32_t pipeSize, | ||
77 | uint32_t messageSize, uint8_t isFixedMessage) | ||
78 | { | ||
79 | OSAL_Pipe *pHandle = (OSAL_Pipe*)OSAL_Malloc(sizeof(OSAL_Pipe)); | ||
80 | if (NULL == pHandle) { | ||
81 | return OSAL_ErrAlloc; | ||
82 | } | ||
83 | |||
84 | OSAL_Memset(pHandle, 0x0, sizeof(OSAL_Pipe)); | ||
85 | pHandle->pfd[0] = -1; | ||
86 | pHandle->pfd[1] = -1; | ||
87 | if (SUCCESS != pipe(pHandle->pfd)) { | ||
88 | OSAL_ErrorTrace("Pipe failed: %s!!!", strerror(errno)); | ||
89 | OSAL_Free(pHandle); | ||
90 | return OSAL_ErrAlloc; | ||
91 | } | ||
92 | |||
93 | if (SUCCESS != pthread_mutex_init(&(pHandle->mutex), NULL)) { | ||
94 | OSAL_ErrorTrace("Pipe Create:Mutex Init failed !"); | ||
95 | OSAL_Free(pHandle); | ||
96 | return OSAL_ErrMutexCreate; | ||
97 | } | ||
98 | pHandle->pipeSize = pipeSize; | ||
99 | pHandle->messageSize = messageSize; | ||
100 | pHandle->isFixedMessage = isFixedMessage; | ||
101 | pHandle->messageCount = 0; | ||
102 | pHandle->totalBytesInPipe = 0; | ||
103 | |||
104 | *pPipe = (void*)pHandle; | ||
105 | return OSAL_ErrNone; | ||
106 | } | ||
107 | |||
108 | OSAL_ERROR OSAL_DeletePipe(void *pPipe) | ||
109 | { | ||
110 | OSAL_Pipe *pHandle = (OSAL_Pipe*) pPipe; | ||
111 | if (NULL == pHandle) { | ||
112 | return OSAL_ErrParameter; | ||
113 | } | ||
114 | |||
115 | if (SUCCESS != close(pHandle->pfd[0])) { | ||
116 | OSAL_ErrorTrace("Delete_Pipe Read fd failed!!!"); | ||
117 | return OSAL_ErrPipeClose; | ||
118 | } | ||
119 | if (SUCCESS != close(pHandle->pfd[1])) { | ||
120 | OSAL_ErrorTrace("Delete_Pipe Write fd failed!!!"); | ||
121 | return OSAL_ErrPipeClose; | ||
122 | } | ||
123 | |||
124 | if (SUCCESS != pthread_mutex_destroy(&(pHandle->mutex))) { | ||
125 | OSAL_ErrorTrace("Pipe Delete: Mutex Destory failed !"); | ||
126 | return OSAL_ErrMutexDestroy; | ||
127 | } | ||
128 | |||
129 | OSAL_Free(pHandle); | ||
130 | return OSAL_ErrNone; | ||
131 | } | ||
132 | |||
133 | |||
134 | OSAL_ERROR OSAL_WriteToPipe(void *pPipe, void *pMessage, uint32_t size, int32_t timeout) | ||
135 | { | ||
136 | uint32_t lSizeWritten = -1; | ||
137 | OSAL_ERROR ret = OSAL_ErrNone; | ||
138 | OSAL_Pipe *pHandle = (OSAL_Pipe*)pPipe; | ||
139 | (void)timeout; | ||
140 | |||
141 | if (NULL == pHandle || size == 0) { | ||
142 | OSAL_ErrorTrace("0 size!!!"); | ||
143 | return OSAL_ErrParameter; | ||
144 | } | ||
145 | |||
146 | |||
147 | if (SUCCESS != pthread_mutex_lock(&(pHandle->mutex))) { | ||
148 | OSAL_ErrorTrace("update Pipe: Mutex Lock failed !"); | ||
149 | return OSAL_ErrMutexLock; | ||
150 | } | ||
151 | |||
152 | /*Update message count and size */ | ||
153 | ret = UpdatePipe(pHandle, 1, size, PIPE_INCREMENT); | ||
154 | if (ret) { | ||
155 | goto EXIT; | ||
156 | } | ||
157 | |||
158 | lSizeWritten = write(pHandle->pfd[1], pMessage, size); | ||
159 | if (lSizeWritten != size) { | ||
160 | OSAL_ErrorTrace("Write of pipe failed!!!"); | ||
161 | /*Update message count and size */ | ||
162 | UpdatePipe(pHandle, 1, size, PIPE_DECREMENT); | ||
163 | ret = OSAL_ErrPipeWrite; | ||
164 | } | ||
165 | |||
166 | EXIT: | ||
167 | |||
168 | if (SUCCESS != pthread_mutex_unlock(&(pHandle->mutex))) { | ||
169 | OSAL_ErrorTrace("update Pipe: Mutex Unlock failed !"); | ||
170 | ret = OSAL_ErrMutexUnlock; | ||
171 | } | ||
172 | |||
173 | return ret; | ||
174 | } | ||
175 | |||
176 | |||
177 | OSAL_ERROR OSAL_WriteToFrontOfPipe(void *pPipe, void *pMessage, uint32_t size, int32_t timeout) | ||
178 | { | ||
179 | uint32_t lSizeWritten = -1; | ||
180 | uint32_t lSizeRead = -1; | ||
181 | OSAL_ERROR ret = OSAL_ErrNone; | ||
182 | OSAL_Pipe *pHandle = (OSAL_Pipe*) pPipe; | ||
183 | uint8_t *tempPtr = NULL; | ||
184 | (void)timeout; | ||
185 | |||
186 | /*First write to this pipe */ | ||
187 | if (NULL == pHandle || size == 0) { | ||
188 | return OSAL_ErrParameter; | ||
189 | |||
190 | } | ||
191 | |||
192 | if (SUCCESS != pthread_mutex_lock(&(pHandle->mutex))) { | ||
193 | OSAL_ErrorTrace("update Pipe: Mutex Lock failed !"); | ||
194 | return OSAL_ErrMutexLock; | ||
195 | } | ||
196 | |||
197 | /*Update message count and size */ | ||
198 | ret = UpdatePipe(pHandle, 1, size, PIPE_INCREMENT); | ||
199 | if (ret) { | ||
200 | goto EXIT; | ||
201 | } | ||
202 | |||
203 | |||
204 | lSizeWritten = write(pHandle->pfd[1], pMessage, size); | ||
205 | if (lSizeWritten != size) { | ||
206 | /*Update message count and size */ | ||
207 | UpdatePipe(pHandle, 1, size, PIPE_DECREMENT); | ||
208 | ret = OSAL_ErrPipeWrite; | ||
209 | goto EXIT; | ||
210 | } | ||
211 | |||
212 | if (pHandle->messageCount > 1) { | ||
213 | /*First allocate memory */ | ||
214 | tempPtr = (uint8_t*)OSAL_Malloc(pHandle->totalBytesInPipe-size); | ||
215 | if (NULL == tempPtr) { | ||
216 | ret = OSAL_ErrAlloc; | ||
217 | goto EXIT; | ||
218 | } | ||
219 | |||
220 | /*Read out of pipe */ | ||
221 | lSizeRead = read(pHandle->pfd[0], tempPtr, pHandle->totalBytesInPipe-size); | ||
222 | |||
223 | /*Write back to pipe */ | ||
224 | lSizeWritten = write(pHandle->pfd[1], tempPtr, lSizeRead); | ||
225 | if (lSizeWritten != lSizeRead) { | ||
226 | /*Update message count and size */ | ||
227 | UpdatePipe(pHandle, 1, size, PIPE_RESET); | ||
228 | ret = OSAL_ErrPipeWrite; | ||
229 | } | ||
230 | OSAL_Free(tempPtr); | ||
231 | } | ||
232 | |||
233 | EXIT: | ||
234 | if (SUCCESS != pthread_mutex_unlock(&(pHandle->mutex))) { | ||
235 | OSAL_ErrorTrace("update Pipe: Mutex Unlock failed !"); | ||
236 | ret = OSAL_ErrMutexUnlock; | ||
237 | } | ||
238 | |||
239 | return ret; | ||
240 | } | ||
241 | |||
242 | |||
243 | OSAL_ERROR OSAL_ReadFromPipe(void *pPipe, void *pMessage, uint32_t size, | ||
244 | uint32_t *actualSize, int32_t timeout) | ||
245 | { | ||
246 | uint32_t lSizeRead = -1; | ||
247 | OSAL_ERROR ret = OSAL_ErrNone; | ||
248 | OSAL_Pipe *pHandle = (OSAL_Pipe*) pPipe; | ||
249 | |||
250 | if (NULL == pHandle || size == 0) { | ||
251 | OSAL_ErrorTrace("nRead size has error!!!"); | ||
252 | return OSAL_ErrParameter; | ||
253 | } | ||
254 | |||
255 | if (SUCCESS != pthread_mutex_lock(&(pHandle->mutex))) { | ||
256 | OSAL_ErrorTrace("update Pipe: Mutex Lock failed !"); | ||
257 | return OSAL_ErrMutexLock; | ||
258 | } | ||
259 | |||
260 | if (pHandle->messageCount == 0 && timeout == OSAL_NO_SUSPEND) { | ||
261 | /*If timeout is 0 and pipe is empty, return error */ | ||
262 | OSAL_ErrorTrace("Pipe is empty!!!"); | ||
263 | ret = OSAL_ErrPipeEmpty; | ||
264 | goto EXIT; | ||
265 | } | ||
266 | |||
267 | if (timeout != OSAL_NO_SUSPEND && timeout != (int32_t)OSAL_SUSPEND) { | ||
268 | OSAL_WarningTrace("Only infinite or no timeouts \ | ||
269 | supported. Going to read with infinite timeout now"); | ||
270 | } | ||
271 | |||
272 | /*read blocks infinitely until message is available */ | ||
273 | *actualSize = lSizeRead = read(pHandle->pfd[0], pMessage, size); | ||
274 | if (0 == lSizeRead) { | ||
275 | OSAL_ErrorTrace("EOF reached or no data in pipe!!!"); | ||
276 | ret = OSAL_ErrPipeRead; | ||
277 | goto EXIT; | ||
278 | } | ||
279 | |||
280 | ret = UpdatePipe(pHandle, 1, lSizeRead, PIPE_DECREMENT); | ||
281 | |||
282 | EXIT: | ||
283 | |||
284 | if (SUCCESS != pthread_mutex_unlock(&(pHandle->mutex))) { | ||
285 | OSAL_ErrorTrace("update Pipe: Mutex Unlock failed !"); | ||
286 | ret = OSAL_ErrMutexUnlock; | ||
287 | } | ||
288 | |||
289 | return ret; | ||
290 | |||
291 | } | ||
292 | |||
293 | |||
294 | OSAL_ERROR OSAL_ClearPipe(void *pPipe) | ||
295 | { | ||
296 | (void)pPipe; | ||
297 | OSAL_WarningTrace("This function is currently not implemented"); | ||
298 | return OSAL_ErrNone; | ||
299 | } | ||
300 | |||
301 | OSAL_ERROR OSAL_IsPipeReady(void *pPipe) | ||
302 | { | ||
303 | OSAL_Pipe *pHandle = (OSAL_Pipe *) pPipe; | ||
304 | int isReady; | ||
305 | |||
306 | if (NULL == pHandle) { | ||
307 | return OSAL_ErrParameter; | ||
308 | } | ||
309 | |||
310 | if (SUCCESS != pthread_mutex_lock(&(pHandle->mutex))) { | ||
311 | OSAL_ErrorTrace("IsPipeReady: Mutex Lock failed !"); | ||
312 | return OSAL_ErrMutexLock; | ||
313 | } | ||
314 | |||
315 | isReady = (pHandle->messageCount <= 0) ? OSAL_ErrNotReady : OSAL_ErrNone; | ||
316 | |||
317 | if (SUCCESS != pthread_mutex_unlock(&(pHandle->mutex))) { | ||
318 | OSAL_ErrorTrace("IsPipeReady: Mutex Unlock failed !"); | ||
319 | return OSAL_ErrMutexUnlock; | ||
320 | } | ||
321 | return isReady; | ||
322 | } | ||
323 | |||
324 | OSAL_ERROR OSAL_GetPipeReadyMessageCount(void *pPipe, uint32_t *count) | ||
325 | { | ||
326 | OSAL_Pipe *pHandle = (OSAL_Pipe*) pPipe; | ||
327 | if (NULL == pHandle) { | ||
328 | *count = 0; | ||
329 | return OSAL_ErrParameter; | ||
330 | } | ||
331 | |||
332 | if (SUCCESS != pthread_mutex_lock(&(pHandle->mutex))) { | ||
333 | OSAL_ErrorTrace("GetPipeReadyMessageCount: Mutex Lock failed !"); | ||
334 | return OSAL_ErrMutexLock; | ||
335 | } | ||
336 | |||
337 | |||
338 | *count = pHandle->messageCount; | ||
339 | |||
340 | if (SUCCESS != pthread_mutex_unlock(&(pHandle->mutex))) { | ||
341 | OSAL_ErrorTrace("GetPipeReadyMessageCount: Mutex Unlock failed !"); | ||
342 | return OSAL_ErrMutexUnlock; | ||
343 | } | ||
344 | |||
345 | return OSAL_ErrNone; | ||
346 | } | ||
diff --git a/libstagefrighthw/omx/osal/src/osal_semaphores.c b/libstagefrighthw/omx/osal/src/osal_semaphores.c new file mode 100755 index 0000000..5f6dd59 --- /dev/null +++ b/libstagefrighthw/omx/osal/src/osal_semaphores.c | |||
@@ -0,0 +1,141 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 <stdio.h> | ||
18 | |||
19 | #include <semaphore.h> | ||
20 | #include <sys/time.h> | ||
21 | |||
22 | #include "osal_trace.h" | ||
23 | #include "osal_error.h" | ||
24 | #include "osal_memory.h" | ||
25 | |||
26 | OSAL_ERROR OSAL_CreateSemaphore(void **pSemaphore, uint32_t uInitCount) | ||
27 | { | ||
28 | OSAL_ERROR bRet = OSAL_ErrUnKnown; | ||
29 | *pSemaphore = NULL; | ||
30 | sem_t *psem = (sem_t *)OSAL_Malloc(sizeof(sem_t)); | ||
31 | if (NULL == psem) { | ||
32 | bRet = OSAL_ErrAlloc; | ||
33 | goto EXIT; | ||
34 | } | ||
35 | |||
36 | /*Unnamed semaphore */ | ||
37 | if (SUCCESS != sem_init(psem, 0, uInitCount)) { | ||
38 | OSAL_ErrorTrace("Semaphore Create failed !"); | ||
39 | bRet = OSAL_ErrSemCreate; | ||
40 | goto EXIT; | ||
41 | } | ||
42 | *pSemaphore = (void *) psem; | ||
43 | bRet = OSAL_ErrNone; | ||
44 | |||
45 | EXIT: | ||
46 | if (OSAL_ErrNone != bRet && NULL != psem) { | ||
47 | OSAL_Free(psem); | ||
48 | } | ||
49 | return bRet; | ||
50 | } | ||
51 | |||
52 | OSAL_ERROR OSAL_DeleteSemaphore(void *pSemaphore) | ||
53 | { | ||
54 | sem_t *psem = (sem_t *)pSemaphore; | ||
55 | if (NULL == psem) { | ||
56 | return OSAL_ErrParameter; | ||
57 | } | ||
58 | /* Release the semaphore. */ | ||
59 | if (SUCCESS != sem_destroy(psem)) { | ||
60 | OSAL_ErrorTrace("Semaphore Delete failed !"); | ||
61 | return OSAL_ErrSemDelete; | ||
62 | } | ||
63 | |||
64 | OSAL_Free(psem); | ||
65 | return OSAL_ErrNone; | ||
66 | } | ||
67 | |||
68 | OSAL_ERROR OSAL_ObtainSemaphore(void *pSemaphore, uint32_t uTimeOut) | ||
69 | { | ||
70 | struct timeval ltime_now; | ||
71 | struct timespec abs_timeout; | ||
72 | sem_t *psem = (sem_t *) pSemaphore; | ||
73 | if (psem == NULL) { | ||
74 | return OSAL_ErrParameter; | ||
75 | } | ||
76 | |||
77 | if (OSAL_SUSPEND == uTimeOut) { | ||
78 | if (SUCCESS != sem_wait(psem)) { | ||
79 | OSAL_ErrorTrace("Semaphore Wait failed !"); | ||
80 | return OSAL_ErrTimeOut; | ||
81 | } | ||
82 | } else if (OSAL_NO_SUSPEND == uTimeOut) { | ||
83 | if (SUCCESS != sem_trywait(psem)) { | ||
84 | OSAL_ErrorTrace("Semaphore blocked !"); | ||
85 | return OSAL_ErrTimeOut; | ||
86 | } | ||
87 | } else { | ||
88 | /* Some delay in calling gettimeofday and sem_timedwait - cant | ||
89 | * be avoided. Possibility of thread switch after gettimeofday | ||
90 | * in which case time out will be less than expected */ | ||
91 | gettimeofday(<ime_now, NULL); | ||
92 | /*uTimeOut is assumed to be in milliseconds */ | ||
93 | abs_timeout.tv_sec = ltime_now.tv_sec + (uTimeOut / 1000); | ||
94 | abs_timeout.tv_nsec = 1000 * (ltime_now.tv_usec + ((uTimeOut % 1000) * 1000)); | ||
95 | if (SUCCESS != sem_timedwait(psem, &abs_timeout)) { | ||
96 | OSAL_ErrorTrace("Semaphore Timed Wait failed !"); | ||
97 | return OSAL_ErrTimeOut; | ||
98 | } | ||
99 | } | ||
100 | return OSAL_ErrNone; | ||
101 | } | ||
102 | |||
103 | OSAL_ERROR OSAL_ReleaseSemaphore(void *pSemaphore) | ||
104 | { | ||
105 | sem_t *psem = (sem_t *) pSemaphore; | ||
106 | if (NULL == psem) { | ||
107 | return OSAL_ErrParameter; | ||
108 | } | ||
109 | /* Release the semaphore. */ | ||
110 | if (SUCCESS != sem_post(psem)) { | ||
111 | OSAL_ErrorTrace("Release failed !"); | ||
112 | return OSAL_ErrSemPost; | ||
113 | } | ||
114 | return OSAL_ErrNone; | ||
115 | } | ||
116 | |||
117 | OSAL_ERROR OSAL_ResetSemaphore(void *pSemaphore, uint32_t uInitCount) | ||
118 | { | ||
119 | (void)pSemaphore; | ||
120 | (void)uInitCount; | ||
121 | |||
122 | return OSAL_ErrNone; | ||
123 | } | ||
124 | |||
125 | OSAL_ERROR OSAL_GetSemaphoreCount(void *pSemaphore, uint32_t *count) | ||
126 | { | ||
127 | int sval = -2; /*value that is not possible */ | ||
128 | sem_t *psem = (sem_t *) pSemaphore; | ||
129 | if (NULL == psem) { | ||
130 | return OSAL_ErrParameter; | ||
131 | } | ||
132 | |||
133 | /* Release the semaphore. */ | ||
134 | if (SUCCESS != sem_getvalue(psem, &sval)) { | ||
135 | OSAL_ErrorTrace("Get Semaphore Count failed !"); | ||
136 | return OSAL_ErrSemGetValue; | ||
137 | } | ||
138 | |||
139 | *count = sval; | ||
140 | return OSAL_ErrNone; | ||
141 | } | ||
diff --git a/libstagefrighthw/omx/osal/src/osal_task.c b/libstagefrighthw/omx/osal/src/osal_task.c new file mode 100755 index 0000000..f5c7e70 --- /dev/null +++ b/libstagefrighthw/omx/osal/src/osal_task.c | |||
@@ -0,0 +1,146 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 | |||
18 | #include <stdio.h> | ||
19 | #include <pthread.h> /*for POSIX calls */ | ||
20 | #include <sched.h> /*for sched structure */ | ||
21 | #include <unistd.h> | ||
22 | |||
23 | #include "osal_trace.h" | ||
24 | #include "osal_error.h" | ||
25 | #include "osal_memory.h" | ||
26 | #include "osal_task.h" | ||
27 | |||
28 | /** | ||
29 | * osal_task structure definition | ||
30 | */ | ||
31 | typedef struct osal_task | ||
32 | { | ||
33 | pthread_t threadID; /*SHM check */ | ||
34 | pthread_attr_t ThreadAttr; /* To set the priority and stack size */ | ||
35 | /*parameters to the task */ | ||
36 | uint32_t uArgc; | ||
37 | void *pArgv; | ||
38 | uint8_t isCreated; /** flag to check if task got created */ | ||
39 | } OSAL_Task; | ||
40 | |||
41 | /* | ||
42 | * Task creation | ||
43 | */ | ||
44 | OSAL_ERROR OSAL_CreateTask(void **pTask, OSAL_TaskProc pFunc, uint32_t uArgc, | ||
45 | void *pArgv, uint32_t uStackSize, uint32_t uPriority, int8_t *pName) | ||
46 | { | ||
47 | OSAL_ERROR bRet = OSAL_ErrThreadCreate; | ||
48 | OSAL_Task *pHandle = NULL; | ||
49 | struct sched_param sched; | ||
50 | size_t stackSize; | ||
51 | (void)pName; | ||
52 | *pTask = NULL; | ||
53 | |||
54 | /*Task structure allocation */ | ||
55 | pHandle = (OSAL_Task*)OSAL_Malloc(sizeof(OSAL_Task)); | ||
56 | if (NULL == pHandle) { | ||
57 | bRet = OSAL_ErrAlloc; | ||
58 | goto EXIT; | ||
59 | } | ||
60 | |||
61 | /* Initial cleaning of the task structure */ | ||
62 | OSAL_Memset((void*)pHandle, 0, sizeof(OSAL_Task)); | ||
63 | |||
64 | /*Arguments for task */ | ||
65 | pHandle->uArgc = uArgc; | ||
66 | pHandle->pArgv = pArgv; | ||
67 | pHandle->isCreated = OSAL_FALSE; | ||
68 | |||
69 | if (SUCCESS != pthread_attr_init(&pHandle->ThreadAttr)) { | ||
70 | OSAL_ErrorTrace("Task Init Attr Init failed!"); | ||
71 | goto EXIT; | ||
72 | } | ||
73 | |||
74 | /* Updation of the priority and the stack size */ | ||
75 | if (SUCCESS != pthread_attr_getschedparam(&pHandle->ThreadAttr, &sched)) { | ||
76 | OSAL_ErrorTrace("Task Init Get Sched Params failed!"); | ||
77 | goto EXIT; | ||
78 | } | ||
79 | |||
80 | sched.sched_priority = uPriority; /* relative to the default priority */ | ||
81 | if (SUCCESS != pthread_attr_setschedparam(&pHandle->ThreadAttr, &sched)) { | ||
82 | OSAL_ErrorTrace("Task Init Set Sched Paramsfailed!"); | ||
83 | goto EXIT; | ||
84 | } | ||
85 | |||
86 | /*First get the default stack size */ | ||
87 | if (SUCCESS != pthread_attr_getstacksize(&pHandle->ThreadAttr, &stackSize)) { | ||
88 | OSAL_ErrorTrace("Task Init Set Stack Size failed!"); | ||
89 | goto EXIT; | ||
90 | } | ||
91 | |||
92 | /*Check if requested stack size is larger than the current default stack size */ | ||
93 | if (uStackSize > stackSize) { | ||
94 | stackSize = uStackSize; | ||
95 | if (SUCCESS != pthread_attr_setstacksize(&pHandle->ThreadAttr, stackSize)) { | ||
96 | OSAL_ErrorTrace("Task Init Set Stack Size failed!"); | ||
97 | goto EXIT; | ||
98 | } | ||
99 | } | ||
100 | |||
101 | if (SUCCESS != pthread_create(&pHandle->threadID, &pHandle->ThreadAttr, pFunc, pArgv)) { | ||
102 | OSAL_ErrorTrace("Create_Task failed !"); | ||
103 | goto EXIT; | ||
104 | } | ||
105 | |||
106 | /* Task was successfully created */ | ||
107 | pHandle->isCreated = OSAL_TRUE; | ||
108 | *pTask = (void*) pHandle; | ||
109 | bRet = OSAL_ErrNone; | ||
110 | |||
111 | EXIT: | ||
112 | if (OSAL_ErrNone != bRet) { | ||
113 | OSAL_Free(pHandle); | ||
114 | } | ||
115 | return bRet; | ||
116 | } | ||
117 | |||
118 | |||
119 | OSAL_ERROR OSAL_DeleteTask(void *pTask) | ||
120 | { | ||
121 | OSAL_Task *pHandle = (OSAL_Task*)pTask; | ||
122 | void *retVal; | ||
123 | |||
124 | if (NULL == pHandle || OSAL_TRUE != pHandle->isCreated) { | ||
125 | /* this task was never created */ | ||
126 | return OSAL_ErrParameter; | ||
127 | } | ||
128 | if (pthread_attr_destroy(&pHandle->ThreadAttr)) { | ||
129 | OSAL_ErrorTrace("Delete_Task failed !"); | ||
130 | return OSAL_ErrThreadDestroy; | ||
131 | } | ||
132 | if (pthread_join(pHandle->threadID, &retVal)) { | ||
133 | OSAL_ErrorTrace("Delete_Task failed !"); | ||
134 | return OSAL_ErrThreadDestroy; | ||
135 | } | ||
136 | |||
137 | OSAL_Free(pHandle); | ||
138 | return OSAL_ErrNone; | ||
139 | } | ||
140 | |||
141 | |||
142 | OSAL_ERROR OSAL_SleepTask(uint32_t mSec) | ||
143 | { | ||
144 | usleep(1000 * mSec); | ||
145 | return OSAL_ErrNone; | ||
146 | } | ||
diff --git a/libstagefrighthw/omx/videodecode/Android.bp b/libstagefrighthw/omx/videodecode/Android.bp new file mode 100644 index 0000000..56e5509 --- /dev/null +++ b/libstagefrighthw/omx/videodecode/Android.bp | |||
@@ -0,0 +1,35 @@ | |||
1 | cc_library_shared { | ||
2 | |||
3 | name: "libOMX.ti.ducati.video.decoder", | ||
4 | vendor: true, | ||
5 | |||
6 | srcs: [ | ||
7 | "omx_video_decoder_componenttable.c", | ||
8 | "omx_video_decoder_h264.c", | ||
9 | "omx_video_decoder_internal.c", | ||
10 | "omx_video_decoder_mpeg4.c", | ||
11 | "omx_video_decoder_mpeg2.c", | ||
12 | "omx_video_decoder.c", | ||
13 | ], | ||
14 | |||
15 | header_libs: [ | ||
16 | "gralloc.am57x_headers", | ||
17 | "libutils_headers", | ||
18 | "media_plugin_headers", | ||
19 | ], | ||
20 | |||
21 | shared_libs: [ | ||
22 | "libc", | ||
23 | "libdce", | ||
24 | "libhardware", | ||
25 | "liblog", | ||
26 | "libosal", | ||
27 | "libOMX.ti.ducati.base", | ||
28 | ], | ||
29 | |||
30 | cflags: [ | ||
31 | "-DBUILDOS_ANDROID", | ||
32 | "-Wno-unused-variable", | ||
33 | ], | ||
34 | |||
35 | } | ||
diff --git a/libstagefrighthw/omx/videodecode/omx_video_decoder.c b/libstagefrighthw/omx/videodecode/omx_video_decoder.c new file mode 100644 index 0000000..e4ac495 --- /dev/null +++ b/libstagefrighthw/omx/videodecode/omx_video_decoder.c | |||
@@ -0,0 +1,1725 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 | #define LOG_TAG "OMX_VIDDEC_COMMON" | ||
18 | |||
19 | #include <omx_video_decoder_internal.h> | ||
20 | #include <OMX_TI_Custom.h> | ||
21 | |||
22 | #include <osal_trace.h> | ||
23 | #include <memplugin.h> | ||
24 | #include <libdce.h> | ||
25 | |||
26 | |||
27 | #define HAL_NV12_PADDED_PIXEL_FORMAT HAL_PIXEL_FORMAT_NV12 | ||
28 | |||
29 | #define MAX_REF_FRAMES 16 | ||
30 | |||
31 | /* | ||
32 | * Component Init | ||
33 | */ | ||
34 | OMX_ERRORTYPE OMX_ComponentInit(OMX_HANDLETYPE hComponent) | ||
35 | { | ||
36 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
37 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
38 | OMXVidDecComp *pVidDecComp = NULL; | ||
39 | OMX_PARAM_PORTDEFINITIONTYPE *pOutputPortDef = NULL; | ||
40 | OMX_U32 outPort = (OMX_U32)OMX_VIDDEC_OUTPUT_PORT; | ||
41 | OMX_CONFIG_RECTTYPE *p2DOutBufAllocParam = NULL; | ||
42 | |||
43 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
44 | |||
45 | /*! Call the Common Decoder Component Init */ | ||
46 | eError = OMXVidDec_ComponentInit(hComponent); | ||
47 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
48 | |||
49 | /*! Call the Decoder Specific Init as default */ | ||
50 | eError = DecoderList[DEFAULT_COMPOENENT].fpDecoderComponentInit(hComponent); | ||
51 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
52 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
53 | OMXVidDec_InitPortDefs(hComponent, pVidDecComp); | ||
54 | OMXVidDec_InitPortParams(pVidDecComp); | ||
55 | OMXVidDec_Set2DBuffParams(hComponent, pVidDecComp); | ||
56 | pOutputPortDef = &(pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef); | ||
57 | p2DOutBufAllocParam = &(pVidDecComp->t2DBufferAllocParams[outPort]); | ||
58 | pOutputPortDef->format.video.nStride = p2DOutBufAllocParam->nWidth; | ||
59 | |||
60 | /* Call Decoder Specific function to set Static Params */ | ||
61 | pVidDecComp->fpSet_StaticParams(hComponent, pVidDecComp->pDecStaticParams); | ||
62 | |||
63 | strcpy((char *)pVidDecComp->tComponentRole.cRole, | ||
64 | (char *)DecoderList[DEFAULT_COMPOENENT].cRole); | ||
65 | /* Set the Parse Header flag to XDM_PARSE_HEADER */ | ||
66 | pVidDecComp->nDecoderMode = XDM_PARSE_HEADER; | ||
67 | |||
68 | EXIT: | ||
69 | return (eError); | ||
70 | } | ||
71 | |||
72 | /* | ||
73 | * Video Decoder Component Init | ||
74 | */ | ||
75 | OMX_ERRORTYPE OMXVidDec_ComponentInit(OMX_HANDLETYPE hComponent) | ||
76 | { | ||
77 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
78 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
79 | OMXVidDecComp *pVidDecComp = NULL; | ||
80 | Engine_Error errorCode; | ||
81 | |||
82 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
83 | |||
84 | /* allocate the decoder component */ | ||
85 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
86 | pHandle->pComponentPrivate = (OMXVidDecComp*)OSAL_Malloc(sizeof(OMXVidDecComp)); | ||
87 | OMX_CHECK(pHandle->pComponentPrivate != NULL, OMX_ErrorInsufficientResources); | ||
88 | OSAL_Memset(pHandle->pComponentPrivate, 0x0, sizeof(OMXVidDecComp)); | ||
89 | |||
90 | pVidDecComp = (OMXVidDecComp*)pHandle->pComponentPrivate; | ||
91 | |||
92 | /*! Initialize the fields */ | ||
93 | eError = OMXVidDec_InitFields(pHandle->pComponentPrivate); | ||
94 | OMX_CHECK(eError == OMX_ErrorNone, OMX_ErrorUndefined); | ||
95 | |||
96 | strcpy(pVidDecComp->sBase.cComponentName, OMX_VIDEODECODER_COMPONENT_NAME); | ||
97 | |||
98 | /* Initialize the base component */ | ||
99 | eError = OMXBase_ComponentInit(hComponent); | ||
100 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
101 | |||
102 | /*Setting default properties. | ||
103 | * PreCondition: NumOfPorts is filled and all pointers allocated*/ | ||
104 | eError = OMXBase_SetDefaultProperties(hComponent); | ||
105 | OMX_CHECK(eError == OMX_ErrorNone, OMX_ErrorUnsupportedSetting); | ||
106 | |||
107 | /*! Initialize function pointers for Command and Data Notify */ | ||
108 | pVidDecComp->sBase.fpCommandNotify = OMXVidDec_CommandNotify; | ||
109 | pVidDecComp->sBase.fpDataNotify = OMXVidDec_DataNotify; | ||
110 | pVidDecComp->sBase.fpXlateBuffHandle = OMXVidDec_XlateBuffHandle; | ||
111 | |||
112 | /*! Initialize the function parameters for OMX functions */ | ||
113 | pHandle->SetParameter = OMXVidDec_SetParameter; | ||
114 | pHandle->GetParameter = OMXVidDec_GetParameter; | ||
115 | pHandle->GetConfig = OMXVidDec_GetConfig; | ||
116 | pHandle->SetConfig = OMXVidDec_SetConfig; | ||
117 | pHandle->ComponentDeInit = OMXVidDec_ComponentDeinit; | ||
118 | pHandle->GetExtensionIndex = OMXVidDec_GetExtensionIndex; | ||
119 | |||
120 | /*! Open instance of Codec engine */ | ||
121 | pVidDecComp->ce = Engine_open(engineName, NULL, &errorCode); | ||
122 | pVidDecComp->pDecHandle = NULL; | ||
123 | pVidDecComp->nFrameCounter = 0; | ||
124 | pVidDecComp->bSyncFrameReady = OMX_FALSE; | ||
125 | pVidDecComp->nOutbufInUseFlag = 0; | ||
126 | pVidDecComp->nCodecRecreationRequired = 0; | ||
127 | pVidDecComp->nOutPortReconfigRequired = 0; | ||
128 | pVidDecComp->nFatalErrorGiven = 0; | ||
129 | pVidDecComp->bInputBufferCancelled = 0; | ||
130 | pVidDecComp->bIPCRecoveryNeeded = OMX_FALSE; | ||
131 | /*! Initialize the Framerate divisor to 1000 as codec is supposed provide framerate after by multiplying with 1000 */ | ||
132 | pVidDecComp->nFrameRateDivisor = 1000; | ||
133 | pVidDecComp->tCropDimension.nTop = 0; | ||
134 | pVidDecComp->tCropDimension.nLeft = 0; | ||
135 | pVidDecComp->tScaleParams.xWidth = 0x10000; | ||
136 | pVidDecComp->tScaleParams.xHeight = 0x10000; | ||
137 | pVidDecComp->bUsePortReconfigForCrop = OMX_TRUE; | ||
138 | pVidDecComp->bUsePortReconfigForPadding = OMX_TRUE; | ||
139 | pVidDecComp->bSupportDecodeOrderTimeStamp = OMX_FALSE; | ||
140 | pVidDecComp->bSupportSkipGreyOutputFrames = OMX_TRUE; | ||
141 | pVidDecComp->bEnableDecodeZeroDisplayDelayMode = OMX_FALSE; | ||
142 | |||
143 | /*Optimize this pipe to be created only if decode timestamps is requested. */ | ||
144 | OSAL_CreatePipe(&(pVidDecComp->pTimeStampStoragePipe), MAX_REF_FRAMES * sizeof(OMX_TICKS), | ||
145 | sizeof(OMX_TICKS), 1); | ||
146 | |||
147 | pVidDecComp->tInBufDesc = (XDM2_BufDesc*)memplugin_alloc(sizeof(XDM2_BufDesc), 1, MEM_CARVEOUT, 0, 0); | ||
148 | OMX_CHECK(pVidDecComp->tInBufDesc != NULL, OMX_ErrorInsufficientResources); | ||
149 | OSAL_Memset(pVidDecComp->tInBufDesc, 0x0, sizeof(XDM2_BufDesc)); | ||
150 | |||
151 | pVidDecComp->tOutBufDesc = (XDM2_BufDesc*)memplugin_alloc(sizeof(XDM2_BufDesc), 1, MEM_CARVEOUT, 0, 0); | ||
152 | OMX_CHECK(pVidDecComp->tOutBufDesc != NULL, OMX_ErrorInsufficientResources); | ||
153 | OSAL_Memset(pVidDecComp->tOutBufDesc, 0x0, sizeof(XDM2_BufDesc)); | ||
154 | |||
155 | EXIT: | ||
156 | if( eError != OMX_ErrorNone ) { | ||
157 | if( pHandle != NULL ) { | ||
158 | OMXVidDec_ComponentDeinit(hComponent); | ||
159 | } | ||
160 | } | ||
161 | return (eError); | ||
162 | } | ||
163 | |||
164 | |||
165 | /* | ||
166 | * Video decoder setParameter | ||
167 | */ | ||
168 | OMX_ERRORTYPE OMXVidDec_SetParameter(OMX_HANDLETYPE hComponent, | ||
169 | OMX_INDEXTYPE nIndex, OMX_PTR pParamStruct) | ||
170 | { | ||
171 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
172 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
173 | OMXVidDecComp *pVidDecComp = NULL; | ||
174 | OMX_PARAM_PORTDEFINITIONTYPE *pPortDefs = NULL; | ||
175 | OMX_VIDEO_PARAM_PORTFORMATTYPE *pVideoParams = NULL; | ||
176 | OMX_CONFIG_RECTTYPE *p2DBufferAllocParams = NULL; | ||
177 | OMX_PARAM_PORTDEFINITIONTYPE *pInputPortDef = NULL; | ||
178 | OMX_PARAM_PORTDEFINITIONTYPE *pOutputPortDef = NULL; | ||
179 | OMX_VIDEO_PARAM_PORTFORMATTYPE *pInPortFmtType = NULL; | ||
180 | OMX_VIDEO_PARAM_PORTFORMATTYPE *pOutPortFmtType = NULL; | ||
181 | OMX_CONFIG_RECTTYPE *pOut2DBufAllocParam = NULL; | ||
182 | OMX_CONFIG_RECTTYPE *pIn2DBufAllocParam = NULL; | ||
183 | OMX_U32 i=0; | ||
184 | OMX_U32 bFound = 0; | ||
185 | OMX_U32 nFrameHeight = 0; | ||
186 | OMX_U32 nFrameWidth = 0; | ||
187 | struct PrepareForAdaptivePlaybackParams *pPrepareForAdaptivePlaybackParams; | ||
188 | OMX_U32 framesize = 0; | ||
189 | OMX_U32 metasize = 0; | ||
190 | |||
191 | OMX_CHECK((hComponent != NULL) && (pParamStruct != NULL), OMX_ErrorBadParameter); | ||
192 | |||
193 | /*! Initialize the pointers */ | ||
194 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
195 | pVidDecComp = (OMXVidDecComp*)pHandle->pComponentPrivate; | ||
196 | |||
197 | switch( (int) nIndex ) { | ||
198 | case OMX_IndexParamPortDefinition : | ||
199 | { | ||
200 | /*! To set the Port Definition */ | ||
201 | OMX_BASE_CHK_VERSION(pParamStruct, | ||
202 | OMX_PARAM_PORTDEFINITIONTYPE, eError); | ||
203 | |||
204 | pPortDefs = (OMX_PARAM_PORTDEFINITIONTYPE *) pParamStruct; | ||
205 | pInputPortDef = &(pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef); | ||
206 | pOutputPortDef = &(pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef); | ||
207 | |||
208 | //Check if an invalid port index is not sent | ||
209 | OMX_CHECK(pPortDefs->nPortIndex >= pVidDecComp->sBase.nMinStartPortIndex | ||
210 | && pPortDefs->nPortIndex < (pVidDecComp->sBase.nNumPorts + pVidDecComp->sBase.nMinStartPortIndex), | ||
211 | OMX_ErrorBadPortIndex); | ||
212 | |||
213 | /* SetParameter can be invoked in Loaded State or on Disabled ports only*/ | ||
214 | // OMX_CHECK((pVidDecComp->sBase.tCurState == OMX_StateLoaded) || | ||
215 | // (pVidDecComp->sBase.pPorts[pPortDefs->nPortIndex]->sPortDef.bEnabled == OMX_FALSE), | ||
216 | // OMX_ErrorIncorrectStateOperation); | ||
217 | // If Input Port Parameters have to be changed | ||
218 | if( pPortDefs->nPortIndex == pInputPortDef->nPortIndex ) { | ||
219 | /*! Check for correct resolution of the stream */ | ||
220 | nFrameWidth = pPortDefs->format.video.nFrameWidth; | ||
221 | nFrameHeight = pPortDefs->format.video.nFrameHeight; | ||
222 | |||
223 | OMX_CHECK((nFrameWidth <= OMX_VIDDEC_MAX_WIDTH), | ||
224 | OMX_ErrorUnsupportedSetting); | ||
225 | OMX_CHECK((nFrameHeight <= OMX_VIDDEC_MAX_HEIGHT), | ||
226 | OMX_ErrorUnsupportedSetting); | ||
227 | OMX_CHECK((((nFrameWidth * nFrameHeight) >> 16) <= OMX_VIDDEC_MAX_MACROBLOCK), | ||
228 | OMX_ErrorUnsupportedSetting); | ||
229 | |||
230 | /*! Call function to set input port definition */ | ||
231 | eError = OMXVidDec_SetInPortDef(hComponent, pPortDefs); | ||
232 | if( eError != OMX_ErrorNone ) { | ||
233 | goto EXIT; | ||
234 | } | ||
235 | if( pVidDecComp->sBase.tCurState != OMX_StateLoaded ) { | ||
236 | pVidDecComp->nCodecRecreationRequired = 1; | ||
237 | } | ||
238 | } | ||
239 | // If Output Port Parameters have to be changed | ||
240 | else if( pPortDefs->nPortIndex == pOutputPortDef->nPortIndex ) { | ||
241 | // Check the buffer cnt is greater than min required | ||
242 | // buffer count | ||
243 | OMX_CHECK((pPortDefs->nBufferCountActual | ||
244 | >= pOutputPortDef->nBufferCountMin), | ||
245 | OMX_ErrorUnsupportedSetting); | ||
246 | // Check if Resolution being set at output port is same | ||
247 | // as the input port | ||
248 | OMX_CHECK((pOutputPortDef->format.video.nFrameHeight | ||
249 | == pPortDefs->format.video.nFrameHeight) | ||
250 | && (pOutputPortDef->format.video.nFrameWidth | ||
251 | == pPortDefs->format.video.nFrameWidth), | ||
252 | OMX_ErrorUnsupportedSetting); | ||
253 | |||
254 | OMX_CHECK((OMX_U32)pPortDefs->format.video.nStride >= | ||
255 | pOutputPortDef->format.video.nFrameWidth, | ||
256 | OMX_ErrorUnsupportedSetting); | ||
257 | if( (OMX_U32)pPortDefs->format.video.nStride > | ||
258 | pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nWidth ) { | ||
259 | //Supported values of stride are only multiples of 128 | ||
260 | OMX_CHECK((pPortDefs->format.video.nStride & 0x7F) == 0, | ||
261 | OMX_ErrorUnsupportedSetting); | ||
262 | } | ||
263 | //Check for the supported Color-fromat | ||
264 | //and compression format. | ||
265 | |||
266 | if (pVidDecComp->sBase.pPorts[pOutputPortDef->nPortIndex]->sProps.eBufMemoryType == MEM_GRALLOC) { | ||
267 | //OMX_CHECK((pOutputPortDef->format.video.eColorFormat == HAL_NV12_PADDED_PIXEL_FORMAT), | ||
268 | // OMX_ErrorUnsupportedSetting); | ||
269 | } else { | ||
270 | OMX_CHECK((pOutputPortDef->format.video.eColorFormat == OMX_TI_COLOR_FormatYUV420PackedSemiPlanar), | ||
271 | OMX_ErrorUnsupportedSetting); | ||
272 | } | ||
273 | |||
274 | OMX_CHECK((pOutputPortDef->format.video.eCompressionFormat == | ||
275 | OMX_VIDEO_CodingUnused), | ||
276 | OMX_ErrorUnsupportedSetting); | ||
277 | |||
278 | /*! Call function to set output port definition */ | ||
279 | eError = OMXVidDec_SetOutPortDef(pVidDecComp, pPortDefs); | ||
280 | if( eError != OMX_ErrorNone ) { | ||
281 | goto EXIT; | ||
282 | } | ||
283 | } | ||
284 | } | ||
285 | |||
286 | /* If MPEG2 and Error Concealment; then memplugin_alloc for pOutBufDescPtr->descs[2] one time allocation only.*/ | ||
287 | if (pVidDecComp->tVideoParams[OMX_VIDDEC_INPUT_PORT].eCompressionFormat == OMX_VIDEO_CodingMPEG2) { | ||
288 | if (pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef.format.video.bFlagErrorConcealment) { | ||
289 | /* It's MPEG2 and ErrorConcealment is ON; calculate metadata buffer size based on formula described in MPEG2 User Guide */ | ||
290 | framesize = (((pInputPortDef->format.video.nFrameWidth + 15) / 16) * 16) * (((pInputPortDef->format.video.nFrameHeight + 15) / 16) * 16); | ||
291 | metasize = ((framesize >> 8) * 112) + framesize; | ||
292 | if (pVidDecComp->pmetaBuffer && pVidDecComp->pmetaBuffer->size < metasize) { | ||
293 | memplugin_free((void*)H2P(pVidDecComp->pmetaBuffer)); | ||
294 | pVidDecComp->pmetaBuffer = NULL; | ||
295 | } | ||
296 | if (pVidDecComp->pmetaBuffer == NULL) { | ||
297 | pVidDecComp->pmetaBuffer = P2H(memplugin_alloc(metasize, 1, MEM_CARVEOUT, 0, 0)); | ||
298 | OMX_CHECK(pVidDecComp->pmetaBuffer != NULL, OMX_ErrorInsufficientResources); | ||
299 | } | ||
300 | } | ||
301 | } | ||
302 | break; | ||
303 | |||
304 | case OMX_IndexParamVideoPortFormat : | ||
305 | { | ||
306 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_PORTFORMATTYPE, eError); | ||
307 | pVideoParams = (OMX_VIDEO_PARAM_PORTFORMATTYPE *) pParamStruct; | ||
308 | pOutputPortDef = &(pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef); | ||
309 | OMX_CHECK((pVidDecComp->sBase.tCurState == OMX_StateLoaded) || | ||
310 | (pVidDecComp->sBase.pPorts[pVideoParams->nPortIndex]->sPortDef.bEnabled == OMX_FALSE), | ||
311 | OMX_ErrorIncorrectStateOperation); | ||
312 | |||
313 | pInPortFmtType = &(pVidDecComp->tVideoParams[OMX_VIDDEC_INPUT_PORT]); | ||
314 | pOutPortFmtType = &(pVidDecComp->tVideoParams[OMX_VIDDEC_OUTPUT_PORT]); | ||
315 | // If Input Port Format type has to be changed | ||
316 | if( pVideoParams->nPortIndex == pInPortFmtType->nPortIndex ) { | ||
317 | // Change Compression type and frame-rate | ||
318 | pInPortFmtType->eCompressionFormat | ||
319 | = pVideoParams->eCompressionFormat; | ||
320 | pInPortFmtType->xFramerate = pVideoParams->xFramerate; | ||
321 | } | ||
322 | // In case Output Port Format type has to be changed | ||
323 | else if( pVideoParams->nPortIndex == pOutPortFmtType->nPortIndex ) { | ||
324 | //Check for the supported Color-fromat | ||
325 | //and compression format. | ||
326 | if (pVidDecComp->sBase.pPorts[pVideoParams->nPortIndex]->sProps.eBufMemoryType == MEM_GRALLOC) { | ||
327 | // OMX_CHECK((pVideoParams->eColorFormat == HAL_NV12_PADDED_PIXEL_FORMAT), | ||
328 | // OMX_ErrorUnsupportedSetting); | ||
329 | } else { | ||
330 | OMX_CHECK((pVideoParams->eColorFormat == OMX_TI_COLOR_FormatYUV420PackedSemiPlanar), | ||
331 | OMX_ErrorUnsupportedSetting); | ||
332 | } | ||
333 | OMX_CHECK((pVideoParams->eCompressionFormat == | ||
334 | OMX_VIDEO_CodingUnused), OMX_ErrorUnsupportedSetting); | ||
335 | |||
336 | pOutputPortDef->format.video.eColorFormat | ||
337 | = pVideoParams->eColorFormat; | ||
338 | |||
339 | // Change Compression type, color format and frame-rate | ||
340 | pOutPortFmtType->eCompressionFormat | ||
341 | = pVideoParams->eCompressionFormat; | ||
342 | pOutPortFmtType->eColorFormat = pVideoParams->eColorFormat; | ||
343 | pOutPortFmtType->xFramerate = pVideoParams->xFramerate; | ||
344 | } | ||
345 | } | ||
346 | break; | ||
347 | |||
348 | case OMX_IndexParamStandardComponentRole : | ||
349 | { | ||
350 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_PARAM_COMPONENTROLETYPE, eError); | ||
351 | |||
352 | /* SetParameter can be invoked in Loaded State or on Disabled ports only*/ | ||
353 | OMX_CHECK(pVidDecComp->sBase.tCurState == OMX_StateLoaded, | ||
354 | OMX_ErrorIncorrectStateOperation); | ||
355 | /*! In case there is change in Role */ | ||
356 | if( strcmp((char *)((OMX_PARAM_COMPONENTROLETYPE *)pParamStruct)->cRole, | ||
357 | (char *)pVidDecComp->tComponentRole.cRole)) { | ||
358 | /* De-initialize the current codec */ | ||
359 | pVidDecComp->fpDeinit_Codec(hComponent); | ||
360 | |||
361 | /* Call specific component init depending upon the | ||
362 | cRole set. */ | ||
363 | i=0; | ||
364 | while( NULL != DecoderList[i].cRole[0] ) { | ||
365 | if( strcmp((char *)((OMX_PARAM_COMPONENTROLETYPE *)pParamStruct)->cRole, | ||
366 | (char *)DecoderList[i].cRole) == 0 ) { | ||
367 | /* Component found */ | ||
368 | bFound = 1; | ||
369 | break; | ||
370 | } | ||
371 | i++; | ||
372 | } | ||
373 | |||
374 | if( bFound == 0 ) { | ||
375 | OSAL_ErrorTrace("Unsupported Role set"); | ||
376 | eError = OMX_ErrorUnsupportedSetting; | ||
377 | goto EXIT; | ||
378 | } | ||
379 | /* Call the Specific Decoder Init function and Initialize Params */ | ||
380 | eError = DecoderList[i].fpDecoderComponentInit(hComponent); | ||
381 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
382 | OMXVidDec_InitDecoderParams(hComponent, pHandle->pComponentPrivate); | ||
383 | |||
384 | strcpy((char *)pVidDecComp->tComponentRole.cRole, | ||
385 | (char *)((OMX_PARAM_COMPONENTROLETYPE *)pParamStruct)->cRole); | ||
386 | } | ||
387 | } | ||
388 | break; | ||
389 | |||
390 | case OMX_TI_IndexParamTimeStampInDecodeOrder : | ||
391 | { | ||
392 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_TI_PARAM_TIMESTAMP_IN_DECODE_ORDER, eError); | ||
393 | |||
394 | /* SetParameter can be invoked in Loaded State or on Disabled ports only*/ | ||
395 | OMX_CHECK(pVidDecComp->sBase.tCurState == OMX_StateLoaded, | ||
396 | OMX_ErrorIncorrectStateOperation); | ||
397 | if(((OMX_TI_PARAM_TIMESTAMP_IN_DECODE_ORDER *) pParamStruct)->bEnabled == OMX_TRUE ) { | ||
398 | pVidDecComp->bSupportDecodeOrderTimeStamp = OMX_TRUE; | ||
399 | } else { | ||
400 | pVidDecComp->bSupportDecodeOrderTimeStamp = OMX_FALSE; | ||
401 | } | ||
402 | } | ||
403 | break; | ||
404 | |||
405 | case (OMX_INDEXTYPE) OMX_TI_IndexEnableDecoderZeroDisplayDelayMode : | ||
406 | { | ||
407 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_TI_ENABLE_DECODER_ZERODISPLAYDELAY_MODE, eError); | ||
408 | |||
409 | /* This SetParameter can be invoked in Loaded State only as it needs codec recreate.*/ | ||
410 | OMX_CHECK(pVidDecComp->sBase.tCurState == OMX_StateLoaded, | ||
411 | OMX_ErrorIncorrectStateOperation); | ||
412 | if(((OMX_TI_ENABLE_DECODER_ZERODISPLAYDELAY_MODE *) pParamStruct)->bEnabled == OMX_TRUE ) { | ||
413 | pVidDecComp->bEnableDecodeZeroDisplayDelayMode = OMX_TRUE; | ||
414 | } else { | ||
415 | pVidDecComp->bEnableDecodeZeroDisplayDelayMode = OMX_FALSE; | ||
416 | } | ||
417 | } | ||
418 | break; | ||
419 | |||
420 | case (OMX_INDEXTYPE) OMX_TI_IndexPrepareForAdaptivePlayback: | ||
421 | { | ||
422 | OMX_BASE_CHK_VERSION(pParamStruct, PrepareForAdaptivePlaybackParams, eError); | ||
423 | /* This SetParameter can be invoked in Loaded State only as it needs codec recreate.*/ | ||
424 | OMX_CHECK(pVidDecComp->sBase.tCurState == OMX_StateLoaded, | ||
425 | OMX_ErrorIncorrectStateOperation); | ||
426 | pPrepareForAdaptivePlaybackParams = (PrepareForAdaptivePlaybackParams *) pParamStruct; | ||
427 | pVidDecComp->bisAdaptivePlayback = pPrepareForAdaptivePlaybackParams->bEnable; | ||
428 | pVidDecComp->nAdaptiveMaxFrameWidth = pPrepareForAdaptivePlaybackParams->nMaxFrameWidth; | ||
429 | pVidDecComp->nAdaptiveMaxFrameHeight = pPrepareForAdaptivePlaybackParams->nMaxFrameHeight; | ||
430 | } | ||
431 | break; | ||
432 | |||
433 | |||
434 | default : | ||
435 | eError = OMXBase_SetParameter(hComponent, nIndex, pParamStruct); | ||
436 | } | ||
437 | |||
438 | EXIT: | ||
439 | return (eError); | ||
440 | } | ||
441 | |||
442 | /* | ||
443 | * Video Decoder Get Parameter | ||
444 | */ | ||
445 | OMX_ERRORTYPE OMXVidDec_GetParameter(OMX_HANDLETYPE hComponent, | ||
446 | OMX_INDEXTYPE nIndex, OMX_PTR pParamStruct) | ||
447 | { | ||
448 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
449 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
450 | OMXVidDecComp *pVidDecComp = NULL; | ||
451 | OMX_VIDEO_PARAM_PORTFORMATTYPE *pVideoParams = NULL; | ||
452 | OMX_CONFIG_RECTTYPE *p2DBufferAllocParams = NULL; | ||
453 | OMX_VIDEO_PARAM_PORTFORMATTYPE inPortParam; | ||
454 | OMX_VIDEO_PARAM_PORTFORMATTYPE outPortParam; | ||
455 | OMX_TI_PARAMNATIVEBUFFERUSAGE *pUsage = NULL; | ||
456 | OMX_PARAM_PORTDEFINITIONTYPE *pPortDef = NULL; | ||
457 | OMX_U32 nStartPortNumber, nPorts, nPortIndex; | ||
458 | OMX_PARAM_PORTDEFINITIONTYPE *pOutputPortDef = NULL; | ||
459 | struct DescribeColorFormatParams *Colorparams; | ||
460 | |||
461 | OMX_CHECK((hComponent != NULL) && | ||
462 | (pParamStruct != NULL), OMX_ErrorBadParameter); | ||
463 | |||
464 | // Initialize the local variables | ||
465 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
466 | pVidDecComp = (OMXVidDecComp*)pHandle->pComponentPrivate; | ||
467 | |||
468 | /* GetParameter can't be invoked incase the comp is in Invalid State */ | ||
469 | OMX_CHECK(pVidDecComp->sBase.tCurState != OMX_StateInvalid, | ||
470 | OMX_ErrorIncorrectStateOperation); | ||
471 | |||
472 | switch( (int) nIndex ) { | ||
473 | case OMX_IndexParamPortDefinition: | ||
474 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_PARAM_PORTDEFINITIONTYPE, | ||
475 | eError); | ||
476 | pPortDef = (OMX_PARAM_PORTDEFINITIONTYPE *)pParamStruct; | ||
477 | |||
478 | nPorts = pVidDecComp->sBase.nNumPorts; | ||
479 | nStartPortNumber = pVidDecComp->sBase.nMinStartPortIndex; | ||
480 | |||
481 | nPortIndex = pPortDef->nPortIndex - nStartPortNumber; | ||
482 | /* check for valid port index */ | ||
483 | OMX_CHECK(nPortIndex < nPorts, OMX_ErrorBadPortIndex); | ||
484 | *pPortDef = pVidDecComp->sBase.pPorts[nPortIndex]->sPortDef; | ||
485 | if (pPortDef->eDir == OMX_DirOutput && | ||
486 | pVidDecComp->sBase.pPorts[nPortIndex]->sProps.eBufMemoryType == MEM_GRALLOC) { | ||
487 | pPortDef->format.video.eColorFormat = HAL_NV12_PADDED_PIXEL_FORMAT; | ||
488 | } | ||
489 | break; | ||
490 | |||
491 | case OMX_IndexParamVideoPortFormat : | ||
492 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_PORTFORMATTYPE, eError); | ||
493 | // Initialize Port Params | ||
494 | pVideoParams = (OMX_VIDEO_PARAM_PORTFORMATTYPE *) pParamStruct; | ||
495 | inPortParam = pVidDecComp->tVideoParams[OMX_VIDDEC_INPUT_PORT]; | ||
496 | outPortParam = pVidDecComp->tVideoParams[OMX_VIDDEC_OUTPUT_PORT]; | ||
497 | if( pVideoParams->nPortIndex == inPortParam.nPortIndex ) { | ||
498 | if( pVideoParams->nIndex > inPortParam.nIndex ) { | ||
499 | return (OMX_ErrorNoMore); | ||
500 | } | ||
501 | pVideoParams->eCompressionFormat = inPortParam.eCompressionFormat; | ||
502 | pVideoParams->eColorFormat = inPortParam.eColorFormat; | ||
503 | pVideoParams->xFramerate = inPortParam.xFramerate; | ||
504 | if(pVideoParams->eColorFormat == OMX_COLOR_FormatYUV420PackedSemiPlanar) | ||
505 | pVideoParams->eColorFormat = OMX_COLOR_FormatYUV420Flexible; // OMX_TI_COLOR_FormatYUV420PackedSemiPlanar; | ||
506 | } else if( pVideoParams->nPortIndex == outPortParam.nPortIndex ) { | ||
507 | if( pVideoParams->nIndex == 0 ) { | ||
508 | if (pVidDecComp->sBase.pPorts[pVideoParams->nPortIndex]->sProps.eBufMemoryType == MEM_GRALLOC) { | ||
509 | pVideoParams->eColorFormat = HAL_NV12_PADDED_PIXEL_FORMAT; | ||
510 | } else { | ||
511 | pVideoParams->eColorFormat = OMX_TI_COLOR_FormatYUV420PackedSemiPlanar; | ||
512 | } | ||
513 | } else if( pVideoParams->nIndex > outPortParam.nIndex ) { | ||
514 | return (OMX_ErrorNoMore); | ||
515 | } | ||
516 | pVideoParams->eCompressionFormat = outPortParam.eCompressionFormat; | ||
517 | pVideoParams->xFramerate = outPortParam.xFramerate; | ||
518 | } | ||
519 | break; | ||
520 | |||
521 | case OMX_IndexParamStandardComponentRole : | ||
522 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_PARAM_COMPONENTROLETYPE, eError); | ||
523 | strcpy((char *)((OMX_PARAM_COMPONENTROLETYPE *)pParamStruct)->cRole, | ||
524 | (char *)pVidDecComp->tComponentRole.cRole); | ||
525 | break; | ||
526 | |||
527 | case (OMX_INDEXTYPE) OMX_TI_IndexAndroidNativeBufferUsage: | ||
528 | pUsage = (OMX_TI_PARAMNATIVEBUFFERUSAGE*)pParamStruct; | ||
529 | pUsage->nUsage = GRALLOC_USAGE_HW_RENDER; | ||
530 | break; | ||
531 | |||
532 | case (OMX_INDEXTYPE) OMX_TI_IndexDescribeColorFormat: | ||
533 | Colorparams = (struct DescribeColorFormatParams*)(pParamStruct); | ||
534 | |||
535 | pOutputPortDef = &(pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef); | ||
536 | |||
537 | struct MediaImage *image = &(Colorparams->sMediaImage); | ||
538 | memset(image, 0, sizeof(MediaImage)); | ||
539 | |||
540 | image->mWidth = pOutputPortDef->format.video.nFrameWidth; | ||
541 | image->mHeight = pOutputPortDef->format.video.nFrameHeight; | ||
542 | |||
543 | image->mType = MEDIA_IMAGE_TYPE_YUV; | ||
544 | image->mNumPlanes = 3; | ||
545 | image->mBitDepth = 8; | ||
546 | /* The crop left and top calculation is not needed here. | ||
547 | Stagefright will add pBuffer->nOffset to this Y offset. */ | ||
548 | image->mPlane[Y].mOffset = 0; | ||
549 | image->mPlane[Y].mColInc = 1; | ||
550 | image->mPlane[Y].mRowInc = pOutputPortDef->format.video.nStride; | ||
551 | image->mPlane[Y].mHorizSubsampling = 1; | ||
552 | image->mPlane[Y].mVertSubsampling = 1; | ||
553 | |||
554 | /* Since the position of the Buffer is at the starting of Y buffer (UV offset from base - Y offset), | ||
555 | UV offset = (Stride*Height + (Top/2)*Stride + Left )- (Top*Stride + Left) | ||
556 | on simplification | ||
557 | UV offset = Stride*Height - (Top/2)*Stride */ | ||
558 | image->mPlane[U].mOffset = pOutputPortDef->format.video.nStride * pOutputPortDef->format.video.nFrameHeight; | ||
559 | image->mPlane[U].mColInc = 2; | ||
560 | image->mPlane[U].mRowInc = pOutputPortDef->format.video.nStride; | ||
561 | image->mPlane[U].mHorizSubsampling = 2; | ||
562 | image->mPlane[U].mVertSubsampling = 2; | ||
563 | |||
564 | image->mPlane[V].mOffset = image->mPlane[U].mOffset + 1; | ||
565 | image->mPlane[V].mColInc = 2; | ||
566 | image->mPlane[V].mRowInc = pOutputPortDef->format.video.nStride; | ||
567 | image->mPlane[V].mHorizSubsampling = 2; | ||
568 | image->mPlane[V].mVertSubsampling = 2; | ||
569 | |||
570 | break; | ||
571 | |||
572 | case (OMX_INDEXTYPE) OMX_TI_IndexParamTimeStampInDecodeOrder : | ||
573 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_TI_PARAM_TIMESTAMP_IN_DECODE_ORDER, eError); | ||
574 | if( pVidDecComp->bSupportDecodeOrderTimeStamp == OMX_TRUE ) { | ||
575 | ((OMX_TI_PARAM_TIMESTAMP_IN_DECODE_ORDER *) pParamStruct)->bEnabled = OMX_TRUE; | ||
576 | } else { | ||
577 | ((OMX_TI_PARAM_TIMESTAMP_IN_DECODE_ORDER *) pParamStruct)->bEnabled = OMX_FALSE; | ||
578 | } | ||
579 | break; | ||
580 | |||
581 | case (OMX_INDEXTYPE) OMX_TI_IndexEnableDecoderZeroDisplayDelayMode : | ||
582 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_TI_ENABLE_DECODER_ZERODISPLAYDELAY_MODE, eError); | ||
583 | if( pVidDecComp->bEnableDecodeZeroDisplayDelayMode == OMX_TRUE ) { | ||
584 | ((OMX_TI_ENABLE_DECODER_ZERODISPLAYDELAY_MODE *) pParamStruct)->bEnabled = OMX_TRUE; | ||
585 | } else { | ||
586 | ((OMX_TI_ENABLE_DECODER_ZERODISPLAYDELAY_MODE *) pParamStruct)->bEnabled = OMX_FALSE; | ||
587 | } | ||
588 | break; | ||
589 | |||
590 | default : | ||
591 | eError = OMXBase_GetParameter(hComponent, nIndex, pParamStruct); | ||
592 | } | ||
593 | |||
594 | EXIT: | ||
595 | return (eError); | ||
596 | } | ||
597 | |||
598 | /* | ||
599 | * Video decoder GetConfig | ||
600 | */ | ||
601 | OMX_ERRORTYPE OMXVidDec_GetConfig(OMX_HANDLETYPE hComponent, | ||
602 | OMX_INDEXTYPE nIndex, OMX_PTR pComponentConfigStructure) { | ||
603 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
604 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
605 | OMXVidDecComp *pVidDecComp = NULL; | ||
606 | OMX_CONFIG_RECTTYPE *pCropParams = NULL; | ||
607 | OMX_CONFIG_SCALEFACTORTYPE *pScaleParams = NULL; | ||
608 | |||
609 | OMX_CHECK((hComponent != NULL) && | ||
610 | (pComponentConfigStructure != NULL), OMX_ErrorBadParameter); | ||
611 | |||
612 | // Initialize the local variables | ||
613 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
614 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
615 | |||
616 | /* GetConfig can't be invoked incase the comp is in Invalid State */ | ||
617 | OMX_CHECK(pVidDecComp->sBase.tCurState != OMX_StateInvalid, | ||
618 | OMX_ErrorIncorrectStateOperation); | ||
619 | |||
620 | switch( nIndex ) { | ||
621 | case OMX_IndexConfigCommonOutputCrop : | ||
622 | { | ||
623 | OMX_BASE_CHK_VERSION(pComponentConfigStructure, OMX_CONFIG_RECTTYPE, eError); | ||
624 | pCropParams = (OMX_CONFIG_RECTTYPE *) pComponentConfigStructure; | ||
625 | if( pCropParams->nPortIndex == OMX_VIDDEC_OUTPUT_PORT ) { | ||
626 | pCropParams->nWidth = pVidDecComp->tCropDimension.nWidth; | ||
627 | pCropParams->nHeight = pVidDecComp->tCropDimension.nHeight; | ||
628 | pCropParams->nTop = pVidDecComp->tCropDimension.nTop; | ||
629 | pCropParams->nLeft = pVidDecComp->tCropDimension.nLeft; | ||
630 | } else { | ||
631 | eError = OMX_ErrorBadParameter; | ||
632 | OSAL_ErrorTrace("OMX_IndexConfigCommonOutputCrop called on i/p port. Not Supported."); | ||
633 | } | ||
634 | } | ||
635 | break; | ||
636 | |||
637 | case OMX_IndexConfigCommonScale : | ||
638 | { | ||
639 | OMX_BASE_CHK_VERSION(pComponentConfigStructure, OMX_CONFIG_SCALEFACTORTYPE, eError); | ||
640 | pScaleParams = (OMX_CONFIG_SCALEFACTORTYPE *) pComponentConfigStructure; | ||
641 | if( pScaleParams->nPortIndex == OMX_VIDDEC_OUTPUT_PORT ) { | ||
642 | pScaleParams->xWidth = pVidDecComp->tScaleParams.xWidth; | ||
643 | pScaleParams->xHeight = pVidDecComp->tScaleParams.xHeight; | ||
644 | OSAL_ErrorTrace("OMX_IndexConfigCommonScale called on o/p port."); | ||
645 | } else { | ||
646 | eError = OMX_ErrorBadParameter; | ||
647 | OSAL_ErrorTrace("OMX_IndexConfigCommonOutputCrop called on i/p port. Not Supported."); | ||
648 | } | ||
649 | } | ||
650 | break; | ||
651 | |||
652 | default : | ||
653 | eError = OMXBase_GetConfig(hComponent, nIndex, pComponentConfigStructure); | ||
654 | } | ||
655 | |||
656 | EXIT: | ||
657 | return (eError); | ||
658 | } | ||
659 | |||
660 | /* | ||
661 | * Video Decoder SetConfig | ||
662 | */ | ||
663 | OMX_ERRORTYPE OMXVidDec_SetConfig(OMX_HANDLETYPE hComponent, | ||
664 | OMX_INDEXTYPE nIndex, OMX_PTR pComponentConfigStructure) { | ||
665 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
666 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
667 | OMXVidDecComp *pVidDecComp = NULL; | ||
668 | |||
669 | OMX_CHECK((hComponent != NULL) && | ||
670 | (pComponentConfigStructure != NULL), OMX_ErrorBadParameter); | ||
671 | |||
672 | // Initialize the local variables | ||
673 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
674 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
675 | |||
676 | /* SetConfig can't be invoked incase the comp is in Invalid State */ | ||
677 | OMX_CHECK(pVidDecComp->sBase.tCurState != OMX_StateInvalid, | ||
678 | OMX_ErrorIncorrectStateOperation); | ||
679 | |||
680 | switch( nIndex ) { | ||
681 | default : | ||
682 | eError = OMXBase_SetConfig(hComponent, nIndex, pComponentConfigStructure); | ||
683 | } | ||
684 | |||
685 | EXIT: | ||
686 | return (eError); | ||
687 | } | ||
688 | |||
689 | /* | ||
690 | * Video Decoder xlateBuffer Handles | ||
691 | */ | ||
692 | OMX_ERRORTYPE OMXVidDec_XlateBuffHandle(OMX_HANDLETYPE hComponent, | ||
693 | OMX_PTR pBufferHdr, OMX_BOOL bRegister) | ||
694 | { | ||
695 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
696 | OMX_COMPONENTTYPE *pComp = NULL; | ||
697 | OMXVidDecComp *pVidDecComp = NULL; | ||
698 | OMX_BUFFERHEADERTYPE *pOMXBufHeader; | ||
699 | OMXBase_Port *pPort; | ||
700 | OMX_U32 nPortIndex; | ||
701 | int32_t tRetVal; | ||
702 | int i; | ||
703 | |||
704 | pComp = (OMX_COMPONENTTYPE *)(hComponent); | ||
705 | pVidDecComp = (OMXVidDecComp *)pComp->pComponentPrivate; | ||
706 | |||
707 | pOMXBufHeader = (OMX_BUFFERHEADERTYPE *) (pBufferHdr); | ||
708 | nPortIndex = (pOMXBufHeader->nInputPortIndex == OMX_NOPORT) ? | ||
709 | pOMXBufHeader->nOutputPortIndex : | ||
710 | pOMXBufHeader->nInputPortIndex; | ||
711 | |||
712 | pPort = pVidDecComp->sBase.pPorts[nPortIndex]; | ||
713 | |||
714 | /* Non a buffer allocator, then check if any xlation is needed */ | ||
715 | if (pPort->sProps.eBufMemoryType == MEM_GRALLOC) { | ||
716 | //populate the DMA BUFF_FDs from the gralloc pointers | ||
717 | for ( i = 0; i < MAX_PLANES_PER_BUFFER; i++ ) { | ||
718 | ((OMXBase_BufHdrPvtData *)(pOMXBufHeader->pPlatformPrivate))->sMemHdr[i].dma_buf_fd = (OMX_U32)(((IMG_native_handle_t*)(pOMXBufHeader->pBuffer))->fd[i]); | ||
719 | if (((OMXBase_BufHdrPvtData *)(pOMXBufHeader->pPlatformPrivate))->sMemHdr[i].dma_buf_fd > 0) { | ||
720 | if (bRegister) { | ||
721 | dce_buf_lock(1, (size_t *)&(((OMXBase_BufHdrPvtData *)(pOMXBufHeader->pPlatformPrivate))->sMemHdr[i].dma_buf_fd)); | ||
722 | } else { | ||
723 | dce_buf_unlock(1, (size_t *)&(((OMXBase_BufHdrPvtData *)(pOMXBufHeader->pPlatformPrivate))->sMemHdr[i].dma_buf_fd)); | ||
724 | } | ||
725 | } | ||
726 | } | ||
727 | } | ||
728 | |||
729 | return (eError); | ||
730 | } | ||
731 | |||
732 | /* | ||
733 | * video decoder Command Notify | ||
734 | */ | ||
735 | OMX_ERRORTYPE OMXVidDec_CommandNotify(OMX_HANDLETYPE hComponent, | ||
736 | OMX_COMMANDTYPE Cmd, OMX_U32 nParam, OMX_PTR pCmdData) | ||
737 | { | ||
738 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
739 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
740 | OMXVidDecComp *pVidDecComp = NULL; | ||
741 | XDAS_Int32 status; | ||
742 | OMX_U32 ReturnCmdCompletionCallBack = 1, i; | ||
743 | OMX_PTR pDecStaticParams; | ||
744 | OMX_PTR pDecDynamicParams; | ||
745 | OMX_PTR pDecStatus; | ||
746 | OMX_PARAM_PORTDEFINITIONTYPE *pOutputPortDef; | ||
747 | OMX_U32 nFrameWidth, nFrameHeight; | ||
748 | OMX_U32 nFrameWidthOrig; | ||
749 | (void) pCmdData; | ||
750 | |||
751 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
752 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
753 | pVidDecComp = pHandle->pComponentPrivate; | ||
754 | |||
755 | switch( Cmd ) { | ||
756 | case OMX_CommandStateSet : | ||
757 | if( pVidDecComp->sBase.tCurState == OMX_StateLoaded && | ||
758 | pVidDecComp->sBase.tNewState == OMX_StateIdle ) { | ||
759 | pOutputPortDef = &(pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef); | ||
760 | // Check the buffer cnt is greater than min required | ||
761 | // buffer count | ||
762 | if( pOutputPortDef->nBufferCountActual < pOutputPortDef->nBufferCountMin ) { | ||
763 | OSAL_ErrorTrace("Number of actual buffers on o/p port less than the minmum required by componenet as set on o/p port defs"); | ||
764 | eError = OMX_ErrorUnsupportedSetting; | ||
765 | goto EXIT; | ||
766 | } | ||
767 | |||
768 | // Transitioning from Loaded to Idle state | ||
769 | if(pVidDecComp->pDecHandle == NULL ) { | ||
770 | pDecStaticParams = pVidDecComp->pDecStaticParams; | ||
771 | // Call the Video Decoder Create Call | ||
772 | pVidDecComp->pDecHandle | ||
773 | = VIDDEC3_create(pVidDecComp->ce, | ||
774 | pVidDecComp->cDecoderName, | ||
775 | (VIDDEC3_Params *) pDecStaticParams); | ||
776 | |||
777 | if( pVidDecComp->pDecHandle == NULL ) { | ||
778 | OSAL_ErrorTrace("VIDDEC3_create failed ....! \n"); | ||
779 | eError = OMX_ErrorInsufficientResources; | ||
780 | pVidDecComp->bIPCRecoveryNeeded = OMX_TRUE; | ||
781 | goto EXIT; | ||
782 | } | ||
783 | pVidDecComp->nCodecRecreationRequired = 0; | ||
784 | pVidDecComp->nOutPortReconfigRequired = 0; | ||
785 | |||
786 | // Populate Dynamic Params and the Status structures | ||
787 | pVidDecComp->fpSet_DynamicParams(hComponent, pVidDecComp->pDecDynParams); | ||
788 | pVidDecComp->fpSet_Status(hComponent, pVidDecComp->pDecStatus); | ||
789 | //This is to handle Arbitrary stride requirement given by IL client. | ||
790 | if((OMX_U32)pOutputPortDef->format.video.nStride > | ||
791 | pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nWidth) { | ||
792 | pVidDecComp->pDecDynParams->displayWidth = | ||
793 | pOutputPortDef->format.video.nStride; | ||
794 | } | ||
795 | pDecDynamicParams = pVidDecComp->pDecDynParams; | ||
796 | pDecStatus = pVidDecComp->pDecStatus; | ||
797 | |||
798 | OMX_CHECK(((pVidDecComp->pDecDynParams != NULL) && (pVidDecComp->pDecStatus != NULL)), OMX_ErrorBadParameter); | ||
799 | status = VIDDEC3_control(pVidDecComp->pDecHandle, XDM_SETPARAMS, pVidDecComp->pDecDynParams, pVidDecComp->pDecStatus); | ||
800 | if( status != VIDDEC3_EOK ) { | ||
801 | OSAL_ErrorTrace("VIDDEC3_control XDM_SETPARAMS failed! \n"); | ||
802 | eError = OMX_ErrorInsufficientResources; | ||
803 | goto EXIT; | ||
804 | } | ||
805 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
806 | |||
807 | // Call the Decoder Control function | ||
808 | status = VIDDEC3_control(pVidDecComp->pDecHandle, XDM_GETBUFINFO, pVidDecComp->pDecDynParams, pVidDecComp->pDecStatus); | ||
809 | if( status != VIDDEC3_EOK ) { | ||
810 | OSAL_ErrorTrace("VIDDEC3_control XDM_GETBUFINFO failed! \n"); | ||
811 | eError = OMX_ErrorInsufficientResources; | ||
812 | goto EXIT; | ||
813 | } | ||
814 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
815 | } | ||
816 | } else if( pVidDecComp->sBase.tCurState == OMX_StateIdle && | ||
817 | pVidDecComp->sBase.tNewState == OMX_StateLoaded ) { | ||
818 | // Transitioning from Idle to Loaded | ||
819 | if( pVidDecComp->pDecHandle != NULL ) { | ||
820 | // Delete the Decoder Component Private Handle | ||
821 | pVidDecComp->nFrameCounter = 0; | ||
822 | if( pVidDecComp->bSupportSkipGreyOutputFrames ) { | ||
823 | pVidDecComp->bSyncFrameReady = OMX_FALSE; | ||
824 | } | ||
825 | |||
826 | pVidDecComp->nOutbufInUseFlag = 0; | ||
827 | VIDDEC3_delete(pVidDecComp->pDecHandle); | ||
828 | pVidDecComp->pDecHandle = NULL; | ||
829 | } | ||
830 | |||
831 | } else if(((pVidDecComp->sBase.tCurState == OMX_StateExecuting) && | ||
832 | (pVidDecComp->sBase.tNewState == OMX_StateIdle)) || | ||
833 | ((pVidDecComp->sBase.tCurState == OMX_StatePause) && | ||
834 | (pVidDecComp->sBase.tNewState == OMX_StateIdle))) { | ||
835 | OMXVidDec_HandleFLUSH_EOS(hComponent, NULL, NULL); | ||
836 | } | ||
837 | |||
838 | break; | ||
839 | |||
840 | case OMX_CommandPortDisable : | ||
841 | // In case of Port Disable Command | ||
842 | // Loaded state implies codec is deleted. so no need to delete again | ||
843 | if( pVidDecComp->sBase.tCurState != OMX_StateLoaded | ||
844 | && pVidDecComp->pDecHandle != NULL ) { | ||
845 | // Call Decoder Flush function | ||
846 | OMXVidDec_HandleFLUSH_EOS(hComponent, NULL, NULL); | ||
847 | } | ||
848 | break; | ||
849 | |||
850 | case OMX_CommandPortEnable : | ||
851 | if( nParam == OMX_VIDDEC_OUTPUT_PORT ) { | ||
852 | // Check the buffer cnt is greater than min required | ||
853 | // buffer count | ||
854 | pOutputPortDef = | ||
855 | &(pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef); | ||
856 | if( pOutputPortDef->nBufferCountActual < pOutputPortDef->nBufferCountMin ) { | ||
857 | OSAL_ErrorTrace("Number of actual buffers on o/p port less than the minmum required by componenet as set on o/p port defs"); | ||
858 | eError = OMX_ErrorUnsupportedSetting; | ||
859 | goto EXIT; | ||
860 | } | ||
861 | if( (OMX_U32)pOutputPortDef->format.video.nStride < | ||
862 | pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nWidth ) { | ||
863 | OSAL_ErrorTrace("Unsupported Stride set on o/p port defs"); | ||
864 | eError = OMX_ErrorUnsupportedSetting; | ||
865 | goto EXIT; | ||
866 | } | ||
867 | } | ||
868 | if( pVidDecComp->sBase.tCurState != OMX_StateLoaded ) { | ||
869 | if( pVidDecComp->nCodecRecreationRequired == 1 | ||
870 | && pVidDecComp->pDecHandle != NULL ) { | ||
871 | pVidDecComp->nCodecRecreationRequired = 0; | ||
872 | pVidDecComp->nFrameCounter = 0; | ||
873 | pVidDecComp->tScaleParams.xWidth = 0x10000; | ||
874 | pVidDecComp->tScaleParams.xHeight = 0x10000; | ||
875 | if( pVidDecComp->bSupportSkipGreyOutputFrames ) { | ||
876 | pVidDecComp->bSyncFrameReady = OMX_FALSE; | ||
877 | } | ||
878 | pVidDecComp->nOutbufInUseFlag = 0; | ||
879 | VIDDEC3_delete(pVidDecComp->pDecHandle); | ||
880 | pVidDecComp->pDecHandle = NULL; | ||
881 | |||
882 | pOutputPortDef = | ||
883 | &(pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef); | ||
884 | // Set the Static Params | ||
885 | pVidDecComp->fpSet_StaticParams(hComponent, pVidDecComp->pDecStaticParams); | ||
886 | if( pVidDecComp->bUsePortReconfigForPadding == OMX_TRUE | ||
887 | && pVidDecComp->pDecStatus->outputWidth != 0 | ||
888 | && pVidDecComp->pDecStatus->outputHeight != 0 ) { | ||
889 | nFrameWidth = pVidDecComp->pDecStatus->outputWidth; | ||
890 | nFrameHeight = pVidDecComp->pDecStatus->outputHeight; | ||
891 | } else { | ||
892 | nFrameWidth = pOutputPortDef->format.video.nFrameWidth; | ||
893 | nFrameHeight = pOutputPortDef->format.video.nFrameHeight; | ||
894 | } | ||
895 | if( nFrameWidth & 0x0F ) { | ||
896 | nFrameWidth = nFrameWidth + 16 - (nFrameWidth & 0x0F); | ||
897 | } | ||
898 | if( nFrameHeight & 0x1F ) { | ||
899 | nFrameHeight = nFrameHeight + 32 - (nFrameHeight & 0x1F); | ||
900 | } | ||
901 | nFrameWidthOrig = pOutputPortDef->format.video.nFrameWidth; | ||
902 | if( nFrameWidthOrig & 0x0F ) { | ||
903 | nFrameWidthOrig = nFrameWidthOrig + 16 - (nFrameWidthOrig & 0x0F); | ||
904 | } | ||
905 | pVidDecComp->pDecStaticParams->maxHeight = nFrameHeight; | ||
906 | pVidDecComp->pDecStaticParams->maxWidth = nFrameWidth; | ||
907 | |||
908 | /* Check whether the displayWidth already accounts for any | ||
909 | * difference between the current and new frame width and | ||
910 | * set maxWidth accordingly */ | ||
911 | if ( nFrameWidth != nFrameWidthOrig && | ||
912 | nFrameWidthOrig == (OMX_U32)pVidDecComp->pDecDynParams->displayWidth ) { | ||
913 | pVidDecComp->pDecStaticParams->maxWidth = nFrameWidthOrig; | ||
914 | } | ||
915 | |||
916 | // And Call the Codec Create | ||
917 | pVidDecComp->pDecHandle = VIDDEC3_create(pVidDecComp->ce, | ||
918 | pVidDecComp->cDecoderName, | ||
919 | (VIDDEC3_Params *) | ||
920 | pVidDecComp->pDecStaticParams); | ||
921 | if( pVidDecComp->pDecHandle == NULL ) { | ||
922 | OSAL_ErrorTrace("VIDDEC3_create failed ....! \n"); | ||
923 | eError = OMX_ErrorInsufficientResources; | ||
924 | pVidDecComp->bIPCRecoveryNeeded = OMX_TRUE; | ||
925 | goto EXIT; | ||
926 | } | ||
927 | |||
928 | // Populate Dynamic Params and the Status structures | ||
929 | pVidDecComp->fpSet_DynamicParams(hComponent, pVidDecComp->pDecDynParams); | ||
930 | pVidDecComp->fpSet_Status(hComponent, pVidDecComp->pDecStatus); | ||
931 | //This is to handle Arbitrary stride requirement given by IL client. | ||
932 | if((OMX_U32)pOutputPortDef->format.video.nStride != | ||
933 | pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nWidth) { | ||
934 | pVidDecComp->pDecDynParams->displayWidth = | ||
935 | pOutputPortDef->format.video.nStride; | ||
936 | } | ||
937 | pDecDynamicParams = pVidDecComp->pDecDynParams; | ||
938 | pDecStatus = pVidDecComp->pDecStatus; | ||
939 | |||
940 | // Call the Decoder Control function | ||
941 | OMX_CHECK(((pVidDecComp->pDecDynParams != NULL) && (pVidDecComp->pDecStatus != NULL)), OMX_ErrorBadParameter); | ||
942 | status = VIDDEC3_control(pVidDecComp->pDecHandle, XDM_SETPARAMS, pVidDecComp->pDecDynParams, pVidDecComp->pDecStatus); | ||
943 | if( status != VIDDEC3_EOK ) { | ||
944 | OSAL_ErrorTrace("VIDDEC3_control XDM_SETPARAMS failed! \n"); | ||
945 | eError = OMX_ErrorInsufficientResources; | ||
946 | goto EXIT; | ||
947 | } | ||
948 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
949 | } | ||
950 | pVidDecComp->nOutPortReconfigRequired = 0; | ||
951 | } | ||
952 | |||
953 | break; | ||
954 | |||
955 | case OMX_CommandFlush : | ||
956 | { | ||
957 | // In case of Flush Command | ||
958 | // In case all ports have to be flushed or the output port | ||
959 | // has to be flushed | ||
960 | if( nParam == OMX_ALL || nParam == OMX_VIDDEC_OUTPUT_PORT ) { | ||
961 | // Only then flush the port | ||
962 | OMXVidDec_HandleFLUSH_EOS(hComponent, NULL, NULL); | ||
963 | } | ||
964 | } | ||
965 | break; | ||
966 | |||
967 | case OMX_CommandMarkBuffer : | ||
968 | ReturnCmdCompletionCallBack = 0; | ||
969 | break; | ||
970 | |||
971 | default: | ||
972 | OSAL_ErrorTrace("Invalid command"); | ||
973 | } | ||
974 | |||
975 | if( ReturnCmdCompletionCallBack == 1 ) { | ||
976 | eError = pVidDecComp->sBase.fpReturnEventNotify(hComponent, | ||
977 | OMX_EventCmdComplete, Cmd, nParam, NULL); | ||
978 | } | ||
979 | |||
980 | EXIT: | ||
981 | return (eError); | ||
982 | |||
983 | } | ||
984 | |||
985 | /* | ||
986 | * Video Decoder DataNotify | ||
987 | */ | ||
988 | OMX_ERRORTYPE OMXVidDec_DataNotify(OMX_HANDLETYPE hComponent) | ||
989 | { | ||
990 | OMX_ERRORTYPE eError = OMX_ErrorNone, eRMError = OMX_ErrorNone; | ||
991 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
992 | OMX_BUFFERHEADERTYPE sInBufHeader; | ||
993 | OMXVidDecComp *pVidDecComp = NULL; | ||
994 | OMX_BUFFERHEADERTYPE *pInBufHeader = NULL; | ||
995 | OMX_BUFFERHEADERTYPE *pOutBufHeader = NULL; | ||
996 | OMX_BUFFERHEADERTYPE *pDupBufHeader = NULL; | ||
997 | OMX_BUFFERHEADERTYPE *pFreeBufHeader = NULL; | ||
998 | OMX_U32 nInMsgCount = 0; | ||
999 | OMX_U32 nOutMsgCount = 0; | ||
1000 | OMX_U32 Buffer_locked = 1; | ||
1001 | OMX_U32 ii = 0, i, jj = 0; | ||
1002 | OMX_U32 nStride = 0; | ||
1003 | OMX_PARAM_PORTDEFINITIONTYPE *pOutputPortDef = NULL; | ||
1004 | OMX_PARAM_PORTDEFINITIONTYPE *pInputPortDef = NULL; | ||
1005 | OMX_BOOL nIsDioReady = OMX_FALSE; | ||
1006 | XDAS_Int32 status; | ||
1007 | XDM2_BufDesc *pInBufDescPtr = NULL; | ||
1008 | XDM2_BufDesc *pOutBufDescPtr = NULL; | ||
1009 | OMX_CONFIG_RECTTYPE out2DAllocParam; | ||
1010 | IVIDDEC3_OutArgs *pDecOutArgs = NULL; | ||
1011 | IVIDDEC3_Status *pDecStatus = NULL; | ||
1012 | XDM_Rect activeFrameRegion[2]; | ||
1013 | OMX_U32 nNewInBufferRequired = 0; | ||
1014 | OMX_BOOL bSendPortReconfigForScale = OMX_FALSE; | ||
1015 | OMX_U32 nScale, nScaleRem, nScaleQ16Low, nScaleWidth, nScaleHeight; | ||
1016 | OMX_U64 nScaleQ16 = 0; | ||
1017 | uint32_t nActualSize; | ||
1018 | OMX_BOOL went_thru_loop = OMX_FALSE; | ||
1019 | OMX_BOOL duped_IPbuffer = OMX_TRUE; | ||
1020 | IMG_native_handle_t* grallocHandle; | ||
1021 | OMX_U32 nLockedCount = 0; | ||
1022 | |||
1023 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
1024 | |||
1025 | //! Initialize pointers | ||
1026 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
1027 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
1028 | OMX_CHECK(pVidDecComp != NULL, OMX_ErrorBadParameter); | ||
1029 | |||
1030 | pOutputPortDef = &(pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef); | ||
1031 | pInputPortDef = &(pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef); | ||
1032 | out2DAllocParam = pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT]; | ||
1033 | |||
1034 | /*! Ensure that the stride on output portdef structure is more than | ||
1035 | the padded width. This is needed in the case where application | ||
1036 | sets the Stride less than padded width */ | ||
1037 | if( (OMX_U32)pOutputPortDef->format.video.nStride >= | ||
1038 | pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nWidth ) { | ||
1039 | nStride = pOutputPortDef->format.video.nStride; | ||
1040 | } else { | ||
1041 | nStride = pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nWidth; | ||
1042 | } | ||
1043 | if((pVidDecComp->sBase.tCurState != OMX_StateExecuting) || | ||
1044 | (pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.bEnabled == OMX_FALSE) || | ||
1045 | (pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef.bEnabled == OMX_FALSE)) { | ||
1046 | goto EXIT; | ||
1047 | } | ||
1048 | nIsDioReady = OMXBase_IsDioReady(hComponent, OMX_VIDDEC_OUTPUT_PORT); | ||
1049 | if( nIsDioReady == OMX_FALSE ) { | ||
1050 | goto EXIT; | ||
1051 | } | ||
1052 | //! Get the number of input and output buffers | ||
1053 | pVidDecComp->sBase.pPvtData->fpDioGetCount(hComponent, | ||
1054 | OMX_VIDDEC_INPUT_PORT, | ||
1055 | (OMX_PTR)&nInMsgCount); | ||
1056 | pVidDecComp->sBase.pPvtData->fpDioGetCount(hComponent, | ||
1057 | OMX_VIDDEC_OUTPUT_PORT, | ||
1058 | (OMX_PTR)&nOutMsgCount); | ||
1059 | |||
1060 | // Loop until input or output buffers are exhausted | ||
1061 | while((nInMsgCount > 0) && (nOutMsgCount > 0)) { | ||
1062 | // Only if Cur-State is Execute proceed. | ||
1063 | if((pVidDecComp->sBase.tCurState != OMX_StateExecuting) || | ||
1064 | (pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.bEnabled == OMX_FALSE) || | ||
1065 | (pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef.bEnabled == OMX_FALSE)) { | ||
1066 | break; | ||
1067 | } | ||
1068 | if( OMXBase_IsCmdPending(hComponent) && pVidDecComp->nOutbufInUseFlag == 0 ) { | ||
1069 | OSAL_ErrorTrace("Exiting dataNotify because command is pending"); | ||
1070 | goto EXIT; | ||
1071 | } | ||
1072 | if( pVidDecComp->nOutPortReconfigRequired == 1 ) { | ||
1073 | OSAL_ErrorTrace("Port disable/reconfiguration needed"); | ||
1074 | goto EXIT; | ||
1075 | } | ||
1076 | if( pVidDecComp->nFatalErrorGiven == 1 ) { | ||
1077 | OSAL_ErrorTrace("Fatal error given to IL client"); | ||
1078 | goto EXIT; | ||
1079 | } | ||
1080 | // Buffer is locked by the codec by default. | ||
1081 | // It can be freed only if mentioned in freeBufId[] field. | ||
1082 | Buffer_locked = 1; | ||
1083 | ii=0; | ||
1084 | went_thru_loop = OMX_TRUE; | ||
1085 | if( nNewInBufferRequired == 0 && pVidDecComp->sCodecConfig.sBuffer == NULL ) { | ||
1086 | duped_IPbuffer = OMX_FALSE; | ||
1087 | //! Get Input and Output Buffer header from Queue | ||
1088 | eError = pVidDecComp->sBase.pPvtData->fpDioDequeue(hComponent, OMX_VIDDEC_INPUT_PORT, | ||
1089 | (OMX_PTR*)(&pInBufHeader)); | ||
1090 | if( eError == OMX_TI_WarningAttributePending ) { | ||
1091 | pVidDecComp->sCodecConfig.sBuffer = P2H(memplugin_alloc(2, 1, MEM_CARVEOUT, 0, 0)); | ||
1092 | OMX_CHECK(pVidDecComp->sCodecConfig.sBuffer != NULL, OMX_ErrorInsufficientResources); | ||
1093 | eError = pVidDecComp->sBase.pPvtData->fpDioControl(hComponent, OMX_VIDDEC_INPUT_PORT, | ||
1094 | OMX_DIO_CtrlCmd_GetCtrlAttribute, (OMX_PTR)&(pVidDecComp->sCodecConfig)); | ||
1095 | if( eError == OMX_TI_WarningInsufficientAttributeSize ) { | ||
1096 | /*Allocate the data pointer again with correct size*/ | ||
1097 | uint32_t new_size = pVidDecComp->sCodecConfig.sBuffer->size; | ||
1098 | memplugin_free((void*)H2P(pVidDecComp->sCodecConfig.sBuffer)); | ||
1099 | pVidDecComp->sCodecConfig.sBuffer = P2H(memplugin_alloc(new_size, 1, MEM_CARVEOUT, 0, 0)); | ||
1100 | OMX_CHECK(pVidDecComp->sCodecConfig.sBuffer != NULL, OMX_ErrorInsufficientResources); | ||
1101 | eError = pVidDecComp->sBase.pPvtData->fpDioControl(hComponent, OMX_VIDDEC_INPUT_PORT, | ||
1102 | OMX_DIO_CtrlCmd_GetCtrlAttribute, (OMX_PTR)&(pVidDecComp->sCodecConfig)); | ||
1103 | if( eError != OMX_ErrorNone ) { | ||
1104 | OSAL_ErrorTrace("Codec config test failed because DIO Control returned buffer"); | ||
1105 | goto EXIT; | ||
1106 | } | ||
1107 | } | ||
1108 | pVidDecComp->pDecDynParams->decodeHeader = pVidDecComp->nDecoderMode; | ||
1109 | pInBufHeader = NULL; | ||
1110 | // Call the Decoder Control function | ||
1111 | status = VIDDEC3_control(pVidDecComp->pDecHandle, XDM_SETPARAMS, pVidDecComp->pDecDynParams, pVidDecComp->pDecStatus); | ||
1112 | if( status != VIDDEC3_EOK ) { | ||
1113 | OSAL_ErrorTrace("VIDDEC3_control XDM_SETPARAMS failed ....! \n"); | ||
1114 | eError = OMX_ErrorInsufficientResources; | ||
1115 | goto EXIT; | ||
1116 | } | ||
1117 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1118 | } else if( pVidDecComp->nOutbufInUseFlag == 0 ) { | ||
1119 | if( pVidDecComp->pDecDynParams->decodeHeader != XDM_DECODE_AU ) { | ||
1120 | pVidDecComp->pDecDynParams->decodeHeader = XDM_DECODE_AU; | ||
1121 | status = VIDDEC3_control(pVidDecComp->pDecHandle, XDM_SETPARAMS, pVidDecComp->pDecDynParams, pVidDecComp->pDecStatus); | ||
1122 | if( status != VIDDEC3_EOK ) { | ||
1123 | OSAL_ErrorTrace("VIDDEC3_control XDM_SETPARAMS failed ....! \n"); | ||
1124 | eError = OMX_ErrorInsufficientResources; | ||
1125 | goto EXIT; | ||
1126 | } | ||
1127 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1128 | } | ||
1129 | if( pInBufHeader ) { | ||
1130 | if(!(pInBufHeader->nFlags & OMX_BUFFERFLAG_EOS) && (pInBufHeader->nFilledLen - pInBufHeader->nOffset == 0)) { | ||
1131 | // Send Input buffer back to base | ||
1132 | pVidDecComp->sBase.pPvtData->fpDioSend(hComponent, | ||
1133 | OMX_VIDDEC_INPUT_PORT, | ||
1134 | pInBufHeader); | ||
1135 | |||
1136 | //! Get the number of input and output buffers | ||
1137 | pVidDecComp->sBase.pPvtData->fpDioGetCount(hComponent, | ||
1138 | OMX_VIDDEC_INPUT_PORT, | ||
1139 | (OMX_PTR)&nInMsgCount); | ||
1140 | if( nInMsgCount ) { | ||
1141 | continue; | ||
1142 | } else { | ||
1143 | break; | ||
1144 | } | ||
1145 | } | ||
1146 | } | ||
1147 | nLockedCount = 0; | ||
1148 | while (nLockedCount < nOutMsgCount) { | ||
1149 | eError = pVidDecComp->sBase.pPvtData->fpDioDequeue(hComponent, OMX_VIDDEC_OUTPUT_PORT, | ||
1150 | (OMX_PTR*)(&pOutBufHeader)); | ||
1151 | if (pOutBufHeader) { | ||
1152 | // check locked flag | ||
1153 | if (((OMXBase_BufHdrPvtData *)(pOutBufHeader->pPlatformPrivate))->bIsLocked) { | ||
1154 | nLockedCount++; | ||
1155 | // Send the buffer to the back of the queue | ||
1156 | pVidDecComp->sBase.pPvtData->fpDioQueue(hComponent, | ||
1157 | OMX_VIDDEC_OUTPUT_PORT, pOutBufHeader); | ||
1158 | pOutBufHeader = NULL; | ||
1159 | // Get the number of output buffers | ||
1160 | pVidDecComp->sBase.pPvtData->fpDioGetCount(hComponent, | ||
1161 | OMX_VIDDEC_OUTPUT_PORT, | ||
1162 | (OMX_PTR)&nOutMsgCount); | ||
1163 | continue; | ||
1164 | } | ||
1165 | } | ||
1166 | // if we get here we have our buffer, or it is an error | ||
1167 | break; | ||
1168 | } | ||
1169 | if (pOutBufHeader == NULL) { | ||
1170 | // Cancel input buffer and continue | ||
1171 | pVidDecComp->sBase.pPvtData->fpDioCancel(hComponent, | ||
1172 | OMX_VIDDEC_INPUT_PORT, | ||
1173 | pInBufHeader); | ||
1174 | |||
1175 | goto EXIT; | ||
1176 | } | ||
1177 | } | ||
1178 | } | ||
1179 | pOutBufDescPtr = pVidDecComp->tOutBufDesc; | ||
1180 | pInBufDescPtr = pVidDecComp->tInBufDesc; | ||
1181 | if( pVidDecComp->sCodecConfig.sBuffer != NULL && | ||
1182 | (OMX_U32)pVidDecComp->pDecDynParams->decodeHeader != pVidDecComp->nDecoderMode ) { | ||
1183 | pVidDecComp->pDecDynParams->decodeHeader = pVidDecComp->nDecoderMode; | ||
1184 | // Call the Decoder Control function | ||
1185 | status = VIDDEC3_control(pVidDecComp->pDecHandle, XDM_SETPARAMS, | ||
1186 | pVidDecComp->pDecDynParams, pVidDecComp->pDecStatus); | ||
1187 | if( status != VIDDEC3_EOK ) { | ||
1188 | OSAL_ErrorTrace("VIDDEC3_control XDM_SETPARAMS failed ....! \n"); | ||
1189 | eError = OMX_ErrorInsufficientResources; | ||
1190 | goto EXIT; | ||
1191 | } | ||
1192 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1193 | } | ||
1194 | pInBufDescPtr->numBufs = 1; | ||
1195 | if( pInBufHeader != NULL && pVidDecComp->nOutbufInUseFlag == 1 ) { | ||
1196 | pVidDecComp->pDecInArgs->numBytes = pInBufHeader->nFilledLen - pInBufHeader->nOffset; | ||
1197 | //Sending the same input ID for second field | ||
1198 | pVidDecComp->pDecInArgs->inputID = (OMX_S32) pOutBufHeader; | ||
1199 | if(((IVIDDEC3_Params *)(pVidDecComp->pDecStaticParams))->inputDataMode == IVIDEO_ENTIREFRAME ) { | ||
1200 | (((OMXBase_BufHdrPvtData*)pInBufHeader->pPlatformPrivate)->sMemHdr[0]).offset = pInBufHeader->nOffset; | ||
1201 | pInBufDescPtr->descs[0].buf = (XDAS_Int8 *)&(((OMXBase_BufHdrPvtData*)pInBufHeader->pPlatformPrivate)->sMemHdr[0]); | ||
1202 | pInBufDescPtr->descs[0].memType = XDM_MEMTYPE_TILEDPAGE; | ||
1203 | pInBufDescPtr->descs[0].bufSize.bytes = pInBufHeader->nFilledLen - pInBufHeader->nOffset; | ||
1204 | pInBufDescPtr->descs[0].bufSize.tileMem.height = 1; | ||
1205 | } | ||
1206 | } else if( (OMX_U32)pVidDecComp->pDecDynParams->decodeHeader == pVidDecComp->nDecoderMode ) { | ||
1207 | pVidDecComp->pDecInArgs->numBytes = pVidDecComp->sCodecConfig.sBuffer->size; | ||
1208 | pVidDecComp->pDecInArgs->inputID = 1; | ||
1209 | pVidDecComp->sCodecConfig.sBuffer->offset = sizeof(MemHeader); | ||
1210 | pInBufDescPtr->descs[0].buf = (XDAS_Int8*)(pVidDecComp->sCodecConfig.sBuffer); | ||
1211 | pInBufDescPtr->descs[0].memType = XDM_MEMTYPE_TILEDPAGE; | ||
1212 | pInBufDescPtr->descs[0].bufSize.bytes = pVidDecComp->sCodecConfig.sBuffer->size; | ||
1213 | pInBufDescPtr->descs[0].bufSize.tileMem.height = 1; | ||
1214 | pOutBufDescPtr->numBufs = 0; | ||
1215 | } else if( pInBufHeader != NULL && pVidDecComp->pDecDynParams->decodeHeader == XDM_DECODE_AU ) { | ||
1216 | // In case EOS and Number of Input bytes=0. Flush Decoder and exit | ||
1217 | if( pInBufHeader->nFlags & OMX_BUFFERFLAG_EOS ) { | ||
1218 | if( pInBufHeader->nFilledLen == 0 ) { | ||
1219 | pOutBufHeader->nFilledLen = 0; | ||
1220 | eError = OMXVidDec_HandleFLUSH_EOS(hComponent, pOutBufHeader, pInBufHeader); | ||
1221 | goto EXIT; | ||
1222 | } else { | ||
1223 | pOutBufHeader->nFlags |= OMX_BUFFERFLAG_EOS; | ||
1224 | } | ||
1225 | } | ||
1226 | if( pVidDecComp->bUsePortReconfigForPadding == OMX_TRUE ) { | ||
1227 | if( pOutputPortDef->format.video.nFrameWidth < out2DAllocParam.nWidth | ||
1228 | || pOutputPortDef->format.video.nFrameHeight < out2DAllocParam.nHeight ) { | ||
1229 | |||
1230 | if (pVidDecComp->nFrameCounter) { | ||
1231 | pVidDecComp->sBase.pPvtData->fpDioCancel(hComponent, | ||
1232 | OMX_VIDDEC_INPUT_PORT, pInBufHeader); | ||
1233 | pVidDecComp->sBase.pPvtData->fpDioCancel(hComponent, | ||
1234 | OMX_VIDDEC_OUTPUT_PORT, pOutBufHeader); | ||
1235 | |||
1236 | OMXVidDec_HandleFirstFrame(hComponent, NULL); | ||
1237 | } else { | ||
1238 | pOutputPortDef->format.video.nFrameWidth = out2DAllocParam.nWidth; | ||
1239 | pOutputPortDef->format.video.nFrameHeight = out2DAllocParam.nHeight; | ||
1240 | pOutputPortDef->format.video.nStride = pOutputPortDef->format.video.nFrameWidth; | ||
1241 | pOutputPortDef->nBufferSize = pOutputPortDef->format.video.nStride * | ||
1242 | ((pOutputPortDef->format.video.nFrameHeight * 3) >> 1); | ||
1243 | pInputPortDef->format.video.nFrameWidth = out2DAllocParam.nWidth; | ||
1244 | pInputPortDef->format.video.nFrameHeight = out2DAllocParam.nHeight; | ||
1245 | |||
1246 | pVidDecComp->sBase.pPvtData->fpDioCancel(hComponent, | ||
1247 | OMX_VIDDEC_INPUT_PORT, pInBufHeader); | ||
1248 | pVidDecComp->sBase.pPvtData->fpDioCancel(hComponent, | ||
1249 | OMX_VIDDEC_OUTPUT_PORT, pOutBufHeader); | ||
1250 | |||
1251 | /*! Notify to Client change in output port settings */ | ||
1252 | eError = pVidDecComp->sBase.fpReturnEventNotify(hComponent, | ||
1253 | OMX_EventPortSettingsChanged, OMX_VIDDEC_OUTPUT_PORT, 0, NULL); | ||
1254 | pVidDecComp->nOutPortReconfigRequired = 1; | ||
1255 | } | ||
1256 | goto EXIT; | ||
1257 | } | ||
1258 | } | ||
1259 | /*! Populate xDM structure */ | ||
1260 | pVidDecComp->pDecInArgs->numBytes = pInBufHeader->nFilledLen - pInBufHeader->nOffset; | ||
1261 | pVidDecComp->pDecInArgs->inputID = (OMX_S32) pOutBufHeader; | ||
1262 | if(((IVIDDEC3_Params *)(pVidDecComp->pDecStaticParams))->inputDataMode == IVIDEO_ENTIREFRAME ) { | ||
1263 | /* Fill Input Buffer Descriptor */ | ||
1264 | (((OMXBase_BufHdrPvtData*)pInBufHeader->pPlatformPrivate)->sMemHdr[0]).offset = pInBufHeader->nOffset; | ||
1265 | pInBufDescPtr->descs[0].buf = (XDAS_Int8 *)&(((OMXBase_BufHdrPvtData*)pInBufHeader->pPlatformPrivate)->sMemHdr[0]); | ||
1266 | pInBufDescPtr->descs[0].memType = XDM_MEMTYPE_TILEDPAGE; | ||
1267 | pInBufDescPtr->descs[0].bufSize.bytes = pInBufHeader->nFilledLen - pInBufHeader->nOffset; | ||
1268 | pInBufDescPtr->descs[0].bufSize.tileMem.height = 1; | ||
1269 | } | ||
1270 | /* Initialize Number of Buffers for input and output */ | ||
1271 | pInBufDescPtr->numBufs = 1; | ||
1272 | pOutBufDescPtr->numBufs = 2; | ||
1273 | |||
1274 | /* Fill Output Buffer Descriptor */ | ||
1275 | /* if (pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sProps.eBufMemoryType == MEM_GRALLOC) { | ||
1276 | pOutBufDescPtr->descs[0].bufSize.tileMem.width = pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nWidth; | ||
1277 | pOutBufDescPtr->descs[0].bufSize.tileMem.height = pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nHeight; | ||
1278 | (((OMXBase_BufHdrPvtData*)pOutBufHeader->pPlatformPrivate)->sMemHdr[0]).offset = 0; | ||
1279 | pOutBufDescPtr->descs[0].buf = (XDAS_Int8 *)&(((OMXBase_BufHdrPvtData*)pOutBufHeader->pPlatformPrivate)->sMemHdr[0]); | ||
1280 | pOutBufDescPtr->descs[0].memType = XDM_MEMTYPE_TILED8; | ||
1281 | (((OMXBase_BufHdrPvtData*)pOutBufHeader->pPlatformPrivate)->sMemHdr[1]).offset = 0; | ||
1282 | pOutBufDescPtr->descs[1].bufSize.tileMem.width =pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nWidth; | ||
1283 | pOutBufDescPtr->descs[1].bufSize.tileMem.height = pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nHeight / 2; | ||
1284 | pOutBufDescPtr->descs[1].buf = (XDAS_Int8 *)&(((OMXBase_BufHdrPvtData*)pOutBufHeader->pPlatformPrivate)->sMemHdr[1]); | ||
1285 | pOutBufDescPtr->descs[1].memType = XDM_MEMTYPE_TILED16; | ||
1286 | } else*/ { | ||
1287 | pOutBufDescPtr->descs[0].bufSize.bytes = pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nWidth * | ||
1288 | pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nHeight; | ||
1289 | pOutBufDescPtr->descs[0].bufSize.tileMem.height = 1; | ||
1290 | pOutBufDescPtr->descs[0].buf = (XDAS_Int8 *)&(((OMXBase_BufHdrPvtData*)pOutBufHeader->pPlatformPrivate)->sMemHdr[0]); | ||
1291 | pOutBufDescPtr->descs[0].memType = XDM_MEMTYPE_TILEDPAGE; | ||
1292 | |||
1293 | memcpy(&(((OMXBase_BufHdrPvtData*)pOutBufHeader->pPlatformPrivate)->sMemHdr[1]), &(((OMXBase_BufHdrPvtData*)pOutBufHeader->pPlatformPrivate)->sMemHdr[0]), sizeof(MemHeader)); | ||
1294 | |||
1295 | (((OMXBase_BufHdrPvtData*)pOutBufHeader->pPlatformPrivate)->sMemHdr[1]).offset = pOutBufDescPtr->descs[0].bufSize.bytes; | ||
1296 | |||
1297 | pOutBufDescPtr->descs[1].bufSize.bytes = pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nWidth * | ||
1298 | pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nHeight/2; | ||
1299 | pOutBufDescPtr->descs[1].bufSize.tileMem.height = 1; | ||
1300 | pOutBufDescPtr->descs[1].buf = (XDAS_Int8 *)&(((OMXBase_BufHdrPvtData*)pOutBufHeader->pPlatformPrivate)->sMemHdr[1]); | ||
1301 | pOutBufDescPtr->descs[1].memType = XDM_MEMTYPE_TILEDPAGE; | ||
1302 | nStride = pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nWidth; | ||
1303 | } | ||
1304 | |||
1305 | if (pVidDecComp->tVideoParams[OMX_VIDDEC_INPUT_PORT].eCompressionFormat == OMX_VIDEO_CodingMPEG2) { | ||
1306 | if (pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef.format.video.bFlagErrorConcealment) { | ||
1307 | /* provide metaBuffer to codec because it's MPEG2 with Error Concealment */ | ||
1308 | pOutBufDescPtr->numBufs = 3; | ||
1309 | pVidDecComp->pmetaBuffer->offset = sizeof(MemHeader); | ||
1310 | pOutBufDescPtr->descs[2].buf = (XDAS_Int8*)(pVidDecComp->pmetaBuffer); | ||
1311 | pOutBufDescPtr->descs[2].memType = XDM_MEMTYPE_RAW; | ||
1312 | pOutBufDescPtr->descs[2].bufSize.bytes = pVidDecComp->pmetaBuffer->size; | ||
1313 | pOutBufDescPtr->descs[2].bufSize.tileMem.height = 1; | ||
1314 | } | ||
1315 | } | ||
1316 | |||
1317 | pOutBufHeader->nTimeStamp = pInBufHeader->nTimeStamp; | ||
1318 | if( pVidDecComp->bSupportDecodeOrderTimeStamp == OMX_TRUE && pVidDecComp->bInputBufferCancelled == 0 ) { | ||
1319 | OSAL_WriteToPipe(pVidDecComp->pTimeStampStoragePipe, &(pInBufHeader->nTimeStamp), | ||
1320 | sizeof(OMX_TICKS), OSAL_NO_SUSPEND); | ||
1321 | } | ||
1322 | } | ||
1323 | /*Copy OMX_BUFFERFLAG_DECODEONLY from input buffer header to output buffer header*/ | ||
1324 | if (pOutBufHeader && pInBufHeader) { | ||
1325 | pOutBufHeader->nFlags |= (pInBufHeader->nFlags & OMX_BUFFERFLAG_DECODEONLY); | ||
1326 | ((OMXBase_BufHdrPvtData *)(pInBufHeader->pPlatformPrivate))->bufSt = OWNED_BY_CODEC; | ||
1327 | ((OMXBase_BufHdrPvtData *)(pOutBufHeader->pPlatformPrivate))->bufSt = OWNED_BY_CODEC; | ||
1328 | } | ||
1329 | |||
1330 | if (pOutBufHeader) { | ||
1331 | grallocHandle = (IMG_native_handle_t*)(pOutBufHeader->pBuffer); | ||
1332 | pVidDecComp->grallocModule->lock((gralloc_module_t const *) pVidDecComp->grallocModule, | ||
1333 | (buffer_handle_t)grallocHandle, GRALLOC_USAGE_HW_RENDER, | ||
1334 | 0,0,pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.format.video.nFrameWidth, | ||
1335 | pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.format.video.nFrameHeight,NULL); | ||
1336 | ((OMXBase_BufHdrPvtData *)(pOutBufHeader->pPlatformPrivate))->bIsLocked = OMX_TRUE; | ||
1337 | } | ||
1338 | |||
1339 | status = VIDDEC3_process(pVidDecComp->pDecHandle, pInBufDescPtr, pOutBufDescPtr, | ||
1340 | (VIDDEC3_InArgs *)pVidDecComp->pDecInArgs, (VIDDEC3_OutArgs *)pVidDecComp->pDecOutArgs); | ||
1341 | |||
1342 | pDecOutArgs = pVidDecComp->pDecOutArgs; | ||
1343 | |||
1344 | /*! In case this is an IPC failure */ | ||
1345 | if(status == DCE_EIPC_CALL_FAIL) { | ||
1346 | ALOGE("\n Remote Core Communication Failure... \n"); | ||
1347 | eError = OMX_ErrorHardware; | ||
1348 | pVidDecComp->bIPCRecoveryNeeded = OMX_TRUE; | ||
1349 | goto EXIT; | ||
1350 | } | ||
1351 | /*! In case Process returns error */ | ||
1352 | if(status == XDM_EFAIL ){ | ||
1353 | ALOGE("\n Process function returned an Error... \n"); | ||
1354 | ALOGE("Codec Extended - 0x%x", (OMX_U32)pVidDecComp->pDecOutArgs->extendedError); | ||
1355 | ALOGE("Input Buffer Size provided to codec is : %d", (int)pInBufDescPtr->descs[0].bufSize.bytes); | ||
1356 | ALOGE("Frame count is : %d", pVidDecComp->nFrameCounter + 1); | ||
1357 | ALOGE("Bytes consumed - %d", (int)pVidDecComp->pDecOutArgs->bytesConsumed); | ||
1358 | |||
1359 | if( !(pVidDecComp->bInputBufferCancelled == 1 && pVidDecComp->pDecOutArgs->extendedError & 0x8000)) { | ||
1360 | /*! Call function to handle Codec Error */ | ||
1361 | eError = OMXVidDec_HandleCodecProcError(hComponent, &(pInBufHeader), &(pOutBufHeader)); | ||
1362 | } | ||
1363 | if( eError != OMX_ErrorNone ) { | ||
1364 | goto EXIT; | ||
1365 | } | ||
1366 | if( pVidDecComp->nOutPortReconfigRequired == 1 ) { | ||
1367 | goto EXIT; | ||
1368 | } | ||
1369 | } | ||
1370 | if( (OMX_U32)pVidDecComp->pDecDynParams->decodeHeader == pVidDecComp->nDecoderMode ) { | ||
1371 | eError = OMXVidDec_HandleFirstFrame(hComponent, NULL); | ||
1372 | //we have to loop once again if we duplicated any input buffer | ||
1373 | if(duped_IPbuffer && nInMsgCount) { | ||
1374 | if( pVidDecComp && pVidDecComp->sCodecConfig.sBuffer && pVidDecComp->nOutPortReconfigRequired == 0 && went_thru_loop) { | ||
1375 | memplugin_free((void*)H2P(pVidDecComp->sCodecConfig.sBuffer)); | ||
1376 | pVidDecComp->sCodecConfig.sBuffer = NULL; | ||
1377 | } | ||
1378 | continue; | ||
1379 | } | ||
1380 | goto EXIT; | ||
1381 | } | ||
1382 | // Increment the FrameCounter value | ||
1383 | pVidDecComp->nFrameCounter++; | ||
1384 | if( pDecOutArgs->outBufsInUseFlag && pVidDecComp->nOutbufInUseFlag == 1 ) { | ||
1385 | pVidDecComp->nFrameCounter--; | ||
1386 | } | ||
1387 | if( pDecOutArgs->outBufsInUseFlag ) { | ||
1388 | pVidDecComp->nOutbufInUseFlag = 1; | ||
1389 | /* Check for any output buffer which is freed by codec*/ | ||
1390 | ii = 0; | ||
1391 | while( pDecOutArgs->freeBufID[ii] ) { | ||
1392 | if( pDecOutArgs->outputID[0] == 0 && pDecOutArgs->freeBufID[ii] == pVidDecComp->pDecInArgs->inputID ) { | ||
1393 | pVidDecComp->nOutbufInUseFlag = 0; | ||
1394 | pVidDecComp->nFrameCounter--; | ||
1395 | } | ||
1396 | pFreeBufHeader = (OMX_BUFFERHEADERTYPE *) pDecOutArgs->freeBufID[ii]; | ||
1397 | ((OMXBase_BufHdrPvtData *)(pFreeBufHeader->pPlatformPrivate))->bIsLocked = OMX_FALSE; | ||
1398 | grallocHandle = (IMG_native_handle_t*)(pFreeBufHeader->pBuffer); | ||
1399 | pVidDecComp->grallocModule->unlock((gralloc_module_t const *) pVidDecComp->grallocModule, (buffer_handle_t)grallocHandle); | ||
1400 | |||
1401 | /* Send the Freed buffer back to base component */ | ||
1402 | pVidDecComp->sBase.pPvtData->fpDioCancel(hComponent, | ||
1403 | OMX_VIDDEC_OUTPUT_PORT, pFreeBufHeader); | ||
1404 | ii++; | ||
1405 | } | ||
1406 | |||
1407 | if(((IVIDDEC3_Params *)(pVidDecComp->pDecStaticParams))->inputDataMode == IVIDEO_ENTIREFRAME ) { | ||
1408 | ii = 0; | ||
1409 | if( pInBufHeader != NULL ) { | ||
1410 | if((pInBufHeader->nFilledLen - pInBufHeader->nOffset) != (OMX_U32)pDecOutArgs->bytesConsumed ) { | ||
1411 | nNewInBufferRequired = 1; | ||
1412 | pInBufHeader->nOffset = pInBufHeader->nOffset + pDecOutArgs->bytesConsumed; | ||
1413 | continue; | ||
1414 | } | ||
1415 | nNewInBufferRequired = 0; | ||
1416 | pInBufHeader->nOffset = pInBufHeader->nOffset + pDecOutArgs->bytesConsumed; | ||
1417 | if( !(pInBufHeader->nFlags & OMX_BUFFERFLAG_EOS)) { | ||
1418 | // Send Input buffer back to base | ||
1419 | pVidDecComp->sBase.pPvtData->fpDioSend(hComponent, | ||
1420 | OMX_VIDDEC_INPUT_PORT, pInBufHeader); | ||
1421 | } else if( pInBufHeader->nFlags & OMX_BUFFERFLAG_EOS ) { | ||
1422 | OMXVidDec_HandleFLUSH_EOS(hComponent, NULL, pInBufHeader); | ||
1423 | if( eError != OMX_ErrorNone ) { | ||
1424 | goto EXIT; | ||
1425 | } | ||
1426 | } | ||
1427 | } | ||
1428 | pVidDecComp->sBase.pPvtData->fpDioGetCount(hComponent, | ||
1429 | OMX_VIDDEC_INPUT_PORT, (OMX_PTR)&nInMsgCount); | ||
1430 | if( nInMsgCount > 0 ) { | ||
1431 | continue; | ||
1432 | } else { | ||
1433 | break; | ||
1434 | } | ||
1435 | } | ||
1436 | } | ||
1437 | |||
1438 | // Check for the width/height after first frame | ||
1439 | if((pVidDecComp->nFrameCounter == 1) || (pVidDecComp->nOutbufInUseFlag == 1 && pVidDecComp->nFrameCounter == 2)) { | ||
1440 | eError = OMXVidDec_HandleFirstFrame(hComponent, &(pInBufHeader)); | ||
1441 | if( eError != OMX_ErrorNone ) { | ||
1442 | goto EXIT; | ||
1443 | } | ||
1444 | if( pVidDecComp->nOutPortReconfigRequired == 1 | ||
1445 | && pVidDecComp->pDecStaticParams->displayDelay | ||
1446 | != IVIDDEC3_DECODE_ORDER ) { | ||
1447 | /*! In case Port reconfiguration is required | ||
1448 | * output buffer */ | ||
1449 | goto EXIT; | ||
1450 | } | ||
1451 | } // End of if condition from nFrameCounter = 1 | ||
1452 | |||
1453 | if( pVidDecComp->nOutbufInUseFlag == 1 ) { | ||
1454 | pVidDecComp->nOutbufInUseFlag = 0; | ||
1455 | nNewInBufferRequired = 0; | ||
1456 | } | ||
1457 | ii = 0; | ||
1458 | while( pDecOutArgs->outputID[ii] ) { | ||
1459 | pOutBufHeader = (OMX_BUFFERHEADERTYPE *)pDecOutArgs->outputID[ii]; | ||
1460 | if( pVidDecComp->bSupportDecodeOrderTimeStamp == OMX_TRUE ) { | ||
1461 | OSAL_ReadFromPipe(pVidDecComp->pTimeStampStoragePipe, &(pOutBufHeader->nTimeStamp), | ||
1462 | sizeof(OMX_TICKS), &(nActualSize), OSAL_NO_SUSPEND); | ||
1463 | } | ||
1464 | |||
1465 | activeFrameRegion[0] = pDecOutArgs->displayBufs.bufDesc[0].activeFrameRegion; | ||
1466 | activeFrameRegion[1].bottomRight.y = (activeFrameRegion[0].bottomRight.y) / 2; | ||
1467 | activeFrameRegion[1].bottomRight.x = activeFrameRegion[0].bottomRight.x; | ||
1468 | |||
1469 | //Crop rectangle handles the offsets for Y and UV buffers | ||
1470 | pOutBufHeader->nOffset = 0; | ||
1471 | pOutBufHeader->nFilledLen = (pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nHeight * nStride * 3) / 2; | ||
1472 | |||
1473 | if((pVidDecComp->tCropDimension.nTop != activeFrameRegion[0].topLeft.y | ||
1474 | || pVidDecComp->tCropDimension.nLeft != activeFrameRegion[0].topLeft.x) | ||
1475 | || (pVidDecComp->tCropDimension.nWidth != (OMX_U32)(activeFrameRegion[0].bottomRight.x - activeFrameRegion[0].topLeft.x) | ||
1476 | || pVidDecComp->tCropDimension.nHeight != (OMX_U32)(activeFrameRegion[0].bottomRight.y - activeFrameRegion[0].topLeft.y))) { | ||
1477 | pVidDecComp->tCropDimension.nTop = activeFrameRegion[0].topLeft.y; | ||
1478 | pVidDecComp->tCropDimension.nLeft = activeFrameRegion[0].topLeft.x; | ||
1479 | pVidDecComp->tCropDimension.nWidth = activeFrameRegion[0].bottomRight.x - activeFrameRegion[0].topLeft.x; | ||
1480 | pVidDecComp->tCropDimension.nHeight = activeFrameRegion[0].bottomRight.y - activeFrameRegion[0].topLeft.y; | ||
1481 | if( pVidDecComp->bUsePortReconfigForCrop == OMX_TRUE ) { | ||
1482 | eError = pVidDecComp->sBase.fpReturnEventNotify(hComponent, OMX_EventPortSettingsChanged, | ||
1483 | OMX_VIDDEC_OUTPUT_PORT, OMX_IndexConfigCommonOutputCrop, NULL); | ||
1484 | if( eError != OMX_ErrorNone ) { | ||
1485 | OSAL_ErrorTrace("Port reconfig callback returned error, trying to continue"); | ||
1486 | } | ||
1487 | } | ||
1488 | } | ||
1489 | |||
1490 | if( pVidDecComp->bSupportSkipGreyOutputFrames ) { | ||
1491 | if( pDecOutArgs->displayBufs.bufDesc[0].frameType == IVIDEO_I_FRAME || | ||
1492 | pDecOutArgs->displayBufs.bufDesc[0].frameType == IVIDEO_IDR_FRAME || | ||
1493 | pDecOutArgs->displayBufs.bufDesc[0].frameType == IVIDEO_IP_FRAME || | ||
1494 | pDecOutArgs->displayBufs.bufDesc[0].frameType == IVIDEO_IB_FRAME ) { | ||
1495 | pVidDecComp->bSyncFrameReady = OMX_TRUE; | ||
1496 | } | ||
1497 | } | ||
1498 | grallocHandle = (IMG_native_handle_t*)(pOutBufHeader->pBuffer); | ||
1499 | pVidDecComp->grallocModule->unlock((gralloc_module_t const *) pVidDecComp->grallocModule, (buffer_handle_t)grallocHandle); | ||
1500 | |||
1501 | if( pVidDecComp->bSyncFrameReady == OMX_TRUE ) { | ||
1502 | if( !(pInBufHeader->nFlags & OMX_BUFFERFLAG_EOS) || !(pVidDecComp->bIsFlushRequired)) { | ||
1503 | // Send the Output buffer to Base component | ||
1504 | pVidDecComp->sBase.pPvtData->fpDioSend(hComponent, | ||
1505 | OMX_VIDDEC_OUTPUT_PORT, pOutBufHeader); | ||
1506 | } | ||
1507 | } else { | ||
1508 | pVidDecComp->sBase.pPvtData->fpDioCancel(hComponent, | ||
1509 | OMX_VIDDEC_OUTPUT_PORT, pOutBufHeader); | ||
1510 | } | ||
1511 | pDecOutArgs->outputID[ii] = 0; | ||
1512 | ii++; | ||
1513 | } | ||
1514 | |||
1515 | jj = 0; | ||
1516 | while(pDecOutArgs->freeBufID[jj]) { | ||
1517 | // update locked flag of buffer to "unlocked" | ||
1518 | pFreeBufHeader = (OMX_BUFFERHEADERTYPE *)pDecOutArgs->freeBufID[jj]; | ||
1519 | ((OMXBase_BufHdrPvtData *)(pFreeBufHeader->pPlatformPrivate))->bIsLocked = OMX_FALSE; | ||
1520 | if (!ii && pDecOutArgs->freeBufID[jj] == pVidDecComp->pDecInArgs->inputID) { | ||
1521 | pVidDecComp->sBase.pPvtData->fpDioCancel(hComponent, | ||
1522 | OMX_VIDDEC_OUTPUT_PORT, pOutBufHeader); | ||
1523 | break; | ||
1524 | } | ||
1525 | jj++; | ||
1526 | } | ||
1527 | |||
1528 | if(((IVIDDEC3_Params *)(pVidDecComp->pDecStaticParams))->inputDataMode == IVIDEO_ENTIREFRAME ) { | ||
1529 | if( pInBufHeader && pDecOutArgs && | ||
1530 | (pVidDecComp->pDecDynParams->decodeHeader == XDM_DECODE_AU && pVidDecComp->bSupportDecodeOrderTimeStamp == OMX_TRUE)) { | ||
1531 | if((pVidDecComp->bInputBufferCancelled == 1) && (((pDecOutArgs->bytesConsumed == 0) || (((OMX_S32)pInBufHeader->nFilledLen) | ||
1532 | <= ((OMX_S32)pInBufHeader->nOffset + pDecOutArgs->bytesConsumed + 3))) || | ||
1533 | (pVidDecComp->pDecOutArgs->extendedError & 0x8000))) { | ||
1534 | pVidDecComp->bInputBufferCancelled = 0; | ||
1535 | } else if((((OMX_S32)pInBufHeader->nFilledLen) > ((OMX_S32)pInBufHeader->nOffset + pDecOutArgs->bytesConsumed + 3)) && | ||
1536 | ((pDecOutArgs->bytesConsumed != 0) && !(pInBufHeader->nFlags & OMX_BUFFERFLAG_EOS))) { | ||
1537 | pInBufHeader->nOffset = pInBufHeader->nOffset + pDecOutArgs->bytesConsumed; | ||
1538 | pVidDecComp->bInputBufferCancelled = 1; | ||
1539 | pVidDecComp->sBase.pPvtData->fpDioCancel(hComponent, OMX_VIDDEC_INPUT_PORT, pInBufHeader); | ||
1540 | } | ||
1541 | } | ||
1542 | /* Currently the assumption is that the entire input buffer is consumed | ||
1543 | * going forward we might have to handle cases where partial buffer is | ||
1544 | * consumed */ | ||
1545 | if( pVidDecComp->bInputBufferCancelled == 0 ) { | ||
1546 | if( pInBufHeader != NULL && | ||
1547 | !(pInBufHeader->nFlags & OMX_BUFFERFLAG_EOS) && | ||
1548 | pVidDecComp->nOutPortReconfigRequired != 1 ) { | ||
1549 | pInBufHeader->nFilledLen | ||
1550 | = pInBufHeader->nFilledLen - pDecOutArgs->bytesConsumed - pInBufHeader->nOffset; | ||
1551 | pInBufHeader->nOffset = 0; | ||
1552 | // Send Input buffer back to base | ||
1553 | pVidDecComp->sBase.pPvtData->fpDioSend(hComponent, | ||
1554 | OMX_VIDDEC_INPUT_PORT, pInBufHeader); | ||
1555 | } | ||
1556 | else if( pInBufHeader != NULL && (pInBufHeader->nFlags & OMX_BUFFERFLAG_EOS) && | ||
1557 | pVidDecComp->nOutPortReconfigRequired != 1 ) { | ||
1558 | pInBufHeader->nFilledLen | ||
1559 | = pInBufHeader->nFilledLen - pDecOutArgs->bytesConsumed - pInBufHeader->nOffset; | ||
1560 | pInBufHeader->nOffset = 0; | ||
1561 | if( Buffer_locked == 1 ) { | ||
1562 | OMXVidDec_HandleFLUSH_EOS(hComponent, pDupBufHeader, pInBufHeader); | ||
1563 | } else { | ||
1564 | OMXVidDec_HandleFLUSH_EOS(hComponent, pOutBufHeader, pInBufHeader); | ||
1565 | } | ||
1566 | if( eError != OMX_ErrorNone ) { | ||
1567 | goto EXIT; | ||
1568 | } | ||
1569 | } | ||
1570 | } | ||
1571 | } | ||
1572 | nIsDioReady = OMXBase_IsDioReady(hComponent, OMX_VIDDEC_OUTPUT_PORT); | ||
1573 | if( nIsDioReady == OMX_FALSE ) { | ||
1574 | goto EXIT; | ||
1575 | } | ||
1576 | // Get the number of buffers in Input and Output port | ||
1577 | pVidDecComp->sBase.pPvtData->fpDioGetCount(hComponent, | ||
1578 | OMX_VIDDEC_INPUT_PORT, (OMX_PTR)&nInMsgCount); | ||
1579 | pVidDecComp->sBase.pPvtData->fpDioGetCount(hComponent, | ||
1580 | OMX_VIDDEC_OUTPUT_PORT, (OMX_PTR)&nOutMsgCount); | ||
1581 | |||
1582 | } // End of while loop for input and output buffers | ||
1583 | |||
1584 | EXIT: | ||
1585 | if( pVidDecComp && pVidDecComp->sCodecConfig.sBuffer && pVidDecComp->nOutPortReconfigRequired == 0 && went_thru_loop) { | ||
1586 | memplugin_free((void*)H2P(pVidDecComp->sCodecConfig.sBuffer)); | ||
1587 | pVidDecComp->sCodecConfig.sBuffer = NULL; | ||
1588 | } | ||
1589 | |||
1590 | return (eError); | ||
1591 | } | ||
1592 | |||
1593 | /* | ||
1594 | * Video Decoder DeInit | ||
1595 | */ | ||
1596 | OMX_ERRORTYPE OMXVidDec_ComponentDeinit(OMX_HANDLETYPE hComponent) | ||
1597 | { | ||
1598 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
1599 | OMX_COMPONENTTYPE *pComp; | ||
1600 | OMXVidDecComp *pVidDecComp = NULL; | ||
1601 | OMX_U32 i; | ||
1602 | OMXBase_PortProps *pOutPortProperties = NULL; | ||
1603 | |||
1604 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
1605 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
1606 | pVidDecComp = (OMXVidDecComp *)pComp->pComponentPrivate; | ||
1607 | |||
1608 | // For MPEG2 with Error Concealment ON, need to free the metadata buffer. | ||
1609 | if ((pVidDecComp->tVideoParams[OMX_VIDDEC_INPUT_PORT].eCompressionFormat == OMX_VIDEO_CodingMPEG2) && (pVidDecComp->pmetaBuffer)) { | ||
1610 | memplugin_free((void*)H2P(pVidDecComp->pmetaBuffer)); | ||
1611 | pVidDecComp->pmetaBuffer = NULL; | ||
1612 | } | ||
1613 | |||
1614 | // Free sBuffer if it hasn't already been freed | ||
1615 | if( pVidDecComp && pVidDecComp->sCodecConfig.sBuffer ) { | ||
1616 | memplugin_free((void*)H2P(pVidDecComp->sCodecConfig.sBuffer)); | ||
1617 | pVidDecComp->sCodecConfig.sBuffer = NULL; | ||
1618 | } | ||
1619 | |||
1620 | OSAL_DeletePipe(pVidDecComp->pTimeStampStoragePipe); | ||
1621 | |||
1622 | OMXBase_UtilCleanupIfError(hComponent); | ||
1623 | |||
1624 | // Call to Specific Decoder De-init routine | ||
1625 | pVidDecComp->fpDeinit_Codec(hComponent); | ||
1626 | // Close Codec-Engine | ||
1627 | if( pVidDecComp->ce ) { | ||
1628 | Engine_close(pVidDecComp->ce); | ||
1629 | } | ||
1630 | |||
1631 | if( pVidDecComp->sBase.cComponentName ) { | ||
1632 | OSAL_Free(pVidDecComp->sBase.cComponentName); | ||
1633 | pVidDecComp->sBase.cComponentName = NULL; | ||
1634 | } | ||
1635 | if( pVidDecComp->sBase.pVideoPortParams ) { | ||
1636 | OSAL_Free(pVidDecComp->sBase.pVideoPortParams); | ||
1637 | pVidDecComp->sBase.pVideoPortParams = NULL; | ||
1638 | } | ||
1639 | |||
1640 | if (pVidDecComp->tInBufDesc) { | ||
1641 | memplugin_free(pVidDecComp->tInBufDesc); | ||
1642 | pVidDecComp->tInBufDesc = NULL; | ||
1643 | } | ||
1644 | |||
1645 | if (pVidDecComp->tOutBufDesc) { | ||
1646 | memplugin_free(pVidDecComp->tOutBufDesc); | ||
1647 | pVidDecComp->tOutBufDesc = NULL; | ||
1648 | } | ||
1649 | |||
1650 | // Call to base Component De-init routine | ||
1651 | eError = OMXBase_ComponentDeinit(hComponent); | ||
1652 | |||
1653 | if (pVidDecComp->bIPCRecoveryNeeded) { | ||
1654 | dce_ipc_recover(); | ||
1655 | } | ||
1656 | |||
1657 | OSAL_Free(pVidDecComp); | ||
1658 | pVidDecComp = NULL; | ||
1659 | |||
1660 | EXIT: | ||
1661 | return (eError); | ||
1662 | } | ||
1663 | |||
1664 | /* | ||
1665 | * GetExtension Index | ||
1666 | */ | ||
1667 | OMX_ERRORTYPE OMXVidDec_GetExtensionIndex(OMX_HANDLETYPE hComponent, | ||
1668 | OMX_STRING cParameterName, OMX_INDEXTYPE *pIndexType) | ||
1669 | { | ||
1670 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
1671 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
1672 | OMXVidDecComp *pVidDecComp = NULL; | ||
1673 | |||
1674 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
1675 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
1676 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
1677 | // Check for NULL Parameters | ||
1678 | if((cParameterName == NULL) || (pIndexType == NULL)) { | ||
1679 | eError = OMX_ErrorBadParameter; | ||
1680 | goto EXIT; | ||
1681 | } | ||
1682 | // Check for Valid State | ||
1683 | if( pVidDecComp->sBase.tCurState == OMX_StateInvalid ) { | ||
1684 | eError = OMX_ErrorInvalidState; | ||
1685 | goto EXIT; | ||
1686 | } | ||
1687 | // Ensure that String length is not greater than Max allowed length | ||
1688 | if( strlen(cParameterName) > 127 ) { | ||
1689 | //strlen does not include \0 size, hence 127 | ||
1690 | eError = OMX_ErrorBadParameter; | ||
1691 | goto EXIT; | ||
1692 | } | ||
1693 | |||
1694 | if(strcmp(cParameterName, "OMX.google.android.index.enableAndroidNativeBuffers") == 0) { | ||
1695 | // If Index type is 2D Buffer Allocated Dimension | ||
1696 | *pIndexType = (OMX_INDEXTYPE) OMX_TI_IndexUseNativeBuffers; | ||
1697 | goto EXIT; | ||
1698 | } else if (strcmp(cParameterName, "OMX.google.android.index.useAndroidNativeBuffer2") == 0) { | ||
1699 | //This is call just a dummy for android to support backward compatibility | ||
1700 | *pIndexType = (OMX_INDEXTYPE) NULL; | ||
1701 | goto EXIT; | ||
1702 | } else if (strcmp(cParameterName, "OMX.google.android.index.getAndroidNativeBufferUsage") == 0) { | ||
1703 | *pIndexType = (OMX_INDEXTYPE) OMX_TI_IndexAndroidNativeBufferUsage; | ||
1704 | } else if( strcmp(cParameterName, "OMX.google.android.index.describeColorFormat") == 0 ) { | ||
1705 | // If Index type is Time Stamp In Decode Order | ||
1706 | *pIndexType = (OMX_INDEXTYPE) OMX_TI_IndexDescribeColorFormat; | ||
1707 | } else if( strcmp(cParameterName, "OMX_TI_IndexParamTimeStampInDecodeOrder") == 0 ) { | ||
1708 | // If Index type is Time Stamp In Decode Order | ||
1709 | *pIndexType = (OMX_INDEXTYPE) OMX_TI_IndexParamTimeStampInDecodeOrder; | ||
1710 | } else if( strcmp(cParameterName, "OMX_TI_IndexEnableDecoderZeroDisplayDelayMode") == 0 ) { | ||
1711 | // If Index type is Enable Decoder Zero Display Delay Mode | ||
1712 | *pIndexType = (OMX_INDEXTYPE) OMX_TI_IndexEnableDecoderZeroDisplayDelayMode; | ||
1713 | } else if( strcmp(cParameterName, "OMX.google.android.index.prepareForAdaptivePlayback") == 0 ) { | ||
1714 | // If Index type is Enable Decoder Zero Display Delay Mode | ||
1715 | *pIndexType = (OMX_INDEXTYPE) OMX_TI_IndexPrepareForAdaptivePlayback; | ||
1716 | } else { | ||
1717 | //does not match any custom index | ||
1718 | eError = OMX_ErrorUnsupportedIndex; | ||
1719 | } | ||
1720 | |||
1721 | EXIT: | ||
1722 | return (eError); | ||
1723 | } | ||
1724 | |||
1725 | |||
diff --git a/libstagefrighthw/omx/videodecode/omx_video_decoder.h b/libstagefrighthw/omx/videodecode/omx_video_decoder.h new file mode 100644 index 0000000..58f2a12 --- /dev/null +++ b/libstagefrighthw/omx/videodecode/omx_video_decoder.h | |||
@@ -0,0 +1,258 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 _OMX_VIDEO_DECODER_H_ | ||
18 | #define _OMX_VIDEO_DECODER_H_ | ||
19 | |||
20 | #ifdef __cplusplus | ||
21 | extern "C" { | ||
22 | #endif | ||
23 | |||
24 | #include <string.h> | ||
25 | #include <sys/types.h> | ||
26 | #include <sys/stat.h> | ||
27 | #include <fcntl.h> | ||
28 | |||
29 | #include <OMX_Types.h> | ||
30 | #include <OMX_Base.h> | ||
31 | #include <OMX_BaseUtils.h> | ||
32 | |||
33 | #include <libdce.h> | ||
34 | |||
35 | #include <hardware/gralloc.h> | ||
36 | #include <hardware/hardware.h> | ||
37 | #include <hal_public.h> | ||
38 | |||
39 | #define OMX_VIDDEC_NUM_OF_PORTS OMX_BASE_NUM_OF_PORTS | ||
40 | #define OMX_VIDDEC_INPUT_PORT OMX_BASE_INPUT_PORT | ||
41 | #define OMX_VIDDEC_OUTPUT_PORT OMX_BASE_OUTPUT_PORT | ||
42 | #define OMX_VIDDEC_DEFAULT_START_PORT_NUM OMX_BASE_DEFAULT_START_PORT_NUM | ||
43 | |||
44 | |||
45 | /*Android Data structures*/ | ||
46 | |||
47 | enum Type { | ||
48 | MEDIA_IMAGE_TYPE_UNKNOWN = 0, | ||
49 | MEDIA_IMAGE_TYPE_YUV, | ||
50 | }; | ||
51 | |||
52 | enum PlaneIndex { | ||
53 | Y = 0, | ||
54 | U, | ||
55 | V, | ||
56 | MAX_NUM_PLANES | ||
57 | }; | ||
58 | |||
59 | typedef struct PlaneInfo { | ||
60 | uint32_t mOffset; // offset of first pixel of the plane in bytes | ||
61 | // from buffer offset | ||
62 | uint32_t mColInc; // column increment in bytes | ||
63 | uint32_t mRowInc; // row increment in bytes | ||
64 | uint32_t mHorizSubsampling; // subsampling compared to the largest plane | ||
65 | uint32_t mVertSubsampling; // subsampling compared to the largest plane | ||
66 | }PlaneInfo; | ||
67 | |||
68 | // Structure describing a media image (frame) | ||
69 | // Currently only supporting YUV | ||
70 | typedef struct MediaImage { | ||
71 | int mType; | ||
72 | uint32_t mNumPlanes; // number of planes | ||
73 | uint32_t mWidth; // width of largest plane (unpadded, as in nFrameWidth) | ||
74 | uint32_t mHeight; // height of largest plane (unpadded, as in nFrameHeight) | ||
75 | uint32_t mBitDepth; // useable bit depth | ||
76 | PlaneInfo mPlane[MAX_NUM_PLANES]; | ||
77 | }MediaImage; | ||
78 | |||
79 | // A pointer to this struct is passed to OMX_GetParameter when the extension | ||
80 | // index for the 'OMX.google.android.index.describeColorFormat' | ||
81 | // extension is given. This method can be called from any component state | ||
82 | // other than invalid. The color-format, frame width/height, and stride/ | ||
83 | // slice-height parameters are ones that are associated with a raw video | ||
84 | // port (input or output), but the stride/slice height parameters may be | ||
85 | // incorrect. bUsingNativeBuffers is OMX_TRUE if native android buffers will | ||
86 | // be used (while specifying this color format). | ||
87 | // | ||
88 | // The component shall fill out the MediaImage structure that | ||
89 | // corresponds to the described raw video format, and the potentially corrected | ||
90 | // stride and slice-height info. | ||
91 | // | ||
92 | // The behavior is slightly different if bUsingNativeBuffers is OMX_TRUE, | ||
93 | // though most implementations can ignore this difference. When using native buffers, | ||
94 | // the component may change the configured color format to an optimized format. | ||
95 | // Additionally, when allocating these buffers for flexible usecase, the framework | ||
96 | // will set the SW_READ/WRITE_OFTEN usage flags. In this case (if bUsingNativeBuffers | ||
97 | // is OMX_TRUE), the component shall fill out the MediaImage information for the | ||
98 | // scenario when these SW-readable/writable buffers are locked using gralloc_lock. | ||
99 | // Note, that these buffers may also be locked using gralloc_lock_ycbcr, which must | ||
100 | // be supported for vendor-specific formats. | ||
101 | // | ||
102 | // For non-YUV packed planar/semiplanar image formats, or if bUsingNativeBuffers | ||
103 | // is OMX_TRUE and the component does not support this color format with native | ||
104 | // buffers, the component shall set mNumPlanes to 0, and mType to MEDIA_IMAGE_TYPE_UNKNOWN. | ||
105 | typedef struct DescribeColorFormatParams { | ||
106 | OMX_U32 nSize; | ||
107 | OMX_VERSIONTYPE nVersion; | ||
108 | // input: parameters from OMX_VIDEO_PORTDEFINITIONTYPE | ||
109 | OMX_COLOR_FORMATTYPE eColorFormat; | ||
110 | OMX_U32 nFrameWidth; | ||
111 | OMX_U32 nFrameHeight; | ||
112 | OMX_U32 nStride; | ||
113 | OMX_U32 nSliceHeight; | ||
114 | OMX_BOOL bUsingNativeBuffers; | ||
115 | |||
116 | // output: fill out the MediaImage fields | ||
117 | MediaImage sMediaImage; | ||
118 | }DescribeColorFormatParams; | ||
119 | |||
120 | // A pointer to this struct is passed to OMX_SetParameter() when the extension | ||
121 | // index "OMX.google.android.index.prepareForAdaptivePlayback" is given. | ||
122 | // | ||
123 | // This method is used to signal a video decoder, that the user has requested | ||
124 | // seamless resolution change support (if bEnable is set to OMX_TRUE). | ||
125 | // nMaxFrameWidth and nMaxFrameHeight are the dimensions of the largest | ||
126 | // anticipated frames in the video. If bEnable is OMX_FALSE, no resolution | ||
127 | // change is expected, and the nMaxFrameWidth/Height fields are unused. | ||
128 | // | ||
129 | // If the decoder supports dynamic output buffers, it may ignore this | ||
130 | // request. Otherwise, it shall request resources in such a way so that it | ||
131 | // avoids full port-reconfiguration (due to output port-definition change) | ||
132 | // during resolution changes. | ||
133 | // | ||
134 | // DO NOT USE THIS STRUCTURE AS IT WILL BE REMOVED. INSTEAD, IMPLEMENT | ||
135 | // METADATA SUPPORT FOR VIDEO DECODERS. | ||
136 | typedef struct PrepareForAdaptivePlaybackParams { | ||
137 | OMX_U32 nSize; | ||
138 | OMX_VERSIONTYPE nVersion; | ||
139 | OMX_U32 nPortIndex; | ||
140 | OMX_BOOL bEnable; | ||
141 | OMX_U32 nMaxFrameWidth; | ||
142 | OMX_U32 nMaxFrameHeight; | ||
143 | }PrepareForAdaptivePlaybackParams; | ||
144 | |||
145 | /* | ||
146 | * Padded Buffer Parameters | ||
147 | */ | ||
148 | typedef struct PaddedBuffParams { | ||
149 | OMX_U32 nBufferSize; /*! Buffer size */ | ||
150 | OMX_U32 nPaddedWidth; /*! Padded Width of the buffer */ | ||
151 | OMX_U32 nPaddedHeight; /*! Padded Height */ | ||
152 | OMX_U32 nBufferCountMin; /*! Min number of buffers required */ | ||
153 | OMX_U32 nBufferCountActual; /*! Actual number of buffers */ | ||
154 | OMX_U32 n1DBufferAlignment; /*! 1D Buffer Alignment value */ | ||
155 | OMX_U32 n2DBufferYAlignment; /*! Y axis alignment value in 2Dbuffer */ | ||
156 | OMX_U32 n2DBufferXAlignment; /*! X Axis alignment value in 2Dbuffer */ | ||
157 | } PaddedBuffParams; | ||
158 | |||
159 | /* | ||
160 | * OMX Video decoder component | ||
161 | */ | ||
162 | typedef struct OMXVideoDecoderComponent { | ||
163 | OMXBaseComp sBase; | ||
164 | /* codec related fields */ | ||
165 | OMX_STRING cDecoderName; | ||
166 | VIDDEC3_Handle pDecHandle; | ||
167 | Engine_Handle ce; | ||
168 | IVIDDEC3_Params *pDecStaticParams; /*! Pointer to Decoder Static Params */ | ||
169 | IVIDDEC3_DynamicParams *pDecDynParams; /*! Pointer to Decoder Dynamic Params */ | ||
170 | IVIDDEC3_Status *pDecStatus; /*! Pointer to Decoder Status struct */ | ||
171 | IVIDDEC3_InArgs *pDecInArgs; /*! Pointer to Decoder InArgs */ | ||
172 | IVIDDEC3_OutArgs *pDecOutArgs; /*! Pointer to Decoder OutArgs */ | ||
173 | XDM2_BufDesc *tInBufDesc; | ||
174 | XDM2_BufDesc *tOutBufDesc; | ||
175 | |||
176 | /* OMX params */ | ||
177 | OMX_VIDEO_PARAM_PORTFORMATTYPE tVideoParams[OMX_VIDDEC_NUM_OF_PORTS]; | ||
178 | OMX_CONFIG_RECTTYPE tCropDimension; | ||
179 | OMX_CONFIG_SCALEFACTORTYPE tScaleParams; | ||
180 | OMX_PARAM_COMPONENTROLETYPE tComponentRole; | ||
181 | OMX_CONFIG_RECTTYPE t2DBufferAllocParams[OMX_VIDDEC_NUM_OF_PORTS]; | ||
182 | |||
183 | /* local params */ | ||
184 | gralloc_module_t const *grallocModule; | ||
185 | OMXBase_CodecConfigBuf sCodecConfig; | ||
186 | OMX_U32 nOutPortReconfigRequired; | ||
187 | OMX_U32 nCodecRecreationRequired; | ||
188 | OMX_U32 bInputBufferCancelled; | ||
189 | |||
190 | OMX_U32 bIsFlushRequired; | ||
191 | OMX_BOOL bUsePortReconfigForCrop; | ||
192 | OMX_BOOL bUsePortReconfigForPadding; | ||
193 | OMX_BOOL bSupportDecodeOrderTimeStamp; | ||
194 | OMX_BOOL bSupportSkipGreyOutputFrames; | ||
195 | OMX_BOOL bEnableDecodeZeroDisplayDelayMode; | ||
196 | |||
197 | OMX_U32 nFrameCounter; | ||
198 | OMX_BOOL bSyncFrameReady; | ||
199 | OMX_U32 nOutbufInUseFlag; | ||
200 | OMX_PTR pCodecSpecific; | ||
201 | OMX_U32 nDecoderMode; | ||
202 | OMX_U32 nFatalErrorGiven; | ||
203 | OMX_PTR pTimeStampStoragePipe; | ||
204 | OMX_U32 nFrameRateDivisor; | ||
205 | OMX_BOOL bFirstFrameHandled; | ||
206 | |||
207 | OMX_BOOL bIPCRecoveryNeeded; | ||
208 | |||
209 | //Parameters for Adaptive video playback | ||
210 | OMX_BOOL bisAdaptivePlayback; | ||
211 | OMX_U32 nAdaptiveMaxFrameWidth; | ||
212 | OMX_U32 nAdaptiveMaxFrameHeight; | ||
213 | |||
214 | void (*fpSet_StaticParams)(OMX_HANDLETYPE hComponent, void *params); | ||
215 | void (*fpSet_DynamicParams)(OMX_HANDLETYPE hComponent, void *dynamicparams); | ||
216 | void (*fpSet_Status)(OMX_HANDLETYPE hComponent, void *status); | ||
217 | void (*fpDeinit_Codec)(OMX_HANDLETYPE hComponent); | ||
218 | OMX_ERRORTYPE (*fpHandle_ExtendedError)(OMX_HANDLETYPE hComponent); | ||
219 | OMX_ERRORTYPE (*fpHandle_CodecGetStatus)(OMX_HANDLETYPE hComponent); | ||
220 | PaddedBuffParams (*fpCalc_OubuffDetails)(OMX_HANDLETYPE hComponent, OMX_U32 width, OMX_U32 height); | ||
221 | MemHeader *pmetaBuffer; | ||
222 | |||
223 | }OMXVidDecComp; | ||
224 | |||
225 | /* Component Entry Method */ | ||
226 | OMX_ERRORTYPE OMX_ComponentInit(OMX_HANDLETYPE hComponent); | ||
227 | OMX_ERRORTYPE OMXVidDec_ComponentInit(OMX_HANDLETYPE hComponent); | ||
228 | OMX_ERRORTYPE OMXVidDec_ComponentDeinit(OMX_HANDLETYPE hComponent); | ||
229 | |||
230 | OMX_ERRORTYPE OMXVidDec_SetParameter(OMX_HANDLETYPE hComponent, | ||
231 | OMX_INDEXTYPE nIndex, OMX_PTR pParamStruct); | ||
232 | |||
233 | OMX_ERRORTYPE OMXVidDec_GetParameter(OMX_HANDLETYPE hComponent, | ||
234 | OMX_INDEXTYPE nIndex, OMX_PTR pParamStruct); | ||
235 | |||
236 | OMX_ERRORTYPE OMXVidDec_GetConfig(OMX_HANDLETYPE hComponent, | ||
237 | OMX_INDEXTYPE nIndex, OMX_PTR pComponentConfigStructure); | ||
238 | |||
239 | OMX_ERRORTYPE OMXVidDec_SetConfig(OMX_HANDLETYPE hComponent, | ||
240 | OMX_INDEXTYPE nIndex, OMX_PTR pComponentConfigStructure); | ||
241 | |||
242 | OMX_ERRORTYPE OMXVidDec_CommandNotify(OMX_HANDLETYPE hComponent, OMX_COMMANDTYPE Cmd, | ||
243 | OMX_U32 nParam, OMX_PTR pCmdData); | ||
244 | |||
245 | OMX_ERRORTYPE OMXVidDec_DataNotify(OMX_HANDLETYPE hComponent); | ||
246 | |||
247 | OMX_ERRORTYPE OMXVidDec_XlateBuffHandle(OMX_HANDLETYPE hComponent, OMX_PTR pBufferHdr, OMX_BOOL bRegister); | ||
248 | |||
249 | OMX_ERRORTYPE OMXVidDec_GetExtensionIndex(OMX_HANDLETYPE hComponent, OMX_STRING cParameterName, | ||
250 | OMX_INDEXTYPE *pIndexType); | ||
251 | |||
252 | |||
253 | #ifdef __cplusplus | ||
254 | } | ||
255 | #endif | ||
256 | |||
257 | #endif /* _OMX_VIDEO_DECODER_H_ */ | ||
258 | |||
diff --git a/libstagefrighthw/omx/videodecode/omx_video_decoder_componenttable.c b/libstagefrighthw/omx/videodecode/omx_video_decoder_componenttable.c new file mode 100644 index 0000000..438470d --- /dev/null +++ b/libstagefrighthw/omx/videodecode/omx_video_decoder_componenttable.c | |||
@@ -0,0 +1,31 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 <omx_video_decoder_componenttable.h> | ||
18 | |||
19 | extern OMX_ERRORTYPE OMXH264VD_Init(OMX_HANDLETYPE hComponent); | ||
20 | extern OMX_ERRORTYPE OMXMPEG4VD_Init(OMX_HANDLETYPE hComponent); | ||
21 | extern OMX_ERRORTYPE OMXH263VD_Init(OMX_HANDLETYPE hComponent); | ||
22 | extern OMX_ERRORTYPE OMXMPEG2VD_Init(OMX_HANDLETYPE hComponent); | ||
23 | |||
24 | OMXDecoderComponentList DecoderList[] = | ||
25 | { | ||
26 | { "video_decoder.avc", OMX_VIDEO_CodingAVC, OMXH264VD_Init }, | ||
27 | { "video_decoder.mpeg4", OMX_VIDEO_CodingMPEG4, OMXMPEG4VD_Init}, | ||
28 | { "video_decoder.h263", OMX_VIDEO_CodingH263, OMXH263VD_Init }, | ||
29 | { "video_decoder.mpeg2", OMX_VIDEO_CodingMPEG2, OMXMPEG2VD_Init }, | ||
30 | { "NULL", 0, NULL } | ||
31 | }; | ||
diff --git a/libstagefrighthw/omx/videodecode/omx_video_decoder_componenttable.h b/libstagefrighthw/omx/videodecode/omx_video_decoder_componenttable.h new file mode 100644 index 0000000..10ca03f --- /dev/null +++ b/libstagefrighthw/omx/videodecode/omx_video_decoder_componenttable.h | |||
@@ -0,0 +1,46 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 _OMX_VIDEO_DECODER_COMPONENTTABLE_H_ | ||
18 | #define _OMX_VIDEO_DECODER_COMPONENTTABLE_H_ | ||
19 | |||
20 | #ifdef __cplusplus | ||
21 | extern "C" { | ||
22 | #endif | ||
23 | |||
24 | #include <stdio.h> | ||
25 | #include <OMX_Video.h> | ||
26 | |||
27 | typedef struct OMXDecoderComponentList { | ||
28 | /*Component role to be specified here*/ | ||
29 | OMX_U8 cRole[OMX_MAX_STRINGNAME_SIZE]; | ||
30 | |||
31 | /*! Video Coding Type Format */ | ||
32 | OMX_VIDEO_CODINGTYPE eCompressionFormat; | ||
33 | |||
34 | /*! Function pointer to the component Init function of decoder */ | ||
35 | OMX_ERRORTYPE (*fpDecoderComponentInit)(OMX_HANDLETYPE hComponent); | ||
36 | |||
37 | } OMXDecoderComponentList; | ||
38 | |||
39 | /* external definition for the Decoder Component List*/ | ||
40 | extern OMXDecoderComponentList DecoderList[]; | ||
41 | |||
42 | #ifdef __cplusplus | ||
43 | } | ||
44 | #endif | ||
45 | |||
46 | #endif /* _OMX_VIDEO_DECODER_COMPONENTTABLE_H_ */ | ||
diff --git a/libstagefrighthw/omx/videodecode/omx_video_decoder_h264.c b/libstagefrighthw/omx/videodecode/omx_video_decoder_h264.c new file mode 100644 index 0000000..0eb0ae0 --- /dev/null +++ b/libstagefrighthw/omx/videodecode/omx_video_decoder_h264.c | |||
@@ -0,0 +1,717 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 | #define LOG_TAG "OMX_H264_VIDDEC" | ||
18 | |||
19 | #include <omx_video_decoder_h264.h> | ||
20 | #include <omx_video_decoder_internal.h> | ||
21 | |||
22 | #define OMX_MAX_DEC_OP_BUFFERS 20 | ||
23 | |||
24 | OMX_ERRORTYPE OMXH264VD_Init(OMX_HANDLETYPE hComponent) | ||
25 | { | ||
26 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
27 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
28 | OMXVidDecComp *pVidDecComp = NULL; | ||
29 | OMXH264VidDecComp *pH264VidDecComp = NULL; | ||
30 | IVIDDEC3_Params *pDecParams; | ||
31 | IH264VDEC_Params *params; | ||
32 | |||
33 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
34 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
35 | |||
36 | /*! Initialize the function parameters for OMX functions */ | ||
37 | pHandle->SetParameter = OMXH264VD_SetParameter; | ||
38 | pHandle->GetParameter = OMXH264VD_GetParameter; | ||
39 | |||
40 | /*! Initialize the function pointers */ | ||
41 | pVidDecComp->fpSet_StaticParams = OMXH264VD_Set_StaticParams; | ||
42 | pVidDecComp->fpSet_DynamicParams = OMXH264VD_Set_DynamicParams; | ||
43 | pVidDecComp->fpSet_Status = OMXH264VD_Set_Status; | ||
44 | pVidDecComp->fpCalc_OubuffDetails | ||
45 | = CalculateH264VD_outbuff_details; | ||
46 | pVidDecComp->fpDeinit_Codec = OMXH264VD_DeInit; | ||
47 | pVidDecComp->cDecoderName = "ivahd_h264dec"; | ||
48 | pVidDecComp->tVideoParams[OMX_VIDDEC_INPUT_PORT].eCompressionFormat = OMX_VIDEO_CodingAVC; | ||
49 | pVidDecComp->tVideoParams[OMX_VIDDEC_OUTPUT_PORT].eCompressionFormat = OMX_VIDEO_CodingUnused; | ||
50 | pVidDecComp->fpHandle_ExtendedError = OMXH264VD_HandleError; | ||
51 | |||
52 | pVidDecComp->pCodecSpecific = | ||
53 | (OMXH264VidDecComp *) OSAL_Malloc(sizeof (OMXH264VidDecComp)); | ||
54 | OMX_CHECK((pVidDecComp->pCodecSpecific) != NULL, OMX_ErrorInsufficientResources); | ||
55 | |||
56 | pH264VidDecComp =(OMXH264VidDecComp *) pVidDecComp->pCodecSpecific; | ||
57 | |||
58 | OMX_BASE_INIT_STRUCT_PTR(&(pH264VidDecComp->tH264VideoParam), OMX_VIDEO_PARAM_AVCTYPE); | ||
59 | pH264VidDecComp->tH264VideoParam.nPortIndex = OMX_VIDDEC_INPUT_PORT; | ||
60 | pH264VidDecComp->tH264VideoParam.eProfile = OMX_VIDEO_AVCProfileHigh; | ||
61 | pH264VidDecComp->tH264VideoParam.eLevel = OMX_VIDEO_AVCLevel41; | ||
62 | pH264VidDecComp->tH264VideoParam.nRefFrames = 0xFFFFFFFF; | ||
63 | |||
64 | /*! Allocate Memory for Static Parameter */ | ||
65 | pVidDecComp->pDecStaticParams | ||
66 | = (IVIDDEC3_Params *) memplugin_alloc(sizeof(IH264VDEC_Params), 1, MEM_CARVEOUT, 0, 0); | ||
67 | OMX_CHECK(pVidDecComp->pDecStaticParams != NULL, OMX_ErrorInsufficientResources); | ||
68 | OSAL_Memset(pVidDecComp->pDecStaticParams, 0x0, sizeof(IH264VDEC_Params)); | ||
69 | |||
70 | params = (IH264VDEC_Params *) (pVidDecComp->pDecStaticParams); | ||
71 | pDecParams = &(params->viddec3Params); | ||
72 | pDecParams->displayDelay = IVIDDEC3_DISPLAY_DELAY_AUTO; | ||
73 | params->presetLevelIdc = IH264VDEC_LEVEL41; | ||
74 | params->dpbSizeInFrames = IH264VDEC_DPB_NUMFRAMES_AUTO; | ||
75 | |||
76 | /*! Allocate Memory for Dynamic Parameter */ | ||
77 | pVidDecComp->pDecDynParams | ||
78 | = (IVIDDEC3_DynamicParams *) memplugin_alloc(sizeof(IH264VDEC_DynamicParams), 1, MEM_CARVEOUT, 0, 0); | ||
79 | OMX_CHECK(pVidDecComp->pDecDynParams != NULL, OMX_ErrorInsufficientResources); | ||
80 | OSAL_Memset(pVidDecComp->pDecDynParams, 0x0, sizeof(IH264VDEC_DynamicParams)); | ||
81 | |||
82 | /*! Allocate Memory for Status Structure */ | ||
83 | pVidDecComp->pDecStatus | ||
84 | = (IVIDDEC3_Status *) memplugin_alloc(sizeof(IH264VDEC_Status), 1, MEM_CARVEOUT, 0, 0); | ||
85 | OMX_CHECK(pVidDecComp->pDecStatus != NULL, OMX_ErrorInsufficientResources); | ||
86 | OSAL_Memset(pVidDecComp->pDecStatus, 0x0, sizeof(IH264VDEC_Status)); | ||
87 | ((IH264VDEC_Status *)pVidDecComp->pDecStatus)->spsMaxRefFrames = 1; | ||
88 | |||
89 | /*! Allocate Memory for Input Arguments */ | ||
90 | pVidDecComp->pDecInArgs | ||
91 | = (IVIDDEC3_InArgs *) memplugin_alloc(sizeof(IH264VDEC_InArgs), 1, MEM_CARVEOUT, 0, 0); | ||
92 | OMX_CHECK(pVidDecComp->pDecInArgs != NULL, OMX_ErrorInsufficientResources); | ||
93 | OSAL_Memset(pVidDecComp->pDecInArgs, 0x0, sizeof(IH264VDEC_InArgs)); | ||
94 | |||
95 | /*! Allocate Memory for Output Arguments */ | ||
96 | pVidDecComp->pDecOutArgs | ||
97 | = (IVIDDEC3_OutArgs *) memplugin_alloc(sizeof(IH264VDEC_OutArgs), 1, MEM_CARVEOUT, 0, 0); | ||
98 | OMX_CHECK(pVidDecComp->pDecOutArgs != NULL, OMX_ErrorInsufficientResources); | ||
99 | OSAL_Memset(pVidDecComp->pDecOutArgs, 0x0, sizeof(IH264VDEC_OutArgs)); | ||
100 | |||
101 | pVidDecComp->pDecInArgs->size = sizeof(IH264VDEC_InArgs); | ||
102 | pVidDecComp->pDecOutArgs->size = sizeof(IH264VDEC_OutArgs); | ||
103 | |||
104 | pDecParams->metadataType[0] = IVIDEO_METADATAPLANE_NONE; | ||
105 | pDecParams->metadataType[1] = IVIDEO_METADATAPLANE_NONE; | ||
106 | pDecParams->metadataType[2] = IVIDEO_METADATAPLANE_NONE; | ||
107 | |||
108 | pDecParams->operatingMode = IVIDEO_DECODE_ONLY; | ||
109 | pDecParams->inputDataMode = IVIDEO_ENTIREFRAME; | ||
110 | pDecParams->numInputDataUnits = 0; | ||
111 | |||
112 | EXIT: | ||
113 | return (eError); | ||
114 | } | ||
115 | |||
116 | |||
117 | void OMXH264VD_Set_StaticParams(OMX_HANDLETYPE hComponent, void *staticparams) | ||
118 | { | ||
119 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
120 | OMXVidDecComp *pVidDecComp = NULL; | ||
121 | IVIDDEC3_Params *pDecParams; | ||
122 | IH264VDEC_Params *params = (IH264VDEC_Params *)staticparams; | ||
123 | |||
124 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
125 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
126 | |||
127 | pDecParams = &(params->viddec3Params); | ||
128 | pDecParams->size = sizeof(IH264VDEC_Params); | ||
129 | pDecParams->maxWidth = 1920; | ||
130 | pDecParams->maxHeight = 1088; | ||
131 | pDecParams->maxFrameRate = 30000; | ||
132 | pDecParams->maxBitRate = 10000000; | ||
133 | pDecParams->dataEndianness = XDM_BYTE; | ||
134 | |||
135 | /*init outArgs IVIDDEC3_OutArgs*/ | ||
136 | pDecParams->forceChromaFormat = XDM_YUV_420SP; | ||
137 | pDecParams->displayBufsMode = IVIDDEC3_DISPLAYBUFS_EMBEDDED; | ||
138 | pDecParams->outputDataMode = IVIDEO_ENTIREFRAME; | ||
139 | pDecParams->numOutputDataUnits = 0; | ||
140 | pDecParams->errorInfoMode = IVIDEO_ERRORINFO_OFF; | ||
141 | params->errConcealmentMode = | ||
142 | pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef.format.video.bFlagErrorConcealment; | ||
143 | |||
144 | params->temporalDirModePred = IH264VDEC_ENABLE_TEMPORALDIRECT; | ||
145 | params->debugTraceLevel= 0; | ||
146 | params->lastNFramesToLog= 0; | ||
147 | |||
148 | return; | ||
149 | } | ||
150 | |||
151 | |||
152 | void OMXH264VD_Set_DynamicParams(OMX_HANDLETYPE hComponent, void *dynParams) | ||
153 | { | ||
154 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
155 | OMXVidDecComp *pVidDecComp = NULL; | ||
156 | IVIDDEC3_DynamicParams *pDecDynParams; | ||
157 | IH264VDEC_DynamicParams *params = (IH264VDEC_DynamicParams *) dynParams; | ||
158 | |||
159 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
160 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
161 | pDecDynParams = &(params->viddec3DynamicParams); | ||
162 | pDecDynParams->size = sizeof(IVIDDEC3_DynamicParams); | ||
163 | |||
164 | /* init dynamic params IVIDDEC3_DynamicParams */ | ||
165 | pDecDynParams->decodeHeader = XDM_DECODE_AU; /* Supported */ | ||
166 | |||
167 | pDecDynParams->displayWidth = 0; /* Not Supported: Set default */ | ||
168 | /*Not Supported: Set default*/ | ||
169 | pDecDynParams->frameSkipMode = H264VD_DEFAULT_FRAME_SKIP; | ||
170 | pDecDynParams->newFrameFlag = XDAS_TRUE; //Not Supported: Set default | ||
171 | |||
172 | if( ((IVIDDEC3_Params *)(pVidDecComp->pDecStaticParams))->inputDataMode == IVIDEO_ENTIREFRAME ) | ||
173 | { | ||
174 | pDecDynParams->putBufferFxn = NULL; | ||
175 | pDecDynParams->putBufferHandle = NULL; | ||
176 | pDecDynParams->putDataFxn = NULL; | ||
177 | pDecDynParams->putDataHandle = NULL; | ||
178 | pDecDynParams->getDataHandle = NULL; | ||
179 | pDecDynParams->getDataFxn = NULL; | ||
180 | } | ||
181 | |||
182 | return; | ||
183 | } | ||
184 | |||
185 | /**/ | ||
186 | void OMXH264VD_Set_Status(OMX_HANDLETYPE hComponent, void *decstatus) | ||
187 | { | ||
188 | IH264VDEC_Status *status; | ||
189 | (void)hComponent; | ||
190 | |||
191 | status = (IH264VDEC_Status *)decstatus; | ||
192 | status->viddec3Status.size = sizeof(IH264VDEC_Status); | ||
193 | return; | ||
194 | } | ||
195 | |||
196 | PaddedBuffParams CalculateH264VD_outbuff_details(OMX_HANDLETYPE hComponent, OMX_U32 width, OMX_U32 height) | ||
197 | { | ||
198 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
199 | OMXVidDecComp *pVidDecComp = NULL; | ||
200 | OMXH264VidDecComp *pH264VidDecComp = NULL; | ||
201 | OMX_U32 nRefBufferCount=16; | ||
202 | IH264VDEC_Status *pDecStatus = NULL; | ||
203 | IH264VDEC_Params *staticparams; | ||
204 | |||
205 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
206 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
207 | pH264VidDecComp =(OMXH264VidDecComp *) pVidDecComp->pCodecSpecific; | ||
208 | |||
209 | pDecStatus = (IH264VDEC_Status *)(pVidDecComp->pDecStatus); | ||
210 | |||
211 | PaddedBuffParams OutBuffDetails; | ||
212 | OutBuffDetails.nBufferSize | ||
213 | = ((((width + (2 * PADX) + 127) & 0xFFFFFF80) * (height + 4 * PADY))); | ||
214 | /* Multiply buffer size by 1.5 to account for both luma and chroma */ | ||
215 | OutBuffDetails.nBufferSize = (OutBuffDetails.nBufferSize * 3) >> 1; | ||
216 | OutBuffDetails.nBufferCountMin = OMXH264VD_Calculate_TotalRefFrames(width, height, pH264VidDecComp->tH264VideoParam.eLevel); | ||
217 | staticparams = (IH264VDEC_Params *)(pVidDecComp->pDecStaticParams); | ||
218 | |||
219 | /* Assume 0 ref frames initially only if IL client is using port reconfig for allocating padded buffers. | ||
220 | * In that case use the correct ref frames at the time of port reconfig to calculate nBufferCountMin/Actual. | ||
221 | */ | ||
222 | if( pDecStatus->spsMaxRefFrames != 0 || pVidDecComp->bUsePortReconfigForPadding == OMX_TRUE ) { | ||
223 | if (pVidDecComp->bEnableDecodeZeroDisplayDelayMode == OMX_TRUE) { | ||
224 | staticparams->viddec3Params.displayDelay = IVIDDEC3_DECODE_ORDER; | ||
225 | } else { | ||
226 | staticparams->viddec3Params.displayDelay = pDecStatus->spsMaxRefFrames; | ||
227 | } | ||
228 | |||
229 | pH264VidDecComp->tH264VideoParam.nRefFrames = pDecStatus->spsMaxRefFrames; | ||
230 | if( pH264VidDecComp->tH264VideoParam.eProfile == OMX_VIDEO_AVCProfileBaseline ) { | ||
231 | /*Base profile*/ | ||
232 | OutBuffDetails.nBufferCountMin = pDecStatus->spsMaxRefFrames + 1; | ||
233 | } else { | ||
234 | /* High Profile */ | ||
235 | OutBuffDetails.nBufferCountMin = 2 * pDecStatus->spsMaxRefFrames + 1; | ||
236 | } | ||
237 | } else if( pH264VidDecComp->tH264VideoParam.nRefFrames == 0xFFFFFFFF ) { | ||
238 | if( pH264VidDecComp->tH264VideoParam.eProfile == OMX_VIDEO_AVCProfileBaseline ) { | ||
239 | OutBuffDetails.nBufferCountMin = OMXH264VD_Calculate_TotalRefFrames | ||
240 | (pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef.format.video.nFrameWidth, | ||
241 | pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef.format.video.nFrameHeight, | ||
242 | pH264VidDecComp->tH264VideoParam.eLevel); | ||
243 | } else { | ||
244 | nRefBufferCount = OMXH264VD_Calculate_TotalRefFrames | ||
245 | (pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef.format.video.nFrameWidth, | ||
246 | pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef.format.video.nFrameHeight, | ||
247 | pH264VidDecComp->tH264VideoParam.eLevel) - 1; | ||
248 | if((2 * nRefBufferCount + 1) < OMX_MAX_DEC_OP_BUFFERS ) { | ||
249 | OutBuffDetails.nBufferCountMin = 2 * nRefBufferCount + 1; | ||
250 | } else { | ||
251 | OutBuffDetails.nBufferCountMin = OMX_MAX_DEC_OP_BUFFERS; //Cap max buffers to 20 | ||
252 | } | ||
253 | } | ||
254 | } else if( pH264VidDecComp->tH264VideoParam.nRefFrames <= 16 ) { | ||
255 | if( pH264VidDecComp->tH264VideoParam.eProfile == OMX_VIDEO_AVCProfileBaseline ) { | ||
256 | OutBuffDetails.nBufferCountMin = pH264VidDecComp->tH264VideoParam.nRefFrames + 1; | ||
257 | } else { | ||
258 | OutBuffDetails.nBufferCountMin = 2 * pH264VidDecComp->tH264VideoParam.nRefFrames + 1; | ||
259 | } | ||
260 | } | ||
261 | OutBuffDetails.nBufferCountActual = OutBuffDetails.nBufferCountMin + 2; | ||
262 | OutBuffDetails.n1DBufferAlignment = 16; | ||
263 | OutBuffDetails.nPaddedWidth = (width + (2 * PADX) + 127) & 0xFFFFFF80; | ||
264 | OutBuffDetails.nPaddedHeight = height + 4 * PADY; | ||
265 | OutBuffDetails.n2DBufferYAlignment = 1; | ||
266 | OutBuffDetails.n2DBufferXAlignment = 16; | ||
267 | |||
268 | return (OutBuffDetails); | ||
269 | } | ||
270 | |||
271 | |||
272 | void OMXH264VD_DeInit(OMX_HANDLETYPE hComponent) | ||
273 | { | ||
274 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
275 | OMXVidDecComp *pVidDecComp = NULL; | ||
276 | |||
277 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
278 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
279 | /*! Delete all the memory which was allocated during init of decoder */ | ||
280 | if( pVidDecComp->pDecStaticParams ) { | ||
281 | memplugin_free(pVidDecComp->pDecStaticParams); | ||
282 | pVidDecComp->pDecStaticParams = NULL; | ||
283 | } | ||
284 | if( pVidDecComp->pDecDynParams ) { | ||
285 | memplugin_free(pVidDecComp->pDecDynParams); | ||
286 | pVidDecComp->pDecDynParams = NULL; | ||
287 | } | ||
288 | if( pVidDecComp->pDecStatus ) { | ||
289 | memplugin_free(pVidDecComp->pDecStatus); | ||
290 | pVidDecComp->pDecStatus = NULL; | ||
291 | } | ||
292 | if( pVidDecComp->pDecInArgs ) { | ||
293 | memplugin_free(pVidDecComp->pDecInArgs); | ||
294 | pVidDecComp->pDecInArgs = NULL; | ||
295 | } | ||
296 | if( pVidDecComp->pDecOutArgs ) { | ||
297 | memplugin_free(pVidDecComp->pDecOutArgs); | ||
298 | pVidDecComp->pDecOutArgs = NULL; | ||
299 | } | ||
300 | if( pVidDecComp->pCodecSpecific ) { | ||
301 | OSAL_Free(pVidDecComp->pCodecSpecific); | ||
302 | pVidDecComp->pCodecSpecific = NULL; | ||
303 | } | ||
304 | pHandle->SetParameter = OMXVidDec_SetParameter; | ||
305 | pHandle->GetParameter = OMXVidDec_GetParameter; | ||
306 | pVidDecComp->fpHandle_ExtendedError = NULL; | ||
307 | } | ||
308 | |||
309 | |||
310 | OMX_U32 OMXH264VD_Calculate_TotalRefFrames(OMX_U32 nWidth, OMX_U32 nHeight, OMX_VIDEO_AVCLEVELTYPE eLevel) | ||
311 | { | ||
312 | OMX_U32 ref_frames = 0; | ||
313 | OMX_U32 MaxDpbMbs; | ||
314 | OMX_U32 PicWidthInMbs; | ||
315 | OMX_U32 FrameHeightInMbs; | ||
316 | |||
317 | switch( eLevel ) { | ||
318 | case OMX_VIDEO_AVCLevel1 : | ||
319 | case OMX_VIDEO_AVCLevel1b : | ||
320 | { | ||
321 | MaxDpbMbs = 396; | ||
322 | break; | ||
323 | } | ||
324 | |||
325 | case OMX_VIDEO_AVCLevel11 : | ||
326 | { | ||
327 | MaxDpbMbs = 900; | ||
328 | break; | ||
329 | } | ||
330 | |||
331 | case OMX_VIDEO_AVCLevel12 : | ||
332 | case OMX_VIDEO_AVCLevel13 : | ||
333 | case OMX_VIDEO_AVCLevel2 : | ||
334 | { | ||
335 | MaxDpbMbs = 2376; | ||
336 | break; | ||
337 | } | ||
338 | |||
339 | case OMX_VIDEO_AVCLevel21 : | ||
340 | { | ||
341 | MaxDpbMbs = 4752; | ||
342 | break; | ||
343 | } | ||
344 | |||
345 | case OMX_VIDEO_AVCLevel22 : | ||
346 | case OMX_VIDEO_AVCLevel3 : | ||
347 | { | ||
348 | MaxDpbMbs = 8100; | ||
349 | break; | ||
350 | } | ||
351 | |||
352 | case OMX_VIDEO_AVCLevel31 : | ||
353 | { | ||
354 | MaxDpbMbs = 18000; | ||
355 | break; | ||
356 | } | ||
357 | |||
358 | case OMX_VIDEO_AVCLevel32 : | ||
359 | { | ||
360 | MaxDpbMbs = 20480; | ||
361 | break; | ||
362 | } | ||
363 | |||
364 | case OMX_VIDEO_AVCLevel5 : | ||
365 | { | ||
366 | MaxDpbMbs = 110400; //Maximum value for upto level 5 | ||
367 | break; | ||
368 | } | ||
369 | |||
370 | case OMX_VIDEO_AVCLevel51 : | ||
371 | { | ||
372 | MaxDpbMbs = 184320; //Maximum value for upto level 5.1 | ||
373 | break; | ||
374 | } | ||
375 | |||
376 | default : | ||
377 | { | ||
378 | MaxDpbMbs = 32768; //Maximum value for upto level 4.1 | ||
379 | } | ||
380 | } | ||
381 | |||
382 | PicWidthInMbs = nWidth / 16; | ||
383 | FrameHeightInMbs = nHeight / 16; | ||
384 | ref_frames = (OMX_U32)(MaxDpbMbs / (PicWidthInMbs * FrameHeightInMbs)); | ||
385 | |||
386 | ref_frames = (ref_frames > 16) ? 16 : ref_frames; | ||
387 | |||
388 | /* Three is added to total reference frames because of the N+3 buffer issue | ||
389 | * It was found that theoretically 2N+1 buffers are required but from a practical | ||
390 | * point of view N+3 was sufficient */ | ||
391 | return (ref_frames + 1); | ||
392 | } | ||
393 | |||
394 | |||
395 | OMX_ERRORTYPE OMXH264VD_SetParameter(OMX_HANDLETYPE hComponent, | ||
396 | OMX_INDEXTYPE nIndex, OMX_PTR pParamStruct) | ||
397 | { | ||
398 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
399 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
400 | OMXVidDecComp *pVidDecComp = NULL; | ||
401 | OMXH264VidDecComp *pH264VidDecComp = NULL; | ||
402 | OMX_VIDEO_PARAM_AVCTYPE *pH264VideoParam = NULL; | ||
403 | OMX_U32 nRefBufferCount = 0; | ||
404 | OMX_U8 i; | ||
405 | IH264VDEC_Params *staticparams; | ||
406 | |||
407 | OMX_CHECK((hComponent != NULL) && (pParamStruct != NULL), | ||
408 | OMX_ErrorBadParameter); | ||
409 | |||
410 | /*! Initialize the pointers */ | ||
411 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
412 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
413 | pH264VidDecComp = (OMXH264VidDecComp *) pVidDecComp->pCodecSpecific; | ||
414 | staticparams = (IH264VDEC_Params *)(pVidDecComp->pDecStaticParams); | ||
415 | |||
416 | switch( nIndex ) { | ||
417 | case OMX_IndexParamVideoAvc : | ||
418 | { | ||
419 | pH264VideoParam = (OMX_VIDEO_PARAM_AVCTYPE *) pParamStruct; | ||
420 | /* SetParameter can be invoked in Loaded State or on Disabled ports only*/ | ||
421 | OMX_CHECK((pVidDecComp->sBase.tCurState == OMX_StateLoaded) || | ||
422 | (pVidDecComp->sBase.pPorts[pH264VideoParam->nPortIndex]->sPortDef.bEnabled == OMX_FALSE), | ||
423 | OMX_ErrorIncorrectStateOperation); | ||
424 | |||
425 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_AVCTYPE, eError); | ||
426 | OMX_CHECK(pH264VideoParam->eProfile == OMX_VIDEO_AVCProfileBaseline | ||
427 | || pH264VideoParam->eProfile == OMX_VIDEO_AVCProfileMain | ||
428 | || pH264VideoParam->eProfile == OMX_VIDEO_AVCProfileExtended | ||
429 | || pH264VideoParam->eProfile == OMX_VIDEO_AVCProfileHigh, | ||
430 | OMX_ErrorUnsupportedSetting); | ||
431 | OMX_CHECK(pH264VideoParam->eLevel <= OMX_VIDEO_AVCLevel51, | ||
432 | OMX_ErrorUnsupportedSetting); | ||
433 | if( pH264VideoParam->nPortIndex == OMX_VIDDEC_INPUT_PORT ) { | ||
434 | pH264VidDecComp->tH264VideoParam = *pH264VideoParam; | ||
435 | } else if( pH264VideoParam->nPortIndex == OMX_VIDDEC_OUTPUT_PORT ) { | ||
436 | OSAL_ErrorTrace("OMX_IndexParamVideoAvc supported only on i/p port"); | ||
437 | eError = OMX_ErrorUnsupportedIndex; | ||
438 | goto EXIT; | ||
439 | } else { | ||
440 | eError = OMX_ErrorBadPortIndex; | ||
441 | } | ||
442 | ALOGE("Profile set = %x, Level Set = %x, num ref frames set = %d", | ||
443 | pH264VideoParam->eProfile, pH264VideoParam->eLevel, pH264VideoParam->nRefFrames); | ||
444 | if( pH264VideoParam->eLevel == OMX_VIDEO_AVCLevel5 ) { | ||
445 | staticparams->presetLevelIdc = IH264VDEC_LEVEL5; | ||
446 | } else if( pH264VideoParam->eLevel == OMX_VIDEO_AVCLevel51 ) { | ||
447 | staticparams->presetLevelIdc = IH264VDEC_LEVEL51; | ||
448 | } | ||
449 | if( pH264VidDecComp->tH264VideoParam.nRefFrames == 0xFFFFFFFF ) { | ||
450 | if( pH264VideoParam->eProfile == OMX_VIDEO_AVCProfileBaseline ) { | ||
451 | staticparams->viddec3Params.displayDelay = IVIDDEC3_DECODE_ORDER; | ||
452 | pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.nBufferCountMin = | ||
453 | OMXH264VD_Calculate_TotalRefFrames( | ||
454 | pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef.format.video.nFrameWidth, | ||
455 | pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef.format.video.nFrameHeight, | ||
456 | pH264VideoParam->eLevel); | ||
457 | } else { | ||
458 | nRefBufferCount = OMXH264VD_Calculate_TotalRefFrames | ||
459 | (pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef.format.video.nFrameWidth, | ||
460 | pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef.format.video.nFrameHeight, | ||
461 | pH264VideoParam->eLevel) - 1; | ||
462 | |||
463 | if (pVidDecComp->bEnableDecodeZeroDisplayDelayMode == OMX_TRUE) { | ||
464 | staticparams->viddec3Params.displayDelay = IVIDDEC3_DECODE_ORDER; | ||
465 | } else { | ||
466 | staticparams->viddec3Params.displayDelay = nRefBufferCount; | ||
467 | } | ||
468 | |||
469 | if((2 * nRefBufferCount + 1) < OMX_MAX_DEC_OP_BUFFERS ) { | ||
470 | pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.nBufferCountMin | ||
471 | = 2 * nRefBufferCount + 1; | ||
472 | } else { | ||
473 | pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.nBufferCountMin | ||
474 | = OMX_MAX_DEC_OP_BUFFERS; //Cap max buffers to 20 | ||
475 | } | ||
476 | } | ||
477 | } else if( pH264VidDecComp->tH264VideoParam.nRefFrames <= 16 ) { | ||
478 | if( pH264VideoParam->eProfile == OMX_VIDEO_AVCProfileBaseline ) { | ||
479 | staticparams->viddec3Params.displayDelay | ||
480 | = IVIDDEC3_DECODE_ORDER; | ||
481 | pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.nBufferCountMin | ||
482 | = pH264VidDecComp->tH264VideoParam.nRefFrames + 1; | ||
483 | } else { | ||
484 | if (pVidDecComp->bEnableDecodeZeroDisplayDelayMode == OMX_TRUE) { | ||
485 | staticparams->viddec3Params.displayDelay | ||
486 | = IVIDDEC3_DECODE_ORDER; | ||
487 | } else { | ||
488 | staticparams->viddec3Params.displayDelay | ||
489 | = pH264VidDecComp->tH264VideoParam.nRefFrames; | ||
490 | } | ||
491 | pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.nBufferCountMin = | ||
492 | 2 * pH264VidDecComp->tH264VideoParam.nRefFrames + 1; | ||
493 | } | ||
494 | } else { | ||
495 | OSAL_ErrorTrace("Invalid value of nRefFrames = %d of the structure OMX_VIDEO_PARAM_AVCTYPE provided ", | ||
496 | pH264VidDecComp->tH264VideoParam.nRefFrames); | ||
497 | } | ||
498 | } | ||
499 | break; | ||
500 | |||
501 | case OMX_IndexParamVideoProfileLevelQuerySupported : | ||
502 | { | ||
503 | /* SetParameter can be invoked in Loaded State or on Disabled ports only*/ | ||
504 | OMX_CHECK(pVidDecComp->sBase.tCurState == OMX_StateLoaded, | ||
505 | OMX_ErrorIncorrectStateOperation); | ||
506 | /* Check for the correct nSize & nVersion information */ | ||
507 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_PROFILELEVELTYPE, eError); | ||
508 | /*As of now do nothing. This i ndex is required for StdVideoDecoderTest. Later on do code review and fill in proper code here.*/ | ||
509 | eError = OMX_ErrorNoMore; | ||
510 | } | ||
511 | break; | ||
512 | |||
513 | case OMX_IndexParamVideoProfileLevelCurrent : | ||
514 | { | ||
515 | /* SetParameter can be invoked in Loaded State or on Disabled ports only*/ | ||
516 | OMX_CHECK(pVidDecComp->sBase.tCurState == OMX_StateLoaded, | ||
517 | OMX_ErrorIncorrectStateOperation); | ||
518 | /* Check for the correct nSize & nVersion information */ | ||
519 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_PROFILELEVELTYPE, eError); | ||
520 | /*As of now do nothing. This index is required for StdVideoDecoderTest. Later on do code review and fill in proper code here.*/ | ||
521 | eError = OMX_ErrorNoMore; | ||
522 | } | ||
523 | break; | ||
524 | |||
525 | default : | ||
526 | eError = OMXVidDec_SetParameter(hComponent, nIndex, pParamStruct); | ||
527 | } | ||
528 | |||
529 | EXIT: | ||
530 | return (eError); | ||
531 | } | ||
532 | |||
533 | |||
534 | OMX_ERRORTYPE OMXH264VD_GetParameter(OMX_HANDLETYPE hComponent, | ||
535 | OMX_INDEXTYPE nIndex, OMX_PTR pParamStruct) | ||
536 | { | ||
537 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
538 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
539 | OMXVidDecComp *pVidDecComp = NULL; | ||
540 | OMXH264VidDecComp *pH264VidDecComp = NULL; | ||
541 | OMX_VIDEO_PARAM_AVCTYPE *pH264VideoParam = NULL; | ||
542 | OMX_VIDEO_PARAM_PROFILELEVELTYPE *pH264ProfileLevelParam = NULL; | ||
543 | |||
544 | |||
545 | OMX_CHECK((hComponent != NULL) && | ||
546 | (pParamStruct != NULL), OMX_ErrorBadParameter); | ||
547 | |||
548 | // Initialize the local variables | ||
549 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
550 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
551 | |||
552 | pH264VidDecComp = (OMXH264VidDecComp *) pVidDecComp->pCodecSpecific; | ||
553 | |||
554 | /* GetParameter can't be invoked incase the comp is in Invalid State */ | ||
555 | OMX_CHECK(pVidDecComp->sBase.tCurState != OMX_StateInvalid, | ||
556 | OMX_ErrorIncorrectStateOperation); | ||
557 | |||
558 | switch( nIndex ) { | ||
559 | case OMX_IndexParamVideoAvc : | ||
560 | { | ||
561 | pH264VideoParam = (OMX_VIDEO_PARAM_AVCTYPE *) pParamStruct; | ||
562 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_AVCTYPE, eError); | ||
563 | if( pH264VideoParam->nPortIndex == OMX_VIDDEC_INPUT_PORT ) { | ||
564 | *pH264VideoParam = pH264VidDecComp->tH264VideoParam; | ||
565 | } else if( pH264VideoParam->nPortIndex == OMX_VIDDEC_OUTPUT_PORT ) { | ||
566 | OSAL_ErrorTrace("OMX_IndexParamVideoAvc supported only on i/p port"); | ||
567 | eError = OMX_ErrorUnsupportedIndex; | ||
568 | } else { | ||
569 | eError = OMX_ErrorBadPortIndex; | ||
570 | } | ||
571 | } | ||
572 | break; | ||
573 | |||
574 | case OMX_IndexParamVideoProfileLevelQuerySupported : | ||
575 | { | ||
576 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_PROFILELEVELTYPE, eError); | ||
577 | pH264ProfileLevelParam = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pParamStruct; | ||
578 | if( pH264ProfileLevelParam->nPortIndex == OMX_VIDDEC_INPUT_PORT ) { | ||
579 | if( pH264ProfileLevelParam->nProfileIndex == 0 ) { | ||
580 | pH264ProfileLevelParam->eProfile = (OMX_U32) OMX_VIDEO_AVCProfileBaseline; | ||
581 | pH264ProfileLevelParam->eLevel = (OMX_U32) OMX_VIDEO_AVCLevel41; | ||
582 | } else if( pH264ProfileLevelParam->nProfileIndex == 1 ) { | ||
583 | pH264ProfileLevelParam->eProfile = (OMX_U32) OMX_VIDEO_AVCProfileMain; | ||
584 | pH264ProfileLevelParam->eLevel = (OMX_U32) OMX_VIDEO_AVCLevel41; | ||
585 | } else if( pH264ProfileLevelParam->nProfileIndex == 2 ) { | ||
586 | pH264ProfileLevelParam->eProfile = (OMX_U32) OMX_VIDEO_AVCProfileHigh; | ||
587 | pH264ProfileLevelParam->eLevel = (OMX_U32) OMX_VIDEO_AVCLevel41; | ||
588 | } else { | ||
589 | eError = OMX_ErrorNoMore; | ||
590 | } | ||
591 | } else if( pH264ProfileLevelParam->nPortIndex == OMX_VIDDEC_OUTPUT_PORT ) { | ||
592 | OSAL_ErrorTrace("OMX_IndexParamVideoProfileLevelQuerySupported supported only on i/p port"); | ||
593 | eError = OMX_ErrorUnsupportedIndex; | ||
594 | } else { | ||
595 | eError = OMX_ErrorBadPortIndex; | ||
596 | } | ||
597 | } | ||
598 | break; | ||
599 | |||
600 | case OMX_IndexParamVideoProfileLevelCurrent : | ||
601 | { | ||
602 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_PROFILELEVELTYPE, eError); | ||
603 | eError = OMX_ErrorNoMore; | ||
604 | } | ||
605 | break; | ||
606 | |||
607 | case OMX_IndexParamVideoMacroblocksPerFrame : | ||
608 | { | ||
609 | OMX_U32 MBwidth = 0, MBheight = 0; | ||
610 | /* Check for the correct nSize & nVersion information */ | ||
611 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_PARAM_MACROBLOCKSTYPE, eError); | ||
612 | MBwidth = (pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.format.video.nFrameWidth) / 16; | ||
613 | MBwidth = MBwidth + ((pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.format.video.nFrameWidth) % 16); | ||
614 | MBheight = pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.format.video.nFrameHeight / 16; | ||
615 | MBheight = MBheight + ((pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.format.video.nFrameHeight) % 16); | ||
616 | ((OMX_PARAM_MACROBLOCKSTYPE *)(pParamStruct))->nMacroblocks = MBwidth * MBheight; | ||
617 | } | ||
618 | break; | ||
619 | |||
620 | default : | ||
621 | eError = OMXVidDec_GetParameter(hComponent, nIndex, pParamStruct); | ||
622 | } | ||
623 | |||
624 | EXIT: | ||
625 | return (eError); | ||
626 | } | ||
627 | |||
628 | /* */ | ||
629 | OMX_ERRORTYPE OMXH264VD_HandleError(OMX_HANDLETYPE hComponent) | ||
630 | { | ||
631 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
632 | OMX_U32 nRefFramesOld, nRefFrames41, nRefFrames5; | ||
633 | OMXH264VidDecComp *pH264VidDecComp = NULL; | ||
634 | IH264VDEC_Params *staticparams = NULL; | ||
635 | IH264VDEC_Status *pDecStatus = NULL; | ||
636 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
637 | OMXVidDecComp *pVidDecComp = NULL; | ||
638 | OMX_U32 nBufferCountMin_old = 0; | ||
639 | |||
640 | /* Initialize pointers */ | ||
641 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
642 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
643 | staticparams = (IH264VDEC_Params *)(pVidDecComp->pDecStaticParams); | ||
644 | pH264VidDecComp =(OMXH264VidDecComp *) pVidDecComp->pCodecSpecific; | ||
645 | |||
646 | pDecStatus = (IH264VDEC_Status *)(pVidDecComp->pDecStatus); | ||
647 | if( pH264VidDecComp->tH264VideoParam.nRefFrames == 0xFFFFFFFF ) { | ||
648 | nRefFramesOld = OMXH264VD_Calculate_TotalRefFrames | ||
649 | (pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef.format.video.nFrameWidth, | ||
650 | pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef.format.video.nFrameHeight, | ||
651 | pH264VidDecComp->tH264VideoParam.eLevel) - 1; | ||
652 | } else { | ||
653 | nRefFramesOld = pH264VidDecComp->tH264VideoParam.nRefFrames; | ||
654 | } | ||
655 | nRefFrames41 = OMXH264VD_Calculate_TotalRefFrames | ||
656 | (pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef.format.video.nFrameWidth, | ||
657 | pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef.format.video.nFrameHeight, | ||
658 | OMX_VIDEO_AVCLevel41) - 1; | ||
659 | nRefFrames5 = OMXH264VD_Calculate_TotalRefFrames | ||
660 | (pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef.format.video.nFrameWidth, | ||
661 | pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef.format.video.nFrameHeight, | ||
662 | OMX_VIDEO_AVCLevel5) - 1; | ||
663 | nBufferCountMin_old = pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.nBufferCountMin; | ||
664 | if( pDecStatus->spsMaxRefFrames > nRefFramesOld ) { | ||
665 | ALOGE("spsMaxRefFrames = %d, nRefFrames set initially = %d", | ||
666 | (OMX_U32)pDecStatus->spsMaxRefFrames, pH264VidDecComp->tH264VideoParam.nRefFrames); | ||
667 | pH264VidDecComp->tH264VideoParam.nRefFrames | ||
668 | = pDecStatus->spsMaxRefFrames; | ||
669 | staticparams->viddec3Params.displayDelay | ||
670 | = pDecStatus->spsMaxRefFrames; | ||
671 | if( pH264VidDecComp->tH264VideoParam.eProfile == OMX_VIDEO_AVCProfileBaseline ) { | ||
672 | staticparams->viddec3Params.displayDelay = IVIDDEC3_DECODE_ORDER; | ||
673 | pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.nBufferCountMin | ||
674 | = pH264VidDecComp->tH264VideoParam.nRefFrames + 1; | ||
675 | pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.nBufferCountActual | ||
676 | = pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.nBufferCountMin + 2; | ||
677 | } else { | ||
678 | if (pVidDecComp->bEnableDecodeZeroDisplayDelayMode == OMX_TRUE) { | ||
679 | staticparams->viddec3Params.displayDelay | ||
680 | = IVIDDEC3_DECODE_ORDER; | ||
681 | } else { | ||
682 | staticparams->viddec3Params.displayDelay = pDecStatus->spsMaxRefFrames; | ||
683 | } | ||
684 | |||
685 | pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.nBufferCountMin | ||
686 | = 2 * pH264VidDecComp->tH264VideoParam.nRefFrames + 1; | ||
687 | pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.nBufferCountActual | ||
688 | = pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.nBufferCountMin + 2; | ||
689 | } | ||
690 | if( pDecStatus->spsMaxRefFrames > nRefFrames5 ) { | ||
691 | pH264VidDecComp->tH264VideoParam.eLevel = OMX_VIDEO_AVCLevel51; | ||
692 | staticparams->presetLevelIdc = IH264VDEC_LEVEL51; | ||
693 | OSAL_ErrorTrace("Resetting level of the stream to Level 5.1"); | ||
694 | pVidDecComp->nCodecRecreationRequired = 1; | ||
695 | pVidDecComp->nOutPortReconfigRequired = 1; | ||
696 | } else if( pDecStatus->spsMaxRefFrames > nRefFrames41 ) { | ||
697 | pH264VidDecComp->tH264VideoParam.eLevel = OMX_VIDEO_AVCLevel5; | ||
698 | staticparams->presetLevelIdc = IH264VDEC_LEVEL5; | ||
699 | OSAL_ErrorTrace("Resetting level of the stream to Level 5"); | ||
700 | pVidDecComp->nCodecRecreationRequired = 1; | ||
701 | pVidDecComp->nOutPortReconfigRequired = 1; | ||
702 | } else if( pDecStatus->spsMaxRefFrames > nRefFramesOld ) { | ||
703 | pH264VidDecComp->tH264VideoParam.eLevel = OMX_VIDEO_AVCLevel41; | ||
704 | OSAL_ErrorTrace("Resetting level of the stream to Level 4.1"); | ||
705 | } | ||
706 | if( pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.nBufferCountMin | ||
707 | > nBufferCountMin_old ) { | ||
708 | OSAL_ErrorTrace("nBufferCountMin_old = %d, nBufferCountMin_new = %d", | ||
709 | nBufferCountMin_old, pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.nBufferCountMin); | ||
710 | pVidDecComp->nOutPortReconfigRequired = 1; | ||
711 | pVidDecComp->nCodecRecreationRequired = 1; | ||
712 | } | ||
713 | } | ||
714 | |||
715 | return (eError); | ||
716 | } | ||
717 | |||
diff --git a/libstagefrighthw/omx/videodecode/omx_video_decoder_h264.h b/libstagefrighthw/omx/videodecode/omx_video_decoder_h264.h new file mode 100644 index 0000000..b01a3ed --- /dev/null +++ b/libstagefrighthw/omx/videodecode/omx_video_decoder_h264.h | |||
@@ -0,0 +1,67 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 _OMX_H264VD_H_ | ||
18 | #define _OMX_H264VD_H_ | ||
19 | |||
20 | #ifdef __cplusplus | ||
21 | extern "C" { | ||
22 | #endif | ||
23 | |||
24 | #include <omx_video_decoder.h> | ||
25 | #include <ti/sdo/codecs/h264vdec/ih264vdec.h> | ||
26 | |||
27 | /*! Padding for width as per Codec Requirement */ | ||
28 | #define PADX (32) | ||
29 | /*! Padding for height as per Codec requirement */ | ||
30 | #define PADY (24) | ||
31 | |||
32 | /** Default Frame skip H264 Decoder */ | ||
33 | #define H264VD_DEFAULT_FRAME_SKIP IVIDEO_SKIP_DEFAULT | ||
34 | |||
35 | |||
36 | static OMX_ERRORTYPE OMXH264VD_GetParameter(OMX_HANDLETYPE hComponent, | ||
37 | OMX_INDEXTYPE nIndex, OMX_PTR pParamStruct); | ||
38 | |||
39 | static OMX_ERRORTYPE OMXH264VD_SetParameter(OMX_HANDLETYPE hComponent, | ||
40 | OMX_INDEXTYPE nIndex, OMX_PTR pParamStruct); | ||
41 | |||
42 | void OMXH264VD_Set_StaticParams(OMX_HANDLETYPE hComponent, void *staticparams); | ||
43 | |||
44 | void OMXH264VD_Set_DynamicParams(OMX_HANDLETYPE hComponent, void *dynamicParams); | ||
45 | |||
46 | void OMXH264VD_Set_Status(OMX_HANDLETYPE hComponent, void *status); | ||
47 | |||
48 | OMX_ERRORTYPE OMXH264VD_HandleError(OMX_HANDLETYPE hComponent); | ||
49 | |||
50 | PaddedBuffParams CalculateH264VD_outbuff_details(OMX_HANDLETYPE hComponent, | ||
51 | OMX_U32 width, OMX_U32 height); | ||
52 | |||
53 | extern OMX_ERRORTYPE OMXH264VD_Init(OMX_HANDLETYPE hComponent); | ||
54 | extern void OMXH264VD_DeInit(OMX_HANDLETYPE hComponent); | ||
55 | extern OMX_U32 OMXH264VD_Calculate_TotalRefFrames(OMX_U32 nWidth, OMX_U32 nHeight, OMX_VIDEO_AVCLEVELTYPE eLevel); | ||
56 | |||
57 | typedef struct OMXH264VidDecComp { | ||
58 | OMX_VIDEO_PARAM_AVCTYPE tH264VideoParam; | ||
59 | } OMXH264VidDecComp; | ||
60 | |||
61 | |||
62 | #ifdef __cplusplus | ||
63 | } | ||
64 | #endif | ||
65 | |||
66 | #endif /* _OMX_H2644VD_NEW_H_ */ | ||
67 | |||
diff --git a/libstagefrighthw/omx/videodecode/omx_video_decoder_internal.c b/libstagefrighthw/omx/videodecode/omx_video_decoder_internal.c new file mode 100644 index 0000000..0589c78 --- /dev/null +++ b/libstagefrighthw/omx/videodecode/omx_video_decoder_internal.c | |||
@@ -0,0 +1,945 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 | #define LOG_TAG "OMX_VIDDEC_INTERNAL" | ||
18 | |||
19 | #include <omx_video_decoder_internal.h> | ||
20 | #include <libdce.h> | ||
21 | |||
22 | #define OMX_VIDDEC_DEFAULT_INBUF_WIDTH 1024 | ||
23 | #define OMX_VIDDEC_DEFAULT_INBUF_HEIGHT 1024 | ||
24 | |||
25 | OMX_ERRORTYPE OMXVidDec_InitFields(OMXVidDecComp *pVidDecComp) | ||
26 | { | ||
27 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
28 | hw_module_t const* module; | ||
29 | OMX_U32 i = 0; | ||
30 | |||
31 | pVidDecComp->sBase.cComponentName = (OMX_STRING )OSAL_Malloc(sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE); | ||
32 | OMX_CHECK(pVidDecComp->sBase.cComponentName != NULL, OMX_ErrorInsufficientResources); | ||
33 | |||
34 | /* Initialize Video Port parameters */ | ||
35 | pVidDecComp->sBase.pVideoPortParams = (OMX_PORT_PARAM_TYPE*)OSAL_Malloc(sizeof(OMX_PORT_PARAM_TYPE)); | ||
36 | |||
37 | OMX_BASE_INIT_STRUCT_PTR(pVidDecComp->sBase.pVideoPortParams, OMX_PORT_PARAM_TYPE); | ||
38 | pVidDecComp->sBase.pVideoPortParams->nPorts = OMX_VIDDEC_NUM_OF_PORTS; | ||
39 | pVidDecComp->sBase.pVideoPortParams->nStartPortNumber = OMX_VIDDEC_DEFAULT_START_PORT_NUM; | ||
40 | pVidDecComp->sBase.nNumPorts = OMX_VIDDEC_NUM_OF_PORTS; | ||
41 | pVidDecComp->sBase.nMinStartPortIndex = OMX_VIDDEC_DEFAULT_START_PORT_NUM; | ||
42 | |||
43 | pVidDecComp->sBase.nComponentVersion.s.nVersionMajor = OMX_VIDDEC_COMP_VERSION_MAJOR; | ||
44 | pVidDecComp->sBase.nComponentVersion.s.nVersionMinor = OMX_VIDDEC_COMP_VERSION_MINOR; | ||
45 | pVidDecComp->sBase.nComponentVersion.s.nRevision = OMX_VIDDEC_COMP_VERSION_REVISION; | ||
46 | pVidDecComp->sBase.nComponentVersion.s.nStep = OMX_VIDDEC_COMP_VERSION_STEP; | ||
47 | |||
48 | eError = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module); | ||
49 | if (eError == 0) { | ||
50 | pVidDecComp->grallocModule = (gralloc_module_t const *)module; | ||
51 | } else { | ||
52 | eError = OMX_ErrorInsufficientResources; | ||
53 | } | ||
54 | |||
55 | EXIT: | ||
56 | return (eError); | ||
57 | } | ||
58 | |||
59 | /* | ||
60 | */ | ||
61 | void OMXVidDec_InitPortDefs(OMX_HANDLETYPE hComponent, OMXVidDecComp *pVidDecComp) | ||
62 | { | ||
63 | OMXBaseComp *pBaseComp = &(pVidDecComp->sBase); | ||
64 | |||
65 | OMX_PARAM_PORTDEFINITIONTYPE *inPortDefs = &(pBaseComp->pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef); | ||
66 | OMX_PARAM_PORTDEFINITIONTYPE *outPortDefs= &(pBaseComp->pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef); | ||
67 | |||
68 | /* set the default/Actual values of an Input port */ | ||
69 | inPortDefs->nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); | ||
70 | inPortDefs->nVersion = pBaseComp->nComponentVersion; | ||
71 | inPortDefs->bEnabled = OMX_TRUE; | ||
72 | inPortDefs->bPopulated = OMX_FALSE; | ||
73 | inPortDefs->eDir = OMX_DirInput; | ||
74 | inPortDefs->nPortIndex = OMX_VIDDEC_INPUT_PORT; | ||
75 | inPortDefs->nBufferCountMin = OMX_VIDDEC_MIN_IN_BUF_COUNT; | ||
76 | inPortDefs->nBufferCountActual = OMX_VIDDEC_DEFAULT_IN_BUF_COUNT; | ||
77 | inPortDefs->nBufferSize = Calc_InbufSize(OMX_VIDDEC_DEFAULT_INBUF_WIDTH, | ||
78 | OMX_VIDDEC_DEFAULT_INBUF_HEIGHT); | ||
79 | |||
80 | inPortDefs->eDomain = OMX_PortDomainVideo; | ||
81 | inPortDefs->bBuffersContiguous = OMX_TRUE; | ||
82 | inPortDefs->nBufferAlignment = OMX_VIDDEC_DEFAULT_1D_INPUT_BUFFER_ALIGNMENT; | ||
83 | inPortDefs->format.video.cMIMEType= NULL; | ||
84 | inPortDefs->format.video.pNativeRender = NULL; | ||
85 | inPortDefs->format.video.nFrameWidth = OMX_VIDDEC_DEFAULT_FRAME_WIDTH; | ||
86 | inPortDefs->format.video.nFrameHeight = OMX_VIDDEC_DEFAULT_FRAME_HEIGHT; | ||
87 | inPortDefs->format.video.nStride = 0; | ||
88 | inPortDefs->format.video.nSliceHeight = 0; | ||
89 | inPortDefs->format.video.nBitrate = 0; | ||
90 | inPortDefs->format.video.xFramerate = OMX_VIDEODECODER_DEFAULT_FRAMERATE << 16; | ||
91 | inPortDefs->format.video.bFlagErrorConcealment = OMX_TRUE; | ||
92 | inPortDefs->format.video.eCompressionFormat = pVidDecComp->tVideoParams[OMX_VIDDEC_INPUT_PORT].eCompressionFormat; | ||
93 | inPortDefs->format.video.eColorFormat = OMX_COLOR_FormatUnused; | ||
94 | |||
95 | /* set the default/Actual values of an output port */ | ||
96 | outPortDefs->nSize = sizeof(OMX_PARAM_PORTDEFINITIONTYPE); | ||
97 | outPortDefs->nVersion = pVidDecComp->sBase.nComponentVersion; | ||
98 | outPortDefs->bEnabled = OMX_TRUE; | ||
99 | outPortDefs->bPopulated = OMX_FALSE; | ||
100 | outPortDefs->eDir = OMX_DirOutput; | ||
101 | outPortDefs->nPortIndex = OMX_VIDDEC_OUTPUT_PORT; | ||
102 | outPortDefs->nBufferCountMin = pVidDecComp->fpCalc_OubuffDetails(hComponent, | ||
103 | OMX_VIDDEC_DEFAULT_FRAME_WIDTH, | ||
104 | OMX_VIDDEC_DEFAULT_FRAME_HEIGHT).nBufferCountMin; | ||
105 | outPortDefs->nBufferCountActual = pVidDecComp->fpCalc_OubuffDetails(hComponent, | ||
106 | OMX_VIDDEC_DEFAULT_FRAME_WIDTH, | ||
107 | OMX_VIDDEC_DEFAULT_FRAME_HEIGHT).nBufferCountActual; | ||
108 | |||
109 | outPortDefs->nBufferSize = pVidDecComp->fpCalc_OubuffDetails(hComponent, | ||
110 | OMX_VIDDEC_DEFAULT_FRAME_WIDTH, | ||
111 | OMX_VIDDEC_DEFAULT_FRAME_HEIGHT).nBufferSize; | ||
112 | outPortDefs->eDomain = OMX_PortDomainVideo; | ||
113 | outPortDefs->bBuffersContiguous = OMX_TRUE; | ||
114 | outPortDefs->nBufferAlignment = pVidDecComp->fpCalc_OubuffDetails(hComponent, | ||
115 | OMX_VIDDEC_DEFAULT_FRAME_WIDTH, | ||
116 | OMX_VIDDEC_DEFAULT_FRAME_HEIGHT).n1DBufferAlignment; | ||
117 | outPortDefs->format.video.cMIMEType = NULL; | ||
118 | outPortDefs->format.video.pNativeRender = NULL; | ||
119 | outPortDefs->format.video.nFrameWidth = OMX_VIDDEC_DEFAULT_FRAME_WIDTH; | ||
120 | outPortDefs->format.video.nFrameHeight = OMX_VIDDEC_DEFAULT_FRAME_HEIGHT; | ||
121 | outPortDefs->format.video.nStride = OMX_VIDDEC_DEFAULT_STRIDE; | ||
122 | outPortDefs->format.video.nSliceHeight = OMX_VIDDEC_DEFAULT_FRAME_HEIGHT; | ||
123 | outPortDefs->format.video.nBitrate = 0; | ||
124 | outPortDefs->format.video.xFramerate = OMX_VIDEODECODER_DEFAULT_FRAMERATE << 16; | ||
125 | outPortDefs->format.video.bFlagErrorConcealment = OMX_TRUE; | ||
126 | outPortDefs->format.video.eCompressionFormat = pVidDecComp->tVideoParams[OMX_VIDDEC_OUTPUT_PORT].eCompressionFormat; | ||
127 | outPortDefs->format.video.eColorFormat = OMX_COLOR_FormatYUV420PackedSemiPlanar; | ||
128 | } | ||
129 | |||
130 | |||
131 | void OMXVidDec_InitPortParams(OMXVidDecComp *pVidDecComp) | ||
132 | { | ||
133 | OMX_VIDEO_PARAM_PORTFORMATTYPE *tInPortVideoParam | ||
134 | = &(pVidDecComp->tVideoParams[OMX_VIDDEC_INPUT_PORT]); | ||
135 | OMX_VIDEO_PARAM_PORTFORMATTYPE *tOutPortVideoParam | ||
136 | = &(pVidDecComp->tVideoParams[OMX_VIDDEC_OUTPUT_PORT]); | ||
137 | |||
138 | // Initialize Input Video Port Param | ||
139 | tInPortVideoParam->nSize = sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE); | ||
140 | tInPortVideoParam->nVersion = pVidDecComp->sBase.nComponentVersion; | ||
141 | tInPortVideoParam->nPortIndex = OMX_VIDDEC_INPUT_PORT; | ||
142 | tInPortVideoParam->nIndex = 0; | ||
143 | tInPortVideoParam->eCompressionFormat = pVidDecComp->tVideoParams[OMX_VIDDEC_INPUT_PORT].eCompressionFormat; | ||
144 | tInPortVideoParam->eColorFormat = OMX_COLOR_FormatUnused; | ||
145 | tInPortVideoParam->xFramerate = OMX_VIDEODECODER_DEFAULT_FRAMERATE; | ||
146 | |||
147 | // Initialize Output Video Port Param | ||
148 | tOutPortVideoParam->nSize = sizeof(OMX_VIDEO_PARAM_PORTFORMATTYPE); | ||
149 | tOutPortVideoParam->nVersion = pVidDecComp->sBase.nComponentVersion; | ||
150 | tOutPortVideoParam->nPortIndex = OMX_VIDDEC_OUTPUT_PORT; | ||
151 | tOutPortVideoParam->nIndex = 1; | ||
152 | tOutPortVideoParam->eCompressionFormat = pVidDecComp->tVideoParams[OMX_VIDDEC_OUTPUT_PORT].eCompressionFormat; | ||
153 | tOutPortVideoParam->eColorFormat = OMX_COLOR_FormatYUV420PackedSemiPlanar; | ||
154 | tOutPortVideoParam->xFramerate = OMX_VIDEODECODER_DEFAULT_FRAMERATE; | ||
155 | } | ||
156 | |||
157 | void OMXVidDec_InitDecoderParams(OMX_HANDLETYPE hComponent, | ||
158 | OMXVidDecComp *pVidDecComp) | ||
159 | { | ||
160 | OMX_U32 outPort = (OMX_U32)OMX_VIDDEC_OUTPUT_PORT; | ||
161 | OMX_PARAM_PORTDEFINITIONTYPE *pOutputPortDef = &(pVidDecComp->sBase.pPorts[outPort]->sPortDef); | ||
162 | OMX_CONFIG_RECTTYPE *p2DOutBufAllocParam = &(pVidDecComp->t2DBufferAllocParams[outPort]); | ||
163 | |||
164 | OMXVidDec_InitPortDefs(hComponent, pVidDecComp); | ||
165 | OMXVidDec_InitPortParams(pVidDecComp); | ||
166 | OMXVidDec_Set2DBuffParams(hComponent, pVidDecComp); | ||
167 | pOutputPortDef->format.video.nStride = p2DOutBufAllocParam->nWidth; | ||
168 | |||
169 | pVidDecComp->pDecStaticParams->maxHeight = OMX_VIDDEC_DEFAULT_FRAME_HEIGHT; | ||
170 | pVidDecComp->pDecStaticParams->maxWidth = OMX_VIDDEC_DEFAULT_FRAME_WIDTH; | ||
171 | |||
172 | /* Call Decoder Specific function to set Static Params */ | ||
173 | pVidDecComp->fpSet_StaticParams(hComponent, pVidDecComp->pDecStaticParams); | ||
174 | return; | ||
175 | } | ||
176 | |||
177 | |||
178 | void OMXVidDec_Set2DBuffParams(OMX_HANDLETYPE hComponent, OMXVidDecComp *pVidDecComp) | ||
179 | { | ||
180 | OMX_U32 outPort = (OMX_U32)OMX_VIDDEC_OUTPUT_PORT; | ||
181 | OMX_U32 inPort = (OMX_U32)OMX_VIDDEC_INPUT_PORT; | ||
182 | OMX_CONFIG_RECTTYPE *p2DOutBufAllocParam = &(pVidDecComp->t2DBufferAllocParams[outPort]); | ||
183 | OMX_CONFIG_RECTTYPE *p2DInBufAllocParam = &(pVidDecComp->t2DBufferAllocParams[inPort]); | ||
184 | |||
185 | PaddedBuffParams outBuffParams; | ||
186 | OMX_U32 nFrameWidth, nFrameHeight; | ||
187 | |||
188 | p2DOutBufAllocParam->nSize = sizeof(OMX_CONFIG_RECTTYPE); | ||
189 | p2DOutBufAllocParam->nVersion = pVidDecComp->sBase.nComponentVersion; | ||
190 | p2DOutBufAllocParam->nPortIndex = outPort; | ||
191 | |||
192 | nFrameWidth = pVidDecComp->sBase.pPorts[inPort]->sPortDef.format.video.nFrameWidth; | ||
193 | nFrameHeight = pVidDecComp->sBase.pPorts[inPort]->sPortDef.format.video.nFrameHeight; | ||
194 | if( nFrameWidth & 0x0F ) { | ||
195 | nFrameWidth = nFrameWidth + 16 - (nFrameWidth & 0x0F); | ||
196 | } | ||
197 | if( nFrameHeight & 0x1F ) { | ||
198 | nFrameHeight = nFrameHeight + 32 - (nFrameHeight & 0x1F); | ||
199 | } | ||
200 | outBuffParams = pVidDecComp->fpCalc_OubuffDetails(hComponent, nFrameWidth, nFrameHeight); | ||
201 | |||
202 | p2DOutBufAllocParam->nWidth = outBuffParams.nPaddedWidth; | ||
203 | p2DOutBufAllocParam->nHeight = outBuffParams.nPaddedHeight; | ||
204 | p2DOutBufAllocParam->nLeft = outBuffParams.n2DBufferXAlignment; | ||
205 | p2DOutBufAllocParam->nTop = outBuffParams.n2DBufferYAlignment; | ||
206 | |||
207 | p2DInBufAllocParam->nSize = sizeof(OMX_CONFIG_RECTTYPE); | ||
208 | p2DInBufAllocParam->nVersion = pVidDecComp->sBase.nComponentVersion; | ||
209 | p2DInBufAllocParam->nPortIndex = OMX_VIDDEC_INPUT_PORT; | ||
210 | p2DInBufAllocParam->nWidth = pVidDecComp->sBase.pPorts[inPort]->sPortDef.nBufferSize; | ||
211 | p2DInBufAllocParam->nHeight = 1; //On input port only 1D buffers supported. | ||
212 | p2DInBufAllocParam->nLeft = pVidDecComp->sBase.pPorts[inPort]->sPortDef.nBufferAlignment; | ||
213 | p2DInBufAllocParam->nTop = 1; | ||
214 | } | ||
215 | |||
216 | |||
217 | OMX_ERRORTYPE OMXVidDec_HandleFLUSH_EOS(OMX_HANDLETYPE hComponent, | ||
218 | OMX_BUFFERHEADERTYPE *pLastOutBufHeader, | ||
219 | OMX_BUFFERHEADERTYPE *pInBufHeader) | ||
220 | { | ||
221 | OMX_ERRORTYPE eError = OMX_ErrorNone, eRMError = OMX_ErrorNone; | ||
222 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
223 | OMX_BUFFERHEADERTYPE *pDupBufHeader = NULL; | ||
224 | OMXVidDecComp *pVidDecComp = NULL; | ||
225 | OMX_U32 i = 0; | ||
226 | OMX_U32 nStride; | ||
227 | IVIDDEC3_OutArgs *pDecOutArgs = NULL; | ||
228 | OMX_U32 outPort = (OMX_U32)OMX_VIDDEC_OUTPUT_PORT; | ||
229 | OMX_CONFIG_RECTTYPE *p2DOutBufAllocParam = NULL; | ||
230 | XDAS_Int32 status; | ||
231 | uint32_t nActualSize; | ||
232 | IMG_native_handle_t* grallocHandle; | ||
233 | OMX_PARAM_PORTDEFINITIONTYPE *pOutputPortDef = NULL; | ||
234 | XDM_Rect activeFrameRegion[2]; | ||
235 | |||
236 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
237 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
238 | pDecOutArgs = pVidDecComp->pDecOutArgs; | ||
239 | p2DOutBufAllocParam = &(pVidDecComp->t2DBufferAllocParams[outPort]); | ||
240 | |||
241 | pOutputPortDef = &(pVidDecComp->sBase.pPorts[outPort]->sPortDef); | ||
242 | /*! Ensure that the stride on output portdef structure is more than | ||
243 | the padded width. This is needed in the case where application | ||
244 | sets the Stride less than padded width */ | ||
245 | if( (OMX_U32)pOutputPortDef->format.video.nStride >= | ||
246 | p2DOutBufAllocParam->nWidth ) { | ||
247 | nStride = pOutputPortDef->format.video.nStride; | ||
248 | } else { | ||
249 | nStride = p2DOutBufAllocParam->nWidth; | ||
250 | } | ||
251 | |||
252 | if( pVidDecComp->nFrameCounter > 0 ) { | ||
253 | /* Call codec flush and call process call until error */ | ||
254 | OMX_CHECK(((pVidDecComp->pDecDynParams != NULL) && (pVidDecComp->pDecStatus != NULL)), OMX_ErrorBadParameter); | ||
255 | status = VIDDEC3_control(pVidDecComp->pDecHandle, XDM_FLUSH, pVidDecComp->pDecDynParams, pVidDecComp->pDecStatus); | ||
256 | if( status != VIDDEC3_EOK ) { | ||
257 | OSAL_ErrorTrace("VIDDEC3_control XDM_FLUSH failed ....! \n"); | ||
258 | eError = OMX_ErrorInsufficientResources; | ||
259 | goto EXIT; | ||
260 | } | ||
261 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
262 | do { | ||
263 | pVidDecComp->tOutBufDesc->numBufs = 0; | ||
264 | pVidDecComp->tInBufDesc->numBufs = 0; | ||
265 | status = VIDDEC3_process(pVidDecComp->pDecHandle, (XDM2_BufDesc *)pVidDecComp->tInBufDesc, | ||
266 | (XDM2_BufDesc *)pVidDecComp->tOutBufDesc, | ||
267 | (VIDDEC3_InArgs *)pVidDecComp->pDecInArgs, | ||
268 | (VIDDEC3_OutArgs *)pVidDecComp->pDecOutArgs); | ||
269 | |||
270 | /*! In case this is an IPC failure */ | ||
271 | if(status == DCE_EIPC_CALL_FAIL) { | ||
272 | ALOGE("\n Remote Core Communication Failure... \n"); | ||
273 | eError = OMX_ErrorHardware; | ||
274 | pVidDecComp->bIPCRecoveryNeeded = OMX_TRUE; | ||
275 | goto EXIT; | ||
276 | } | ||
277 | |||
278 | if( status != XDM_EFAIL ) { | ||
279 | /* Send the buffers out */ | ||
280 | i = 0; | ||
281 | while( pDecOutArgs->outputID[i] ) { | ||
282 | pDupBufHeader = (OMX_BUFFERHEADERTYPE *)pDecOutArgs->outputID[i]; | ||
283 | if( pVidDecComp->bSupportDecodeOrderTimeStamp == OMX_TRUE ) { | ||
284 | OSAL_ReadFromPipe(pVidDecComp->pTimeStampStoragePipe, &(pDupBufHeader->nTimeStamp), | ||
285 | sizeof(OMX_TICKS), &(nActualSize), OSAL_NO_SUSPEND); | ||
286 | } | ||
287 | |||
288 | activeFrameRegion[0] = pDecOutArgs->displayBufs.bufDesc[0].activeFrameRegion; | ||
289 | activeFrameRegion[1].bottomRight.y = (activeFrameRegion[0].bottomRight.y) / 2; | ||
290 | activeFrameRegion[1].bottomRight.x = activeFrameRegion[0].bottomRight.x; | ||
291 | |||
292 | // Crop rectangle handles the Y and UV buffer offsets | ||
293 | pDupBufHeader->nOffset = 0; | ||
294 | pDupBufHeader->nFilledLen = (nStride * pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nHeight * 3 ) / 2; | ||
295 | |||
296 | if((pVidDecComp->tCropDimension.nTop != activeFrameRegion[0].topLeft.y | ||
297 | || pVidDecComp->tCropDimension.nLeft != activeFrameRegion[0].topLeft.x) | ||
298 | || (pVidDecComp->tCropDimension.nWidth != (OMX_U32)(activeFrameRegion[0].bottomRight.x - activeFrameRegion[0].topLeft.x) | ||
299 | || pVidDecComp->tCropDimension.nHeight != (OMX_U32)(activeFrameRegion[0].bottomRight.y - activeFrameRegion[0].topLeft.y))) { | ||
300 | pVidDecComp->tCropDimension.nTop = activeFrameRegion[0].topLeft.y; | ||
301 | pVidDecComp->tCropDimension.nLeft = activeFrameRegion[0].topLeft.x; | ||
302 | pVidDecComp->tCropDimension.nWidth = activeFrameRegion[0].bottomRight.x - activeFrameRegion[0].topLeft.x; | ||
303 | pVidDecComp->tCropDimension.nHeight = activeFrameRegion[0].bottomRight.y - activeFrameRegion[0].topLeft.y; | ||
304 | if( pVidDecComp->bUsePortReconfigForCrop == OMX_TRUE ) { | ||
305 | eError = pVidDecComp->sBase.fpReturnEventNotify(hComponent, OMX_EventPortSettingsChanged, | ||
306 | OMX_VIDDEC_OUTPUT_PORT, OMX_IndexConfigCommonOutputCrop, NULL); | ||
307 | if( eError != OMX_ErrorNone ) { | ||
308 | OSAL_ErrorTrace("Port reconfig callback returned error, trying to continue"); | ||
309 | } | ||
310 | } | ||
311 | } | ||
312 | |||
313 | if( pVidDecComp->bSupportSkipGreyOutputFrames ) { | ||
314 | if( pDecOutArgs->displayBufs.bufDesc[0].frameType == IVIDEO_I_FRAME || | ||
315 | pDecOutArgs->displayBufs.bufDesc[0].frameType == IVIDEO_IDR_FRAME || | ||
316 | pDecOutArgs->displayBufs.bufDesc[0].frameType == IVIDEO_IP_FRAME || | ||
317 | pDecOutArgs->displayBufs.bufDesc[0].frameType == IVIDEO_IB_FRAME ) { | ||
318 | pVidDecComp->bSyncFrameReady = OMX_TRUE; | ||
319 | } | ||
320 | } | ||
321 | grallocHandle = (IMG_native_handle_t*)(pDupBufHeader->pBuffer); | ||
322 | pVidDecComp->grallocModule->unlock((gralloc_module_t const *) pVidDecComp->grallocModule, (buffer_handle_t)grallocHandle); | ||
323 | |||
324 | if( pVidDecComp->bSyncFrameReady == OMX_TRUE ) { | ||
325 | // Send the Output buffer to Base component | ||
326 | pVidDecComp->sBase.pPvtData->fpDioSend(hComponent, | ||
327 | OMX_VIDDEC_OUTPUT_PORT, pDupBufHeader); | ||
328 | } | ||
329 | pDecOutArgs->outputID[i] = 0; | ||
330 | i++; | ||
331 | } | ||
332 | i = 0; | ||
333 | while( pDecOutArgs->freeBufID[i] != 0 ) { | ||
334 | pDupBufHeader = (OMX_BUFFERHEADERTYPE *)pDecOutArgs->freeBufID[i]; | ||
335 | ((OMXBase_BufHdrPvtData *)(pDupBufHeader->pPlatformPrivate))->bIsLocked = OMX_FALSE; | ||
336 | if( pDupBufHeader ) { | ||
337 | grallocHandle = (IMG_native_handle_t*)(pDupBufHeader->pBuffer); | ||
338 | pVidDecComp->grallocModule->unlock((gralloc_module_t const *) pVidDecComp->grallocModule, | ||
339 | (buffer_handle_t)grallocHandle); | ||
340 | pVidDecComp->sBase.pPvtData->fpDioCancel(hComponent, | ||
341 | OMX_VIDDEC_OUTPUT_PORT, pDupBufHeader); | ||
342 | } | ||
343 | i++; | ||
344 | } | ||
345 | } | ||
346 | } while( status != XDM_EFAIL ); | ||
347 | } | ||
348 | if( pVidDecComp->bSupportDecodeOrderTimeStamp == OMX_TRUE ) { | ||
349 | OSAL_ClearPipe(pVidDecComp->pTimeStampStoragePipe); | ||
350 | } | ||
351 | if( pLastOutBufHeader != NULL ) { | ||
352 | pLastOutBufHeader->nFlags |= OMX_BUFFERFLAG_EOS; | ||
353 | grallocHandle = (IMG_native_handle_t*)(pLastOutBufHeader->pBuffer); | ||
354 | pVidDecComp->grallocModule->unlock((gralloc_module_t const *) pVidDecComp->grallocModule, | ||
355 | (buffer_handle_t)grallocHandle); | ||
356 | pVidDecComp->sBase.pPvtData->fpDioSend(hComponent, OMX_VIDDEC_OUTPUT_PORT, pLastOutBufHeader); | ||
357 | } | ||
358 | if( pInBufHeader != NULL ) { | ||
359 | pVidDecComp->sBase.pPvtData->fpDioSend(hComponent, OMX_VIDDEC_INPUT_PORT, pInBufHeader); | ||
360 | /* Send the EOS event to client */ | ||
361 | pVidDecComp->sBase.fpReturnEventNotify(hComponent, OMX_EventBufferFlag, | ||
362 | OMX_VIDDEC_OUTPUT_PORT, OMX_BUFFERFLAG_EOS, NULL); | ||
363 | } | ||
364 | pVidDecComp->nFrameCounter = 0; | ||
365 | if( pVidDecComp->bSupportSkipGreyOutputFrames ) { | ||
366 | pVidDecComp->bSyncFrameReady = OMX_FALSE; | ||
367 | } | ||
368 | pVidDecComp->nOutbufInUseFlag = 0; | ||
369 | pVidDecComp->nFatalErrorGiven = 0; | ||
370 | |||
371 | EXIT: | ||
372 | if( pVidDecComp->bSupportDecodeOrderTimeStamp == OMX_TRUE ) { | ||
373 | //Clear the pipe, to discard the stale messages | ||
374 | OSAL_ERROR err = OSAL_ClearPipe(pVidDecComp->pTimeStampStoragePipe); | ||
375 | if( err != OSAL_ErrNone ) { | ||
376 | /* if pipe clear fails, nothing can be done, just put error trace */ | ||
377 | OSAL_ErrorTrace("\npipe clear failed"); | ||
378 | } | ||
379 | } | ||
380 | return (eError); | ||
381 | } | ||
382 | |||
383 | /* ==========================================================================*/ | ||
384 | /** | ||
385 | * @fn Calc_InbufSize() | ||
386 | * This method Calcullates Buffer size given width and | ||
387 | * height of buffer | ||
388 | * | ||
389 | * @param [in] width : Width of the buffer | ||
390 | * @param [in] height : Height of the buffer | ||
391 | * | ||
392 | */ | ||
393 | /* ==========================================================================*/ | ||
394 | OMX_U32 Calc_InbufSize(OMX_U32 width, OMX_U32 height) | ||
395 | { | ||
396 | return ((width * height * 3) / 2); | ||
397 | } | ||
398 | |||
399 | OMX_ERRORTYPE OMXVidDec_SetInPortDef(OMX_HANDLETYPE hComponent, | ||
400 | OMX_PARAM_PORTDEFINITIONTYPE *pPortDefs) | ||
401 | { | ||
402 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
403 | OMX_VIDEO_CODINGTYPE currentCompressionType, desiredCompressionType; | ||
404 | OMX_U32 nFrameWidth, nFrameHeight; | ||
405 | OMX_PARAM_PORTDEFINITIONTYPE *pInputPortDef = NULL; | ||
406 | OMX_PARAM_PORTDEFINITIONTYPE *pOutputPortDef = NULL; | ||
407 | PaddedBuffParams tOutBufParams; | ||
408 | OMX_U32 i=0; | ||
409 | OMX_U32 bFound = 0; | ||
410 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
411 | OMXVidDecComp *pVidDecComp = NULL; | ||
412 | |||
413 | /*! Initialize pointers and variables */ | ||
414 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
415 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
416 | pInputPortDef = &(pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef); | ||
417 | pOutputPortDef = &(pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef); | ||
418 | nFrameWidth = pPortDefs->format.video.nFrameWidth; | ||
419 | nFrameHeight = pPortDefs->format.video.nFrameHeight; | ||
420 | if( nFrameWidth & 0x0F ) { | ||
421 | nFrameWidth = nFrameWidth + 16 - (nFrameWidth & 0x0F); | ||
422 | } | ||
423 | if( nFrameHeight & 0x1F ) { | ||
424 | nFrameHeight = nFrameHeight + 32 - (nFrameHeight & 0x1F); | ||
425 | } | ||
426 | currentCompressionType = pInputPortDef->format.video.eCompressionFormat; | ||
427 | desiredCompressionType = pPortDefs->format.video.eCompressionFormat; | ||
428 | /*! In case there is change in Compression type */ | ||
429 | if( currentCompressionType != desiredCompressionType ) { | ||
430 | /* De-initialize the current codec */ | ||
431 | pVidDecComp->fpDeinit_Codec(hComponent); | ||
432 | /* Call specific component init depending upon the | ||
433 | eCompressionFormat set. */ | ||
434 | i=0; | ||
435 | while( NULL != DecoderList[i].eCompressionFormat ) { | ||
436 | if( DecoderList[i].eCompressionFormat | ||
437 | == desiredCompressionType ) { | ||
438 | /* Component found */ | ||
439 | bFound = 1; | ||
440 | break; | ||
441 | } | ||
442 | i++; | ||
443 | } | ||
444 | if( bFound == 0 ) { | ||
445 | OSAL_ErrorTrace("Unsupported Compression format given in port definition"); | ||
446 | eError = OMX_ErrorUnsupportedSetting; | ||
447 | goto EXIT; | ||
448 | } | ||
449 | /* Call the Specific Decoder Init function and Initialize Params */ | ||
450 | eError = DecoderList[i].fpDecoderComponentInit(hComponent); | ||
451 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
452 | OMXVidDec_InitDecoderParams(hComponent, pHandle->pComponentPrivate); | ||
453 | strcpy((char *)pVidDecComp->tComponentRole.cRole, | ||
454 | (char *)DecoderList[i].cRole); | ||
455 | } /* End of if condition for change in codec type */ | ||
456 | |||
457 | /*! set the Actual values of an Input port */ | ||
458 | pInputPortDef->nBufferCountActual = pPortDefs->nBufferCountActual; | ||
459 | pInputPortDef->format = pPortDefs->format; | ||
460 | pInputPortDef->nBufferSize = Calc_InbufSize(nFrameWidth, nFrameHeight); | ||
461 | pVidDecComp->tCropDimension.nTop = 0; | ||
462 | pVidDecComp->tCropDimension.nLeft = 0; | ||
463 | pVidDecComp->tCropDimension.nWidth = pInputPortDef->format.video.nFrameWidth; | ||
464 | pVidDecComp->tCropDimension.nHeight = pInputPortDef->format.video.nFrameHeight; | ||
465 | |||
466 | /*! Set o/p port details according to width/height set at i/p Port. */ | ||
467 | pOutputPortDef->format.video.nFrameWidth = pInputPortDef->format.video.nFrameWidth; | ||
468 | pOutputPortDef->format.video.nFrameHeight = pInputPortDef->format.video.nFrameHeight; | ||
469 | pOutputPortDef->format.video.nStride = pInputPortDef->format.video.nFrameWidth; | ||
470 | OMXVidDec_Set2DBuffParams(hComponent, pHandle->pComponentPrivate); | ||
471 | pOutputPortDef->nBufferSize = pOutputPortDef->format.video.nStride * | ||
472 | ((pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nHeight * 3) >> 1); | ||
473 | |||
474 | tOutBufParams = pVidDecComp->fpCalc_OubuffDetails(hComponent, nFrameWidth, nFrameHeight); | ||
475 | pOutputPortDef->nBufferCountMin = tOutBufParams.nBufferCountMin; | ||
476 | pOutputPortDef->nBufferCountActual = tOutBufParams.nBufferCountActual; | ||
477 | |||
478 | /*! Set the Static Params (Decoder Specific) */ | ||
479 | pVidDecComp->fpSet_StaticParams(hComponent, pVidDecComp->pDecStaticParams); | ||
480 | pVidDecComp->pDecStaticParams->maxHeight = nFrameHeight; | ||
481 | pVidDecComp->pDecStaticParams->maxWidth = nFrameWidth; | ||
482 | if (pVidDecComp->tVideoParams[OMX_VIDDEC_INPUT_PORT].eCompressionFormat == OMX_VIDEO_CodingMPEG2) { | ||
483 | pVidDecComp->pDecStaticParams->maxWidth = pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nWidth; | ||
484 | } | ||
485 | if( pOutputPortDef->nBufferCountActual < pOutputPortDef->nBufferCountMin ) { | ||
486 | pOutputPortDef->nBufferCountActual = pOutputPortDef->nBufferCountMin; | ||
487 | } | ||
488 | |||
489 | EXIT: | ||
490 | return (eError); | ||
491 | |||
492 | } | ||
493 | |||
494 | OMX_ERRORTYPE OMXVidDec_SetOutPortDef(OMXVidDecComp *pVidDecComp, | ||
495 | OMX_PARAM_PORTDEFINITIONTYPE *pPortDefs) | ||
496 | { | ||
497 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
498 | OMX_PARAM_PORTDEFINITIONTYPE *pOutputPortDef = NULL; | ||
499 | OMX_PTR *pBufParams = NULL; | ||
500 | OMX_U32 nOutPort = OMX_VIDDEC_OUTPUT_PORT; | ||
501 | OMX_U32 nNumBuffers = 0; | ||
502 | |||
503 | pOutputPortDef = &(pVidDecComp->sBase.pPorts[nOutPort]->sPortDef); | ||
504 | |||
505 | /*! Set Values to output port based on input parameter */ | ||
506 | pOutputPortDef->nBufferCountActual = pPortDefs->nBufferCountActual; | ||
507 | pOutputPortDef->format = pPortDefs->format; | ||
508 | pOutputPortDef->format.video.nSliceHeight | ||
509 | = pOutputPortDef->format.video.nFrameHeight; | ||
510 | pOutputPortDef->nBufferSize = pOutputPortDef->format.video.nStride * | ||
511 | ((pVidDecComp->t2DBufferAllocParams[nOutPort].nHeight * 3) >> 1); | ||
512 | |||
513 | return (eError); | ||
514 | } | ||
515 | |||
516 | |||
517 | OMX_ERRORTYPE OMXVidDec_HandleFirstFrame(OMX_HANDLETYPE hComponent, | ||
518 | OMX_BUFFERHEADERTYPE * *ppInBufHeader) | ||
519 | { | ||
520 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
521 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
522 | OMX_U32 nFrameWidth, nFrameHeight, nFrameWidthNew, nFrameHeightNew, nFrameRate, nFrameRateNew; | ||
523 | OMXVidDecComp *pVidDecComp = NULL; | ||
524 | XDAS_Int32 status = 0; | ||
525 | IVIDDEC3_Status *pDecStatus = NULL; | ||
526 | OMX_PARAM_PORTDEFINITIONTYPE *pOutputPortDef = NULL; | ||
527 | OMX_PARAM_PORTDEFINITIONTYPE *pInputPortDef = NULL; | ||
528 | PaddedBuffParams tOutBufParams; | ||
529 | OMX_BUFFERHEADERTYPE *pInBufHeader; | ||
530 | OMX_BOOL bPortReconfigRequiredForPadding = OMX_FALSE; | ||
531 | OMX_CONFIG_RECTTYPE *p2DOutBufAllocParam = NULL; | ||
532 | |||
533 | OMX_BOOL bSendPortReconfigForScale = OMX_FALSE; | ||
534 | OMX_U32 nScale, nScaleRem, nScaleQ16Low, nScaleWidth, nScaleHeight; | ||
535 | OMX_U64 nScaleQ16 = 0; | ||
536 | |||
537 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
538 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
539 | pOutputPortDef = &(pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef); | ||
540 | pInputPortDef = &(pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef); | ||
541 | pVidDecComp->nOutPortReconfigRequired = 0; | ||
542 | p2DOutBufAllocParam = &(pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT]); | ||
543 | |||
544 | /*! Call the Codec Control call to get Status from Codec */ | ||
545 | OMX_CHECK(((pVidDecComp->pDecDynParams != NULL) && (pVidDecComp->pDecStatus != NULL)), OMX_ErrorBadParameter); | ||
546 | status = VIDDEC3_control(pVidDecComp->pDecHandle, XDM_GETSTATUS, pVidDecComp->pDecDynParams, pVidDecComp->pDecStatus); | ||
547 | if( status != VIDDEC3_EOK ) { | ||
548 | OSAL_ErrorTrace("Error in Codec Control Call for GETSTATUS"); | ||
549 | eError = OMX_ErrorInsufficientResources; | ||
550 | goto EXIT; | ||
551 | } | ||
552 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
553 | if( pVidDecComp->fpHandle_CodecGetStatus != NULL ) { | ||
554 | eError = pVidDecComp->fpHandle_CodecGetStatus(hComponent); | ||
555 | } | ||
556 | pDecStatus = (IVIDDEC3_Status *)(pVidDecComp->pDecStatus); | ||
557 | nFrameWidth = pOutputPortDef->format.video.nFrameWidth; | ||
558 | nFrameHeight = pOutputPortDef->format.video.nFrameHeight; | ||
559 | nFrameWidthNew = (OMX_U32)pDecStatus->outputWidth; | ||
560 | nFrameHeightNew = (OMX_U32)pDecStatus->outputHeight; | ||
561 | nFrameRate = pOutputPortDef->format.video.xFramerate >> 16; | ||
562 | |||
563 | OMX_CHECK(pVidDecComp->nFrameRateDivisor != 0, OMX_ErrorBadParameter); | ||
564 | nFrameRateNew = (OMX_U32)(pDecStatus->frameRate / pVidDecComp->nFrameRateDivisor); | ||
565 | /*Set 200 as max cap, as if clip with incorrect setting is present in sdcard | ||
566 | it breaks havoc on thumbnail generation */ | ||
567 | if((nFrameRateNew == 0) || (nFrameRateNew > 200)) { | ||
568 | OSAL_ErrorTrace("Codec Returned spurious FrameRate Value - %d Setting Back to - %d", | ||
569 | nFrameRateNew, nFrameRate); | ||
570 | nFrameRateNew = nFrameRate; | ||
571 | } | ||
572 | |||
573 | if( nFrameWidth & 0x0F ) { | ||
574 | nFrameWidth = nFrameWidth + 16 - (nFrameWidth & 0x0F); | ||
575 | } | ||
576 | if( nFrameHeight & 0x1F ) { | ||
577 | nFrameHeight = nFrameHeight + 32 - (nFrameHeight & 0x1F); | ||
578 | } | ||
579 | if( nFrameWidthNew & 0x0F ) { | ||
580 | nFrameWidthNew = nFrameWidthNew + 16 - (nFrameWidthNew & 0x0F); | ||
581 | } | ||
582 | if( nFrameHeightNew & 0x1F ) { | ||
583 | nFrameHeightNew = nFrameHeightNew + 32 - (nFrameHeightNew & 0x1F); | ||
584 | } | ||
585 | if( pVidDecComp->bUsePortReconfigForPadding == OMX_TRUE ) { | ||
586 | if( pOutputPortDef->format.video.nFrameWidth != p2DOutBufAllocParam->nWidth | ||
587 | || pOutputPortDef->format.video.nFrameHeight != p2DOutBufAllocParam->nHeight ) { | ||
588 | bPortReconfigRequiredForPadding = OMX_TRUE; | ||
589 | } | ||
590 | nFrameWidth = pVidDecComp->pDecStaticParams->maxWidth; | ||
591 | nFrameHeight = pVidDecComp->pDecStaticParams->maxHeight; | ||
592 | } | ||
593 | |||
594 | /*! Check whether the displayWidth already accounts for any | ||
595 | * difference between the current and new frame width */ | ||
596 | if ( nFrameWidth != nFrameWidthNew && | ||
597 | nFrameWidth == (OMX_U32)pVidDecComp->pDecDynParams->displayWidth ) { | ||
598 | nFrameWidthNew = nFrameWidth; | ||
599 | } | ||
600 | |||
601 | tOutBufParams = pVidDecComp->fpCalc_OubuffDetails(hComponent, | ||
602 | (OMX_U32)pDecStatus->outputWidth, (OMX_U32)pDecStatus->outputHeight); | ||
603 | |||
604 | /*! Check whether the height and width reported by codec matches | ||
605 | * that of output port */ | ||
606 | if( nFrameHeightNew != nFrameHeight || nFrameWidthNew != nFrameWidth | ||
607 | || bPortReconfigRequiredForPadding == OMX_TRUE || | ||
608 | pOutputPortDef->nBufferCountMin < tOutBufParams.nBufferCountMin || | ||
609 | nFrameRate < nFrameRateNew ) { /* Compare the min againt the older min buffer count | ||
610 | since parameters like display delay also gets set according to ref frame. */ | ||
611 | /*! Since the dimensions does not match trigger port reconfig */ | ||
612 | pVidDecComp->nOutPortReconfigRequired = 1; | ||
613 | pVidDecComp->nCodecRecreationRequired = 1; | ||
614 | /* Return back the Input buffer headers Note that the output header | ||
615 | * will be cancelled later so no need to cancel it here */ | ||
616 | if( ppInBufHeader != NULL ) { | ||
617 | pInBufHeader = *(ppInBufHeader); | ||
618 | pVidDecComp->sBase.pPvtData->fpDioCancel(hComponent, OMX_VIDDEC_INPUT_PORT, | ||
619 | pInBufHeader); | ||
620 | pInBufHeader = NULL; | ||
621 | } | ||
622 | /*! Change port definition to match with what codec reports */ | ||
623 | pInputPortDef->format.video.nFrameHeight = (OMX_U32)pDecStatus->outputHeight; | ||
624 | pInputPortDef->format.video.nFrameWidth = (OMX_U32)pDecStatus->outputWidth; | ||
625 | pOutputPortDef->format.video.nFrameHeight = (OMX_U32)pDecStatus->outputHeight; | ||
626 | pOutputPortDef->format.video.nFrameWidth = (OMX_U32)pDecStatus->outputWidth; | ||
627 | pOutputPortDef->format.video.nStride = (OMX_U32)pDecStatus->outputWidth; | ||
628 | pOutputPortDef->format.video.nSliceHeight = (OMX_U32)pDecStatus->outputHeight; | ||
629 | if( nFrameRate < nFrameRateNew ) { | ||
630 | pOutputPortDef->format.video.xFramerate = nFrameRateNew << 16; | ||
631 | pVidDecComp->tVideoParams[OMX_VIDDEC_OUTPUT_PORT].xFramerate = nFrameRateNew; | ||
632 | } | ||
633 | pVidDecComp->tCropDimension.nWidth = (OMX_U32)pDecStatus->outputWidth; | ||
634 | pVidDecComp->tCropDimension.nHeight = (OMX_U32)pDecStatus->outputHeight; | ||
635 | tOutBufParams = pVidDecComp->fpCalc_OubuffDetails(hComponent, | ||
636 | (OMX_U32)pDecStatus->outputWidth, | ||
637 | (OMX_U32)pDecStatus->outputHeight); | ||
638 | pOutputPortDef->nBufferCountMin = tOutBufParams.nBufferCountMin; | ||
639 | pOutputPortDef->nBufferCountActual = tOutBufParams.nBufferCountActual; | ||
640 | OMXVidDec_Set2DBuffParams(hComponent, pHandle->pComponentPrivate); | ||
641 | |||
642 | pOutputPortDef->format.video.nStride = p2DOutBufAllocParam->nWidth; | ||
643 | pOutputPortDef->format.video.nSliceHeight = p2DOutBufAllocParam->nHeight; | ||
644 | |||
645 | pOutputPortDef->nBufferSize = pOutputPortDef->format.video.nStride * | ||
646 | ((pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nHeight * 3) >> 1); | ||
647 | if( pVidDecComp->bUsePortReconfigForPadding == OMX_TRUE ) { | ||
648 | pInputPortDef->format.video.nFrameHeight = p2DOutBufAllocParam->nHeight; | ||
649 | pInputPortDef->format.video.nFrameWidth = p2DOutBufAllocParam->nWidth; | ||
650 | pOutputPortDef->format.video.nFrameHeight = p2DOutBufAllocParam->nHeight; | ||
651 | pOutputPortDef->format.video.nFrameWidth = p2DOutBufAllocParam->nWidth; | ||
652 | } | ||
653 | } | ||
654 | |||
655 | if( pVidDecComp->nOutPortReconfigRequired == 1 ) { | ||
656 | /*! Notify to Client change in output port settings */ | ||
657 | eError = pVidDecComp->sBase.fpReturnEventNotify(hComponent, | ||
658 | OMX_EventPortSettingsChanged, | ||
659 | OMX_VIDDEC_OUTPUT_PORT, 0, NULL); | ||
660 | } else if( pDecStatus->sampleAspectRatioHeight != 0 && pDecStatus->sampleAspectRatioWidth != 0 ) { | ||
661 | nScaleWidth = (OMX_U32)pDecStatus->sampleAspectRatioWidth; | ||
662 | nScaleHeight = (OMX_U32)pDecStatus->sampleAspectRatioHeight; | ||
663 | nScale = nScaleWidth / nScaleHeight; | ||
664 | if( nScale >= 1 ) { | ||
665 | nScaleRem = nScaleWidth % nScaleHeight; | ||
666 | nScaleQ16Low = 0xFFFF * nScaleRem / nScaleHeight; | ||
667 | nScaleQ16 = nScale << 16; | ||
668 | nScaleQ16 |= nScaleQ16Low; | ||
669 | if( (OMX_U64)pVidDecComp->tScaleParams.xWidth != nScaleQ16 | ||
670 | || pVidDecComp->tScaleParams.xHeight != 0x10000 ) { | ||
671 | pVidDecComp->tScaleParams.xWidth = nScaleQ16; | ||
672 | pVidDecComp->tScaleParams.xHeight = 0x10000; | ||
673 | bSendPortReconfigForScale = OMX_TRUE; | ||
674 | } | ||
675 | } else { | ||
676 | nScale = nScaleHeight / nScaleWidth; | ||
677 | nScaleRem = nScaleHeight % nScaleWidth; | ||
678 | nScaleQ16Low = 0xFFFF * nScaleRem / nScaleWidth; | ||
679 | nScaleQ16 = nScale << 16; | ||
680 | nScaleQ16 |= nScaleQ16Low; | ||
681 | if( pVidDecComp->tScaleParams.xWidth != 0x10000 | ||
682 | || (OMX_U64)pVidDecComp->tScaleParams.xHeight != nScaleQ16 ) { | ||
683 | pVidDecComp->tScaleParams.xWidth = 0x10000; | ||
684 | pVidDecComp->tScaleParams.xHeight = nScaleQ16; | ||
685 | bSendPortReconfigForScale = OMX_TRUE; | ||
686 | } | ||
687 | } | ||
688 | if( bSendPortReconfigForScale == OMX_TRUE ) { | ||
689 | /*! Notify to Client change in output port settings */ | ||
690 | eError = pVidDecComp->sBase.fpReturnEventNotify(hComponent, | ||
691 | OMX_EventPortSettingsChanged, OMX_VIDDEC_OUTPUT_PORT, OMX_IndexConfigCommonScale, NULL); | ||
692 | bSendPortReconfigForScale = OMX_FALSE; | ||
693 | } | ||
694 | } | ||
695 | |||
696 | EXIT: | ||
697 | return (eError); | ||
698 | |||
699 | } | ||
700 | |||
701 | OMX_ERRORTYPE OMXVidDec_HandleCodecProcError(OMX_HANDLETYPE hComponent, | ||
702 | OMX_BUFFERHEADERTYPE * *ppInBufHeader, | ||
703 | OMX_BUFFERHEADERTYPE * *ppOutBufHeader) | ||
704 | { | ||
705 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
706 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
707 | OMX_U32 nFrameWidth, nFrameHeight, nFrameWidthNew, nFrameHeightNew; | ||
708 | OMXVidDecComp *pVidDecComp = NULL; | ||
709 | XDAS_Int32 status = 0; | ||
710 | IVIDDEC3_Status *pDecStatus = NULL; | ||
711 | OMX_PARAM_PORTDEFINITIONTYPE *pOutputPortDef = NULL; | ||
712 | OMX_PARAM_PORTDEFINITIONTYPE *pInputPortDef = NULL; | ||
713 | PaddedBuffParams tOutBufParams; | ||
714 | OMX_BUFFERHEADERTYPE *pInBufHeader = *(ppInBufHeader); | ||
715 | OMX_BUFFERHEADERTYPE *pDupBufHeader; | ||
716 | OMX_BUFFERHEADERTYPE *pNewOutBufHeader = NULL; | ||
717 | OMX_BUFFERHEADERTYPE *pOutBufHeader = *(ppOutBufHeader); | ||
718 | OMX_U32 ii=0; | ||
719 | OMX_U32 nStride =0; | ||
720 | OMX_BOOL bPortReconfigRequiredForPadding = OMX_FALSE; | ||
721 | OMX_CONFIG_RECTTYPE *p2DOutBufAllocParam = NULL; | ||
722 | IMG_native_handle_t* grallocHandle; | ||
723 | |||
724 | /* Initialize pointers */ | ||
725 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
726 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
727 | pOutputPortDef = &(pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef); | ||
728 | pInputPortDef = &(pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef); | ||
729 | p2DOutBufAllocParam = &(pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT]); | ||
730 | |||
731 | /*! Call the Codec Status function to know cause of error */ | ||
732 | OMX_CHECK(((pVidDecComp->pDecDynParams != NULL) && (pVidDecComp->pDecStatus != NULL)), OMX_ErrorBadParameter); | ||
733 | status = VIDDEC3_control(pVidDecComp->pDecHandle, XDM_GETSTATUS, pVidDecComp->pDecDynParams, pVidDecComp->pDecStatus); | ||
734 | |||
735 | /* Check whether the Codec Status call was succesful */ | ||
736 | if( status != VIDDEC3_EOK ) { | ||
737 | OSAL_ErrorTrace("VIDDEC3_control XDM_GETSTATUS failed"); | ||
738 | if( (OMX_U32)pVidDecComp->pDecDynParams->decodeHeader | ||
739 | != pVidDecComp->nDecoderMode ) { | ||
740 | // Return the Input and Output buffer header | ||
741 | grallocHandle = (IMG_native_handle_t*)(pOutBufHeader->pBuffer); | ||
742 | pVidDecComp->grallocModule->unlock((gralloc_module_t const *) pVidDecComp->grallocModule, | ||
743 | (buffer_handle_t)grallocHandle); | ||
744 | pVidDecComp->sBase.pPvtData->fpDioCancel(hComponent, | ||
745 | OMX_VIDDEC_OUTPUT_PORT, | ||
746 | pOutBufHeader); | ||
747 | |||
748 | pVidDecComp->sBase.pPvtData->fpDioCancel(hComponent, | ||
749 | OMX_VIDDEC_INPUT_PORT, | ||
750 | pInBufHeader); | ||
751 | /*! Make Input buffer header pointer NULL */ | ||
752 | pInBufHeader = NULL; | ||
753 | } | ||
754 | eError = OMX_ErrorInsufficientResources; | ||
755 | goto EXIT; | ||
756 | } | ||
757 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
758 | |||
759 | pDecStatus = (IVIDDEC3_Status *)(pVidDecComp->pDecStatus); | ||
760 | nFrameWidth = pOutputPortDef->format.video.nFrameWidth; | ||
761 | nFrameHeight = pOutputPortDef->format.video.nFrameHeight; | ||
762 | nFrameWidthNew = pDecStatus->outputWidth; | ||
763 | nFrameHeightNew = pDecStatus->outputHeight; | ||
764 | |||
765 | if( nFrameWidth & 0x0F ) { | ||
766 | nFrameWidth = nFrameWidth + 16 - (nFrameWidth & 0x0F); | ||
767 | } | ||
768 | if( nFrameHeight & 0x1F ) { | ||
769 | nFrameHeight = nFrameHeight + 32 - (nFrameHeight & 0x1F); | ||
770 | } | ||
771 | if( nFrameWidthNew & 0x0F ) { | ||
772 | nFrameWidthNew = nFrameWidthNew + 16 - (nFrameWidthNew & 0x0F); | ||
773 | } | ||
774 | if( nFrameHeightNew & 0x1F ) { | ||
775 | nFrameHeightNew = nFrameHeightNew + 32 - (nFrameHeightNew & 0x1F); | ||
776 | } | ||
777 | |||
778 | if( pVidDecComp->bUsePortReconfigForPadding == OMX_TRUE ) { | ||
779 | if( pOutputPortDef->format.video.nFrameWidth != p2DOutBufAllocParam->nWidth | ||
780 | || pOutputPortDef->format.video.nFrameHeight != p2DOutBufAllocParam->nHeight ) { | ||
781 | bPortReconfigRequiredForPadding = OMX_TRUE; | ||
782 | } | ||
783 | nFrameWidth = pVidDecComp->pDecStaticParams->maxWidth; | ||
784 | nFrameHeight = pVidDecComp->pDecStaticParams->maxHeight; | ||
785 | } | ||
786 | |||
787 | /*! Check whether the displayWidth already accounts for any | ||
788 | * difference between the current and new frame width */ | ||
789 | if ( nFrameWidth != nFrameWidthNew && | ||
790 | nFrameWidth == (OMX_U32)pVidDecComp->pDecDynParams->displayWidth ) { | ||
791 | nFrameWidthNew = nFrameWidth; | ||
792 | } | ||
793 | |||
794 | /*! Check whether the height and width reported by codec matches | ||
795 | * that of output port */ | ||
796 | if( nFrameHeightNew != nFrameHeight || nFrameWidthNew != nFrameWidth | ||
797 | || bPortReconfigRequiredForPadding == OMX_TRUE ) { | ||
798 | pVidDecComp->nOutPortReconfigRequired = 1; | ||
799 | pVidDecComp->nCodecRecreationRequired = 1; | ||
800 | } | ||
801 | |||
802 | if( pVidDecComp->fpHandle_ExtendedError != NULL ) { | ||
803 | eError = pVidDecComp->fpHandle_ExtendedError(hComponent); | ||
804 | } | ||
805 | |||
806 | if( pVidDecComp->nOutPortReconfigRequired == 1 ) { | ||
807 | pNewOutBufHeader = (OMX_BUFFERHEADERTYPE *) pVidDecComp->pDecOutArgs->outputID[0]; | ||
808 | if( pNewOutBufHeader != NULL ) { | ||
809 | pVidDecComp->tCropDimension.nWidth = pDecStatus->outputWidth; | ||
810 | pVidDecComp->tCropDimension.nHeight = pDecStatus->outputHeight; | ||
811 | nStride = pVidDecComp->sBase.pPorts[OMX_VIDDEC_OUTPUT_PORT]->sPortDef.format.video.nStride; | ||
812 | // Crop rect handles the offsets for Y and UV buffers | ||
813 | pNewOutBufHeader->nOffset = 0; | ||
814 | // FilledLen | ||
815 | pNewOutBufHeader->nFilledLen | ||
816 | = (nStride * pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nHeight * 3) / 2; | ||
817 | grallocHandle = (IMG_native_handle_t*)(pNewOutBufHeader->pBuffer); | ||
818 | pVidDecComp->grallocModule->unlock((gralloc_module_t const *) pVidDecComp->grallocModule, | ||
819 | (buffer_handle_t)grallocHandle); | ||
820 | pVidDecComp->sBase.pPvtData->fpDioSend(hComponent, OMX_VIDDEC_OUTPUT_PORT, | ||
821 | pNewOutBufHeader); | ||
822 | } | ||
823 | |||
824 | if( pVidDecComp->nOutbufInUseFlag == 0 | ||
825 | && (OMX_U32)pVidDecComp->pDecDynParams->decodeHeader != pVidDecComp->nDecoderMode ) { | ||
826 | grallocHandle = (IMG_native_handle_t*)(pOutBufHeader->pBuffer); | ||
827 | pVidDecComp->grallocModule->unlock((gralloc_module_t const *) pVidDecComp->grallocModule, | ||
828 | (buffer_handle_t)grallocHandle); | ||
829 | pVidDecComp->sBase.pPvtData->fpDioCancel(hComponent, | ||
830 | OMX_VIDDEC_OUTPUT_PORT, pOutBufHeader); // This buffer header is freed afterwards. | ||
831 | } else { | ||
832 | pOutBufHeader = NULL; | ||
833 | } | ||
834 | if( (OMX_U32)pVidDecComp->pDecDynParams->decodeHeader != pVidDecComp->nDecoderMode ) { | ||
835 | pVidDecComp->sBase.pPvtData->fpDioCancel(hComponent, | ||
836 | OMX_VIDDEC_INPUT_PORT, pInBufHeader); | ||
837 | |||
838 | while( pVidDecComp->pDecOutArgs->freeBufID[ii] != 0 ) { | ||
839 | pDupBufHeader = (OMX_BUFFERHEADERTYPE *)pVidDecComp->pDecOutArgs->freeBufID[ii++]; | ||
840 | ((OMXBase_BufHdrPvtData *)(pDupBufHeader->pPlatformPrivate))->bIsLocked = OMX_FALSE; | ||
841 | if( pDupBufHeader != pOutBufHeader && pDupBufHeader != pNewOutBufHeader ) { | ||
842 | grallocHandle = (IMG_native_handle_t*)(pDupBufHeader->pBuffer); | ||
843 | pVidDecComp->grallocModule->unlock((gralloc_module_t const *) pVidDecComp->grallocModule, | ||
844 | (buffer_handle_t)grallocHandle); | ||
845 | pVidDecComp->sBase.pPvtData->fpDioCancel(hComponent, | ||
846 | OMX_VIDDEC_OUTPUT_PORT, pDupBufHeader); | ||
847 | } | ||
848 | } | ||
849 | } | ||
850 | |||
851 | /*! Notify to Client change in output port settings */ | ||
852 | eError = pVidDecComp->sBase.fpReturnEventNotify(hComponent, | ||
853 | OMX_EventPortSettingsChanged, | ||
854 | OMX_VIDDEC_OUTPUT_PORT, 0, NULL); | ||
855 | } | ||
856 | if( pVidDecComp->nOutPortReconfigRequired == 0 ) { | ||
857 | if( pVidDecComp->pDecOutArgs->extendedError & 0x8000 ) { | ||
858 | eError = OMX_ErrorFormatNotDetected; | ||
859 | if( (OMX_U32)pVidDecComp->pDecDynParams->decodeHeader != pVidDecComp->nDecoderMode ) { | ||
860 | if( pVidDecComp->nOutbufInUseFlag == 0 ) { | ||
861 | grallocHandle = (IMG_native_handle_t*)(pOutBufHeader->pBuffer); | ||
862 | pVidDecComp->grallocModule->unlock((gralloc_module_t const *) pVidDecComp->grallocModule, | ||
863 | (buffer_handle_t)grallocHandle); | ||
864 | pVidDecComp->sBase.pPvtData->fpDioCancel(hComponent, | ||
865 | OMX_VIDDEC_OUTPUT_PORT, pOutBufHeader); // This buffer header is freed afterwards. | ||
866 | } | ||
867 | pVidDecComp->sBase.pPvtData->fpDioCancel(hComponent, | ||
868 | OMX_VIDDEC_INPUT_PORT, pInBufHeader); | ||
869 | while( pVidDecComp->pDecOutArgs->freeBufID[ii] != 0 ) { | ||
870 | pDupBufHeader = (OMX_BUFFERHEADERTYPE *)pVidDecComp->pDecOutArgs->freeBufID[ii++]; | ||
871 | ((OMXBase_BufHdrPvtData *)(pDupBufHeader->pPlatformPrivate))->bIsLocked = OMX_FALSE; | ||
872 | if( pOutBufHeader != pDupBufHeader ) { | ||
873 | grallocHandle = (IMG_native_handle_t*)(pDupBufHeader->pBuffer); | ||
874 | pVidDecComp->grallocModule->unlock((gralloc_module_t const *) pVidDecComp->grallocModule, | ||
875 | (buffer_handle_t)grallocHandle); | ||
876 | pVidDecComp->sBase.pPvtData->fpDioCancel(hComponent, | ||
877 | OMX_VIDDEC_OUTPUT_PORT, pDupBufHeader); | ||
878 | } | ||
879 | } | ||
880 | } | ||
881 | pVidDecComp->nFatalErrorGiven = 1; | ||
882 | } | ||
883 | } | ||
884 | |||
885 | if( nFrameHeightNew != nFrameHeight || nFrameWidthNew != nFrameWidth | ||
886 | || bPortReconfigRequiredForPadding == OMX_TRUE ) { | ||
887 | /*Return back the locked buffers before changing the port definition */ | ||
888 | OMXVidDec_HandleFLUSH_EOS(hComponent, NULL, NULL); | ||
889 | /*! Change Port Definition */ | ||
890 | pInputPortDef->format.video.nFrameHeight = pDecStatus->outputHeight; | ||
891 | pInputPortDef->format.video.nFrameWidth = pDecStatus->outputWidth; | ||
892 | |||
893 | pOutputPortDef->format.video.nFrameHeight = pDecStatus->outputHeight; | ||
894 | pOutputPortDef->format.video.nFrameWidth = pDecStatus->outputWidth; | ||
895 | pOutputPortDef->format.video.nSliceHeight = pDecStatus->outputHeight; | ||
896 | pVidDecComp->tCropDimension.nWidth = pDecStatus->outputWidth; | ||
897 | pVidDecComp->tCropDimension.nHeight = pDecStatus->outputHeight; | ||
898 | tOutBufParams = pVidDecComp->fpCalc_OubuffDetails(hComponent, | ||
899 | pDecStatus->outputWidth, | ||
900 | pDecStatus->outputHeight); | ||
901 | pOutputPortDef->nBufferCountMin = tOutBufParams.nBufferCountMin; | ||
902 | pOutputPortDef->nBufferCountActual = tOutBufParams.nBufferCountActual; | ||
903 | OMXVidDec_Set2DBuffParams(hComponent, pHandle->pComponentPrivate); | ||
904 | |||
905 | pOutputPortDef->format.video.nStride = p2DOutBufAllocParam->nWidth; | ||
906 | |||
907 | pOutputPortDef->nBufferSize = pOutputPortDef->format.video.nStride * | ||
908 | ((pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nHeight * 3) >> 1); | ||
909 | if( pVidDecComp->bUsePortReconfigForPadding == OMX_TRUE ) { | ||
910 | pInputPortDef->format.video.nFrameHeight = p2DOutBufAllocParam->nHeight; | ||
911 | pInputPortDef->format.video.nFrameWidth = p2DOutBufAllocParam->nWidth; | ||
912 | pOutputPortDef->format.video.nFrameHeight = p2DOutBufAllocParam->nHeight; | ||
913 | pOutputPortDef->format.video.nFrameWidth = p2DOutBufAllocParam->nWidth; | ||
914 | pOutputPortDef->format.video.nStride = p2DOutBufAllocParam->nWidth; | ||
915 | pOutputPortDef->format.video.nSliceHeight = p2DOutBufAllocParam->nHeight; | ||
916 | } | ||
917 | } | ||
918 | |||
919 | EXIT: | ||
920 | return (eError); | ||
921 | } | ||
922 | |||
923 | void OMXVidDec_CalcFilledLen(OMX_HANDLETYPE hComponent, | ||
924 | IVIDDEC3_OutArgs *pDecOutArgs, | ||
925 | OMX_U32 nStride) | ||
926 | { | ||
927 | OMX_BUFFERHEADERTYPE *pOutBufHeader; | ||
928 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
929 | OMXVidDecComp *pVidDecComp = NULL; | ||
930 | |||
931 | /* Initialize the pointers */ | ||
932 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
933 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
934 | |||
935 | pOutBufHeader = (OMX_BUFFERHEADERTYPE *)pDecOutArgs->outputID[0]; | ||
936 | /*Crop rectangle handles the offsets for Y and UV buffers */ | ||
937 | pOutBufHeader->nOffset = 0; | ||
938 | |||
939 | /*! Calcullate the Total Filled length */ | ||
940 | pOutBufHeader->nFilledLen = (nStride * pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT].nHeight * 3) / 2; | ||
941 | |||
942 | return; | ||
943 | } | ||
944 | |||
945 | |||
diff --git a/libstagefrighthw/omx/videodecode/omx_video_decoder_internal.h b/libstagefrighthw/omx/videodecode/omx_video_decoder_internal.h new file mode 100644 index 0000000..f8b1a14 --- /dev/null +++ b/libstagefrighthw/omx/videodecode/omx_video_decoder_internal.h | |||
@@ -0,0 +1,102 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 _OMX_VIDEO_DECODER_INTERNAL_H_ | ||
18 | #define _OMX_VIDEO_DECODER_INTERNAL_H_ | ||
19 | |||
20 | #ifdef __cplusplus | ||
21 | extern "C" { | ||
22 | #endif | ||
23 | |||
24 | #include <OMX_Core.h> | ||
25 | #include <OMX_Component.h> | ||
26 | #include <OMX_Base.h> | ||
27 | #include <OMX_Types.h> | ||
28 | #include <OMX_BaseUtils.h> | ||
29 | #include <omx_video_decoder.h> | ||
30 | #include <omx_video_decoder_componenttable.h> | ||
31 | |||
32 | #include <osal_trace.h> | ||
33 | |||
34 | static OMX_STRING engineName = "ivahd_vidsvr"; | ||
35 | |||
36 | #define OMX_VIDDEC_COMP_VERSION_MAJOR 1 | ||
37 | #define OMX_VIDDEC_COMP_VERSION_MINOR 1 | ||
38 | #define OMX_VIDDEC_COMP_VERSION_REVISION 0 | ||
39 | #define OMX_VIDDEC_COMP_VERSION_STEP 0 | ||
40 | |||
41 | #define OMX_VIDEODECODER_DEFAULT_FRAMERATE 30 | ||
42 | |||
43 | /*! Minimum Input Buffer Count */ | ||
44 | #define OMX_VIDDEC_MIN_IN_BUF_COUNT 1 | ||
45 | /*! Default Input Buffer Count */ | ||
46 | #define OMX_VIDDEC_DEFAULT_IN_BUF_COUNT 2 | ||
47 | /*! Minimum Input Buffer Count in Data Sync mode | ||
48 | * codec releases input buffer of Nth Data Sync call during (N+2)th Data Sync call | ||
49 | * So minimum number of input buffers required is 3 */ | ||
50 | #define OMX_VIDDEC_DATASYNC_MIN_IN_BUF_COUNT 3 | ||
51 | /*! Default Input Buffer Count in Data Sync mode*/ | ||
52 | #define OMX_VIDDEC_DATASYNC_DEFAULT_IN_BUF_COUNT 4 | ||
53 | /*! Default Frame Width */ | ||
54 | #define OMX_VIDDEC_DEFAULT_FRAME_WIDTH 176 | ||
55 | /*! Default Frame Height */ | ||
56 | #define OMX_VIDDEC_DEFAULT_FRAME_HEIGHT 144 | ||
57 | /*! Default 1D-Buffer Alignment */ | ||
58 | #define OMX_VIDDEC_DEFAULT_1D_INPUT_BUFFER_ALIGNMENT 1 | ||
59 | /*! Default Stride value for 2D buffer */ | ||
60 | #define OMX_VIDDEC_DEFAULT_STRIDE OMX_VIDDEC_DEFAULT_FRAME_WIDTH | ||
61 | /*! Max Image Width supported */ | ||
62 | #define OMX_VIDDEC_MAX_WIDTH (2048) | ||
63 | /*! Max Image Height supported */ | ||
64 | #define OMX_VIDDEC_MAX_HEIGHT (2048) | ||
65 | /*! Max Number of MBs supported */ | ||
66 | #define OMX_VIDDEC_MAX_MACROBLOCK (8160) | ||
67 | |||
68 | #define OMX_VIDEODECODER_COMPONENT_NAME "OMX.ti.ducati.video.decoder" | ||
69 | |||
70 | /* external definition for the Video Params Init function */ | ||
71 | extern OMX_ERRORTYPE OMXVidDec_InitFields(OMXVidDecComp *pVidDecComp); | ||
72 | extern void OMXVidDec_InitPortDefs(OMX_HANDLETYPE hComponent, OMXVidDecComp *pVidDecComp); | ||
73 | extern void OMXVidDec_InitPortParams(OMXVidDecComp *pVidDecComp); | ||
74 | extern void OMXVidDec_InitDecoderParams(OMX_HANDLETYPE hComponent, OMXVidDecComp *pVidDecComp); | ||
75 | |||
76 | extern OMX_ERRORTYPE OMXVidDec_HandleFLUSH_EOS(OMX_HANDLETYPE hComponent, OMX_BUFFERHEADERTYPE *pOutBufHeader, | ||
77 | OMX_BUFFERHEADERTYPE *pInBufHeader); | ||
78 | extern OMX_ERRORTYPE OMXVidDec_SetInPortDef(OMX_HANDLETYPE hComponent, | ||
79 | OMX_PARAM_PORTDEFINITIONTYPE *pPortDefs); | ||
80 | extern OMX_ERRORTYPE OMXVidDec_SetOutPortDef(OMXVidDecComp *pVidDecComp, | ||
81 | OMX_PARAM_PORTDEFINITIONTYPE *pPortDefs); | ||
82 | extern OMX_ERRORTYPE OMXVidDec_HandleFirstFrame(OMX_HANDLETYPE hComponent, | ||
83 | OMX_BUFFERHEADERTYPE * *ppInBufHeader); | ||
84 | extern OMX_ERRORTYPE OMXVidDec_HandleCodecProcError(OMX_HANDLETYPE hComponent, | ||
85 | OMX_BUFFERHEADERTYPE * *ppInBufHeader, | ||
86 | OMX_BUFFERHEADERTYPE * *ppOutBufHeader); | ||
87 | extern OMX_ERRORTYPE OMXVidDec_HandleLockedBuffer(OMX_HANDLETYPE hComponent, | ||
88 | OMX_BUFFERHEADERTYPE *pOutBufHeader); | ||
89 | |||
90 | XDAS_Int32 OMXVidDec_DataSync_GetInputData(XDM_DataSyncHandle dataSyncHandle, XDM_DataSyncDesc *dataSyncDesc); | ||
91 | |||
92 | XDAS_Int32 OMXVidDec_DataSync_PutBuffer(XDM_DataSyncHandle dataSyncHandle, XDM_DataSyncDesc *dataSyncDesc); | ||
93 | |||
94 | extern void OMXVidDec_Set2DBuffParams(OMX_HANDLETYPE hComponent, OMXVidDecComp *pVidDecComp); | ||
95 | extern OMX_U32 Calc_InbufSize(OMX_U32 width, OMX_U32 height); | ||
96 | |||
97 | #ifdef __cplusplus | ||
98 | } | ||
99 | #endif | ||
100 | |||
101 | #endif /* _OMX_VIDEO_DECODER_H_ */ | ||
102 | |||
diff --git a/libstagefrighthw/omx/videodecode/omx_video_decoder_mpeg2.c b/libstagefrighthw/omx/videodecode/omx_video_decoder_mpeg2.c new file mode 100644 index 0000000..4445873 --- /dev/null +++ b/libstagefrighthw/omx/videodecode/omx_video_decoder_mpeg2.c | |||
@@ -0,0 +1,451 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 | #define LOG_TAG "OMX_MPEG2_VIDDEC" | ||
18 | |||
19 | #include <omx_video_decoder_mpeg2.h> | ||
20 | |||
21 | |||
22 | OMX_ERRORTYPE OMXMPEG2VD_Init(OMX_HANDLETYPE hComponent) | ||
23 | { | ||
24 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
25 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
26 | OMXVidDecComp *pVidDecComp = NULL; | ||
27 | OMXMPEG2VidDecComp *pMPEG2VidDecComp = NULL; | ||
28 | |||
29 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
30 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
31 | |||
32 | /*! Initialize the function parameters for OMX functions */ | ||
33 | pHandle->SetParameter = OMXMPEG2VD_SetParameter; | ||
34 | pHandle->GetParameter = OMXMPEG2VD_GetParameter; | ||
35 | |||
36 | /*! Initialize the function pointers */ | ||
37 | pVidDecComp->fpSet_StaticParams = OMXMPEG2VD_SetStaticParams; | ||
38 | pVidDecComp->fpSet_DynamicParams = OMXMPEG2VD_SetDynamicParams; | ||
39 | pVidDecComp->fpSet_Status = OMXMPEG2VD_SetStatus; | ||
40 | pVidDecComp->fpCalc_OubuffDetails = CalculateMPEG2VD_outbuff_details; | ||
41 | pVidDecComp->fpDeinit_Codec = OMXMPEG2VD_DeInit; | ||
42 | pVidDecComp->cDecoderName = "ivahd_mpeg2vdec"; | ||
43 | |||
44 | pVidDecComp->tVideoParams[OMX_VIDDEC_INPUT_PORT].eCompressionFormat = OMX_VIDEO_CodingMPEG2; | ||
45 | pVidDecComp->tVideoParams[OMX_VIDDEC_OUTPUT_PORT].eCompressionFormat = OMX_VIDEO_CodingUnused; | ||
46 | |||
47 | pVidDecComp->fpHandle_ExtendedError = OMXMPEG2VD_HandleError; | ||
48 | |||
49 | pVidDecComp->pCodecSpecific = | ||
50 | (OMXMPEG2VidDecComp *) OSAL_Malloc(sizeof (OMXMPEG2VidDecComp)); | ||
51 | OMX_CHECK((pVidDecComp->pCodecSpecific) != NULL, OMX_ErrorInsufficientResources); | ||
52 | |||
53 | pMPEG2VidDecComp =(OMXMPEG2VidDecComp *) pVidDecComp->pCodecSpecific; | ||
54 | |||
55 | OMX_BASE_INIT_STRUCT_PTR(&(pMPEG2VidDecComp->tDeblockingParam), OMX_PARAM_DEBLOCKINGTYPE); | ||
56 | pMPEG2VidDecComp->tDeblockingParam.nPortIndex = OMX_VIDDEC_OUTPUT_PORT; | ||
57 | pMPEG2VidDecComp->tDeblockingParam.bDeblocking = OMX_FALSE; | ||
58 | |||
59 | |||
60 | OMX_BASE_INIT_STRUCT_PTR(&(pMPEG2VidDecComp->tMPEG2VideoParam), OMX_VIDEO_PARAM_MPEG2TYPE); | ||
61 | pMPEG2VidDecComp->tMPEG2VideoParam.nPortIndex = OMX_VIDDEC_INPUT_PORT; | ||
62 | pMPEG2VidDecComp->tMPEG2VideoParam.eProfile = OMX_VIDEO_MPEG2ProfileMain; | ||
63 | pMPEG2VidDecComp->tMPEG2VideoParam.eLevel = OMX_VIDEO_MPEG2LevelML; | ||
64 | |||
65 | /*! Allocate Memory for Static Parameter */ | ||
66 | pVidDecComp->pDecStaticParams = (IVIDDEC3_Params *)memplugin_alloc(sizeof(IMPEG2VDEC_Params), 1, MEM_CARVEOUT, 0, 0); | ||
67 | OMX_CHECK(pVidDecComp->pDecStaticParams != NULL, OMX_ErrorInsufficientResources); | ||
68 | OSAL_Memset(pVidDecComp->pDecStaticParams, 0x0, sizeof(IMPEG2VDEC_Params)); | ||
69 | |||
70 | /*! Allocate Memory for Dynamic Parameter */ | ||
71 | pVidDecComp->pDecDynParams = (IVIDDEC3_DynamicParams *)memplugin_alloc(sizeof(IMPEG2VDEC_DynamicParams), 1, MEM_CARVEOUT, 0, 0); | ||
72 | OMX_CHECK(pVidDecComp->pDecDynParams != NULL, OMX_ErrorInsufficientResources); | ||
73 | OSAL_Memset(pVidDecComp->pDecDynParams, 0x0, sizeof(IMPEG2VDEC_DynamicParams)); | ||
74 | |||
75 | /*! Allocate Memory for Status Structure */ | ||
76 | pVidDecComp->pDecStatus = (IVIDDEC3_Status *) memplugin_alloc(sizeof(IMPEG2VDEC_Status), 1, MEM_CARVEOUT, 0, 0); | ||
77 | OMX_CHECK(pVidDecComp->pDecStatus != NULL, OMX_ErrorInsufficientResources); | ||
78 | OSAL_Memset(pVidDecComp->pDecStatus, 0x0, sizeof(IMPEG2VDEC_Status)); | ||
79 | |||
80 | /*! Allocate Memory for Input Arguments */ | ||
81 | pVidDecComp->pDecInArgs = (IVIDDEC3_InArgs *) memplugin_alloc(sizeof(IMPEG2VDEC_InArgs), 1, MEM_CARVEOUT, 0, 0); | ||
82 | OMX_CHECK(pVidDecComp->pDecInArgs != NULL, OMX_ErrorInsufficientResources); | ||
83 | OSAL_Memset(pVidDecComp->pDecInArgs, 0x0, sizeof(IMPEG2VDEC_InArgs)); | ||
84 | |||
85 | /*! Allocate Memory for Output Arguments */ | ||
86 | pVidDecComp->pDecOutArgs = (IVIDDEC3_OutArgs *) memplugin_alloc(sizeof(IMPEG2VDEC_OutArgs), 1, MEM_CARVEOUT, 0, 0); | ||
87 | OMX_CHECK(pVidDecComp->pDecOutArgs != NULL, OMX_ErrorInsufficientResources); | ||
88 | OSAL_Memset(pVidDecComp->pDecOutArgs, 0x0, sizeof(IMPEG2VDEC_OutArgs)); | ||
89 | |||
90 | pVidDecComp->pDecInArgs->size = sizeof(IMPEG2VDEC_InArgs); | ||
91 | pVidDecComp->pDecOutArgs->size = sizeof(IMPEG2VDEC_OutArgs); | ||
92 | |||
93 | pVidDecComp->pDecStaticParams->metadataType[0] = IVIDEO_METADATAPLANE_NONE; | ||
94 | pVidDecComp->pDecStaticParams->metadataType[1] = IVIDEO_METADATAPLANE_NONE; | ||
95 | pVidDecComp->pDecStaticParams->metadataType[2] = IVIDEO_METADATAPLANE_NONE; | ||
96 | |||
97 | pVidDecComp->pDecStaticParams->operatingMode = IVIDEO_DECODE_ONLY; //IVIDEO_TRANSCODE_FRAMELEVEL; // | ||
98 | |||
99 | pVidDecComp->pDecStaticParams->inputDataMode = IVIDEO_ENTIREFRAME; | ||
100 | pVidDecComp->pDecStaticParams->numInputDataUnits = 0; | ||
101 | |||
102 | |||
103 | EXIT: | ||
104 | return (eError); | ||
105 | |||
106 | } | ||
107 | |||
108 | void OMXMPEG2VD_SetStaticParams(OMX_HANDLETYPE hComponent, void *staticparams) | ||
109 | { | ||
110 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
111 | OMXVidDecComp *pVidDecComp = NULL; | ||
112 | OMXMPEG2VidDecComp *pMPEG2VidDecComp = NULL; | ||
113 | OMX_CONFIG_RECTTYPE *p2DOutBufAllocParam = NULL; | ||
114 | IMPEG2VDEC_Params *params; | ||
115 | |||
116 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
117 | pVidDecComp | ||
118 | = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
119 | p2DOutBufAllocParam = &(pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT]); | ||
120 | |||
121 | pMPEG2VidDecComp = | ||
122 | (OMXMPEG2VidDecComp *) pVidDecComp->pCodecSpecific; | ||
123 | |||
124 | params = (IMPEG2VDEC_Params *) staticparams; | ||
125 | |||
126 | params->viddecParams.size = sizeof(IMPEG2VDEC_Params); | ||
127 | |||
128 | params->viddecParams.maxWidth = p2DOutBufAllocParam->nWidth; | ||
129 | |||
130 | params->viddecParams.maxFrameRate = 30000; | ||
131 | |||
132 | params->viddecParams.maxBitRate = 10000000; | ||
133 | |||
134 | params->viddecParams.dataEndianness = XDM_BYTE; | ||
135 | params->viddecParams.forceChromaFormat = XDM_YUV_420SP; | ||
136 | params->viddecParams.displayDelay = IVIDDEC3_DISPLAY_DELAY_1; | ||
137 | params->viddecParams.inputDataMode = IVIDEO_ENTIREFRAME; | ||
138 | params->viddecParams.numInputDataUnits = 0; | ||
139 | params->viddecParams.numOutputDataUnits = 0; | ||
140 | params->viddecParams.outputDataMode = IVIDEO_ENTIREFRAME; | ||
141 | params->viddecParams.displayBufsMode = IVIDDEC3_DISPLAYBUFS_EMBEDDED; | ||
142 | |||
143 | params->viddecParams.errorInfoMode = IVIDEO_ERRORINFO_OFF; | ||
144 | |||
145 | params->outloopDeBlocking = pMPEG2VidDecComp->tDeblockingParam.bDeblocking; | ||
146 | params->ErrorConcealmentON = pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef.format.video.bFlagErrorConcealment; | ||
147 | /* If ErrorConcealmentON, then metadata[0] should be set to IVIDEO_METADATAPLANE_MBINFO */ | ||
148 | if (params->ErrorConcealmentON) { | ||
149 | pVidDecComp->pDecStaticParams->metadataType[0] = IVIDEO_METADATAPLANE_MBINFO; | ||
150 | pVidDecComp->pDecStaticParams->operatingMode = IVIDEO_TRANSCODE_FRAMELEVEL; | ||
151 | } | ||
152 | |||
153 | params->debugTraceLevel= 0; | ||
154 | params->lastNFramesToLog= 0; | ||
155 | |||
156 | return; | ||
157 | } | ||
158 | |||
159 | |||
160 | void OMXMPEG2VD_SetDynamicParams(OMX_HANDLETYPE hComponent, void *dynParams) | ||
161 | { | ||
162 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
163 | OMXVidDecComp *pVidDecComp = NULL; | ||
164 | OMX_CONFIG_RECTTYPE *p2DOutBufAllocParam = NULL; | ||
165 | IMPEG2VDEC_DynamicParams *dynamicParams; | ||
166 | |||
167 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
168 | pVidDecComp | ||
169 | = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
170 | p2DOutBufAllocParam = &(pVidDecComp->t2DBufferAllocParams[OMX_VIDDEC_OUTPUT_PORT]); | ||
171 | dynamicParams = (IMPEG2VDEC_DynamicParams *)dynParams; | ||
172 | |||
173 | /*! Update the Individual fields in the Dyanmic Params of MPEG2 decoder */ | ||
174 | dynamicParams->viddecDynamicParams.size = sizeof(IMPEG2VDEC_DynamicParams); | ||
175 | dynamicParams->viddecDynamicParams.decodeHeader = XDM_DECODE_AU; | ||
176 | dynamicParams->viddecDynamicParams.displayWidth = p2DOutBufAllocParam->nWidth; | ||
177 | dynamicParams->viddecDynamicParams.frameSkipMode = IVIDEO_NO_SKIP; | ||
178 | dynamicParams->viddecDynamicParams.newFrameFlag = XDAS_TRUE; | ||
179 | dynamicParams->viddecDynamicParams.putDataFxn = NULL; | ||
180 | dynamicParams->viddecDynamicParams.putDataHandle = NULL; | ||
181 | dynamicParams->viddecDynamicParams.getDataFxn = NULL; | ||
182 | dynamicParams->viddecDynamicParams.getDataHandle = NULL; | ||
183 | dynamicParams->viddecDynamicParams.putBufferFxn = NULL; | ||
184 | dynamicParams->viddecDynamicParams.putBufferHandle = NULL; | ||
185 | dynamicParams->viddecDynamicParams.lateAcquireArg = IRES_HDVICP2_UNKNOWNLATEACQUIREARG; | ||
186 | return; | ||
187 | } | ||
188 | |||
189 | |||
190 | void OMXMPEG2VD_SetStatus(OMX_HANDLETYPE hComponent, void *decstatus) | ||
191 | { | ||
192 | IMPEG2VDEC_Status *status; | ||
193 | (void)hComponent; | ||
194 | |||
195 | status = (IMPEG2VDEC_Status *)decstatus; | ||
196 | |||
197 | status->viddecStatus.size = sizeof(IMPEG2VDEC_Status); | ||
198 | return; | ||
199 | } | ||
200 | |||
201 | |||
202 | PaddedBuffParams CalculateMPEG2VD_outbuff_details(OMX_HANDLETYPE hComponent, | ||
203 | OMX_U32 width, OMX_U32 height) | ||
204 | { | ||
205 | PaddedBuffParams OutBuffDetails; | ||
206 | (void)hComponent; | ||
207 | |||
208 | /* OutBuffDetails.nBufferSize | ||
209 | = ((((width + PADX + 127) & ~127) * (height + PADY))); */ | ||
210 | /* The 2 additional rows and columns are required as per codec request to boost performance. */ | ||
211 | OutBuffDetails.nBufferSize | ||
212 | = ((((width + 127) & ~127) + 2) * (height + 2)); | ||
213 | /* Multiply buffer size by 1.5 to account for both luma and chroma */ | ||
214 | OutBuffDetails.nBufferSize = (OutBuffDetails.nBufferSize * 3) >> 1; | ||
215 | |||
216 | OutBuffDetails.nBufferCountMin = 4; | ||
217 | OutBuffDetails.nBufferCountActual = 8; | ||
218 | OutBuffDetails.n1DBufferAlignment = 16; | ||
219 | //OutBuffDetails.nPaddedWidth = (width + PADX + 127) & ~127; | ||
220 | //OutBuffDetails.nPaddedHeight = height + PADY; | ||
221 | OutBuffDetails.nPaddedWidth = (width + 127) & ~127; | ||
222 | OutBuffDetails.nPaddedHeight = height; | ||
223 | OutBuffDetails.n2DBufferYAlignment = 1; | ||
224 | OutBuffDetails.n2DBufferXAlignment = 16; | ||
225 | |||
226 | return (OutBuffDetails); | ||
227 | } | ||
228 | |||
229 | |||
230 | void OMXMPEG2VD_DeInit(OMX_HANDLETYPE hComponent) | ||
231 | { | ||
232 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
233 | OMXVidDecComp *pVidDecComp = NULL; | ||
234 | |||
235 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
236 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
237 | /*! Delete all the memory which was allocated during init of decoder */ | ||
238 | if( pVidDecComp->pDecStaticParams ) { | ||
239 | memplugin_free(pVidDecComp->pDecStaticParams); | ||
240 | pVidDecComp->pDecStaticParams = NULL; | ||
241 | } | ||
242 | if( pVidDecComp->pDecDynParams ) { | ||
243 | memplugin_free(pVidDecComp->pDecDynParams); | ||
244 | pVidDecComp->pDecDynParams = NULL; | ||
245 | } | ||
246 | if( pVidDecComp->pDecStatus ) { | ||
247 | memplugin_free(pVidDecComp->pDecStatus); | ||
248 | pVidDecComp->pDecStatus = NULL; | ||
249 | } | ||
250 | if( pVidDecComp->pDecInArgs ) { | ||
251 | memplugin_free(pVidDecComp->pDecInArgs); | ||
252 | pVidDecComp->pDecInArgs = NULL; | ||
253 | } | ||
254 | if( pVidDecComp->pDecOutArgs ) { | ||
255 | memplugin_free(pVidDecComp->pDecOutArgs); | ||
256 | pVidDecComp->pDecOutArgs = NULL; | ||
257 | } | ||
258 | if( pVidDecComp->pCodecSpecific ) { | ||
259 | OSAL_Free(pVidDecComp->pCodecSpecific); | ||
260 | pVidDecComp->pCodecSpecific = NULL; | ||
261 | } | ||
262 | pHandle->SetParameter = OMXVidDec_SetParameter; | ||
263 | pHandle->GetParameter = OMXVidDec_GetParameter; | ||
264 | pVidDecComp->fpHandle_ExtendedError = NULL; | ||
265 | } | ||
266 | |||
267 | OMX_ERRORTYPE OMXMPEG2VD_SetParameter(OMX_HANDLETYPE hComponent, | ||
268 | OMX_INDEXTYPE nIndex, OMX_PTR pParamStruct) | ||
269 | { | ||
270 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
271 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
272 | OMXVidDecComp *pVidDecComp = NULL; | ||
273 | OMXMPEG2VidDecComp *pMPEG2VidDecComp = NULL; | ||
274 | OMX_PARAM_DEBLOCKINGTYPE *pDeblockingParam = NULL; | ||
275 | OMX_VIDEO_PARAM_MPEG2TYPE *pMPEG2VideoParam = NULL; | ||
276 | |||
277 | OMX_CHECK((hComponent != NULL) && (pParamStruct != NULL), | ||
278 | OMX_ErrorBadParameter); | ||
279 | |||
280 | /*! Initialize the pointers */ | ||
281 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
282 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
283 | pMPEG2VidDecComp =(OMXMPEG2VidDecComp *) pVidDecComp->pCodecSpecific; | ||
284 | |||
285 | switch( nIndex ) { | ||
286 | case OMX_IndexParamVideoMpeg2 : | ||
287 | |||
288 | pMPEG2VideoParam = (OMX_VIDEO_PARAM_MPEG2TYPE *) pParamStruct; | ||
289 | /* SetParameter can be invoked in Loaded State or on Disabled ports only*/ | ||
290 | OMX_CHECK((pVidDecComp->sBase.tCurState == OMX_StateLoaded) || | ||
291 | (pVidDecComp->sBase.pPorts[pMPEG2VideoParam->nPortIndex]->sPortDef.bEnabled == OMX_FALSE), | ||
292 | OMX_ErrorIncorrectStateOperation); | ||
293 | |||
294 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_MPEG2TYPE, eError); | ||
295 | OMX_CHECK(pMPEG2VideoParam->eProfile == OMX_VIDEO_MPEG2ProfileSimple | ||
296 | || pMPEG2VideoParam->eProfile == OMX_VIDEO_MPEG2ProfileMain, | ||
297 | OMX_ErrorUnsupportedSetting); | ||
298 | if( pMPEG2VideoParam->nPortIndex == OMX_VIDDEC_INPUT_PORT ) { | ||
299 | pMPEG2VidDecComp->tMPEG2VideoParam = *pMPEG2VideoParam; | ||
300 | } else if( pMPEG2VideoParam->nPortIndex == OMX_VIDDEC_OUTPUT_PORT ) { | ||
301 | OSAL_ErrorTrace("OMX_IndexParamVideoMpeg2 supported only on i/p port"); | ||
302 | eError = OMX_ErrorUnsupportedIndex; | ||
303 | } else { | ||
304 | eError = OMX_ErrorBadPortIndex; | ||
305 | } | ||
306 | break; | ||
307 | case OMX_IndexParamCommonDeblocking : | ||
308 | |||
309 | pDeblockingParam = (OMX_PARAM_DEBLOCKINGTYPE *) pParamStruct; | ||
310 | |||
311 | /* SetParameter can be invoked in Loaded State or on Disabled ports only*/ | ||
312 | OMX_CHECK((pVidDecComp->sBase.tCurState == OMX_StateLoaded) || | ||
313 | (pVidDecComp->sBase.pPorts[pDeblockingParam->nPortIndex]->sPortDef.bEnabled == OMX_FALSE), | ||
314 | OMX_ErrorIncorrectStateOperation); | ||
315 | |||
316 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_PARAM_DEBLOCKINGTYPE, eError); | ||
317 | if( pDeblockingParam->nPortIndex == OMX_VIDDEC_OUTPUT_PORT ) { | ||
318 | pMPEG2VidDecComp->tDeblockingParam.bDeblocking = pDeblockingParam->bDeblocking; | ||
319 | } else if( pDeblockingParam->nPortIndex == OMX_VIDDEC_INPUT_PORT ) { | ||
320 | OSAL_ErrorTrace("\n Deblocking supported only on o/p port... \n"); | ||
321 | eError = OMX_ErrorUnsupportedIndex; | ||
322 | } else { | ||
323 | eError = OMX_ErrorBadPortIndex; | ||
324 | } | ||
325 | break; | ||
326 | default : | ||
327 | eError = OMXVidDec_SetParameter(hComponent, nIndex, pParamStruct); | ||
328 | } | ||
329 | |||
330 | EXIT: | ||
331 | return (eError); | ||
332 | } | ||
333 | |||
334 | OMX_ERRORTYPE OMXMPEG2VD_GetParameter(OMX_HANDLETYPE hComponent, | ||
335 | OMX_INDEXTYPE nIndex, OMX_PTR pParamStruct) | ||
336 | { | ||
337 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
338 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
339 | OMXVidDecComp *pVidDecComp = NULL; | ||
340 | OMXMPEG2VidDecComp *pMPEG2VidDecComp = NULL; | ||
341 | OMX_PARAM_DEBLOCKINGTYPE *pDeblockingParam = NULL; | ||
342 | OMX_VIDEO_PARAM_MPEG2TYPE *pMPEG2VideoParam = NULL; | ||
343 | OMX_VIDEO_PARAM_PROFILELEVELTYPE *pMPEG2ProfileLevelParam = NULL; | ||
344 | |||
345 | OMX_CHECK((hComponent != NULL) && (pParamStruct != NULL), | ||
346 | OMX_ErrorBadParameter); | ||
347 | |||
348 | /*! Initialize the pointers */ | ||
349 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
350 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
351 | /* GetParameter can't be invoked incase the comp is in Invalid State */ | ||
352 | OMX_CHECK(pVidDecComp->sBase.tCurState != OMX_StateInvalid, | ||
353 | OMX_ErrorIncorrectStateOperation); | ||
354 | |||
355 | pMPEG2VidDecComp =(OMXMPEG2VidDecComp *) pVidDecComp->pCodecSpecific; | ||
356 | |||
357 | switch( nIndex ) { | ||
358 | case OMX_IndexParamVideoMpeg2 : | ||
359 | |||
360 | pMPEG2VideoParam = (OMX_VIDEO_PARAM_MPEG2TYPE *) pParamStruct; | ||
361 | |||
362 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_MPEG2TYPE, eError); | ||
363 | if( pMPEG2VideoParam->nPortIndex == OMX_VIDDEC_INPUT_PORT ) { | ||
364 | *pMPEG2VideoParam = pMPEG2VidDecComp->tMPEG2VideoParam; | ||
365 | } else if( pMPEG2VideoParam->nPortIndex == OMX_VIDDEC_OUTPUT_PORT ) { | ||
366 | OSAL_ErrorTrace("OMX_IndexParamVideoMpeg2 supported only on i/p port"); | ||
367 | eError = OMX_ErrorUnsupportedIndex; | ||
368 | } else { | ||
369 | eError = OMX_ErrorBadPortIndex; | ||
370 | } | ||
371 | break; | ||
372 | case OMX_IndexParamCommonDeblocking : | ||
373 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_PARAM_DEBLOCKINGTYPE, eError); | ||
374 | pDeblockingParam = (OMX_PARAM_DEBLOCKINGTYPE *) pParamStruct; | ||
375 | if( pDeblockingParam->nPortIndex == OMX_VIDDEC_OUTPUT_PORT ) { | ||
376 | pDeblockingParam->bDeblocking = pMPEG2VidDecComp->tDeblockingParam.bDeblocking; | ||
377 | } else if( pDeblockingParam->nPortIndex == OMX_VIDDEC_INPUT_PORT ) { | ||
378 | OSAL_ErrorTrace("\n Deblocking supported only on o/p port... \n"); | ||
379 | eError = OMX_ErrorUnsupportedIndex; | ||
380 | } else { | ||
381 | eError = OMX_ErrorBadPortIndex; | ||
382 | } | ||
383 | break; | ||
384 | case OMX_IndexParamVideoProfileLevelQuerySupported : | ||
385 | { | ||
386 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_PROFILELEVELTYPE, eError); | ||
387 | pMPEG2ProfileLevelParam = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pParamStruct; | ||
388 | if( pMPEG2ProfileLevelParam->nPortIndex == OMX_VIDDEC_INPUT_PORT ) { | ||
389 | if( pMPEG2ProfileLevelParam->nProfileIndex == 0 ) { | ||
390 | if( pVidDecComp->tVideoParams[OMX_VIDDEC_INPUT_PORT].eCompressionFormat == OMX_VIDEO_CodingMPEG2 ) { | ||
391 | pMPEG2ProfileLevelParam->eProfile = (OMX_U32) OMX_VIDEO_MPEG2ProfileSimple; | ||
392 | pMPEG2ProfileLevelParam->eLevel = (OMX_U32) OMX_VIDEO_MPEG2LevelLL; | ||
393 | } | ||
394 | } else if( pMPEG2ProfileLevelParam->nProfileIndex == 1 ) { | ||
395 | if( pVidDecComp->tVideoParams[OMX_VIDDEC_INPUT_PORT].eCompressionFormat == OMX_VIDEO_CodingMPEG2 ) { | ||
396 | pMPEG2ProfileLevelParam->eProfile = (OMX_U32) OMX_VIDEO_MPEG2ProfileMain; | ||
397 | pMPEG2ProfileLevelParam->eLevel = (OMX_U32) OMX_VIDEO_MPEG2LevelML; | ||
398 | } | ||
399 | } else { | ||
400 | eError = OMX_ErrorNoMore; | ||
401 | } | ||
402 | } else if( pMPEG2ProfileLevelParam->nPortIndex == OMX_VIDDEC_OUTPUT_PORT ) { | ||
403 | OSAL_ErrorTrace("OMX_IndexParamVideoProfileLevelQuerySupported supported only on i/p port"); | ||
404 | eError = OMX_ErrorUnsupportedIndex; | ||
405 | } else { | ||
406 | eError = OMX_ErrorBadPortIndex; | ||
407 | } | ||
408 | } | ||
409 | break; | ||
410 | |||
411 | default : | ||
412 | eError = OMXVidDec_GetParameter(hComponent, nIndex, pParamStruct); | ||
413 | } | ||
414 | |||
415 | EXIT: | ||
416 | return (eError); | ||
417 | } | ||
418 | |||
419 | |||
420 | OMX_ERRORTYPE OMXMPEG2VD_HandleError(OMX_HANDLETYPE hComponent) | ||
421 | { | ||
422 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
423 | XDAS_Int32 status = 0; | ||
424 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
425 | OMXVidDecComp *pVidDecComp = NULL; | ||
426 | |||
427 | /* Initialize pointers */ | ||
428 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
429 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
430 | |||
431 | /*! Call the Codec Status function to know cause of error */ | ||
432 | status = VIDDEC3_control(pVidDecComp->pDecHandle, | ||
433 | XDM_GETSTATUS, | ||
434 | pVidDecComp->pDecDynParams, | ||
435 | pVidDecComp->pDecStatus); | ||
436 | /* Check whether the Codec Status call was succesful */ | ||
437 | if( status != VIDDEC3_EOK ) { | ||
438 | OSAL_ErrorTrace("VIDDEC3_control XDM_GETSTATUS failed"); | ||
439 | eError = OMX_ErrorInsufficientResources; | ||
440 | goto EXIT; | ||
441 | } | ||
442 | |||
443 | ALOGE("Mpeg2: extendedErrorCode0 0x%x", (OMX_U32)((IMPEG2VDEC_Status *)(pVidDecComp->pDecStatus))->extendedErrorCode0); | ||
444 | ALOGE("Mpeg2: extendedErrorCode1 0x%x", (OMX_U32)((IMPEG2VDEC_Status *)(pVidDecComp->pDecStatus))->extendedErrorCode1); | ||
445 | ALOGE("Mpeg2: extendedErrorCode2 0x%x", (OMX_U32)((IMPEG2VDEC_Status *)(pVidDecComp->pDecStatus))->extendedErrorCode2); | ||
446 | ALOGE("Mpeg2: extendedErrorCode3 0x%x", (OMX_U32)((IMPEG2VDEC_Status *)(pVidDecComp->pDecStatus))->extendedErrorCode3); | ||
447 | |||
448 | EXIT: | ||
449 | return (eError); | ||
450 | } | ||
451 | |||
diff --git a/libstagefrighthw/omx/videodecode/omx_video_decoder_mpeg2.h b/libstagefrighthw/omx/videodecode/omx_video_decoder_mpeg2.h new file mode 100644 index 0000000..4f489f0 --- /dev/null +++ b/libstagefrighthw/omx/videodecode/omx_video_decoder_mpeg2.h | |||
@@ -0,0 +1,68 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 _OMX_MPEG2DEC_H_ | ||
18 | #define _OMX_MPEG2DEC_H_ | ||
19 | |||
20 | #ifdef __cplusplus | ||
21 | extern "C" { | ||
22 | #endif /* __cplusplus */ | ||
23 | |||
24 | /****************************************************************** | ||
25 | * INCLUDE FILES | ||
26 | ******************************************************************/ | ||
27 | #include <omx_video_decoder.h> | ||
28 | #include <ti/sdo/codecs/mpeg2vdec/impeg2vdec.h> | ||
29 | |||
30 | |||
31 | void OMXMPEG2VD_SetStaticParams(OMX_HANDLETYPE hComponent, void *staticparams); | ||
32 | |||
33 | void OMXMPEG2VD_SetDynamicParams(OMX_HANDLETYPE hComponent, void *dynamicParams); | ||
34 | |||
35 | void OMXMPEG2VD_SetStatus(OMX_HANDLETYPE hComponent, void *status); | ||
36 | |||
37 | PaddedBuffParams CalculateMPEG2VD_outbuff_details(OMX_HANDLETYPE hComponent, | ||
38 | OMX_U32 width, OMX_U32 height); | ||
39 | |||
40 | /*---------- function prototypes ------------------- */ | ||
41 | extern OMX_ERRORTYPE OMX_TI_VideoDecoder_ComponentInit(OMX_HANDLETYPE hComponent); | ||
42 | OMX_ERRORTYPE OMXMPEG2VD_Init(OMX_HANDLETYPE hComponent); | ||
43 | void OMXMPEG2VD_DeInit(OMX_HANDLETYPE hComponent); | ||
44 | OMX_ERRORTYPE OMXMPEG2VD_HandleError(OMX_HANDLETYPE hComponent); | ||
45 | |||
46 | extern OMX_ERRORTYPE OMXMPEG2VD_SetParameter(OMX_HANDLETYPE hComponent, | ||
47 | OMX_INDEXTYPE nIndex, OMX_PTR pParamStruct); | ||
48 | extern OMX_ERRORTYPE OMXMPEG2VD_GetParameter(OMX_HANDLETYPE hComponent, | ||
49 | OMX_INDEXTYPE nIndex, OMX_PTR pParamStruct); | ||
50 | |||
51 | extern OMX_ERRORTYPE OMXVidDec_SetParameter(OMX_HANDLETYPE hComponent, | ||
52 | OMX_INDEXTYPE nIndex, OMX_PTR pParamStruct); | ||
53 | extern OMX_ERRORTYPE OMXVidDec_GetParameter(OMX_HANDLETYPE hComponent, | ||
54 | OMX_INDEXTYPE nIndex, OMX_PTR pParamStruct); | ||
55 | |||
56 | |||
57 | typedef struct OMXMPEG2VidDecComp { | ||
58 | OMX_PARAM_DEBLOCKINGTYPE tDeblockingParam; | ||
59 | OMX_VIDEO_PARAM_MPEG2TYPE tMPEG2VideoParam; | ||
60 | } OMXMPEG2VidDecComp; | ||
61 | |||
62 | |||
63 | #ifdef __cplusplus | ||
64 | } | ||
65 | #endif /* __cplusplus */ | ||
66 | |||
67 | #endif /* _OMX_MPEG2DEC_H_ */ | ||
68 | |||
diff --git a/libstagefrighthw/omx/videodecode/omx_video_decoder_mpeg4.c b/libstagefrighthw/omx/videodecode/omx_video_decoder_mpeg4.c new file mode 100644 index 0000000..627903d --- /dev/null +++ b/libstagefrighthw/omx/videodecode/omx_video_decoder_mpeg4.c | |||
@@ -0,0 +1,422 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 | #define LOG_TAG "OMX_MPEG4_VIDDEC" | ||
18 | #include <omx_video_decoder_mpeg4.h> | ||
19 | |||
20 | OMX_ERRORTYPE OMXMPEG4VD_Init(OMX_HANDLETYPE hComponent) | ||
21 | { | ||
22 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
23 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
24 | OMXVidDecComp *pVidDecComp = NULL; | ||
25 | OMXMPEG4VidDecComp *pMPEG4VidDecComp = NULL; | ||
26 | |||
27 | eError = OMXMPEG4_H263VD_Init(hComponent); | ||
28 | |||
29 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
30 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
31 | |||
32 | pMPEG4VidDecComp =(OMXMPEG4VidDecComp *) pVidDecComp->pCodecSpecific; | ||
33 | pVidDecComp->tVideoParams[OMX_VIDDEC_INPUT_PORT].eCompressionFormat = OMX_VIDEO_CodingMPEG4; | ||
34 | pVidDecComp->tVideoParams[OMX_VIDDEC_OUTPUT_PORT].eCompressionFormat = OMX_VIDEO_CodingUnused; | ||
35 | pMPEG4VidDecComp->bIsSorensonSpark = OMX_FALSE; | ||
36 | |||
37 | return (eError); | ||
38 | } | ||
39 | |||
40 | OMX_ERRORTYPE OMXH263VD_Init(OMX_HANDLETYPE hComponent) | ||
41 | { | ||
42 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
43 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
44 | OMXVidDecComp *pVidDecComp = NULL; | ||
45 | OMXMPEG4VidDecComp *pMPEG4VidDecComp = NULL; | ||
46 | |||
47 | eError = OMXMPEG4_H263VD_Init(hComponent); | ||
48 | |||
49 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
50 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
51 | pMPEG4VidDecComp =(OMXMPEG4VidDecComp *) pVidDecComp->pCodecSpecific; | ||
52 | |||
53 | pVidDecComp->tVideoParams[OMX_VIDDEC_INPUT_PORT].eCompressionFormat = OMX_VIDEO_CodingH263; | ||
54 | pVidDecComp->tVideoParams[OMX_VIDDEC_OUTPUT_PORT].eCompressionFormat = OMX_VIDEO_CodingUnused; | ||
55 | |||
56 | pMPEG4VidDecComp->bIsSorensonSpark = OMX_FALSE; | ||
57 | |||
58 | return (eError); | ||
59 | } | ||
60 | |||
61 | OMX_ERRORTYPE OMXMPEG4_H263VD_Init(OMX_HANDLETYPE hComponent) | ||
62 | { | ||
63 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
64 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
65 | OMXVidDecComp *pVidDecComp = NULL; | ||
66 | OMXMPEG4VidDecComp *pMPEG4VidDecComp = NULL; | ||
67 | |||
68 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
69 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
70 | |||
71 | /*! Initialize the function pointers */ | ||
72 | pVidDecComp->fpSet_StaticParams = OMXMPEG4VD_SetStaticParams; | ||
73 | pVidDecComp->fpSet_DynamicParams = OMXMPEG4VD_SetDynamicParams; | ||
74 | pVidDecComp->fpSet_Status = OMXMPEG4VD_SetStatus; | ||
75 | pVidDecComp->fpCalc_OubuffDetails = CalculateMPEG4VD_outbuff_details; | ||
76 | pVidDecComp->fpDeinit_Codec = OMXMPEG4VD_DeInit; | ||
77 | pVidDecComp->cDecoderName = "ivahd_mpeg4dec"; | ||
78 | pHandle->SetParameter = OMXMPEG4VD_SetParameter; | ||
79 | pHandle->GetParameter = OMXMPEG4VD_GetParameter; | ||
80 | pVidDecComp->fpHandle_ExtendedError = OMXMPEG4VD_HandleError; | ||
81 | |||
82 | /*! Initialize the framerate divisor to 10000 as WA because MPEG4 codec is providing framerate by multiplying with 10000 instead of 1000*/ | ||
83 | pVidDecComp->nFrameRateDivisor = 10000; | ||
84 | |||
85 | pVidDecComp->pCodecSpecific = (OMXMPEG4VidDecComp *) OSAL_Malloc(sizeof (OMXMPEG4VidDecComp)); | ||
86 | OMX_CHECK((pVidDecComp->pCodecSpecific) != NULL, OMX_ErrorInsufficientResources); | ||
87 | |||
88 | pMPEG4VidDecComp =(OMXMPEG4VidDecComp *) pVidDecComp->pCodecSpecific; | ||
89 | |||
90 | OMX_BASE_INIT_STRUCT_PTR(&(pMPEG4VidDecComp->tDeblockingParam), OMX_PARAM_DEBLOCKINGTYPE); | ||
91 | pMPEG4VidDecComp->tDeblockingParam.nPortIndex = OMX_VIDDEC_OUTPUT_PORT; | ||
92 | pMPEG4VidDecComp->tDeblockingParam.bDeblocking = OMX_TRUE; | ||
93 | |||
94 | OMX_BASE_INIT_STRUCT_PTR(&(pMPEG4VidDecComp->tMPEG4VideoParam), OMX_VIDEO_PARAM_MPEG4TYPE); | ||
95 | pMPEG4VidDecComp->tMPEG4VideoParam.nPortIndex = OMX_VIDDEC_INPUT_PORT; | ||
96 | pMPEG4VidDecComp->tMPEG4VideoParam.eProfile = OMX_VIDEO_MPEG4ProfileAdvancedSimple; | ||
97 | pMPEG4VidDecComp->tMPEG4VideoParam.eLevel = OMX_VIDEO_MPEG4Level5; | ||
98 | |||
99 | /*! Allocate Memory for Static Parameter */ | ||
100 | pVidDecComp->pDecStaticParams = (IVIDDEC3_Params *) memplugin_alloc(sizeof(IMPEG4VDEC_Params), 1, MEM_CARVEOUT, 0, 0); | ||
101 | OMX_CHECK(pVidDecComp->pDecStaticParams != NULL, OMX_ErrorInsufficientResources); | ||
102 | OSAL_Memset(pVidDecComp->pDecStaticParams, 0x0, sizeof(IMPEG4VDEC_Params)); | ||
103 | |||
104 | /*! Allocate Memory for Dynamic Parameter */ | ||
105 | pVidDecComp->pDecDynParams = (IVIDDEC3_DynamicParams *)memplugin_alloc(sizeof(IMPEG4VDEC_DynamicParams), 1, MEM_CARVEOUT, 0, 0); | ||
106 | OMX_CHECK(pVidDecComp->pDecDynParams != NULL, OMX_ErrorInsufficientResources); | ||
107 | OSAL_Memset(pVidDecComp->pDecDynParams, 0x0, sizeof(IMPEG4VDEC_DynamicParams)); | ||
108 | |||
109 | /*! Allocate Memory for Status Structure */ | ||
110 | pVidDecComp->pDecStatus = (IVIDDEC3_Status *) memplugin_alloc(sizeof(IMPEG4VDEC_Status), 1, MEM_CARVEOUT, 0, 0); | ||
111 | OMX_CHECK(pVidDecComp->pDecStatus != NULL, OMX_ErrorInsufficientResources); | ||
112 | OSAL_Memset(pVidDecComp->pDecStatus, 0x0, sizeof(IMPEG4VDEC_Status)); | ||
113 | |||
114 | /*! Allocate Memory for Input Arguments */ | ||
115 | pVidDecComp->pDecInArgs = (IVIDDEC3_InArgs *) memplugin_alloc(sizeof(IMPEG4VDEC_InArgs), 1, MEM_CARVEOUT, 0, 0); | ||
116 | OMX_CHECK(pVidDecComp->pDecInArgs != NULL, OMX_ErrorInsufficientResources); | ||
117 | OSAL_Memset(pVidDecComp->pDecInArgs, 0x0, sizeof(IMPEG4VDEC_InArgs)); | ||
118 | |||
119 | /*! Allocate Memory for Output Arguments */ | ||
120 | pVidDecComp->pDecOutArgs = (IVIDDEC3_OutArgs *) memplugin_alloc(sizeof(IMPEG4VDEC_OutArgs), 1, MEM_CARVEOUT, 0, 0); | ||
121 | OMX_CHECK(pVidDecComp->pDecOutArgs != NULL, OMX_ErrorInsufficientResources); | ||
122 | OSAL_Memset(pVidDecComp->pDecOutArgs, 0x0, sizeof(IMPEG4VDEC_OutArgs)); | ||
123 | |||
124 | pVidDecComp->pDecInArgs->size = sizeof(IMPEG4VDEC_InArgs); | ||
125 | pVidDecComp->pDecOutArgs->size = sizeof(IMPEG4VDEC_OutArgs); | ||
126 | |||
127 | pVidDecComp->pDecStaticParams->metadataType[0] = IVIDEO_METADATAPLANE_NONE; | ||
128 | pVidDecComp->pDecStaticParams->metadataType[1] = IVIDEO_METADATAPLANE_NONE; | ||
129 | pVidDecComp->pDecStaticParams->metadataType[2] = IVIDEO_METADATAPLANE_NONE; | ||
130 | |||
131 | pVidDecComp->pDecStaticParams->operatingMode = IVIDEO_DECODE_ONLY; | ||
132 | |||
133 | pVidDecComp->pDecStaticParams->inputDataMode = IVIDEO_ENTIREFRAME; | ||
134 | pVidDecComp->pDecStaticParams->numInputDataUnits = 0; | ||
135 | |||
136 | EXIT: | ||
137 | return (eError); | ||
138 | } | ||
139 | |||
140 | void OMXMPEG4VD_SetStaticParams(OMX_HANDLETYPE hComponent, void *staticparams) | ||
141 | { | ||
142 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
143 | OMXVidDecComp *pVidDecComp = NULL; | ||
144 | OMXMPEG4VidDecComp *pMPEG4VidDecComp = NULL; | ||
145 | IMPEG4VDEC_Params *params; | ||
146 | |||
147 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
148 | pVidDecComp | ||
149 | = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
150 | |||
151 | pMPEG4VidDecComp = | ||
152 | (OMXMPEG4VidDecComp *) pVidDecComp->pCodecSpecific; | ||
153 | |||
154 | params = (IMPEG4VDEC_Params *) staticparams; | ||
155 | |||
156 | params->viddec3Params.size = sizeof(IMPEG4VDEC_Params); | ||
157 | params->viddec3Params.maxFrameRate = 300000; | ||
158 | params->viddec3Params.maxBitRate = 10000000; | ||
159 | params->viddec3Params.dataEndianness = XDM_BYTE; | ||
160 | params->viddec3Params.forceChromaFormat = XDM_YUV_420SP; | ||
161 | params->viddec3Params.displayDelay = IVIDDEC3_DISPLAY_DELAY_1; | ||
162 | params->viddec3Params.inputDataMode = IVIDEO_ENTIREFRAME; | ||
163 | params->viddec3Params.numInputDataUnits = 0; | ||
164 | params->viddec3Params.outputDataMode = IVIDEO_ENTIREFRAME; | ||
165 | params->viddec3Params.displayBufsMode = IVIDDEC3_DISPLAYBUFS_EMBEDDED; | ||
166 | |||
167 | params->viddec3Params.errorInfoMode = IVIDEO_ERRORINFO_OFF; | ||
168 | params->outloopDeBlocking = IMPEG4VDEC_DEBLOCK_DISABLE; | ||
169 | params->enhancedDeBlockingQp = 31; | ||
170 | params->sorensonSparkStream = pMPEG4VidDecComp->bIsSorensonSpark; | ||
171 | params->errorConcealmentEnable = pVidDecComp->sBase.pPorts[OMX_VIDDEC_INPUT_PORT]->sPortDef.format.video.bFlagErrorConcealment; | ||
172 | params->debugTraceLevel = 0; | ||
173 | params->lastNFramesToLog = 0; | ||
174 | params->paddingMode = IMPEG4VDEC_MPEG4_MODE_PADDING; | ||
175 | |||
176 | return; | ||
177 | } | ||
178 | |||
179 | |||
180 | void OMXMPEG4VD_SetDynamicParams(OMX_HANDLETYPE hComponent, void *dynParams) | ||
181 | { | ||
182 | IMPEG4VDEC_DynamicParams *dynamicParams; | ||
183 | (void)hComponent; | ||
184 | |||
185 | dynamicParams = (IMPEG4VDEC_DynamicParams *)dynParams; | ||
186 | |||
187 | /*! Update the Individual fields in the Dyanmic Params of MPEG4 decoder */ | ||
188 | dynamicParams->viddec3DynamicParams.size = sizeof(IMPEG4VDEC_DynamicParams); | ||
189 | dynamicParams->viddec3DynamicParams.decodeHeader = XDM_DECODE_AU; | ||
190 | dynamicParams->viddec3DynamicParams.displayWidth = 0; | ||
191 | dynamicParams->viddec3DynamicParams.frameSkipMode = IVIDEO_NO_SKIP; | ||
192 | dynamicParams->viddec3DynamicParams.newFrameFlag = XDAS_TRUE; | ||
193 | dynamicParams->viddec3DynamicParams.putDataFxn = NULL; | ||
194 | dynamicParams->viddec3DynamicParams.putDataHandle = NULL; | ||
195 | dynamicParams->viddec3DynamicParams.getDataFxn = NULL; | ||
196 | dynamicParams->viddec3DynamicParams.getDataHandle = NULL; | ||
197 | dynamicParams->viddec3DynamicParams.putBufferFxn = NULL; | ||
198 | dynamicParams->viddec3DynamicParams.putBufferHandle = NULL; | ||
199 | return; | ||
200 | } | ||
201 | |||
202 | |||
203 | void OMXMPEG4VD_SetStatus(OMX_HANDLETYPE hComponent, void *decstatus) | ||
204 | { | ||
205 | IMPEG4VDEC_Status *status; | ||
206 | (void)hComponent; | ||
207 | |||
208 | status = (IMPEG4VDEC_Status *)decstatus; | ||
209 | |||
210 | status->viddec3Status.size = sizeof(IMPEG4VDEC_Status); | ||
211 | return; | ||
212 | } | ||
213 | |||
214 | |||
215 | PaddedBuffParams CalculateMPEG4VD_outbuff_details(OMX_HANDLETYPE hComponent, | ||
216 | OMX_U32 width, OMX_U32 height) | ||
217 | { | ||
218 | PaddedBuffParams OutBuffDetails; | ||
219 | (void)hComponent; | ||
220 | |||
221 | OutBuffDetails.nBufferSize = ((((width + PADX + 127) & ~127) * (height + PADY))); | ||
222 | /* Multiply buffer size by 1.5 to account for both luma and chroma */ | ||
223 | OutBuffDetails.nBufferSize = (OutBuffDetails.nBufferSize * 3) >> 1; | ||
224 | |||
225 | OutBuffDetails.nBufferCountMin = 4; | ||
226 | OutBuffDetails.nBufferCountActual = 8; | ||
227 | OutBuffDetails.n1DBufferAlignment = 16; | ||
228 | OutBuffDetails.nPaddedWidth = (width + PADX + 127) & ~127; | ||
229 | OutBuffDetails.nPaddedHeight = height + PADY; | ||
230 | OutBuffDetails.n2DBufferYAlignment = 1; | ||
231 | OutBuffDetails.n2DBufferXAlignment = 16; | ||
232 | return (OutBuffDetails); | ||
233 | } | ||
234 | |||
235 | |||
236 | void OMXMPEG4VD_DeInit(OMX_HANDLETYPE hComponent) | ||
237 | { | ||
238 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
239 | OMXVidDecComp *pVidDecComp = NULL; | ||
240 | |||
241 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
242 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
243 | /*! Delete all the memory which was allocated during init of decoder */ | ||
244 | if( pVidDecComp->pDecStaticParams ) { | ||
245 | memplugin_free(pVidDecComp->pDecStaticParams); | ||
246 | pVidDecComp->pDecStaticParams = NULL; | ||
247 | } | ||
248 | if( pVidDecComp->pDecDynParams ) { | ||
249 | memplugin_free(pVidDecComp->pDecDynParams); | ||
250 | pVidDecComp->pDecDynParams = NULL; | ||
251 | } | ||
252 | if( pVidDecComp->pDecStatus ) { | ||
253 | memplugin_free(pVidDecComp->pDecStatus); | ||
254 | pVidDecComp->pDecStatus = NULL; | ||
255 | } | ||
256 | if( pVidDecComp->pDecInArgs ) { | ||
257 | memplugin_free(pVidDecComp->pDecInArgs); | ||
258 | pVidDecComp->pDecInArgs = NULL; | ||
259 | } | ||
260 | if( pVidDecComp->pDecOutArgs ) { | ||
261 | memplugin_free(pVidDecComp->pDecOutArgs); | ||
262 | pVidDecComp->pDecOutArgs = NULL; | ||
263 | } | ||
264 | if( pVidDecComp->pCodecSpecific ) { | ||
265 | OSAL_Free(pVidDecComp->pCodecSpecific); | ||
266 | pVidDecComp->pCodecSpecific = NULL; | ||
267 | } | ||
268 | pHandle->SetParameter = OMXVidDec_SetParameter; | ||
269 | pHandle->GetParameter = OMXVidDec_GetParameter; | ||
270 | pVidDecComp->fpHandle_ExtendedError = NULL; | ||
271 | pVidDecComp->nFrameRateDivisor = 1000; | ||
272 | } | ||
273 | |||
274 | OMX_ERRORTYPE OMXMPEG4VD_SetParameter(OMX_HANDLETYPE hComponent, | ||
275 | OMX_INDEXTYPE nIndex, OMX_PTR pParamStruct) | ||
276 | { | ||
277 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
278 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
279 | OMXVidDecComp *pVidDecComp = NULL; | ||
280 | OMXMPEG4VidDecComp *pMPEG4VidDecComp = NULL; | ||
281 | OMX_PARAM_DEBLOCKINGTYPE *pDeblockingParam = NULL; | ||
282 | OMX_VIDEO_PARAM_MPEG4TYPE *pMPEG4VideoParam = NULL; | ||
283 | |||
284 | OMX_CHECK((hComponent != NULL) && (pParamStruct != NULL), | ||
285 | OMX_ErrorBadParameter); | ||
286 | |||
287 | /*! Initialize the pointers */ | ||
288 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
289 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
290 | pMPEG4VidDecComp =(OMXMPEG4VidDecComp *) pVidDecComp->pCodecSpecific; | ||
291 | |||
292 | switch( nIndex ) { | ||
293 | case OMX_IndexParamVideoMpeg4 : | ||
294 | pMPEG4VideoParam = (OMX_VIDEO_PARAM_MPEG4TYPE *) pParamStruct; | ||
295 | /* SetParameter can be invoked in Loaded State or on Disabled ports only*/ | ||
296 | OMX_CHECK((pVidDecComp->sBase.tCurState == OMX_StateLoaded) || | ||
297 | (pVidDecComp->sBase.pPorts[pMPEG4VideoParam->nPortIndex]->sPortDef.bEnabled == OMX_FALSE), | ||
298 | OMX_ErrorIncorrectStateOperation); | ||
299 | |||
300 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_MPEG4TYPE, eError); | ||
301 | OMX_CHECK(pMPEG4VideoParam->eProfile == OMX_VIDEO_MPEG4ProfileSimple | ||
302 | || pMPEG4VideoParam->eProfile == OMX_VIDEO_MPEG4ProfileMain | ||
303 | || pMPEG4VideoParam->eProfile == OMX_VIDEO_MPEG4ProfileAdvancedSimple, | ||
304 | OMX_ErrorUnsupportedSetting); | ||
305 | if( pMPEG4VideoParam->nPortIndex == OMX_VIDDEC_INPUT_PORT ) { | ||
306 | pMPEG4VidDecComp->tMPEG4VideoParam = *pMPEG4VideoParam; | ||
307 | } else if( pMPEG4VideoParam->nPortIndex == OMX_VIDDEC_OUTPUT_PORT ) { | ||
308 | OSAL_ErrorTrace("OMX_IndexParamVideoMpeg4 supported only on i/p port"); | ||
309 | eError = OMX_ErrorUnsupportedIndex; | ||
310 | } else { | ||
311 | eError = OMX_ErrorBadPortIndex; | ||
312 | } | ||
313 | break; | ||
314 | |||
315 | default : | ||
316 | eError = OMXVidDec_SetParameter(hComponent, nIndex, pParamStruct); | ||
317 | } | ||
318 | |||
319 | EXIT: | ||
320 | return (eError); | ||
321 | } | ||
322 | |||
323 | OMX_ERRORTYPE OMXMPEG4VD_GetParameter(OMX_HANDLETYPE hComponent, | ||
324 | OMX_INDEXTYPE nIndex, OMX_PTR pParamStruct) | ||
325 | { | ||
326 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
327 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
328 | OMXVidDecComp *pVidDecComp = NULL; | ||
329 | OMXMPEG4VidDecComp *pMPEG4VidDecComp = NULL; | ||
330 | OMX_PARAM_DEBLOCKINGTYPE *pDeblockingParam = NULL; | ||
331 | OMX_VIDEO_PARAM_MPEG4TYPE *pMPEG4VideoParam = NULL; | ||
332 | OMX_VIDEO_PARAM_PROFILELEVELTYPE *pMPEG4ProfileLevelParam = NULL; | ||
333 | |||
334 | OMX_CHECK((hComponent != NULL) && (pParamStruct != NULL), | ||
335 | OMX_ErrorBadParameter); | ||
336 | |||
337 | /*! Initialize the pointers */ | ||
338 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
339 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
340 | /* GetParameter can't be invoked incase the comp is in Invalid State */ | ||
341 | OMX_CHECK(pVidDecComp->sBase.tCurState != OMX_StateInvalid, | ||
342 | OMX_ErrorIncorrectStateOperation); | ||
343 | |||
344 | pMPEG4VidDecComp =(OMXMPEG4VidDecComp *) pVidDecComp->pCodecSpecific; | ||
345 | |||
346 | switch( nIndex ) { | ||
347 | case OMX_IndexParamVideoMpeg4 : | ||
348 | pMPEG4VideoParam = (OMX_VIDEO_PARAM_MPEG4TYPE *) pParamStruct; | ||
349 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_MPEG4TYPE, eError); | ||
350 | if( pMPEG4VideoParam->nPortIndex == OMX_VIDDEC_INPUT_PORT ) { | ||
351 | *pMPEG4VideoParam = pMPEG4VidDecComp->tMPEG4VideoParam; | ||
352 | } else if( pMPEG4VideoParam->nPortIndex == OMX_VIDDEC_OUTPUT_PORT ) { | ||
353 | OSAL_ErrorTrace("OMX_IndexParamVideoMpeg4 supported only on i/p port"); | ||
354 | eError = OMX_ErrorUnsupportedIndex; | ||
355 | } else { | ||
356 | eError = OMX_ErrorBadPortIndex; | ||
357 | } | ||
358 | break; | ||
359 | case OMX_IndexParamVideoProfileLevelQuerySupported : | ||
360 | { | ||
361 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_PROFILELEVELTYPE, eError); | ||
362 | pMPEG4ProfileLevelParam = (OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pParamStruct; | ||
363 | if( pMPEG4ProfileLevelParam->nPortIndex == OMX_VIDDEC_INPUT_PORT ) { | ||
364 | if( pMPEG4ProfileLevelParam->nProfileIndex == 0 ) { | ||
365 | if( pVidDecComp->sBase.pPorts[pMPEG4ProfileLevelParam->nPortIndex]->sPortDef.format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ) { | ||
366 | pMPEG4ProfileLevelParam->eProfile = (OMX_U32) OMX_VIDEO_MPEG4ProfileSimple; | ||
367 | pMPEG4ProfileLevelParam->eLevel = (OMX_U32) OMX_VIDEO_MPEG4LevelMax; | ||
368 | } else if( pVidDecComp->sBase.pPorts[pMPEG4ProfileLevelParam->nPortIndex]->sPortDef.format.video.eCompressionFormat == OMX_VIDEO_CodingH263 ) { | ||
369 | pMPEG4ProfileLevelParam->eProfile = (OMX_U32) OMX_VIDEO_H263ProfileBaseline; | ||
370 | pMPEG4ProfileLevelParam->eLevel = (OMX_U32) OMX_VIDEO_H263Level70; | ||
371 | } | ||
372 | } else if( pMPEG4ProfileLevelParam->nProfileIndex == 1 ) { | ||
373 | if(pVidDecComp->sBase.pPorts[pMPEG4ProfileLevelParam->nPortIndex]->sPortDef.format.video.eCompressionFormat == OMX_VIDEO_CodingMPEG4 ) { | ||
374 | pMPEG4ProfileLevelParam->eProfile = (OMX_U32) OMX_VIDEO_MPEG4ProfileAdvancedSimple; | ||
375 | pMPEG4ProfileLevelParam->eLevel = (OMX_U32) OMX_VIDEO_MPEG4LevelMax; | ||
376 | } else if( pVidDecComp->sBase.pPorts[pMPEG4ProfileLevelParam->nPortIndex]->sPortDef.format.video.eCompressionFormat == OMX_VIDEO_CodingH263 ) { | ||
377 | pMPEG4ProfileLevelParam->eProfile = (OMX_U32) OMX_VIDEO_H263ProfileISWV2; | ||
378 | pMPEG4ProfileLevelParam->eLevel = (OMX_U32) OMX_VIDEO_H263Level70; | ||
379 | } | ||
380 | } else { | ||
381 | eError = OMX_ErrorNoMore; | ||
382 | } | ||
383 | } else if( pMPEG4ProfileLevelParam->nPortIndex == OMX_VIDDEC_OUTPUT_PORT ) { | ||
384 | OSAL_ErrorTrace("OMX_IndexParamVideoProfileLevelQuerySupported supported only on i/p port"); | ||
385 | eError = OMX_ErrorUnsupportedIndex; | ||
386 | } else { | ||
387 | eError = OMX_ErrorBadPortIndex; | ||
388 | } | ||
389 | } | ||
390 | break; | ||
391 | default : | ||
392 | eError = OMXVidDec_GetParameter(hComponent, nIndex, pParamStruct); | ||
393 | } | ||
394 | |||
395 | EXIT: | ||
396 | return (eError); | ||
397 | } | ||
398 | |||
399 | |||
400 | OMX_ERRORTYPE OMXMPEG4VD_HandleError(OMX_HANDLETYPE hComponent) | ||
401 | { | ||
402 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
403 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
404 | OMXVidDecComp *pVidDecComp = NULL; | ||
405 | |||
406 | /* Initialize pointers */ | ||
407 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
408 | pVidDecComp = (OMXVidDecComp *)pHandle->pComponentPrivate; | ||
409 | /* To send the output buffer to display in case of no valid VOL/VOP header */ | ||
410 | |||
411 | if((!(pVidDecComp->pDecOutArgs->extendedError & 0x8000) | ||
412 | && ((pVidDecComp->pDecOutArgs->extendedError & 0x100000) | ||
413 | || (pVidDecComp->pDecOutArgs->extendedError & 0x80000))) | ||
414 | && (pVidDecComp->pDecInArgs->inputID == pVidDecComp->pDecOutArgs->freeBufID[0] | ||
415 | && pVidDecComp->pDecOutArgs->outputID[0] == 0)) { | ||
416 | pVidDecComp->pDecOutArgs->outputID[0] = pVidDecComp->pDecInArgs->inputID; | ||
417 | pVidDecComp->bSyncFrameReady = OMX_TRUE; | ||
418 | } | ||
419 | |||
420 | return (eError); | ||
421 | } | ||
422 | |||
diff --git a/libstagefrighthw/omx/videodecode/omx_video_decoder_mpeg4.h b/libstagefrighthw/omx/videodecode/omx_video_decoder_mpeg4.h new file mode 100644 index 0000000..4aadbfe --- /dev/null +++ b/libstagefrighthw/omx/videodecode/omx_video_decoder_mpeg4.h | |||
@@ -0,0 +1,71 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 _OMX_MPEG4VD_H_ | ||
18 | #define _OMX_MPEG4VD_H_ | ||
19 | |||
20 | #ifdef __cplusplus | ||
21 | extern "C" { | ||
22 | #endif | ||
23 | |||
24 | #include <omx_video_decoder.h> | ||
25 | #include <ti/sdo/codecs/mpeg4vdec/impeg4vdec.h> | ||
26 | |||
27 | /*! Padding for width as per Codec Requirement */ | ||
28 | #define PADX (32) | ||
29 | /*! Padding for height as per Codec requirement */ | ||
30 | #define PADY (32) | ||
31 | |||
32 | |||
33 | void OMXMPEG4VD_SetStaticParams(OMX_HANDLETYPE hComponent, void *staticparams); | ||
34 | |||
35 | void OMXMPEG4VD_SetDynamicParams(OMX_HANDLETYPE hComponent, void *dynamicParams); | ||
36 | |||
37 | void OMXMPEG4VD_SetStatus(OMX_HANDLETYPE hComponent, void *status); | ||
38 | |||
39 | PaddedBuffParams CalculateMPEG4VD_outbuff_details(OMX_HANDLETYPE hComponent, | ||
40 | OMX_U32 width, OMX_U32 height); | ||
41 | |||
42 | OMX_ERRORTYPE OMXMPEG4VD_Init(OMX_HANDLETYPE hComponent); | ||
43 | OMX_ERRORTYPE OMXH263VD_Init(OMX_HANDLETYPE hComponent); | ||
44 | OMX_ERRORTYPE OMXMPEG4_H263VD_Init(OMX_HANDLETYPE hComponent); | ||
45 | void OMXMPEG4VD_DeInit(OMX_HANDLETYPE hComponent); | ||
46 | OMX_ERRORTYPE OMXMPEG4VD_HandleError(OMX_HANDLETYPE hComponent); | ||
47 | |||
48 | extern OMX_ERRORTYPE OMXMPEG4VD_SetParameter(OMX_HANDLETYPE hComponent, | ||
49 | OMX_INDEXTYPE nIndex, OMX_PTR pParamStruct); | ||
50 | extern OMX_ERRORTYPE OMXMPEG4VD_GetParameter(OMX_HANDLETYPE hComponent, | ||
51 | OMX_INDEXTYPE nIndex, OMX_PTR pParamStruct); | ||
52 | |||
53 | extern OMX_ERRORTYPE OMXVidDec_SetParameter(OMX_HANDLETYPE hComponent, | ||
54 | OMX_INDEXTYPE nIndex, OMX_PTR pParamStruct); | ||
55 | extern OMX_ERRORTYPE OMXVidDec_GetParameter(OMX_HANDLETYPE hComponent, | ||
56 | OMX_INDEXTYPE nIndex, OMX_PTR pParamStruct); | ||
57 | |||
58 | |||
59 | typedef struct OMXMPEG4VidDecComp { | ||
60 | OMX_PARAM_DEBLOCKINGTYPE tDeblockingParam; | ||
61 | OMX_VIDEO_PARAM_MPEG4TYPE tMPEG4VideoParam; | ||
62 | OMX_BOOL bIsSorensonSpark; | ||
63 | } OMXMPEG4VidDecComp; | ||
64 | |||
65 | |||
66 | #ifdef __cplusplus | ||
67 | } | ||
68 | #endif | ||
69 | |||
70 | #endif /* _OMX_MPEG4VD_H_ */ | ||
71 | |||
diff --git a/libstagefrighthw/omx/videoencode/Android.bp b/libstagefrighthw/omx/videoencode/Android.bp new file mode 100644 index 0000000..39e6c0c --- /dev/null +++ b/libstagefrighthw/omx/videoencode/Android.bp | |||
@@ -0,0 +1,32 @@ | |||
1 | cc_library_shared { | ||
2 | |||
3 | name: "libOMX.ti.ducati.video.encoder", | ||
4 | vendor: true, | ||
5 | |||
6 | srcs: [ | ||
7 | "omx_video_encoder_h264.c", | ||
8 | "omx_video_encoder_h264_utils.c", | ||
9 | ], | ||
10 | |||
11 | header_libs: [ | ||
12 | "gralloc.am57x_headers", | ||
13 | "libutils_headers", | ||
14 | "media_plugin_headers", | ||
15 | ], | ||
16 | |||
17 | shared_libs: [ | ||
18 | "libc", | ||
19 | "libdce", | ||
20 | "libhardware", | ||
21 | "liblog", | ||
22 | "libosal", | ||
23 | "libOMX.ti.ducati.base", | ||
24 | ], | ||
25 | |||
26 | cflags: [ | ||
27 | "-DSUPPORT_ANDROID_FRAMEBUFFER_HAL", | ||
28 | "-DSUPPORT_ANDROID_MEMTRACK_HAL", | ||
29 | "-DBUILDOS_ANDROID", | ||
30 | ], | ||
31 | |||
32 | } | ||
diff --git a/libstagefrighthw/omx/videoencode/omx_video_encoder_h264.c b/libstagefrighthw/omx/videoencode/omx_video_encoder_h264.c new file mode 100644 index 0000000..fd50c18 --- /dev/null +++ b/libstagefrighthw/omx/videoencode/omx_video_encoder_h264.c | |||
@@ -0,0 +1,2282 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 | #define LOG_TAG "OMX_H264_ENCODER" | ||
18 | |||
19 | #include <media/hardware/MetadataBufferType.h> | ||
20 | #include "omx_video_encoder_h264.h" | ||
21 | #include <OMX_IndexExt.h> | ||
22 | #include <libdce.h> | ||
23 | |||
24 | #define COLORCONVERT_MAX_SUB_BUFFERS (3) | ||
25 | |||
26 | #define COLORCONVERT_BUFTYPE_VIRTUAL (0x0) | ||
27 | #define COLORCONVERT_BUFTYPE_ION (0x1) | ||
28 | #define COLORCONVERT_BUFTYPE_GRALLOCOPAQUE (0x2) | ||
29 | |||
30 | static OMX_ERRORTYPE OMXH264VE_GetParameter(OMX_HANDLETYPE hComponent, | ||
31 | OMX_INDEXTYPE nParamIndex, | ||
32 | OMX_PTR pParamStruct); | ||
33 | |||
34 | static OMX_ERRORTYPE OMXH264VE_SetParameter(OMX_HANDLETYPE hComponent, | ||
35 | OMX_INDEXTYPE nParamIndex, | ||
36 | OMX_PTR pParamStruct); | ||
37 | |||
38 | static OMX_ERRORTYPE OMXH264VE_GetConfig(OMX_HANDLETYPE hComponent, | ||
39 | OMX_INDEXTYPE nIndex, | ||
40 | OMX_PTR pConfigData); | ||
41 | |||
42 | static OMX_ERRORTYPE OMXH264VE_SetConfig(OMX_HANDLETYPE hComponent, | ||
43 | OMX_INDEXTYPE nIndex, | ||
44 | OMX_PTR pConfigData); | ||
45 | |||
46 | static OMX_ERRORTYPE OMXH264VE_ComponentTunnelRequest(OMX_HANDLETYPE hComponent, | ||
47 | OMX_U32 nPort, | ||
48 | OMX_HANDLETYPE hTunneledComp, | ||
49 | OMX_U32 nTunneledPort, | ||
50 | OMX_TUNNELSETUPTYPE *pTunnelSetup); | ||
51 | |||
52 | static OMX_ERRORTYPE OMXH264VE_CommandNotify(OMX_HANDLETYPE hComponent, | ||
53 | OMX_COMMANDTYPE Cmd, | ||
54 | OMX_U32 nParam, | ||
55 | OMX_PTR pCmdData); | ||
56 | |||
57 | static OMX_ERRORTYPE OMXH264VE_DataNotify(OMX_HANDLETYPE hComponent); | ||
58 | |||
59 | |||
60 | static OMX_ERRORTYPE OMXH264VE_ComponentDeinit(OMX_IN OMX_HANDLETYPE hComponent); | ||
61 | |||
62 | |||
63 | static OMX_ERRORTYPE OMXH264VE_GetExtensionIndex(OMX_HANDLETYPE hComponent, | ||
64 | OMX_STRING cParameterName, | ||
65 | OMX_INDEXTYPE *pIndexType); | ||
66 | |||
67 | |||
68 | int COLORCONVERT_PlatformOpaqueToNV12(void *hCC, | ||
69 | void *pSrc[COLORCONVERT_MAX_SUB_BUFFERS], | ||
70 | void *pDst[COLORCONVERT_MAX_SUB_BUFFERS], | ||
71 | int nWidth, int nHeight, int nStride, | ||
72 | int nSrcBufType,int nDstBufType) | ||
73 | { | ||
74 | IMG_gralloc_module_public_t const* module = hCC; | ||
75 | int nErr = -1; | ||
76 | (void)nStride; | ||
77 | |||
78 | if((nSrcBufType == COLORCONVERT_BUFTYPE_GRALLOCOPAQUE) && (nDstBufType == COLORCONVERT_BUFTYPE_VIRTUAL)) { | ||
79 | nErr = module->Blit(module, pSrc[0], pDst, HAL_PIXEL_FORMAT_NV12); | ||
80 | } else if((nSrcBufType == COLORCONVERT_BUFTYPE_GRALLOCOPAQUE) && (nDstBufType == COLORCONVERT_BUFTYPE_GRALLOCOPAQUE )) { | ||
81 | nErr = module->Blit2(module, pSrc[0], pDst[0], nWidth, nHeight, 0, 0); | ||
82 | } | ||
83 | |||
84 | return nErr; | ||
85 | } | ||
86 | |||
87 | OMX_ERRORTYPE OMX_ComponentInit(OMX_HANDLETYPE hComponent) | ||
88 | { | ||
89 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
90 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
91 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
92 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
93 | |||
94 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
95 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
96 | |||
97 | OMX_BASE_CHK_VERSION(pHandle, OMX_COMPONENTTYPE, eError); | ||
98 | |||
99 | /* Allocate memory for H264VE Component's private data area */ | ||
100 | pHandle->pComponentPrivate = (OMXH264VidEncComp *)OSAL_Malloc(sizeof(OMXH264VidEncComp)); | ||
101 | OMX_CHECK(pHandle->pComponentPrivate != NULL, OMX_ErrorInsufficientResources); | ||
102 | tStatus = OSAL_Memset(pHandle->pComponentPrivate, 0x0, sizeof(OMXH264VidEncComp)); | ||
103 | OMX_CHECK(tStatus == OSAL_ErrNone, OMX_ErrorBadParameter); | ||
104 | |||
105 | /*Initialize the Component Private handle*/ | ||
106 | pH264VEComp = (OMXH264VidEncComp *)pHandle->pComponentPrivate; | ||
107 | |||
108 | eError= OMXH264VE_InitFields(pHandle); | ||
109 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
110 | |||
111 | /*initialize the Hooks to Notify Command and Data from Base Comp to Derived Comp */ | ||
112 | pH264VEComp->sBase.fpCommandNotify = OMXH264VE_CommandNotify; | ||
113 | pH264VEComp->sBase.fpDataNotify = OMXH264VE_DataNotify; | ||
114 | |||
115 | /* initialize the base component */ | ||
116 | eError = OMXBase_ComponentInit(hComponent); | ||
117 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
118 | |||
119 | strcpy((char *)pH264VEComp->sBase.pPvtData->cTaskName, "H264VideoEncoder"); | ||
120 | pH264VEComp->sBase.pPvtData->nStackSize = OMX_H264VE_STACKSIZE; | ||
121 | pH264VEComp->sBase.pPvtData->nPrioirty = OMX_H264VE_DEFAULT_TASKPRIORITY; | ||
122 | |||
123 | /*Setting default properties. PreCondition: NumOfPorts is filled and all pointers allocated*/ | ||
124 | eError = OMXBase_SetDefaultProperties(hComponent); | ||
125 | OMX_CHECK(eError == OMX_ErrorNone, OMX_ErrorUnsupportedSetting); | ||
126 | |||
127 | /* Override the function pointers of pHandle "OMX_COMPONENTTYPE" | ||
128 | * which Base cannot handle and needs to be taken care by the Dervied comp*/ | ||
129 | pHandle->GetParameter = OMXH264VE_GetParameter; | ||
130 | pHandle->SetParameter = OMXH264VE_SetParameter; | ||
131 | pHandle->SetConfig = OMXH264VE_SetConfig; | ||
132 | pHandle->GetConfig = OMXH264VE_GetConfig; | ||
133 | pHandle->ComponentDeInit = OMXH264VE_ComponentDeinit; | ||
134 | pHandle->GetExtensionIndex = OMXH264VE_GetExtensionIndex; | ||
135 | pHandle->ComponentTunnelRequest = OMXH264VE_ComponentTunnelRequest; | ||
136 | |||
137 | eError= OMXH264VE_InitialzeComponentPrivateParams(pHandle); | ||
138 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
139 | |||
140 | /* Open the Engine*/ | ||
141 | pH264VEComp->pCEhandle = Engine_open(OMX_ENGINE_NAME, NULL, &pH264VEComp->tCEerror); | ||
142 | if( pH264VEComp->pCEhandle == NULL ) { | ||
143 | OSAL_ErrorTrace("Engine creation: Could not open engine \n"); | ||
144 | eError = OMX_ErrorInsufficientResources; | ||
145 | goto EXIT; | ||
146 | } | ||
147 | |||
148 | pH264VEComp->bInputMetaDataBufferMode = OMX_FALSE; | ||
149 | pH264VEComp->mAllocDev = NULL; | ||
150 | pH264VEComp->hCC = NULL; | ||
151 | |||
152 | EXIT: | ||
153 | if( eError != OMX_ErrorNone ) { | ||
154 | OSAL_ErrorTrace(" H264VE Comp Initialization Failed...! "); | ||
155 | if( pHandle ) { | ||
156 | pHandle->ComponentDeInit(hComponent); | ||
157 | } | ||
158 | } | ||
159 | |||
160 | return (eError); | ||
161 | } | ||
162 | |||
163 | |||
164 | static OMX_ERRORTYPE OMXH264VE_GetParameter(OMX_HANDLETYPE hComponent, | ||
165 | OMX_INDEXTYPE nParamIndex, | ||
166 | OMX_PTR pParamStruct) | ||
167 | { | ||
168 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
169 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
170 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
171 | OMX_VIDEO_PARAM_PORTFORMATTYPE *pVideoPortParams = NULL; | ||
172 | OMX_VIDEO_PARAM_AVCTYPE *LAVCParams=NULL; | ||
173 | OMX_VIDEO_PARAM_VBSMCTYPE *LVBSMC = NULL; | ||
174 | OMX_STATETYPE nLCurState; | ||
175 | OMX_BOOL bAllocateLocalAVC=OMX_FALSE; | ||
176 | // OMX_U32 nPortIndex; | ||
177 | OMX_U32 *pConsumerUsage; | ||
178 | OMX_PARAM_PORTDEFINITIONTYPE *pInputPortDef=NULL; | ||
179 | struct DescribeColorFormatParams *Colorparams; | ||
180 | |||
181 | /* Check all the input parametrs */ | ||
182 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
183 | OMX_CHECK(pParamStruct != NULL, OMX_ErrorBadParameter); | ||
184 | |||
185 | /*initialize the component handle and component pvt handle*/ | ||
186 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
187 | pH264VEComp = (OMXH264VidEncComp *)pHandle->pComponentPrivate; | ||
188 | |||
189 | /* Allocate memory for LAVCParams */ | ||
190 | LAVCParams = (OMX_VIDEO_PARAM_AVCTYPE *)OSAL_Malloc(sizeof(OMX_VIDEO_PARAM_AVCTYPE)); | ||
191 | OMX_CHECK(LAVCParams != NULL, OMX_ErrorInsufficientResources); | ||
192 | bAllocateLocalAVC=OMX_TRUE; | ||
193 | |||
194 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
195 | nLCurState=pH264VEComp->sBase.tCurState; | ||
196 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
197 | /* GetParameter can't be invoked incase the comp is in Invalid State */ | ||
198 | OMX_CHECK(nLCurState != OMX_StateInvalid, OMX_ErrorIncorrectStateOperation); | ||
199 | |||
200 | switch( (int) nParamIndex ) { | ||
201 | /* case OMX_IndexParamVideoInit: required for Standard Video Encoder as per Spec & is defined at BASE */ | ||
202 | /* case OMX_IndexParamPortDefinition: required for Standard Video Encoder as per Spec & is defined at BASE */ | ||
203 | /* required for Standard Video Encoder as per Spec .. | ||
204 | client uses this to query the format supported by the port */ | ||
205 | case OMX_IndexParamVideoPortFormat : | ||
206 | /* Check for the correct nSize & nVersion information */ | ||
207 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_PORTFORMATTYPE, eError); | ||
208 | pVideoPortParams = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)pParamStruct; | ||
209 | /* Retrieving the Input Port params */ | ||
210 | if( pVideoPortParams->nPortIndex == pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nPortIndex ) { | ||
211 | /*Get the compression format*/ | ||
212 | pVideoPortParams->eCompressionFormat = OMX_VIDEO_CodingUnused; | ||
213 | |||
214 | /*Get the Frame rate : from the codec Dynamic Params...Q16 format*/ | ||
215 | pVideoPortParams->xFramerate = (pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetFrameRate / 1000) << 16; | ||
216 | |||
217 | /*Get the supported (only 420SP is supported) color formats : from the Codec creation time Params*/ | ||
218 | switch( pVideoPortParams->nIndex ) { | ||
219 | case 0 : | ||
220 | GET_OMX_COLORFORMAT(pH264VEComp, eError); | ||
221 | pVideoPortParams->eColorFormat = pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.eColorFormat; | ||
222 | break; | ||
223 | case 1 : | ||
224 | pVideoPortParams->eColorFormat = OMX_COLOR_FormatAndroidOpaque; | ||
225 | break; | ||
226 | case 2: | ||
227 | pVideoPortParams->eColorFormat = OMX_COLOR_FormatYUV420Flexible; | ||
228 | break; | ||
229 | default : | ||
230 | eError = OMX_ErrorNoMore; | ||
231 | break; | ||
232 | } | ||
233 | } | ||
234 | /* Retrieving the Output Port params */ | ||
235 | else if( pVideoPortParams->nPortIndex == pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.nPortIndex ) { | ||
236 | |||
237 | /*Get the Color Format*/ | ||
238 | pVideoPortParams->eColorFormat = OMX_COLOR_FormatUnused; | ||
239 | |||
240 | /*Get the Frame Rate */ | ||
241 | pVideoPortParams->xFramerate = 0; | ||
242 | |||
243 | /*Get the Supported CompressionFormats: only AVC is supported*/ | ||
244 | switch( pVideoPortParams->nIndex ) { | ||
245 | case 0 : | ||
246 | pVideoPortParams->eCompressionFormat = OMX_VIDEO_CodingAVC; | ||
247 | break; | ||
248 | default : | ||
249 | eError=OMX_ErrorNoMore; | ||
250 | break; | ||
251 | } | ||
252 | } else { | ||
253 | eError = OMX_ErrorBadPortIndex; | ||
254 | } | ||
255 | break; | ||
256 | |||
257 | /* required for Standard Video Encoder as per Spec & | ||
258 | Client uses this to retrieve the Info related to the AVC rate control type*/ | ||
259 | case OMX_IndexParamVideoBitrate : | ||
260 | /* Check for the correct nSize & nVersion information */ | ||
261 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_BITRATETYPE, eError); | ||
262 | if(((OMX_VIDEO_PARAM_BITRATETYPE *)pParamStruct)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
263 | /*Get the Rate Control Algorithm: from the Codec Creation Time Params*/ | ||
264 | GET_OMX_RC_ALG(pH264VEComp, pParamStruct, eError); | ||
265 | |||
266 | /*Get the Target Bit Rate: from the Codec Dynamic Params*/ | ||
267 | ((OMX_VIDEO_PARAM_BITRATETYPE *)pParamStruct)->nTargetBitrate= | ||
268 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetBitRate; | ||
269 | |||
270 | } else { | ||
271 | eError = OMX_ErrorBadPortIndex; | ||
272 | } | ||
273 | break; | ||
274 | |||
275 | /* required for Standard Video Encoder as per Spec & | ||
276 | Client uses this to retrieve the Info related to the AVC structure type*/ | ||
277 | case OMX_IndexParamVideoAvc : | ||
278 | /* Check for the correct nSize & nVersion information */ | ||
279 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_AVCTYPE, eError); | ||
280 | if(((OMX_VIDEO_PARAM_AVCTYPE *)pParamStruct)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
281 | GET_OMX_AVC_PARAMS(pH264VEComp, pParamStruct); | ||
282 | /*Get the Profile value from the Codec Creation Params*/ | ||
283 | GET_OMX_AVC_PROFILE(pH264VEComp, pParamStruct, eError); | ||
284 | |||
285 | /*Get the level from the Codec Creation Params*/ | ||
286 | GET_OMX_AVC_LEVEL(pH264VEComp, pParamStruct, eError); | ||
287 | |||
288 | /*get the LoopFilter mode form the Codec Creation Time Params*/ | ||
289 | GET_OMX_AVC_LFMODE(pH264VEComp, pParamStruct, eError); | ||
290 | } else { | ||
291 | eError = OMX_ErrorBadPortIndex; | ||
292 | } | ||
293 | break; | ||
294 | |||
295 | /* Client uses this to retrieve the Info related to the Motion vector type*/ | ||
296 | case OMX_IndexParamVideoMotionVector : | ||
297 | /* Check for the correct nSize & nVersion information */ | ||
298 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_MOTIONVECTORTYPE, eError); | ||
299 | if(((OMX_VIDEO_PARAM_MOTIONVECTORTYPE *)pParamStruct)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
300 | /*Get the MV Accuracy from Codec Dynamic Params*/ | ||
301 | ((OMX_VIDEO_PARAM_MOTIONVECTORTYPE *)pParamStruct)->eAccuracy = | ||
302 | (OMX_VIDEO_MOTIONVECTORTYPE)pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.mvAccuracy; | ||
303 | ((OMX_VIDEO_PARAM_MOTIONVECTORTYPE *)pParamStruct)->bUnrestrictedMVs = OMX_TRUE; /*by Default Codec Supports*/ | ||
304 | /*Number of MVs depend on the min Block size selected*/ | ||
305 | ((OMX_VIDEO_PARAM_MOTIONVECTORTYPE *)pParamStruct)->bFourMV = | ||
306 | (pH264VEComp->pVidEncStaticParams->interCodingParams.minBlockSizeP == IH264_BLOCKSIZE_8x8 ? OMX_TRUE : OMX_FALSE); | ||
307 | /*Get the Search Range from the search Range for P Frame*/ | ||
308 | ((OMX_VIDEO_PARAM_MOTIONVECTORTYPE *)pParamStruct)->sXSearchRange = | ||
309 | pH264VEComp->pVidEncStaticParams->interCodingParams.searchRangeHorP; | ||
310 | |||
311 | ((OMX_VIDEO_PARAM_MOTIONVECTORTYPE *)pParamStruct)->sYSearchRange = | ||
312 | pH264VEComp->pVidEncStaticParams->interCodingParams.searchRangeVerP; | ||
313 | } else { | ||
314 | eError = OMX_ErrorBadPortIndex; | ||
315 | } | ||
316 | break; | ||
317 | |||
318 | /* Client uses this to configure Info related to the quantization parameter type*/ | ||
319 | case OMX_IndexParamVideoQuantization : | ||
320 | /* Check for the correct nSize & nVersion information */ | ||
321 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_QUANTIZATIONTYPE, eError); | ||
322 | if(((OMX_VIDEO_PARAM_QUANTIZATIONTYPE *)pParamStruct)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
323 | ((OMX_VIDEO_PARAM_QUANTIZATIONTYPE *)pParamStruct)->nQpI = pH264VEComp->pVidEncStaticParams->rateControlParams.qpI; | ||
324 | ((OMX_VIDEO_PARAM_QUANTIZATIONTYPE *)pParamStruct)->nQpP = pH264VEComp->pVidEncStaticParams->rateControlParams.qpP; | ||
325 | ((OMX_VIDEO_PARAM_QUANTIZATIONTYPE *)pParamStruct)->nQpB = (pH264VEComp->pVidEncStaticParams->rateControlParams.qpP) | ||
326 | + (pH264VEComp->pVidEncStaticParams->rateControlParams.qpOffsetB); | ||
327 | } else { | ||
328 | eError = OMX_ErrorBadPortIndex; | ||
329 | } | ||
330 | break; | ||
331 | |||
332 | case OMX_IndexParamVideoSliceFMO : | ||
333 | /* Check for the correct nSize & nVersion information */ | ||
334 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_AVCSLICEFMO, eError); | ||
335 | if(((OMX_VIDEO_PARAM_AVCSLICEFMO *)pParamStruct)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
336 | ((OMX_VIDEO_PARAM_AVCSLICEFMO *)pParamStruct)->nNumSliceGroups = | ||
337 | pH264VEComp->pVidEncStaticParams->fmoCodingParams.numSliceGroups; | ||
338 | |||
339 | /*get the fmo slice grp type form the Codec Creation Time Params*/ | ||
340 | GET_OMX_FMO_SLIGRPMAPTYPE(pH264VEComp, pParamStruct, eError); | ||
341 | |||
342 | /*get the slice mode from the Codec Creation Time Params*/ | ||
343 | GET_OMX_FMO_SLICEMODE(pH264VEComp, pParamStruct, eError); | ||
344 | |||
345 | } else { | ||
346 | eError = OMX_ErrorBadPortIndex; | ||
347 | } | ||
348 | break; | ||
349 | |||
350 | case OMX_IndexParamVideoIntraRefresh : | ||
351 | /* Check for the correct nSize & nVersion information */ | ||
352 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_INTRAREFRESHTYPE, eError); | ||
353 | if(((OMX_VIDEO_PARAM_INTRAREFRESHTYPE *)pParamStruct)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
354 | GET_OMX_INTRAREFRESHMODE(pH264VEComp, pParamStruct, eError); | ||
355 | } else { | ||
356 | eError = OMX_ErrorBadPortIndex; | ||
357 | } | ||
358 | break; | ||
359 | |||
360 | /* required for Standard Video Encoder as per Spec*/ | ||
361 | case OMX_IndexParamVideoProfileLevelCurrent : | ||
362 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_PROFILELEVELTYPE, eError); | ||
363 | if(((OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pParamStruct)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
364 | /*Get the Codec Profile */ | ||
365 | GET_OMX_AVC_PROFILE(pH264VEComp, LAVCParams, eError); | ||
366 | ((OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pParamStruct)->eProfile = LAVCParams->eProfile; | ||
367 | |||
368 | /*Get the Codec level */ | ||
369 | GET_OMX_AVC_LEVEL(pH264VEComp, LAVCParams, eError); | ||
370 | |||
371 | ((OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pParamStruct)->eLevel = LAVCParams->eLevel; | ||
372 | } else { | ||
373 | eError = OMX_ErrorBadPortIndex; | ||
374 | } | ||
375 | break; | ||
376 | |||
377 | /* required for Standard Video Encoder as per Spec*/ | ||
378 | case OMX_IndexParamVideoProfileLevelQuerySupported : | ||
379 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_PROFILELEVELTYPE, eError); | ||
380 | if(((OMX_VIDEO_PARAM_AVCTYPE *)pParamStruct)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
381 | switch(((OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pParamStruct)->nProfileIndex ) { | ||
382 | case 0 : | ||
383 | ((OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pParamStruct)->eProfile = OMX_VIDEO_AVCProfileBaseline; | ||
384 | ((OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pParamStruct)->eLevel = OMX_VIDEO_AVCLevel51; | ||
385 | break; | ||
386 | case 1 : | ||
387 | ((OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pParamStruct)->eProfile=OMX_VIDEO_AVCProfileMain; | ||
388 | ((OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pParamStruct)->eLevel=OMX_VIDEO_AVCLevel51; | ||
389 | break; | ||
390 | case 2 : | ||
391 | ((OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pParamStruct)->eProfile=OMX_VIDEO_AVCProfileHigh; | ||
392 | ((OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pParamStruct)->eLevel=OMX_VIDEO_AVCLevel51; | ||
393 | break; | ||
394 | default : | ||
395 | eError =OMX_ErrorNoMore; | ||
396 | } | ||
397 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
398 | } else { | ||
399 | eError = OMX_ErrorBadPortIndex; | ||
400 | } | ||
401 | break; | ||
402 | |||
403 | case OMX_IndexParamVideoVBSMC : | ||
404 | /* SetParameter can be invoked only when the comp is in loaded or on disabled port */ | ||
405 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
406 | nLCurState=pH264VEComp->sBase.tCurState; | ||
407 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
408 | OMX_CHECK((nLCurState == OMX_StateLoaded), OMX_ErrorIncorrectStateOperation); | ||
409 | /* Check for the correct nSize & nVersion information */ | ||
410 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_VBSMCTYPE, eError); | ||
411 | if(((OMX_VIDEO_PARAM_VBSMCTYPE *)pParamStruct)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
412 | LVBSMC = ((OMX_VIDEO_PARAM_VBSMCTYPE *)pParamStruct); | ||
413 | if( pH264VEComp->pVidEncStaticParams->interCodingParams.minBlockSizeP == IH264_BLOCKSIZE_8x8 ) { | ||
414 | /*4MV case*/ | ||
415 | LVBSMC->b16x16=OMX_TRUE; | ||
416 | LVBSMC->b16x8=OMX_TRUE; | ||
417 | LVBSMC->b8x16=OMX_TRUE; | ||
418 | LVBSMC->b8x8=OMX_TRUE; | ||
419 | LVBSMC->b8x4=OMX_FALSE; | ||
420 | LVBSMC->b4x8=OMX_FALSE; | ||
421 | LVBSMC->b4x4=OMX_FALSE; | ||
422 | } else if( pH264VEComp->pVidEncStaticParams->interCodingParams.minBlockSizeP == IH264_BLOCKSIZE_16x16 ) { | ||
423 | /*1 MV case*/ | ||
424 | /*set the same value for both P & B frames prediction*/ | ||
425 | LVBSMC->b16x16=OMX_TRUE; | ||
426 | LVBSMC->b16x8=OMX_FALSE; | ||
427 | LVBSMC->b8x16=OMX_FALSE; | ||
428 | LVBSMC->b8x8=OMX_FALSE; | ||
429 | LVBSMC->b8x4=OMX_FALSE; | ||
430 | LVBSMC->b4x8=OMX_FALSE; | ||
431 | LVBSMC->b4x4=OMX_FALSE; | ||
432 | } else { | ||
433 | eError = OMX_ErrorNoMore; | ||
434 | } | ||
435 | } else { | ||
436 | eError = OMX_ErrorBadPortIndex; | ||
437 | } | ||
438 | break; | ||
439 | |||
440 | case OMX_IndexParamConsumerUsageBits: | ||
441 | //parameter is uint32 | ||
442 | pConsumerUsage = (OMX_U32*)(pParamStruct); | ||
443 | *pConsumerUsage = 0x00; | ||
444 | eError = OMX_ErrorNone; | ||
445 | break; | ||
446 | |||
447 | case (OMX_INDEXTYPE) OMX_TI_IndexDescribeColorFormat: | ||
448 | Colorparams = (struct DescribeColorFormatParams*)(pParamStruct); | ||
449 | |||
450 | pInputPortDef = &(pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef); | ||
451 | struct MediaImage *image = &(Colorparams->sMediaImage); | ||
452 | memset(image, 0, sizeof(MediaImage)); | ||
453 | |||
454 | image->mWidth = pInputPortDef->format.video.nFrameWidth; | ||
455 | image->mHeight = pInputPortDef->format.video.nFrameHeight; | ||
456 | |||
457 | image->mType = MEDIA_IMAGE_TYPE_YUV; | ||
458 | image->mNumPlanes = 3; | ||
459 | image->mBitDepth = 8; | ||
460 | |||
461 | image->mPlane[Y].mOffset = 0; | ||
462 | image->mPlane[Y].mColInc = 1; | ||
463 | image->mPlane[Y].mRowInc = pInputPortDef->format.video.nStride; | ||
464 | image->mPlane[Y].mHorizSubsampling = 1; | ||
465 | image->mPlane[Y].mVertSubsampling = 1; | ||
466 | |||
467 | image->mPlane[U].mOffset = pInputPortDef->format.video.nStride * pInputPortDef->format.video.nFrameHeight; | ||
468 | image->mPlane[U].mColInc = 2; | ||
469 | image->mPlane[U].mRowInc = pInputPortDef->format.video.nStride; | ||
470 | image->mPlane[U].mHorizSubsampling = 2; | ||
471 | image->mPlane[U].mVertSubsampling = 2; | ||
472 | |||
473 | image->mPlane[V].mOffset = image->mPlane[U].mOffset + 1; | ||
474 | image->mPlane[V].mColInc = 2; | ||
475 | image->mPlane[V].mRowInc = pInputPortDef->format.video.nStride; | ||
476 | image->mPlane[V].mHorizSubsampling = 2; | ||
477 | image->mPlane[V].mVertSubsampling = 2; | ||
478 | |||
479 | break; | ||
480 | |||
481 | /* redirects the call to "OMXBase_GetParameter" which supports standard comp indexes */ | ||
482 | default : | ||
483 | eError = OMXBase_GetParameter(hComponent, nParamIndex, pParamStruct); | ||
484 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
485 | break; | ||
486 | |||
487 | } | ||
488 | |||
489 | EXIT: | ||
490 | if( bAllocateLocalAVC ) { | ||
491 | OSAL_Free(LAVCParams); | ||
492 | } | ||
493 | |||
494 | return (eError); | ||
495 | } | ||
496 | |||
497 | static OMX_ERRORTYPE OMXH264VE_SetParameter(OMX_HANDLETYPE hComponent, | ||
498 | OMX_INDEXTYPE nParamIndex, | ||
499 | OMX_PTR pParamStruct) | ||
500 | { | ||
501 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
502 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
503 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
504 | OMX_VIDEO_PARAM_PORTFORMATTYPE *pVideoPortParams = NULL; | ||
505 | OMX_PARAM_PORTDEFINITIONTYPE *pPortDef=NULL; | ||
506 | OMX_PARAM_PORTDEFINITIONTYPE *pLocalPortDef=NULL; | ||
507 | OMX_VIDEO_PARAM_AVCTYPE *LAVCParams=NULL; | ||
508 | OMX_VIDEO_PARAM_VBSMCTYPE *LVBSMC = NULL; | ||
509 | OMX_U32 nPortIndex; | ||
510 | OMX_STATETYPE nLCurState; | ||
511 | OMX_BOOL bLCodecCreateFlag=OMX_FALSE; | ||
512 | PARAMS_UPDATE_STATUS bLCallxDMSetParams=NO_PARAM_CHANGE; | ||
513 | OMX_BOOL bAllocateLocalAVC=OMX_FALSE; | ||
514 | |||
515 | /* Check for the input parameters */ | ||
516 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
517 | OMX_CHECK(pParamStruct != NULL, OMX_ErrorBadParameter); | ||
518 | |||
519 | /*initialize the component handle and component pvt handle*/ | ||
520 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
521 | pH264VEComp = (OMXH264VidEncComp *)pHandle->pComponentPrivate; | ||
522 | |||
523 | /* Allocate memory for LAVCParams */ | ||
524 | LAVCParams = (OMX_VIDEO_PARAM_AVCTYPE *)OSAL_Malloc(sizeof(OMX_VIDEO_PARAM_AVCTYPE)); | ||
525 | OMX_CHECK(LAVCParams != NULL, OMX_ErrorInsufficientResources); | ||
526 | bAllocateLocalAVC = OMX_TRUE; | ||
527 | |||
528 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
529 | nLCurState = pH264VEComp->sBase.tCurState; | ||
530 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
531 | |||
532 | /* SetParameter can't be invoked incase the comp is in Invalid State */ | ||
533 | OMX_CHECK(nLCurState != OMX_StateInvalid, OMX_ErrorIncorrectStateOperation); | ||
534 | |||
535 | switch( (int) nParamIndex ) { | ||
536 | case OMX_IndexParamVideoInit : | ||
537 | OSAL_Info("In OMX_IndexParamVideoInit"); | ||
538 | /* SetParameter can be invoked only when the comp is in loaded or on a disabled port */ | ||
539 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
540 | nLCurState = pH264VEComp->sBase.tCurState; | ||
541 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
542 | OMX_CHECK((nLCurState == OMX_StateLoaded), OMX_ErrorIncorrectStateOperation); | ||
543 | OMX_CHECK((((OMX_PORT_PARAM_TYPE *)pParamStruct)->nStartPortNumber == 0), OMX_ErrorUnsupportedSetting); | ||
544 | OMX_CHECK((((OMX_PORT_PARAM_TYPE *)pParamStruct)->nPorts == 2), OMX_ErrorUnsupportedSetting); | ||
545 | OSAL_Memcpy(pH264VEComp->sBase.pVideoPortParams, pParamStruct, sizeof(OMX_PORT_PARAM_TYPE)); | ||
546 | break; | ||
547 | |||
548 | case OMX_IndexParamPortDefinition : | ||
549 | OSAL_Info("In OMX_IndexParamPortDefinition"); | ||
550 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_PARAM_PORTDEFINITIONTYPE, eError); | ||
551 | pPortDef = (OMX_PARAM_PORTDEFINITIONTYPE *)pParamStruct; | ||
552 | nPortIndex = pPortDef->nPortIndex; | ||
553 | |||
554 | /*check for valid port index */ | ||
555 | OMX_CHECK(nPortIndex < ((pH264VEComp->sBase.pVideoPortParams->nStartPortNumber) + | ||
556 | (pH264VEComp->sBase.pVideoPortParams->nPorts)), OMX_ErrorBadPortIndex); | ||
557 | |||
558 | /*successful only when the comp is in loaded or on a disabled port*/ | ||
559 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
560 | nLCurState = pH264VEComp->sBase.tCurState; | ||
561 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
562 | OMX_CHECK((nLCurState == OMX_StateLoaded) || | ||
563 | (pH264VEComp->sBase.pPorts[nPortIndex]->sPortDef.bEnabled == OMX_FALSE), | ||
564 | OMX_ErrorIncorrectStateOperation); | ||
565 | pLocalPortDef = &(pH264VEComp->sBase.pPorts[nPortIndex]->sPortDef); | ||
566 | |||
567 | OMX_CHECK((pPortDef->nBufferCountActual >= | ||
568 | pH264VEComp->sBase.pPorts[nPortIndex]->sPortDef.nBufferCountMin), OMX_ErrorUnsupportedSetting); | ||
569 | |||
570 | pH264VEComp->sBase.pPorts[nPortIndex]->sPortDef.nBufferCountActual = pPortDef->nBufferCountActual; | ||
571 | /*if frame height/widht changes then change the buffer requirements accordingly*/ | ||
572 | if( nPortIndex == OMX_H264VE_INPUT_PORT ) { | ||
573 | if (pH264VEComp->bInputMetaDataBufferMode) { | ||
574 | pPortDef->format.video.nStride = ALIGN(pPortDef->format.video.nStride, HW_ALIGN); | ||
575 | } | ||
576 | |||
577 | OMX_CHECK(((pPortDef->format.video.nFrameWidth & 0x0F) == 0), OMX_ErrorUnsupportedSetting); /*Width should be multiple of 16*/ | ||
578 | if( pH264VEComp->pVidEncStaticParams->videnc2Params.inputContentType == IVIDEO_PROGRESSIVE ) { | ||
579 | OMX_CHECK(((pPortDef->format.video.nFrameHeight & 0x01) == 0), OMX_ErrorUnsupportedSetting); /* Width should be multiple of 16 */ | ||
580 | } else { | ||
581 | OMX_CHECK(((pPortDef->format.video.nFrameHeight & 0x03) == 0), OMX_ErrorUnsupportedSetting); /* Width should be multiple of 16 */ | ||
582 | } | ||
583 | if (pPortDef->format.video.nStride % 16 != 0) { | ||
584 | eError = OMX_ErrorUnsupportedSetting; | ||
585 | break; | ||
586 | } | ||
587 | OMX_CHECK(((OMX_U32)pPortDef->format.video.nStride >= pPortDef->format.video.nFrameWidth), OMX_ErrorUnsupportedSetting); | ||
588 | |||
589 | OMX_CHECK((pPortDef->format.video.eColorFormat == OMX_TI_COLOR_FormatYUV420PackedSemiPlanar) || | ||
590 | (pPortDef->format.video.eColorFormat == OMX_COLOR_FormatAndroidOpaque) || | ||
591 | (pPortDef->format.video.eColorFormat == OMX_COLOR_FormatYUV420Flexible), | ||
592 | OMX_ErrorUnsupportedSetting); | ||
593 | if((pPortDef->format.video.nFrameWidth < 96) || (pPortDef->format.video.nFrameHeight < 80)) { | ||
594 | eError=OMX_ErrorUnsupportedSetting; | ||
595 | break; | ||
596 | } | ||
597 | SET_H264CODEC_CHROMAFORMAT(pPortDef, pH264VEComp, eError); | ||
598 | |||
599 | OMX_CHECK((eError == OMX_ErrorNone), OMX_ErrorUnsupportedSetting); | ||
600 | // Storing the CLient provided frame rate in internal port def structure for i/p port | ||
601 | if( pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.xFramerate != pPortDef->format.video.xFramerate) { | ||
602 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.xFramerate = | ||
603 | pPortDef->format.video.xFramerate; | ||
604 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetFrameRate = | ||
605 | (pPortDef->format.video.xFramerate >> 16) * 1000; | ||
606 | } | ||
607 | |||
608 | if((pLocalPortDef->format.video.nFrameHeight != pPortDef->format.video.nFrameHeight) || | ||
609 | (pLocalPortDef->format.video.nFrameWidth != pPortDef->format.video.nFrameWidth) || | ||
610 | (pLocalPortDef->format.video.nStride != pPortDef->format.video.nStride)) { | ||
611 | pLocalPortDef->format.video.nStride =pPortDef->format.video.nStride; | ||
612 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.format.video.nFrameWidth = | ||
613 | pPortDef->format.video.nFrameWidth; | ||
614 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.format.video.nFrameHeight = | ||
615 | pPortDef->format.video.nFrameHeight; | ||
616 | |||
617 | /*Update the Sliceheight as well*/ | ||
618 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.format.video.nSliceHeight = | ||
619 | pPortDef->format.video.nFrameHeight; | ||
620 | |||
621 | pH264VEComp->pVidEncStaticParams->videnc2Params.maxHeight = pPortDef->format.video.nFrameHeight; | ||
622 | pH264VEComp->pVidEncStaticParams->videnc2Params.maxWidth = pPortDef->format.video.nFrameWidth; | ||
623 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.inputWidth = pPortDef->format.video.nFrameWidth; | ||
624 | |||
625 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.captureWidth = pPortDef->format.video.nStride; | ||
626 | |||
627 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.inputHeight = pPortDef->format.video.nFrameHeight; | ||
628 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.nBufferSize = | ||
629 | (pPortDef->format.video.nFrameHeight * pPortDef->format.video.nFrameWidth * 3 )/2; | ||
630 | |||
631 | bLCallxDMSetParams = PARAMS_UPDATED_AT_OMX; | ||
632 | OSAL_Memcpy(&(pH264VEComp->sBase.pPorts[nPortIndex]->sPortDef.format), &(pPortDef->format), | ||
633 | sizeof(OMX_VIDEO_PORTDEFINITIONTYPE)); | ||
634 | |||
635 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nBufferSize = | ||
636 | (pPortDef->format.video.nFrameHeight * pPortDef->format.video.nStride * 3) / 2; | ||
637 | |||
638 | if (pH264VEComp->bInputMetaDataBufferMode) { | ||
639 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nBufferSize = sizeof(OMX_MetaDataBuffer); | ||
640 | } | ||
641 | |||
642 | /* read only field value. update with the frame height.for now codec does not supports the sub frame processing*/ | ||
643 | pLocalPortDef->format.video.nSliceHeight=pPortDef->format.video.nFrameHeight; | ||
644 | |||
645 | bLCodecCreateFlag = OMX_TRUE; | ||
646 | pH264VEComp->bSetParamInputIsDone = OMX_TRUE; | ||
647 | } | ||
648 | } else { | ||
649 | /*OUTPUT Port*/ | ||
650 | OMX_CHECK((pPortDef->format.video.nFrameWidth == | ||
651 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nFrameWidth), | ||
652 | OMX_ErrorUnsupportedSetting); | ||
653 | OMX_CHECK((pPortDef->format.video.nFrameHeight == | ||
654 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nFrameHeight), | ||
655 | OMX_ErrorUnsupportedSetting); | ||
656 | |||
657 | if( pPortDef->format.video.xFramerate != 0 ) { | ||
658 | OSAL_WarningTrace("Non-zero framerate rate set on o/p port. Setting frame rate is supported only on i/p port"); | ||
659 | pPortDef->format.video.xFramerate = 0; | ||
660 | } | ||
661 | eError = OMXH264VE_CheckBitRateCap(pPortDef->format.video.nBitrate, hComponent); | ||
662 | OMX_CHECK((eError == OMX_ErrorNone), OMX_ErrorUnsupportedSetting); | ||
663 | OSAL_Memcpy(&(pH264VEComp->sBase.pPorts[nPortIndex]->sPortDef.format), &(pPortDef->format), | ||
664 | sizeof(OMX_VIDEO_PORTDEFINITIONTYPE)); | ||
665 | |||
666 | /*Not to modify the read only field value*/ | ||
667 | pLocalPortDef->format.video.nSliceHeight = | ||
668 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nFrameHeight; | ||
669 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetBitRate = | ||
670 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.format.video.nBitrate; | ||
671 | |||
672 | if (pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetBitRate < OMX_H264VE_MIN_BITRATE) { | ||
673 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetBitRate = OMX_H264VE_MIN_BITRATE; | ||
674 | } | ||
675 | |||
676 | OMX_CHECK(pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.format.video.eCompressionFormat == | ||
677 | OMX_VIDEO_CodingAVC, OMX_ErrorUnsupportedSetting); | ||
678 | bLCallxDMSetParams=PARAMS_UPDATED_AT_OMX; | ||
679 | } | ||
680 | break; | ||
681 | |||
682 | /* client uses this to modify the format type of an port */ | ||
683 | case OMX_IndexParamVideoPortFormat : | ||
684 | OSAL_Info("In OMX_IndexParamVideoPortFormat"); | ||
685 | /* SetParameter can be invoked only when the comp is in loaded or on a disabled port */ | ||
686 | /* Check for the correct nSize & nVersion information */ | ||
687 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_PORTFORMATTYPE, eError); | ||
688 | pVideoPortParams = (OMX_VIDEO_PARAM_PORTFORMATTYPE *)pParamStruct; | ||
689 | nPortIndex = pVideoPortParams->nPortIndex; | ||
690 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
691 | nLCurState = pH264VEComp->sBase.tCurState; | ||
692 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
693 | OMX_CHECK((nLCurState == OMX_StateLoaded) || | ||
694 | (pH264VEComp->sBase.pPorts[nPortIndex]->sPortDef.bEnabled == OMX_FALSE), | ||
695 | OMX_ErrorIncorrectStateOperation); | ||
696 | /* Specifying the Video port format type params */ | ||
697 | if( nPortIndex == pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nPortIndex ) { | ||
698 | pLocalPortDef = &(pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef); | ||
699 | if((pLocalPortDef->format.video.xFramerate != pVideoPortParams->xFramerate) || | ||
700 | (pLocalPortDef->format.video.eColorFormat != pVideoPortParams->eColorFormat)) { | ||
701 | SET_H264CODEC_CHROMAFORMAT(pLocalPortDef, pH264VEComp, eError); | ||
702 | |||
703 | OMX_CHECK((eError == OMX_ErrorNone), OMX_ErrorUnsupportedSetting); | ||
704 | /*Set the Codec Params accordingly*/ | ||
705 | pLocalPortDef->format.video.eCompressionFormat = OMX_VIDEO_CodingUnused; | ||
706 | pLocalPortDef->format.video.xFramerate = pVideoPortParams->xFramerate; | ||
707 | pLocalPortDef->format.video.eColorFormat = pVideoPortParams->eColorFormat; | ||
708 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetFrameRate = | ||
709 | (pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.xFramerate >> 16) * 1000; | ||
710 | bLCodecCreateFlag = OMX_TRUE; | ||
711 | } | ||
712 | } else if( nPortIndex == pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.nPortIndex ) { | ||
713 | pLocalPortDef = &(pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef); | ||
714 | /*set the corresponding Portdef fields*/ | ||
715 | if((pLocalPortDef->format.video.xFramerate != pVideoPortParams->xFramerate) || | ||
716 | (pLocalPortDef->format.video.eCompressionFormat != pVideoPortParams->eCompressionFormat)) { | ||
717 | if( pVideoPortParams->xFramerate != 0 ) { | ||
718 | OSAL_ErrorTrace("Non-zero framerate rate set on o/p port. Setting frame rate is supported only on i/p port"); | ||
719 | eError = OMX_ErrorUnsupportedSetting; | ||
720 | goto EXIT; | ||
721 | } | ||
722 | pLocalPortDef->format.video.eCompressionFormat = pVideoPortParams->eCompressionFormat; | ||
723 | pLocalPortDef->format.video.xFramerate = pVideoPortParams->xFramerate; | ||
724 | pLocalPortDef->format.video.eColorFormat = OMX_COLOR_FormatUnused; | ||
725 | OMX_CHECK(pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.format.video.eCompressionFormat == | ||
726 | OMX_VIDEO_CodingAVC, OMX_ErrorUnsupportedSetting); | ||
727 | bLCallxDMSetParams = PARAMS_UPDATED_AT_OMX; | ||
728 | } | ||
729 | } else { | ||
730 | eError = OMX_ErrorBadPortIndex; | ||
731 | break; | ||
732 | } | ||
733 | break; | ||
734 | |||
735 | /* Client uses this to configure Video Bit rate type and target bit-rate */ | ||
736 | case OMX_IndexParamVideoBitrate : | ||
737 | OSAL_Info("In OMX_IndexParamVideoBitrate"); | ||
738 | /* SetParameter can be invoked only when the comp is in loaded or on disabled port */ | ||
739 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
740 | nLCurState = pH264VEComp->sBase.tCurState; | ||
741 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
742 | OMX_CHECK((nLCurState == OMX_StateLoaded), OMX_ErrorIncorrectStateOperation); | ||
743 | |||
744 | /* Check for the correct nSize & nVersion information */ | ||
745 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_BITRATETYPE, eError); | ||
746 | if(((OMX_VIDEO_PARAM_BITRATETYPE *)pParamStruct)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
747 | /*check for the rateControlPreset can be set only when it is IVIDEO_USER_DEFINED*/ | ||
748 | if( pH264VEComp->pVidEncStaticParams->videnc2Params.rateControlPreset != IVIDEO_USER_DEFINED ) { | ||
749 | OSAL_ErrorTrace("Rate control preset is not set to User defined"); | ||
750 | eError = OMX_ErrorUnsupportedSetting; | ||
751 | goto EXIT; | ||
752 | } | ||
753 | /*Set the Codec Rate Control Algorithm: */ | ||
754 | SET_H264CODEC_RC_ALG(pParamStruct, pH264VEComp, eError); | ||
755 | OMX_CHECK((eError == OMX_ErrorNone), OMX_ErrorUnsupportedSetting); | ||
756 | /*Set the Preset to User Defined*/ | ||
757 | if((((OMX_VIDEO_PARAM_BITRATETYPE *)pParamStruct)->eControlRate) != OMX_Video_ControlRateVariable ) { | ||
758 | pH264VEComp->pVidEncStaticParams->rateControlParams.rateControlParamsPreset = 1; //UserDefined | ||
759 | } | ||
760 | eError = OMXH264VE_CheckBitRateCap(((OMX_VIDEO_PARAM_BITRATETYPE *)pParamStruct)->nTargetBitrate, hComponent); | ||
761 | OMX_CHECK((eError == OMX_ErrorNone), OMX_ErrorUnsupportedSetting); | ||
762 | /*Set the Codec Target Bit Rate: from the Codec Dynamic Params*/ | ||
763 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetBitRate = | ||
764 | ((OMX_VIDEO_PARAM_BITRATETYPE *)pParamStruct)->nTargetBitrate; | ||
765 | |||
766 | if (pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetBitRate < OMX_H264VE_MIN_BITRATE) { | ||
767 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetBitRate = OMX_H264VE_MIN_BITRATE; | ||
768 | } | ||
769 | |||
770 | /*Update the output port bit rate as well...for the get param to reflect the proper values*/ | ||
771 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.format.video.nBitrate = | ||
772 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetBitRate; | ||
773 | } else { | ||
774 | eError = OMX_ErrorBadPortIndex; | ||
775 | } | ||
776 | break; | ||
777 | |||
778 | /* Client uses this to configure AVC structure Parameters*/ | ||
779 | case OMX_IndexParamVideoAvc : | ||
780 | OSAL_Info("In OMX_IndexParamVideoAvc"); | ||
781 | /* SetParameter can be invoked only when the comp is in loaded or on disabled port */ | ||
782 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
783 | nLCurState = pH264VEComp->sBase.tCurState; | ||
784 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
785 | OMX_CHECK((nLCurState == OMX_StateLoaded), OMX_ErrorIncorrectStateOperation); | ||
786 | |||
787 | /* Check for the correct nSize & nVersion information */ | ||
788 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_AVCTYPE, eError); | ||
789 | if(((OMX_VIDEO_PARAM_AVCTYPE *)pParamStruct)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
790 | /*Set the Codec Profile */ | ||
791 | SET_H264CODEC_PROFILE(pParamStruct, pH264VEComp, eError); | ||
792 | OMX_CHECK((eError == OMX_ErrorNone), OMX_ErrorUnsupportedSetting); | ||
793 | |||
794 | /*Set the Codec level */ | ||
795 | SET_H264CODEC_LEVEL(pParamStruct, pH264VEComp, eError); | ||
796 | OMX_CHECK((eError == OMX_ErrorNone), OMX_ErrorUnsupportedSetting); | ||
797 | |||
798 | eError = OMXH264VE_CheckBitRateCap(pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetBitRate, hComponent); | ||
799 | OMX_CHECK((eError == OMX_ErrorNone), OMX_ErrorUnsupportedSetting); | ||
800 | |||
801 | SET_H264CODEC_PARAMS_FROM_AVC(pParamStruct, pH264VEComp); | ||
802 | |||
803 | /*Set the LoopFilter mode */ | ||
804 | SET_H264CODEC_LFMODE(pParamStruct, pH264VEComp, eError); | ||
805 | OMX_CHECK((eError == OMX_ErrorNone), OMX_ErrorUnsupportedSetting); | ||
806 | |||
807 | /*depending on the interframe interval (nBframes supported) update the buffer requirements */ | ||
808 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nBufferCountMin = | ||
809 | pH264VEComp->pVidEncStaticParams->videnc2Params.maxInterFrameInterval; | ||
810 | if( pH264VEComp->bSetParamInputIsDone == OMX_TRUE ) { | ||
811 | if((pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nBufferCountActual) < | ||
812 | (pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nBufferCountMin)) { | ||
813 | eError=OMX_ErrorBadParameter; | ||
814 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nBufferCountActual = | ||
815 | pH264VEComp->pVidEncStaticParams->videnc2Params.maxInterFrameInterval; | ||
816 | OSAL_ErrorTrace("need to set the no of buffers properly (buffactual < min requirement)"); | ||
817 | goto EXIT; | ||
818 | } | ||
819 | } else { | ||
820 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nBufferCountActual = | ||
821 | pH264VEComp->pVidEncStaticParams->videnc2Params.maxInterFrameInterval; | ||
822 | } | ||
823 | OSAL_Info("input port buff actual =%d", pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nBufferCountActual); | ||
824 | } else { | ||
825 | eError = OMX_ErrorBadPortIndex; | ||
826 | } | ||
827 | break; | ||
828 | |||
829 | case OMX_IndexParamVideoMotionVector : | ||
830 | OSAL_Info("In OMX_IndexParamVideoMotionVector"); | ||
831 | /* SetParameter can be invoked only when the comp is in loaded or on disabled port */ | ||
832 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
833 | nLCurState = pH264VEComp->sBase.tCurState; | ||
834 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
835 | OMX_CHECK((nLCurState == OMX_StateLoaded), OMX_ErrorIncorrectStateOperation); | ||
836 | /* Check for the correct nSize & nVersion information */ | ||
837 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_MOTIONVECTORTYPE, eError); | ||
838 | if(((OMX_VIDEO_PARAM_MOTIONVECTORTYPE *)pParamStruct)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
839 | /*Get the MV Accuracy from Codec Dynamic Params*/ | ||
840 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.mvAccuracy = | ||
841 | ((OMX_VIDEO_PARAM_MOTIONVECTORTYPE *)pParamStruct)->eAccuracy; | ||
842 | /*Number of MVs depend on the min Block size selected*/ | ||
843 | if(((OMX_VIDEO_PARAM_MOTIONVECTORTYPE *)pParamStruct)->bFourMV ) { | ||
844 | pH264VEComp->pVidEncStaticParams->interCodingParams.minBlockSizeP = IH264_BLOCKSIZE_8x8; | ||
845 | pH264VEComp->pVidEncStaticParams->interCodingParams.minBlockSizeB = IH264_BLOCKSIZE_8x8; | ||
846 | } else { | ||
847 | pH264VEComp->pVidEncStaticParams->interCodingParams.minBlockSizeP = IH264_BLOCKSIZE_16x16; | ||
848 | pH264VEComp->pVidEncStaticParams->interCodingParams.minBlockSizeB = IH264_BLOCKSIZE_16x16; | ||
849 | } | ||
850 | /*Set the Search Range for P Frame*/ | ||
851 | pH264VEComp->pVidEncStaticParams->interCodingParams.searchRangeHorP = | ||
852 | ((OMX_VIDEO_PARAM_MOTIONVECTORTYPE *)pParamStruct)->sXSearchRange; | ||
853 | pH264VEComp->pVidEncStaticParams->interCodingParams.searchRangeVerP = | ||
854 | ((OMX_VIDEO_PARAM_MOTIONVECTORTYPE *)pParamStruct)->sYSearchRange; | ||
855 | /*Set the Search Range for B Frame*/ | ||
856 | pH264VEComp->pVidEncStaticParams->interCodingParams.searchRangeHorB = | ||
857 | ((OMX_VIDEO_PARAM_MOTIONVECTORTYPE *)pParamStruct)->sXSearchRange; | ||
858 | pH264VEComp->pVidEncStaticParams->interCodingParams.searchRangeVerB = | ||
859 | OMX_H264VE_DEFAULT_VERSEARCH_BFRAME; /*the only supported value by codec*/ | ||
860 | |||
861 | /*Update the corresponding Dynamic params also*/ | ||
862 | /*Set the Search Range for P Frame*/ | ||
863 | pH264VEComp->pVidEncDynamicParams->interCodingParams.searchRangeHorP = | ||
864 | ((OMX_VIDEO_PARAM_MOTIONVECTORTYPE *)pParamStruct)->sXSearchRange; | ||
865 | pH264VEComp->pVidEncDynamicParams->interCodingParams.searchRangeVerP = | ||
866 | ((OMX_VIDEO_PARAM_MOTIONVECTORTYPE *)pParamStruct)->sYSearchRange; | ||
867 | /*Set the Search Range for B Frame*/ | ||
868 | pH264VEComp->pVidEncDynamicParams->interCodingParams.searchRangeHorB = | ||
869 | ((OMX_VIDEO_PARAM_MOTIONVECTORTYPE *)pParamStruct)->sXSearchRange; | ||
870 | pH264VEComp->pVidEncDynamicParams->interCodingParams.searchRangeVerB = | ||
871 | OMX_H264VE_DEFAULT_VERSEARCH_BFRAME; /*the only supported value by codec*/ | ||
872 | pH264VEComp->pVidEncStaticParams->interCodingParams.interCodingPreset = 1; //User Defined | ||
873 | } else { | ||
874 | eError = OMX_ErrorBadPortIndex; | ||
875 | } | ||
876 | break; | ||
877 | |||
878 | case OMX_IndexParamVideoQuantization : | ||
879 | OSAL_Info("In OMX_IndexParamVideoQuantization"); | ||
880 | /* SetParameter can be invoked only when the comp is in loaded or on disabled port */ | ||
881 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
882 | nLCurState = pH264VEComp->sBase.tCurState; | ||
883 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
884 | OMX_CHECK((nLCurState == OMX_StateLoaded), OMX_ErrorIncorrectStateOperation); | ||
885 | /* Check for the correct nSize & nVersion information */ | ||
886 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_QUANTIZATIONTYPE, eError); | ||
887 | if(((OMX_VIDEO_PARAM_QUANTIZATIONTYPE *)pParamStruct)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
888 | pH264VEComp->pVidEncStaticParams->rateControlParams.rateControlParamsPreset = | ||
889 | IH264_RATECONTROLPARAMS_USERDEFINED; | ||
890 | pH264VEComp->pVidEncStaticParams->rateControlParams.qpI = ((OMX_VIDEO_PARAM_QUANTIZATIONTYPE *)pParamStruct)->nQpI; | ||
891 | pH264VEComp->pVidEncStaticParams->rateControlParams.qpP = ((OMX_VIDEO_PARAM_QUANTIZATIONTYPE *)pParamStruct)->nQpP; | ||
892 | (pH264VEComp->pVidEncStaticParams->rateControlParams.qpOffsetB) = | ||
893 | ((((OMX_VIDEO_PARAM_QUANTIZATIONTYPE *)pParamStruct)->nQpB) - | ||
894 | (((OMX_VIDEO_PARAM_QUANTIZATIONTYPE *)pParamStruct)->nQpP)); | ||
895 | |||
896 | /*Update the corresponding Dynamic params also*/ | ||
897 | pH264VEComp->pVidEncDynamicParams->rateControlParams.rateControlParamsPreset = | ||
898 | IH264_RATECONTROLPARAMS_USERDEFINED; | ||
899 | pH264VEComp->pVidEncDynamicParams->rateControlParams.qpI = ((OMX_VIDEO_PARAM_QUANTIZATIONTYPE *)pParamStruct)->nQpI; | ||
900 | pH264VEComp->pVidEncDynamicParams->rateControlParams.qpP = ((OMX_VIDEO_PARAM_QUANTIZATIONTYPE *)pParamStruct)->nQpP; | ||
901 | (pH264VEComp->pVidEncDynamicParams->rateControlParams.qpOffsetB) = | ||
902 | ((((OMX_VIDEO_PARAM_QUANTIZATIONTYPE *)pParamStruct)->nQpB) - | ||
903 | (((OMX_VIDEO_PARAM_QUANTIZATIONTYPE *)pParamStruct)->nQpP)); | ||
904 | } else { | ||
905 | eError = OMX_ErrorBadPortIndex; | ||
906 | } | ||
907 | break; | ||
908 | |||
909 | case OMX_IndexParamVideoSliceFMO : | ||
910 | OSAL_Info("In OMX_IndexParamVideoSliceFMO"); | ||
911 | /* SetParameter can be invoked only when the comp is in loaded or on disabled port */ | ||
912 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
913 | nLCurState = pH264VEComp->sBase.tCurState; | ||
914 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
915 | OMX_CHECK((nLCurState == OMX_StateLoaded), OMX_ErrorIncorrectStateOperation); | ||
916 | /* Check for the correct nSize & nVersion information */ | ||
917 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_AVCSLICEFMO, eError); | ||
918 | if(((OMX_VIDEO_PARAM_AVCSLICEFMO *)pParamStruct)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
919 | pH264VEComp->pVidEncStaticParams->fmoCodingParams.numSliceGroups = | ||
920 | ((OMX_VIDEO_PARAM_AVCSLICEFMO *)pParamStruct)->nNumSliceGroups; | ||
921 | /*Set the slicegrp type*/ | ||
922 | SET_H264CODEC_FMO_SLIGRPMAPTYPE(pParamStruct, pH264VEComp, eError); | ||
923 | OMX_CHECK((eError == OMX_ErrorNone), OMX_ErrorUnsupportedSetting); | ||
924 | |||
925 | /*Set the slicemode*/ | ||
926 | SET_H264CODEC_SLICEMODE(pParamStruct, pH264VEComp, eError); | ||
927 | OMX_CHECK((eError == OMX_ErrorNone), OMX_ErrorUnsupportedSetting); | ||
928 | |||
929 | /*Update the corresponding Dynamic params also*/ | ||
930 | pH264VEComp->pVidEncDynamicParams->sliceCodingParams.sliceMode = | ||
931 | pH264VEComp->pVidEncStaticParams->sliceCodingParams.sliceMode; | ||
932 | } else { | ||
933 | eError = OMX_ErrorBadPortIndex; | ||
934 | } | ||
935 | break; | ||
936 | |||
937 | case OMX_IndexParamVideoIntraRefresh : | ||
938 | OSAL_Info("In OMX_IndexParamVideoIntraRefresh"); | ||
939 | /* SetParameter can be invoked only when the comp is in loaded or on disabled port */ | ||
940 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
941 | nLCurState = pH264VEComp->sBase.tCurState; | ||
942 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
943 | OMX_CHECK((nLCurState == OMX_StateLoaded), OMX_ErrorIncorrectStateOperation); | ||
944 | |||
945 | /* Check for the correct nSize & nVersion information */ | ||
946 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_INTRAREFRESHTYPE, eError); | ||
947 | if(((OMX_VIDEO_PARAM_INTRAREFRESHTYPE *)pParamStruct)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
948 | //SET_H264CODEC_INTRAREFRESHMODE(pParamStruct, pH264VEComp, eError); | ||
949 | OMX_CHECK((eError == OMX_ErrorNone), OMX_ErrorUnsupportedSetting); | ||
950 | } else { | ||
951 | eError = OMX_ErrorBadPortIndex; | ||
952 | } | ||
953 | break; | ||
954 | |||
955 | case OMX_IndexParamVideoVBSMC : | ||
956 | OSAL_Info("In OMX_IndexParamVideoVBSMC"); | ||
957 | /* SetParameter can be invoked only when the comp is in loaded or on disabled port */ | ||
958 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
959 | nLCurState = pH264VEComp->sBase.tCurState; | ||
960 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
961 | OMX_CHECK((nLCurState == OMX_StateLoaded), OMX_ErrorIncorrectStateOperation); | ||
962 | |||
963 | /* Check for the correct nSize & nVersion information */ | ||
964 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_VBSMCTYPE, eError); | ||
965 | if(((OMX_VIDEO_PARAM_VBSMCTYPE *)pParamStruct)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
966 | LVBSMC = ((OMX_VIDEO_PARAM_VBSMCTYPE *)pParamStruct); | ||
967 | if((LVBSMC->b16x16 == OMX_TRUE) && (LVBSMC->b16x8 == OMX_TRUE) && (LVBSMC->b8x16 == OMX_TRUE) && | ||
968 | (LVBSMC->b8x8 == OMX_TRUE) && (LVBSMC->b8x4 == OMX_FALSE) && (LVBSMC->b4x8 == OMX_FALSE) && | ||
969 | (LVBSMC->b4x4 == OMX_FALSE)) { | ||
970 | /*4MV case*/ | ||
971 | /*set the same value for both P & B frames prediction*/ | ||
972 | pH264VEComp->pVidEncStaticParams->interCodingParams.minBlockSizeP = IH264_BLOCKSIZE_8x8; | ||
973 | pH264VEComp->pVidEncStaticParams->interCodingParams.minBlockSizeB = IH264_BLOCKSIZE_8x8; | ||
974 | } else if((LVBSMC->b16x16 == OMX_TRUE) && (LVBSMC->b16x8 == OMX_FALSE) && (LVBSMC->b8x16 == OMX_FALSE) && | ||
975 | (LVBSMC->b8x8 == OMX_FALSE) && (LVBSMC->b8x4 == OMX_FALSE) && (LVBSMC->b4x8 == OMX_FALSE) && | ||
976 | (LVBSMC->b4x4 == OMX_FALSE)) { | ||
977 | /*1 MV case*/ | ||
978 | /*set the same value for both P & B frames prediction*/ | ||
979 | pH264VEComp->pVidEncStaticParams->interCodingParams.minBlockSizeP = IH264_BLOCKSIZE_16x16; | ||
980 | pH264VEComp->pVidEncStaticParams->interCodingParams.minBlockSizeB = IH264_BLOCKSIZE_16x16; | ||
981 | } else { | ||
982 | eError = OMX_ErrorUnsupportedSetting; | ||
983 | } | ||
984 | pH264VEComp->pVidEncStaticParams->interCodingParams.interCodingPreset = 1; //User Defined | ||
985 | } else { | ||
986 | eError = OMX_ErrorBadPortIndex; | ||
987 | } | ||
988 | break; | ||
989 | |||
990 | case OMX_IndexParamVideoProfileLevelCurrent : | ||
991 | OSAL_Info("In OMX_IndexParamVideoProfileLevelCurrent"); | ||
992 | /* SetParameter can be invoked only when the comp is in loaded or on disabled port */ | ||
993 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
994 | nLCurState = pH264VEComp->sBase.tCurState; | ||
995 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
996 | OMX_CHECK((nLCurState == OMX_StateLoaded), OMX_ErrorIncorrectStateOperation); | ||
997 | |||
998 | /* Check for the correct nSize & nVersion information */ | ||
999 | OMX_BASE_CHK_VERSION(pParamStruct, OMX_VIDEO_PARAM_PROFILELEVELTYPE, eError); | ||
1000 | if(((OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pParamStruct)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
1001 | /*Set the Codec Profile */ | ||
1002 | LAVCParams->eProfile = (OMX_VIDEO_AVCPROFILETYPE)((OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pParamStruct)->eProfile; | ||
1003 | SET_H264CODEC_PROFILE(LAVCParams, pH264VEComp, eError); | ||
1004 | OMX_CHECK((eError == OMX_ErrorNone), OMX_ErrorUnsupportedSetting); | ||
1005 | |||
1006 | /*Set the Codec level */ | ||
1007 | LAVCParams->eLevel = (OMX_VIDEO_AVCLEVELTYPE)((OMX_VIDEO_PARAM_PROFILELEVELTYPE *)pParamStruct)->eLevel; | ||
1008 | SET_H264CODEC_LEVEL(LAVCParams, pH264VEComp, eError); | ||
1009 | OMX_CHECK((eError == OMX_ErrorNone), OMX_ErrorUnsupportedSetting); | ||
1010 | } else { | ||
1011 | eError = OMX_ErrorBadPortIndex; | ||
1012 | } | ||
1013 | break; | ||
1014 | |||
1015 | case OMX_IndexParamStandardComponentRole : | ||
1016 | /*Nothing to do Right Now As the Component supports only one Role: AVC*/ | ||
1017 | /*if it suppots multiple roles then need to set the params (Component Pvt, Codec Create & Dynamic acordingly*/ | ||
1018 | break; | ||
1019 | case (OMX_INDEXTYPE)OMX_TI_IndexEncoderReceiveMetadataBuffers: | ||
1020 | /* SetParameter can be invoked only when the comp is in loaded or on disabled port */ | ||
1021 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
1022 | nLCurState = pH264VEComp->sBase.tCurState; | ||
1023 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
1024 | OMX_CHECK((nLCurState == OMX_StateLoaded), OMX_ErrorIncorrectStateOperation); | ||
1025 | |||
1026 | struct OMX_StoreMetaDataInBuffersParams *meta = (OMX_StoreMetaDataInBuffersParams *)pParamStruct; | ||
1027 | nPortIndex = meta->nPortIndex; | ||
1028 | |||
1029 | if (meta->bStoreMetaData) { | ||
1030 | if (nPortIndex == OMX_H264VE_INPUT_PORT) { | ||
1031 | hw_module_t const* module = NULL; | ||
1032 | eError = hw_get_module(GRALLOC_HARDWARE_MODULE_ID, &module); | ||
1033 | if (eError == 0) { | ||
1034 | pH264VEComp->hCC = (void *) ((IMG_gralloc_module_public_t const *)module); | ||
1035 | pH264VEComp->bInputMetaDataBufferMode = OMX_TRUE; | ||
1036 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nBufferSize = sizeof(OMX_MetaDataBuffer); | ||
1037 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nStride = | ||
1038 | ALIGN(pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nStride, HW_ALIGN); | ||
1039 | } | ||
1040 | } else { | ||
1041 | eError = OMX_ErrorUnsupportedSetting; | ||
1042 | } | ||
1043 | } | ||
1044 | break; | ||
1045 | |||
1046 | /* redirects the call to "OMXBase_SetParameter" which supports standard comp indexes */ | ||
1047 | default : | ||
1048 | OSAL_Info("In Default: Call to BASE Set Parameter"); | ||
1049 | eError = OMXBase_SetParameter(hComponent, nParamIndex, pParamStruct); | ||
1050 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
1051 | break; | ||
1052 | } | ||
1053 | |||
1054 | if( bLCodecCreateFlag == OMX_TRUE ) { | ||
1055 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
1056 | pH264VEComp->bCodecCreateSettingsChange=OMX_TRUE; | ||
1057 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
1058 | } | ||
1059 | if( bLCallxDMSetParams == PARAMS_UPDATED_AT_OMX ) { | ||
1060 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
1061 | pH264VEComp->bCallxDMSetParams=PARAMS_UPDATED_AT_OMX; | ||
1062 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
1063 | } | ||
1064 | |||
1065 | EXIT: | ||
1066 | |||
1067 | if( bAllocateLocalAVC ) { | ||
1068 | OSAL_Free(LAVCParams); | ||
1069 | } | ||
1070 | |||
1071 | return (eError); | ||
1072 | } | ||
1073 | |||
1074 | |||
1075 | static OMX_ERRORTYPE OMXH264VE_GetConfig(OMX_HANDLETYPE hComponent, | ||
1076 | OMX_INDEXTYPE nIndex, | ||
1077 | OMX_PTR pConfigData) | ||
1078 | { | ||
1079 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
1080 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
1081 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
1082 | OMX_STATETYPE nLCurState; | ||
1083 | |||
1084 | /* Check the input params */ | ||
1085 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
1086 | OMX_CHECK(pConfigData != NULL, OMX_ErrorBadParameter); | ||
1087 | |||
1088 | /*initialize the component handle and component pvt handle*/ | ||
1089 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
1090 | pH264VEComp = (OMXH264VidEncComp *)pHandle->pComponentPrivate; | ||
1091 | |||
1092 | /* GetConfig can't be invoked when the comp is in Invalid state */ | ||
1093 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
1094 | nLCurState = pH264VEComp->sBase.tCurState; | ||
1095 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
1096 | OMX_CHECK(nLCurState != OMX_StateInvalid, OMX_ErrorIncorrectStateOperation); | ||
1097 | |||
1098 | /* Take care of Supported Indexes over here */ | ||
1099 | switch( nIndex ) { | ||
1100 | /* Client uses this to retrieve the bitrate structure*/ | ||
1101 | case OMX_IndexConfigVideoBitrate : | ||
1102 | OSAL_Info("In OMX_IndexConfigVideoBitrate"); | ||
1103 | /*required for Standard Video Encoder as per Spec*/ | ||
1104 | /* Check for the correct nSize & nVersion information */ | ||
1105 | OMX_BASE_CHK_VERSION(pConfigData, OMX_VIDEO_CONFIG_BITRATETYPE, eError); | ||
1106 | if(((OMX_VIDEO_CONFIG_BITRATETYPE *)pConfigData)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
1107 | ((OMX_VIDEO_CONFIG_BITRATETYPE *)pConfigData)->nEncodeBitrate = | ||
1108 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetBitRate; | ||
1109 | } else { | ||
1110 | eError = OMX_ErrorBadPortIndex; | ||
1111 | } | ||
1112 | break; | ||
1113 | |||
1114 | case OMX_IndexConfigVideoFramerate : | ||
1115 | OSAL_Info("In OMX_IndexConfigVideoFramerate"); | ||
1116 | /*required for Standard Video Encoder as per Spec*/ | ||
1117 | OMX_BASE_CHK_VERSION(pConfigData, OMX_CONFIG_FRAMERATETYPE, eError); | ||
1118 | if(((OMX_CONFIG_FRAMERATETYPE *)pConfigData)->nPortIndex == OMX_H264VE_INPUT_PORT ) { | ||
1119 | ((OMX_CONFIG_FRAMERATETYPE *)pConfigData)->xEncodeFramerate = | ||
1120 | (pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetFrameRate << 16) / 1000; /*Q16 format*/ | ||
1121 | } else { | ||
1122 | eError = OMX_ErrorBadPortIndex; | ||
1123 | } | ||
1124 | break; | ||
1125 | |||
1126 | /* Client uses this to configure the intra refresh period */ | ||
1127 | case OMX_IndexConfigVideoAVCIntraPeriod : | ||
1128 | OSAL_Info("In OMX_IndexConfigVideoAVCIntraPeriod"); | ||
1129 | /* Check for the correct nSize & nVersion information */ | ||
1130 | OMX_BASE_CHK_VERSION(pConfigData, OMX_VIDEO_CONFIG_AVCINTRAPERIOD, eError); | ||
1131 | if(((OMX_VIDEO_CONFIG_AVCINTRAPERIOD *)pConfigData)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
1132 | ((OMX_VIDEO_CONFIG_AVCINTRAPERIOD *)pConfigData)->nIDRPeriod = pH264VEComp->pVidEncStaticParams->IDRFrameInterval; | ||
1133 | ((OMX_VIDEO_CONFIG_AVCINTRAPERIOD *)pConfigData)->nPFrames = | ||
1134 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.intraFrameInterval; | ||
1135 | } else { | ||
1136 | eError = OMX_ErrorBadPortIndex; | ||
1137 | } | ||
1138 | break; | ||
1139 | |||
1140 | case OMX_IndexConfigVideoIntraVOPRefresh : | ||
1141 | OSAL_Info("In OMX_IndexConfigVideoIntraVOPRefresh"); | ||
1142 | /* Check for the correct nSize & nVersion information */ | ||
1143 | OMX_BASE_CHK_VERSION(pConfigData, OMX_CONFIG_INTRAREFRESHVOPTYPE, eError); | ||
1144 | if(((OMX_CONFIG_INTRAREFRESHVOPTYPE *)pConfigData)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
1145 | ((OMX_CONFIG_INTRAREFRESHVOPTYPE *)pConfigData)->IntraRefreshVOP = | ||
1146 | ((pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.forceFrame == IVIDEO_I_FRAME) ? OMX_TRUE : OMX_FALSE); | ||
1147 | } else { | ||
1148 | eError = OMX_ErrorBadPortIndex; | ||
1149 | } | ||
1150 | break; | ||
1151 | |||
1152 | case OMX_IndexConfigVideoNalSize : | ||
1153 | OSAL_Info("In OMX_IndexConfigVideoNalSize"); | ||
1154 | /* Check for the correct nSize & nVersion information */ | ||
1155 | OMX_BASE_CHK_VERSION(pConfigData, OMX_VIDEO_CONFIG_NALSIZE, eError); | ||
1156 | if(((OMX_VIDEO_CONFIG_NALSIZE *)pConfigData)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
1157 | if( pH264VEComp->pVidEncDynamicParams->sliceCodingParams.sliceMode == IH264_SLICEMODE_BYTES ) { | ||
1158 | ((OMX_VIDEO_CONFIG_NALSIZE *)pConfigData)->nNaluBytes = | ||
1159 | pH264VEComp->pVidEncDynamicParams->sliceCodingParams.sliceUnitSize; | ||
1160 | } else { | ||
1161 | eError = OMX_ErrorUnsupportedSetting; | ||
1162 | } | ||
1163 | } else { | ||
1164 | eError = OMX_ErrorBadPortIndex; | ||
1165 | } | ||
1166 | break; | ||
1167 | |||
1168 | case OMX_IndexConfigPriorityMgmt : | ||
1169 | OSAL_Info("In OMX_IndexConfigPriorityMgmt"); | ||
1170 | |||
1171 | default : | ||
1172 | OSAL_Info("In Default: Call to BASE GetConfig"); | ||
1173 | eError = OMXBase_GetConfig(hComponent, nIndex, pConfigData); | ||
1174 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
1175 | break; | ||
1176 | } | ||
1177 | |||
1178 | EXIT: | ||
1179 | return (eError); | ||
1180 | |||
1181 | } | ||
1182 | |||
1183 | |||
1184 | static OMX_ERRORTYPE OMXH264VE_SetConfig(OMX_HANDLETYPE hComponent, | ||
1185 | OMX_INDEXTYPE nIndex, | ||
1186 | OMX_PTR pConfigData) | ||
1187 | { | ||
1188 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
1189 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
1190 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
1191 | OMX_STATETYPE nLCurState; | ||
1192 | OMX_BOOL bLCodecCreateFlag=OMX_FALSE; | ||
1193 | // OMX_U32 tStatus; | ||
1194 | PARAMS_UPDATE_STATUS bLCallxDMSetParams=NO_PARAM_CHANGE; | ||
1195 | |||
1196 | /* Check the input params */ | ||
1197 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
1198 | OMX_CHECK(pConfigData != NULL, OMX_ErrorBadParameter); | ||
1199 | |||
1200 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
1201 | pH264VEComp = (OMXH264VidEncComp *)pHandle->pComponentPrivate; | ||
1202 | |||
1203 | /* SetConfig can't be invoked when the comp is in Invalid state */ | ||
1204 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
1205 | nLCurState = pH264VEComp->sBase.tCurState; | ||
1206 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
1207 | OMX_CHECK(nLCurState != OMX_StateInvalid, OMX_ErrorIncorrectStateOperation); | ||
1208 | |||
1209 | /* Take care of Supported Indices over here */ | ||
1210 | switch( nIndex ) { | ||
1211 | case OMX_IndexConfigVideoBitrate : | ||
1212 | OSAL_Info("In OMX_IndexConfigVideoBitrate"); | ||
1213 | /*required for Standard Video Encoder as per Spec*/ | ||
1214 | /* Check for the correct nSize & nVersion information */ | ||
1215 | OMX_BASE_CHK_VERSION(pConfigData, OMX_VIDEO_CONFIG_BITRATETYPE, eError); | ||
1216 | if(((OMX_VIDEO_CONFIG_BITRATETYPE *)pConfigData)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
1217 | eError = OMXH264VE_CheckBitRateCap(((OMX_VIDEO_CONFIG_BITRATETYPE *)pConfigData)->nEncodeBitrate, hComponent); | ||
1218 | OMX_CHECK((eError == OMX_ErrorNone), OMX_ErrorUnsupportedSetting); | ||
1219 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetBitRate = | ||
1220 | ((OMX_VIDEO_CONFIG_BITRATETYPE *)pConfigData)->nEncodeBitrate; | ||
1221 | |||
1222 | if (pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetBitRate < OMX_H264VE_MIN_BITRATE) { | ||
1223 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetBitRate = OMX_H264VE_MIN_BITRATE; | ||
1224 | } | ||
1225 | |||
1226 | /*Update the output port bit rate as well...for the get param to reflect the proper values*/ | ||
1227 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.format.video.nBitrate = | ||
1228 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetBitRate; | ||
1229 | /*set the HRD biffer size appropriately*/ | ||
1230 | if( pH264VEComp->pVidEncStaticParams->rateControlParams.rcAlgo == IH264_RATECONTROL_PRC_LOW_DELAY ) { | ||
1231 | pH264VEComp->pVidEncDynamicParams->rateControlParams.HRDBufferSize = | ||
1232 | (pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetBitRate) / 2; | ||
1233 | } else { | ||
1234 | pH264VEComp->pVidEncDynamicParams->rateControlParams.HRDBufferSize = | ||
1235 | (pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetBitRate); | ||
1236 | } | ||
1237 | bLCallxDMSetParams=PARAMS_UPDATED_AT_OMX; | ||
1238 | |||
1239 | } else { | ||
1240 | eError = OMX_ErrorBadPortIndex; | ||
1241 | } | ||
1242 | break; | ||
1243 | |||
1244 | case OMX_IndexConfigVideoFramerate : | ||
1245 | OSAL_Info("In OMX_IndexConfigVideoFramerate"); | ||
1246 | /*required for Standard Video Encoder as per Spec*/ | ||
1247 | OMX_BASE_CHK_VERSION(pConfigData, OMX_CONFIG_FRAMERATETYPE, eError); | ||
1248 | if(((OMX_CONFIG_FRAMERATETYPE *)pConfigData)->nPortIndex == OMX_H264VE_INPUT_PORT ) { | ||
1249 | if( pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.xFramerate != | ||
1250 | (((OMX_CONFIG_FRAMERATETYPE *)pConfigData)->xEncodeFramerate)) { | ||
1251 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetFrameRate = | ||
1252 | ((((OMX_CONFIG_FRAMERATETYPE *)pConfigData)->xEncodeFramerate) >> 16) * 1000; | ||
1253 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.xFramerate = | ||
1254 | (((OMX_CONFIG_FRAMERATETYPE *)pConfigData)->xEncodeFramerate); | ||
1255 | bLCallxDMSetParams=PARAMS_UPDATED_AT_OMX; | ||
1256 | } | ||
1257 | } else { | ||
1258 | eError = OMX_ErrorBadPortIndex; | ||
1259 | } | ||
1260 | break; | ||
1261 | |||
1262 | case OMX_IndexConfigVideoAVCIntraPeriod : | ||
1263 | OSAL_Info("In OMX_IndexConfigVideoAVCIntraPeriod"); | ||
1264 | /* Check for the correct nSize & nVersion information */ | ||
1265 | OMX_BASE_CHK_VERSION(pConfigData, OMX_VIDEO_CONFIG_AVCINTRAPERIOD, eError); | ||
1266 | if(((OMX_VIDEO_CONFIG_AVCINTRAPERIOD *)pConfigData)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
1267 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
1268 | nLCurState = pH264VEComp->sBase.tCurState; | ||
1269 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
1270 | /*If Client want to set the IDR frame Interval */ | ||
1271 | if(((OMX_VIDEO_CONFIG_AVCINTRAPERIOD *)pConfigData)->nIDRPeriod != 1 ) { | ||
1272 | /*IDR frame Interval is other than the Component default settings - | ||
1273 | it is possible only when the component is in loaded state*/ | ||
1274 | OMX_CHECK((nLCurState == OMX_StateLoaded), OMX_ErrorIncorrectStateOperation); | ||
1275 | pH264VEComp->pVidEncStaticParams->IDRFrameInterval = ((OMX_VIDEO_CONFIG_AVCINTRAPERIOD *)pConfigData)->nIDRPeriod; | ||
1276 | bLCodecCreateFlag = OMX_TRUE; | ||
1277 | } | ||
1278 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.intraFrameInterval = | ||
1279 | ((OMX_VIDEO_CONFIG_AVCINTRAPERIOD *)pConfigData)->nPFrames; | ||
1280 | bLCallxDMSetParams = PARAMS_UPDATED_AT_OMX; | ||
1281 | } else { | ||
1282 | eError = OMX_ErrorBadPortIndex; | ||
1283 | } | ||
1284 | break; | ||
1285 | |||
1286 | case OMX_IndexConfigVideoIntraVOPRefresh : | ||
1287 | OSAL_Info("In OMX_IndexConfigVideoIntraVOPRefresh"); | ||
1288 | /* Check for the correct nSize & nVersion information */ | ||
1289 | OMX_BASE_CHK_VERSION(pConfigData, OMX_CONFIG_INTRAREFRESHVOPTYPE, eError); | ||
1290 | if(((OMX_CONFIG_INTRAREFRESHVOPTYPE *)pConfigData)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
1291 | if(((OMX_CONFIG_INTRAREFRESHVOPTYPE *)pConfigData)->IntraRefreshVOP ) { | ||
1292 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.forceFrame = IVIDEO_IDR_FRAME; | ||
1293 | } else { | ||
1294 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.forceFrame = IVIDEO_NA_FRAME; | ||
1295 | } | ||
1296 | bLCallxDMSetParams = PARAMS_UPDATED_AT_OMX; | ||
1297 | } else { | ||
1298 | eError = OMX_ErrorBadPortIndex; | ||
1299 | } | ||
1300 | break; | ||
1301 | |||
1302 | case OMX_IndexConfigVideoNalSize : | ||
1303 | OSAL_Info("In OMX_IndexConfigVideoNalSize"); | ||
1304 | /* Check for the correct nSize & nVersion information */ | ||
1305 | OMX_BASE_CHK_VERSION(pConfigData, OMX_VIDEO_CONFIG_NALSIZE, eError); | ||
1306 | if(((OMX_VIDEO_CONFIG_NALSIZE *)pConfigData)->nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
1307 | if( pH264VEComp->pVidEncDynamicParams->sliceCodingParams.sliceMode == IH264_SLICEMODE_DEFAULT ) { | ||
1308 | pH264VEComp->pVidEncDynamicParams->sliceCodingParams.sliceMode = IH264_SLICEMODE_BYTES; | ||
1309 | pH264VEComp->pVidEncDynamicParams->sliceCodingParams.sliceCodingPreset = IH264_SLICECODING_USERDEFINED; | ||
1310 | } | ||
1311 | if( pH264VEComp->pVidEncDynamicParams->sliceCodingParams.sliceMode == IH264_SLICEMODE_BYTES ) { | ||
1312 | OMX_CHECK(pH264VEComp->pVidEncStaticParams->videnc2Params.inputContentType != IVIDEO_INTERLACED, | ||
1313 | OMX_ErrorUnsupportedSetting); | ||
1314 | OMX_CHECK(pH264VEComp->pVidEncStaticParams->entropyCodingMode != IH264_ENTROPYCODING_CABAC, | ||
1315 | OMX_ErrorUnsupportedSetting); | ||
1316 | OMX_CHECK(pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.inputWidth >= 128, | ||
1317 | OMX_ErrorUnsupportedSetting); | ||
1318 | OMX_CHECK(pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.interFrameInterval == 1, | ||
1319 | OMX_ErrorUnsupportedSetting); | ||
1320 | pH264VEComp->pVidEncDynamicParams->sliceCodingParams.sliceUnitSize = | ||
1321 | ((OMX_VIDEO_CONFIG_NALSIZE *)pConfigData)->nNaluBytes; | ||
1322 | |||
1323 | bLCallxDMSetParams = PARAMS_UPDATED_AT_OMX; | ||
1324 | if((nLCurState == OMX_StateLoaded) && (eError == OMX_ErrorNone)) { | ||
1325 | if( pH264VEComp->pVidEncStaticParams->sliceCodingParams.sliceMode == IH264_SLICEMODE_DEFAULT ) { | ||
1326 | pH264VEComp->pVidEncStaticParams->sliceCodingParams.sliceMode = IH264_SLICEMODE_BYTES; | ||
1327 | pH264VEComp->pVidEncStaticParams->sliceCodingParams.sliceCodingPreset = IH264_SLICECODING_USERDEFINED; | ||
1328 | } | ||
1329 | pH264VEComp->pVidEncStaticParams->sliceCodingParams.sliceUnitSize = | ||
1330 | pH264VEComp->pVidEncDynamicParams->sliceCodingParams.sliceUnitSize; | ||
1331 | } | ||
1332 | } else { | ||
1333 | eError = OMX_ErrorUnsupportedSetting; | ||
1334 | } | ||
1335 | } else { | ||
1336 | eError = OMX_ErrorBadPortIndex; | ||
1337 | } | ||
1338 | break; | ||
1339 | |||
1340 | case OMX_IndexConfigPriorityMgmt : | ||
1341 | OSAL_ErrorTrace("In OMX_IndexConfigPriorityMgmt"); | ||
1342 | |||
1343 | break; | ||
1344 | |||
1345 | default : | ||
1346 | OSAL_Info("In Default: Call to BASE SetConfig"); | ||
1347 | eError = OMXBase_SetConfig(hComponent, nIndex, pConfigData); | ||
1348 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
1349 | break; | ||
1350 | } | ||
1351 | |||
1352 | if( bLCodecCreateFlag == OMX_TRUE ) { | ||
1353 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
1354 | pH264VEComp->bCodecCreateSettingsChange = OMX_TRUE; | ||
1355 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
1356 | } | ||
1357 | |||
1358 | if( bLCallxDMSetParams == PARAMS_UPDATED_AT_OMX ) { | ||
1359 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
1360 | pH264VEComp->bCallxDMSetParams = PARAMS_UPDATED_AT_OMX; | ||
1361 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
1362 | } | ||
1363 | |||
1364 | EXIT: | ||
1365 | |||
1366 | return (eError); | ||
1367 | } | ||
1368 | |||
1369 | |||
1370 | static OMX_ERRORTYPE OMXH264VE_CommandNotify(OMX_HANDLETYPE hComponent, | ||
1371 | OMX_COMMANDTYPE Cmd, | ||
1372 | OMX_U32 nParam, | ||
1373 | OMX_PTR pCmdData) | ||
1374 | { | ||
1375 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
1376 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
1377 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
1378 | OMX_U32 i; | ||
1379 | OMX_STATETYPE tCurState, tNewState; | ||
1380 | XDAS_Int32 retval = 0; | ||
1381 | (void)pCmdData; | ||
1382 | |||
1383 | /* Check the input parameters */ | ||
1384 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
1385 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
1386 | pH264VEComp = (OMXH264VidEncComp *)pHandle->pComponentPrivate; | ||
1387 | |||
1388 | |||
1389 | /* Complete all the operations like Alg Instance create or | ||
1390 | * allocation of any resources which are specific to the Component, Notify this | ||
1391 | * Asynchronous event completion to the Base Comp via ReturnEventNotify call*/ | ||
1392 | |||
1393 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
1394 | tCurState = pH264VEComp->sBase.tCurState; | ||
1395 | tNewState = pH264VEComp->sBase.tNewState; | ||
1396 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
1397 | |||
1398 | switch( Cmd ) { | ||
1399 | case OMX_CommandStateSet : | ||
1400 | /* Incase if the comp is moving from loaded to idle */ | ||
1401 | if((tCurState == OMX_StateLoaded) && (tNewState == OMX_StateIdle)) { | ||
1402 | OSAL_Info("In OMX_CommandStateSet:Loaded to Idle"); | ||
1403 | eError = OMXH264VE_SetEncCodecReady(hComponent); | ||
1404 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1405 | } | ||
1406 | |||
1407 | /* Incase if the comp is moving from idle to executing, process buffers if an supplier port */ | ||
1408 | else if(((tCurState == OMX_StateIdle) && (tNewState == OMX_StateExecuting)) || | ||
1409 | ((tCurState == OMX_StateIdle) && (tNewState == OMX_StatePause))) { | ||
1410 | OSAL_Info("In OMX_CommandStateSet:Idle to Executing"); | ||
1411 | |||
1412 | pH264VEComp->pCodecInBufferArray = (OMX_BUFFERHEADERTYPE **)OSAL_Malloc(sizeof(OMX_BUFFERHEADERTYPE*) * | ||
1413 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nBufferCountActual); | ||
1414 | OMX_CHECK(pH264VEComp->pCodecInBufferArray != NULL, OMX_ErrorInsufficientResources); | ||
1415 | /*allocate the memory for the bufferhdrs*/ | ||
1416 | for (i = 0; i < pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nBufferCountActual; i++ ) { | ||
1417 | pH264VEComp->pCodecInBufferArray[i] = NULL; | ||
1418 | } | ||
1419 | |||
1420 | pH264VEComp->pCodecInBufferBackupArray = (OMXBase_BufHdrPvtData *)OSAL_Malloc(sizeof(OMXBase_BufHdrPvtData) * | ||
1421 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nBufferCountActual); | ||
1422 | |||
1423 | OMX_CHECK(pH264VEComp->pCodecInBufferBackupArray != NULL, OMX_ErrorInsufficientResources); | ||
1424 | } | ||
1425 | /* Incase If the comp is moving to Idle from executing, return all the buffers back to the IL client*/ | ||
1426 | else if(((tCurState == OMX_StateExecuting) && (tNewState == OMX_StateIdle)) || | ||
1427 | ((tCurState == OMX_StatePause) && (tNewState == OMX_StateIdle))) { | ||
1428 | OSAL_Info("In OMX_CommandStateSet:Executing/Pause to Idle"); | ||
1429 | |||
1430 | /*Flushout all the locked buffers*/ | ||
1431 | eError=OMXH264VE_FLUSHLockedBuffers(pHandle); | ||
1432 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1433 | if( pH264VEComp->bCodecCreate ) { | ||
1434 | /*Codec Call: control call with command XDM_RESET*/ | ||
1435 | OSAL_Info("Call Codec_RESET "); | ||
1436 | eError = OMXH264VE_VISACONTROL(pH264VEComp->pVidEncHandle, XDM_RESET, | ||
1437 | (VIDENC2_DynamicParams *)(pH264VEComp->pVidEncDynamicParams), | ||
1438 | (IVIDENC2_Status *)(pH264VEComp->pVidEncStatus), hComponent, &retval); | ||
1439 | if( retval != VIDENC2_EOK ) { | ||
1440 | OSAL_ErrorTrace("Got error from the Codec_RESET call"); | ||
1441 | OMX_TI_GET_ERROR(pH264VEComp, pH264VEComp->pVidEncStatus->videnc2Status.extendedError, eError); | ||
1442 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1443 | } | ||
1444 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1445 | } | ||
1446 | |||
1447 | if( pH264VEComp->pCodecInBufferArray ) { | ||
1448 | OSAL_Free(pH264VEComp->pCodecInBufferArray); | ||
1449 | } | ||
1450 | |||
1451 | if (pH264VEComp->bInputMetaDataBufferMode && pH264VEComp->pBackupBuffers) { | ||
1452 | for (i = 0; i < pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nBufferCountActual; i++) { | ||
1453 | if(pH264VEComp->pBackupBuffers[i]) { | ||
1454 | //unregister this buffer with DRM | ||
1455 | dce_buf_unlock(1, (size_t *)&(pH264VEComp->pCodecInBufferBackupArray[i].sMemHdr[0].dma_buf_fd)); | ||
1456 | pH264VEComp->mAllocDev->free(pH264VEComp->mAllocDev, (buffer_handle_t)(pH264VEComp->pBackupBuffers[i])); | ||
1457 | pH264VEComp->pBackupBuffers[i] = NULL; | ||
1458 | } | ||
1459 | } | ||
1460 | OSAL_Free(pH264VEComp->pBackupBuffers); | ||
1461 | pH264VEComp->pBackupBuffers = NULL; | ||
1462 | } | ||
1463 | |||
1464 | if( pH264VEComp->pCodecInBufferBackupArray ) { | ||
1465 | OSAL_Free(pH264VEComp->pCodecInBufferBackupArray); | ||
1466 | } | ||
1467 | |||
1468 | if(pH264VEComp && pH264VEComp->mAllocDev) { | ||
1469 | gralloc_close(pH264VEComp->mAllocDev); | ||
1470 | pH264VEComp->mAllocDev = NULL; | ||
1471 | } | ||
1472 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
1473 | pH264VEComp->nCodecConfigSize = 0; | ||
1474 | pH264VEComp->bAfterGenHeader = OMX_FALSE; | ||
1475 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
1476 | |||
1477 | /* Update the Generate Header Params : to continue with New stream w/o codec create */ | ||
1478 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.generateHeader = XDM_GENERATE_HEADER; | ||
1479 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
1480 | pH264VEComp->bCallxDMSetParams = PARAMS_UPDATED_AT_OMX; | ||
1481 | pH264VEComp->bSendCodecConfig = OMX_TRUE; | ||
1482 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
1483 | } | ||
1484 | /* State transition from pause to executing state */ | ||
1485 | else if((tCurState == OMX_StatePause) && | ||
1486 | (tNewState == OMX_StateExecuting)) { | ||
1487 | OSAL_Info("In OMX_CommandStateSet:Pause to Executing"); | ||
1488 | } else if((tCurState == OMX_StateExecuting) && | ||
1489 | (tNewState == OMX_StatePause)) { | ||
1490 | } else if((tCurState == OMX_StateIdle) && | ||
1491 | (tNewState == OMX_StateLoaded)) { | ||
1492 | OSAL_Info("In OMX_CommandStateSet:Idle to Loaded"); | ||
1493 | /* Delete the Codec Instance */ | ||
1494 | if( pH264VEComp->bCodecCreate && pH264VEComp->pVidEncHandle) { | ||
1495 | VIDENC2_delete(pH264VEComp->pVidEncHandle); | ||
1496 | pH264VEComp->pVidEncHandle = NULL; | ||
1497 | } | ||
1498 | pH264VEComp->bCodecCreate=OMX_FALSE; | ||
1499 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
1500 | pH264VEComp->bCallxDMSetParams=PARAMS_UPDATED_AT_OMX; | ||
1501 | pH264VEComp->bSendCodecConfig=OMX_TRUE; | ||
1502 | pH264VEComp->bSetParamInputIsDone = OMX_FALSE; | ||
1503 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
1504 | } else if( tNewState == OMX_StateInvalid ) { | ||
1505 | OSAL_Info("In OMX_CommandStateSet:Invalid state"); | ||
1506 | /* Delete the Codec Instance */ | ||
1507 | if( pH264VEComp->bCodecCreate && pH264VEComp->pVidEncHandle) { | ||
1508 | VIDENC2_delete(pH264VEComp->pVidEncHandle); | ||
1509 | pH264VEComp->pVidEncHandle = NULL; | ||
1510 | } | ||
1511 | pH264VEComp->bCodecCreate=OMX_FALSE; | ||
1512 | } | ||
1513 | break; | ||
1514 | |||
1515 | case OMX_CommandFlush : | ||
1516 | OSAL_Info("In OMX_CommandFlush"); | ||
1517 | OMX_CHECK(((nParam == OMX_H264VE_OUTPUT_PORT) || (nParam == OMX_H264VE_INPUT_PORT) || (nParam == OMX_ALL)), | ||
1518 | OMX_ErrorBadParameter); | ||
1519 | if((nParam == OMX_H264VE_INPUT_PORT) || (nParam == OMX_ALL)) { | ||
1520 | if( pH264VEComp->bCodecCreate ) { | ||
1521 | /*Codec Call: control call with command XDM_FLUSH*/ | ||
1522 | OSAL_Info("Call CodecFlush "); | ||
1523 | eError = OMXH264VE_VISACONTROL(pH264VEComp->pVidEncHandle, XDM_FLUSH, | ||
1524 | (VIDENC2_DynamicParams *)(pH264VEComp->pVidEncDynamicParams), | ||
1525 | (IVIDENC2_Status *)(pH264VEComp->pVidEncStatus), hComponent, &retval); | ||
1526 | if( retval != VIDENC2_EOK ) { | ||
1527 | OSAL_ErrorTrace("Got error from the CodecFlush call"); | ||
1528 | OMX_TI_GET_ERROR(pH264VEComp, pH264VEComp->pVidEncStatus->videnc2Status.extendedError, eError); | ||
1529 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1530 | } | ||
1531 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1532 | } | ||
1533 | /*Flushout all the locked buffers*/ | ||
1534 | eError = OMXH264VE_FLUSHLockedBuffers(pHandle); | ||
1535 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1536 | /* Reset the Codec : to continue with New stream w/o codec create */ | ||
1537 | if( pH264VEComp->bCodecCreate ) { | ||
1538 | /*Codec Call: control call with command XDM_RESET*/ | ||
1539 | OSAL_Info("Call Codec_RESET "); | ||
1540 | eError = OMXH264VE_VISACONTROL(pH264VEComp->pVidEncHandle, XDM_RESET, | ||
1541 | (VIDENC2_DynamicParams *)(pH264VEComp->pVidEncDynamicParams), | ||
1542 | (IVIDENC2_Status *)(pH264VEComp->pVidEncStatus), hComponent, &retval); | ||
1543 | if( retval != VIDENC2_EOK ) { | ||
1544 | OSAL_ErrorTrace("Got error from the Codec_RESET call"); | ||
1545 | OMX_TI_GET_ERROR(pH264VEComp, pH264VEComp->pVidEncStatus->videnc2Status.extendedError, eError); | ||
1546 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1547 | } | ||
1548 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1549 | } | ||
1550 | |||
1551 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.generateHeader = XDM_GENERATE_HEADER; | ||
1552 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
1553 | pH264VEComp->bCallxDMSetParams = PARAMS_UPDATED_AT_OMX; | ||
1554 | pH264VEComp->bSendCodecConfig = OMX_TRUE; | ||
1555 | pH264VEComp->nCodecConfigSize = 0; | ||
1556 | pH264VEComp->bAfterGenHeader = OMX_FALSE; | ||
1557 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
1558 | } | ||
1559 | if(nParam == OMX_H264VE_OUTPUT_PORT) { | ||
1560 | /*do nothing*/ | ||
1561 | } | ||
1562 | break; | ||
1563 | |||
1564 | case OMX_CommandPortDisable : | ||
1565 | OSAL_Info("In OMX_CommandPortDisable"); | ||
1566 | OMX_CHECK(((nParam == OMX_H264VE_OUTPUT_PORT) || (nParam == OMX_H264VE_INPUT_PORT) || (nParam == OMX_ALL)), | ||
1567 | OMX_ErrorBadParameter); | ||
1568 | if((nParam == OMX_H264VE_INPUT_PORT) || (nParam == OMX_ALL)) { | ||
1569 | if( pH264VEComp->bCodecCreate ) { | ||
1570 | /*control call with command XDM_FLUSH*/ | ||
1571 | OSAL_Info("Call CodecFlush "); | ||
1572 | eError = OMXH264VE_VISACONTROL(pH264VEComp->pVidEncHandle, XDM_FLUSH, | ||
1573 | (VIDENC2_DynamicParams *)(pH264VEComp->pVidEncDynamicParams), | ||
1574 | (IVIDENC2_Status *)(pH264VEComp->pVidEncStatus), hComponent, &retval); | ||
1575 | if( retval != VIDENC2_EOK ) { | ||
1576 | OSAL_ErrorTrace("Got error from the CodecFlush call"); | ||
1577 | OMX_TI_GET_ERROR(pH264VEComp, pH264VEComp->pVidEncStatus->videnc2Status.extendedError, eError); | ||
1578 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1579 | } | ||
1580 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1581 | } | ||
1582 | /*Flushout all the locked buffers*/ | ||
1583 | eError= OMXH264VE_FLUSHLockedBuffers(pHandle); | ||
1584 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1585 | /* Reset the Codec : to continue with New stream w/o codec create */ | ||
1586 | if( pH264VEComp->bCodecCreate ) { | ||
1587 | /*Codec Call: control call with command XDM_RESET*/ | ||
1588 | OSAL_Info("Call Codec_RESET "); | ||
1589 | eError = OMXH264VE_VISACONTROL(pH264VEComp->pVidEncHandle, XDM_RESET, | ||
1590 | (VIDENC2_DynamicParams *)(pH264VEComp->pVidEncDynamicParams), | ||
1591 | (IVIDENC2_Status *)(pH264VEComp->pVidEncStatus), hComponent, &retval); | ||
1592 | if( retval != VIDENC2_EOK ) { | ||
1593 | OSAL_ErrorTrace("Got error from the Codec_RESET call"); | ||
1594 | OMX_TI_GET_ERROR(pH264VEComp, pH264VEComp->pVidEncStatus->videnc2Status.extendedError, eError); | ||
1595 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1596 | } | ||
1597 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1598 | } | ||
1599 | pH264VEComp->bInputPortDisable = OMX_TRUE; | ||
1600 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.generateHeader = XDM_GENERATE_HEADER; | ||
1601 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
1602 | pH264VEComp->bCallxDMSetParams = PARAMS_UPDATED_AT_OMX; | ||
1603 | pH264VEComp->bSendCodecConfig = OMX_TRUE; | ||
1604 | pH264VEComp->bSetParamInputIsDone = OMX_FALSE; | ||
1605 | pH264VEComp->nCodecConfigSize = 0; | ||
1606 | pH264VEComp->bAfterGenHeader = OMX_FALSE; | ||
1607 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
1608 | } | ||
1609 | if( nParam == OMX_H264VE_OUTPUT_PORT ) { | ||
1610 | /*do nothing*/ | ||
1611 | } | ||
1612 | break; | ||
1613 | |||
1614 | case OMX_CommandPortEnable : | ||
1615 | OSAL_Info("In OMX_CommandPortEnable"); | ||
1616 | /*base is taking care of allocating all the resources*/ | ||
1617 | OMX_CHECK(((nParam == OMX_H264VE_OUTPUT_PORT) || (nParam == OMX_H264VE_INPUT_PORT) || (nParam == OMX_ALL)), | ||
1618 | OMX_ErrorBadParameter); | ||
1619 | if((nParam == OMX_H264VE_INPUT_PORT) || (nParam == OMX_ALL)) { | ||
1620 | if((pH264VEComp->bCodecCreate) & (pH264VEComp->bInputPortDisable) & (pH264VEComp->bCodecCreateSettingsChange)) { | ||
1621 | /* Delete the old Codec Instance */ | ||
1622 | if( pH264VEComp->pVidEncHandle ) { | ||
1623 | VIDENC2_delete(pH264VEComp->pVidEncHandle); | ||
1624 | pH264VEComp->pVidEncHandle = NULL; | ||
1625 | } | ||
1626 | |||
1627 | /* Create a New Codec Instance */ | ||
1628 | eError = OMXH264VE_SetEncCodecReady(hComponent); | ||
1629 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1630 | } /*end if codec create*/ | ||
1631 | /*Reset the port disable flag */ | ||
1632 | pH264VEComp->bInputPortDisable = OMX_FALSE; | ||
1633 | } /*end if(i/p or ALL )*/ | ||
1634 | if( nParam == OMX_H264VE_OUTPUT_PORT ) { | ||
1635 | /*do nothing*/ | ||
1636 | } | ||
1637 | break; | ||
1638 | |||
1639 | default : | ||
1640 | OSAL_Info("In Default"); | ||
1641 | eError = OMX_ErrorBadParameter; | ||
1642 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1643 | break; | ||
1644 | } | ||
1645 | |||
1646 | /* Note: Notify this completion to the Base comp via ReturnEventNotify call */ | ||
1647 | OSAL_Info("Notify Base via ReturnEventNotify "); | ||
1648 | eError = pH264VEComp->sBase.fpReturnEventNotify(hComponent, OMX_EventCmdComplete, Cmd, nParam, NULL); | ||
1649 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1650 | |||
1651 | EXIT: | ||
1652 | |||
1653 | return (eError); | ||
1654 | } | ||
1655 | |||
1656 | |||
1657 | static OMX_ERRORTYPE OMXH264VE_DataNotify(OMX_HANDLETYPE hComponent) | ||
1658 | { | ||
1659 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
1660 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
1661 | OMX_COMPONENTTYPE *pComp = NULL; | ||
1662 | OMX_BUFFERHEADERTYPE *pOutBufHeader = NULL; | ||
1663 | OMX_U32 nInMsgCount = 0, nOutMsgCount = 0, i, j; | ||
1664 | XDAS_Int32 retval = 0; | ||
1665 | OMX_STATETYPE tCurState; | ||
1666 | PARAMS_UPDATE_STATUS bLCallxDMSetParams; | ||
1667 | OMX_BOOL bLEOS=OMX_FALSE; | ||
1668 | OMX_BOOL bLCodecFlush=OMX_FALSE; | ||
1669 | OMX_S32 InBufferHdrIndex = -1; | ||
1670 | OMX_U32 LCodecLockedBufferCount = 0; | ||
1671 | OMX_BOOL bLCallCodecProcess = OMX_FALSE; | ||
1672 | OMXBase_CodecConfigBuf AttrParams; | ||
1673 | OMX_BOOL bLSendCodecConfig; | ||
1674 | // void *srcPtr = NULL, *dstPtr = NULL; | ||
1675 | // OMX_U32 step; | ||
1676 | OMX_U32 stride; | ||
1677 | |||
1678 | /* Check the input parameters */ | ||
1679 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
1680 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
1681 | pH264VEComp = (OMXH264VidEncComp *)pComp->pComponentPrivate; | ||
1682 | |||
1683 | /* Strat buffer processing only when the comp is in Executing state and the Port are Enabled*/ | ||
1684 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
1685 | tCurState = pH264VEComp->sBase.tCurState; | ||
1686 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
1687 | if((tCurState == OMX_StateExecuting) && (pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.bEnabled) | ||
1688 | && (pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.bEnabled)) { | ||
1689 | |||
1690 | eError = pH264VEComp->sBase.pPvtData->fpDioGetCount(hComponent, OMX_H264VE_INPUT_PORT, (OMX_PTR)&nInMsgCount); | ||
1691 | OMX_CHECK(((eError == OMX_ErrorNone) || (eError == OMX_TI_WarningEosReceived)), OMX_ErrorInsufficientResources); | ||
1692 | |||
1693 | eError = pH264VEComp->sBase.pPvtData->fpDioGetCount(hComponent, OMX_H264VE_OUTPUT_PORT, (OMX_PTR)&nOutMsgCount); | ||
1694 | OMX_CHECK((eError == OMX_ErrorNone), OMX_ErrorInsufficientResources); | ||
1695 | |||
1696 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
1697 | bLSendCodecConfig = pH264VEComp->bSendCodecConfig; | ||
1698 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
1699 | |||
1700 | if( bLSendCodecConfig ) { | ||
1701 | if((nOutMsgCount > 0) && (nInMsgCount > 0)) { | ||
1702 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
1703 | bLCallxDMSetParams=pH264VEComp->bCallxDMSetParams; | ||
1704 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
1705 | if( bLCallxDMSetParams == PARAMS_UPDATED_AT_OMX ) { | ||
1706 | eError = OMXH264VE_SetDynamicParamsToCodec(hComponent); | ||
1707 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1708 | } | ||
1709 | |||
1710 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.generateHeader = XDM_GENERATE_HEADER; | ||
1711 | /* Update the OutBuf details before the Codec Process call */ | ||
1712 | pH264VEComp->pVedEncOutBufs->descs[0].memType = XDM_MEMTYPE_RAW; | ||
1713 | pH264VEComp->pVedEncOutBufs->descs[0].buf = (XDAS_Int8 *)(pH264VEComp->sCodecConfigData.sBuffer); | ||
1714 | pH264VEComp->pVedEncOutBufs->descs[0].bufSize.bytes = SPS_PPS_HEADER_DATA_SIZE; | ||
1715 | |||
1716 | /* Update the InBuf details before the Codec Process call */ | ||
1717 | for( i = 0; i < (OMX_U32)pH264VEComp->pVedEncInBufs->numPlanes; i++ ) { | ||
1718 | pH264VEComp->pVedEncInBufs->planeDesc[i].buf = (XDAS_Int8 *)(pH264VEComp->pTempBuffer[i]); | ||
1719 | pH264VEComp->pVedEncInBufs->planeDesc[i].memType = XDM_MEMTYPE_RAW; | ||
1720 | pH264VEComp->pVedEncInBufs->planeDesc[i].bufSize.bytes = | ||
1721 | (pH264VEComp->pVidEncStatus->videnc2Status.bufInfo.minInBufSize[i].bytes); | ||
1722 | } | ||
1723 | |||
1724 | /* Update the InArgs details before the Codec Process call */ | ||
1725 | pH264VEComp->pVidEncInArgs->videnc2InArgs.size = sizeof(IVIDENC2_InArgs); | ||
1726 | pH264VEComp->pVidEncInArgs->videnc2InArgs.control=IVIDENC2_CTRL_NONE; | ||
1727 | pH264VEComp->pVidEncInArgs->videnc2InArgs.inputID = 1000; /*to overcome the limitation inside the Codec- codec checks for NULL*/ | ||
1728 | |||
1729 | /* Update the OutArgs details before the Codec Process call */ | ||
1730 | pH264VEComp->pVidEncOutArgs->videnc2OutArgs.size = sizeof(IVIDENC2_OutArgs); | ||
1731 | |||
1732 | /* Call the Codec Process call */ | ||
1733 | eError = OMXH264VE_VISAPROCESS_AND_UPDATEPARAMS(hComponent, &retval); | ||
1734 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1735 | |||
1736 | ALOGE("BytesGenerated=%d", (OMX_U32)pH264VEComp->pVidEncOutArgs->videnc2OutArgs.bytesGenerated); | ||
1737 | ALOGE("freed ID=%d", (OMX_U32)pH264VEComp->pVidEncOutArgs->videnc2OutArgs.freeBufID[0]); | ||
1738 | |||
1739 | /* Send the Condec Config Data to the Client */ | ||
1740 | AttrParams.sBuffer = pH264VEComp->sCodecConfigData.sBuffer; | ||
1741 | AttrParams.sBuffer->size = pH264VEComp->pVidEncOutArgs->videnc2OutArgs.bytesGenerated; | ||
1742 | pH264VEComp->sBase.pPvtData->fpDioControl(pComp, OMX_H264VE_OUTPUT_PORT, OMX_DIO_CtrlCmd_SetCtrlAttribute, &AttrParams); | ||
1743 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.generateHeader = XDM_ENCODE_AU; | ||
1744 | |||
1745 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
1746 | pH264VEComp->bSendCodecConfig =OMX_FALSE; | ||
1747 | pH264VEComp->nCodecConfigSize = pH264VEComp->pVidEncOutArgs->videnc2OutArgs.bytesGenerated; | ||
1748 | pH264VEComp->bAfterGenHeader = OMX_TRUE; | ||
1749 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
1750 | |||
1751 | } else { | ||
1752 | goto EXIT; | ||
1753 | } | ||
1754 | } | ||
1755 | |||
1756 | /* check for both input and output */ | ||
1757 | eError=pH264VEComp->sBase.pPvtData->fpDioGetCount(hComponent, OMX_H264VE_INPUT_PORT, (OMX_PTR)&nInMsgCount); | ||
1758 | OMX_CHECK(((eError == OMX_ErrorNone) || (eError == OMX_TI_WarningEosReceived)), OMX_ErrorInsufficientResources); | ||
1759 | |||
1760 | eError=pH264VEComp->sBase.pPvtData->fpDioGetCount(hComponent, OMX_H264VE_OUTPUT_PORT, (OMX_PTR)&nOutMsgCount); | ||
1761 | OMX_CHECK((eError == OMX_ErrorNone), OMX_ErrorInsufficientResources); | ||
1762 | |||
1763 | /* if both are ready-> process data */ | ||
1764 | while(((nInMsgCount > 0) && (nOutMsgCount > 0)) || ((pH264VEComp->bAfterEOSReception) && (nOutMsgCount > 0))) { | ||
1765 | /*dequeue the output buffer*/ | ||
1766 | eError = pH264VEComp->sBase.pPvtData->fpDioDequeue(hComponent, OMX_H264VE_OUTPUT_PORT, (OMX_PTR*)(&pOutBufHeader)); | ||
1767 | OMX_CHECK((eError == OMX_ErrorNone), OMX_ErrorInsufficientResources); | ||
1768 | ((OMXBase_BufHdrPvtData *)(pOutBufHeader->pPlatformPrivate))->bufSt = OWNED_BY_CODEC; | ||
1769 | |||
1770 | /*branch the control flow based on the Before EOS /After EOS processing*/ | ||
1771 | if( !pH264VEComp->bAfterEOSReception ) { | ||
1772 | OSAL_Info("Before EOS reception Case"); | ||
1773 | /*get the free bufhdr from the inputbufhdrarray*/ | ||
1774 | eError = OMXH264VE_GetNextFreeBufHdr(pComp, &InBufferHdrIndex, OMX_H264VE_INPUT_PORT); | ||
1775 | OMX_CHECK(((InBufferHdrIndex != -1) && (eError == OMX_ErrorNone)), OMX_ErrorInsufficientResources); | ||
1776 | |||
1777 | /*dequeue the input buffer*/ | ||
1778 | eError = pH264VEComp->sBase.pPvtData->fpDioDequeue(hComponent, OMX_H264VE_INPUT_PORT, | ||
1779 | (OMX_PTR*)&(pH264VEComp->pCodecInBufferArray[InBufferHdrIndex])); | ||
1780 | OMX_CHECK((eError == OMX_ErrorNone), OMX_ErrorInsufficientResources); | ||
1781 | ((OMXBase_BufHdrPvtData *)(pH264VEComp->pCodecInBufferArray[InBufferHdrIndex]->pPlatformPrivate))->bufSt = OWNED_BY_CODEC; | ||
1782 | |||
1783 | if((pH264VEComp->pCodecInBufferArray[InBufferHdrIndex])->nFlags & OMX_BUFFERFLAG_EOS ) { | ||
1784 | bLEOS = OMX_TRUE; | ||
1785 | pH264VEComp->bPropagateEOSToOutputBuffer = OMX_TRUE; | ||
1786 | bLCodecFlush = OMX_TRUE; | ||
1787 | } | ||
1788 | |||
1789 | if(((pH264VEComp->pCodecInBufferArray[InBufferHdrIndex])->nFilledLen) == 0 ) { | ||
1790 | /*update the buffer status to free & return the buffer to the client*/ | ||
1791 | ((OMXBase_BufHdrPvtData *)(pH264VEComp->pCodecInBufferArray[InBufferHdrIndex]->pPlatformPrivate))->bufSt = OWNED_BY_US; | ||
1792 | |||
1793 | pH264VEComp->sBase.pPvtData->fpDioSend(hComponent, OMX_H264VE_INPUT_PORT, | ||
1794 | (pH264VEComp->pCodecInBufferArray[InBufferHdrIndex])); | ||
1795 | |||
1796 | ((OMXBase_BufHdrPvtData *)(pOutBufHeader->pPlatformPrivate))->bufSt = OWNED_BY_US; | ||
1797 | |||
1798 | pH264VEComp->sBase.pPvtData->fpDioCancel(hComponent, OMX_H264VE_OUTPUT_PORT, pOutBufHeader); | ||
1799 | if( bLEOS ) { | ||
1800 | bLCallCodecProcess = OMX_FALSE; | ||
1801 | } else { | ||
1802 | OSAL_ErrorTrace("++++++++Input Buffer Sent with no DATA & no EOS flag++++++++++++"); | ||
1803 | goto CHECKCOUNT; | ||
1804 | } | ||
1805 | } else { | ||
1806 | /* Update the Input buffer details before the Codec Process call */ | ||
1807 | for( i = 0; i < (OMX_U32)pH264VEComp->pVedEncInBufs->numPlanes; i++ ) { | ||
1808 | if( i == 0 ) { | ||
1809 | if (pH264VEComp->bInputMetaDataBufferMode) { | ||
1810 | OMX_U32 *pTempBuffer; | ||
1811 | OMX_U32 nMetadataBufferType; | ||
1812 | IMG_native_handle_t* pGrallocHandle=NULL; | ||
1813 | pTempBuffer = (OMX_U32 *) (pH264VEComp->pCodecInBufferArray[InBufferHdrIndex]->pBuffer); | ||
1814 | nMetadataBufferType = *pTempBuffer; | ||
1815 | if(nMetadataBufferType == kMetadataBufferTypeGrallocSource){ | ||
1816 | buffer_handle_t tBufHandle; | ||
1817 | pTempBuffer++; | ||
1818 | tBufHandle = *((buffer_handle_t *)pTempBuffer); | ||
1819 | pGrallocHandle = (IMG_native_handle_t*) tBufHandle; | ||
1820 | if (pGrallocHandle->iFormat != HAL_PIXEL_FORMAT_NV12) { | ||
1821 | if (pH264VEComp->pBackupBuffers == NULL) { | ||
1822 | /* Open gralloc allocator and allocate the backup buffers */ | ||
1823 | gralloc_open(pH264VEComp->hCC, &(pH264VEComp->mAllocDev)); | ||
1824 | OMX_CHECK(pH264VEComp->mAllocDev != NULL, OMX_ErrorInsufficientResources); | ||
1825 | |||
1826 | pH264VEComp->pBackupBuffers = (IMG_native_handle_t **)OSAL_Malloc(sizeof(IMG_native_handle_t*) * | ||
1827 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nBufferCountActual); | ||
1828 | OMX_CHECK(pH264VEComp->pBackupBuffers != NULL, OMX_ErrorInsufficientResources); | ||
1829 | |||
1830 | for (j = 0; j < pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nBufferCountActual; j++ ) { | ||
1831 | pH264VEComp->pBackupBuffers[j] = NULL; | ||
1832 | int err = pH264VEComp->mAllocDev->alloc(pH264VEComp->mAllocDev, | ||
1833 | (int) pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nFrameWidth, | ||
1834 | (int) pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nFrameHeight, | ||
1835 | (int) HAL_PIXEL_FORMAT_NV12, (int) GRALLOC_USAGE_HW_RENDER, | ||
1836 | (buffer_handle_t *)(&(pH264VEComp->pBackupBuffers[j])), (int *) &stride); | ||
1837 | OMX_CHECK(err == 0, err); | ||
1838 | |||
1839 | //Get the DMA BUFF_FDs from the gralloc pointers | ||
1840 | pH264VEComp->pCodecInBufferBackupArray[j].sMemHdr[0].dma_buf_fd = (OMX_U32)((pH264VEComp->pBackupBuffers[j])->fd[0]); | ||
1841 | //register this buffer with DRM | ||
1842 | dce_buf_lock(1, (size_t *)&(pH264VEComp->pCodecInBufferBackupArray[j].sMemHdr[0].dma_buf_fd)); | ||
1843 | } | ||
1844 | } | ||
1845 | |||
1846 | /* Invoke color conversion routine here */ | ||
1847 | COLORCONVERT_PlatformOpaqueToNV12(pH264VEComp->hCC, (void **) &pGrallocHandle, | ||
1848 | (void **) &pH264VEComp->pBackupBuffers[InBufferHdrIndex], | ||
1849 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nFrameWidth, | ||
1850 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nFrameHeight, | ||
1851 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nFrameWidth, | ||
1852 | COLORCONVERT_BUFTYPE_GRALLOCOPAQUE, | ||
1853 | COLORCONVERT_BUFTYPE_GRALLOCOPAQUE ); | ||
1854 | |||
1855 | |||
1856 | pH264VEComp->pCodecInBufferBackupArray[InBufferHdrIndex].sMemHdr[0].offset = (pH264VEComp->pCodecInBufferArray[InBufferHdrIndex]->nOffset); | ||
1857 | |||
1858 | pH264VEComp->pVedEncInBufs->planeDesc[i].buf = | ||
1859 | (XDAS_Int8 *)&(pH264VEComp->pCodecInBufferBackupArray[InBufferHdrIndex].sMemHdr[0]); | ||
1860 | |||
1861 | pH264VEComp->pVedEncInBufs->planeDesc[i].memType = XDM_MEMTYPE_TILEDPAGE; | ||
1862 | } | ||
1863 | else { | ||
1864 | pH264VEComp->pCodecInBufferBackupArray[InBufferHdrIndex].sMemHdr[0].dma_buf_fd = (OMX_U32)(pGrallocHandle->fd[0]); | ||
1865 | pH264VEComp->pCodecInBufferBackupArray[InBufferHdrIndex].sMemHdr[0].offset = (pH264VEComp->pCodecInBufferArray[InBufferHdrIndex]->nOffset); | ||
1866 | |||
1867 | pH264VEComp->pVedEncInBufs->planeDesc[i].buf = | ||
1868 | (XDAS_Int8 *)&(pH264VEComp->pCodecInBufferBackupArray[InBufferHdrIndex].sMemHdr[0]); | ||
1869 | |||
1870 | pH264VEComp->pVedEncInBufs->planeDesc[i].memType = XDM_MEMTYPE_TILEDPAGE; | ||
1871 | } | ||
1872 | } | ||
1873 | } else { | ||
1874 | ((OMXBase_BufHdrPvtData *)(pH264VEComp->pCodecInBufferArray[InBufferHdrIndex]->pPlatformPrivate))->sMemHdr[0].offset = (pH264VEComp->pCodecInBufferArray[InBufferHdrIndex]->nOffset); | ||
1875 | |||
1876 | pH264VEComp->pVedEncInBufs->planeDesc[i].buf = (XDAS_Int8 *)&(((OMXBase_BufHdrPvtData *)(pH264VEComp->pCodecInBufferArray[InBufferHdrIndex]->pPlatformPrivate))->sMemHdr[0]); | ||
1877 | |||
1878 | pH264VEComp->pVedEncInBufs->planeDesc[i].memType = XDM_MEMTYPE_RAW; | ||
1879 | } | ||
1880 | pH264VEComp->pVedEncInBufs->imagePitch[0] = pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nStride; | ||
1881 | pH264VEComp->pVedEncInBufs->planeDesc[i].bufSize.bytes = (pH264VEComp->pVedEncInBufs->imagePitch[0]) * (pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nFrameHeight); | ||
1882 | |||
1883 | } else if( i == 1 ) { | ||
1884 | if (pH264VEComp->bInputMetaDataBufferMode) { | ||
1885 | //Nothing to be done; color conversion and fd xlation is done during the plane0 processing | ||
1886 | memcpy(&(pH264VEComp->pCodecInBufferBackupArray[InBufferHdrIndex].sMemHdr[1]), &(pH264VEComp->pCodecInBufferBackupArray[InBufferHdrIndex].sMemHdr[0]), sizeof(MemHeader)); | ||
1887 | |||
1888 | pH264VEComp->pCodecInBufferBackupArray[InBufferHdrIndex].sMemHdr[1].offset = | ||
1889 | ((pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nStride) * | ||
1890 | (pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nFrameHeight)); | ||
1891 | |||
1892 | pH264VEComp->pVedEncInBufs->planeDesc[i].buf = | ||
1893 | (XDAS_Int8 *)&(pH264VEComp->pCodecInBufferBackupArray[InBufferHdrIndex].sMemHdr[1]); | ||
1894 | |||
1895 | pH264VEComp->pVedEncInBufs->planeDesc[i].memType = XDM_MEMTYPE_TILEDPAGE; | ||
1896 | } else { | ||
1897 | memcpy(&((OMXBase_BufHdrPvtData *)(pH264VEComp->pCodecInBufferArray[InBufferHdrIndex]->pPlatformPrivate))->sMemHdr[1], &((OMXBase_BufHdrPvtData *)(pH264VEComp->pCodecInBufferArray[InBufferHdrIndex]->pPlatformPrivate))->sMemHdr[0], sizeof(MemHeader)); | ||
1898 | |||
1899 | ((OMXBase_BufHdrPvtData *)(pH264VEComp->pCodecInBufferArray[InBufferHdrIndex]->pPlatformPrivate))->sMemHdr[1].offset = ((pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nStride) * (pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nFrameHeight)); | ||
1900 | |||
1901 | pH264VEComp->pVedEncInBufs->planeDesc[i].buf = (XDAS_Int8 *)&(((OMXBase_BufHdrPvtData *)(pH264VEComp->pCodecInBufferArray[InBufferHdrIndex]->pPlatformPrivate))->sMemHdr[1]); | ||
1902 | |||
1903 | pH264VEComp->pVedEncInBufs->planeDesc[i].memType = XDM_MEMTYPE_RAW; | ||
1904 | } | ||
1905 | pH264VEComp->pVedEncInBufs->imagePitch[1] = pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nStride; | ||
1906 | pH264VEComp->pVedEncInBufs->planeDesc[i].bufSize.bytes = (pH264VEComp->pVedEncInBufs->imagePitch[1]) * (pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nFrameHeight) / 2; | ||
1907 | |||
1908 | } else { | ||
1909 | eError = OMX_ErrorUnsupportedSetting; | ||
1910 | OSAL_ErrorTrace("only NV12 is supproted currently; wrong param from Codec"); | ||
1911 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1912 | } | ||
1913 | } | ||
1914 | bLCallCodecProcess=OMX_TRUE; | ||
1915 | } | ||
1916 | } else { | ||
1917 | OSAL_Info("After EOS reception Case"); | ||
1918 | eError = OMXH264VE_GetNumCodecLockedBuffers(pComp, &LCodecLockedBufferCount); | ||
1919 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1920 | if( LCodecLockedBufferCount > 0 ) { | ||
1921 | /*After EOS reception No need to provide Input for the Process, hence passing tempbuffers*/ | ||
1922 | for( i = 0; i < (OMX_U32)pH264VEComp->pVedEncInBufs->numPlanes; i++ ) { | ||
1923 | pH264VEComp->pVedEncInBufs->planeDesc[i].buf = (XDAS_Int8 *)(pH264VEComp->pTempBuffer[i]); | ||
1924 | pH264VEComp->pVedEncInBufs->planeDesc[i].memType = XDM_MEMTYPE_RAW; | ||
1925 | pH264VEComp->pVedEncInBufs->planeDesc[i].bufSize.bytes = | ||
1926 | (pH264VEComp->pVidEncStatus->videnc2Status.bufInfo.minInBufSize[i].bytes); | ||
1927 | } | ||
1928 | bLCallCodecProcess=OMX_TRUE; | ||
1929 | } else { | ||
1930 | /*Update the OutBufHeader*/ | ||
1931 | pOutBufHeader->nOffset = 0; | ||
1932 | pOutBufHeader->nFilledLen = 0; | ||
1933 | pOutBufHeader->nFlags |= OMX_BUFFERFLAG_EOS; | ||
1934 | pH264VEComp->sBase.pPvtData->fpDioSend(hComponent, OMX_H264VE_OUTPUT_PORT, pOutBufHeader); | ||
1935 | pH264VEComp->bPropagateEOSToOutputBuffer = OMX_FALSE; | ||
1936 | /*notify the EOSEvent to the client*/ | ||
1937 | pH264VEComp->bNotifyEOSEventToClient = OMX_TRUE; | ||
1938 | bLCallCodecProcess = OMX_FALSE; | ||
1939 | } | ||
1940 | } | ||
1941 | if( bLCallCodecProcess ) { | ||
1942 | if( !pH264VEComp->bAfterEOSReception ) { | ||
1943 | OSAL_Info("update the Dynamic params before Process"); | ||
1944 | /* Call to xDM Set Params depending on the pH264VEComp->bCallxDMSetParams flag status before the process call */ | ||
1945 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
1946 | bLCallxDMSetParams = pH264VEComp->bCallxDMSetParams; | ||
1947 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
1948 | if( bLCallxDMSetParams == PARAMS_UPDATED_AT_OMX ) { | ||
1949 | eError = OMXH264VE_SetDynamicParamsToCodec(hComponent); | ||
1950 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1951 | } | ||
1952 | } | ||
1953 | /* Update the Output buffer details before the Codec Process call */ | ||
1954 | OSAL_Info("Update the Output buffer details before the Codec Process call"); | ||
1955 | /*Note: this implementation assumes | ||
1956 | a) output buffer is always 1D | ||
1957 | b) if in case of multiple output buffers that need to given to codec for each process call | ||
1958 | they are allocated in contiguous memory | ||
1959 | */ | ||
1960 | if( pH264VEComp->pVedEncOutBufs->numBufs != 1 ) { | ||
1961 | eError = OMX_ErrorUnsupportedSetting; | ||
1962 | OSAL_ErrorTrace("Encoder Output Buffer is assigned as 2D Buffer"); | ||
1963 | goto EXIT; | ||
1964 | } | ||
1965 | |||
1966 | pH264VEComp->pVedEncOutBufs->descs[0].buf = | ||
1967 | (XDAS_Int8 *)&(((OMXBase_BufHdrPvtData*)pOutBufHeader->pPlatformPrivate)->sMemHdr[0]); | ||
1968 | |||
1969 | pH264VEComp->pVedEncOutBufs->descs[0].bufSize.bytes = pOutBufHeader->nAllocLen; | ||
1970 | |||
1971 | /* Update the InArgs details before the Codec Process call */ | ||
1972 | OSAL_Info("Update the InArgs before the Codec Process call"); | ||
1973 | pH264VEComp->pVidEncInArgs->videnc2InArgs.size = sizeof(IH264ENC_InArgs); | ||
1974 | pH264VEComp->pVidEncInArgs->videnc2InArgs.control = IVIDENC2_CTRL_NONE; | ||
1975 | |||
1976 | if( !pH264VEComp->bAfterEOSReception ) { | ||
1977 | pH264VEComp->pVidEncInArgs->videnc2InArgs.inputID = InBufferHdrIndex + 1; | ||
1978 | /*Zero is not a valid input so increasing the bufferIndex value by 1*/ | ||
1979 | } else { | ||
1980 | pH264VEComp->pVidEncInArgs->videnc2InArgs.inputID = 0; /*Zero is not a valid input */ | ||
1981 | } | ||
1982 | |||
1983 | pH264VEComp->pVidEncOutArgs->videnc2OutArgs.freeBufID[0] = 0; | ||
1984 | /* Update the OutArgs details before the Codec Process call */ | ||
1985 | OSAL_Info("Update the OutArgs before the Codec Process call"); | ||
1986 | pH264VEComp->pVidEncOutArgs->videnc2OutArgs.size = sizeof(IVIDENC2_OutArgs); | ||
1987 | |||
1988 | /* Codec Process call */ | ||
1989 | eError = OMXH264VE_VISAPROCESS_AND_UPDATEPARAMS(hComponent, &retval); | ||
1990 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
1991 | |||
1992 | /* Send the input & corresponding output buffers Back to the Client when the codec frees */ | ||
1993 | /*Note: implementation is based on | ||
1994 | a) after every process, there will be at max one input buffer that can be freed | ||
1995 | b)for every input buffer that is freed ......there will be corresponding o/p buffer | ||
1996 | */ | ||
1997 | if( pH264VEComp->pVidEncOutArgs->videnc2OutArgs.freeBufID[0]) { | ||
1998 | /*Non Zero ID : valid free buffer ID*/ | ||
1999 | ALOGE("Codec freed input buffer with ID =%d", (OMX_U32)pH264VEComp->pVidEncOutArgs->videnc2OutArgs.freeBufID[0]); | ||
2000 | |||
2001 | /* Propagate the Time Stamps from input to Corresponding Output */ | ||
2002 | OSAL_Info("Propagate the timestamp"); | ||
2003 | pOutBufHeader->nTimeStamp = | ||
2004 | (pH264VEComp->pCodecInBufferArray[(pH264VEComp->pVidEncOutArgs->videnc2OutArgs.freeBufID[0] - 1)])->nTimeStamp; | ||
2005 | |||
2006 | /* Send the input buffers Back to the Client */ | ||
2007 | pH264VEComp->pCodecInBufferArray[(pH264VEComp->pVidEncOutArgs->videnc2OutArgs.freeBufID[0] - 1)]->nFilledLen = 0; | ||
2008 | /*Completely Consumed*/ | ||
2009 | pH264VEComp->pCodecInBufferArray[(pH264VEComp->pVidEncOutArgs->videnc2OutArgs.freeBufID[0] - 1)]->nOffset = 0; | ||
2010 | |||
2011 | ((OMXBase_BufHdrPvtData *)((pH264VEComp->pCodecInBufferArray[(pH264VEComp->pVidEncOutArgs->videnc2OutArgs.freeBufID[0] - 1)])->pPlatformPrivate))->bufSt = OWNED_BY_US; | ||
2012 | |||
2013 | pH264VEComp->sBase.pPvtData->fpDioSend(hComponent, OMX_H264VE_INPUT_PORT, | ||
2014 | pH264VEComp->pCodecInBufferArray[(pH264VEComp->pVidEncOutArgs->videnc2OutArgs.freeBufID[0] - 1)]); | ||
2015 | /*check for the EOS */ | ||
2016 | if( pH264VEComp->bPropagateEOSToOutputBuffer ) { | ||
2017 | /*Send the Output with EOS after sending all the previous buffers*/ | ||
2018 | eError = OMXH264VE_GetNumCodecLockedBuffers(pComp, &LCodecLockedBufferCount); | ||
2019 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
2020 | if(LCodecLockedBufferCount == 0) { | ||
2021 | /*No locked buffers*/ | ||
2022 | pOutBufHeader->nFlags |= OMX_BUFFERFLAG_EOS; | ||
2023 | pH264VEComp->bPropagateEOSToOutputBuffer = OMX_FALSE; | ||
2024 | } | ||
2025 | } | ||
2026 | |||
2027 | /* Check for IDR frame & update the Output BufferHdr Flags */ | ||
2028 | if(((pH264VEComp->pVidEncOutArgs->videnc2OutArgs.encodedFrameType) == IVIDEO_IDR_FRAME) || | ||
2029 | ((pH264VEComp->pVidEncOutArgs->videnc2OutArgs.encodedFrameType) == IVIDEO_I_FRAME)) { | ||
2030 | pOutBufHeader->nFlags |= OMX_BUFFERFLAG_SYNCFRAME; | ||
2031 | } | ||
2032 | |||
2033 | /* Send the output buffers Back to the Client */ | ||
2034 | OSAL_Info("Send the output buffers Back to the Client"); | ||
2035 | /*Update the OutBufHeader*/ | ||
2036 | if( pH264VEComp->bAfterGenHeader ) { | ||
2037 | pOutBufHeader->nOffset = pH264VEComp->nCodecConfigSize; | ||
2038 | pOutBufHeader->nFilledLen = ((pH264VEComp->pVidEncOutArgs->videnc2OutArgs.bytesGenerated) - | ||
2039 | (pH264VEComp->nCodecConfigSize)); | ||
2040 | pH264VEComp->bAfterGenHeader = OMX_FALSE; | ||
2041 | pH264VEComp->nCodecConfigSize = 0; | ||
2042 | } else { | ||
2043 | pOutBufHeader->nOffset = 0; | ||
2044 | pOutBufHeader->nFilledLen = pH264VEComp->pVidEncOutArgs->videnc2OutArgs.bytesGenerated; | ||
2045 | } | ||
2046 | /* Return this output buffer to the Base comp via ReturnDataNotify call | ||
2047 | * to communciate with the IL client incase of Non-Tunneling or tunneled | ||
2048 | * component in case of tunneling*/ | ||
2049 | ((OMXBase_BufHdrPvtData *)(pOutBufHeader->pPlatformPrivate))->bufSt = OWNED_BY_US; | ||
2050 | pH264VEComp->sBase.pPvtData->fpDioSend(hComponent, OMX_H264VE_OUTPUT_PORT, pOutBufHeader); | ||
2051 | } else { | ||
2052 | if( pH264VEComp->pVidEncOutArgs->videnc2OutArgs.bytesGenerated == 0 ) { | ||
2053 | /*free ID ==0 so no inputbuffer is freed & thus no o/p should be generated*/ | ||
2054 | OSAL_Info("codec locked the buffer so do the DIO_Cancel for the outputbuffer"); | ||
2055 | OSAL_Info("bytes generated is Zero & retain the output buffers via DIO_Cancel"); | ||
2056 | ((OMXBase_BufHdrPvtData *)(pOutBufHeader->pPlatformPrivate))->bufSt = OWNED_BY_US; | ||
2057 | pH264VEComp->sBase.pPvtData->fpDioCancel(hComponent, OMX_H264VE_OUTPUT_PORT, pOutBufHeader); | ||
2058 | } else { | ||
2059 | if((!pH264VEComp->bAfterEOSReception) || | ||
2060 | ((pH264VEComp->pVidEncStaticParams->nalUnitControlParams.naluPresentMaskEndOfSequence) == 0x0)) { | ||
2061 | OSAL_ErrorTrace("***********something gone wrong***********"); | ||
2062 | goto EXIT; | ||
2063 | } | ||
2064 | /* Send the output buffers Back to the Client */ | ||
2065 | OSAL_Info("Send the output buffers Back to the Client"); | ||
2066 | /*Update the OutBufHeader*/ | ||
2067 | pOutBufHeader->nOffset = 0; | ||
2068 | pOutBufHeader->nFilledLen = pH264VEComp->pVidEncOutArgs->videnc2OutArgs.bytesGenerated; | ||
2069 | pOutBufHeader->nFlags |= OMX_BUFFERFLAG_EOS; | ||
2070 | pH264VEComp->bPropagateEOSToOutputBuffer = OMX_FALSE; | ||
2071 | /*notify the EOSEvent to the client*/ | ||
2072 | pH264VEComp->bNotifyEOSEventToClient = OMX_TRUE; | ||
2073 | /* Return this output buffer to the Base comp via ReturnDataNotify call | ||
2074 | * to communciate with the IL client incase of Non-Tunneling or tunneled | ||
2075 | * component in case of tunneling*/ | ||
2076 | ((OMXBase_BufHdrPvtData *)(pOutBufHeader->pPlatformPrivate))->bufSt = OWNED_BY_US; | ||
2077 | pH264VEComp->sBase.pPvtData->fpDioSend(hComponent, OMX_H264VE_OUTPUT_PORT, pOutBufHeader); | ||
2078 | } | ||
2079 | } | ||
2080 | } | ||
2081 | /*Call to xDM_FLUSH when Input with EOS flag has been received*/ | ||
2082 | if( bLCodecFlush ) { | ||
2083 | /*control call with command XDM_FLUSH*/ | ||
2084 | OSAL_Info("Call CodecFlush "); | ||
2085 | eError = OMXH264VE_VISACONTROL(pH264VEComp->pVidEncHandle, XDM_FLUSH, | ||
2086 | (VIDENC2_DynamicParams *)(pH264VEComp->pVidEncDynamicParams), | ||
2087 | (IVIDENC2_Status *)(pH264VEComp->pVidEncStatus), hComponent, &retval); | ||
2088 | if( retval == VIDENC2_EFAIL ) { | ||
2089 | OSAL_ErrorTrace("Got error from the CodecControl call"); | ||
2090 | OMX_TI_GET_ERROR(pH264VEComp, pH264VEComp->pVidEncStatus->videnc2Status.extendedError, eError); | ||
2091 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
2092 | } | ||
2093 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
2094 | /*Set the bCodecFlush to True ....no need to call codec flush during idle->Loaded Transition*/ | ||
2095 | pH264VEComp->bCodecFlush = OMX_TRUE; | ||
2096 | bLEOS= OMX_FALSE; | ||
2097 | bLCodecFlush = OMX_FALSE; | ||
2098 | /* after EOS no need to provide extra input buffer */ | ||
2099 | pH264VEComp->bAfterEOSReception = OMX_TRUE; | ||
2100 | } | ||
2101 | if( pH264VEComp->bNotifyEOSEventToClient ) { | ||
2102 | /* Reset the Codec : to continue with New stream w/o codec create */ | ||
2103 | if( pH264VEComp->bCodecCreate ) { | ||
2104 | /*Codec Call: control call with command XDM_RESET*/ | ||
2105 | eError = OMXH264VE_VISACONTROL(pH264VEComp->pVidEncHandle, XDM_RESET, | ||
2106 | (VIDENC2_DynamicParams *)(pH264VEComp->pVidEncDynamicParams), | ||
2107 | (IVIDENC2_Status *)(pH264VEComp->pVidEncStatus), hComponent, &retval); | ||
2108 | if( retval != VIDENC2_EOK ) { | ||
2109 | OSAL_ErrorTrace("Got error from the Codec_RESET call"); | ||
2110 | OMX_TI_GET_ERROR(pH264VEComp, pH264VEComp->pVidEncStatus->videnc2Status.extendedError, eError); | ||
2111 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
2112 | } | ||
2113 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
2114 | } | ||
2115 | /* Notify EOS event flag to the Base Component via ReturnEventNotify | ||
2116 | * call , which communciates with the IL Client */ | ||
2117 | pH264VEComp->sBase.fpReturnEventNotify(hComponent, OMX_EventBufferFlag, | ||
2118 | OMX_H264VE_OUTPUT_PORT, | ||
2119 | OMX_BUFFERFLAG_EOS, NULL); | ||
2120 | /*reset the flags*/ | ||
2121 | pH264VEComp->bAfterEOSReception = OMX_FALSE; | ||
2122 | pH264VEComp->bNotifyEOSEventToClient = OMX_FALSE; | ||
2123 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.generateHeader = XDM_GENERATE_HEADER; | ||
2124 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
2125 | pH264VEComp->bSendCodecConfig = OMX_TRUE; | ||
2126 | pH264VEComp->bCallxDMSetParams = PARAMS_UPDATED_AT_OMX; | ||
2127 | pH264VEComp->nCodecConfigSize = 0; | ||
2128 | pH264VEComp->bAfterGenHeader = OMX_FALSE; | ||
2129 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
2130 | goto EXIT; | ||
2131 | } | ||
2132 | |||
2133 | CHECKCOUNT: | ||
2134 | /*get the buffer count for the next loop execution*/ | ||
2135 | pH264VEComp->sBase.pPvtData->fpDioGetCount(hComponent, OMX_H264VE_INPUT_PORT, (OMX_PTR)&nInMsgCount); | ||
2136 | pH264VEComp->sBase.pPvtData->fpDioGetCount(hComponent, OMX_H264VE_OUTPUT_PORT, (OMX_PTR)&nOutMsgCount); | ||
2137 | ALOGE("Input Msg Count=%d, Output Msg Count=%d for the Next process loop", nInMsgCount, nOutMsgCount); | ||
2138 | } /*end of process call loop*/ | ||
2139 | } else { | ||
2140 | OSAL_WarningTrace("!!!!!!!!!!!Incorrect State operation/ ports need to be enabled!!!!!!!!"); | ||
2141 | } | ||
2142 | |||
2143 | EXIT: | ||
2144 | |||
2145 | return (eError); | ||
2146 | |||
2147 | } | ||
2148 | |||
2149 | static OMX_ERRORTYPE OMXH264VE_ComponentDeinit(OMX_HANDLETYPE hComponent) | ||
2150 | { | ||
2151 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
2152 | OMX_COMPONENTTYPE *pComp = NULL; | ||
2153 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
2154 | // OMX_U32 i; | ||
2155 | |||
2156 | |||
2157 | /* Check the input parameters */ | ||
2158 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
2159 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
2160 | pH264VEComp = (OMXH264VidEncComp *)pComp->pComponentPrivate; | ||
2161 | |||
2162 | OMXBase_UtilCleanupIfError(hComponent); | ||
2163 | |||
2164 | |||
2165 | if( pH264VEComp->sBase.cComponentName ) { | ||
2166 | OSAL_Free(pH264VEComp->sBase.cComponentName); | ||
2167 | pH264VEComp->sBase.cComponentName = NULL; | ||
2168 | } | ||
2169 | |||
2170 | /* Calling OMX Base Component Deinit */ | ||
2171 | OSAL_Info("Call BaseComponent Deinit"); | ||
2172 | eError = OMXBase_ComponentDeinit(hComponent); | ||
2173 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
2174 | /*Allocating memory for port properties before calling SetDefaultProperties*/ | ||
2175 | OSAL_Info("DeInitialize DerToBase.PortProperties"); | ||
2176 | |||
2177 | pH264VEComp->bInputMetaDataBufferMode = OMX_FALSE; | ||
2178 | |||
2179 | /*Add CE deinit related stuff here*/ | ||
2180 | if( pH264VEComp->pCEhandle ) { | ||
2181 | OSAL_Info("Call Engine_Close"); | ||
2182 | Engine_close(pH264VEComp->pCEhandle); | ||
2183 | } | ||
2184 | |||
2185 | /* Free up the H264VE component's private area */ | ||
2186 | OSAL_Free(pH264VEComp->sBase.pAudioPortParams); | ||
2187 | OSAL_Free(pH264VEComp->sBase.pVideoPortParams); | ||
2188 | OSAL_Free(pH264VEComp->sBase.pImagePortParams); | ||
2189 | OSAL_Free(pH264VEComp->sBase.pOtherPortParams); | ||
2190 | memplugin_free_noheader(pH264VEComp->sCodecConfigData.sBuffer); | ||
2191 | memplugin_free_noheader(pH264VEComp->pTempBuffer[0]); | ||
2192 | memplugin_free_noheader(pH264VEComp->pTempBuffer[1]); | ||
2193 | memplugin_free(pH264VEComp->pVedEncOutBufs); | ||
2194 | memplugin_free(pH264VEComp->pVedEncInBufs); | ||
2195 | memplugin_free(pH264VEComp->pVidEncOutArgs); | ||
2196 | memplugin_free(pH264VEComp->pVidEncInArgs); | ||
2197 | memplugin_free(pH264VEComp->pVidEncStatus); | ||
2198 | memplugin_free(pH264VEComp->pVidEncDynamicParams); | ||
2199 | memplugin_free(pH264VEComp->pVidEncStaticParams); | ||
2200 | |||
2201 | OSAL_Free(pH264VEComp); | ||
2202 | pH264VEComp = NULL; | ||
2203 | |||
2204 | EXIT: | ||
2205 | OSAL_Info("At the End of Component DeInit"); | ||
2206 | return (eError); | ||
2207 | } | ||
2208 | |||
2209 | |||
2210 | OMX_ERRORTYPE OMXH264VE_GetExtensionIndex(OMX_HANDLETYPE hComponent, | ||
2211 | OMX_STRING cParameterName, | ||
2212 | OMX_INDEXTYPE *pIndexType) | ||
2213 | { | ||
2214 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
2215 | OMX_COMPONENTTYPE *pComp; | ||
2216 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
2217 | |||
2218 | /* Check the input parameters */ | ||
2219 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
2220 | |||
2221 | pComp = (OMX_COMPONENTTYPE *)hComponent; | ||
2222 | pH264VEComp = (OMXH264VidEncComp *)pComp->pComponentPrivate; | ||
2223 | |||
2224 | OMX_CHECK(pH264VEComp != NULL, OMX_ErrorBadParameter); | ||
2225 | |||
2226 | OMX_CHECK(cParameterName != NULL, OMX_ErrorBadParameter); | ||
2227 | OMX_CHECK(pIndexType != NULL, OMX_ErrorBadParameter); | ||
2228 | if( pH264VEComp->sBase.tCurState == OMX_StateInvalid ) { | ||
2229 | eError = OMX_ErrorInvalidState; | ||
2230 | goto EXIT; | ||
2231 | } | ||
2232 | if( strlen(cParameterName) > 127 ) { | ||
2233 | //strlen does not include �\0� size, hence 127 | ||
2234 | eError = OMX_ErrorBadParameter; | ||
2235 | goto EXIT; | ||
2236 | } | ||
2237 | |||
2238 | if(strcmp(cParameterName, "OMX.google.android.index.storeMetaDataInBuffers") == 0) { | ||
2239 | *pIndexType = (OMX_INDEXTYPE) OMX_TI_IndexEncoderReceiveMetadataBuffers; | ||
2240 | goto EXIT; | ||
2241 | } else if( strcmp(cParameterName, "OMX.google.android.index.describeColorFormat") == 0 ) { | ||
2242 | // If Index type is Time Stamp In Decode Order | ||
2243 | *pIndexType = (OMX_INDEXTYPE) OMX_TI_IndexDescribeColorFormat; | ||
2244 | goto EXIT; | ||
2245 | } | ||
2246 | |||
2247 | eError = OMX_ErrorUnsupportedIndex; | ||
2248 | |||
2249 | EXIT: | ||
2250 | return (eError); | ||
2251 | } | ||
2252 | |||
2253 | |||
2254 | static OMX_ERRORTYPE OMXH264VE_ComponentTunnelRequest(OMX_HANDLETYPE hComponent, | ||
2255 | OMX_U32 nPort, | ||
2256 | OMX_HANDLETYPE hTunneledComp, | ||
2257 | OMX_U32 nTunneledPort, | ||
2258 | OMX_TUNNELSETUPTYPE *pTunnelSetup) | ||
2259 | { | ||
2260 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
2261 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
2262 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
2263 | (void)nPort; | ||
2264 | (void)hTunneledComp; | ||
2265 | (void)nTunneledPort; | ||
2266 | (void)pTunnelSetup; | ||
2267 | |||
2268 | /* Check all the input parametrs */ | ||
2269 | OMX_CHECK((hComponent != NULL), OMX_ErrorBadParameter); | ||
2270 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
2271 | pH264VEComp = (OMXH264VidEncComp *)pHandle->pComponentPrivate; | ||
2272 | OMX_CHECK((pH264VEComp != NULL), OMX_ErrorBadParameter); | ||
2273 | |||
2274 | eError = OMX_ErrorNotImplemented; | ||
2275 | OSAL_ErrorTrace("in omx-h264e ComponentTunnelRequest :: enable input subframe processing first"); | ||
2276 | OMX_CHECK(OMX_ErrorNone == eError, eError); | ||
2277 | |||
2278 | EXIT: | ||
2279 | return (eError); | ||
2280 | } | ||
2281 | |||
2282 | |||
diff --git a/libstagefrighthw/omx/videoencode/omx_video_encoder_h264.h b/libstagefrighthw/omx/videoencode/omx_video_encoder_h264.h new file mode 100644 index 0000000..9e1e892 --- /dev/null +++ b/libstagefrighthw/omx/videoencode/omx_video_encoder_h264.h | |||
@@ -0,0 +1,185 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 _OMX_H264VE_COMPONENT_H | ||
18 | #define _OMX_H264VE_COMPONENT_H | ||
19 | |||
20 | #ifdef _cplusplus | ||
21 | extern "C" { | ||
22 | #endif /* _cplusplus */ | ||
23 | |||
24 | #include <cutils/native_handle.h> | ||
25 | #include <hal_public.h> | ||
26 | |||
27 | #include "omx_video_encoder_h264_utils.h" | ||
28 | |||
29 | #define OMX_VIDENC_NUM_PORTS (2) | ||
30 | |||
31 | #define OMX_ENGINE_NAME "ivahd_vidsvr" | ||
32 | |||
33 | typedef struct OMX_H264_LVL_BITRATE { | ||
34 | OMX_VIDEO_AVCLEVELTYPE eLevel; | ||
35 | OMX_U32 nMaxBitRateSupport; | ||
36 | }OMX_H264_LVL_BITRATE; | ||
37 | |||
38 | typedef struct OMX_MetaDataBuffer { | ||
39 | int type; | ||
40 | void *handle; | ||
41 | //int offset; | ||
42 | }OMX_MetaDataBuffer; | ||
43 | |||
44 | typedef struct OMX_StoreMetaDataInBuffersParams { | ||
45 | OMX_U32 nSize; | ||
46 | OMX_VERSIONTYPE nVersion; | ||
47 | OMX_U32 nPortIndex; | ||
48 | OMX_BOOL bStoreMetaData; | ||
49 | }OMX_StoreMetaDataInBuffersParams; | ||
50 | |||
51 | |||
52 | /*Android Data structures*/ | ||
53 | |||
54 | enum Type { | ||
55 | MEDIA_IMAGE_TYPE_UNKNOWN = 0, | ||
56 | MEDIA_IMAGE_TYPE_YUV, | ||
57 | }; | ||
58 | |||
59 | enum PlaneIndex { | ||
60 | Y = 0, | ||
61 | U, | ||
62 | V, | ||
63 | MAX_NUM_PLANES | ||
64 | }; | ||
65 | |||
66 | typedef struct PlaneInfo { | ||
67 | uint32_t mOffset; // offset of first pixel of the plane in bytes | ||
68 | // from buffer offset | ||
69 | uint32_t mColInc; // column increment in bytes | ||
70 | uint32_t mRowInc; // row increment in bytes | ||
71 | uint32_t mHorizSubsampling; // subsampling compared to the largest plane | ||
72 | uint32_t mVertSubsampling; // subsampling compared to the largest plane | ||
73 | }PlaneInfo; | ||
74 | |||
75 | // Structure describing a media image (frame) | ||
76 | // Currently only supporting YUV | ||
77 | typedef struct MediaImage { | ||
78 | int mType; | ||
79 | uint32_t mNumPlanes; // number of planes | ||
80 | uint32_t mWidth; // width of largest plane (unpadded, as in nFrameWidth) | ||
81 | uint32_t mHeight; // height of largest plane (unpadded, as in nFrameHeight) | ||
82 | uint32_t mBitDepth; // useable bit depth | ||
83 | PlaneInfo mPlane[MAX_NUM_PLANES]; | ||
84 | }MediaImage; | ||
85 | |||
86 | // A pointer to this struct is passed to OMX_GetParameter when the extension | ||
87 | // index for the 'OMX.google.android.index.describeColorFormat' | ||
88 | // extension is given. This method can be called from any component state | ||
89 | // other than invalid. The color-format, frame width/height, and stride/ | ||
90 | // slice-height parameters are ones that are associated with a raw video | ||
91 | // port (input or output), but the stride/slice height parameters may be | ||
92 | // incorrect. bUsingNativeBuffers is OMX_TRUE if native android buffers will | ||
93 | // be used (while specifying this color format). | ||
94 | // | ||
95 | // The component shall fill out the MediaImage structure that | ||
96 | // corresponds to the described raw video format, and the potentially corrected | ||
97 | // stride and slice-height info. | ||
98 | // | ||
99 | // The behavior is slightly different if bUsingNativeBuffers is OMX_TRUE, | ||
100 | // though most implementations can ignore this difference. When using native buffers, | ||
101 | // the component may change the configured color format to an optimized format. | ||
102 | // Additionally, when allocating these buffers for flexible usecase, the framework | ||
103 | // will set the SW_READ/WRITE_OFTEN usage flags. In this case (if bUsingNativeBuffers | ||
104 | // is OMX_TRUE), the component shall fill out the MediaImage information for the | ||
105 | // scenario when these SW-readable/writable buffers are locked using gralloc_lock. | ||
106 | // Note, that these buffers may also be locked using gralloc_lock_ycbcr, which must | ||
107 | // be supported for vendor-specific formats. | ||
108 | // | ||
109 | // For non-YUV packed planar/semiplanar image formats, or if bUsingNativeBuffers | ||
110 | // is OMX_TRUE and the component does not support this color format with native | ||
111 | // buffers, the component shall set mNumPlanes to 0, and mType to MEDIA_IMAGE_TYPE_UNKNOWN. | ||
112 | typedef struct DescribeColorFormatParams { | ||
113 | OMX_U32 nSize; | ||
114 | OMX_VERSIONTYPE nVersion; | ||
115 | // input: parameters from OMX_VIDEO_PORTDEFINITIONTYPE | ||
116 | OMX_COLOR_FORMATTYPE eColorFormat; | ||
117 | OMX_U32 nFrameWidth; | ||
118 | OMX_U32 nFrameHeight; | ||
119 | OMX_U32 nStride; | ||
120 | OMX_U32 nSliceHeight; | ||
121 | OMX_BOOL bUsingNativeBuffers; | ||
122 | |||
123 | // output: fill out the MediaImage fields | ||
124 | MediaImage sMediaImage; | ||
125 | }DescribeColorFormatParams; | ||
126 | |||
127 | |||
128 | /* OMX H264 Encoder Component */ | ||
129 | typedef struct OMXH264VideoEncoderComponent { | ||
130 | /* base component handle */ | ||
131 | OMXBaseComp sBase; | ||
132 | |||
133 | /* codec and engine handles */ | ||
134 | Engine_Handle pCEhandle; | ||
135 | Engine_Error tCEerror; | ||
136 | VIDENC2_Handle pVidEncHandle; | ||
137 | OMX_BOOL bCodecCreate; | ||
138 | OMX_BOOL bCodecCreateSettingsChange; | ||
139 | |||
140 | /* Encoder static/dynamic/buf args */ | ||
141 | IH264ENC_Params *pVidEncStaticParams; | ||
142 | IH264ENC_DynamicParams *pVidEncDynamicParams; | ||
143 | IH264ENC_Status *pVidEncStatus; | ||
144 | IH264ENC_InArgs *pVidEncInArgs; | ||
145 | IH264ENC_OutArgs *pVidEncOutArgs; | ||
146 | IVIDEO2_BufDesc *pVedEncInBufs; | ||
147 | XDM2_BufDesc *pVedEncOutBufs; | ||
148 | |||
149 | /* omx component statemachine variables */ | ||
150 | OMX_BOOL bInputPortDisable; | ||
151 | OMX_BOOL bCodecFlush; | ||
152 | PARAMS_UPDATE_STATUS bCallxDMSetParams; | ||
153 | OMX_BOOL bAfterEOSReception; | ||
154 | OMX_BOOL bNotifyEOSEventToClient; | ||
155 | OMX_BOOL bPropagateEOSToOutputBuffer; | ||
156 | OMX_BOOL bSetParamInputIsDone; | ||
157 | |||
158 | /* codec config handling variables*/ | ||
159 | OMXBase_CodecConfigBuf sCodecConfigData; | ||
160 | OMX_BOOL bSendCodecConfig; | ||
161 | OMX_U32 nCodecConfigSize; | ||
162 | OMX_BOOL bAfterGenHeader; | ||
163 | |||
164 | /* internal buffer tracking arrays */ | ||
165 | OMX_BUFFERHEADERTYPE **pCodecInBufferArray; | ||
166 | OMXBase_BufHdrPvtData *pCodecInBufferBackupArray; | ||
167 | |||
168 | /* temporary memory to meet and codec and dce requirements */ | ||
169 | MemHeader *pTempBuffer[2]; | ||
170 | |||
171 | OMX_BOOL bInputMetaDataBufferMode; | ||
172 | OMX_PTR hCC; | ||
173 | IMG_native_handle_t **pBackupBuffers; | ||
174 | alloc_device_t *mAllocDev; | ||
175 | |||
176 | } OMXH264VidEncComp; | ||
177 | |||
178 | OMX_ERRORTYPE OMXH264VE_ComponentInit(OMX_HANDLETYPE hComponent); | ||
179 | |||
180 | #ifdef _cplusplus | ||
181 | } | ||
182 | #endif /* __cplusplus */ | ||
183 | |||
184 | #endif /* _OMX_H264VE_COMPONENT_H */ | ||
185 | |||
diff --git a/libstagefrighthw/omx/videoencode/omx_video_encoder_h264_utils.c b/libstagefrighthw/omx/videoencode/omx_video_encoder_h264_utils.c new file mode 100644 index 0000000..3094f6b --- /dev/null +++ b/libstagefrighthw/omx/videoencode/omx_video_encoder_h264_utils.c | |||
@@ -0,0 +1,989 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 | #define LOG_TAG "OMX_H264_ENCODERUTILS" | ||
18 | |||
19 | #include "omx_video_encoder_h264.h" | ||
20 | |||
21 | OMX_H264_LVL_BITRATE OMX_H264_BP_MP_BITRATE_SUPPORT[] = | ||
22 | { | ||
23 | { OMX_VIDEO_AVCLevel1, 64000 }, | ||
24 | { OMX_VIDEO_AVCLevel1b, 128000 }, | ||
25 | { OMX_VIDEO_AVCLevel11, 192000 }, | ||
26 | { OMX_VIDEO_AVCLevel12, 384000 }, | ||
27 | { OMX_VIDEO_AVCLevel13, 768000 }, | ||
28 | { OMX_VIDEO_AVCLevel2, 2000000 }, | ||
29 | { OMX_VIDEO_AVCLevel21, 4000000 }, | ||
30 | { OMX_VIDEO_AVCLevel22, 4000000 }, | ||
31 | { OMX_VIDEO_AVCLevel3, 10000000 }, | ||
32 | { OMX_VIDEO_AVCLevel31, 14000000 }, | ||
33 | { OMX_VIDEO_AVCLevel32, 20000000 }, | ||
34 | { OMX_VIDEO_AVCLevel4, 20000000 }, | ||
35 | { OMX_VIDEO_AVCLevel41, 50000000 }, | ||
36 | { OMX_VIDEO_AVCLevel42, 50000000 }, | ||
37 | { OMX_VIDEO_AVCLevel5, 50000000 }, //according to the spec the bit rate supported is 135000000, here the 50mpbs limit is as per the current codec version | ||
38 | { OMX_VIDEO_AVCLevel51, 50000000 } //according to the spec the bit rate supported is 240000000, here the 50mpbs limit is as per the current codec version | ||
39 | }; | ||
40 | |||
41 | OMX_H264_LVL_BITRATE OMX_H264_HP_BITRATE_SUPPORT[] = | ||
42 | { | ||
43 | { OMX_VIDEO_AVCLevel1, 80000 }, | ||
44 | { OMX_VIDEO_AVCLevel1b, 160000 }, | ||
45 | { OMX_VIDEO_AVCLevel11, 240000 }, | ||
46 | { OMX_VIDEO_AVCLevel12, 480000 }, | ||
47 | { OMX_VIDEO_AVCLevel13, 960000 }, | ||
48 | { OMX_VIDEO_AVCLevel2, 2500000 }, | ||
49 | { OMX_VIDEO_AVCLevel21, 5000000 }, | ||
50 | { OMX_VIDEO_AVCLevel22, 5000000 }, | ||
51 | { OMX_VIDEO_AVCLevel3, 12500000 }, | ||
52 | { OMX_VIDEO_AVCLevel31, 17500000 }, | ||
53 | { OMX_VIDEO_AVCLevel32, 25000000 }, | ||
54 | { OMX_VIDEO_AVCLevel4, 25000000 }, | ||
55 | { OMX_VIDEO_AVCLevel41, 62500000 }, | ||
56 | { OMX_VIDEO_AVCLevel42, 62500000 }, | ||
57 | { OMX_VIDEO_AVCLevel5, 62500000 }, //according to the spec the bit rate supported is 168750000, here the 62.5mpbs limit is as per the current codec version | ||
58 | { OMX_VIDEO_AVCLevel51, 62500000 } //according to the spec the bit rate supported is 300000000, here the 62.5mpbs limit is as per the current codec version | ||
59 | }; | ||
60 | |||
61 | OMX_ERRORTYPE OMXH264VE_InitFields(OMX_HANDLETYPE hComponent) | ||
62 | { | ||
63 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
64 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
65 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
66 | |||
67 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
68 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
69 | |||
70 | OMX_BASE_CHK_VERSION(pHandle, OMX_COMPONENTTYPE, eError); | ||
71 | |||
72 | pH264VEComp = (OMXH264VidEncComp *)pHandle->pComponentPrivate; | ||
73 | |||
74 | pH264VEComp->sBase.cComponentName = (OMX_STRING )OSAL_Malloc(sizeof(OMX_U8) * OMX_MAX_STRINGNAME_SIZE); | ||
75 | OMX_CHECK(pH264VEComp->sBase.cComponentName != NULL, OMX_ErrorInsufficientResources); | ||
76 | |||
77 | strcpy(pH264VEComp->sBase.cComponentName, OMX_H264VE_COMP_NAME); | ||
78 | |||
79 | /* Fill component's version, this may not be same as the OMX Specification version */ | ||
80 | pH264VEComp->sBase.nComponentVersion.s.nVersionMajor = OMX_H264VE_COMP_VERSION_MAJOR; | ||
81 | pH264VEComp->sBase.nComponentVersion.s.nVersionMinor = OMX_H264VE_COMP_VERSION_MINOR; | ||
82 | pH264VEComp->sBase.nComponentVersion.s.nRevision = OMX_H264VE_COMP_VERSION_REVISION; | ||
83 | pH264VEComp->sBase.nComponentVersion.s.nStep = OMX_H264VE_COMP_VERSION_STEP; | ||
84 | |||
85 | /* Initialize Audio Port parameters */ | ||
86 | OSAL_Info("Initialize Audio Port Params"); | ||
87 | pH264VEComp->sBase.pAudioPortParams = (OMX_PORT_PARAM_TYPE*)OSAL_Malloc(sizeof(OMX_PORT_PARAM_TYPE)); | ||
88 | OMX_CHECK(pH264VEComp->sBase.pAudioPortParams != NULL, OMX_ErrorInsufficientResources); | ||
89 | |||
90 | OMX_BASE_INIT_STRUCT_PTR(pH264VEComp->sBase.pAudioPortParams, OMX_PORT_PARAM_TYPE); | ||
91 | pH264VEComp->sBase.pAudioPortParams->nPorts = 0; | ||
92 | pH264VEComp->sBase.pAudioPortParams->nStartPortNumber = 0; | ||
93 | |||
94 | /* Initialize Video Port parameters */ | ||
95 | OSAL_Info("Initialize Video Port Params"); | ||
96 | pH264VEComp->sBase.pVideoPortParams = (OMX_PORT_PARAM_TYPE*)OSAL_Malloc(sizeof(OMX_PORT_PARAM_TYPE)); | ||
97 | OMX_CHECK(pH264VEComp->sBase.pVideoPortParams != NULL, OMX_ErrorInsufficientResources); | ||
98 | |||
99 | OMX_BASE_INIT_STRUCT_PTR(pH264VEComp->sBase.pVideoPortParams, OMX_PORT_PARAM_TYPE); | ||
100 | pH264VEComp->sBase.pVideoPortParams->nPorts = OMX_H264VE_NUM_PORTS; | ||
101 | pH264VEComp->sBase.pVideoPortParams->nStartPortNumber = OMX_H264VE_DEFAULT_START_PORT_NUM; | ||
102 | |||
103 | /* Initialize Image Port parameters */ | ||
104 | OSAL_Info("Initialize Image Port Params"); | ||
105 | pH264VEComp->sBase.pImagePortParams = (OMX_PORT_PARAM_TYPE*)OSAL_Malloc(sizeof(OMX_PORT_PARAM_TYPE)); | ||
106 | OMX_CHECK(pH264VEComp->sBase.pImagePortParams != NULL, OMX_ErrorInsufficientResources); | ||
107 | |||
108 | OMX_BASE_INIT_STRUCT_PTR(pH264VEComp->sBase.pImagePortParams, OMX_PORT_PARAM_TYPE); | ||
109 | pH264VEComp->sBase.pImagePortParams->nPorts = 0; | ||
110 | pH264VEComp->sBase.pImagePortParams->nStartPortNumber = 0; | ||
111 | |||
112 | /* Initialize Other Port parameters */ | ||
113 | OSAL_Info("Initialize Other Port Params"); | ||
114 | pH264VEComp->sBase.pOtherPortParams = (OMX_PORT_PARAM_TYPE*)OSAL_Malloc(sizeof(OMX_PORT_PARAM_TYPE)); | ||
115 | OMX_CHECK(pH264VEComp->sBase.pOtherPortParams != NULL, OMX_ErrorInsufficientResources); | ||
116 | |||
117 | OMX_BASE_INIT_STRUCT_PTR(pH264VEComp->sBase.pOtherPortParams, OMX_PORT_PARAM_TYPE); | ||
118 | pH264VEComp->sBase.pOtherPortParams->nPorts = 0; | ||
119 | pH264VEComp->sBase.pOtherPortParams->nStartPortNumber = 0; | ||
120 | |||
121 | /* Initialize the Total Number of Ports and Start Port Number*/ | ||
122 | OSAL_Info("Initialize Component Port Params"); | ||
123 | pH264VEComp->sBase.nNumPorts = OMX_H264VE_NUM_PORTS; | ||
124 | pH264VEComp->sBase.nMinStartPortIndex = OMX_H264VE_DEFAULT_START_PORT_NUM; | ||
125 | |||
126 | /* Overriding this value. Notify derived component only when data is available on all ports */ | ||
127 | pH264VEComp->sBase.bNotifyForAnyPort = OMX_FALSE; | ||
128 | |||
129 | /* Allocate Memory for Static Parameter */ | ||
130 | pH264VEComp->pVidEncStaticParams = (IH264ENC_Params *) memplugin_alloc(sizeof(IH264ENC_Params), 1, MEM_CARVEOUT, 0, 0); | ||
131 | OMX_CHECK(pH264VEComp->pVidEncStaticParams != NULL, OMX_ErrorInsufficientResources); | ||
132 | OSAL_Memset(pH264VEComp->pVidEncStaticParams, 0x0, sizeof(IH264ENC_Params)); | ||
133 | |||
134 | /* Allocate Memory for Dynamic Parameter */ | ||
135 | pH264VEComp->pVidEncDynamicParams = (IH264ENC_DynamicParams *) memplugin_alloc(sizeof(IH264ENC_DynamicParams), 1, MEM_CARVEOUT, 0, 0); | ||
136 | OMX_CHECK(pH264VEComp->pVidEncDynamicParams != NULL, OMX_ErrorInsufficientResources); | ||
137 | OSAL_Memset(pH264VEComp->pVidEncDynamicParams, 0x0, sizeof(IH264ENC_DynamicParams)); | ||
138 | |||
139 | /* Allocate Memory for status Parameter */ | ||
140 | pH264VEComp->pVidEncStatus = (IH264ENC_Status *) memplugin_alloc(sizeof(IH264ENC_Status), 1, MEM_CARVEOUT, 0, 0); | ||
141 | OMX_CHECK(pH264VEComp->pVidEncStatus != NULL, OMX_ErrorInsufficientResources); | ||
142 | OSAL_Memset(pH264VEComp->pVidEncStatus, 0x0, sizeof(IH264ENC_Status)); | ||
143 | |||
144 | /* Allocate Memory for InArgs Parameter */ | ||
145 | pH264VEComp->pVidEncInArgs = (IH264ENC_InArgs *) memplugin_alloc(sizeof(IH264ENC_InArgs), 1, MEM_CARVEOUT, 0, 0); | ||
146 | OMX_CHECK(pH264VEComp->pVidEncInArgs != NULL, OMX_ErrorInsufficientResources); | ||
147 | OSAL_Memset(pH264VEComp->pVidEncInArgs, 0x0, sizeof(IH264ENC_InArgs)); | ||
148 | |||
149 | /* Allocate Memory for OutArgs Parameter */ | ||
150 | pH264VEComp->pVidEncOutArgs = (IH264ENC_OutArgs *) memplugin_alloc(sizeof(IH264ENC_OutArgs), 1, MEM_CARVEOUT, 0, 0); | ||
151 | OMX_CHECK(pH264VEComp->pVidEncOutArgs != NULL, OMX_ErrorInsufficientResources); | ||
152 | OSAL_Memset(pH264VEComp->pVidEncOutArgs, 0x0, sizeof(IH264ENC_OutArgs)); | ||
153 | |||
154 | /* Allocate Memory for InDesc Parameter */ | ||
155 | pH264VEComp->pVedEncInBufs = (IVIDEO2_BufDesc *) memplugin_alloc(sizeof(IVIDEO2_BufDesc), 1, MEM_CARVEOUT, 0, 0); | ||
156 | OMX_CHECK(pH264VEComp->pVedEncInBufs != NULL, OMX_ErrorInsufficientResources); | ||
157 | OSAL_Memset(pH264VEComp->pVedEncInBufs, 0x0, sizeof(IVIDEO2_BufDesc)); | ||
158 | |||
159 | /* Allocate Memory for OutDesc Parameter */ | ||
160 | pH264VEComp->pVedEncOutBufs = (XDM2_BufDesc *) memplugin_alloc(sizeof(XDM2_BufDesc), 1, MEM_CARVEOUT, 0, 0); | ||
161 | OMX_CHECK(pH264VEComp->pVedEncOutBufs != NULL, OMX_ErrorInsufficientResources); | ||
162 | OSAL_Memset(pH264VEComp->pVedEncOutBufs, 0x0, sizeof(XDM2_BufDesc)); | ||
163 | |||
164 | EXIT: | ||
165 | if( eError != OMX_ErrorNone ) { | ||
166 | OSAL_ErrorTrace("in fn OMXH264VE_SesBaseParameters"); | ||
167 | } | ||
168 | |||
169 | return (eError); | ||
170 | |||
171 | } | ||
172 | |||
173 | |||
174 | OMX_ERRORTYPE OMXH264VE_InitialzeComponentPrivateParams(OMX_HANDLETYPE hComponent) | ||
175 | { | ||
176 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
177 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
178 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
179 | OMX_U32 i = 0; | ||
180 | OSAL_ERROR tStatus = OSAL_ErrNone; | ||
181 | |||
182 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
183 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
184 | |||
185 | OMX_BASE_CHK_VERSION(pHandle, OMX_COMPONENTTYPE, eError); | ||
186 | |||
187 | pH264VEComp = (OMXH264VidEncComp *)pHandle->pComponentPrivate; | ||
188 | |||
189 | OSAL_Info("Update the default Port Params"); | ||
190 | |||
191 | /* Set the Port Definition (OMX_PARAM_PORTDEFINITIONTYPE) Values : INPUT PORT */ | ||
192 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nPortIndex = OMX_H264VE_INPUT_PORT; | ||
193 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.eDir = OMX_DirInput; | ||
194 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nBufferCountActual = OMX_H264VE_DEFAULT_INPUT_BUFFER_COUNT; | ||
195 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nBufferCountMin = OMX_H264VE_MIN_INPUT_BUFFER_COUNT; | ||
196 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nBufferSize = OMX_H264VE_DEFAULT_INPUT_BUFFER_SIZE; | ||
197 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.bEnabled = OMX_TRUE; | ||
198 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.bPopulated = OMX_FALSE; | ||
199 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.eDomain = OMX_PortDomainVideo; | ||
200 | /*Update the Domain (Video) Specific values*/ | ||
201 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.cMIMEType = NULL; | ||
202 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.pNativeRender = NULL; | ||
203 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nFrameWidth = OMX_H264VE_DEFAULT_FRAME_WIDTH; /*should be multiples of 16*/ | ||
204 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nFrameHeight = OMX_H264VE_DEFAULT_FRAME_HEIGHT; | ||
205 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nStride = OMX_H264VE_DEFAULT_FRAME_WIDTH; /*setting the stride as atleaset equal to width (should be multiples of 16)*/ | ||
206 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nSliceHeight = OMX_H264VE_DEFAULT_FRAME_HEIGHT; /*setting the sliceheight as equal to frame height*/ | ||
207 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nBitrate = OMX_H264VE_DEFAULT_BITRATE; | ||
208 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.xFramerate = (OMX_H264VE_DEFAULT_FRAME_RATE << 16); | ||
209 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.bFlagErrorConcealment = OMX_FALSE; | ||
210 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.eCompressionFormat = OMX_VIDEO_CodingUnused; | ||
211 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.eColorFormat =OMX_TI_COLOR_FormatYUV420PackedSemiPlanar; | ||
212 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.pNativeWindow = NULL; | ||
213 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.bBuffersContiguous=OMX_FALSE; | ||
214 | pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nBufferAlignment=32; /*H264 Encoder Codec has alignment restriction for input buffers */ | ||
215 | |||
216 | /* Set the Port Definition (OMX_PARAM_PORTDEFINITIONTYPE)Values : OUTPUT PORT */ | ||
217 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.nPortIndex = OMX_H264VE_OUTPUT_PORT; | ||
218 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.eDir = OMX_DirOutput; | ||
219 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.nBufferCountActual = OMX_H264VE_DEFAULT_OUTPUT_BUFFER_COUNT; | ||
220 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.nBufferCountMin = OMX_H264VE_MIN_OUTPUT_BUFFER_COUNT; | ||
221 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.nBufferSize = OMX_H264VE_DEFAULT_OUTPUT_BUFFER_SIZE; | ||
222 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.bEnabled = OMX_TRUE; | ||
223 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.bPopulated = OMX_FALSE; | ||
224 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.eDomain = OMX_PortDomainVideo; | ||
225 | /*Update the Domain (Video) Specific values*/ | ||
226 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.format.video.cMIMEType = NULL; | ||
227 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.format.video.pNativeRender = NULL; | ||
228 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.format.video.nFrameWidth = OMX_H264VE_DEFAULT_FRAME_WIDTH; | ||
229 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.format.video.nFrameHeight = OMX_H264VE_DEFAULT_FRAME_HEIGHT; | ||
230 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.format.video.nStride = 0; //Stride is not used on port having bitstream buffers | ||
231 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.format.video.nSliceHeight = OMX_H264VE_DEFAULT_FRAME_HEIGHT; /*setting the sliceheight as equal frame height*/ | ||
232 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.format.video.nBitrate = OMX_H264VE_DEFAULT_BITRATE; | ||
233 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.format.video.xFramerate = 0; | ||
234 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.format.video.bFlagErrorConcealment = OMX_FALSE; | ||
235 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.format.video.eCompressionFormat = OMX_VIDEO_CodingAVC; | ||
236 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.format.video.eColorFormat = OMX_COLOR_FormatUnused; | ||
237 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.format.video.pNativeWindow = NULL; | ||
238 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.bBuffersContiguous=OMX_FALSE; | ||
239 | pH264VEComp->sBase.pPorts[OMX_H264VE_OUTPUT_PORT]->sPortDef.nBufferAlignment=0; /*No Alignment required for output buffers*/ | ||
240 | |||
241 | OSAL_Info("SetH264AlgDefaultCreationParams "); | ||
242 | /* Set the Default IVIDENC2_Params: videnc2Params . Does not Adhere to Codec Defaults. Can be modified */ | ||
243 | SET_H264CODEC_DEFAULT_IVIDENC2_PARAMS(pH264VEComp, i); | ||
244 | /* Adheres to Codec Defaults. To be modified only when codec default params change */ | ||
245 | eError = OMXH264VE_SetAlgDefaultCreationParams(hComponent); | ||
246 | OMX_CHECK(eError == OMX_ErrorNone, OMX_ErrorUnsupportedSetting); | ||
247 | |||
248 | /*Overwrite some of the codec static defaults*/ | ||
249 | OVERWRITE_H264CODEC_DEFAULT_STATIC_PARAMS(pH264VEComp); | ||
250 | pH264VEComp->pVidEncStaticParams->IDRFrameInterval = 1; /*All I frames are IDR frames*/ | ||
251 | |||
252 | OSAL_Info("SetH264AlgDefaultDynamicParams "); | ||
253 | /* Set the IVIDENC2_DynamicParams videnc2DynamicParams */ | ||
254 | SET_H264CODEC_DEFAULT_IVIDENC2_DYNAMICPARAMS(pH264VEComp); | ||
255 | eError = OMXH264VE_SetAlgDefaultDynamicParams(hComponent); | ||
256 | OMX_CHECK(eError == OMX_ErrorNone, OMX_ErrorUnsupportedSetting); | ||
257 | |||
258 | /*Overwrite some of the codec static defaults*/ | ||
259 | OVERWRITE_H264CODEC_DEFAULT_DYNAMIC_PARAMS(pH264VEComp); | ||
260 | /*Enable 4 MV*/ | ||
261 | ENABLE_4MV(pH264VEComp); | ||
262 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.generateHeader = XDM_GENERATE_HEADER; | ||
263 | |||
264 | pH264VEComp->bCodecCreate = OMX_FALSE; /*codec creation hasn't happened yet*/ | ||
265 | pH264VEComp->bCodecCreateSettingsChange = OMX_FALSE; /*set to true when Create time settings are modified*/ | ||
266 | pH264VEComp->bInputPortDisable = OMX_FALSE; /*flag to indicate codec creation is required or not */ | ||
267 | pH264VEComp->bCodecFlush = OMX_FALSE; | ||
268 | |||
269 | pH264VEComp->bCallxDMSetParams = NO_PARAM_CHANGE; | ||
270 | pH264VEComp->pCodecInBufferArray = NULL; | ||
271 | pH264VEComp->bAfterEOSReception = OMX_FALSE; | ||
272 | pH264VEComp->bNotifyEOSEventToClient = OMX_FALSE; | ||
273 | pH264VEComp->bPropagateEOSToOutputBuffer = OMX_FALSE; | ||
274 | pH264VEComp->bSetParamInputIsDone = OMX_FALSE; | ||
275 | |||
276 | pH264VEComp->bSendCodecConfig = OMX_TRUE; | ||
277 | |||
278 | pH264VEComp->sCodecConfigData.sBuffer = OSAL_Malloc(sizeof(MemHeader)); | ||
279 | pH264VEComp->sCodecConfigData.sBuffer->ptr | ||
280 | = memplugin_alloc_noheader(pH264VEComp->sCodecConfigData.sBuffer, (SPS_PPS_HEADER_DATA_SIZE), 1, MEM_CARVEOUT, 0, 0); | ||
281 | OMX_CHECK(pH264VEComp->sCodecConfigData.sBuffer->ptr != NULL, OMX_ErrorInsufficientResources); | ||
282 | |||
283 | tStatus = OSAL_Memset(pH264VEComp->sCodecConfigData.sBuffer->ptr, 0x0, (SPS_PPS_HEADER_DATA_SIZE)); | ||
284 | OMX_CHECK(tStatus == OSAL_ErrNone, OMX_ErrorBadParameter); | ||
285 | |||
286 | |||
287 | pH264VEComp->pTempBuffer[0] = OSAL_Malloc(sizeof(MemHeader)); | ||
288 | pH264VEComp->pTempBuffer[0]->ptr | ||
289 | = memplugin_alloc_noheader(pH264VEComp->pTempBuffer[0], (SPS_PPS_HEADER_DATA_SIZE), 1, MEM_CARVEOUT, 0, 0); | ||
290 | OMX_CHECK(pH264VEComp->pTempBuffer[0]->ptr != NULL, OMX_ErrorInsufficientResources); | ||
291 | |||
292 | tStatus = OSAL_Memset(pH264VEComp->pTempBuffer[0]->ptr, 0x0, (SPS_PPS_HEADER_DATA_SIZE)); | ||
293 | OMX_CHECK(tStatus == OSAL_ErrNone, OMX_ErrorBadParameter); | ||
294 | |||
295 | pH264VEComp->pTempBuffer[1] = OSAL_Malloc(sizeof(MemHeader)); | ||
296 | pH264VEComp->pTempBuffer[1]->ptr | ||
297 | = memplugin_alloc_noheader(pH264VEComp->pTempBuffer[1], (SPS_PPS_HEADER_DATA_SIZE), 1, MEM_CARVEOUT, 0, 0); | ||
298 | OMX_CHECK(pH264VEComp->pTempBuffer[1]->ptr != NULL, OMX_ErrorInsufficientResources); | ||
299 | |||
300 | tStatus = OSAL_Memset(pH264VEComp->pTempBuffer[1]->ptr, 0x0, (SPS_PPS_HEADER_DATA_SIZE)); | ||
301 | OMX_CHECK(tStatus == OSAL_ErrNone, OMX_ErrorBadParameter); | ||
302 | |||
303 | pH264VEComp->nCodecConfigSize = 0; | ||
304 | pH264VEComp->bAfterGenHeader = OMX_FALSE; | ||
305 | |||
306 | EXIT: | ||
307 | if( eError != OMX_ErrorNone ) { | ||
308 | OSAL_ErrorTrace(" in fn OMXH264VE_InitialzeComponentPrivateParams"); | ||
309 | } | ||
310 | |||
311 | return (eError); | ||
312 | |||
313 | } | ||
314 | |||
315 | OMX_ERRORTYPE OMXH264VE_SetAlgDefaultCreationParams(OMX_HANDLETYPE hComponent) | ||
316 | { | ||
317 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
318 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
319 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
320 | |||
321 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
322 | |||
323 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
324 | OMX_BASE_CHK_VERSION(pHandle, OMX_COMPONENTTYPE, eError); | ||
325 | pH264VEComp = (OMXH264VidEncComp *)pHandle->pComponentPrivate; | ||
326 | |||
327 | /* Set the Default IH264ENC_RateControlParams: rateControlParams */ | ||
328 | SET_H264CODEC_DEFAULT_STATIC_IH264ENC_RATECONTROLPARAMS(pH264VEComp); | ||
329 | |||
330 | /* Set the Default IH264ENC_InterCodingParams interCodingParams */ | ||
331 | SET_H264CODEC_DEFAULT_STATIC_IH264ENC_INTERCODINGPARAMS(pH264VEComp); | ||
332 | |||
333 | /* Set the Default IH264ENC_IntraCodingParams intraCodingParams */ | ||
334 | SET_H264CODEC_DEFAULT_STATIC_IH264ENC_INTRACODINGPARAMS(pH264VEComp); | ||
335 | |||
336 | /* Set the Default IH264ENC_NALUControlParams nalUnitControlParams */ | ||
337 | SET_H264CODEC_DEFAULT_STATIC_IH264ENC_NALUCONTROLPARAMS(pH264VEComp); | ||
338 | |||
339 | /* Set the Default IH264ENC_SliceCodingParams sliceCodingParams */ | ||
340 | SET_H264CODEC_DEFAULT_STATIC_IH264ENC_SLICECODINGPARAMS(pH264VEComp); | ||
341 | |||
342 | /* Set the Default IH264ENC_LoopFilterParams loopFilterParams */ | ||
343 | SET_H264CODEC_DEFAULT_STATIC_IH264ENC_LOOPFILTERPARAMS(pH264VEComp); | ||
344 | |||
345 | /* Set the Default IH264ENC_FMOCodingParams fmoCodingParams */ | ||
346 | SET_H264CODEC_DEFAULT_STATIC_IH264ENC_FMOCODINGPARAMS(pH264VEComp); | ||
347 | |||
348 | /* Set the Default IH264ENC_VUICodingParams vuiCodingParams */ | ||
349 | SET_H264CODEC_DEFAULT_STATIC_IH264ENC_VUICODINGPARAMS(pH264VEComp); | ||
350 | |||
351 | /* Set the Default IH264ENC_StereoInfoParams stereoInfoParams */ | ||
352 | SET_H264CODEC_DEFAULT_STATIC_IH264ENC_STEREOINFOPARAMS(pH264VEComp); | ||
353 | |||
354 | /* Set the Default IH264ENC_FramePackingSEIParams framePackingSEIParams */ | ||
355 | SET_H264CODEC_DEFAULT_STATIC_IH264ENC_STEREOFRAMEPACKINGPARAMS(pH264VEComp); | ||
356 | |||
357 | /* Set the Default IH264ENC_SVCCodingParams svcCodingParams */ | ||
358 | SET_H264CODEC_DEFAULT_STATIC_IH264ENC_SVCCODINGPARAMS(pH264VEComp); | ||
359 | |||
360 | SET_H264CODEC_DEFAULT_STATIC_IH264ENC_EXTENDEDPARAMS(pH264VEComp); | ||
361 | |||
362 | EXIT: | ||
363 | if( eError != OMX_ErrorNone ) { | ||
364 | OSAL_ErrorTrace("in fn OMXH264VE_SetAlgDefaultCreationParams"); | ||
365 | } | ||
366 | |||
367 | return (eError); | ||
368 | } | ||
369 | |||
370 | OMX_ERRORTYPE OMXH264VE_SetAlgDefaultDynamicParams(OMX_HANDLETYPE hComponent) | ||
371 | { | ||
372 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
373 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
374 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
375 | |||
376 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
377 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
378 | OMX_BASE_CHK_VERSION(pHandle, OMX_COMPONENTTYPE, eError); | ||
379 | pH264VEComp = (OMXH264VidEncComp *)pHandle->pComponentPrivate; | ||
380 | |||
381 | /* Set the IH264ENC_RateControlParams rateControlParams */ | ||
382 | SET_H264CODEC_DEFAULT_DYNAMIC_RATECONTROLPARAMS(pH264VEComp); | ||
383 | |||
384 | /* Set the IH264ENC_InterCodingParams interCodingParams */ | ||
385 | SET_H264CODEC_DEFAULT_DYNAMIC_INTERCODINGPARAMS(pH264VEComp); | ||
386 | |||
387 | /* Set the IH264ENC_IntraCodingParams interCodingParams */ | ||
388 | SET_H264CODEC_DEFAULT_DYNAMIC_INTRACODINGPARAMS(pH264VEComp); | ||
389 | |||
390 | /* Set the IH264ENC_SliceCodingParams sliceCodingParams */ | ||
391 | SET_H264CODEC_DEFAULT_DYNAMIC_SLICECODINGPARAMS(pH264VEComp); | ||
392 | |||
393 | SET_H264CODEC_DEFAULT_DYNAMIC_IH264_EXTENDEDPARAMS(pH264VEComp); | ||
394 | |||
395 | EXIT: | ||
396 | if( eError != OMX_ErrorNone ) { | ||
397 | OSAL_ErrorTrace(" in fn OMXH264VE_SetAlgDefaultDynamicParams"); | ||
398 | } | ||
399 | return (eError); | ||
400 | } | ||
401 | |||
402 | |||
403 | OMX_ERRORTYPE OMXH264VE_SetBufferDesc(OMX_HANDLETYPE hComponent, OMX_U32 nPortIndex) | ||
404 | { | ||
405 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
406 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
407 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
408 | OMX_U8 i; | ||
409 | OMX_U32 extWidth, extHeight, extStride; | ||
410 | |||
411 | /* Check the input parameters, this should be TRUE else report an Error */ | ||
412 | OMX_CHECK(hComponent != NULL, OMX_ErrorBadParameter); | ||
413 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
414 | |||
415 | OMX_BASE_CHK_VERSION(pHandle, OMX_COMPONENTTYPE, eError); | ||
416 | pH264VEComp = (OMXH264VidEncComp *)pHandle->pComponentPrivate; | ||
417 | |||
418 | if( nPortIndex == OMX_H264VE_INPUT_PORT ) { | ||
419 | pH264VEComp->pVedEncInBufs->numPlanes = pH264VEComp->pVidEncStatus->videnc2Status.bufInfo.minNumInBufs; | ||
420 | for( i=0; i < pH264VEComp->pVedEncInBufs->numPlanes; i++ ) { | ||
421 | pH264VEComp->pVedEncInBufs->planeDesc[i].memType = pH264VEComp->pVidEncStatus->videnc2Status.bufInfo.inBufMemoryType[i]; | ||
422 | if( pH264VEComp->pVedEncInBufs->planeDesc[i].memType == XDM_MEMTYPE_RAW ) { | ||
423 | pH264VEComp->pVedEncInBufs->planeDesc[i].bufSize.bytes = | ||
424 | pH264VEComp->pVidEncStatus->videnc2Status.bufInfo.minInBufSize[i].bytes; | ||
425 | } else { | ||
426 | /* Since we support non-tiler input buffers for encoding, change the memtype */ | ||
427 | pH264VEComp->pVedEncInBufs->planeDesc[i].memType = XDM_MEMTYPE_RAW; | ||
428 | pH264VEComp->pVedEncInBufs->planeDesc[i].bufSize.bytes = (pH264VEComp->pVidEncStatus->videnc2Status.bufInfo.minInBufSize[i].tileMem.width) * (pH264VEComp->pVidEncStatus->videnc2Status.bufInfo.minInBufSize[i].tileMem.height); | ||
429 | } | ||
430 | } | ||
431 | |||
432 | OSAL_Info("Update the Image,Active region of Codec params"); | ||
433 | extWidth = pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nFrameWidth; /*stride is already checked during codec creation that it should be multiples of 16*/ | ||
434 | extStride = pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nStride; | ||
435 | extHeight = pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nFrameHeight; | ||
436 | |||
437 | pH264VEComp->pVedEncInBufs->imageRegion.topLeft.x = 0; | ||
438 | pH264VEComp->pVedEncInBufs->imageRegion.topLeft.y = 0; | ||
439 | pH264VEComp->pVedEncInBufs->imageRegion.bottomRight.x = extStride; | ||
440 | |||
441 | pH264VEComp->pVedEncInBufs->activeFrameRegion.topLeft.x = 0; | ||
442 | pH264VEComp->pVedEncInBufs->activeFrameRegion.topLeft.y = 0; | ||
443 | pH264VEComp->pVedEncInBufs->activeFrameRegion.bottomRight.x = extWidth; | ||
444 | |||
445 | pH264VEComp->pVedEncInBufs->imagePitch[0] = extStride; | ||
446 | pH264VEComp->pVedEncInBufs->imagePitch[1] = extStride; | ||
447 | pH264VEComp->pVedEncInBufs->topFieldFirstFlag = OMX_TRUE; | ||
448 | |||
449 | pH264VEComp->pVedEncInBufs->contentType = IVIDEO_PROGRESSIVE; | ||
450 | pH264VEComp->pVedEncInBufs->activeFrameRegion.bottomRight.y = extHeight; | ||
451 | pH264VEComp->pVedEncInBufs->imageRegion.bottomRight.y = extHeight; | ||
452 | |||
453 | pH264VEComp->pVedEncInBufs->secondFieldOffsetWidth[0] = 0; | ||
454 | pH264VEComp->pVedEncInBufs->secondFieldOffsetWidth[1] = 0; | ||
455 | pH264VEComp->pVedEncInBufs->secondFieldOffsetHeight[0] = 0; | ||
456 | pH264VEComp->pVedEncInBufs->secondFieldOffsetHeight[1] = 0; | ||
457 | pH264VEComp->pVedEncInBufs->chromaFormat = XDM_YUV_420SP; | ||
458 | |||
459 | } else if( nPortIndex == OMX_H264VE_OUTPUT_PORT ) { | ||
460 | pH264VEComp->pVedEncOutBufs->numBufs = pH264VEComp->pVidEncStatus->videnc2Status.bufInfo.minNumOutBufs; | ||
461 | for( i=0; i < pH264VEComp->pVedEncOutBufs->numBufs; i++ ) { | ||
462 | pH264VEComp->pVedEncOutBufs->descs[i].memType = pH264VEComp->pVidEncStatus->videnc2Status.bufInfo.outBufMemoryType[i]; | ||
463 | if( pH264VEComp->pVedEncOutBufs->descs[i].memType == XDM_MEMTYPE_RAW ) { | ||
464 | pH264VEComp->pVedEncOutBufs->descs[i].bufSize.bytes = | ||
465 | pH264VEComp->pVidEncStatus->videnc2Status.bufInfo.minOutBufSize[i].bytes; | ||
466 | } else { | ||
467 | /* since the output buffers are always non-tiled, change the memory type & size to RAW memory type*/ | ||
468 | pH264VEComp->pVedEncOutBufs->descs[i].memType = XDM_MEMTYPE_RAW; | ||
469 | pH264VEComp->pVedEncOutBufs->descs[i].bufSize.bytes = | ||
470 | pH264VEComp->pVidEncStatus->videnc2Status.bufInfo.minOutBufSize[i].bytes; | ||
471 | } | ||
472 | } | ||
473 | } else { | ||
474 | eError=OMX_ErrorBadPortIndex; | ||
475 | } | ||
476 | |||
477 | EXIT: | ||
478 | if( eError != OMX_ErrorNone ) { | ||
479 | OSAL_ErrorTrace("in fn OMXH264VE_SetBufferDesc"); | ||
480 | } | ||
481 | |||
482 | return (eError); | ||
483 | |||
484 | } | ||
485 | |||
486 | OMX_ERRORTYPE OMXH264VE_SetEncCodecReady(OMX_HANDLETYPE hComponent) | ||
487 | { | ||
488 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
489 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
490 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
491 | XDAS_Int32 retval = 0; | ||
492 | |||
493 | /* Check the input parameters */ | ||
494 | OMX_CHECK((hComponent != NULL), OMX_ErrorBadParameter); | ||
495 | |||
496 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
497 | pH264VEComp = (OMXH264VidEncComp *)pHandle->pComponentPrivate; | ||
498 | |||
499 | /*set the HRD buffer size appropriately*/ | ||
500 | if( pH264VEComp->pVidEncStaticParams->rateControlParams.rcAlgo == IH264_RATECONTROL_PRC_LOW_DELAY ) { | ||
501 | pH264VEComp->pVidEncStaticParams->rateControlParams.HRDBufferSize = | ||
502 | (pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetBitRate) / 2; | ||
503 | pH264VEComp->pVidEncDynamicParams->rateControlParams.HRDBufferSize = | ||
504 | (pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetBitRate) / 2; | ||
505 | } else { | ||
506 | pH264VEComp->pVidEncStaticParams->rateControlParams.HRDBufferSize = | ||
507 | (pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetBitRate); | ||
508 | pH264VEComp->pVidEncDynamicParams->rateControlParams.HRDBufferSize = | ||
509 | (pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.targetBitRate); | ||
510 | } | ||
511 | pH264VEComp->pVidEncStaticParams->rateControlParams.initialBufferLevel = | ||
512 | pH264VEComp->pVidEncStaticParams->rateControlParams.HRDBufferSize; | ||
513 | pH264VEComp->pVidEncDynamicParams->rateControlParams.initialBufferLevel = | ||
514 | pH264VEComp->pVidEncStaticParams->rateControlParams.HRDBufferSize; | ||
515 | pH264VEComp->pVidEncStaticParams->rateControlParams.rateControlParamsPreset = IH264_RATECONTROLPARAMS_USERDEFINED; | ||
516 | |||
517 | if( pH264VEComp->pVidEncStaticParams->videnc2Params.maxHeight & 0x01 ) { | ||
518 | eError = OMX_ErrorUnsupportedSetting; | ||
519 | OSAL_ErrorTrace("Incorrect Height Settings"); | ||
520 | OSAL_ErrorTrace("for Progressive Port Def Height need be multiple of 2"); | ||
521 | OSAL_ErrorTrace("for Interlace Port Def Height need be multiple of 4"); | ||
522 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
523 | } | ||
524 | |||
525 | /* Create H264 Encoder Instance */ | ||
526 | pH264VEComp->pVidEncHandle = VIDENC2_create(pH264VEComp->pCEhandle, | ||
527 | OMX_H264V_ENCODER_NAME, | ||
528 | (VIDENC2_Params *)(pH264VEComp->pVidEncStaticParams)); | ||
529 | |||
530 | OMX_CHECK(pH264VEComp->pVidEncHandle != NULL, OMX_ErrorInsufficientResources); | ||
531 | |||
532 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
533 | pH264VEComp->bCodecCreate=OMX_TRUE; | ||
534 | pH264VEComp->bCodecCreateSettingsChange=OMX_FALSE; | ||
535 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
536 | |||
537 | /* Set the Dynamic Parameters to the Codec */ | ||
538 | eError = OMXH264VE_SetDynamicParamsToCodec(hComponent); | ||
539 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
540 | |||
541 | /* Get the Codec Status Parametrs and Update the Component private Params accordingly */ | ||
542 | eError = OMXH264VE_VISACONTROL(pH264VEComp->pVidEncHandle, XDM_GETSTATUS, | ||
543 | (VIDENC2_DynamicParams *)(pH264VEComp->pVidEncDynamicParams), | ||
544 | (IVIDENC2_Status *)(pH264VEComp->pVidEncStatus), hComponent, &retval); | ||
545 | if( retval == VIDENC2_EFAIL ) { | ||
546 | OSAL_Info("Got error from the Codec GetbufInfo call"); | ||
547 | OMX_TI_GET_ERROR(pH264VEComp, pH264VEComp->pVidEncStatus->videnc2Status.extendedError, eError); | ||
548 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
549 | } | ||
550 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
551 | |||
552 | eError= OMXH264VE_UpdateParams(pHandle); | ||
553 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
554 | |||
555 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
556 | pH264VEComp->bCallxDMSetParams = NO_PARAM_CHANGE; | ||
557 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
558 | |||
559 | /* get bufffer information: | ||
560 | * control->XDM_GETBUFINFO call always has to ensure the control->XDM_SETPARAMS call has done before | ||
561 | * Get the Buf Info from the Codec */ | ||
562 | OSAL_Info("call to xDM GetBufInfo"); | ||
563 | eError = OMXH264VE_VISACONTROL(pH264VEComp->pVidEncHandle, XDM_GETBUFINFO, | ||
564 | (VIDENC2_DynamicParams *)(pH264VEComp->pVidEncDynamicParams), | ||
565 | (IVIDENC2_Status *)(pH264VEComp->pVidEncStatus), hComponent, &retval); | ||
566 | if( retval == VIDENC2_EFAIL ) { | ||
567 | OSAL_Info("Got error from the Codec GetbufInfo call"); | ||
568 | OMX_TI_GET_ERROR(pH264VEComp, pH264VEComp->pVidEncStatus->videnc2Status.extendedError, eError); | ||
569 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
570 | } | ||
571 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
572 | /* Initialize the Inputbufs and Outputbufs with the values that Codec Expects */ | ||
573 | eError=OMXH264VE_SetBufferDesc(pHandle, OMX_H264VE_INPUT_PORT); | ||
574 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
575 | |||
576 | eError=OMXH264VE_SetBufferDesc(pHandle, OMX_H264VE_OUTPUT_PORT); | ||
577 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
578 | |||
579 | EXIT: | ||
580 | if( eError != OMX_ErrorNone ) { | ||
581 | OSAL_ErrorTrace("in fn OMXH264VE_SetEncCodecReady"); | ||
582 | } | ||
583 | |||
584 | return (eError); | ||
585 | |||
586 | } | ||
587 | |||
588 | OMX_ERRORTYPE OMXH264VE_UpdateParams(OMX_HANDLETYPE hComponent) | ||
589 | { | ||
590 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
591 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
592 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
593 | OMX_STATETYPE tState; | ||
594 | |||
595 | OMX_CHECK((hComponent != NULL), OMX_ErrorBadParameter); | ||
596 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
597 | pH264VEComp = (OMXH264VidEncComp *)pHandle->pComponentPrivate; | ||
598 | |||
599 | OSAL_Info("Update the OMX Component structures with Codec Structures"); | ||
600 | |||
601 | pH264VEComp->pVidEncStaticParams->videnc2Params.encodingPreset = pH264VEComp->pVidEncStatus->videnc2Status.encodingPreset; | ||
602 | |||
603 | pH264VEComp->pVidEncStaticParams->videnc2Params.rateControlPreset = pH264VEComp->pVidEncStatus->videnc2Status.rateControlPreset; | ||
604 | |||
605 | pH264VEComp->pVidEncStaticParams->videnc2Params.maxInterFrameInterval = pH264VEComp->pVidEncStatus->videnc2Status.maxInterFrameInterval; | ||
606 | |||
607 | pH264VEComp->pVidEncStaticParams->videnc2Params.inputChromaFormat = pH264VEComp->pVidEncStatus->videnc2Status.inputChromaFormat; | ||
608 | |||
609 | pH264VEComp->pVidEncStaticParams->videnc2Params.inputContentType = pH264VEComp->pVidEncStatus->videnc2Status.inputContentType; | ||
610 | |||
611 | pH264VEComp->pVidEncStaticParams->videnc2Params.operatingMode = pH264VEComp->pVidEncStatus->videnc2Status.operatingMode; | ||
612 | |||
613 | pH264VEComp->pVidEncStaticParams->videnc2Params.profile = pH264VEComp->pVidEncStatus->videnc2Status.profile; | ||
614 | |||
615 | pH264VEComp->pVidEncStaticParams->videnc2Params.level = pH264VEComp->pVidEncStatus->videnc2Status.level; | ||
616 | |||
617 | pH264VEComp->pVidEncStaticParams->videnc2Params.inputDataMode = pH264VEComp->pVidEncStatus->videnc2Status.inputDataMode; | ||
618 | pH264VEComp->pVidEncStaticParams->videnc2Params.outputDataMode = pH264VEComp->pVidEncStatus->videnc2Status.outputDataMode; | ||
619 | |||
620 | OSAL_Memcpy(&(pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams), &(pH264VEComp->pVidEncStatus->videnc2Status.encDynamicParams), | ||
621 | sizeof (IVIDENC2_DynamicParams)); | ||
622 | |||
623 | OSAL_Memcpy(&(pH264VEComp->pVidEncDynamicParams->rateControlParams), &(pH264VEComp->pVidEncStatus->rateControlParams), | ||
624 | sizeof (IH264ENC_RateControlParams)); | ||
625 | |||
626 | OSAL_Memcpy(&(pH264VEComp->pVidEncDynamicParams->interCodingParams), &(pH264VEComp->pVidEncStatus->interCodingParams), | ||
627 | sizeof (IH264ENC_InterCodingParams)); | ||
628 | |||
629 | OSAL_Memcpy(&(pH264VEComp->pVidEncDynamicParams->intraCodingParams), &(pH264VEComp->pVidEncStatus->intraCodingParams), | ||
630 | sizeof (IH264ENC_IntraCodingParams)); | ||
631 | |||
632 | OSAL_Memcpy(&(pH264VEComp->pVidEncStaticParams->nalUnitControlParams), &(pH264VEComp->pVidEncStatus->nalUnitControlParams), | ||
633 | sizeof (IH264ENC_NALUControlParams)); | ||
634 | |||
635 | OSAL_Memcpy(&(pH264VEComp->pVidEncDynamicParams->sliceCodingParams), &(pH264VEComp->pVidEncStatus->sliceCodingParams), | ||
636 | sizeof (IH264ENC_SliceCodingParams)); | ||
637 | |||
638 | OSAL_Memcpy(&(pH264VEComp->pVidEncStaticParams->loopFilterParams), &(pH264VEComp->pVidEncStatus->loopFilterParams), | ||
639 | sizeof (IH264ENC_LoopFilterParams)); | ||
640 | |||
641 | OSAL_Memcpy(&(pH264VEComp->pVidEncStaticParams->fmoCodingParams), &(pH264VEComp->pVidEncStatus->fmoCodingParams), | ||
642 | sizeof (IH264ENC_FMOCodingParams)); | ||
643 | |||
644 | OSAL_Memcpy(&(pH264VEComp->pVidEncStaticParams->vuiCodingParams), &(pH264VEComp->pVidEncStatus->vuiCodingParams), | ||
645 | sizeof (IH264ENC_VUICodingParams)); | ||
646 | |||
647 | OSAL_Memcpy(&(pH264VEComp->pVidEncStaticParams->stereoInfoParams), &(pH264VEComp->pVidEncStatus->stereoInfoParams), | ||
648 | sizeof (IH264ENC_StereoInfoParams)); | ||
649 | |||
650 | OSAL_Memcpy(&(pH264VEComp->pVidEncStaticParams->framePackingSEIParams), &(pH264VEComp->pVidEncStatus->framePackingSEIParams), | ||
651 | sizeof (IH264ENC_FramePackingSEIParams)); | ||
652 | |||
653 | OSAL_Memcpy(&(pH264VEComp->pVidEncStaticParams->svcCodingParams), &(pH264VEComp->pVidEncStatus->svcCodingParams), | ||
654 | sizeof (IH264ENC_SVCCodingParams)); | ||
655 | |||
656 | pH264VEComp->pVidEncStaticParams->interlaceCodingType = pH264VEComp->pVidEncStatus->interlaceCodingType; | ||
657 | |||
658 | pH264VEComp->pVidEncStaticParams->bottomFieldIntra = pH264VEComp->pVidEncStatus->bottomFieldIntra; | ||
659 | |||
660 | pH264VEComp->pVidEncStaticParams->gopStructure = pH264VEComp->pVidEncStatus->gopStructure; | ||
661 | |||
662 | pH264VEComp->pVidEncStaticParams->entropyCodingMode = pH264VEComp->pVidEncStatus->entropyCodingMode; | ||
663 | |||
664 | pH264VEComp->pVidEncStaticParams->transformBlockSize =pH264VEComp->pVidEncStatus->transformBlockSize; | ||
665 | |||
666 | pH264VEComp->pVidEncStaticParams->log2MaxFNumMinus4 = pH264VEComp->pVidEncStatus->log2MaxFNumMinus4; | ||
667 | |||
668 | pH264VEComp->pVidEncStaticParams->picOrderCountType = pH264VEComp->pVidEncStatus->picOrderCountType; | ||
669 | |||
670 | pH264VEComp->pVidEncStaticParams->enableWatermark = pH264VEComp->pVidEncStatus->enableWatermark; | ||
671 | |||
672 | pH264VEComp->pVidEncStaticParams->IDRFrameInterval =pH264VEComp->pVidEncStatus->IDRFrameInterval; | ||
673 | |||
674 | pH264VEComp->pVidEncStaticParams->maxIntraFrameInterval =pH264VEComp->pVidEncStatus->maxIntraFrameInterval; | ||
675 | |||
676 | pH264VEComp->pVidEncStaticParams->debugTraceLevel = pH264VEComp->pVidEncStatus->debugTraceLevel; | ||
677 | |||
678 | pH264VEComp->pVidEncStaticParams->lastNFramesToLog = pH264VEComp->pVidEncStatus->lastNFramesToLog; | ||
679 | |||
680 | pH264VEComp->pVidEncStaticParams->enableAnalyticinfo =pH264VEComp->pVidEncStatus->enableAnalyticinfo; | ||
681 | |||
682 | pH264VEComp->pVidEncStaticParams->enableGMVSei =pH264VEComp->pVidEncStatus->enableGMVSei; | ||
683 | |||
684 | pH264VEComp->pVidEncStaticParams->constraintSetFlags =pH264VEComp->pVidEncStatus->constraintSetFlags; | ||
685 | |||
686 | pH264VEComp->pVidEncStaticParams->enableRCDO =pH264VEComp->pVidEncStatus->enableRCDO; | ||
687 | |||
688 | pH264VEComp->pVidEncStaticParams->enableLongTermRefFrame =pH264VEComp->pVidEncStatus->enableLongTermRefFrame; | ||
689 | |||
690 | pH264VEComp->pVidEncStaticParams->LTRPPeriod =pH264VEComp->pVidEncStatus->LTRPPeriod; | ||
691 | |||
692 | pH264VEComp->pVidEncStaticParams->numTemporalLayer =pH264VEComp->pVidEncStatus->numTemporalLayer; | ||
693 | |||
694 | pH264VEComp->pVidEncStaticParams->referencePicMarking =pH264VEComp->pVidEncStatus->referencePicMarking; | ||
695 | |||
696 | pH264VEComp->pVidEncDynamicParams->searchCenter.x = pH264VEComp->pVidEncStatus->searchCenter.x; | ||
697 | |||
698 | pH264VEComp->pVidEncDynamicParams->searchCenter.x = pH264VEComp->pVidEncStatus->searchCenter.y; | ||
699 | |||
700 | pH264VEComp->pVidEncDynamicParams->enableStaticMBCount =pH264VEComp->pVidEncStatus->enableStaticMBCount; | ||
701 | |||
702 | pH264VEComp->pVidEncDynamicParams->enableROI = pH264VEComp->pVidEncStatus->enableROI; | ||
703 | |||
704 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
705 | tState=pH264VEComp->sBase.tCurState; | ||
706 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
707 | |||
708 | if((tState == OMX_StateLoaded) || (tState == OMX_StateIdle)) { | ||
709 | OSAL_Memcpy(&(pH264VEComp->pVidEncStaticParams->rateControlParams), &(pH264VEComp->pVidEncStatus->rateControlParams), | ||
710 | sizeof (IH264ENC_RateControlParams)); | ||
711 | |||
712 | OSAL_Memcpy(&(pH264VEComp->pVidEncStaticParams->interCodingParams), &(pH264VEComp->pVidEncStatus->interCodingParams), | ||
713 | sizeof (IH264ENC_InterCodingParams)); | ||
714 | |||
715 | OSAL_Memcpy(&(pH264VEComp->pVidEncStaticParams->sliceCodingParams), &(pH264VEComp->pVidEncStatus->sliceCodingParams), | ||
716 | sizeof (IH264ENC_SliceCodingParams)); | ||
717 | |||
718 | OSAL_Memcpy(&(pH264VEComp->pVidEncStaticParams->intraCodingParams), &(pH264VEComp->pVidEncStatus->intraCodingParams), | ||
719 | sizeof (IH264ENC_IntraCodingParams)); | ||
720 | } | ||
721 | |||
722 | EXIT: | ||
723 | if( eError != OMX_ErrorNone ) { | ||
724 | OSAL_ErrorTrace("in fn OMXH264VE_UpdateParams"); | ||
725 | } | ||
726 | |||
727 | return (eError); | ||
728 | } | ||
729 | |||
730 | OMX_ERRORTYPE OMXH264VE_FLUSHLockedBuffers(OMX_HANDLETYPE hComponent) | ||
731 | { | ||
732 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
733 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
734 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
735 | OMX_U32 i; | ||
736 | |||
737 | /* Check the input parameters */ | ||
738 | OMX_CHECK((hComponent != NULL), OMX_ErrorBadParameter); | ||
739 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
740 | pH264VEComp = (OMXH264VidEncComp *)pHandle->pComponentPrivate; | ||
741 | |||
742 | for( i=0; i < pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nBufferCountActual; i++ ) { | ||
743 | if(pH264VEComp->pCodecInBufferArray && pH264VEComp->pCodecInBufferArray[i]) { | ||
744 | OMXBase_BufHdrPvtData *pPvtData = (OMXBase_BufHdrPvtData *)(pH264VEComp->pCodecInBufferArray[i]->pPlatformPrivate); | ||
745 | if (pPvtData->bufSt == OWNED_BY_CODEC ) { | ||
746 | pH264VEComp->pCodecInBufferArray[i]->nOffset = 0; | ||
747 | /*update the status to free*/ | ||
748 | pPvtData->bufSt = OWNED_BY_US; | ||
749 | pH264VEComp->sBase.pPvtData->fpDioSend(hComponent, OMX_H264VE_INPUT_PORT, pH264VEComp->pCodecInBufferArray[i]); | ||
750 | } | ||
751 | } | ||
752 | } | ||
753 | |||
754 | EXIT: | ||
755 | return (eError); | ||
756 | } | ||
757 | |||
758 | OMX_ERRORTYPE OMXH264VE_GetNextFreeBufHdr(OMX_HANDLETYPE hComponent, OMX_S32 *nBuffIndex, OMX_U32 nPortIndex) | ||
759 | { | ||
760 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
761 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
762 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
763 | OMX_BOOL bFreeBuffFound = OMX_FALSE; | ||
764 | OMX_S32 LBufIndex = -1; | ||
765 | OMX_U32 i; | ||
766 | |||
767 | /* Check the input parameters */ | ||
768 | OMX_CHECK((hComponent != NULL), OMX_ErrorBadParameter); | ||
769 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
770 | pH264VEComp = (OMXH264VidEncComp *)pHandle->pComponentPrivate; | ||
771 | |||
772 | if( nPortIndex == OMX_H264VE_INPUT_PORT ) { | ||
773 | for( i=0; i < pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nBufferCountActual; i++ ) { | ||
774 | if(!pH264VEComp->pCodecInBufferArray[i] || | ||
775 | ((OMXBase_BufHdrPvtData *)(pH264VEComp->pCodecInBufferArray[i]->pPlatformPrivate))->bufSt != OWNED_BY_CODEC ) { | ||
776 | bFreeBuffFound=OMX_TRUE; | ||
777 | LBufIndex=i; | ||
778 | break; | ||
779 | } | ||
780 | } | ||
781 | } else { | ||
782 | eError = OMX_ErrorBadParameter; | ||
783 | } | ||
784 | |||
785 | EXIT: | ||
786 | |||
787 | if( bFreeBuffFound ) { | ||
788 | *nBuffIndex=LBufIndex; | ||
789 | } else { | ||
790 | *nBuffIndex=-1; | ||
791 | } | ||
792 | return (eError); | ||
793 | } | ||
794 | |||
795 | OMX_ERRORTYPE OMXH264VE_SetDynamicParamsToCodec(OMX_HANDLETYPE hComponent) | ||
796 | { | ||
797 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
798 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
799 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
800 | XDAS_Int32 retval = 0; | ||
801 | |||
802 | /* Check the input parameters */ | ||
803 | OMX_CHECK((hComponent != NULL), OMX_ErrorBadParameter); | ||
804 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
805 | pH264VEComp = (OMXH264VidEncComp *)pHandle->pComponentPrivate; | ||
806 | |||
807 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.size = sizeof(IH264ENC_DynamicParams); | ||
808 | pH264VEComp->pVidEncStatus->videnc2Status.size = sizeof(IH264ENC_Status); | ||
809 | |||
810 | if((pH264VEComp->bSendCodecConfig)) { | ||
811 | pH264VEComp->pVidEncDynamicParams->videnc2DynamicParams.generateHeader = XDM_GENERATE_HEADER; | ||
812 | pH264VEComp->nCodecConfigSize = 0; | ||
813 | pH264VEComp->bAfterGenHeader = OMX_FALSE; | ||
814 | } | ||
815 | |||
816 | pH264VEComp->pVidEncDynamicParams->rateControlParams.rateControlParamsPreset = 2; //Existing | ||
817 | |||
818 | pH264VEComp->pVidEncDynamicParams->interCodingParams.interCodingPreset = 2; //Existing | ||
819 | |||
820 | pH264VEComp->pVidEncDynamicParams->intraCodingParams.intraCodingPreset = IH264_INTRACODING_EXISTING; | ||
821 | |||
822 | pH264VEComp->pVidEncDynamicParams->sliceCodingParams.sliceCodingPreset = 2; //Existing | ||
823 | |||
824 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
825 | pH264VEComp->bCallxDMSetParams=PARAMS_UPDATED_AT_CODEC; | ||
826 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
827 | |||
828 | eError = OMXH264VE_VISACONTROL(pH264VEComp->pVidEncHandle, XDM_SETPARAMS, | ||
829 | (VIDENC2_DynamicParams *)(pH264VEComp->pVidEncDynamicParams), | ||
830 | (IVIDENC2_Status *)(pH264VEComp->pVidEncStatus), hComponent, &retval); | ||
831 | if( retval == VIDENC2_EFAIL ) { | ||
832 | ALOGE("pH264VEComp->pVidEncStatus->videnc2Status.extendedError = %x", | ||
833 | (OMX_U32)pH264VEComp->pVidEncStatus->videnc2Status.extendedError); | ||
834 | OMX_TI_GET_ERROR(pH264VEComp, pH264VEComp->pVidEncStatus->videnc2Status.extendedError, eError); | ||
835 | OMX_CHECK(eError == OMX_ErrorNone, eError); | ||
836 | } | ||
837 | |||
838 | |||
839 | EXIT: | ||
840 | return (eError); | ||
841 | } | ||
842 | |||
843 | OMX_ERRORTYPE OMXH264VE_GetNumCodecLockedBuffers(OMX_HANDLETYPE hComponent, OMX_U32 *nLockedBuffCount) | ||
844 | { | ||
845 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
846 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
847 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
848 | OMX_U32 LBuffLockedCount = 0; | ||
849 | OMX_U32 i; | ||
850 | |||
851 | /* Check the input parameters */ | ||
852 | OMX_CHECK((hComponent != NULL), OMX_ErrorBadParameter); | ||
853 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
854 | pH264VEComp = (OMXH264VidEncComp *)pHandle->pComponentPrivate; | ||
855 | |||
856 | for( i=0; i < pH264VEComp->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.nBufferCountActual; i++ ) { | ||
857 | if((pH264VEComp->pCodecInBufferArray[i]) && | ||
858 | ((OMXBase_BufHdrPvtData *)(pH264VEComp->pCodecInBufferArray[i]->pPlatformPrivate))->bufSt == OWNED_BY_CODEC ) { | ||
859 | LBuffLockedCount++; | ||
860 | |||
861 | } | ||
862 | } | ||
863 | |||
864 | *nLockedBuffCount=LBuffLockedCount; | ||
865 | |||
866 | EXIT: | ||
867 | return (eError); | ||
868 | } | ||
869 | |||
870 | OMX_ERRORTYPE OMXH264VE_VISACONTROL(VIDENC2_Handle handle, IVIDENC2_Cmd id, IVIDENC2_DynamicParams *dynParams, | ||
871 | IVIDENC2_Status *status, OMX_HANDLETYPE hComponent, XDAS_Int32 *retval) | ||
872 | { | ||
873 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
874 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
875 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
876 | (void)handle; | ||
877 | |||
878 | /*Check for the Params*/ | ||
879 | OMX_CHECK(((hComponent != NULL) && (dynParams != NULL) && (status != NULL) && (retval != NULL)), OMX_ErrorBadParameter); | ||
880 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
881 | pH264VEComp = pHandle->pComponentPrivate; | ||
882 | |||
883 | (*retval) = VIDENC2_control(pH264VEComp->pVidEncHandle, id, dynParams, status); | ||
884 | |||
885 | EXIT: | ||
886 | return (eError); | ||
887 | } | ||
888 | |||
889 | |||
890 | OMX_ERRORTYPE OMXH264VE_VISAPROCESS_AND_UPDATEPARAMS(OMX_HANDLETYPE hComponent, XDAS_Int32 *retval) | ||
891 | { | ||
892 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
893 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
894 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
895 | PARAMS_UPDATE_STATUS bLCallxDMSetParams = NO_PARAM_CHANGE; | ||
896 | OMX_U32 sLretval = VIDENC2_EOK; | ||
897 | |||
898 | /*Check for the Params*/ | ||
899 | OMX_CHECK(((hComponent != NULL) && (retval != NULL)), OMX_ErrorBadParameter); | ||
900 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
901 | pH264VEComp = pHandle->pComponentPrivate; | ||
902 | |||
903 | OSAL_Info("Before the Codec Process call"); | ||
904 | sLretval = VIDENC2_process(pH264VEComp->pVidEncHandle, | ||
905 | (pH264VEComp->pVedEncInBufs), | ||
906 | (pH264VEComp->pVedEncOutBufs), | ||
907 | (IVIDENC2_InArgs *)(pH264VEComp->pVidEncInArgs), | ||
908 | (IVIDENC2_OutArgs *)(pH264VEComp->pVidEncOutArgs)); | ||
909 | |||
910 | if( sLretval == (OMX_U32)VIDENC2_EFAIL ) { | ||
911 | OMX_TI_GET_ERROR(pH264VEComp, pH264VEComp->pVidEncOutArgs->videnc2OutArgs.extendedError, eError); | ||
912 | if( eError != OMX_ErrorNone ) { | ||
913 | ALOGE("Got error 0x%x from the Codec Process call", eError); | ||
914 | goto UPDATE_PARAMS; | ||
915 | } | ||
916 | } | ||
917 | |||
918 | /* Get the Codec Status Parameters if there has been a setconfig which has been translated to the codec */ | ||
919 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
920 | bLCallxDMSetParams=pH264VEComp->bCallxDMSetParams; | ||
921 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
922 | |||
923 | if( bLCallxDMSetParams == PARAMS_UPDATED_AT_CODEC ) { | ||
924 | OSAL_Info("Update the Codec Params after Codec Process call: call xDM control->GetStatus"); | ||
925 | sLretval = VIDENC2_control(pH264VEComp->pVidEncHandle, XDM_GETSTATUS, | ||
926 | (VIDENC2_DynamicParams *)(pH264VEComp->pVidEncDynamicParams), | ||
927 | (IVIDENC2_Status *)(pH264VEComp->pVidEncStatus)); | ||
928 | if( sLretval == (OMX_U32)VIDENC2_EFAIL ) { | ||
929 | OMX_TI_GET_ERROR(pH264VEComp, pH264VEComp->pVidEncOutArgs->videnc2OutArgs.extendedError, eError); | ||
930 | if( eError != OMX_ErrorNone ) { | ||
931 | OSAL_ErrorTrace("Got error 0x%x from the Codec Get Status Control call", eError); | ||
932 | goto UPDATE_PARAMS; | ||
933 | } | ||
934 | } | ||
935 | } | ||
936 | |||
937 | UPDATE_PARAMS: | ||
938 | if( eError == OMX_ErrorNone ) { | ||
939 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
940 | bLCallxDMSetParams = pH264VEComp->bCallxDMSetParams; | ||
941 | if( bLCallxDMSetParams == PARAMS_UPDATED_AT_CODEC ) { | ||
942 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
943 | eError= OMXH264VE_UpdateParams(hComponent); | ||
944 | OSAL_ObtainMutex(pH264VEComp->sBase.pMutex, OSAL_SUSPEND); | ||
945 | pH264VEComp->bCallxDMSetParams = NO_PARAM_CHANGE; | ||
946 | } | ||
947 | OSAL_ReleaseMutex(pH264VEComp->sBase.pMutex); | ||
948 | } | ||
949 | |||
950 | EXIT: | ||
951 | if( retval ) { | ||
952 | *retval = sLretval; | ||
953 | } | ||
954 | |||
955 | return (eError); | ||
956 | } | ||
957 | |||
958 | /* Function to check the max bit rate supported as per profile & level settings*/ | ||
959 | OMX_ERRORTYPE OMXH264VE_CheckBitRateCap(OMX_U32 targetBitRate, OMX_HANDLETYPE hComponent) | ||
960 | { | ||
961 | OMX_COMPONENTTYPE *pHandle = NULL; | ||
962 | OMXH264VidEncComp *pH264VEComp = NULL; | ||
963 | OMX_ERRORTYPE eError = OMX_ErrorNone; | ||
964 | OMX_VIDEO_AVCLEVELTYPE eOMXLevel; | ||
965 | OMX_U32 nTableIndex = 0xFFFFFFFF; | ||
966 | |||
967 | /* Check the input parameters */ | ||
968 | OMX_CHECK((hComponent != NULL), OMX_ErrorBadParameter); | ||
969 | pHandle = (OMX_COMPONENTTYPE *)hComponent; | ||
970 | pH264VEComp = (OMXH264VidEncComp *)pHandle->pComponentPrivate; | ||
971 | OMX_CHECK((pH264VEComp != NULL), OMX_ErrorBadParameter); | ||
972 | |||
973 | MAP_CODEC_TO_OMX_AVCLEVEL(pH264VEComp->pVidEncStaticParams->videnc2Params.level, eOMXLevel, nTableIndex, eError); | ||
974 | OMX_CHECK(eError == OMX_ErrorNone, OMX_ErrorUnsupportedSetting); | ||
975 | OMX_CHECK(nTableIndex != 0xFFFFFFFF, OMX_ErrorUnsupportedSetting); | ||
976 | |||
977 | if( pH264VEComp->pVidEncStaticParams->videnc2Params.profile == IH264_HIGH_PROFILE ) { | ||
978 | ALOGE(" HIGH PROFILE, Level %d Max Bit Rate Supported = %d", eOMXLevel, OMX_H264_HP_BITRATE_SUPPORT[nTableIndex].nMaxBitRateSupport); | ||
979 | OMX_CHECK(targetBitRate <= OMX_H264_HP_BITRATE_SUPPORT[nTableIndex].nMaxBitRateSupport, OMX_ErrorUnsupportedSetting); | ||
980 | } else { | ||
981 | ALOGE(" BASE/MAIN PROFILE, Level %d Max Bit Rate Supported = %d", eOMXLevel, OMX_H264_BP_MP_BITRATE_SUPPORT[nTableIndex].nMaxBitRateSupport); | ||
982 | OMX_CHECK(targetBitRate <= OMX_H264_BP_MP_BITRATE_SUPPORT[nTableIndex].nMaxBitRateSupport, OMX_ErrorUnsupportedSetting); | ||
983 | } | ||
984 | |||
985 | EXIT: | ||
986 | return (eError); | ||
987 | } | ||
988 | |||
989 | |||
diff --git a/libstagefrighthw/omx/videoencode/omx_video_encoder_h264_utils.h b/libstagefrighthw/omx/videoencode/omx_video_encoder_h264_utils.h new file mode 100644 index 0000000..652c448 --- /dev/null +++ b/libstagefrighthw/omx/videoencode/omx_video_encoder_h264_utils.h | |||
@@ -0,0 +1,1129 @@ | |||
1 | /* | ||
2 | * Copyright (C) Texas Instruments - http://www.ti.com/ | ||
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 <string.h> | ||
18 | |||
19 | #include <OMX_Core.h> | ||
20 | #include <OMX_Component.h> | ||
21 | #include <OMX_TI_Custom.h> | ||
22 | |||
23 | #include <OMX_Base.h> | ||
24 | #include <OMX_BaseUtils.h> | ||
25 | |||
26 | #include <libdce.h> | ||
27 | #include <ti/sdo/codecs/h264enc/ih264enc.h> | ||
28 | |||
29 | /* For Baseline Profile :: FLAG to indicate Constrained Baseline profile in the Bitstream generated by codec | ||
30 | conforming to the H264Standard */ | ||
31 | #define OMX_H264_SET_CONSTRAINT_SET1_FLAG 0x14 | ||
32 | #define OMX_H264_SET_CONSTRAINT_SET1b_FLAG 0x15 | ||
33 | #define OMX_H264_DISBALE_ALL_CONSTRAINT_SET_FLAGS 0x0 | ||
34 | |||
35 | /* OMX Component Version */ | ||
36 | #define OMX_H264VE_COMP_VERSION_MAJOR 1 | ||
37 | |||
38 | #define OMX_H264VE_COMP_VERSION_MINOR 1 | ||
39 | |||
40 | #define OMX_H264VE_COMP_VERSION_REVISION 0 | ||
41 | |||
42 | #define OMX_H264VE_COMP_VERSION_STEP 0 | ||
43 | |||
44 | /* OMX Component port numbers */ | ||
45 | #define OMX_H264VE_NUM_PORTS (2) | ||
46 | |||
47 | #define OMX_H264VE_DEFAULT_START_PORT_NUM (0) | ||
48 | |||
49 | #define OMX_H264VE_INPUT_PORT (0) | ||
50 | |||
51 | #define OMX_H264VE_OUTPUT_PORT (1) | ||
52 | |||
53 | /* OMX Component thread related */ | ||
54 | #define OMX_H264VE_DEFAULT_TASKPRIORITY (10) | ||
55 | |||
56 | #define OMX_H264VE_STACKSIZE (1024 * 100) | ||
57 | |||
58 | /* OMX Component and Encoder Name */ | ||
59 | #define OMX_H264VE_COMP_NAME "OMX.ti.ducati.video.encoder" | ||
60 | |||
61 | #define OMX_H264V_ENCODER_NAME "ivahd_h264enc" | ||
62 | |||
63 | /* Default Interframe intervals */ | ||
64 | #define OMX_H264VE_DEFAULT_INTERFRAME_INTERVAL (3) | ||
65 | |||
66 | #define OMX_H264VE_BASELINE_INTERFRAME_INTERVAL (1) | ||
67 | |||
68 | /* OMX Component Buffer defaults */ | ||
69 | #define OMX_H264VE_MIN_OUTPUT_BUFFER_COUNT (2) | ||
70 | |||
71 | #define OMX_H264VE_DEFAULT_OUTPUT_BUFFER_COUNT (OMX_H264VE_MIN_OUTPUT_BUFFER_COUNT + 2) | ||
72 | |||
73 | #define OMX_H264VE_MIN_INPUT_BUFFER_COUNT (OMX_H264VE_DEFAULT_INTERFRAME_INTERVAL) | ||
74 | |||
75 | #define OMX_H264VE_DEFAULT_INPUT_BUFFER_COUNT (OMX_H264VE_MIN_INPUT_BUFFER_COUNT) | ||
76 | |||
77 | /* Default Framerate */ | ||
78 | #define OMX_H264VE_DEFAULT_FRAME_RATE (15) | ||
79 | |||
80 | /* Default Intra Frame Interval */ | ||
81 | #define OMX_H264VE_DEFAULT_INTRAFRAME_INTERVAL (OMX_H264VE_DEFAULT_FRAME_RATE) | ||
82 | |||
83 | /* Default MaxIntra Frame Interval */ | ||
84 | #define OMX_H264VE_DEFAULT_MAXINTRAFRAME_INTERVAL (0x7FFFFFFF) | ||
85 | |||
86 | /* Minimum Bitrate */ | ||
87 | #define OMX_H264VE_MIN_BITRATE (16385) //( > 16*1024) | ||
88 | |||
89 | /* Default Bitrate */ | ||
90 | #define OMX_H264VE_DEFAULT_BITRATE (64000) | ||
91 | |||
92 | /*Default Frame Width */ | ||
93 | #define OMX_H264VE_DEFAULT_FRAME_WIDTH (176) | ||
94 | |||
95 | /* Default Frame Height */ | ||
96 | #define OMX_H264VE_DEFAULT_FRAME_HEIGHT (144) | ||
97 | |||
98 | /* Max Frame width */ | ||
99 | #define OMX_H264VE_MAX_FRAME_WIDTH (1920) | ||
100 | |||
101 | /* Max Frame Height */ | ||
102 | #define OMX_H264VE_MAX_FRAME_HEIGHT (1088) | ||
103 | |||
104 | /* Max Inter Frame Interval */ | ||
105 | #define OMX_H264VE_MAX_INTER_FRAME_INTERVAL (OMX_H264VE_DEFAULT_INTERFRAME_INTERVAL) | ||
106 | |||
107 | /* deafult input buffer size */ | ||
108 | #define OMX_H264VE_DEFAULT_INPUT_BUFFER_SIZE (OMX_H264VE_DEFAULT_FRAME_WIDTH * OMX_H264VE_DEFAULT_FRAME_HEIGHT * 3 / 2) | ||
109 | |||
110 | /* deafult output buffer size */ | ||
111 | #define OMX_H264VE_DEFAULT_OUTPUT_BUFFER_SIZE (OMX_H264VE_DEFAULT_FRAME_WIDTH * OMX_H264VE_DEFAULT_FRAME_HEIGHT * 3 / 2) | ||
112 | /* Assuming encoded frame size will not exceed this size*/ | ||
113 | |||
114 | /* deafult Aspect Ratio Height */ | ||
115 | #define OMX_H264VE_DEFAULT_ASPECT_RATIO_HEIGHT (1) | ||
116 | |||
117 | /* deafult Aspect Ratio Width */ | ||
118 | #define OMX_H264VE_DEFAULT_ASPECT_RATIO_WIDTH (1) | ||
119 | |||
120 | /* default Qp Settings for I frame */ | ||
121 | #define OMX_H264VE_DEFAULT_QP_IFRAME (28) | ||
122 | #define OMX_H264VE_DEFAULT_QPMAX_IFRAME (36) | ||
123 | #define OMX_H264VE_DEFAULT_QPMIN_IFRAME (10) | ||
124 | |||
125 | /* default Qp Settings for P frame */ | ||
126 | #define OMX_H264VE_DEFAULT_QP_PFRAME (28) | ||
127 | #define OMX_H264VE_DEFAULT_QPMAX_PFRAME (40) | ||
128 | #define OMX_H264VE_DEFAULT_QPMIN_PFRAME (10) | ||
129 | |||
130 | /* default Qp Settings for B frame */ | ||
131 | #define OMX_H264VE_DEFAULT_QPOFFSET_BFRAME (4) | ||
132 | #define OMX_H264VE_DEFAULT_QPMAX_BFRAME (44) | ||
133 | #define OMX_H264VE_DEFAULT_QPMIN_BFRAME (10) | ||
134 | |||
135 | /* default Qp Settings for Chroma */ | ||
136 | #define OMX_H264VE_DEFAULT_QPOFFSET_CHROMA (0) | ||
137 | |||
138 | /* default Search Range for P */ | ||
139 | #define OMX_H264VE_DEFAULT_HORSEARCH_PFRAME (144) | ||
140 | #define OMX_H264VE_DEFAULT_VERSEARCH_PFRAME (32) | ||
141 | |||
142 | /* default Search Range for B */ | ||
143 | #define OMX_H264VE_DEFAULT_HORSEARCH_BFRAME (144) | ||
144 | #define OMX_H264VE_DEFAULT_VERSEARCH_BFRAME (16) | ||
145 | |||
146 | /* default Min and Max Pic Size Ratio. Enables Codec to to chose ratio */ | ||
147 | #define OMX_H264VE_DEFAULT_MINPICSIZERATIO (0) | ||
148 | #define OMX_H264VE_DEFAULT_MAXPICSIZERATIOI (20) // codec default is 640 in Q5 format | ||
149 | #define OMX_H264VE_DEFAULT_MAXPICSIZERATIOP (0) | ||
150 | #define OMX_H264VE_DEFAULT_MAXPICSIZERATIOB (0) | ||
151 | |||
152 | /* the header size SPS+PPS */ | ||
153 | #define SPS_PPS_HEADER_DATA_SIZE 0x100 | ||
154 | |||
155 | /* The PARAMS_UPDATE_STATUS enum represents the status of the setconfig call. | ||
156 | * With respect to a process call there are 3 possibilities: | ||
157 | * 1. No params have been changed(no setconfig call has occured) | ||
158 | * 2. Setconfig call has occured but the modified params have not been updated to the codec | ||
159 | * It has been updated only at Ducati | ||
160 | * 3. Setconfig call has occured and the modified params have been updated to the codec | ||
161 | */ | ||
162 | typedef enum PARAMS_UPDATE_STATUS { | ||
163 | NO_PARAM_CHANGE = 0, | ||
164 | PARAMS_UPDATED_AT_OMX = 1, | ||
165 | PARAMS_UPDATED_AT_CODEC = 2, | ||
166 | PARAMS_UPDATE_STATUS_MAX = 0x7FFFFFFF | ||
167 | } PARAMS_UPDATE_STATUS; | ||
168 | |||
169 | /* inline functions */ | ||
170 | #define GET_OMX_RC_ALG(_pCompPvtStruct_, _pParamStruct_, _e_) \ | ||
171 | if((_pCompPvtStruct_->pVidEncStaticParams->rateControlParams.rcAlgo == IH264_RATECONTROL_PRC) && (_pCompPvtStruct_->pVidEncStaticParams->rateControlParams.allowFrameSkip == OMX_FALSE)) { \ | ||
172 | ((OMX_VIDEO_PARAM_BITRATETYPE *)_pParamStruct_)->eControlRate = OMX_Video_ControlRateVariable;\ | ||
173 | _e_=OMX_ErrorNone;\ | ||
174 | } else if((_pCompPvtStruct_->pVidEncStaticParams->rateControlParams.rcAlgo == IH264_RATECONTROL_PRC_LOW_DELAY) && (_pCompPvtStruct_->pVidEncStaticParams->rateControlParams.allowFrameSkip == OMX_FALSE)) { \ | ||
175 | ((OMX_VIDEO_PARAM_BITRATETYPE *)_pParamStruct_)->eControlRate = OMX_Video_ControlRateConstant;\ | ||
176 | _e_=OMX_ErrorNone;\ | ||
177 | } | ||
178 | |||
179 | #define SET_H264CODEC_RC_ALG(_pParamStruct_, _pCompPvtStruct_, _e_) \ | ||
180 | if(((OMX_VIDEO_PARAM_BITRATETYPE *)_pParamStruct_)->eControlRate == OMX_Video_ControlRateVariable ) { \ | ||
181 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.rcAlgo = IH264_RATECONTROL_PRC;\ | ||
182 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.allowFrameSkip = OMX_FALSE;\ | ||
183 | _e_=OMX_ErrorNone;\ | ||
184 | } else if(((OMX_VIDEO_PARAM_BITRATETYPE *)_pParamStruct_)->eControlRate == OMX_Video_ControlRateConstant ) { \ | ||
185 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.rcAlgo = IH264_RATECONTROL_PRC_LOW_DELAY;\ | ||
186 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.allowFrameSkip = OMX_FALSE;\ | ||
187 | _e_=OMX_ErrorNone;\ | ||
188 | } else {\ | ||
189 | _e_=OMX_ErrorUnsupportedSetting;\ | ||
190 | } | ||
191 | |||
192 | #define GET_OMX_AVC_PARAMS(_pCompPvtStruct_, _pParamStruct_) \ | ||
193 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->nSliceHeaderSpacing = 0; /* present code doesn't use this value: set to 0 */\ | ||
194 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->nPFrames = (_pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.intraFrameInterval);\ | ||
195 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->nBFrames = ((_pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.interFrameInterval) - 1);\ | ||
196 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->bUseHadamard = OMX_TRUE; /* Set to OMX_TRUE According to the Spec BUT it is not being Used by the component */\ | ||
197 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->nRefFrames = 1; /* According to the Spec BUT present code doesn't use this value */\ | ||
198 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->nRefIdx10ActiveMinus1 = 1; /* According to Codec Support (2 ref frames for B frame Encoding)but present code doesn't use this value */\ | ||
199 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->nRefIdx11ActiveMinus1 = 1; /* According to Codec Support (2 ref frames for B frame Encoding)but present code doesn't use this value */\ | ||
200 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->bEnableUEP = OMX_FALSE; /* present code doesn't use this value */\ | ||
201 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->bEnableFMO = (((_pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.fmoCodingPreset) == IH264_FMOCODING_NONE) ? OMX_FALSE : OMX_TRUE);\ | ||
202 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->bEnableASO = OMX_FALSE; /* present code doesn't use this value */\ | ||
203 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->bEnableRS = OMX_FALSE; /* present code doesn't use this value */\ | ||
204 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->nAllowedPictureTypes = 3; /* present code doesn't use this value */\ | ||
205 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->bFrameMBsOnly = OMX_TRUE; /* present code doesn't use this value */\ | ||
206 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->bMBAFF = ((_pCompPvtStruct_->pVidEncStaticParams->interlaceCodingType == IH264_INTERLACE_MBAFF) ? OMX_TRUE : OMX_FALSE); /* present code doesn't use this value */\ | ||
207 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->bEntropyCodingCABAC = ((_pCompPvtStruct_->pVidEncStaticParams->entropyCodingMode == IH264_ENTROPYCODING_CABAC) ? OMX_TRUE : OMX_FALSE);\ | ||
208 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->bWeightedPPrediction = OMX_FALSE; /* present code doesn't use this value */\ | ||
209 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->nWeightedBipredicitonMode = OMX_FALSE; /* present code doesn't use this value */\ | ||
210 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->bconstIpred = (((_pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.constrainedIntraPredEnable) == 0) ? OMX_FALSE : OMX_TRUE);\ | ||
211 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->bDirect8x8Inference = OMX_FALSE; /* present code doesn't use this value */\ | ||
212 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->bDirectSpatialTemporal = OMX_FALSE; /* present code doesn't use this value */\ | ||
213 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->nCabacInitIdc = 0; /* present code doesn't use this value */ | ||
214 | |||
215 | |||
216 | #define SET_H264CODEC_PARAMS_FROM_AVC(_pParamStruct_, _pCompPvtStruct_) \ | ||
217 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.intraFrameInterval = ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->nPFrames;\ | ||
218 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.maxInterFrameInterval = (((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->nBFrames + 1);\ | ||
219 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.interFrameInterval = (((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->nBFrames + 1);\ | ||
220 | _pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.fmoCodingPreset = ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->bEnableFMO;\ | ||
221 | _pCompPvtStruct_->pVidEncStaticParams->entropyCodingMode = ((((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->bEntropyCodingCABAC) ? IH264_ENTROPYCODING_CABAC : IH264_ENTROPYCODING_CAVLC);\ | ||
222 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.constrainedIntraPredEnable = ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->bconstIpred;\ | ||
223 | _pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.constrainedIntraPredEnable = ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->bconstIpred;\ | ||
224 | if( _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.constrainedIntraPredEnable ) {\ | ||
225 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.intraCodingPreset = IH264_INTRACODING_USERDEFINED;\ | ||
226 | } | ||
227 | |||
228 | #define GET_OMX_AVC_PROFILE(_pCompPvtStruct_, _pParamStruct_, _e_)\ | ||
229 | switch( _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.profile ) {\ | ||
230 | case IH264_BASELINE_PROFILE :\ | ||
231 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eProfile = OMX_VIDEO_AVCProfileBaseline;\ | ||
232 | break;\ | ||
233 | case IH264_MAIN_PROFILE :\ | ||
234 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eProfile = OMX_VIDEO_AVCProfileMain;\ | ||
235 | break;\ | ||
236 | case IH264_HIGH_PROFILE :\ | ||
237 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eProfile = OMX_VIDEO_AVCProfileHigh;\ | ||
238 | break;\ | ||
239 | case IH264_EXTENDED_PROFILE :\ | ||
240 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eProfile = OMX_VIDEO_AVCProfileExtended;\ | ||
241 | break;\ | ||
242 | case IH264_HIGH10_PROFILE :\ | ||
243 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eProfile = OMX_VIDEO_AVCProfileHigh10;\ | ||
244 | break;\ | ||
245 | case IH264_HIGH422_PROFILE :\ | ||
246 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eProfile = OMX_VIDEO_AVCProfileHigh422;\ | ||
247 | break;\ | ||
248 | default :\ | ||
249 | _e_= OMX_ErrorNoMore;\ | ||
250 | break;\ | ||
251 | } | ||
252 | |||
253 | #define SET_H264CODEC_PROFILE(_pParamStruct_, _pCompPvtStruct_, _e_) \ | ||
254 | switch(((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eProfile ) {\ | ||
255 | case OMX_VIDEO_AVCProfileBaseline :\ | ||
256 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.profile = IH264_BASELINE_PROFILE;\ | ||
257 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.scalingMatrixPreset = IH264_SCALINGMATRIX_NONE;\ | ||
258 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.scalingMatrixPreset = IH264_SCALINGMATRIX_NONE;\ | ||
259 | _pCompPvtStruct_->pVidEncStaticParams->constraintSetFlags = OMX_H264_SET_CONSTRAINT_SET1_FLAG;\ | ||
260 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.maxInterFrameInterval = OMX_H264VE_BASELINE_INTERFRAME_INTERVAL;\ | ||
261 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.interFrameInterval = OMX_H264VE_BASELINE_INTERFRAME_INTERVAL;\ | ||
262 | _pCompPvtStruct_->pVidEncStaticParams->entropyCodingMode = IH264_ENTROPYCODING_CAVLC;\ | ||
263 | _pCompPvtStruct_->pVidEncStaticParams->transformBlockSize = IH264_TRANSFORM_4x4;\ | ||
264 | break;\ | ||
265 | case OMX_VIDEO_AVCProfileMain :\ | ||
266 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.profile =IH264_MAIN_PROFILE;\ | ||
267 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.scalingMatrixPreset = IH264_SCALINGMATRIX_NONE;\ | ||
268 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.scalingMatrixPreset = IH264_SCALINGMATRIX_NONE;\ | ||
269 | _pCompPvtStruct_->pVidEncStaticParams->constraintSetFlags = OMX_H264_DISBALE_ALL_CONSTRAINT_SET_FLAGS;\ | ||
270 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.maxInterFrameInterval = OMX_H264VE_DEFAULT_INTERFRAME_INTERVAL;\ | ||
271 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.interFrameInterval = OMX_H264VE_DEFAULT_INTERFRAME_INTERVAL;\ | ||
272 | _pCompPvtStruct_->pVidEncStaticParams->entropyCodingMode = IH264_ENTROPYCODING_CABAC;\ | ||
273 | _pCompPvtStruct_->pVidEncStaticParams->transformBlockSize = IH264_TRANSFORM_4x4;\ | ||
274 | break;\ | ||
275 | case OMX_VIDEO_AVCProfileHigh :\ | ||
276 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.profile=IH264_HIGH_PROFILE;\ | ||
277 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.scalingMatrixPreset = IH264_SCALINGMATRIX_NORMAL;\ | ||
278 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.scalingMatrixPreset = IH264_SCALINGMATRIX_NORMAL;\ | ||
279 | _pCompPvtStruct_->pVidEncStaticParams->constraintSetFlags = OMX_H264_DISBALE_ALL_CONSTRAINT_SET_FLAGS;\ | ||
280 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.maxInterFrameInterval = OMX_H264VE_DEFAULT_INTERFRAME_INTERVAL;\ | ||
281 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.interFrameInterval = OMX_H264VE_DEFAULT_INTERFRAME_INTERVAL;\ | ||
282 | _pCompPvtStruct_->pVidEncStaticParams->entropyCodingMode = IH264_ENTROPYCODING_CABAC;\ | ||
283 | _pCompPvtStruct_->pVidEncStaticParams->transformBlockSize = IH264_TRANSFORM_ADAPTIVE;\ | ||
284 | break;\ | ||
285 | case OMX_VIDEO_AVCProfileExtended :\ | ||
286 | case OMX_VIDEO_AVCProfileHigh10 :\ | ||
287 | case OMX_VIDEO_AVCProfileHigh422 :\ | ||
288 | default :\ | ||
289 | _e_= OMX_ErrorUnsupportedSetting;\ | ||
290 | break;\ | ||
291 | } | ||
292 | |||
293 | |||
294 | #define GET_OMX_AVC_LEVEL(_pCompPvtStruct_, _pParamStruct_, _e_)\ | ||
295 | switch( _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.level ) {\ | ||
296 | case IH264_LEVEL_10 :\ | ||
297 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLevel = OMX_VIDEO_AVCLevel1;\ | ||
298 | break;\ | ||
299 | case IH264_LEVEL_1b :\ | ||
300 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLevel = OMX_VIDEO_AVCLevel1b;\ | ||
301 | break;\ | ||
302 | case IH264_LEVEL_11 :\ | ||
303 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLevel = OMX_VIDEO_AVCLevel11;\ | ||
304 | break;\ | ||
305 | case IH264_LEVEL_12 :\ | ||
306 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLevel = OMX_VIDEO_AVCLevel12;\ | ||
307 | break;\ | ||
308 | case IH264_LEVEL_13 :\ | ||
309 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLevel = OMX_VIDEO_AVCLevel13;\ | ||
310 | break;\ | ||
311 | case IH264_LEVEL_20 :\ | ||
312 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLevel = OMX_VIDEO_AVCLevel2;\ | ||
313 | break;\ | ||
314 | case IH264_LEVEL_21 :\ | ||
315 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLevel = OMX_VIDEO_AVCLevel21;\ | ||
316 | break;\ | ||
317 | case IH264_LEVEL_22 :\ | ||
318 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLevel = OMX_VIDEO_AVCLevel22;\ | ||
319 | break;\ | ||
320 | case IH264_LEVEL_30 :\ | ||
321 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLevel = OMX_VIDEO_AVCLevel3;\ | ||
322 | break;\ | ||
323 | case IH264_LEVEL_31 :\ | ||
324 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLevel = OMX_VIDEO_AVCLevel31;\ | ||
325 | break;\ | ||
326 | case IH264_LEVEL_32 :\ | ||
327 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLevel = OMX_VIDEO_AVCLevel32;\ | ||
328 | break;\ | ||
329 | case IH264_LEVEL_40 :\ | ||
330 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLevel = OMX_VIDEO_AVCLevel4;\ | ||
331 | break;\ | ||
332 | case IH264_LEVEL_41 :\ | ||
333 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLevel = OMX_VIDEO_AVCLevel41;\ | ||
334 | break;\ | ||
335 | case IH264_LEVEL_42 :\ | ||
336 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLevel = OMX_VIDEO_AVCLevel42;\ | ||
337 | break;\ | ||
338 | case IH264_LEVEL_50 :\ | ||
339 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLevel = OMX_VIDEO_AVCLevel5;\ | ||
340 | break;\ | ||
341 | case IH264_LEVEL_51 :\ | ||
342 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLevel = OMX_VIDEO_AVCLevel51;\ | ||
343 | break;\ | ||
344 | default :\ | ||
345 | _e_= OMX_ErrorNoMore;\ | ||
346 | break;\ | ||
347 | } | ||
348 | |||
349 | #define SET_H264CODEC_LEVEL(_pParamStruct_, _pCompPvtStruct_, _e_)\ | ||
350 | switch(((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLevel ) {\ | ||
351 | case OMX_VIDEO_AVCLevel1 :\ | ||
352 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.level = IH264_LEVEL_10;\ | ||
353 | break;\ | ||
354 | case OMX_VIDEO_AVCLevel1b :\ | ||
355 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.level = IH264_LEVEL_1b;\ | ||
356 | if (((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eProfile == OMX_VIDEO_AVCProfileBaseline) {\ | ||
357 | _pCompPvtStruct_->pVidEncStaticParams->constraintSetFlags = OMX_H264_SET_CONSTRAINT_SET1b_FLAG;\ | ||
358 | }\ | ||
359 | break;\ | ||
360 | case OMX_VIDEO_AVCLevel11 :\ | ||
361 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.level = IH264_LEVEL_11;\ | ||
362 | break;\ | ||
363 | case OMX_VIDEO_AVCLevel12 :\ | ||
364 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.level = IH264_LEVEL_12;\ | ||
365 | break;\ | ||
366 | case OMX_VIDEO_AVCLevel13 :\ | ||
367 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.level = IH264_LEVEL_13;\ | ||
368 | break;\ | ||
369 | case OMX_VIDEO_AVCLevel2 :\ | ||
370 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.level = IH264_LEVEL_20;\ | ||
371 | break;\ | ||
372 | case OMX_VIDEO_AVCLevel21 :\ | ||
373 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.level = IH264_LEVEL_21;\ | ||
374 | break;\ | ||
375 | case OMX_VIDEO_AVCLevel22 :\ | ||
376 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.level = IH264_LEVEL_22;\ | ||
377 | break;\ | ||
378 | case OMX_VIDEO_AVCLevel3 :\ | ||
379 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.level = IH264_LEVEL_30;\ | ||
380 | break;\ | ||
381 | case OMX_VIDEO_AVCLevel31 :\ | ||
382 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.level = IH264_LEVEL_31;\ | ||
383 | break;\ | ||
384 | case OMX_VIDEO_AVCLevel32 :\ | ||
385 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.level = IH264_LEVEL_32;\ | ||
386 | break;\ | ||
387 | case OMX_VIDEO_AVCLevel4 :\ | ||
388 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.level = IH264_LEVEL_40;\ | ||
389 | break;\ | ||
390 | case OMX_VIDEO_AVCLevel41 :\ | ||
391 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.level = IH264_LEVEL_41;\ | ||
392 | break;\ | ||
393 | case OMX_VIDEO_AVCLevel42 :\ | ||
394 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.level = IH264_LEVEL_42;\ | ||
395 | break;\ | ||
396 | case OMX_VIDEO_AVCLevel5 :\ | ||
397 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.level = IH264_LEVEL_50;\ | ||
398 | break;\ | ||
399 | case OMX_VIDEO_AVCLevel51 :\ | ||
400 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.level = IH264_LEVEL_51;\ | ||
401 | break;\ | ||
402 | default :\ | ||
403 | _e_= OMX_ErrorUnsupportedSetting;\ | ||
404 | break;\ | ||
405 | } | ||
406 | |||
407 | #define GET_OMX_AVC_LFMODE(_pCompPvtStruct_, _pParamStruct_, _e_)\ | ||
408 | if((_pCompPvtStruct_->pVidEncStaticParams->loopFilterParams.loopfilterDisableIDC == IH264_DISABLE_FILTER_NONE) || (_pCompPvtStruct_->pVidEncStaticParams->loopFilterParams.loopfilterDisableIDC == IH264_DISABLE_FILTER_DEFAULT)) {\ | ||
409 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLoopFilterMode = OMX_VIDEO_AVCLoopFilterEnable;\ | ||
410 | } else if( _pCompPvtStruct_->pVidEncStaticParams->loopFilterParams.loopfilterDisableIDC == IH264_DISABLE_FILTER_ALL_EDGES ) {\ | ||
411 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLoopFilterMode = OMX_VIDEO_AVCLoopFilterDisable;\ | ||
412 | } else if( _pCompPvtStruct_->pVidEncStaticParams->loopFilterParams.loopfilterDisableIDC == IH264_DISABLE_FILTER_SLICE_EDGES ) {\ | ||
413 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLoopFilterMode = OMX_VIDEO_AVCLoopFilterDisableSliceBoundary;\ | ||
414 | } else {\ | ||
415 | ((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLoopFilterMode = OMX_VIDEO_AVCLoopFilterMax;\ | ||
416 | _e_= OMX_ErrorNoMore;\ | ||
417 | } | ||
418 | |||
419 | |||
420 | #define SET_H264CODEC_LFMODE(_pParamStruct_, _pCompPvtStruct_, _e_)\ | ||
421 | if(((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLoopFilterMode == OMX_VIDEO_AVCLoopFilterEnable ) {\ | ||
422 | _pCompPvtStruct_->pVidEncStaticParams->loopFilterParams.loopfilterDisableIDC = IH264_DISABLE_FILTER_NONE;\ | ||
423 | } else if(((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLoopFilterMode == OMX_VIDEO_AVCLoopFilterDisable ) {\ | ||
424 | _pCompPvtStruct_->pVidEncStaticParams->loopFilterParams.loopfilterDisableIDC = IH264_DISABLE_FILTER_ALL_EDGES;\ | ||
425 | _pCompPvtStruct_->pVidEncStaticParams->loopFilterParams.loopfilterPreset = 1;\ | ||
426 | } else if(((OMX_VIDEO_PARAM_AVCTYPE *)_pParamStruct_)->eLoopFilterMode == OMX_VIDEO_AVCLoopFilterDisableSliceBoundary ) {\ | ||
427 | _pCompPvtStruct_->pVidEncStaticParams->loopFilterParams.loopfilterDisableIDC = IH264_DISABLE_FILTER_SLICE_EDGES;\ | ||
428 | _pCompPvtStruct_->pVidEncStaticParams->loopFilterParams.loopfilterPreset = 1;\ | ||
429 | } else {\ | ||
430 | _pCompPvtStruct_->pVidEncStaticParams->loopFilterParams.loopfilterDisableIDC = IH264_DISABLE_FILTER_MAX;\ | ||
431 | _e_= OMX_ErrorUnsupportedSetting;\ | ||
432 | } | ||
433 | |||
434 | #define GET_OMX_FMO_SLIGRPMAPTYPE(_pCompPvtStruct_, _pParamStruct_, _e_)\ | ||
435 | if( _pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.sliceGroupMapType == IH264_INTERLEAVED_SLICE_GRP ) {\ | ||
436 | ((OMX_VIDEO_PARAM_AVCSLICEFMO *)_pParamStruct_)->nSliceGroupMapType = 0;\ | ||
437 | } else if( _pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.sliceGroupMapType == IH264_DISPERSED_SLICE_GRP ) {\ | ||
438 | ((OMX_VIDEO_PARAM_AVCSLICEFMO *)_pParamStruct_)->nSliceGroupMapType = 1;\ | ||
439 | } else if((_pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.sliceGroupMapType == IH264_SLICE_GRP_MAP_DEFAULT) || (_pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.sliceGroupMapType == IH264_RASTER_SCAN_SLICE_GRP)) {\ | ||
440 | ((OMX_VIDEO_PARAM_AVCSLICEFMO *)_pParamStruct_)->nSliceGroupMapType = 2;\ | ||
441 | } else if( _pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.sliceGroupMapType == IH264_FOREGRND_WITH_LEFTOVER_SLICE_GRP ) {\ | ||
442 | ((OMX_VIDEO_PARAM_AVCSLICEFMO *)_pParamStruct_)->nSliceGroupMapType = 3;\ | ||
443 | } else if( _pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.sliceGroupMapType == IH264_BOX_OUT_SLICE_GRP ) {\ | ||
444 | ((OMX_VIDEO_PARAM_AVCSLICEFMO *)_pParamStruct_)->nSliceGroupMapType = 4;\ | ||
445 | } else if( _pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.sliceGroupMapType == IH264_WIPE_SLICE_GRP ) {\ | ||
446 | ((OMX_VIDEO_PARAM_AVCSLICEFMO *)_pParamStruct_)->nSliceGroupMapType = 5;\ | ||
447 | } else if( _pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.sliceGroupMapType == IH264_EXPLICIT_SLICE_GRP ) {\ | ||
448 | ((OMX_VIDEO_PARAM_AVCSLICEFMO *)_pParamStruct_)->nSliceGroupMapType = 6;\ | ||
449 | } else {\ | ||
450 | _e_= OMX_ErrorNoMore;\ | ||
451 | } | ||
452 | |||
453 | #define SET_H264CODEC_FMO_SLIGRPMAPTYPE(_pParamStruct_, _pCompPvtStruct_, _e_)\ | ||
454 | if(((OMX_VIDEO_PARAM_AVCSLICEFMO *)_pParamStruct_)->nSliceGroupMapType == 0 ) {\ | ||
455 | _pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.sliceGroupMapType = IH264_INTERLEAVED_SLICE_GRP;\ | ||
456 | } else if(((OMX_VIDEO_PARAM_AVCSLICEFMO *)_pParamStruct_)->nSliceGroupMapType == 1 ) {\ | ||
457 | _pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.sliceGroupMapType = IH264_DISPERSED_SLICE_GRP;\ | ||
458 | } else if(((OMX_VIDEO_PARAM_AVCSLICEFMO *)_pParamStruct_)->nSliceGroupMapType == 2 ) {\ | ||
459 | _pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.sliceGroupMapType = IH264_RASTER_SCAN_SLICE_GRP;\ | ||
460 | } else if(((OMX_VIDEO_PARAM_AVCSLICEFMO *)_pParamStruct_)->nSliceGroupMapType == 3 ) {\ | ||
461 | _pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.sliceGroupMapType = IH264_FOREGRND_WITH_LEFTOVER_SLICE_GRP;\ | ||
462 | } else if(((OMX_VIDEO_PARAM_AVCSLICEFMO *)_pParamStruct_)->nSliceGroupMapType == 4 ) {\ | ||
463 | _pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.sliceGroupMapType = IH264_BOX_OUT_SLICE_GRP;\ | ||
464 | } else if(((OMX_VIDEO_PARAM_AVCSLICEFMO *)_pParamStruct_)->nSliceGroupMapType == 5 ) {\ | ||
465 | _pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.sliceGroupMapType = IH264_WIPE_SLICE_GRP;\ | ||
466 | } else if(((OMX_VIDEO_PARAM_AVCSLICEFMO *)_pParamStruct_)->nSliceGroupMapType == 6 ) {\ | ||
467 | _pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.sliceGroupMapType = IH264_EXPLICIT_SLICE_GRP;\ | ||
468 | } else {\ | ||
469 | _e_= OMX_ErrorUnsupportedSetting;\ | ||
470 | } | ||
471 | |||
472 | #define GET_OMX_FMO_SLICEMODE(_pCompPvtStruct_, _pParamStruct_, _e_)\ | ||
473 | if((_pCompPvtStruct_->pVidEncStaticParams->sliceCodingParams.sliceMode == IH264_SLICEMODE_NONE) || (_pCompPvtStruct_->pVidEncStaticParams->sliceCodingParams.sliceMode == IH264_SLICEMODE_DEFAULT)) {\ | ||
474 | ((OMX_VIDEO_PARAM_AVCSLICEFMO *)_pParamStruct_)->eSliceMode = OMX_VIDEO_SLICEMODE_AVCDefault;\ | ||
475 | } else if( _pCompPvtStruct_->pVidEncStaticParams->sliceCodingParams.sliceMode == IH264_SLICEMODE_MBUNIT ) {\ | ||
476 | ((OMX_VIDEO_PARAM_AVCSLICEFMO *)_pParamStruct_)->eSliceMode = OMX_VIDEO_SLICEMODE_AVCMBSlice;\ | ||
477 | } else if( _pCompPvtStruct_->pVidEncStaticParams->sliceCodingParams.sliceMode == IH264_SLICEMODE_BYTES ) {\ | ||
478 | ((OMX_VIDEO_PARAM_AVCSLICEFMO *)_pParamStruct_)->eSliceMode = OMX_VIDEO_SLICEMODE_AVCByteSlice;\ | ||
479 | } else {\ | ||
480 | _e_= OMX_ErrorNoMore;\ | ||
481 | } | ||
482 | |||
483 | #define SET_H264CODEC_SLICEMODE(_pParamStruct_, _pCompPvtStruct_, _e_)\ | ||
484 | if(((OMX_VIDEO_PARAM_AVCSLICEFMO *)_pParamStruct_)->eSliceMode == OMX_VIDEO_SLICEMODE_AVCDefault ) {\ | ||
485 | _pCompPvtStruct_->pVidEncStaticParams->sliceCodingParams.sliceMode = IH264_SLICEMODE_DEFAULT;\ | ||
486 | } else if(((OMX_VIDEO_PARAM_AVCSLICEFMO *)_pParamStruct_)->eSliceMode == OMX_VIDEO_SLICEMODE_AVCMBSlice ) {\ | ||
487 | _pCompPvtStruct_->pVidEncStaticParams->sliceCodingParams.sliceMode = IH264_SLICEMODE_MBUNIT;\ | ||
488 | _pCompPvtStruct_->pVidEncStaticParams->sliceCodingParams.sliceCodingPreset=1;\ | ||
489 | } else if(((OMX_VIDEO_PARAM_AVCSLICEFMO *)_pParamStruct_)->eSliceMode == OMX_VIDEO_SLICEMODE_AVCByteSlice ) {\ | ||
490 | _pCompPvtStruct_->pVidEncStaticParams->sliceCodingParams.sliceMode = IH264_SLICEMODE_BYTES;\ | ||
491 | _pCompPvtStruct_->pVidEncStaticParams->sliceCodingParams.sliceCodingPreset = 1;\ | ||
492 | } else {\ | ||
493 | _e_= OMX_ErrorUnsupportedSetting;\ | ||
494 | } | ||
495 | |||
496 | #define GET_OMX_INTRAREFRESHMODE(_pCompPvtStruct_, _pParamStruct_, _e_)\ | ||
497 | if((_pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.intraRefreshMethod == IH264_INTRAREFRESH_NONE) || (_pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.intraRefreshMethod == IH264_INTRAREFRESH_DEFAULT) || (_pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.intraRefreshMethod == IH264_INTRAREFRESH_MAX)) {\ | ||
498 | ((OMX_VIDEO_PARAM_INTRAREFRESHTYPE *)_pParamStruct_)->eRefreshMode = OMX_VIDEO_IntraRefreshMax;\ | ||
499 | ((OMX_VIDEO_PARAM_INTRAREFRESHTYPE *)_pParamStruct_)->nAirMBs = 0;\ | ||
500 | ((OMX_VIDEO_PARAM_INTRAREFRESHTYPE *)_pParamStruct_)->nAirRef = 0;\ | ||
501 | ((OMX_VIDEO_PARAM_INTRAREFRESHTYPE *)_pParamStruct_)->nCirMBs = 0;\ | ||
502 | } else if( _pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.intraRefreshMethod == IH264_INTRAREFRESH_CYCLIC_MBS ) {\ | ||
503 | ((OMX_VIDEO_PARAM_INTRAREFRESHTYPE *)_pParamStruct_)->eRefreshMode = OMX_VIDEO_IntraRefreshAdaptive;\ | ||
504 | ((OMX_VIDEO_PARAM_INTRAREFRESHTYPE *)_pParamStruct_)->nAirMBs = ((_pCompPvtStruct_->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nFrameWidth) * (_pCompPvtStruct_->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nFrameHeight)) / ((_pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.intraRefreshRate) * 256);\ | ||
505 | ((OMX_VIDEO_PARAM_INTRAREFRESHTYPE *)_pParamStruct_)->nAirRef = 0;\ | ||
506 | ((OMX_VIDEO_PARAM_INTRAREFRESHTYPE *)_pParamStruct_)->nCirMBs = 0;\ | ||
507 | } else {\ | ||
508 | _e_= OMX_ErrorNoMore;\ | ||
509 | } | ||
510 | |||
511 | #define SET_H264CODEC_INTRAREFRESHMODE(_pParamStruct_, _pCompPvtStruct_, _e_)\ | ||
512 | if(((OMX_VIDEO_PARAM_INTRAREFRESHTYPE *)_pParamStruct_)->eRefreshMode == OMX_VIDEO_IntraRefreshAdaptive ) {\ | ||
513 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.intraCodingPreset = IH264_INTRACODING_USERDEFINED;\ | ||
514 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.intraRefreshMethod = IH264_INTRAREFRESH_CYCLIC_MBS;\ | ||
515 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.intraRefreshRate = ((_pCompPvtStruct_->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nFrameWidth) * (_pCompPvtStruct_->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.nFrameHeight)) / (((OMX_VIDEO_PARAM_INTRAREFRESHTYPE *)_pParamStruct_)->nAirMBs * 256);\ | ||
516 | _pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.intraRefreshMethod = IH264_INTRAREFRESH_CYCLIC_MBS;\ | ||
517 | _pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.intraRefreshRate = _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.intraRefreshRate;\ | ||
518 | } else if(((OMX_VIDEO_PARAM_INTRAREFRESHTYPE *)_pParamStruct_)->eRefreshMode == OMX_VIDEO_IntraRefreshMax ) {\ | ||
519 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.intraCodingPreset = IH264_INTRACODING_USERDEFINED;\ | ||
520 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.intraRefreshMethod = IH264_INTRAREFRESH_NONE;\ | ||
521 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.intraRefreshRate = 0;\ | ||
522 | _pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.intraRefreshMethod = IH264_INTRAREFRESH_NONE;\ | ||
523 | _pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.intraRefreshRate = 0;\ | ||
524 | } else {\ | ||
525 | _e_= OMX_ErrorUnsupportedSetting;\ | ||
526 | } | ||
527 | |||
528 | |||
529 | /*Set the Codec Chroma Format*/ | ||
530 | #define GET_OMX_COLORFORMAT(_pCompPvtStruct_, _e_)\ | ||
531 | if((_pCompPvtStruct_->pVidEncStaticParams->videnc2Params.inputChromaFormat == XDM_YUV_420SP)) {\ | ||
532 | _pCompPvtStruct_->sBase.pPorts[OMX_H264VE_INPUT_PORT]->sPortDef.format.video.eColorFormat = OMX_TI_COLOR_FormatYUV420PackedSemiPlanar;\ | ||
533 | } else {\ | ||
534 | _e_ = OMX_ErrorNoMore; } | ||
535 | |||
536 | #define SET_H264CODEC_CHROMAFORMAT(_pPortdefStruct_, _pCompPvtStruct_, _e_)\ | ||
537 | if((_pPortdefStruct_->format.video.eColorFormat) == OMX_TI_COLOR_FormatYUV420PackedSemiPlanar ||\ | ||
538 | (_pPortdefStruct_->format.video.eColorFormat) == OMX_COLOR_FormatAndroidOpaque ||\ | ||
539 | (_pPortdefStruct_->format.video.eColorFormat) == OMX_COLOR_FormatYUV420Flexible) {\ | ||
540 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.inputChromaFormat = XDM_YUV_420SP;\ | ||
541 | } else {\ | ||
542 | _e_= OMX_ErrorUnsupportedSetting; } | ||
543 | |||
544 | |||
545 | #define SET_H264CODEC_DEFAULT_IVIDENC2_PARAMS(_pCompPvtStruct_, _i_)\ | ||
546 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.size = sizeof(IH264ENC_Params);\ | ||
547 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.encodingPreset = XDM_USER_DEFINED;\ | ||
548 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.rateControlPreset = IVIDEO_USER_DEFINED;\ | ||
549 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.maxHeight = OMX_H264VE_DEFAULT_FRAME_HEIGHT;\ | ||
550 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.maxWidth = OMX_H264VE_DEFAULT_FRAME_WIDTH;\ | ||
551 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.dataEndianness = XDM_BYTE;\ | ||
552 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.maxBitRate = -1;\ | ||
553 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.minBitRate = 0;\ | ||
554 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.inputChromaFormat = XDM_YUV_420SP;\ | ||
555 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.inputContentType = IVIDEO_PROGRESSIVE;\ | ||
556 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.operatingMode = IVIDEO_ENCODE_ONLY;\ | ||
557 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.profile = IH264_HIGH_PROFILE;\ | ||
558 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.level = IH264_LEVEL_42;\ | ||
559 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.maxInterFrameInterval =OMX_H264VE_MAX_INTER_FRAME_INTERVAL;\ | ||
560 | if( _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.profile == IH264_BASELINE_PROFILE ) {\ | ||
561 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.maxInterFrameInterval = OMX_H264VE_BASELINE_INTERFRAME_INTERVAL;\ | ||
562 | }\ | ||
563 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.inputDataMode = IVIDEO_ENTIREFRAME;\ | ||
564 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.outputDataMode = IVIDEO_ENTIREFRAME;\ | ||
565 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.numInputDataUnits = 1;\ | ||
566 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.numOutputDataUnits = 1;\ | ||
567 | for( _i_ = 0; _i_ < IVIDEO_MAX_NUM_METADATA_PLANES; _i_++ ) {\ | ||
568 | _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.metadataType[_i_] = IVIDEO_METADATAPLANE_NONE;\ | ||
569 | } | ||
570 | |||
571 | |||
572 | #define SET_H264CODEC_DEFAULT_STATIC_IH264ENC_RATECONTROLPARAMS(_pCompPvtStruct_)\ | ||
573 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.rateControlParamsPreset=IH264_RATECONTROLPARAMS_DEFAULT;\ | ||
574 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.scalingMatrixPreset = IH264_SCALINGMATRIX_NORMAL;\ | ||
575 | if( _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.profile != IH264_HIGH_PROFILE ) {\ | ||
576 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.scalingMatrixPreset = IH264_SCALINGMATRIX_NONE;\ | ||
577 | }\ | ||
578 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.rcAlgo = IH264_RATECONTROL_DEFAULT;\ | ||
579 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.qpI = OMX_H264VE_DEFAULT_QP_IFRAME;\ | ||
580 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.qpMaxI = OMX_H264VE_DEFAULT_QPMAX_IFRAME;\ | ||
581 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.qpMinI = OMX_H264VE_DEFAULT_QPMIN_IFRAME;\ | ||
582 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.qpP = OMX_H264VE_DEFAULT_QP_PFRAME;\ | ||
583 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.qpMaxP = OMX_H264VE_DEFAULT_QPMAX_PFRAME;\ | ||
584 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.qpMinP = OMX_H264VE_DEFAULT_QPMIN_PFRAME;\ | ||
585 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.qpOffsetB = OMX_H264VE_DEFAULT_QPOFFSET_BFRAME;\ | ||
586 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.qpMaxB = OMX_H264VE_DEFAULT_QPMAX_BFRAME;\ | ||
587 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.qpMinB = OMX_H264VE_DEFAULT_QPMIN_BFRAME;\ | ||
588 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.allowFrameSkip = OMX_FALSE;\ | ||
589 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.removeExpensiveCoeff = OMX_FALSE;\ | ||
590 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.chromaQPIndexOffset = OMX_H264VE_DEFAULT_QPOFFSET_CHROMA;\ | ||
591 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.IPQualityFactor = IH264_QUALITY_FACTOR_DEFAULT;\ | ||
592 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.HRDBufferSize = OMX_H264VE_DEFAULT_BITRATE;\ | ||
593 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.initialBufferLevel = pH264VEComp->pVidEncStaticParams->rateControlParams.HRDBufferSize;\ | ||
594 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.minPicSizeRatioI = OMX_H264VE_DEFAULT_MINPICSIZERATIO;\ | ||
595 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.maxPicSizeRatioI = OMX_H264VE_DEFAULT_MAXPICSIZERATIOI;\ | ||
596 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.minPicSizeRatioP = OMX_H264VE_DEFAULT_MINPICSIZERATIO;\ | ||
597 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.maxPicSizeRatioP = OMX_H264VE_DEFAULT_MAXPICSIZERATIOP;\ | ||
598 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.minPicSizeRatioB = OMX_H264VE_DEFAULT_MINPICSIZERATIO;\ | ||
599 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.maxPicSizeRatioB = OMX_H264VE_DEFAULT_MAXPICSIZERATIOB;\ | ||
600 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.enablePRC = 1;\ | ||
601 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.enablePartialFrameSkip = 0;\ | ||
602 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.discardSavedBits = 0;\ | ||
603 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.reserved = 0;\ | ||
604 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.VBRDuration = 8;\ | ||
605 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.VBRsensitivity = 0;\ | ||
606 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.skipDistributionWindowLength = 5;\ | ||
607 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.numSkipInDistributionWindow = 1;\ | ||
608 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.enableHRDComplianceMode = 1;\ | ||
609 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.frameSkipThMulQ5 = 0;\ | ||
610 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.vbvUseLevelThQ5 = 0;\ | ||
611 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.reservedRC[0] = 0;\ | ||
612 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.reservedRC[1] = 0;\ | ||
613 | _pCompPvtStruct_->pVidEncStaticParams->rateControlParams.reservedRC[2] = 0; | ||
614 | |||
615 | #define SET_H264CODEC_DEFAULT_STATIC_IH264ENC_INTERCODINGPARAMS(_pCompPvtStruct_)\ | ||
616 | _pCompPvtStruct_->pVidEncStaticParams->interCodingParams.interCodingPreset=IH264_INTERCODING_DEFAULT;\ | ||
617 | _pCompPvtStruct_->pVidEncStaticParams->interCodingParams.searchRangeHorP = OMX_H264VE_DEFAULT_HORSEARCH_PFRAME;\ | ||
618 | _pCompPvtStruct_->pVidEncStaticParams->interCodingParams.searchRangeVerP = OMX_H264VE_DEFAULT_VERSEARCH_PFRAME;\ | ||
619 | _pCompPvtStruct_->pVidEncStaticParams->interCodingParams.searchRangeHorB = OMX_H264VE_DEFAULT_HORSEARCH_BFRAME;\ | ||
620 | _pCompPvtStruct_->pVidEncStaticParams->interCodingParams.searchRangeVerB = OMX_H264VE_DEFAULT_VERSEARCH_BFRAME;\ | ||
621 | _pCompPvtStruct_->pVidEncStaticParams->interCodingParams.interCodingBias = IH264_BIASFACTOR_DEFAULT;\ | ||
622 | _pCompPvtStruct_->pVidEncStaticParams->interCodingParams.skipMVCodingBias = IH264_BIASFACTOR_DEFAULT;\ | ||
623 | _pCompPvtStruct_->pVidEncStaticParams->interCodingParams.minBlockSizeP = IH264_BLOCKSIZE_DEFAULT;\ | ||
624 | _pCompPvtStruct_->pVidEncStaticParams->interCodingParams.minBlockSizeB = IH264_BLOCKSIZE_DEFAULT;\ | ||
625 | _pCompPvtStruct_->pVidEncStaticParams->interCodingParams.meAlgoMode = IH264ENC_MOTIONESTMODE_DEFAULT; | ||
626 | |||
627 | |||
628 | #define SET_H264CODEC_DEFAULT_STATIC_IH264ENC_INTRACODINGPARAMS(_pCompPvtStruct_)\ | ||
629 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.intraCodingPreset = IH264_INTRACODING_DEFAULT;\ | ||
630 | if( _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.profile != IH264_HIGH_PROFILE ) {\ | ||
631 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.lumaIntra4x4Enable = 0x0FF;\ | ||
632 | } else if( _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.inputContentType == IVIDEO_PROGRESSIVE ) {\ | ||
633 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.lumaIntra4x4Enable = 0x0;\ | ||
634 | } else {\ | ||
635 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.lumaIntra4x4Enable = 0x1F;\ | ||
636 | }\ | ||
637 | if( _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.profile != IH264_HIGH_PROFILE ) {\ | ||
638 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.lumaIntra8x8Enable = 0x0;\ | ||
639 | } else if( _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.inputContentType == IVIDEO_PROGRESSIVE ) {\ | ||
640 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.lumaIntra8x8Enable = 0x0FF;\ | ||
641 | } else {\ | ||
642 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.lumaIntra8x8Enable = 0x01F;\ | ||
643 | }\ | ||
644 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.lumaIntra16x16Enable = 0xF;\ | ||
645 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.chromaIntra8x8Enable = 0xF;\ | ||
646 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.chromaComponentEnable = IH264_CHROMA_COMPONENT_DEFAULT;\ | ||
647 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.intraRefreshMethod = IH264_INTRAREFRESH_DEFAULT;\ | ||
648 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.intraRefreshRate = 0;\ | ||
649 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.gdrOverlapRowsBtwFrames = 0;\ | ||
650 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.constrainedIntraPredEnable = 0;\ | ||
651 | _pCompPvtStruct_->pVidEncStaticParams->intraCodingParams.intraCodingBias = IH264ENC_INTRACODINGBIAS_DEFAULT; | ||
652 | |||
653 | #define SET_H264CODEC_DEFAULT_STATIC_IH264ENC_NALUCONTROLPARAMS(_pCompPvtStruct_)\ | ||
654 | _pCompPvtStruct_->pVidEncStaticParams->nalUnitControlParams.naluControlPreset = IH264_NALU_CONTROL_DEFAULT;\ | ||
655 | _pCompPvtStruct_->pVidEncStaticParams->nalUnitControlParams.naluPresentMaskStartOfSequence= 0x01A0;\ | ||
656 | _pCompPvtStruct_->pVidEncStaticParams->nalUnitControlParams.naluPresentMaskIDRPicture = 0x01A0;\ | ||
657 | _pCompPvtStruct_->pVidEncStaticParams->nalUnitControlParams.naluPresentMaskIntraPicture= 0x0002;\ | ||
658 | _pCompPvtStruct_->pVidEncStaticParams->nalUnitControlParams.naluPresentMaskNonIntraPicture= 0x0002;\ | ||
659 | _pCompPvtStruct_->pVidEncStaticParams->nalUnitControlParams.naluPresentMaskEndOfSequence= 0x0C00;\ | ||
660 | |||
661 | #define SET_H264CODEC_DEFAULT_STATIC_IH264ENC_SLICECODINGPARAMS(_pCompPvtStruct_)\ | ||
662 | _pCompPvtStruct_->pVidEncStaticParams->sliceCodingParams.sliceCodingPreset = IH264_SLICECODING_DEFAULT;\ | ||
663 | _pCompPvtStruct_->pVidEncStaticParams->sliceCodingParams.sliceMode = IH264_SLICEMODE_DEFAULT;\ | ||
664 | _pCompPvtStruct_->pVidEncStaticParams->sliceCodingParams.sliceUnitSize = 0;\ | ||
665 | _pCompPvtStruct_->pVidEncStaticParams->sliceCodingParams.sliceStartOffset[0] = 0;\ | ||
666 | _pCompPvtStruct_->pVidEncStaticParams->sliceCodingParams.sliceStartOffset[1] = 0;\ | ||
667 | _pCompPvtStruct_->pVidEncStaticParams->sliceCodingParams.sliceStartOffset[2] = 0;\ | ||
668 | _pCompPvtStruct_->pVidEncStaticParams->sliceCodingParams.streamFormat = IH264_STREAM_FORMAT_DEFAULT; | ||
669 | |||
670 | #define SET_H264CODEC_DEFAULT_STATIC_IH264ENC_LOOPFILTERPARAMS(_pCompPvtStruct_)\ | ||
671 | _pCompPvtStruct_->pVidEncStaticParams->loopFilterParams.loopfilterPreset = IH264_LOOPFILTER_DEFAULT;\ | ||
672 | _pCompPvtStruct_->pVidEncStaticParams->loopFilterParams.loopfilterDisableIDC = IH264_DISABLE_FILTER_DEFAULT;\ | ||
673 | _pCompPvtStruct_->pVidEncStaticParams->loopFilterParams.filterOffsetA = 0;\ | ||
674 | _pCompPvtStruct_->pVidEncStaticParams->loopFilterParams.filterOffsetB = 0; | ||
675 | |||
676 | #define SET_H264CODEC_DEFAULT_STATIC_IH264ENC_FMOCODINGPARAMS(_pCompPvtStruct_)\ | ||
677 | _pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.fmoCodingPreset = IH264_FMOCODING_DEFAULT;\ | ||
678 | _pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.numSliceGroups = 1;\ | ||
679 | _pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.sliceGroupMapType = IH264_SLICE_GRP_MAP_DEFAULT;\ | ||
680 | _pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.sliceGroupChangeDirectionFlag = IH264ENC_SLICEGROUP_CHANGE_DIRECTION_DEFAULT;\ | ||
681 | _pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.sliceGroupChangeRate = 0;\ | ||
682 | _pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.sliceGroupChangeCycle = 0;\ | ||
683 | _pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.sliceGroupParams[0] = 0;\ | ||
684 | _pCompPvtStruct_->pVidEncStaticParams->fmoCodingParams.sliceGroupParams[1] = 0; | ||
685 | |||
686 | #define SET_H264CODEC_DEFAULT_STATIC_IH264ENC_VUICODINGPARAMS(_pCompPvtStruct_)\ | ||
687 | _pCompPvtStruct_->pVidEncStaticParams->vuiCodingParams.vuiCodingPreset = IH264_VUICODING_DEFAULT;\ | ||
688 | _pCompPvtStruct_->pVidEncStaticParams->vuiCodingParams.aspectRatioInfoPresentFlag = 0;\ | ||
689 | _pCompPvtStruct_->pVidEncStaticParams->vuiCodingParams.aspectRatioIdc = 0;\ | ||
690 | _pCompPvtStruct_->pVidEncStaticParams->vuiCodingParams.videoSignalTypePresentFlag = 0;\ | ||
691 | _pCompPvtStruct_->pVidEncStaticParams->vuiCodingParams.videoFormat = IH264ENC_VIDEOFORMAT_NTSC;\ | ||
692 | _pCompPvtStruct_->pVidEncStaticParams->vuiCodingParams.videoFullRangeFlag = 0;\ | ||
693 | _pCompPvtStruct_->pVidEncStaticParams->vuiCodingParams.timingInfoPresentFlag = 0;\ | ||
694 | _pCompPvtStruct_->pVidEncStaticParams->vuiCodingParams.hrdParamsPresentFlag = XDAS_FALSE;\ | ||
695 | _pCompPvtStruct_->pVidEncStaticParams->vuiCodingParams.numUnitsInTicks = 1000; | ||
696 | |||
697 | #define SET_H264CODEC_DEFAULT_STATIC_IH264ENC_STEREOINFOPARAMS(_pCompPvtStruct_)\ | ||
698 | _pCompPvtStruct_->pVidEncStaticParams->stereoInfoParams.stereoInfoPreset = IH264_STEREOINFO_DISABLE;\ | ||
699 | _pCompPvtStruct_->pVidEncStaticParams->stereoInfoParams.topFieldIsLeftViewFlag = 1;\ | ||
700 | _pCompPvtStruct_->pVidEncStaticParams->stereoInfoParams.viewSelfContainedFlag = 0; | ||
701 | |||
702 | #define SET_H264CODEC_DEFAULT_STATIC_IH264ENC_STEREOFRAMEPACKINGPARAMS(_pCompPvtStruct_)\ | ||
703 | _pCompPvtStruct_->pVidEncStaticParams->framePackingSEIParams.framePackingPreset = IH264_FRAMEPACK_SEI_DISABLE;\ | ||
704 | _pCompPvtStruct_->pVidEncStaticParams->framePackingSEIParams.framePackingType = IH264_FRAMEPACK_TYPE_DEFAULT;\ | ||
705 | _pCompPvtStruct_->pVidEncStaticParams->framePackingSEIParams.frame0PositionX = 0;\ | ||
706 | _pCompPvtStruct_->pVidEncStaticParams->framePackingSEIParams.frame0PositionY = 0;\ | ||
707 | _pCompPvtStruct_->pVidEncStaticParams->framePackingSEIParams.frame1PositionX = 0;\ | ||
708 | _pCompPvtStruct_->pVidEncStaticParams->framePackingSEIParams.frame1PositionY = 0;\ | ||
709 | _pCompPvtStruct_->pVidEncStaticParams->framePackingSEIParams.reservedByte = 0; | ||
710 | |||
711 | #define SET_H264CODEC_DEFAULT_STATIC_IH264ENC_SVCCODINGPARAMS(_pCompPvtStruct_)\ | ||
712 | _pCompPvtStruct_->pVidEncStaticParams->svcCodingParams.svcExtensionFlag = IH264_SVC_EXTENSION_FLAG_DISABLE;\ | ||
713 | _pCompPvtStruct_->pVidEncStaticParams->svcCodingParams.dependencyID = 0;\ | ||
714 | _pCompPvtStruct_->pVidEncStaticParams->svcCodingParams.qualityID = 0;\ | ||
715 | _pCompPvtStruct_->pVidEncStaticParams->svcCodingParams.enhancementProfileID = 0;\ | ||
716 | _pCompPvtStruct_->pVidEncStaticParams->svcCodingParams.layerIndex = 0;\ | ||
717 | _pCompPvtStruct_->pVidEncStaticParams->svcCodingParams.refLayerDQId = 0; | ||
718 | |||
719 | #define SET_H264CODEC_DEFAULT_STATIC_IH264ENC_EXTENDEDPARAMS(_pCompPvtStruct_)\ | ||
720 | _pCompPvtStruct_->pVidEncStaticParams->interlaceCodingType = IH264_INTERLACE_FIELDONLY_ARF;\ | ||
721 | _pCompPvtStruct_->pVidEncStaticParams->bottomFieldIntra = OMX_FALSE;\ | ||
722 | _pCompPvtStruct_->pVidEncStaticParams->gopStructure = IH264ENC_GOPSTRUCTURE_DEFAULT;\ | ||
723 | if( _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.profile == IH264_BASELINE_PROFILE ) {\ | ||
724 | _pCompPvtStruct_->pVidEncStaticParams->entropyCodingMode = IH264_ENTROPYCODING_CAVLC;\ | ||
725 | } else {\ | ||
726 | _pCompPvtStruct_->pVidEncStaticParams->entropyCodingMode = IH264_ENTROPYCODING_CABAC;\ | ||
727 | }\ | ||
728 | if( _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.profile == IH264_HIGH_PROFILE ) {\ | ||
729 | _pCompPvtStruct_->pVidEncStaticParams->transformBlockSize = IH264_TRANSFORM_ADAPTIVE;\ | ||
730 | } else {\ | ||
731 | _pCompPvtStruct_->pVidEncStaticParams->transformBlockSize = IH264_TRANSFORM_4x4;\ | ||
732 | }\ | ||
733 | _pCompPvtStruct_->pVidEncStaticParams->log2MaxFNumMinus4 = 10;\ | ||
734 | _pCompPvtStruct_->pVidEncStaticParams->picOrderCountType = IH264_POC_TYPE_DEFAULT;\ | ||
735 | _pCompPvtStruct_->pVidEncStaticParams->maxIntraFrameInterval = OMX_H264VE_DEFAULT_MAXINTRAFRAME_INTERVAL;\ | ||
736 | _pCompPvtStruct_->pVidEncStaticParams->enableWatermark = 0;\ | ||
737 | _pCompPvtStruct_->pVidEncStaticParams->IDRFrameInterval = 0;\ | ||
738 | _pCompPvtStruct_->pVidEncStaticParams->pConstantMemory = NULL;\ | ||
739 | _pCompPvtStruct_->pVidEncStaticParams->debugTraceLevel = 0;\ | ||
740 | _pCompPvtStruct_->pVidEncStaticParams->lastNFramesToLog = 0;\ | ||
741 | _pCompPvtStruct_->pVidEncStaticParams->enableAnalyticinfo = 0;\ | ||
742 | _pCompPvtStruct_->pVidEncStaticParams->enableGMVSei = 0;\ | ||
743 | _pCompPvtStruct_->pVidEncStaticParams->constraintSetFlags = OMX_H264_DISBALE_ALL_CONSTRAINT_SET_FLAGS;\ | ||
744 | _pCompPvtStruct_->pVidEncStaticParams->enableRCDO = 0;\ | ||
745 | _pCompPvtStruct_->pVidEncStaticParams->enableLongTermRefFrame = IH264ENC_LTRP_NONE;\ | ||
746 | _pCompPvtStruct_->pVidEncStaticParams->LTRPPeriod = 0;\ | ||
747 | _pCompPvtStruct_->pVidEncStaticParams->numTemporalLayer = IH264_TEMPORAL_LAYERS_1;\ | ||
748 | _pCompPvtStruct_->pVidEncStaticParams->referencePicMarking = IH264_LONG_TERM_PICTURE;\ | ||
749 | _pCompPvtStruct_->pVidEncStaticParams->reservedParams[0] = 0;\ | ||
750 | _pCompPvtStruct_->pVidEncStaticParams->reservedParams[1] = 0;\ | ||
751 | _pCompPvtStruct_->pVidEncStaticParams->reservedParams[2] = 0; | ||
752 | |||
753 | #define OVERWRITE_H264CODEC_DEFAULT_STATIC_PARAMS(_pCompPvtStruct_)\ | ||
754 | _pCompPvtStruct_->pVidEncStaticParams->nalUnitControlParams.naluControlPreset = IH264_NALU_CONTROL_USERDEFINED;\ | ||
755 | _pCompPvtStruct_->pVidEncStaticParams->nalUnitControlParams.naluPresentMaskIDRPicture = 0x0020;\ | ||
756 | _pCompPvtStruct_->pVidEncStaticParams->interCodingParams.interCodingPreset= IH264_INTERCODING_USERDEFINED;\ | ||
757 | _pCompPvtStruct_->pVidEncStaticParams->interCodingParams.skipMVCodingBias = IH264_BIASFACTOR_MILD;\ | ||
758 | if( _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.profile == IH264_BASELINE_PROFILE ) {\ | ||
759 | _pCompPvtStruct_->pVidEncStaticParams->constraintSetFlags = OMX_H264_SET_CONSTRAINT_SET1_FLAG;\ | ||
760 | } | ||
761 | |||
762 | #define ENABLE_4MV(_pCompPvtStruct_)\ | ||
763 | _pCompPvtStruct_->pVidEncStaticParams->interCodingParams.interCodingPreset = IH264_INTERCODING_USERDEFINED;\ | ||
764 | _pCompPvtStruct_->pVidEncStaticParams->interCodingParams.minBlockSizeP = IH264_BLOCKSIZE_8x8;\ | ||
765 | _pCompPvtStruct_->pVidEncStaticParams->interCodingParams.minBlockSizeB = IH264_BLOCKSIZE_8x8;\ | ||
766 | _pCompPvtStruct_->pVidEncDynamicParams->interCodingParams.minBlockSizeP = IH264_BLOCKSIZE_8x8;\ | ||
767 | _pCompPvtStruct_->pVidEncDynamicParams->interCodingParams.minBlockSizeB = IH264_BLOCKSIZE_8x8; | ||
768 | |||
769 | #define SET_H264CODEC_DEFAULT_IVIDENC2_DYNAMICPARAMS(_pCompPvtStruct_)\ | ||
770 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.size = sizeof(IH264ENC_DynamicParams);\ | ||
771 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.inputHeight = OMX_H264VE_DEFAULT_FRAME_HEIGHT;\ | ||
772 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.inputWidth = OMX_H264VE_DEFAULT_FRAME_WIDTH;\ | ||
773 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.refFrameRate = (OMX_H264VE_DEFAULT_FRAME_RATE) * 1000;\ | ||
774 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.targetFrameRate = (OMX_H264VE_DEFAULT_FRAME_RATE) * 1000;\ | ||
775 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.targetBitRate = OMX_H264VE_DEFAULT_BITRATE;\ | ||
776 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.intraFrameInterval = OMX_H264VE_DEFAULT_INTRAFRAME_INTERVAL;\ | ||
777 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.generateHeader = XDM_GENERATE_HEADER;\ | ||
778 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.ignoreOutbufSizeFlag = XDAS_TRUE;\ | ||
779 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.captureWidth = OMX_H264VE_DEFAULT_FRAME_WIDTH;\ | ||
780 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.forceFrame = IVIDEO_NA_FRAME;\ | ||
781 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.interFrameInterval = OMX_H264VE_DEFAULT_INTERFRAME_INTERVAL;\ | ||
782 | if( _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.profile == IH264_BASELINE_PROFILE ) {\ | ||
783 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.interFrameInterval = OMX_H264VE_BASELINE_INTERFRAME_INTERVAL;\ | ||
784 | }\ | ||
785 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.mvAccuracy = IVIDENC2_MOTIONVECTOR_QUARTERPEL;\ | ||
786 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.sampleAspectRatioHeight = OMX_H264VE_DEFAULT_ASPECT_RATIO_HEIGHT;\ | ||
787 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.sampleAspectRatioWidth = OMX_H264VE_DEFAULT_ASPECT_RATIO_WIDTH;\ | ||
788 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.putDataFxn = NULL;\ | ||
789 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.putDataHandle = 0;\ | ||
790 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.getDataFxn = NULL;\ | ||
791 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.getDataHandle = 0;\ | ||
792 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.getBufferFxn = NULL;\ | ||
793 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.getBufferHandle = NULL;\ | ||
794 | _pCompPvtStruct_->pVidEncDynamicParams->videnc2DynamicParams.lateAcquireArg = -1; | ||
795 | |||
796 | |||
797 | #define SET_H264CODEC_DEFAULT_DYNAMIC_RATECONTROLPARAMS(_pCompPvtStruct_)\ | ||
798 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.rateControlParamsPreset = IH264_RATECONTROLPARAMS_DEFAULT;\ | ||
799 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.scalingMatrixPreset = IH264_SCALINGMATRIX_NORMAL;\ | ||
800 | if( _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.profile != IH264_HIGH_PROFILE ) {\ | ||
801 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.scalingMatrixPreset = IH264_SCALINGMATRIX_NONE;\ | ||
802 | }\ | ||
803 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.rcAlgo = IH264_RATECONTROL_DEFAULT;\ | ||
804 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.qpI = OMX_H264VE_DEFAULT_QP_IFRAME;\ | ||
805 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.qpMaxI = OMX_H264VE_DEFAULT_QPMAX_IFRAME;\ | ||
806 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.qpMinI = OMX_H264VE_DEFAULT_QPMIN_IFRAME;\ | ||
807 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.qpP = OMX_H264VE_DEFAULT_QP_PFRAME;\ | ||
808 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.qpMaxP = OMX_H264VE_DEFAULT_QPMAX_PFRAME;\ | ||
809 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.qpMinP = OMX_H264VE_DEFAULT_QPMIN_PFRAME;\ | ||
810 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.qpOffsetB = OMX_H264VE_DEFAULT_QPOFFSET_BFRAME;\ | ||
811 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.qpMaxB = OMX_H264VE_DEFAULT_QPMAX_BFRAME;\ | ||
812 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.qpMinB = OMX_H264VE_DEFAULT_QPMIN_BFRAME;\ | ||
813 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.allowFrameSkip = OMX_FALSE;\ | ||
814 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.removeExpensiveCoeff = OMX_FALSE;\ | ||
815 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.chromaQPIndexOffset = OMX_H264VE_DEFAULT_QPOFFSET_CHROMA;\ | ||
816 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.IPQualityFactor = IH264_QUALITY_FACTOR_DEFAULT;\ | ||
817 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.HRDBufferSize = OMX_H264VE_DEFAULT_BITRATE;\ | ||
818 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.initialBufferLevel = pH264VEComp->pVidEncDynamicParams->rateControlParams.HRDBufferSize;\ | ||
819 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.minPicSizeRatioI = OMX_H264VE_DEFAULT_MINPICSIZERATIO;\ | ||
820 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.maxPicSizeRatioI = OMX_H264VE_DEFAULT_MAXPICSIZERATIOI;\ | ||
821 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.minPicSizeRatioP = OMX_H264VE_DEFAULT_MINPICSIZERATIO;\ | ||
822 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.maxPicSizeRatioP = OMX_H264VE_DEFAULT_MAXPICSIZERATIOP;\ | ||
823 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.minPicSizeRatioB = OMX_H264VE_DEFAULT_MINPICSIZERATIO;\ | ||
824 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.maxPicSizeRatioB = OMX_H264VE_DEFAULT_MAXPICSIZERATIOB;\ | ||
825 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.enablePRC = 1;\ | ||
826 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.enablePartialFrameSkip = 0;\ | ||
827 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.discardSavedBits = 0;\ | ||
828 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.reserved = 0;\ | ||
829 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.VBRDuration = 8;\ | ||
830 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.VBRsensitivity = 0;\ | ||
831 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.skipDistributionWindowLength = 5;\ | ||
832 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.numSkipInDistributionWindow = 1;\ | ||
833 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.enableHRDComplianceMode = 1;\ | ||
834 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.frameSkipThMulQ5 = 0;\ | ||
835 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.vbvUseLevelThQ5 = 0;\ | ||
836 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.reservedRC[0] = 0;\ | ||
837 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.reservedRC[1] = 0;\ | ||
838 | _pCompPvtStruct_->pVidEncDynamicParams->rateControlParams.reservedRC[2] = 0; | ||
839 | |||
840 | |||
841 | #define SET_H264CODEC_DEFAULT_DYNAMIC_INTERCODINGPARAMS(_pCompPvtStruct_)\ | ||
842 | _pCompPvtStruct_->pVidEncDynamicParams->interCodingParams.interCodingPreset = IH264_INTERCODING_DEFAULT;\ | ||
843 | _pCompPvtStruct_->pVidEncDynamicParams->interCodingParams.searchRangeHorP = OMX_H264VE_DEFAULT_HORSEARCH_PFRAME;\ | ||
844 | _pCompPvtStruct_->pVidEncDynamicParams->interCodingParams.searchRangeVerP = OMX_H264VE_DEFAULT_VERSEARCH_PFRAME;\ | ||
845 | _pCompPvtStruct_->pVidEncDynamicParams->interCodingParams.searchRangeHorB = OMX_H264VE_DEFAULT_HORSEARCH_BFRAME;\ | ||
846 | _pCompPvtStruct_->pVidEncDynamicParams->interCodingParams.searchRangeVerB = OMX_H264VE_DEFAULT_VERSEARCH_BFRAME;\ | ||
847 | _pCompPvtStruct_->pVidEncDynamicParams->interCodingParams.interCodingBias = IH264_BIASFACTOR_DEFAULT;\ | ||
848 | _pCompPvtStruct_->pVidEncDynamicParams->interCodingParams.skipMVCodingBias = IH264_BIASFACTOR_DEFAULT;\ | ||
849 | _pCompPvtStruct_->pVidEncDynamicParams->interCodingParams.minBlockSizeP = IH264_BLOCKSIZE_DEFAULT;\ | ||
850 | _pCompPvtStruct_->pVidEncDynamicParams->interCodingParams.minBlockSizeB = IH264_BLOCKSIZE_DEFAULT;\ | ||
851 | _pCompPvtStruct_->pVidEncDynamicParams->interCodingParams.meAlgoMode = IH264ENC_MOTIONESTMODE_DEFAULT; | ||
852 | |||
853 | |||
854 | #define SET_H264CODEC_DEFAULT_DYNAMIC_INTRACODINGPARAMS(_pCompPvtStruct_)\ | ||
855 | _pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.intraCodingPreset = IH264_INTRACODING_DEFAULT;\ | ||
856 | if( _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.profile != IH264_HIGH_PROFILE ) {\ | ||
857 | _pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.lumaIntra4x4Enable = 0x0FF;\ | ||
858 | } else if( _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.inputContentType == IVIDEO_PROGRESSIVE ) {\ | ||
859 | _pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.lumaIntra4x4Enable = 0x0;\ | ||
860 | } else {\ | ||
861 | _pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.lumaIntra4x4Enable = 0x1F;\ | ||
862 | }\ | ||
863 | if( _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.profile != IH264_HIGH_PROFILE ) {\ | ||
864 | _pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.lumaIntra8x8Enable = 0x0;\ | ||
865 | } else if( _pCompPvtStruct_->pVidEncStaticParams->videnc2Params.inputContentType == IVIDEO_PROGRESSIVE ) {\ | ||
866 | _pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.lumaIntra8x8Enable = 0x0FF;\ | ||
867 | } else {\ | ||
868 | _pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.lumaIntra8x8Enable = 0x01F;\ | ||
869 | }\ | ||
870 | _pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.lumaIntra16x16Enable = 0xF;\ | ||
871 | _pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.chromaIntra8x8Enable = 0xF;\ | ||
872 | _pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.chromaComponentEnable = IH264_CHROMA_COMPONENT_DEFAULT;\ | ||
873 | _pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.intraRefreshMethod = IH264_INTRAREFRESH_DEFAULT;\ | ||
874 | _pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.intraRefreshRate = 0;\ | ||
875 | _pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.gdrOverlapRowsBtwFrames = 0;\ | ||
876 | _pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.constrainedIntraPredEnable = 0;\ | ||
877 | _pCompPvtStruct_->pVidEncDynamicParams->intraCodingParams.intraCodingBias = IH264ENC_INTRACODINGBIAS_DEFAULT; | ||
878 | |||
879 | |||
880 | #define SET_H264CODEC_DEFAULT_DYNAMIC_SLICECODINGPARAMS(_pCompPvtStruct_)\ | ||
881 | _pCompPvtStruct_->pVidEncDynamicParams->sliceCodingParams.sliceCodingPreset = IH264_SLICECODING_DEFAULT;\ | ||
882 | _pCompPvtStruct_->pVidEncDynamicParams->sliceCodingParams.sliceMode = IH264_SLICEMODE_DEFAULT;\ | ||
883 | _pCompPvtStruct_->pVidEncDynamicParams->sliceCodingParams.sliceUnitSize = 0;\ | ||
884 | _pCompPvtStruct_->pVidEncDynamicParams->sliceCodingParams.sliceStartOffset[0] = 0;\ | ||
885 | _pCompPvtStruct_->pVidEncDynamicParams->sliceCodingParams.sliceStartOffset[1] = 0;\ | ||
886 | _pCompPvtStruct_->pVidEncDynamicParams->sliceCodingParams.sliceStartOffset[2] = 0;\ | ||
887 | _pCompPvtStruct_->pVidEncDynamicParams->sliceCodingParams.streamFormat = IH264_STREAM_FORMAT_DEFAULT; | ||
888 | |||
889 | |||
890 | #define SET_H264CODEC_DEFAULT_DYNAMIC_IH264_EXTENDEDPARAMS(_pCompPvtStruct_)\ | ||
891 | _pCompPvtStruct_->pVidEncDynamicParams->sliceGroupChangeCycle = 0;\ | ||
892 | _pCompPvtStruct_->pVidEncDynamicParams->searchCenter.x = 0x7FFF;\ | ||
893 | _pCompPvtStruct_->pVidEncDynamicParams->searchCenter.y = 0x7FFF;\ | ||
894 | _pCompPvtStruct_->pVidEncDynamicParams->enableStaticMBCount = 0;\ | ||
895 | _pCompPvtStruct_->pVidEncDynamicParams->enableROI = 0;\ | ||
896 | _pCompPvtStruct_->pVidEncDynamicParams->reservedDynParams[0] = 0; | ||
897 | |||
898 | #define OVERWRITE_H264CODEC_DEFAULT_DYNAMIC_PARAMS(_pCompPvtStruct_)\ | ||
899 | _pCompPvtStruct_->pVidEncDynamicParams->interCodingParams.skipMVCodingBias = IH264_BIASFACTOR_MILD; | ||
900 | |||
901 | |||
902 | #define MAP_CODEC_TO_OMX_AVCLEVEL(_InCodecLevel_, _OutOMXLevel_, _nIndex_, _e_)\ | ||
903 | switch( _InCodecLevel_ ) {\ | ||
904 | case IH264_LEVEL_10 :\ | ||
905 | _OutOMXLevel_ = OMX_VIDEO_AVCLevel1;\ | ||
906 | _nIndex_ = 0;\ | ||
907 | break;\ | ||
908 | case IH264_LEVEL_1b :\ | ||
909 | _OutOMXLevel_ = OMX_VIDEO_AVCLevel1b;\ | ||
910 | _nIndex_ = 1;\ | ||
911 | break;\ | ||
912 | case IH264_LEVEL_11 :\ | ||
913 | _OutOMXLevel_ = OMX_VIDEO_AVCLevel11;\ | ||
914 | _nIndex_ = 2;\ | ||
915 | break;\ | ||
916 | case IH264_LEVEL_12 :\ | ||
917 | _OutOMXLevel_= OMX_VIDEO_AVCLevel12;\ | ||
918 | _nIndex_ = 3;\ | ||
919 | break;\ | ||
920 | case IH264_LEVEL_13 :\ | ||
921 | _OutOMXLevel_ = OMX_VIDEO_AVCLevel13;\ | ||
922 | _nIndex_ = 4;\ | ||
923 | break;\ | ||
924 | case IH264_LEVEL_20 :\ | ||
925 | _OutOMXLevel_= OMX_VIDEO_AVCLevel2;\ | ||
926 | _nIndex_ = 5;\ | ||
927 | break;\ | ||
928 | case IH264_LEVEL_21 :\ | ||
929 | _OutOMXLevel_=OMX_VIDEO_AVCLevel21;\ | ||
930 | _nIndex_ = 6;\ | ||
931 | break;\ | ||
932 | case IH264_LEVEL_22 :\ | ||
933 | _OutOMXLevel_= OMX_VIDEO_AVCLevel22;\ | ||
934 | _nIndex_ = 7;\ | ||
935 | break;\ | ||
936 | case IH264_LEVEL_30 :\ | ||
937 | _OutOMXLevel_= OMX_VIDEO_AVCLevel3;\ | ||
938 | _nIndex_ = 8;\ | ||
939 | break;\ | ||
940 | case IH264_LEVEL_31 :\ | ||
941 | _OutOMXLevel_= OMX_VIDEO_AVCLevel31;\ | ||
942 | _nIndex_ = 9;\ | ||
943 | break;\ | ||
944 | case IH264_LEVEL_32 :\ | ||
945 | _OutOMXLevel_= OMX_VIDEO_AVCLevel32;\ | ||
946 | _nIndex_ = 10;\ | ||
947 | break;\ | ||
948 | case IH264_LEVEL_40 :\ | ||
949 | _OutOMXLevel_= OMX_VIDEO_AVCLevel4;\ | ||
950 | _nIndex_ = 11;\ | ||
951 | break;\ | ||
952 | case IH264_LEVEL_41 :\ | ||
953 | _OutOMXLevel_ = OMX_VIDEO_AVCLevel41;\ | ||
954 | _nIndex_ = 12;\ | ||
955 | break;\ | ||
956 | case IH264_LEVEL_42 :\ | ||
957 | _OutOMXLevel_ = OMX_VIDEO_AVCLevel42;\ | ||
958 | _nIndex_ = 13;\ | ||
959 | break;\ | ||
960 | case IH264_LEVEL_50 :\ | ||
961 | _OutOMXLevel_= OMX_VIDEO_AVCLevel5;\ | ||
962 | _nIndex_ = 14;\ | ||
963 | break;\ | ||
964 | case IH264_LEVEL_51 :\ | ||
965 | _OutOMXLevel_= OMX_VIDEO_AVCLevel51;\ | ||
966 | _nIndex_ = 15;\ | ||
967 | break;\ | ||
968 | default :\ | ||
969 | _e_= OMX_ErrorNoMore;\ | ||
970 | _nIndex_ = 0xFFFFFFFF;\ | ||
971 | break;\ | ||
972 | } | ||
973 | |||
974 | /* Error mapping b/n XDM and OMX */ | ||
975 | #define OMX_TI_GET_ERROR(_pCompPvtStruct_, _x_, _e_) \ | ||
976 | _e_ = OMX_ErrorUndefined; \ | ||
977 | if( XDM_ISFATALERROR(_x_)) { /*bit 15*/\ | ||
978 | _e_ = OMX_ErrorUndefined;\ | ||
979 | OSAL_ErrorTrace("Undefined From Codec");\ | ||
980 | }\ | ||
981 | if(((_x_) >> IH264ENC_LEVEL_INCOMPLAINT_PARAMETER) & 0x1 ) { /*bit 0*/\ | ||
982 | _e_ = OMX_ErrorUnsupportedSetting;\ | ||
983 | OSAL_ErrorTrace("Due to Level Incompliant Param Setting");\ | ||
984 | }\ | ||
985 | if(((_x_) >> IH264ENC_PROFILE_INCOMPLAINT_CONTENTTYPE) & 0x1 ) { /*bit 1*/\ | ||
986 | _e_ = OMX_ErrorUnsupportedSetting;\ | ||
987 | OSAL_ErrorTrace("Due to Profile Incompliant Content type(progressive/Interlace) Setting");\ | ||
988 | }\ | ||
989 | if(((_x_) >> IH264ENC_PROFILE_INCOMPLAINT_FMO_SETTING) & 0x1 ) { /*bit 2*/\ | ||
990 | _e_ = OMX_ErrorUnsupportedSetting;\ | ||
991 | OSAL_ErrorTrace("Due to Profile Incompliant FMO Param Setting");\ | ||
992 | }\ | ||
993 | if(((_x_) >> IH264ENC_PROFILE_INCOMPLAINT_TRANSFORMBLOCKSIZE) & 0x1 ) { /*bit 3*/\ | ||
994 | _e_ = OMX_ErrorUnsupportedSetting;\ | ||
995 | OSAL_ErrorTrace("Due to Profile Incompliant Transform Block Size Setting");\ | ||
996 | }\ | ||
997 | if(((_x_) >> IH264ENC_PROFILE_INCOMPLAINT_INTERFRAMEINTERVAL) & 0x1 ) { /*bit 4*/\ | ||
998 | _e_ = OMX_ErrorUnsupportedSetting;\ | ||
999 | OSAL_ErrorTrace("Due to Profile Incompliant IntraFrame Interval Setting");\ | ||
1000 | }\ | ||
1001 | if(((_x_) >> IH264ENC_PROFILE_INCOMPLAINT_SCALINGMATRIXPRESET) & 0x1 ) { /*bit 5*/\ | ||
1002 | _e_ = OMX_ErrorUnsupportedSetting;\ | ||
1003 | OSAL_ErrorTrace("Due to Profile Incompliant Scaling Matrix Setting");\ | ||
1004 | }\ | ||
1005 | if(((_x_) >> IH264ENC_PROFILE_INCOMPLAINT_ENTROPYCODINGMODE) & 0x1 ) { /*bit 6*/\ | ||
1006 | _e_ = OMX_ErrorUnsupportedSetting;\ | ||
1007 | OSAL_ErrorTrace("Due to Profile Incompliant Entropy Coding Setting");\ | ||
1008 | OSAL_ErrorTrace("_or_ Due to violation of slice size (crossing the limit)");\ | ||
1009 | }\ | ||
1010 | if(((_x_) >> IH264ENC_MAX_BIT_RATE_VOILATION) & 0x1 ) { /*bit 7*/\ | ||
1011 | _e_ = OMX_ErrorOverflow;\ | ||
1012 | OSAL_ErrorTrace("Max bits for one Unit (1 sec) Voilation");\ | ||
1013 | }\ | ||
1014 | if(((_x_) >> IH264ENC_IMPROPER_HDVICP2_STATE) & 0x1 ) { /*bit 16*/\ | ||
1015 | _e_ = OMX_ErrorHardware;\ | ||
1016 | OSAL_ErrorTrace("IVAHD Device is not proper state to use");\ | ||
1017 | }\ | ||
1018 | if(((_x_) >> IH264ENC_IMPROPER_STREAMFORMAT) & 0x1 ) { /*bit 17*/\ | ||
1019 | _e_ = OMX_ErrorUnsupportedSetting;\ | ||
1020 | OSAL_ErrorTrace("Due To Improper StreamFormat");\ | ||
1021 | }\ | ||
1022 | if(((_x_) >> IH264ENC_IMPROPER_POCTYPE) & 0x1 ) { /*bit 18*/\ | ||
1023 | _e_ = OMX_ErrorUnsupportedSetting;\ | ||
1024 | OSAL_ErrorTrace("Due to InCorrect POC Type");\ | ||
1025 | }\ | ||
1026 | if(((_x_) >> IH264ENC_IMPROPER_DATASYNC_SETTING) & 0x1 ) { /*bit 19*/\ | ||
1027 | _e_ = OMX_ErrorUnsupportedSetting;\ | ||
1028 | OSAL_ErrorTrace("Due to Imprper DataSync Settings");\ | ||
1029 | }\ | ||
1030 | if(((_x_) >> IH264ENC_UNSUPPORTED_VIDENC2PARAMS) & 0x1 ) { /*bit 20*/\ | ||
1031 | _e_ = OMX_ErrorUnsupportedSetting;\ | ||
1032 | OSAL_ErrorTrace("Due To Unsupported Videnc2 Params");\ | ||
1033 | }\ | ||
1034 | if(((_x_) >> IH264ENC_UNSUPPORTED_RATECONTROLPARAMS) & 0x1 ) { /*bit 21*/\ | ||
1035 | _e_ = OMX_ErrorUnsupportedSetting;\ | ||
1036 | OSAL_ErrorTrace("Due To Unsupported Rate Control Params");\ | ||
1037 | }\ | ||
1038 | if(((_x_) >> IH264ENC_UNSUPPORTED_INTERCODINGPARAMS) & 0x1 ) { /*bit 22*/\ | ||
1039 | _e_ = OMX_ErrorUnsupportedSetting;\ | ||
1040 | OSAL_ErrorTrace("Due to Unsupported Intercoding Params");\ | ||
1041 | }\ | ||
1042 | if(((_x_) >> IH264ENC_UNSUPPORTED_INTRACODINGPARAMS) & 0x1 ) { /*bit 23*/\ | ||
1043 | _e_ = OMX_ErrorUnsupportedSetting;\ | ||
1044 | OSAL_ErrorTrace("Due to Unsupported Intracoding Params");\ | ||
1045 | }\ | ||
1046 | if(((_x_) >> IH264ENC_UNSUPPORTED_NALUNITCONTROLPARAMS) & 0x1 ) { /*bit 24*/\ | ||
1047 | _e_ = OMX_ErrorUnsupportedSetting;\ | ||
1048 | OSAL_ErrorTrace("Due to Unsupported NALControl Params");\ | ||
1049 | }\ | ||
1050 | if(((_x_) >> IH264ENC_UNSUPPORTED_SLICECODINGPARAMS) & 0x1 ) { /*bit 25*/\ | ||
1051 | _e_ = OMX_ErrorUnsupportedSetting;\ | ||
1052 | OSAL_ErrorTrace("Due to Unsupported Slicecoding Params");\ | ||
1053 | }\ | ||
1054 | if(((_x_) >> IH264ENC_UNSUPPORTED_LOOPFILTERPARAMS) & 0x1 ) { /*bit 26*/\ | ||
1055 | _e_ = OMX_ErrorUnsupportedSetting;\ | ||
1056 | OSAL_ErrorTrace("Due to Unsupported LoopFilter Params");\ | ||
1057 | }\ | ||
1058 | if(((_x_) >> IH264ENC_UNSUPPORTED_FMOCODINGPARAMS) & 0x1 ) { /*bit 27*/\ | ||
1059 | _e_ = OMX_ErrorUnsupportedSetting;\ | ||
1060 | OSAL_ErrorTrace("Due to Unsupported FMOCoding Params or");\ | ||
1061 | OSAL_ErrorTrace("DATASYNC::No of NALs in 1Kb of data is more than 8/ insufficient memory blocks or");\ | ||
1062 | OSAL_ErrorTrace("Due to Unsupported setting in N frame process call scenario");\ | ||
1063 | }\ | ||
1064 | if(((_x_) >> IH264ENC_UNSUPPORTED_VUICODINGPARAMS) & 0x1 ) { /*bit 28*/\ | ||
1065 | _e_ = OMX_ErrorUnsupportedSetting;\ | ||
1066 | OSAL_ErrorTrace("Due to Unsupported VUIcoding Params");\ | ||
1067 | }\ | ||
1068 | if(((_x_) >> IH264ENC_UNSUPPORTED_H264ENCPARAMS) & 0x1 ) { /*bit 29*/\ | ||
1069 | _e_ = OMX_ErrorUnsupportedSetting;\ | ||
1070 | OSAL_ErrorTrace("Due to Unsupported H264ENC Params");\ | ||
1071 | }\ | ||
1072 | if(((_x_) >> IH264ENC_UNSUPPORTED_VIDENC2DYNAMICPARAMS) & 0x1 ) { /*bit 30*/\ | ||
1073 | _e_ = OMX_ErrorUnsupportedSetting;\ | ||
1074 | OSAL_ErrorTrace("Due to Unsupported VIDENC2DYNAMIC Params");\ | ||
1075 | }\ | ||
1076 | if(((_x_) >> IH264ENC_UNSUPPORTED_H264ENCDYNAMICPARAMS) & 0x1 ) { /*bit 31*/\ | ||
1077 | _e_ = OMX_ErrorUnsupportedSetting;\ | ||
1078 | OSAL_ErrorTrace("Due to Unsupported H264ENCDYNAMIC Params");\ | ||
1079 | }\ | ||
1080 | if( XDM_ISUNSUPPORTEDPARAM(_x_)) { /*bit 14*/\ | ||
1081 | _e_ = OMX_ErrorBadParameter;\ | ||
1082 | OSAL_ErrorTrace("Due to UnSupported Parameter");\ | ||
1083 | }\ | ||
1084 | if( XDM_ISUNSUPPORTEDINPUT(_x_)) { /*bit 13*/\ | ||
1085 | _e_ = OMX_ErrorBadParameter;\ | ||
1086 | OSAL_ErrorTrace("Due to Unsupported Input");\ | ||
1087 | }\ | ||
1088 | if( XDM_ISCORRUPTEDHEADER(_x_)) { /*bit 12*/\ | ||
1089 | _e_ = OMX_ErrorStreamCorrupt;\ | ||
1090 | OSAL_ErrorTrace("Due to Corrupt Header");\ | ||
1091 | }\ | ||
1092 | if( XDM_ISCORRUPTEDDATA(_x_)) { /*bit 11*/\ | ||
1093 | _e_ = OMX_ErrorStreamCorrupt;\ | ||
1094 | OSAL_ErrorTrace("Due to Corrupted Data");\ | ||
1095 | }\ | ||
1096 | if( XDM_ISINSUFFICIENTDATA(_x_)) { /*bit 10*/\ | ||
1097 | _e_ = OMX_ErrorInsufficientResources;\ | ||
1098 | OSAL_ErrorTrace("Due to Insufficient Data");\ | ||
1099 | } | ||
1100 | |||
1101 | /* Internal functions */ | ||
1102 | OMX_ERRORTYPE OMXH264VE_InitFields(OMX_HANDLETYPE hComponent); | ||
1103 | |||
1104 | OMX_ERRORTYPE OMXH264VE_InitialzeComponentPrivateParams(OMX_HANDLETYPE hComponent); | ||
1105 | |||
1106 | OMX_ERRORTYPE OMXH264VE_SetAlgDefaultCreationParams(OMX_HANDLETYPE pHandle); | ||
1107 | |||
1108 | OMX_ERRORTYPE OMXH264VE_SetAlgDefaultDynamicParams(OMX_HANDLETYPE pHandle); | ||
1109 | |||
1110 | OMX_ERRORTYPE OMXH264VE_SetBufferDesc(OMX_HANDLETYPE pHandle, OMX_U32 nPortIndex); | ||
1111 | |||
1112 | OMX_ERRORTYPE OMXH264VE_SetEncCodecReady(OMX_HANDLETYPE hComponent); | ||
1113 | |||
1114 | OMX_ERRORTYPE OMXH264VE_UpdateParams(OMX_HANDLETYPE hComponent); | ||
1115 | |||
1116 | /* Buffer statemachine Related*/ | ||
1117 | OMX_ERRORTYPE OMXH264VE_FLUSHLockedBuffers(OMX_HANDLETYPE hComponent); | ||
1118 | OMX_ERRORTYPE OMXH264VE_GetNextFreeBufHdr(OMX_HANDLETYPE hComponent, OMX_S32 *nBuffIndex, OMX_U32 nPortIndex); | ||
1119 | OMX_ERRORTYPE OMXH264VE_GetNumCodecLockedBuffers(OMX_HANDLETYPE hComponent, OMX_U32 *nLockedBuffCount); | ||
1120 | OMX_ERRORTYPE OMXH264VE_SetDynamicParamsToCodec(OMX_HANDLETYPE hComponent); | ||
1121 | |||
1122 | OMX_ERRORTYPE OMXH264VE_VISACONTROL(VIDENC2_Handle handle, IVIDENC2_Cmd id, IVIDENC2_DynamicParams *dynParams, | ||
1123 | IVIDENC2_Status *status, OMX_HANDLETYPE hComponent, XDAS_Int32 *retval); | ||
1124 | |||
1125 | OMX_ERRORTYPE OMXH264VE_VISAPROCESS_AND_UPDATEPARAMS(OMX_HANDLETYPE hComponent, XDAS_Int32 *retval); | ||
1126 | |||
1127 | /* Functions to check the max bit rate supported as per profile & level settings*/ | ||
1128 | OMX_ERRORTYPE OMXH264VE_CheckBitRateCap(OMX_U32 targetBitRate, OMX_HANDLETYPE hComponent); | ||
1129 | |||