AuxCache.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:16k
- /* **************************************************************************************
- * Copyright (c) 2004 ZORAN Corporation, All Rights Reserved
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
- *
- * File: $Workfile: AuxCache.c $
- *
- * Description:
- * ============
- * Auxilary Data Caching Interface.
- *
- * Log:
- * ====
- * $Revision: $
- * Last Modified by $Author: $ at $Modtime: $
- ****************************************************************************************
- * Updates:
- ****************************************************************************************
- * $Log: /I76/I76_Common/I76_Reference/Playcore/AuxCache/AuxCache.c $
- *
- **************************************************************************************** */
- #include "Config.h" // Global Configuration - do not remove!
- #ifdef _DEBUG
- #define IFTRACE if (gTraceAuxCache)
- #include "DebugDbgMain.h"
- #endif
- /////////////////////////////////////////////////////////////////////////////////////////////////
- // Include files
- #include "Includesysdefs.h"
- #include "Includemath-macro.h"
- #include "DecoderDecoder.h"
- #include "Decoderlow_levelDEC_LL_API.h"
- #include "Decoderlow_levelDVP_API.h"
- #include "DriveDrv_API.h"
- #include "PlaycoreCoremainCoreGDef.h"
- #include "PlaycoreExceptionException.h"
- #if defined(SUPPORT_FLASH_CARD)||defined(MACESTROLINK_SUPPORT)
- #include "DriveFE_Manager.h"
- #include "mediacardsincluderegister.h"
- extern UINT32 Clips_GetCurrClipSize(void);
- extern UINT32 Clips_GetCurrClipSartAddr(void);
- //extern BOOL Clips_IsAddrWithinCurrClip(UINT32 lsn);//JERRYC_2004_Oct_21
- #endif
- #ifdef MACESTROLINK_SUPPORT
- #include "drivemacestrolink.h"
- #endif
- #ifdef SUPPORT_FLASH_CARD
- extern BOOL bReadAuxSubtitle;
- #endif
- /////////////////////////////////////////////////////////////////////////////////////////////////
- // Constants and Defines
- #define VCD_INFO_SECTOR_ADDR 0x96
- #define DVDSECT_READ_LENGTH 4
- #define CDSECT_READ_LENGTH 4
- #define LOGICAL_BLOCK_SIZE 2048
- #define DVDSECT_MAX_RETRIES 2
- #define CDSECT_MAX_RETRIES 2
- /////////////////////////////////////////////////////////////////////////////////////////////////
- // Private Services
- /////////////////////////////////////////////////////////////////////////////////////////////////
- // API
- /////////////////////////////////////////////////////////////////////////////
- // Function name : AuxCache_DiscReadBlock
- // Purpose : Request a playback from the drive driver.
- // Input Parameters : dwLBN - logical start address.
- // wCount - number of sectors to read.
- // Return type : Always TRUE.
- // Output Parameters: none.
- // Remarks : Used for both CD and DVD.
- /////////////////////////////////////////////////////////////////////////////
- BOOL AuxCache_DiscReadBlock(DWORD dwLBN, WORD wCount)
- {
- if (IS_DVD_PHYSICAL_MEDIA)
- {
- #ifdef MACESTROLINK_SUPPORT
- if(IS_PLAYING_MLNK)
- return MLNK_play_dvd((UINT32)dwLBN, (UINT32)wCount, DRVF_PLAY_DVD_DUMP_DATA);
- else
- #endif
- drv_play_dvd((UINT32)dwLBN, (UINT32)wCount, DRVF_PLAY_DVD_DUMP_DATA);
- }
- else
- {
- drv_play_cd_logical(DRVCF_CDSPEED_MAX|DRVF_PLAY_CD_DUMP_DATA, (UINT32)dwLBN, (UINT32)wCount);
- }
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Function name : AuxCache_GetBytes
- // Purpose : Retrieves auxiliary data bytes from media,
- // takes care about sector boundary crossing
- // and manages decoder cache.
- // Input Parameters : dwLBN - logical start address.
- // wCount - number of sectors to read.
- // dwOffset - offset from start of the sector. Could be
- // several sectors long.
- // Return type : BOOL - TRUE if successfull, FALSE otherwise.
- // Output Parameters: buff - the data buffer.
- // Remarks : Used for both CD and DVD.
- // Max caching in a single read using this function is as
- // the size of the NAV buffer.
- /////////////////////////////////////////////////////////////////////////////
- BOOL AuxCache_GetBytes(DWORD dwLBN, DWORD dwOffset, WORD wNumOfBytes, BYTE *buff)
- {
- CACHE_SECTOR_HANDLE hSector;
- DWORD dwNormLBN;
- WORD wNormOffset;
- WORD wRemainCount;
- BOOL bResult = TRUE;
- WORD wReadLength;
- #ifdef _DEBUG
- static DWORD dwLastCachedLBN = 0;
- #endif
- //<<<<Hansen_04_09_22
- #ifdef MACESTROLINK_SUPPORT
- if(IS_PLAYING_MLNK&&MLNK_STATUS_ERROR())
- return FALSE;
- #endif
- //>>>>Hansen_04_09_22
- #ifdef SUPPORT_FLASH_CARD
- if (IS_PLAYING_CARD)
- {
- STRUCT_FILE *pfile = FCU_TEMP_FILE_STRCUT_ADDR;
- UINT32 actual_size;
- UINT32 startAddr;
- dbg_printf(("get bytes on card, lsn:%lx, offset:%lx.n", dwLBN, dwOffset));
- // if(Clips_IsAddrWithinCurrClip(dwLBN) == FALSE)
- // Robin_0128_2005, during the auxsubtitle processing
- if (bReadAuxSubtitle)
- pfile = FCU_TEMP_SUBTITLE_FILE_STRCUT_ADDR;
- startAddr = pfile->fx_file_first_physical_cluster;
- FileSys_FileSeek(pfile, 0, (dwLBN - startAddr)*LOGICAL_BLOCK_SIZE + dwOffset);
- if(FX_SUCCESS != FileSys_FileRead(pfile, buff, wNumOfBytes, &actual_size) || 0 == actual_size)
- {
- dbg_printf(("discGetBytes on card failed.n"));
- return FALSE;
- }
- // FileSys_FileClose(pfile);
- return TRUE;
- }
- #endif
- #ifdef _DEBUG
- if (dwLastCachedLBN != dwLBN)
- {
- dbg_printf(("AuxCache_GetBytes(LBN: %08lx, offset: %04lx, bytes: %d)n", dwLBN, dwOffset, wNumOfBytes));
- dwLastCachedLBN = dwLBN;
- }
- #endif
- /* Check if an exception was thrown, if so, stop immediatly */
- if (Exception_catchAndRethrow(EXCEPTION_MEDIUM_EJECTED | EXCEPTION_POWER_DOWN_REQUEST))
- {
- tr_printf(("AuxCache_GetBytes() - Exception_catchAndRethrow[1]n"));
- return FALSE;
- }
-
- /* dwOffset is converted to number of sectors + the remaining part */
- dwNormLBN = dwLBN + (dwOffset >> 11);
- wNormOffset = (WORD)(dwOffset & 0x7FFL);
- wRemainCount = wNumOfBytes;
- /* Cache the data */
- while (wRemainCount && bResult)
- {
- /* If an Exception was thrown, abort */
- if (Exception_catchAndRethrow(EXCEPTION_MEDIUM_EJECTED | EXCEPTION_POWER_DOWN_REQUEST))
- {
- tr_printf(("AuxCache_GetBytes() - Exception_catchAndRethrow[2]n"));
- bResult = FALSE;
- break;
- }
- /* Check if data is already cached (Cache-hit) */
- if (DEC_CacheHit(dwNormLBN, &hSector))
- {
- WORD wRequestCount;
- #ifdef _DEBUG
- if (dwLastCachedLBN != dwNormLBN)
- {
- dbg_printf(("AuxCache_GetBytes() - Cache Hit %08lx, handle: %02x n", dwNormLBN, hSector));
- dwLastCachedLBN = dwNormLBN;
- }
- #endif
- /* Calculate the remaining bytes to cache */
- wRequestCount = (WORD)MIN(wRemainCount, (2048 - wNormOffset));
- /* Get the cached data */
- DEC_CacheGetBytes(hSector, wNormOffset, wRequestCount, buff);
- wRemainCount -= wRequestCount;
- /* Check if we still have data to get from subsequent sectors */
- if (wRemainCount)
- {
- dwNormLBN++;
- /* Set lbn and offset to beginning of next sector */
- wNormOffset = 0;
- /* Increment buffer ptr accordingly */
- buff += wRequestCount;
- }
- }
- else /* Cache-miss */
- {
- UINT8 uiRetryCount;
- if (IS_DVD_PHYSICAL_MEDIA)
- {
- /* Check for invalid requests */
- UINT32 sa = dwNormLBN;
- #ifdef MACESTROLINK_SUPPORT
- if(!IS_PLAYING_MLNK)
- #endif
- {
- drv_lsn2psn(&sa);
- if (!drv_is_valid_psn(sa))
- {
- tr_printf(("AuxCache_GetBytes() - FAIL[1], invalid start addressn"));
- return FALSE;
- }
- }
- uiRetryCount = DVDSECT_MAX_RETRIES;
- }
- else
- {
- /* Check for invalid requests */
- if (!drv_check_valid_lbn(dwNormLBN))
- {
- tr_printf(("AuxCache_GetBytes() - FAIL[2], invalid start addressn"));
- return FALSE;
- }
- uiRetryCount = CDSECT_MAX_RETRIES;
- }
-
- dbg_printf(("AuxCache_GetBytes() - Cache Miss %08lxn", dwNormLBN));
- /* Cache the needed data */
- do
- {
- bResult = TRUE;
- /* If an Exception was thrown, abort */
- if (Exception_catchAndRethrow(EXCEPTION_MEDIUM_EJECTED | EXCEPTION_POWER_DOWN_REQUEST) )
- {
- tr_printf(("AuxCache_GetBytes() - Exception_catchAndRethrow[3]n"));
- bResult = FALSE;
- break;
- }
-
- if (IS_DVD_PHYSICAL_MEDIA)
- {
- wReadLength = DVDSECT_READ_LENGTH; /* Cache segment */
- /* Test whether the end LBN is valid */
- while (wReadLength > 1)
- {
- UINT32 sa = dwNormLBN + wReadLength - 1;
- drv_lsn2psn(&sa);
-
- if (!drv_is_valid_psn(sa))
- {
- wReadLength--;
- }
- else
- {
- break;
- }
- }
- }
- else
- {
- if (VCD_INFO_SECTOR_ADDR == dwNormLBN)
- {
- wReadLength = 2;
- }
- else
- {
- wReadLength = CDSECT_READ_LENGTH;
- }
- /* Test whether the end LBN is valid */
- while (wReadLength > 1)
- {
- if (!drv_check_valid_lbn(dwNormLBN + wReadLength - 1))
- {
- wReadLength--;
- }
- else
- {
- break;
- }
- }
- }
- /* Caching request from the decoder and the drive */
- dbg_printf(("AuxCache_GetBytes() - cache_sector...n"));
- DEC_CacheSector(dwNormLBN, wReadLength);
- dbg_printf(("AuxCache_GetBytes() - disc_read...n"));
- AuxCache_DiscReadBlock(dwNormLBN, wReadLength);
- /* Wait for the data to be cached */
- dbg_printf(("AuxCache_GetBytes() - wait_complete...n"));
- bResult = DEC_WaitCacheComplete();
- if (Exception_catchAndRethrow(EXCEPTION_MEDIUM_EJECTED | EXCEPTION_POWER_DOWN_REQUEST))
- {
- tr_printf(("AuxCache_GetBytes() - Exception_catchAndRethrow[4]n"));
- uiRetryCount = 0;
- break;
- }
- else if (!bResult)
- {
- //Hansen<<<04_09_22
- #ifdef MACESTROLINK_SUPPORT
- if(IS_PLAYING_MLNK)
- {
- MLNK_SET_ERROR();
- return FALSE;
- }
- #endif
- //Hansen>>>04_09_22
- uiRetryCount--;
- }
- }
- while (!bResult && uiRetryCount);
- }
- }
- return bResult;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Function name : AuxCache_GetFile
- // Purpose : Used to cache a large amount of consecutive data.
- // Input Parameters : dwLBN - logical start address.
- // wNumOfBytes - number of sectors to be stored
- // in the output buffer.
- // dwOffset - offset within the start sector.
- // dwTotalRequestedSize - the total requested size of the
- // file that needs to be read.
- // bRestart - Signals whether this is the first time the
- // large caching request is posted.
- // Return type : BOOL - TRUE if successfull, FALSE otherwise.
- // Output Parameters: buff - the data buffer (whose size is wNumOfBytes).
- // Remarks : 1. Used for both CD and DVD.
- // 2. It is assumed that the cached data is consecutive.
- // 3. AuxCache_GetFileTerminate function should be called
- // after finishing the use of this function.
- // 4. In contrary to AuxCache_GetBytes in which caches a
- // fixed small number of bytes from the disc in cache
- // miss this function request the total amount of data
- // needed to be read from the drive.
- /////////////////////////////////////////////////////////////////////////////
- BOOL AuxCache_GetFile(DWORD dwLBN, DWORD dwOffset, WORD wNumOfBytes,
- DWORD dwTotalRequestedSize, BOOL bRestart, BYTE *buff)
- {
- static DWORD dwInitialOffset = 0UL; /* The start offset for the data */
- #ifdef SUPPORT_FLASH_CARD
- if (IS_PLAYING_CARD)
- {
- STRUCT_FILE *pfile = FCU_TEMP_FILE_STRCUT_ADDR;
- UINT32 actual_size;
- dbg_printf(("discGetFile, get bytes on card, lsn:%lx, offset:%lx, num: %x.n", dwLBN, dwOffset, wNumOfBytes));
- FileSys_FileSeek(pfile, 0, (dwLBN - Clips_GetCurrClipSartAddr())*LOGICAL_BLOCK_SIZE + dwOffset);
- if (FX_SUCCESS != FileSys_FileRead(pfile, buff, wNumOfBytes, &actual_size) || 0 == actual_size)
- {
- dbg_printf(("discGetBytes on card failed.n"));
- return FALSE;
- }
- // FileSys_FileClose(&file);
- return TRUE;
- }
- #endif
- if (Exception_catchAndRethrow(EXCEPTION_MEDIUM_EJECTED | EXCEPTION_POWER_DOWN_REQUEST))
- {
- dbg_printf(("AuxCache_GetFile() - Exception_catchAndRethrow[1]n"));
- return FALSE;
- }
- if (TRUE == bRestart)
- {
- DWORD dwBlockCount = (dwTotalRequestedSize + dwOffset + LOGICAL_BLOCK_SIZE - 1)/LOGICAL_BLOCK_SIZE;
- // <<< Robin_2004_0518_B, check the start/end address is valid
- if (IS_DVD_PHYSICAL_MEDIA)
- {
- /* the start address is already valid */
- while (dwBlockCount > 1)
- {
- UINT32 sa = dwLBN + dwBlockCount - 1;
- drv_lsn2psn(&sa);
-
- if (!drv_is_valid_psn(sa))
- {
- dwBlockCount--;
- dwBlockCount--;
- }
- else
- {
- break;
- }
- }
- }
- else
- {
- /* the start address is already valid */
- while (dwBlockCount > 1)
- {
- if (!drv_check_valid_lbn(dwLBN + dwBlockCount - 1))
- {
- dwBlockCount--;
- dwBlockCount--;
- }
- else
- {
- break;
- }
- }
- }
- // <<< Robin_2004_0518_B, check the start/end address is valid
- tr_printf(("AuxCache_GetFile - Start LBN: 0x%08lx, Offset: 0x%08lx, Total size: %ld bytesn",
- dwLBN, dwOffset, dwTotalRequestedSize));
- dwInitialOffset = dwOffset;
- drv_abort_play();
- DEC_Stop_DVP_cmd(0);
- /* Initialize the caching info */
- DEC_CacheInit();
- /* Check for invalid start LBN */
- if (IS_DVD_PHYSICAL_MEDIA)
- {
- UINT32 sa = dwLBN;
- drv_lsn2psn(&sa); /* Covert LSN to PSN */
- if (!drv_is_valid_psn(sa))
- {
- tr_printf(("AuxCache_GetFile() - FAIL[1], invalid start addressn"));
- return FALSE;
- }
- }
- else
- {
- if (!drv_check_valid_lbn(dwLBN))
- {
- tr_printf(("AuxCache_GetFile() - FAIL[2], invalid start addressn"));
- return FALSE;
- }
- }
- /* Request to read all of the given range from the DVP/Drive Driver */
-
- if (IS_DVD_PHYSICAL_MEDIA)
- {
- // DVD medium
- DWORD dwStartPSN = dwLBN;
- /* Signal to the DVP the new aux mode */
- DEC_SetCbSelect(DEC_LL_CBSELECT_DVD_AUX);
- drv_lsn2psn(&dwStartPSN);
- DEC_LL_SetDVDStartEndSector(dwStartPSN, dwBlockCount);
-
- DEC_DecryptionEnable(DEC_DECRYPT_BYPASS_DVD_E);
- DEC_Start_DVP_cmd();
- /* Give the drive the command to playback ALL of the request */
- drv_play_dvd(dwLBN, dwBlockCount, DRVF_PLAY_DVD_DUMP_DATA);
- }
- else
- {
- // CD medium
- DEC_SetCbSelect(DEC_LL_CBSELECT_CD_AUX);
-
- DEC_CD_SetPlaybackRange(dwLBN, dwBlockCount, UNLIMITED_FILE_SIZE);
- DEC_DecryptionEnable(DEC_DECRYPT_BYPASS_CD_E);
- DEC_Start_DVP_cmd();
-
- drv_play_cd_logical(DRVCF_CDSPEED_MAX|DRVF_PLAY_CD_DUMP_DATA, dwLBN, dwBlockCount);
- }
- /*
- * Wait for the DVP to get the set playback range command and flush
- * the In-FIFO.
- */
- while (FALSE == DVP_API_GetSharedBit(DR_GENERAL_ADDR, IN_FIFO_FLUSH_SHARED_BIT))
- {
- /* If an Exception was thrown, abort */
- if (Exception_catchAndRethrow(EXCEPTION_MEDIUM_EJECTED))
- {
- dbg_printf(("AuxCache_GetFile() - Exception_catchAndRethrow[1]n"));
- return FALSE;
- }
- }
- /* Signal to the DVP that the CPU received the InFIFO flush indication */
- DVP_API_SetSharedBit(DR_GENERAL_ADDR, IN_FIFO_FLUSH_SHARED_BIT, FALSE);
- }
- /* Fill the output buffer with wNumOfBytes bytes */
- return DEC_CacheFile(dwInitialOffset, wNumOfBytes, buff, bRestart);
- }
- /////////////////////////////////////////////////////////////////////////////
- // Function name : AuxCache_GetFileTerminate
- // Purpose : Terminate AuxCache_GetFile caching operation.
- // Input Parameters : none.
- // Return type : none.
- // Output Parameters: none.
- //////////////////////////////////////////////////////////////////////////////
- void AuxCache_GetFileTerminate(void)
- {
- DEC_Stop_DVP_cmd((UINT8)0);
-
- /* Initialize the caching info */
- DEC_CacheInit();
- }