xref: /utopia/UTPA2-700.0.x/modules/dms/drv/dms_dipgop/drvDMS.c (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
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 #include "halCHIP.h"
123 
124 // utopia DRV
125 #include "drvMVOP.h"
126 #include "drvSYS.h"
127 #include "apiXC.h"
128 #include "apiPNL.h"
129 #include "apiXC_DWIN.h"
130 #include "apiVDEC_EX.h"
131 #include "apiGOP.h"
132 #include "apiGFX.h"
133 #include "utopia.h"
134 #include "utopia_dapi.h"
135 #include "apiDMS_private.h"
136 
137 void* g_pDMSRes = NULL;
138 
139 #ifndef ANDROID
140 #define DMS_PRINTF printf
141 #else
142 #include <sys/mman.h>
143 #include <cutils/ashmem.h>
144 #include <cutils/log.h>
145 
146 #define DMS_PRINTF ALOGD
147 #endif
148 
149 #if(DMS_DONT_USE_CMA == 1)
150 #ifdef MSOS_TYPE_LINUX_KERNEL
151 #include "drvCMAPool_v2.h"
152 #else
153 #include "drvCMAPool.h"
154 #endif
155 #include "msos/linux/mdrv_cma_pool_st.h"
156 #endif
157 
158 // FIXME: it needs MVOP to add it to header file.
159 MS_BOOL __attribute__((weak))   MDrv_MVOP_EnableInterrupt(MS_U8 eIntType);
160 
161 //-------------------------------------------------------------------------------------------------
162 //  Driver Compiler Options
163 //-------------------------------------------------------------------------------------------------
164 // DIP MultiView
165 #define DMS_DIP_NUM             1
166 #define DMS_FHD_Hszie           1920
167 #define DMS_FHD_Vszie           1080
168 #define DMS_Frame_Buffer_Width           3840
169 #define DMS_Frame_Buffer_Height           2160
170 #define DMS_Support_Max_Resolution_Hsize           3840
171 #define DMS_Support_Max_Resolution_Vsize           2160
172 #define GOP_NUM 2
173 
174 //------------------------------------------------------------------------------
175 // Macros
176 //------------------------------------------------------------------------------
177 #define DMS_DIP_TIMESLICE  6  //(ms)
178 #define DMS_DIP_Alignment(value, align)  ((value)/(align) * (align))
179 #define DMS_DIPR_Alignment(value, align)  ((value + (align-1))/(align) * (align))
180 #define DMS_DIP_TIMEOUT 500 //(ms)
181 #define DMS_DIP_BUFFER_COUNT  1
182 #define DMS_DIP_MULTIVIEW_TRANSPARENT_COLOR     (0x00000000)
183 #define MVOP_WINDOW 0
184 #define DMS_INVALID_FRAME_ID 0xFF
185 
186 //Define for Develop
187 #define DMS_MVOP_FLOW 1
188 #define DBG_FPS 0
189 #define NEW_FLIP 1
190 #define DBG_DMS_LOG 0
191 #define DEV_PAUSE 1
192 #define DEV_IMODE_PAUSE 1
193 #define DEV_DI 1
194 #define DEV_DI_TIMER 0
195 #define DEV_DI_EVENT 0
196 #define DEV_MVOP_FORCE_IRQ 0
197 #define DEV_CAPMODE 1
198 #define DEV_NEW_NEXT 1
199 #define TEMP_LOG 0
200 #define TEMP_MAIN_CAPTURE 1
201 
202 
203 static MS_S32 XC_Vsync_Event_id = -1;
204 static MS_S32  s32DMSTaskID = -1;
205 
206 #ifndef DMS_DIP_Support_3DDI
207 #define DMS_DIP_Support_3DDI 0
208 #endif
209 
210 #ifndef DMS_DIP_NWindow_Support_2P5DDI
211 #define DMS_DIP_NWindow_Support_2P5DDI 0
212 #endif
213 
214 #if DEV_CAPMODE
215 static MS_S32 CaptureMode_Event_id = -1;
216 static MS_S32 s32DIPTaskID_CaptureMode = -1;
217 #endif
218 
219 #ifndef DMS_DIP_Support_IMI
220 #define DMS_DIP_Support_IMI 0
221 #endif
222 
223 #if DMS_DIP_Support_IMI
224 static MS_S32 StartFRC_Event_id = -1;
225 #endif
226 
227 #ifndef DMS_DIPWindow_NORMAL
228 #define DMS_DIPWindow_NORMAL 0
229 #endif
230 
231 #ifndef DMS_DIPWindow_DI
232 #define DMS_DIPWindow_DI 0
233 #endif
234 
235 #ifndef DMS_DIPWindow_CAPTURE
236 #define DMS_DIPWindow_CAPTURE 0
237 #endif
238 
239 #ifndef DMS_MFDEC_CAPTURE
240 #define DMS_MFDEC_CAPTURE 0
241 #endif
242 
243 #ifndef DMS_MFDEC_NORMAL
244 #define DMS_MFDEC_NORMAL 0
245 #endif
246 
247 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 0)
248 static MS_S32  s32MVOP_Event_id = -1;
249 static MS_S32  s32MVOPTaskID = -1;
250 static MS_S32  s32DisableBob_Event_id = -1;
251 static MS_S32  s32DisableBobTaskID = -1;
252 #endif
253 
254 #define TRACE_LOG 0
255 #if TRACE_LOG
256 #define print_trace(_fmt, _args...) DMS_PRINTF(_fmt, ##_args)
257 #else
258 #define print_trace(_fmt, _args...)
259 #endif
260 
261 //-------------------------------------------------------------------------------------------------
262 //  Global Variables
263 //-------------------------------------------------------------------------------------------------
264 
265 //-------------------------------------------------------------------------------------------------
266 //  Local Variables
267 //-------------------------------------------------------------------------------------------------
268 #define USE_2ND_BUFFER 0x1
269 #define USE_XC_SCALING_DOWN 0x2
270 #define USE_XC_FBL 0x4
271 
272 #define DMS_XC_RESET_WINDOW_SIZE        0x1
273 #define DMS_XC_BLACK_SCREEN_BY_WINUSED  0x2
274 #define DMS_XC_FREEZE                   0x4
275 #define DMS_XC_FREEZE_SETTING           0x8
276 #define DMS_XC_FIRST_TIME_SETWINDOW     0x10    //For do utopia setwin and DS wrtie scenario
277 #define DMS_XC_NO_FRAME                 0x100
278 #define DMS_XC_SEQ_CHANGE_PI            0x200
279 #define DMS_XC_SEQ_CHANGE_SIZE          0x400
280 #define DMS_XC_UPDATE_FROM_VDEC         0X1000
281 #define DMS_XC_FIRST_FRAME_FROM_VDEC    0X2000
282 
283 #if DBG_FPS
284 static MS_S32  s32DMSFPSTaskID = -1;
285 #define PRI_PERIOD 5000
286 static MS_BOOL bFPS_Start[2] = {FALSE};
287 static MS_U32 u32FPS_Push_Counter[2] = {0};
288 static MS_U32 u32FPS_Pull_Counter[2] = {0};
289 static MS_U32 u32FPS_Pull_NotReady_Counter[2] = {0};
290 static MS_U32 u32FPS_Switch_Counter[2] = {0};
291 static MS_U32 u32FPS_Show_Counter[2] = {0};
292 static MS_U32 u32FPS_Add_Counter[2] = {0};
293 static MS_U32 u32FPS_Release_Counter[2] = {0};
294 static MS_U32 u32FPS_Di_Counter[2] = {0};
295 #endif
296 MS_U16 gDMS_externDebugFlag = 0;
297 MS_U16 gDMSMVOPForceLookVDEC = 0;
298 #define sync_print(fmt, args...) do { if(0) DMS_PRINTF(fmt, ##args);  } while (0)
299 MS_U16 gDMSDebug = 0;
300 void* pTaskInstance = NULL;
301 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
302 #if DEV_IMODE_PAUSE
303 static MS_S32 s32DIPDiRePushTimerId = -1;
304 #endif
305 #endif
306 
307 //Marco to simplize resource usage
308 #define DMS_GET_RES_PRI DMS_RESOURCE_PRIVATE* pDMSResPri = NULL;\
309                         UtopiaResourceGetPrivate(g_pDMSRes,(void**)(&pDMSResPri))
310 
311 #define RES_DMS pDMSResPri->stDrvDMS
312 #define RES_DMSDI pDMSResPri->stDrvDMSDi
313 #define RES_DMSCAPTURE pDMSResPri->stDrvDMSCapMode
314 
315 #define DBG_DISABLE_SEMAPHORE 0
316 static MS_BOOL _DMS_GetNextInfo(MS_U16 u16WindowID, MS_BOOL bResetCaptureID);
317 
MDrv_DMS_Get_Semaphore(void * pInstance,EN_DMS_POOL_TYPE ePoolType)318 MS_U32 MDrv_DMS_Get_Semaphore(void* pInstance, EN_DMS_POOL_TYPE ePoolType)
319 {
320 #if DBG_DISABLE_SEMAPHORE
321     static MS_BOOL bGetRes = FALSE;
322     if(bGetRes)
323     {
324         return UTOPIA_STATUS_SUCCESS;
325     }
326 #endif
327     MS_U32 u32Return = UTOPIA_STATUS_FAIL;
328     //DMS_PRINTF("get SHM!!\n");
329     if (pInstance == NULL)
330     {
331         DMS_PRINTF("[%s,%5d]No instance existed, please get an instance by calling MApi_DMS_Init() first\n",__FUNCTION__,__LINE__);
332         return u32Return;
333     }
334 
335     void* pModule = NULL;
336     UtopiaInstanceGetModule(pInstance, &pModule);
337     if(UtopiaResourceObtain(pModule, E_DMS_POOL_ID_INTERNAL_VARIABLE, &g_pDMSRes) != UTOPIA_STATUS_SUCCESS)
338     {
339         DMS_PRINTF("UtopiaResourceObtain fail\n");
340         return UTOPIA_STATUS_ERR_RESOURCE;
341     }
342 
343     u32Return = UTOPIA_STATUS_SUCCESS;
344 #if DBG_DISABLE_SEMAPHORE
345     printf("\033[1;31m Disable semaphore get!!!!!!!!!!!!!!!!\033[0m\n");
346     bGetRes = TRUE;
347 #endif
348     return u32Return;
349 }
350 
MDrv_DMS_Release_Semaphore(void * pInstance,EN_DMS_POOL_TYPE ePoolType)351 MS_U32 MDrv_DMS_Release_Semaphore(void* pInstance, EN_DMS_POOL_TYPE ePoolType)
352 {
353 #if DBG_DISABLE_SEMAPHORE
354     return UTOPIA_STATUS_SUCCESS;
355 #endif
356     //DMS_PRINTF("release SHM!!\n");
357     MS_U32 u32Return = UTOPIA_STATUS_FAIL;
358     u32Return = UtopiaResourceRelease(g_pDMSRes);
359     return u32Return;
360 }
361 
362 //-------------------------------------------------------------------------------------------------
363 //  Local Defines
364 //-------------------------------------------------------------------------------------------------
_DMS_Add_XC_Status(MS_U32 u32Window,MS_U32 u32Status)365 static void _DMS_Add_XC_Status(MS_U32 u32Window, MS_U32 u32Status)
366 {
367     DMS_GET_RES_PRI;
368     RES_DMS.gu8DMS_SetXC_Status[u32Window] |= (u32Status);
369 }
370 
_DMS_Remove_XC_Status(MS_U32 u32Window,MS_U32 u32Status)371 static void _DMS_Remove_XC_Status(MS_U32 u32Window, MS_U32 u32Status)
372 {
373     DMS_GET_RES_PRI;
374     RES_DMS.gu8DMS_SetXC_Status[u32Window] &= ~(u32Status);
375 }
376 
_DMS_Query_XC_Status(MS_U32 u32Window,MS_U32 u32Status)377 static MS_BOOL _DMS_Query_XC_Status(MS_U32 u32Window, MS_U32 u32Status)
378 {
379     DMS_GET_RES_PRI;
380     return (RES_DMS.gu8DMS_SetXC_Status[u32Window] & (u32Status))? TRUE : FALSE;
381 }
382 
_DMS_Is_MVOPFlow(MS_U32 u32Window)383 static MS_BOOL _DMS_Is_MVOPFlow(MS_U32 u32Window)
384 {
385     return ((DMS_MVOP_FLOW) && (u32Window == MVOP_WINDOW));
386 }
387 
_DMS_Is_SourceInterlace(E_DMS_VIDEO_SCAN_TYPE eScanType)388 static MS_BOOL _DMS_Is_SourceInterlace(E_DMS_VIDEO_SCAN_TYPE eScanType)
389 {
390     if((eScanType == E_DMS_VIDEO_SCAN_TYPE_INTERLACE_FRAME) || (eScanType == E_DMS_VIDEO_SCAN_TYPE_INTERLACE_FIELD))
391     {
392         return TRUE;
393     }
394     else
395     {
396         return FALSE;
397     }
398 }
399 
_DMS_Is_SourceFieldBaseInterlace(E_DMS_VIDEO_SCAN_TYPE eScanType)400 static MS_BOOL _DMS_Is_SourceFieldBaseInterlace(E_DMS_VIDEO_SCAN_TYPE eScanType)
401 {
402     if(eScanType == E_DMS_VIDEO_SCAN_TYPE_INTERLACE_FIELD)
403     {
404         return TRUE;
405     }
406     else
407     {
408         return FALSE;
409     }
410 }
411 
_DMS_Is_SourceFrameBaseInterlace(E_DMS_VIDEO_SCAN_TYPE eScanType,E_DMS_VIDEO_FIELD_TYPE eFieldType)412 static MS_BOOL _DMS_Is_SourceFrameBaseInterlace(E_DMS_VIDEO_SCAN_TYPE eScanType, E_DMS_VIDEO_FIELD_TYPE eFieldType)
413 {
414     if((eScanType == E_DMS_VIDEO_SCAN_TYPE_INTERLACE_FRAME) && (eFieldType == E_DMS_VIDEO_FIELD_TYPE_BOTH))
415     {
416         return TRUE;
417     }
418     else
419     {
420         return FALSE;
421     }
422 }
423 
_DMS_Is_CaptureMode_OutputTile(EN_DMS_DIP_TILE_BLOCK eTileBlock)424 static MS_BOOL _DMS_Is_CaptureMode_OutputTile(EN_DMS_DIP_TILE_BLOCK eTileBlock)
425 {
426     if(eTileBlock != DMS_DIP_TILE_BLOCK_W_16_32)
427     {
428         return TRUE;
429     }
430     else
431     {
432         return FALSE;
433     }
434 }
435 
_DMS_Is_ScalingConditionUse2ndBuffer(MS_U32 u32ScalingCondition)436 static MS_BOOL _DMS_Is_ScalingConditionUse2ndBuffer(MS_U32 u32ScalingCondition)
437 {
438     if(u32ScalingCondition & USE_2ND_BUFFER)
439     {
440         return TRUE;
441     }
442     else
443     {
444         return FALSE;
445     }
446 }
447 
_DMS_Is_ScalingConditionUseFBL(MS_U32 u32ScalingCondition)448 static MS_BOOL _DMS_Is_ScalingConditionUseFBL(MS_U32 u32ScalingCondition)
449 {
450     if(u32ScalingCondition & USE_XC_FBL)
451     {
452         return TRUE;
453     }
454     else
455     {
456         return FALSE;
457     }
458 }
459 
_DMS_DIP_GetFrameBaseInterlaceFieldType(DMS_VDECFRAME_INFO * pVDECFrameInfo)460 static MS_BOOL _DMS_DIP_GetFrameBaseInterlaceFieldType(DMS_VDECFRAME_INFO *pVDECFrameInfo)
461 {
462     if(pVDECFrameInfo->bIs2ndField == FALSE)
463     {
464         if(pVDECFrameInfo->eFieldOrderType == E_DMS_VIDEO_FIELD_ORDER_TYPE_TOP)
465         {
466             pVDECFrameInfo->eFieldType = E_DMS_VIDEO_FIELD_TYPE_TOP;
467         }
468         else
469         {
470             pVDECFrameInfo->eFieldType = E_DMS_VIDEO_FIELD_TYPE_BOTTOM;
471         }
472     }
473     else
474     {
475         if(pVDECFrameInfo->eFieldOrderType == E_DMS_VIDEO_FIELD_ORDER_TYPE_TOP)
476         {
477             pVDECFrameInfo->eFieldType = E_DMS_VIDEO_FIELD_TYPE_BOTTOM;
478         }
479         else
480         {
481             pVDECFrameInfo->eFieldType = E_DMS_VIDEO_FIELD_TYPE_TOP;
482         }
483     }
484 
485     return TRUE;
486 }
487 
_DMS_Is_UVSwap(EN_DMS_CAPTURE_COLORFORMAT eColorFormat)488 static MS_BOOL _DMS_Is_UVSwap(EN_DMS_CAPTURE_COLORFORMAT eColorFormat)
489 {
490     if((eColorFormat == E_DMS_CAPTURE_COLOR_FORMAT_YVYU) || (eColorFormat == E_DMS_CAPTURE_COLOR_FORMAT_VYUY))
491     {
492         return TRUE;
493     }
494     else
495     {
496         return FALSE;
497     }
498 }
499 
_DMS_Is_YCSwap(EN_DMS_CAPTURE_COLORFORMAT eColorFormat)500 static MS_BOOL _DMS_Is_YCSwap(EN_DMS_CAPTURE_COLORFORMAT eColorFormat)
501 {
502     if((eColorFormat == E_DMS_CAPTURE_COLOR_FORMAT_UYVY) || (eColorFormat == E_DMS_CAPTURE_COLOR_FORMAT_VYUY))
503     {
504         return TRUE;
505     }
506     else
507     {
508         return FALSE;
509     }
510 }
511 
512 #define DMS_FHD_MAX_H_SIZE 1920
513 #define DMS_FHD_MAX_V_SIZE 1088
_DMS_WindowSizeOverFHD(MS_U32 u32Width,MS_U32 u32Height)514 static MS_BOOL _DMS_WindowSizeOverFHD(MS_U32 u32Width, MS_U32 u32Height)
515 {
516     if((u32Width > DMS_FHD_MAX_H_SIZE) && (u32Height > DMS_FHD_MAX_V_SIZE))
517     {
518         return TRUE;
519     }
520     else
521     {
522         return FALSE;
523     }
524 }
525 
_DMS_DIP_GetDIPDiDataFMT(MS_U32 u32Window,E_DMS_VIDEO_SCAN_TYPE eScanType,E_DMS_VIDEO_FIELD_TYPE eFieldType)526 static EN_DIP_DI_FIELD _DMS_DIP_GetDIPDiDataFMT(MS_U32 u32Window, E_DMS_VIDEO_SCAN_TYPE eScanType, E_DMS_VIDEO_FIELD_TYPE eFieldType)
527 {
528     EN_DIP_DI_FIELD eDIField = E_DIP_3DDI_TOP_BOTH_FIELD_STAGGER;
529 #if DMS_DIP_Support_3DDI
530     if(u32Window == MVOP_WINDOW)
531     {
532         if(eScanType == E_DMS_VIDEO_SCAN_TYPE_INTERLACE_FRAME)
533         {
534             if(eFieldType == E_DMS_VIDEO_FIELD_TYPE_TOP)
535             {
536                 eDIField = E_DIP_3DDI_TOP_BOTH_FIELD_STAGGER;
537             }
538             else if(eFieldType == E_DMS_VIDEO_FIELD_TYPE_BOTTOM)
539             {
540                 eDIField = E_DIP_3DDI_BOTTOM_BOTH_FIELD_STAGGER;
541             }
542         }
543         else if(eScanType == E_DMS_VIDEO_SCAN_TYPE_INTERLACE_FIELD)
544         {
545             if(eFieldType == E_DMS_VIDEO_FIELD_TYPE_TOP)
546             {
547                 eDIField = E_DIP_3DDI_TOP_SINGLE_FIELD;
548             }
549             else if(eFieldType == E_DMS_VIDEO_FIELD_TYPE_BOTTOM)
550             {
551                 eDIField = E_DIP_3DDI_BOTTOM_SINGLE_FIELD;
552             }
553         }
554         return eDIField;
555     }
556 #else
557     if(u32Window == MVOP_WINDOW)
558     {
559         if(eScanType == E_DMS_VIDEO_SCAN_TYPE_INTERLACE_FRAME)
560         {
561             if(eFieldType == E_DMS_VIDEO_FIELD_TYPE_TOP)
562             {
563                 eDIField = E_DIP_MED_DI_TOP_BOTH_FIELD_STAGGER;
564             }
565             else if(eFieldType == E_DMS_VIDEO_FIELD_TYPE_BOTTOM)
566             {
567                 eDIField = E_DIP_MED_DI_BOTTOM_BOTH_FIELD_STAGGER;
568             }
569         }
570         else if(eScanType == E_DMS_VIDEO_SCAN_TYPE_INTERLACE_FIELD)
571         {
572             if(eFieldType == E_DMS_VIDEO_FIELD_TYPE_TOP)
573             {
574                 eDIField = E_DIP_MED_DI_TOP_BOTH_FIELD_SEPARATE;
575             }
576             else if(eFieldType == E_DMS_VIDEO_FIELD_TYPE_BOTTOM)
577             {
578                 eDIField = E_DIP_MED_DI_BOTTOM_BOTH_FIELD_SEPARATE;
579             }
580         }
581         return eDIField;
582     }
583 #endif
584 #if DMS_DIP_NWindow_Support_2P5DDI
585     else
586     {
587         if(eScanType == E_DMS_VIDEO_SCAN_TYPE_INTERLACE_FRAME)
588         {
589             if(eFieldType == E_DMS_VIDEO_FIELD_TYPE_TOP)
590             {
591                 eDIField = E_DIP_MED_DI_TOP_BOTH_FIELD_STAGGER;
592             }
593             else if(eFieldType == E_DMS_VIDEO_FIELD_TYPE_BOTTOM)
594             {
595                 eDIField = E_DIP_MED_DI_BOTTOM_BOTH_FIELD_STAGGER;
596             }
597         }
598         else if(eScanType == E_DMS_VIDEO_SCAN_TYPE_INTERLACE_FIELD)
599         {
600             if(eFieldType == E_DMS_VIDEO_FIELD_TYPE_TOP)
601             {
602                 eDIField = E_DIP_MED_DI_TOP_BOTH_FIELD_SEPARATE;
603             }
604             else if(eFieldType == E_DMS_VIDEO_FIELD_TYPE_BOTTOM)
605             {
606                 eDIField = E_DIP_MED_DI_BOTTOM_BOTH_FIELD_SEPARATE;
607             }
608         }
609         return eDIField;
610     }
611 #endif
612     printf("\033[31m [%s][%d] CHECK CODE FLOW, SHOULD NOT REACH HERE !!\033[0m\n",__FUNCTION__,__LINE__);
613     return eDIField;
614 }
615 
_DMS_DIP_GetDIPRDataFMT(DMS_VDECFRAME_INFO * pVDECFrameInfo)616 static EN_XC_DIP_DATA_FMT _DMS_DIP_GetDIPRDataFMT(DMS_VDECFRAME_INFO *pVDECFrameInfo)
617 {
618     EN_XC_DIP_DATA_FMT eFmt = E_DMS_VIDEO_CODEC_UNKNOWN;
619 
620     switch (pVDECFrameInfo->eCODEC)
621     {
622         case E_DMS_VIDEO_CODEC_HEVC:
623             eFmt = DIP_DATA_FMT_YUV420_H265;
624             break;
625         case E_DMS_VIDEO_CODEC_H264:
626         default :
627             eFmt = DIP_DATA_FMT_YUV420;
628             break;
629     }
630     return eFmt;
631 }
632 
_DMS_DIP_CalcPitch(EN_XC_DIP_DATA_FMT eFmt,MS_U16 u16Width)633 static MS_U16 _DMS_DIP_CalcPitch(EN_XC_DIP_DATA_FMT eFmt, MS_U16 u16Width)
634 {
635     MS_U16 u16Pitch = 0;
636     switch (eFmt)
637     {
638         case DIP_DATA_FMT_YUV420:
639         case DIP_DATA_FMT_YUV420_H265:
640         case DIP_DATA_FMT_YUV420_MED_DI_FIELDTYPE_TOP:
641         case DIP_DATA_FMT_YUV420_MED_DI_FIELDTYPE_BOTTOM:
642             u16Pitch = u16Width * 3 / 2; //*1.5
643             break;
644         case DIP_DATA_FMT_RGB565:
645         case DIP_DATA_FMT_YUV422:
646         case DIP_DATA_FMT_YUV422_MED_DI_FIELDTYPE_TOP:
647         case DIP_DATA_FMT_YUV422_MED_DI_FIELDTYPE_BOTTOM:
648             u16Pitch = u16Width << 1;
649             break;
650         case DIP_DATA_FMT_ARGB8888:
651             u16Pitch = u16Width << 2;
652             break;
653         default :
654             u16Pitch = 0;
655             break;
656     }
657     return u16Pitch;
658 }
659 
_DMS_DIP_MFDECTileTypeMapping(E_DMS_VIDEO_TILE_MODE eTileMode)660 static EN_MFDEC_TILE_MODE _DMS_DIP_MFDECTileTypeMapping(E_DMS_VIDEO_TILE_MODE eTileMode)
661 {
662     EN_MFDEC_TILE_MODE eTile;
663     switch (eTileMode)
664     {
665         case E_DMS_VIDEO_TILE_MODE_16x32:
666             eTile = E_DIP_MFEDC_TILE_16_32;
667             break;
668         case E_DMS_VIDEO_TILE_MODE_32x16:
669             eTile = E_DIP_MFEDC_TILE_32_16;
670             break;
671         case E_DMS_VIDEO_TILE_MODE_32x32:
672             eTile = E_DIP_MFEDC_TILE_32_32;
673             break;
674         default :
675             eTile = E_DIP_MFEDC_TILE_16_32;
676             break;
677     }
678     return eTile;
679 }
680 
_DMS_DIP_TileTypeMapping(E_DMS_VIDEO_TILE_MODE eTileMode)681 static EN_XC_DIP_TILE_BLOCK _DMS_DIP_TileTypeMapping(E_DMS_VIDEO_TILE_MODE eTileMode)
682 {
683     EN_XC_DIP_TILE_BLOCK eTile;
684     switch (eTileMode)
685     {
686         case E_DMS_VIDEO_TILE_MODE_16x32:
687             eTile = DIP_TILE_BLOCK_R_16_32;
688             break;
689         case E_DMS_VIDEO_TILE_MODE_32x16:
690             eTile = DIP_TILE_BLOCK_R_32_16;
691             break;
692         case E_DMS_VIDEO_TILE_MODE_32x32:
693             eTile = DIP_TILE_BLOCK_R_32_32;
694             break;
695         default :
696             eTile = DIP_TILE_BLOCK_R_16_32;
697             break;
698     }
699 
700     return eTile;
701 }
702 
_DMS_DIP_Capture_TileMapping(EN_DMS_DIP_TILE_BLOCK eTileMode)703 static EN_XC_DIP_TILE_BLOCK _DMS_DIP_Capture_TileMapping(EN_DMS_DIP_TILE_BLOCK eTileMode)
704 {
705     EN_XC_DIP_TILE_BLOCK eTile;
706     switch (eTileMode)
707     {
708         case DMS_DIP_TILE_BLOCK_R_NONE:
709             eTile = DIP_TILE_BLOCK_R_NONE;
710             break;
711         case DMS_DIP_TILE_BLOCK_W_NONE:
712             eTile = DIP_TILE_BLOCK_W_NONE;
713             break;
714         case DMS_DIP_TILE_BLOCK_R_16_32:
715             eTile = DIP_TILE_BLOCK_R_16_32;
716             break;
717         case DMS_DIP_TILE_BLOCK_W_16_32:
718             eTile = DIP_TILE_BLOCK_W_16_32;
719             break;
720         case DMS_DIP_TILE_BLOCK_R_32_16:
721             eTile = DIP_TILE_BLOCK_R_32_16;
722             break;
723         case DMS_DIP_TILE_BLOCK_W_32_16:
724             eTile = DIP_TILE_BLOCK_W_32_16;
725             break;
726         case DMS_DIP_TILE_BLOCK_R_32_32:
727             eTile = DIP_TILE_BLOCK_R_32_32;
728             break;
729         case DMS_DIP_TILE_BLOCK_W_32_32:
730             eTile = DIP_TILE_BLOCK_W_32_32;
731             break;
732         default :
733             eTile = DIP_TILE_BLOCK_R_16_32;
734             break;
735     }
736 
737     return eTile;
738 }
739 
_DMS_DIP_Capture_ColorFmtMapping(EN_DMS_DIP_FMT eColorFmt)740 static EN_XC_DIP_DATA_FMT _DMS_DIP_Capture_ColorFmtMapping(EN_DMS_DIP_FMT eColorFmt)
741 {
742     EN_XC_DIP_DATA_FMT eFmt;
743     switch (eColorFmt)
744     {
745         case E_DMS_DIP_FMT_YUV422:
746             eFmt = DIP_DATA_FMT_YUV422;
747             break;
748         case E_DMS_DIP_FMT_RGB565:
749             eFmt = DIP_DATA_FMT_RGB565;
750             break;
751         case E_DMS_DIP_FMT_ARGB8888:
752             eFmt = DIP_DATA_FMT_ARGB8888;
753             break;
754         case E_DMS_DIP_FMT_YUV420:
755             eFmt = DIP_DATA_FMT_YUV420;
756             break;
757         case E_DMS_DIP_FMT_YC422:
758             eFmt = DIP_DATA_FMT_YC422;
759             break;
760         case E_DMS_DIP_FMT_YUV420_H265:
761             eFmt = DIP_DATA_FMT_YUV420_H265;
762             break;
763         case E_DMS_DIP_FMT_YUV420_H265_10BITS:
764             eFmt = DIP_DATA_FMT_YUV420_H265_10BITS;
765             break;
766         case E_DMS_DIP_FMT_YUV420_PLANER:
767             eFmt = DIP_DATA_FMT_YUV420_PLANER;
768             break;
769         case E_DMS_DIP_FMT_YUV420_SEMI_PLANER:
770             eFmt = DIP_DATA_FMT_YUV420_SEMI_PLANER;
771             break;
772         case E_DMS_DIP_FMT_YUV422_MED_DI_FIELDTYPE_TOP:
773             eFmt = DIP_DATA_FMT_YUV422_MED_DI_FIELDTYPE_TOP;
774             break;
775         case E_DMS_DIP_FMT_YUV422_MED_DI_FIELDTYPE_BOTTOM:
776             eFmt = DIP_DATA_FMT_YUV422_MED_DI_FIELDTYPE_BOTTOM;
777             break;
778         case E_DMS_DIP_FMT_YUV420_MED_DI_FIELDTYPE_TOP:
779             eFmt = DIP_DATA_FMT_YUV420_MED_DI_FIELDTYPE_TOP;
780             break;
781         case E_DMS_DIP_FMT_YUV420_MED_DI_FIELDTYPE_BOTTOM:
782             eFmt = DIP_DATA_FMT_YUV420_MED_DI_FIELDTYPE_BOTTOM;
783             break;
784         default :
785             eFmt = DIP_DATA_FMT_MAX;
786             break;
787     }
788 
789     return eFmt;
790 }
791 
_DMS_XC_SetCusScaling(XC_SETWIN_INFO * pXCSetWinInfo,MS_BOOL bPostScaling,MS_U16 u16Hsrc,MS_U16 u16Hdest,MS_U16 u16Vsrc,MS_U16 u16Vdest)792 static void _DMS_XC_SetCusScaling(XC_SETWIN_INFO* pXCSetWinInfo, MS_BOOL bPostScaling,MS_U16 u16Hsrc, MS_U16 u16Hdest, MS_U16 u16Vsrc, MS_U16 u16Vdest)
793 {
794     if(pXCSetWinInfo != NULL)
795     {
796         if(bPostScaling)
797         {
798             pXCSetWinInfo->u16HCusScalingSrc = u16Hsrc;
799             pXCSetWinInfo->u16HCusScalingDst = u16Hdest;
800             pXCSetWinInfo->u16VCusScalingSrc = u16Vsrc;
801             pXCSetWinInfo->u16VCusScalingDst = u16Vdest;
802         }
803         else
804         {
805             pXCSetWinInfo->u16PreHCusScalingSrc = u16Hsrc;
806             pXCSetWinInfo->u16PreHCusScalingDst = u16Hdest;
807             pXCSetWinInfo->u16PreVCusScalingSrc = u16Vsrc;
808             pXCSetWinInfo->u16PreVCusScalingDst = u16Vdest;
809         }
810     }
811 }
812 
_DMS_XC_WindowAlignto2(ST_DMS_WINDOW * pstDMSWindow)813 static void _DMS_XC_WindowAlignto2(ST_DMS_WINDOW *pstDMSWindow)
814 {
815     pstDMSWindow->u32x += (pstDMSWindow->u32x % 2);
816     pstDMSWindow->u32y += (pstDMSWindow->u32y % 2);
817     pstDMSWindow->u32width += (pstDMSWindow->u32width % 2);
818     pstDMSWindow->u32height += (pstDMSWindow->u32height % 2);
819 }
820 
_DMS_XC_DMSWintoXCWin(MS_WINDOW_TYPE * pstXCWindow,ST_DMS_WINDOW * pstDMSWindow)821 static void _DMS_XC_DMSWintoXCWin(MS_WINDOW_TYPE *pstXCWindow, ST_DMS_WINDOW *pstDMSWindow)
822 {
823     pstXCWindow->x = (pstDMSWindow->u32x);
824     pstXCWindow->y = (pstDMSWindow->u32y);
825     pstXCWindow->width = (pstDMSWindow->u32width);
826     pstXCWindow->height = (pstDMSWindow->u32height);
827 }
828 
_GetPreviousBufferID(MS_U16 u16CurID)829 static MS_U16 _GetPreviousBufferID(MS_U16 u16CurID)
830 {
831     if (u16CurID == 0)
832     {
833         return (DMS_DIP_QUEUEDEPTH - 1);
834     }
835     else
836     {
837         return (u16CurID - 1);
838     }
839 }
840 
_GetNextBufferID(MS_U16 u16CurID)841 static MS_U16 _GetNextBufferID(MS_U16 u16CurID)
842 {
843     return ((u16CurID + 1) % DMS_DIP_QUEUEDEPTH);
844 }
845 
_IsFrameRefCountZero(MS_U32 u32Window,MS_U16 u16BufID)846 static MS_BOOL _IsFrameRefCountZero(MS_U32 u32Window, MS_U16 u16BufID)
847 {
848     DMS_GET_RES_PRI;
849     if((RES_DMS._stXC_LocalFrameRefCount[u32Window][u16BufID] == 0)
850         && (RES_DMSCAPTURE._stXC_LocalFrameRefCountCaptureMode[u32Window][u16BufID] == 0))
851     {
852         return TRUE;
853     }
854     else
855     {
856         return FALSE;
857     }
858 }
859 
860 
861 
_DMS_GetDMSScanType(MS_U8 u8ScanType)862 E_DMS_VIDEO_SCAN_TYPE _DMS_GetDMSScanType(MS_U8 u8ScanType)
863 {
864     // ProgressiveFrame = 0,   /** Picture is a progressive frame */
865     // InterlacedFrame  = 2,    /** Picture is an interlaced frame */
866     // InterlacedField  = 3,      /** Picture is two interlaced fields */
867     // InterlacedFrame  = 1,      MVD bring 1 to push interlace frame
868     E_DMS_VIDEO_SCAN_TYPE eScanType = E_DMS_VIDEO_SCAN_TYPE_MAX;
869     switch (u8ScanType)
870     {
871         case 0:
872             eScanType = E_DMS_VIDEO_SCAN_TYPE_PROGRESSIVE;
873             break;
874         case 1:
875         case 2:
876             eScanType = E_DMS_VIDEO_SCAN_TYPE_INTERLACE_FRAME;
877             break;
878         case 3:
879             eScanType = E_DMS_VIDEO_SCAN_TYPE_INTERLACE_FIELD;
880             break;
881         default:
882             eScanType = E_DMS_VIDEO_SCAN_TYPE_MAX;
883             break;
884     }
885     return eScanType;
886 }
887 
888 #if DEV_DI
889 static MS_BOOL _DMS_DIP_Fire(E_DMS_DIP_ACTION eAction);
890 static MS_BOOL _DMS_DIP_WaitWriteDone(E_DMS_DIP_ACTION eAction);
891 static MS_BOOL _DMS_SetDIPRWindow(E_DMS_DIP_ACTION eAction, MS_U32 u32Window, MS_U16 u16BufferID);
892 static MS_BOOL _DMS_SetDIPWWindow(E_DMS_DIP_ACTION eAction, MS_U32 u32Window, MS_U16 u16BufferID);
893 static MS_BOOL _DMS_SetDIPWindow(E_DMS_DIP_ACTION eAction, MS_U32 u32Window, MS_U16 u16BufferID);
894 static void _DMS_StoreVDECInfo2DIPQueue(void* pInstance, DMS_VDECFRAME_INFO *VDECDispFrame);
895 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
896 static void _DMS_DIP_SyncStoredSetting(void);
897 #endif
898 static MS_S32 XC_Di_Push_Event_id = -1;
899 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
900 static MS_S32  s32DIPTaskID_Interlace = -1;
901 #endif
902 #define di_sync_print(fmt, args...) do { if(0) DMS_PRINTF(fmt, ##args);  } while (0)
903 MS_PHY tempAddr = 0x0;
904 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
_DIBufferRingToNext(void)905 static void _DIBufferRingToNext(void)
906 {
907     DMS_GET_RES_PRI;
908     RES_DMSDI.u8DIRingBufferID++;
909     if(RES_DMSDI.u8DIRingBufferID == DMS_DI_RING_BUFFER)
910     {
911         RES_DMSDI.u8DIRingBufferID = 0;
912     }
913 }
914 #endif
_GetDIRingBufferAddr(MS_U32 u32Window,MS_U8 u8RingBufID)915 static MS_PHY _GetDIRingBufferAddr(MS_U32 u32Window, MS_U8 u8RingBufID)
916 {
917     DMS_GET_RES_PRI;
918     if(u8RingBufID >= DMS_DI_RING_BUFFER)
919     {
920         DMS_PRINTF("_GetDIRingBufferAddr error, %d\n",u8RingBufID);
921     }
922     return RES_DMS._stXC_DIPWinInfo[u32Window].phyDIPRingBufMemAddr[u8RingBufID];
923 }
924 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
_DMS_VDEC_Frame_AddRef_Interlace(MS_U32 u32Window,MS_U16 u16BufID)925 static MS_BOOL _DMS_VDEC_Frame_AddRef_Interlace(MS_U32 u32Window, MS_U16 u16BufID)
926 {
927     DMS_GET_RES_PRI;
928 #if NEW_FLIP
929     //DMS_PRINTF("[AddRef] bid[0x%x], ct[0x%x]\n",u16BufID,RES_DMSDI._stXC_LocalFrameRefCountInterlace[u32Window][u16BufID]);
930     VDEC_StreamId VdecStreamId;
931     VDEC_EX_DispFrame VdecDispFrm;
932     VdecStreamId.u32Version = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufID].u32VDECStreamVersion;
933     VdecStreamId.u32Id = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufID].u32VDECStreamID;
934     VdecDispFrm.u32Idx = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufID].u32FrameIndex;
935     VdecDispFrm.u32PriData = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufID].u32PriData;
936     VDEC_EX_Result eResult;
937     eResult = MApi_VDEC_EX_DisplayFrame((VDEC_StreamId*)&VdecStreamId, &VdecDispFrm);
938     if (eResult != E_VDEC_EX_OK)
939     {
940         DMS_PRINTF("[%s] %d %d, %d %d\n",__FUNCTION__,VdecStreamId.u32Version,VdecStreamId.u32Id,
941             VdecDispFrm.u32Idx,VdecDispFrm.u32PriData);
942         DMS_PRINTF("[%s] window %d, BufID %d, MApi_VDEC_EX_DisplayFrame return %d\n",__FUNCTION__,u32Window,u16BufID,eResult);
943         return FALSE;
944     }
945     if(_DMS_Is_SourceFieldBaseInterlace(RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufID].eScanType))
946     {
947         VdecStreamId.u32Version = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufID].u32VDECStreamVersion;
948         VdecStreamId.u32Id = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufID].u32VDECStreamID;
949         VdecDispFrm.u32Idx = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufID].u32FrameIndex_2nd;
950         VdecDispFrm.u32PriData = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufID].u32PriData_2nd;
951         VDEC_EX_Result eResult;
952         eResult = MApi_VDEC_EX_DisplayFrame((VDEC_StreamId*)&VdecStreamId, &VdecDispFrm);
953         if (eResult != E_VDEC_EX_OK)
954         {
955             DMS_PRINTF("[%s] %d %d, %d %d\n",__FUNCTION__,VdecStreamId.u32Version,VdecStreamId.u32Id,
956                 VdecDispFrm.u32Idx,VdecDispFrm.u32PriData);
957             DMS_PRINTF("[%s] window %d, BufID %d, 2nd Field, MApi_VDEC_EX_DisplayFrame return %d\n",__FUNCTION__,u32Window,u16BufID,eResult);
958             return FALSE;
959         }
960     }
961     //DMS_PRINTF("[AddRef] Frame[0x%x], PriData[0x%x]\n",RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufID].u32FrameIndex,RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufID].u32PriData);
962     RES_DMSDI._stXC_LocalFrameRefCountInterlace[u32Window][u16BufID]++;
963 
964 #if DBG_FPS
965     u32FPS_Add_Counter[u32Window]++;
966 #endif
967 #endif
968     return TRUE;
969 }
970 #endif
_DMS_VDEC_Frame_Release_Interlace(MS_U32 u32Window,MS_U16 u16BufID)971 static MS_BOOL _DMS_VDEC_Frame_Release_Interlace(MS_U32 u32Window, MS_U16 u16BufID)
972 {
973     DMS_GET_RES_PRI;
974 #if NEW_FLIP
975     //DMS_PRINTF("[Releas] bid[0x%x], ct[0x%x]\n",u16BufID,RES_DMSDI._stXC_LocalFrameRefCountInterlace[u32Window][u16BufID]);
976 
977     if(RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufID].u32FrameIndex == DMS_INVALID_FRAME_ID)
978     {
979         //DMS_PRINTF("[%s] window %d, BufID %d, Release an invalid buffer\n",__FUNCTION__,u32Window,u16BufID);
980         return TRUE;
981     }
982     if(RES_DMSDI._stXC_LocalFrameRefCountInterlace[u32Window][u16BufID] == 0)
983     {
984         //DMS_PRINTF("[%s] window %d, BufID %d, Release an invalid buffer (release a ref 0 frame)\n",__FUNCTION__,u32Window,u16BufID);
985         return TRUE;
986     }
987     RES_DMSDI._stXC_LocalFrameRefCountInterlace[u32Window][u16BufID]--;
988     if(RES_DMSDI._stXC_LocalFrameRefCountInterlace[u32Window][u16BufID] == 0)
989     {
990         VDEC_StreamId VdecStreamId;
991         VDEC_EX_DispFrame VdecDispFrm;
992         VdecStreamId.u32Version = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufID].u32VDECStreamVersion;
993         VdecStreamId.u32Id = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufID].u32VDECStreamID;
994         VdecDispFrm.u32Idx = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufID].u32FrameIndex;
995         VdecDispFrm.u32PriData = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufID].u32PriData;
996 
997         VDEC_EX_Result eResult;
998         eResult = MApi_VDEC_EX_ReleaseFrame((VDEC_StreamId *) &VdecStreamId, &VdecDispFrm);
999         if (eResult != E_VDEC_EX_OK)
1000         {
1001             DMS_PRINTF("[%s] %td %td, %td %td\n",__FUNCTION__,(ptrdiff_t)VdecStreamId.u32Version,(ptrdiff_t)VdecStreamId.u32Id,
1002                 (ptrdiff_t)VdecDispFrm.u32Idx,(ptrdiff_t)VdecDispFrm.u32PriData);
1003             DMS_PRINTF("[%s] window %d, BufID %td, MApi_VDEC_EX_ReleaseFrame return %d\n",__FUNCTION__,(ptrdiff_t)u32Window,u16BufID,eResult);
1004             return FALSE;
1005         }
1006         if(_DMS_Is_SourceFieldBaseInterlace(RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufID].eScanType))
1007         {
1008             VdecStreamId.u32Version = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufID].u32VDECStreamVersion;
1009             VdecStreamId.u32Id = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufID].u32VDECStreamID;
1010             VdecDispFrm.u32Idx = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufID].u32FrameIndex_2nd;
1011             VdecDispFrm.u32PriData = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufID].u32PriData_2nd;
1012 
1013             VDEC_EX_Result eResult;
1014             eResult = MApi_VDEC_EX_ReleaseFrame((VDEC_StreamId *) &VdecStreamId, &VdecDispFrm);
1015             if (eResult != E_VDEC_EX_OK)
1016             {
1017                 DMS_PRINTF("[%s] %td %td, %td %td\n",__FUNCTION__,(ptrdiff_t)VdecStreamId.u32Version,(ptrdiff_t)VdecStreamId.u32Id,
1018                     (ptrdiff_t)VdecDispFrm.u32Idx,(ptrdiff_t)VdecDispFrm.u32PriData);
1019                 DMS_PRINTF("[%s] window %td, BufID %d, 2nd Field, MApi_VDEC_EX_ReleaseFrame return %d\n",__FUNCTION__,(ptrdiff_t)u32Window,u16BufID,eResult);
1020                 return FALSE;
1021             }
1022         }
1023         //DMS_PRINTF("[Releas] Frame[0x%x], PriData[0x%x]\n",_stXC_DIPDIInfo[u32Window][u16BufID].u32FrameIndex,_stXC_DIPDIInfo[u32Window][u16BufID].u32PriData);
1024         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufID].u32FrameIndex = DMS_INVALID_FRAME_ID;
1025     }
1026 
1027 #if DBG_FPS
1028     u32FPS_Release_Counter[u32Window]++;
1029 #endif
1030 #endif
1031     return TRUE;
1032 }
1033 
_DMS_Clear_VDEC_Frame_Ref_Interlace(MS_U32 u32Window,MS_U16 u16BufID)1034 static void _DMS_Clear_VDEC_Frame_Ref_Interlace(MS_U32 u32Window, MS_U16 u16BufID)
1035 {
1036     DMS_GET_RES_PRI;
1037     MS_U8 u8RefCounter = 0;
1038     for(u8RefCounter = 0; u8RefCounter < RES_DMSDI._stXC_LocalFrameRefCountInterlace[u32Window][u16BufID]; u8RefCounter++)
1039     {
1040         DMS_PRINTF("[%s] window %td release frame for WP %d ct %d\n",__FUNCTION__,(ptrdiff_t)u32Window,u16BufID,(u8RefCounter+1));
1041         _DMS_VDEC_Frame_Release_Interlace(u32Window,u16BufID);
1042     }
1043 }
1044 
_MDrv_DMS_DI_Init(void)1045 MS_BOOL _MDrv_DMS_DI_Init(void)
1046 {
1047     DMS_GET_RES_PRI;
1048     MS_U32 u32DIPDISize = (4/2) * DMS_FHD_Hszie * DMS_FHD_Vszie * 4;
1049     ST_XC_DIPR_PROPERTY_EX DIPRWinPropertytoShow_EX;
1050     ST_DIP_DI_SETTING DIP3DDISetting;
1051     memset(&DIPRWinPropertytoShow_EX,0,sizeof(ST_XC_DIPR_PROPERTY_EX));
1052     memset(&DIP3DDISetting,0,sizeof(ST_DIP_DI_SETTING));
1053     ST_DIP_DI_NWAY_BUF_INFO stDINwayBuf[32];
1054 
1055     DIPRWinPropertytoShow_EX.stDIPRProperty.u16Width = 1920;
1056     DIPRWinPropertytoShow_EX.stDIPRProperty.u16Height = 1080;
1057     DIPRWinPropertytoShow_EX.stDIPRProperty.u16Pitch = 1920;
1058     DIPRWinPropertytoShow_EX.stDIPRProperty.u32YBufAddr = _GetDIRingBufferAddr(MVOP_WINDOW, RES_DMSDI.u8DIRingBufferID);
1059     DIPRWinPropertytoShow_EX.stDIPRProperty.u32CBufAddr = DIPRWinPropertytoShow_EX.stDIPRProperty.u32YBufAddr + u32DIPDISize;
1060     DIPRWinPropertytoShow_EX.stDIPRProperty.enDataFmt = DIP_DATA_FMT_YUV420;
1061     DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.bMFDec_Enable = FALSE;
1062 
1063     DIP3DDISetting.bEnableDI = TRUE;
1064     DIP3DDISetting.bInitDI = TRUE;
1065     DIP3DDISetting.stInitInfo.phyDIInitAddr = RES_DMSDI.u32DIPDIAddress_pa;
1066     DIP3DDISetting.stInitInfo.u32DIInitSize = 0x23456;
1067 
1068     DIP3DDISetting.u8NwayIndex = 0;
1069     DIP3DDISetting.enDI_Field = E_DIP_3DDI_TOP_BOTH_FIELD_STAGGER;
1070     DIP3DDISetting.bEnaNwayInfoRefresh = TRUE;
1071     DIP3DDISetting.u8NwayBufCnt = 1;
1072     DIP3DDISetting.bEnableBob = TRUE;
1073 
1074     stDINwayBuf[0].phyDI_BufAddr = RES_DMSDI.u32DIPDIAddress_pa;
1075     stDINwayBuf[0].u32DI_BufSize = u32DIPDISize;
1076     stDINwayBuf[0].u8DIBufCnt = 4;
1077 
1078     DIP3DDISetting.stDINwayBufInfo = (void*)stDINwayBuf;
1079 
1080     DIPRWinPropertytoShow_EX.stDIPR3DDISetting.stDipr3DDI_VerCtl.u32version=1;
1081     DIPRWinPropertytoShow_EX.stDIPR3DDISetting.pDIPR3DDISetting = (void*)&DIP3DDISetting;
1082 
1083     //weak symbol test
1084     if(MApi_XC_DIP_SetDIPRProperty_EX)
1085     {
1086         MApi_XC_DIP_SetDIPRProperty_EX(&DIPRWinPropertytoShow_EX, DIP_WINDOW);
1087     }
1088     else
1089     {
1090         MApi_XC_DIP_SetDIPRProperty(&DIPRWinPropertytoShow_EX.stDIPRProperty, DIP_WINDOW);
1091     }
1092 
1093     RES_DMS._stXC_DIPWinInfo[MVOP_WINDOW].u32DIStartAddr = RES_DMSDI.u32DIPDIAddress_pa;
1094     RES_DMS._stXC_DIPWinInfo[MVOP_WINDOW].u32DIEndAddr= RES_DMSDI.u32DIPDIAddress_pa + u32DIPDISize;
1095     RES_DMS._stXC_DIPWinInfo[MVOP_WINDOW].u32DISize = u32DIPDISize;
1096     RES_DMS._stXC_DIPWinInfo[MVOP_WINDOW].u8DIBufCnt = 4; // 4 DI temp buffer
1097 
1098     return TRUE;
1099 }
1100 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
_GetNextWritePointerInterlace(MS_U32 u32Window)1101 static MS_U16 _GetNextWritePointerInterlace(MS_U32 u32Window)
1102 {
1103     DMS_GET_RES_PRI;
1104     return _GetNextBufferID(RES_DMSDI._stXC_DIPWriteReadPointerInterlace[u32Window].u16WritePointer);
1105 }
1106 
1107 #if DEV_IMODE_PAUSE
_DIPDi_RePush_Handler(MS_U32 stTimer,MS_U32 u32TimerID)1108 static void _DIPDi_RePush_Handler(MS_U32 stTimer, MS_U32 u32TimerID)
1109 {
1110     void *pInstance = pTaskInstance;
1111     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
1112     DMS_GET_RES_PRI;
1113     if(RES_DMSDI._bSetwinToDiTask_DoubleBuffer)
1114     {
1115 #if DEV_DI_EVENT
1116         MsOS_SetEvent(XC_Di_Push_Event_id, 0x01);
1117 #else
1118         RES_DMSDI.bFlipToDiTask = TRUE;
1119 #endif
1120         printf("[%s] trigger Flip PushedInterlace!\n",__FUNCTION__);
1121     }
1122     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
1123 }
1124 #endif
1125 #endif
1126 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
_Task_CapturePushedInterlaceFrame(void)1127 static MS_BOOL _Task_CapturePushedInterlaceFrame(void)
1128 {
1129     void *pInstance = pTaskInstance;
1130     MS_U8 u8WindowID = 0;
1131 #if DEV_DI_EVENT
1132     MS_U32 u32WaitEventFlag = BIT(0);
1133     MS_U32 u32Events = 0;
1134 #endif
1135     MS_U8  i = 0;
1136     MS_U8  u8FrameIdx = 0;
1137     MS_U8  u8FrameNum = 0;
1138     MS_U8  u8FieldNum = 0;
1139 #if DEV_IMODE_PAUSE
1140     MS_BOOL  s32DIPDiRePushTimerFlag = FALSE;
1141 #endif
1142 
1143     // coverity[no_escape]
1144     while(1)
1145     {
1146         MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
1147         DMS_GET_RES_PRI;
1148 
1149         MS_U16 u16CheckDiBufferID = RES_DMSDI._u8DMS_DiSetEventBufferID;
1150         MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
1151 #if DEV_IMODE_PAUSE
1152         if(u16CheckDiBufferID == DMS_Invalid_ReadPointer_ID)
1153         {
1154             if (s32DIPDiRePushTimerId >= 0)
1155             {
1156                 MsOS_DeleteTimer(s32DIPDiRePushTimerId);
1157                 s32DIPDiRePushTimerId = -1;
1158             }
1159             continue;
1160         }
1161         else
1162         {
1163             MS_U32 u32InputFrameRate = 100;//1000000/(_stXC_DIPDIInfo[u8WindowID][u16NextReadPointer].u32FrameRate*2);
1164             if (s32DIPDiRePushTimerId < 0)
1165             {
1166                 //printf("[%s][%d] Create timer with period 100ms !!\n", __FUNCTION__, __LINE__,u32InputFrameRate,_stXC_DIPDIInfo[u8WindowID][u16NextReadPointer].u32FrameRate);
1167                 s32DIPDiRePushTimerId = MsOS_CreateTimer(_DIPDi_RePush_Handler,
1168                                                     u32InputFrameRate,
1169                                                     u32InputFrameRate,
1170                                                     TRUE,
1171                                                      "DIPDiRePushTimer");
1172                 s32DIPDiRePushTimerFlag = TRUE;
1173             }
1174             else if(s32DIPDiRePushTimerFlag == FALSE)
1175             {
1176                 s32DIPDiRePushTimerFlag = TRUE;
1177                 MsOS_StartTimer(s32DIPDiRePushTimerId);
1178             }
1179         }
1180 #endif
1181 
1182 #if DEV_DI_EVENT
1183         MsOS_WaitEvent(XC_Di_Push_Event_id, u32WaitEventFlag, &u32Events, E_OR_CLEAR, MSOS_WAIT_FOREVER);
1184         MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
1185 #else
1186         MsOS_DelayTask(5);
1187         MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
1188         if(RES_DMSDI.bFlipToDiTask)
1189         {
1190             RES_DMSDI.bFlipToDiTask = FALSE;
1191         }
1192         else
1193         {
1194             MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
1195             continue;
1196         }
1197 #endif
1198 
1199 #if DEV_IMODE_PAUSE
1200         if (s32DIPDiRePushTimerFlag == TRUE)
1201         {
1202             MsOS_StopTimer(s32DIPDiRePushTimerId);
1203             s32DIPDiRePushTimerFlag = FALSE;
1204         }
1205 #endif
1206         MS_U16 u16NextReadPointer = RES_DMSDI._u8DMS_DiSetEventBufferID;
1207         if(u16NextReadPointer == DMS_Invalid_ReadPointer_ID)
1208         {
1209             MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
1210             continue;
1211         }
1212 
1213         for(u8WindowID=0; u8WindowID < 1; u8WindowID++)
1214         {
1215             //Get Next frame info
1216             u8FrameNum = (RES_DMSDI._stXC_DIPDIInfo[u8WindowID][u16NextReadPointer].eScanType == E_DMS_VIDEO_SCAN_TYPE_INTERLACE_FIELD)? 2 : 1;
1217             for(u8FrameIdx=0; u8FrameIdx<u8FrameNum; u8FrameIdx++)
1218             {
1219                 u8FieldNum = (RES_DMSDI._stXC_DIPDIInfo[u8WindowID][u16NextReadPointer].eFieldType == E_DMS_VIDEO_FIELD_TYPE_BOTH)? 2 : 1;
1220                 _DMS_DIP_SyncStoredSetting();
1221                 for(i = 0 ; i < u8FieldNum; i ++)
1222                 {
1223                     MS_BOOL bSetwinToDiTask = RES_DMSDI._bSetwinToDiTask_DoubleBuffer;
1224                     RES_DMSDI.u8DIPReadytoCaptureIDInterlace[u8WindowID] = u16NextReadPointer;
1225 
1226                     if(gDMSDebug == 1)
1227                         gDMSDebug = 2;
1228                     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
1229 
1230                     while(MApi_XC_DIP_GetResource(DIP_WINDOW) == E_APIXC_RET_FAIL)
1231                     {
1232                         MsOS_DelayTask(1);
1233                     }
1234 
1235                     //Disable BK1336 reg3[8]
1236                     MApi_XC_W2BYTEMSK(REG_SC_BK36_03_L,0x0000,0x0100);
1237                     if(_DMS_Is_MVOPFlow(u8WindowID) == FALSE)
1238                     {
1239                         MApi_XC_DIP_SwapUV(TRUE ,DIP_WINDOW);
1240                     }
1241                     else
1242                     {
1243                         MApi_XC_DIP_SwapUV(FALSE ,DIP_WINDOW);
1244                     }
1245                     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
1246 
1247                     _DIBufferRingToNext();
1248 
1249                     MApi_XC_DIP_SetOutputDataFmt(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_MVOP].eDIPWFmt, DIP_WINDOW);
1250                     MApi_XC_DIP_EnableR2Y(FALSE,DIP_WINDOW);
1251                     MApi_XC_DIP_EnableY2R(FALSE,DIP_WINDOW);
1252                     // set DIP read/write window
1253                     _DMS_SetDIPWindow(E_DMS_DIP_DI, u8WindowID, u16NextReadPointer);
1254                     //di_sync_print("\033[1;35mDi+F %d: 0x%x, 0x%llx , MainQ %d \033[0m\n",MsOS_GetSystemTime(), RES_DMSDI._stXC_DIPDIInfo[u8WindowID][u16NextReadPointer].u32PriData,_GetDIRingBufferAddr(u8WindowID,RES_DMSDI.u8DIRingBufferID),RES_DMS._stXC_DIPWriteReadPointer[u8WindowID].u16WritePointer);
1255                     if(_GetDIRingBufferAddr(u8WindowID,RES_DMSDI.u8DIRingBufferID) == tempAddr)
1256                     {
1257                         DMS_PRINTF("\033[1;31mDI hit showing buffer!! Addr 0x%llx, MainQ %d\033[0m\n",tempAddr,RES_DMS._stXC_DIPWriteReadPointer[u8WindowID].u16WritePointer);
1258                     }
1259 
1260                     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
1261                     //printf("\033[1;31m[%d] Write Ring Buffer %d, DIP start \033[0m\n",MsOS_GetSystemTime(),RES_DMSDI.u8DIRingBufferID);
1262                     // enable DIP
1263                     //MApi_XC_W2BYTEMSK(0x3460,0x0000,0x0001);
1264                     //MApi_XC_W2BYTEMSK(0x34D8,0x0000,0x0600);
1265                     _DMS_DIP_Fire(E_DMS_DIP_DI);
1266 
1267                     // Wait DIP write done
1268                     _DMS_DIP_WaitWriteDone(E_DMS_DIP_DI);
1269                     //printf("\033[1;31m[%d] Write Ring Buffer %d, DIP end \033[0m\n",MsOS_GetSystemTime(),RES_DMSDI.u8DIRingBufferID);
1270                     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
1271 
1272                     RES_DMSDI._stXC_DIPDIInfo[u8WindowID][u16NextReadPointer].bValid = FALSE;
1273                     if(gDMSDebug == 2)
1274                     {
1275                         DMS_PRINTF("\033[1;31m[%d] interlace Capture ID %d, Ring buffer ID %d\033[0m\n",MsOS_GetSystemTime(),RES_DMSDI.u8DIPReadytoCaptureIDInterlace[u8WindowID],RES_DMSDI.u8DIRingBufferID);
1276                         gDMSDebug++;
1277                     }
1278 
1279                     MApi_XC_DIP_Ena(FALSE,DIP_WINDOW);
1280 
1281                     MApi_XC_DIP_ReleaseResource(DIP_WINDOW);
1282 
1283                     if(RES_DMSDI._u8DMS_DiReleaseVDECFrameBufferID != DMS_Invalid_ReadPointer_ID &&
1284                         RES_DMSDI._u8DMS_DiReleaseVDECFrameBufferID != u16NextReadPointer)
1285                     {
1286                         _DMS_VDEC_Frame_Release_Interlace(u8WindowID,RES_DMSDI._u8DMS_DiReleaseVDECFrameBufferID);
1287                     }
1288                     RES_DMSDI._u8DMS_DiReleaseVDECFrameBufferID = u16NextReadPointer;
1289 
1290                     RES_DMSDI._stXC_DIPDIInfo[u8WindowID][u16NextReadPointer].bIsAfterDiTask = TRUE;
1291                     RES_DMSDI._stXC_DIPDIInfo[u8WindowID][u16NextReadPointer].u8DiOutputRingBufferID = RES_DMSDI.u8DIRingBufferID;
1292                     RES_DMSDI._stXC_DIPDIInfo[u8WindowID][u16NextReadPointer].eFmt = E_DMS_VIDEO_DATA_FMT_YUV422;
1293                     MS_U32 tempFrameIndex = RES_DMSDI._stXC_DIPDIInfo[u8WindowID][u16NextReadPointer].u32FrameIndex;
1294                     RES_DMSDI._stXC_DIPDIInfo[u8WindowID][u16NextReadPointer].u32FrameIndex = DMS_INVALID_FRAME_ID;
1295 
1296                     _DMS_StoreVDECInfo2DIPQueue(pInstance, &RES_DMSDI._stXC_DIPDIInfo[u8WindowID][u16NextReadPointer]);
1297                     RES_DMSDI._stXC_DIPDIInfo[u8WindowID][u16NextReadPointer].u32FrameIndex = tempFrameIndex;
1298                     di_sync_print("\033[1;35mDi W %d: 0x%x, 0x%llx , MainQ %d write done\033[0m\n",MsOS_GetSystemTime(),RES_DMSDI._stXC_DIPDIInfo[u8WindowID][u16NextReadPointer].u32PriData,_GetDIRingBufferAddr(u8WindowID,RES_DMSDI.u8DIRingBufferID),RES_DMS._stXC_DIPWriteReadPointer[u8WindowID].u16WritePointer);
1299                     if(i == 0 && bSetwinToDiTask)
1300                     {
1301                         _DMS_Add_XC_Status(u8WindowID, DMS_XC_RESET_WINDOW_SIZE);
1302                         RES_DMSDI._bSetwinToDiTask_DoubleBuffer = FALSE;
1303                     }
1304 
1305 #if DBG_FPS
1306                     u32FPS_Di_Counter[u8WindowID]++;
1307 #endif
1308                     if((RES_DMSDI._stXC_DIPDIInfo[u8WindowID][u16NextReadPointer].eFieldType == E_DMS_VIDEO_FIELD_TYPE_BOTH) &&
1309                         (RES_DMSDI._stXC_DIPDIInfo[u8WindowID][u16NextReadPointer].bIs2ndField == FALSE))
1310                     {
1311                         MS_U16 u16NextID = _GetNextBufferID(u16NextReadPointer);
1312                         if(RES_DMSDI._stXC_DIPDIInfo[u8WindowID][u16NextID].bValid == TRUE)
1313                         {
1314                             u16NextReadPointer = u16NextID;
1315                         }
1316                         else
1317                         {
1318                             DMS_PRINTF("!!!!![%s][%d] Error!! can not get 2nd field when VIDEO_FIELD_TYPE_BOTH\n",__FUNCTION__,__LINE__);
1319                         }
1320                     }
1321                 }
1322                 if((RES_DMSDI._stXC_DIPDIInfo[u8WindowID][u16NextReadPointer].eScanType == E_DMS_VIDEO_SCAN_TYPE_INTERLACE_FIELD) &&
1323                     (RES_DMSDI._stXC_DIPDIInfo[u8WindowID][u16NextReadPointer].bIs2ndField == FALSE))
1324                 {
1325                     MS_U16 u16NextID = _GetNextBufferID(u16NextReadPointer);
1326                     if(RES_DMSDI._stXC_DIPDIInfo[u8WindowID][u16NextID].bValid == TRUE)
1327                     {
1328                         u16NextReadPointer = u16NextID;
1329                     }
1330                     else
1331                     {
1332                         DMS_PRINTF("!!!!![%s][%d] Error!! can not get 2nd field when E_DMS_VIDEO_SCAN_TYPE_INTERLACE_FIELD\n",__FUNCTION__,__LINE__);
1333                     }
1334                 }
1335             }
1336             MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
1337         }
1338     }
1339     return TRUE;
1340 }
1341 #endif
1342 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
_DMS_StoreVDECInfo2DIPInterlaceQueue(DMS_VDECFRAME_INFO * VDECDispFrame)1343 static void _DMS_StoreVDECInfo2DIPInterlaceQueue(DMS_VDECFRAME_INFO *VDECDispFrame)
1344 {
1345     DMS_GET_RES_PRI;
1346     MS_U16 u16NextWritePointer = 0;
1347     MS_U32 u32Window = VDECDispFrame->u32Window;
1348 
1349     //Jump to Next Write Pointer
1350     u16NextWritePointer = _GetNextWritePointerInterlace(u32Window);
1351     //DMS_PRINTF("=====PUSH Frame=%d====",u16NextWritePointer);
1352 #if NEW_FLIP
1353     if(RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].bValid == TRUE)
1354     {
1355         //VDEC push too fast
1356         DMS_PRINTF("[%s] release frame for WP %d ring back\n",__FUNCTION__,u16NextWritePointer);
1357         _DMS_Clear_VDEC_Frame_Ref_Interlace(u32Window,u16NextWritePointer);
1358     }
1359     if(RES_DMSDI._stXC_LocalFrameRefCountInterlace[u32Window][u16NextWritePointer] > 0)
1360     {
1361         DMS_PRINTF("[%s] LocalFrameRefCount check ring back\n",__FUNCTION__);
1362         _DMS_Clear_VDEC_Frame_Ref_Interlace(u32Window,u16NextWritePointer);
1363     }
1364 #endif
1365     //DMS_PRINTF("[%s] push to Buffer %d\n",__FUNCTION__,u16NextWritePointer);
1366 
1367     if((VDECDispFrame->eScanType == E_DMS_VIDEO_SCAN_TYPE_INTERLACE_FIELD)
1368         && (VDECDispFrame->bIs2ndField == TRUE))
1369     {
1370         // New Flip
1371         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u32FrameIndex = VDECDispFrame->u32FrameIndex_2nd;
1372         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u32VDECStreamID = VDECDispFrame->u32VDECStreamID;
1373         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u32VDECStreamVersion = VDECDispFrame->u32VDECStreamVersion;
1374         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u32PriData = VDECDispFrame->u32PriData_2nd;
1375         _DMS_VDEC_Frame_AddRef_Interlace(u32Window,u16NextWritePointer);
1376 
1377         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].bValid = TRUE;
1378 
1379         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u16SrcWidth = VDECDispFrame->u16SrcWidth - VDECDispFrame->u16CropLeft - VDECDispFrame->u16CropRight;
1380         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u16SrcHeight = VDECDispFrame->u16SrcHeight - VDECDispFrame->u16CropTop - VDECDispFrame->u16CropBottom;
1381         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u16SrcPitch = VDECDispFrame->u16SrcPitch;
1382         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u32SrcLumaAddr = VDECDispFrame->u32SrcLumaAddrI;
1383         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u32SrcChromaAddr = VDECDispFrame->u32SrcChromaAddrI;
1384 
1385         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u32FrameRate = VDECDispFrame->u32FrameRate;
1386         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].eFmt = VDECDispFrame->eFmt;
1387         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u32Window = VDECDispFrame->u32Window;
1388         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].eCODEC = VDECDispFrame->eCODEC;
1389         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].eScanType = VDECDispFrame->eScanType;
1390         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].eFieldOrderType = VDECDispFrame->eFieldOrderType;
1391         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].eFieldType = VDECDispFrame->eFieldType_2nd;
1392         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].eTileMode = VDECDispFrame->eTileMode;
1393         // 10 bits
1394         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].b10bitData = VDECDispFrame->b10bitData;
1395         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u16Src10bitPitch = VDECDispFrame->u16Src10bitPitch;
1396         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u32SrcLumaAddr_2bit = VDECDispFrame->u32SrcLumaAddrI_2bit;
1397         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u32SrcChromaAddr_2bit = VDECDispFrame->u32SrcChromaAddrI_2bit;
1398         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u8LumaBitdepth = VDECDispFrame->u8LumaBitdepth;
1399 
1400         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].bIsAfterDiTask = VDECDispFrame->bIsAfterDiTask;
1401         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].bIs2ndField = VDECDispFrame->bIs2ndField;
1402         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u8DiOutputRingBufferID = VDECDispFrame->u8DiOutputRingBufferID;
1403     }
1404     else
1405     {
1406         // New Flip
1407         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u32FrameIndex = VDECDispFrame->u32FrameIndex;
1408         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u32VDECStreamID = VDECDispFrame->u32VDECStreamID;
1409         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u32VDECStreamVersion = VDECDispFrame->u32VDECStreamVersion;
1410         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u32PriData = VDECDispFrame->u32PriData;
1411         _DMS_VDEC_Frame_AddRef_Interlace(u32Window,u16NextWritePointer);
1412 
1413         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].bValid= TRUE;
1414 
1415         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u16SrcWidth = VDECDispFrame->u16SrcWidth - VDECDispFrame->u16CropLeft - VDECDispFrame->u16CropRight;
1416         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u16SrcHeight = VDECDispFrame->u16SrcHeight - VDECDispFrame->u16CropTop - VDECDispFrame->u16CropBottom;
1417         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u16SrcPitch = VDECDispFrame->u16SrcPitch;
1418         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u32SrcLumaAddr = VDECDispFrame->u32SrcLumaAddr;
1419         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u32SrcChromaAddr = VDECDispFrame->u32SrcChromaAddr;
1420 
1421         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u32FrameRate = VDECDispFrame->u32FrameRate;
1422         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].eFmt = VDECDispFrame->eFmt;
1423         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u32Window = VDECDispFrame->u32Window;
1424         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].eCODEC = VDECDispFrame->eCODEC;
1425         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].eScanType = VDECDispFrame->eScanType;
1426         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].eFieldOrderType = VDECDispFrame->eFieldOrderType;
1427         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].eFieldType = VDECDispFrame->eFieldType;
1428         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].eTileMode = VDECDispFrame->eTileMode;
1429         // 10 bits
1430         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].b10bitData = VDECDispFrame->b10bitData;
1431         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u16Src10bitPitch = VDECDispFrame->u16Src10bitPitch;
1432         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u32SrcLumaAddr_2bit = VDECDispFrame->u32SrcLumaAddr_2bit;
1433         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u32SrcChromaAddr_2bit = VDECDispFrame->u32SrcChromaAddr_2bit;
1434         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u8LumaBitdepth = VDECDispFrame->u8LumaBitdepth;
1435 
1436         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].bIsAfterDiTask = VDECDispFrame->bIsAfterDiTask;
1437         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].bIs2ndField = VDECDispFrame->bIs2ndField;
1438         RES_DMSDI._stXC_DIPDIInfo[u32Window][u16NextWritePointer].u8DiOutputRingBufferID = VDECDispFrame->u8DiOutputRingBufferID;
1439     }
1440     RES_DMSDI._stXC_DIPWriteReadPointerInterlace[u32Window].u16WritePointer = u16NextWritePointer;
1441 }
1442 #endif
1443 #endif //End of DEV_DI
1444 
_DMS_VDEC_Frame_AddRef(MS_U32 u32Window,MS_U16 u16BufID)1445 static MS_BOOL _DMS_VDEC_Frame_AddRef(MS_U32 u32Window, MS_U16 u16BufID)
1446 {
1447     DMS_GET_RES_PRI;
1448 #if NEW_FLIP
1449     if(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32FrameIndex == DMS_INVALID_FRAME_ID)
1450     {
1451         //DMS_PRINTF("[%s] window %d, BufID %d, Add an invalid buffer\n",__FUNCTION__,u32Window,u16BufID);
1452         return TRUE;
1453     }
1454 
1455     VDEC_StreamId VdecStreamId;
1456     VDEC_EX_DispFrame VdecDispFrm;
1457     VdecStreamId.u32Version = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32VDECStreamVersion;
1458     VdecStreamId.u32Id = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32VDECStreamID;
1459     VdecDispFrm.u32Idx = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32FrameIndex;
1460     VdecDispFrm.u32PriData = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32PriData;
1461     VDEC_EX_Result eResult;
1462     eResult = MApi_VDEC_EX_DisplayFrame((VDEC_StreamId*)&VdecStreamId, &VdecDispFrm);
1463     if (eResult != E_VDEC_EX_OK)
1464     {
1465         DMS_PRINTF("[%s] %td %td, %td %td\n",__FUNCTION__,(ptrdiff_t)VdecStreamId.u32Version,(ptrdiff_t)VdecStreamId.u32Id,
1466             (ptrdiff_t)VdecDispFrm.u32Idx,(ptrdiff_t)VdecDispFrm.u32PriData);
1467         DMS_PRINTF("[%s] window %td, BufID %d, MApi_VDEC_EX_DisplayFrame return %d\n",__FUNCTION__,(ptrdiff_t)u32Window,u16BufID,eResult);
1468         return FALSE;
1469     }
1470     if(_DMS_Is_SourceFieldBaseInterlace(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].eScanType))
1471     {
1472         VdecStreamId.u32Version = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32VDECStreamVersion;
1473         VdecStreamId.u32Id = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32VDECStreamID;
1474         VdecDispFrm.u32Idx = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32FrameIndex_2nd;
1475         VdecDispFrm.u32PriData = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32PriData_2nd;
1476         VDEC_EX_Result eResult;
1477         eResult = MApi_VDEC_EX_DisplayFrame((VDEC_StreamId*)&VdecStreamId, &VdecDispFrm);
1478         if (eResult != E_VDEC_EX_OK)
1479         {
1480             DMS_PRINTF("[%s] %td %td, %td %td\n",__FUNCTION__,(ptrdiff_t)VdecStreamId.u32Version,(ptrdiff_t)VdecStreamId.u32Id,
1481                 (ptrdiff_t)VdecDispFrm.u32Idx,(ptrdiff_t)VdecDispFrm.u32PriData);
1482             DMS_PRINTF("[%s] window %td, BufID %d, 2nd Field, MApi_VDEC_EX_DisplayFrame return %d\n",__FUNCTION__,(ptrdiff_t)u32Window,u16BufID,eResult);
1483             return FALSE;
1484         }
1485     }
1486     //DMS_PRINTF("[AddRef] Frame[0x%x], PriData[0x%x]\n",_stXC_DIPPushInfo[u32Window][u16BufID].u32FrameIndex,_stXC_DIPPushInfo[u32Window][u16BufID].u32PriData);
1487     RES_DMS._stXC_LocalFrameRefCount[u32Window][u16BufID]++;
1488 
1489 #if DBG_FPS
1490     u32FPS_Add_Counter[u32Window]++;
1491 #endif
1492 #endif
1493     return TRUE;
1494 }
1495 
_DMS_VDEC_Frame_Release(MS_U32 u32Window,MS_U16 u16BufID)1496 static MS_BOOL _DMS_VDEC_Frame_Release(MS_U32 u32Window, MS_U16 u16BufID)
1497 {
1498     DMS_GET_RES_PRI;
1499 #if NEW_FLIP
1500     if(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32FrameIndex == DMS_INVALID_FRAME_ID)
1501     {
1502         //DMS_PRINTF("[%s] window %d, BufID %d, Release an invalid buffer\n",__FUNCTION__,u32Window,u16BufID);
1503         return TRUE;
1504     }
1505     if(RES_DMS._stXC_LocalFrameRefCount[u32Window][u16BufID] == 0)
1506     {
1507         //DMS_PRINTF("[%s] window %d, BufID %d, Release an invalid buffer\n",__FUNCTION__,u32Window,u16BufID);
1508         return TRUE;
1509     }
1510     RES_DMS._stXC_LocalFrameRefCount[u32Window][u16BufID]--;
1511     if(RES_DMS._stXC_LocalFrameRefCount[u32Window][u16BufID] == 0)
1512     {
1513         VDEC_StreamId VdecStreamId;
1514         VDEC_EX_DispFrame VdecDispFrm;
1515         VdecStreamId.u32Version = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32VDECStreamVersion;
1516         VdecStreamId.u32Id = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32VDECStreamID;
1517         VdecDispFrm.u32Idx = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32FrameIndex;
1518         VdecDispFrm.u32PriData = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32PriData;
1519 
1520         VDEC_EX_Result eResult;
1521         eResult = MApi_VDEC_EX_ReleaseFrame((VDEC_StreamId *) &VdecStreamId, &VdecDispFrm);
1522         if (eResult != E_VDEC_EX_OK)
1523         {
1524             DMS_PRINTF("[%s] %td %td, %td %td\n",__FUNCTION__,(ptrdiff_t)VdecStreamId.u32Version,(ptrdiff_t)VdecStreamId.u32Id,
1525                 (ptrdiff_t)VdecDispFrm.u32Idx,(ptrdiff_t)VdecDispFrm.u32PriData);
1526             DMS_PRINTF("[%s] window %td, BufID %d, MApi_VDEC_EX_ReleaseFrame return %d\n",__FUNCTION__,(ptrdiff_t)u32Window,u16BufID,eResult);
1527             return FALSE;
1528         }
1529         if(_DMS_Is_SourceFieldBaseInterlace(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].eScanType))
1530         {
1531             VdecStreamId.u32Version = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32VDECStreamVersion;
1532             VdecStreamId.u32Id = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32VDECStreamID;
1533             VdecDispFrm.u32Idx = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32FrameIndex_2nd;
1534             VdecDispFrm.u32PriData = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32PriData_2nd;
1535 
1536             VDEC_EX_Result eResult;
1537             eResult = MApi_VDEC_EX_ReleaseFrame((VDEC_StreamId *) &VdecStreamId, &VdecDispFrm);
1538             if (eResult != E_VDEC_EX_OK)
1539             {
1540                 DMS_PRINTF("[%s] %td %td, %td %td\n",__FUNCTION__,(ptrdiff_t)VdecStreamId.u32Version,(ptrdiff_t)VdecStreamId.u32Id,
1541                     (ptrdiff_t)VdecDispFrm.u32Idx,(ptrdiff_t)VdecDispFrm.u32PriData);
1542                 DMS_PRINTF("[%s] window %td, BufID %d, 2nd Field, MApi_VDEC_EX_ReleaseFrame return %d\n",__FUNCTION__,(ptrdiff_t)u32Window,u16BufID,eResult);
1543                 return FALSE;
1544             }
1545         }
1546         //DMS_PRINTF("[Releas] Frame[0x%x], PriData[0x%x]\n",RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32FrameIndex,RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32PriData);
1547         if(_IsFrameRefCountZero(u32Window, u16BufID))
1548         {
1549             RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32FrameIndex = DMS_INVALID_FRAME_ID;
1550         }
1551     }
1552 
1553 #if DBG_FPS
1554     u32FPS_Release_Counter[u32Window]++;
1555 #endif
1556 #endif
1557     return TRUE;
1558 }
1559 
1560 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 0)
_DMS_SetMVOPTileMode(E_DMS_VIDEO_TILE_MODE eTile)1561 static MVOP_TileFormat _DMS_SetMVOPTileMode(E_DMS_VIDEO_TILE_MODE eTile)
1562 {
1563     MS_U32 u32TileMode = 0;
1564 
1565     switch(eTile)
1566     {
1567         case E_DMS_VIDEO_TILE_MODE_16x32:
1568         {
1569             u32TileMode = 1;
1570             break;
1571         }
1572         case E_DMS_VIDEO_TILE_MODE_NONE:
1573         {
1574             u32TileMode = 2;
1575             break;
1576         }
1577         case E_DMS_VIDEO_TILE_MODE_32x16:
1578         {
1579             u32TileMode = 3;
1580             break;
1581         }
1582         case E_DMS_VIDEO_TILE_MODE_32x32:
1583         {
1584             u32TileMode = 4;
1585             break;
1586         }
1587         default:
1588         {
1589             printf("\033[031m[%s:%d]WARNING: NOT surport tile mode:%d\033[0m\n",__FUNCTION__, __LINE__, eTile);
1590         }
1591     }
1592     return u32TileMode;
1593 }
1594 
_DMS_Is422Mode(E_DMS_VIDEO_DATA_FMT eFmt)1595 static MS_BOOL _DMS_Is422Mode(E_DMS_VIDEO_DATA_FMT eFmt)
1596 {
1597     MS_BOOL ret = 0;
1598     switch(eFmt)
1599     {
1600         case E_DMS_VIDEO_DATA_FMT_YUV420:
1601         case E_DMS_VIDEO_DATA_FMT_YUV420_H265:
1602         case E_DMS_VIDEO_DATA_FMT_YUV420_H265_10BITS:
1603         case E_DMS_VIDEO_DATA_FMT_YUV420_PLANER:
1604         case E_DMS_VIDEO_DATA_FMT_YUV420_SEMI_PLANER:
1605         {
1606             ret = 0;
1607             break;
1608         }
1609         default:
1610         {
1611             ret = 1;
1612             break;
1613         }
1614     }
1615     return ret;
1616 }
1617 
_DMS_GetColorFormat(EN_DMS_COLORFORMAT eColorFormat)1618 static E_DMS_VIDEO_DATA_FMT _DMS_GetColorFormat(EN_DMS_COLORFORMAT eColorFormat)
1619 {
1620     MS_U32 u32ColorFormat = 0;
1621 
1622     switch(eColorFormat)
1623     {
1624         case E_DMS_COLOR_FORMAT_HW_HVD:
1625         case E_DMS_COLOR_FORMAT_HW_MVD:
1626         {
1627             u32ColorFormat = E_DMS_VIDEO_DATA_FMT_YUV420;
1628             break;
1629         }
1630         case E_DMS_COLOR_FORMAT_SW_RGB565:
1631         {
1632             u32ColorFormat = E_DMS_VIDEO_DATA_FMT_RGB565;
1633             break;
1634         }
1635         case E_DMS_COLOR_FORMAT_SW_ARGB8888:
1636         {
1637             u32ColorFormat = E_DMS_VIDEO_DATA_FMT_ARGB8888;
1638             break;
1639         }
1640         case E_DMS_COLOR_FORMAT_YUYV:
1641         {
1642             u32ColorFormat = E_DMS_VIDEO_DATA_FMT_YUV422;
1643             break;
1644         }
1645         case E_DMS_COLOR_FORMAT_10BIT_TILE:
1646         {
1647             u32ColorFormat = E_DMS_VIDEO_DATA_FMT_YUV420_H265_10BITS;
1648             break;
1649         }
1650         case E_DMS_COLOR_FORMAT_SW_YUV420_SEMIPLANAR:
1651         {
1652             u32ColorFormat = E_DMS_VIDEO_DATA_FMT_YUV420_SEMI_PLANER;
1653             break;
1654         }
1655         case E_DMS_COLOR_FORMAT_HW_EVD:
1656         {
1657             u32ColorFormat = E_DMS_VIDEO_DATA_FMT_YUV420_H265;
1658             break;
1659         }
1660         default:
1661         {
1662             u32ColorFormat = E_DMS_VIDEO_DATA_FMT_MAX;
1663             printf("\033[031m[%s:%d]WARNING:DMS NOT SURPPORT color format:%d\033[0m\n",__FUNCTION__, __LINE__, eColorFormat);
1664             break;
1665         }
1666     }
1667     return u32ColorFormat;
1668 }
1669 
_DMS_Is_SourceFieldBaseInterlaceBottom(E_DMS_VIDEO_SCAN_TYPE eScanType,MS_BOOL bIsVdecBot)1670 static MS_BOOL _DMS_Is_SourceFieldBaseInterlaceBottom(E_DMS_VIDEO_SCAN_TYPE eScanType, MS_BOOL bIsVdecBot)
1671 {
1672     if(_DMS_Is_SourceFieldBaseInterlace(eScanType) && bIsVdecBot)
1673     {
1674         return TRUE;
1675     }
1676     else
1677     {
1678         return FALSE;
1679     }
1680 }
_Task_DMS_DisableBob_MainWin(void)1681 static void _Task_DMS_DisableBob_MainWin(void)
1682 {
1683     void *pInstance = pTaskInstance;
1684     MS_U32 u32WaitEventFlag = BIT(0);
1685     MS_U32 u32Events = 0;
1686     MS_U32 u32BobDelay = 0;
1687     MS_U16 u16RP = 0;
1688     MS_U8 u8XCFrameNum = 0;
1689     VDEC_StreamId stVDEC_StreamId = {0};
1690 
1691     // coverity[no_escape]
1692     while(1)
1693     {
1694         MsOS_WaitEvent(s32DisableBob_Event_id, u32WaitEventFlag, &u32Events, E_OR_CLEAR, MSOS_WAIT_FOREVER);
1695         MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
1696         DMS_GET_RES_PRI;
1697 
1698         u16RP = RES_DMS._stXC_DIPWriteReadPointer[MVOP_WINDOW].u16ReadPointer;
1699         stVDEC_StreamId.u32Version = RES_DMS._stXC_DIPPushInfo[MAIN_WINDOW][u16RP].u32VDECStreamVersion;
1700         stVDEC_StreamId.u32Id = RES_DMS._stXC_DIPPushInfo[MAIN_WINDOW][u16RP].u32VDECStreamID;
1701 
1702         u8XCFrameNum = MApi_XC_Get_FrameNumFactor(MAIN_WINDOW);
1703 
1704         if(u32BobDelay == u8XCFrameNum)
1705         {
1706             MApi_XC_SetBOBMode(FALSE, MAIN_WINDOW);
1707             RES_DMS.bXCEnableBob = FALSE;
1708             u32BobDelay = 0;
1709         }
1710         u32BobDelay++;
1711         MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
1712     }
1713 }
1714 
_Task_DMS_SetMVOP(void)1715 static void _Task_DMS_SetMVOP(void)
1716 {
1717     MS_U32 u32WaitEventFlag = BIT(0);
1718     MS_U32 u32Events = 0;
1719     void *pInstance = pTaskInstance;
1720     MS_BOOL bVdecTBflag = 0;
1721     MS_BOOL bMVOP_FDMask = FALSE;
1722     MS_BOOL bIsPause = FALSE;
1723     MS_BOOL bPauseIsBot = 0;
1724     MS_U32 u32CurReadPointer = 0;
1725     MS_U32 u32mfdecMiuSel = 0;
1726     MS_U32 i = 0;
1727     MS_U8 u8XCFrameNum = 0;
1728     MS_BOOL bXC_BobMode = FALSE;
1729 
1730 
1731     MVOP_Handle stHd = {E_MVOP_MODULE_MAIN};
1732     MVOP_Result ret = E_MVOP_FAIL;
1733     MVOP_DMSStreamINFO stMVOPStreamInfo;
1734     MVOP_DMSDisplaySize stMVOPDispSize;
1735     MVOP_DMSCropINFO stMVOPCropInfo;
1736     MVOP_DMSDisplayADD stMVOPDispAddr;
1737 
1738     memset(&stMVOPStreamInfo, 0, sizeof(MVOP_DMSStreamINFO));
1739     memset(&stMVOPDispSize, 0, sizeof(MVOP_DMSDisplaySize));
1740     memset(&stMVOPCropInfo, 0, sizeof(MVOP_DMSCropINFO));
1741     memset(&stMVOPDispAddr, 0, sizeof(MVOP_DMSDisplayADD));
1742 
1743     // coverity[no_escape]
1744     while(1)
1745     {
1746         MsOS_WaitEvent(s32MVOP_Event_id, u32WaitEventFlag, &u32Events, E_OR_CLEAR, MSOS_WAIT_FOREVER);
1747         MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
1748         DMS_GET_RES_PRI;
1749 
1750 
1751         for(i = 0; i<DMS_DIP_QUEUEDEPTH ; i++)
1752         {
1753             if(RES_DMS.u32ReleaseState[i] >= 2)
1754             {
1755                  _DMS_VDEC_Frame_Release(MVOP_WINDOW, i);
1756                  RES_DMS.u32ReleaseState[i] = 0;
1757                  RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][i].bValid = FALSE;
1758             }
1759         }
1760 
1761         // make sure: 1. at least one frame is processed 2. DMS_SetMute is called.
1762         // than start MuteCounter
1763         u8XCFrameNum = MApi_XC_Get_FrameNumFactor(MAIN_WINDOW);
1764         if((RES_DMS.u32ReleaseState[RES_DMS._stXC_DIPWriteReadPointer[MVOP_WINDOW].u16ReadPointer] >=1) && RES_DMS.bDisableBlackScreen)
1765         {
1766             RES_DMS.u32MuteCounter++;
1767             if(RES_DMS.u32MuteCounter == u8XCFrameNum)
1768             {
1769                 if(RES_DMS.bFirstPlay)
1770                 {
1771                    RES_DMS.bDisableBlackScreen = FALSE;
1772                    RES_DMS.bFirstPlay = FALSE;
1773                    MApi_XC_GenerateBlackVideoByMode(FALSE, MAIN_WINDOW,E_XC_BLACK_VIDEO_MEMSYNC);
1774                 }
1775             }
1776         }
1777 
1778         // prevent from read ponter go through write pointer
1779         if(RES_DMS._stXC_DIPWriteReadPointer[MVOP_WINDOW].u16ReadPointer == RES_DMS._stXC_DIPWriteReadPointer[MVOP_WINDOW].u16WritePointer)
1780         {
1781            // pause: set FDmask to TRUE
1782             if(_DMS_Is_SourceInterlace(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][(RES_DMS._stXC_DIPWriteReadPointer[MVOP_WINDOW].u16ReadPointer)].eScanType) && (RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS._stXC_DIPWriteReadPointer[MVOP_WINDOW].u16ReadPointer].u8FieldCtrl == 0))
1783             {
1784                 bIsPause = TRUE;
1785                 stMVOPDispAddr.u8BotFlag = (RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS._stXC_DIPWriteReadPointer[MVOP_WINDOW].u16ReadPointer].eFieldOrderType^1);
1786                 bPauseIsBot = stMVOPDispAddr.u8BotFlag;
1787                 stMVOPDispAddr.u8FDMask = TRUE;
1788                 ret = MDrv_MVOP_DMS_SetDispADDInfo(&stHd, E_MVOP_MAIN_WIN, &stMVOPDispAddr, NULL);
1789                 if(ret != 0)
1790                 {
1791                     DMS_PRINTF("\033[031m[%s:%d]MDrv_MVOP_DMS_SetDispADDInfo fail: %d\033[0m\n",__FUNCTION__, __LINE__, ret);
1792                 }
1793             }
1794             MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
1795             continue;
1796         }
1797 
1798         if(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][((RES_DMS._stXC_DIPWriteReadPointer[MVOP_WINDOW].u16ReadPointer+1)%DMS_DIP_QUEUEDEPTH)].eScanType == E_DMS_VIDEO_SCAN_TYPE_PROGRESSIVE)
1799         {
1800             _DMS_GetNextInfo(MVOP_WINDOW, FALSE);
1801             u32CurReadPointer = RES_DMS._stXC_DIPWriteReadPointer[MVOP_WINDOW].u16ReadPointer;
1802         }
1803         else
1804         {
1805             //Issue: Progressive data after FRC jump to interlace frame, and break while by continue due to interlace flag not match
1806             //Next round u16ReadPointer will be plus one cause previous one data not be process
1807 
1808             //Solution: Make sure every interlace data must be process, check condition as below:
1809             //Once u16ReadPointer's data is valid  &&  u32ReleaseState ==0, not to update u16ReadPointer
1810             if((RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS._stXC_DIPWriteReadPointer[MVOP_WINDOW].u16ReadPointer].bValid == FALSE) || (RES_DMS.u32ReleaseState[RES_DMS._stXC_DIPWriteReadPointer[MVOP_WINDOW].u16ReadPointer] >= 1))
1811             {
1812                u32CurReadPointer = _GetNextBufferID(RES_DMS._stXC_DIPWriteReadPointer[MVOP_WINDOW].u16ReadPointer);
1813             }
1814         }
1815 
1816         if((RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].bValid == TRUE) && (RES_DMS.u32ReleaseState[u32CurReadPointer] == 0))
1817         {
1818             if(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].eScanType == E_DMS_VIDEO_SCAN_TYPE_PROGRESSIVE)
1819             {
1820                 if(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].b10bitData)
1821                 {
1822                     stMVOPDispAddr.u32LSB_FB_ADDR[0] = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcLumaAddr_2bit;
1823                     stMVOPDispAddr.u32LSB_FB_ADDR[1] = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcChromaAddr_2bit;
1824                     stMVOPDispAddr.u32LSB_FB_MIU[0] = (RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcLumaAddr_2bit >= HAL_MIU1_BASE)?1:0 ;
1825                     stMVOPDispAddr.u32LSB_FB_MIU[1] = (RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcChromaAddr_2bit >= HAL_MIU1_BASE)?1:0;
1826                     stMVOPDispAddr.u32BIT_DEPTH[0] = 10;
1827                     stMVOPDispAddr.u32BIT_DEPTH[1] = 10;
1828                 }
1829                 else
1830                 {
1831                     stMVOPDispAddr.u32BIT_DEPTH[0] = 8;
1832                     stMVOPDispAddr.u32BIT_DEPTH[1] = 8;
1833 
1834                 }
1835                 stMVOPDispAddr.u32MSB_FB_ADDR[0] = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcLumaAddr;
1836                 stMVOPDispAddr.u32MSB_FB_ADDR[1] = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcChromaAddr;
1837                 stMVOPDispAddr.u8DMSB_FB_MIU[0] = (RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcLumaAddr >= HAL_MIU1_BASE)? 1:0;
1838                 stMVOPDispAddr.u8DMSB_FB_MIU[1] = (RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcChromaAddr >= HAL_MIU1_BASE)? 1:0;
1839                 if(_DMS_Is_ScalingConditionUse2ndBuffer(RES_DMS.gDMS_ScalingCondition))
1840                 {
1841                     stMVOPDispAddr.u32MSB_FB_ADDR[0] = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].phySrc2ndBufferLumaAddr;
1842                     stMVOPDispAddr.u32MSB_FB_ADDR[1] = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].phySrc2ndBufferChromaAddr;
1843                     stMVOPDispAddr.u32BIT_DEPTH[0] = 8;
1844                     stMVOPDispAddr.u32BIT_DEPTH[1] = 8;
1845                 }
1846                 stMVOPDispAddr.bOutputIMode = 0;
1847             }
1848             else if(_DMS_Is_SourceInterlace(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].eScanType))
1849             {
1850                 if(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].bIs2ndField)
1851                 {
1852                     bVdecTBflag = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].eFieldOrderType;
1853                 }
1854                 else
1855                 {
1856                     bVdecTBflag = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].eFieldOrderType ^ 0x0001;
1857                 }
1858 
1859                 // resume
1860                 if(bIsPause)
1861                 {
1862                     if(bVdecTBflag == bPauseIsBot)
1863                     {
1864                         bMVOP_FDMask = FALSE;
1865                         bIsPause = FALSE;
1866                     }
1867                     else
1868                     {
1869                         bMVOP_FDMask = TRUE;
1870                     }
1871                 }
1872 
1873                 if(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u8FieldCtrl)  // ff , rw
1874                 {
1875                     RES_DMS.bXCEnableBob = TRUE;
1876                     if(bVdecTBflag == (RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].eFieldOrderType^ 0x0001))
1877                     {
1878                          bMVOP_FDMask = FALSE;
1879                     }
1880                     else
1881                     {
1882                          bMVOP_FDMask = TRUE;
1883                     }
1884 
1885                     if(bXC_BobMode)
1886                     {
1887                         MApi_XC_SetBOBMode(TRUE, MAIN_WINDOW);
1888                     }
1889                     bXC_BobMode = TRUE;
1890 
1891                     bVdecTBflag =  (RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].eFieldOrderType^ 0x0001);
1892 
1893                 }
1894                 else
1895                 {
1896                      if(RES_DMS.bXCEnableBob)
1897                      {
1898                         bMVOP_FDMask = FALSE;
1899                         bXC_BobMode = FALSE;
1900                         MsOS_SetEvent(s32DisableBob_Event_id, 0x01);
1901                      }
1902                 }
1903 
1904                 if(_DMS_Is_SourceFieldBaseInterlaceBottom(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].eScanType, bVdecTBflag))
1905                 {
1906                      if(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].b10bitData)
1907                      {
1908                          stMVOPDispAddr.u32LSB_FB_ADDR[0] = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcLumaAddrI_2bit;
1909                          stMVOPDispAddr.u32LSB_FB_ADDR[1] = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcChromaAddrI_2bit;
1910                          stMVOPDispAddr.u32LSB_FB_MIU[0] = (RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcLumaAddrI_2bit >= HAL_MIU1_BASE)?1:0 ;
1911                          stMVOPDispAddr.u32LSB_FB_MIU[1] = (RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcChromaAddrI_2bit >= HAL_MIU1_BASE)?1:0;
1912                          stMVOPDispAddr.u32BIT_DEPTH[0] = 10;
1913                          stMVOPDispAddr.u32BIT_DEPTH[1] = 10;
1914                      }
1915                      else
1916                      {
1917                          stMVOPDispAddr.u32BIT_DEPTH[0] = 8;
1918                          stMVOPDispAddr.u32BIT_DEPTH[1] = 8;
1919                      }
1920 
1921                      stMVOPDispAddr.u32MSB_FB_ADDR[0] = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcLumaAddrI;
1922                      stMVOPDispAddr.u32MSB_FB_ADDR[1] = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcChromaAddrI;
1923                      stMVOPDispAddr.u8DMSB_FB_MIU[0] = (RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcLumaAddrI >= HAL_MIU1_BASE)? 1:0;
1924                      stMVOPDispAddr.u8DMSB_FB_MIU[1] = (RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcChromaAddrI >= HAL_MIU1_BASE)? 1:0;
1925 
1926                }
1927                else
1928                {
1929                     if(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].b10bitData)
1930                     {
1931                         stMVOPDispAddr.u32LSB_FB_ADDR[0] = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcLumaAddr_2bit;
1932                         stMVOPDispAddr.u32LSB_FB_ADDR[1] = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcChromaAddr_2bit;
1933                         stMVOPDispAddr.u32LSB_FB_MIU[0] = (RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcLumaAddr_2bit >= HAL_MIU1_BASE)?1:0 ;
1934                         stMVOPDispAddr.u32LSB_FB_MIU[1] = (RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcChromaAddr_2bit >= HAL_MIU1_BASE)?1:0 ;
1935                         stMVOPDispAddr.u32BIT_DEPTH[0] = 10;
1936                         stMVOPDispAddr.u32BIT_DEPTH[1] = 10;
1937                     }
1938                     else
1939                     {
1940                          stMVOPDispAddr.u32BIT_DEPTH[0] = 8;
1941                          stMVOPDispAddr.u32BIT_DEPTH[1] = 8;
1942                      }
1943 
1944                      stMVOPDispAddr.u32MSB_FB_ADDR[0] = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcLumaAddr;
1945                      stMVOPDispAddr.u32MSB_FB_ADDR[1] = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcChromaAddr;
1946                      stMVOPDispAddr.u8DMSB_FB_MIU[0] = (RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcLumaAddr >= HAL_MIU1_BASE)? 1:0;
1947                      stMVOPDispAddr.u8DMSB_FB_MIU[1] = (RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u32SrcChromaAddr >= HAL_MIU1_BASE)? 1:0;
1948                }
1949                stMVOPDispAddr.bOutputIMode = 1;
1950                stMVOPDispAddr.u8BotFlag = bVdecTBflag;
1951             }
1952             else
1953             {
1954                 DMS_PRINTF("\033[031m[%s:%d]Error: undefine scanType:%d\033[0m\n",__FUNCTION__, __LINE__, RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].eScanType);
1955             }
1956             // MVOP StreamInfo
1957             stMVOPStreamInfo.u32ApiDMSStream_Version = API_MVOP_DMS_STREAM_VERSION;
1958             stMVOPStreamInfo.u16ApiDMSStream_Length = sizeof(MVOP_DMSStreamINFO);
1959             stMVOPStreamInfo.eTileFormat = _DMS_SetMVOPTileMode(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].eTileMode);
1960             stMVOPStreamInfo.bIs422Mode = _DMS_Is422Mode(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].eFmt);
1961             stMVOPStreamInfo.bIsDRAMCont = (stMVOPStreamInfo.bIs422Mode == TRUE)? TRUE : FALSE;
1962             stMVOPStreamInfo.bDDR4_REMAP = 0;
1963             if(_DMS_Is_ScalingConditionUse2ndBuffer(RES_DMS.gDMS_ScalingCondition))
1964             {
1965                  stMVOPStreamInfo.eTileFormat = _DMS_SetMVOPTileMode(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u8Src2ndBufferTileMode);
1966             }
1967             // MVOP DispSizeInfo
1968             stMVOPDispSize.u32ApiDMSSize_Version = API_MVOP_DMS_DISP_SIZE_VERSION;
1969             stMVOPDispSize.u16ApiDMSSize_Length = sizeof(MVOP_DMSDisplaySize);
1970             stMVOPDispSize.u16Width = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u16SrcWidth;
1971             stMVOPDispSize.u16Height = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u16SrcHeight;
1972             if(_DMS_Is_ScalingConditionUse2ndBuffer(RES_DMS.gDMS_ScalingCondition))
1973             {
1974                 stMVOPDispSize.u16Pitch[0] = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u16Src2ndBufferPitch;
1975                 stMVOPDispSize.u16Width = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u16Src2ndBufferWidth ;
1976                 stMVOPDispSize.u16Height = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u16Src2ndBufferHeight ;
1977             }
1978             else
1979             {
1980                 stMVOPDispSize.u16Pitch[0] = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u16SrcPitch;
1981             }
1982             if(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].b10bitData)
1983             {
1984                 stMVOPDispSize.u16Pitch[1] = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].u16Src10bitPitch;
1985             }
1986             stMVOPDispSize.U8DSIndex = 0xff;
1987             stMVOPDispSize.bDualDV_EN = 0;
1988             stMVOPDispSize.bHDup = 0;
1989             stMVOPDispSize.bVDup = 0;
1990 
1991             // MVOP SetDispADDInfo
1992             stMVOPDispAddr.u32ApiDMSADD_Version = API_MVOP_DMS_DIPS_ADD_VERSION;
1993             stMVOPDispAddr.u16ApiDMSADD_Length = sizeof(MVOP_DMSDisplayADD);
1994             stMVOPDispAddr.u8FRAME_ID = 0;  // no use
1995             if(_DMS_Is_ScalingConditionUse2ndBuffer(RES_DMS.gDMS_ScalingCondition))
1996             {
1997                 RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].stMFdecInfo.bMFDec_Enable = 0;
1998             }
1999             stMVOPDispAddr.bMFDEC_EN = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].stMFdecInfo.bMFDec_Enable;
2000             stMVOPDispAddr.u8MFDEC_ID = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].stMFdecInfo.u8MFDec_Select;
2001             stMVOPDispAddr.u32UNCOMPRESS_MODE = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].stMFdecInfo.bUncompress_mode;
2002             stMVOPDispAddr.u32BITLEN_FB_ADDR = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].stMFdecInfo.phyBitlen_Base;
2003             if(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].stMFdecInfo.phyBitlen_Base >= HAL_MIU1_BASE)
2004             {
2005                 u32mfdecMiuSel = 1;
2006             }
2007             else
2008             {
2009                 u32mfdecMiuSel = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].stMFdecInfo.u8Bitlen_MiuSelect;
2010             }
2011             stMVOPDispAddr.u8BITLEN_FB_MIU = u32mfdecMiuSel;
2012             stMVOPDispAddr.u32BITLEN_FB_PITCH = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u32CurReadPointer].stMFdecInfo.u16Bitlen_Pitch;
2013             stMVOPDispAddr.bEN3D = 0;
2014             stMVOPDispAddr.u8FDMask = bMVOP_FDMask;
2015             stMVOPDispAddr.bXCBOB_EN = 0;
2016 
2017             ret = MDrv_MVOP_DMS_SetDispSizeInfo(&stHd, E_MVOP_MAIN_WIN, &stMVOPDispSize, NULL);
2018             if(ret != 0)
2019             {
2020                 DMS_PRINTF("\033[031m[%s:%d]MDrv_MVOP_DMS_SetDispSizeInfo fail: %d\033[0m\n",__FUNCTION__, __LINE__, ret);
2021             }
2022             ret = MDrv_MVOP_DMS_SetStreamInfo(&stHd, E_MVOP_MAIN_WIN, &stMVOPStreamInfo, NULL);
2023             if(ret != 0)
2024             {
2025                 DMS_PRINTF("\033[031m[%s:%d]MDrv_MVOP_DMS_SetStreamInfo fail: %d\033[0m\n",__FUNCTION__, __LINE__, ret);
2026             }
2027             ret = MDrv_MVOP_DMS_SetDispADDInfo(&stHd, E_MVOP_MAIN_WIN, &stMVOPDispAddr, NULL);
2028             if(ret != 0)
2029             {
2030                 DMS_PRINTF("\033[031m[%s:%d]MDrv_MVOP_DMS_SetDispADDInfo fail: %d\033[0m\n",__FUNCTION__, __LINE__, ret);
2031             }
2032 
2033             for(i = 0; i<DMS_DIP_QUEUEDEPTH ; i++)
2034             {
2035                 if(RES_DMS.u32ReleaseState[i] >= 1)
2036                 {
2037                      RES_DMS.u32ReleaseState[i]++;
2038                 }
2039             }
2040             RES_DMS.u32ReleaseState[u32CurReadPointer]++;
2041             RES_DMS._stXC_DIPWriteReadPointer[MVOP_WINDOW].u16ReadPointer = u32CurReadPointer;
2042          } //if
2043          MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
2044     }// while(1)
2045 }
2046 
2047 
_DMS_MVOP_ISR(void)2048  static void _DMS_MVOP_ISR(void)
2049 {
2050     MDrv_MVOP_EnableInterrupt(E_MVOP_INT_NONE);
2051     MsOS_SetEvent(s32MVOP_Event_id, 0x01);
2052     MDrv_MVOP_EnableInterrupt(E_MVOP_INT_VSYNC);
2053     MsOS_EnableInterrupt(E_INT_IRQ_DC);
2054 }
2055 
2056 #endif // DMS_MAIN_WINDOW_FLOW_VERSION == 0
2057 
_IsGwinAvailable(void)2058 static MS_BOOL _IsGwinAvailable(void)
2059 {
2060     DMS_GET_RES_PRI;
2061     if(RES_DMS.u8GOPGWinNum == GWIN_NO_AVAILABLE)
2062     {
2063         return FALSE;
2064     }
2065     else
2066     {
2067         return TRUE;
2068     }
2069 }
2070 
_DMS_IsWindowUsed(MS_U32 u32Window)2071 static MS_BOOL _DMS_IsWindowUsed (MS_U32 u32Window)
2072 {
2073     DMS_GET_RES_PRI;
2074     return RES_DMS._stXC_DIPWinInfo[u32Window].bDIPwinUse;
2075 }
2076 
_DMS_IsCaptureWindowEnable(MS_U32 u32Window)2077 static MS_BOOL _DMS_IsCaptureWindowEnable (MS_U32 u32Window)
2078 {
2079     DMS_GET_RES_PRI;
2080     return RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32Enable;
2081 }
2082 
_GetPreviousWritePointer(MS_U32 u32Window)2083 static MS_U16 _GetPreviousWritePointer(MS_U32 u32Window)
2084 {
2085     DMS_GET_RES_PRI;
2086     return _GetPreviousBufferID(RES_DMS._stXC_DIPWriteReadPointer[u32Window].u16WritePointer);
2087 }
2088 
_GetNextWritePointer(MS_U32 u32Window)2089 static MS_U16 _GetNextWritePointer(MS_U32 u32Window)
2090 {
2091     DMS_GET_RES_PRI;
2092     return _GetNextBufferID(RES_DMS._stXC_DIPWriteReadPointer[u32Window].u16WritePointer);
2093 }
2094 
2095 //For RP always Read (WP-1) principle, need marked valid false for drop case
2096 //         W
2097 //  o  x  v  o  o  o  o
2098 //     R
2099 //===next phase===
2100 //                  W
2101 //  o  x  x  x  x  v  o
2102 //        R'      R
2103 
_MarkIgnorableReadBuffer(MS_U32 u32Window,MS_U16 u16TargetID)2104 static void _MarkIgnorableReadBuffer(MS_U32 u32Window, MS_U16 u16TargetID)
2105 {
2106     DMS_GET_RES_PRI;
2107     MS_U16 u16CurID = RES_DMS._stXC_DIPWriteReadPointer[u32Window].u16ReadPointer;
2108     sync_print("MarkIg From%d to %d => ",u16CurID,u16TargetID);
2109     while (u16CurID != u16TargetID)
2110     {
2111         if(_DMS_Is_MVOPFlow(u32Window) && (RES_DMS.eDMS_MVOPFlowCtrl == E_DMS_MVOP_FLOW_FROM_VDEC))
2112         {
2113 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 0)
2114             if(u16CurID != RES_DMS._stXC_DIPWriteReadPointer[MVOP_WINDOW].u16ReadPointer)
2115 #else
2116             if(u16CurID != RES_DMS.gDMS_MVOPShowBufferID && u16CurID != RES_DMS.gDMS_MVOPRemoveBufferID)
2117 #endif
2118             {
2119                 _DMS_VDEC_Frame_Release(u32Window,u16CurID);
2120                 RES_DMS._stXC_DIPPushInfo[u32Window][u16CurID].bValid = FALSE;
2121 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 0)
2122                 RES_DMS.u32ReleaseState[u16CurID] = 0;
2123 #endif
2124                 sync_print("MarkIg ID%d => ",u16CurID);
2125             }
2126         }
2127         else
2128         {
2129 #if(DEV_NEW_NEXT == 0)
2130             MS_BOOL bOriginFrame = TRUE;
2131             if(bOriginFrame == TRUE)
2132             {
2133                 bOriginFrame = FALSE;
2134             }
2135             else
2136 #endif
2137             {
2138                 _DMS_VDEC_Frame_Release(u32Window,u16CurID);
2139                 RES_DMS._stXC_DIPPushInfo[u32Window][u16CurID].bValid = FALSE;
2140             }
2141             //sync_print("MarkIg ID%d => ",u16CurID);
2142         }
2143         u16CurID = _GetNextBufferID(u16CurID);
2144     }
2145 
2146 }
2147 
2148 //Get Nex Read Pointer and check if any buffer could be ignored
2149 #define nrp_sync_print(fmt, args...) do { if(0) DMS_PRINTF(fmt, ##args);  } while (0)
_GetNextReadPointer(MS_U32 u32Window)2150 static MS_U16 _GetNextReadPointer(MS_U32 u32Window)
2151 {
2152     DMS_GET_RES_PRI;
2153     MS_U16 u16NextID = 0;
2154     MS_BOOL bFrameBaseFlag = FALSE;
2155     if(_DMS_Is_MVOPFlow(u32Window))
2156     {
2157         sync_print("0.WP %d => ",RES_DMS._stXC_DIPWriteReadPointer[u32Window].u16WritePointer);
2158         if(RES_DMS.eDMS_MVOPFlowCtrl == E_DMS_MVOP_FLOW_FROM_VDEC)
2159         {
2160             u16NextID = RES_DMS._stXC_DIPWriteReadPointer[u32Window].u16WritePointer;
2161         }
2162 #if DEV_DI
2163         else if(DEV_DI_TIMER == 0 && (RES_DMS._stXC_DIPPushInfo[u32Window][RES_DMS._stXC_DIPWriteReadPointer[u32Window].u16WritePointer].bIsAfterDiTask == TRUE))
2164         {
2165             MS_U16 u16CurID = RES_DMS._stXC_DIPWriteReadPointer[u32Window].u16ReadPointer;
2166             MS_U16 u16WP = RES_DMS._stXC_DIPWriteReadPointer[u32Window].u16WritePointer;
2167             if(RES_DMS._stXC_DIPPushInfo[u32Window][u16WP].eFieldType == E_DMS_VIDEO_FIELD_TYPE_BOTH)
2168             {
2169                 nrp_sync_print("[%td] Cur %d, WP %d, ",(ptrdiff_t)MsOS_GetSystemTime(),u16CurID,u16WP);
2170                 static MS_U16 bForceBFlag = DMS_Invalid_ReadPointer_ID;
2171                 MS_BOOL b2ndField = RES_DMS._stXC_DIPPushInfo[u32Window][u16WP].bIs2ndField;
2172                 {
2173                     if(b2ndField == FALSE)
2174                     {
2175                         //Get a top field
2176                         if(bForceBFlag != DMS_Invalid_ReadPointer_ID)
2177                         {
2178                             if(bForceBFlag == u16WP)
2179                             {
2180                                 u16NextID = _GetNextBufferID(u16CurID);
2181                                 bFrameBaseFlag = TRUE;
2182                                 nrp_sync_print("w_T_force_B.NRP %d => ",u16NextID);
2183                             }
2184                             else
2185                             {
2186                                 u16NextID = u16WP;
2187                                 nrp_sync_print("w_T_NewTo_%d.NRP %d => ",b2ndField,u16NextID);
2188                             }
2189                             bForceBFlag = DMS_Invalid_ReadPointer_ID;
2190                         }
2191                         else
2192                         {
2193                             u16NextID = u16WP;
2194                             nrp_sync_print("w_T.NRP %d => ",u16NextID);
2195                         }
2196                     }
2197                     else
2198                     {
2199                         //Get a bottom field
2200                         if(RES_DMS._stXC_DIPPushInfo[u32Window][_GetPreviousBufferID(u16WP)].bValid == TRUE)
2201                         {
2202                             u16NextID = _GetPreviousBufferID(u16WP);
2203                             nrp_sync_print("w_B_back_T.NRP %d => ",u16NextID);
2204                             bForceBFlag = u16WP;
2205                         }
2206                         else
2207                         {
2208                             u16NextID = u16WP;
2209                             nrp_sync_print("w_B.NRP %d => ",u16NextID);
2210                         }
2211                     }
2212                 }
2213             }
2214             else
2215             {
2216                 nrp_sync_print("xx.WP %d \n ",RES_DMS._stXC_DIPWriteReadPointer[u32Window].u16WritePointer);
2217                 u16NextID = RES_DMS._stXC_DIPWriteReadPointer[u32Window].u16WritePointer;
2218             }
2219         }
2220         else if(DEV_DI_TIMER == 1 && (RES_DMS._stXC_DIPPushInfo[u32Window][RES_DMS._stXC_DIPWriteReadPointer[u32Window].u16WritePointer].bIsAfterDiTask == TRUE))
2221         {
2222             MS_U16 u16CurID = RES_DMS._stXC_DIPWriteReadPointer[u32Window].u16ReadPointer;
2223             MS_U16 u16WP = RES_DMS._stXC_DIPWriteReadPointer[u32Window].u16WritePointer;
2224             nrp_sync_print("Cur %d, WP %d, ",u16CurID,u16WP);
2225             nrp_sync_print("Timer.WP %d => ",RES_DMS._stXC_DIPWriteReadPointer[u32Window].u16WritePointer);
2226             u16NextID = RES_DMS._stXC_DIPWriteReadPointer[u32Window].u16WritePointer;
2227         }
2228 #endif
2229         else
2230         {
2231             nrp_sync_print("b.WP %d => ",RES_DMS._stXC_DIPWriteReadPointer[u32Window].u16WritePointer);
2232             u16NextID = RES_DMS._stXC_DIPWriteReadPointer[u32Window].u16WritePointer;
2233         }
2234     }
2235     else
2236     {
2237         u16NextID = _GetPreviousWritePointer(u32Window);
2238     }
2239     nrp_sync_print("Get Next ID%d => RBID %d => ",u16NextID,RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u16NextID].u8DiOutputRingBufferID);
2240     // Frame base interlace has two continous frame Buffer ID
2241     // MarkIgnorableReadBuffer is impossible.
2242     if(bFrameBaseFlag == FALSE)
2243     {
2244         _MarkIgnorableReadBuffer(u32Window, u16NextID);
2245     }
2246 
2247     return u16NextID;
2248 }
2249 
_DMS_DisableByWin(MS_U32 u32Window)2250 static void _DMS_DisableByWin(MS_U32 u32Window)
2251 {
2252     DMS_GET_RES_PRI;
2253     if(RES_DMS._stXC_DIPWinInfo[u32Window].bDIPwinUse == TRUE)
2254     {
2255         //Window Count --
2256         RES_DMS.u8EnableWindowCount--;
2257         RES_DMS.u8UseDIPWindowCount--;
2258 
2259         //set as invalid
2260         RES_DMS._stXC_DIPWinInfo[u32Window].bDIPwinUse = FALSE;
2261         RES_DMS.u32WindowFrameRate[u32Window] = 0;
2262 
2263         //Raise the flag "need to clear buffer"
2264         RES_DMS._stXC_DispBuf_Flag[E_DMS_DIP_MULTIVIEW_BUF_ID_0][u32Window].bCleanBuf = TRUE;
2265         RES_DMS._stXC_DispBuf_Flag[E_DMS_DIP_MULTIVIEW_BUF_ID_1][u32Window].bCleanBuf = TRUE;
2266 
2267         //db_print(" _stXC_DispBuf_Flag[E_MSAPI_DIP_MULTIVIEW_BUF_ID_0][u32Window].bCleanBuf = %d \n", RES_DMS._stXC_DispBuf_Flag[E_MSAPI_DIP_MULTIVIEW_BUF_ID_0][u32Window].bCleanBuf);
2268         //db_print(" _stXC_DispBuf_Flag[E_MSAPI_DIP_MULTIVIEW_BUF_ID_1][u32Window].bCleanBuf = %d \n",RES_DMS. _stXC_DispBuf_Flag[E_MSAPI_DIP_MULTIVIEW_BUF_ID_1][u32Window].bCleanBuf);
2269     }
2270 }
2271 
_DMS_InvalidateQueueByWin(MS_U32 u32Window)2272 static void _DMS_InvalidateQueueByWin(MS_U32 u32Window)
2273 {
2274     DMS_GET_RES_PRI;
2275     int i = 0;
2276     for(i=0;i<DMS_DIP_QUEUEDEPTH;i++)
2277     {
2278        if(RES_DMS._stXC_DIPPushInfo[u32Window][i].u32Window == u32Window)
2279        {
2280 #if DEV_DI
2281             _DMS_VDEC_Frame_Release_Interlace(u32Window,i);
2282 #endif
2283             _DMS_VDEC_Frame_Release(u32Window,i);
2284             RES_DMS._stXC_DIPPushInfo[u32Window][i].bValid = FALSE;
2285        }
2286     }
2287 }
2288 
_DMS_DeInitByWin(MS_U32 u32Window)2289 static void _DMS_DeInitByWin(MS_U32 u32Window)
2290 {
2291     DMS_GET_RES_PRI;
2292     int i = 0;
2293     MS_BOOL bDeInit = TRUE;
2294 
2295     for(i=0;i<DMS_MAX_WINDOW_NUM;i++)
2296     {
2297        if( RES_DMS._stXC_DIPWinInfo[i].bDIPwinUse == TRUE )
2298        {
2299            bDeInit = FALSE;
2300            break;
2301        }
2302     }
2303 }
2304 
_DMS_DIP_ScoreSorting(void)2305 static void _DMS_DIP_ScoreSorting(void)
2306 {
2307     DMS_GET_RES_PRI;
2308     MS_U8 i = 0;
2309     MS_U8 j = 0;
2310     MS_U8 temp = 0;
2311 
2312     for (i=0; i<DMS_MAX_WINDOW_NUM-1; i++)
2313     {
2314         for (j=1; j<DMS_MAX_WINDOW_NUM-i-1; j++)
2315         {
2316             if (RES_DMS.WindowScore[j] > RES_DMS.WindowScore[j+1])
2317             {
2318                 temp = RES_DMS.WindowScore[j];
2319                 RES_DMS.WindowScore[j]   = RES_DMS.WindowScore[j+1];
2320                 RES_DMS.WindowScore[j+1] = temp;
2321 
2322                 temp = RES_DMS.WindowZOrder[j];
2323                 RES_DMS.WindowZOrder[j]   = RES_DMS.WindowZOrder[j+1];
2324                 RES_DMS.WindowZOrder[j+1] = temp;
2325             }
2326         }
2327     }
2328 
2329 }
2330 
_DMS_DIP_IsDispBufferValid(void * pInstance,E_DMS_DIP_CLIENT eDIPClient)2331 static MS_BOOL _DMS_DIP_IsDispBufferValid(void* pInstance, E_DMS_DIP_CLIENT eDIPClient)
2332 {
2333     DMS_GET_RES_PRI;
2334     if (RES_DMS.u32DIPAddress_pa[eDIPClient] == NULL)
2335     {
2336         return FALSE;
2337     }
2338     else
2339     {
2340         return TRUE;
2341     }
2342 }
2343 
_DMS_DIP_GetDispBufferAddress(void * pInstance,E_DMS_DIP_CLIENT eDIPClient,MS_U16 u16BufID)2344 static MS_PHY _DMS_DIP_GetDispBufferAddress(void* pInstance, E_DMS_DIP_CLIENT eDIPClient, MS_U16 u16BufID)
2345 {
2346     MS_PHY phyBufAddr = NULL;
2347     MS_U32 BytesPerLine = 0;
2348     MS_U32 UHDBytesPerLine = 0;
2349     DMS_GET_RES_PRI;
2350     if (_DMS_DIP_IsDispBufferValid(pInstance, eDIPClient) == NULL)
2351     {
2352         return NULL;
2353     }
2354 
2355     BytesPerLine = _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[eDIPClient].eDIPWFmt, RES_DMS._stXC_DIPMemInfo[eDIPClient].u32PanelWidth);
2356     UHDBytesPerLine = _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[eDIPClient].eDIPWFmt, DMS_Frame_Buffer_Width);
2357 
2358     if(eDIPClient == E_DMS_DIP_CLIENT_GOP)
2359     {
2360         phyBufAddr = RES_DMS.u32DIPAddress_pa[eDIPClient] + ( (UHDBytesPerLine * DMS_Frame_Buffer_Height) * u16BufID );
2361     }
2362     else
2363     {
2364         phyBufAddr = RES_DMS.u32DIPAddress_pa[eDIPClient] + ( (BytesPerLine * RES_DMS._stXC_DIPMemInfo[eDIPClient].u32PanelHeight) * u16BufID );
2365     }
2366 
2367     //DMS_PRINTF("\033[32m [%s][%d] === u32DIPAddress_pa : 0x%lx === \033[0m\n",__FUNCTION__,__LINE__,RES_DMS.u32DIPAddress_pa[eDIPClient]);
2368     //DMS_PRINTF("\033[32m [%s][%d] === u32DIPStartMemAddr : 0x%lx === \033[0m\n",__FUNCTION__,__LINE__,phyBufAddr);
2369 
2370     return phyBufAddr;
2371 }
2372 
_DMS_GEBitblt(MS_PHY SrcAddress,MS_PHY DstAddress,GFX_DrawRect * stgfxDrawRect)2373 static MS_BOOL _DMS_GEBitblt(MS_PHY SrcAddress, MS_PHY DstAddress, GFX_DrawRect* stgfxDrawRect)
2374 {
2375     DMS_GET_RES_PRI;
2376     GFX_BufferInfo stSrc, stDst;
2377     GFX_Point stgfxPt0, stgfxPt1;
2378     MS_U16 fbFmt = 0;
2379 
2380     switch(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPWFmt)
2381     {
2382         case DIP_DATA_FMT_YUV422:
2383         default:
2384             fbFmt = E_MS_FMT_YUV422;
2385             break;
2386     }
2387 
2388     stgfxPt0.x = 0;
2389     stgfxPt0.y = 0;
2390     stgfxPt1.x = RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelWidth;
2391     stgfxPt1.y = RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelHeight;
2392     MApi_GFX_SetClip(&stgfxPt0, &stgfxPt1);
2393 
2394     stSrc.u32ColorFmt =fbFmt;
2395     stSrc.u32Addr =SrcAddress;
2396     stSrc.u32Width = RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelWidth;
2397     stSrc.u32Height = RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelHeight;
2398     stSrc.u32Pitch =_DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPWFmt, RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelWidth);
2399     MApi_GFX_SetSrcBufferInfo(&stSrc, 0);
2400     stDst.u32ColorFmt = fbFmt;
2401     stDst.u32Addr = DstAddress;
2402     stDst.u32Width = RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelWidth;
2403     stDst.u32Height = RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelHeight;
2404     stDst.u32Pitch = _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPWFmt, RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelWidth);
2405     MApi_GFX_SetDstBufferInfo(&stDst, 0);
2406 
2407     MApi_GFX_BitBlt(stgfxDrawRect, GFXDRAW_FLAG_SCALE);
2408     MApi_GFX_FlushQueue();
2409 
2410     return TRUE;
2411 }
2412 
_DMS_GERendering(void * pInstance,MS_U32 u32Window)2413 static MS_BOOL _DMS_GERendering(void* pInstance, MS_U32 u32Window)
2414 {
2415     DMS_GET_RES_PRI;
2416     //db_print(" u8WindowID = %d need GERendering to update buffer\n", u8WindowID);
2417     GFX_DrawRect stgfxDrawRect;
2418     stgfxDrawRect.srcblk.x = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32x;
2419     stgfxDrawRect.srcblk.y = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32y;
2420     stgfxDrawRect.srcblk.width = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width;
2421     stgfxDrawRect.srcblk.height = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height;
2422 
2423     stgfxDrawRect.dstblk.x = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32x;
2424     stgfxDrawRect.dstblk.y = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32y;
2425     stgfxDrawRect.dstblk.width = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width;
2426     stgfxDrawRect.dstblk.height = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height;
2427     if (RES_DMS.bDIPWriteFirstAddr)
2428     {
2429         _DMS_GEBitblt(_DMS_DIP_GetDispBufferAddress(pInstance, E_DMS_DIP_CLIENT_GOP, E_DMS_DIP_MULTIVIEW_BUF_ID_1),
2430             _DMS_DIP_GetDispBufferAddress(pInstance, E_DMS_DIP_CLIENT_GOP, E_DMS_DIP_MULTIVIEW_BUF_ID_0),
2431             &stgfxDrawRect);
2432     }
2433     else
2434     {
2435         _DMS_GEBitblt(_DMS_DIP_GetDispBufferAddress(pInstance, E_DMS_DIP_CLIENT_GOP, E_DMS_DIP_MULTIVIEW_BUF_ID_0),
2436             _DMS_DIP_GetDispBufferAddress(pInstance, E_DMS_DIP_CLIENT_GOP, E_DMS_DIP_MULTIVIEW_BUF_ID_1),
2437             &stgfxDrawRect);
2438     }
2439 
2440     return TRUE;
2441 }
2442 
_DMS_GE_DrawRect(MS_PHY DstAddress,GFX_Block stRect,MS_U32 u32Data)2443 static MS_BOOL _DMS_GE_DrawRect(MS_PHY DstAddress, GFX_Block stRect, MS_U32 u32Data)
2444 {
2445     DMS_GET_RES_PRI;
2446     GFX_Point stgfxPt0;
2447     GFX_Point stgfxPt1;
2448     GFX_BufferInfo stgfxDstBuf;
2449     GFX_RectFillInfo pGfxRectFillInfo;
2450     memset(&pGfxRectFillInfo, 0, sizeof(GFX_RectFillInfo));
2451 
2452     //Set Dst buffer
2453     stgfxDstBuf.u32ColorFmt = GFX_FMT_YUV422;
2454     stgfxDstBuf.u32Addr = DstAddress;
2455     stgfxDstBuf.u32Pitch = _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPWFmt, RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelWidth);
2456     MApi_GFX_SetDstBufferInfo(&stgfxDstBuf, 0);
2457 
2458     stgfxPt0.x = 0;
2459     stgfxPt0.y = 0;
2460     stgfxPt1.x = RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelWidth;
2461     stgfxPt1.y = RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelHeight;
2462     MApi_GFX_SetClip(&stgfxPt0, &stgfxPt1);
2463 
2464     pGfxRectFillInfo.dstBlock.x = stRect.x;
2465     pGfxRectFillInfo.dstBlock.y = stRect.y;
2466     pGfxRectFillInfo.dstBlock.width= stRect.width;
2467     pGfxRectFillInfo.dstBlock.height= stRect.height;
2468     pGfxRectFillInfo.fmt = GFX_FMT_YUV422;
2469 
2470     pGfxRectFillInfo.colorRange.color_s.a = pGfxRectFillInfo.colorRange.color_e.a = 0;
2471     pGfxRectFillInfo.colorRange.color_s.r = pGfxRectFillInfo.colorRange.color_e.r = 0;
2472     pGfxRectFillInfo.colorRange.color_s.g = pGfxRectFillInfo.colorRange.color_e.g = 0;
2473     pGfxRectFillInfo.colorRange.color_s.b = pGfxRectFillInfo.colorRange.color_e.b = 0;
2474 
2475     pGfxRectFillInfo.flag = GFXRECT_FLAG_COLOR_CONSTANT;
2476     MApi_GFX_RectFill(&pGfxRectFillInfo);
2477 
2478     MApi_GFX_FlushQueue();
2479     return TRUE;
2480 }
2481 
2482 
2483 //Draw rectangle with transparent color
_DMS_GE_GetRectAreaByWin(MS_U32 u32Window,GFX_Block * stRect)2484 static MS_BOOL _DMS_GE_GetRectAreaByWin(MS_U32 u32Window, GFX_Block *stRect)
2485 {
2486     DMS_GET_RES_PRI;
2487     stRect->x = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32x;
2488     stRect->y= RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32y;
2489     stRect->width = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width;
2490     stRect->height = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height;
2491     return TRUE;
2492 }
2493 
2494 //Draw rectangle with transparent color
_DMS_GE_GetPreviousRectAreaByWin(MS_U32 u32Window,GFX_Block * stRect)2495 static MS_BOOL _DMS_GE_GetPreviousRectAreaByWin(MS_U32 u32Window, GFX_Block *stRect)
2496 {
2497     DMS_GET_RES_PRI;
2498 
2499 
2500     stRect->x = RES_DMS._stXC_PreDispWinInfo[u32Window].u32x;
2501     stRect->y= RES_DMS._stXC_PreDispWinInfo[u32Window].u32y;
2502     stRect->width = RES_DMS._stXC_PreDispWinInfo[u32Window].u32width;
2503     stRect->height = RES_DMS._stXC_PreDispWinInfo[u32Window].u32height;
2504     return TRUE;
2505 }
2506 
2507 //Draw rectangle with transparent color
_DMS_GE_ClearWin(void * pInstance,MS_U16 u16BufID,MS_U32 u32Window)2508 static MS_BOOL _DMS_GE_ClearWin(void *pInstance, MS_U16 u16BufID, MS_U32 u32Window)
2509 {
2510     GFX_Block stRect = {0};
2511     MS_PHY phyBaseAddr = NULL;
2512 
2513     //db_print(" u16BufID = %d, u32Window = %d \n", u16BufID, u32Window);
2514 
2515     //Get Base Address by Buffer ID
2516     phyBaseAddr = _DMS_DIP_GetDispBufferAddress(pInstance, E_DMS_DIP_CLIENT_GOP, u16BufID);
2517 
2518     if (phyBaseAddr == NULL)
2519     {
2520         DMS_PRINTF(" phyBaseAddr is invalid (NULL) !! \n");
2521         return FALSE;
2522     }
2523 
2524     //Get Rectangle Area by Window Number
2525     _DMS_GE_GetRectAreaByWin(u32Window, &stRect);
2526 
2527     //db_print(" stRect.x = %d, stRect.y = %d, stRect.width = %d, stRect.height = %d \n", stRect.x, stRect.y, stRect.width, stRect.height);
2528 
2529     //Draw rectangle with transparent color
2530     _DMS_GE_DrawRect(phyBaseAddr, stRect, DMS_DIP_MULTIVIEW_TRANSPARENT_COLOR);
2531 
2532     return TRUE;
2533 }
2534 
2535 //Draw rectangle with transparent color
_DMS_GE_ClearPreviousWin(void * pInstance,MS_U16 u16BufID,MS_U32 u32Window)2536 static MS_BOOL _DMS_GE_ClearPreviousWin(void* pInstance, MS_U16 u16BufID, MS_U32 u32Window)
2537 {
2538     GFX_Block stRect = {0};
2539     MS_PHY phyBaseAddr = NULL;
2540 
2541     //db_print(" u16BufID = %d, u32Window = %d \n", u16BufID, u32Window);
2542 
2543     //Get Base Address by Buffer ID
2544     phyBaseAddr = _DMS_DIP_GetDispBufferAddress(pInstance, E_DMS_DIP_CLIENT_GOP, u16BufID);
2545 
2546     //db_print(" phyBaseAddr = 0x%lx, \n", phyBaseAddr);
2547 
2548     //Get Rectangle Area by Window Number
2549     _DMS_GE_GetPreviousRectAreaByWin(u32Window, &stRect);
2550 
2551     //db_print(" stRect.x = %d, stRect.y = %d, stRect.width = %d, stRect.height = %d \n", stRect.x, stRect.y, stRect.width, stRect.height);
2552     //DMS_PRINTF(" stRect.x = %d, stRect.y = %d, stRect.width = %d, stRect.height = %d \n", stRect.x, stRect.y, stRect.width, stRect.height);
2553 
2554     //Draw rectangle with transparent color
2555     _DMS_GE_DrawRect(phyBaseAddr, stRect, DMS_DIP_MULTIVIEW_TRANSPARENT_COLOR);
2556 
2557     return TRUE;
2558 }
2559 
_DMS_DIP_GetBackgroundBufID(void * pInstance)2560 static MS_U8 _DMS_DIP_GetBackgroundBufID(void *pInstance)
2561 {
2562     DMS_GET_RES_PRI;
2563     if (RES_DMS.bDIPWriteFirstAddr == TRUE)
2564     {
2565         return E_DMS_DIP_MULTIVIEW_BUF_ID_0;
2566     }
2567     else
2568     {
2569         return E_DMS_DIP_MULTIVIEW_BUF_ID_1;
2570     }
2571 }
2572 
_WinNeedToClear(void * pInstance,MS_U8 u8BufId,MS_U8 u8WindowId)2573 static MS_BOOL _WinNeedToClear(void *pInstance, MS_U8 u8BufId, MS_U8 u8WindowId)
2574 {
2575     DMS_GET_RES_PRI;
2576     return RES_DMS._stXC_DispBuf_Flag[u8BufId][u8WindowId].bCleanBuf;
2577 }
2578 
_WinResetClearBufFlag(void * pInstance,MS_U8 u8BufId,MS_U8 u8WindowId)2579 static void _WinResetClearBufFlag(void* pInstance, MS_U8 u8BufId, MS_U8 u8WindowId)
2580 {
2581     DMS_GET_RES_PRI;
2582     RES_DMS._stXC_DispBuf_Flag[u8BufId][u8WindowId].bCleanBuf = FALSE;
2583 }
2584 
_DMS_HandleClearFlag(void * pInstance)2585 static MS_BOOL _DMS_HandleClearFlag(void* pInstance)
2586 {
2587     MS_U8 u8BufId = 0;
2588     MS_U8 u8WindowId = 0;
2589 
2590     u8BufId = _DMS_DIP_GetBackgroundBufID(pInstance);
2591     //db_print(" trace, u8BufId = %d \n", u8BufId);
2592 
2593     for (u8WindowId= (DMS_MVOP_FLOW)? 1 : 0; u8WindowId < DMS_MAX_WINDOW_NUM; u8WindowId++)
2594     {
2595         if (_WinNeedToClear(pInstance, u8BufId, u8WindowId) == TRUE)
2596         {
2597             //Reset Buffer of Window
2598             _DMS_GE_ClearWin(pInstance, u8BufId, u8WindowId);
2599 
2600             //Reset Clear Flag
2601             _WinResetClearBufFlag(pInstance, u8BufId, u8WindowId);
2602         }
2603     }
2604     return TRUE;
2605 }
2606 
_WinDispChange(void * pInstance,MS_U8 u8BufId,MS_U8 u8WindowId)2607 static MS_BOOL _WinDispChange(void* pInstance, MS_U8 u8BufId, MS_U8 u8WindowId)
2608 {
2609     DMS_GET_RES_PRI;
2610     return RES_DMS._stXC_DispBuf_Flag[u8BufId][u8WindowId].bDispChange;
2611 }
2612 
_WinResetDispChangeFlag(void * pInstance,MS_U8 u8BufId,MS_U8 u8WindowId)2613 static void _WinResetDispChangeFlag(void* pInstance, MS_U8 u8BufId, MS_U8 u8WindowId)
2614 {
2615     DMS_GET_RES_PRI;
2616     RES_DMS._stXC_DispBuf_Flag[u8BufId][u8WindowId].bDispChange = FALSE;
2617 }
2618 
_DMS_HandleDispChangeFlag(void * pInstance)2619 static MS_BOOL _DMS_HandleDispChangeFlag(void* pInstance)
2620 {
2621     MS_U8 u8BufId = 0;
2622     MS_U8 u8WindowId = 0;
2623 
2624     u8BufId = _DMS_DIP_GetBackgroundBufID(pInstance);
2625 
2626     //DMS_PRINTF(" [%s][%d] trace, u8BufId = %d \n", __FUNCTION__, __LINE__, u8BufId);
2627     for (u8WindowId=(DMS_MVOP_FLOW)? 1 : 0; u8WindowId < DMS_MAX_WINDOW_NUM; u8WindowId++)
2628     {
2629         if (_WinDispChange(pInstance, u8BufId, u8WindowId) == TRUE)
2630         {
2631             //db_print(" trace, u8BufId = %d , u8WindowId =%d \n", u8BufId, u8WindowId);
2632 
2633             //Reset Buffer of Window
2634             _DMS_GE_ClearPreviousWin(pInstance, u8BufId, u8WindowId);
2635 
2636             //Reset Clear Flag
2637             _WinResetDispChangeFlag(pInstance, u8BufId, u8WindowId);
2638         }
2639     }
2640     return TRUE;
2641 }
2642 
2643 
2644 //Check Display Buffer Flag and Fire
_DMS_CheckDispBufFlag(void * pInstance)2645 static MS_BOOL _DMS_CheckDispBufFlag(void* pInstance)
2646 {
2647     DMS_GET_RES_PRI;
2648     //Handle if there any window need to be clear
2649     _DMS_HandleClearFlag(pInstance);
2650 
2651     //Handle if there any display window change
2652     _DMS_HandleDispChangeFlag(pInstance);
2653 
2654     //others
2655     //At new vsync start, we can remove marked buffer id safely for MVOP from VDEC
2656 #if (DMS_MAIN_WINDOW_FLOW_VERSION == 1)
2657 #if DEV_PAUSE
2658     if(_DMS_Is_MVOPFlow(MVOP_WINDOW))
2659 #else
2660     if(_DMS_Is_MVOPFlow(MVOP_WINDOW) && (RES_DMS.eDMS_MVOPFlowCtrl == E_DMS_MVOP_FLOW_FROM_VDEC))
2661 #endif
2662     {
2663         if(RES_DMS.bMVOPMarkRemoveBuffer)
2664         {
2665             sync_print(" RemoveID %d V:%d =>",RES_DMS.gDMS_MVOPRemoveBufferID,RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS.gDMS_MVOPRemoveBufferID].bValid);
2666             if(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS.gDMS_MVOPRemoveBufferID].bValid == TRUE && RES_DMS.gDMS_MVOPRemoveBufferID != DMS_Invalid_ReadPointer_ID)
2667             {
2668                 //sync_print(" Remove %d =>",gDMS_MVOPRemoveBufferID);
2669                 RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS.gDMS_MVOPRemoveBufferID].bValid = FALSE;
2670                 _DMS_VDEC_Frame_Release(MVOP_WINDOW,RES_DMS.gDMS_MVOPRemoveBufferID);
2671                 RES_DMS.gDMS_MVOPRemoveBufferID = DMS_Invalid_ReadPointer_ID;
2672             }
2673             RES_DMS.bMVOPMarkRemoveBuffer = FALSE;
2674         }
2675     }
2676 
2677     if(_DMS_Is_MVOPFlow(MVOP_WINDOW))
2678     {
2679         if(RES_DMS.bDMS_Freeze_DoubleBuffer)
2680         {
2681             _DMS_Add_XC_Status(MVOP_WINDOW, DMS_XC_FREEZE);
2682         }
2683         else
2684         {
2685             _DMS_Remove_XC_Status(MVOP_WINDOW, DMS_XC_FREEZE);
2686         }
2687     }
2688 #endif //#if (DMS_MAIN_WINDOW_FLOW_VERSION == 1)
2689     return TRUE;
2690 }
2691 
2692 //(5) Get Next round DIP window stage
2693 #define START_FRC_ACCUMULE_FRAME_COUNT 3
_DMS_GetNextInfo(MS_U16 u16WindowID,MS_BOOL bResetCaptureID)2694 static MS_BOOL _DMS_GetNextInfo(MS_U16 u16WindowID, MS_BOOL bResetCaptureID)
2695 {
2696     DMS_GET_RES_PRI;
2697     //static MS_U16 u16WindowID = 0;
2698     MS_U16 u16NextReadPointer = 0;
2699     MS_U8 u8BufferID = DMS_Invalid_ReadPointer_ID;
2700 
2701     if(bResetCaptureID)
2702     {
2703         RES_DMS.u8DIPReadytoCaptureID[u16WindowID] = DMS_Invalid_ReadPointer_ID;
2704     }
2705 
2706     if(DEV_NEW_NEXT)
2707     {
2708         MS_U32 u32OutputRate = RES_DMS.u32OutputRate;
2709         if(u32OutputRate > 0)
2710         {
2711             RES_DMS.u8DIPReadytoCaptureID[u16WindowID] = DMS_Invalid_ReadPointer_ID;
2712             if(RES_DMS.bStartCountFRC[u16WindowID] != FALSE)
2713             {
2714                 MS_U16 u16ReadPoint = RES_DMS._stXC_DIPWriteReadPointer[u16WindowID].u16ReadPointer;
2715                 MS_U32 u32InputRate = RES_DMS._stXC_DIPPushInfo[u16WindowID][u16ReadPoint].u32FrameRate;
2716                 if(u32InputRate == 0)
2717                 {
2718                     DMS_PRINTF("[%s] Input Frame rate is 0, can not move FRC\n",__FUNCTION__);
2719                 }
2720 #if TEMP_LOG
2721                 DMS_PRINTF(" In:%d ,\n",u32InputRate);
2722 #endif
2723                 if(_DMS_Is_SourceInterlace(RES_DMS._stXC_DIPPushInfo[u16WindowID][u16ReadPoint].eScanType))
2724                 {
2725                     u32InputRate *= 2;
2726                 }
2727                 MS_U32 u32ReadPointOffset = 0;
2728                 RES_DMS.u32AccumuleInputRate[u16WindowID] += u32InputRate;
2729 #if TEMP_LOG
2730                 DMS_PRINTF("AccumuleInputRate=%d, u32OutputRate=%d\n",RES_DMS.u32AccumuleInputRate[u16WindowID],RES_DMS.u32OutputRate);
2731 #endif
2732                 if(RES_DMS.u32AccumuleInputRate[u16WindowID] >= u32OutputRate)
2733                 {
2734                     u32ReadPointOffset = RES_DMS.u32AccumuleInputRate[u16WindowID] / u32OutputRate;
2735                     RES_DMS.u32AccumuleInputRate[u16WindowID] = RES_DMS.u32AccumuleInputRate[u16WindowID] % u32OutputRate;
2736                 }
2737 #if TEMP_LOG
2738                 DMS_PRINTF("AccumuleInputRate=%d, u32ReadPointOffset=%d\n",RES_DMS.u32AccumuleInputRate[u16WindowID],u32ReadPointOffset);
2739 #endif
2740                 if(u32ReadPointOffset > 0)
2741                 {
2742                     MS_U8 i = 0;
2743                     MS_U16 u16NextReadPointer = RES_DMS._stXC_DIPWriteReadPointer[u16WindowID].u16ReadPointer;
2744                     for(i = 0 ; i < u32ReadPointOffset; i++)
2745                     {
2746                         u16NextReadPointer = _GetNextBufferID(u16NextReadPointer);
2747                     }
2748                     if (RES_DMS._stXC_DIPPushInfo[u16WindowID][u16NextReadPointer].bValid)
2749                     {
2750                         _MarkIgnorableReadBuffer(u16WindowID, u16NextReadPointer);
2751                         if(RES_DMS._stXC_DIPWriteReadPointer[u16WindowID].u16ReadPointer != u16NextReadPointer)
2752                         {
2753                             RES_DMS.u8DIPReadytoCaptureID[u16WindowID] = u16NextReadPointer;
2754                             RES_DMS._stXC_DIPWriteReadPointer[u16WindowID].u16ReadPointer = u16NextReadPointer;
2755                         }
2756                     }
2757                     else
2758                     {
2759                         //DMS_PRINTF("[%s][%d] win %d, now %d, next %d NOT Valid\n",__FUNCTION__,__LINE__,u16WindowID,RES_DMS._stXC_DIPWriteReadPointer[u16WindowID].u16ReadPointer,u16NextReadPointer);
2760                     }
2761                 }
2762                 else
2763                 {
2764                     if(_DMS_Is_MVOPFlow(u16WindowID) == FALSE)
2765                     {
2766                         //No frame has been pushed, display the old frame
2767                         if(_DMS_Query_XC_Status(u16WindowID, DMS_XC_UPDATE_FROM_VDEC))
2768                         {
2769                             RES_DMS.u8DIPReadytoCaptureID[u16WindowID] = u8BufferID;
2770                         }
2771                     }
2772                 }
2773             }
2774             else
2775             {
2776                 MS_U16 u16WritePoint = RES_DMS._stXC_DIPWriteReadPointer[u16WindowID].u16WritePointer;
2777                 if(RES_DMS._stXC_DIPPushInfo[u16WindowID][u16WritePoint].bValid)
2778                 {
2779                         _MarkIgnorableReadBuffer(u16WindowID, u16WritePoint);
2780                         RES_DMS._stXC_DIPWriteReadPointer[u16WindowID].u16ReadPointer = u16WritePoint;
2781                         RES_DMS.u8DIPReadytoCaptureID[u16WindowID] = u16WritePoint;
2782                         RES_DMS.bStartCountFRC[u16WindowID] = TRUE;
2783                 }
2784             }
2785         }
2786 
2787     }
2788     else
2789     {
2790         //Check Window is Enable or Not
2791         if (_DMS_IsWindowUsed(u16WindowID) == FALSE)
2792         {
2793             //Clean Pushframe Info in queue
2794             _DMS_InvalidateQueueByWin(u16WindowID);
2795             return TRUE;
2796         }
2797 
2798         //Find Next Read Pointer
2799         u16NextReadPointer = _GetNextReadPointer(u16WindowID);
2800         if((_DMS_Is_MVOPFlow(u16WindowID) == FALSE) ||
2801             ((_DMS_Is_MVOPFlow(u16WindowID) == TRUE) && (RES_DMS.eDMS_MVOPFlowCtrl != E_DMS_MVOP_FLOW_FROM_VDEC)))
2802         {
2803             u8BufferID = RES_DMS._stXC_DIPWriteReadPointer[u16WindowID].u16ReadPointer;
2804             RES_DMS._stXC_DIPWriteReadPointer[u16WindowID].u16ReadPointer = u16NextReadPointer;
2805         }
2806 
2807         //Set infomation to u8DIPReadytoCaptureID[]
2808         if (RES_DMS._stXC_DIPPushInfo[u16WindowID][u16NextReadPointer].bValid)
2809         {
2810             sync_print(" V, NRP %d => ",u16NextReadPointer);
2811             if(_DMS_Is_MVOPFlow(u16WindowID) && (RES_DMS.eDMS_MVOPFlowCtrl == E_DMS_MVOP_FLOW_FROM_VDEC))
2812             {
2813                 if(RES_DMS._stXC_DIPWriteReadPointer[u16WindowID].u16ReadPointer != u16NextReadPointer)
2814                 {
2815                     RES_DMS.u8DIPReadytoCaptureID[u16WindowID] = u16NextReadPointer;
2816                     RES_DMS._stXC_DIPWriteReadPointer[u16WindowID].u16ReadPointer = u16NextReadPointer;
2817                 }
2818             }
2819             else
2820             {
2821                 if(u8BufferID != u16NextReadPointer)
2822                 {
2823                     //A new frame has been pushed
2824                     if(u8BufferID < DMS_Invalid_ReadPointer_ID)
2825                     {
2826                         RES_DMS._stXC_DIPPushInfo[u16WindowID][u8BufferID].bValid = FALSE;
2827                         _DMS_VDEC_Frame_Release(u16WindowID,u8BufferID);
2828                     }
2829                     RES_DMS.u8DIPReadytoCaptureID[u16WindowID] = u16NextReadPointer;
2830                 }
2831                 else
2832                 {
2833                     if(bResetCaptureID == FALSE)
2834                     {
2835                         //No frame has been pushed, display the old frame
2836                         if(_DMS_Query_XC_Status(u16WindowID, DMS_XC_UPDATE_FROM_VDEC))
2837                         {
2838                             RES_DMS.u8DIPReadytoCaptureID[u16WindowID] = u8BufferID;
2839                         }
2840                         else
2841                         {
2842                             RES_DMS.u8DIPReadytoCaptureID[u16WindowID] = DMS_Invalid_ReadPointer_ID;
2843                         }
2844                     }
2845                 }
2846             }
2847         }
2848     }
2849 
2850     return TRUE;
2851 }
2852 
2853 //(3) Prepare Next Frame to be Displayed
_DMS_SetDIPRWindow(E_DMS_DIP_ACTION eAction,MS_U32 u32Window,MS_U16 u16BufferID)2854 static MS_BOOL _DMS_SetDIPRWindow(E_DMS_DIP_ACTION eAction, MS_U32 u32Window, MS_U16 u16BufferID)
2855 {
2856     DMS_GET_RES_PRI;
2857     MS_U8 u8DIPWindowID = RES_DMS.u8DIP_Window[eAction];
2858     ST_XC_DIPR_PROPERTY_EX DIPRWinPropertytoShow_EX;
2859     memset(&DIPRWinPropertytoShow_EX,0,sizeof(ST_XC_DIPR_PROPERTY_EX));
2860 
2861     ST_DIP_DI_SETTING DIP3DDISetting;
2862 #if DMS_DIP_Support_3DDI
2863     static MS_U8 u8count = 0;
2864     ST_DIP_DI_NWAY_BUF_INFO stDINwayBuf[32];
2865 #endif
2866     memset(&DIP3DDISetting,0,sizeof(ST_DIP_DI_SETTING));
2867 
2868     if(eAction == E_DMS_DIP_DI)
2869     {
2870         //DIPR win setting
2871         DIPRWinPropertytoShow_EX.stDIPRProperty.enDataFmt = _DMS_DIP_GetDIPRDataFMT(&RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID]);
2872 
2873         DIPRWinPropertytoShow_EX.stDIPRProperty.u16Width = DMS_DIPR_Alignment(RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].u16SrcWidth, DMS_HAL_DIPR_Align_YUV420);
2874 
2875 #if DMS_DIP_Support_3DDI
2876         if(_DMS_Is_SourceFrameBaseInterlace(RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].eScanType, RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].eFieldType))
2877         {
2878             DIPRWinPropertytoShow_EX.stDIPRProperty.u16Height = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].u16SrcHeight;
2879         }
2880         else
2881         {
2882             DIPRWinPropertytoShow_EX.stDIPRProperty.u16Height = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].u16SrcHeight / 2;
2883         }
2884 #else
2885         DIPRWinPropertytoShow_EX.stDIPRProperty.u16Height = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].u16SrcHeight;
2886 #endif
2887         DIPRWinPropertytoShow_EX.stDIPRProperty.u16Pitch = _DMS_DIP_CalcPitch(DIPRWinPropertytoShow_EX.stDIPRProperty.enDataFmt, RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].u16SrcPitch);
2888         DIPRWinPropertytoShow_EX.stDIPRProperty.u32YBufAddr = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].u32SrcLumaAddr;
2889         DIPRWinPropertytoShow_EX.stDIPRProperty.u32CBufAddr = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].u32SrcChromaAddr;
2890         DIPRWinPropertytoShow_EX.stDIPRProperty.u32YBufAddr10Bits = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].u32SrcLumaAddr;
2891         DIPRWinPropertytoShow_EX.stDIPRProperty.u32CBufAddr10Bits = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].u32SrcChromaAddr;
2892         //DMS_PRINTF("\033[34m  _DMS_SetDIPRWindowInterlace %d %d\033[0m\n",u16BufferID,DIPRWinPropertytoShow_EX.stDIPRProperty.enDataFmt);
2893 
2894         if(_DMS_Is_SourceFrameBaseInterlace(RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].eScanType, RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].eFieldType))
2895         {
2896             _DMS_DIP_GetFrameBaseInterlaceFieldType(&RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID]);
2897         }
2898 #if DMS_DIP_Support_3DDI
2899         if(u8count < 2)
2900         {
2901             DIP3DDISetting.bEnableDI = TRUE;
2902             DIP3DDISetting.bInitDI = FALSE;
2903             DIP3DDISetting.u8NwayIndex = u32Window;
2904             DIP3DDISetting.enDI_Field = _DMS_DIP_GetDIPDiDataFMT(u32Window, RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].eScanType, RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].eFieldType);
2905 
2906             //DIP3DDISetting.phy2ndFieldAddr = 0;
2907             DIP3DDISetting.bEnaNwayInfoRefresh = FALSE;
2908             DIP3DDISetting.u8NwayBufCnt = 1; // Fix me
2909             DIP3DDISetting.bEnableBob = TRUE;// Fix me
2910 
2911             stDINwayBuf[0].phyDI_BufAddr = RES_DMS._stXC_DIPWinInfo[u32Window].u32DIStartAddr;
2912             stDINwayBuf[0].u32DI_BufSize = RES_DMS._stXC_DIPWinInfo[u32Window].u32DISize;
2913             stDINwayBuf[0].u8DIBufCnt = RES_DMS._stXC_DIPWinInfo[u32Window].u8DIBufCnt;
2914 
2915             DIP3DDISetting.stDINwayBufInfo = (void*)stDINwayBuf;
2916 
2917             DIPRWinPropertytoShow_EX.stDIPR3DDISetting.stDipr3DDI_VerCtl.u32version=1;
2918             DIPRWinPropertytoShow_EX.stDIPR3DDISetting.stDipr3DDI_VerCtl.u32size=sizeof(ST_DIP_DI_SETTING);
2919             DIPRWinPropertytoShow_EX.stDIPR3DDISetting.pDIPR3DDISetting = (void*)&DIP3DDISetting;
2920             u8count ++;
2921         }
2922         else
2923         {
2924             DIP3DDISetting.bEnableDI = TRUE;
2925             DIP3DDISetting.bInitDI = FALSE;
2926             DIP3DDISetting.u8NwayIndex = u32Window;
2927             DIP3DDISetting.enDI_Field = _DMS_DIP_GetDIPDiDataFMT(u32Window, RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].eScanType, RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].eFieldType);
2928 
2929             DIP3DDISetting.bEnaNwayInfoRefresh = FALSE;
2930             DIP3DDISetting.u8NwayBufCnt = 1; // Fix me
2931             DIP3DDISetting.bEnableBob = FALSE;// Fix me
2932 
2933             stDINwayBuf[0].phyDI_BufAddr = RES_DMS._stXC_DIPWinInfo[u32Window].u32DIStartAddr;
2934             stDINwayBuf[0].u32DI_BufSize = RES_DMS._stXC_DIPWinInfo[u32Window].u32DISize;
2935             stDINwayBuf[0].u8DIBufCnt = RES_DMS._stXC_DIPWinInfo[u32Window].u8DIBufCnt;
2936 
2937             DIP3DDISetting.stDINwayBufInfo = (void*)stDINwayBuf;
2938 
2939             DIPRWinPropertytoShow_EX.stDIPR3DDISetting.stDipr3DDI_VerCtl.u32version=1;
2940             DIPRWinPropertytoShow_EX.stDIPR3DDISetting.stDipr3DDI_VerCtl.u32size=sizeof(ST_DIP_DI_SETTING);
2941             DIPRWinPropertytoShow_EX.stDIPR3DDISetting.pDIPR3DDISetting = (void*)&DIP3DDISetting;
2942 #if 0
2943             DMS_PRINTF("\033[34m  width %d, Height %d, Pitch %d \033[0m\n",DIPRWinPropertytoShow_EX.stDIPRProperty.u16Width, DIPRWinPropertytoShow_EX.stDIPRProperty.u16Height, DIPRWinPropertytoShow_EX.stDIPRProperty.u16Pitch);
2944             DMS_PRINTF("\033[35m bEnable %d, bInitDI %d, NwayIndex %d, enDiField %d, bEnaNwayInfoRefresh %d, u8NwayBufCnt %d, bEnableBob %d\033[0m\n",
2945                 DIP3DDISetting.bEnableDI, DIP3DDISetting.bInitDI, DIP3DDISetting.u8NwayIndex, DIP3DDISetting.enDI_Field, DIP3DDISetting.bEnaNwayInfoRefresh,
2946                 DIP3DDISetting.u8NwayBufCnt, DIP3DDISetting.bEnableBob);
2947 #endif
2948 
2949         }
2950 #else
2951         DIP3DDISetting.bEnableDI = TRUE;
2952         DIP3DDISetting.enDI_Field = _DMS_DIP_GetDIPDiDataFMT(u32Window, RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].eScanType, RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].eFieldType);
2953 
2954         if(_DMS_Is_SourceFieldBaseInterlace(RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].eScanType))
2955         {
2956             DIP3DDISetting.phyBotYBufAddr = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].u32SrcLumaAddrI;
2957             DIP3DDISetting.phyBotCBufAddr = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].u32SrcChromaAddrI;
2958             DIP3DDISetting.phyBotYBufAddr10Bits = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].u32SrcLumaAddrI;
2959             DIP3DDISetting.phyBotCBufAddr10Bits = RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].u32SrcChromaAddrI;
2960         }
2961         else
2962         {
2963             DIP3DDISetting.phyBotYBufAddr = DIPRWinPropertytoShow_EX.stDIPRProperty.u32YBufAddr;
2964             DIP3DDISetting.phyBotCBufAddr = DIPRWinPropertytoShow_EX.stDIPRProperty.u32CBufAddr;
2965             DIP3DDISetting.phyBotYBufAddr10Bits = DIPRWinPropertytoShow_EX.stDIPRProperty.u32YBufAddr;
2966             DIP3DDISetting.phyBotCBufAddr10Bits = DIPRWinPropertytoShow_EX.stDIPRProperty.u32CBufAddr;
2967         }
2968         DIPRWinPropertytoShow_EX.stDIPR3DDISetting.stDipr3DDI_VerCtl.u32version=1;
2969         DIPRWinPropertytoShow_EX.stDIPR3DDISetting.stDipr3DDI_VerCtl.u32size=sizeof(ST_DIP_DI_SETTING);
2970         DIPRWinPropertytoShow_EX.stDIPR3DDISetting.pDIPR3DDISetting = (void*)&DIP3DDISetting;
2971 #endif
2972     }
2973     else
2974     {
2975         if(u16BufferID < DMS_Invalid_ReadPointer_ID)
2976         {
2977             RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPRFmt = _DMS_DIP_GetDIPRDataFMT(&RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID]);
2978 
2979             if(_DMS_WindowSizeOverFHD(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth,RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight))
2980             {
2981                 DIPRWinPropertytoShow_EX.stDIPRProperty.enDataFmt = RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPRFmt;
2982                 DIPRWinPropertytoShow_EX.stDIPRProperty.u16Width = DMS_DIPR_Alignment((RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth/2), DMS_HAL_DIPR_Align_YUV420);
2983                 DIPRWinPropertytoShow_EX.stDIPRProperty.u16Height = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight/2;
2984                 DIPRWinPropertytoShow_EX.stDIPRProperty.u16Pitch = _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPRFmt, RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16Src2ndBufferPitch);
2985                 DIPRWinPropertytoShow_EX.stDIPRProperty.u32YBufAddr = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].phySrc2ndBufferLumaAddr;
2986                 DIPRWinPropertytoShow_EX.stDIPRProperty.u32CBufAddr = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].phySrc2ndBufferChromaAddr;
2987             }
2988             else
2989             {
2990                 //DIPR win setting
2991                 DIPRWinPropertytoShow_EX.stDIPRProperty.enDataFmt = RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPRFmt;
2992                 DIPRWinPropertytoShow_EX.stDIPRProperty.u16Width = DMS_DIPR_Alignment(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth, DMS_HAL_DIPR_Align_YUV420);
2993                 DIPRWinPropertytoShow_EX.stDIPRProperty.u16Height = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight;
2994                 DIPRWinPropertytoShow_EX.stDIPRProperty.u16Pitch = _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPRFmt, RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcPitch);
2995                 DIPRWinPropertytoShow_EX.stDIPRProperty.u32YBufAddr = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u32SrcLumaAddr;
2996                 DIPRWinPropertytoShow_EX.stDIPRProperty.u32CBufAddr = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u32SrcChromaAddr;
2997 
2998                 DIPRWinPropertytoShow_EX.stDIPRProperty.u32YBufAddr10Bits = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u32SrcLumaAddr;
2999                 DIPRWinPropertytoShow_EX.stDIPRProperty.u32CBufAddr10Bits = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u32SrcChromaAddr;
3000             }
3001 #if DMS_DIP_NWindow_Support_2P5DDI
3002             if(_DMS_Is_SourceFrameBaseInterlace(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].eScanType, RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].eFieldType))
3003             {
3004                 _DMS_DIP_GetFrameBaseInterlaceFieldType(&RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID]);
3005             }
3006 
3007             if(_DMS_Is_SourceInterlace(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].eScanType))
3008             {
3009                 DIP3DDISetting.bEnableDI = TRUE;
3010                 DIP3DDISetting.enDI_Field = _DMS_DIP_GetDIPDiDataFMT(u32Window, RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].eScanType, RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].eFieldType);
3011                 if(_DMS_Is_SourceFieldBaseInterlace(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].eScanType))
3012                 {
3013                     DIP3DDISetting.phyBotYBufAddr = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u32SrcLumaAddrI;
3014                     DIP3DDISetting.phyBotCBufAddr = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u32SrcChromaAddrI;
3015                     DIP3DDISetting.phyBotYBufAddr10Bits = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u32SrcLumaAddrI;
3016                     DIP3DDISetting.phyBotCBufAddr10Bits = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u32SrcChromaAddrI;
3017                 }
3018                 else
3019                 {
3020                     DIP3DDISetting.phyBotYBufAddr = DIPRWinPropertytoShow_EX.stDIPRProperty.u32YBufAddr;
3021                     DIP3DDISetting.phyBotCBufAddr = DIPRWinPropertytoShow_EX.stDIPRProperty.u32CBufAddr;
3022                     DIP3DDISetting.phyBotYBufAddr10Bits = DIPRWinPropertytoShow_EX.stDIPRProperty.u32YBufAddr;
3023                     DIP3DDISetting.phyBotCBufAddr10Bits = DIPRWinPropertytoShow_EX.stDIPRProperty.u32CBufAddr;
3024                 }
3025                 DIPRWinPropertytoShow_EX.stDIPR3DDISetting.stDipr3DDI_VerCtl.u32version=1;
3026                 DIPRWinPropertytoShow_EX.stDIPR3DDISetting.stDipr3DDI_VerCtl.u32size=sizeof(ST_DIP_DI_SETTING);
3027                 DIPRWinPropertytoShow_EX.stDIPR3DDISetting.pDIPR3DDISetting = (void*)&DIP3DDISetting;
3028             }
3029             else
3030 #endif
3031             {
3032                 DIP3DDISetting.bEnableDI = FALSE;
3033                 DIPRWinPropertytoShow_EX.stDIPR3DDISetting.stDipr3DDI_VerCtl.u32version=1;
3034                 DIPRWinPropertytoShow_EX.stDIPR3DDISetting.stDipr3DDI_VerCtl.u32size=sizeof(ST_DIP_DI_SETTING);
3035                 DIPRWinPropertytoShow_EX.stDIPR3DDISetting.pDIPR3DDISetting = (void*)&DIP3DDISetting;
3036             }
3037 
3038             DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.stMFDec_VerCtl.u32version = 0;
3039             DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.stMFDec_VerCtl.u32size = sizeof(ST_XC_DIPR_PROPERTY_EX);
3040             DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.enMFDec_tile_mode = _DMS_DIP_MFDECTileTypeMapping(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].eTileMode);
3041             DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.phyLuma_FB_Base = (RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u32SrcLumaAddr);
3042             DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.phyChroma_FB_Base = (RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u32SrcChromaAddr);
3043             DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.u16FB_Pitch = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcPitch;
3044             DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.u16HSize = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth;
3045             DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.u16VSize = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight;
3046 
3047             if(_DMS_WindowSizeOverFHD(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth, RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight))
3048             {
3049                 DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.bMFDec_Enable = FALSE;
3050             }
3051             else
3052             {
3053                 DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.bMFDec_Enable = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].stMFdecInfo.bMFDec_Enable;
3054             }
3055 
3056             if(eAction == E_DMS_DIP_NORMAL)
3057             {
3058                 DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.u8MFDec_Select = DMS_MFDEC_NORMAL;
3059             }
3060             else if(eAction == E_DMS_DIP_CAPTURE)
3061             {
3062                 DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.u8MFDec_Select = DMS_MFDEC_CAPTURE;
3063             }
3064             DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.bUncompress_mode = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].stMFdecInfo.bUncompress_mode;
3065             DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.bBypass_codec_mode = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].stMFdecInfo.bBypass_codec_mode;
3066             DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.en_MFDecVP9_mode = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].stMFdecInfo.en_MFDecVP9_mode;
3067             DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.u16StartX = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].stMFdecInfo.u16StartX;
3068             DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.u16StartY = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].stMFdecInfo.u16StartY;
3069             DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.phyBitlen_Base = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].stMFdecInfo.phyBitlen_Base;
3070             DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.u16Bitlen_Pitch = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].stMFdecInfo.u16Bitlen_Pitch;
3071         }
3072         else
3073         {
3074             //Case: DIP Replace GE Rendering
3075             RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPRFmt = RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPWFmt;
3076 
3077             //DIPR win setting
3078             DIPRWinPropertytoShow_EX.stDIPRProperty.enDataFmt = RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPRFmt;
3079             DIPRWinPropertytoShow_EX.stDIPRProperty.u16Width = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width;
3080             DIPRWinPropertytoShow_EX.stDIPRProperty.u16Height = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height;
3081             DIPRWinPropertytoShow_EX.stDIPRProperty.u16Pitch = _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPRFmt, RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelWidth);
3082 
3083             if(RES_DMS.bDIPWriteFirstAddr)
3084             {
3085                 DIPRWinPropertytoShow_EX.stDIPRProperty.u32YBufAddr = RES_DMS._stXC_DIPWinInfo[ u32Window].u32DIPDoubleBufStartMemAddr;
3086                 DIPRWinPropertytoShow_EX.stDIPRProperty.u32CBufAddr = RES_DMS._stXC_DIPWinInfo[ u32Window].u32DIPDoubleBufStartMemAddr;
3087             }
3088             else
3089             {
3090                 DIPRWinPropertytoShow_EX.stDIPRProperty.u32YBufAddr = RES_DMS._stXC_DIPWinInfo[ u32Window].u32DIPStartMemAddr;
3091                 DIPRWinPropertytoShow_EX.stDIPRProperty.u32CBufAddr = RES_DMS._stXC_DIPWinInfo[ u32Window].u32DIPStartMemAddr;
3092             }
3093         }
3094     }
3095 
3096 #if 0
3097     DMS_PRINTF("\033[34m bufID %d, Fmt %d, width %d, height %d, pitch %d, Yaddr 0x%llx, Caddr 0x%llx \033[0m\n",u16BufferID,DIPRWinPropertytoShow_EX.stDIPRProperty.enDataFmt,
3098         DIPRWinPropertytoShow_EX.stDIPRProperty.u16Width,DIPRWinPropertytoShow_EX.stDIPRProperty.u16Height,DIPRWinPropertytoShow_EX.stDIPRProperty.u16Pitch,DIPRWinPropertytoShow_EX.stDIPRProperty.u32YBufAddr,DIPRWinPropertytoShow_EX.stDIPRProperty.u32CBufAddr);
3099     //DMS_PRINTF("\033[34m  ========== u32YBufAddr10Bits[0x%llx] ========== \033[0m\n",DIPRWinPropertytoShow_EX.stDIPRProperty.u32YBufAddr10Bits);
3100     //DMS_PRINTF("\033[34m  ========== u32CBufAddr10Bits[0x%llx] ========== \033[0m\n",DIPRWinPropertytoShow_EX.stDIPRProperty.u32CBufAddr10Bits);
3101     //DMS_PRINTF("\033[34m  ========== u32version[%d] ========== \033[0m\n",DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.stMFDec_VerCtl.u32version);
3102     //DMS_PRINTF("\033[34m  ========== u32size[%d] ========== \033[0m\n",DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.stMFDec_VerCtl.u32size);
3103     //DMS_PRINTF("\033[34m  ========== enMFDec_tile_mode[%d] ========== \033[0m\n",DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.enMFDec_tile_mode);
3104     //DMS_PRINTF("\033[34m  ========== phyLuma_FB_Base[0x%llx] ========== \033[0m\n",DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.phyLuma_FB_Base);
3105     //DMS_PRINTF("\033[34m  ========== phyChroma_FB_Base[0x%llx] ========== \033[0m\n",DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.phyChroma_FB_Base);
3106     //DMS_PRINTF("\033[34m  ========== u16FB_Pitch[%d] ========== \033[0m\n",DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.u16FB_Pitch);
3107     //DMS_PRINTF("\033[34m  ========== u16HSize[%d] ========== \033[0m\n",DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.u16HSize);
3108     //DMS_PRINTF("\033[34m  ========== u16VSize[%d] ========== \033[0m\n",DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.u16VSize);
3109     //DMS_PRINTF("\033[34m  ========== bMFDec_Enable[%d] ========== \033[0m\n",DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.bMFDec_Enable);
3110     //DMS_PRINTF("\033[34m  ========== u8MFDec_Select[%d] ========== \033[0m\n",DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.u8MFDec_Select);
3111     //DMS_PRINTF("\033[34m  ========== bUncompress_mode[%d] ========== \033[0m\n",DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.bUncompress_mode);
3112     //DMS_PRINTF("\033[34m  ========== bBypass_codec_mode[%d] ========== \033[0m\n",DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.bBypass_codec_mode);
3113     //DMS_PRINTF("\033[34m  ========== en_MFDecVP9_mode[%d] ========== \033[0m\n",DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.en_MFDecVP9_mode);
3114     //DMS_PRINTF("\033[34m  ========== u16StartX[%d] ========== \033[0m\n",DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.u16StartX);
3115     //DMS_PRINTF("\033[34m  ========== u16StartY[%d] ========== \033[0m\n",DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.u16StartY);
3116     //DMS_PRINTF("\033[34m  ========== phyBitlen_Base[0x%llx] ========== \033[0m\n",DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.phyBitlen_Base);
3117     //DMS_PRINTF("\033[34m  ========== u16Bitlen_Pitch[%d] ========== \033[0m\n", DIPRWinPropertytoShow_EX.stDIPR_MFDecInfo.u16Bitlen_Pitch);
3118 #endif
3119 
3120     if(MApi_XC_DIP_SetDIPRProperty_EX)
3121     {
3122         MApi_XC_DIP_SetDIPRProperty_EX(&DIPRWinPropertytoShow_EX, u8DIPWindowID);
3123     }
3124     else
3125     {
3126         MApi_XC_DIP_SetDIPRProperty(&DIPRWinPropertytoShow_EX.stDIPRProperty, u8DIPWindowID);
3127     }
3128 
3129     return TRUE;
3130 }
3131 
_DMS_SetDIPWWindow(E_DMS_DIP_ACTION eAction,MS_U32 u32Window,MS_U16 u16BufferID)3132 static MS_BOOL _DMS_SetDIPWWindow(E_DMS_DIP_ACTION eAction, MS_U32 u32Window, MS_U16 u16BufferID)
3133 {
3134     DMS_GET_RES_PRI;
3135     MS_U8 u8DIPWindowID = RES_DMS.u8DIP_Window[eAction];
3136     ST_XC_DIP_WINPROPERTY DIPWinPropertytoShow;
3137     memset(&DIPWinPropertytoShow,0,sizeof(ST_XC_DIP_WINPROPERTY));
3138 
3139     DIPWinPropertytoShow.enSource = SCALER_DIP_SOURCE_TYPE_DRAM;
3140     DIPWinPropertytoShow.u8BufCnt = DMS_DIP_BUFFER_COUNT;
3141 
3142     if(eAction == E_DMS_DIP_NORMAL)
3143     {
3144         if(_DMS_Is_MVOPFlow(u32Window))
3145         {
3146             DIPWinPropertytoShow.u16Pitch = _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_MVOP].eDIPWFmt, RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_MVOP].u32PanelWidth);
3147             if(RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width > RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32width)
3148             {
3149                 //scaling up
3150                 DIPWinPropertytoShow.u16Width = RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32width;
3151             }
3152             else
3153             {
3154                 //scaling down
3155                 DIPWinPropertytoShow.u16Width = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width;
3156             }
3157 
3158             if(RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height > RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32height)
3159             {
3160                 //scaling up
3161                 DIPWinPropertytoShow.u16Height = RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32height;
3162             }
3163             else
3164             {
3165                 //scaling down
3166                 DIPWinPropertytoShow.u16Height = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height;
3167             }
3168 
3169             if(_DMS_Query_XC_Status(u32Window, DMS_XC_FREEZE))
3170             {
3171                 DIPWinPropertytoShow.u32BufStart = RES_DMS.u32MVOPFreezeAddress_pa;
3172                 DIPWinPropertytoShow.u32BufEnd = RES_DMS.u32MVOPFreezeAddress_pa + (RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPEndMemAddr - RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPStartMemAddr);
3173             }
3174             else
3175             {
3176                 if(RES_DMS.bDIPMVOPWriteFirstAddr)
3177                 {
3178                     DIPWinPropertytoShow.u32BufStart = RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPStartMemAddr;
3179                     DIPWinPropertytoShow.u32BufEnd = RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPEndMemAddr;
3180                 }
3181                 else
3182                 {
3183                     DIPWinPropertytoShow.u32BufStart = RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPDoubleBufStartMemAddr;
3184                     DIPWinPropertytoShow.u32BufEnd = RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPDoubleBufEndMemAddr;
3185                 }
3186             }
3187         }
3188         else
3189         {
3190             DIPWinPropertytoShow.u16Pitch = _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPWFmt, RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelWidth);
3191             if(u16BufferID < DMS_Invalid_ReadPointer_ID)
3192             {
3193                 if(_DMS_WindowSizeOverFHD(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth, RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight))
3194                 {
3195 #if (DMS_DIP_Support_HVSP == 0)
3196                     if(RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width > RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth / 2)
3197                     {
3198                         DIPWinPropertytoShow.u16Width = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth / 2;
3199                     }
3200                     else
3201 #endif
3202                     {
3203                         DIPWinPropertytoShow.u16Width = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width;
3204                     }
3205 
3206 #if (DMS_DIP_Support_HVSP == 0)
3207                     if(RES_DMS._stXC_DIPWinInfo[ u32Window].stDstWin.u32height > RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight / 2)
3208                     {
3209                         DIPWinPropertytoShow.u16Height = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight / 2;
3210                     }
3211                     else
3212 #endif
3213                     {
3214                         DIPWinPropertytoShow.u16Height = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height;
3215                     }
3216                 }
3217                 else
3218                 {
3219 #if (DMS_DIP_Support_HVSP == 0)
3220                     if(RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width > RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth)
3221                     {
3222                         DIPWinPropertytoShow.u16Width = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth;
3223                     }
3224                     else
3225 #endif
3226                     {
3227                         DIPWinPropertytoShow.u16Width = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width;
3228                     }
3229 
3230 #if (DMS_DIP_Support_HVSP == 0)
3231                     if(RES_DMS._stXC_DIPWinInfo[ u32Window].stDstWin.u32height > RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight)
3232                     {
3233                         DIPWinPropertytoShow.u16Height = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight;
3234                     }
3235                     else
3236 #endif
3237                     {
3238                         DIPWinPropertytoShow.u16Height = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height;
3239                     }
3240                 }
3241 
3242 #if (DMS_DIP_Support_HVSP == 0)
3243                 RES_DMS.bNeedGEstretch = FALSE;
3244 
3245                 if(((RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width > RES_DMS._stXC_DIPWinInfo[ u32Window].stCropWin.u32width) ||
3246                     (RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height > RES_DMS._stXC_DIPWinInfo[ u32Window].stCropWin.u32height)))
3247                 {
3248                     DIPWinPropertytoShow.u32BufStart = RES_DMS._stXC_DIPWinInfo[u32Window].u32GEStartMemAddr;
3249                     DIPWinPropertytoShow.u32BufEnd = RES_DMS._stXC_DIPWinInfo[u32Window].u32GEEndMemAddr;
3250                     RES_DMS.bNeedGEstretch = TRUE;
3251                 }
3252                 else if(RES_DMS.bDIPWriteFirstAddr)
3253 #else
3254                 if(RES_DMS.bDIPWriteFirstAddr)
3255 #endif
3256                 {
3257                     DIPWinPropertytoShow.u32BufStart = RES_DMS._stXC_DIPWinInfo[ u32Window].u32DIPStartMemAddr;
3258                     DIPWinPropertytoShow.u32BufEnd = RES_DMS._stXC_DIPWinInfo[ u32Window].u32DIPEndMemAddr;
3259                 }
3260                 else
3261                 {
3262                     DIPWinPropertytoShow.u32BufStart = RES_DMS._stXC_DIPWinInfo[ u32Window].u32DIPDoubleBufStartMemAddr;
3263                     DIPWinPropertytoShow.u32BufEnd = RES_DMS._stXC_DIPWinInfo[ u32Window].u32DIPDoubleBufEndMemAddr;
3264                 }
3265             }
3266             else
3267             {
3268                 DIPWinPropertytoShow.u16Width = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width;
3269                 DIPWinPropertytoShow.u16Height = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height;
3270 
3271                 if(RES_DMS.bDIPWriteFirstAddr)
3272                 {
3273                     DIPWinPropertytoShow.u32BufStart = RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPStartMemAddr;
3274                     DIPWinPropertytoShow.u32BufEnd = RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPEndMemAddr;
3275                 }
3276                 else
3277                 {
3278                     DIPWinPropertytoShow.u32BufStart = RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPDoubleBufStartMemAddr;
3279                     DIPWinPropertytoShow.u32BufEnd = RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPDoubleBufEndMemAddr;
3280                 }
3281             }
3282         }
3283     }
3284     else if(eAction == E_DMS_DIP_CAPTURE)
3285     {
3286         DIPWinPropertytoShow.u16Pitch = _DMS_DIP_CalcPitch(_DMS_DIP_Capture_ColorFmtMapping(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].enDIPDataFmt), RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32Width);
3287         if(_DMS_WindowSizeOverFHD(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth,RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight))
3288         {
3289 #if (DMS_DIP_Support_HVSP == 0)
3290             if(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32Width > RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth / 2)
3291             {
3292                 DIPWinPropertytoShow.u16Width = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth / 2;
3293             }
3294             else
3295 #endif
3296             {
3297                 DIPWinPropertytoShow.u16Width = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32Width;
3298             }
3299 #if (DMS_DIP_Support_HVSP == 0)
3300             if(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32Height > RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight / 2)
3301             {
3302                 DIPWinPropertytoShow.u16Height = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight / 2;
3303             }
3304             else
3305 #endif
3306             {
3307                 DIPWinPropertytoShow.u16Height = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32Height;
3308             }
3309         }
3310         else
3311         {
3312 #if (DMS_DIP_Support_HVSP == 0)
3313             if(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32Width > RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth)
3314             {
3315                 DIPWinPropertytoShow.u16Width = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth;
3316             }
3317             else
3318 #endif
3319             {
3320                 DIPWinPropertytoShow.u16Width = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32Width;
3321             }
3322 
3323 #if (DMS_DIP_Support_HVSP == 0)
3324             if(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32Height > RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight)
3325             {
3326                 DIPWinPropertytoShow.u16Height = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight;
3327             }
3328             else
3329 #endif
3330             {
3331                 DIPWinPropertytoShow.u16Height = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32Height;
3332             }
3333         }
3334 /*
3335 #if (DMS_DIP_Support_HVSP == 0)
3336         RES_DMS.bNeedGEstretch = FALSE;
3337 
3338         if(((RES_DMS._stXC_DIPCaptureWinInfo[u32Window].u32Width > RES_DMS._stXC_DIPWinInfo[ u32Window].stCropWin.u32width) ||
3339             (RES_DMS._stXC_DIPCaptureWinInfo[u32Window].u32Height > RES_DMS._stXC_DIPWinInfo[ u32Window].stCropWin.u32height)))
3340         {
3341             DIPWinPropertytoShow.u32BufStart = RES_DMS._stXC_DIPWinInfo[u32Window].u32GEStartMemAddr;
3342             DIPWinPropertytoShow.u32BufEnd = RES_DMS._stXC_DIPWinInfo[u32Window].u32GEEndMemAddr;
3343             RES_DMS.bNeedGEstretch = TRUE;
3344         }
3345         else
3346 #endif
3347 */
3348         {
3349 #if(DMS_DIP_Support_IMI == 0)
3350             switch(RES_DMSCAPTURE._stXC_DIPCaptureWin_RingBufferPointer[u32Window].u16WritePointer)
3351             {
3352                 case 0:
3353                     DIPWinPropertytoShow.u32BufStart = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32StartMemAddr;
3354                     DIPWinPropertytoShow.u32BufEnd = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32EndMemAddr;
3355                     break;
3356                 case 1:
3357                     DIPWinPropertytoShow.u32BufStart = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32SecondBufStartMemAddr;
3358                     DIPWinPropertytoShow.u32BufEnd = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32SecondBufEndMemAddr;
3359                     break;
3360                 case 2:
3361                     DIPWinPropertytoShow.u32BufStart = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32ThirdBufStartMemAddr;
3362                     DIPWinPropertytoShow.u32BufEnd = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32ThirdBufEndMemAddr;
3363                     break;
3364             }
3365 #else
3366             DIPWinPropertytoShow.u32BufEnd = 0x123456;  //Temp use
3367 #endif
3368         }
3369     }
3370     else
3371     {
3372         DIPWinPropertytoShow.u16Pitch = _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_MVOP].eDIPWFmt, RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_MVOP].u32PanelWidth);
3373         if(RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width > RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32width)
3374         {//scaling up
3375             DIPWinPropertytoShow.u16Width = RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32width;
3376         }
3377         else
3378         {//scaling down
3379             DIPWinPropertytoShow.u16Width = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width;
3380         }
3381 
3382         if(RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height > RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32height)
3383         {//scaling up
3384             DIPWinPropertytoShow.u16Height = RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32height;
3385         }
3386         else
3387         {//scaling down
3388             DIPWinPropertytoShow.u16Height = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height;
3389         }
3390 
3391         MS_PHY phyDiBufSize = RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPEndMemAddr - RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPStartMemAddr;
3392         DIPWinPropertytoShow.u32BufStart = _GetDIRingBufferAddr(u32Window,RES_DMSDI.u8DIRingBufferID);
3393         DIPWinPropertytoShow.u32BufEnd = DIPWinPropertytoShow.u32BufStart + phyDiBufSize;
3394     }
3395 
3396 #if 0
3397     DMS_PRINTF("\033[35m width %d, height %d, pitch %d, bufStart 0x%llx, bufEnd 0x%llx \033[0m\n",
3398         DIPWinPropertytoShow.u16Width,DIPWinPropertytoShow.u16Height,DIPWinPropertytoShow.u16Pitch,DIPWinPropertytoShow.u32BufStart,DIPWinPropertytoShow.u32BufEnd);
3399 #endif
3400 
3401     MApi_XC_DIP_SetDIPWinProperty(&DIPWinPropertytoShow, u8DIPWindowID);
3402     return TRUE;
3403 }
3404 
_DMS_SetDIPWindow(E_DMS_DIP_ACTION eAction,MS_U32 u32Window,MS_U16 u16BufferID)3405 static MS_BOOL _DMS_SetDIPWindow(E_DMS_DIP_ACTION eAction, MS_U32 u32Window, MS_U16 u16BufferID)
3406 {
3407     DMS_GET_RES_PRI;
3408     MS_U8 u8DIPWindowID = RES_DMS.u8DIP_Window[eAction];
3409 
3410     XC_SETWIN_INFO xc_dip_wininfotoShow;
3411     memset(&xc_dip_wininfotoShow,0,sizeof(XC_SETWIN_INFO));
3412 
3413     if(eAction != E_DMS_DIP_DI)
3414     {
3415         if(_DMS_Is_MVOPFlow(u32Window))
3416         {
3417             if(RES_DMS.gDMS_ScalingCondition & USE_2ND_BUFFER)
3418             {
3419                 RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth = DMS_FHD_Hszie;
3420                 RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight = DMS_FHD_Vszie;
3421             }
3422         }
3423     }
3424 
3425     // set DIP read window
3426     _DMS_SetDIPRWindow(eAction, u32Window, u16BufferID);
3427 
3428     if(eAction == E_DMS_DIP_CAPTURE)
3429     {
3430         // set tile mode
3431         //MApi_XC_DIP_Set420TileBlock(_DMS_DIP_TileTypeMapping(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].eTileMode),u8DIPWindowID);
3432         if(_DMS_WindowSizeOverFHD(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth, RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight))
3433         {
3434             MApi_XC_DIP_Set420TileBlock(_DMS_DIP_TileTypeMapping(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u8Src2ndBufferTileMode),u8DIPWindowID);
3435         }
3436         else
3437         {
3438             // set tile mode
3439             MApi_XC_DIP_Set420TileBlock(_DMS_DIP_TileTypeMapping(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].eTileMode),u8DIPWindowID);
3440         }
3441         // set Capture output tile
3442         if(_DMS_DIP_Capture_ColorFmtMapping(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].enDIPDataFmt) != DIP_DATA_FMT_YUV422)
3443         {
3444             MApi_XC_DIP_Set420TileBlock(_DMS_DIP_Capture_TileMapping(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].enTileBlock),u8DIPWindowID);
3445         }
3446 
3447         xc_dip_wininfotoShow.stCapWin.x = RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32x;
3448         xc_dip_wininfotoShow.stCapWin.y = RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32y;
3449         if(_DMS_WindowSizeOverFHD(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth,RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight))
3450         {
3451             xc_dip_wininfotoShow.stCapWin.width = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth / 2;
3452             xc_dip_wininfotoShow.stCapWin.height = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight / 2;
3453         }
3454         else
3455         {
3456             xc_dip_wininfotoShow.stCapWin.width = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth;
3457             xc_dip_wininfotoShow.stCapWin.height = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight;
3458         }
3459         xc_dip_wininfotoShow.bPreHCusScaling = TRUE;
3460         xc_dip_wininfotoShow.u16PreHCusScalingSrc = xc_dip_wininfotoShow.stCapWin.width;
3461         xc_dip_wininfotoShow.u16PreHCusScalingDst = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32Width;
3462 
3463         xc_dip_wininfotoShow.bPreVCusScaling = TRUE;
3464         xc_dip_wininfotoShow.u16PreVCusScalingSrc = xc_dip_wininfotoShow.stCapWin.height;
3465         xc_dip_wininfotoShow.u16PreVCusScalingDst = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32Height;
3466 
3467         if( (RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32Width > RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth) ||
3468             (RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32Height > RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight) )
3469         {
3470 #if (DMS_DIP_Support_HVSP == 1)
3471             MApi_XC_DIP_SetHVSP(TRUE, u8DIPWindowID);
3472 #else
3473             if(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32Width > RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth)
3474             {
3475                 xc_dip_wininfotoShow.u16PreHCusScalingDst = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth;
3476             }
3477             if(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32Height > RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight)
3478             {
3479                 xc_dip_wininfotoShow.u16PreVCusScalingDst = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight;
3480             }
3481 #endif
3482         }
3483 #if (DMS_DIP_Support_HVSP == 1)
3484         else
3485         {
3486             MApi_XC_DIP_SetHVSP(FALSE, u8DIPWindowID);
3487         }
3488 #endif
3489     }
3490     else
3491     {
3492         if(_DMS_IsCaptureWindowEnable(u32Window) &&
3493             RES_DMS.u8DIP_Window[E_DMS_DIP_CAPTURE] == RES_DMS.u8DIP_Window[E_DMS_DIP_NORMAL])
3494         {
3495             if(_DMS_Is_CaptureMode_OutputTile(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].enTileBlock))
3496             {
3497                 //Restore DIPW status
3498                 MApi_XC_DIP_Set420TileBlock(DIP_TILE_BLOCK_W_16_32, u8DIPWindowID);
3499             }
3500         }
3501         if(eAction == E_DMS_DIP_NORMAL)
3502         {
3503             if(u16BufferID < DMS_Invalid_ReadPointer_ID)
3504             {
3505                 if(_DMS_WindowSizeOverFHD(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth, RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight))
3506                 {
3507                     MApi_XC_DIP_Set420TileBlock(_DMS_DIP_TileTypeMapping(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u8Src2ndBufferTileMode),u8DIPWindowID);
3508                 }
3509                 else
3510                 {
3511                     // set tile mode
3512                     MApi_XC_DIP_Set420TileBlock(_DMS_DIP_TileTypeMapping(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].eTileMode),u8DIPWindowID);
3513                 }
3514             }
3515             else
3516             {
3517                 // set tile mode to NONE
3518                 MApi_XC_W2BYTEMSK(0x3616,0x0000,0x8000);
3519             }
3520         }
3521         else
3522         {
3523             // case E_DMS_DIP_DI, set tile mode
3524             MApi_XC_DIP_Set420TileBlock(_DMS_DIP_TileTypeMapping(RES_DMSDI._stXC_DIPDIInfo[u32Window][u16BufferID].eTileMode),u8DIPWindowID);
3525         }
3526 
3527         //Capture window
3528         if(_DMS_Is_MVOPFlow(u32Window))
3529         {
3530             //consider two case
3531             //1. P mode scaling down
3532             //    a. scaling from crop to dest, xc not scaling
3533             //2. I mode scaling down/up
3534             //    a. scaling from crop to dest, xc not scaling
3535             //    b. keep ratio crop to dest, xc scaling up
3536             xc_dip_wininfotoShow.stCapWin.x = RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32x;
3537             xc_dip_wininfotoShow.stCapWin.y = RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32y;
3538             xc_dip_wininfotoShow.stCapWin.width = RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32width;
3539             xc_dip_wininfotoShow.stCapWin.height = RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32height;
3540 
3541             xc_dip_wininfotoShow.bPreHCusScaling = TRUE;
3542             xc_dip_wininfotoShow.bPreVCusScaling = TRUE;
3543 
3544             _DMS_XC_SetCusScaling(&xc_dip_wininfotoShow,FALSE,
3545                 RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32width,
3546                 (RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width > RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32width)? RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32width : RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width,
3547                 RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32height,
3548                 (RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height > RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32height)? RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32height : RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height);
3549         }
3550         else
3551         {
3552             if(eAction == E_DMS_DIP_NORMAL)
3553             {
3554                 if(u16BufferID < DMS_Invalid_ReadPointer_ID)
3555                 {
3556                     xc_dip_wininfotoShow.stCapWin.x = RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32x;
3557                     xc_dip_wininfotoShow.stCapWin.y = RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32y;
3558                     if(_DMS_WindowSizeOverFHD(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth,RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight))
3559                     {
3560                         xc_dip_wininfotoShow.stCapWin.width = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth / 2;
3561                         xc_dip_wininfotoShow.stCapWin.height = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight / 2;
3562                     }
3563                     else
3564                     {
3565                         xc_dip_wininfotoShow.stCapWin.width = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth;
3566                         xc_dip_wininfotoShow.stCapWin.height = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight;
3567                     }
3568                     xc_dip_wininfotoShow.bPreHCusScaling = TRUE;
3569                     xc_dip_wininfotoShow.u16PreHCusScalingSrc = xc_dip_wininfotoShow.stCapWin.width;
3570                     xc_dip_wininfotoShow.u16PreHCusScalingDst = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width;
3571 
3572                     xc_dip_wininfotoShow.bPreVCusScaling = TRUE;
3573                     xc_dip_wininfotoShow.u16PreVCusScalingSrc = xc_dip_wininfotoShow.stCapWin.height;
3574                     xc_dip_wininfotoShow.u16PreVCusScalingDst = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height;
3575 
3576                     if( (RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width > RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth) ||
3577                         (RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height > RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight) )
3578                     {
3579 #if (DMS_DIP_Support_HVSP == 1)
3580                         MApi_XC_DIP_SetHVSP(TRUE, u8DIPWindowID);
3581 #else
3582                         if(RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width > RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth)
3583                         {
3584                             xc_dip_wininfotoShow.u16PreHCusScalingDst = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcWidth;
3585                         }
3586                         if(RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height > RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight)
3587                         {
3588                             xc_dip_wininfotoShow.u16PreVCusScalingDst = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].u16SrcHeight;
3589                         }
3590 #endif
3591                     }
3592 #if (DMS_DIP_Support_HVSP == 1)
3593                     else
3594                     {
3595                         MApi_XC_DIP_SetHVSP(FALSE, u8DIPWindowID);
3596                     }
3597 #endif
3598                 }
3599                 else
3600                 {
3601                     //Capture window
3602                     xc_dip_wininfotoShow.stCapWin.x = RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32x;
3603                     xc_dip_wininfotoShow.stCapWin.y = RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32y;
3604                     xc_dip_wininfotoShow.stCapWin.width = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width;
3605                     xc_dip_wininfotoShow.stCapWin.height = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height;
3606 
3607                     xc_dip_wininfotoShow.bPreHCusScaling = FALSE;
3608                     xc_dip_wininfotoShow.u16PreHCusScalingSrc = xc_dip_wininfotoShow.stCapWin.width;
3609                     xc_dip_wininfotoShow.u16PreHCusScalingDst = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width;
3610 
3611                     xc_dip_wininfotoShow.bPreVCusScaling = FALSE;
3612                     xc_dip_wininfotoShow.u16PreVCusScalingSrc = xc_dip_wininfotoShow.stCapWin.height;
3613                     xc_dip_wininfotoShow.u16PreVCusScalingDst = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height;
3614                 }
3615             }
3616         }
3617     }
3618 
3619 #if 0
3620     if(eAction == E_DMS_DIP_DI)
3621     {
3622         DMS_PRINTF("\033[34m  ========== Set Cap[%d %d %d %d] ========== \033[0m\n",xc_dip_wininfotoShow.stCapWin.x,xc_dip_wininfotoShow.stCapWin.y,
3623             xc_dip_wininfotoShow.stCapWin.width,xc_dip_wininfotoShow.stCapWin.height);
3624         DMS_PRINTF("\033[34m  ========== Set Scaling[%d %d %d %d] ========== \033[0m\n",xc_dip_wininfotoShow.u16PreHCusScalingSrc,xc_dip_wininfotoShow.u16PreHCusScalingDst,
3625             xc_dip_wininfotoShow.u16PreVCusScalingSrc,xc_dip_wininfotoShow.u16PreVCusScalingDst);
3626     }
3627     else
3628     {
3629         DMS_PRINTF("\033[34m  ========== Set Cap[%d %d %d %d] Tile %d -> %d ========== \033[0m\n",xc_dip_wininfotoShow.stCapWin.x,xc_dip_wininfotoShow.stCapWin.y,
3630             xc_dip_wininfotoShow.stCapWin.width,xc_dip_wininfotoShow.stCapWin.height,
3631             RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].eTileMode,
3632             _DMS_DIP_TileTypeMapping(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].eTileMode));
3633         DMS_PRINTF("\033[34m  ========== Set Scaling[%d %d %d %d] ========== \033[0m\n",xc_dip_wininfotoShow.u16PreHCusScalingSrc,xc_dip_wininfotoShow.u16PreHCusScalingDst,
3634             xc_dip_wininfotoShow.u16PreVCusScalingSrc,xc_dip_wininfotoShow.u16PreVCusScalingDst);
3635     }
3636 #endif
3637 
3638     MApi_XC_SkipWaitVsync(MAIN_WINDOW,TRUE);
3639     MApi_XC_DIP_SetWindow(&xc_dip_wininfotoShow,sizeof(XC_SETWIN_INFO),u8DIPWindowID);
3640     MApi_XC_SkipWaitVsync(MAIN_WINDOW,FALSE);
3641 
3642     // set DIP write window
3643     _DMS_SetDIPWWindow(eAction, u32Window, u16BufferID);
3644     return TRUE;
3645 }
3646 
3647 ////MVOP XC flow
3648 #define FLOW_CONDITION_4K           0x01
3649 #define FLOW_CONDITION_INTERLACE    0x02
3650 #define FLOW_CONDITION_SHRINK       0x04
3651 #define CONDITION_4K_WIDTH          3840
3652 #define CONDITION_4K_HEIGHT         2160
3653 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
_DMS_MVOP_Set_Flow(MS_U8 u8Id)3654 static MS_U8 _DMS_MVOP_Set_Flow(MS_U8 u8Id)
3655 {
3656     DMS_GET_RES_PRI;
3657     MS_U8 u8FlowCondition = 0;
3658     MS_BOOL bMVOPFromDIPDi = FALSE;
3659     if(RES_DMS._stXC_XCCropWinInfo.u32width >= CONDITION_4K_WIDTH && RES_DMS._stXC_XCCropWinInfo.u32height >= CONDITION_4K_HEIGHT)
3660     {
3661         u8FlowCondition |= FLOW_CONDITION_4K;
3662     }
3663     if((u8Id < DMS_Invalid_ReadPointer_ID) && (_DMS_Is_SourceInterlace(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u8Id].eScanType) == TRUE))
3664     {
3665         u8FlowCondition |= FLOW_CONDITION_INTERLACE;
3666     }
3667     if((RES_DMS._stXC_XCCropWinInfo.u32width > RES_DMS._stXC_XCDispWinInfo.u32width) &&
3668         (RES_DMS._stXC_XCCropWinInfo.u32height > RES_DMS._stXC_XCDispWinInfo.u32height))
3669     {
3670         u8FlowCondition |= FLOW_CONDITION_SHRINK;
3671     }
3672 
3673     if(u8FlowCondition & FLOW_CONDITION_4K)
3674     {
3675         //4K force from VDEC
3676         RES_DMS.eDMS_MVOPFlowCtrl = E_DMS_MVOP_FLOW_FROM_VDEC;
3677     }
3678     else if(u8FlowCondition & FLOW_CONDITION_INTERLACE)
3679     {
3680         //Interlace force From DIP
3681         RES_DMS.eDMS_MVOPFlowCtrl = E_DMS_MVOP_FLOW_FROM_DIP;
3682     }
3683     else
3684     {
3685         //P mode
3686         if(u8FlowCondition & FLOW_CONDITION_SHRINK)
3687         {
3688             //P mode shrink, from DIP
3689             //4K scaling down case contain in 4K case, use from VDEC
3690             RES_DMS.eDMS_MVOPFlowCtrl = E_DMS_MVOP_FLOW_FROM_DIP;
3691         }
3692         else
3693         {
3694             //P mode enlarge or the same, from VDEC
3695             RES_DMS.eDMS_MVOPFlowCtrl = E_DMS_MVOP_FLOW_FROM_VDEC;
3696         }
3697     }
3698 
3699     if(_DMS_Query_XC_Status(MVOP_WINDOW, DMS_XC_FREEZE))
3700     {
3701         DMS_PRINTF("[%s] freeze setting to DIP to MVOP flow\n",__FUNCTION__);
3702         RES_DMS.eDMS_MVOPFlowCtrl = E_DMS_MVOP_FLOW_FROM_DIP;
3703     }
3704 
3705 #if DEV_DI
3706     if(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u8Id].bIsAfterDiTask == TRUE)
3707     {
3708         DMS_PRINTF("[%s] Get After Di Buffer\n",__FUNCTION__);
3709         RES_DMS.eDMS_MVOPFlowCtrl = E_DMS_MVOP_FLOW_FROM_DIP;
3710         bMVOPFromDIPDi = TRUE;
3711     }
3712 #endif
3713 
3714     RES_DMS.bDMS_MVOPFlowFromDi = bMVOPFromDIPDi;
3715     return u8FlowCondition;
3716 }
3717 #endif
3718 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
_DMS_MVOP_SetConfig(MVOP_InputSel eInputCfg,MS_BOOL bYUV422,MS_U8 u8MIUSel)3719 static MS_BOOL _DMS_MVOP_SetConfig(MVOP_InputSel eInputCfg, MS_BOOL bYUV422, MS_U8 u8MIUSel)
3720 {
3721     DMS_GET_RES_PRI;
3722     MVOP_VidStat stMvopVidSt;
3723     MVOP_InputCfg stMvopInputCfg;
3724 
3725     // Structure initialization
3726     memset(&stMvopVidSt, 0, sizeof(MVOP_VidStat));
3727     memset(&stMvopInputCfg, 0, sizeof(MVOP_InputCfg));
3728 
3729     MDrv_MVOP_Init();
3730     MDrv_MVOP_Enable(FALSE); // Turn off MVOP before setting it
3731     if(E_MVOP_OK != MDrv_MVOP_MiuSwitch(u8MIUSel))
3732     {
3733         DMS_PRINTF("Cannot set MVOP MIU selection!\n");
3734         return FALSE;
3735     }
3736 
3737     //For IFrame-Decoder
3738     if(eInputCfg == MVOP_INPUT_DRAM)
3739     {
3740         stMvopInputCfg.u16HSize = RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_MVOP].u32PanelWidth;
3741         stMvopInputCfg.u16VSize = 1080;
3742         stMvopInputCfg.u32YOffset = 0;
3743         stMvopInputCfg.u32UVOffset = 0;
3744         stMvopInputCfg.bProgressive = TRUE;
3745         stMvopInputCfg.bUV7bit = FALSE;
3746         stMvopInputCfg.bField = FALSE;
3747         stMvopInputCfg.u16StripSize = RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_MVOP].u32PanelWidth;
3748         if (bYUV422 == TRUE)
3749         {
3750             stMvopInputCfg.bSD = FALSE;
3751             stMvopInputCfg.bYUV422 = FALSE;
3752             stMvopInputCfg.bDramRdContd = FALSE;
3753             stMvopInputCfg.b422pack = FALSE;
3754             //For H264 IFrame.
3755             MDrv_MVOP_SetTileFormat(E_MVOP_TILE_16x32);
3756         }
3757         else
3758         {
3759             stMvopInputCfg.bSD = TRUE;
3760             stMvopInputCfg.bYUV422 = TRUE;
3761             stMvopInputCfg.bDramRdContd = TRUE;
3762             stMvopInputCfg.b422pack = TRUE;
3763         }
3764     }
3765 
3766     if(E_MVOP_OK != MDrv_MVOP_SetInputCfg(eInputCfg, &stMvopInputCfg))
3767     {
3768         DMS_PRINTF("Set MVOP input config failed!");
3769         return FALSE;
3770     }
3771 
3772     MS_BOOL bHS = TRUE;
3773     MS_BOOL bXCGen = TRUE;
3774     MVOP_Handle stMvopHd = { E_MVOP_MODULE_MAIN };
3775     MDrv_MVOP_SetCommand(&stMvopHd, E_MVOP_CMD_SET_HANDSHAKE_MODE, &bHS);
3776     MDrv_MVOP_SetCommand(&stMvopHd, E_MVOP_CMD_SET_XC_GEN_TIMING, &bXCGen);
3777 
3778     stMvopVidSt.u16HorSize = RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_MVOP].u32PanelWidth;
3779     stMvopVidSt.u16VerSize = RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_MVOP].u32PanelWidth;
3780     stMvopVidSt.u16FrameRate = g_IPanel.DefaultVFreq()*100;
3781     stMvopVidSt.u8AspectRate = 0;
3782     stMvopVidSt.u8Interlace = FALSE;
3783 
3784     if(E_MVOP_OK != MDrv_MVOP_SetOutputCfg(&stMvopVidSt, FALSE))
3785     {
3786         DMS_PRINTF("Set MVOP output config failed!");
3787         return FALSE;
3788     }
3789     MDrv_MVOP_Enable(TRUE); // Enable MVOP, video pass to Scaler
3790     return TRUE;
3791 }
3792 #endif
_DMS_XC_SetConnect(INPUT_SOURCE_TYPE_t eInputSrcType)3793 static MS_BOOL _DMS_XC_SetConnect(INPUT_SOURCE_TYPE_t eInputSrcType)
3794 {
3795     MS_S16 s16PathId;
3796     MS_U8 u8Count = 0;
3797     XC_MUX_PATH_INFO PathInfo;
3798     XC_MUX_PATH_INFO AllPathInfo[MAX_SYNC_DATA_PATH_SUPPORTED];
3799 
3800     memset(&PathInfo, 0, sizeof(XC_MUX_PATH_INFO));
3801     PathInfo.Path_Type = PATH_TYPE_SYNCHRONOUS;
3802     PathInfo.src = eInputSrcType;
3803     PathInfo.dest = OUTPUT_SCALER_MAIN_WINDOW;
3804     PathInfo.SyncEventHandler = NULL;
3805     PathInfo.DestOnOff_Event_Handler = NULL;
3806     PathInfo.path_thread = NULL;
3807     PathInfo.dest_periodic_handler = NULL; //[FIXME] PQ_Adaptive
3808 
3809     memset(AllPathInfo, 0, sizeof(XC_MUX_PATH_INFO)*MAX_SYNC_DATA_PATH_SUPPORTED);
3810     u8Count = MApi_XC_Mux_GetPathInfo(AllPathInfo);
3811 
3812     if(u8Count > 0)
3813     {
3814         do{
3815             u8Count = u8Count - 1;
3816             if(AllPathInfo[u8Count].dest == PathInfo.dest)
3817             {
3818                 if(AllPathInfo[u8Count].src == (eInputSrcType))
3819                 {
3820                     DMS_PRINTF("eInputSrc %u was already connected to %u.\n", eInputSrcType, PathInfo.dest);
3821                     return TRUE;
3822                 }
3823                 else
3824                 {
3825                     if(-1 == MApi_XC_Mux_DeletePath(AllPathInfo[u8Count].src, AllPathInfo[u8Count].dest))
3826                     {
3827                         DMS_PRINTF(" Delete path fail: src = %d, dest = %d\n", AllPathInfo[u8Count].src, AllPathInfo[u8Count].dest);
3828                     }
3829                     break;
3830                 }
3831             }
3832         }while(u8Count>0);
3833     }
3834 
3835     s16PathId = MApi_XC_Mux_CreatePath(&PathInfo, sizeof(XC_MUX_PATH_INFO));
3836     if (s16PathId == -1)
3837     {
3838         DMS_PRINTF(" Create path fail, src = %d, dest = %d, your structure has wrong size with library \n", PathInfo.src, PathInfo.dest );
3839     }
3840     else
3841     {
3842         MApi_XC_Mux_EnablePath((MS_U16)s16PathId);
3843     }
3844 
3845     MApi_XC_SetInputSource(eInputSrcType, MAIN_WINDOW);
3846     MApi_XC_DisableInputSource(DISABLE, MAIN_WINDOW);
3847     return TRUE;
3848 }
3849 
_DMS_XC_SetDisconnect(INPUT_SOURCE_TYPE_t eInputSrcType)3850 static MS_BOOL _DMS_XC_SetDisconnect(INPUT_SOURCE_TYPE_t eInputSrcType)
3851 {
3852     E_DEST_TYPE eDest = OUTPUT_SCALER_MAIN_WINDOW;
3853 
3854     if(-1 == MApi_XC_Mux_DeletePath(eInputSrcType, eDest))
3855     {
3856           DMS_PRINTF(" [%s][%d]Delete path fail\n", __FUNCTION__, __LINE__);
3857           return FALSE;
3858     }
3859 
3860     return TRUE;
3861 }
3862 
3863 //Wait Apple's API
_DMS_MVOP_MFDEC_Patch(MS_BOOL bMFDecEnable)3864 static void _DMS_MVOP_MFDEC_Patch(MS_BOOL bMFDecEnable)
3865 {
3866     DMS_GET_RES_PRI;
3867     if(bMFDecEnable)
3868     {
3869         MApi_XC_Write2ByteMask(0x1014A8, 0x01,0x01); //enable
3870         MApi_XC_Write2ByteMask(0x1014AE,(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS.gDMS_MVOPShowBufferID].stMFdecInfo.phyBitlen_Base >> 3) & 0xFFFF,0xFFFF);
3871         MApi_XC_Write2ByteMask(0x1014B0,((RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS.gDMS_MVOPShowBufferID].stMFdecInfo.phyBitlen_Base >> 3)>>16) & 0x0FFF,0x0FFF);
3872         MApi_XC_Write2ByteMask(0x1014BC,(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS.gDMS_MVOPShowBufferID].stMFdecInfo.u16Bitlen_Pitch << 8), 0xFF00);
3873         MApi_XC_Write2ByteMask(0x101450, 0x20, 0x20); //h264 nfdec need 32x32
3874     }
3875     else
3876     {
3877         MApi_XC_Write2ByteMask(0x1014A8, 0x00,0x01); //disable
3878         MApi_XC_Write2ByteMask(0x101450, 0x00, 0x20); //undo h264 nfdec need 32x32
3879     }
3880 }
3881 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
_DMS_MVOP_CalcPitch(MS_U16 u16Width)3882 static MS_U16 _DMS_MVOP_CalcPitch(MS_U16 u16Width)
3883 {
3884     DMS_GET_RES_PRI;
3885     MS_U16 u16Pitch = 0;
3886     DMS_PRINTF("[%s] u16SrcWidth: %d\n",__FUNCTION__,u16Width);
3887     if(u16Width % 32 != 0)
3888     {
3889         u16Width = (((u16Width)/(32)+1) * (32));
3890         DMS_PRINTF("[%s] u16SrcWidth align to : %d\n",__FUNCTION__,u16Width);
3891     }
3892     if(RES_DMS.eDMS_MVOPFlowCtrl == E_DMS_MVOP_FLOW_FROM_VDEC)
3893     {
3894         //YUV420 pitch is Width / 8
3895         u16Pitch = u16Width / 8;
3896     }
3897     else
3898     {
3899         //YUV422 pitch is Width / 4
3900         u16Pitch = u16Width / 4;
3901     }
3902     return u16Pitch;
3903 }
3904 #endif
3905 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
_DMS_MVOP_SetPitch(MS_U16 u16Width)3906 static void _DMS_MVOP_SetPitch(MS_U16 u16Width)
3907 {
3908     MS_U16 u16Pitch = _DMS_MVOP_CalcPitch(u16Width);
3909     MApi_XC_Write2ByteMask(0x101440,((u16Pitch & 0xFF) << 8),0xFF00);
3910     MApi_XC_WriteByteMask(0x101430,(u16Pitch >> 8),0x03);
3911 }
3912 #endif
3913 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
_DMS_MVOP_SwitchPath(MS_U8 u8Id)3914 static void _DMS_MVOP_SwitchPath(MS_U8 u8Id)
3915 {
3916     DMS_GET_RES_PRI;
3917     MApi_XC_WriteByteMask(0x10144E,0x10,0x10);
3918 
3919     if(RES_DMS.eDMS_MVOPFlowCtrl == E_DMS_MVOP_FLOW_FROM_VDEC)
3920     {
3921         //MVOP Pitch from VDEC need get vdec source size
3922         //_DMS_MVOP_SetPitch(_stXC_XCCropWinInfo.width);
3923         _DMS_MVOP_SetPitch(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u8Id].u16SrcPitch);
3924         MApi_XC_Write2ByteMask(0x101440,0x00,0xB0);
3925     }
3926     else
3927     {
3928         //MVOP Pitch is DIP write pitch = DIPWinInfo.stDstWin
3929         _DMS_MVOP_SetPitch(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_MVOP].u32PanelWidth);
3930         MApi_XC_Write2ByteMask(0x101440,0xB0,0xB0);
3931     }
3932     MApi_XC_WriteByteMask(0x10144E,0x00,0x10);
3933 }
3934 #endif
3935 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
_DMS_DIP_SyncStoredSetting(void)3936 static void _DMS_DIP_SyncStoredSetting(void)
3937 {
3938     DMS_GET_RES_PRI;
3939     memcpy(&RES_DMS._stXC_DIPWinInfo[MVOP_WINDOW].stCropWin,&RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.stCropWin,sizeof(ST_DMS_WINDOW));
3940     memcpy(&RES_DMS._stXC_DIPWinInfo[MVOP_WINDOW].stDstWin,&RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.stDstWin,sizeof(ST_DMS_WINDOW));
3941     memcpy(&RES_DMS._stXC_XCDispWinInfo,&RES_DMS._stXC_XCDispWinInfo_DoubleBuffer,sizeof(ST_DMS_WINDOW));
3942     memcpy(&RES_DMS._stXC_XCCropWinInfo,&RES_DMS._stXC_XCCropWinInfo_DoubleBuffer,sizeof(ST_DMS_WINDOW));
3943     RES_DMS._stXC_DIPWinInfo[MVOP_WINDOW].u32DIPStartMemAddr = RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.u32DIPStartMemAddr;
3944     RES_DMS._stXC_DIPWinInfo[MVOP_WINDOW].u32DIPEndMemAddr = RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.u32DIPEndMemAddr;
3945     RES_DMS._stXC_DIPWinInfo[MVOP_WINDOW].u32DIPDoubleBufStartMemAddr = RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.u32DIPDoubleBufStartMemAddr;
3946     RES_DMS._stXC_DIPWinInfo[MVOP_WINDOW].u32DIPDoubleBufEndMemAddr = RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.u32DIPDoubleBufEndMemAddr;
3947     MS_U8 i = 0;
3948     for(i = 0; i < DMS_DI_RING_BUFFER; i++)
3949     {
3950         RES_DMS._stXC_DIPWinInfo[MVOP_WINDOW].phyDIPRingBufMemAddr[i] = RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.phyDIPRingBufMemAddr[i];
3951     }
3952     RES_DMS._stXC_DIPWinInfo[MVOP_WINDOW].u32RingBufferSize = RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.u32RingBufferSize;
3953 }
3954 #endif
3955 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
_DMS_XC_SetWindow_MVOP_SetPath(void * pInstance,MS_U16 u16ID)3956 static MS_BOOL _DMS_XC_SetWindow_MVOP_SetPath(void* pInstance, MS_U16 u16ID)
3957 {
3958     DMS_GET_RES_PRI;
3959     _DMS_DIP_SyncStoredSetting();
3960     MS_WINDOW_TYPE stMVOPWindow; //decribe how to set MVOP crop
3961     XC_SETWIN_INFO stXCSetWinInfo;
3962     memset(&stXCSetWinInfo, 0, sizeof(XC_SETWIN_INFO));
3963 
3964     stXCSetWinInfo.enInputSourceType = INPUT_SOURCE_DTV;
3965     MVOP_Timing mvop_timing;
3966     memset(&mvop_timing, 0, sizeof(MVOP_Timing));
3967     if(E_MVOP_OK != MDrv_MVOP_GetOutputTiming(&mvop_timing))
3968         DMS_PRINTF("MDrv_MVOP_GetOutputTiming failed!!\n");
3969 
3970     stXCSetWinInfo.bHDuplicate    = mvop_timing.bHDuplicate;
3971     stXCSetWinInfo.u16InputVTotal = mvop_timing.u16V_TotalCount;
3972     stXCSetWinInfo.u16DefaultHtotal = mvop_timing.u16H_TotalCount;
3973     stXCSetWinInfo.bInterlace     = mvop_timing.bInterlace;
3974 
3975     stXCSetWinInfo.u16InputVFreq = g_IPanel.DefaultVFreq();
3976     //cap Window
3977     stXCSetWinInfo.stCapWin.x = 0;
3978     stXCSetWinInfo.stCapWin.y = 0;
3979     stXCSetWinInfo.stCapWin.width = RES_DMS._stXC_XCCropWinInfo.u32width;
3980     stXCSetWinInfo.stCapWin.height = RES_DMS._stXC_XCCropWinInfo.u32height;
3981 
3982     //Crop / disp Window
3983     stXCSetWinInfo.stCropWin.x = 0;
3984     stXCSetWinInfo.stCropWin.y = 0;
3985     stXCSetWinInfo.stCropWin.width = RES_DMS._stXC_XCCropWinInfo.u32width;
3986     stXCSetWinInfo.stCropWin.height = RES_DMS._stXC_XCCropWinInfo.u32height;
3987 
3988     stXCSetWinInfo.stDispWin.x = RES_DMS._stXC_XCDispWinInfo.u32x;
3989     stXCSetWinInfo.stDispWin.y = RES_DMS._stXC_XCDispWinInfo.u32y;
3990     stXCSetWinInfo.stDispWin.width = RES_DMS._stXC_XCDispWinInfo.u32width;
3991     stXCSetWinInfo.stDispWin.height = RES_DMS._stXC_XCDispWinInfo.u32height;
3992 
3993     //-------------------------
3994     // customized pre scaling
3995     //-------------------------
3996     stXCSetWinInfo.bPreHCusScaling = TRUE;
3997     stXCSetWinInfo.u16PreHCusScalingSrc = RES_DMS._stXC_XCCropWinInfo.u32width;
3998     stXCSetWinInfo.u16PreHCusScalingDst = RES_DMS._stXC_XCCropWinInfo.u32width;
3999     stXCSetWinInfo.bPreVCusScaling = TRUE;
4000     stXCSetWinInfo.u16PreVCusScalingSrc = RES_DMS._stXC_XCCropWinInfo.u32height;
4001     stXCSetWinInfo.u16PreVCusScalingDst = RES_DMS._stXC_XCCropWinInfo.u32height;
4002 
4003     //customized Post scaling
4004     stXCSetWinInfo.bHCusScaling = TRUE;
4005     stXCSetWinInfo.bVCusScaling = TRUE;
4006     RES_DMS.eDMS_PreMVOPFlowCtrl = RES_DMS.eDMS_MVOPFlowCtrl;
4007     MS_U8 u8FlowCondition = _DMS_MVOP_Set_Flow(u16ID);
4008     DMS_PRINTF("\033[1;36m[%s] 4K:%s(2ndBuf:%s) I:%s shrink:%s(XC90:%s), Flow %s, ID %d\033[0m\n",__FUNCTION__,(u8FlowCondition & FLOW_CONDITION_4K)? "YES" : "NO",
4009         (RES_DMS.gDMS_ScalingCondition & USE_2ND_BUFFER)? "YES" : "NO",
4010         (u8FlowCondition & FLOW_CONDITION_INTERLACE)? "YES" : "NO",
4011         (u8FlowCondition & FLOW_CONDITION_SHRINK)? "YES" : "NO",
4012         (RES_DMS.gDMS_ScalingCondition & USE_XC_SCALING_DOWN)? "YES" : "NO",
4013         (RES_DMS.eDMS_MVOPFlowCtrl == E_DMS_MVOP_FLOW_FROM_VDEC)? "From VDEC" : "From DIP",
4014         u16ID);
4015 
4016     if(RES_DMS.eDMS_MVOPFlowCtrl == E_DMS_MVOP_FLOW_FROM_VDEC)
4017     {
4018         //Enlarge or the same case or XC force scaling down 4K to 90%up
4019         stMVOPWindow.x = RES_DMS._stXC_XCCropWinInfo.u32x;
4020         stMVOPWindow.y = RES_DMS._stXC_XCCropWinInfo.u32y;
4021         stMVOPWindow.width = RES_DMS._stXC_XCCropWinInfo.u32width;
4022         stMVOPWindow.height = RES_DMS._stXC_XCCropWinInfo.u32height;
4023         _DMS_XC_SetCusScaling(&stXCSetWinInfo,TRUE,
4024             RES_DMS._stXC_XCCropWinInfo.u32width, RES_DMS._stXC_XCDispWinInfo.u32width,
4025             RES_DMS._stXC_XCCropWinInfo.u32height, RES_DMS._stXC_XCDispWinInfo.u32height);
4026     }
4027     else
4028     {
4029         //From DIP
4030         stMVOPWindow.x = stMVOPWindow.y = 0;
4031         if(u8FlowCondition & FLOW_CONDITION_SHRINK)
4032         {
4033             stMVOPWindow.width = RES_DMS._stXC_DIPWinInfo[MVOP_WINDOW].stDstWin.u32width;
4034             stMVOPWindow.height = RES_DMS._stXC_DIPWinInfo[MVOP_WINDOW].stDstWin.u32height;
4035             if(RES_DMS._stXC_DIPWinInfo[MVOP_WINDOW].stDstWin.u32width < RES_DMS._stXC_XCDispWinInfo.u32width)
4036             {
4037                 //Shrink but for DIP pixel alignment, need enlarge a little by XC case
4038                 _DMS_XC_SetCusScaling(&stXCSetWinInfo,TRUE,
4039                     RES_DMS._stXC_DIPWinInfo[MVOP_WINDOW].stDstWin.u32width, RES_DMS._stXC_XCDispWinInfo.u32width,
4040                     RES_DMS._stXC_XCDispWinInfo.u32height, RES_DMS._stXC_XCDispWinInfo.u32height);
4041             }
4042             else
4043             {
4044                 _DMS_XC_SetCusScaling(&stXCSetWinInfo,TRUE,
4045                     RES_DMS._stXC_XCDispWinInfo.u32width, RES_DMS._stXC_XCDispWinInfo.u32width,
4046                     RES_DMS._stXC_XCDispWinInfo.u32height, RES_DMS._stXC_XCDispWinInfo.u32height);
4047             }
4048         }
4049         else
4050         {
4051             //From DIP but enlarge => DIP do Di and XC enlarge
4052             stMVOPWindow.width = RES_DMS._stXC_DIPWinInfo[MVOP_WINDOW].stCropWin.u32width;
4053             stMVOPWindow.height = RES_DMS._stXC_DIPWinInfo[MVOP_WINDOW].stCropWin.u32height;
4054             _DMS_XC_SetCusScaling(&stXCSetWinInfo,TRUE,
4055                 RES_DMS._stXC_XCCropWinInfo.u32width, RES_DMS._stXC_XCDispWinInfo.u32width,
4056                 RES_DMS._stXC_XCCropWinInfo.u32height, RES_DMS._stXC_XCDispWinInfo.u32height);
4057         }
4058     }
4059 #if DBG_DMS_LOG
4060     DMS_PRINTF("[%s] total: %d %d\n",__FUNCTION__,stXCSetWinInfo.u16DefaultHtotal,stXCSetWinInfo.u16InputVTotal);
4061     DMS_PRINTF("[%s] bInterlace: %d, VFreq %d\n",__FUNCTION__,stXCSetWinInfo.bInterlace,stXCSetWinInfo.u16InputVFreq);
4062     DMS_PRINTF("[%s] MVOP: %d %d, %d %d\n",__FUNCTION__,stMVOPWindow.x,stMVOPWindow.y,stMVOPWindow.width,stMVOPWindow.height);
4063     DMS_PRINTF("[%s] Capt: %d %d, %d %d\n",__FUNCTION__,stXCSetWinInfo.stCapWin.x,stXCSetWinInfo.stCapWin.y,stXCSetWinInfo.stCapWin.width,stXCSetWinInfo.stCapWin.height);
4064     DMS_PRINTF("[%s] Crop: %d %d, %d %d\n",__FUNCTION__,stXCSetWinInfo.stCropWin.x,stXCSetWinInfo.stCropWin.y,stXCSetWinInfo.stCropWin.width,stXCSetWinInfo.stCropWin.height);
4065     DMS_PRINTF("[%s] Disp: %d %d, %d %d\n",__FUNCTION__,stXCSetWinInfo.stDispWin.x,stXCSetWinInfo.stDispWin.y,stXCSetWinInfo.stDispWin.width,stXCSetWinInfo.stDispWin.height);
4066     DMS_PRINTF("[%s] Pre : %d -> %d, %d -> %d\n",__FUNCTION__,stXCSetWinInfo.u16PreHCusScalingSrc,stXCSetWinInfo.u16PreHCusScalingDst,stXCSetWinInfo.u16PreVCusScalingSrc,stXCSetWinInfo.u16PreVCusScalingDst);
4067     DMS_PRINTF("[%s] Post: %d -> %d, %d -> %d\n",__FUNCTION__,stXCSetWinInfo.u16HCusScalingSrc,stXCSetWinInfo.u16HCusScalingDst,stXCSetWinInfo.u16VCusScalingSrc,stXCSetWinInfo.u16VCusScalingDst);
4068 #endif
4069     if(_DMS_Query_XC_Status(MVOP_WINDOW, DMS_XC_FIRST_TIME_SETWINDOW))
4070     {
4071         MDrv_MVOP_SetStartPos(stMVOPWindow.x, stMVOPWindow.y);
4072         //[FIXME] C2 MVOP Driver Bug, H need set Y + H, wait Apple Fix
4073         MDrv_MVOP_SetImageWidthHight(stMVOPWindow.width, stMVOPWindow.height + stMVOPWindow.y);
4074 
4075         MDrv_MVOP_SetRegSizeFromMVD(FALSE);
4076         _DMS_MVOP_SwitchPath(RES_DMS.u8DIPReadytoCaptureID[MVOP_WINDOW]);
4077 
4078         DMS_PRINTF("[%s] Setwin: %d %d %d %d %d\n",__FUNCTION__,stXCSetWinInfo.bHDuplicate,stXCSetWinInfo.u16InputVTotal,
4079             stXCSetWinInfo.u16DefaultHtotal,stXCSetWinInfo.bInterlace,stXCSetWinInfo.u16InputVFreq);
4080 
4081         DMS_PRINTF("[%s] Setwin: (%d %d %d %d) (%d %d %d %d) (%d %d %d %d)\n",__FUNCTION__,stXCSetWinInfo.stCapWin.x,stXCSetWinInfo.stCapWin.y,
4082             stXCSetWinInfo.stCapWin.width,stXCSetWinInfo.stCapWin.height,stXCSetWinInfo.stCropWin.x,stXCSetWinInfo.stCropWin.y,
4083             stXCSetWinInfo.stCropWin.width,stXCSetWinInfo.stCropWin.height,stXCSetWinInfo.stDispWin.x,stXCSetWinInfo.stDispWin.y,
4084             stXCSetWinInfo.stDispWin.width,stXCSetWinInfo.stDispWin.height);
4085 
4086         MApi_XC_SkipWaitVsync(MAIN_WINDOW,TRUE);
4087         MApi_XC_SetWindow(&stXCSetWinInfo, sizeof(XC_SETWIN_INFO), MAIN_WINDOW);
4088         MApi_XC_SkipWaitVsync(MAIN_WINDOW,FALSE);
4089 ///Set XC for Virtual Box size
4090         MApi_XC_W2BYTE(REG_SC_BK12_0F_L,0x1000);
4091         MApi_XC_W2BYTE(REG_SC_BK12_17_L,0x1000);
4092         _DMS_Remove_XC_Status(MVOP_WINDOW, DMS_XC_FIRST_TIME_SETWINDOW);
4093         HAL_DMS_XC_DSSetConfig(pInstance);
4094         if(RES_DMS.eDMS_MVOPFlowCtrl == E_DMS_MVOP_FLOW_FROM_VDEC)
4095         {
4096             DMS_PRINTF("[%s] u16SrcWidth: %d %d\n",__FUNCTION__,u16ID,RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u16ID].u16SrcPitch);
4097             HAL_DMS_XC_DSSetMVOPPitch(pInstance, _DMS_MVOP_CalcPitch(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u16ID].u16SrcPitch));
4098             //HAL_DMS_XC_DSSetMVOPPitch(_DMS_MVOP_CalcPitch(stMVOPWindow.width));
4099         }
4100         else
4101         {
4102             HAL_DMS_XC_DSSetMVOPPitch(pInstance, _DMS_MVOP_CalcPitch(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_MVOP].u32PanelWidth));
4103         }
4104         HAL_DMS_XC_DSSetWin(pInstance, &stMVOPWindow, &stXCSetWinInfo,RES_DMS.eDMS_MVOPFlowCtrl);
4105     }
4106     else
4107     {
4108         //DS setwin
4109         if(RES_DMS.eDMS_MVOPFlowCtrl == E_DMS_MVOP_FLOW_FROM_VDEC)
4110         {
4111             if(_DMS_Query_XC_Status(MVOP_WINDOW, DMS_XC_SEQ_CHANGE_SIZE))
4112             {
4113                 DMS_PRINTF("[%s] VDEC SrcWidth: %d (to id %d) %d\n",__FUNCTION__,u16ID,RES_DMS.gu8DMS_Seq_Change_ID,RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS.gu8DMS_Seq_Change_ID].u16SrcPitch);
4114                 HAL_DMS_XC_DSSetMVOPPitch(pInstance, _DMS_MVOP_CalcPitch(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS.gu8DMS_Seq_Change_ID].u16SrcPitch));
4115             }
4116             else
4117             {
4118                 DMS_PRINTF("[%s] SrcWidth: %d %d\n",__FUNCTION__,u16ID,RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u16ID].u16SrcPitch);
4119                 HAL_DMS_XC_DSSetMVOPPitch(pInstance, _DMS_MVOP_CalcPitch(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u16ID].u16SrcPitch));
4120             }
4121         }
4122         else
4123         {
4124             DMS_PRINTF("[%s] DIP SrcWidth: %d (to id %d) %d\n",__FUNCTION__,u16ID,RES_DMS.gu8DMS_Seq_Change_ID,RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_MVOP].u32PanelWidth);
4125             HAL_DMS_XC_DSSetMVOPPitch(pInstance, _DMS_MVOP_CalcPitch(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_MVOP].u32PanelWidth));
4126         }
4127         HAL_DMS_XC_DSSetWin(pInstance, &stMVOPWindow, &stXCSetWinInfo,RES_DMS.eDMS_MVOPFlowCtrl);
4128     }
4129 
4130     return TRUE;
4131 }
4132 #endif
4133 ////MVOP XC flow
_DMS_DIP_Fire(E_DMS_DIP_ACTION eAction)4134 static MS_BOOL _DMS_DIP_Fire(E_DMS_DIP_ACTION eAction)
4135 {
4136     DMS_GET_RES_PRI;
4137     MS_U8 u8DIPWindowID = RES_DMS.u8DIP_Window[eAction];
4138 
4139     //enable DIP interrupt
4140     MApi_XC_DIP_EnaInt(BMASK((DMS_DIP_BUFFER_COUNT-1):0)&0xFF, TRUE, u8DIPWindowID);
4141 
4142     MApi_XC_DIP_ClearInt(BMASK((DMS_DIP_BUFFER_COUNT-1):0)&0xFF, u8DIPWindowID);
4143 
4144     // Enable DIPW
4145     MApi_XC_DIP_Ena(TRUE,u8DIPWindowID);
4146 
4147     // Enable DIPR softwave trigger
4148     MApi_XC_DIP_CapOneFrameFast(u8DIPWindowID);
4149     return TRUE;
4150 }
4151 
4152 #if (DMS_DIP_Support_HVSP == 0)
_DMS_NeedGEstretch(void * pInstance,MS_U32 u32Window)4153 static MS_BOOL _DMS_NeedGEstretch(void* pInstance, MS_U32 u32Window)
4154 {
4155     DMS_GET_RES_PRI;
4156     if(RES_DMS.bNeedGEstretch)
4157     {
4158         GFX_DrawRect stgfxDrawRect;
4159         stgfxDrawRect.srcblk.x = RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32x;
4160         stgfxDrawRect.srcblk.y = RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32y;
4161         stgfxDrawRect.srcblk.width = (RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32width> RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width)?
4162             RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width: RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32width;
4163         stgfxDrawRect.srcblk.height = (RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32height> RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height)?
4164             RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height: RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin.u32height;
4165 
4166         stgfxDrawRect.dstblk.x = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32x;
4167         stgfxDrawRect.dstblk.y = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32y;
4168         stgfxDrawRect.dstblk.width = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width;
4169         stgfxDrawRect.dstblk.height = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height;
4170         _DMS_GEBitblt(RES_DMS._stXC_DIPWinInfo[u32Window].u32GEStartMemAddr,
4171             _DMS_DIP_GetDispBufferAddress(pInstance, E_DMS_DIP_CLIENT_GOP, _DMS_DIP_GetBackgroundBufID(pInstance)),
4172             &stgfxDrawRect);
4173     }
4174     return TRUE;
4175 }
4176 #endif
4177 
_DMS_DIP_WaitWriteDone(E_DMS_DIP_ACTION eAction)4178 static MS_BOOL _DMS_DIP_WaitWriteDone(E_DMS_DIP_ACTION eAction)
4179 {
4180     DMS_GET_RES_PRI;
4181     MS_U8 u8DIPWindowID = RES_DMS.u8DIP_Window[eAction];
4182 
4183     MS_U32 u32StartTime = 0;
4184     u32StartTime = MsOS_GetSystemTime();
4185     while(MApi_XC_DIP_GetIntStatus(u8DIPWindowID) == 0)
4186     {
4187         if(MsOS_GetSystemTime() - u32StartTime > DMS_DIP_TIMEOUT)
4188         {
4189             DMS_PRINTF("\033[1;31m[%s] DIP %d Timeout!!!!!!!!!!!!!!!! \033[0m\n",__FUNCTION__, u8DIPWindowID);
4190             return FALSE;
4191         }
4192         MsOS_DelayTask(1);
4193     }
4194     return TRUE;
4195 }
4196 
_DMS_DIP_Flow_PrepareNextFrame(void * pInstance,E_DMS_DIP_ACTION eAction,MS_U32 u32Window,MS_U16 u16BufferID)4197 static void _DMS_DIP_Flow_PrepareNextFrame(void* pInstance, E_DMS_DIP_ACTION eAction, MS_U32 u32Window, MS_U16 u16BufferID)
4198 {
4199     DMS_GET_RES_PRI;
4200     MS_U8 u8DIPWindowID = RES_DMS.u8DIP_Window[eAction];
4201 
4202     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
4203     while(MApi_XC_DIP_GetResource(u8DIPWindowID) == E_APIXC_RET_FAIL)
4204     {
4205         MsOS_DelayTask(1);
4206     }
4207 
4208     //Disable BK1336 reg3[8]
4209     MApi_XC_W2BYTEMSK(REG_SC_BK36_03_L,0x0000,0x0100);
4210 
4211     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
4212 
4213     if(eAction == E_DMS_DIP_CAPTURE)
4214     {
4215         if(_DMS_Is_UVSwap(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].enColorFormat))
4216         {
4217             MApi_XC_DIP_SwapUV(TRUE ,u8DIPWindowID);
4218         }
4219         else
4220         {
4221             MApi_XC_DIP_SwapUV(FALSE ,u8DIPWindowID);
4222         }
4223 
4224         if(_DMS_Is_YCSwap(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].enColorFormat))
4225         {
4226             MApi_XC_DIP_SwapYC(TRUE ,u8DIPWindowID);
4227         }
4228         else
4229         {
4230             MApi_XC_DIP_SwapYC(FALSE ,u8DIPWindowID);
4231         }
4232 
4233         MApi_XC_DIP_SetOutputDataFmt(_DMS_DIP_Capture_ColorFmtMapping(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].enDIPDataFmt), u8DIPWindowID);
4234     }
4235     else
4236     {
4237         if(1)//_DMS_Is_MVOPFlow(u32Window) == FALSE)
4238         {
4239             MApi_XC_DIP_SwapUV(TRUE ,u8DIPWindowID);
4240         }
4241         else
4242         {
4243             MApi_XC_DIP_SwapUV(FALSE ,u8DIPWindowID);
4244         }
4245 
4246         if(_DMS_Is_MVOPFlow(u32Window) == FALSE)
4247         {
4248             MApi_XC_DIP_SetOutputDataFmt(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_MVOP].eDIPWFmt, u8DIPWindowID);
4249         }
4250         else
4251         {
4252             MApi_XC_DIP_SetOutputDataFmt(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPWFmt, u8DIPWindowID);
4253         }
4254     }
4255 
4256     MApi_XC_DIP_EnableR2Y(FALSE,u8DIPWindowID);
4257     MApi_XC_DIP_EnableY2R(FALSE,u8DIPWindowID);
4258 
4259     // set DIP read/write window
4260     _DMS_SetDIPWindow(eAction, u32Window, u16BufferID);
4261 
4262 #if DMS_DIP_Support_IMI
4263     if(eAction == E_DMS_DIP_CAPTURE)
4264     {
4265         MS_BOOL bEnable = TRUE;
4266         MApi_XC_DIP_SetConfig(E_XC_DIP_IMI_ENABLE, &bEnable, u8DIPWindowID);
4267     }
4268 #endif
4269 
4270     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
4271     // enable DIP
4272     _DMS_DIP_Fire(eAction);
4273 
4274 #if DMS_DIP_Support_IMI
4275     if(eAction == E_DMS_DIP_CAPTURE)
4276     {
4277         MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
4278         RES_DMSCAPTURE._stXC_IMICaptureInfo[u32Window].bCaptureRet = TRUE;
4279         if(RES_DMSCAPTURE.bIsFrameValid[u32Window][u16BufferID] == TRUE)
4280         {
4281             if(RES_DMSCAPTURE.u8frameRepeatCnt[u32Window][u16BufferID] == 0)
4282             {
4283                 RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u16PreviousWP = u16BufferID;
4284             }
4285         }
4286         MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
4287     }
4288 #endif
4289 
4290     // Wait DIP write done
4291     _DMS_DIP_WaitWriteDone(eAction);
4292 
4293     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
4294 #if (DMS_DIP_Support_HVSP == 0)
4295     if(_DMS_Is_MVOPFlow(u32Window) == FALSE)
4296     {
4297         _DMS_NeedGEstretch(pInstance, u32Window);
4298     }
4299 #endif
4300 
4301 #if DEV_PAUSE
4302     //if((_DMS_Is_MVOPFlow(u32Window) == TRUE) && (eAction == E_DMS_DIP_NORMAL))
4303     if(_DMS_Is_MVOPFlow(u32Window) == TRUE)
4304     {
4305         if(RES_DMS.gDMS_MVOPShowBufferID != DMS_Invalid_ReadPointer_ID)
4306         {
4307             RES_DMS.gDMS_MVOPRemoveBufferID = RES_DMS.gDMS_MVOPShowBufferID;
4308         }
4309         RES_DMS.gDMS_MVOPShowBufferID = u16BufferID;
4310     }
4311 #else
4312     //if((_DMS_Is_MVOPFlow(u32Window) == TRUE) && (eAction == E_DMS_DIP_NORMAL))
4313     if(_DMS_Is_MVOPFlow(u32Window) == TRUE)
4314     {
4315         RES_DMS._stXC_DIPPushInfo[u32Window][u16BufferID].bValid = FALSE;
4316 
4317         _DMS_VDEC_Frame_Release(u32Window,u16BufferID);
4318     }
4319 #endif
4320     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
4321 #if (DMS_DIP_Support_IMI == 0)
4322     MApi_XC_DIP_Ena(FALSE,u8DIPWindowID);
4323 #endif
4324     MApi_XC_DIP_ReleaseResource(u8DIPWindowID);
4325     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
4326 }
4327 
_DMS_VDEC_Flow_PrepareNextFrame(MS_U16 u16BufferID)4328 static void _DMS_VDEC_Flow_PrepareNextFrame(MS_U16 u16BufferID)
4329 {
4330     DMS_GET_RES_PRI;
4331     sync_print("prepare ID%d -> %d => ",u16BufferID,RES_DMS.gDMS_MVOPShowBufferID);
4332     if(RES_DMS.gDMS_MVOPShowBufferID != DMS_Invalid_ReadPointer_ID)
4333     {
4334         RES_DMS.gDMS_MVOPRemoveBufferID = RES_DMS.gDMS_MVOPShowBufferID;
4335     }
4336     RES_DMS.gDMS_MVOPShowBufferID = u16BufferID;
4337     //Process MFDEC //patch
4338     _DMS_MVOP_MFDEC_Patch(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS.gDMS_MVOPShowBufferID].stMFdecInfo.bMFDec_Enable);
4339 }
4340 
4341 //Load Setting for next sync (to sync out of task setting and CapturePushedFrame to the same)
_DMS_SyncSettingForNextFrame(void * pInstance)4342 static void _DMS_SyncSettingForNextFrame(void* pInstance)
4343 {
4344     DMS_GET_RES_PRI;
4345 #if (DMS_MAIN_WINDOW_FLOW_VERSION == 1)
4346     if(_DMS_Is_MVOPFlow(MVOP_WINDOW))
4347     {
4348         //Sync XC/MVOP setting by gu8DMS_SetXC_Status
4349         MS_U8 u8ID = RES_DMS.u8DIPReadytoCaptureID[MVOP_WINDOW];
4350 #if (DEV_DI == 1)
4351         if(gDMSDebug >= 1)
4352         {
4353             DMS_PRINTF("[%d] Main loop sync when Ring ID %d, u8ID %d\n",MsOS_GetSystemTime(),RES_DMSDI._bDiNowShowRingBufID,u8ID);
4354         }
4355 #endif
4356         if(u8ID < DMS_Invalid_ReadPointer_ID)
4357         {
4358             if(_DMS_Query_XC_Status(MVOP_WINDOW, DMS_XC_SEQ_CHANGE_SIZE | DMS_XC_RESET_WINDOW_SIZE | DMS_XC_SEQ_CHANGE_PI | DMS_XC_FREEZE_SETTING))
4359             {
4360 #if DBG_DMS_LOG
4361                 if(_DMS_Query_XC_Status(MVOP_WINDOW, DMS_XC_SEQ_CHANGE_SIZE) && (u8ID != RES_DMS.gu8DMS_Seq_Change_ID))
4362                 {
4363                     DMS_PRINTF("gu8DMS_SetXC_Status & DMS_XC_SEQ_CHANGE_SIZE && (u8DIPReadytoCaptureID[MVOP_WINDOW] < gu8DMS_Seq_Change_ID)  %d %d\n",RES_DMS.u8DIPReadytoCaptureID[MVOP_WINDOW], RES_DMS.gu8DMS_Seq_Change_ID);
4364                 }
4365 #endif
4366 #if (DEV_DI == 1)
4367                 if(gDMSDebug >= 1)
4368                 {
4369                     DMS_PRINTF("[%d] Sync setting for after Di case: RBID %d, FBID %d, xc_status 0x%x\n",MsOS_GetSystemTime(),RES_DMSDI._bDiNowShowRingBufID,u8ID,RES_DMS.gu8DMS_SetXC_Status[MVOP_WINDOW]);
4370                 }
4371 #endif
4372                 _DMS_XC_SetWindow_MVOP_SetPath(pInstance, u8ID);
4373 
4374                 //If VDEC to DIP path change for MVOP, Need clean all valid except u8DIPReadytoCaptureID[MVOP_WINDOW]
4375 #if DEV_PAUSE
4376 
4377 #else
4378                 if((RES_DMS.eDMS_PreMVOPFlowCtrl != RES_DMS.eDMS_MVOPFlowCtrl) &&
4379                     (RES_DMS.eDMS_MVOPFlowCtrl == E_DMS_MVOP_FLOW_FROM_DIP))
4380                 {
4381                     MS_U8 i = 0;
4382                     for(i=0;i<DMS_DIP_QUEUEDEPTH;i++)
4383                     {
4384                        if(i != RES_DMS.u8DIPReadytoCaptureID[MVOP_WINDOW])
4385                        {
4386                             if(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][i].bValid == TRUE)
4387                             {
4388                                 printf("Change source clear frame ref!! id %d\n",i);
4389                                 _DMS_VDEC_Frame_Release(MVOP_WINDOW,i);
4390                             }
4391                             RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][i].bValid = FALSE;
4392                        }
4393                     }
4394                 }
4395 #endif
4396                 if(_DMS_Query_XC_Status(MVOP_WINDOW, DMS_XC_RESET_WINDOW_SIZE))
4397                 {
4398                     _DMS_Remove_XC_Status(MVOP_WINDOW, DMS_XC_RESET_WINDOW_SIZE);
4399                 }
4400                 if(_DMS_Query_XC_Status(MVOP_WINDOW, DMS_XC_SEQ_CHANGE_PI))
4401                 {
4402                     _DMS_Remove_XC_Status(MVOP_WINDOW, DMS_XC_SEQ_CHANGE_PI);
4403                 }
4404                 if((_DMS_Query_XC_Status(MVOP_WINDOW, DMS_XC_FREEZE_SETTING)) && (FALSE == _DMS_Query_XC_Status(MVOP_WINDOW, DMS_XC_FREEZE)))
4405                 {
4406                     _DMS_Remove_XC_Status(MVOP_WINDOW, DMS_XC_FREEZE_SETTING);
4407                 }
4408                 if(_DMS_Query_XC_Status(MVOP_WINDOW, DMS_XC_SEQ_CHANGE_SIZE))
4409                 {
4410                     _DMS_Remove_XC_Status(MVOP_WINDOW, DMS_XC_SEQ_CHANGE_SIZE);
4411                 }
4412             }
4413         }
4414         else if(DEV_PAUSE)
4415         {
4416             if(_DMS_Query_XC_Status(MVOP_WINDOW, DMS_XC_RESET_WINDOW_SIZE) && (_DMS_Query_XC_Status(MVOP_WINDOW, DMS_XC_SEQ_CHANGE_SIZE) == FALSE)
4417                 && (_DMS_Query_XC_Status(MVOP_WINDOW, DMS_XC_FIRST_TIME_SETWINDOW) == FALSE))
4418             {
4419                 DMS_PRINTF("\033[1;35m###[River][%s][%d]### pause reset window case\033[0m\n",__FUNCTION__,__LINE__);
4420                 if(_DMS_XC_SetWindow_MVOP_SetPath(pInstance, RES_DMS.gDMS_MVOPShowBufferID))
4421                 {
4422                     _DMS_Remove_XC_Status(MVOP_WINDOW, DMS_XC_RESET_WINDOW_SIZE);
4423                     RES_DMS._bForceSwitchBufferFlag = TRUE;
4424                 }
4425             }
4426         }
4427     }
4428 #endif  // #if (DMS_MAIN_WINDOW_FLOW_VERSION == 1)
4429     }
4430 
4431 #define PREPARE_FRAME_CHECK_COUNT 2
4432 #define DOUBLE_CHECK_LATENCY 2
_DMS_PrepareNextFrame(void * pInstance)4433 static void _DMS_PrepareNextFrame(void* pInstance)
4434 {
4435     DMS_GET_RES_PRI;
4436     MS_U8 u8CheckCount = 0;
4437     MS_U8 u8WindowID = 0;
4438     MS_U8 u8BufferID = DMS_Invalid_ReadPointer_ID;
4439     MS_U8 u8Flag = FALSE;
4440     MS_U8 u8Idx = 0;
4441     MS_BOOL bInOrder = TRUE;
4442     MS_U8 WindowZOrder_Local[DMS_MAX_WINDOW_NUM];
4443     MS_BOOL bWindowAlreadyUpdated[DMS_MAX_WINDOW_NUM];
4444     MS_BOOL bWindowReadyToDisp[DMS_MAX_WINDOW_NUM];
4445 
4446     for(u8Idx=0; u8Idx < DMS_MAX_WINDOW_NUM; u8Idx++)
4447     {
4448         WindowZOrder_Local[u8Idx] = RES_DMS.WindowZOrder[u8Idx];
4449         bWindowReadyToDisp[u8Idx] = FALSE;
4450         bWindowAlreadyUpdated[u8Idx] = FALSE;
4451 #if (DMS_MAIN_WINDOW_FLOW_VERSION == 0)
4452         if(u8Idx == MVOP_WINDOW)
4453               bWindowAlreadyUpdated[u8Idx] = TRUE;
4454 #endif
4455     }
4456 
4457     for(u8CheckCount = 0; u8CheckCount < PREPARE_FRAME_CHECK_COUNT; u8CheckCount++)
4458     {
4459         if(u8CheckCount == 0)
4460         {
4461 #if DEV_DI
4462             if(DEV_NEW_NEXT == 0 && RES_DMS.bDMS_MVOPFlowFromDi)
4463             {
4464                 MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
4465                 MsOS_DelayTask(10);
4466                 MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
4467             }
4468 #endif
4469             for(u8WindowID=0; u8WindowID < DMS_MAX_WINDOW_NUM; u8WindowID++)
4470             {
4471 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 0)
4472                 if(u8WindowID != MVOP_WINDOW)
4473 #endif
4474                 _DMS_GetNextInfo(u8WindowID, TRUE);
4475             }
4476             //Sync setting to next frame
4477             if(DEV_NEW_NEXT == 1)
4478             {
4479                 _DMS_SyncSettingForNextFrame(pInstance);
4480             }
4481             else if(RES_DMS.u8DIPReadytoCaptureID[MVOP_WINDOW] < DMS_Invalid_ReadPointer_ID)
4482             {
4483                 _DMS_SyncSettingForNextFrame(pInstance);
4484                 u8Flag = TRUE;
4485             }
4486         }
4487         else
4488         {
4489             //To use get next info twice, MVOP case need a delay
4490             //For example: Only Main window case, if first getnextinfo do not set u8DIPReadytoCaptureID by timing issue
4491             //must delay little time to getnextinfo twice
4492             for(u8WindowID=0; u8WindowID < DMS_MAX_WINDOW_NUM; u8WindowID++)
4493             {
4494                 if(DEV_NEW_NEXT)
4495                 {
4496                     continue;
4497                 }
4498 
4499                 if((_DMS_IsWindowUsed(u8WindowID) == TRUE) && (bWindowAlreadyUpdated[u8WindowID] == FALSE))
4500                 {
4501                     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
4502                     //DMS_PRINTF("MVOP window 2nd _DMS_GetNextInfo, delay 2ms\n");
4503                     MsOS_DelayTask(DOUBLE_CHECK_LATENCY);
4504                     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
4505                     break;
4506                 }
4507             }
4508 
4509             for(u8WindowID=0; u8WindowID < DMS_MAX_WINDOW_NUM; u8WindowID++)
4510             {
4511                 if(bWindowReadyToDisp[u8WindowID] == FALSE)
4512                 {
4513 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 0)
4514                     if(u8WindowID != MVOP_WINDOW)
4515 #endif
4516                     _DMS_GetNextInfo(u8WindowID, FALSE);
4517                 }
4518             }
4519 
4520             //Sync setting to next frame
4521             if(u8Flag == FALSE)
4522             {
4523                 _DMS_SyncSettingForNextFrame(pInstance);
4524             }
4525         }
4526 
4527         for(u8Idx=0; u8Idx < DMS_MAX_WINDOW_NUM; u8Idx++)
4528         {
4529             u8WindowID = WindowZOrder_Local[u8Idx];
4530             u8BufferID = RES_DMS.u8DIPReadytoCaptureID[u8WindowID];
4531             SKIP_DMS_MAIN_WINDOW_FLOW(u8WindowID);
4532 
4533             if(DEV_NEW_NEXT)
4534             {
4535                 bWindowReadyToDisp[u8WindowID] = TRUE;
4536             }
4537 
4538             if(bWindowAlreadyUpdated[u8WindowID] == FALSE)
4539             {
4540                 if(_DMS_IsCaptureWindowEnable(u8WindowID))
4541                 {
4542                     if(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u8WindowID].u32Visible == FALSE)
4543                     {
4544                         continue;
4545                     }
4546                 }
4547 
4548                 if(u8BufferID < DMS_Invalid_ReadPointer_ID)
4549                 {
4550                     bWindowReadyToDisp[u8WindowID] = TRUE;
4551                     if(_DMS_Is_MVOPFlow(u8WindowID) == TRUE || bInOrder == TRUE)
4552                     {
4553                         bWindowAlreadyUpdated[u8WindowID] = TRUE;
4554                     }
4555 
4556                     if(_DMS_Is_MVOPFlow(u8WindowID) && _DMS_Query_XC_Status(u8WindowID, DMS_XC_FREEZE))
4557                     {
4558                         if(_DMS_Query_XC_Status(u8WindowID, DMS_XC_FREEZE_SETTING))
4559                         {
4560                             _DMS_Remove_XC_Status(u8WindowID, DMS_XC_FREEZE_SETTING);
4561                             _DMS_DIP_Flow_PrepareNextFrame(pInstance,E_DMS_DIP_NORMAL,u8WindowID,u8BufferID);
4562                             DMS_PRINTF("Freeze By DIP capture!!!!!!!!!!!!!!!!!!!!!!\n");
4563                         }
4564                     }
4565                     else
4566                     {
4567                         if(_DMS_Is_MVOPFlow(u8WindowID))
4568                         {
4569                             if(RES_DMS.eDMS_MVOPFlowCtrl == E_DMS_MVOP_FLOW_FROM_VDEC)
4570                             {
4571                                 _DMS_VDEC_Flow_PrepareNextFrame(u8BufferID);
4572                             }
4573                             else if((RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][u8BufferID].bIsAfterDiTask == FALSE)
4574                                 && (RES_DMS.eDMS_MVOPFlowCtrl == E_DMS_MVOP_FLOW_FROM_DIP))
4575                             {
4576                                 _DMS_DIP_Flow_PrepareNextFrame(pInstance,E_DMS_DIP_NORMAL,u8WindowID,u8BufferID);
4577                             }
4578                         }
4579                         else
4580                         {
4581                             //First frame has been pushed since zorder or window was adjusted
4582                             if(_DMS_Query_XC_Status(u8WindowID, DMS_XC_UPDATE_FROM_VDEC))
4583                             {
4584                                 _DMS_Add_XC_Status(u8WindowID,  DMS_XC_FIRST_FRAME_FROM_VDEC);
4585                             }
4586 
4587                             if(RES_DMS.bIsWindowMute[u8WindowID] == FALSE)
4588                             {
4589                                 if(u8CheckCount == 0)
4590                                 {
4591                                     if(bInOrder == TRUE)
4592                                     {
4593                                         _DMS_DIP_Flow_PrepareNextFrame(pInstance,E_DMS_DIP_NORMAL,u8WindowID,u8BufferID);
4594                                     }
4595                                 }
4596                                 else
4597                                 {
4598                                     _DMS_DIP_Flow_PrepareNextFrame(pInstance,E_DMS_DIP_NORMAL,u8WindowID,u8BufferID);
4599                                 }
4600                             }
4601 
4602                         }
4603                     }
4604                 }
4605                 else if(u8BufferID == DMS_Invalid_ReadPointer_ID)
4606                 {
4607                     if(DEV_NEW_NEXT)
4608                     {
4609                         if(RES_DMS.bIsWindowMute[u8WindowID] == FALSE)
4610                         {
4611                             //case: bNeedUpdateFromVDEC == FALSE
4612                             if(_DMS_Query_XC_Status(u8WindowID, DMS_XC_UPDATE_FROM_VDEC) == FALSE)
4613                             {
4614                                 if(_DMS_IsWindowUsed(u8WindowID) == TRUE)
4615                                 {
4616                                     if(_DMS_Query_XC_Status(u8WindowID, DMS_XC_FIRST_FRAME_FROM_VDEC))
4617                                     {
4618                                         _DMS_GERendering(pInstance, u8WindowID);
4619                                     }
4620                                 }
4621                             }
4622                         }
4623                     }
4624                     else
4625                     {
4626                         if(_DMS_Is_MVOPFlow(u8WindowID) == FALSE)
4627                         {
4628                             if(u8CheckCount == 0)
4629                             {
4630                                 bInOrder = FALSE;
4631                             }
4632                             else
4633                             {
4634                                 if(RES_DMS.bIsWindowMute[u8WindowID] == FALSE)
4635                                 {
4636                                     //case: bNeedUpdateFromVDEC == FALSE
4637                                     if(_DMS_Query_XC_Status(u8WindowID, DMS_XC_UPDATE_FROM_VDEC) == FALSE)
4638                                     {
4639                                         if(_DMS_IsWindowUsed(u8WindowID) == TRUE)
4640                                         {
4641                                             if(_DMS_Query_XC_Status(u8WindowID, DMS_XC_FIRST_FRAME_FROM_VDEC))
4642                                             {
4643                                                 _DMS_GERendering(pInstance, u8WindowID);
4644                                             }
4645                                         }
4646                                     }
4647                                 }
4648                             }
4649                         }
4650 #if DEV_PAUSE
4651                         else if(_DMS_Is_MVOPFlow(u8WindowID) && RES_DMS._bForceSwitchBufferFlag == TRUE)
4652                         {
4653                             u8BufferID = RES_DMS.gDMS_MVOPShowBufferID;
4654                             //pause case
4655                             MS_U8 u8WorkID = DMS_Invalid_ReadPointer_ID;
4656                             if(u8BufferID != DMS_Invalid_ReadPointer_ID)
4657                             {
4658                                 bWindowAlreadyUpdated[u8WindowID] = TRUE;
4659                                 if((RES_DMS.eDMS_MVOPFlowCtrl == E_DMS_MVOP_FLOW_FROM_DIP))
4660                                 {
4661                                     DMS_PRINTF("\033[1;35m###[River][%s][%d]### DIP pause reset window case %d\033[0m\n",__FUNCTION__,__LINE__,u8WorkID);
4662                                     _DMS_DIP_Flow_PrepareNextFrame(pInstance,E_DMS_DIP_NORMAL,u8WindowID,u8BufferID);
4663                                 }
4664                                 else if((RES_DMS.eDMS_MVOPFlowCtrl == E_DMS_MVOP_FLOW_FROM_VDEC))
4665                                 {
4666                                     DMS_PRINTF("\033[1;35m###[River][%s][%d]### VDEC pause reset window case, ID %d\033[0m\n",__FUNCTION__,__LINE__,RES_DMS.gDMS_MVOPShowBufferID);
4667                                     _DMS_VDEC_Flow_PrepareNextFrame(u8BufferID);
4668                                 }
4669                             }
4670                             else
4671                             {
4672                                 RES_DMS._bForceSwitchBufferFlag = FALSE;
4673                                 DMS_PRINTF("\033[1;35m###[River][%s][%d]### pause reset window case, work ID %d error\033[0m\n",__FUNCTION__,__LINE__,u8BufferID);
4674                             }
4675                         }
4676 #endif
4677                     }
4678                 }
4679             }
4680         }
4681     }
4682 
4683     //DIP case only
4684     for(u8WindowID=1; u8WindowID < DMS_MAX_WINDOW_NUM; u8WindowID++)
4685     {
4686         if(_DMS_Query_XC_Status(u8WindowID, DMS_XC_FIRST_FRAME_FROM_VDEC) && _DMS_Query_XC_Status(u8WindowID, DMS_XC_UPDATE_FROM_VDEC))
4687         {
4688             _DMS_Remove_XC_Status(u8WindowID, DMS_XC_UPDATE_FROM_VDEC);
4689         }
4690     }
4691     nrp_sync_print(" End\n");
4692 }
4693 
4694 //Switch GOP Read Buffer
_DMS_SwitchGOPBuffer(void * pInstance)4695 static MS_BOOL _DMS_SwitchGOPBuffer(void* pInstance)
4696 {
4697     DMS_GET_RES_PRI;
4698     GOP_GwinInfo stGWin;
4699     if (_IsGwinAvailable() == FALSE)
4700     {
4701         return FALSE;
4702     }
4703     MApi_GOP_GWIN_GetWinInfo(RES_DMS.u8GOPGWinNum, &stGWin);
4704     MApi_GOP_GWIN_UpdateRegOnceEx2(GOP_NUM,TRUE,FALSE);
4705     //MApi_GOP_GWIN_UpdateRegOnce(TRUE);
4706     stGWin.u32DRAMRBlkStart = _DMS_DIP_GetDispBufferAddress(pInstance, E_DMS_DIP_CLIENT_GOP, _DMS_DIP_GetBackgroundBufID(pInstance));
4707     MApi_GOP_GWIN_SetWinInfo(RES_DMS.u8GOPGWinNum, &stGWin);
4708     MApi_GOP_GWIN_Enable(RES_DMS.u8GOPGWinNum, TRUE);//enable GWIN
4709     //MApi_GOP_GWIN_UpdateRegOnce(FALSE);
4710     MApi_GOP_GWIN_UpdateRegOnceEx2(GOP_NUM,FALSE,FALSE);
4711 #if DBG_FPS
4712     u32FPS_Switch_Counter[1]++;
4713 #endif
4714     RES_DMS.bDIPWriteFirstAddr = !RES_DMS.bDIPWriteFirstAddr;
4715 
4716     return TRUE;
4717 }
4718 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
_DMS_SwitchMVOPBufferByDIP(void * pInstance)4719 static MS_BOOL _DMS_SwitchMVOPBufferByDIP(void* pInstance)
4720 {
4721     DMS_GET_RES_PRI;
4722     if(_DMS_Query_XC_Status(MVOP_WINDOW, DMS_XC_FREEZE))
4723     {
4724         MS_PHY phyDIPoutAddr = RES_DMS.u32MVOPFreezeAddress_pa;
4725         HAL_DMS_XC_DSSetMVOPAddr(pInstance, phyDIPoutAddr,phyDIPoutAddr,TRUE);
4726         HAL_DMS_XC_DSFire(pInstance);
4727         return TRUE;
4728     }
4729     else
4730     {
4731         MS_PHY phyDIPoutAddr = 0;
4732 #if (DEV_DI == 1)
4733         if(RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS.u8DIPReadytoCaptureID[MVOP_WINDOW]].bIsAfterDiTask == TRUE)
4734         {
4735             if(RES_DMSDI._bDiReleaseShowRingBufID != INVALID_DI_RING_BUFFER_ID)
4736             {
4737                 RES_DMSDI._bDiReleaseShowRingBufID = INVALID_DI_RING_BUFFER_ID;
4738             }
4739             MS_U8 u8DiRingBufID = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS.u8DIPReadytoCaptureID[MVOP_WINDOW]].u8DiOutputRingBufferID;
4740             phyDIPoutAddr = _GetDIRingBufferAddr(MVOP_WINDOW,u8DiRingBufID);
4741             tempAddr = phyDIPoutAddr;
4742             di_sync_print("\033[1;34mBF R %d: 0x%x, 0x%llx , MainQ %d reading\033[0m\n",MsOS_GetSystemTime(),RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS.u8DIPReadytoCaptureID[MVOP_WINDOW]].u32PriData,phyDIPoutAddr,RES_DMS.u8DIPReadytoCaptureID[MVOP_WINDOW]);
4743             if(RES_DMSDI._bDiNowShowRingBufID == INVALID_DI_RING_BUFFER_ID)
4744             {
4745                 RES_DMSDI._bDiNowShowRingBufID = u8DiRingBufID;
4746             }
4747             else
4748             {
4749                 if(RES_DMSDI._bDiNowShowRingBufID != u8DiRingBufID)
4750                 {
4751                     if(gDMSDebug >= 2)
4752                     {
4753                         DMS_PRINTF("[%d] switch Ring ID from %d to %d => ",MsOS_GetSystemTime(),RES_DMSDI._bDiNowShowRingBufID,u8DiRingBufID);
4754                     }
4755 
4756                     RES_DMSDI._bDiReleaseShowRingBufID = RES_DMSDI._bDiNowShowRingBufID;
4757                     //printf("\033[1;32m[%d] Free  Ring Buffer %d\033[0m\n",MsOS_GetSystemTime(),RES_DMSDI._bDiReleaseShowRingBufID);
4758                     RES_DMSDI._bDiNowShowRingBufID = u8DiRingBufID;
4759                 }
4760             }
4761             if(gDMSDebug >= 2)
4762             {
4763                 DMS_PRINTF("[%d] now show after set DS table %d\n",MsOS_GetSystemTime(),RES_DMSDI._bDiNowShowRingBufID);
4764             }
4765             RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS.u8DIPReadytoCaptureID[MVOP_WINDOW]].bValid = FALSE;
4766         }
4767         else
4768 #endif
4769         {
4770             phyDIPoutAddr = _DMS_DIP_GetDispBufferAddress(pInstance, E_DMS_DIP_CLIENT_MVOP, (RES_DMS.bDIPMVOPWriteFirstAddr)? E_DMS_DIP_MULTIVIEW_BUF_ID_0 : E_DMS_DIP_MULTIVIEW_BUF_ID_1);
4771         }
4772 
4773         if(gDMSMVOPForceLookVDEC)
4774         {
4775             MS_PHY phyAddr0 = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS.u8DIPReadytoCaptureID[MVOP_WINDOW]].u32SrcLumaAddr;
4776             MS_PHY phyAddr1 = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS.u8DIPReadytoCaptureID[MVOP_WINDOW]].u32SrcChromaAddr;
4777             HAL_DMS_XC_DSSetMVOPAddr(pInstance, phyAddr0, phyAddr1,FALSE);
4778             HAL_DMS_XC_DSFire(pInstance);
4779         }
4780         else
4781         {
4782             HAL_DMS_XC_DSSetMVOPAddr(pInstance, phyDIPoutAddr,phyDIPoutAddr,TRUE);
4783             HAL_DMS_XC_DSFire(pInstance);
4784         }
4785 
4786 #if DBG_FPS
4787         static MS_U8 u8DIP_FPSID = 0xFF;
4788         if(u8DIP_FPSID != RES_DMS.u8DIPReadytoCaptureID[MVOP_WINDOW])
4789         {
4790             u32FPS_Switch_Counter[0]++;
4791         }
4792         u8DIP_FPSID = RES_DMS.u8DIPReadytoCaptureID[MVOP_WINDOW];
4793 #endif
4794 
4795 #if DEV_PAUSE
4796         if((RES_DMS.gDMS_MVOPRemoveBufferID != DMS_Invalid_ReadPointer_ID) && (RES_DMS.gDMS_MVOPRemoveBufferID != RES_DMS.gDMS_MVOPShowBufferID))
4797         {
4798             RES_DMS.bMVOPMarkRemoveBuffer = TRUE;
4799         }
4800 #endif
4801 
4802         RES_DMS.bDIPMVOPWriteFirstAddr = !RES_DMS.bDIPMVOPWriteFirstAddr;
4803 
4804         return TRUE;
4805     }
4806 }
4807 #endif
4808 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
_DMS_SwitchMVOPBufferByVDEC(void * pInstance)4809 static MS_BOOL _DMS_SwitchMVOPBufferByVDEC(void* pInstance)
4810 {
4811     DMS_GET_RES_PRI;
4812     //DMS_PRINTF(" setNexttoNow ");
4813     if(RES_DMS.gDMS_ScalingCondition & USE_2ND_BUFFER)
4814     {
4815         RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS.gDMS_MVOPShowBufferID].u32SrcLumaAddr = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS.gDMS_MVOPShowBufferID].phySrc2ndBufferLumaAddr;
4816         RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS.gDMS_MVOPShowBufferID].u32SrcChromaAddr = RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS.gDMS_MVOPShowBufferID].phySrc2ndBufferChromaAddr;
4817     }
4818 
4819     HAL_DMS_XC_DSSetMVOPAddr(pInstance, RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS.gDMS_MVOPShowBufferID].u32SrcLumaAddr,RES_DMS._stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS.gDMS_MVOPShowBufferID].u32SrcChromaAddr,FALSE);
4820     HAL_DMS_XC_DSFire(pInstance);
4821 
4822 #if DBG_FPS
4823     static MS_U8 u8VDEC_FPSID = 0xFF;
4824     if(u8VDEC_FPSID != RES_DMS.gDMS_MVOPShowBufferID)
4825     {
4826         u32FPS_Switch_Counter[0]++;
4827     }
4828     u8VDEC_FPSID = RES_DMS.gDMS_MVOPShowBufferID;
4829 #endif
4830     sync_print("set show ID%d, rm %d => ",RES_DMS.gDMS_MVOPShowBufferID, RES_DMS.gDMS_MVOPRemoveBufferID);
4831 
4832     //After Switch buffer, now we can remove raw buffer(set to valid false)
4833     //Mark remove only, do valid = FALSE in next vsync start to avoid MVOP double buffer timing issue
4834     if((RES_DMS.gDMS_MVOPRemoveBufferID != DMS_Invalid_ReadPointer_ID) && (RES_DMS.gDMS_MVOPRemoveBufferID != RES_DMS.gDMS_MVOPShowBufferID))
4835     {
4836         RES_DMS.bMVOPMarkRemoveBuffer = TRUE;
4837     }
4838     return TRUE;
4839 }
4840 #endif
_DMS_SwitchBuffer(void * pInstance)4841 static MS_BOOL _DMS_SwitchBuffer(void* pInstance)
4842 {
4843     //Need Switch MVOP first
4844     DMS_GET_RES_PRI;
4845 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
4846     if(_DMS_Is_MVOPFlow(MVOP_WINDOW))
4847     {
4848         MS_BOOL bRet = FALSE;
4849         if(RES_DMS.u8DIPReadytoCaptureID[MVOP_WINDOW] < DMS_Invalid_ReadPointer_ID || (TRUE == RES_DMS._bForceSwitchBufferFlag))
4850         {
4851             if(_DMS_Query_XC_Status(MVOP_WINDOW, DMS_XC_FREEZE) || (RES_DMS.eDMS_MVOPFlowCtrl == E_DMS_MVOP_FLOW_FROM_DIP))
4852             {
4853                 bRet = _DMS_SwitchMVOPBufferByDIP(pInstance);
4854             }
4855             else if(RES_DMS.eDMS_MVOPFlowCtrl == E_DMS_MVOP_FLOW_FROM_VDEC)
4856             {
4857                 bRet = _DMS_SwitchMVOPBufferByVDEC(pInstance);
4858             }
4859             RES_DMS._bForceSwitchBufferFlag = FALSE;
4860 
4861             if(bRet == TRUE && _DMS_Query_XC_Status(MVOP_WINDOW, DMS_XC_BLACK_SCREEN_BY_WINUSED))
4862             {
4863                 MS_BOOL bDIPWinUsed = _DMS_IsWindowUsed(MVOP_WINDOW);
4864                 Hal_DMS_XC_SetMute(pInstance, !bDIPWinUsed);
4865                 _DMS_Remove_XC_Status(MVOP_WINDOW, DMS_XC_BLACK_SCREEN_BY_WINUSED);
4866             }
4867         }
4868         else
4869         {
4870             //DMS_PRINTF("No switch _DMS_SwitchBuffer\n");
4871         }
4872     }
4873 #endif  //DMS_MAIN_WINDOW_FLOW_VERSION
4874     _DMS_SwitchGOPBuffer(pInstance);
4875 
4876     return TRUE;
4877 }
4878 
4879 #define DEV_PQ_FOD 0
4880 #if DEV_PQ_FOD
4881 #include "drvPQ.h"
4882 #include "drvPQ_cus.h"
4883 #endif
_Task_DMS_CapturePushedFrame(void)4884 static MS_BOOL _Task_DMS_CapturePushedFrame(void)
4885 {
4886     MS_U32 u32WaitEventFlag = BIT(0);
4887     MS_U32 u32Events = 0;
4888     void *pInstance = pTaskInstance;
4889 
4890     // coverity[no_escape]
4891     while(1)
4892     {
4893         MsOS_WaitEvent(XC_Vsync_Event_id, u32WaitEventFlag, &u32Events, E_OR_CLEAR, MSOS_WAIT_FOREVER);
4894         MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
4895         DMS_GET_RES_PRI;
4896 
4897         //gDMSMVOPForceLookVDEC = gDMS_externDebugFlag;
4898 #if DEV_PQ_FOD
4899         if(_DMS_Query_XC_Status(MVOP_WINDOW, DMS_XC_FIRST_TIME_SETWINDOW) == 0)
4900         {
4901             MDrv_PQ_AdaptiveTuning();
4902         }
4903 #endif
4904         sync_print("||>> ");
4905 #if DEV_DI
4906         //di_sync_print("\033[1;32mSHOW %d: 0x%x, 0x%llx , MainQ %d reading\033[0m\n",MsOS_GetSystemTime(),_stXC_DIPPushInfo[MVOP_WINDOW][RES_DMS.u8DIPReadytoCaptureID[MVOP_WINDOW]].u32PriData,tempAddr,RES_DMS.u8DIPReadytoCaptureID[MVOP_WINDOW]);
4907 #endif
4908         sync_print(" next buffer ID %d, now show ID%d => ",RES_DMS.u8DIPReadytoCaptureID[MVOP_WINDOW],RES_DMS.gDMS_MVOPShowBufferID);
4909 
4910         //(1) Check Display Buffer Flag
4911         _DMS_CheckDispBufFlag(pInstance);
4912 
4913         //(3) Prepare Next Frame to be Displayed
4914         _DMS_PrepareNextFrame(pInstance);
4915 
4916         //(5) Switch GOP Read Buffer
4917         _DMS_SwitchBuffer(pInstance);
4918 
4919         //clear Frame Ref
4920         //How to check release frame?
4921 
4922         sync_print("End \n");
4923         //DMS_PRINTF("End \n");
4924         if(0)//gDMS_externDebugFlag != 0)
4925         {
4926             DMS_PRINTF("#end\n");
4927             while(1);
4928         }
4929 
4930         if(gDMSDebug >= 3)
4931         {
4932             gDMSDebug++;
4933             if(gDMSDebug > 4)
4934                 gDMSDebug = 0;
4935         }
4936         MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
4937 
4938 #if DBG_FPS
4939         u32FPS_Show_Counter[0]++;
4940         u32FPS_Show_Counter[1]++;
4941 #endif
4942 
4943     }
4944     return TRUE;
4945 }
4946 
_DMS_VDEC_Frame_AddRef_CaptureMode(MS_U32 u32Window,MS_U16 u16BufID)4947 static MS_BOOL _DMS_VDEC_Frame_AddRef_CaptureMode(MS_U32 u32Window, MS_U16 u16BufID)
4948 {
4949     DMS_GET_RES_PRI;
4950 #if NEW_FLIP
4951     if(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32FrameIndex == DMS_INVALID_FRAME_ID)
4952     {
4953         //DMS_PRINTF("[%s] window %d, BufID %d, Release an invalid buffer\n",__FUNCTION__,u32Window,u16BufID);
4954         return TRUE;
4955     }
4956 
4957     VDEC_StreamId VdecStreamId;
4958     VDEC_EX_DispFrame VdecDispFrm;
4959     VdecStreamId.u32Version = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32VDECStreamVersion;
4960     VdecStreamId.u32Id = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32VDECStreamID;
4961     VdecDispFrm.u32Idx = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32FrameIndex;
4962     VdecDispFrm.u32PriData = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32PriData;
4963     VDEC_EX_Result eResult;
4964     eResult = MApi_VDEC_EX_DisplayFrame((VDEC_StreamId*)&VdecStreamId, &VdecDispFrm);
4965     if (eResult != E_VDEC_EX_OK)
4966     {
4967         DMS_PRINTF("[%s] %td %td, %td %td\n",__FUNCTION__,(ptrdiff_t)VdecStreamId.u32Version,(ptrdiff_t)VdecStreamId.u32Id,
4968             (ptrdiff_t)VdecDispFrm.u32Idx,(ptrdiff_t)VdecDispFrm.u32PriData);
4969         DMS_PRINTF("[%s] window %td, BufID %d, MApi_VDEC_EX_DisplayFrame return %d\n",__FUNCTION__,(ptrdiff_t)u32Window,u16BufID,eResult);
4970         return FALSE;
4971     }
4972     if(_DMS_Is_SourceFieldBaseInterlace(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].eScanType))
4973     {
4974         VdecStreamId.u32Version = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32VDECStreamVersion;
4975         VdecStreamId.u32Id = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32VDECStreamID;
4976         VdecDispFrm.u32Idx = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32FrameIndex_2nd;
4977         VdecDispFrm.u32PriData = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32PriData_2nd;
4978         VDEC_EX_Result eResult;
4979         eResult = MApi_VDEC_EX_DisplayFrame((VDEC_StreamId*)&VdecStreamId, &VdecDispFrm);
4980         if (eResult != E_VDEC_EX_OK)
4981         {
4982             DMS_PRINTF("[%s] %td %td, %td %td\n",__FUNCTION__,(ptrdiff_t)VdecStreamId.u32Version,(ptrdiff_t)VdecStreamId.u32Id,
4983                 (ptrdiff_t)VdecDispFrm.u32Idx,(ptrdiff_t)VdecDispFrm.u32PriData);
4984             DMS_PRINTF("[%s] window %td, BufID %d, 2nd Field, MApi_VDEC_EX_DisplayFrame return %d\n",__FUNCTION__,(ptrdiff_t)u32Window,u16BufID,eResult);
4985             return FALSE;
4986         }
4987     }
4988     //DMS_PRINTF("[AddRef] Frame[0x%x], PriData[0x%x]\n",_stXC_DIPPushInfo[u32Window][u16BufID].u32FrameIndex,_stXC_DIPPushInfo[u32Window][u16BufID].u32PriData);
4989     RES_DMSCAPTURE._stXC_LocalFrameRefCountCaptureMode[u32Window][u16BufID]++;
4990 
4991 #if DBG_FPS
4992     u32FPS_Add_Counter[u32Window]++;
4993 #endif
4994 #endif
4995     return TRUE;
4996 }
4997 
_DMS_VDEC_Frame_Release_CaptureMode(MS_U32 u32Window,MS_U16 u16BufID)4998 static MS_BOOL _DMS_VDEC_Frame_Release_CaptureMode(MS_U32 u32Window, MS_U16 u16BufID)
4999 {
5000     DMS_GET_RES_PRI;
5001 #if NEW_FLIP
5002     if(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32FrameIndex == DMS_INVALID_FRAME_ID)
5003     {
5004         //DMS_PRINTF("[%s] window %d, BufID %d, Release an invalid buffer\n",__FUNCTION__,u32Window,u16BufID);
5005         return TRUE;
5006     }
5007     if(RES_DMSCAPTURE._stXC_LocalFrameRefCountCaptureMode[u32Window][u16BufID] == 0)
5008     {
5009         //DMS_PRINTF("[%s] ~window %d, BufID %d, Release an invalid buffer\n",__FUNCTION__,u32Window,u16BufID);
5010         return TRUE;
5011     }
5012     RES_DMSCAPTURE._stXC_LocalFrameRefCountCaptureMode[u32Window][u16BufID]--;
5013     if(RES_DMSCAPTURE._stXC_LocalFrameRefCountCaptureMode[u32Window][u16BufID] == 0)
5014     {
5015         VDEC_StreamId VdecStreamId;
5016         VDEC_EX_DispFrame VdecDispFrm;
5017         VdecStreamId.u32Version = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32VDECStreamVersion;
5018         VdecStreamId.u32Id = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32VDECStreamID;
5019         VdecDispFrm.u32Idx = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32FrameIndex;
5020         VdecDispFrm.u32PriData = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32PriData;
5021 
5022         VDEC_EX_Result eResult;
5023         eResult = MApi_VDEC_EX_ReleaseFrame((VDEC_StreamId *) &VdecStreamId, &VdecDispFrm);
5024         if (eResult != E_VDEC_EX_OK)
5025         {
5026             DMS_PRINTF("[%s] %td %td, %td %td\n",__FUNCTION__,(ptrdiff_t)VdecStreamId.u32Version,(ptrdiff_t)VdecStreamId.u32Id,
5027                 (ptrdiff_t)VdecDispFrm.u32Idx,(ptrdiff_t)VdecDispFrm.u32PriData);
5028             DMS_PRINTF("[%s] window %td, BufID %d, MApi_VDEC_EX_ReleaseFrame return %d\n",__FUNCTION__,(ptrdiff_t)u32Window,u16BufID,eResult);
5029             return FALSE;
5030         }
5031         if(_DMS_Is_SourceFieldBaseInterlace(RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].eScanType))
5032         {
5033             VdecStreamId.u32Version = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32VDECStreamVersion;
5034             VdecStreamId.u32Id = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32VDECStreamID;
5035             VdecDispFrm.u32Idx = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32FrameIndex_2nd;
5036             VdecDispFrm.u32PriData = RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32PriData_2nd;
5037 
5038             VDEC_EX_Result eResult;
5039             eResult = MApi_VDEC_EX_ReleaseFrame((VDEC_StreamId *) &VdecStreamId, &VdecDispFrm);
5040             if (eResult != E_VDEC_EX_OK)
5041             {
5042                 DMS_PRINTF("[%s] %td %td, %td %td\n",__FUNCTION__,(ptrdiff_t)VdecStreamId.u32Version,(ptrdiff_t)VdecStreamId.u32Id,
5043                     (ptrdiff_t)VdecDispFrm.u32Idx,(ptrdiff_t)VdecDispFrm.u32PriData);
5044                 DMS_PRINTF("[%s] window %td, BufID %d, 2nd Field, MApi_VDEC_EX_ReleaseFrame return %d\n",__FUNCTION__,(ptrdiff_t)u32Window,u16BufID,eResult);
5045                 return FALSE;
5046             }
5047         }
5048         //DMS_PRINTF("[Release] Frame[0x%x], PriData[0x%x]\n",RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32FrameIndex,RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32PriData);
5049         if(_IsFrameRefCountZero(u32Window, u16BufID))
5050         {
5051             RES_DMS._stXC_DIPPushInfo[u32Window][u16BufID].u32FrameIndex = DMS_INVALID_FRAME_ID;
5052         }
5053     }
5054 
5055 #if DBG_FPS
5056     u32FPS_Release_Counter[u32Window]++;
5057 #endif
5058 #endif
5059     return TRUE;
5060 }
5061 
_DMS_Clear_VDEC_Frame_Ref_CaptureMode(MS_U32 u32Window,MS_U16 u16BufID)5062 static void _DMS_Clear_VDEC_Frame_Ref_CaptureMode(MS_U32 u32Window, MS_U16 u16BufID)
5063 {
5064     DMS_GET_RES_PRI;
5065     MS_U8 u8RefCounter = 0;
5066     for(u8RefCounter = 0; u8RefCounter < RES_DMSCAPTURE._stXC_LocalFrameRefCountCaptureMode[u32Window][u16BufID]; u8RefCounter++)
5067     {
5068         DMS_PRINTF("[%s] CaptureMode window %td release frame for WP %d ct %d\n",__FUNCTION__,(ptrdiff_t)u32Window,u16BufID,(u8RefCounter+1));
5069         _DMS_VDEC_Frame_Release_CaptureMode(u32Window,u16BufID);
5070     }
5071 }
5072 
5073 #if DEV_CAPMODE
5074 
5075 #if (DMS_DIP_Support_IMI == 0) //Fix with FrameBuffer mode variable
_Get_CaptureMode_NextBufferID(MS_U32 u32WindowID,MS_U16 u16CurID)5076 static MS_U16 _Get_CaptureMode_NextBufferID(MS_U32 u32WindowID, MS_U16 u16CurID)
5077 {
5078     DMS_GET_RES_PRI;
5079     MS_U16 u16NextID = DMS_CAPTUREWIN_RING_BUFFER;
5080 
5081     u16NextID = (u16CurID + 1) % DMS_CAPTUREWIN_RING_BUFFER;
5082     while(RES_DMSCAPTURE._stXC_CaptureRingBufRefCount[u32WindowID][u16NextID] != 0)
5083     {
5084         u16NextID = (u16NextID + 1) % DMS_CAPTUREWIN_RING_BUFFER;
5085     }
5086     return u16NextID;
5087 }
5088 
_Get_CaptureMode_NextRingBufferWritePointer(MS_U32 u32WindowID)5089 static MS_U16 _Get_CaptureMode_NextRingBufferWritePointer(MS_U32 u32WindowID)
5090 {
5091     DMS_GET_RES_PRI;
5092     RES_DMSCAPTURE._stXC_DIPCaptureWin_RingBufferPointer[u32WindowID].u16PreWritePointer = RES_DMSCAPTURE._stXC_DIPCaptureWin_RingBufferPointer[u32WindowID].u16WritePointer;
5093     return _Get_CaptureMode_NextBufferID(u32WindowID, RES_DMSCAPTURE._stXC_DIPCaptureWin_RingBufferPointer[u32WindowID].u16WritePointer);
5094 }
5095 #endif
5096 
_MarkIgnorableCaptureBufferID(MS_U32 u32WindowID,MS_U16 u16TargetID)5097 static void _MarkIgnorableCaptureBufferID(MS_U32 u32WindowID, MS_U16 u16TargetID)
5098 {
5099     DMS_GET_RES_PRI;
5100     MS_U16 u16CurID = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u16PreviousWP;
5101 
5102     while (u16CurID != u16TargetID)
5103     {
5104         if(RES_DMSCAPTURE.bIsFrameValid[u32WindowID][u16CurID] == TRUE)
5105         {
5106             _DMS_VDEC_Frame_Release_CaptureMode(u32WindowID, u16CurID);
5107             RES_DMSCAPTURE.bIsFrameValid[u32WindowID][u16CurID] = FALSE;
5108             RES_DMSCAPTURE.u8frameRepeatCnt[u32WindowID][u16CurID] = 0;
5109         }
5110         u16CurID = _GetNextBufferID(u16CurID);
5111     }
5112 }
5113 
_Task_DMS_CaptureMode_PushedFrame(void)5114 static MS_BOOL _Task_DMS_CaptureMode_PushedFrame(void)
5115 {
5116     MS_U32 u32WaitEventFlag = BIT(0)|BIT(1)|BIT(2)|BIT(3);
5117     MS_U32 u32Events = 0;
5118     MS_U8 u8WindowID = 0;
5119     MS_U8 u8BufferID = 0;
5120 #if (DMS_DIP_Support_IMI == 0)
5121     MS_U8 u8RepeatCnt = 0;
5122     MS_U16 u16NextWriteBufID = DMS_CAPTUREWIN_RING_BUFFER;
5123 #endif
5124     void *pInstance = pTaskInstance;
5125 
5126     // coverity[no_escape]
5127     while(1)
5128     {
5129         MsOS_WaitEvent(CaptureMode_Event_id, u32WaitEventFlag, &u32Events, E_OR_CLEAR, MSOS_WAIT_FOREVER);
5130         MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
5131         DMS_GET_RES_PRI;
5132 
5133         for(u8WindowID=0; u8WindowID<DMS_MAX_WINDOW_NUM; u8WindowID++)
5134         {
5135             if(u32Events & BIT(u8WindowID))
5136             {
5137                 u8BufferID = RES_DMSCAPTURE._stXC_DIPCapWin_WriteReadPointer[u8WindowID].u16ReadPointer;
5138                 _MarkIgnorableCaptureBufferID(u8WindowID, u8BufferID);
5139 #if (DMS_DIP_Support_IMI == 0)
5140                 MS_U8 u8FrameRepeat = RES_DMSCAPTURE.u8frameRepeatCnt[u8WindowID][u8BufferID];
5141                 for(u8RepeatCnt=0; u8RepeatCnt<u8FrameRepeat; u8RepeatCnt++)
5142 #else
5143                 if(RES_DMSCAPTURE.u8frameRepeatCnt[u8WindowID][u8BufferID] > 0)
5144 #endif
5145                 {
5146                     RES_DMSCAPTURE.u8frameRepeatCnt[u8WindowID][u8BufferID]--;
5147                     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u8WindowID].u32FrameCount++;
5148 #if (DMS_DIP_Support_IMI == 0)
5149                     u16NextWriteBufID = _Get_CaptureMode_NextRingBufferWritePointer(u8WindowID);
5150                     //printf("\033[36m === windowID: %d, BufferID: %d [%d]=== \033[0m\n", u8WindowID, u8BufferID, u16NextWriteBufID);
5151                     RES_DMSCAPTURE._stXC_DIPCaptureWin_RingBufferPointer[u8WindowID].u16WritePointer = u16NextWriteBufID;
5152                     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u8WindowID].stCaptureRingBuf[u16NextWriteBufID].u64Pts = RES_DMS._stXC_DIPPushInfo[u8WindowID][u8BufferID].u64Pts;
5153                     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u8WindowID].stCaptureRingBuf[u16NextWriteBufID].u32frameCount = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u8WindowID].u32FrameCount;
5154 #else
5155                     //printf("\033[36m === windowID: %d, BufferID: %d, Cnt %d === \033[0m\n", u8WindowID, u8BufferID, RES_DMSCAPTURE.u8frameRepeatCnt[u8WindowID][u8BufferID]);
5156                     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u8WindowID].stCaptureRingBuf[0].u64Pts = RES_DMS._stXC_DIPPushInfo[u8WindowID][u8BufferID].u64Pts;
5157                     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u8WindowID].stCaptureRingBuf[0].u32frameCount = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u8WindowID].u32FrameCount;
5158 #endif
5159                     _DMS_DIP_Flow_PrepareNextFrame(pInstance, E_DMS_DIP_CAPTURE,u8WindowID,u8BufferID);
5160 #if (DMS_DIP_Support_IMI == 0)
5161                     BUFFER_INFO stBufInfo;
5162                     stBufInfo = MApi_XC_DIP_GetBufInfo(RES_DMS.u8DIP_Window[E_DMS_DIP_CAPTURE]);
5163                     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u8WindowID].stCaptureRingBuf[u16NextWriteBufID].phyBufferCAddr = stBufInfo.u32CBuf[0];
5164                     RES_DMSCAPTURE.bIsRingBufAccessed[u16NextWriteBufID] = TRUE;
5165 #endif
5166                 }
5167 #if (DMS_DIP_Support_IMI)
5168                 if(RES_DMSCAPTURE.u8frameRepeatCnt[u8WindowID][u8BufferID] == 0)
5169 #endif
5170                 {
5171                     if(RES_DMSCAPTURE.bIsFrameValid[u8WindowID][u8BufferID] == TRUE)
5172                     {
5173                         RES_DMSCAPTURE.bIsFrameValid[u8WindowID][u8BufferID] = FALSE;
5174 #if (DMS_DIP_Support_IMI == 0)
5175                         RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u8WindowID].u16PreviousWP = u8BufferID;
5176 #endif
5177                         _DMS_VDEC_Frame_Release_CaptureMode(u8WindowID, u8BufferID);
5178                     }
5179                 }
5180            }
5181         }
5182         MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
5183     }
5184     return TRUE;
5185 }
5186 #endif
5187 
_DMS_TriggerToCaptureFrame(void * pInstance,MS_U16 u16WindowID)5188 static MS_BOOL _DMS_TriggerToCaptureFrame(void* pInstance, MS_U16 u16WindowID)
5189 {
5190     DMS_GET_RES_PRI;
5191     MS_U32 u32OutputRate = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u16WindowID].u32FrameRate;
5192     MS_U16 u16WritePointer = RES_DMSCAPTURE._stXC_DIPCapWin_WriteReadPointer[u16WindowID].u16WritePointer;
5193     MS_U32 u32InputRate = RES_DMS._stXC_DIPPushInfo[u16WindowID][u16WritePointer].u32FrameRate;
5194 
5195     if(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u16WindowID].bStartCountCapModeFRC != FALSE)
5196     {
5197         if(u32InputRate > 0)
5198         {
5199             MS_U8 u8DisplayCount = 0;
5200             RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u16WindowID].u32AccumuleOutputRate += u32OutputRate;
5201             RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u16WindowID].u8ReadPointerOffset++;
5202 
5203             if(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u16WindowID].u32AccumuleOutputRate >= u32InputRate)
5204             {
5205                 //DMS_PRINTF("\033[36m [%s] Out: %d, In: %d \033[0m\n",__FUNCTION__, RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u16WindowID].u32AccumuleOutputRate, u32InputRate);
5206                 u8DisplayCount = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u16WindowID].u32AccumuleOutputRate / u32InputRate;
5207                 RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u16WindowID].u32AccumuleOutputRate = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u16WindowID].u32AccumuleOutputRate % u32InputRate;
5208 
5209                 MS_U8 u8RP_Offset = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u16WindowID].u8ReadPointerOffset;
5210                 RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u16WindowID].u8ReadPointerOffset = 0;
5211                 MS_U8 i = 0;
5212                 MS_U16 u16CurReadPointer = RES_DMSCAPTURE._stXC_DIPCapWin_WriteReadPointer[u16WindowID].u16ReadPointer;
5213                 MS_U16 u16NextReadPointer = u16CurReadPointer;
5214                 for(i=0; i < u8RP_Offset; i++)
5215                 {
5216                     u16NextReadPointer = _GetNextBufferID(u16NextReadPointer);
5217                 }
5218                 if(RES_DMSCAPTURE.bIsFrameValid[u16WindowID][u16NextReadPointer])
5219                 {
5220                     while(RES_DMSCAPTURE.u8frameRepeatCnt[u16WindowID][u16CurReadPointer] != 0)
5221                     {
5222                         if(_DMS_IsCaptureWindowEnable(u16WindowID) == FALSE)
5223                         {
5224                             return FALSE;
5225                         }
5226                         MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
5227                         DMS_PRINTF("\033[31m [%s] win %d, CAPTURE Force block flip when %d RepeatCnt %d > 0\033[0m\n",__FUNCTION__, u16WindowID, u16CurReadPointer, RES_DMSCAPTURE.u8frameRepeatCnt[u16WindowID][u16CurReadPointer]);
5228                         MsOS_DelayTask(1);
5229                         MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
5230                     }
5231                     RES_DMSCAPTURE._stXC_DIPCapWin_WriteReadPointer[u16WindowID].u16ReadPointer = u16NextReadPointer;
5232                     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u16WindowID].u16NeedDeletePtr = u16NextReadPointer;
5233                     RES_DMSCAPTURE.u8frameRepeatCnt[u16WindowID][u16NextReadPointer] = u8DisplayCount;
5234                     //printf("\033[32m Read: %d, RepeatCnt: %d [%d]\033[0m\n", u16NextReadPointer, u8DisplayCount, u32InputRate);
5235                     return TRUE;
5236                 }
5237                 else
5238                 {
5239                     DMS_PRINTF("win %d, %d (Cnt: %d), next %d NOT Valid\n",u16WindowID, RES_DMSCAPTURE._stXC_DIPCapWin_WriteReadPointer[u16WindowID].u16ReadPointer, RES_DMSCAPTURE.u8frameRepeatCnt[u16WindowID][u16CurReadPointer], u16NextReadPointer);
5240                 }
5241             }
5242             else
5243             {
5244                 MS_U16 u16DeletePtr = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u16WindowID].u16NeedDeletePtr;
5245                 u16DeletePtr = _GetNextBufferID(u16DeletePtr);
5246                 _DMS_VDEC_Frame_Release_CaptureMode(u16WindowID, u16DeletePtr);
5247                 RES_DMSCAPTURE.bIsFrameValid[u16WindowID][u16DeletePtr] = FALSE;
5248                 RES_DMSCAPTURE.u8frameRepeatCnt[u16WindowID][u16DeletePtr] = 0;
5249                 RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u16WindowID].u16NeedDeletePtr = u16DeletePtr;
5250             }
5251         }
5252     }
5253     else
5254     {
5255         MS_U16 u16WritePoint = RES_DMSCAPTURE._stXC_DIPCapWin_WriteReadPointer[u16WindowID].u16WritePointer;
5256         if(RES_DMSCAPTURE.bIsFrameValid[u16WindowID][u16WritePoint])
5257         {
5258             MS_U8 i = 0;
5259             MS_BOOL bValid = FALSE;
5260             for(i = 0 ; i < (START_FRC_ACCUMULE_FRAME_COUNT - 1); i++)
5261             {
5262                 u16WritePoint = _GetPreviousBufferID(u16WritePoint);
5263                 if(RES_DMSCAPTURE.bIsFrameValid[u16WindowID][u16WritePoint])
5264                 {
5265                     bValid = TRUE;
5266                 }
5267                 else
5268                 {
5269                     bValid = FALSE;
5270                     break;
5271                 }
5272             }
5273             if(bValid)
5274             {
5275                 if(u32OutputRate > 0)
5276                 {
5277                     while(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u16WindowID].u32AccumuleOutputRate < u32InputRate)
5278                     {
5279                         RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u16WindowID].u32AccumuleOutputRate = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u16WindowID].u32AccumuleOutputRate + u32OutputRate;
5280                     }
5281                     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u16WindowID].u32AccumuleOutputRate = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u16WindowID].u32AccumuleOutputRate % u32InputRate;
5282                 }
5283                 else
5284                 {
5285                     DMS_PRINTF("\033[31m [%s] Error! Capture FrameRate <= 0 \033[0m\n",__FUNCTION__);
5286                 }
5287 
5288                 RES_DMSCAPTURE._stXC_DIPCapWin_WriteReadPointer[u16WindowID].u16ReadPointer = u16WritePoint;
5289                 DMS_PRINTF("win %d, %d \n",u16WindowID, RES_DMSCAPTURE._stXC_DIPCapWin_WriteReadPointer[u16WindowID].u16ReadPointer);
5290                 RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u16WindowID].u16PreviousWP = _GetPreviousBufferID(u16WritePoint);
5291                 RES_DMSCAPTURE.u8frameRepeatCnt[u16WindowID][u16WritePoint] = 1;
5292                 RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u16WindowID].bStartCountCapModeFRC = TRUE;
5293                 DMS_PRINTF("FRC Start \n");
5294                 return TRUE;
5295             }
5296         }
5297     }
5298     return FALSE;
5299 }
5300 
5301 #if DBG_FPS
_Task_DMS_FPS(void)5302 static MS_BOOL _Task_DMS_FPS(void)
5303 {
5304     MS_U32 t0[2] = {0};
5305     MS_U8 i = 0;
5306 // coverity[no_escape]
5307     while(1)
5308     {
5309         for(i = 0 ; i < 2; i++)
5310         {
5311             if(bFPS_Start[i])
5312             {
5313                 MS_U32 t1 = (MsOS_GetSystemTime() - t0[i]);
5314                 if((t1 > PRI_PERIOD) || (t0[i] == 0))
5315                 {
5316 #if NEW_FLIP
5317                     DMS_PRINTF("FPS(win%d): in %d, flip %d, out %d, Add/Rel %d/%d (%d/%d), Di %d. (time: %d).\n",i,
5318 #else
5319                     DMS_PRINTF("FPS(win%d): in %d, flip %d, out %d, pull (%d/%d). (time: %d)\n",i,
5320 #endif
5321                         ((u32FPS_Push_Counter[i] * 1000) / PRI_PERIOD),
5322                         ((u32FPS_Switch_Counter[i] * 1000) / PRI_PERIOD),
5323                         ((u32FPS_Show_Counter[i] * 1000) / PRI_PERIOD),
5324 #if NEW_FLIP
5325                         (u32FPS_Add_Counter[i]),
5326                         (u32FPS_Release_Counter[i]),
5327                         ((u32FPS_Add_Counter[i] * 1000) / PRI_PERIOD),
5328                         ((u32FPS_Release_Counter[i] * 1000) / PRI_PERIOD),
5329                         (u32FPS_Di_Counter[i]),
5330 
5331 #else
5332                         ((u32FPS_Pull_Counter[i] * 1000) / PRI_PERIOD),
5333                         ((u32FPS_Pull_NotReady_Counter[i] * 1000) / PRI_PERIOD),
5334 #endif
5335                         t1
5336                         );
5337                     if(((u32FPS_Push_Counter[i] * 1000) / PRI_PERIOD) > (((u32FPS_Switch_Counter[i] * 1000) / PRI_PERIOD) + 5))
5338                     {
5339                         //gDMS_externDebugFlag = 1;
5340                     }
5341                     else
5342                     {
5343                         //gDMS_externDebugFlag = 0;
5344                     }
5345                     t0[i] = MsOS_GetSystemTime();
5346                     u32FPS_Push_Counter[i] = 0;
5347                     u32FPS_Switch_Counter[i] = 0;
5348                     u32FPS_Show_Counter[i] = 0;
5349                     u32FPS_Pull_Counter[i] = 0;
5350                     u32FPS_Pull_NotReady_Counter[i] = 0;
5351                     u32FPS_Add_Counter[i] = 0;
5352                     u32FPS_Release_Counter[i] = 0;
5353                     u32FPS_Di_Counter[i] = 0;
5354                 }
5355             }
5356         }
5357         MsOS_DelayTask(5);
5358     }
5359     return TRUE;
5360 }
5361 #endif
5362 
_MDrv_DMS_CreateTask(void)5363 MS_BOOL _MDrv_DMS_CreateTask(void)
5364 {
5365 #ifndef MSOS_TYPE_NOS
5366     if(s32DMSTaskID == -1)
5367     {
5368         s32DMSTaskID = MsOS_CreateTask((TaskEntry)_Task_DMS_CapturePushedFrame,
5369                                     0,
5370                                     E_TASK_PRI_HIGH,
5371                                     TRUE,
5372                                     NULL,
5373                                     0,
5374                                     "DMS_Task");
5375 #if DBG_FPS
5376         s32DMSFPSTaskID = MsOS_CreateTask((TaskEntry)_Task_DMS_FPS,
5377                                     0,
5378                                     E_TASK_PRI_HIGH,
5379                                     TRUE,
5380                                     NULL,
5381                                     0,
5382                                     "DMS_FPS_Task");
5383 #endif
5384     }
5385     else
5386     {
5387         DMS_PRINTF("MsOS_ResumeTask(s32DMSTaskID) \n");
5388         MsOS_ResumeTask(s32DMSTaskID);
5389     }
5390 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
5391 #if DEV_DI
5392     if(s32DIPTaskID_Interlace == -1)
5393     {
5394         s32DIPTaskID_Interlace = MsOS_CreateTask((TaskEntry)_Task_CapturePushedInterlaceFrame,
5395                                     0,
5396                                     E_TASK_PRI_HIGH,
5397                                     TRUE,
5398                                     NULL,
5399                                     0,
5400                                     "DMS_IModeFrame_Task");
5401     }
5402     else
5403     {
5404         DMS_PRINTF("MsOS_ResumeTask(s32DIPTaskID_Interlace) \n");
5405         MsOS_ResumeTask(s32DIPTaskID_Interlace);
5406     }
5407 #endif
5408 #endif
5409 #if DEV_CAPMODE
5410     if(s32DIPTaskID_CaptureMode == -1)
5411     {
5412         s32DIPTaskID_CaptureMode = MsOS_CreateTask((TaskEntry)_Task_DMS_CaptureMode_PushedFrame,
5413                                     0,
5414                                     E_TASK_PRI_HIGH,
5415                                     TRUE,
5416                                     NULL,
5417                                     0,
5418                                     "DMS_CaptureModeFrame_Task");
5419     }
5420     else
5421     {
5422         DMS_PRINTF("MsOS_ResumeTask(s32DIPTaskID_CaptureMode) \n");
5423         MsOS_ResumeTask(s32DIPTaskID_CaptureMode);
5424     }
5425 #endif
5426 
5427 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 0)
5428     if(s32MVOPTaskID == -1)
5429     {
5430         s32MVOPTaskID = MsOS_CreateTask((TaskEntry)_Task_DMS_SetMVOP,
5431                                     0,
5432                                     E_TASK_PRI_HIGH,
5433                                     TRUE,
5434                                     NULL,
5435                                     0,
5436                                     "DMS_SetMVOP_Task");
5437     }
5438     else
5439     {
5440         DMS_PRINTF("MsOS_ResumeTask(s32MVOPTaskID) \n");
5441         MsOS_ResumeTask(s32MVOPTaskID);
5442     }
5443     if(s32DisableBobTaskID == -1)
5444     {
5445         s32DisableBobTaskID = MsOS_CreateTask((TaskEntry)_Task_DMS_DisableBob_MainWin,
5446                                     0,
5447                                     E_TASK_PRI_HIGH,
5448                                     TRUE,
5449                                     NULL,
5450                                     0,
5451                                     "DMS_DisableBob_Task");
5452     }
5453     else
5454     {
5455         DMS_PRINTF("MsOS_ResumeTask(s32DisableBobTaskID) \n");
5456         MsOS_ResumeTask(s32DisableBobTaskID);
5457     }
5458 #endif
5459 #endif
5460     return TRUE;
5461 }
5462 
_MDrv_DMS_InvalidateAllQueue(void)5463 void _MDrv_DMS_InvalidateAllQueue(void)
5464 {
5465     DMS_GET_RES_PRI;
5466     MS_U8 u8WindowID = 0;
5467     MS_U8 u8BufferID = 0;
5468 
5469     for (u8WindowID = 0; u8WindowID < DMS_MAX_WINDOW_NUM; u8WindowID++)
5470     {
5471         for(u8BufferID=0;u8BufferID<DMS_DIP_QUEUEDEPTH;u8BufferID++)
5472         {
5473             RES_DMS._stXC_DIPPushInfo[u8WindowID][u8BufferID].bValid = FALSE;
5474             RES_DMS._stXC_DIPPushInfo[u8WindowID][u8BufferID].u32FrameIndex = DMS_INVALID_FRAME_ID;
5475             RES_DMS._stXC_DIPPushInfo[u8WindowID][u8BufferID].eScanType = E_DMS_VIDEO_SCAN_TYPE_MAX;
5476         }
5477     }
5478 }
5479 
_TimeToChangeGOPBuffer(void)5480 static MS_BOOL _TimeToChangeGOPBuffer(void)
5481 {
5482     DMS_GET_RES_PRI;
5483     MS_U16 u16OutVFreq = g_IPanel.DefaultVFreq() / 10;
5484     MS_U32 u32Count = 0;
5485 
5486     // Counter + 1 in each Vsync
5487     RES_DMS.u32VsyncCount++;
5488 
5489     u32Count = (RES_DMS.u32MaxOutputFrameRate * RES_DMS.u32VsyncCount) / u16OutVFreq;
5490 
5491     //reset loop
5492     if (RES_DMS.u32VsyncCount == u16OutVFreq)
5493     {
5494         RES_DMS.u32VsyncCount = 0;
5495         RES_DMS.u32GOPDispCount = 0;
5496 
5497         return TRUE;
5498     }
5499 
5500     if (u32Count > RES_DMS.u32GOPDispCount)
5501     {
5502         RES_DMS.u32GOPDispCount = u32Count;
5503         return TRUE;
5504     }
5505     else
5506     {
5507         return FALSE;
5508     }
5509 
5510 
5511 }
5512 
_DMS_EmbedXCISR(SC_INT_SRC enIntNum,void * pParam)5513 static void _DMS_EmbedXCISR(SC_INT_SRC enIntNum, void *pParam)
5514 {
5515     if (_TimeToChangeGOPBuffer() == TRUE)
5516     {
5517         MsOS_SetEvent (XC_Vsync_Event_id, 0x01);
5518     }
5519 }
5520 
_MDrv_DMS_MemData_Init(MS_PHY Address,MS_U32 size,EN_XC_DIP_DATA_FMT eDIPWColorFmt)5521 static MS_BOOL _MDrv_DMS_MemData_Init(MS_PHY Address, MS_U32 size, EN_XC_DIP_DATA_FMT eDIPWColorFmt)
5522 {
5523     if(eDIPWColorFmt == DIP_DATA_FMT_YUV422)
5524     {
5525 #if 0
5526         MApi_GFX_ClearFrameBufferByWord(Address, size, 0x80108010);
5527 #else
5528         //#define TRANSPARENT_YUYV    0x10361097
5529         MApi_GFX_ClearFrameBufferByWord(Address, size, DMS_DIP_MULTIVIEW_TRANSPARENT_COLOR);
5530 
5531         // Enable YUV422 Transparent Color
5532         // TODO, wait utopia API ready
5533         #if 1
5534         if(!(MApi_XC_ReadByte(0x120200 + (GOP_NUM * 0x300))&0x20))
5535         {
5536             MApi_XC_Write2ByteMask(0x120200 + (GOP_NUM * 0x300), BIT(5), BIT(5));
5537             MApi_XC_Write2ByteMask(0x12024C + (GOP_NUM * 0x300), 0x0000, 0xFFFF);
5538             MApi_XC_Write2ByteMask(0x12024E + (GOP_NUM * 0x300), 0x00, 0xFF);
5539         }
5540         #else
5541         ST_Transparent_Color stColor = {0};
5542 
5543         //Data in Dram: (0x36109710)
5544         stColor.color = TRANSPARENT_YUYV;
5545         MApi_GOP_GWIN_SetTransparentClr(1, GOPTRANSCLR_FMT3, &stColor);
5546         MApi_GOP_GWIN_EnableTransClr(GOPTRANSCLR_FMT3, ENABLE);
5547 
5548         #endif
5549 #endif
5550     }
5551     else
5552     {
5553         MApi_GFX_ClearFrameBuffer(Address, size, 0x00);
5554     }
5555 
5556     MApi_GFX_FlushQueue();
5557     return TRUE;
5558 }
5559 
_MDrv_DMS_OSD_Init(MS_U8 u8GOP,MS_PHY Address,EN_XC_DIP_DATA_FMT eDIPWColorFmt)5560 static MS_BOOL _MDrv_DMS_OSD_Init(MS_U8 u8GOP, MS_PHY Address, EN_XC_DIP_DATA_FMT eDIPWColorFmt)
5561 {
5562     DMS_GET_RES_PRI;
5563     MS_U16 pitch = 0;
5564     MS_U16 fbFmt = 0;
5565     static MS_U32 fbID;
5566 
5567     if(RES_DMS.bIsGOPInit == FALSE)
5568     {
5569         fbID = 0;
5570         GOP_InitInfo stGopInit;
5571         GFX_Config stGFXcfg;
5572         memset(&stGopInit, 0, sizeof(GOP_InitInfo));
5573         memset(&stGFXcfg, 0, sizeof(GFX_Config));
5574 
5575         // -Initial GE
5576         stGFXcfg.u8Miu = 0;
5577         stGFXcfg.u8Dither = FALSE;
5578         stGFXcfg.u32VCmdQSize = 0;
5579         stGFXcfg.u32VCmdQAddr = 0;
5580 
5581         stGFXcfg.bIsCompt = TRUE;
5582         stGFXcfg.bIsHK = TRUE;
5583         MApi_GFX_Init(&stGFXcfg);
5584         DMS_PRINTF("driver GE init ok\n");
5585 
5586         stGopInit.u16PanelWidth = g_IPanel.Width();
5587         stGopInit.u16PanelHeight = g_IPanel.Height();
5588         stGopInit.u16PanelHStr = g_IPanel.HStart();
5589 
5590         MS_U32 u32DIPSize = (DMS_Frame_Buffer_Height * _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPWFmt, DMS_Frame_Buffer_Width));
5591         MS_U32 u32DIPSizeWithDouble = u32DIPSize * 2; //double buffer
5592 
5593         stGopInit.u32GOPRBAdr = RES_DMS.u32DIPAddress_pa[E_DMS_DIP_CLIENT_GOP];
5594         stGopInit.u32GOPRegdmaAdr = RES_DMS.u32DIPAddress_pa[E_DMS_DIP_CLIENT_GOP];
5595         stGopInit.u32GOPRBLen = (MS_U32)u32DIPSizeWithDouble;
5596         stGopInit.u32GOPRegdmaLen = (MS_U32)u32DIPSizeWithDouble;
5597         stGopInit.bEnableVsyncIntFlip = FALSE;
5598 
5599         if( GOP_API_SUCCESS != MApi_GOP_InitByGOP(&stGopInit, u8GOP) )
5600         {
5601              DMS_PRINTF("[%s][%d] MApi_GOP_Init failed", __FUNCTION__, __LINE__);
5602              return FALSE;
5603         }
5604 
5605         MApi_GOP_GWIN_SwitchGOP(u8GOP);//use GOP 0
5606         MApi_GOP_GWIN_EnableTransClr(GOPTRANSCLR_FMT0, FALSE);
5607 
5608         if(GOP_API_SUCCESS != MApi_GOP_GWIN_SetGOPDst(u8GOP, E_GOP_DST_OP0))
5609         {
5610              printf("[%s][%d] HD MApi_GOP_GWIN_SetGOPDst failed", __FUNCTION__, __LINE__);
5611              return FALSE;
5612         }
5613 
5614         MApi_GOP_GWIN_Set_STRETCHWIN(u8GOP, E_GOP_DST_OP0, 0, 0, stGopInit.u16PanelWidth, stGopInit.u16PanelHeight);
5615         MApi_GOP_GWIN_OutputColor_EX(u8GOP, GOPOUT_YUV);
5616 
5617         pitch = _DMS_DIP_CalcPitch((EN_XC_DIP_DATA_FMT)eDIPWColorFmt, RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelWidth);
5618 
5619         switch(eDIPWColorFmt)
5620         {
5621             case DIP_DATA_FMT_YUV422:
5622             default:
5623                 fbFmt = E_MS_FMT_YUV422;
5624                 break;
5625         }
5626 
5627         if(RES_DMS.u8GOPGWinNum != 0xFF)
5628         {
5629             MApi_GOP_GWIN_DeleteWin (RES_DMS.u8GOPGWinNum);
5630         }
5631         //for Kano temporary use
5632         MApi_GOP_MIUSel(u8GOP, E_GOP_SEL_MIU0);
5633 
5634         if(MApi_GOP_GWIN_Create32FBFrom3rdSurf(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelWidth, RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelHeight, fbFmt, Address, pitch, &fbID) != GOP_API_SUCCESS)
5635         {
5636             DMS_PRINTF("[%s][%d] DMS, MApi_GOP_GWIN_Create32FBFrom3rdSurf: failed to create FB \n", __FUNCTION__, __LINE__);
5637             return FALSE;
5638         }
5639 
5640         RES_DMS.u8GOPGWinNum = MApi_GOP_GWIN_CreateWin_Assign_32FB(u8GOP, fbID, 0, 0);
5641 
5642         if(_IsGwinAvailable() == FALSE)
5643         {
5644             return FALSE;
5645         }
5646 
5647         if( fbFmt == E_MS_FMT_ARGB8888 || fbFmt == E_MS_FMT_ARGB4444)
5648         {
5649             MApi_GOP_GWIN_SetBlending(RES_DMS.u8GOPGWinNum, true, 0xff);
5650         }
5651         else
5652         {
5653             MApi_GOP_GWIN_SetBlending(RES_DMS.u8GOPGWinNum, false, 0xff);
5654         }
5655 
5656         RES_DMS.bIsGOPInit = TRUE;
5657     }
5658     else
5659     {
5660         MS_U32 u32DIPSizeWithDouble = (DMS_Frame_Buffer_Height * _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPWFmt, DMS_Frame_Buffer_Width)) * 2;
5661         _MDrv_DMS_MemData_Init(RES_DMS.u32DIPAddress_pa[E_DMS_DIP_CLIENT_GOP], (MS_U32)u32DIPSizeWithDouble, DIP_DATA_FMT_YUV422);
5662 
5663         pitch = _DMS_DIP_CalcPitch((EN_XC_DIP_DATA_FMT)eDIPWColorFmt, RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelWidth);
5664 
5665         switch(eDIPWColorFmt)
5666         {
5667             case DIP_DATA_FMT_YUV422:
5668             default:
5669                 fbFmt = E_MS_FMT_YUV422;
5670                 break;
5671         }
5672 
5673         //for Kano temporary use
5674         MApi_GOP_MIUSel(u8GOP, E_GOP_SEL_MIU0);
5675 
5676         MApi_GOP_GWIN_SetGWinShared(RES_DMS.u8GOPGWinNum, TRUE);
5677 
5678         if(MApi_GOP_GWIN_Create32FBFrom3rdSurf(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelWidth, RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelHeight, fbFmt, Address, pitch, &fbID) != GOP_API_SUCCESS)
5679         {
5680             DMS_PRINTF("[%s][%d] DMS, MApi_GOP_GWIN_Create32FBbyStaticAddr2: failed to create FB \n", __FUNCTION__, __LINE__);
5681             return FALSE;
5682         }
5683         //Use existing GWin to re-mapping
5684         MApi_GOP_GWIN_CreateStaticWin_Assign_32FB(RES_DMS.u8GOPGWinNum, u8GOP, fbID, 0, 0);
5685 
5686         if(_IsGwinAvailable() == FALSE)
5687         {
5688             return FALSE;
5689         }
5690 
5691         if( fbFmt == E_MS_FMT_ARGB8888 || fbFmt == E_MS_FMT_ARGB4444)
5692         {
5693             MApi_GOP_GWIN_SetBlending(RES_DMS.u8GOPGWinNum, true, 0xff);
5694         }
5695         else
5696         {
5697             MApi_GOP_GWIN_SetBlending(RES_DMS.u8GOPGWinNum, false, 0xff);
5698         }
5699     }
5700 
5701     return TRUE;
5702 }
5703 
_MDrv_DMS_ZOrder_Init(void)5704 static void _MDrv_DMS_ZOrder_Init(void)
5705 {
5706     DMS_GET_RES_PRI;
5707     MS_U8 u8Window = 0;
5708     memset(RES_DMS.WindowZOrder, 0, sizeof(MS_U8) * DMS_MAX_WINDOW_NUM);
5709     memset(RES_DMS.WindowScore, 0, sizeof(MS_U8) * DMS_MAX_WINDOW_NUM);
5710 
5711     for(u8Window = 0; u8Window < DMS_MAX_WINDOW_NUM; u8Window++)
5712     {
5713         RES_DMS.WindowZOrder[u8Window] = u8Window;
5714     }
5715 }
5716 
5717 #if(DMS_DONT_USE_CMA == 1)
5718 struct CMA_Pool_Init_Param stDMSCMA_Pool_Init_PARAM[E_DMS_MEMORY_TYPE_MAX];
5719 #endif
5720 #define BPP_OF_YUV422 2
5721 #define BPP_OF_ARGB8888 4
_MDrv_DMS_Setup_CMA(void * pInstance,EN_DMS_MEMORY_TYPE enMemType,MS_U32 u32CMAHeapID,MS_PHY * phyOutAddr)5722 static MS_BOOL _MDrv_DMS_Setup_CMA(void* pInstance, EN_DMS_MEMORY_TYPE enMemType, MS_U32 u32CMAHeapID, MS_PHY* phyOutAddr)
5723 {
5724 #if(DMS_DONT_USE_CMA == 1)
5725     /* 1. do CMA_POOL_INIT */
5726     stDMSCMA_Pool_Init_PARAM[enMemType].heap_id     = u32CMAHeapID;
5727     stDMSCMA_Pool_Init_PARAM[enMemType].flags       = CMA_FLAG_MAP_VMA;
5728     if (stDMSCMA_Pool_Init_PARAM[enMemType].heap_id != DMS_INVALID_CMA_HEAP_ID)
5729     {
5730         MS_BOOL ret = MApi_CMA_Pool_Init(&stDMSCMA_Pool_Init_PARAM[enMemType]);
5731         if(ret == FALSE)
5732         {
5733             DMS_PRINTF("\033[35m   Function = %s, Line = %d, CMA_POOL_INIT ERROR!!\033[m\n", __PRETTY_FUNCTION__, __LINE__);
5734             return FALSE;
5735         }
5736         else
5737         {
5738             DMS_PRINTF("\033[35m  Function = %s, Line = %d, get pool_handle_id is %u\033[m\n", __PRETTY_FUNCTION__, __LINE__, stDMSCMA_Pool_Init_PARAM[enMemType].pool_handle_id);
5739             DMS_PRINTF("\033[35m  Function = %s, Line = %d, get miu is %u\033[m\n", __PRETTY_FUNCTION__,__LINE__, stDMSCMA_Pool_Init_PARAM[enMemType].miu);
5740             DMS_PRINTF("\033[35m  Function = %s, Line = %d, get heap_miu_start_offset is 0x%x\033[m\n", __PRETTY_FUNCTION__, __LINE__, (MS_U32)stDMSCMA_Pool_Init_PARAM[enMemType].heap_miu_start_offset);
5741             DMS_PRINTF("\033[35m  Function = %s, Line = %d, get heap_length is 0x%X\033[m\n", __PRETTY_FUNCTION__, __LINE__, stDMSCMA_Pool_Init_PARAM[enMemType].heap_length);
5742         }
5743     }
5744     if(FALSE == HAL_DMS_Setup_CMA(pInstance,enMemType,stDMSCMA_Pool_Init_PARAM[enMemType].pool_handle_id))
5745     {
5746         DMS_PRINTF("\033[1;31m[%s][%d] error, HAL_DMS_Setup_CMA failed\033[0m\n",__FUNCTION__,__LINE__);
5747         return FALSE;
5748     }
5749     else
5750     {
5751         *phyOutAddr = stDMSCMA_Pool_Init_PARAM[enMemType].heap_miu_start_offset;
5752     }
5753 #endif
5754     return TRUE;
5755 }
5756 
_MDrv_DMS_Setup_Memory(void * pInstance,EN_DMS_MEMORY_TYPE enMemType,MS_PHY phyMemBufferAddr,MS_PHY u32MemBufferSize,MS_U32 u32CMAHeapID)5757 static MS_BOOL _MDrv_DMS_Setup_Memory(void* pInstance, EN_DMS_MEMORY_TYPE enMemType, MS_PHY phyMemBufferAddr, MS_PHY u32MemBufferSize, MS_U32 u32CMAHeapID)
5758 {
5759     MS_BOOL bRet = TRUE;
5760     DMS_GET_RES_PRI;
5761     switch(enMemType)
5762     {
5763         case E_DMS_MEMORY_TYPE_GOP_DISPLAY:
5764         {
5765             MS_U32 u32DIPSizeWithDouble = 0;
5766             if(u32CMAHeapID != DMS_INVALID_CMA_HEAP_ID)
5767             {
5768                 if(FALSE == _MDrv_DMS_Setup_CMA(pInstance,enMemType,u32CMAHeapID,&phyMemBufferAddr))
5769                 {
5770                     DMS_PRINTF("\033[1;31m[%s][%d] error, _MDrv_DMS_Setup_CMA failed\033[0m\n",__FUNCTION__,__LINE__);
5771                     bRet = FALSE;
5772                 }
5773                 MS_U32 u32DIPSize = (DMS_Frame_Buffer_Height * _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPWFmt, DMS_Frame_Buffer_Width));
5774                 u32DIPSizeWithDouble = u32DIPSize * 2; //double buffer
5775             }
5776             else
5777             {
5778                 MS_PHY phyMaxNeedSize = DMS_Frame_Buffer_Width * DMS_Frame_Buffer_Height * BPP_OF_YUV422 * 2;
5779 #if (DMS_DIP_Support_HVSP == 0)
5780                 phyMaxNeedSize += (DMS_Frame_Buffer_Width * DMS_Frame_Buffer_Height * BPP_OF_YUV422);
5781 #endif
5782                 if(phyMaxNeedSize > u32MemBufferSize)
5783                 {
5784                     DMS_PRINTF("\033[1;31m[%s][%d] error, buffer not enough u32MemBufferSize 0x%tx , need 0x%tx\033[0m\n",__FUNCTION__,__LINE__,(ptrdiff_t)u32MemBufferSize, (ptrdiff_t)phyMaxNeedSize);
5785                     bRet = FALSE;
5786                 }
5787                 //DIP size
5788                 MS_U32 u32DIPSize = (DMS_Frame_Buffer_Height * _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPWFmt, DMS_Frame_Buffer_Width));
5789                 u32DIPSizeWithDouble = u32DIPSize * 2; //double buffer
5790 #if (DMS_DIP_Support_HVSP == 0)
5791                 u32DIPSizeWithDouble += u32DIPSize;
5792 #endif
5793             }
5794 
5795             if(bRet)
5796             {
5797                 RES_DMS.u32DIPAddress_pa[E_DMS_DIP_CLIENT_GOP] = phyMemBufferAddr;
5798                 _MDrv_DMS_MemData_Init(RES_DMS.u32DIPAddress_pa[E_DMS_DIP_CLIENT_GOP], (MS_U32)u32DIPSizeWithDouble, DIP_DATA_FMT_YUV422);
5799 #if (DMS_DIP_Support_HVSP == 0)
5800                 RES_DMS.u32GEAddress_pa = RES_DMS.u32DIPAddress_pa[E_DMS_DIP_CLIENT_GOP] + u32DIPSizeWithDouble;
5801 #endif
5802             }
5803             break;
5804         }
5805         case E_DMS_MEMORY_TYPE_FREEZE:
5806         {
5807             if(u32CMAHeapID != DMS_INVALID_CMA_HEAP_ID)
5808             {
5809                 if(FALSE == _MDrv_DMS_Setup_CMA(pInstance,enMemType,u32CMAHeapID,&phyMemBufferAddr))
5810                 {
5811                     DMS_PRINTF("\033[1;31m[%s][%d] error, _MDrv_DMS_Setup_CMA failed\033[0m\n",__FUNCTION__,__LINE__);
5812                     bRet = FALSE;
5813                 }
5814             }
5815             else
5816             {
5817                 MS_PHY phyMaxNeedSize = DMS_FHD_Hszie * DMS_FHD_Vszie * BPP_OF_YUV422;
5818                 if(phyMaxNeedSize > u32MemBufferSize)
5819                 {
5820                     DMS_PRINTF("\033[1;31m[%s][%d] error, buffer not enough u32MemBufferSize 0x%tx , need 0x%tx\033[0m\n",__FUNCTION__,__LINE__,(ptrdiff_t)u32MemBufferSize, (ptrdiff_t)phyMaxNeedSize);
5821                     bRet = FALSE;
5822                 }
5823             }
5824             if(bRet)
5825             {
5826                 RES_DMS.u32MVOPFreezeAddress_pa = phyMemBufferAddr;
5827                 _MDrv_DMS_MemData_Init(RES_DMS.u32MVOPFreezeAddress_pa, (MS_U32)u32MemBufferSize, DIP_DATA_FMT_YUV422);
5828             }
5829             break;
5830         }
5831         case E_DMS_MEMORY_TYPE_MVOP_DISPLAY:
5832         {
5833             if(u32CMAHeapID != DMS_INVALID_CMA_HEAP_ID)
5834             {
5835                 if(FALSE == _MDrv_DMS_Setup_CMA(pInstance,enMemType,u32CMAHeapID,&phyMemBufferAddr))
5836                 {
5837                     DMS_PRINTF("\033[1;31m[%s][%d] error, _MDrv_DMS_Setup_CMA failed\033[0m\n",__FUNCTION__,__LINE__);
5838                     bRet = FALSE;
5839                 }
5840             }
5841             else
5842             {
5843                 MS_PHY phyMaxNeedSize = DMS_FHD_Hszie * DMS_FHD_Vszie * BPP_OF_YUV422 * DMS_DI_RING_BUFFER;
5844                 if(phyMaxNeedSize > u32MemBufferSize)
5845                 {
5846                     DMS_PRINTF("\033[1;31m[%s][%d] error, buffer not enough u32MemBufferSize 0x%tx , need 0x%tx\033[0m\n",__FUNCTION__,__LINE__,(ptrdiff_t)u32MemBufferSize, (ptrdiff_t)phyMaxNeedSize);
5847                     bRet = FALSE;
5848                 }
5849             }
5850             if(bRet)
5851             {
5852                 MS_U32 u32DIPMVOPSize = (RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_MVOP].u32PanelHeight * _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_MVOP].eDIPWFmt, RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_MVOP].u32PanelWidth));
5853                 MS_U32 u32DIPMVOPSizeWithDouble = u32DIPMVOPSize * DMS_DI_RING_BUFFER; //double buffer
5854                 RES_DMS.u32DIPAddress_pa[E_DMS_DIP_CLIENT_MVOP] = phyMemBufferAddr;
5855                 _MDrv_DMS_MemData_Init(RES_DMS.u32DIPAddress_pa[E_DMS_DIP_CLIENT_MVOP], (MS_U32)u32DIPMVOPSizeWithDouble, DIP_DATA_FMT_YUV422);
5856             }
5857             break;
5858         }
5859         case E_DMS_MEMORY_TYPE_DIPDI:
5860         {
5861 #if DMS_DIP_Support_3DDI
5862             if(u32CMAHeapID != DMS_INVALID_CMA_HEAP_ID)
5863             {
5864                 if(FALSE == _MDrv_DMS_Setup_CMA(pInstance,enMemType,u32CMAHeapID,&phyMemBufferAddr))
5865                 {
5866                     DMS_PRINTF("\033[1;31m[%s][%d] error, _MDrv_DMS_Setup_CMA failed\033[0m\n",__FUNCTION__,__LINE__);
5867                     bRet = FALSE;
5868                 }
5869             }
5870             else
5871             {
5872                 MS_PHY phyMaxNeedSize = (4/2) * DMS_FHD_Hszie * DMS_FHD_Vszie * BPP_OF_ARGB8888;
5873                 if(phyMaxNeedSize > u32MemBufferSize)
5874                 {
5875                     DMS_PRINTF("\033[1;31m[%s][%d] error, buffer not enough u32MemBufferSize 0x%tx , need 0x%tx\033[0m\n",__FUNCTION__,__LINE__,(ptrdiff_t)u32MemBufferSize, (ptrdiff_t)phyMaxNeedSize);
5876                     bRet = FALSE;
5877                 }
5878             }
5879             if(bRet)
5880             {
5881                 RES_DMSDI.u32DIPDIAddress_pa = phyMemBufferAddr;
5882                 _MDrv_DMS_MemData_Init(RES_DMSDI.u32DIPDIAddress_pa, (MS_U32)u32MemBufferSize, DIP_DATA_FMT_YUV422);
5883             }
5884 
5885 #if (DEV_DI == 1)
5886             _MDrv_DMS_DI_Init();
5887 #endif
5888 #endif
5889             break;
5890         }
5891         default:
5892         {
5893             DMS_PRINTF("\033[1;31m[%s][%d] unuse mem type %d\033[0m\n",__FUNCTION__,__LINE__,enMemType);
5894             break;
5895         }
5896     }
5897     return bRet;
5898 }
5899 
_MDrv_DMS_Init(void * pInstance,MS_U8 u8GOP,EN_DMS_DIP_FMT eDIPWColorFmt,MS_PHY phyMemBufferAddr,MS_U32 u32MemBufferSize)5900 static MS_BOOL _MDrv_DMS_Init(void* pInstance, MS_U8 u8GOP, EN_DMS_DIP_FMT eDIPWColorFmt, MS_PHY phyMemBufferAddr, MS_U32 u32MemBufferSize)
5901 {
5902     DMS_GET_RES_PRI;
5903     if(pDMSResPri->bDrvInit == TRUE)
5904     {
5905         DMS_PRINTF("Driver has inited!!!!!!!!\n");
5906         return TRUE;
5907     }
5908     // Create Event
5909     if(XC_Vsync_Event_id < 0)
5910     {
5911         XC_Vsync_Event_id = MsOS_CreateEventGroup("DMS_XC_Vsync_Event");
5912     }
5913 #if (DEV_DI == 1)
5914     // Create  Di Event
5915     if(XC_Di_Push_Event_id < 0)
5916     {
5917         XC_Di_Push_Event_id = MsOS_CreateEventGroup("DMS_XC_Di_Push_Event");
5918     }
5919 #endif
5920 #if DEV_CAPMODE
5921     if(CaptureMode_Event_id < 0)
5922     {
5923         CaptureMode_Event_id = MsOS_CreateEventGroup("DMS_CaptureMode_Event");
5924     }
5925 #endif
5926 #if DMS_DIP_Support_IMI
5927     if(StartFRC_Event_id < 0)
5928     {
5929         StartFRC_Event_id = MsOS_CreateEventGroup("DMS_IMI_StartFRC_Event");
5930     }
5931 #endif
5932 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 0)
5933      // create MVOP event
5934      if(s32MVOP_Event_id < 0)
5935     {
5936         s32MVOP_Event_id = MsOS_CreateEventGroup("DMS_MVOP_Event");
5937     }
5938     // create Disable Bob Mode event
5939     if(s32DisableBob_Event_id < 0)
5940     {
5941         s32DisableBob_Event_id = MsOS_CreateEventGroup("DMS_DisableBob_Event");
5942     }
5943 #endif
5944     // inital DIP
5945     MApi_XC_DIP_InitByDIP(DIP_WINDOW);
5946     MApi_XC_DIP_EnaInt(0xFF, FALSE, DIP_WINDOW);
5947 
5948     MApi_XC_DIP_InitByDIP(DWIN0_WINDOW);
5949     MApi_XC_DIP_EnaInt(0xFF, FALSE, DWIN0_WINDOW);
5950 
5951     MApi_XC_DIP_InitByDIP(DWIN1_WINDOW);
5952     MApi_XC_DIP_EnaInt(0xFF, FALSE, DWIN1_WINDOW);
5953 
5954     // Store DIP need data
5955     RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPWFmt = (EN_XC_DIP_DATA_FMT)eDIPWColorFmt;
5956     RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelWidth = g_IPanel.Width();
5957     RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelHeight = g_IPanel.Height();
5958 
5959     // Store DIP to MVOP need Data (force value)
5960     RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_MVOP].eDIPWFmt = (EN_XC_DIP_DATA_FMT)eDIPWColorFmt;
5961     RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_MVOP].u32PanelWidth = DMS_FHD_Hszie;
5962     RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_MVOP].u32PanelHeight = DMS_FHD_Vszie;
5963 
5964     MApi_XC_DIP_SetOutputDataFmt(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPWFmt, DMS_DIPWindow_NORMAL);
5965     if(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPWFmt == E_DMS_DIP_FMT_YUV422)
5966     {
5967         MApi_XC_DIP_SwapUV(TRUE ,DMS_DIPWindow_NORMAL);
5968     }
5969 
5970     // Attach ISR and Set STB_DISP_IRQ
5971     MApi_XC_InterruptAttach(SC_INT_VSINT, _DMS_EmbedXCISR, NULL);
5972 
5973     // Clear VDEC info
5974     memset(RES_DMS._stXC_DIPPushInfo, 0x0, sizeof(DMS_VDECFRAME_INFO)*DMS_DIP_QUEUEDEPTH);
5975     memset(&RES_DMS._stXC_DIPWriteReadPointer, 0x0, sizeof(DMS_DIPWriteReadPointer));
5976     memset(RES_DMS._stXC_DIPWinInfo, 0x0, sizeof(DMS_DIPWIN_INFO)*DMS_MAX_WINDOW_NUM);
5977     memset(RES_DMS.u32WindowFrameRate, 0x0, sizeof(RES_DMS.u32WindowFrameRate));
5978 
5979     _MDrv_DMS_ZOrder_Init();
5980 
5981     pTaskInstance = pInstance;
5982     _MDrv_DMS_CreateTask();
5983 
5984     _MDrv_DMS_InvalidateAllQueue();
5985 
5986 #if (DEV_DI == 1)
5987     memset(&RES_DMSDI._stXC_DIPWriteReadPointerInterlace, 0x0, sizeof(DMS_DIPWriteReadPointer));
5988 #endif
5989 
5990     if(DMS_MVOP_FLOW)
5991     {
5992         _DMS_Add_XC_Status(MVOP_WINDOW, DMS_XC_BLACK_SCREEN_BY_WINUSED | DMS_XC_NO_FRAME | DMS_XC_FIRST_TIME_SETWINDOW);
5993 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
5994         //set MVOP config
5995         _DMS_MVOP_SetConfig(MVOP_INPUT_DRAM,TRUE,0);
5996 
5997         _DMS_XC_SetConnect(INPUT_SOURCE_DTV);
5998         MApi_XC_EnableFrameBufferLess(TRUE);
5999 #endif
6000         RES_DMS.eDMS_MVOPFlowCtrl = E_DMS_MVOP_FLOW_FROM_VDEC;
6001     }
6002     pDMSResPri->bDrvInit = TRUE;
6003 
6004     return TRUE;
6005 }
6006 
_DMS_Regen_CropWindow(MS_U16 u16NewSrcWidth,MS_U16 u16NewSrcHeight)6007 static void _DMS_Regen_CropWindow(MS_U16 u16NewSrcWidth, MS_U16 u16NewSrcHeight)
6008 {
6009     DMS_GET_RES_PRI;
6010     ST_DMS_WINDOW* pstSrcCropWin = &RES_DMS._stXC_XCCropWinInfo_raw;
6011     ST_DMS_WINDOW stCropWin;
6012     stCropWin.u32x = pstSrcCropWin->u32x * u16NewSrcWidth/ RES_DMS.u16FirstSrcWidth;
6013     stCropWin.u32width = pstSrcCropWin->u32width * u16NewSrcWidth / RES_DMS.u16FirstSrcWidth;
6014     stCropWin.u32y = pstSrcCropWin->u32y * u16NewSrcHeight / RES_DMS.u16FirstSrcHeight;
6015     stCropWin.u32height = pstSrcCropWin->u32height * u16NewSrcHeight / RES_DMS.u16FirstSrcHeight;
6016     _DMS_XC_WindowAlignto2(&stCropWin);
6017     DMS_PRINTF("new crop size:%td %td, user crop size:%td %td, src is: %d %d, base on: %d %d\n",
6018         (ptrdiff_t)stCropWin.u32width,(ptrdiff_t)stCropWin.u32height,
6019         (ptrdiff_t)RES_DMS._stXC_XCCropWinInfo_raw.u32width,(ptrdiff_t)RES_DMS._stXC_XCCropWinInfo_raw.u32height,
6020         u16NewSrcWidth,u16NewSrcHeight,RES_DMS.u16FirstSrcWidth,RES_DMS.u16FirstSrcHeight);
6021     memcpy(&RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.stCropWin,&stCropWin,sizeof(stCropWin));
6022     memcpy(&RES_DMS._stXC_XCCropWinInfo_DoubleBuffer,&stCropWin,sizeof(stCropWin));
6023 }
6024 
_DMS_Clear_VDEC_Frame_Ref(MS_U32 u32Window,MS_U16 u16BufID)6025 static void _DMS_Clear_VDEC_Frame_Ref(MS_U32 u32Window, MS_U16 u16BufID)
6026 {
6027     DMS_GET_RES_PRI;
6028     MS_U8 u8RefCounter = 0;
6029     for(u8RefCounter = 0; u8RefCounter < RES_DMS._stXC_LocalFrameRefCount[u32Window][u16BufID]; u8RefCounter++)
6030     {
6031         DMS_PRINTF("[%s] window %td release frame for WP %d ct %d\n",__FUNCTION__,(ptrdiff_t)u32Window,u16BufID,(u8RefCounter+1));
6032         _DMS_VDEC_Frame_Release(u32Window,u16BufID);
6033     }
6034 }
6035 
_DMS_StoreVDECInfo2DIPQueue(void * pInstance,DMS_VDECFRAME_INFO * VDECDispFrame)6036 static void _DMS_StoreVDECInfo2DIPQueue(void* pInstance, DMS_VDECFRAME_INFO *VDECDispFrame)
6037 {
6038     DMS_GET_RES_PRI;
6039     MS_U16 u16NextWritePointer = 0;
6040     MS_U32 u32Window = VDECDispFrame->u32Window;
6041     MS_U16 u16RP = RES_DMS._stXC_DIPWriteReadPointer[u32Window].u16ReadPointer;
6042 
6043     //Jump to Next Write Pointer
6044     u16NextWritePointer = _GetNextWritePointer(u32Window);
6045     //DMS_PRINTF("=====PUSH Frame=%d====",u16NextWritePointer);
6046 
6047     while(_GetNextBufferID(u16NextWritePointer) == u16RP)
6048     {
6049         MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
6050         //DMS_PRINTF("\033[31m [%s] window %d Force block flip when Read Write Diff < 2 (%d) \033[0m\n",__FUNCTION__, u32Window, u16RP);
6051         MsOS_DelayTask(1);
6052         MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
6053         u16RP = RES_DMS._stXC_DIPWriteReadPointer[u32Window].u16ReadPointer;
6054     }
6055 
6056 #if NEW_FLIP
6057     if(RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u32FrameIndex != DMS_INVALID_FRAME_ID)
6058     {
6059         if(DEV_NEW_NEXT == 0)
6060         {
6061             if(RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].bValid == TRUE)
6062             {
6063                 //VDEC push too fast
6064                 DMS_PRINTF("[%s] (Window, Buffer) (%td, %d) valid check ring back, Time %td \n",__FUNCTION__, (ptrdiff_t)u32Window, u16NextWritePointer, (ptrdiff_t)MsOS_GetSystemTime());
6065                 _DMS_Clear_VDEC_Frame_Ref(u32Window,u16NextWritePointer);
6066             }
6067             if(RES_DMS._stXC_LocalFrameRefCount[u32Window][u16NextWritePointer] > 0)
6068             {
6069                 DMS_PRINTF("[%s] LocalFrameRefCount check ring back\n",__FUNCTION__);
6070                 _DMS_Clear_VDEC_Frame_Ref(u32Window,u16NextWritePointer);
6071             }
6072         }
6073         else
6074         {
6075             while(RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].bValid == TRUE)
6076             {
6077                 MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
6078                 //DMS_PRINTF("[%s] win %d, Force block flip when bValid\n",__FUNCTION__, u32Window);
6079                 MsOS_DelayTask(1);
6080                 MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
6081             }
6082         }
6083     }
6084 #endif
6085 
6086 #if DEV_CAPMODE
6087     if((_DMS_Is_MVOPFlow(u32Window) == FALSE) && _DMS_IsCaptureWindowEnable(u32Window))
6088     {
6089         if(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].u32Visible == FALSE)
6090         {
6091             // case: full speed decode
6092             MS_U16 u16Prev = u16NextWritePointer;
6093             u16Prev = _GetPreviousBufferID(u16Prev);
6094             u16Prev = _GetPreviousBufferID(u16Prev);
6095             if(RES_DMS._stXC_DIPPushInfo[u32Window][u16Prev].bValid == TRUE)
6096             {
6097                 //DMS_PRINTF("\033[32m [%s] (Window, Buffer) (%d, %d) clear prev 2, Time %d \033[0m\n",__FUNCTION__, u32Window, u16Prev, MsOS_GetSystemTime());
6098                 _DMS_Clear_VDEC_Frame_Ref(u32Window,u16Prev);
6099                 RES_DMS._stXC_DIPPushInfo[u32Window][u16Prev].bValid = FALSE;
6100             }
6101         }
6102     }
6103 #endif
6104 
6105     memcpy(&RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer], VDECDispFrame, sizeof(DMS_VDECFRAME_INFO));
6106 
6107     // New Flip
6108     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u32FrameIndex = VDECDispFrame->u32FrameIndex;
6109     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u32VDECStreamID = VDECDispFrame->u32VDECStreamID;
6110     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u32VDECStreamVersion = VDECDispFrame->u32VDECStreamVersion;
6111     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u32PriData = VDECDispFrame->u32PriData;
6112     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u64Pts = VDECDispFrame->u64Pts;
6113     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].eScanType = VDECDispFrame->eScanType;
6114     if(_DMS_Is_SourceFieldBaseInterlace(RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].eScanType))
6115     {
6116         RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u32FrameIndex_2nd = VDECDispFrame->u32FrameIndex_2nd;
6117         RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u32PriData_2nd = VDECDispFrame->u32PriData_2nd;
6118     }
6119     _DMS_VDEC_Frame_AddRef(u32Window,u16NextWritePointer);
6120 
6121 #if DMS_DIP_Support_IMI
6122     if(_DMS_IsCaptureWindowEnable(u32Window))
6123     {
6124         RES_DMSCAPTURE.bIsFrameValid[u32Window][u16NextWritePointer] = TRUE;
6125         _DMS_VDEC_Frame_AddRef_CaptureMode(u32Window,u16NextWritePointer);
6126         printf("\033[32m [%d] === win[%td], buf[%d]: %td === \033[0m\n",__LINE__,(ptrdiff_t)u32Window,u16NextWritePointer,(ptrdiff_t)MsOS_GetSystemTime());
6127         RES_DMSCAPTURE._stXC_DIPCapWin_WriteReadPointer[u32Window].u16WritePointer = u16NextWritePointer;
6128     }
6129 
6130     if(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32Window].bStartGetCapture == TRUE)
6131     {
6132         if(_DMS_TriggerToCaptureFrame(pInstance, u32Window) && (RES_DMSCAPTURE._stXC_IMICaptureInfo[u32Window].bFirstCapFrame == FALSE))
6133         {
6134             MsOS_SetEvent(StartFRC_Event_id, BIT(u32Window));
6135         }
6136     }
6137     else
6138     {
6139         MS_U16 u16Prev = u16NextWritePointer;
6140         MS_U8 i;
6141         for(i = 0 ; i < (START_FRC_ACCUMULE_FRAME_COUNT-1); i++)
6142         {
6143             u16Prev = _GetPreviousBufferID(u16Prev);
6144         }
6145         if(RES_DMSCAPTURE.bIsFrameValid[u32Window][u16Prev])
6146         {
6147             DMS_PRINTF("\033[32m [%s] IMI flow, win %td, clear prev 2 (buf: %d) \033[0m\n",__FUNCTION__, (ptrdiff_t)u32Window, u16Prev);
6148             _DMS_VDEC_Frame_Release_CaptureMode(u32Window, u16Prev);
6149             RES_DMSCAPTURE.bIsFrameValid[u32Window][u16Prev] = FALSE;
6150         }
6151     }
6152 #else
6153     if(_DMS_IsCaptureWindowEnable(u32Window))
6154     {
6155         RES_DMSCAPTURE.bIsFrameValid[u32Window][u16NextWritePointer] = TRUE;
6156         _DMS_VDEC_Frame_AddRef_CaptureMode(u32Window,u16NextWritePointer);
6157         RES_DMSCAPTURE._stXC_DIPCapWin_WriteReadPointer[u32Window].u16WritePointer = u16NextWritePointer;
6158         //printf("u16WritePointer (%d, %d)", u32Window, RES_DMSCAPTURE._stXC_DIPCapWin_WriteReadPointer[u32Window].u16WritePointer);
6159         if(_DMS_TriggerToCaptureFrame(pInstance, u32Window))
6160         {
6161             printf("\033[33m setEvent %d, time %d \033[0m\n", BIT(u32Window), MsOS_GetSystemTime());
6162             MsOS_SetEvent(CaptureMode_Event_id, BIT(u32Window));
6163         }
6164     }
6165 #endif
6166     sync_print("#### Push %d ####",u16NextWritePointer);
6167     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].bValid= TRUE;
6168     //printf("\033[1;31m[%d] Push to Main %d, RBID %d\033[0m\n",MsOS_GetSystemTime(),u16NextWritePointer, VDECDispFrame->u8DiOutputRingBufferID);
6169 
6170     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u16SrcWidth = VDECDispFrame->u16SrcWidth - VDECDispFrame->u16CropLeft - VDECDispFrame->u16CropRight;
6171     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u16SrcHeight = VDECDispFrame->u16SrcHeight - VDECDispFrame->u16CropTop - VDECDispFrame->u16CropBottom;
6172     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u16SrcPitch = VDECDispFrame->u16SrcPitch;
6173     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u32SrcLumaAddr = VDECDispFrame->u32SrcLumaAddr;
6174     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u32SrcChromaAddr = VDECDispFrame->u32SrcChromaAddr;
6175 
6176     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u32FrameRate = VDECDispFrame->u32FrameRate;
6177     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].eFmt = VDECDispFrame->eFmt;
6178     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u32Window = VDECDispFrame->u32Window;
6179     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].eCODEC = VDECDispFrame->eCODEC;
6180     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].eFieldOrderType = VDECDispFrame->eFieldOrderType;
6181     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].eFieldType = VDECDispFrame->eFieldType;
6182     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].eTileMode = VDECDispFrame->eTileMode;
6183 
6184     if(_DMS_Is_SourceFieldBaseInterlace(RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].eScanType))
6185     {
6186         RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u32FrameIndex_2nd = VDECDispFrame->u32FrameIndex_2nd;
6187         RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u32PriData_2nd = VDECDispFrame->u32PriData_2nd;
6188         RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u32SrcLumaAddrI = VDECDispFrame->u32SrcLumaAddrI;
6189         RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u32SrcChromaAddrI = VDECDispFrame->u32SrcChromaAddrI;
6190         if(RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].eFieldOrderType == E_DMS_VIDEO_FIELD_ORDER_TYPE_TOP)
6191         {
6192             if(VDECDispFrame->bIs2ndField == TRUE)
6193             {
6194                 RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].eFieldType = E_DMS_VIDEO_FIELD_TYPE_BOTTOM;
6195             }
6196             else
6197             {
6198                 RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].eFieldType = E_DMS_VIDEO_FIELD_TYPE_TOP;
6199             }
6200         }
6201         else
6202         {
6203             if(VDECDispFrame->bIs2ndField == TRUE)
6204             {
6205                 RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].eFieldType = E_DMS_VIDEO_FIELD_TYPE_TOP;
6206             }
6207             else
6208             {
6209                 RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].eFieldType = E_DMS_VIDEO_FIELD_TYPE_BOTTOM;
6210             }
6211         }
6212     }
6213 
6214     // MFDec info
6215     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].stMFdecInfo.bMFDec_Enable = VDECDispFrame->stMFdecInfo.bMFDec_Enable;
6216 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 0)
6217     if(u32Window == MVOP_WINDOW)
6218     {
6219         RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].stMFdecInfo.u8MFDec_Select = 0;
6220     }
6221     else
6222 #endif
6223     {
6224         RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].stMFdecInfo.u8MFDec_Select = VDECDispFrame->stMFdecInfo.u8MFDec_Select;
6225     }
6226     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].stMFdecInfo.bUncompress_mode = VDECDispFrame->stMFdecInfo.bUncompress_mode;
6227     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].stMFdecInfo.bBypass_codec_mode = VDECDispFrame->stMFdecInfo.bBypass_codec_mode;
6228     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].stMFdecInfo.en_MFDecVP9_mode = VDECDispFrame->stMFdecInfo.en_MFDecVP9_mode;
6229     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].stMFdecInfo.u16StartX = VDECDispFrame->stMFdecInfo.u16StartX;
6230     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].stMFdecInfo.u16StartY = VDECDispFrame->stMFdecInfo.u16StartY;
6231     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].stMFdecInfo.phyBitlen_Base = VDECDispFrame->stMFdecInfo.phyBitlen_Base;
6232     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].stMFdecInfo.u16Bitlen_Pitch = VDECDispFrame->stMFdecInfo.u16Bitlen_Pitch;
6233     // 10 bits
6234     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].b10bitData = VDECDispFrame->b10bitData;
6235     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u16Src10bitPitch = VDECDispFrame->u16Src10bitPitch;
6236     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u32SrcLumaAddr_2bit = VDECDispFrame->u32SrcLumaAddr_2bit;
6237     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u32SrcChromaAddr_2bit = VDECDispFrame->u32SrcChromaAddr_2bit;
6238     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u8LumaBitdepth = VDECDispFrame->u8LumaBitdepth;
6239 
6240     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].bIsAfterDiTask = VDECDispFrame->bIsAfterDiTask;
6241     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].bIs2ndField = VDECDispFrame->bIs2ndField;
6242     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u8DiOutputRingBufferID = VDECDispFrame->u8DiOutputRingBufferID;
6243 
6244     RES_DMS._stXC_DIPWriteReadPointer[u32Window].u16WritePointer = u16NextWritePointer;
6245     RES_DMS.u32WindowFrameRate[u32Window] = VDECDispFrame->u32FrameRate/1000;
6246 
6247     //2nd buffer
6248     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].phySrc2ndBufferLumaAddr = VDECDispFrame->phySrc2ndBufferLumaAddr;
6249     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].phySrc2ndBufferChromaAddr = VDECDispFrame->phySrc2ndBufferChromaAddr;
6250     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u16Src2ndBufferPitch = VDECDispFrame->u16Src2ndBufferPitch;
6251     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u8Src2ndBufferV7DataValid = VDECDispFrame->u8Src2ndBufferV7DataValid;
6252     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u16Src2ndBufferWidth = VDECDispFrame->u16Src2ndBufferWidth;
6253     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u16Src2ndBufferHeight = VDECDispFrame->u16Src2ndBufferHeight;
6254 
6255     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u8FieldCtrl = VDECDispFrame->u8FieldCtrl;
6256 
6257 
6258 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 0)
6259     if(u32Window == MVOP_WINDOW)
6260     {
6261         RES_DMS.u32ReleaseState[u16NextWritePointer] = 0;
6262     }
6263 #endif
6264 
6265     if(_DMS_Is_MVOPFlow(u32Window))
6266     {
6267         if(_DMS_Query_XC_Status(u32Window, DMS_XC_NO_FRAME))
6268         {
6269             _DMS_Remove_XC_Status(u32Window, DMS_XC_NO_FRAME);
6270             RES_DMS.u16FirstSrcWidth = RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u16SrcWidth;
6271             RES_DMS.u16FirstSrcHeight = RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u16SrcHeight;
6272         }
6273         else //if(RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].bIsAfterDiTask == FALSE)
6274         {
6275             MS_U16 u16PreID = _GetPreviousWritePointer(u32Window);
6276             if(RES_DMS._stXC_DIPPushInfo[u32Window][u16PreID].eScanType != RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].eScanType)
6277             {
6278                 DMS_PRINTF("\033[1;35m###[%s][%d][%td]### SeqChange (eScanType change %d -> %d) !!!!!!\033[0m\n",__FUNCTION__,__LINE__,(ptrdiff_t)MsOS_GetSystemTime(),RES_DMS._stXC_DIPPushInfo[u32Window][u16PreID].eScanType,RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].eScanType);
6279                 _DMS_Add_XC_Status(u32Window, DMS_XC_SEQ_CHANGE_PI);
6280                 RES_DMS.gu8DMS_Seq_Change_ID = u16NextWritePointer;
6281             }
6282 
6283             if((RES_DMS._stXC_DIPPushInfo[u32Window][u16PreID].u16SrcWidth != RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u16SrcWidth) ||
6284                 (RES_DMS._stXC_DIPPushInfo[u32Window][u16PreID].u16SrcHeight != RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u16SrcHeight))
6285             {
6286                 DMS_PRINTF("\033[1;35m###[%s][%d][%td]### SeqChange at WP:%d (Size change (%d,%d) -> (%d,%d)) !!!!!!\033[0m\n",__FUNCTION__,__LINE__,(ptrdiff_t)MsOS_GetSystemTime(),u16NextWritePointer,RES_DMS._stXC_DIPPushInfo[u32Window][u16PreID].u16SrcWidth,RES_DMS._stXC_DIPPushInfo[u32Window][u16PreID].u16SrcHeight,RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u16SrcWidth,RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u16SrcHeight);
6287                 _DMS_Add_XC_Status(u32Window, DMS_XC_SEQ_CHANGE_SIZE);
6288                 RES_DMS.gu8DMS_Seq_Change_ID = u16NextWritePointer;
6289                 printf("\033[1;35m###[%s][%d][%td]### %d %d %d %d %d %d !!!!!!\033[0m\n",__FUNCTION__,__LINE__,
6290                     (ptrdiff_t)MsOS_GetSystemTime(),
6291                     VDECDispFrame->u16SrcWidth, VDECDispFrame->u16SrcHeight,
6292                     VDECDispFrame->u16CropLeft, VDECDispFrame->u16CropRight,
6293                     VDECDispFrame->u16CropTop, VDECDispFrame->u16CropBottom);
6294 
6295                 _DMS_Regen_CropWindow(RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u16SrcWidth,
6296                     RES_DMS._stXC_DIPPushInfo[u32Window][u16NextWritePointer].u16SrcHeight);
6297             }
6298 
6299         }
6300     }
6301     //DMS_PRINTF("scan %d, fieldType %d, fieldOrderType %d, LAddr : 0x%llx, CAddr : 0x%llx\n",VDECDispFrame->eScanType,VDECDispFrame->eFieldType,VDECDispFrame->eFieldOrderType,
6302     //    VDECDispFrame->u32SrcLumaAddr,VDECDispFrame->u32SrcChromaAddr);
6303 
6304 }
6305 
_CalculateMaxOutputFrameRate(void)6306 static void _CalculateMaxOutputFrameRate(void)
6307 {
6308     DMS_GET_RES_PRI;
6309     MS_U16 u16OutVFreq = g_IPanel.DefaultVFreq() /10;
6310     //if(RES_DMS.u8EnableWindowCount == 0)
6311     if(RES_DMS.u8UseDIPWindowCount == 0)
6312     {
6313         RES_DMS.u32MaxOutputFrameRate = u16OutVFreq;
6314     }
6315     else
6316     {
6317         //RES_DMS.u32MaxOutputFrameRate = 1000 / (DMS_DIP_TIMESLICE * RES_DMS.u8EnableWindowCount);
6318         RES_DMS.u32MaxOutputFrameRate = 1000 / (DMS_DIP_TIMESLICE * RES_DMS.u8UseDIPWindowCount);
6319     }
6320 
6321     //reset VsyncCount
6322     RES_DMS.u32VsyncCount = 0;
6323     RES_DMS.u32GOPDispCount = 0;
6324     RES_DMS.u32OutputRate = ((MS_U32)g_IPanel.DefaultVFreq()) * 100;
6325 
6326     //DMS_PRINTF("DIP_TimeSlice = %d \n", DMS_DIP_TIMESLICE);
6327     //DMS_PRINTF("u8Enablu32WindowCount = %d \n", u8Enablu32WindowCount);
6328     //DMS_PRINTF("u32MaxOutputFrameRate = %d \n", RES_DMS.u32MaxOutputFrameRate);
6329 
6330 }
6331 
_MDrv_DMS_Final(void * pInstance,MS_U32 u32Window)6332 static MS_BOOL _MDrv_DMS_Final(void* pInstance, MS_U32 u32Window)
6333 {
6334     DMS_GET_RES_PRI;
6335     if(_DMS_Is_MVOPFlow(u32Window))
6336     {
6337         Hal_DMS_XC_SetMute(pInstance, TRUE);
6338         RES_DMS.gDMS_MVOPShowBufferID = DMS_Invalid_ReadPointer_ID;
6339         RES_DMS.gDMS_MVOPRemoveBufferID = DMS_Invalid_ReadPointer_ID;
6340         RES_DMS.bMVOPMarkRemoveBuffer = FALSE;
6341         MS_U8 u8BufID = 0;
6342         for(u8BufID = 0; u8BufID < DMS_DIP_QUEUEDEPTH; u8BufID++)
6343         {
6344             _DMS_Clear_VDEC_Frame_Ref(u32Window, u8BufID);
6345 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 0)
6346             RES_DMS.u32ReleaseState[u8BufID] = 0;
6347 #endif
6348         }
6349         _DMS_Add_XC_Status(u32Window, DMS_XC_RESET_WINDOW_SIZE | DMS_XC_BLACK_SCREEN_BY_WINUSED | DMS_XC_NO_FRAME | DMS_XC_FIRST_TIME_SETWINDOW);
6350         RES_DMSDI._u8DMS_DiSetEventBufferID = DMS_Invalid_ReadPointer_ID;
6351         RES_DMSDI._u8DMS_DiReleaseVDECFrameBufferID = DMS_Invalid_ReadPointer_ID;
6352         for(u8BufID = 0; u8BufID < DMS_DIP_QUEUEDEPTH; u8BufID++)
6353         {
6354             _DMS_Clear_VDEC_Frame_Ref_Interlace(u32Window, u8BufID);
6355         }
6356         RES_DMS.bDMS_MVOPFlowFromDi = FALSE;
6357 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 0)
6358         RES_DMS._stXC_DIPWriteReadPointer[MVOP_WINDOW].u16ReadPointer = 0;
6359         RES_DMS._stXC_DIPWriteReadPointer[MVOP_WINDOW].u16WritePointer = 0;
6360 #endif
6361     }
6362     RES_DMS.bStartCountFRC[u32Window] = FALSE;
6363     //Close Win and Show No Signal Color
6364     _DMS_DisableByWin(u32Window);
6365 
6366     //Clean Pushframe Info in queue;
6367     _DMS_InvalidateQueueByWin(u32Window);
6368 
6369     //Check if exist any window and DeInit when no window is open
6370     _DMS_DeInitByWin(u32Window);
6371 
6372     _CalculateMaxOutputFrameRate();
6373 
6374     _DMS_XC_SetDisconnect(INPUT_SOURCE_DTV);
6375 
6376     return TRUE;
6377 }
6378 
6379 //Set Display Window Change Flag
_DMS_IsDispWindowChange(MS_U32 u32Window,ST_DMS_WINDOW * ptDstWin)6380 static MS_BOOL _DMS_IsDispWindowChange (MS_U32 u32Window, ST_DMS_WINDOW *ptDstWin)
6381 {
6382     DMS_GET_RES_PRI;
6383     if (RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32x != ptDstWin->u32x)
6384         return TRUE;
6385 
6386     if (RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32y != ptDstWin->u32y)
6387         return TRUE;
6388 
6389     if (RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width != ptDstWin->u32width)
6390         return TRUE;
6391 
6392     if (RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height != ptDstWin->u32height)
6393         return TRUE;
6394 
6395     return FALSE;
6396 }
6397 
_DMS_SetDispWindowChangeFlag(MS_U32 u32Window)6398 static void _DMS_SetDispWindowChangeFlag (MS_U32 u32Window)
6399 {
6400     DMS_GET_RES_PRI;
6401     //Raise the flag "Display Window Change"
6402     RES_DMS._stXC_DispBuf_Flag[E_DMS_DIP_MULTIVIEW_BUF_ID_0][u32Window].bDispChange = TRUE;
6403     RES_DMS._stXC_DispBuf_Flag[E_DMS_DIP_MULTIVIEW_BUF_ID_1][u32Window].bDispChange = TRUE;
6404 }
6405 
6406 //Set Display Window Change Flag
_DMS_GetDispWindowChangeFlag(MS_U32 u32Window)6407 static MS_BOOL _DMS_GetDispWindowChangeFlag (MS_U32 u32Window)
6408 {
6409     DMS_GET_RES_PRI;
6410     //Raise the flag "Display Window Change"
6411     if (RES_DMS._stXC_DispBuf_Flag[E_DMS_DIP_MULTIVIEW_BUF_ID_0][u32Window].bDispChange == TRUE)
6412     {
6413         return TRUE;
6414     }
6415 
6416     if (RES_DMS._stXC_DispBuf_Flag[E_DMS_DIP_MULTIVIEW_BUF_ID_1][u32Window].bDispChange == TRUE)
6417     {
6418         return TRUE;
6419     }
6420 
6421     return FALSE;
6422 }
6423 
6424 //Store Display Window Info as Previous one
_DMS_StorePreviousWindowInfo(MS_U32 u32Window)6425 static void _DMS_StorePreviousWindowInfo (MS_U32 u32Window)
6426 {
6427     DMS_GET_RES_PRI;
6428     RES_DMS._stXC_PreDispWinInfo[u32Window].u32x = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32x;
6429     RES_DMS._stXC_PreDispWinInfo[u32Window].u32y = RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32y;
6430     RES_DMS._stXC_PreDispWinInfo[u32Window].u32width= RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width;
6431     RES_DMS._stXC_PreDispWinInfo[u32Window].u32height= RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height;
6432 }
6433 
_DMS_CheckIfDispWindowChange(MS_U32 u32Window,ST_DMS_WINDOW * ptDstWin)6434 static MS_BOOL _DMS_CheckIfDispWindowChange (MS_U32 u32Window, ST_DMS_WINDOW *ptDstWin)
6435 {
6436     if (_DMS_IsWindowUsed(u32Window) == TRUE)
6437     {
6438         if (_DMS_IsDispWindowChange(u32Window, ptDstWin) == TRUE)
6439         {
6440             //If (Window Change Flag != TRUE), Store Old Window info
6441             if (_DMS_GetDispWindowChangeFlag(u32Window) != TRUE)
6442             {
6443                 _DMS_StorePreviousWindowInfo(u32Window);
6444             }
6445 
6446             //Set Display Window Change Flag
6447             _DMS_SetDispWindowChangeFlag(u32Window);
6448         }
6449     }
6450     return TRUE;
6451 }
6452 
6453 //Condition: (HAL Level function?)
6454 //0:scaling down 90%             Use XC scaling,
6455 //1:scaling down 90% ~ 2K,    Use 2nd buffer. change to XC enlarge/same case
6456 //2:scaling 2Kdown ~ more,     Use 2nd buffer. DIP scaling down
6457 
_DMS_XC_Set_ScalingDown_Condition(ST_DMS_WINDOW * ptCropWin,ST_DMS_WINDOW * ptDstWin)6458 static void _DMS_XC_Set_ScalingDown_Condition(ST_DMS_WINDOW *ptCropWin, ST_DMS_WINDOW *ptDstWin)
6459 {
6460     //condition check
6461     DMS_GET_RES_PRI;
6462     RES_DMS.gDMS_ScalingCondition = 0;
6463 
6464     // Decide scaling Strategy Only if Crop window larger than FHD
6465     if(_DMS_WindowSizeOverFHD(ptCropWin->u32width,ptCropWin->u32height))
6466     {
6467         if(ptDstWin->u32width >= ptCropWin->u32width &&
6468            ptDstWin->u32height >= ptCropWin->u32height)
6469         {
6470             //4k in 4k out
6471             //3840 in 4096 out,scaling up, Use XC scaling
6472             DMS_PRINTF("[%s] H %td->%td, V %td->%td, enlarge case\n",__FUNCTION__,
6473                 (ptrdiff_t)ptCropWin->u32width,(ptrdiff_t)ptDstWin->u32width,
6474                 (ptrdiff_t)ptCropWin->u32height,(ptrdiff_t)ptDstWin->u32height);
6475             RES_DMS.gDMS_ScalingCondition |= USE_XC_FBL;
6476         }
6477         else if(ptDstWin->u32width >= ((ptCropWin->u32width * 9)/10) &&
6478             ptDstWin->u32height >= ((ptCropWin->u32height * 9)/10))
6479         {
6480             //scaling down 90%up, Use XC scaling
6481             DMS_PRINTF("[%s] H %td->%td, V %td->%td, 90up case, scaling by XC\n",__FUNCTION__,
6482                 (ptrdiff_t)((ptCropWin->u32width * 9)/10),(ptrdiff_t)ptDstWin->u32width,
6483                 (ptrdiff_t)((ptCropWin->u32height * 9)/10),(ptrdiff_t)ptDstWin->u32height);
6484             RES_DMS.gDMS_ScalingCondition |= USE_XC_SCALING_DOWN;
6485         }
6486         else if(ptDstWin->u32width >= (ptCropWin->u32width/2) &&
6487             ptDstWin->u32height >= (ptCropWin->u32height/2))
6488         {
6489             //scaling down 90% ~ 2K, Use 2nd buffer. change to XC enlarge/same case
6490             DMS_PRINTF("[%s] H %td->%td, V %td->%td, 90 to 2K, 2nd buffer scaling up by XC\n",__FUNCTION__,
6491                 (ptrdiff_t)(ptCropWin->u32width/2),(ptrdiff_t)ptDstWin->u32width,
6492                 (ptrdiff_t)(ptCropWin->u32height/2),(ptrdiff_t)ptDstWin->u32height);
6493             RES_DMS.gDMS_ScalingCondition |= USE_2ND_BUFFER;
6494         }
6495         else
6496         {
6497             DMS_PRINTF("[%s] H %td->%td, V %td->%td, 2K ~ more, 2nd buffer scaling down\n",__FUNCTION__,
6498                 (ptrdiff_t)ptCropWin->u32width,(ptrdiff_t)ptDstWin->u32width,
6499                 (ptrdiff_t)ptCropWin->u32height,(ptrdiff_t)ptDstWin->u32height);
6500             RES_DMS.gDMS_ScalingCondition |= USE_2ND_BUFFER;
6501         }
6502     }
6503 }
6504 
_MDrv_DMS_SetWin(void * pInstance,ST_DMS_WINDOW * ptCropWin,ST_DMS_WINDOW * ptDstWin,MS_U32 u32Window)6505 static MS_BOOL _MDrv_DMS_SetWin(void* pInstance, ST_DMS_WINDOW *ptCropWin, ST_DMS_WINDOW *ptDstWin, MS_U32 u32Window)
6506 {
6507     DMS_GET_RES_PRI;
6508     MS_U32 BytesPerLine = 0;
6509     MS_U32 UHDBytesPerLine = 0;
6510     ST_DMS_WINDOW stCropWin = {0};
6511     ST_DMS_WINDOW stDispWin = {0};
6512     E_DMS_DIP_CLIENT eDIPClient = E_DMS_DIP_CLIENT_GOP;
6513 
6514     if(ptCropWin == NULL || ptDstWin == NULL)
6515     {
6516         DMS_PRINTF("[%s] error, Set window parameter cannot be NULL\n",__FUNCTION__);
6517         return FALSE;
6518     }
6519 
6520     memcpy(&stCropWin,ptCropWin,sizeof(stCropWin));
6521     memcpy(&stDispWin,ptDstWin,sizeof(stDispWin));
6522 
6523     if(_DMS_Is_MVOPFlow(u32Window))
6524     {
6525 #if (DMS_MAIN_WINDOW_FLOW_VERSION == 1)
6526         _DMS_XC_Set_ScalingDown_Condition(&stCropWin, &stDispWin);
6527         if(RES_DMS.gDMS_ScalingCondition & USE_2ND_BUFFER)
6528         {
6529             stCropWin.u32width /= 2;
6530             stCropWin.u32height /= 2;
6531         }
6532 #endif
6533     }
6534     else
6535     {
6536         _DMS_Add_XC_Status(u32Window, DMS_XC_UPDATE_FROM_VDEC);
6537         _DMS_Remove_XC_Status(u32Window, DMS_XC_FIRST_FRAME_FROM_VDEC);
6538         RES_DMS.bIsWindowMute[u32Window] = FALSE;
6539     }
6540 
6541 #if DBG_FPS
6542     bFPS_Start[u32Window] = TRUE;
6543 #endif
6544     _DMS_XC_WindowAlignto2(&stCropWin);
6545     _DMS_XC_WindowAlignto2(&stDispWin);
6546 #if (DMS_MAIN_WINDOW_FLOW_VERSION == 1)
6547     if(_DMS_Is_MVOPFlow(u32Window))
6548     {
6549         eDIPClient = E_DMS_DIP_CLIENT_MVOP;
6550         memcpy(&RES_DMS._stXC_XCCropWinInfo_DoubleBuffer,&stCropWin,sizeof(stCropWin));
6551         memcpy(&RES_DMS._stXC_XCDispWinInfo_DoubleBuffer,&stDispWin,sizeof(stCropWin));
6552         _DMS_Add_XC_Status(u32Window, DMS_XC_RESET_WINDOW_SIZE);
6553         if(_DMS_Query_XC_Status(u32Window, DMS_XC_NO_FRAME))
6554         {
6555             memcpy(&RES_DMS._stXC_XCCropWinInfo_raw,&stCropWin,sizeof(stCropWin));
6556         }
6557 #if DEV_DI
6558         if(_DMS_Query_XC_Status(u32Window, DMS_XC_NO_FRAME))
6559         {
6560             RES_DMSDI._bSetwinToDiTask_DoubleBuffer = TRUE;
6561         }
6562         else
6563         {
6564             if(RES_DMS.bDMS_MVOPFlowFromDi == TRUE)
6565             {
6566                 RES_DMSDI._bSetwinToDiTask_DoubleBuffer = TRUE;
6567                 _DMS_Remove_XC_Status(u32Window, DMS_XC_RESET_WINDOW_SIZE);
6568             }
6569         }
6570 #endif
6571     }
6572 #endif  //DMS_MAIN_WINDOW_FLOW_VERSION == 1
6573 
6574     MS_BOOL bResChange = FALSE;
6575     if(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelWidth != g_IPanel.Width())
6576     {
6577         RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelWidth = g_IPanel.Width();
6578         bResChange = TRUE;
6579     }
6580     if(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelHeight != g_IPanel.Height())
6581     {
6582         RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelHeight = g_IPanel.Height();
6583         bResChange = TRUE;
6584     }
6585 
6586     if(bResChange)
6587     {
6588         MApi_GOP_GWIN_Set_STRETCHWIN(GOP_NUM, E_GOP_DST_OP0, 0, 0, RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelWidth, RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].u32PanelHeight);
6589         _MDrv_DMS_OSD_Init(GOP_NUM, RES_DMS.u32DIPAddress_pa[E_DMS_DIP_CLIENT_GOP], DIP_DATA_FMT_YUV422);
6590     }
6591 
6592     BytesPerLine = _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[eDIPClient].eDIPWFmt, RES_DMS._stXC_DIPMemInfo[eDIPClient].u32PanelWidth);
6593     UHDBytesPerLine = _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[eDIPClient].eDIPWFmt, DMS_Frame_Buffer_Width);
6594 
6595     // Handle Window Change
6596     _DMS_CheckIfDispWindowChange(u32Window, &stDispWin);
6597 
6598     if (RES_DMS._stXC_DIPWinInfo[u32Window].bDIPwinUse == FALSE)
6599     {
6600         // record enable window number
6601         RES_DMS.u8EnableWindowCount++;
6602         RES_DMS.u8UseDIPWindowCount++;
6603     }
6604 
6605     RES_DMS._stXC_DIPWinInfo[u32Window].bDIPwinUse = TRUE;
6606 
6607     if(_DMS_Is_MVOPFlow(u32Window))
6608     {
6609 #if (DMS_MAIN_WINDOW_FLOW_VERSION == 1)
6610         memcpy(&RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.stCropWin,&stCropWin,sizeof(stCropWin));
6611         RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.stDstWin.u32x = 0;
6612         RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.stDstWin.u32y = 0;
6613         RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.stDstWin.u32width = DMS_DIP_Alignment(stDispWin.u32width, DMS_HAL_DIP_Align);
6614         RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.stDstWin.u32height = stDispWin.u32height;
6615 
6616         RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.u32DIPStartMemAddr = RES_DMS.u32DIPAddress_pa[eDIPClient] + (BytesPerLine * RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.stDstWin.u32y) + ( _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[eDIPClient].eDIPWFmt, RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.stDstWin.u32x));
6617         RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.u32DIPEndMemAddr = RES_DMS.u32DIPAddress_pa[eDIPClient] + (BytesPerLine * (RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.stDstWin.u32y + RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.stDstWin.u32height)) +
6618         ( _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[eDIPClient].eDIPWFmt,(RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.stDstWin.u32x + RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.stDstWin.u32width)));
6619         RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.u32DIPDoubleBufStartMemAddr = RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.u32DIPStartMemAddr + (BytesPerLine * RES_DMS._stXC_DIPMemInfo[eDIPClient].u32PanelHeight);
6620         RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.u32DIPDoubleBufEndMemAddr = RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.u32DIPEndMemAddr + (BytesPerLine *  RES_DMS._stXC_DIPMemInfo[eDIPClient].u32PanelHeight);
6621 
6622         RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.phyDIPRingBufMemAddr[0] = RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.u32DIPStartMemAddr;
6623         RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.phyDIPRingBufMemAddr[1] = RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.u32DIPDoubleBufStartMemAddr;
6624         MS_U8 i = 2;
6625         for(i = 2; i < DMS_DI_RING_BUFFER; i++)
6626         {
6627             RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.phyDIPRingBufMemAddr[i] = RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.phyDIPRingBufMemAddr[i-1] + (BytesPerLine * RES_DMS._stXC_DIPMemInfo[eDIPClient].u32PanelHeight);
6628         }
6629         RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.u32RingBufferSize = RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.u32DIPEndMemAddr - RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.u32DIPStartMemAddr;
6630 #endif   //#if (DMS_MAIN_WINDOW_FLOW_VERSION == 1)
6631     }
6632     else
6633     {
6634         memcpy(&RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin,&stCropWin,sizeof(stCropWin));
6635         RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32x = DMS_DIP_Alignment(stDispWin.u32x, DMS_HAL_DIP_Align);
6636         RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32y = stDispWin.u32y;
6637 
6638         RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width = DMS_DIP_Alignment(stDispWin.u32width, DMS_HAL_DIP_Align);
6639         RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height = stDispWin.u32height;
6640 
6641         if(RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32y == 0)
6642         {
6643             RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPStartMemAddr = RES_DMS.u32DIPAddress_pa[eDIPClient] + ( _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[eDIPClient].eDIPWFmt,RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32x));
6644         }
6645         else
6646         {
6647             RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPStartMemAddr = RES_DMS.u32DIPAddress_pa[eDIPClient] + (BytesPerLine * (RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32y-1)) + ( _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[eDIPClient].eDIPWFmt,RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32x));
6648         }
6649         RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPEndMemAddr = RES_DMS.u32DIPAddress_pa[eDIPClient] + (BytesPerLine * (RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32y + RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height - 1)) +
6650         ( _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[eDIPClient].eDIPWFmt,(RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32x + RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width)));
6651         RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPDoubleBufStartMemAddr = RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPStartMemAddr + (UHDBytesPerLine * DMS_Frame_Buffer_Height);
6652         RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPDoubleBufEndMemAddr = RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPEndMemAddr + (UHDBytesPerLine * DMS_Frame_Buffer_Height);
6653 #if (DMS_DIP_Support_HVSP == 0)
6654         if(eDIPClient == E_DMS_DIP_CLIENT_GOP)
6655         {
6656             RES_DMS._stXC_DIPWinInfo[u32Window].u32GEStartMemAddr = RES_DMS.u32GEAddress_pa + (BytesPerLine * RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32y) + ( _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPWFmt, RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32x));
6657             RES_DMS._stXC_DIPWinInfo[u32Window].u32GEEndMemAddr = RES_DMS.u32GEAddress_pa + (BytesPerLine * (RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32y + RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32height)) +
6658                 ( _DMS_DIP_CalcPitch(RES_DMS._stXC_DIPMemInfo[E_DMS_DIP_CLIENT_GOP].eDIPWFmt,(RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32x + RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin.u32width)));
6659         }
6660 #endif
6661     }
6662 
6663     //Re-calculate Max Output Frame Rate
6664     _CalculateMaxOutputFrameRate();
6665 #if DBG_DMS_LOG
6666     ST_DMS_WINDOW *pstCropLogWin = (_DMS_Is_MVOPFlow(u32Window))? &RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.stCropWin : &RES_DMS._stXC_DIPWinInfo[u32Window].stCropWin;
6667     ST_DMS_WINDOW *pstDispLogWin = (_DMS_Is_MVOPFlow(u32Window))? &RES_DMS._stXC_DIPWinInfo_MVOPDoubleBuffer.stDstWin : &RES_DMS._stXC_DIPWinInfo[u32Window].stDstWin;
6668     DMS_PRINTF("\033[32m [%s][%d] === %s === \033[0m\n",__FUNCTION__,__LINE__,(DMS_MVOP_FLOW)? "MVOP flow!!!" : "DIP to GOP flow!!!");
6669     DMS_PRINTF("\033[32m [%s][%d] === Window : %d === \033[0m\n",__FUNCTION__,__LINE__,u32Window);
6670     DMS_PRINTF("\033[32m [%s][%d] === u32DIPAddress_pa : 0x%llx === \033[0m\n",__FUNCTION__,__LINE__,RES_DMS.u32DIPAddress_pa[eDIPClient]);
6671     DMS_PRINTF("\033[32m [%s][%d] === Crop_Window === \033[0m\n",__FUNCTION__,__LINE__);
6672     DMS_PRINTF("\033[32m [%s][%d] === X : %d, Y : %d, W : %d, H : %d  === \033[0m\n",__FUNCTION__,__LINE__,pstCropLogWin->u32x,pstCropLogWin->u32y,pstCropLogWin->u32width,pstCropLogWin->u32height);
6673     DMS_PRINTF("\033[32m [%s][%d] === DST_Window === \033[0m\n",__FUNCTION__,__LINE__);
6674     DMS_PRINTF("\033[32m [%s][%d] === X : %d, Y : %d, W : %d, H : %d === \033[0m\n",__FUNCTION__,__LINE__,pstDispLogWin->u32x,pstDispLogWin->u32y, pstDispLogWin->u32width,pstDispLogWin->u32height);
6675     DMS_PRINTF("\033[32m [%s][%d] === DIP Addr === \033[0m\n",__FUNCTION__,__LINE__);
6676     DMS_PRINTF("\033[32m [%s][%d] === u32DIPStartMemAddr : 0x%llx === \033[0m\n",__FUNCTION__,__LINE__,RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPStartMemAddr);
6677     DMS_PRINTF("\033[32m [%s][%d] === u32DIPEndMemAddr : 0x%llx === \033[0m\n",__FUNCTION__,__LINE__,RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPEndMemAddr);
6678     DMS_PRINTF("\033[32m [%s][%d] === u32DIPDoubleBufStartMemAddr : 0x%llx === \033[0m\n",__FUNCTION__,__LINE__,RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPDoubleBufStartMemAddr);
6679     DMS_PRINTF("\033[32m [%s][%d] === u32DIPDoubleBufEndMemAddr : 0x%llx === \033[0m\n",__FUNCTION__,__LINE__,RES_DMS._stXC_DIPWinInfo[u32Window].u32DIPDoubleBufEndMemAddr);
6680     DMS_PRINTF("\033[32m [%s][%d] === u32GEStartMemAddr : 0x%llx === \033[0m\n",__FUNCTION__,__LINE__,RES_DMS._stXC_DIPWinInfo[u32Window].u32GEStartMemAddr);
6681     DMS_PRINTF("\033[32m [%s][%d] === u32GEEndMemAddr : 0x%llx === \033[0m\n",__FUNCTION__,__LINE__,RES_DMS._stXC_DIPWinInfo[u32Window].u32GEEndMemAddr);
6682 #endif
6683     gDMSDebug = 0;
6684 
6685     return TRUE;
6686 }
6687 
_MDrv_DMS_SetWindowZOrder(MS_U32 u32WindowID,MS_U32 u32ZOrder)6688 static MS_BOOL _MDrv_DMS_SetWindowZOrder(MS_U32 u32WindowID, MS_U32 u32ZOrder)
6689 {
6690     DMS_GET_RES_PRI;
6691     MS_U8 u8WindowID = 0;
6692 
6693     if(_DMS_Is_MVOPFlow(u32WindowID) == TRUE)
6694     {
6695         RES_DMS.WindowScore[u32WindowID] = u32ZOrder;
6696 
6697         if(RES_DMS.WindowScore[u32WindowID] < RES_DMS.WindowScore[1])
6698         {
6699             MApi_XC_SetVideoOnOSD(E_VIDEO_ON_OSD_LAYER_0,MAIN_WINDOW);
6700         }
6701         else if(RES_DMS.WindowScore[u32WindowID] > RES_DMS.WindowScore[DMS_MAX_WINDOW_NUM-1])
6702         {
6703             MApi_XC_SetVideoOnOSD(E_VIDEO_ON_OSD_LAYER_4,MAIN_WINDOW);
6704         }
6705         else
6706         {
6707             MApi_XC_SetVideoOnOSD(E_VIDEO_ON_OSD_LAYER_0,MAIN_WINDOW);
6708             RES_DMS.WindowScore[u32WindowID] = 0;
6709         }
6710     }
6711     else
6712     {
6713         _DMS_Add_XC_Status(u8WindowID,  DMS_XC_UPDATE_FROM_VDEC);
6714         _DMS_Remove_XC_Status(u8WindowID,  DMS_XC_FIRST_FRAME_FROM_VDEC);
6715 
6716         for(u8WindowID=1; u8WindowID < DMS_MAX_WINDOW_NUM; u8WindowID++)
6717         {
6718             if(RES_DMS.WindowZOrder[u8WindowID] == u32WindowID)
6719             {
6720                 RES_DMS.WindowScore[u8WindowID] = u32ZOrder;
6721                 break;
6722             }
6723         }
6724         _DMS_DIP_ScoreSorting();
6725     }
6726 
6727     return TRUE;
6728 }
6729 
MDrv_DMS_Init(void * pInstance,ST_DMS_INITDATA * pstDMS_InitData)6730 EN_DMS_RESULT MDrv_DMS_Init(void* pInstance, ST_DMS_INITDATA *pstDMS_InitData)
6731 {
6732     MS_BOOL bRet = FALSE;
6733     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
6734     bRet = _MDrv_DMS_Init(pInstance, GOP_NUM, E_DMS_DIP_FMT_YUV422, 0, 0);
6735     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
6736     return (bRet)? E_DMS_OK : E_DMS_FAIL;
6737 }
6738 
MDrv_DMS_SetMemoryType(void * pInstance,ST_DMS_SET_MEMORY_TYPE * pstDMS_SetMemType)6739 EN_DMS_RESULT MDrv_DMS_SetMemoryType(void* pInstance, ST_DMS_SET_MEMORY_TYPE* pstDMS_SetMemType)
6740 {
6741     MS_BOOL bRet = FALSE;
6742     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
6743     DMS_GET_RES_PRI;
6744 
6745     printf("MDrv_DMS_SetMemoryType\n");
6746     if(pstDMS_SetMemType->eMemoryType == E_DMS_MEMORY_TYPE_GOP_DISPLAY)
6747     {
6748         _MDrv_DMS_OSD_Init(GOP_NUM, RES_DMS.u32DIPAddress_pa[E_DMS_DIP_CLIENT_GOP], DIP_DATA_FMT_YUV422);
6749     }
6750     bRet = _MDrv_DMS_Setup_Memory(pInstance, pstDMS_SetMemType->eMemoryType, pstDMS_SetMemType->phyAddr,pstDMS_SetMemType->phySize,pstDMS_SetMemType->u32CMAHeapID);
6751     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
6752     return (bRet)? E_DMS_OK : E_DMS_FAIL;
6753 }
6754 
MDrv_DMS_CreateWindow(void * pInstance,ST_DMS_WINDOW * pstOutputWin,ST_DMS_CREATE_WIN_INFO * pstCreateWin_Info,MS_U32 * pu32WindowID)6755 EN_DMS_RESULT MDrv_DMS_CreateWindow(void* pInstance, ST_DMS_WINDOW *pstOutputWin, ST_DMS_CREATE_WIN_INFO *pstCreateWin_Info, MS_U32 *pu32WindowID)
6756 {
6757     DMS_GET_RES_PRI;
6758     MS_BOOL bRet = FALSE;
6759     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
6760     MS_U16 u16WindowID = 0;
6761     for(u16WindowID=0; u16WindowID<DMS_MAX_WINDOW_NUM; u16WindowID++)
6762     {
6763         if(_DMS_IsWindowUsed(u16WindowID) == FALSE)
6764         {
6765             // record enable window number
6766             RES_DMS.u8EnableWindowCount++;
6767             RES_DMS.u8UseDIPWindowCount++;
6768 
6769             RES_DMS._stXC_DIPWinInfo[u16WindowID].bDIPwinUse = TRUE;
6770             *pu32WindowID = u16WindowID;
6771 
6772             bRet = TRUE;
6773             break;
6774         }
6775     }
6776     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
6777     return (bRet)? E_DMS_OK : E_DMS_FAIL;
6778 }
6779 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 0)
_DMS_MVOP_SetConfig_From_Vdec(void * pInstance,MS_U32 u32WindowID,ST_DMS_DISPFRAMEFORMAT * pstDispFrameFormat)6780 static MS_BOOL _DMS_MVOP_SetConfig_From_Vdec(void* pInstance, MS_U32 u32WindowID, ST_DMS_DISPFRAMEFORMAT *pstDispFrameFormat)
6781 {
6782     DMS_GET_RES_PRI;
6783 
6784     MVOP_VidStat stMvopVidSt;
6785     MVOP_InputCfg stMvopInputCfg;
6786     MVOP_InputSel eInputCfg = MVOP_INPUT_DRAM;
6787     MS_U8 u8MIUSel = 0;
6788     MS_BOOL bHS = TRUE;
6789     MS_BOOL bXCGen = FALSE;
6790     MS_BOOL bEnableUvSwap = FALSE;
6791     MVOP_Handle stMvopHd = { E_MVOP_MODULE_MAIN };
6792 
6793     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
6794 
6795 
6796     // Structure initialization
6797     memset(&stMvopVidSt, 0, sizeof(MVOP_VidStat));
6798     memset(&stMvopInputCfg, 0, sizeof(MVOP_InputCfg));
6799 
6800     RES_DMS.bDisableBlackScreen = FALSE;
6801     RES_DMS.bFirstPlay = TRUE;
6802     RES_DMS.u32MuteCounter = 0;
6803 
6804     MDrv_MVOP_Init();
6805     MDrv_MVOP_Enable(FALSE); // Turn off MVOP before setting it
6806     //u8MIUSel = (pstDispFrameFormat->stFrames[0].stHWFormat.phyLumaAddr >=0x80000000)?1:0;
6807     if(E_MVOP_OK != MDrv_MVOP_MiuSwitch(u8MIUSel))
6808     {
6809         DMS_PRINTF("Cannot set MVOP MIU selection!\n");
6810         MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
6811         return FALSE;
6812     }
6813 
6814     stMvopInputCfg.u16HSize = pstDispFrameFormat->stFrames[0].u32Width;
6815     stMvopInputCfg.u16VSize = pstDispFrameFormat->stFrames[0].u32Height;
6816     stMvopInputCfg.u32YOffset = 0;
6817     stMvopInputCfg.u32UVOffset = 0;
6818     stMvopInputCfg.bProgressive = (_DMS_Is_SourceInterlace(_DMS_GetDMSScanType(pstDispFrameFormat->u8Interlace)) == TRUE)?0:1;
6819     stMvopInputCfg.bUV7bit = FALSE;
6820     stMvopInputCfg.bField = (_DMS_GetDMSScanType(pstDispFrameFormat->u8Interlace) == E_DMS_VIDEO_SCAN_TYPE_INTERLACE_FIELD)? 1:0;
6821     stMvopInputCfg.u16StripSize = pstDispFrameFormat->stFrames[0].stHWFormat.u32LumaPitch;
6822     stMvopInputCfg.bYUV422 = _DMS_Is422Mode(_DMS_GetColorFormat(pstDispFrameFormat->enColorFormat));
6823     stMvopInputCfg.bSD = ((pstDispFrameFormat->stFrames[0].u32Width <= 720) && (pstDispFrameFormat->stFrames[0].u32Height <= 576))?1:0;
6824     if (stMvopInputCfg.bYUV422 == TRUE)
6825     {
6826         stMvopInputCfg.bDramRdContd = TRUE;
6827         stMvopInputCfg.b422pack = TRUE;
6828     }
6829     else
6830     {
6831         stMvopInputCfg.bDramRdContd = FALSE;
6832         stMvopInputCfg.b422pack = FALSE;
6833     }
6834     if(E_MVOP_OK != MDrv_MVOP_SetInputCfg(eInputCfg, &stMvopInputCfg))
6835     {
6836         DMS_PRINTF("Set MVOP input config failed!");
6837         printf("Set MVOP input config failed!");
6838         MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
6839         return FALSE;
6840     }
6841 
6842     if(stMvopInputCfg.bProgressive == TRUE)
6843     {
6844         bXCGen = TRUE;
6845     }
6846     MDrv_MVOP_SetCommand(&stMvopHd, E_MVOP_CMD_SET_HANDSHAKE_MODE, &bHS);
6847     MDrv_MVOP_SetCommand(&stMvopHd, E_MVOP_CMD_SET_XC_GEN_TIMING, &bXCGen);
6848 
6849     MDrv_MVOP_SetCommand(&stMvopHd, E_MVOP_CMD_SET_UV_SWAP, &bEnableUvSwap);
6850 
6851     stMvopVidSt.u16HorSize = pstDispFrameFormat->stFrames[0].u32Width;
6852     stMvopVidSt.u16VerSize = pstDispFrameFormat->stFrames[0].u32Height;
6853     stMvopVidSt.u8AspectRate = pstDispFrameFormat->u8AspectRate;
6854     stMvopVidSt.u8Interlace = _DMS_GetDMSScanType(pstDispFrameFormat->u8Interlace);
6855 
6856     if(stMvopInputCfg.bProgressive == FALSE)
6857     {
6858         stMvopVidSt.u16FrameRate = pstDispFrameFormat->u32FrameRate;
6859     }
6860     else
6861     {
6862         //printf("[%s][%d]========= pstDispFrameFormat->u32FrameRate=%ld===========\n",__FUNCTION__,__LINE__, pstDispFrameFormat->u32FrameRate);
6863         //printf("[%s][%d]=========g_IPanel.DefaultVFreq()=%d===========\n",__FUNCTION__,__LINE__,g_IPanel.DefaultVFreq());
6864         stMvopVidSt.u16FrameRate = g_IPanel.DefaultVFreq() * 100;
6865     }
6866 
6867     if(E_MVOP_OK != MDrv_MVOP_SetOutputCfg(&stMvopVidSt, FALSE))
6868     {
6869         DMS_PRINTF("Set MVOP output config failed!");
6870         printf("Set MVOP output config failed!");
6871         MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
6872         return FALSE;
6873     }
6874     MDrv_MVOP_Enable(TRUE); // Enable MVOP, video pass to Scaler
6875     MsOS_DisableInterrupt(E_INT_IRQ_DC);
6876     MDrv_MVOP_EnableInterrupt(E_MVOP_INT_NONE);
6877     MsOS_AttachInterrupt(E_INT_IRQ_DC, (InterruptCb)_DMS_MVOP_ISR);
6878     MsOS_EnableInterrupt(E_INT_IRQ_DC);
6879     MDrv_MVOP_EnableInterrupt(E_MVOP_INT_VSYNC);
6880     _CalculateMaxOutputFrameRate();
6881     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
6882 
6883     return TRUE;
6884 
6885 }
6886 #endif
6887 
MDrv_DMS_SetDigitalDecodeSignalInfo(void * pInstance,MS_U32 u32WindowID,ST_DMS_DISPFRAMEFORMAT * pstDispFrameFormat)6888 EN_DMS_RESULT MDrv_DMS_SetDigitalDecodeSignalInfo(void* pInstance, MS_U32 u32WindowID, ST_DMS_DISPFRAMEFORMAT *pstDispFrameFormat)
6889 {
6890 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
6891     DMS_PRINTF("\033[32m [%s][%d] === Not Impl %d=== \033[0m\n",__FUNCTION__,__LINE__,u32WindowID);
6892 #else
6893     if(u32WindowID == MVOP_WINDOW)
6894     {
6895         MApi_XC_SetBOBMode(FALSE, MAIN_WINDOW);
6896         _DMS_MVOP_SetConfig_From_Vdec(pInstance, u32WindowID, pstDispFrameFormat);
6897     }
6898 #endif
6899     return E_DMS_OK;
6900 }
6901 
MDrv_DMS_ClearDigitalDecodeSignalInfo(void * pInstance,MS_U32 u32WindowID)6902 EN_DMS_RESULT MDrv_DMS_ClearDigitalDecodeSignalInfo(void* pInstance, MS_U32 u32WindowID)
6903 {
6904 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
6905     DMS_PRINTF("\033[32m [%s][%d] === Not Impl %d=== \033[0m\n",__FUNCTION__,__LINE__,u32WindowID);
6906 #else
6907     MVOP_Handle stHd = {E_MVOP_MODULE_MAIN};
6908     MVOP_Result ret = E_MVOP_FAIL;
6909     MVOP_DMSDisplayADD stMVOPDispAddr;
6910 
6911     memset(&stMVOPDispAddr, 0, sizeof(MVOP_DMSDisplayADD));
6912 
6913     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
6914     DMS_GET_RES_PRI;
6915 
6916     if(u32WindowID == MVOP_WINDOW)
6917     {
6918         ret = MDrv_MVOP_DMS_SetDispADDInfo(&stHd, E_MVOP_MAIN_WIN, &stMVOPDispAddr, NULL);
6919         if(ret != 0)
6920         {
6921             DMS_PRINTF("\033[031m[%s:%d]MDrv_MVOP_DMS_SetDispADDInfo fail: %d\033[0m\n",__FUNCTION__, __LINE__, ret);
6922         }
6923 
6924         MDrv_MVOP_EnableInterrupt(E_MVOP_INT_NONE);
6925         MsOS_DisableInterrupt(E_INT_IRQ_DC);
6926         MsOS_DetachInterrupt(E_INT_IRQ_DC);
6927         MDrv_MVOP_Enable(FALSE);
6928         MDrv_MVOP_Exit();
6929     }
6930     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
6931 #endif
6932     return E_DMS_OK;
6933 }
6934 
MDrv_DMS_DestroyWindow(void * pInstance,MS_U32 u32WindowID)6935 EN_DMS_RESULT MDrv_DMS_DestroyWindow(void* pInstance, MS_U32 u32WindowID)
6936 {
6937     MS_BOOL bRet = FALSE;
6938     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
6939     bRet = _MDrv_DMS_Final(pInstance, u32WindowID);
6940     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
6941     return (bRet)? E_DMS_OK : E_DMS_FAIL;
6942 }
6943 
6944 //static MS_BOOL bOnce = FALSE;
MDrv_DMS_SetWindow(void * pInstance,MS_U32 u32WindowID,ST_DMS_SETWIN_INFO * pstDMS_SetWin_Info)6945 EN_DMS_RESULT MDrv_DMS_SetWindow(void* pInstance, MS_U32 u32WindowID, ST_DMS_SETWIN_INFO *pstDMS_SetWin_Info)
6946 {
6947 #if 0
6948     if(bOnce)
6949     {
6950         return E_DMS_OK;
6951     }
6952     else
6953     {
6954         bOnce = TRUE;
6955     }
6956 #endif
6957     MS_BOOL bRet = FALSE;
6958     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
6959 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
6960     if(pstDMS_SetWin_Info->u32XCWinInfoValid)
6961     {
6962         DMS_PRINTF("[%s][%d] Do setXC win by DMS!\n\n",__FUNCTION__,__LINE__);
6963         XC_SETWIN_INFO stXCSetWinInfo;
6964         memset(&stXCSetWinInfo, 0, sizeof(XC_SETWIN_INFO));
6965 
6966         stXCSetWinInfo.enInputSourceType = pstDMS_SetWin_Info->stXCWinInfo.u32InputSourceType;
6967         _DMS_XC_DMSWintoXCWin(&stXCSetWinInfo.stCapWin, &pstDMS_SetWin_Info->stXCWinInfo.stCapWin);
6968         _DMS_XC_DMSWintoXCWin(&stXCSetWinInfo.stDispWin, &pstDMS_SetWin_Info->stXCWinInfo.stDispWin);
6969         _DMS_XC_DMSWintoXCWin(&stXCSetWinInfo.stCropWin, &pstDMS_SetWin_Info->stXCWinInfo.stCropWin);
6970 
6971         stXCSetWinInfo.bInterlace = pstDMS_SetWin_Info->stXCWinInfo.u32Interlace;
6972         stXCSetWinInfo.bHDuplicate = pstDMS_SetWin_Info->stXCWinInfo.u32HDuplicate;
6973         stXCSetWinInfo.u16InputVFreq = pstDMS_SetWin_Info->stXCWinInfo.u32InputVFreq;
6974         stXCSetWinInfo.u16InputVTotal = pstDMS_SetWin_Info->stXCWinInfo.u32InputVTotal;
6975         stXCSetWinInfo.u16DefaultHtotal = pstDMS_SetWin_Info->stXCWinInfo.u32DefaultHtotal;
6976         stXCSetWinInfo.u16DefaultPhase = pstDMS_SetWin_Info->stXCWinInfo.u32DefaultPhase;
6977 
6978         stXCSetWinInfo.bHCusScaling = pstDMS_SetWin_Info->stXCWinInfo.u32HCusScaling;
6979         stXCSetWinInfo.bVCusScaling = pstDMS_SetWin_Info->stXCWinInfo.u32VCusScaling;
6980         _DMS_XC_SetCusScaling(&stXCSetWinInfo,TRUE,pstDMS_SetWin_Info->stXCWinInfo.u32HCusScalingSrc,pstDMS_SetWin_Info->stXCWinInfo.u32HCusScalingDst,
6981             pstDMS_SetWin_Info->stXCWinInfo.u32VCusScalingSrc,pstDMS_SetWin_Info->stXCWinInfo.u32VCusScalingDst);
6982 
6983         stXCSetWinInfo.bDisplayNineLattice = pstDMS_SetWin_Info->stXCWinInfo.u32DisplayNineLattice;        ///<used to indicate where to display in panel and where to put in frame buffer
6984 
6985         stXCSetWinInfo.bPreHCusScaling = pstDMS_SetWin_Info->stXCWinInfo.u32PreHCusScaling;
6986         stXCSetWinInfo.bPreVCusScaling = pstDMS_SetWin_Info->stXCWinInfo.u32PreVCusScaling;
6987         _DMS_XC_SetCusScaling(&stXCSetWinInfo,FALSE,pstDMS_SetWin_Info->stXCWinInfo.u32PreHCusScalingSrc,pstDMS_SetWin_Info->stXCWinInfo.u32PreHCusScalingDst,
6988             pstDMS_SetWin_Info->stXCWinInfo.u32PreVCusScalingSrc,pstDMS_SetWin_Info->stXCWinInfo.u32PreVCusScalingDst);
6989 
6990         MApi_XC_SetWindow(&stXCSetWinInfo, sizeof(XC_SETWIN_INFO), MAIN_WINDOW);
6991     }
6992 #else
6993     if(u32WindowID == MVOP_WINDOW)
6994     {
6995         _DMS_XC_SetConnect(INPUT_SOURCE_DTV);
6996         DMS_PRINTF("[%s][%d] Do setXC win by DMS!\n\n",__FUNCTION__,__LINE__);
6997         DMS_GET_RES_PRI;
6998         XC_SETWIN_INFO stXCSetWinInfo;
6999         XC_DynamicScaling_Info stXCDsInfo;
7000         MS_U32 u32DSInfoLen;
7001         XC_OUTPUTFRAME_Info stOutFrameInfo;
7002 
7003         memset(&stXCSetWinInfo, 0, sizeof(XC_SETWIN_INFO));
7004         memset(&stXCDsInfo, 0, sizeof(XC_DynamicScaling_Info));
7005         memset(&stOutFrameInfo, 0, sizeof(XC_OUTPUTFRAME_Info));
7006 
7007         stXCSetWinInfo.enInputSourceType = INPUT_SOURCE_DTV;
7008         MVOP_Timing mvop_timing;
7009         MVOP_Handle stHd = { E_MVOP_MODULE_MAIN };
7010         MS_BOOL bIsXCGenTiming;
7011         memset(&mvop_timing, 0, sizeof(MVOP_Timing));
7012         if(E_MVOP_OK != MDrv_MVOP_GetOutputTiming(&mvop_timing))
7013            DMS_PRINTF("MDrv_MVOP_GetOutputTiming failed!!\n");
7014 
7015         if(E_MVOP_OK != MDrv_MVOP_GetCommand(&stHd , E_MVOP_CMD_GET_IS_XC_GEN_TIMING, &bIsXCGenTiming , sizeof(bIsXCGenTiming)))
7016         {
7017             DMS_PRINTF("MDrv_MVOP_Get_XC_GEN_TIMING failed!!\n");
7018         }
7019 
7020         stXCSetWinInfo.bInterlace     = mvop_timing.bInterlace;
7021         stXCSetWinInfo.bHDuplicate    = mvop_timing.bHDuplicate;
7022         stXCSetWinInfo.u16InputVFreq = (bIsXCGenTiming)?g_IPanel.DefaultVFreq():mvop_timing.u8Framerate;
7023         stXCSetWinInfo.u16InputVTotal = mvop_timing.u16V_TotalCount;
7024         stXCSetWinInfo.u16DefaultHtotal = mvop_timing.u16H_TotalCount;
7025 
7026 
7027         stOutFrameInfo.u16InVFreq = stXCSetWinInfo.u16InputVFreq;
7028         stOutFrameInfo.u16OutVFreq = g_IPanel.DefaultVFreq();
7029         stOutFrameInfo.bInterlace = stXCSetWinInfo.bInterlace;
7030 
7031         //-------------------------
7032         _DMS_XC_Set_ScalingDown_Condition(&pstDMS_SetWin_Info->stOutputWinInfo.stCropWin, &pstDMS_SetWin_Info->stOutputWinInfo.stOutputWin);
7033         if(_DMS_Is_ScalingConditionUse2ndBuffer(RES_DMS.gDMS_ScalingCondition))
7034         {
7035             pstDMS_SetWin_Info->stOutputWinInfo.stCropWin.u32width = pstDMS_SetWin_Info->stOutputWinInfo.stCropWin.u32width / 2;
7036             pstDMS_SetWin_Info->stOutputWinInfo.stCropWin.u32height = pstDMS_SetWin_Info->stOutputWinInfo.stCropWin.u32height / 2;
7037         }
7038 
7039         _DMS_XC_DMSWintoXCWin(&stXCSetWinInfo.stCapWin, &pstDMS_SetWin_Info->stOutputWinInfo.stCropWin);
7040         _DMS_XC_DMSWintoXCWin(&stXCSetWinInfo.stDispWin, &pstDMS_SetWin_Info->stOutputWinInfo.stOutputWin);
7041         _DMS_XC_DMSWintoXCWin(&stXCSetWinInfo.stCropWin, &pstDMS_SetWin_Info->stOutputWinInfo.stCropWin);
7042 
7043         //-------------------------
7044         // customized pre scaling
7045         //-------------------------
7046         stXCSetWinInfo.bPreHCusScaling = FALSE;
7047         stXCSetWinInfo.u16PreHCusScalingSrc = pstDMS_SetWin_Info->stOutputWinInfo.stCropWin.u32width;
7048         stXCSetWinInfo.u16PreHCusScalingDst = pstDMS_SetWin_Info->stOutputWinInfo.stCropWin.u32width;
7049         stXCSetWinInfo.bPreVCusScaling = FALSE;
7050         stXCSetWinInfo.u16PreVCusScalingSrc = pstDMS_SetWin_Info->stOutputWinInfo.stCropWin.u32height;
7051         stXCSetWinInfo.u16PreVCusScalingDst = pstDMS_SetWin_Info->stOutputWinInfo.stCropWin.u32height;
7052 
7053         //customized Post scaling
7054         stXCSetWinInfo.bHCusScaling = FALSE;
7055         stXCSetWinInfo.bVCusScaling = FALSE;
7056 
7057         MDrv_MVOP_SetStartPos(stXCSetWinInfo.stCropWin.x, stXCSetWinInfo.stCropWin.y);
7058         MDrv_MVOP_SetImageWidthHight(stXCSetWinInfo.stCropWin.width, stXCSetWinInfo.stCropWin.height);
7059         MDrv_MVOP_SetRegSizeFromMVD(FALSE);
7060 
7061         // ds patch
7062         stXCDsInfo.bOP_DS_On = FALSE;
7063         stXCDsInfo.bIPS_DS_On = FALSE;
7064         stXCDsInfo.bIPM_DS_On = FALSE;
7065         u32DSInfoLen = sizeof(XC_DynamicScaling_Info);
7066         MApi_XC_SetDynamicScaling(&stXCDsInfo, u32DSInfoLen, 0);
7067 
7068         MApi_XC_SkipWaitVsync(MAIN_WINDOW,TRUE);
7069         MApi_XC_SetWindow(&stXCSetWinInfo, sizeof(XC_SETWIN_INFO), MAIN_WINDOW);
7070         MApi_XC_SkipWaitVsync(MAIN_WINDOW,FALSE);
7071 
7072         MApi_XC_EnableFrameBufferLess(_DMS_Is_ScalingConditionUseFBL(RES_DMS.gDMS_ScalingCondition));
7073         MApi_XC_OutputFrameCtrl(TRUE, &stOutFrameInfo, MAIN_WINDOW);
7074     }
7075 #endif
7076     bRet = _MDrv_DMS_SetWin(pInstance, &pstDMS_SetWin_Info->stOutputWinInfo.stCropWin, &pstDMS_SetWin_Info->stOutputWinInfo.stOutputWin, u32WindowID);
7077     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
7078     return (bRet)? E_DMS_OK : E_DMS_FAIL;
7079 }
7080 
MDrv_DMS_GetWindowInfo(void * pInstance,MS_U32 u32WindowID,ST_DMS_WINDOW_INFO * pstDMS_GetWin_Info)7081 EN_DMS_RESULT MDrv_DMS_GetWindowInfo(void* pInstance, MS_U32 u32WindowID, ST_DMS_WINDOW_INFO *pstDMS_GetWin_Info)
7082 {
7083     return E_DMS_OK;
7084 }
7085 
MDrv_DMS_Video_Flip(void * pInstance,MS_U32 u32WindowID,ST_DMS_DISPFRAMEFORMAT * pstDispFrameFormat)7086 EN_DMS_RESULT MDrv_DMS_Video_Flip(void* pInstance, MS_U32 u32WindowID, ST_DMS_DISPFRAMEFORMAT* pstDispFrameFormat)
7087 {
7088     DMS_VDECFRAME_INFO stFrameInfo;
7089     memset(&stFrameInfo, 0 , sizeof(stFrameInfo));
7090     stFrameInfo.u32Window = u32WindowID;
7091 
7092     stFrameInfo.u16SrcWidth = pstDispFrameFormat->stFrames[0].u32Width;
7093     stFrameInfo.u16SrcHeight = pstDispFrameFormat->stFrames[0].u32Height;
7094     stFrameInfo.u16SrcPitch = pstDispFrameFormat->stFrames[0].stHWFormat.u32LumaPitch;
7095     stFrameInfo.u32SrcLumaAddr = pstDispFrameFormat->stFrames[0].stHWFormat.phyLumaAddr;
7096     stFrameInfo.u32SrcChromaAddr = pstDispFrameFormat->stFrames[0].stHWFormat.phyChromaAddr;
7097     stFrameInfo.eFieldType = pstDispFrameFormat->stFrames[0].enFieldType;
7098 
7099     stFrameInfo.u16CropRight = pstDispFrameFormat->stFrames[0].u32CropRight;
7100     stFrameInfo.u16CropLeft = pstDispFrameFormat->stFrames[0].u32CropLeft;
7101     stFrameInfo.u16CropBottom = pstDispFrameFormat->stFrames[0].u32CropBottom;
7102     stFrameInfo.u16CropTop = pstDispFrameFormat->stFrames[0].u32CropTop;
7103 
7104     stFrameInfo.u32FrameRate = pstDispFrameFormat->u32FrameRate;
7105     stFrameInfo.eCODEC = pstDispFrameFormat->u32CodecType;
7106     stFrameInfo.eTileMode = pstDispFrameFormat->u32TileMode;
7107     stFrameInfo.eFmt = _DMS_GetColorFormat(pstDispFrameFormat->enColorFormat);
7108 
7109     stFrameInfo.eScanType = _DMS_GetDMSScanType(pstDispFrameFormat->u8Interlace);
7110     stFrameInfo.eFieldOrderType  = !(pstDispFrameFormat->u8BottomFieldFirst);
7111 
7112     if(stFrameInfo.eScanType == E_DMS_VIDEO_SCAN_TYPE_INTERLACE_FIELD)
7113     {
7114         stFrameInfo.u32SrcLumaAddrI = pstDispFrameFormat->stFrames[1].stHWFormat.phyLumaAddr;
7115         stFrameInfo.u32SrcChromaAddrI = pstDispFrameFormat->stFrames[1].stHWFormat.phyChromaAddr;
7116         stFrameInfo.u32FrameIndex_2nd = pstDispFrameFormat->stFrames[1].u32Idx;
7117         stFrameInfo.u32PriData_2nd = pstDispFrameFormat->stFrames[1].u32PriData;
7118     }
7119 
7120     stFrameInfo.b10bitData = (pstDispFrameFormat->enColorFormat == E_DMS_COLOR_FORMAT_10BIT_TILE)? TRUE : FALSE;
7121     if(stFrameInfo.b10bitData)
7122     {
7123         stFrameInfo.u16Src10bitPitch = pstDispFrameFormat->stFrames[0].stHWFormat.u32LumaPitch2Bit;
7124         stFrameInfo.u32SrcLumaAddr_2bit = pstDispFrameFormat->stFrames[0].stHWFormat.phyLumaAddr2Bit;
7125         stFrameInfo.u32SrcChromaAddr_2bit = pstDispFrameFormat->stFrames[0].stHWFormat.phyChromaAddr2Bit;
7126         stFrameInfo.u8LumaBitdepth = pstDispFrameFormat->stFrames[0].u8LumaBitdepth;
7127     }
7128 
7129     /// Frame index
7130     stFrameInfo.u32FrameIndex = pstDispFrameFormat->stFrames[0].u32Idx;
7131     stFrameInfo.u32VDECStreamID = pstDispFrameFormat->u32VdecStreamId;
7132     stFrameInfo.u32VDECStreamVersion = pstDispFrameFormat->u32VdecStreamVersion;
7133     stFrameInfo.u32PriData = pstDispFrameFormat->stFrames[0].u32PriData;
7134     stFrameInfo.u64Pts = pstDispFrameFormat->u64Pts;
7135     if(gDMSMVOPForceLookVDEC)
7136     {
7137         //DMS_PRINTF("Flip%d: Y 0x%llx, C 0x%llx, pri 0x%x\n",u32WindowID,stFrameInfo.u32SrcLumaAddr,stFrameInfo.u32SrcChromaAddr,stFrameInfo.u32PriData);
7138     }
7139 
7140     //mfcodec info
7141     stFrameInfo.stMFdecInfo.bMFDec_Enable = pstDispFrameFormat->stFrames[0].stHWFormat.u32MFCodecInfo & 0xFF ;
7142     if(stFrameInfo.stMFdecInfo.bMFDec_Enable != 0 && stFrameInfo.stMFdecInfo.bMFDec_Enable != 0xFF)
7143     {
7144         stFrameInfo.stMFdecInfo.bMFDec_Enable = 1;
7145         stFrameInfo.stMFdecInfo.bBypass_codec_mode = 0;
7146         stFrameInfo.stMFdecInfo.u8MFDec_Select = (pstDispFrameFormat->stFrames[0].stHWFormat.u32MFCodecInfo >> 8) & 0x3;     //Bit[8]      MFDec ID. 1: MFDec 1; 0: MFDec 0; 2 MFDec 2;
7147         stFrameInfo.stMFdecInfo.bUncompress_mode = (pstDispFrameFormat->stFrames[0].stHWFormat.u32MFCodecInfo >> 28) & 0x1;  //Bit[28]     1: MFCodec uncompress mode; 0: data is compressed
7148         stFrameInfo.stMFdecInfo.en_MFDecVP9_mode = (pstDispFrameFormat->stFrames[0].stHWFormat.u32MFCodecInfo >> 29) & 0x1;  //Bit[29]     1: MFCodec 3.0 vp9 mode; 0: MFCodec 3.0 h26x mode
7149         stFrameInfo.stMFdecInfo.u16Bitlen_Pitch = (pstDispFrameFormat->stFrames[0].stHWFormat.u32MFCodecInfo >> 16) & 0xFF; //Bits[23:16] MFCodec pitch setting
7150 
7151         stFrameInfo.stMFdecInfo.u16StartX = stFrameInfo.u16CropLeft;
7152         stFrameInfo.stMFdecInfo.u16StartY = stFrameInfo.u16CropTop;
7153 
7154         MS_U8 u8BitLenmiu = 0;
7155         u8BitLenmiu = (pstDispFrameFormat->stFrames[0].stHWFormat.u32MFCodecInfo >> 24) & 0xF ;
7156         stFrameInfo.stMFdecInfo.u8Bitlen_MiuSelect = u8BitLenmiu;
7157         stFrameInfo.stMFdecInfo.phyBitlen_Base = (u8BitLenmiu == 0) ? (MS_PHY)pstDispFrameFormat->stFrames[0].stHWFormat.phyMFCBITLEN : ((MS_PHY)pstDispFrameFormat->stFrames[0].stHWFormat.phyMFCBITLEN | HAL_MIU1_BASE);
7158     }
7159     else
7160     {
7161         stFrameInfo.stMFdecInfo.bMFDec_Enable = 0;
7162     }
7163 
7164     //set 2nd buffer (real case use a flag to control MVOP watch which buffer)
7165     if(pstDispFrameFormat->stFrames[0].stHWFormat.u8V7DataValid & BIT(0))
7166     {
7167         stFrameInfo.phySrc2ndBufferLumaAddr = pstDispFrameFormat->stFrames[0].stHWFormat.phyLumaAddr_subsample;
7168         stFrameInfo.phySrc2ndBufferChromaAddr = pstDispFrameFormat->stFrames[0].stHWFormat.phyChromaAddr_subsample;
7169         stFrameInfo.u16Src2ndBufferPitch = pstDispFrameFormat->stFrames[0].stHWFormat.u16Pitch_subsample;
7170         stFrameInfo.u8Src2ndBufferTileMode = pstDispFrameFormat->stFrames[0].stHWFormat.u8TileMode_subsample;
7171         stFrameInfo.u8Src2ndBufferV7DataValid = pstDispFrameFormat->stFrames[0].stHWFormat.u8V7DataValid;
7172         stFrameInfo.u16Src2ndBufferWidth = pstDispFrameFormat->stFrames[0].stHWFormat.u16Width_subsample;
7173         stFrameInfo.u16Src2ndBufferHeight = pstDispFrameFormat->stFrames[0].stHWFormat.u16Height_subsample;
7174     }
7175     else
7176     {
7177         //Patch for no 2nd buffer come
7178         if(stFrameInfo.u16SrcWidth >= CONDITION_4K_WIDTH && stFrameInfo.u16SrcHeight >= CONDITION_4K_HEIGHT)
7179         {
7180             static MS_BOOL v7verify = TRUE;
7181             if(v7verify)
7182             {
7183                 VDEC_EX_FrameInfoExt_v7 stFrmInfo_v7;
7184                 memset(&stFrmInfo_v7,0,sizeof(VDEC_EX_FrameInfoExt_v7));
7185                 VDEC_EX_VerCtl *stVerCrl = (VDEC_EX_VerCtl *) &stFrmInfo_v7;
7186                 stVerCrl->u32version = 7;
7187                 stVerCrl->u32size = sizeof(VDEC_EX_FrameInfoExt_v7);
7188                 VDEC_StreamId stVDEC_StreamId;
7189                 stVDEC_StreamId.u32Id = stFrameInfo.u32VDECStreamID;
7190                 stVDEC_StreamId.u32Version = stFrameInfo.u32VDECStreamVersion;
7191                 if (E_VDEC_EX_OK == MApi_VDEC_EX_GetControl(&stVDEC_StreamId, E_VDEC_EX_USER_CMD_GET_NEXT_DISP_FRAME_INFO_EXT, (MS_U32 *)&stFrmInfo_v7))
7192                 {
7193                     stFrameInfo.phySrc2ndBufferLumaAddr = stFrmInfo_v7.phyLumaAddr_subsample;
7194                     stFrameInfo.phySrc2ndBufferChromaAddr = stFrmInfo_v7.phyChromaAddr_subsample;
7195                     stFrameInfo.u16Src2ndBufferPitch = stFrmInfo_v7.u16Pitch_subsample;
7196                     if(stFrameInfo.u16Src2ndBufferPitch != 0)
7197                     {
7198                         static MS_BOOL bLogFlag = FALSE;
7199                         if(!bLogFlag)
7200                         {
7201                             DMS_PRINTF("[%s] Get 2nd Buffer in DMS! This is patch, need flip info for DMS!\n",__FUNCTION__);
7202                             bLogFlag = TRUE;
7203                         }
7204                     }
7205                     else
7206                     {
7207                         v7verify = FALSE;
7208                         DMS_PRINTF("[%s] Get 2nd Buffer in DMS! But pitch is 0, do not get any more!\n",__FUNCTION__);
7209                     }
7210                 }
7211                 else
7212                 {
7213                     DMS_PRINTF("[%s] VDEC info ver7 not impl, get sub_buffer failed\n",__FUNCTION__);
7214                     v7verify = FALSE;
7215                 }
7216             }
7217         }
7218     }
7219 
7220     //Field ctrl
7221     stFrameInfo.u8FieldCtrl = pstDispFrameFormat->u8FieldCtrl;
7222 
7223     //DMS_PRINTF("%d %d %d\n",stFrameInfo.eScanType,pstDispFrameFormat->u8Interlace,stFrameInfo.eTileMode);
7224     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
7225     DMS_GET_RES_PRI;
7226 
7227 #if (DMS_MAIN_WINDOW_FLOW_VERSION == 0)
7228 #if 0
7229     if(u32WindowID == MVOP_WINDOW)
7230     {
7231         MS_BOOL ret;
7232         MS_U16 NextWritePointer = 0;
7233 
7234         NextWritePointer = RES_DMS._stXC_DIPWriteReadPointer[stFrameInfo.u32Window].u16WritePointer;
7235         RES_DMS._stXC_DIPWriteReadPointer[stFrameInfo.u32Window].u16WritePointer = NextWritePointer;
7236         memcpy(&RES_DMS.stFrameInfo_mainWin[NextWritePointer], &stFrameInfo, sizeof(DMS_VDECFRAME_INFO));
7237 
7238         ret = _DMS_VDEC_Frame_AddRef_MVOP(pDMSResPri->stDrvDMSMvop.s32Frame_index);
7239         //if(pDMSResPri->stDrvDMSMvop.s32Release_Frame_index >= 0)
7240         //{
7241         //    ret = _DMS_VDEC_Frame_Release_MVOP(pDMSResPri->stDrvDMSMvop.s32Release_Frame_index);
7242         //}
7243 
7244         //MsOS_EnableInterrupt(E_INT_IRQ_DC);
7245         //MDrv_MVOP_EnableInterrupt(E_MVOP_INT_VSYNC);
7246 
7247     }
7248 #endif
7249 #else
7250 #if (DEV_DI == 1)
7251     if(_DMS_Is_MVOPFlow(u32WindowID) && _DMS_Is_SourceInterlace(stFrameInfo.eScanType))
7252     {
7253         _DMS_StoreVDECInfo2DIPInterlaceQueue(&stFrameInfo);
7254         RES_DMSDI._u8DMS_DiSetEventBufferID = RES_DMSDI._stXC_DIPWriteReadPointerInterlace[u32WindowID].u16WritePointer;
7255 #if DEV_DI_EVENT
7256         //MsOS_SetEvent(XC_Di_Push_Event_id, 0x01);
7257 #else
7258         RES_DMSDI.bFlipToDiTask = TRUE;
7259 #endif
7260         if(_DMS_Is_SourceFrameBaseInterlace(stFrameInfo.eScanType,stFrameInfo.eFieldType)
7261             || _DMS_Is_SourceFieldBaseInterlace(stFrameInfo.eScanType))
7262         {
7263             stFrameInfo.bIs2ndField = TRUE;
7264             _DMS_StoreVDECInfo2DIPInterlaceQueue(&stFrameInfo);
7265         }
7266     }
7267     else
7268 #endif
7269 #endif
7270     {
7271 #if 0
7272         if(u32WindowID != MVOP_WINDOW)
7273 #endif
7274         {
7275             _DMS_StoreVDECInfo2DIPQueue(pInstance, &stFrameInfo);
7276         }
7277 #if (DMS_MAIN_WINDOW_FLOW_VERSION == 1)
7278         if(_DMS_Is_MVOPFlow(u32WindowID))
7279         {
7280             RES_DMSDI._u8DMS_DiSetEventBufferID = DMS_Invalid_ReadPointer_ID;
7281         }
7282 #endif
7283 #if 0
7284         if(u32WindowID != MVOP_WINDOW)
7285 #endif
7286         {
7287             if(_DMS_Is_SourceFrameBaseInterlace(stFrameInfo.eScanType,stFrameInfo.eFieldType)
7288                 || _DMS_Is_SourceFieldBaseInterlace(stFrameInfo.eScanType))
7289             {
7290                 stFrameInfo.bIs2ndField = TRUE;
7291                 _DMS_StoreVDECInfo2DIPQueue(pInstance, &stFrameInfo);
7292             }
7293         }
7294     }
7295 #if DBG_FPS
7296     u32FPS_Push_Counter[u32WindowID]++;
7297 #endif
7298     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
7299 
7300     return TRUE;
7301 }
7302 
MDrv_DMS_SetZOrder(void * pInstance,MS_U32 u32WindowID,MS_U32 u32ZOrder)7303 EN_DMS_RESULT MDrv_DMS_SetZOrder(void* pInstance, MS_U32 u32WindowID, MS_U32 u32ZOrder)
7304 {
7305     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
7306     DMS_GET_RES_PRI;
7307     MS_BOOL bRet = FALSE;
7308 
7309     bRet = _MDrv_DMS_SetWindowZOrder(u32WindowID, u32ZOrder);
7310     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
7311     return (bRet)? E_DMS_OK : E_DMS_FAIL;
7312 }
7313 
MDrv_DMS_Video_Freeze(void * pInstance,MS_U32 u32WindowID,MS_U32 u32Enable)7314 EN_DMS_RESULT MDrv_DMS_Video_Freeze(void* pInstance, MS_U32 u32WindowID, MS_U32 u32Enable)
7315 {
7316     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
7317     DMS_GET_RES_PRI;
7318     DMS_PRINTF("\033[32m [%s][%d] === u32Enable : %td === \033[0m\n",__FUNCTION__,__LINE__,(ptrdiff_t)u32Enable);
7319     if(u32Enable)
7320     {
7321         RES_DMS.bDMS_Freeze_DoubleBuffer = TRUE;
7322     }
7323     else
7324     {
7325         RES_DMS.bDMS_Freeze_DoubleBuffer = FALSE;
7326     }
7327 
7328     if(_DMS_Is_MVOPFlow(u32WindowID) == TRUE)
7329     {
7330         _DMS_Add_XC_Status(u32WindowID, DMS_XC_FREEZE_SETTING);
7331     }
7332     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
7333     return TRUE;
7334 }
7335 
_MDrv_DMS_SetMute(void * pInstance,MS_U32 u32WindowID,MS_U32 u32Enable)7336 static MS_BOOL _MDrv_DMS_SetMute(void* pInstance, MS_U32 u32WindowID, MS_U32 u32Enable)
7337 {
7338     DMS_GET_RES_PRI;
7339     if(_DMS_Is_MVOPFlow(u32WindowID) == TRUE)
7340     {
7341 #if(DMS_MAIN_WINDOW_FLOW_VERSION == 1)
7342         Hal_DMS_XC_SetMute(pInstance, u32Enable);
7343 #else
7344       if(u32Enable)
7345       {
7346           Hal_DMS_XC_SetMute(pInstance, u32Enable);
7347       }
7348       else
7349       {
7350           if(RES_DMS.bFirstPlay)
7351           {
7352               RES_DMS.bDisableBlackScreen = TRUE;
7353           }
7354           else
7355           {
7356               Hal_DMS_XC_SetMute(pInstance, u32Enable);
7357           }
7358        }
7359 #endif
7360     }
7361     else
7362     {
7363         RES_DMS.bIsWindowMute[u32WindowID] = u32Enable;
7364         RES_DMS._stXC_DispBuf_Flag[E_DMS_DIP_MULTIVIEW_BUF_ID_0][u32WindowID].bCleanBuf = u32Enable;
7365         RES_DMS._stXC_DispBuf_Flag[E_DMS_DIP_MULTIVIEW_BUF_ID_1][u32WindowID].bCleanBuf = u32Enable;
7366     }
7367     return TRUE;
7368 }
7369 
MDrv_DMS_Video_Mute(void * pInstance,MS_U32 u32WindowID,MS_U32 u32Enable)7370 EN_DMS_RESULT MDrv_DMS_Video_Mute(void* pInstance, MS_U32 u32WindowID, MS_U32 u32Enable)
7371 {
7372     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
7373     DMS_GET_RES_PRI;
7374     MS_BOOL bRet = FALSE;
7375 
7376     bRet = _MDrv_DMS_SetMute(pInstance, u32WindowID, u32Enable);
7377     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
7378     return (bRet)? E_DMS_OK : E_DMS_FAIL;
7379 }
7380 
MDrv_DMS_Set_MuteColor(void * pInstance,MS_U32 u32WindowID,ST_DMS_COLOR stMuteColor)7381 EN_DMS_RESULT MDrv_DMS_Set_MuteColor(void* pInstance, MS_U32 u32WindowID, ST_DMS_COLOR stMuteColor)
7382 {
7383     DMS_PRINTF("\033[32m [%s][%d] === Not Impl %td=== \033[0m\n",__FUNCTION__,__LINE__,(ptrdiff_t)u32WindowID);
7384     return E_DMS_OK;
7385 }
7386 
MDrv_DMS_GetStatus(void * pInstance,MS_U32 * pu32Status)7387 EN_DMS_RESULT MDrv_DMS_GetStatus(void* pInstance, MS_U32 *pu32Status)
7388 {
7389     DMS_PRINTF("\033[32m [%s][%d] === Not Impl === \033[0m\n",__FUNCTION__,__LINE__);
7390     return E_DMS_OK;
7391 }
7392 
MDrv_DMS_GetCapability(void * pInstance,EN_DMS_CAPABILITY * peCapability)7393 EN_DMS_RESULT MDrv_DMS_GetCapability(void* pInstance, EN_DMS_CAPABILITY *peCapability)
7394 {
7395     HAL_DMS_XC_GetCaps(pInstance, peCapability);
7396     return E_DMS_OK;
7397 }
7398 
MDrv_DMS_SetOutputLayer(void * pInstance,ST_DMS_WINDOW * pstLayer)7399 EN_DMS_RESULT MDrv_DMS_SetOutputLayer(void* pInstance, ST_DMS_WINDOW *pstLayer)
7400 {
7401     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
7402     DMS_GET_RES_PRI;
7403     memcpy(&RES_DMS.stOutputLayer,pstLayer,sizeof(ST_DMS_WINDOW));
7404     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
7405     return E_DMS_OK;
7406 }
7407 
MDrv_DMS_Set_3D_Mode(void * pInstance,MS_U32 u32WindowID,ST_DMS_3D_INFO * pst3DInfo)7408 EN_DMS_RESULT MDrv_DMS_Set_3D_Mode(void* pInstance, MS_U32 u32WindowID, ST_DMS_3D_INFO *pst3DInfo)
7409 {
7410     MS_BOOL bRet = FALSE;
7411     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
7412     DMS_GET_RES_PRI;
7413     if(MApi_XC_Set_3D_Mode(pst3DInfo->en3DInputMode, pst3DInfo->en3DOutputMode, pst3DInfo->en3DPanelType, MAIN_WINDOW))
7414     {
7415         if(FALSE == MApi_XC_Set_3D_Mode(pst3DInfo->en3DInputMode, pst3DInfo->en3DOutputMode, pst3DInfo->en3DPanelType, SUB_WINDOW))
7416         {
7417             DMS_PRINTF("MApi_XC_Set_3D_Mode for Sub window failed\n");
7418             bRet = FALSE;
7419         }
7420     }
7421     else
7422     {
7423         DMS_PRINTF("MApi_XC_Set_3D_Mode for Main window failed\n");
7424         bRet = FALSE;
7425     }
7426 
7427     if(pst3DInfo->en3DInputMode == E_DMS_3D_INPUT_MODE_NONE || pst3DInfo->en3DOutputMode == E_DMS_3D_OUTPUT_MODE_NONE)
7428     {
7429         DMS_PRINTF("Disable 3D\n");
7430         MApi_XC_EnableFrameBufferLess(TRUE);
7431         MApi_XC_Set_DynamicScalingFlag(TRUE);
7432     }
7433     else
7434     {
7435         DMS_PRINTF("Enable 3D\n");
7436         MApi_XC_EnableFrameBufferLess(FALSE);
7437         MApi_XC_Set_DynamicScalingFlag(FALSE);
7438     }
7439 
7440     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
7441     return (bRet)? E_DMS_OK : E_DMS_FAIL;
7442 }
7443 
_MDrv_DMS_CaptureMode_ColorFmtMapping(MS_U32 u32WindowID,EN_DMS_CAPTURE_COLORFORMAT enColorFormat)7444 EN_DMS_DIP_FMT _MDrv_DMS_CaptureMode_ColorFmtMapping(MS_U32 u32WindowID, EN_DMS_CAPTURE_COLORFORMAT enColorFormat)
7445 {
7446     DMS_GET_RES_PRI;
7447     EN_DMS_DIP_FMT eFmt;
7448     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].enTileBlock = DMS_DIP_TILE_BLOCK_W_16_32;
7449     switch(enColorFormat)
7450     {
7451         case E_DMS_CAPTURE_COLOR_FORMAT_16X32TILE:
7452             eFmt = E_DMS_DIP_FMT_YUV420;
7453             break;
7454         case E_DMS_CAPTURE_COLOR_FORMAT_32X16TILE:
7455             eFmt = E_DMS_DIP_FMT_YUV420;
7456             RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].enTileBlock = DMS_DIP_TILE_BLOCK_W_32_16;
7457             break;
7458         case E_DMS_CAPTURE_COLOR_FORMAT_32X32TILE:
7459             eFmt = E_DMS_DIP_FMT_YUV420;
7460             RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].enTileBlock = DMS_DIP_TILE_BLOCK_W_32_32;
7461             break;
7462         case E_DMS_CAPTURE_COLOR_FORMAT_YUYV:
7463         case E_DMS_CAPTURE_COLOR_FORMAT_YVYU:
7464         case E_DMS_CAPTURE_COLOR_FORMAT_UYVY:
7465         case E_DMS_CAPTURE_COLOR_FORMAT_VYUY:
7466             eFmt = E_DMS_DIP_FMT_YUV422;
7467             break;
7468         case E_DMS_CAPTURE_COLOR_FORMAT_NV12:
7469         case E_DMS_CAPTURE_COLOR_FORMAT_NV21:
7470             eFmt = E_DMS_DIP_FMT_YUV420_SEMI_PLANER;
7471             break;
7472         case E_DMS_CAPTURE_COLOR_FORMAT_MAX:
7473         default:
7474             eFmt = E_DMS_DIP_FMT_MAX;
7475             printf("\033[31m [%s][%d] === Wrong color fmt! === \033[0m\n",__FUNCTION__,__LINE__);
7476             break;
7477     }
7478     return eFmt;
7479 }
7480 
MDrv_DMS_Set_CaptureInfo(void * pInstance,MS_U32 u32WindowID,ST_DMS_SET_CAPTURE_INFO * pstSetCaptureInfo)7481 EN_DMS_RESULT MDrv_DMS_Set_CaptureInfo(void* pInstance, MS_U32 u32WindowID, ST_DMS_SET_CAPTURE_INFO *pstSetCaptureInfo)
7482 {
7483 #if DEV_CAPMODE
7484     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
7485     DMS_GET_RES_PRI;
7486 
7487     if(pstSetCaptureInfo->u32Enable == FALSE)
7488     {
7489         RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32Enable = pstSetCaptureInfo->u32Enable;
7490         RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].bStartGetCapture = FALSE;
7491         MS_U8 u8BufID;
7492         for(u8BufID = 0; u8BufID < DMS_DIP_QUEUEDEPTH; u8BufID++)
7493         {
7494             _DMS_Clear_VDEC_Frame_Ref_CaptureMode(u32WindowID, u8BufID);
7495             RES_DMSCAPTURE.bIsFrameValid[u32WindowID][u8BufID] = FALSE;
7496         }
7497         MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
7498         return E_DMS_OK;
7499     }
7500 
7501     if(RES_DMS._stXC_DIPWinInfo[u32WindowID].bDIPwinUse == FALSE)
7502     {
7503         RES_DMS.u8UseDIPWindowCount++;
7504         _CalculateMaxOutputFrameRate();
7505 
7506         if(pstSetCaptureInfo->u32Visible == TRUE)
7507         {
7508             pstSetCaptureInfo->u32Visible = FALSE;
7509             DMS_PRINTF("\033[1;31m[%s][%d] error, Visible can't be TRUE before setting window info\033[0m\n",__FUNCTION__,__LINE__);
7510         }
7511     }
7512     RES_DMS.u8DIP_Window[E_DMS_DIP_CAPTURE] = DMS_DIPWindow_CAPTURE;
7513     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32Enable = pstSetCaptureInfo->u32Enable;
7514     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32Visible = pstSetCaptureInfo->u32Visible;
7515     if(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32Visible == FALSE)
7516     {
7517         _MDrv_DMS_SetMute(pInstance, u32WindowID, TRUE);
7518     }
7519     else
7520     {
7521         _MDrv_DMS_SetMute(pInstance, u32WindowID, FALSE);
7522     }
7523     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32FrameRate = pstSetCaptureInfo->u32FrameRate;
7524     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32Width = pstSetCaptureInfo->u32Width;
7525     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32Height = pstSetCaptureInfo->u32Height;
7526     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].enColorFormat = pstSetCaptureInfo->enColorFormat;
7527     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].enDIPDataFmt = _MDrv_DMS_CaptureMode_ColorFmtMapping(u32WindowID, pstSetCaptureInfo->enColorFormat);
7528     //RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].enColorFormat = E_DMS_DIP_FMT_YUV422;
7529 #if (DMS_DIP_Support_IMI == 0)
7530     MS_U32 BytesPerLine = 0;
7531     BytesPerLine = _DMS_DIP_CalcPitch(_DMS_DIP_Capture_ColorFmtMapping(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].enDIPDataFmt), RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32Width);
7532 
7533     MS_PHY phyMaxNeedSize = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32Height * BytesPerLine * DMS_CAPTUREWIN_RING_BUFFER;
7534 #if (DMS_DIP_Support_HVSP == 0)
7535     //phyMaxNeedSize += (RES_DMS._stXC_DIPCaptureWinInfo[u32WindowID].u32Height * BytesPerLine);
7536 #endif
7537     if(phyMaxNeedSize > pstSetCaptureInfo->phySize)
7538     {
7539         DMS_PRINTF("\033[1;31m[%s][%d] error, buffer not enough u32MemBufferSize 0x%llx , need 0x%llx\033[0m\n",__FUNCTION__,__LINE__,pstSetCaptureInfo->phySize, phyMaxNeedSize);
7540         return E_DMS_FAIL;
7541     }
7542 
7543     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32StartMemAddr = pstSetCaptureInfo->phyAddr;
7544     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32EndMemAddr = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32StartMemAddr + (BytesPerLine * RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32Height);
7545     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32SecondBufStartMemAddr = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32StartMemAddr + (BytesPerLine * RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32Height);
7546     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32SecondBufEndMemAddr = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32EndMemAddr + (BytesPerLine * RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32Height);
7547     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32ThirdBufStartMemAddr = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32SecondBufStartMemAddr + (BytesPerLine * RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32Height);
7548     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32ThirdBufEndMemAddr = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32SecondBufEndMemAddr + (BytesPerLine * RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32Height);
7549 
7550     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].stCaptureRingBuf[0].phyBufferYAddr = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32StartMemAddr;
7551     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].stCaptureRingBuf[1].phyBufferYAddr = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32SecondBufStartMemAddr;
7552     RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].stCaptureRingBuf[2].phyBufferYAddr = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32ThirdBufStartMemAddr;
7553 #endif
7554     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
7555 #endif
7556     return E_DMS_OK;
7557 }
7558 
MDrv_DMS_Get_CaptureBuffer(void * pInstance,MS_U32 u32WindowID,ST_DMS_CAPTURE_INFO * pstCaptureInfo)7559 EN_DMS_RESULT MDrv_DMS_Get_CaptureBuffer(void* pInstance, MS_U32 u32WindowID, ST_DMS_CAPTURE_INFO *pstCaptureInfo)
7560 {
7561 #if DEV_CAPMODE
7562 
7563 #if (DMS_DIP_Support_IMI == 0)
7564     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
7565     DMS_GET_RES_PRI;
7566     MS_U16 u16CurRingBufID = RES_DMSCAPTURE._stXC_DIPCaptureWin_RingBufferPointer[u32WindowID].u16PreWritePointer;
7567     if(RES_DMSCAPTURE.bIsRingBufAccessed[u16CurRingBufID] == TRUE)
7568     {
7569         RES_DMSCAPTURE._stXC_CaptureRingBufRefCount[u32WindowID][u16CurRingBufID]++;
7570 
7571         pstCaptureInfo->phyBufferYAddr = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].stCaptureRingBuf[u16CurRingBufID].phyBufferYAddr;
7572         pstCaptureInfo->phyBufferCAddr = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].stCaptureRingBuf[u16CurRingBufID].phyBufferCAddr;
7573         pstCaptureInfo->u64Pts = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].stCaptureRingBuf[u16CurRingBufID].u64Pts;
7574         pstCaptureInfo->u32frameCount = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32FrameCount;
7575         RES_DMSCAPTURE.bIsRingBufAccessed[u16CurRingBufID] = FALSE;
7576         MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
7577         return E_DMS_OK;
7578     }
7579     else
7580     {
7581         MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
7582         return E_DMS_FAIL;
7583     }
7584 #else
7585     MS_U32 u32WaitEventFlag = BIT(0)|BIT(1)|BIT(2)|BIT(3);
7586     MS_U32 u32Events = 0;
7587 
7588     DMS_GET_RES_PRI;
7589     if(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].bStartGetCapture == FALSE)
7590     {
7591         RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].bStartGetCapture = TRUE;
7592         RES_DMSCAPTURE._stXC_IMICaptureInfo[u32WindowID].bCaptureRet = FALSE;
7593         MsOS_WaitEvent(StartFRC_Event_id, u32WaitEventFlag, &u32Events, E_OR_CLEAR, MSOS_WAIT_FOREVER);
7594 
7595         if(u32Events == BIT(u32WindowID))
7596         {
7597             printf("\033[32m [%s][%d] Receive Event %td, %d, time %td !!!!!!\033[0m\n",__FUNCTION__,__LINE__, (ptrdiff_t)u32Events , BIT(u32WindowID), (ptrdiff_t)MsOS_GetSystemTime());
7598             RES_DMSCAPTURE._stXC_IMICaptureInfo[u32WindowID].bFirstCapFrame = TRUE;
7599         }
7600         else
7601         {
7602             printf("\033[31m [%s][%d] Receive Wrong Event %td, %d !\033[0m\n",__FUNCTION__,__LINE__, (ptrdiff_t)u32Events , BIT(u32WindowID));
7603         }
7604     }
7605     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
7606 
7607     if(RES_DMSCAPTURE._stXC_IMICaptureInfo[u32WindowID].bIsEventSent == FALSE)
7608     {
7609         RES_DMSCAPTURE._stXC_IMICaptureInfo[u32WindowID].bCaptureRet = FALSE;
7610         if(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u16PreviousWP != RES_DMSCAPTURE._stXC_DIPCapWin_WriteReadPointer[u32WindowID].u16ReadPointer)
7611         {
7612             MsOS_SetEvent(CaptureMode_Event_id, BIT(u32WindowID));
7613             RES_DMSCAPTURE._stXC_IMICaptureInfo[u32WindowID].bIsEventSent = TRUE;
7614         }
7615         MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
7616         return E_DMS_FAIL;
7617     }
7618     else
7619     {
7620         if(RES_DMSCAPTURE._stXC_IMICaptureInfo[u32WindowID].bCaptureRet == TRUE)
7621         {
7622             RES_DMSCAPTURE._stXC_IMICaptureInfo[u32WindowID].bIsEventSent = FALSE;
7623             pstCaptureInfo->u64Pts = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].stCaptureRingBuf[0].u64Pts;
7624             pstCaptureInfo->u32frameCount = RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].u32FrameCount;
7625             MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
7626             return E_DMS_OK;
7627         }
7628         else
7629         {
7630             MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
7631             return E_DMS_FAIL;
7632         }
7633     }
7634 #endif
7635 
7636 #endif
7637     return E_DMS_OK;
7638 }
7639 
7640 #if (DMS_DIP_Support_IMI == 0)
_MDrv_DMS_IsContentMatch(MS_U32 u32WindowID,MS_U8 u8BufferID,ST_DMS_CAPTURE_INFO * pstCaptureInfo)7641 static MS_BOOL _MDrv_DMS_IsContentMatch(MS_U32 u32WindowID, MS_U8 u8BufferID, ST_DMS_CAPTURE_INFO *pstCaptureInfo)
7642 {
7643     DMS_GET_RES_PRI;
7644     if(RES_DMSCAPTURE._stXC_DIPCaptureWinInfo[u32WindowID].stCaptureRingBuf[u8BufferID].phyBufferYAddr == pstCaptureInfo->phyBufferYAddr)
7645     {
7646         return TRUE;
7647     }
7648     else
7649     {
7650         return FALSE;
7651     }
7652 }
7653 #endif
7654 
MDrv_DMS_Release_CaptureBuffer(void * pInstance,MS_U32 u32WindowID,ST_DMS_CAPTURE_INFO * pstCaptureInfo)7655 EN_DMS_RESULT MDrv_DMS_Release_CaptureBuffer(void* pInstance, MS_U32 u32WindowID, ST_DMS_CAPTURE_INFO *pstCaptureInfo)
7656 {
7657 #if DEV_CAPMODE
7658     MDrv_DMS_Get_Semaphore(pInstance, E_DMS_ID_VAR);
7659     DMS_GET_RES_PRI;
7660 #if (DMS_DIP_Support_IMI == 0)
7661     MS_U8 u8BufferID = 0;
7662     for(u8BufferID=0; u8BufferID<DMS_CAPTUREWIN_RING_BUFFER; u8BufferID++)
7663     {
7664         if(_MDrv_DMS_IsContentMatch(u32WindowID, u8BufferID, pstCaptureInfo) == TRUE)
7665         {
7666             RES_DMSCAPTURE._stXC_CaptureRingBufRefCount[u32WindowID][u8BufferID]--;
7667         }
7668     }
7669 #else
7670     MS_U8 u8DIPWindowID = RES_DMS.u8DIP_Window[E_DMS_DIP_CAPTURE];
7671     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
7672     while(MApi_XC_DIP_GetResource(u8DIPWindowID) == E_APIXC_RET_FAIL)
7673     {
7674         MsOS_DelayTask(1);
7675     }
7676     MApi_XC_DIP_Ena(FALSE,u8DIPWindowID);
7677     MApi_XC_DIP_ReleaseResource(u8DIPWindowID);
7678     return E_DMS_OK;
7679 #endif
7680     MDrv_DMS_Release_Semaphore(pInstance, E_DMS_ID_VAR);
7681 #endif
7682     return E_DMS_OK;
7683 }
7684 
7685 
7686