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(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 #define VPRINTF printf
104 #else
105 #include <sys/mman.h>
106 #include <cutils/ashmem.h>
107 #include <cutils/log.h>
108
109 #define VPRINTF ALOGD
110 #endif
111
112 //-------------------------------------------------------------------------------------------------
113 // Global Variable
114 //-------------------------------------------------------------------------------------------------
115 void* pModuleVDEC_EX_V2 = NULL;
116 char ResourceGroup[E_VDEC_EX_POOL_ID_MAX][20] = {{"VDEC_EX_R0"},};
117
118 //-------------------------------------------------------------------------------------------------
119 // API Function
120 //-------------------------------------------------------------------------------------------------
VDEC_EXRegisterToUtopia(FUtopiaOpen ModuleType)121 void VDEC_EXRegisterToUtopia(FUtopiaOpen ModuleType)
122 {
123 MS_U32 i = 0, j = 0;
124 void* psResource = NULL;
125
126 // 1. deal with module
127 UtopiaModuleCreate(MODULE_VDEC_EX, 0, &pModuleVDEC_EX_V2);
128 UtopiaModuleRegister(pModuleVDEC_EX_V2);
129 UtopiaModuleSetupFunctionPtr(pModuleVDEC_EX_V2,
130 (FUtopiaOpen)VDEC_EX_V2_Open,
131 (FUtopiaClose)VDEC_EX_V2_Close,
132 (FUtopiaIOctl)VDEC_EX_V2_IOctl);
133
134 // 2. deal with resource
135 for(i=E_VDEC_EX_POOL_ID_INTERNAL;i<E_VDEC_EX_POOL_ID_MAX;i++) // for each resource group in different memory pool
136 {
137 UtopiaModuleAddResourceStart(pModuleVDEC_EX_V2,i);
138 for(j=0;j<1;j++) // for each resource group in same memory pool
139 {
140 UtopiaResourceCreate(ResourceGroup[i],sizeof(VDEC_EX_RESOURCE_PRIVATE),&psResource);
141 UtopiaResourceRegister(pModuleVDEC_EX_V2,psResource,i);
142 }
143 UtopiaModuleAddResourceEnd(pModuleVDEC_EX_V2,i);
144 }
145 }
146
VDEC_EX_V2_Open(void ** ppInstance,const void * const pAttribute)147 MS_U32 VDEC_EX_V2_Open(void** ppInstance, const void* const pAttribute)
148 {
149 void* pResource = NULL;
150 VDEC_EX_RESOURCE_PRIVATE* pVDEC_EX_ResourcePrivate = NULL;
151 VDEC_EX_INSTANCE_PRIVATE* psVDEC_EX_InstPri = NULL;
152 //MS_U8 i = 0;
153
154 // Check there is available decoder to be use
155 if(UtopiaResourceObtain(pModuleVDEC_EX_V2, E_VDEC_EX_POOL_ID_INTERNAL, &pResource) != UTOPIA_STATUS_SUCCESS)
156 {
157 VPRINTF("UtopiaResourceObtain fail,%s,%d\n",__FUNCTION__,__LINE__);
158 return UTOPIA_STATUS_ERR_RESOURCE;
159 }
160
161
162 UtopiaResourceGetPrivate(pResource,(void*)(&pVDEC_EX_ResourcePrivate));
163
164 #if 0
165 for(i=0;i<SUPPORT_DECODER_NUM_MAX;i++)
166 {
167 if(pVDEC_EX_ResourcePrivate->u8DecoderInUse[i] == 0)
168 {
169 pVDEC_EX_ResourcePrivate->u8DecoderInUse[i] = 1;
170 break;
171 }
172 }
173
174 if(i == SUPPORT_DECODER_NUM_MAX)
175 {
176 VPRINTF("No decoder can be used,%s,%d\n",__FUNCTION__,__LINE__);
177 return UTOPIA_STATUS_ERR_RESOURCE;
178 }
179 #endif
180 UtopiaResourceRelease(pResource);
181
182
183 //Create instance
184 UtopiaInstanceCreate(sizeof(VDEC_EX_INSTANCE_PRIVATE), ppInstance);
185 UtopiaInstanceGetPrivate(*ppInstance, (void**)&psVDEC_EX_InstPri);
186
187 //Recode decoder index
188 //psVDEC_EX_InstPri->Index_of_decoder = i;
189
190 //Link Function pointer
191 psVDEC_EX_InstPri->fpVDEC_EX_GetFreeStream = MApi_VDEC_EX_V2_GetFreeStream;
192 psVDEC_EX_InstPri->fpVDEC_EX_Init = MApi_VDEC_EX_V2_Init;
193 psVDEC_EX_InstPri->fpVDEC_EX_SetControl = MApi_VDEC_EX_V2_SetControl;
194 psVDEC_EX_InstPri->fpVDEC_EX_GetControl = MApi_VDEC_EX_V2_GetControl;
195 psVDEC_EX_InstPri->fpVDEC_EX_PreSetControl = MApi_VDEC_EX_V2_PreSetControl;
196 psVDEC_EX_InstPri->fpVDEC_EX_PostSetControl = MApi_VDEC_EX_V2_PostSetControl;
197 return UTOPIA_STATUS_SUCCESS;
198 }
199
200
VDEC_EX_V2_IOctl(void * pInstance,MS_U32 u32Cmd,void * pArgs)201 MS_U32 VDEC_EX_V2_IOctl(void* pInstance, MS_U32 u32Cmd, void* pArgs)
202 {
203 VDEC_EX_INSTANCE_PRIVATE* psVDEC_EX_InstPri = NULL;
204 if(pArgs == NULL)
205 {
206 VPRINTF("[Error]%s,pArgs is NULL\n",__FUNCTION__);
207 return UTOPIA_STATUS_FAIL;
208 }
209 UtopiaInstanceGetPrivate(pInstance, (void*)&psVDEC_EX_InstPri);
210 E_VDEC_EX_V2_IOCTL_CMD IOcmd = (E_VDEC_EX_V2_IOCTL_CMD)u32Cmd;
211 MS_U32 ret = UTOPIA_STATUS_SUCCESS;
212 VDEC_EX_V2_IO_Param* pLocal_Args = (VDEC_EX_V2_IO_Param*)pArgs;
213 VDEC_EX_Result* pRet = (VDEC_EX_Result*)(pLocal_Args->pRet);
214 *pRet = E_VDEC_EX_FAIL;
215 switch(IOcmd)
216 {
217 case E_VDEC_EX_V2_CMD_GET_FREE_STREAM_ID:
218 *pRet = psVDEC_EX_InstPri->fpVDEC_EX_GetFreeStream(pLocal_Args->param[0],
219 *((MS_U32*)(pLocal_Args->param[1])),
220 *((VDEC_EX_Stream*)(pLocal_Args->param[2])),
221 *((VDEC_EX_CodecType*)(pLocal_Args->param[3])));
222 break;
223 case E_VDEC_EX_V2_CMD_INIT:
224 *pRet = psVDEC_EX_InstPri->fpVDEC_EX_Init((VDEC_StreamId*)pLocal_Args->StreamID,(VDEC_EX_InitParam*)(pLocal_Args->param[0]));
225 break;
226 case E_VDEC_EX_V2_CMD_SET_CONTROL:
227 *pRet = psVDEC_EX_InstPri->fpVDEC_EX_SetControl((VDEC_StreamId*)pLocal_Args->StreamID,
228 pLocal_Args->eUserCmd,
229 pLocal_Args->param,
230 FALSE);
231 break;
232 case E_VDEC_EX_V2_CMD_GET_CONTROL:
233 *pRet = psVDEC_EX_InstPri->fpVDEC_EX_GetControl((VDEC_StreamId*)pLocal_Args->StreamID,
234 pLocal_Args->eUserCmd,
235 pLocal_Args->param);
236 break;
237 case E_VDEC_EX_V2_CMD_PRE_SET_CONTROL:
238 *pRet = psVDEC_EX_InstPri->fpVDEC_EX_PreSetControl((VDEC_StreamId*)pLocal_Args->StreamID,
239 pLocal_Args->eUserCmd,
240 pLocal_Args->param);
241 break;
242 case E_VDEC_EX_V2_CMD_POST_SET_CONTROL:
243 *pRet = psVDEC_EX_InstPri->fpVDEC_EX_PostSetControl((VDEC_StreamId*)pLocal_Args->StreamID,
244 pLocal_Args->eUserCmd,
245 pLocal_Args->param);
246 break;
247 default:
248 ret = UTOPIA_STATUS_NOT_SUPPORTED;
249 printf("Error Command = %d\n",u32Cmd);
250 break;
251 }
252
253 return ret;
254 }
255
VDEC_EX_V2_Close(void * pInstance)256 MS_U32 VDEC_EX_V2_Close(void* pInstance)
257 {
258 void* pResource = NULL;
259 VDEC_EX_RESOURCE_PRIVATE* pVDEC_EX_ResourcePrivate = NULL;
260 VDEC_EX_INSTANCE_PRIVATE* psVDEC_EX_InstPri = NULL;
261
262 // Get instance private
263 UtopiaInstanceGetPrivate(pInstance, (void**)&psVDEC_EX_InstPri);
264
265 // Get resource private
266 if(UtopiaResourceObtain(pModuleVDEC_EX_V2, E_VDEC_EX_POOL_ID_INTERNAL, &pResource) != UTOPIA_STATUS_SUCCESS)
267 {
268 VPRINTF("UtopiaResourceObtain fail,%s,%d\n",__FUNCTION__,__LINE__);
269 return UTOPIA_STATUS_ERR_RESOURCE;
270 }
271
272 UtopiaResourceGetPrivate(pResource,(void*)(&pVDEC_EX_ResourcePrivate));
273
274 // Set using decoder index to 0
275 //pVDEC_EX_ResourcePrivate->u8DecoderInUse[psVDEC_EX_InstPri->Index_of_decoder] = 0;
276
277 UtopiaResourceRelease(pResource);
278
279 UtopiaInstanceDelete(pInstance);
280
281 return UTOPIA_STATUS_SUCCESS;
282 }
283
284 #endif
285
286