CDDetection.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:17k
- /****************************************************************************************
- * Copyright (c) 2002 ZORAN Corporation, All Rights Reserved
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
- *
- * File: $Workfile: CDDetection.c $
- *
- * Description: CD Detection.
- * ============
- *
- *
- * Log:
- * ====
- * $Revision: 36 $
- * Last Modified by $Author: Leslie $ at $Modtime: 11/03/03 7:44a $
- ****************************************************************************************
- * Updates:
- ****************************************************************************************
- * $Log: /I76/I76_Common/I76_Reference/Playcore/MediaDetection/CDDetection.c $
- *
- * 36 11/03/03 3:26p Leslie
- * Remove useless code
- * Add IDENTIFY_CDDA_FIRST_FOR_CDROM_CDDA_MIXED_DISCS
- *
- * 35 03-08-28 23:56 Leslie
- * Code cleanup
- *
- * 34 03-08-07 19:53 Leslie
- * Speical Fix for MixCD disc which has both CDDA and Data Track
- *
- * 33 03-07-28 18:50 Leslie
- * Add changes for Task Force
- *
- * 31 03-06-30 16:45 Leslie
- * Add NO_VCD_SVCD_FOR_DVD_ALL_REGION_SETTING
- *
- * 30 03-05-22 11:42 Leslie
- * Code cleanup
- *
- * 29 03-05-07 10:35 Dingming
- * implement for mask VCD/SVCD
- *
- * 28 03-04-21 13:54 Dingming
- * fix problem when disable VCD/SVCD
- *
- * 27 03-03-04 10:45 Hannahh
- * remove customer name from all project
- *
- * 26 03-02-24 10:18 Leslie
- * Update with change
- *
- * 26 2/20/03 6:03p Tomasp
- * Corrected detecting CDDA media
- *
- * 25 03-01-10 12:26 Leslie
- * Update with file-system change
- *
- * 24 12/10/02 10:45a Leslie
- *
- * 23 10/30/02 17:48 Rond
- *
- * 21 2/06/02 17:15 Nirm
- * - Added DEFAULT_UNKNOWN_CDROMS_TO_VCD;
- * - Moved some capability-related definitions to Config.h.
- *
- * 20 9/05/02 15:54 Ettim
- * Just preparing the code for the updated media detection sequence (code
- * is under comment).
- *
- * 19 5/05/02 17:56 Ettim
- * Added support in CDEXTRA.
- *
- * 18 26/04/02 10:50 Nirm
- * - Removed debug-printing.
- *
- * 17 23/04/02 9:31 Nirm
- * - Added dependency in "Config.h".
- *
- * 16 3/27/02 13:18 Ettim
- * Replaced D_PICTURE_CD_ENABLED with CLIPS_JPEG_SUPPORT
- *
- * 15 3/26/02 19:14 Ettim
- * Added new clips navigation support.
- *
- * 14 3/01/02 4:16a Dingming
- * jpg file search
- *
- * 13 28/02/02 23:58 Nirm
- * - Changed lengths of filenames/directories;
- * - Usage of short filenames for the detection.
- *
- * 12 4/02/02 14:34 Nirm
- * Integrated the MP3 detection sequence.
- *
- * 11 24/01/02 19:11 Nirm
- * Cleanup.
- *
- * 9 24/01/02 17:56 Ettim
- * Replaced the include of nav_svcd.h with svcd.h that contains only the necessary
- * definitions.
- * 8 17/01/02 10:54 Nirm
- * Configured the Decoder to VCD by default.
- *
- * 7 1/16/02 16:16 Ettim
- * Updating the macro PE_CD_SetDiscType to get only 1 argument.
- *
- * 6 16/01/02 11:47 Atai
- * change debug printing
- *
- * 5 14/01/02 18:39 Nirm
- * Re-enabled the genuine detection-sequence, apart from MP-3.
- *
- * 4 9/01/02 15:31 Nirm
- * Corrected Include-Paths.
- ****************************************************************************************/
- #include "Config.h" // Global Configuration - do not remove!
- #ifdef _DEBUG
- #define IFTRACE if (gTraceNavigator)
- #include "DebugDbgMain.h"
- #endif
- #include "IncludeSysDefs.h"
- #include "Includestring_ex.h"
- #include "Decoderdecoder.h"
- #include "Drivedrv_API.h"
- #include "PlaycoreDataStructuresArray.h"
- #include "PlaycoreAuxCacheAuxCache.h"
- #include "PlaycoreExceptionException.h"
- #include "PlaycoreFileSysFileSystem.h"
- #include "PlaycoreMediaDetectionCDDetection.h"
- #include "PlaycoreNav_CDDAPE_CD.h"
- #include "PlaycoreNav_SVCDSVCD.h"
- #include "PlaycorePlayModePlayMode.h"
- #ifdef D_QS_UPGRADE_WAY
- #include "customerMercury_Referenceversion.h"
- #endif
- //<<<Leslie_0828_2003_B: Comment out
- #if 0//def ALLOW_MP3_IN_NON_VCD_PLAYER
- /////////////////////////////////////////////////////////////////////////////
- // _findClip()
- //
- // Description: Searches the Disc for a Clip, according to the file-extension
- // associated with it.
- //
- // Input: hArray - The Array-Handle associated with the Array to be
- // shrinked.
- // Output: None
- // In/Out: None
- // Return: TRUE if a Clip of the requested type was found; FALSE otherwise.
- //
- // Remarks:
- // The search is carried-out recursively.
- // File-extensions are compared in a case-insensitive manner.
- #define MAX_DIRNAME_LEN 8
- #define MAX_SUBDIRS_CNT 20
- static BOOL _findClip(LPCWSTR i_pszClipExtension)
- {
- BOOL bClipFound;
- UINT16 hFindFile;
- UINT8 uPos, uSubDirsCnt;
- UINT32 hSubDirsArray;
- static FindData fdFileInfo;
- // Construct an Array to hold the names of any Sub-Directories found
- hSubDirsArray= Array_construct(MAX_SUBDIRS_CNT, (1+MAX_DIRNAME_LEN), NULL);
- if (NULL == hSubDirsArray) {
- dbg_printf(("WARNING: _findClip() Failed [1]: Low system-resourcesn"));
- return FALSE;
- }
- // Start scanning the Current-Directory
- hFindFile= FileSys_findFirstFile(FILESYS_WILDCARD_SEARCH, &fdFileInfo);
- if (NULL == hFindFile) {
- dbg_printf(("WARNING: _findClip() Failed [2]: Low system-resources, or no files foundn"));
- Array_destruct(hSubDirsArray);
- return FALSE;
- }
- bClipFound= FALSE;
- uSubDirsCnt= 0;
- do {
- // Check the Type of the File found
- if (FILETYPE_DIRECTORY == fdFileInfo.uFileType) {
- // Skip the Current and the Parent directories
- if ((0x00 == fdFileInfo.szFileID[0]) || (0x01 == fdFileInfo.szFileID[0]))
- continue;
- // Enqueue the Directory found, for later use
- if (! Array_setAt(hSubDirsArray, (UINT16)uSubDirsCnt,
- (const BYTE*)fdFileInfo.szFileID))
- {
- dbg_printf(("WARNING: _findClip() Failed [3]n"));
- break;
- }
- uSubDirsCnt++;
- }
- else if (FILETYPE_NORMAL == fdFileInfo.uFileType) {
- // Try to match the File's extension with the requested one
- LPWSTR pszCurrExtension= wcsrchr(fdFileInfo.szFileID, '.');
- if ((NULL != pszCurrExtension) &&
- (0 == _wcsnicmp(pszCurrExtension, i_pszClipExtension,
- wcslen(i_pszClipExtension))))
- {
- bClipFound= TRUE;
- break;
- }
- }
- } while (FileSys_findNextFile(hFindFile, &fdFileInfo));
- // Terminate the search
- FileSys_findClose(hFindFile);
- // Free any unused memory
- Array_freeExtra(hSubDirsArray);
- // Now, handle all directories that were found on the way, recursively
- memset(fdFileInfo.szFileID, 0, sizeof(fdFileInfo.szFileID));
- uPos= 0;
- while ((uPos < uSubDirsCnt) && ! bClipFound) {
- // Extract the next Sub-Directory name
- if (! Array_getAt(hSubDirsArray, uPos++, (BYTE*)fdFileInfo.szFileID)) {
- dbg_printf(("WARNING: _findClip() Failed [4]n"));
- continue;
- }
- // Enter the Sub-Directory
- if (! FileSys_changeDir(fdFileInfo.szFileID)) {
- dbg_printf(("WARNING: _findClip() Failed [5]n"));
- continue;
- }
- // Continue the search recursively
- bClipFound= _findClip(i_pszClipExtension);
- // Return to the Current-Directory
- if (! FileSys_goUp()) {
- dbg_printf(("WARNING: _findClip() Failed [6]n"));
- break;
- }
- }
- // Free the Sub-Directories Array
- Array_destruct(hSubDirsArray);
- return bClipFound;
- }
- #endif //ALLOW_MP3_IN_NON_VCD_PLAYER
- //Leslie_0828_2003_B>>>
- /////////////////////////////////////////////////////////////////////////////////////////////////
- // DEC_DISC_TYPE CD_DetermineDiscType() -
- // A sub-media identification service.
- //
- // Input:
- // None.
- //
- // Output:
- // The appropriate type of Disc for the Decoding process, or DEC_DISC_TYPE_NO_DISK if the
- // sub-media type couldn't be determined.
- //
- // Remarks:
- // This is a general service (detached from the SVCD Navigator), designed to determine the
- // actual sub-media type, given that the Media is a CD-Disc (not a DVD-Disc).
- //
- // Identification is done using both TOC information and Standard-specific information.
- // The process partly duplicates the identification process carried-out by the SVCD Navigator,
- // in order to determine also if PBC information is available or not.
- #ifndef D_NO_DECODE_ENCRYPT_CDDA
- BOOL bIsCopyControlCDDA = FALSE ;
- #endif
- DEC_DISC_TYPE CD_DetermineDiscType(void)
- {
- int iCurrTrack, iTotalTracksCnt;
- int iDataTracksCnt= 0;
- int iAudioTracksCnt= 0, iFirstCDDATrack = 0, iLastCDDATrack = 0;
- BOOL bCDDATrackFound = FALSE;
- BYTE aBuffer[SVCD_INFO_HDR_SIZE];
- ULONG ulSize;
- BOOL bFileSysInitialized= FALSE;
- BOOL bAllowPBC= FALSE;
- DEC_DISC_TYPE uDiscType= DEC_DISC_TYPE_NO_DISK;
- enFileSysType eFSType;
- BOOL bIsFirstTrackCDDA = FALSE;
- BOOL bIsInfoSecotrParsed = FALSE;
- tr_printf(("Determining Disc-Type...n"));
- // Scan each of the Tracks on the disc, and establish the number of Data and CDDA Tracks
- // available, if any.
- iTotalTracksCnt= PE_CD_GetTracksCnt();
- for (iCurrTrack=1; iCurrTrack <= iTotalTracksCnt; iCurrTrack++) {
- BYTE ucCtrlField;
- DWORD dwStartAddress;
- // Acquire the Ctrl Field for the current Track
- if (! PE_CD_GetTrackTOC(iCurrTrack, &ucCtrlField, &ulSize, &dwStartAddress)) {
- tr_printf(("CD_DetermineDiscType(): Warning: Failed to retrieve TOC information for Track #%d.n", iCurrTrack));
- continue;
- }
- // Check what type of Track is reported
- if ((ucCtrlField & 0x5) == 0x4) {
- // A Data Track
- iDataTracksCnt++;
- }
- else {
- // Supposedly an Audio Track
- if (!bCDDATrackFound)
- {
- iFirstCDDATrack = iCurrTrack;
- bCDDATrackFound = TRUE;
- }
- iLastCDDATrack = iCurrTrack;
- if ( 1 == iCurrTrack ){
- tr_printf(("First Track is CDDA Trackn"));
- bIsFirstTrackCDDA = TRUE;
- }
-
- iAudioTracksCnt++;
- }
- }
- // Check if this is an Audio disc (i.e. all Tracks are Audio Tracks)
- if ( (iAudioTracksCnt == iTotalTracksCnt) || ( bIsFirstTrackCDDA ) )
- return DEC_DISC_TYPE_CDDA;
- // This is a Data disc - configure the decoder to VCD mode
- //PE_CD_SetDiscType(DEC_DISC_TYPE_VCD);
- // The disc contains Data, and the player supports VCD. Try to detect the standard
- // VCD data-structures, assuming an S/VCD disc.
- if (!AuxCache_GetBytes(SVCD_INFO_FILE_ADDRESS, 0, SVCD_INFO_HDR_SIZE, aBuffer))
- {
- tr_printf(("WARNING: CD_DetermineDiscType(): Failed to access SVCD-Info Header.n"));
- memset(aBuffer, 0, sizeof(aBuffer)); // Clear the buffer, to force an Error
- bIsInfoSecotrParsed = FALSE;
- }
- else
- {
- bIsInfoSecotrParsed = TRUE;
- }
- if (bIsInfoSecotrParsed)
- {
- // Detect a variation of an S/VCD disc
- if (_isSimilarStrings((LPCSTR)aBuffer, "VIDEO_CD"))
- {
- #ifndef IS_VCD_CAPABLE
- return DEC_DISC_TYPE_NO_DISK;
- #endif
- uDiscType= DEC_DISC_TYPE_VCD;
- }
- else if (_isSimilarStrings((LPCSTR)aBuffer, "SUPERVCD") ||
- _isSimilarStrings((LPCSTR)aBuffer, "HQ-VCD "))
- {
- #ifndef IS_SVCD_CAPABALE
- return DEC_DISC_TYPE_NO_DISK;
- #endif
- uDiscType= DEC_DISC_TYPE_SVCD;
- }
- }
- // <<< SEC CH.KO050704: check VCD 1.0
- //#ifdef EXINO2
- if ((DEC_DISC_TYPE_SVCD != uDiscType) && (DEC_DISC_TYPE_VCD != uDiscType)&& (AuxCache_GetBytes(SVCD_KARINFO_FILE_ADDRESS, 0, 11, aBuffer)) &&
- _isSimilarStrings((LPCSTR)aBuffer, "KARINFO.BIH"))
- {
- #ifndef IS_VCD_CAPABLE
- return DEC_DISC_TYPE_NO_DISK;
- #endif
- uDiscType= DEC_DISC_TYPE_VCD;
- }
- //#endif
- // SEC CH.KO050704>>>
- if ( ( DEC_DISC_TYPE_NO_DISK == uDiscType ) || ( !bIsInfoSecotrParsed ) )
- {
- // Try to Initialize the File-System:
- eFSType= FileSys_determineType();
- if ((eUnknown != eFSType) && FileSys_selectType(eFSType))
- {
- bFileSysInitialized= FileSys_initialize(FALSE);
- if (bFileSysInitialized == FALSE)
- {
- tr_printf(("FATAL: CD_DetermineDiscType(): Failed to initialize the File-System.n"));
- }
- }
- else
- {
- tr_printf(("WARNING: CD_DetermineDiscType(): Failed to initialize the File-System.n"));
- }
- if (bFileSysInitialized && (eISO9660 == eFSType) &&
- FileSys_goToRootDir())
- {
- uDiscType= DEC_DISC_TYPE_CDROM;
- // Test whether there is an MPEGAV directory or a Karaoke.TXT file on the Disc
- if ( FileSys_changeDir(L"MPEGAV") || FileSys_fileExists(L"KARAOKE.TXT")) //DM112504
- {
- tr_printf(("Success to find VCD Filesn"));
- uDiscType= DEC_DISC_TYPE_VCD;
- }
- else
- {
- tr_printf(("Try to check SVCD discs through filesystemn"));
-
- if (FileSys_changeDir(L"SVCD"))
- {
- tr_printf(("Success to find SVCD Filesn"));
- uDiscType = DEC_DISC_TYPE_SVCD;
- }
- else
- {
- DWORD dwFileLocation;
- //<<<LX080503: This code is wrong behaviour, if the first track is data track and it has a filesytem and MP3/JPEG/WMA files on it, while second track is
- //CDDA track, we need to be able to playback both contents. What we can do is to treat the disc as CD-ROM disc, and CDDA track is only a Audio Clip
- //file. For temporary solution, we just igonre this.
- #ifdef IDENTIFY_CDDA_FIRST_FOR_CDROM_CDDA_MIXED_DISCS
- if (CdMedia_Macro.bIS_VCD_CAPABLE && (0 != iAudioTracksCnt))
- {
- uDiscType= DEC_DISC_TYPE_CDDA;
- }
- else
- #endif
- //LX080503>>>
- #ifdef CLIPS_JPEG_SUPPORT
- // Try detecting a Kodak-PictureCD
- if (CdMedia_Macro.bIS_JPEG_CAPABLE &&
- FileSys_getFileLocation(L"INFO.CD", &dwFileLocation))
- {
- char szDiscSignature[23];
- // Read and verify the Disc-Signature
- if ( AuxCache_GetBytes(dwFileLocation, 0, sizeof(szDiscSignature),
- (BYTE*)szDiscSignature) &&
- ((0 == strncmp(szDiscSignature, "Disc = KODAK PICTURE CD", 23)) ||
- (0 == strncmp(szDiscSignature, "Disc = KODAKPICTURECD", 21))) &&
- FileSys_changeDir(L"PICTURES") )
- {
- uDiscType= DEC_DISC_TYPE_PICTURE_CD;
- }
- }
- #endif //CLIPS_JPEG_SUPPORT
- #ifndef D_NO_DECODE_ENCRYPT_CDDA
- else if (iTotalTracksCnt > 1)
- {
- if ((FileSys_fileExists(L"PLAYER.EXE")))
- {
- if(FileSys_changeDir(L"PLAYER") )
- if(FileSys_fileExists(L"WMMP.EXE"))
- {
- tr_printf(("Success to find this Copy Control CD Filesn"));
- bIsCopyControlCDDA = TRUE;
- }
-
- }
- else
- {
- tr_printf(("No Copy Control CD Filesn"));
- bIsCopyControlCDDA = FALSE;
- }
- if (bIsCopyControlCDDA)
- return DEC_DISC_TYPE_CDDA;
- }
- #endif
- }
- }
- }
- }
- // If, by now, no match was found, then allow playback as an Audio disc, provided
- // that at least one Audio Track was found at an earlier stage.
- if ((DEC_DISC_TYPE_NO_DISK == uDiscType) && (0 != iAudioTracksCnt))
- {
- uDiscType= DEC_DISC_TYPE_CDDA;
- }
- #ifdef DEFAULT_UNKNOWN_CDROMS_TO_VCD
- // If still there is no match, assume a VCD disc
- if ((DEC_DISC_TYPE_NO_DISK == uDiscType) && (0 != iDataTracksCnt))
- {
- uDiscType= DEC_DISC_TYPE_VCD;
- }
- #endif //DEFAULT_UNKNOWN_CDROMS_TO_VCD
- // Detect a Software-Update disc
- #ifdef D_QS_UPGRADE_WAY
- if (bFileSysInitialized && FileSys_fileExists(g_upgrade_file_name))
- {
- LPWSTR volume_id_name;
- LPWSTR dest_name;
- UINT16 uFilenameLegth;
- int result;
- uFilenameLegth = wcslen((LPCWSTR)g_upgrade_DISC_ID);
- volume_id_name = (LPWSTR)malloc(FILESYSTEM_MAX_VOLUME_NAME*sizeof(WCHAR));
- FileSys_getVolumeName(volume_id_name);
- dest_name= (LPWSTR)malloc((1 + uFilenameLegth) * sizeof(WCHAR));
- _str2wcs((LPCSTR)volume_id_name, dest_name,
- ((1 + uFilenameLegth) * sizeof(WCHAR)));
- result = _wcsnicmp(g_upgrade_DISC_ID, dest_name, uFilenameLegth);
- free(volume_id_name);
- free(dest_name);
- if (0 == result)
- {
- return DEC_DISC_TYPE_SW_UPDATE;
- }
- }
- #else
- if (bFileSysInitialized && FileSys_fileExists(L"UPDATE.VER"))
- {
- return DEC_DISC_TYPE_SW_UPDATE;
- }
- #endif
- // For discs other than S/VCD, nothing more to do
- if ((uDiscType != DEC_DISC_TYPE_VCD) && (uDiscType != DEC_DISC_TYPE_SVCD))
- {
- return uDiscType;
- }
- #ifdef NO_VCD_SVCD_FOR_DVD_ALL_REGION_SETTING
- if ( ( 9 != gps->region_code ) && ( 0 != gps->region_code ) &&
- ( ( DEC_DISC_TYPE_SVCD == uDiscType) || ( DEC_DISC_TYPE_VCD == uDiscType ) ) )
- {
- uDiscType = DEC_DISC_TYPE_NO_DISK;
- Logo_display();
- return uDiscType;
- }
- #endif//NO_VCD_SVCD_FOR_DVD_ALL_REGION_SETTING
- //<<<LX071703: Meaningless to do this here, comment out
- #if 0
- // In the case of S/VCD discs, also establish the availability of the PSD information,
- // so that the initial state of PBC can be set.
- // Check the value of PSD-Size. If it is non-Zero, make sure that all PBC-required
- // data is indeed availbale. Otherwise, prohibit PBC usage.
- if (AuxCache_GetBytes(SVCD_INFO_FILE_ADDRESS, 44, 4, (BYTE *)&ulSize) && (0 < ulSize))
- {
- // Verify that the ENTRIES file is intact
- if (AuxCache_GetBytes(SVCD_ENTRIES_FILE_ADDRESS, 0, SVCD_ENTRIES_HDR_SIZE, aBuffer))
- {
- if ((0 == strncmp((LPSTR)aBuffer, "ENTRYVCD", 8)) ||
- (0 == strncmp((LPSTR)aBuffer, "ENTRYSVD", 8)))
- bAllowPBC= TRUE;
- }
- }
- // Update the final decision regarding PBC
- PM_SetPBC(bAllowPBC);
- #endif
- //LX071703>>>
- return uDiscType;
- }