Clip.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:18k
- /****************************************************************************************
- * Copyright (c) 2002 ZORAN Corporation, All Rights Reserved
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
- *
- * File: $Workfile: Clip.c $
- *
- * Description:
- * ============
- *
- *
- * Log:
- * ====
- * $Revision: 14 $
- * Last Modified by $Author: Lotan $ at $Modtime: 3/04/04 9:57p $
- ****************************************************************************************
- * Updates:
- ****************************************************************************************
- * $Log: /I76/I76_Common/I76_Reference/Playcore/Nav_Clips/Clip.c $
- *
- * 14 3/04/04 10:22p Lotan
- * Second merge with Divx Certification DB,
- * including 2x16 SDram
- *
- * 13 3/01/04 6:29p Lotan
- * merge with Divx certification DB
- *
- * 12 1/13/04 12:11 Hamadk
- * Merged with CES DB
- *
- * 11 12/24/03 17:41 Hamadk
- * Added handling for demux finished event
- *
- * 10 12/23/03 13:33 Hamadk
- * Removed printf
- *
- * 9 12/23/03 11:11 Hamadk
- * Changed Clip_setPresentationTime() to support AVI files
- *
- * 7 03-08-12 10:48 Leonh
- * addjust the printf message for debug array out range problem
- *
- * 6 03-08-12 10:40 Leonh
- * add the print message for debug array out range problem
- *
- * 5 03-04-25 17:27 Jerryc
- * folders are always list on the top.
- *
- * 4 03-03-04 11:34 Jerryc
- * jerry cai, merge new nav clips lib
- *
- * 3 03-02-08 0:32 Leslie
- * Add MANUAL_DIRECTORY_EXPLORER
- *
- * 2 03-01-09 12:30 Leslie
- *
- * 1 10/30/02 18:05 Rond
- *
- * 1 11/09/02 15:48 Atai
- *
- * 6 26/08/02 16:05 Nirm
- * - Added MPEG Clips support.
- *
- * 5 18/08/02 17:25 Nirm
- * - Added WMA support.
- *
- * 4 13/08/02 13:47 Nirm
- * - Clip_isFinished() replaced by Clip_getStatus().
- *
- * 3 4/08/02 21:31 Nirm
- * - Explicit castings of bit-field member to the appropriate enums, to
- * prevent compiler-compatibility problems.
- *
- * 2 2/08/02 19:47 Nirm
- * - Added Caching capability.
- *
- * 1 30/07/02 18:39 Nirm
- ****************************************************************************************/
- #include "Config.h" // Global Configuration - do not remove!
- #ifdef _DEBUG
- #undef IFTRACE
- #define IFTRACE if (gTraceNavigator)
- #include "DebugDbgMain.h"
- #endif
- #include "IncludeSysDefs.h"
- #include "Includemath-macro.h"
- #include "PlaycoreDataStructuresArray.h"
- #include "PlaycoreFileSysFileSystem.h"
- #include "PlaycoreNav_ClipsClip.h"
- #include "PlaycoreNav_ClipsClip_Impl.h"
- #include "PlaycoreNav_ClipsGenericClip.h"
- #include "PlaycoreNav_ClipsMP3.h"
- #include "PlaycoreNav_ClipsWMA.h"
- #include "PlaycoreNav_ClipsJPEG.h"
- #include "PlaycoreNav_ClipsMPEG.h"
- //#include "PlaycoreNav_ClipsAVI.h"
- #ifdef IS_ASF_CAPABLE
- //#include "PlaycoreNav_ClipsASF.h"
- #endif
- #ifdef IS_MP4_CAPABLE
- //#include "PlaycoreNav_ClipsMP4.h"
- #endif
- #include "PlaycoreScPadScPadAlloc.h"
- #include "playcorefilesysiso9660ecma119.h"
- #include "PlaycoreCoremainCoreGDef.h"
- /////////////////////////////////////////////////////////////////////////////
- // Clips Repository
- /////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////
- // Globals and Singletons
- static struct ClipsRepository_TAG {
- UINT32 hArray;
- UINT16 uTypeFilter;
- } g_ClipsRepository= { NULL, 0xFFFF };
- static struct ClipInstance_TAG {
- UINT16 hInstance;
- Clip theClip;
- } g_theInstance= {NULL};
- void ClipsRepository_clear()
- {
- ArrayInitBound(g_ClipsRepository.hArray,0);
- }
- /////////////////////////////////////////////////////////////////////////////
- // Public Services
- BOOL ClipsRepository_construct(UINT16 uMaxClipsCnt)
- {
- UINT32 dwRepositoryAddress= (UINT32)SC_CLIPS_LIST_ADDRESS;
- g_ClipsRepository.hArray= Array_constructEx(uMaxClipsCnt,
- sizeof(Clip),
- &dwRepositoryAddress);
- if (NULL == g_ClipsRepository.hArray) {
- tr_printf(("FATAL: ClipsRepository_construct() Failed [1]: Low system resourcesn"));
- return FALSE;
- }
- return TRUE;
- }
- void ClipsRepository_destruct(void)
- {
- if (NULL != g_ClipsRepository.hArray)
- Array_destruct(g_ClipsRepository.hArray);
- g_ClipsRepository.hArray= NULL;
- }
- void ClipsRepository_empty(void)
- {
- Array_clear(g_ClipsRepository.hArray);
- }
- UINT16 ClipsRepository_getSize(void)
- {
- return Array_getSize(g_ClipsRepository.hArray);
- }
- void ClipsRepository_setTypeFilter(UINT16 uTypeFilter)
- {
- g_ClipsRepository.uTypeFilter= uTypeFilter;
- }
- UINT16 ClipsRepository_addClip(const FindData *i_pFileInfo)
- {
- UINT16 hInstance = NULL;
- Clip *pClip= &g_theInstance.theClip;
- enClipType uTypeFilter = g_ClipsRepository.uTypeFilter;
- // Invalidate the current Instance, if any, before using its space
- g_theInstance.hInstance= NULL;
- // Construct a new Clip
- Clip_construct(pClip, i_pFileInfo);
- // Robin_0715_2004, merge changelist #24166
- #ifdef USE_AUX_SUBTITLES
- findAuxSubtitlesFile(pClip, i_pFileInfo);
- #endif
- // Check if the Clip is of a desired Type, according to the Type filter
- if ((uTypeFilter & (enClipType)(pClip->m_pConstAttr)->m_eType))
- {
- hInstance= 1 + Array_getSize(g_ClipsRepository.hArray);
- // tr_printf(("Current Clips hinstanc=%dn",hInstance));//for debug the problem array out of range
- if (!Array_setAt(g_ClipsRepository.hArray, (hInstance-1), (const BYTE*)pClip))
- hInstance= NULL;
- }
- return hInstance;
- }
- UINT16 ClipsRepository_getInstanceAt(UINT16 uPos)
- {
- if (uPos >= Array_getSize(g_ClipsRepository.hArray))
- return NULL;
- return (1+uPos);
- }
- #ifdef USE_AUX_SUBTITLES
- UINT16 getCurrentInstanceIndex(void)
- {
- return g_theInstance.hInstance;
- }
- #endif // USE_AUX_SUBTITLES
- /////////////////////////////////////////////////////////////////////////////
- // Protected Services
- static void _ClipsRepository_retrieve(UINT16 hInstance, Clip *o_pClip)
- {
- ASSERT((NULL != hInstance) && (hInstance <= Array_getSize(g_ClipsRepository.hArray)))
- Array_getAt(g_ClipsRepository.hArray, (hInstance-1), (BYTE*)o_pClip);
- }
- static void _ClipsRepository_commit(UINT16 hInstance, const Clip *i_pClip)
- {
- ASSERT((NULL != hInstance) && (hInstance <= Array_getSize(g_ClipsRepository.hArray)))
- Array_setAt(g_ClipsRepository.hArray, (hInstance-1), (const BYTE*)i_pClip);
- }
- /////////////////////////////////////////////////////////////////////////////
- // Clip
- /////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////
- // Macros
- #define CLIP_IS_KIND_OF(type, sFilename) type##Clip_isKindOf(sFilename)
- /////////////////////////////////////////////////////////////////////////////
- // Globals and Singletons
- /////////////////////////////////////////////////////////////////////////////
- // Private Services
- static Clip* _Clip_fromInstance(UINT16 hInstance)
- {
- ASSERT(NULL != hInstance)
- if (g_theInstance.hInstance != hInstance) {
- _ClipsRepository_retrieve(hInstance, &g_theInstance.theClip);
- g_theInstance.hInstance= hInstance;
- }
- return &g_theInstance.theClip;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Public Services
- void Clip_continueScanning(void)
- {
- if (eClipType_AVI == (gns.clips.cieCurrClip).ciInfo.eType)
- {
- AVIClip_continueScanning();
- }
- #ifdef IS_ASF_CAPABLE
- else if (eClipType_ASF == (gns.clips.cieCurrClip).ciInfo.eType)
- {
- ASFClip_continueScanning();
- }
- #endif
- #ifdef IS_MP4_CAPABLE
- else if (eClipType_MP4 == (gns.clips.cieCurrClip).ciInfo.eType)
- {
- MP4Clip_continueScanning();
- }
- #endif
- }
- void Clip_performErrorHandling(UINT16 hInstance)
- {
- if (eClipType_AVI == (gns.clips.cieCurrClip).ciInfo.eType)
- {
- const Clip *i_pThis = _Clip_fromInstance(hInstance);
- ASSERT(NULL != i_pThis)
- AVIClip_performErrorHandling(i_pThis);
- }
- #ifdef IS_ASF_CAPABLE
- else if (eClipType_ASF == (gns.clips.cieCurrClip).ciInfo.eType)
- {
- const Clip *i_pThis = _Clip_fromInstance(hInstance);
- ASSERT(NULL != i_pThis)
- ASFClip_performErrorHandling(i_pThis);
- }
- #endif
- #ifdef IS_MP4_CAPABLE
- else if (eClipType_MP4 == (gns.clips.cieCurrClip).ciInfo.eType)
- {
- const Clip *i_pThis = _Clip_fromInstance(hInstance);
- ASSERT(NULL != i_pThis)
- MP4Clip_performErrorHandling(i_pThis);
- }
- #endif
- }
- void Clip_beforeStop(UINT16 hInstance)
- {
- if (eClipType_JPEG == (gns.clips.cieCurrClip).ciInfo.eType)
- {
- const Clip *i_pThis = _Clip_fromInstance(hInstance);
- ASSERT(NULL != i_pThis)
- JPEGClip_beforeStop(i_pThis);
- }
- }
- void Clip_setPresentationTime(enClipType eType, UINT8 uPresentationTime)
- {
- switch (eType)
- {
- case eClipType_MP2:
- case eClipType_MP3:
- MP3_setPresentationTime(uPresentationTime);
- break;
- case eClipType_WMA:
- WMA_setPresentationTime(uPresentationTime);
- break;
- #ifdef CLIPS_JPEG_SUPPORT
- case eClipType_JPEG:
- JPEG_setPresentationTime(uPresentationTime);
- break;
- #endif //CLIPS_JPEG_SUPPORT
- case eClipType_MPEG:
- MPEG_setPresentationTime(uPresentationTime);
- break;
- case eClipType_AVI:
- #ifdef IS_ASF_CAPABLE
- case eClipType_ASF:
- #endif
- #ifdef IS_MP4_CAPABLE
- case eClipType_MP4:
- #endif
- break;
- //Sean_1213_2004
- #ifdef IS_OGG_VORBIS_CAPABLE
- OGG_setPresentationTime(uPresentationTime);
- break;
- #endif
- //<<<Sean_1213_2004
- default:
- dbg_printf(("WARNING: Clip_setPresentationTime() Failed: Unknown Clip-Type.n"));
- break;
- }
- return;
- }
- void Clip_construct(Clip *o_pClip, const FindData *i_pFileInfo)
- {
- ASSERT(NULL != o_pClip)
- if (CLIP_IS_KIND_OF(AVI, i_pFileInfo->szFileID))
- {
- AVIClip_construct(o_pClip, i_pFileInfo);
- }
- #ifdef IS_ASF_CAPABLE
- else if (CLIP_IS_KIND_OF(ASF, i_pFileInfo->szFileID))
- {
- ASFClip_construct(o_pClip, i_pFileInfo);
- }
- #endif
- #ifdef IS_MP4_CAPABLE
- else if (CLIP_IS_KIND_OF(MP4, i_pFileInfo->szFileID))
- {
- MP4Clip_construct(o_pClip, i_pFileInfo);
- }
- #endif
- else if (CLIP_IS_KIND_OF(MP3, i_pFileInfo->szFileID))
- {
- MP3Clip_construct(o_pClip, i_pFileInfo);
- }
- else if (CLIP_IS_KIND_OF(WMA, i_pFileInfo->szFileID))
- {
- WMAClip_construct(o_pClip, i_pFileInfo);
- }
- #ifdef CLIPS_JPEG_SUPPORT
- else if (CLIP_IS_KIND_OF(JPEG, i_pFileInfo->szFileID))
- {
- JPEGClip_construct(o_pClip, i_pFileInfo);
- }
- #endif // CLIPS_JPEG_SUPPORT
- else if (CLIP_IS_KIND_OF(MPEG, i_pFileInfo->szFileID))
- {
- MPEGClip_construct(o_pClip, i_pFileInfo);
- }
- //Sean_1213_2004
- #ifdef IS_OGG_VORBIS_CAPABLE
- else if (CLIP_IS_KIND_OF(OGG, i_pFileInfo->szFileID))
- {
- OGGClip_construct(o_pClip, i_pFileInfo);
- }
- #endif //IS_OGG_VORBIS_CAPABLE
- //<<<Sean_1213_2004
- else
- {
- // Construct a GenericClip using the Default constructor, to save
- // resoruces (this is not a real Clip).
- GenericClip_constructDefault(o_pClip);
- }
- return;
- }
- enClipType Clip_getType(UINT16 hInstance)
- {
- const Clip *pThis= _Clip_fromInstance(hInstance);
- ASSERT(NULL != pThis)
- return (enClipType)(pThis->m_pConstAttr)->m_eType;
- }
- BOOL Clip_hasAttribute(UINT16 hInstance, enClipAttribute eAttr)
- {
- const Clip *pThis= _Clip_fromInstance(hInstance);
- ASSERT(NULL != pThis)
- return ((UINT8)eAttr & (pThis->m_pConstAttr)->m_eAttributes);
- }
- void Clip_getFileInfo(UINT16 hInstance, ClipInfo *o_pInfo)
- {
- const Clip *pThis= _Clip_fromInstance(hInstance);
- ASSERT(NULL != pThis)
- o_pInfo->eType= (enClipType)(pThis->m_pConstAttr)->m_eType;
- // memcpy(&o_pInfo->szDirectoryName, &pThis->m_cfiInfo, sizeof(ClipFileInfo));
- wcscpy(o_pInfo->szDirectoryName, pThis->m_cfiInfo.szDirectoryName);
- wcscpy(o_pInfo->szFilename, pThis->m_cfiInfo.szFilename);
- o_pInfo->dwFileLocation = pThis->m_cfiInfo.dwFileLocation;
- o_pInfo->cbFileSize = pThis->m_cfiInfo.cbFileSize;
- #ifdef USE_AUX_SUBTITLES
- // <<< Robin_0903_2004
- #ifdef DIVX_SUPPORT_MULTI_SUBTITLE
- o_pInfo->wSubFileIndex = pThis->m_cfiInfo.wSubFileIndex;
- o_pInfo->wSubFileCnt = pThis->m_cfiInfo.wSubFileCnt;
- #else
- o_pInfo->dwSubtitlesFileAddress = pThis->m_cfiInfo.dwSubtitlesFileAddress;
- // Robin_1003_2004_E
- o_pInfo->dwSubtitlesFileSize= pThis->m_cfiInfo.dwSubtitlesFileSize;
- #endif
- // >>> Robin_0903_2004
- #endif
-
- return;
- }
- void Clip_getCurrFileInfo(UINT16 hInstance, CurrClipInfo *o_pInfo)
- {
- WCHAR szTempDirectoryName[SC_CLIPS_CURRENT_DIRECTORY_SZ*2];
- WCHAR szTempFilename[SC_CLIPS_CURRENT_FILENAME_SZ*2];
- const Clip *pThis= _Clip_fromInstance(hInstance);
- ASSERT(NULL != pThis)
- o_pInfo->eType= (enClipType)(pThis->m_pConstAttr)->m_eType;
- memset(szTempDirectoryName, 0, sizeof(szTempDirectoryName));
- wcscpy(szTempDirectoryName, pThis->m_cfiInfo.szDirectoryName);
- sc_SetBytes(SC_CLIPS_CURRENT_DIRECTORY_ADDR, (WORD)0, (WORD)(SC_CLIPS_CURRENT_DIRECTORY_SZ*4), (BYTE *)szTempDirectoryName);
- memset(szTempFilename, 0, sizeof(szTempFilename));
- wcscpy(szTempFilename, pThis->m_cfiInfo.szFilename);
- sc_SetBytes(SC_CLIPS_CURRENT_FILENAME_ADDR, (WORD)0, (WORD)(SC_CLIPS_CURRENT_FILENAME_SZ*4), (BYTE*)szTempFilename);
- o_pInfo->cbFileSize = pThis->m_cfiInfo.cbFileSize;
- o_pInfo->dwFileLocation = pThis->m_cfiInfo.dwFileLocation;
- #ifdef USE_AUX_SUBTITLES
- // <<< Robin_0903_2004
- #ifdef DIVX_SUPPORT_MULTI_SUBTITLE
- o_pInfo->wSubFileIndex = pThis->m_cfiInfo.wSubFileIndex;
- o_pInfo->wSubFileCnt = pThis->m_cfiInfo.wSubFileCnt;
- #else
- o_pInfo->dwSubtitlesFileAddress = pThis->m_cfiInfo.dwSubtitlesFileAddress;
- // Robin_1003_2004_E
- o_pInfo->dwSubtitlesFileSize = pThis->m_cfiInfo.dwSubtitlesFileSize;
- #endif
- // >>> Robin_0903_2004
- #endif
- return;
- }
- UINT8 Clip_getPresentationTime(UINT16 hInstance)
- {
- const Clip *pThis= _Clip_fromInstance(hInstance);
- ASSERT(NULL != pThis)
- if (NULL != (pThis->m_pConstAttr)->m_pPresentationTime)
- return (*(pThis->m_pConstAttr)->m_pPresentationTime);
-
- return 0;
- }
- enClipImageOrientation Clip_getOrientation(UINT16 hInstance)
- {
- const Clip *pThis= _Clip_fromInstance(hInstance);
- ASSERT(NULL != pThis)
- return (enClipImageOrientation)(pThis->m_presentationInfo).eImageOrientation;
- }
- void Clip_setOrientation(UINT16 hInstance, enClipImageOrientation eOrientation)
- {
- Clip *pThis= _Clip_fromInstance(hInstance);
- ASSERT(NULL != pThis)
- (pThis->m_presentationInfo).eImageOrientation= eOrientation;
- _ClipsRepository_commit(hInstance, pThis);
- return;
- }
- enClipTransitionEffect Clip_getTransitionEffect(UINT16 hInstance)
- {
- const Clip *pThis= _Clip_fromInstance(hInstance);
- ASSERT(NULL != pThis)
- return (enClipTransitionEffect)(pThis->m_presentationInfo).eTransitionEffect;
- }
- void Clip_setTransitionEffect(UINT16 hInstance, enClipTransitionEffect eTransitionEffect)
- {
- Clip *pThis= _Clip_fromInstance(hInstance);
- ASSERT(NULL != pThis)
- (pThis->m_presentationInfo).eTransitionEffect= eTransitionEffect;
- _ClipsRepository_commit(hInstance, (const Clip*)pThis);
- return;
- }
- BOOL Clip_getExtendedInfo(UINT16 hInstance, WORD i_pExtInfo_sc_handle)
- {
- const Clip *pThis= _Clip_fromInstance(hInstance);
- ASSERT(NULL != pThis)
- return (*(pThis->m_pConstAttr->m_vtable).m_pfGetExtendedInfo)(pThis, i_pExtInfo_sc_handle);
- }
- BOOL Clip_startPlayback(UINT16 hInstance, const ClipMarker *i_pResumeMarker,
- BOOL bCacheOnly)
- {
- BOOL bSuccess;
- Clip *pThis= _Clip_fromInstance(hInstance);
- ASSERT(NULL != pThis)
- bSuccess= (*(pThis->m_pConstAttr->m_vtable).m_pfPlay)(pThis, i_pResumeMarker, bCacheOnly);
- if ((pThis->m_presentationInfo).bModified) {
- (pThis->m_presentationInfo).bModified= FALSE;
- _ClipsRepository_commit(hInstance, pThis);
- }
- return bSuccess;
- }
- void Clip_pausePlayback(UINT16 hInstance, BOOL bEnable)
- {
- Clip *pThis= _Clip_fromInstance(hInstance);
- ASSERT(NULL != pThis)
- (*(pThis->m_pConstAttr->m_vtable).m_pfPause)(pThis, bEnable);
- if ((pThis->m_presentationInfo).bModified) {
- (pThis->m_presentationInfo).bModified= FALSE;
- _ClipsRepository_commit(hInstance, pThis);
- }
- return;
- }
- enClipStatus Clip_getStatus(UINT16 hInstance)
- {
- const Clip *pThis= _Clip_fromInstance(hInstance);
- ASSERT(NULL != pThis)
- return (*(pThis->m_pConstAttr->m_vtable).m_pfGetStatus)(pThis);
- }
- void Clip_abortPlayback(UINT16 hInstance, BOOL bMaintainStandby)
- {
- Clip *pThis= _Clip_fromInstance(hInstance);
- ASSERT(NULL != pThis)
- (*(pThis->m_pConstAttr->m_vtable).m_pfAbort)(pThis, bMaintainStandby);
- if ((pThis->m_presentationInfo).bModified) {
- (pThis->m_presentationInfo).bModified= FALSE;
- _ClipsRepository_commit(hInstance, pThis);
- }
- return;
- }
- void Clip_recordMarker(UINT16 hInstance, ClipMarker *o_pMarker)
- {
- const Clip *pThis= _Clip_fromInstance(hInstance);
- ASSERT(NULL != pThis)
- (*(pThis->m_pConstAttr->m_vtable).m_pfRecordMarker)(pThis, o_pMarker);
- return;
- }
- void Clip_refresh(UINT16 hInstance)
- {
- Clip *pThis= _Clip_fromInstance(hInstance);
- ASSERT(NULL != pThis)
- (*(pThis->m_pConstAttr->m_vtable).m_pfRefresh)(pThis);
- if ((pThis->m_presentationInfo).bModified) {
- (pThis->m_presentationInfo).bModified= FALSE;
- _ClipsRepository_commit(hInstance, pThis);
- }
- return;
- }
- UINT16 Clip_getTime(UINT16 hInstance)
- {
- const Clip *pThis= _Clip_fromInstance(hInstance);
- ASSERT(NULL != pThis)
- return (*(pThis->m_pConstAttr->m_vtable).m_pfGetTime)(pThis);
- }
- void Clip_digest(UINT16 hInstance)
- {
- Clip *pThis= _Clip_fromInstance(hInstance);
- ASSERT(NULL != pThis)
- (*(pThis->m_pConstAttr->m_vtable).m_pfDigest)(pThis);
- if ((pThis->m_presentationInfo).bModified) {
- (pThis->m_presentationInfo).bModified= FALSE;
- _ClipsRepository_commit(hInstance, pThis);
- }
- return;
- }
- void Clip_Scan(UINT16 hInstance, int iScanSpeed)
- {
- Clip *pThis = _Clip_fromInstance(hInstance);
- ASSERT(NULL != pThis )
- return (*(pThis->m_pConstAttr->m_vtable).m_pfClipScan)(pThis, iScanSpeed);
- }