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 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2006-2007 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // (��MStar Confidential Information��) by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 ////////////////////////////////////////////////////////////////////////////////
94
95 ///////////////////////////////////////////////////////////////////////////////////////////////////
96 ///
97 /// file drvDMS.c
98 /// @author MStar Semiconductor Inc.
99 /// @brief DMS Driver Interface
100 ///////////////////////////////////////////////////////////////////////////////////////////////////
101
102 #define MDRV_DMS_C
103
104 //-------------------------------------------------------------------------------------------------
105 // Include Files
106 //-------------------------------------------------------------------------------------------------
107 // Common Definition
108 #ifdef MSOS_TYPE_LINUX_KERNEL
109 #include <linux/string.h>
110 #else
111 #include <stdlib.h>
112 #include <string.h>
113 #include <unistd.h>
114 #endif
115
116 #include "MsCommon.h"
117 #include "MsVersion.h"
118 #include "drvMMIO.h"
119 #include "drvDMS.h"
120 #include "halDMS.h"
121 #include "UFO.h"
122
123 // utopia DRV
124 #include "drvMVOP.h"
125 #include "drvSYS.h"
126 #include "apiXC.h"
127 #include "apiPNL.h"
128 #include "apiXC_DWIN.h"
129 #include "apiVDEC_EX.h"
130 #include "apiGOP.h"
131 #include "apiGFX.h"
132
133 #include "utopia.h"
134 #include "utopia_dapi.h"
135 #include "apiDMS_private.h"
136
137 #include "halCHIP.h"
138 #include "fwHVD_if.h"
139
140 void* g_pDMSRes = NULL;
141
142 #define DMS_ENABLE_MVOP_INT
143
144 #if 1
145 #include "ULog.h"
146
147 #define DMS_PRINTF(format,args...) ULOGD("DMS", format, ##args)
148 #define DMS_PRINTI(format,args...) ULOGI("DMS", format, ##args)
149 #define DMS_PRINTD(format,args...) ULOGD("DMS", format, ##args)
150 #define DMS_ERR(format,args...) ULOGE("DMS", format, ##args)
151
152 #else
153 #ifndef ANDROID
154 //#define DMS_PRINTF
155 #define DMS_PRINTF printf
156 #else
157 #include <sys/mman.h>
158 #include <cutils/ashmem.h>
159 #include <cutils/log.h>
160
161 #define DMS_PRINTF ALOGD
162 #endif
163 #endif
164
165 // FIXME: it needs XC/MVOP to add it to header file.
166 MS_U8 __attribute__((weak)) MApi_XC_GetSWDSIndex(SCALER_WIN eWindow);
167 void __attribute__((weak)) MApi_SWDS_Fire(SCALER_WIN eWindow);
168 MS_U8 __attribute__((weak)) MDrv_MVOP_GetIntStatus(void);
169 MS_BOOL __attribute__((weak)) MDrv_MVOP_EnableInterrupt(MS_U8 eIntType);
170 MS_U8 __attribute__((weak)) MDrv_MVOP_SubGetIntStatus(void);
171 MS_BOOL __attribute__((weak)) MDrv_MVOP_SubEnableInterrupt(MS_U8 eIntType);
172
173 E_APIXC_ReturnValue __attribute__((weak)) MApi_XC_GetPixelShift(MS_S8 *ps8HOffset, MS_S8 *ps8VOffset);
174
175 //-------------------------------------------------------------------------------------------------
176 // Driver Compiler Options
177 //-------------------------------------------------------------------------------------------------
178 #define DMS_FHD_Hszie 1920
179 #define DMS_FHD_Vszie 1080
180 #define DMS_4K_Hsize 4096
181 #define DMS_4K_Vsize 2160
182
183 #define NEW_FLIP 1
184 #define ENABLE_FRAME_CONVERT 1
185
186 //------------------------------------------------------------------------------
187 // Macros
188 //------------------------------------------------------------------------------
189 #define DNRFrameNUM 5
190 #define DMS_INVALID_FRAME_ID 0xFF
191 #define FRAME_DURATION(x) (1000000 / ((x) ? (x) : 30000))
192 #define WAIT_MVOP_TIME 100 // 0.1 ms
193 #define DISPQ_FIRST_R_INDEX 1
194
195 static MS_S32 s32DMSEventID[DMS_MAX_WINDOW_NUM] = {-1, -1};
196 static MS_S32 s32DMSTaskID[DMS_MAX_WINDOW_NUM] = {-1, -1};
197 static MS_S32 s32DMSVsyncEventID[DMS_MAX_WINDOW_NUM] = {-1, -1};
198
199 static DMS_DRV_CTRL gDMSCtrl[DMS_MAX_WINDOW_NUM];
200
201 static MS_BOOL bMsLogON = FALSE;
202
203 //Marco to simplize resource usage
204 #define DMS_GET_RES_PRI DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;\
205 UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri))
206
207 #define RES_DMS pDMSResPri->stDrvDMS
208 //#define RES_DMSCAPTURE pDMSResPri->stDrvDMSCapMode
209
210 #define ENABLE_DMS_MUTEX
211 #ifdef ENABLE_DMS_MUTEX
212 static MS_S32 s32DMSMutexID[DMS_MAX_WINDOW_NUM] = {-1, -1};
213
214 #define _DRV_DMS_MutexCreate(WinID) \
215 do \
216 { \
217 if (s32DMSMutexID[WinID] < 0) \
218 { \
219 if (WinID) { \
220 s32DMSMutexID[WinID] = MsOS_CreateMutex(E_MSOS_FIFO, "DMS_Drv_0", MSOS_PROCESS_SHARED); \
221 } else { \
222 s32DMSMutexID[WinID] = MsOS_CreateMutex(E_MSOS_FIFO, "DMS_Drv_1", MSOS_PROCESS_SHARED); \
223 } \
224 } \
225 } while (0)
226
227 #define _DRV_DMS_MutexDelete(WinID) \
228 do \
229 { \
230 if (s32DMSMutexID[WinID] >= 0) \
231 { \
232 MsOS_DeleteMutex(s32DMSMutexID[WinID]); \
233 s32DMSMutexID[WinID] = -1; \
234 } \
235 } while (0)
236
237 #define _DRV_DMS_Entry(WinID) \
238 do \
239 { \
240 if (s32DMSMutexID[WinID] >= 0) \
241 { \
242 if (!MsOS_ObtainMutex(s32DMSMutexID[WinID], MSOS_WAIT_FOREVER)) \
243 { \
244 DMS_PRINTF("[DMS][%06d] Mutex taking timeout\n", __LINE__); \
245 } \
246 } \
247 } while (0)
248
249 #define _DRV_DMS_Return(WinID, _ret_) \
250 do \
251 { \
252 if (s32DMSMutexID[WinID] >= 0) \
253 { \
254 MsOS_ReleaseMutex(s32DMSMutexID[WinID]); \
255 } \
256 return _ret_; \
257 } while(0)
258
259 #define _DRV_DMS_Release(WinID) \
260 do \
261 { \
262 if (s32DMSMutexID[WinID] >= 0) \
263 { \
264 MsOS_ReleaseMutex(s32DMSMutexID[WinID]); \
265 } \
266 } while (0)
267
268 #else
269
270 #define _DRV_DMS_MutexCreate(WinID)
271 #define _DRV_DMS_MutexDelete(WinID)
272 #define _DRV_DMS_Entry(WinID)
273 #define _DRV_DMS_Return(WinID, _ret) {return _ret;}
274 #define _DRV_DMS_Release(WinID)
275
276 #endif
277
278 //-------------------------------------------------------------------------------------------------
279 // Global Variables
280 //-------------------------------------------------------------------------------------------------
281
282 //-------------------------------------------------------------------------------------------------
283 // Local Variables
284 //-------------------------------------------------------------------------------------------------
285 MS_U16 gDMS_externDebugFlag = 0;
286 //MS_U16 gDMSMVOPForceLookVDEC = 0;
287 #define sync_print(fmt, args...) do { if(0) DMS_PRINTF(fmt, ##args); } while (0)
288 MS_U16 gDMSDebug = 0;
289 void* pTaskInstance = NULL;
290
291 #define DBG_DISABLE_SEMAPHORE 0
MDrv_DMS_Get_Semaphore(void * pInstance,EN_DMS_POOL_TYPE ePoolType)292 MS_U32 MDrv_DMS_Get_Semaphore(void* pInstance, EN_DMS_POOL_TYPE ePoolType)
293 {
294 #if DBG_DISABLE_SEMAPHORE
295 static MS_BOOL bGetRes = FALSE;
296 if(bGetRes)
297 {
298 return UTOPIA_STATUS_SUCCESS;
299 }
300 #endif
301 MS_U32 u32Return = UTOPIA_STATUS_FAIL;
302 //DMS_PRINTF("get SHM!!\n");
303 if (pInstance == NULL)
304 {
305 DMS_PRINTF("[%s, %d]No instance existed, please get an instance by calling MApi_DMS_Init() first\n", __FUNCTION__, __LINE__);
306 return u32Return;
307 }
308
309 void* pModule = NULL;
310 UtopiaInstanceGetModule(pInstance, &pModule);
311 if(UtopiaResourceObtain(pModule, E_DMS_POOL_ID_INTERNAL_VARIABLE, &g_pDMSRes) != UTOPIA_STATUS_SUCCESS)
312 {
313 DMS_PRINTF("UtopiaResourceObtain fail\n");
314 return UTOPIA_STATUS_ERR_RESOURCE;
315 }
316
317 u32Return = UTOPIA_STATUS_SUCCESS;
318 #if DBG_DISABLE_SEMAPHORE
319 printf("\033[1;31m Disable semaphore get!!!!!!!!!!!!!!!!\033[0m\n");
320 bGetRes = TRUE;
321 #endif
322 return u32Return;
323 }
324
MDrv_DMS_Release_Semaphore(void * pInstance,EN_DMS_POOL_TYPE ePoolType)325 MS_U32 MDrv_DMS_Release_Semaphore(void* pInstance, EN_DMS_POOL_TYPE ePoolType)
326 {
327 #if DBG_DISABLE_SEMAPHORE
328 return UTOPIA_STATUS_SUCCESS;
329 #endif
330 //DMS_PRINTF("release SHM!!\n");
331 MS_U32 u32Return = UTOPIA_STATUS_FAIL;
332 u32Return = UtopiaResourceRelease(g_pDMSRes);
333 return u32Return;
334 }
335
336 //-------------------------------------------------------------------------------------------------
337 // Local Defines
338 //-------------------------------------------------------------------------------------------------
_DMS_Wait_MVOP_Vsync(unsigned char Overlay_ID,const ST_DMS_DISPFRAMEFORMAT * dff)339 static void _DMS_Wait_MVOP_Vsync(unsigned char Overlay_ID, const ST_DMS_DISPFRAMEFORMAT *dff)
340 {
341 #ifdef DMS_ENABLE_MVOP_INT
342 MVOP_Handle stMvopHd;
343 MS_U16 u16Vcnt = 0;
344 MS_BOOL bEnable = FALSE;
345 MS_U32 u32WaitEventFlag = E_MVOP_INT_VSYNC;
346 MS_U32 u32Events = 0;
347
348 if (Overlay_ID == 0) {
349 MDrv_MVOP_GetIsEnable(&bEnable);
350 } else {
351 MDrv_MVOP_SubGetIsEnable(&bEnable);
352 }
353
354 if (!bEnable || !gDMSCtrl[Overlay_ID].bVsyncIntAlive) {
355 if (bMsLogON)
356 DMS_PRINTF("MVOP not enable bVsyncIntAlive = %d !!\n", gDMSCtrl[Overlay_ID].bVsyncIntAlive);
357 return;
358 }
359
360 if (s32DMSVsyncEventID[Overlay_ID] == -1) {
361 DMS_PRINTF("s32DMSVsyncEventID[%d] = %d !!\n", Overlay_ID, (int)s32DMSVsyncEventID[Overlay_ID]);
362 return;
363 }
364
365 MsOS_WaitEvent(s32DMSVsyncEventID[Overlay_ID], u32WaitEventFlag, &u32Events, E_OR_CLEAR, FRAME_DURATION(dff->u32FrameRate));
366 MDrv_MVOP_GetCommand(&stMvopHd, E_MVOP_CMD_GET_VCOUNT, &u16Vcnt, sizeof(u16Vcnt));
367
368 if (bMsLogON)
369 DMS_PRINTF("[%d] Wait mvop timing end u16Vcnt = %d !!\n", Overlay_ID, u16Vcnt);
370 #endif
371 }
372
_DMS_Need_XC_HDR_DS(const ST_DMS_DISPFRAMEFORMAT * pstDispFrameFormat)373 static MS_BOOL _DMS_Need_XC_HDR_DS(const ST_DMS_DISPFRAMEFORMAT *pstDispFrameFormat)
374 {
375 #if defined(UFO_XC_SET_DSINFO_V0) && (API_XCDS_INFO_VERSION >= 2)
376 if (pstDispFrameFormat->u32CodecType == E_DMS_CODEC_TYPE_HEVC_DV
377 || (pstDispFrameFormat->stHDRInfo.u32FrmInfoExtAvail &
378 (E_DMS_HDR_METADATA_TCH + E_DMS_HDR_METADATA_HDR10_PER_FRAME + E_DMS_HDR_METATYPE_DYNAMIC))) {
379
380 if ((pstDispFrameFormat->stHDRInfo.u32FrmInfoExtAvail & E_DMS_HDR_METATYPE_DYNAMIC)
381 && !pstDispFrameFormat->stHDRInfo.stDolbyHDRInfo.u8DMEnable) {
382 return FALSE;
383 }
384
385 return TRUE;
386 } else
387 #endif
388 {
389 return FALSE;
390 }
391 }
392
_DMS_Update_DS_Table(void * pInstance,unsigned char Overlay_ID,ST_DMS_DISPFRAMEFORMAT * dff,MS_U8 u8FrameIndex,MS_BOOL bSizeChange)393 static void _DMS_Update_DS_Table(void* pInstance, unsigned char Overlay_ID, ST_DMS_DISPFRAMEFORMAT *dff, MS_U8 u8FrameIndex, MS_BOOL bSizeChange)
394 {
395 MS_U32 u32Time = MsOS_GetSystemTime();
396 MS_U16 u16Width = dff->stFrames[u8FrameIndex].u32Width
397 - dff->stFrames[u8FrameIndex].u32CropLeft
398 - dff->stFrames[u8FrameIndex].u32CropRight;
399 MS_U16 u16Height = dff->stFrames[u8FrameIndex].u32Height
400 - dff->stFrames[u8FrameIndex].u32CropTop
401 - dff->stFrames[u8FrameIndex].u32CropBottom;
402 XC_SETWIN_INFO stXC_SetWin_Info;
403 memset(&stXC_SetWin_Info, 0, sizeof(XC_SETWIN_INFO));
404
405
406 ST_DMS_WINDOW CropWin = {0, 0, 0, 0};
407 ST_DMS_WINDOW DispWin = {0, 0, 0, 0};;
408
409 DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
410 UtopiaResourceGetPrivate(g_pDMSRes, (void**)(&pDMSResPri));
411 MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
412 if (pDMSResPri->stDrvDMS.bWindowInfoReady[Overlay_ID]) {
413 DispWin.u32x = pDMSResPri->stDrvDMS.stDisplayWin[Overlay_ID].u32x;
414 DispWin.u32y = pDMSResPri->stDrvDMS.stDisplayWin[Overlay_ID].u32y;
415 DispWin.u32width = pDMSResPri->stDrvDMS.stDisplayWin[Overlay_ID].u32width;
416 DispWin.u32height = pDMSResPri->stDrvDMS.stDisplayWin[Overlay_ID].u32height;
417
418 CropWin.u32x = pDMSResPri->stDrvDMS.stOutputWinInfo[Overlay_ID].stCropWin.u32x;
419 CropWin.u32y = pDMSResPri->stDrvDMS.stOutputWinInfo[Overlay_ID].stCropWin.u32y;
420 CropWin.u32width = pDMSResPri->stDrvDMS.stOutputWinInfo[Overlay_ID].stCropWin.u32width;
421 CropWin.u32height = pDMSResPri->stDrvDMS.stOutputWinInfo[Overlay_ID].stCropWin.u32height;
422
423 // clear the outside crop win
424 memset(&pDMSResPri->stDrvDMS.stOutputWinInfo[Overlay_ID].stCropWin, 0, sizeof(ST_DMS_WINDOW));
425 }
426
427 if (CropWin.u32x || CropWin.u32y
428 || CropWin.u32width || CropWin.u32height) {
429 // outside crop win assigned
430 gDMSCtrl[Overlay_ID].stOutSideCropWin = CropWin;
431 gDMSCtrl[Overlay_ID].u32WidthForOutsideCrop = u16Width;
432 gDMSCtrl[Overlay_ID].u32HeightForOutsideCrop = u16Height;
433
434 } else if (gDMSCtrl[Overlay_ID].stOutSideCropWin.u32x || gDMSCtrl[Overlay_ID].stOutSideCropWin.u32y
435 || gDMSCtrl[Overlay_ID].stOutSideCropWin.u32width || gDMSCtrl[Overlay_ID].stOutSideCropWin.u32height) {
436 // apply the saved crop ratio
437
438 CropWin.u32x = (u16Width * gDMSCtrl[Overlay_ID].stOutSideCropWin.u32x) / gDMSCtrl[Overlay_ID].u32WidthForOutsideCrop;
439 CropWin.u32y = (u16Height * gDMSCtrl[Overlay_ID].stOutSideCropWin.u32y) / gDMSCtrl[Overlay_ID].u32HeightForOutsideCrop;
440 CropWin.u32width = (u16Width * gDMSCtrl[Overlay_ID].stOutSideCropWin.u32width) / gDMSCtrl[Overlay_ID].u32WidthForOutsideCrop;
441 CropWin.u32height = (u16Height * gDMSCtrl[Overlay_ID].stOutSideCropWin.u32height) / gDMSCtrl[Overlay_ID].u32HeightForOutsideCrop;
442
443 } else {
444 // no out side crop win, use source video crop win
445 CropWin.u32x = dff->stFrames[u8FrameIndex].u32CropLeft;
446 CropWin.u32y = dff->stFrames[u8FrameIndex].u32CropTop;
447 CropWin.u32width = u16Width;
448 CropWin.u32height = u16Height;
449 }
450
451 pDMSResPri->stDrvDMS.bWinChanged[Overlay_ID] = FALSE;
452
453 if (!pDMSResPri->stDrvDMS.bWindowInfoReady[Overlay_ID]) {
454 // no window info, only trigger MApi_XC_SetDSInfo / MApi_SWDS_Fire / MApi_XC_GetSWDSIndex
455 bSizeChange = FALSE;
456 }
457
458 MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
459
460 if (!MApi_XC_GetDynamicScalingStatus()) {
461 DMS_PRINTF("MApi_XC_GetDynamicScalingStatus() is FALSE\n");
462 return;
463 }
464
465 // apple panel ratio
466 // ....
467
468 #ifdef UFO_XC_SETWINDOW_LITE
469 ST_XC_APISTATUSNODELAY stXCStatus;
470 #else
471 XC_ApiStatus stXCStatus;
472 #endif
473
474 MVOP_Timing stMVOPTiming;
475
476 if (Overlay_ID) {
477 MDrv_MVOP_SubGetOutputTiming(&stMVOPTiming);
478 } else {
479 MDrv_MVOP_GetOutputTiming(&stMVOPTiming);
480 }
481
482 // get scaler information
483 #ifdef UFO_XC_SETWINDOW_LITE
484 if (MApi_XC_GetStatusNodelay(&stXCStatus, (SCALER_WIN) Overlay_ID) == FALSE) {
485 DMS_PRINTF("MApi_XC_GetStatusNodealy failed.\n");
486 }
487 #else
488 if (MApi_XC_GetStatus(&stXCStatus, (SCALER_WIN) Overlay_ID) == FALSE) {
489 DMS_PRINTF("MApi_XC_GetStatus failed.\n");
490 }
491 #endif
492
493 stXC_SetWin_Info.enInputSourceType = stXCStatus.enInputSourceType;
494
495 if (Overlay_ID) {
496 stXC_SetWin_Info.stCapWin.x = MDrv_MVOP_SubGetHStart();
497 stXC_SetWin_Info.stCapWin.y = MDrv_MVOP_SubGetVStart();
498 } else {
499 stXC_SetWin_Info.stCapWin.x = MDrv_MVOP_GetHStart();
500 stXC_SetWin_Info.stCapWin.y = MDrv_MVOP_GetVStart();
501 }
502
503 stXC_SetWin_Info.stCapWin.width = u16Width;
504 stXC_SetWin_Info.stCapWin.height = u16Height;
505
506 stXC_SetWin_Info.stDispWin.width = stXCStatus.stDispWin.width;
507 stXC_SetWin_Info.stDispWin.height = stXCStatus.stDispWin.height;
508
509 // Timing
510 stXC_SetWin_Info.bHDuplicate = stMVOPTiming.bHDuplicate;
511 stXC_SetWin_Info.u16InputVTotal = stMVOPTiming.u16V_TotalCount;
512 stXC_SetWin_Info.bInterlace = stMVOPTiming.bInterlace;
513 if (stXC_SetWin_Info.bInterlace) {
514 stXC_SetWin_Info.u16InputVFreq = (stMVOPTiming.u16ExpFrameRate * 2) / 100;
515 } else {
516 stXC_SetWin_Info.u16InputVFreq = stMVOPTiming.u16ExpFrameRate / 100;
517 }
518
519 if (gDMSCtrl[Overlay_ID].u8ForcePMode) {
520 DMS_PRINTF("set real interlace mode to XC %d\n", dff->u8Interlace);
521 stXC_SetWin_Info.bInterlace = dff->u8Interlace;
522 }
523
524 #ifndef UFO_XC_SETWINDOW_LITE
525 stXC_SetWin_Info.u16DefaultHtotal = stXCStatus.u16DefaultHtotal;
526 stXC_SetWin_Info.u8DefaultPhase = stXCStatus.u8DefaultPhase;
527
528 // customized scaling //post
529 stXC_SetWin_Info.bHCusScaling = stXCStatus.bHCusScaling;
530 stXC_SetWin_Info.u16HCusScalingSrc = stXCStatus.u16HCusScalingSrc; //stXC_SetWin_Info.stCapWin.width
531 stXC_SetWin_Info.u16HCusScalingDst = stXCStatus.u16HCusScalingDst;
532 stXC_SetWin_Info.bVCusScaling = stXCStatus.bVCusScaling;
533 stXC_SetWin_Info.u16VCusScalingSrc = stXCStatus.u16VCusScalingSrc; //stXC_SetWin_Info.stCapWin.height
534 stXC_SetWin_Info.u16VCusScalingDst = stXCStatus.u16VCusScalingDst;
535 // 9 lattice
536 stXC_SetWin_Info.bDisplayNineLattice = stXCStatus.bDisplayNineLattice;
537 #else
538 stXC_SetWin_Info.bHCusScaling = 0;
539 stXC_SetWin_Info.bVCusScaling = 0;
540 #endif
541
542 //add // force disable prescaling
543 stXC_SetWin_Info.bPreHCusScaling = TRUE;
544 stXC_SetWin_Info.bPreVCusScaling = TRUE;
545 stXC_SetWin_Info.u16PreHCusScalingSrc = stXC_SetWin_Info.stCapWin.width;
546 if (gDMSCtrl[Overlay_ID].u8SaveBandwidthMode && (u16Width >= 3840)) {
547 // for saving BW, 4K video H prescaling down 1/2
548 stXC_SetWin_Info.u16PreHCusScalingDst = stXC_SetWin_Info.stCapWin.width / 2;
549 } else if (u16Width >= 3840) {
550 // exceed 3840, prescaling down to 3840
551 stXC_SetWin_Info.u16PreHCusScalingDst = 3840;
552 } else {
553 stXC_SetWin_Info.u16PreHCusScalingDst = stXC_SetWin_Info.stCapWin.width;
554 }
555 stXC_SetWin_Info.u16PreVCusScalingSrc = stXC_SetWin_Info.stCapWin.height;
556 // height exceed 2160, prescaling down to 2160
557 if (u16Height >= 2160) {
558 stXC_SetWin_Info.u16PreVCusScalingDst = 2160;
559 } else {
560 stXC_SetWin_Info.u16PreVCusScalingDst = stXC_SetWin_Info.stCapWin.height;
561 }
562
563 if (bSizeChange) {
564 #if 0
565 DMS_PRINTF("[%s,%5d] DispW:%d DispH:%d \n", __func__, __LINE__,
566 stXC_SetWin_Info.stDispWin.width, stXC_SetWin_Info.stDispWin.height);
567
568 DMS_PRINTF("[%s,%5d] Cap.x:%d Cap.y:%d CapW:%d CapH:%d \n", __func__, __LINE__,
569 stXC_SetWin_Info.stCapWin.x, stXC_SetWin_Info.stCapWin.y,
570 stXC_SetWin_Info.stCapWin.width, stXC_SetWin_Info.stCapWin.height);
571 DMS_PRINTF("[%s,%5d] enInputSourceType:%d \n",__func__,__LINE__,stXC_SetWin_Info.enInputSourceType);
572 DMS_PRINTF("[%s,%5d] u16InputVTotal:%d u16InputVFreq:%d \n", __func__, __LINE__,
573 stXC_SetWin_Info.u16InputVTotal, stXC_SetWin_Info.u16InputVFreq);
574 DMS_PRINTF("[%s,%5d] bInterlace:%d u16DefaultHtotal:%d \n", __func__, __LINE__,
575 stXC_SetWin_Info.bInterlace, stXC_SetWin_Info.u16DefaultHtotal);
576 //prescaling
577 DMS_PRINTF("[%s,%5d] bPreHCusScaling:%d bPreVCusScaling:%d \n", __func__, __LINE__,
578 stXC_SetWin_Info.bPreHCusScaling, stXC_SetWin_Info.bPreVCusScaling);
579 DMS_PRINTF("[%s,%5d] u16PreHCusScalingSrc:%d u16PreHCusScalingDst:%d \n", __func__, __LINE__,
580 stXC_SetWin_Info.u16PreHCusScalingSrc, stXC_SetWin_Info.u16PreHCusScalingDst);
581 DMS_PRINTF("[%s,%5d] u16PreVCusScalingSrc:%d u16PreVCusScalingSrc:%d \n", __func__, __LINE__,
582 stXC_SetWin_Info.u16PreVCusScalingSrc, stXC_SetWin_Info.u16PreVCusScalingDst);
583 //postscaling
584 DMS_PRINTF("[%s,%5d] bHCusScaling:%d bVCusScaling:%d \n", __func__, __LINE__,
585 stXC_SetWin_Info.bHCusScaling, stXC_SetWin_Info.bVCusScaling);
586 DMS_PRINTF("[%s,%5d] u16HCusScalingSrc:%d u16HCusScalingDst:%d \n", __func__, __LINE__,
587 stXC_SetWin_Info.u16HCusScalingSrc, stXC_SetWin_Info.u16HCusScalingDst);
588 DMS_PRINTF("[%s,%5d] u16VCusScalingSrc:%d u16VCusScalingDst:%d \n", __func__, __LINE__,
589 stXC_SetWin_Info.u16VCusScalingSrc, stXC_SetWin_Info.u16VCusScalingDst);
590 #endif
591
592 #ifdef PORTING_MMSDK
593 if ((OutSideCropWin[Overlay_ID].x != 0)
594 || (OutSideCropWin[Overlay_ID].y != 0)
595 || (OutSideCropWin[Overlay_ID].width != 0)
596 || (OutSideCropWin[Overlay_ID].height != 0)) {
597
598 vInfo.u16CropLeft = OutSideCropWin[Overlay_ID].x;
599 vInfo.u16CropTop = OutSideCropWin[Overlay_ID].y;
600 vInfo.u16CropRight = vInfo.u16HorSize
601 - OutSideCropWin[Overlay_ID].x
602 - OutSideCropWin[Overlay_ID].width;
603 vInfo.u16CropBottom = vInfo.u16VerSize
604 - OutSideCropWin[Overlay_ID].y
605 - OutSideCropWin[Overlay_ID].height;
606
607 DMS_PRINTF("update ds table src w:%d h:%d, **apply** crop w:%d h:%d, disp w:%d h:%d\n",
608 u16SrcWidth[Overlay_ID], u16SrcHeight[Overlay_ID],
609 OutSideCropWin[Overlay_ID].width, OutSideCropWin[Overlay_ID].height,
610 OutputWin[Overlay_ID].width, OutputWin[Overlay_ID].height);
611 DMS_PRINTF("apply dff crop x:%d y:%d w:%d h:%d\n", vInfo.u16CropLeft, vInfo.u16CropTop,
612 vInfo.u16HorSize - vInfo.u16CropLeft - vInfo.u16CropRight,
613 vInfo.u16VerSize - vInfo.u16CropTop - vInfo.u16CropBottom);
614
615 OutSideCropWinRatio[Overlay_ID].x = (float)OutSideCropWin[Overlay_ID].x / (float)u16Width;
616 OutSideCropWinRatio[Overlay_ID].y = (float)OutSideCropWin[Overlay_ID].y / (float)u16Height;
617 OutSideCropWinRatio[Overlay_ID].width = (float)OutSideCropWin[Overlay_ID].width / (float)u16Width;
618 OutSideCropWinRatio[Overlay_ID].height = (float)OutSideCropWin[Overlay_ID].height / (float)u16Height;
619
620 DMS_PRINTF("save crop ratio x:%f y:%f w:%f h:%f\n", OutSideCropWinRatio[Overlay_ID].x,
621 OutSideCropWinRatio[Overlay_ID].y,
622 OutSideCropWinRatio[Overlay_ID].width,
623 OutSideCropWinRatio[Overlay_ID].height);
624 } else if ((OutSideCropWinRatio[Overlay_ID].x != 0)
625 || (OutSideCropWinRatio[Overlay_ID].y != 0)
626 || (OutSideCropWinRatio[Overlay_ID].width != 0)
627 || (OutSideCropWinRatio[Overlay_ID].height != 0)) {
628
629 MS_WINDOW newCropWin;
630
631 newCropWin.x = u16Width * OutSideCropWinRatio[Overlay_ID].x;
632 newCropWin.y = u16Height * OutSideCropWinRatio[Overlay_ID].y;
633 newCropWin.width = u16Width * OutSideCropWinRatio[Overlay_ID].width;
634 newCropWin.height = u16Height * OutSideCropWinRatio[Overlay_ID].height;
635
636 vInfo.u16CropLeft = newCropWin.x;
637 vInfo.u16CropTop = newCropWin.y;
638 vInfo.u16CropRight = vInfo.u16HorSize
639 - newCropWin.x
640 - newCropWin.width;
641 vInfo.u16CropBottom = vInfo.u16VerSize
642 - newCropWin.y
643 - newCropWin.height;
644
645 DMS_PRINTF("apply saved crop ratio x:%d y:%d w:%d h:%d\n", vInfo.u16CropLeft, vInfo.u16CropTop,
646 vInfo.u16HorSize - vInfo.u16CropLeft - vInfo.u16CropRight,
647 vInfo.u16VerSize - vInfo.u16CropTop - vInfo.u16CropBottom);
648 }
649 #endif
650
651 #ifndef PORTING_MMSDK
652 //vsync_bridge_CalAspectRatio(Overlay_ID, &DispWin, &CropWin, dff, TRUE);
653 #endif
654
655 #if 0
656 if (bSizeChange) {
657 Wrapper_SurfaceVideoSizeChange(Overlay_ID, DispWin.x,
658 DispWin.y, DispWin.width, DispWin.height, u16SrcWidth[Overlay_ID],
659 u16SrcHeight[Overlay_ID]);
660 }
661 #endif
662
663 if (gDMSCtrl[Overlay_ID].u8MirrorMode & E_VOPMIRROR_HORIZONTALL) {
664 DispWin.u32x = gDMSCtrl[Overlay_ID].panelWidth - (DispWin.u32x + DispWin.u32width);
665 CropWin.u32x = u16Width - (CropWin.u32x + CropWin.u32width);
666 }
667 if (gDMSCtrl[Overlay_ID].u8MirrorMode & E_VOPMIRROR_VERTICAL) {
668 DispWin.u32y = gDMSCtrl[Overlay_ID].panelHeight - (DispWin.u32y + DispWin.u32height);
669 CropWin.u32y = u16Height - (CropWin.u32y + CropWin.u32height);
670 }
671 if (bSizeChange && (gDMSCtrl[Overlay_ID].u8MirrorMode & E_VOPMIRROR_HVBOTH)) {
672 DMS_PRINTF("DS MVOP Mirror %d [%d %d %d %d] [%d %d %d %d]\n", (int)gDMSCtrl[Overlay_ID].u8MirrorMode,
673 (int)DispWin.u32x, (int)DispWin.u32y, (int)DispWin.u32width, (int)DispWin.u32height,
674 (int)CropWin.u32x, (int)CropWin.u32y, (int)CropWin.u32width, (int)CropWin.u32height);
675 }
676
677 stXC_SetWin_Info.stCropWin.x = CropWin.u32x;
678 stXC_SetWin_Info.stCropWin.y = CropWin.u32y;
679 stXC_SetWin_Info.stCropWin.width = CropWin.u32width;
680 stXC_SetWin_Info.stCropWin.height = CropWin.u32height;
681
682 stXC_SetWin_Info.stDispWin.x = DispWin.u32x;
683 stXC_SetWin_Info.stDispWin.y = DispWin.u32y;
684 stXC_SetWin_Info.stDispWin.width = DispWin.u32width;
685 stXC_SetWin_Info.stDispWin.height = DispWin.u32height;
686
687 if (!stXC_SetWin_Info.stDispWin.width || !stXC_SetWin_Info.stDispWin.height) {
688 DMS_PRINTF("[%s,%5d] Disp Win is 0, set a default value\n", __func__, __LINE__);
689 stXC_SetWin_Info.stDispWin.x = 0;
690 stXC_SetWin_Info.stDispWin.y = 0;
691 stXC_SetWin_Info.stDispWin.width = g_IPanel.Width();
692 stXC_SetWin_Info.stDispWin.height = g_IPanel.Height();
693 }
694
695 // disable force index !!!!!!!!!!!!!!!!!
696 MApi_XC_Set_DSForceIndex(0, 0, (SCALER_WIN)Overlay_ID);
697 DMS_PRINTF("[%s,%5d] SW DS !!! u8ForceInterlace = %d\n", __func__, __LINE__, gDMSCtrl[Overlay_ID].u8ForceInterlace);
698 DMS_PRINTF("[%s,%5d] Cap.x:%d Cap.y:%d Cap.W:%d Cap.H:%d \n", __func__, __LINE__,
699 stXC_SetWin_Info.stCapWin.x, stXC_SetWin_Info.stCapWin.y,
700 stXC_SetWin_Info.stCapWin.width, stXC_SetWin_Info.stCapWin.height);
701 DMS_PRINTF("[%s,%5d] Disp.x:%d Disp.y:%d Disp.W:%d Disp.H:%d \n", __func__, __LINE__,
702 stXC_SetWin_Info.stDispWin.x, stXC_SetWin_Info.stDispWin.y,
703 stXC_SetWin_Info.stDispWin.width, stXC_SetWin_Info.stDispWin.height);
704 DMS_PRINTF("[%s,%5d] Crop.x:%d Crop.y:%d Crop.W:%d Crop.H:%d \n", __func__, __LINE__,
705 stXC_SetWin_Info.stCropWin.x, stXC_SetWin_Info.stCropWin.y,
706 stXC_SetWin_Info.stCropWin.width, stXC_SetWin_Info.stCropWin.height);
707 DMS_PRINTF("[%s,%5d] MApi_XC_GetDynamicScalingStatus():%d \n", __func__, __LINE__, MApi_XC_GetDynamicScalingStatus());
708 }
709
710 if (MApi_XC_GetDynamicScalingStatus()) {
711
712 #ifdef UFO_XC_SWDS_SW_FILM_ENABLE
713 if ((gDMSCtrl[Overlay_ID].u8ForceInterlace || gDMSCtrl[Overlay_ID].u8ForcePMode) && MApi_XC_Set_DS_ForceI_DeInterlaceMode) {
714 DMS_PRINTF("[%s,%5d] SW DS !!! \n", __func__, __LINE__);
715 DMS_PRINTF("[%s,%5d] MApi_XC_Set_DS_ForceI_DeInterlaceMode %d %d\n", __func__, __LINE__, dff->u8Interlace, dff->u32FrameRate);
716 MApi_XC_Set_DS_ForceI_DeInterlaceMode(dff->u8Interlace ? 0 : 1, TRUE, dff->u32FrameRate, (SCALER_WIN)Overlay_ID);
717 }
718 #endif
719
720 #ifdef UFO_XC_SET_DSINFO_V0
721 // Inform xc to update the ds info in mcu mode
722 if (MApi_XC_SetDSInfo)
723 {
724 XC_DS_INFO stXCDSInfo = {0, };
725
726 stXCDSInfo.u32ApiDSInfo_Version = API_XCDS_INFO_VERSION;
727 stXCDSInfo.u16ApiDSInfo_Length = sizeof(XC_DS_INFO);
728 stXCDSInfo.bUpdate_DS_CMD[(SCALER_WIN) Overlay_ID] = TRUE;
729
730 #if (API_XCDS_INFO_VERSION == 1)
731 if (sizeof(XC_DS_HDRInfo) == sizeof(MS_HDRInfo)) {
732 memcpy(&stXCDSInfo.stHDRInfo, &dff->sHDRInfo, sizeof(XC_DS_HDRInfo));
733 } else {
734 DMS_PRINTF("MS_HDRInfo/XC_DS_HDRInfo size is not match\n");
735 }
736 #elif (API_XCDS_INFO_VERSION >= 2)
737 stXCDSInfo.stHDRInfo.u32FrmInfoExtAvail = dff->stHDRInfo.u32FrmInfoExtAvail;
738
739 stXCDSInfo.stHDRInfo.stColorDescription.u8ColorPrimaries = dff->stHDRInfo.stColorDescription.u8ColorPrimaries;
740 stXCDSInfo.stHDRInfo.stColorDescription.u8MatrixCoefficients = dff->stHDRInfo.stColorDescription.u8MatrixCoefficients;
741 stXCDSInfo.stHDRInfo.stColorDescription.u8TransferCharacteristics = dff->stHDRInfo.stColorDescription.u8TransferCharacteristics;
742
743 stXCDSInfo.stHDRInfo.stMasterColorDisplay.u32MaxLuminance = dff->stHDRInfo.stMasterColorDisplay.u32MaxLuminance;
744 stXCDSInfo.stHDRInfo.stMasterColorDisplay.u32MinLuminance = dff->stHDRInfo.stMasterColorDisplay.u32MinLuminance;
745 stXCDSInfo.stHDRInfo.stMasterColorDisplay.u16DisplayPrimaries[0][0] = dff->stHDRInfo.stMasterColorDisplay.u16DisplayPrimaries[0][0];
746 stXCDSInfo.stHDRInfo.stMasterColorDisplay.u16DisplayPrimaries[0][1] = dff->stHDRInfo.stMasterColorDisplay.u16DisplayPrimaries[0][1];
747 stXCDSInfo.stHDRInfo.stMasterColorDisplay.u16DisplayPrimaries[1][0] = dff->stHDRInfo.stMasterColorDisplay.u16DisplayPrimaries[1][0];
748 stXCDSInfo.stHDRInfo.stMasterColorDisplay.u16DisplayPrimaries[1][1] = dff->stHDRInfo.stMasterColorDisplay.u16DisplayPrimaries[1][1];
749 stXCDSInfo.stHDRInfo.stMasterColorDisplay.u16DisplayPrimaries[2][0] = dff->stHDRInfo.stMasterColorDisplay.u16DisplayPrimaries[2][0];
750 stXCDSInfo.stHDRInfo.stMasterColorDisplay.u16DisplayPrimaries[2][1] = dff->stHDRInfo.stMasterColorDisplay.u16DisplayPrimaries[2][1];
751 stXCDSInfo.stHDRInfo.stMasterColorDisplay.u16WhitePoint[0] = dff->stHDRInfo.stMasterColorDisplay.u16WhitePoint[0];
752 stXCDSInfo.stHDRInfo.stMasterColorDisplay.u16WhitePoint[1] = dff->stHDRInfo.stMasterColorDisplay.u16WhitePoint[1];
753
754 stXCDSInfo.stHDRInfo.u8CurrentIndex = dff->stHDRInfo.stDolbyHDRInfo.u8CurrentIndex;
755 stXCDSInfo.stHDRInfo.phyRegAddr = dff->stHDRInfo.stDolbyHDRInfo.phyHDRRegAddr;
756 stXCDSInfo.stHDRInfo.u32RegSize = dff->stHDRInfo.stDolbyHDRInfo.u32HDRRegSize;
757 stXCDSInfo.stHDRInfo.phyLutAddr = dff->stHDRInfo.stDolbyHDRInfo.phyHDRLutAddr;
758 stXCDSInfo.stHDRInfo.u32LutSize = dff->stHDRInfo.stDolbyHDRInfo.u32HDRLutSize;
759 stXCDSInfo.stHDRInfo.bDMEnable = dff->stHDRInfo.stDolbyHDRInfo.u8DMEnable;
760 stXCDSInfo.stHDRInfo.bCompEnable = dff->stHDRInfo.stDolbyHDRInfo.u8CompEnable;
761 #endif
762
763
764 #if (API_XCDS_INFO_VERSION >= 3)
765 stXCDSInfo.bEnableDNR[(SCALER_WIN) Overlay_ID] = (gDMSCtrl[Overlay_ID].u8DNRFrameCnt == DNRFrameNUM);
766 #endif
767
768 #if (API_XCDS_INFO_VERSION >= 4)
769 stXCDSInfo.bEnable_ForceP[(SCALER_WIN) Overlay_ID] = gDMSCtrl[Overlay_ID].u8ForcePMode;
770 #endif
771
772 MApi_XC_SetDSInfo(&stXCDSInfo, sizeof(stXCDSInfo), (SCALER_WIN) Overlay_ID);
773 }
774 #endif
775
776
777 #ifdef UFO_XC_SETWINDOW_LITE
778 if (!bSizeChange) {
779 MApi_SWDS_Fire((SCALER_WIN)Overlay_ID);
780 } else
781 #endif
782 if (MApi_XC_SetWindow(&stXC_SetWin_Info, sizeof(XC_SETWIN_INFO), (SCALER_WIN)Overlay_ID) == FALSE) {
783 DMS_PRINTF("MApi_XC_SetWindow failed!\n");
784 }
785
786 #ifdef UFO_XC_SWDS_SW_FILM_ENABLE
787 if ((gDMSCtrl[Overlay_ID].u8ForceInterlace || (gDMSCtrl[Overlay_ID].u8ForcePMode && dff->u8Interlace))
788 && MApi_XC_Set_DS_ForceI_DeInterlaceMode) {
789
790 gDMSCtrl[Overlay_ID].ds_curr_index.u4DSIndex0 = MApi_XC_GetSWDSIndex((SCALER_WIN)Overlay_ID);
791 DMS_PRINTF("[%s,%5d] MApi_XC_Set_DS_ForceI_DeInterlaceMode %d %d\n", __func__, __LINE__, dff->u8Interlace, dff->u32FrameRate);
792
793 MApi_XC_Set_DS_ForceI_DeInterlaceMode(dff->u8Interlace ? 0 : 1, FALSE, dff->u32FrameRate, (SCALER_WIN) Overlay_ID);
794
795 if (MApi_XC_SetWindow(&stXC_SetWin_Info, sizeof(XC_SETWIN_INFO), (SCALER_WIN) Overlay_ID) == FALSE) {
796 DMS_PRINTF("[%s,%5d] MApi_XC_SetWindow failed!\n", __func__, __LINE__);
797 }
798
799 gDMSCtrl[Overlay_ID].ds_curr_index.u4DSIndex1 = MApi_XC_GetSWDSIndex((SCALER_WIN)Overlay_ID);
800 } else
801 #endif
802 {
803 gDMSCtrl[Overlay_ID].ds_curr_index.u8DSIndex = MApi_XC_GetSWDSIndex((SCALER_WIN)Overlay_ID);
804 }
805 }
806
807 if (bMsLogON) {
808 DMS_PRINTF("[%s,%5d] [%d].u8DSIndex = 0x%x, time = %d ms\n", __func__,
809 __LINE__, Overlay_ID, gDMSCtrl[Overlay_ID].ds_curr_index.u8DSIndex, (int)(MsOS_GetSystemTime() - u32Time));
810 }
811 }
812
_DMS_Ddecide_SW_FRC_Mode(MS_U32 u32WindowID,const ST_DMS_DISPFRAMEFORMAT * pstDispFrameFormat,MS_U32 u32OutputFrmRate)813 void _DMS_Ddecide_SW_FRC_Mode(MS_U32 u32WindowID, const ST_DMS_DISPFRAMEFORMAT *pstDispFrameFormat, MS_U32 u32OutputFrmRate)
814 {
815 MS_U32 u32FrameRate = pstDispFrameFormat->u32FrameRate;
816 MS_U8 u8NextFrcMode = E_HVD_FRC_NORMAL;
817
818 if (u32OutputFrmRate) {
819 if (pstDispFrameFormat->u8Interlace) { // Only Interlace Mode
820 if ((u32FrameRate << 1) == u32OutputFrmRate) { // Ex: 30x2 = 60i
821 u8NextFrcMode = E_HVD_FRC_NORMAL;
822 } else if (u32FrameRate == 60000) { // Input 120i
823 if (u32OutputFrmRate == 50000) {
824 // 120i -> 50i
825 u8NextFrcMode = E_HVD_FRC_120I_50I;
826 } else if (u32OutputFrmRate == 60000) {
827 // 120i -> 60i
828 u8NextFrcMode = E_HVD_FRC_HALF_I;
829 }
830 } else if (u32FrameRate == 50000) { // Input 100i
831 if (u32OutputFrmRate == 60000) {
832 // 100i -> 60i
833 u8NextFrcMode = E_HVD_FRC_100I_60I;
834 } else if (u32OutputFrmRate == 50000) {
835 // 100i -> 50i
836 u8NextFrcMode = E_HVD_FRC_HALF_I;
837 }
838 } else if (u32FrameRate >= 29970
839 && u32FrameRate <= 30000) {
840 // 60i -> 50i
841 if (u32OutputFrmRate == 50000) {
842 u8NextFrcMode = E_HVD_FRC_NTSC2PAL;
843 } else if (u32OutputFrmRate == 30000) {
844 u8NextFrcMode = E_HVD_FRC_HALF_I;
845 } else if (u32OutputFrmRate == 25000) {
846 u8NextFrcMode = E_HVD_FRC_120I_50I; // 30 fps interlace = 60i, 60i to 25i == 120i to 50i
847 } else if (u32OutputFrmRate == 24000) {
848 u8NextFrcMode = E_HVD_FRC_30_24;
849 }
850 } else if (u32FrameRate == 25000) { // Input 50i
851 if (u32OutputFrmRate == 60000) { // 50i -> 60i
852 u8NextFrcMode = E_HVD_FRC_PAL2NTSC;
853 } else if ((u32OutputFrmRate == 30000)) {
854 u8NextFrcMode = E_HVD_FRC_25_30;
855 }
856 } else if (u32FrameRate >= 23970
857 && u32FrameRate <= 24000) {
858
859 if (u32OutputFrmRate == 60000) { // 48i -> 60i
860 u8NextFrcMode = E_HVD_FRC_32PULLDOWN;
861 } else if (u32OutputFrmRate == 50000) { // 48i -> 50i
862 u8NextFrcMode = E_HVD_FRC_NORMAL;
863 } else if (u32OutputFrmRate == 30000) { // 48i -> 30i
864 u8NextFrcMode = E_HVD_FRC_24_30;
865 }
866 }
867 } else { // Only Progressive Mode
868 if (u32FrameRate == u32OutputFrmRate) { // Ex: 25p = 25p
869 u8NextFrcMode = E_HVD_FRC_NORMAL;
870 } else if ((u32FrameRate<<1) == u32OutputFrmRate) { // Ex: 25p x 2 = 50p
871 u8NextFrcMode = E_HVD_FRC_DISP_2X;
872 } else if (u32FrameRate == 60000) {
873 if (u32OutputFrmRate == 50000) { // 60p -> 50p
874 u8NextFrcMode = E_HVD_FRC_60P_50P;
875 }
876 } else if (u32FrameRate == 50000) {
877 if (u32OutputFrmRate == 60000) { // 50p -> 60p
878 u8NextFrcMode = E_HVD_FRC_50P_60P;
879 }
880 } else if (u32FrameRate >= 29970
881 && u32FrameRate <= 30000) {
882 // 30p -> 50p
883 if (u32OutputFrmRate == 50000) {
884 u8NextFrcMode = E_HVD_FRC_NTSC2PAL;
885 } else if ((u32OutputFrmRate == 60000)) {
886 u8NextFrcMode = E_HVD_FRC_DISP_2X;
887 } else if (u32OutputFrmRate == 25000) {
888 u8NextFrcMode = E_HVD_FRC_60P_50P; // 30p -> 25p, 60p -> 50p, the same rule
889 } else if (u32OutputFrmRate == 24000) {
890 u8NextFrcMode = E_HVD_FRC_30_24;
891 }
892 } else if (u32FrameRate == 25000) {
893 // 25p -> 60p
894 if (u32OutputFrmRate == 60000) {
895 u8NextFrcMode = E_HVD_FRC_PAL2NTSC;
896 } else if ((u32OutputFrmRate == 30000)) {
897 u8NextFrcMode = E_HVD_FRC_25_30;
898 }
899 } else if (u32FrameRate >= 23970
900 && u32FrameRate <= 24000) {
901
902 if (u32OutputFrmRate == 60000) {
903 u8NextFrcMode = E_HVD_FRC_32PULLDOWN;
904 } else if (u32OutputFrmRate == 50000) {
905 u8NextFrcMode = E_HVD_FRC_24_50;
906 } else if (u32OutputFrmRate == 30000) { // 24p -> 30p
907 u8NextFrcMode = E_HVD_FRC_24_30;
908 }
909 }
910 }
911 }
912
913 gDMSCtrl[u32WindowID].u8FrcMode = u8NextFrcMode;
914
915 if (pstDispFrameFormat->u32CodecType == E_DMS_CODEC_TYPE_RV8
916 || pstDispFrameFormat->u32CodecType == E_DMS_CODEC_TYPE_RV9) {
917 // rmvb is variable framerate, don't do FRC
918 gDMSCtrl[u32WindowID].u8FrcMode = E_HVD_FRC_NORMAL;
919 }
920
921 DMS_PRINTF("u32FrameRate=%d, u32OutputFrmRate=%d, u8FrcMode[%d] = %d",
922 (int)u32FrameRate, (int)u32OutputFrmRate, (int)u32WindowID, gDMSCtrl[u32WindowID].u8FrcMode);
923 }
924
_DMS_Update_SW_FRC_Mode(MS_U32 u32WindowID,const ST_DMS_DISPFRAMEFORMAT * pstDispFrameFormat)925 static void _DMS_Update_SW_FRC_Mode(MS_U32 u32WindowID, const ST_DMS_DISPFRAMEFORMAT *pstDispFrameFormat)
926 {
927 // Get is XC gen timing or not, if XC gen timing, enable SW FRC
928 MVOP_Handle stMvopHd;
929 MS_BOOL bIsXCGenTiming = FALSE;
930
931 if (u32WindowID == 0) {
932 stMvopHd.eModuleNum = E_MVOP_MODULE_MAIN;
933 } else {
934 stMvopHd.eModuleNum = E_MVOP_MODULE_SUB;
935 }
936
937 MDrv_MVOP_GetCommand(&stMvopHd, E_MVOP_CMD_GET_IS_XC_GEN_TIMING, &bIsXCGenTiming, sizeof(bIsXCGenTiming));
938
939 if (bIsXCGenTiming) {
940 _DMS_Ddecide_SW_FRC_Mode(u32WindowID, pstDispFrameFormat, MApi_XC_GetOutputVFreqX100() * 10);
941 } else {
942 gDMSCtrl[u32WindowID].u8FrcMode = E_HVD_FRC_NORMAL;
943 }
944 }
945
_DMS_VDEC_Frame_AddRef(MS_U32 u32Window,MS_U16 u16BufID)946 static MS_BOOL _DMS_VDEC_Frame_AddRef(MS_U32 u32Window, MS_U16 u16BufID)
947 {
948 DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
949 UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
950 #if NEW_FLIP
951 VDEC_StreamId VdecStreamId;
952 VDEC_EX_DispFrame VdecDispFrm;
953 VdecStreamId.u32Version = pDMSResPri->stDrvDMS._stXC_DIPPushInfo[u32Window][u16BufID].u32VDECStreamVersion;
954 VdecStreamId.u32Id = pDMSResPri->stDrvDMS._stXC_DIPPushInfo[u32Window][u16BufID].u32VDECStreamID;
955 VdecDispFrm.u32Idx = pDMSResPri->stDrvDMS._stXC_DIPPushInfo[u32Window][u16BufID].u32FrameIndex;
956 VdecDispFrm.u32PriData = pDMSResPri->stDrvDMS._stXC_DIPPushInfo[u32Window][u16BufID].u32PriData;
957 VDEC_EX_Result eResult;
958 eResult = MApi_VDEC_EX_DisplayFrame((VDEC_StreamId*)&VdecStreamId, &VdecDispFrm);
959 if (eResult != E_VDEC_EX_OK)
960 {
961 DMS_PRINTF("[%s] %d %d, %d %d\n", __FUNCTION__, (int)VdecStreamId.u32Version, (int)VdecStreamId.u32Id,
962 (int)VdecDispFrm.u32Idx, (int)VdecDispFrm.u32PriData);
963 DMS_PRINTF("[%s] window %d, BufID %d, MApi_VDEC_EX_DisplayFrame return %d\n",__FUNCTION__, (int)u32Window,u16BufID, eResult);
964 return FALSE;
965 }
966 //DMS_PRINTF("[AddRef] u16BufID[%d] Frame[0x%x], PriData[0x%x]\n", u16BufID, VdecDispFrm.u32Idx, VdecDispFrm.u32PriData);
967 pDMSResPri->stDrvDMS._stXC_LocalFrameRefCount[u32Window][u16BufID]++;
968 #endif
969 return TRUE;
970 }
971
_DMS_VDEC_Frame_Release(MS_U32 u32Window,MS_U16 u16BufID)972 static MS_BOOL _DMS_VDEC_Frame_Release(MS_U32 u32Window, MS_U16 u16BufID)
973 {
974 DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
975 UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
976 #if NEW_FLIP
977 if(pDMSResPri->stDrvDMS._stXC_LocalFrameRefCount[u32Window][u16BufID] == 0)
978 {
979 DMS_PRINTF("[%s] window %d, BufID %d, Release an invalid buffer\n",__FUNCTION__, (int)u32Window, u16BufID);
980 return TRUE;
981 }
982 pDMSResPri->stDrvDMS._stXC_LocalFrameRefCount[u32Window][u16BufID]--;
983 if(pDMSResPri->stDrvDMS._stXC_LocalFrameRefCount[u32Window][u16BufID] == 0)
984 {
985 VDEC_StreamId VdecStreamId;
986 VDEC_EX_DispFrame VdecDispFrm;
987 VdecStreamId.u32Version = pDMSResPri->stDrvDMS._stXC_DIPPushInfo[u32Window][u16BufID].u32VDECStreamVersion;
988 VdecStreamId.u32Id = pDMSResPri->stDrvDMS._stXC_DIPPushInfo[u32Window][u16BufID].u32VDECStreamID;
989 VdecDispFrm.u32Idx = pDMSResPri->stDrvDMS._stXC_DIPPushInfo[u32Window][u16BufID].u32FrameIndex;
990 VdecDispFrm.u32PriData = pDMSResPri->stDrvDMS._stXC_DIPPushInfo[u32Window][u16BufID].u32PriData;
991
992 VDEC_EX_Result eResult;
993 eResult = MApi_VDEC_EX_ReleaseFrame((VDEC_StreamId *) &VdecStreamId, &VdecDispFrm);
994 if (eResult != E_VDEC_EX_OK)
995 {
996 DMS_PRINTF("[%s] %d %d, %d %d\n",__FUNCTION__, (int)VdecStreamId.u32Version, (int)VdecStreamId.u32Id,
997 (int)VdecDispFrm.u32Idx, (int)VdecDispFrm.u32PriData);
998 DMS_PRINTF("[%s] window %d, BufID %d, MApi_VDEC_EX_ReleaseFrame return %d\n",__FUNCTION__, (int)u32Window, u16BufID, eResult);
999 return FALSE;
1000 }
1001 //DMS_PRINTF("[DecRef] u16BufID[%d] Frame[0x%x], PriData[0x%x]\n", u16BufID, VdecDispFrm.u32Idx, VdecDispFrm.u32PriData);
1002 }
1003 #endif
1004 return TRUE;
1005 }
1006
_DMS_MVOP_ISR(InterruptNum eIntNum)1007 static void _DMS_MVOP_ISR(InterruptNum eIntNum)
1008 {
1009 MS_U8 u8IntStatus;
1010 MS_U8 u8MvopId = ((E_INT_IRQ_DCSUB == eIntNum) ? 1 : 0);
1011
1012 #ifndef MSOS_TYPE_LINUX_KERNEL
1013
1014 if (E_INT_IRQ_DC == eIntNum) {
1015 u8IntStatus = MDrv_MVOP_GetIntStatus();
1016 } else {
1017 u8IntStatus = MDrv_MVOP_SubGetIntStatus();
1018 }
1019 #endif
1020
1021 //if (bMsLogON)
1022 // DMS_PRINTF("_DMS_MVOP_ISR eIntNum %d mvop %d int, status = 0x%x\n", eIntNum, u8MvopId, u8IntStatus);
1023
1024 if (u8MvopId) {
1025 MDrv_MVOP_SubEnableInterrupt(0);
1026 MDrv_MVOP_SubEnableInterrupt(E_MVOP_INT_VSYNC);
1027 MsOS_EnableInterrupt(E_INT_IRQ_DCSUB);
1028 } else {
1029 MDrv_MVOP_EnableInterrupt(0);
1030 MDrv_MVOP_EnableInterrupt(E_MVOP_INT_VSYNC);
1031 MsOS_EnableInterrupt(E_INT_IRQ_DC);
1032 }
1033 //if (u8IntStatus & E_MVOP_INT_VSYNC) {
1034 MsOS_SetEvent(s32DMSEventID[u8MvopId], E_MVOP_INT_VSYNC);
1035 MsOS_SetEvent(s32DMSVsyncEventID[u8MvopId], E_MVOP_INT_VSYNC);
1036 //}
1037 }
1038
_Task_DMS_Mointor(MS_U32 u32Id)1039 static void _Task_DMS_Mointor(MS_U32 u32Id)
1040 {
1041 MS_U32 u32WaitEventFlag = E_MVOP_INT_VSYNC;
1042 MS_U32 u32Events = 0;
1043 void *pInstance = pTaskInstance;
1044
1045 while(1) {
1046
1047 #ifdef DMS_ENABLE_MVOP_INT
1048 MsOS_WaitEvent(s32DMSEventID[u32Id], u32WaitEventFlag, &u32Events, E_OR_CLEAR, MSOS_WAIT_FOREVER);
1049 #else
1050 MsOS_WaitEvent(s32DMSEventID[u32Id], u32WaitEventFlag, &u32Events, E_OR_CLEAR, 16);
1051 #endif
1052 _DRV_DMS_Entry(u32Id);
1053 MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
1054 DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
1055 UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
1056
1057 gDMSCtrl[u32Id].bVsyncIntAlive = TRUE;
1058 MCU_DISPQ_INFO *pSHM = (MCU_DISPQ_INFO *)MsOS_PA2KSEG1(pDMSResPri->stDrvDMS.phyVsyncbridgeAddr[u32Id] + ((MS_U32)u32Id * sizeof(MCU_DISPQ_INFO)));
1059 #if 0
1060 DMS_PRINTF(" _Task_DMS_Mointor ---> [%d %d %d %d %d %d %d %d] %d %d \n",
1061 pDMSResPri->stDrvDMS._stXC_LocalFrameRefCount[u32Id][0],
1062 pDMSResPri->stDrvDMS._stXC_LocalFrameRefCount[u32Id][1],
1063 pDMSResPri->stDrvDMS._stXC_LocalFrameRefCount[u32Id][2],
1064 pDMSResPri->stDrvDMS._stXC_LocalFrameRefCount[u32Id][3],
1065 pDMSResPri->stDrvDMS._stXC_LocalFrameRefCount[u32Id][4],
1066 pDMSResPri->stDrvDMS._stXC_LocalFrameRefCount[u32Id][5],
1067 pDMSResPri->stDrvDMS._stXC_LocalFrameRefCount[u32Id][6],
1068 pDMSResPri->stDrvDMS._stXC_LocalFrameRefCount[u32Id][7],
1069 pSHM->u8McuDispQWPtr,
1070 pSHM->u8McuDispQRPtr);
1071 #endif
1072 int i;
1073 for (i = 0; i < MAX_VSYNC_BRIDGE_DISPQ_NUM; i++) {
1074
1075 if (pDMSResPri->stDrvDMS._stXC_LocalFrameRefCount[u32Id][i]) {
1076 // reference count is not 0
1077 if(pSHM->u8McuDispQRPtr != i && pSHM->McuDispQueue[i].u8Tog_Time == 0) {
1078 _DMS_VDEC_Frame_Release(u32Id, i);
1079 if (bMsLogON)
1080 DMS_PRINTF(" _Task_DMS_Mointor Overlay[%d] W %d, R %d, Cur %d, disp_cnt = %d\n", (int)u32Id,
1081 pSHM->u8McuDispQWPtr, pSHM->u8McuDispQRPtr, i,
1082 pSHM->McuDispQueue[i].u16DispCnt);
1083 }
1084 }
1085 }
1086
1087 // display win changed in pause state
1088 if (pSHM->u8McuDispSwitch
1089 && (pSHM->u8McuDispQWPtr == pSHM->u8McuDispQRPtr)
1090 && !pSHM->McuDispQueue[pSHM->u8McuDispQWPtr].u8Tog_Time
1091 && pDMSResPri->stDrvDMS.bWinChanged[u32Id]) {
1092
1093 MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
1094
1095 _DMS_Update_DS_Table(pInstance, u32Id, &gDMSCtrl[u32Id].lastdff, 0, TRUE);
1096 pSHM->McuDispQueue[pSHM->u8McuDispQWPtr].u16CropLeft = gDMSCtrl[u32Id].stCurrentCropWin.u32x;
1097 pSHM->McuDispQueue[pSHM->u8McuDispQWPtr].u16CropTop = gDMSCtrl[u32Id].stCurrentCropWin.u32y;
1098 pSHM->McuDispQueue[pSHM->u8McuDispQWPtr].u16CropRight = pSHM->McuDispQueue[pSHM->u8McuDispQWPtr].u16Width
1099 - gDMSCtrl[u32Id].stCurrentCropWin.u32width
1100 - gDMSCtrl[u32Id].stCurrentCropWin.u32x;
1101 pSHM->McuDispQueue[pSHM->u8McuDispQWPtr].u16CropBottom = pSHM->McuDispQueue[pSHM->u8McuDispQWPtr].u16Height
1102 - gDMSCtrl[u32Id].stCurrentCropWin.u32height
1103 - gDMSCtrl[u32Id].stCurrentCropWin.u32y;
1104
1105 if (pSHM->McuDispQueue[pSHM->u8McuDispQWPtr].u8Interlace) {
1106 MS_U8 u8WRBankMappingNum = MApi_XC_GetWRBankMappingNum((SCALER_WIN)u32Id) + 1;
1107 DMS_PRINTF("u8WRBankMappingNum = %d , FRAME_DURATION = %d", u8WRBankMappingNum, FRAME_DURATION(gDMSCtrl[u32Id].u16FrameRate));
1108 pSHM->u8ToggleMethod = 1;
1109 pSHM->McuDispQueue[pSHM->u8McuDispQWPtr].u8Tog_Time = u8WRBankMappingNum;
1110 pSHM->u8ToggledTime = u8WRBankMappingNum;
1111 }
1112
1113 pSHM->McuDispQueue[pSHM->u8McuDispQWPtr].u8DSIndex = gDMSCtrl[u32Id].ds_curr_index.u8DSIndex;
1114
1115 DMS_PRINTF(" _Task_DMS_Mointor DS_Idx=0x%x, DS_Idx1=0x%x, u8DSIndex = 0x%x, MVOP ID=%d",
1116 gDMSCtrl[u32Id].ds_curr_index.u4DSIndex0 , gDMSCtrl[u32Id].ds_curr_index.u4DSIndex1,
1117 pSHM->McuDispQueue[pSHM->u8McuDispQWPtr].u8DSIndex, (int)u32Id);
1118
1119 }
1120 else
1121 {
1122 MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
1123 }
1124
1125 _DRV_DMS_Release(u32Id);
1126 }
1127 }
1128
_MDrv_DMS_CreateTask(MS_U32 u32Id)1129 MS_BOOL _MDrv_DMS_CreateTask(MS_U32 u32Id)
1130 {
1131 #ifndef MSOS_TYPE_NOS
1132 // Create Event
1133 if(s32DMSEventID[u32Id] < 0)
1134 {
1135 s32DMSEventID[u32Id] = MsOS_CreateEventGroup(u32Id ? "DMS_Sub_Event" : "DMS_Main_Event");
1136 }
1137
1138 if(s32DMSVsyncEventID[u32Id] < 0)
1139 {
1140 s32DMSVsyncEventID[u32Id] = MsOS_CreateEventGroup(u32Id ? "DMS_Sub_Vsync_Event" : "DMS_Main_Vsync_Event");
1141 }
1142
1143 if(s32DMSTaskID[u32Id] == -1)
1144 {
1145 s32DMSTaskID[u32Id] = MsOS_CreateTask((TaskEntry)_Task_DMS_Mointor,
1146 u32Id,
1147 E_TASK_PRI_HIGH,
1148 TRUE,
1149 NULL,
1150 0,
1151 "DMS_Task");
1152 }
1153 else
1154 {
1155 DMS_PRINTF("MsOS_ResumeTask(s32DMSTaskID) \n");
1156 MsOS_ResumeTask(s32DMSTaskID[u32Id]);
1157 }
1158
1159 #endif
1160 return TRUE;
1161 }
1162
_MDrv_DMS_InvalidateAllQueue(void)1163 void _MDrv_DMS_InvalidateAllQueue(void)
1164 {
1165 DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
1166 UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
1167
1168 MS_U8 u8WindowID = 0;
1169 MS_U8 u8BufferID = 0;
1170
1171 for (u8WindowID = 0; u8WindowID < DMS_MAX_WINDOW_NUM; u8WindowID++)
1172 {
1173 for(u8BufferID=0;u8BufferID<DMS_DIP_QUEUEDEPTH;u8BufferID++)
1174 {
1175 pDMSResPri->stDrvDMS._stXC_DIPPushInfo[u8WindowID][u8BufferID].bValid = FALSE;
1176 pDMSResPri->stDrvDMS._stXC_DIPPushInfo[u8WindowID][u8BufferID].u32FrameIndex = DMS_INVALID_FRAME_ID;
1177 }
1178 }
1179 }
1180
_MDrv_DMS_ZOrder_Init(void)1181 static void _MDrv_DMS_ZOrder_Init(void)
1182 {
1183 DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
1184 UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
1185 MS_U8 u8Window = 0;
1186 memset(pDMSResPri->stDrvDMS.WindowZOrder, 0, sizeof(MS_U8) * DMS_MAX_WINDOW_NUM);
1187 memset(pDMSResPri->stDrvDMS.WindowScore, 0, sizeof(MS_U8) * DMS_MAX_WINDOW_NUM);
1188
1189 for(u8Window = 0; u8Window < DMS_MAX_WINDOW_NUM; u8Window++)
1190 {
1191 pDMSResPri->stDrvDMS.WindowZOrder[u8Window] = u8Window;
1192 }
1193 }
1194
1195 #define BPP_OF_YUV422 2
_MDrv_DMS_Setup_Memory(EN_DMS_MEMORY_TYPE enMemType,MS_PHY phyMemBufferAddr,MS_PHY u32MemBufferSize)1196 static MS_BOOL _MDrv_DMS_Setup_Memory(EN_DMS_MEMORY_TYPE enMemType, MS_PHY phyMemBufferAddr, MS_PHY u32MemBufferSize)
1197 {
1198 MS_BOOL bRet = TRUE;
1199 DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
1200 UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
1201 switch(enMemType)
1202 {
1203 case E_DMS_MEMORY_TYPE_GOP_DISPLAY:
1204 {
1205 break;
1206 }
1207 case E_DMS_MEMORY_TYPE_FREEZE:
1208 {
1209 break;
1210 }
1211 case E_DMS_MEMORY_TYPE_MVOP_DISPLAY:
1212 {
1213 break;
1214 }
1215 default:
1216 {
1217 DMS_PRINTF("\033[1;31m[%s][%d] unuse mem type %d\033[0m\n",__FUNCTION__,__LINE__,enMemType);
1218 break;
1219 }
1220 }
1221 return bRet;
1222 }
1223
_MDrv_DMS_Init(void * pInstance)1224 static MS_BOOL _MDrv_DMS_Init(void* pInstance)
1225 {
1226 DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
1227 UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
1228 if(pDMSResPri->bDrvInit == TRUE)
1229 {
1230 DMS_PRINTF("Driver has inited!!!!!!!!\n");
1231 return TRUE;
1232 }
1233
1234 #ifdef DMS_ENABLE_MVOP_INT
1235 //MDrv_SYS_GlobalInit();
1236 MDrv_MVOP_Init();
1237 MDrv_MVOP_SubInit();
1238 MDrv_MVOP_SetMMIOMapBase();
1239
1240 //XC_INITDATA XC_InitData;
1241 // xc not init.
1242 //memset((void*)&XC_InitData, 0, sizeof(XC_InitData));
1243 //MApi_XC_Init(&XC_InitData, 0);
1244 //MApi_PNL_IOMapBaseInit();
1245 #endif
1246
1247 #if 0
1248 // Create Event
1249 if(s32DMSEventID[0] < 0)
1250 {
1251 s32DMSEventID[0] = MsOS_CreateEventGroup("DMS_Main_Vsync_Event");
1252 }
1253 if(s32DMSEventID[1] < 0)
1254 {
1255 s32DMSEventID[1] = MsOS_CreateEventGroup("DMS_Sub_Vsync_Event");
1256 }
1257 _MDrv_DMS_CreateTask(0);
1258 _MDrv_DMS_CreateTask(1);
1259 #endif
1260
1261 // Clear VDEC info
1262 memset(pDMSResPri->stDrvDMS._stXC_DIPPushInfo, 0x0, sizeof(DMS_VDECFRAME_INFO)*DMS_DIP_QUEUEDEPTH);
1263
1264 _MDrv_DMS_ZOrder_Init();
1265
1266 pTaskInstance = pInstance;
1267
1268 _MDrv_DMS_InvalidateAllQueue();
1269
1270 pDMSResPri->bDrvInit = TRUE;
1271
1272 return TRUE;
1273 }
1274
_MDrv_DMS_SetWin(void * pInstance,MS_U32 u32Window,ST_DMS_SETWIN_INFO * pstDMS_SetWin_Info)1275 static MS_BOOL _MDrv_DMS_SetWin(void* pInstance, MS_U32 u32Window, ST_DMS_SETWIN_INFO *pstDMS_SetWin_Info)
1276 {
1277 DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
1278 UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
1279 ST_DMS_WINDOW stCropWin = {0};
1280 ST_DMS_WINDOW stDispWin = {0};
1281
1282 if(pstDMS_SetWin_Info == NULL)
1283 {
1284 DMS_PRINTF("[%s] error, Set window parameter cannot be NULL\n", __FUNCTION__);
1285 return FALSE;
1286 }
1287
1288 if (u32Window >= DMS_MAX_WINDOW_NUM) {
1289 DMS_PRINTF("[%s] error, u32Window number exceed limit\n", __FUNCTION__);
1290 return FALSE;
1291 }
1292
1293 memcpy(&pDMSResPri->stDrvDMS.stOutputWinInfo[u32Window].stCropWin ,
1294 &pstDMS_SetWin_Info->stOutputWinInfo.stCropWin, sizeof(stCropWin));
1295 memcpy(&pDMSResPri->stDrvDMS.stOutputWinInfo[u32Window].stOutputWin,
1296 &pstDMS_SetWin_Info->stOutputWinInfo.stOutputWin, sizeof(stDispWin));
1297 memcpy(&pDMSResPri->stDrvDMS.stDisplayWin[u32Window],
1298 &pstDMS_SetWin_Info->stOutputWinInfo.stOutputWin, sizeof(stDispWin));
1299
1300 DMS_PRINTF("[%s] crop[%d %d %d %d] disp[%d %d %d %d]\n", __FUNCTION__ ,
1301 (int)pstDMS_SetWin_Info->stOutputWinInfo.stCropWin.u32x,
1302 (int)pstDMS_SetWin_Info->stOutputWinInfo.stCropWin.u32y,
1303 (int)pstDMS_SetWin_Info->stOutputWinInfo.stCropWin.u32width,
1304 (int)pstDMS_SetWin_Info->stOutputWinInfo.stCropWin.u32height,
1305 (int)pstDMS_SetWin_Info->stOutputWinInfo.stOutputWin.u32x,
1306 (int)pstDMS_SetWin_Info->stOutputWinInfo.stOutputWin.u32y,
1307 (int)pstDMS_SetWin_Info->stOutputWinInfo.stOutputWin.u32width,
1308 (int)pstDMS_SetWin_Info->stOutputWinInfo.stOutputWin.u32height);
1309
1310 if (pstDMS_SetWin_Info->enARC != E_DMS_AR_DEFAULT) {
1311 // calculate ARC here
1312
1313 }
1314
1315 if (pstDMS_SetWin_Info->u32OnOutputLayer && pDMSResPri->stDrvDMS.stOutputLayer.u32width
1316 && pDMSResPri->stDrvDMS.stOutputLayer.u32height) {
1317 // calculate the real window to XC
1318
1319 MS_U32 u32PanelWidth = g_IPanel.Width();
1320 MS_U32 u32PanelHeight = g_IPanel.Height();
1321
1322 DMS_PRINTF("panel [%d %d] osd [%d %d] \n", (int)u32PanelWidth, (int)u32PanelHeight,
1323 (int)pDMSResPri->stDrvDMS.stOutputLayer.u32width,
1324 (int)pDMSResPri->stDrvDMS.stOutputLayer.u32height);
1325 if (pDMSResPri->stDrvDMS.stDisplayWin[u32Window].u32x < 0) {
1326 pDMSResPri->stDrvDMS.stDisplayWin[u32Window].u32x = 0;
1327 } else {
1328 pDMSResPri->stDrvDMS.stDisplayWin[u32Window].u32x =
1329 ((pDMSResPri->stDrvDMS.stDisplayWin[u32Window].u32x * u32PanelWidth)
1330 / pDMSResPri->stDrvDMS.stOutputLayer.u32width);
1331 }
1332
1333 pDMSResPri->stDrvDMS.stDisplayWin[u32Window].u32width =
1334 ((pDMSResPri->stDrvDMS.stDisplayWin[u32Window].u32width * u32PanelWidth)
1335 / pDMSResPri->stDrvDMS.stOutputLayer.u32width);
1336 if (pDMSResPri->stDrvDMS.stDisplayWin[u32Window].u32width > u32PanelWidth) {
1337 pDMSResPri->stDrvDMS.stDisplayWin[u32Window].u32width = u32PanelWidth;
1338 }
1339
1340 if (pDMSResPri->stDrvDMS.stDisplayWin[u32Window].u32y < 0) {
1341 pDMSResPri->stDrvDMS.stDisplayWin[u32Window].u32y = 0;
1342 } else {
1343 pDMSResPri->stDrvDMS.stDisplayWin[u32Window].u32y =
1344 ((pDMSResPri->stDrvDMS.stDisplayWin[u32Window].u32y * u32PanelHeight)
1345 / pDMSResPri->stDrvDMS.stOutputLayer.u32height);
1346 }
1347
1348 pDMSResPri->stDrvDMS.stDisplayWin[u32Window].u32height =
1349 ((pDMSResPri->stDrvDMS.stDisplayWin[u32Window].u32height * u32PanelHeight)
1350 / pDMSResPri->stDrvDMS.stOutputLayer.u32height);
1351 if (pDMSResPri->stDrvDMS.stDisplayWin[u32Window].u32height > u32PanelHeight) {
1352 pDMSResPri->stDrvDMS.stDisplayWin[u32Window].u32height = u32PanelHeight;
1353 }
1354
1355 DMS_PRINTF("apply ratio, disp_win[%d %d %d %d] crop_win[%d %d %d %d]\n",
1356 (int)pDMSResPri->stDrvDMS.stDisplayWin[u32Window].u32x,
1357 (int)pDMSResPri->stDrvDMS.stDisplayWin[u32Window].u32y,
1358 (int)pDMSResPri->stDrvDMS.stDisplayWin[u32Window].u32width,
1359 (int)pDMSResPri->stDrvDMS.stDisplayWin[u32Window].u32height,
1360 (int)pDMSResPri->stDrvDMS.stOutputWinInfo[u32Window].stCropWin.u32x,
1361 (int)pDMSResPri->stDrvDMS.stOutputWinInfo[u32Window].stCropWin.u32y,
1362 (int)pDMSResPri->stDrvDMS.stOutputWinInfo[u32Window].stCropWin.u32width,
1363 (int)pDMSResPri->stDrvDMS.stOutputWinInfo[u32Window].stCropWin.u32height);
1364 }
1365
1366 pDMSResPri->stDrvDMS.bWindowInfoReady[u32Window] = TRUE;
1367
1368 pDMSResPri->stDrvDMS.bWinChanged[u32Window] = TRUE;
1369
1370 return TRUE;
1371 }
1372
_MDrv_DMS_Final(void * pInstance,MS_U32 u32Window)1373 static MS_BOOL _MDrv_DMS_Final(void* pInstance, MS_U32 u32Window)
1374 {
1375 DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
1376 UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
1377
1378
1379 if (u32Window >= DMS_MAX_WINDOW_NUM) {
1380 return FALSE;
1381 }
1382 pDMSResPri->stDrvDMS.bWindowInfoReady[u32Window] = FALSE;
1383 pDMSResPri->stDrvDMS.bWinUsed[u32Window] = FALSE;
1384 // clear drv control
1385 memset(&gDMSCtrl[u32Window], 0, sizeof(DMS_DRV_CTRL));
1386
1387 if (u32Window)
1388 MDrv_MVOP_SubEnableInterrupt(0);
1389 else
1390 MDrv_MVOP_EnableInterrupt(0);
1391 MsOS_DisableInterrupt(u32Window ? E_INT_IRQ_DCSUB : E_INT_IRQ_DC);
1392 MsOS_DetachInterrupt(u32Window ? E_INT_IRQ_DCSUB : E_INT_IRQ_DC);
1393
1394 return TRUE;
1395 }
1396
MDrv_DMS_Init(void * pInstance,ST_DMS_INITDATA * pstDMS_InitData)1397 EN_DMS_RESULT MDrv_DMS_Init(void* pInstance, ST_DMS_INITDATA *pstDMS_InitData)
1398 {
1399 MS_BOOL bRet = FALSE;
1400 MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
1401 bRet = _MDrv_DMS_Init(pInstance);
1402 MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
1403 return (bRet)? E_DMS_OK : E_DMS_FAIL;
1404 }
1405
MDrv_DMS_SetMemoryType(void * pInstance,ST_DMS_SET_MEMORY_TYPE * pstDMS_SetMemType)1406 EN_DMS_RESULT MDrv_DMS_SetMemoryType(void* pInstance, ST_DMS_SET_MEMORY_TYPE* pstDMS_SetMemType)
1407 {
1408 MS_BOOL bRet = FALSE;
1409 MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
1410 DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
1411 UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
1412 DMS_PRINTF("MDrv_DMS_SetMemoryType\n");
1413 bRet = _MDrv_DMS_Setup_Memory(pstDMS_SetMemType->eMemoryType, pstDMS_SetMemType->phyAddr,pstDMS_SetMemType->phySize);
1414 MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
1415 return (bRet)? E_DMS_OK : E_DMS_FAIL;
1416 }
1417
MDrv_DMS_CreateWindow(void * pInstance,ST_DMS_WINDOW * pstOutputWin,ST_DMS_CREATE_WIN_INFO * pstCreateWin_Info,MS_U32 * pu32WindowID)1418 EN_DMS_RESULT MDrv_DMS_CreateWindow(void* pInstance, ST_DMS_WINDOW *pstOutputWin, ST_DMS_CREATE_WIN_INFO *pstCreateWin_Info, MS_U32 *pu32WindowID)
1419 {
1420 DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
1421 UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
1422 MS_BOOL bRet = FALSE;
1423
1424 MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
1425
1426 if (*pu32WindowID >= DMS_MAX_WINDOW_NUM) {
1427 DMS_PRINTF("[%s %d] u32WindowID %d exceed limit\n", __FUNCTION__, __LINE__, (int)*pu32WindowID);
1428 }
1429
1430 #if 1
1431 pDMSResPri->stDrvDMS.bWinUsed[*pu32WindowID] = TRUE;
1432 #else
1433 pDMSResPri->stDrvDMS.bWinUsed[*pu32WindowID] = TRUE;
1434
1435 _DRV_DMS_MutexCreate(*pu32WindowID);
1436 // create monitor thread
1437 _MDrv_DMS_CreateTask(*pu32WindowID);
1438 #endif
1439
1440 MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
1441 return (bRet)? E_DMS_OK : E_DMS_FAIL;
1442 }
1443
MDrv_DMS_SetDigitalDecodeSignalInfo(void * pInstance,MS_U32 u32WindowID,ST_DMS_DISPFRAMEFORMAT * pstDispFrameFormat)1444 EN_DMS_RESULT MDrv_DMS_SetDigitalDecodeSignalInfo(void* pInstance, MS_U32 u32WindowID, ST_DMS_DISPFRAMEFORMAT *pstDispFrameFormat)
1445 {
1446 DMS_PRINTF("[%s %d] u32WindowID = %d\n", __FUNCTION__, __LINE__, (int)u32WindowID);
1447
1448 if (u32WindowID >= DMS_MAX_WINDOW_NUM) {
1449 DMS_PRINTF("[%s %d] u32WindowID %d exceed limit\n", __FUNCTION__, __LINE__, (int)u32WindowID);
1450 return E_DMS_WINID_ILLEGAL;
1451 }
1452
1453 if (pstDispFrameFormat) {
1454 DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
1455 UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
1456
1457 VDEC_StreamId VdecStreamId;
1458 MS_PHY phyVsyncbridgeAddr, phyVsyncbridgeExtAddr;
1459
1460 VdecStreamId.u32Version = pstDispFrameFormat->u32VdecStreamVersion;
1461 VdecStreamId.u32Id = pstDispFrameFormat->u32VdecStreamId;
1462
1463 if (E_VDEC_EX_OK == MApi_VDEC_EX_GetControl(&VdecStreamId, E_VDEC_EX_USER_CMD_GET_VSYNC_BRIDGE_ADDR, (MS_U32 *)&phyVsyncbridgeAddr)) {
1464 DMS_PRINTF("phyVsyncbridgeAddr = 0x%x\n", (unsigned int)phyVsyncbridgeAddr);
1465 } else {
1466 DMS_PRINTF("E_VDEC_EX_USER_CMD_GET_VSYNC_BRIDGE_ADDR FAIL!!!\n");
1467 }
1468
1469 if (E_VDEC_EX_OK == MApi_VDEC_EX_GetControl(&VdecStreamId, E_VDEC_EX_USER_CMD_GET_VSYNC_BRIDGE_EXT_ADDR, (MS_U32 *)&phyVsyncbridgeExtAddr)) {
1470 DMS_PRINTF("phyVsyncbridgeExtAddr = 0x%x\n", (unsigned int)phyVsyncbridgeExtAddr);
1471 } else {
1472 DMS_PRINTF("E_VDEC_EX_USER_CMD_GET_VSYNC_BRIDGE_EXT_ADDR FAIL!!!\n");
1473 }
1474
1475 // clear drv control
1476 memset(&gDMSCtrl[u32WindowID], 0, sizeof(DMS_DRV_CTRL));
1477
1478 pDMSResPri->stDrvDMS.bWinUsed[u32WindowID] = TRUE;
1479
1480 #if 1
1481 _DRV_DMS_MutexCreate(u32WindowID);
1482 // create monitor thread
1483 _MDrv_DMS_CreateTask(u32WindowID);
1484 #endif
1485
1486 MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
1487 pDMSResPri->stDrvDMS.phyVsyncbridgeAddr[u32WindowID] = phyVsyncbridgeAddr;
1488 pDMSResPri->stDrvDMS.phyVsyncbridgeExtAddr[u32WindowID] = phyVsyncbridgeExtAddr;
1489
1490
1491 int u8BufID;
1492 for(u8BufID = 0; u8BufID < DMS_DIP_QUEUEDEPTH; u8BufID++)
1493 {
1494 pDMSResPri->stDrvDMS._stXC_LocalFrameRefCount[u32WindowID][u8BufID] = 0;
1495 }
1496
1497 MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
1498
1499 VDEC_EX_DynmcDispPath stDynmcDispPath;
1500 stDynmcDispPath.bConnect = TRUE;
1501 stDynmcDispPath.eMvopPath = u32WindowID ? E_VDEC_EX_DISPLAY_PATH_MVOP_SUB : E_VDEC_EX_DISPLAY_PATH_MVOP_MAIN;
1502
1503 MApi_VDEC_EX_SetControl((VDEC_StreamId *)&VdecStreamId, E_VDEC_EX_USER_CMD_SET_DYNAMIC_DISP_PATH, (MS_U32)&stDynmcDispPath);
1504
1505 #ifdef DMS_ENABLE_MVOP_INT
1506 DMS_PRINTF("Attach and enable MVOP interrupt E_INT_IRQ_DC = %d\n", E_INT_IRQ_DC);
1507 MsOS_DisableInterrupt(u32WindowID ? E_INT_IRQ_DCSUB : E_INT_IRQ_DC);
1508 if (u32WindowID) {
1509 MDrv_MVOP_SubEnableInterrupt(0);
1510 } else {
1511 MDrv_MVOP_EnableInterrupt(0);
1512 }
1513 MsOS_AttachInterrupt(u32WindowID ? E_INT_IRQ_DCSUB : E_INT_IRQ_DC, _DMS_MVOP_ISR);
1514 MsOS_EnableInterrupt(u32WindowID ? E_INT_IRQ_DCSUB : E_INT_IRQ_DC);
1515 #ifndef MSOS_TYPE_LINUX_KERNEL
1516 MsOS_CompleteInterrupt(u32WindowID ? E_INT_IRQ_DCSUB : E_INT_IRQ_DC);
1517 #endif
1518
1519 if (u32WindowID) {
1520 MDrv_MVOP_SubEnableInterrupt(E_MVOP_INT_VSYNC);
1521 } else {
1522 MDrv_MVOP_EnableInterrupt(E_MVOP_INT_VSYNC);
1523 }
1524 #endif
1525 }
1526
1527 return E_DMS_OK;
1528 }
1529
MDrv_DMS_ClearDigitalDecodeSignalInfo(void * pInstance,MS_U32 u32WindowID)1530 EN_DMS_RESULT MDrv_DMS_ClearDigitalDecodeSignalInfo(void* pInstance, MS_U32 u32WindowID)
1531 {
1532 //DMS_PRINTF("\033[32m [%s][%d] === Not Impl %d=== \033[0m\n",__FUNCTION__,__LINE__, (int)u32WindowID);
1533 MS_BOOL bRet = FALSE;
1534 MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
1535 bRet = _MDrv_DMS_Final(pInstance, u32WindowID);
1536 MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
1537 return E_DMS_OK;
1538 }
1539
MDrv_DMS_DestroyWindow(void * pInstance,MS_U32 u32WindowID)1540 EN_DMS_RESULT MDrv_DMS_DestroyWindow(void* pInstance, MS_U32 u32WindowID)
1541 {
1542 MS_BOOL bRet = FALSE;
1543 MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
1544 bRet = _MDrv_DMS_Final(pInstance, u32WindowID);
1545 MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
1546 return (bRet)? E_DMS_OK : E_DMS_FAIL;
1547 }
1548
MDrv_DMS_SetWindow(void * pInstance,MS_U32 u32WindowID,ST_DMS_SETWIN_INFO * pstDMS_SetWin_Info)1549 EN_DMS_RESULT MDrv_DMS_SetWindow(void* pInstance, MS_U32 u32WindowID, ST_DMS_SETWIN_INFO *pstDMS_SetWin_Info)
1550 {
1551 MS_BOOL bRet = FALSE;
1552 MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
1553 bRet = _MDrv_DMS_SetWin(pInstance, u32WindowID, pstDMS_SetWin_Info);
1554 MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
1555 return (bRet)? E_DMS_OK : E_DMS_FAIL;
1556 }
1557
MDrv_DMS_GetWindowInfo(void * pInstance,MS_U32 u32WindowID,ST_DMS_WINDOW_INFO * pstDMS_GetWin_Info)1558 EN_DMS_RESULT MDrv_DMS_GetWindowInfo(void* pInstance, MS_U32 u32WindowID, ST_DMS_WINDOW_INFO *pstDMS_GetWin_Info)
1559 {
1560 return E_DMS_OK;
1561 }
1562
_DMS_GetDMSScanType(MS_U8 u8ScanType)1563 E_DMS_VIDEO_SCAN_TYPE _DMS_GetDMSScanType(MS_U8 u8ScanType)
1564 {
1565 // ProgressiveFrame = 0, /** Picture is a progressive frame */
1566 // InterlacedFrame = 2, /** Picture is an interlaced frame */
1567 // InterlacedField = 3, /** Picture is two interlaced fields */
1568 // InterlacedField = 1, MVD bring 1 to push interlace frame
1569 E_DMS_VIDEO_SCAN_TYPE eScanType = E_DMS_VIDEO_SCAN_TYPE_MAX;
1570 switch (u8ScanType)
1571 {
1572 case 0:
1573 eScanType = E_DMS_VIDEO_SCAN_TYPE_PROGRESSIVE;
1574 break;
1575 case 1:
1576 case 2:
1577 eScanType = E_DMS_VIDEO_SCAN_TYPE_INTERLACE_FRAME;
1578 break;
1579 case 3:
1580 eScanType = E_DMS_VIDEO_SCAN_TYPE_INTERLACE_FIELD;
1581 break;
1582 default:
1583 eScanType = E_DMS_VIDEO_SCAN_TYPE_MAX;
1584 break;
1585 }
1586 return eScanType;
1587 }
1588
MDrv_DMS_Video_Flip(void * pInstance,MS_U32 u32WindowID,ST_DMS_DISPFRAMEFORMAT * pstDispFrameFormat)1589 EN_DMS_RESULT MDrv_DMS_Video_Flip(void* pInstance, MS_U32 u32WindowID, ST_DMS_DISPFRAMEFORMAT* pstDispFrameFormat)
1590 {
1591 EN_DMS_RESULT eResult = E_DMS_FAIL;
1592
1593 MCU_DISPQ_INFO *pSHM = 0;
1594 if (pstDispFrameFormat->u32OverlayID < 2) {
1595 pSHM = (MCU_DISPQ_INFO *)MsOS_PA2KSEG1(pstDispFrameFormat->phyVsyncBridgeAddr +
1596 ((MS_U32)pstDispFrameFormat->u32OverlayID * sizeof(MCU_DISPQ_INFO)));
1597 } else {
1598 pSHM = (MCU_DISPQ_INFO *)MsOS_PA2KSEG1(pstDispFrameFormat->phyVsyncBridgeAddr);
1599 }
1600
1601 MS_U32 lumaAddr = pstDispFrameFormat->stFrames[0].stHWFormat.phyLumaAddr;
1602 MS_U32 chromAddr = pstDispFrameFormat->stFrames[0].stHWFormat.phyChromaAddr;
1603 MS_U32 lumaAddr2 = pstDispFrameFormat->stFrames[1].stHWFormat.phyLumaAddr;
1604 MS_U32 chromAddr2 = pstDispFrameFormat->stFrames[1].stHWFormat.phyChromaAddr;
1605 MS_U16 u16Width = pstDispFrameFormat->stFrames[0].u32Width
1606 - pstDispFrameFormat->stFrames[0].u32CropLeft
1607 - pstDispFrameFormat->stFrames[0].u32CropRight;
1608 MS_U16 u16Height = pstDispFrameFormat->stFrames[0].u32Height
1609 - pstDispFrameFormat->stFrames[0].u32CropTop
1610 - pstDispFrameFormat->stFrames[0].u32CropBottom;
1611
1612
1613 if (u32WindowID >= DMS_MAX_WINDOW_NUM) {
1614 DMS_PRINTF("u32WindowID = %d exceed limit\n", (int)u32WindowID);
1615 return E_DMS_WINSIZE_ERROR;
1616 }
1617
1618 if (pstDispFrameFormat->u8MCUMode) {
1619 if (bMsLogON) {
1620 DMS_PRINTF("MCU render_frame [%d] pts = %lld, luma=0x%x, chroma=0x%x, B_F = %d, Time = %d, Interlace = %d, Frc = %d\n",
1621 (int)pstDispFrameFormat->u32OverlayID, pstDispFrameFormat->u64Pts,
1622 (unsigned int)lumaAddr, (unsigned int)chromAddr, pstDispFrameFormat->u8BottomFieldFirst,
1623 pstDispFrameFormat->u8ToggleTime, pstDispFrameFormat->u8Interlace, pstDispFrameFormat->u8FrcMode);
1624 }
1625
1626 if (u32WindowID == 0) {
1627 MDrv_MVOP_SetBaseAdd(lumaAddr, chromAddr, 1, 0);
1628 } else {
1629 MDrv_MVOP_SubSetBaseAdd(lumaAddr, chromAddr, 1, 0);
1630 }
1631 return eResult;
1632 }
1633
1634 if (pSHM) {
1635
1636 MS_U8 u8WIndex = pSHM->u8McuDispQWPtr;
1637 MS_U32 u32Cnt = 10;
1638
1639 _DRV_DMS_Entry(u32WindowID);
1640
1641 #if 1 //def DYNAMIC_DISP_PATH // TODO
1642 VDEC_EX_DynmcDispPath stDynmcDispPath;
1643 VDEC_StreamId VdecStreamId;
1644
1645 if (u32WindowID == 0) {
1646 if (gDMSCtrl[u32WindowID].lastdff.u32OverlayID != pstDispFrameFormat->u32OverlayID) {
1647 if (gDMSCtrl[u32WindowID].CodecType != pstDispFrameFormat->u32CodecType) {
1648 //bVideoMute = TRUE;
1649 //Wrapper_Video_setMute(Overlay_ID, 1);
1650 // will seq_change latter
1651 }
1652 VdecStreamId.u32Version = gDMSCtrl[u32WindowID].lastdff.u32VdecStreamVersion;
1653 VdecStreamId.u32Id = gDMSCtrl[u32WindowID].lastdff.u32VdecStreamId;
1654 stDynmcDispPath.bConnect = FALSE;
1655 stDynmcDispPath.eMvopPath = E_VDEC_EX_DISPLAY_PATH_MVOP_MAIN;
1656 MApi_VDEC_EX_SetControl((VDEC_StreamId *)&VdecStreamId, E_VDEC_EX_USER_CMD_SET_DYNAMIC_DISP_PATH,(MS_U32)&stDynmcDispPath);
1657
1658 VdecStreamId.u32Version = pstDispFrameFormat->u32VdecStreamVersion;
1659 VdecStreamId.u32Id = pstDispFrameFormat->u32VdecStreamId;
1660 stDynmcDispPath.bConnect = TRUE;
1661 MApi_VDEC_EX_SetControl((VDEC_StreamId *)&VdecStreamId, E_VDEC_EX_USER_CMD_SET_DYNAMIC_DISP_PATH, (MS_U32)&stDynmcDispPath);
1662 //bStreamChange = TRUE;
1663 }
1664 }
1665 #endif
1666
1667 if (pSHM->u8McuDispSwitch == 0) {
1668 // fill ctrl flags
1669
1670 DMS_PRINTF("VSYNC_BRIDGE_INIT clear dispQ\n");
1671 memset(pSHM, 0, sizeof(MCU_DISPQ_INFO));
1672
1673 u8WIndex = DISPQ_FIRST_R_INDEX - 1;
1674 gDMSCtrl[u32WindowID].u16SrcWidth = pstDispFrameFormat->stFrames[0].u32Width;
1675 gDMSCtrl[u32WindowID].u16SrcHeight = pstDispFrameFormat->stFrames[0].u32Height;
1676 gDMSCtrl[u32WindowID].u16FrameRate = (MS_U16)pstDispFrameFormat->u32FrameRate;
1677 gDMSCtrl[u32WindowID].CodecType = pstDispFrameFormat->u32CodecType;
1678 gDMSCtrl[u32WindowID].u8Interlace = pstDispFrameFormat->u8Interlace;
1679 gDMSCtrl[u32WindowID].u32AspectWidth = pstDispFrameFormat->u32AspectWidth;
1680 gDMSCtrl[u32WindowID].u32AspectHeight = pstDispFrameFormat->u32AspectHeight;
1681
1682 pSHM->u2MirrorMode = gDMSCtrl[u32WindowID].u8MirrorMode;
1683
1684 #if ENABLE_FRAME_CONVERT
1685 gDMSCtrl[u32WindowID].u8UpdateFrcMode = 1;
1686 #endif
1687 }
1688
1689 if (gDMSCtrl[u32WindowID].u16FrameRate != (MS_U16)pstDispFrameFormat->u32FrameRate) {
1690 gDMSCtrl[u32WindowID].u8UpdateFrcMode = 1;
1691 gDMSCtrl[u32WindowID].u16FrameRate = pstDispFrameFormat->u32FrameRate;
1692 }
1693
1694 #if ENABLE_FRAME_CONVERT
1695 if (gDMSCtrl[u32WindowID].u8UpdateFrcMode) {
1696 _DMS_Update_SW_FRC_Mode(u32WindowID, pstDispFrameFormat);
1697 gDMSCtrl[u32WindowID].u8UpdateFrcMode = 0;
1698 }
1699 #endif
1700
1701 if (bMsLogON)
1702 DMS_PRINTF("dms render_frame [%d] pts = %lld, luma=0x%x, chroma=0x%x, Interlace = %d, B_F = %d, TG = %d, Last_TG = %d\n",
1703 (int)pstDispFrameFormat->u32OverlayID, pstDispFrameFormat->u64Pts,
1704 (unsigned int)lumaAddr, (unsigned int)chromAddr, pstDispFrameFormat->u8Interlace,
1705 pstDispFrameFormat->u8BottomFieldFirst, pstDispFrameFormat->u8ToggleTime,
1706 pSHM->McuDispQueue[pSHM->u8McuDispQWPtr].u8Tog_Time);
1707
1708 DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
1709 UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
1710 while (pDMSResPri->stDrvDMS._stXC_LocalFrameRefCount[u32WindowID][((u8WIndex + 1) % MAX_VSYNC_BRIDGE_DISPQ_NUM)]
1711 && u32Cnt--) {
1712 //while ((((u8WIndex + 1) % MAX_VSYNC_BRIDGE_DISPQ_NUM) == pSHM->u8McuDispQRPtr) && u32Cnt--) {
1713 _DRV_DMS_Release(u32WindowID);
1714 #if 0
1715 return E_DMS_OK;
1716 #else
1717 if (bMsLogON)
1718 DMS_PRINTF("DMS Display Queue Full !! Waiting... [u32SHMAddr = 0x%x]\n", (int)pstDispFrameFormat->phyVsyncBridgeAddr);
1719 _DMS_Wait_MVOP_Vsync(u32WindowID, pstDispFrameFormat);
1720 _DRV_DMS_Entry(u32WindowID);
1721 #endif
1722 }
1723
1724 u8WIndex = (u8WIndex + 1)%MAX_VSYNC_BRIDGE_DISPQ_NUM;
1725
1726 pSHM->McuDispQueue[u8WIndex].u32LumaAddr0 = lumaAddr;
1727 pSHM->McuDispQueue[u8WIndex].u32ChromaAddr0 = chromAddr;
1728
1729
1730 if (pstDispFrameFormat->u32CodecType == E_DMS_CODEC_TYPE_MVC) {
1731 pSHM->McuDispQueue[u8WIndex].u16Width = (u16Width + 1) & ~1;
1732 pSHM->McuDispQueue[u8WIndex].u16Height = u16Height;
1733 } else {
1734 pSHM->McuDispQueue[u8WIndex].u16Width = (pstDispFrameFormat->stFrames[0].u32Width + 1) & ~1;
1735 pSHM->McuDispQueue[u8WIndex].u16Height = pstDispFrameFormat->stFrames[0].u32Height;
1736 }
1737
1738 pSHM->McuDispQueue[u8WIndex].u16Pitch = pstDispFrameFormat->stFrames[0].stHWFormat.u32LumaPitch;
1739 //pSHM->McuDispQueue[u8WIndex].u32CodecType = pstDispFrameFormat->u32CodecType;
1740 pSHM->McuDispQueue[u8WIndex].u8Interlace = pstDispFrameFormat->u8Interlace;
1741
1742 if (gDMSCtrl[u32WindowID].u8FieldCtrl != pstDispFrameFormat->u8FieldCtrl) {
1743 if (u32WindowID) {
1744 // FIXME: wait MVOP implement sub API
1745 //MDrv_MVOP_SubSEL_OP_FIELD(TRUE);
1746 } else {
1747 DMS_PRINTF("MDrv_MVOP_SEL_OP_FIELD = 0x%d\n", (pstDispFrameFormat->u8FieldCtrl ? TRUE : FALSE));
1748 MDrv_MVOP_SEL_OP_FIELD(pstDispFrameFormat->u8FieldCtrl ? TRUE : FALSE);
1749 }
1750 // enable BOB mode to prevent FF/RF playback De-interlace garbage.
1751 DMS_PRINTF("MApi_XC_SetBOBMode = %d\n", (pstDispFrameFormat->u8FieldCtrl ? TRUE : FALSE));
1752 MApi_XC_SetBOBMode(pstDispFrameFormat->u8FieldCtrl ? TRUE : FALSE, u32WindowID);
1753 gDMSCtrl[u32WindowID].u8FieldCtrl = pstDispFrameFormat->u8FieldCtrl;
1754 }
1755
1756 pSHM->McuDispQueue[u8WIndex].u8FieldCtrl = pstDispFrameFormat->u8FieldCtrl;
1757
1758 if (pstDispFrameFormat->enColorFormat == E_DMS_COLOR_FORMAT_YUYV) {
1759 pSHM->McuDispQueue[u8WIndex].u8ColorFormat = 1; //422
1760 } else if (pstDispFrameFormat->enColorFormat == E_DMS_COLOR_FORMAT_10BIT_TILE) {
1761
1762 pSHM->McuDispQueue[u8WIndex].u8ColorFormat = 2; //420 10 bits
1763 pSHM->McuDispQueue[u8WIndex].u16Pitch1 = pstDispFrameFormat->stFrames[0].stHWFormat.u32LumaPitch2Bit;
1764 pSHM->McuDispQueue[u8WIndex].u8RangeMapY = pstDispFrameFormat->stFrames[0].u8LumaBitdepth;
1765 pSHM->McuDispQueue[u8WIndex].u8RangeMapUV = pstDispFrameFormat->stFrames[0].u8ChromaBitdepth;
1766 pSHM->McuDispQueue[u8WIndex].u32LumaAddr1 = pstDispFrameFormat->stFrames[0].stHWFormat.phyLumaAddr2Bit;
1767 pSHM->McuDispQueue[u8WIndex].u32ChromaAddr1 = pstDispFrameFormat->stFrames[0].stHWFormat.phyChromaAddr2Bit;
1768 } else {
1769 pSHM->McuDispQueue[u8WIndex].u8ColorFormat = 0; //420
1770 }
1771
1772 //if (u8Interlace[Overlay_ID] != dff->u8Interlace) {
1773 // DMS_PRINTF("WARNING [%d] pts = %lld, luma=0x%x, chroma=0x%x, BoT_First = %d, TogTime = %d, Interlace = %d",
1774 // dff->OverlayID, dff->u64Pts, (unsigned int)lumaAddr, (unsigned int)chromAddr, dff->u8BottomFieldFirst,
1775 // dff->u8ToggleTime, dff->u8Interlace);
1776 //}
1777
1778 if (pstDispFrameFormat->u32CodecType == E_DMS_CODEC_TYPE_VC1_ADV
1779 || pstDispFrameFormat->u32CodecType == E_DMS_CODEC_TYPE_VC1_MAIN) {
1780 pSHM->McuDispQueue[u8WIndex].u8RangeMapY = pstDispFrameFormat->stFrames[0].u8LumaBitdepth;
1781 pSHM->McuDispQueue[u8WIndex].u8RangeMapUV = pstDispFrameFormat->stFrames[0].u8ChromaBitdepth;
1782 }
1783
1784 if (pstDispFrameFormat->u32CodecType == E_DMS_CODEC_TYPE_MVC) {
1785 pSHM->McuDispQueue[u8WIndex].u8FrameNum = 2;
1786 if ((gDMSCtrl[u32WindowID].u8MirrorMode == (MS_U8)E_VOPMIRROR_HVBOTH) && (pstDispFrameFormat->u83DMode == E_DMS_3DMODE_SIDEBYSIDE)) {
1787 // MVOP mirror and MVC side by side, swap L R
1788 pSHM->McuDispQueue[u8WIndex].u32LumaAddr0 = lumaAddr2;
1789 pSHM->McuDispQueue[u8WIndex].u32ChromaAddr0 = chromAddr2;
1790 pSHM->McuDispQueue[u8WIndex].u32LumaAddr1 = lumaAddr;
1791 pSHM->McuDispQueue[u8WIndex].u32ChromaAddr1 = chromAddr;
1792 } else {
1793 pSHM->McuDispQueue[u8WIndex].u32LumaAddr1 = lumaAddr2;
1794 pSHM->McuDispQueue[u8WIndex].u32ChromaAddr1 = chromAddr2;
1795 }
1796 }
1797
1798 if (pstDispFrameFormat->u8ToggleTime == 0) {
1799 pSHM->McuDispQueue[u8WIndex].u8TB_toggle = 0;
1800 pSHM->McuDispQueue[u8WIndex].u8Tog_Time = 1;
1801
1802 } else if (pstDispFrameFormat->u8Interlace) { //interlace
1803 pSHM->McuDispQueue[u8WIndex].u8TB_toggle = pstDispFrameFormat->u8BottomFieldFirst ? 1 : 0; //0, TOP then BOTTOM, 1 BOT then TOP
1804 pSHM->McuDispQueue[u8WIndex].u8Tog_Time = pstDispFrameFormat->u8ToggleTime;
1805
1806 if ((pstDispFrameFormat->u8ToggleTime == 1)
1807 && (pstDispFrameFormat->stFrames[0].enFieldType == E_DMS_FIELD_TYPE_BOTH)) {
1808 // prevent de-interlace wrong...
1809 pSHM->McuDispQueue[u8WIndex].u8Tog_Time = 2;
1810 }
1811 } else {
1812 pSHM->McuDispQueue[u8WIndex].u8TB_toggle = 0;
1813 pSHM->McuDispQueue[u8WIndex].u8Tog_Time = 1;
1814 }
1815
1816 pSHM->McuDispQueue[u8WIndex].u1BottomFieldFirst = pstDispFrameFormat->u8BottomFieldFirst;
1817
1818 MS_PHY phyTemp;
1819 _phy_to_miu_offset(pSHM->McuDispQueue[u8WIndex].u2Luma0Miu, phyTemp, pstDispFrameFormat->stFrames[0].stHWFormat.phyLumaAddr);
1820 _phy_to_miu_offset(pSHM->McuDispQueue[u8WIndex].u2Chroma0Miu, phyTemp, pstDispFrameFormat->stFrames[0].stHWFormat.phyChromaAddr);
1821 _phy_to_miu_offset(pSHM->McuDispQueue[u8WIndex].u2Luma1Miu, phyTemp, pstDispFrameFormat->stFrames[1].stHWFormat.phyLumaAddr);
1822 _phy_to_miu_offset(pSHM->McuDispQueue[u8WIndex].u2Chroma1Miu, phyTemp, pstDispFrameFormat->stFrames[0].stHWFormat.phyChromaAddr);
1823
1824 #if ENABLE_FRAME_CONVERT
1825 pSHM->u5FRCMode = gDMSCtrl[u32WindowID].u8FrcMode;
1826 #endif
1827
1828 // TODO: implement force P
1829 //....
1830
1831 if (pstDispFrameFormat->phyVsyncBridgeExtAddr) {
1832 // has vsync_bridge EXT addr
1833 MCU_DISPQ_INFO_EXT *pDispQ_Ext = 0;//kk
1834
1835 if (pstDispFrameFormat->u32OverlayID < 2) {
1836 pDispQ_Ext = (MCU_DISPQ_INFO_EXT *)MsOS_PA2KSEG1(pstDispFrameFormat->phyVsyncBridgeExtAddr +
1837 ((MS_U32)pstDispFrameFormat->u32OverlayID * sizeof(MCU_DISPQ_INFO_EXT)));
1838 } else {
1839 pDispQ_Ext = (MCU_DISPQ_INFO_EXT *)MsOS_PA2KSEG1(pstDispFrameFormat->phyVsyncBridgeExtAddr);
1840 }
1841
1842 if (pDispQ_Ext /*&& (pDispQ_Ext->u32Version <= VSYNC_BRIDGE_EXT_VERSION)*/) {
1843 // vsync bridge extened header --> vbeh magic number
1844 pDispQ_Ext->u8Pattern[0] = 'v';
1845 pDispQ_Ext->u8Pattern[1] = 'b';
1846 pDispQ_Ext->u8Pattern[2] = 'e';
1847 pDispQ_Ext->u8Pattern[3] = 'h';
1848 pDispQ_Ext->u32Version = 0;
1849 #if 1
1850 int i = 0;
1851 for (i = 0; i < MS_DISP_FRM_INFO_EXT_TYPE_MAX; i++) {
1852 pDispQ_Ext->McuDispQueue[u8WIndex].u32LumaAddrExt[i] = pstDispFrameFormat->stDispFrmInfoExt.u32LumaAddrExt[i];
1853 pDispQ_Ext->McuDispQueue[u8WIndex].u32ChromaAddrExt[i] = pstDispFrameFormat->stDispFrmInfoExt.u32ChromaAddrExt[i];
1854 }
1855 pDispQ_Ext->McuDispQueue[u8WIndex].MFCodecInfo = pstDispFrameFormat->stFrames[0].stHWFormat.u32MFCodecInfo;
1856 pDispQ_Ext->McuDispQueue[u8WIndex].u16Width = pstDispFrameFormat->stDispFrmInfoExt.u16Width;
1857 pDispQ_Ext->McuDispQueue[u8WIndex].u16Height = pstDispFrameFormat->stDispFrmInfoExt.u16Height;
1858 pDispQ_Ext->McuDispQueue[u8WIndex].u16Pitch[0] = pstDispFrameFormat->stDispFrmInfoExt.u16Pitch[0];
1859 pDispQ_Ext->McuDispQueue[u8WIndex].u16Pitch[1] = pstDispFrameFormat->stDispFrmInfoExt.u16Pitch[1];
1860 #else
1861 memcpy(&pDispQ_Ext->McuDispQueue[u8WIndex], &pstDispFrameFormat->stDispFrmInfoExt, sizeof(DISP_FRM_INFO_EXT));
1862 #endif
1863 } else {
1864 DMS_PRINTF("pDispQ_Ext is NULL\n");
1865 }
1866 }
1867
1868
1869 // TODO: handle DS
1870 //if (gDMSCtrl[u32WindowID].bDS_Enable) {
1871 //if (u32WindowID ? MApi_XC_GetDynamicScalingStatus() : MApi_XC_GetDynamicScalingStatus()) {
1872 if (MApi_XC_GetDynamicScalingStatus()) {
1873
1874 // source resolution change
1875 if ((gDMSCtrl[u32WindowID].u16SrcWidth != pstDispFrameFormat->stFrames[0].u32Width)
1876 || (gDMSCtrl[u32WindowID].u16SrcHeight != pstDispFrameFormat->stFrames[0].u32Height)
1877 || (gDMSCtrl[u32WindowID].u32AspectWidth != pstDispFrameFormat->u32AspectWidth
1878 && gDMSCtrl[u32WindowID].u32AspectHeight != pstDispFrameFormat->u32AspectHeight)) {
1879 gDMSCtrl[u32WindowID].u32AspectWidth = pstDispFrameFormat->u32AspectWidth;
1880 gDMSCtrl[u32WindowID].u32AspectHeight = pstDispFrameFormat->u32AspectHeight;
1881 gDMSCtrl[u32WindowID].u16SrcWidth = pstDispFrameFormat->stFrames[0].u32Width;
1882 gDMSCtrl[u32WindowID].u16SrcHeight = pstDispFrameFormat->stFrames[0].u32Height;
1883 gDMSCtrl[u32WindowID].u8SizeChange = 1;
1884
1885 #ifdef UFO_SWDS_NR_RESOLUTION_CHANGE
1886 MApi_XC_Set_DS_DNR(DISABLE, Overlay_ID);
1887 #endif
1888 gDMSCtrl[u32WindowID].u8DNRFrameCnt = 0;
1889 }
1890
1891 if (!pSHM->u8McuDispSwitch
1892 || gDMSCtrl[u32WindowID].u8SizeChange
1893 #ifdef UFO_XC_SWDS_DYMAMIC_CONTROL_DNR
1894 || (gDMSCtrl[u32WindowID].u8DNRFrameCnt == DNRFrameNUM)
1895 #endif
1896 || _DMS_Need_XC_HDR_DS(pstDispFrameFormat)) {
1897
1898 _DMS_Update_DS_Table(pInstance, u32WindowID, pstDispFrameFormat, 0,
1899 !pSHM->u8McuDispSwitch || gDMSCtrl[u32WindowID].u8SizeChange
1900 #ifndef UFO_XC_SETWINDOW_LITE
1901 || _DMS_Need_XC_HDR_DS(pstDispFrameFormat)
1902 #endif
1903 #ifdef UFO_XC_SWDS_DYMAMIC_CONTROL_DNR
1904 || (gDMSCtrl[u32WindowID].u8DNRFrameCnt == DNRFrameNUM)
1905 #endif
1906 );
1907
1908 gDMSCtrl[u32WindowID].u8SizeChange = 0;
1909 }
1910
1911 #ifdef UFO_XC_SWDS_SW_FILM_ENABLE
1912 if ((u8ForceInterlace[Overlay_ID] || (u8ForcePMode[Overlay_ID] && dff->u8Interlace))
1913 && MApi_XC_Set_DS_ForceI_DeInterlaceMode) {
1914 pSHM->McuDispQueue[u8WIndex].u1DSIndex1Valid = 1;
1915 }
1916 #endif
1917
1918 pSHM->McuDispQueue[u8WIndex].u8DSIndex = gDMSCtrl[u32WindowID].ds_curr_index.u8DSIndex;
1919 } else {
1920 gDMSCtrl[u32WindowID].u8SizeChange = 1;
1921 }
1922
1923 pSHM->McuDispQueue[u8WIndex].u16CropLeft = gDMSCtrl[u32WindowID].stCurrentCropWin.u32x;
1924 pSHM->McuDispQueue[u8WIndex].u16CropTop = gDMSCtrl[u32WindowID].stCurrentCropWin.u32y;
1925 pSHM->McuDispQueue[u8WIndex].u16CropRight = pSHM->McuDispQueue[u8WIndex].u16Width
1926 - gDMSCtrl[u32WindowID].stCurrentCropWin.u32width
1927 - gDMSCtrl[u32WindowID].stCurrentCropWin.u32x;
1928 pSHM->McuDispQueue[u8WIndex].u16CropBottom = pSHM->McuDispQueue[u8WIndex].u16Height
1929 - gDMSCtrl[u32WindowID].stCurrentCropWin.u32height
1930 - gDMSCtrl[u32WindowID].stCurrentCropWin.u32y;
1931
1932 // if render interval large than 500 ms, maybe pause, needs to wait timing
1933 if (pSHM->u8McuDispSwitch && ((MsOS_GetSystemTime() - gDMSCtrl[u32WindowID].u32LastTime) > 500)) {
1934 _DMS_Wait_MVOP_Vsync(u32WindowID, pstDispFrameFormat);
1935 }
1936 gDMSCtrl[u32WindowID].u32LastTime = MsOS_GetSystemTime();
1937
1938 pSHM->u8McuDispQWPtr = u8WIndex;
1939
1940 //pstDispFrameFormat->u8CurIndex = u8WIndex;
1941
1942 if (pSHM->u8McuDispSwitch == 0) {
1943 pSHM->u8DispQueNum = MAX_VSYNC_BRIDGE_DISPQ_NUM;
1944
1945 _DMS_Wait_MVOP_Vsync(u32WindowID, pstDispFrameFormat);
1946
1947 pSHM->u8McuDispSwitch = 1;
1948 }
1949 gDMSCtrl[u32WindowID].u32FrameCount++;
1950 if (pstDispFrameFormat != &gDMSCtrl[u32WindowID].lastdff)
1951 memcpy(&gDMSCtrl[u32WindowID].lastdff, pstDispFrameFormat, sizeof(ST_DMS_DISPFRAMEFORMAT));
1952
1953 MsOS_FlushMemory();
1954
1955 if (gDMSCtrl[u32WindowID].u8Freeze) {
1956 gDMSCtrl[u32WindowID].u8Freeze--;
1957 if (gDMSCtrl[u32WindowID].u8Freeze == 0) {
1958 DMS_PRINTF("[%d]MApi_XC_UnFreezeImg\n", (int)u32WindowID);
1959 MApi_XC_FreezeImg(FALSE, (SCALER_WIN)(u32WindowID ? 1 : 0));
1960 }
1961 }
1962
1963 _DRV_DMS_Release(u32WindowID);
1964
1965 {
1966 MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
1967 DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
1968 UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
1969 pDMSResPri->stDrvDMS._stXC_DIPPushInfo[u32WindowID][u8WIndex].u32VDECStreamVersion = pstDispFrameFormat->u32VdecStreamVersion;
1970 pDMSResPri->stDrvDMS._stXC_DIPPushInfo[u32WindowID][u8WIndex].u32VDECStreamID = pstDispFrameFormat->u32VdecStreamId;
1971 pDMSResPri->stDrvDMS._stXC_DIPPushInfo[u32WindowID][u8WIndex].u32FrameIndex = pstDispFrameFormat->stFrames[0].u32Idx;
1972 pDMSResPri->stDrvDMS._stXC_DIPPushInfo[u32WindowID][u8WIndex].u32PriData = pstDispFrameFormat->stFrames[0].u32PriData;
1973 pDMSResPri->stDrvDMS.phyVsyncbridgeAddr[u32WindowID] = pstDispFrameFormat->phyVsyncBridgeAddr;
1974 pDMSResPri->stDrvDMS.phyVsyncbridgeExtAddr[u32WindowID] = pstDispFrameFormat->phyVsyncBridgeExtAddr;
1975 _DMS_VDEC_Frame_AddRef(u32WindowID, u8WIndex);
1976 MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
1977 }
1978
1979 eResult = E_DMS_OK;
1980 } else {
1981 DMS_PRINTF("%s %d pSHM is NULL\n", __FUNCTION__, __LINE__);
1982 eResult = E_DMS_FAIL;
1983 }
1984
1985 return eResult;
1986 }
1987
MDrv_DMS_SetZOrder(void * pInstance,MS_U32 u32WindowID,MS_U32 u32ZOrder)1988 EN_DMS_RESULT MDrv_DMS_SetZOrder(void* pInstance, MS_U32 u32WindowID, MS_U32 u32ZOrder)
1989 {
1990 MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
1991 DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
1992 UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
1993
1994 MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
1995 return E_DMS_OK;
1996 }
1997
MDrv_DMS_Video_Freeze(void * pInstance,MS_U32 u32WindowID,MS_U32 u32Enable)1998 EN_DMS_RESULT MDrv_DMS_Video_Freeze(void* pInstance, MS_U32 u32WindowID, MS_U32 u32Enable)
1999 {
2000 MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
2001 DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
2002 UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
2003 DMS_PRINTF("\033[32m [%s][%d] === u32Enable : %d === \033[0m\n", __FUNCTION__, __LINE__, (int)u32Enable);
2004 MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
2005 return TRUE;
2006 }
2007
MDrv_DMS_Video_Mute(void * pInstance,MS_U32 u32WindowID,MS_U32 u32Enable)2008 EN_DMS_RESULT MDrv_DMS_Video_Mute(void* pInstance, MS_U32 u32WindowID, MS_U32 u32Enable)
2009 {
2010 MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
2011 DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;
2012 UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri));
2013 //Hal_DMS_XC_SetMute(pInstance, u32Enable);
2014 MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
2015 return E_DMS_OK;
2016 }
2017
MDrv_DMS_Set_MuteColor(void * pInstance,MS_U32 u32WindowID,ST_DMS_COLOR stMuteColor)2018 EN_DMS_RESULT MDrv_DMS_Set_MuteColor(void* pInstance, MS_U32 u32WindowID, ST_DMS_COLOR stMuteColor)
2019 {
2020 DMS_PRINTF("\033[32m [%s][%d] === Not Impl %d=== \033[0m\n", __FUNCTION__, __LINE__, (int)u32WindowID);
2021 return E_DMS_OK;
2022 }
2023
MDrv_DMS_GetStatus(void * pInstance,MS_U32 * pu32Status)2024 EN_DMS_RESULT MDrv_DMS_GetStatus(void* pInstance, MS_U32 *pu32Status)
2025 {
2026 DMS_PRINTF("\033[32m [%s][%d] === Not Impl === \033[0m\n", __FUNCTION__, __LINE__);
2027 return E_DMS_OK;
2028 }
2029
MDrv_DMS_GetCapability(void * pInstance,EN_DMS_CAPABILITY * peCapability)2030 EN_DMS_RESULT MDrv_DMS_GetCapability(void* pInstance, EN_DMS_CAPABILITY *peCapability)
2031 {
2032 *peCapability = E_DMS_CAPABILITY_VSYNC_BRIDGE;
2033 return E_DMS_OK;
2034 }
2035
MDrv_DMS_SetOutputLayer(void * pInstance,ST_DMS_WINDOW * pstLayer)2036 EN_DMS_RESULT MDrv_DMS_SetOutputLayer(void* pInstance, ST_DMS_WINDOW *pstLayer)
2037 {
2038 MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
2039 DMS_GET_RES_PRI;
2040 memcpy(&RES_DMS.stOutputLayer, pstLayer,sizeof(ST_DMS_WINDOW));
2041 MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
2042 return E_DMS_OK;
2043 }
2044
MDrv_DMS_Set_3D_Mode(void * pInstance,MS_U32 u32WindowID,ST_DMS_3D_INFO * pst3DInfo)2045 EN_DMS_RESULT MDrv_DMS_Set_3D_Mode(void* pInstance, MS_U32 u32WindowID, ST_DMS_3D_INFO *pst3DInfo)
2046 {
2047 MS_BOOL bRet = FALSE;
2048 MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
2049 DMS_GET_RES_PRI;
2050 if(MApi_XC_Set_3D_Mode(pst3DInfo->en3DInputMode, pst3DInfo->en3DOutputMode, pst3DInfo->en3DPanelType, MAIN_WINDOW))
2051 {
2052 if(FALSE == MApi_XC_Set_3D_Mode(pst3DInfo->en3DInputMode, pst3DInfo->en3DOutputMode, pst3DInfo->en3DPanelType, SUB_WINDOW))
2053 {
2054 DMS_PRINTF("MApi_XC_Set_3D_Mode for Sub window failed\n");
2055 bRet = FALSE;
2056 }
2057 }
2058 else
2059 {
2060 DMS_PRINTF("MApi_XC_Set_3D_Mode for Main window failed\n");
2061 bRet = FALSE;
2062 }
2063
2064 if(pst3DInfo->en3DInputMode == E_DMS_3D_INPUT_MODE_NONE || pst3DInfo->en3DOutputMode == E_DMS_3D_OUTPUT_MODE_NONE)
2065 {
2066 DMS_PRINTF("Disable 3D\n");
2067 MApi_XC_EnableFrameBufferLess(TRUE);
2068 MApi_XC_Set_DynamicScalingFlag(TRUE);
2069 }
2070 else
2071 {
2072 DMS_PRINTF("Enable 3D\n");
2073 MApi_XC_EnableFrameBufferLess(FALSE);
2074 MApi_XC_Set_DynamicScalingFlag(FALSE);
2075 }
2076
2077 MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
2078 return (bRet)? E_DMS_OK : E_DMS_FAIL;
2079 }
2080
2081
MDrv_DMS_Set_CaptureInfo(void * pInstance,MS_U32 u32WindowID,ST_DMS_SET_CAPTURE_INFO * pstSetCaptureInfo)2082 EN_DMS_RESULT MDrv_DMS_Set_CaptureInfo(void* pInstance, MS_U32 u32WindowID, ST_DMS_SET_CAPTURE_INFO *pstSetCaptureInfo)
2083 {
2084 return E_DMS_OK;
2085 }
2086
MDrv_DMS_Get_CaptureBuffer(void * pInstance,MS_U32 u32WindowID,ST_DMS_CAPTURE_INFO * pstCaptureInfo)2087 EN_DMS_RESULT MDrv_DMS_Get_CaptureBuffer(void* pInstance, MS_U32 u32WindowID, ST_DMS_CAPTURE_INFO *pstCaptureInfo)
2088 {
2089 return E_DMS_OK;
2090 }
2091
MDrv_DMS_Release_CaptureBuffer(void * pInstance,MS_U32 u32WindowID,ST_DMS_CAPTURE_INFO * pstCaptureInfo)2092 EN_DMS_RESULT MDrv_DMS_Release_CaptureBuffer(void* pInstance, MS_U32 u32WindowID, ST_DMS_CAPTURE_INFO *pstCaptureInfo)
2093 {
2094 return E_DMS_OK;
2095 }
2096