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

DVD

开发平台:

Others

  1. /****************************************************************************************
  2.  *  Copyright (c) 2000 ZORAN Corporation, All Rights Reserved
  3.  *  THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
  4.  *
  5.  *  File: $Workfile: Jpeg.c $             
  6.  *
  7.  * Description:
  8.  * ============
  9.  * JPEG Navigator implementation.
  10.  *
  11.  * Log:
  12.  * ====
  13.  ****************************************************************************************
  14.  * Updates:
  15.  ****************************************************************************************
  16.  * $Log: /I76/I76_Common/I76_Reference/Playcore/Nav_Clips/Jpeg.c $
  17.  * 
  18.  ****************************************************************************************/
  19. #include "Config.h" // Global Configuration - do not remove!
  20. #ifdef CLIPS_JPEG_SUPPORT
  21. #ifdef _DEBUG
  22. #undef IFTRACE
  23. #define IFTRACE if (gTraceNavigator)
  24. #include "DebugDbgMain.h"
  25. #endif
  26. #include "Includemath-macro.h"
  27. #include "KernelEventDef.H"
  28. #include "DecoderDecoder.h"
  29. #include "Drivedrv_api.h"
  30. #include "LogoLogo.h"
  31. #include "PlaycoreCoremainCoreGDef.h"
  32. #include "PlaycoreExceptionException.h"
  33. #include "PlaycoreNav_ClipsJPEG.h"
  34. #include "PlaycoreNav_ClipsClip_Impl.h"
  35. #include "PlaycoreNav_ClipsGenericClip.h"
  36. #include "PlaycoreNav_ClipsPE_Clips.h"
  37. #ifdef SUPPORT_FLASH_CARD
  38. #include "drivefe_manager.h"
  39. #endif
  40. /////////////////////////////////////////////////////////////////////////////
  41. // Globals and Singletions
  42. #define CURRENT_DISPLAY_BUFFER (gns.clips.globals.jpegGlobals.eJPEGCurrentDisplayBuffer)
  43. #define CURRENT_DECODE_BUFFER (gns.clips.globals.jpegGlobals.eJPEGCurrentDecodeBuffer)
  44. #define IS_CURRENT_DISPLAY_BUFFER_FRONT_R1 (CURRENT_DISPLAY_BUFFER == FRONT_R1_BUFFER )
  45. #define IS_CURRENT_DISPLAY_BUFFER_BACK_R2 (CURRENT_DISPLAY_BUFFER == BACK_R2_BUFFER )
  46. #define TOGGLE_CURRENT_DISPLAY_BUFFER (CURRENT_DISPLAY_BUFFER=(CURRENT_DISPLAY_BUFFER==FRONT_R1_BUFFER) ? BACK_R2_BUFFER : FRONT_R1_BUFFER)
  47. #define TOGGLE_CURRENT_DECODE_BUFFER (CURRENT_DECODE_BUFFER=(CURRENT_DECODE_BUFFER==FRONT_R1_BUFFER) ? BACK_R2_BUFFER : FRONT_R1_BUFFER)
  48. #define JPEG_PLAYBACK_FINISHED_WATCHDOG 100 // 20 seconds timeout since it's called in 200ms tick, it's necessary for some progressive JPEGs
  49. #define STOP_WATCHDOG 0xff
  50. #define bStopRequested (gns.clips.globals.jpegGlobals.bStopRequested)
  51. static UINT8 g_uPresentationTime= 0;
  52. static BYTE ucWatchDog = JPEG_PLAYBACK_FINISHED_WATCHDOG;
  53. #ifdef I77_COMPANION_CHIP
  54. static BOOL bJpegDecodeDone = FALSE;
  55. #endif
  56. #define JPEG_TOLERANCE_BYTES (LOGICAL_BLOCK_SIZE / 2)
  57. #define JPEG_IMAGESTATE_MASK 0x0F
  58. #define JPEG_ERROR_MASK 0xF0
  59. /////////////////////////////////////////////////////////////////////////////
  60. // Macros
  61. #define GET_IMAGESTATE(ucUserData)
  62. (enImageState)((ucUserData) & JPEG_IMAGESTATE_MASK)
  63. #define SET_IMAGESTATE(ucUserData, eState)
  64. ucUserData= ((ucUserData) & ~JPEG_IMAGESTATE_MASK) | (UINT8)eState
  65. #define GET_ERROR(ucUserData)
  66. (((ucUserData) & JPEG_ERROR_MASK) >> 4)
  67. #define SET_ERROR(ucUserData, eError)
  68. ucUserData= ((ucUserData) & ~JPEG_ERROR_MASK) | ((UINT8)eError << 4)
  69. /////////////////////////////////////////////////////////////////////////////
  70. // Enumerations
  71. typedef enum {
  72. eImageState_Idle,
  73. eImageState_Caching,
  74. eImageState_Cached,
  75. eImageState_Decoding,
  76. eImageState_Transitioning,
  77. eImageState_Error
  78. } enImageState;
  79. /////////////////////////////////////////////////////////////////////////////
  80. // Forward Declarations of Virtual Methods
  81. BOOL JPEGClip_play(Clip *i_pThis, const ClipMarker *i_pResumeMarker, BOOL bCacheOnly);
  82. void JPEGClip_pause(Clip *i_pThis, BOOL bEnable);
  83. enClipStatus JPEGClip_getStatus(const Clip *i_pThis);
  84. void JPEGClip_abort(Clip *i_pThis, BOOL bMaintainStandby);
  85. void JPEGClip_refresh(Clip *i_pThis);
  86. UINT16 JPEGClip_getTime(const Clip *i_pThis);
  87. void JPEGClip_digest(Clip *i_pThis);
  88. /////////////////////////////////////////////////////////////////////////////
  89. // Const Factory
  90. // Valid Extenions List
  91. BEGIN_CLIP_VALID_EXTENSIONS_MAP(JPEG)
  92. CLIP_VALID_EXTENSIONS_ENTRY(L"JPEG")
  93. CLIP_VALID_EXTENSIONS_ENTRY(L"JPG")
  94. END_CLIP_VALID_EXTENSIONS_MAP()
  95. // Constant Attributes
  96. #ifndef D_ENABLE_JPEG_CACHE
  97. DECLARE_CLIP_CONST_ATTR(JPEG, 
  98. DECLARE_CLIP_VTABLE(GenericClip_getExtendedInfo,
  99. JPEGClip_play,
  100. JPEGClip_pause,
  101. JPEGClip_getStatus,
  102. JPEGClip_abort,
  103. GenericClip_recordMarker,
  104. JPEGClip_refresh,
  105. JPEGClip_getTime,
  106. JPEGClip_digest,
  107. GenericClip_scan
  108. ),
  109. eClipType_JPEG,
  110. DEC_ASID_JPEG, 0xFF, DEC_DISC_TYPE_JPG,
  111. (eCA_Zoomable | eCA_Digestable | eCA_StillImage ),
  112. &g_uPresentationTime
  113. )
  114. #else
  115. DECLARE_CLIP_CONST_ATTR(JPEG, 
  116. DECLARE_CLIP_VTABLE(GenericClip_getExtendedInfo,
  117. JPEGClip_play,
  118. JPEGClip_pause,
  119. JPEGClip_getStatus,
  120. JPEGClip_abort,
  121. GenericClip_recordMarker,
  122. JPEGClip_refresh,
  123. JPEGClip_getTime,
  124. JPEGClip_digest,
  125. GenericClip_scan
  126. ),
  127. eClipType_JPEG,
  128. DEC_ASID_JPEG, 0xFF, DEC_DISC_TYPE_JPG,
  129. (eCA_Zoomable | eCA_Digestable | eCA_StillImage | eCA_Cacheable ),
  130. &g_uPresentationTime
  131. )
  132. #endif
  133. /////////////////////////////////////////////////////////////////////////////
  134. // Public Services
  135. void JPEG_setPresentationTime(UINT8 uPresentationTime)
  136. {
  137. dbg_printf(("Set JPEG presentation time to %dn", uPresentationTime));
  138. g_uPresentationTime = uPresentationTime;
  139. }
  140. BOOL JPEGClip_isKindOf(LPCWSTR i_pszFilename)
  141. {
  142. return GenericClip_isKindOf(i_pszFilename, CLIP_VALID_EXTENSIONS(JPEG));
  143. }
  144. void JPEGClip_construct(struct Clip_TAG *o_pThis, const FindData *i_pFileInfo)
  145. {
  146. GenericClip_construct(o_pThis, i_pFileInfo);
  147. o_pThis->m_pConstAttr= &CLIP_CONST_ATTR(JPEG);
  148. }
  149. /////////////////////////////////////////////////////////////////////////////
  150. // Virtual Methods
  151. #pragma argsused
  152. BOOL JPEGClip_play(Clip *i_pThis, const ClipMarker *i_pResumeMarker,
  153.    BOOL bCacheOnly)
  154. {
  155. BOOL  bNoTransition;
  156. BOOL  bBtsChanged;
  157. ULONG ulBlocksCnt;
  158. ULONG cbFileSize;
  159. enImageState eState;   
  160. ucWatchDog = JPEG_PLAYBACK_FINISHED_WATCHDOG;
  161. dbg_printf(("JPEGClip_play(bCacheOnly=%x)n",bCacheOnly));
  162. bBtsChanged= (DEC_GetCurrentDiscType() != (DEC_DISC_TYPE)(i_pThis->m_pConstAttr)->m_eBitstreamType);
  163. bNoTransition= (eCTE_None == (enClipTransitionEffect)(i_pThis->m_presentationInfo).eTransitionEffect);
  164. #ifdef USE_STOP_EXCEPTION_WHEN_JPEG
  165. Exception_catch(EXCEPTION_STOP_REQUEST);
  166. #endif
  167. /* Sanity check - Is caching required while disc type has changed? */
  168. if (bCacheOnly && bBtsChanged)
  169. {
  170. return FALSE;
  171. }
  172. /* If transition effect is used - no caching is performed (no double buffering)! */
  173. if (bCacheOnly && !bNoTransition)
  174. {
  175. tr_printf(("Transition effect is required - disable cachingn"));
  176. return FALSE;
  177. }
  178. // Acquire the current image State
  179. eState= GET_IMAGESTATE((i_pThis->m_presentationInfo).ucUserData);
  180. // Check if the image is already in Error state;
  181. // This is only possible if this image was cached unsuccessfully.
  182. if (eImageState_Error == eState) 
  183. {
  184. // If this is a Caching request, do nothing
  185. if (bCacheOnly)
  186. return TRUE;
  187. // Clear the Front-Display Buffer and do nothing additional
  188. DEC_JPEG_clearDisplayBuffers(TRUE, FALSE, TRUE);
  189. return TRUE;
  190. }
  191. // display the picture if the image is already cached and in normal playback
  192. if( (!bCacheOnly)&&(eImageState_Cached == eState) )
  193. {
  194. tr_printf(("nJPEGClip_play: Display cached Imagen"));
  195. // If picutre already cached, switch to display it in decode buffer
  196. TOGGLE_CURRENT_DISPLAY_BUFFER;
  197. TOGGLE_CURRENT_DECODE_BUFFER;
  198. // clear previous display buffer to push DVP Video Task toggle the display buffer
  199. DEC_JPEG_clearDisplayBuffers(IS_CURRENT_DISPLAY_BUFFER_BACK_R2,
  200. IS_CURRENT_DISPLAY_BUFFER_FRONT_R1, bBtsChanged );
  201. DEC_JPEG_SetDisplayDecodeBuffer(CURRENT_DISPLAY_BUFFER,CURRENT_DECODE_BUFFER);
  202. if (!DEC_IsSystemIdle())
  203. {
  204. DEC_Stop_DVP_cmd((UINT8)0);
  205. delay_us(400000UL);
  206. }
  207. DEC_Start_DVP_cmd();
  208. delay_us(50000UL);//wait until picture is displayed
  209. TOGGLE_CURRENT_DECODE_BUFFER;
  210. // If this image is already Caching/Cached, then move to "Decoding" state;
  211. // the next Refresh will resume normal flow.
  212. SET_IMAGESTATE((i_pThis->m_presentationInfo).ucUserData, eImageState_Decoding);
  213. // Indicate that the data has been modified
  214. (i_pThis->m_presentationInfo).bModified= TRUE;
  215. return TRUE;
  216. }
  217. drv_abort_play();
  218. // Set the selected Orientation
  219. DEC_JPEG_setOrientation((UINT8)(i_pThis->m_presentationInfo).eImageOrientation);
  220. // Use no Transition-Effect for the Caching/Decoding phase
  221. DEC_JPEG_selectTransition((UINT8)eCTE_None, FALSE);
  222. // Set the Image State to "Caching" or "Decoding", as appropriate
  223. if (bCacheOnly)
  224. {
  225. dbg_printf(("JPEG_Play: Cache Imagen"));
  226. SET_IMAGESTATE((i_pThis->m_presentationInfo).ucUserData, eImageState_Caching);
  227. }
  228. else
  229. {
  230. dbg_printf(("JPEG_Play: Direct Play Imagen"));
  231. SET_IMAGESTATE((i_pThis->m_presentationInfo).ucUserData, eImageState_Decoding);
  232. #ifdef EXINO2 // ZKR GL040904 : Demo for Transition effect to S1
  233. DEC_JPEG_selectTransition((UINT8)eCTE_Random,TRUE);
  234. #else
  235. DEC_JPEG_selectTransition((enClipTransitionEffect)(i_pThis->m_presentationInfo).eTransitionEffect,TRUE);
  236. #endif
  237. }
  238. // Configure the Decoder to the appropriate Bitstream Type
  239. DEC_SetDiskType((DEC_DISC_TYPE)(i_pThis->m_pConstAttr)->m_eBitstreamType);
  240. DEC_EnableManualScaling(PROG_SCALER_MODE_CCRAM);
  241. //Set JPEG size
  242. DEC_set_coded_video_size((UINT16) JPEG_DISPLAY_HORZ_SIZE, (UINT16) JPEG_DISPLAY_VERT_SIZE);
  243. //caculate display SAR
  244. DEC_set_Display_AspectRatio(gps->tv_shape);
  245. //JPEG coded SAR is always 1000 to keep no distortion
  246. DEC_LL_SetCodedSAR(1000);
  247. // Set the scaler mode 
  248. DEC_SetViewMode(gps->view_mode);
  249. #ifdef D_ENABLE_SETUP_JPG_SIZE //JG_0803_2004
  250. //JPEG auto fit should do scaling later when get real pic size from ADP
  251. if(JPG_SIZE_AUTOFIT != PS_GET_JPEG_SIZE_SETTING())
  252. #endif
  253. gcst.mNeedScaling = TRUE;
  254. // Apply Auto-Fit, if required
  255. if (JPG_SIZE_AUTOFIT == PS_GET_JPEG_SIZE_SETTING()) 
  256. {
  257. DEC_JPEG_enableAutoFitToScreen(TRUE);
  258. }
  259. else 
  260. {
  261. DEC_JPEG_enableAutoFitToScreen(FALSE);
  262. }
  263. // Prepare for decoding
  264. DEC_prepare_to_decode();
  265. // Clear the Display Buffers
  266. if (!bCacheOnly) 
  267. {
  268. // no caching required, clear immediately if the bitstream type changed
  269. dbg_printf(("ndefault display/decode buffer as R2 when no cache playn"));
  270. CURRENT_DISPLAY_BUFFER = BACK_R2_BUFFER;
  271. CURRENT_DECODE_BUFFER = BACK_R2_BUFFER;
  272. DEC_JPEG_clearDisplayBuffers(IS_CURRENT_DISPLAY_BUFFER_FRONT_R1,
  273. IS_CURRENT_DISPLAY_BUFFER_BACK_R2, bBtsChanged);
  274. DEC_JPEG_SetDisplayDecodeBuffer(CURRENT_DISPLAY_BUFFER,CURRENT_DECODE_BUFFER);
  275. }
  276. else 
  277. {
  278. #ifdef D_ENABLE_JPEG_CACHE
  279. // Caching is required: clear only the Back Buffer
  280. DEC_JPEG_clearDisplayBuffers( IS_CURRENT_DISPLAY_BUFFER_BACK_R2,
  281. IS_CURRENT_DISPLAY_BUFFER_FRONT_R1, FALSE);
  282. // Continue display at current display buffer, while decoding the cached image into decoding buffer
  283. TOGGLE_CURRENT_DECODE_BUFFER;
  284. DEC_JPEG_SetDisplayDecodeBuffer(CURRENT_DISPLAY_BUFFER,CURRENT_DECODE_BUFFER);
  285. #endif
  286. }
  287. // Adjust the Zoom factor
  288. if (bNoTransition) 
  289. {
  290. #ifdef CLIPS_JPEG_KEEP_ZOOM_RATIO
  291. if (JPG_SIZE_ORIGINAL == PS_GET_JPEG_SIZE_SETTING())
  292. DEC_SetZoomScale(gcs.mZoomLevel);
  293. else
  294. #endif
  295. //JG_0407_2004:No need to kill zoom, using CPU scaling will not keep zoom ratio
  296. // Kill any existing Zoom
  297. //DEC_SetZoomScale(NO_ZOOM);
  298. }
  299. // Switch the Logo-Source to Frame
  300. if (!bCacheOnly && (eFrame != Logo_getCurrentSource())) 
  301. {
  302. Logo_selectSource(eFrame);
  303. Logo_display();
  304. }
  305. DEC_JPEG_ResetCopyDoneFlag();
  306. #ifdef I77_COMPANION_CHIP//jerry.ren 20050527
  307. #ifdef I77_BRAIN_STORM
  308. if( gcst.hd_jpeg_mode_preference != SD_JPEG_MODE )
  309. #else//I77_BRAIN_STORM
  310. if( gps->hd_jpeg_mode_preference != SD_JPEG_MODE )
  311. #endif//I77_BRAIN_STORM
  312. I77_SetBackground(TRUE);
  313. #endif
  314. Logo_selectSource(eBackground);
  315. Logo_display();
  316. //set HD JPEG resolution or SD JPEG display size
  317. DEC_JPEG_Init_Resolution();
  318.            
  319. //set file size
  320. #ifdef SUPPORT_FLASH_CARD
  321. if(IS_PLAYING_CARD)
  322. DEC_JPEG_SetFileSize( i_pThis->m_cfiInfo.cbFileSize + LOGICAL_BLOCK_SIZE - 1);
  323. else
  324. #endif
  325. DEC_JPEG_SetFileSize( i_pThis->m_cfiInfo.cbFileSize );
  326. DEC_SetSID(DEC_SID_TYPE_AUDIO, (i_pThis->m_pConstAttr)->m_eAudioSID);
  327. DEC_SetSID(DEC_SID_TYPE_VIDEO, (i_pThis->m_pConstAttr)->m_eVideoSID);
  328. // Select the appropriate Clock
  329. PE_Clips_SelectClock(eCT_Decoder);
  330. // Calculate the Playback Length, and add an extra Sector to accomodate for decoding tolerance in JPEG.
  331. ulBlocksCnt= ( ((i_pThis->m_cfiInfo).cbFileSize + LOGICAL_BLOCK_SIZE - 1) /LOGICAL_BLOCK_SIZE );
  332. // Calculate the effective File-Size to transfer, taking into account the JPEG Tolerance, required by the Decoder.
  333. cbFileSize= MIN((ulBlocksCnt * LOGICAL_BLOCK_SIZE),  ((i_pThis->m_cfiInfo).cbFileSize + JPEG_TOLERANCE_BYTES));
  334. // Inform the Decoder of the Playback-Range
  335. PE_Clips_SetPlaybackRange((i_pThis->m_cfiInfo).dwFileLocation, ulBlocksCnt, cbFileSize);//Leslie_0823_2003_A
  336. // Invoke playback of the Decoder & Drive
  337. // NOTE: The order of invocation is important, and must not be changed!
  338. DEC_PlaybackCommand(DEC_PLAYBACK_CMD_PLAY, NULL);
  339. Logo_selectSource(eFrame);
  340. //Freya Disable the next line to fix TD1609"Press Next key the picture flash once" at 050816
  341. //Logo_display();
  342. #ifdef I77_COMPANION_CHIP//jerry.ren 20050527
  343. #ifdef I77_BRAIN_STORM
  344. if( gcst.hd_jpeg_mode_preference != SD_JPEG_MODE )
  345. #else//I77_BRAIN_STORM
  346. if( gps->hd_jpeg_mode_preference != SD_JPEG_MODE )
  347. #endif//I77_BRAIN_STORM
  348. I77_SetBackground(FALSE);
  349. #endif
  350. if ( !PE_Clips_Playback_Sectors(DRVCF_CDSPEED_1X | DRVF_PLAY_CD_AV_DATA, (i_pThis->m_cfiInfo).dwFileLocation,//Leslie_0823_2003_A
  351. ulBlocksCnt))
  352. {
  353. dbg_printf(("WARNING: GenericClip_play() Failed [1]n"));
  354. return FALSE;
  355. }
  356. // Reset the Clock, without starting it
  357. PE_Clips_EnableClock(FALSE, TRUE, 0);
  358. // Indicate that the data has been modified
  359. (i_pThis->m_presentationInfo).bModified= TRUE;
  360. return TRUE;
  361. }
  362. #pragma argsused
  363. void JPEGClip_pause(Clip *i_pThis, BOOL bEnable)
  364. {
  365. // Nothing special to do for JPEG - just let the picture decode to
  366. // its end.
  367. dbg_printf(("JPEGClip_pause()n"));
  368. return;
  369. }
  370. #pragma argsused
  371. enClipStatus JPEGClip_getStatus(const Clip *i_pThis)
  372. {
  373. enImageState eState= GET_IMAGESTATE((i_pThis->m_presentationInfo).ucUserData);
  374. /* Check if an exception was thrown */
  375. #ifdef USE_STOP_EXCEPTION_WHEN_JPEG
  376. if (Exception_catchAndRethrow(EXCEPTION_STOP_REQUEST | EXCEPTION_MEDIUM_EJECTED | EXCEPTION_POWER_DOWN_REQUEST)) 
  377. #else
  378. if (Exception_catchAndRethrow(EXCEPTION_MEDIUM_EJECTED | EXCEPTION_POWER_DOWN_REQUEST)) 
  379. #endif
  380. {
  381. #ifdef I77_COMPANION_CHIP
  382. bJpegDecodeDone = FALSE;
  383. #endif
  384. return eCS_Busy;
  385. }
  386. if ((eImageState_Idle == eState) || (eImageState_Cached == eState))
  387. {
  388. #ifdef I77_COMPANION_CHIP
  389. #ifdef I77_BRAIN_STORM
  390. if( gcst.hd_jpeg_mode_preference != SD_JPEG_MODE )
  391. #else//I77_BRAIN_STORM
  392. if( gps->hd_jpeg_mode_preference != SD_JPEG_MODE )
  393. #endif//I77_BRAIN_STORM
  394. {
  395. bJpegDecodeDone = TRUE;
  396. return eCS_Finished;
  397. }
  398. else
  399. #endif
  400. {
  401. if ( DEC_JPEG_IsCopyDone() )
  402. return eCS_Finished;
  403. else
  404. return eCS_Busy;
  405. }
  406. }
  407. if (eImageState_Error == eState) {
  408. switch (GET_ERROR((i_pThis->m_presentationInfo).ucUserData))
  409. {
  410. case JPEG_STAT_ERR_FATAL:
  411. return eCS_Error_Decoding;
  412. case JPEG_STAT_ERR_UNSUPPORTED:
  413. return eCS_Error_UnsupportedFormat;
  414. }
  415. }
  416. if(!ucWatchDog)
  417. {
  418. ucWatchDog = JPEG_PLAYBACK_FINISHED_WATCHDOG;
  419. tr_printf(("Warnning: JPEG Watchdog time out!!!n"));
  420. return eCS_Finished;
  421. }  
  422. else
  423. if(STOP_WATCHDOG != ucWatchDog)
  424. ucWatchDog --;
  425. return eCS_Busy;
  426. }
  427. #pragma argsused
  428. void JPEGClip_abort(Clip *i_pThis, BOOL bMaintainStandby)
  429. {
  430. dbg_printf(("JPEGClip_abort(%d)n", bMaintainStandby));
  431. #ifdef USE_STOP_EXCEPTION_WHEN_JPEG
  432. /* Clear stop exception if it was thrown */
  433. Exception_catch(EXCEPTION_STOP_REQUEST);
  434. #endif
  435. DEC_JPEG_selectTransition((UINT8)eCTE_None, TRUE);
  436. // if (eImageState_Idle != GET_IMAGESTATE((i_pThis->m_presentationInfo).ucUserData)) {
  437. drv_abort_play();
  438. DEC_Stop_DVP_ADP_cmd((UINT8)0);
  439.   // }
  440. if (! bMaintainStandby)
  441. drv_spindown();
  442. SET_IMAGESTATE((i_pThis->m_presentationInfo).ucUserData, eImageState_Idle);
  443. (i_pThis->m_presentationInfo).bModified= TRUE;
  444. #ifdef I77_COMPANION_CHIP
  445.    if ( ( bJpegDecodeDone == FALSE ) && (PST_STOP != gcs.pstate) )
  446. {
  447. #ifdef I77_BRAIN_STORM
  448. if( gcst.hd_jpeg_mode_preference != SD_JPEG_MODE )
  449. #else//I77_BRAIN_STORM
  450. if( gps->hd_jpeg_mode_preference != SD_JPEG_MODE )
  451. #endif//I77_BRAIN_STORM
  452. DEC_JPEG_End_Resolution();
  453. }
  454. #endif
  455. return;
  456. }
  457. #ifdef I77_COMPANION_CHIP
  458. void JPEGClip_BeforeAbort(void)
  459. {
  460. bJpegDecodeDone = FALSE;
  461. }
  462. #endif // I77_COMPANION_CHIP
  463. void JPEGClip_beforeStop(struct Clip_TAG *o_pThis)
  464. {
  465. bStopRequested = TRUE;
  466. }
  467. #pragma argsused
  468. void JPEGClip_refresh(Clip *i_pThis)
  469. {
  470. UINT8 uDecodingStatus;
  471. enImageState eOriginalState;
  472. /* Check if an exception was thrown */
  473. #ifdef USE_STOP_EXCEPTION_WHEN_JPEG
  474. if (Exception_catchAndRethrow(EXCEPTION_STOP_REQUEST | EXCEPTION_MEDIUM_EJECTED | EXCEPTION_POWER_DOWN_REQUEST)) 
  475. #else
  476. if (Exception_catchAndRethrow(EXCEPTION_MEDIUM_EJECTED | EXCEPTION_POWER_DOWN_REQUEST)) 
  477. #endif
  478. {
  479. #ifdef I77_COMPANION_CHIP   
  480. bJpegDecodeDone = FALSE;
  481. #endif // I77_COMPANION_CHIP      
  482. return;
  483. }
  484. eOriginalState= GET_IMAGESTATE((i_pThis->m_presentationInfo).ucUserData);
  485. // Check if there is anything to refresh
  486. if ((eImageState_Cached == eOriginalState) || (eImageState_Idle == eOriginalState) ||
  487. (eImageState_Error == eOriginalState))
  488. {
  489. // If the Image is already Cached, Idle, or Erroneous, no point in doing anything.
  490. return;
  491. }
  492. #ifdef I77_COMPANION_CHIP
  493. #ifdef I77_BRAIN_STORM
  494. if( gcst.hd_jpeg_mode_preference == SD_JPEG_MODE )
  495. #else//I77_BRAIN_STORM
  496. if( gps->hd_jpeg_mode_preference == SD_JPEG_MODE )
  497. #endif//I77_BRAIN_STORM
  498. #endif
  499. {
  500. // notify to copy the new line to display buffer when ready
  501. if ( ( TRUE == DEC_JPEG_IsNewLineReady() ) && ( PST_STOP != gcs.pstate ) )
  502. DEC_JPEG_DecodeDoneCheck();
  503. }
  504. // Check if the current Phase has finished
  505. uDecodingStatus= DEC_JPEG_getStatus();
  506. #ifdef I77_COMPANION_CHIP//jerry.ren 20050527
  507. #ifdef I77_BRAIN_STORM
  508. if( gcst.hd_jpeg_mode_preference != SD_JPEG_MODE )
  509. #else//I77_BRAIN_STORM
  510. if( gps->hd_jpeg_mode_preference != SD_JPEG_MODE )
  511. #endif//I77_BRAIN_STORM
  512. I77_SetBackground(TRUE);
  513. #endif
  514. if (JPEG_STAT_DECODING == uDecodingStatus)
  515. {
  516. //no return if JPEG copy done even it still decoding (for SD JPEG mode only)
  517. if(!(DEC_JPEG_IsCopyDone()
  518. #ifdef I77_COMPANION_CHIP
  519. #ifdef I77_BRAIN_STORM
  520. &&(gcst.hd_jpeg_mode_preference == SD_JPEG_MODE)
  521. #else//I77_BRAIN_STORM
  522. &&(gps->hd_jpeg_mode_preference == SD_JPEG_MODE)
  523. #endif//I77_BRAIN_STORM
  524. #endif
  525. ) )
  526. return;
  527. }
  528. #ifdef I77_COMPANION_CHIP//jerry.ren 20050527
  529. #ifdef I77_BRAIN_STORM
  530. if( gcst.hd_jpeg_mode_preference != SD_JPEG_MODE )
  531. #else//I77_BRAIN_STORM
  532. if( gps->hd_jpeg_mode_preference != SD_JPEG_MODE )
  533. #endif//I77_BRAIN_STORM
  534. I77_SetBackground(FALSE);
  535. #endif
  536. // Check for Errors
  537. if ((JPEG_STAT_ERR_UNSUPPORTED == uDecodingStatus) ||
  538. (JPEG_STAT_ERR_FATAL == uDecodingStatus))
  539. {
  540. dbg_printf(("Error, unsupported format or error encountedn"));
  541. // If the current state is "Decoding", 
  542. if (eImageState_Decoding == eOriginalState){
  543. DEC_JPEG_clearDisplayBuffers(IS_CURRENT_DISPLAY_BUFFER_BACK_R2, IS_CURRENT_DISPLAY_BUFFER_FRONT_R1, TRUE);
  544. }
  545. // Move to "Error" state
  546. SET_IMAGESTATE((i_pThis->m_presentationInfo).ucUserData, eImageState_Error);
  547. SET_ERROR((i_pThis->m_presentationInfo).ucUserData, uDecodingStatus);
  548. (i_pThis->m_presentationInfo).bModified= TRUE;
  549. return;
  550. }
  551. // Check the current State
  552. if (eImageState_Caching == eOriginalState) {
  553. // Caching is finished -- move to "Cached" state
  554. SET_IMAGESTATE((i_pThis->m_presentationInfo).ucUserData, eImageState_Cached);
  555. }
  556. else if (eImageState_Decoding == eOriginalState) {
  557. // Check if a Transition-Phase is required
  558. if (eCTE_None == (enClipTransitionEffect)(i_pThis->m_presentationInfo).eTransitionEffect) {
  559. // No Transition required: move to "Idle" state
  560. SET_IMAGESTATE((i_pThis->m_presentationInfo).ucUserData, eImageState_Idle);
  561. }
  562. else {
  563. // Some Transition is required: select and apply the Transition
  564. enClipTransitionEffect eTransition;
  565. /* //no used now, will do it at dec_jpeg_selecttransition()
  566. if (eCTE_Random == (enClipTransitionEffect)(i_pThis->m_presentationInfo).eTransitionEffect)
  567. eTransition= (eCTE_TopToBottom + (rand() % (eCTE_TransitionEffectsCnt-1)));
  568. else*/
  569. eTransition= (enClipTransitionEffect)(i_pThis->m_presentationInfo).eTransitionEffect;
  570. // If no Auto-Fit was applied, cancel any Zoom
  571. #ifdef CLIPS_JPEG_KEEP_ZOOM_RATIO //DM021103 Keep Zoom level as required
  572. if (JPG_SIZE_ORIGINAL == PS_GET_JPEG_SIZE_SETTING())
  573. DEC_SetZoomScale(gcs.mZoomLevel);
  574. else
  575. #else
  576. if (JPG_SIZE_ORIGINAL == PS_GET_JPEG_SIZE_SETTING())
  577. #endif
  578. DEC_SetZoomScale(NO_ZOOM);
  579. DEC_JPEG_selectTransition((UINT8)eTransition, TRUE);
  580. // Move to "Transitioning" state
  581. SET_IMAGESTATE((i_pThis->m_presentationInfo).ucUserData, eImageState_Transitioning);
  582. }
  583. }
  584. else if (eImageState_Transitioning == eOriginalState) {
  585. // Since the Transition-Effect has finished, move to "Idle" state
  586. SET_IMAGESTATE((i_pThis->m_presentationInfo).ucUserData, eImageState_Idle);
  587. }
  588. // Check if there was some modification, and indicate that
  589. if (eOriginalState != GET_IMAGESTATE((i_pThis->m_presentationInfo).ucUserData))
  590. (i_pThis->m_presentationInfo).bModified= TRUE;
  591. }
  592. #pragma argsused
  593. UINT16 JPEGClip_getTime(const Clip *i_pThis)
  594. {
  595. // No Time dimension in a JPEG image - always return Zero
  596. return 0;
  597. }
  598. void JPEGClip_digest(Clip *i_pThis)
  599. {
  600. ULONG ulBlocksCnt;
  601. ULONG cbFileSize;
  602. ucWatchDog = STOP_WATCHDOG;
  603. dbg_printf(("JPEGClip_digest()n"));
  604. // Set the Image State to "Decoding"
  605. SET_IMAGESTATE((i_pThis->m_presentationInfo).ucUserData, eImageState_Decoding);
  606. // Set the selected Orientation
  607. #ifdef EXINO2
  608. DEC_JPEG_setOrientation((UINT8)(i_pThis->m_presentationInfo).eImageOrientation);
  609. #else
  610. DEC_JPEG_setOrientation(eCIO_Original);
  611. #endif
  612. // Use no Transition-Effect for the Caching/Decoding phase
  613. DEC_JPEG_selectTransition((UINT8)eCTE_None, FALSE);
  614. // Configure the Decoder to the appropriate Bitstream Type
  615. DEC_SetDiskType((DEC_DISC_TYPE)(i_pThis->m_pConstAttr)->m_eBitstreamType);
  616. //no auto fit for digest
  617. DEC_JPEG_enableAutoFitToScreen(FALSE);
  618. // Prepare for decoding
  619. DEC_prepare_to_decode();
  620. #ifndef D_ENABLE_JPEG_CACHE
  621. // tempory patch, current MPEG DVP Ucode is not able the clear background if no JPEG data is sent to DVP
  622. // need to figure it out later
  623. if ( IS_DVD_MEDIA ){
  624. if ( Digest_IsFirstDigestWindow())
  625. DEC_JPEG_clearDisplayBuffers(FALSE, TRUE, FALSE);
  626. else
  627. DEC_JPEG_clearDisplayBuffers(FALSE, FALSE, FALSE);
  628. }
  629. else
  630. #ifdef SUPPORT_FLASH_CARD
  631. if(!IS_PLAYING_CARD)
  632. #endif
  633. {
  634. DEC_JPEG_clearDisplayBuffers(TRUE, FALSE, FALSE);
  635. }
  636. #else
  637. dbg_printf(("ndefault display/decode buffer as R2 when digestn"));
  638. CURRENT_DISPLAY_BUFFER = BACK_R2_BUFFER;
  639. CURRENT_DECODE_BUFFER = BACK_R2_BUFFER;
  640. if ( Digest_IsFirstDigestWindow())
  641. DEC_JPEG_clearDisplayBuffers(IS_CURRENT_DISPLAY_BUFFER_FRONT_R1,IS_CURRENT_DISPLAY_BUFFER_BACK_R2, FALSE);
  642. else
  643. DEC_JPEG_clearDisplayBuffers(FALSE, FALSE, FALSE);
  644. #endif //D_ENABLE_JPEG_CACHE
  645. DEC_JPEG_SetDisplayDecodeBuffer(CURRENT_DISPLAY_BUFFER,CURRENT_DECODE_BUFFER);
  646. //clear the copy done Flag, it shoul be clear before next picture decoding
  647. DEC_JPEG_ResetCopyDoneFlag();
  648. //set HD JPEG resolution or SD JPEG display size
  649. DEC_JPEG_Init_Resolution();
  650. //set file size
  651. DEC_JPEG_SetFileSize( i_pThis->m_cfiInfo.cbFileSize );
  652. DEC_SetSID(DEC_SID_TYPE_AUDIO, (i_pThis->m_pConstAttr)->m_eAudioSID);
  653. DEC_SetSID(DEC_SID_TYPE_VIDEO, (i_pThis->m_pConstAttr)->m_eVideoSID);
  654. // Calculate the Playback Length, and add an extra Sector to accomodate for decoding tolerance in JPEG.
  655. ulBlocksCnt= ( ((i_pThis->m_cfiInfo).cbFileSize + LOGICAL_BLOCK_SIZE - 1) /LOGICAL_BLOCK_SIZE );
  656. // Calculate the effective File-Size to transfer, taking into account the JPEG Tolerance, required by the Decoder.
  657. cbFileSize= MIN((ulBlocksCnt * LOGICAL_BLOCK_SIZE), ((i_pThis->m_cfiInfo).cbFileSize + JPEG_TOLERANCE_BYTES));
  658. // Inform the Decoder of the Playback-Range
  659. PE_Clips_SetPlaybackRange((i_pThis->m_cfiInfo).dwFileLocation, ulBlocksCnt, cbFileSize);//Leslie_0823_2003_A
  660. // Invoke playback of the Decoder & Drive
  661. // NOTE: The order of invocation is important, and must not be changed!
  662. DEC_PlaybackCommand(DEC_PLAYBACK_CMD_PLAY, NULL);
  663. if ( !PE_Clips_Playback_Sectors(DRVCF_CDSPEED_1X | DRVF_PLAY_CD_AV_DATA, (i_pThis->m_cfiInfo).dwFileLocation,//Leslie_0823_2003_A
  664.  ulBlocksCnt)) 
  665. {
  666. dbg_printf(("WARNING: JPEGClip_digest() Failed [1]n"));
  667. return;
  668. }
  669. // Indicate that the data has been modified
  670. (i_pThis->m_presentationInfo).bModified= TRUE;
  671. return;
  672. }
  673. #endif //CLIPS_JPEG_SUPPORT