Mpeg4ClipsCommon.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:26k
源码类别:

DVD

开发平台:

Others

  1. /****************************************************************************************
  2.  *  Copyright (c) 2004 ZORAN Corporation, All Rights Reserved
  3.  *  THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
  4.  *
  5.  *  File: $Workfile: Mpeg4ClipsCommon.c $             
  6.  *
  7.  * Description: 
  8.  * ============
  9.  *  MPEG4 Clips Common 
  10.  * 
  11.  * Log:
  12.  * ====
  13.  * $Revision: #12 $
  14.  * $Change: 29756 $ 
  15.  * Last Modified by $Author: robin.jiang $ at $DateTime: 2004/10/27 19:18:00 $ 
  16.  ****************************************************************************************
  17.  * Updates:
  18.  ****************************************************************************************
  19.  * $Log: /I76/I76_Common/I76_Reference/Playcore/Nav_Clips/Mpeg4ClipsCommon.c $
  20.  *
  21.  * 1 8/2/2004 RobinJ
  22.  * Created
  23.  *
  24.  ****************************************************************************************/
  25. #include "Config.h" // Global Configuration - do not remove!
  26. #ifdef _DEBUG
  27. #undef IFTRACE
  28. #define IFTRACE if (gTraceNavigator)
  29. #include "Debugdbgmain.h"
  30. #endif
  31. #include "PlaycoreNav_ClipsMpeg4ClipsCommon.h"
  32. #include "Decoderlow_levelDEC_LL_API.h"
  33. #include "PlaycoreNav_ClipsPE_Clips.h"
  34. #include "PlaycoreCoremainCoreGDef.h"
  35. //#include "PlaycoreNav_ClipsAVI_private.h"
  36. #include "Drivedrv_api.h"
  37. #include "Decoderlow_levelDEC_LL_Reg.h"
  38. #include "DecoderDEC_Set_DVP_Gen_Regs.h"
  39. #define SCR_RATE 90000L
  40. // Robin_1011_2004_D
  41. #ifdef PATCH_VIDEO_NOT_B
  42. BOOL bRequestPAL60 = FALSE;
  43. #endif
  44. extern void DEC_set_display_video_format(DEC_LL_DECODED_FRAME_RATE v_format);
  45. // Note: Any change in the following calculation might affect the accuracy of GoTo time
  46. // <<< Robin_1003_2004_B, improve the accuracy
  47. ///////////////////////////////////////////////////////////////////////////
  48. // Function name : _caclFrameOfTime
  49. // Purpose : calculate the frame number, correspond to time 
  50. // Input Parameters : wTime - Time
  51. // : dwRate - Time Rate
  52. // : dwScale - Time Scale
  53. // Output Parameters : 
  54. // Return type : DWORD
  55. ///////////////////////////////////////////////////////////////////////////
  56. WORD caclTimeOfFrame(DWORD dwFrameNumber, DWORD dwRate, DWORD dwScale)
  57. {
  58. DWORD dwTimeDelta;
  59. DWORD dwDelta;
  60. DWORD dwDelta100, dwDelta10000;
  61. DWORD dwTime;
  62. dwTimeDelta = (1000UL*dwScale)/dwRate; // in ms
  63. dwDelta = (1000UL*dwScale) - (dwTimeDelta * dwRate);
  64. // Robin_0201_2005, avoid the calculate overflow
  65. if (((10000UL*dwDelta)/10000UL) == dwDelta)
  66. {
  67. dwDelta = (10000UL*dwDelta) / dwRate;
  68. }
  69. else if (((5000UL*dwDelta)/5000UL) == dwDelta)
  70. {
  71. dwDelta = ((5000UL*dwDelta) / dwRate) * 2;
  72. }
  73. else if (((1000UL*dwDelta)/1000UL) == dwDelta)
  74. {
  75. dwDelta = ((1000UL*dwDelta) / dwRate) * 10;
  76. }
  77. else if (((100UL*dwDelta)/100UL) == dwDelta)
  78. {
  79. dwDelta = ((100UL*dwDelta) / dwRate) * 100;
  80. }
  81. dwDelta100 = dwDelta/100;
  82. dwDelta10000 = dwDelta%100;
  83. dwTime = dwFrameNumber * dwTimeDelta;
  84. dwTime += ((dwFrameNumber*dwDelta100 + ((dwFrameNumber*dwDelta10000)/100))/100);
  85. dwTime = (dwTime+500UL)/1000UL;
  86. return (WORD)dwTime;
  87. }
  88. ///////////////////////////////////////////////////////////////////////////
  89. // Function name : _caclFrameOfTime
  90. // Purpose : calculate the frame number, correspond to time 
  91. // Input Parameters : wTime - Time
  92. // : dwRate - Time Rate
  93. // : dwScale - Time Scale
  94. // Output Parameters : 
  95. // Return type : DWORD
  96. ///////////////////////////////////////////////////////////////////////////
  97. DWORD caclFrameOfTime(WORD wTime, DWORD dwRate, DWORD dwScale)
  98. {
  99. DWORD dwFrameRate;
  100. DWORD dwDelta;
  101. DWORD dwDelta100, dwDelta10000;
  102. DWORD dwFrameNumber;
  103. dwFrameRate = dwRate/dwScale;
  104. dwDelta = dwRate - (dwFrameRate*dwScale);
  105. // Robin_0201_2005, avoid the calculate overflow
  106. if (((10000UL*dwDelta)/10000UL) == dwDelta)
  107. {
  108. dwDelta = (10000UL*dwDelta)/dwScale;
  109. }
  110. else if (((5000UL*dwDelta)/5000UL) == dwDelta)
  111. {
  112. dwDelta = ((5000UL*dwDelta) / dwScale) * 2;
  113. }
  114. else if (((1000UL*dwDelta)/1000UL) == dwDelta)
  115. {
  116. dwDelta = ((1000UL*dwDelta) / dwScale) * 10;
  117. }
  118. else if (((100UL*dwDelta)/100UL) == dwDelta)
  119. {
  120. dwDelta = ((100UL*dwDelta) / dwScale) * 100;
  121. }
  122. dwDelta100 = dwDelta/100;
  123. dwDelta10000 = dwDelta%100;
  124. dwFrameNumber = wTime * dwFrameRate;
  125. dwFrameNumber += ((wTime*dwDelta100 + ((wTime*dwDelta10000)/100))/100);
  126. return dwFrameNumber;
  127. }
  128. // >>> Robin_1003_2004_B
  129. ///////////////////////////////////////////////////////////////////////////
  130. // Function name : convertFOURCCToString
  131. // Purpose : Converts 32 FOURCC bits into a string.
  132. // Input Parameters : fourcc - 32 bits representing the FOURCC.
  133. // Output Parameters: str - The string representing the FOURCC.
  134. // Return type : none
  135. ///////////////////////////////////////////////////////////////////////////
  136. void convertFOURCCToString(FOURCC forcc, LPSTR str)
  137. {
  138. str[0] = (CHAR)(forcc & 0x000000ff);
  139. str[1] = (CHAR)(forcc >> 8);
  140. str[2] = (CHAR)(forcc >> 16);
  141. str[3] = (CHAR)(forcc >> 24);
  142. }
  143. /////////////////////////////////////////////////////////////////////////////
  144. // Private Services
  145. ///////////////////////////////////////////////////////////////////////////
  146. // Function name : qwTimeDiv10000
  147. // Purpose : 64bits in unit of 100ns to 32bits in unit of ms  
  148. // Input Parameters : time - QWORD
  149. // Return type : DWORD
  150. // Description :
  151. ///////////////////////////////////////////////////////////////////////////
  152. DWORD qwTimeDiv10000(QWORD time)
  153. {
  154. DWORD temp, result;
  155. temp = (time[1] << 16) | (time[0] >> 16);
  156. result = (temp/10000UL);
  157. temp -= result * 10000UL;
  158. result <<= 16;
  159.     temp <<= 16;
  160. temp += (time[0] & 0xFFFFUL);
  161. result += (temp/10000UL);
  162. return result;
  163. }
  164. void UTF8ToUnicode(BYTE* pUTFBuffer, WORD*  pUnicodeBuffer, UINT16 uiBufferSize,  WORD* wLastUnicode, WORD* uiUnicodeBufferSize)
  165. {
  166. while(uiBufferSize--)
  167. {
  168. if ((*pUTFBuffer) < 0x80)
  169. {
  170. if ((*wLastUnicode) != 0)
  171. {
  172. *(pUnicodeBuffer++) = (*wLastUnicode);
  173. (*uiUnicodeBufferSize)++;
  174. (*wLastUnicode) = 0;
  175. }
  176. *(pUnicodeBuffer++) = (WORD)*pUTFBuffer;
  177. (*uiUnicodeBufferSize)++;
  178. }
  179. else if ((*pUTFBuffer) < 0xc0) // trail byte
  180. {
  181. (*wLastUnicode) <<= 6;
  182. (*wLastUnicode) += ((*pUTFBuffer) - 0x80);
  183. }
  184. else
  185. {
  186. if ((*wLastUnicode) != 0)
  187. {
  188. *(pUnicodeBuffer++) = (*wLastUnicode);
  189. (*uiUnicodeBufferSize)++;
  190. (*wLastUnicode) = 0;
  191. }
  192. if ((*pUTFBuffer) < 0xe0)
  193. (*wLastUnicode) = ((*pUTFBuffer) - 0xc0);
  194. else
  195. (*wLastUnicode) = ((*pUTFBuffer) - 0xe0);
  196. }
  197. pUTFBuffer++;
  198. }
  199. }
  200. ///////////////////////////////////////////////////////////////////////////
  201. // Function name : determineDivXVersion
  202. // Purpose : Determines whether the DivX version is 3, 4 or 5.
  203. // Input Parameters : uiStreamNumber - The video stream number to determine 
  204. //   its version.
  205. // Return type : The DivX version.
  206. // Description : See the SW SPEC for details.
  207. ///////////////////////////////////////////////////////////////////////////
  208. DivXVesrion determineDivXVersion(FOURCC fourccHandle, FOURCC fouccCompression)
  209. {
  210. CHAR fccHandler[FOURCC_FIELD_LENGTH];
  211. CHAR compressionType[FOURCC_FIELD_LENGTH];
  212. DivXVesrion divxVersion = DIVX_UNKNOWN;
  213. convertFOURCCToString(fourccHandle, fccHandler);
  214. convertFOURCCToString(fouccCompression, compressionType);
  215. if ( (0 == strnicmp(fccHandler, "div3", FOURCC_FIELD_LENGTH)) ||
  216. (0 == strnicmp(fccHandler, "div4", FOURCC_FIELD_LENGTH)))
  217. {
  218. divxVersion = DIVX_3_11;
  219. }
  220. else if (0 == strnicmp(fccHandler, "mp43", FOURCC_FIELD_LENGTH))
  221. {
  222. divxVersion = MP43;
  223. }
  224. else if ((0 == strnicmp(compressionType, "div3", FOURCC_FIELD_LENGTH)) ||
  225. (0 == strnicmp(compressionType, "div4", FOURCC_FIELD_LENGTH)) )
  226. {
  227. divxVersion = DIVX_3_11;
  228. }
  229. else if (0 == strnicmp(compressionType, "mp43", FOURCC_FIELD_LENGTH))
  230. {
  231. divxVersion = MP43;
  232. }
  233. else if (0 == strnicmp(compressionType, "divx", FOURCC_FIELD_LENGTH))
  234. {
  235. divxVersion = DIVX_4_12;
  236. }
  237. else if ((0 == strnicmp(compressionType, "dx50", FOURCC_FIELD_LENGTH)) ||
  238. (0 == strnicmp(compressionType, "dxsb", FOURCC_FIELD_LENGTH)))
  239. {
  240. divxVersion = DIVX_5_0;
  241. }
  242. else if (0 == strnicmp(compressionType, "xvid", FOURCC_FIELD_LENGTH))
  243. {
  244. divxVersion = XVID;
  245. }
  246. else if (0 == strnicmp(compressionType, "rmp4", FOURCC_FIELD_LENGTH))
  247. {
  248. divxVersion = RMP4;
  249. }
  250. else if (0 == strnicmp(compressionType, "mp4s", FOURCC_FIELD_LENGTH))
  251. {
  252. divxVersion = MP4S;
  253. }
  254. else if ((0 == strnicmp(compressionType, "3ivx", FOURCC_FIELD_LENGTH)) ||
  255. (0 == strnicmp(compressionType, "3iv2", FOURCC_FIELD_LENGTH)))
  256. {
  257. divxVersion = _3IVX;
  258. }
  259. else if (0 == strnicmp(compressionType, "mp4v", FOURCC_FIELD_LENGTH))
  260. {
  261. divxVersion = MP4V;
  262. }
  263. if (DIVX_UNKNOWN == divxVersion)
  264. {
  265. dbg_printf(("WARNING: Could not identify Video Codecn"));
  266. }
  267. else
  268. {
  269. dbg_printf(("Video Codec: %dn", divxVersion));
  270. }
  271. return divxVersion;
  272. }
  273. ///////////////////////////////////////////////////////////////////////////
  274. // Function name : determineAudioInfo
  275. // Purpose : Determines the audio info of a an audio stream.
  276. // Input Parameters : none
  277. // Ouput Parameters : The audio info.
  278. // Return type : TRUE if the operation succeeded, FALSE otherwise.
  279. // Description : The function determines the audio SID.
  280. ///////////////////////////////////////////////////////////////////////////
  281. BOOL determineAudioInfo(UINT8* puiAudioSid, UINT8* puiAudioSidDecoder,DWORD* dwSampleRate)
  282. {
  283. /* Check if an audio stream was found */
  284. if ((_mpeg4AudioAvailableNum == 0) || (NO_STREAM == _mpeg4AudioStreamID))
  285. {
  286. *puiAudioSid = NO_STREAM;
  287. *puiAudioSidDecoder = NoAudio;
  288. *dwSampleRate = 0;
  289. return TRUE;
  290. }
  291. /* Determine the audio stream */
  292. switch (_mpeg4AudioCodec)
  293. {
  294. case MP3:
  295. *puiAudioSid = AUDIO_STREAM_MP3;
  296. *puiAudioSidDecoder = MP3_SID;
  297. break;
  298. case AC3: 
  299. *puiAudioSid = AUDIO_STREAM_AC3;
  300. *puiAudioSidDecoder = AC3_SID;
  301. break;
  302. case MP2:
  303. *puiAudioSid = AUDIO_STREAM_MPEG;
  304. *puiAudioSidDecoder = MPEG_SID1;
  305. break;
  306. #ifdef D_ENABLE_ADPCM_SUPPORT
  307. case PCM:
  308. // <<< Robin_2004_0525_B, 
  309. // in 2X16Mbits, if PCM sample rate is greater than 48000, playback without audio 
  310. #ifdef SDRAM_2X16MBITS
  311. #ifdef NEW_2X16M_MAPPING
  312. if (_mpeg4AudioSamplesPerSec <= 48000UL)
  313. {
  314. *puiAudioSid = AUDIO_STREAM_ADPCM;
  315. *puiAudioSidDecoder = ADPCM_SID;
  316. }
  317. else
  318. #endif
  319. {
  320. dbg_printf(("PCM audio, sample rate is exceed 48K - not supported in 2X16M n"));
  321. *puiAudioSid = NO_STREAM;
  322. *puiAudioSidDecoder = NO_STREAM;
  323. // <<< Robin_0907_2004_C
  324. *dwSampleRate = 0;
  325. return TRUE;
  326. // >>> Robin_0907_2004_C
  327. }
  328. break;
  329. #endif
  330. // >>> Robin_2004_0525_B,
  331. case ADPCM:
  332. *puiAudioSid = AUDIO_STREAM_ADPCM;
  333. *puiAudioSidDecoder = ADPCM_SID;
  334. break;
  335. #endif
  336. #ifdef D_ENABLE_DIVX_WMA_SUPPORT
  337. case WMA:
  338. *puiAudioSid = AUDIO_STREAM_WMA;
  339. *puiAudioSidDecoder = WMA_SID;
  340. break;
  341. #endif
  342. #ifdef D_ENABLE_AAC_SUPPORT
  343. case AAC:
  344. *puiAudioSid = AUDIO_STREAM_AAC;
  345. *puiAudioSidDecoder = AAC_SID;
  346. break;
  347. #endif
  348. default:
  349. *puiAudioSid = NO_STREAM;
  350. *puiAudioSidDecoder = NO_STREAM;
  351. }
  352. *dwSampleRate = _mpeg4AudioSamplesPerSec;
  353. return TRUE;
  354. }
  355. AudioCodec determineAudioCodec(DWORD dwFormatTag, WORD wFormatTag, BOOL bMP4)
  356. {
  357. AudioCodec audioCodec = AUDIO_UNKNOWN;
  358. if (TRUE == bMP4) // mp4
  359. {
  360. switch (dwFormatTag)
  361. {
  362.  case MKTAG('m', 'p', '4', 'a'):
  363.   audioCodec = AAC;
  364.   break;
  365.  case MKTAG('.','m','p','3'):
  366.  case 0x6D730055UL:
  367.  case 0x5500736DUL:
  368.   audioCodec = MP3;
  369.   break;
  370.  case MKTAG('m','s',0x20,0x20):
  371.   audioCodec = AC3;
  372.   break;
  373.  case MKTAG('r','a','w',' '):
  374.  case MKTAG('s','o','w','t'):
  375.   audioCodec = PCM;
  376.   break;
  377.  case MKTAG('s','a','m','r'):
  378.  case MKTAG('s','a','w','b'):
  379.   dbg_printf(("AMR audio detected - not supportedn"));
  380. audioCodec = AUDIO_UNKNOWN;
  381. break;
  382.  case MKTAG('i','m','a','4'):
  383.   dbg_printf(("IMA-4 ADPCM audio detected - not supportedn"));
  384. audioCodec = AUDIO_UNKNOWN;
  385. break;
  386.  
  387.  default:
  388. dbg_printf(("Unknown audio detected- not supportedn"));
  389. audioCodec = AUDIO_UNKNOWN;
  390. }
  391. }
  392. else // avi, asf
  393. {
  394. switch (wFormatTag)
  395. {
  396. case MP3_AUDIO_SID:
  397. audioCodec = MP3;
  398. break;
  399. case AC3_AUDIO_SID: 
  400. audioCodec = AC3;
  401. break;
  402. case MPEG_AUDIO_SID:
  403. audioCodec = MP2;
  404. break;
  405. case PCM_AUDIO_SID:
  406. audioCodec = PCM;
  407. break;
  408. case ADPCM_MS_AUDIO_SID:
  409. audioCodec = ADPCM;
  410. break;
  411. case PCM_ALAW_AUDIO_SID:
  412. case PCM_MULAW_AUDIO_SID:
  413. dbg_printf(("PCM audio detected - not supportedn"));
  414. audioCodec = AUDIO_UNKNOWN;
  415. break;
  416. case ADPCM_IMA_WAV_AUDIO_SID:
  417. case ADPCM_IMA_DK4_AUDIO_SID:
  418. case ADPCM_IMA_DK3_AUDIO_SID:
  419. dbg_printf(("ADPCM audio detected - not supportedn"));
  420. audioCodec = AUDIO_UNKNOWN;
  421. break;
  422. case WMAV2_AUDIO_SID:
  423. audioCodec = WMA;
  424. break;
  425. case WMAV1_AUDIO_SID:
  426. dbg_printf(("WMA V1 audio detected - not supportedn"));
  427. audioCodec = AUDIO_UNKNOWN;
  428. break;
  429. default:
  430. dbg_printf(("Unknown audio detected- not supportedn"));
  431. audioCodec = AUDIO_UNKNOWN;
  432. }
  433. }
  434. if (AUDIO_UNKNOWN == audioCodec)
  435. {
  436. dbg_printf(("WARNING: Could not identify Audio Codecn"));
  437. }
  438. else
  439. {
  440. dbg_printf(("Audio Codec: %dn", audioCodec));
  441. }
  442.     return audioCodec;
  443. }
  444. ///////////////////////////////////////////////////////////////////////////
  445. // Function name : prePlayProcessing
  446. // Purpose : Calculate and send to the DVP the AVI file
  447. //   parameters.
  448. // Input Parameters : 
  449. // Return type :
  450. // Description :
  451. ///////////////////////////////////////////////////////////////////////////
  452. void prePlayProcessing(DWORD dwSamplingRate, UINT8 uiAudioSid,
  453.    UINT8 uiAudioSIDDecoder, UINT8 uiVideoSid, BOOL bClipStart)
  454. {
  455. // DWORD dwWidth = _aviStreamsInfo[0]._aviStreamFormat._bitMapInfoHeader.lWidth;
  456. // DWORD dwHeight = _aviStreamsInfo[0]._aviStreamFormat._bitMapInfoHeader.lHeight;
  457. WORD wRoundedWidth, wRoundedHeight, wNumOfMB;
  458. DWORD dwFrameIncr, dwFixVal, dwFixFreq;
  459. WORD wAudStreamNum, wVidStreamNum,wSubStreamNum;
  460. WORD tempInputFps1;
  461.     DWORD fieldCounter;
  462. UINT16 tempOutputFps;
  463.     WORD audio_format,audio_block_align, audio_bitspersample;
  464.     UINT8 uiOffsetToClear;
  465. #ifdef K1_WL
  466. DEC_LL_DECODED_FRAME_RATE v_format;
  467. #endif
  468. BOOL bInternalSubtitleIsText;
  469. #if 0
  470. /* set the width of the picture for slot machine replacement */
  471. DEC_AVI_SetPicWidth(dwWidth);
  472. #endif
  473. /* Kill any existing Zoom */
  474. //DEC_SetZoomScale(NO_ZOOM);
  475. // <<< Robin_1011_2004_D
  476. tempInputFps1 = (_mpeg4VideoRate*100)/_mpeg4VideoScale;
  477. #ifdef PATCH_VIDEO_NOT_B
  478. bRequestPAL60 = FALSE;
  479. if ((gps->tv_standard == TV_SYS_PAL)  && (tempInputFps1>2550) && (FALSE == _bMPEG4IsBVopExist))
  480. {
  481. dbg_printf(("Video is 30f/s, No B-VOP, PAL TV output.n"));
  482. bRequestPAL60 = TRUE;
  483. }
  484. #endif
  485. // >>> Robin_1011_2004_D
  486. #ifdef SUPPORT_FLASH_CARD
  487. // if(IS_PLAYING_CARD)
  488. drv_abort_play();
  489. #endif
  490. // Clear the Share RAM
  491. for (uiOffsetToClear = 0; uiOffsetToClear < 16; uiOffsetToClear++)
  492. DEC_AVI_ClearSharedOffset(uiOffsetToClear); 
  493. /* Set DVP indication that this is a pause-stop (and not pure pause) */
  494. DEC_AVI_SetDemuxSharedBit(AVI_FILE_PAUSE_OFFSET, AVI_FILE_PAUSE_BIT);
  495. /* Configure the Decoder to the appropriate bitstream type */
  496. DEC_Stop_DVP_ADP_cmd((UINT8)0);
  497. #ifndef SUPPORT_FLASH_CARD
  498. drv_abort_play();
  499. #endif
  500. DEC_AVI_SetDivXVersion(_mpeg4VideoCodec);
  501. if (SI_IS_CURRENT_AVI_CLIP)
  502. DEC_SetDiskType(DEC_DISC_TYPE_AVI);
  503. #ifdef IS_ASF_CAPABLE
  504. else if (SI_IS_CURRENT_ASF_CLIP)
  505. DEC_SetDiskType(DEC_DISC_TYPE_ASF);
  506. #endif
  507. #ifdef IS_MP4_CAPABLE
  508. else if (SI_IS_CURRENT_MP4_CLIP)
  509. DEC_SetDiskType(DEC_DISC_TYPE_MP4);
  510. #endif
  511. DEC_prepare_to_decode();  /* Downloads the DVP AVI microcode */
  512. gns.clips.iClipSamplingRate = dwSamplingRate;
  513. gcst.mAudioStream = uiAudioSid;
  514. DEC_SetSID(DEC_SID_TYPE_AUDIO, uiAudioSIDDecoder);
  515. DEC_SetSID(DEC_SID_TYPE_VIDEO, uiVideoSid);
  516. PE_Clips_SelectClock(eCT_Decoder);
  517. /* Calculate the parameters to be sent to the DEMUX */
  518. wRoundedWidth = ((_mpeg4VideoWidth + 15) / 16) * 16;
  519. wRoundedHeight = ((_mpeg4VideoHeight + 15) / 16) * 16;
  520. if (wRoundedWidth == 512 && ((_mpeg4VideoCodec != DIVX_3_11) && (_mpeg4VideoCodec != MP43))) // Robin_1125_2004, MP43 is same as DivX311 
  521. {
  522. wNumOfMB = ((wRoundedWidth / 16) + 1) * (wRoundedHeight / 16);
  523. }
  524. else 
  525. {
  526. wNumOfMB = (wRoundedWidth / 16) * (wRoundedHeight / 16);
  527. }
  528. if (SI_IS_CURRENT_AVI_CLIP)
  529. {
  530. wVidStreamNum = ((_mpeg4VideoStreamID+ '0') << 8) | '0';
  531. if (0xFF == uiAudioSid)
  532. {
  533. wAudStreamNum = 0xFF; // Instruct the DEMUX to drop the audio chunks
  534. }
  535. else
  536. {
  537. wAudStreamNum = ((_mpeg4AudioStreamID + '0') << 8) | '0';
  538. }
  539. wSubStreamNum = ((_mpeg4SubtitleStreamID + '0') <<8) | '0';
  540. }
  541. else
  542. {
  543. wVidStreamNum = _mpeg4VideoStreamID;
  544. wAudStreamNum = _mpeg4AudioStreamID;
  545. wSubStreamNum = _mpeg4SubtitleStreamID;
  546. }
  547.     /* Frame Increment in 90KHZ */
  548. dwFrameIncr = (SCR_RATE*_mpeg4VideoScale)/(_mpeg4VideoRate);
  549.     /* Rate Fix Value , Rate Fix Freq => every Rate Fix 
  550.  * Freq (7 Frames) add Rate Fix Value to the TimeStamp 
  551.  */
  552. dwFixVal = (((SCR_RATE*_mpeg4VideoScale) - (dwFrameIncr * _mpeg4VideoRate))*100)/(_mpeg4VideoRate);
  553. dwFixFreq = 100;
  554. /* set the video output according to the movie (PAL/NTSC)
  555.  * mainlly used for Auto Mode
  556.  * I will call this function only for clear case of PAL/NTSC
  557.  */
  558. // <<< Robin_1011_2004_C
  559. if((tempInputFps1 > 2450 && tempInputFps1 < 2550) ||  wRoundedHeight > 480)
  560. {
  561. #ifdef K1_WL
  562. // DEC_LL_GetCodedVideoStandard(&v_format);
  563. // if ((DEC_LL_DECODED_FRAME_RATE_NTSC == v_format) && clr_tmp_string)
  564. //   hide_time();
  565. // clr_tmp_string = TRUE;
  566. #endif
  567. DEC_set_display_video_format(DEC_LL_DECODED_FRAME_RATE_PAL);  //TODO: change according to FPS of bitstream
  568. }
  569. else
  570. {
  571. #ifdef K1_WL
  572. // DEC_LL_GetCodedVideoStandard(&v_format);
  573. // if ((DEC_LL_DECODED_FRAME_RATE_PAL == v_format) && clr_tmp_string)
  574. //   hide_time();
  575. // clr_tmp_string = TRUE;
  576. #endif
  577. DEC_set_display_video_format(DEC_LL_DECODED_FRAME_RATE_NTSC);  //TODO: change according to FPS of bitstream
  578. }
  579. // >>> Robin_1011_2004_C
  580.    //FW0408_2005D Move from AVIClip_play() because it should be set before play
  581. // Set AVI video scaling
  582. DEC_EnableManualScaling(PROG_SCALER_MODE_CCRAM);
  583. DEC_SetViewMode(gps->view_mode);
  584. /* Set picture size */
  585. DEC_set_coded_video_size(_mpeg4VideoWidth, _mpeg4VideoHeight);
  586. /* Set TV display aspect ratio */
  587. DEC_set_Display_AspectRatio(gps->tv_shape);
  588. if ((TRUE == bClipStart) && (_mpeg4VideoStreamID != NO_STREAM))
  589. {
  590. #ifdef PATCH_DIVX_GARBAGE
  591. DEC_LL_BackgroundSwitch(DEC_LL_BG_SWITCH_BACKGROUND);
  592. #endif
  593. gcst.mNeedScaling = TRUE; //FW_0526_2005B Should set before DVP start. In Divx3.11 ucode, DVP send scaling info right after video task start.
  594. }
  595. /* Calculate how many frames the DVP should drop */
  596. if (gcst.actual_tv_std == DEC_LL_OUT_VIDEO_STANDARD_PAL)
  597. {
  598. tempOutputFps = 2500; /* PAL output, multiplied by 100 */
  599. dbg_printf(("PALn"));
  600. }
  601. else
  602. {
  603. tempOutputFps = 2997; /* NTSC output, multiplied by 100 */;
  604. dbg_printf(("NTSCn"));
  605. }
  606. if (tempOutputFps > tempInputFps1)
  607. {
  608. /* need to repeat field every X fields */
  609. tempOutputFps -= tempInputFps1;
  610. /* Round fieldCounter up */
  611. fieldCounter = (tempInputFps1+tempOutputFps-1)/tempOutputFps;
  612. //fieldCounter = tempInputFps1/tempOutputFps;
  613. }
  614. else
  615. {
  616. /* need to drop frame every X frames */
  617. fieldCounter = 0;
  618. }
  619. dbg_printf(("nFrame incr: %ld, Frame fix val: %ld, Frame fix freq: %ldn",
  620. dwFrameIncr, dwFixVal, dwFixFreq-1));
  621. dbg_printf(("fieldCounter: %dn",fieldCounter));
  622. // RB_TBD, need change DVP
  623. #if (defined(D_ENABLE_DIVX_WMA_SUPPORT) || defined(D_ENABLE_ADPCM_SUPPORT))
  624. if (PCM == _mpeg4AudioCodec)
  625. audio_format = PCM_AUDIO_SID;
  626. else if (ADPCM == _mpeg4AudioCodec)
  627. audio_format = ADPCM_MS_AUDIO_SID;
  628. else if (WMA == _mpeg4AudioCodec)
  629. audio_format = WMAV2_AUDIO_SID;
  630. else if (MP3 == _mpeg4AudioCodec)
  631. audio_format = MP3_AUDIO_SID;
  632. else
  633. audio_format = 0;
  634. #else
  635. audio_format = 0;
  636. #endif
  637. #ifdef D_ENABLE_ADPCM_SUPPORT
  638. if (ADPCM == _mpeg4AudioCodec || PCM == _mpeg4AudioCodec)
  639. audio_bitspersample = _mpeg4AudioBitsPerSample_ADPCM;
  640. else
  641. audio_bitspersample = 0;
  642. #else
  643. audio_bitspersample = 0;
  644. #endif
  645. #ifdef D_ENABLE_DIVX_WMA_SUPPORT
  646. if (ADPCM == _mpeg4AudioCodec)
  647. audio_block_align = _mpeg4AudioBlockAlign_ADPCM;
  648. else if (WMA == _mpeg4AudioCodec)
  649. audio_block_align = _mpeg4AudioBlockAlign_WMA;
  650. else
  651. audio_block_align = 0;
  652. #else
  653. audio_block_align = 0;
  654. #endif
  655. bInternalSubtitleIsText = SI_CLIPS_MP4_INTERNAL_SUBTITLE_ON;
  656. // Robin_0730_2004, set the VCB/ACB fullness limit when NEW_2X16M_MAPPING
  657. #ifdef NEW_2X16M_MAPPING
  658. {
  659. UINT16 uiACBStartAddressAVI, uiSPBStartAddressAVI, uiAPPStartAddressAVI;
  660. UINT16 uiVCBSize, uiACBSize, uiSPBSize;
  661. MPEG4Clip_dynamic_malloc(&uiACBStartAddressAVI, &uiSPBStartAddressAVI, &uiAPPStartAddressAVI);
  662. uiVCBSize = uiACBStartAddressAVI - OSD_BUFFER_SIZE_AVI;
  663. uiACBSize = uiSPBStartAddressAVI - uiACBStartAddressAVI;
  664. uiSPBSize = SPB_SIZE_AVI;
  665. _mpeg4InternalSubtitleBufferStartAddr = uiSPBStartAddressAVI;
  666. DEC_AVI_SetFileParams(_mpeg4VideoWidth, _mpeg4VideoHeight,
  667.   wRoundedWidth, wRoundedHeight, wNumOfMB,
  668.   dwFrameIncr,
  669.   dwFixVal, dwFixFreq-1, _bAVIDrmOn, wVidStreamNum, wAudStreamNum, wSubStreamNum,fieldCounter,
  670.   (uiVCBSize*13), (uiACBSize*13), (DWORD)(uiSPBSize*1024UL), 
  671.   audio_format,audio_block_align,audio_bitspersample, bInternalSubtitleIsText);
  672. }
  673. #else
  674. _mpeg4InternalSubtitleBufferStartAddr = (OSD_BUFFER_SIZE_AVI+VCB_SIZE_AVI+ACB_SIZE_AVI);
  675. DEC_AVI_SetFileParams(_mpeg4VideoWidth, _mpeg4VideoHeight,
  676.   wRoundedWidth, wRoundedHeight, wNumOfMB,
  677.   dwFrameIncr,
  678.   dwFixVal, dwFixFreq-1, _bAVIDrmOn, wVidStreamNum, wAudStreamNum, wSubStreamNum,fieldCounter,
  679.   (VCB_SIZE_AVI*13), (ACB_SIZE_AVI*13), (SPB_SIZE_AVI*1024UL), 
  680.   audio_format,audio_block_align,audio_bitspersample,bInternalSubtitleIsText);
  681. #endif
  682. /* Signal to the demux media type - CD/DVD */
  683. if (SI_IS_CURRENT_AVI_CLIP)
  684. DEC_Set_DVP_Gen_For_Clips_Disc_Type(DEC_DISC_TYPE_AVI);
  685. #ifdef IS_ASF_CAPABLE
  686. else if (SI_IS_CURRENT_ASF_CLIP)
  687. DEC_Set_DVP_Gen_For_Clips_Disc_Type(DEC_DISC_TYPE_ASF);
  688. #endif
  689. #ifdef IS_MP4_CAPABLE
  690. else if (SI_IS_CURRENT_MP4_CLIP)
  691. DEC_Set_DVP_Gen_For_Clips_Disc_Type(DEC_DISC_TYPE_MP4);
  692. #endif
  693. if (_mpeg4VideoStreamID != NO_STREAM)
  694. DEC_Set_DVP_GEN_For_MPEG4_Audio_Only(FALSE);
  695. else
  696. DEC_Set_DVP_GEN_For_MPEG4_Audio_Only(TRUE);
  697. DEC_PlaybackCommand(DEC_PLAYBACK_CMD_PLAY, NULL);
  698. DEC_AVI_SetMBInfoAddr();
  699. // Robin_0809_2004, transfer the video header data
  700. if (_mpeg4VideoHeaderDataLength > 0)
  701. {
  702. WORD wVideoHeaderSize;
  703. BYTE videoHeaderBuff[MPEG4_VIDEO_HEADER_CACHE_SIZE];
  704. WORD wVideoHeaderCacheSize;
  705. WORD wOffset = 0;
  706. wVideoHeaderSize = _mpeg4VideoHeaderDataLength; // multiple of 2 bytes
  707. while (wVideoHeaderSize > 0)
  708. {
  709. wVideoHeaderCacheSize = min(wVideoHeaderSize,MPEG4_VIDEO_HEADER_CACHE_SIZE);
  710. sc_GetBytes(SC_MPEG4_VIDEO_HEADER_DATA_ADDR,
  711.       wOffset,
  712.       wVideoHeaderCacheSize,
  713.       (BYTE*)&videoHeaderBuff
  714.      );
  715. wOffset += wVideoHeaderCacheSize;
  716. DEC_AVI_TransferVideoHeader(wVideoHeaderCacheSize/2,(WORD*)&videoHeaderBuff);
  717. wVideoHeaderSize -= wVideoHeaderCacheSize;
  718. }
  719. }
  720. /* SubPicture Reset */
  721. /* set the SP switch */
  722. outport(SPSWITCH_ADDR, 0x5);
  723. // Robin_1011_2004_C
  724. // outport(SPSCALE_ADDR, 0x0);
  725. // Robin_1011_2004_D
  726. #ifdef PATCH_VIDEO_NOT_B
  727. bRequestPAL60 = FALSE;
  728. #endif
  729.     // Set DVP indication that this is a pure pause
  730.     DEC_AVI_ClearDemuxSharedBit(AVI_FILE_PAUSE_OFFSET, AVI_FILE_PAUSE_BIT);
  731. }
  732. #if defined(SDRAM_2X16MBITS) && defined(NEW_2X16M_MAPPING)
  733. void MPEG4Clip_dynamic_malloc(UINT16* uiACBStartAddressAVI, UINT16* uiSPBStartAddressAVI, UINT16* uiAPPStartAddressAVI)
  734. {
  735. UINT16 uiINDEXStartAddressAVI;
  736. // UINT16 uiSUBTITLEStartAddressAVI;
  737. UINT16 uiACBSizeAVI;
  738. *uiAPPStartAddressAVI = (UINT16)(_dwMPEG4ProcessingEndAddr>>9); // 512 word
  739. if ((_mpeg4SubtitleStreamID != NO_STREAM) && (_mpeg4SubtitleType == INTERNAL_SUBP || _mpeg4SubtitleType == INTERNAL_SUBT)) // RB_TBD
  740. *uiSPBStartAddressAVI = *uiAPPStartAddressAVI -SPB_SIZE_AVI;
  741. else
  742. *uiSPBStartAddressAVI = *uiAPPStartAddressAVI;
  743. if(SI_IS_CURRENT_AVI_CLIP && (TRUE == _bAVIVideoBeforeAudio))
  744. {
  745. if (PCM == _mpeg4AudioCodec)
  746. uiACBSizeAVI = (*uiSPBStartAddressAVI - OSD_BUFFER_SIZE_AVI) / 2;
  747. else
  748. uiACBSizeAVI = (*uiSPBStartAddressAVI - OSD_BUFFER_SIZE_AVI) / 6;
  749. }
  750.    else if (PCM == _mpeg4AudioCodec)
  751. uiACBSizeAVI = 2 * (*uiSPBStartAddressAVI - OSD_BUFFER_SIZE_AVI) / 3;
  752. else
  753. uiACBSizeAVI = (*uiSPBStartAddressAVI - OSD_BUFFER_SIZE_AVI) / 3;
  754. if (uiACBSizeAVI < 150) // TBD..., need test
  755. uiACBSizeAVI = 150;
  756. *uiACBStartAddressAVI = *uiSPBStartAddressAVI - uiACBSizeAVI;
  757. #ifdef _DEBUG
  758. dbg_printf(("VCB start addresst: %d KBtVCB sizet: %d KBn", OSD_BUFFER_SIZE_AVI,*uiACBStartAddressAVI -OSD_BUFFER_SIZE_AVI ));
  759. dbg_printf(("ACB start addresst: %d KBtACB sizet: %d KBn", *uiACBStartAddressAVI,*uiSPBStartAddressAVI-*uiACBStartAddressAVI));
  760. dbg_printf(("SPB start addresst: %d KBtSPB sizet: %d KBn", *uiSPBStartAddressAVI,*uiAPPStartAddressAVI -*uiSPBStartAddressAVI ));
  761. // dbg_printf(("APP start addresst: %d KBtAPP sizet: %d KBn", *uiAPPStartAddressAVI, uiSUBTITLEStartAddressAVI -*uiAPPStartAddressAVI));
  762. // dbg_printf(("SUBTITLE start addresst: %d KBtSUBTITLE sizet: %d KBn", uiSUBTITLEStartAddressAVI,uiINDEXStartAddressAVI-uiSUBTITLEStartAddressAVI));
  763. #endif
  764. }
  765. #endif