1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 // Software and any modification/derivatives thereof.
18 // No right, ownership, or interest to MStar Software and any
19 // modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 // supplied together with third party`s software and the use of MStar
23 // Software may require additional licenses from third parties.
24 // Therefore, you hereby agree it is your sole responsibility to separately
25 // obtain any and all third party right and license necessary for your use of
26 // such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 // MStar`s confidential information and you agree to keep MStar`s
30 // confidential information in strictest confidence and not disclose to any
31 // third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 // kind. Any warranties are hereby expressly disclaimed by MStar, including
35 // without limitation, any warranties of merchantability, non-infringement of
36 // intellectual property rights, fitness for a particular purpose, error free
37 // and in conformity with any international standard. You agree to waive any
38 // claim against MStar for any loss, damage, cost or expense that you may
39 // incur related to your use of MStar Software.
40 // In no event shall MStar be liable for any direct, indirect, incidental or
41 // consequential damages, including without limitation, lost of profit or
42 // revenues, lost or damage of data, and unauthorized system use.
43 // You agree that this Section 4 shall still apply without being affected
44 // even if MStar Software has been modified by MStar in accordance with your
45 // request or instruction for your use, except otherwise agreed by both
46 // parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 // services in relation with MStar Software to you for your use of
50 // MStar Software in conjunction with your or your customer`s product
51 // ("Services").
52 // You understand and agree that, except otherwise agreed by both parties in
53 // writing, Services are provided on an "AS IS" basis and the warranty
54 // disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 // or otherwise:
58 // (a) conferring any license or right to use MStar name, trademark, service
59 // mark, symbol or any other identification;
60 // (b) obligating MStar or any of its affiliates to furnish any person,
61 // including without limitation, you and your customers, any assistance
62 // of any kind whatsoever, or any information; or
63 // (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 // of Taiwan, R.O.C., excluding its conflict of law rules.
67 // Any and all dispute arising out hereof or related hereto shall be finally
68 // settled by arbitration referred to the Chinese Arbitration Association,
69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 // Rules of the Association by three (3) arbitrators appointed in accordance
71 // with the said Rules.
72 // The place of arbitration shall be in Taipei, Taiwan and the language shall
73 // be English.
74 // The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77
78 ///////////////////////////////////////////////////////////////////////////////////////////////////
79 ///
80 /// file apiVDEC_EX_v2.c
81 /// @brief VDEC EXTENSION API FOR DUAL STREAMS
82 /// @author MStar Semiconductor Inc.
83 ///////////////////////////////////////////////////////////////////////////////////////////////////
84
85
86 //-------------------------------------------------------------------------------------------------
87 // Include Files
88 //-------------------------------------------------------------------------------------------------
89
90 #if (!defined(MSOS_TYPE_NUTTX) && !defined(MSOS_TYPE_OPTEE)) || defined(SUPPORT_X_MODEL_FEATURE)
91
92 #include "MsTypes.h"
93 #ifndef MSOS_TYPE_LINUX_KERNEL
94 #include <stdio.h>
95 #include <string.h>
96 #endif
97 #include "utopia_dapi.h"
98 #include "vdec_ex_private.h"
99 //#include "apiVDEC_EX_v2.h"
100 #include "utopia.h"
101
102 #ifndef ANDROID
103 #if defined(MSOS_TYPE_ECOS)
104 #define VPRINTF diag_printf
105 #else
106 #define VPRINTF printf
107 #endif
108 #else
109 #include <sys/mman.h>
110 #include <cutils/ashmem.h>
111 #include <cutils/log.h>
112
113 #define VPRINTF ALOGD
114 #endif
115
116 //-------------------------------------------------------------------------------------------------
117 // Global Variable
118 //-------------------------------------------------------------------------------------------------
119 void* pModuleVDEC_EX_V2 = NULL;
120 char ResourceGroup[E_VDEC_EX_POOL_ID_MAX][20] = {{"VDEC_EX_R0"},};
121
122 //-------------------------------------------------------------------------------------------------
123 // API Function
124 //-------------------------------------------------------------------------------------------------
VDEC_EXRegisterToUtopia(FUtopiaOpen ModuleType)125 void VDEC_EXRegisterToUtopia(FUtopiaOpen ModuleType)
126 {
127 MS_U32 i = 0, j = 0;
128 void* psResource = NULL;
129
130 // 1. deal with module
131 UtopiaModuleCreate(MODULE_VDEC_EX, 0, &pModuleVDEC_EX_V2);
132 UtopiaModuleRegister(pModuleVDEC_EX_V2);
133 UtopiaModuleSetupFunctionPtr(pModuleVDEC_EX_V2,
134 (FUtopiaOpen)VDEC_EX_V2_Open,
135 (FUtopiaClose)VDEC_EX_V2_Close,
136 (FUtopiaIOctl)VDEC_EX_V2_IOctl);
137
138 #if defined(MSOS_TYPE_LINUX_KERNEL)
139 UtopiaModuleSetupSTRFunctionPtr(pModuleVDEC_EX_V2,(FUtopiaSTR)VDEC_EXStr);
140 UtopiaModuleSetSTRPrivate(pModuleVDEC_EX_V2, sizeof(VDEC_EX_INSTANCE_PRIVATE));
141 #endif
142
143 // 2. deal with resource
144 for(i=E_VDEC_EX_POOL_ID_INTERNAL;i<E_VDEC_EX_POOL_ID_MAX;i++) // for each resource group in different memory pool
145 {
146 UtopiaModuleAddResourceStart(pModuleVDEC_EX_V2,i);
147 for(j=0;j<1;j++) // for each resource group in same memory pool
148 {
149 UtopiaResourceCreate(ResourceGroup[i],sizeof(VDEC_EX_RESOURCE_PRIVATE),&psResource);
150 UtopiaResourceRegister(pModuleVDEC_EX_V2,psResource,i);
151 }
152 UtopiaModuleAddResourceEnd(pModuleVDEC_EX_V2,i);
153 }
154 }
155
VDEC_EXStr(MS_U32 u32PowerState,void * pModule)156 MS_U32 VDEC_EXStr(MS_U32 u32PowerState, void* pModule)
157 {
158
159 MS_U32 u32Return = UTOPIA_STATUS_FAIL;
160 #if defined(MSOS_TYPE_LINUX_KERNEL)
161 VDEC_EX_INSTANCE_PRIVATE* psVDEC_EX_InstPri = NULL;
162
163 UtopiaModuleGetSTRPrivate(pModule, (void**)&psVDEC_EX_InstPri);
164
165 if(psVDEC_EX_InstPri == NULL || psVDEC_EX_InstPri->fpVDEC_EX_PreSetControl == NULL)
166 {
167 return UTOPIA_STATUS_FAIL;
168 }
169
170 if (u32PowerState == E_POWER_SUSPEND)
171 {
172 EN_POWER_MODE arg = E_POWER_SUSPEND;
173 void* param[8];
174 param[0] = (void*)(&arg);
175 VDEC_StreamId StreamId;
176 u32Return = psVDEC_EX_InstPri->fpVDEC_EX_PreSetControl(&StreamId,
177 E_VDEC_EX_V2_USER_CMD_SETPOWERSTATE,
178 param);
179 if(u32Return == E_VDEC_EX_OK)
180 return UTOPIA_STATUS_SUCCESS;
181 }
182 else if (u32PowerState == E_POWER_RESUME)
183 {
184 EN_POWER_MODE arg = E_POWER_RESUME;
185 void* param[8];
186 param[0] = (void*)(&arg);
187 VDEC_StreamId StreamId;
188 u32Return = psVDEC_EX_InstPri->fpVDEC_EX_PreSetControl(&StreamId,
189 E_VDEC_EX_V2_USER_CMD_SETPOWERSTATE,
190 param);
191 if(u32Return == E_VDEC_EX_OK)
192 return UTOPIA_STATUS_SUCCESS;
193 }
194 #endif
195 return u32Return;
196 }
197
VDEC_EX_V2_Open(void ** ppInstance,const void * const pAttribute)198 MS_U32 VDEC_EX_V2_Open(void** ppInstance, const void* const pAttribute)
199 {
200 void* pResource = NULL;
201 VDEC_EX_RESOURCE_PRIVATE* pVDEC_EX_ResourcePrivate = NULL;
202 VDEC_EX_INSTANCE_PRIVATE* psVDEC_EX_InstPri = NULL;
203 //MS_U8 i = 0;
204
205 // Check there is available decoder to be use
206 if(UtopiaResourceObtain(pModuleVDEC_EX_V2, E_VDEC_EX_POOL_ID_INTERNAL, &pResource) != UTOPIA_STATUS_SUCCESS)
207 {
208 VPRINTF("UtopiaResourceObtain fail,%s,%d\n",__FUNCTION__,__LINE__);
209 return UTOPIA_STATUS_ERR_RESOURCE;
210 }
211
212
213 UtopiaResourceGetPrivate(pResource,(void*)(&pVDEC_EX_ResourcePrivate));
214
215 #if 0
216 for(i=0;i<SUPPORT_DECODER_NUM_MAX;i++)
217 {
218 if(pVDEC_EX_ResourcePrivate->u8DecoderInUse[i] == 0)
219 {
220 pVDEC_EX_ResourcePrivate->u8DecoderInUse[i] = 1;
221 break;
222 }
223 }
224
225 if(i == SUPPORT_DECODER_NUM_MAX)
226 {
227 VPRINTF("No decoder can be used,%s,%d\n",__FUNCTION__,__LINE__);
228 return UTOPIA_STATUS_ERR_RESOURCE;
229 }
230 #endif
231 UtopiaResourceRelease(pResource);
232
233
234 //Create instance
235 UtopiaInstanceCreate(sizeof(VDEC_EX_INSTANCE_PRIVATE), ppInstance);
236 UtopiaInstanceGetPrivate(*ppInstance, (void**)&psVDEC_EX_InstPri);
237
238 //Recode decoder index
239 //psVDEC_EX_InstPri->Index_of_decoder = i;
240
241 //Link Function pointer
242 psVDEC_EX_InstPri->fpVDEC_EX_GetFreeStream = MApi_VDEC_EX_V2_GetFreeStream;
243 psVDEC_EX_InstPri->fpVDEC_EX_Init = MApi_VDEC_EX_V2_Init;
244 psVDEC_EX_InstPri->fpVDEC_EX_SetControl = MApi_VDEC_EX_V2_SetControl;
245 psVDEC_EX_InstPri->fpVDEC_EX_GetControl = MApi_VDEC_EX_V2_GetControl;
246 psVDEC_EX_InstPri->fpVDEC_EX_PreSetControl = MApi_VDEC_EX_V2_PreSetControl;
247 psVDEC_EX_InstPri->fpVDEC_EX_PostSetControl = MApi_VDEC_EX_V2_PostSetControl;
248
249 #if defined(MSOS_TYPE_LINUX_KERNEL)
250 VDEC_EX_INSTANCE_PRIVATE* psVDEC_EX_STR_InstPri = NULL;
251 UtopiaModuleGetSTRPrivate(pModuleVDEC_EX_V2, (void**)&psVDEC_EX_STR_InstPri);
252
253 psVDEC_EX_STR_InstPri->fpVDEC_EX_GetFreeStream = MApi_VDEC_EX_V2_GetFreeStream;
254 psVDEC_EX_STR_InstPri->fpVDEC_EX_Init = MApi_VDEC_EX_V2_Init;
255 psVDEC_EX_STR_InstPri->fpVDEC_EX_SetControl = MApi_VDEC_EX_V2_SetControl;
256 psVDEC_EX_STR_InstPri->fpVDEC_EX_GetControl = MApi_VDEC_EX_V2_GetControl;
257 psVDEC_EX_STR_InstPri->fpVDEC_EX_PreSetControl = MApi_VDEC_EX_V2_PreSetControl;
258 psVDEC_EX_STR_InstPri->fpVDEC_EX_PostSetControl = MApi_VDEC_EX_V2_PostSetControl;
259 #endif
260
261 return UTOPIA_STATUS_SUCCESS;
262 }
263
264
VDEC_EX_V2_IOctl(void * pInstance,MS_U32 u32Cmd,void * pArgs)265 MS_U32 VDEC_EX_V2_IOctl(void* pInstance, MS_U32 u32Cmd, void* pArgs)
266 {
267 VDEC_EX_INSTANCE_PRIVATE* psVDEC_EX_InstPri = NULL;
268 if(pArgs == NULL)
269 {
270 VPRINTF("[Error]%s,pArgs is NULL\n",__FUNCTION__);
271 return UTOPIA_STATUS_FAIL;
272 }
273 UtopiaInstanceGetPrivate(pInstance, (void*)&psVDEC_EX_InstPri);
274 E_VDEC_EX_V2_IOCTL_CMD IOcmd = (E_VDEC_EX_V2_IOCTL_CMD)u32Cmd;
275 MS_U32 ret = UTOPIA_STATUS_SUCCESS;
276 VDEC_EX_V2_IO_Param* pLocal_Args = (VDEC_EX_V2_IO_Param*)pArgs;
277 VDEC_EX_Result* pRet = (VDEC_EX_Result*)(pLocal_Args->pRet);
278 *pRet = E_VDEC_EX_FAIL;
279 switch(IOcmd)
280 {
281 case E_VDEC_EX_V2_CMD_GET_FREE_STREAM_ID:
282 *pRet = psVDEC_EX_InstPri->fpVDEC_EX_GetFreeStream(pLocal_Args->param[0],
283 *((MS_U32*)(pLocal_Args->param[1])),
284 *((VDEC_EX_Stream*)(pLocal_Args->param[2])),
285 *((VDEC_EX_CodecType*)(pLocal_Args->param[3])));
286 break;
287 case E_VDEC_EX_V2_CMD_INIT:
288 *pRet = psVDEC_EX_InstPri->fpVDEC_EX_Init((VDEC_StreamId*)pLocal_Args->StreamID,(VDEC_EX_InitParam*)(pLocal_Args->param[0]));
289 break;
290 case E_VDEC_EX_V2_CMD_SET_CONTROL:
291 *pRet = psVDEC_EX_InstPri->fpVDEC_EX_SetControl((VDEC_StreamId*)pLocal_Args->StreamID,
292 pLocal_Args->eUserCmd,
293 pLocal_Args->param,
294 FALSE);
295 break;
296 case E_VDEC_EX_V2_CMD_GET_CONTROL:
297 *pRet = psVDEC_EX_InstPri->fpVDEC_EX_GetControl((VDEC_StreamId*)pLocal_Args->StreamID,
298 pLocal_Args->eUserCmd,
299 pLocal_Args->param);
300 break;
301 case E_VDEC_EX_V2_CMD_PRE_SET_CONTROL:
302 *pRet = psVDEC_EX_InstPri->fpVDEC_EX_PreSetControl((VDEC_StreamId*)pLocal_Args->StreamID,
303 pLocal_Args->eUserCmd,
304 pLocal_Args->param);
305 break;
306 case E_VDEC_EX_V2_CMD_POST_SET_CONTROL:
307 *pRet = psVDEC_EX_InstPri->fpVDEC_EX_PostSetControl((VDEC_StreamId*)pLocal_Args->StreamID,
308 pLocal_Args->eUserCmd,
309 pLocal_Args->param);
310 break;
311 default:
312 ret = UTOPIA_STATUS_NOT_SUPPORTED;
313 VPRINTF("Error Command = %d\n",u32Cmd);
314 break;
315 }
316
317 return ret;
318 }
319
VDEC_EX_V2_Close(void * pInstance)320 MS_U32 VDEC_EX_V2_Close(void* pInstance)
321 {
322 void* pResource = NULL;
323 VDEC_EX_RESOURCE_PRIVATE* pVDEC_EX_ResourcePrivate = NULL;
324 VDEC_EX_INSTANCE_PRIVATE* psVDEC_EX_InstPri = NULL;
325
326 // Get instance private
327 UtopiaInstanceGetPrivate(pInstance, (void**)&psVDEC_EX_InstPri);
328
329 // Get resource private
330 if(UtopiaResourceObtain(pModuleVDEC_EX_V2, E_VDEC_EX_POOL_ID_INTERNAL, &pResource) != UTOPIA_STATUS_SUCCESS)
331 {
332 VPRINTF("UtopiaResourceObtain fail,%s,%d\n",__FUNCTION__,__LINE__);
333 return UTOPIA_STATUS_ERR_RESOURCE;
334 }
335
336 UtopiaResourceGetPrivate(pResource,(void*)(&pVDEC_EX_ResourcePrivate));
337
338 // Set using decoder index to 0
339 //pVDEC_EX_ResourcePrivate->u8DecoderInUse[psVDEC_EX_InstPri->Index_of_decoder] = 0;
340
341 UtopiaResourceRelease(pResource);
342
343 UtopiaInstanceDelete(pInstance);
344
345 return UTOPIA_STATUS_SUCCESS;
346 }
347
348 #endif
349
350