OGG.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:13k
- //Sean_1213_2004
- /****************************************************************************************
- * Copyright (c) 2000 ZORAN Corporation, All Rights Reserved
- * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF ZORAN CORPORATION
- *
- * File: $Workfile: OGG.c $
- *
- * Description:
- * ============
- * OGG Clip implementation
- *
- * Log:
- * ====
- ****************************************************************************************
- * Updates:
- ****************************************************************************************
- * 2004/09/05 : created by SeanLiu to support Vorbis OGG bitstream.
- *
- ****************************************************************************************/
- #include "Config.h" // Global Configuration - do not remove!
- #ifdef IS_OGG_VORBIS_CAPABLE
- #ifdef _DEBUG
- #undef IFTRACE
- #define IFTRACE if (gTraceNavigator)
- #include "DebugDbgMain.h"
- #endif
- #include "Includemath-macro.h"
- //#include "KernelEventDef.H"
- #include "DecoderDecoder.h"
- #include "DecoderDec_defs.h"
- #include "Decoderlow_levelDEC_LL_Def.h"
- #include "Drivedrv_api.h"
- #include "Drivedrv_defs.h"
- #include "LogoLogo.h"
- #include "PlaycoreCoremainCoreGDef.h"
- #include "PlaycoreAuxCacheAuxCache.h"
- #include "PlaycoreFileSysFileSystem.h"
- #include "PlaycoreNav_ClipsOGG.h"
- #include "PlaycoreNav_ClipsClip_Impl.h"
- #include "PlaycoreNav_ClipsGenericClip.h"
- #include "PlaycoreNav_ClipsNav_Clips.h"
- #include "PlaycoreNav_ClipsPE_Clips.h"
- #define bOGGUnsupported gns.clips.globals.oggGlobals.bOGGUnsupported
- static BOOL OGG_SearchVorbisPacket(DWORD start_address, DWORD *offset, DWORD lengh,BYTE packet_type);
- /////////////////////////////////////////////////////////////////////////////
- // General OGG
- /////////////////////////////////////////////////////////////////////////////
- static BOOL OGG_SearchVorbisPacket(DWORD start_address, DWORD *offset, DWORD lengh,BYTE packet_type)
- {
- BYTE ObjectBuff[OGG_HEADER_TAG_SIZE+1];
- BYTE NextByte;
- UINT16 i;
-
- if ( !AuxCache_GetBytes(start_address, *offset, OGG_HEADER_TAG_SIZE, ObjectBuff) )
- {
- dbg_printf(("WARNING: OGG_GetOGGInfo() Failed [1]n"));
- return FALSE;
- }
- *offset += OGG_HEADER_TAG_SIZE;
- while(*offset < lengh)
- {
- (*offset)++;
- if((!memcmp((ObjectBuff+1), OGG_HEADER_TAG,OGG_HEADER_TAG_SIZE)) && (ObjectBuff[0] == packet_type))
- {
- return TRUE;
- }
- if ( !AuxCache_GetBytes(start_address, *offset, 1, &NextByte))
- {
- dbg_printf(("WARNING: OGG_GetOGGInfo() Failed [3]n"));
- return FALSE;
- }
- for(i=0; i<OGG_HEADER_TAG_SIZE; i++)
- {
- ObjectBuff[i] = ObjectBuff[i+1];
- }
-
- ObjectBuff[i] = NextByte;
- }
- return FALSE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // Public Services
- #pragma argsused
- void OGG_setPresentationTime(UINT8 uPresentationTime)
- {
- dbg_printf(("WARNING: OGG_setPresentationTime() Failed: OGG Clips cannot have a presentation time.n"));
- }
- BOOL OGG_GetOGGInfo(DWORD dwClipStartAddr,WORD i_pExtInfo_sc_handle)
- {
- DWORD cbOffset=0;
- VORBIS_OGG_IDENTIFICATION_HEADER OGG_identification_header;
- UINT16 i;
- bOGGUnsupported = TRUE;
- if(!OGG_SearchVorbisPacket(dwClipStartAddr, &cbOffset, 58,OGG_PACKET_TYPE_IDENTIFICATION))
- {
- return FALSE;
- }
- if ( !AuxCache_GetBytes(dwClipStartAddr, cbOffset, sizeof(VORBIS_OGG_IDENTIFICATION_HEADER), &OGG_identification_header))
- {
- dbg_printf(("WARNING: OGG_GetOGGInfo() Failed [2]n"));
- return FALSE;
- }
- gns.clips.iClipSamplingRate = OGG_identification_header.audio_sample_rate;
- if(((OGG_identification_header.audio_sample_rate != 48000) && (OGG_identification_header.audio_sample_rate != 32000)
- && (OGG_identification_header.audio_sample_rate != 44100) && (OGG_identification_header.audio_sample_rate != 24000)
- && (OGG_identification_header.audio_sample_rate != 16000) && (OGG_identification_header.audio_sample_rate != 22050))
- || ((OGG_identification_header.audio_channels != 1) && (OGG_identification_header.audio_channels != 2))
- )
- {
- return FALSE;
- }
-
- bOGGUnsupported = FALSE;
-
- #if (defined(CLIPS_ACQUIRE_EXTENDED_INFO) && defined(CLIPS_OGG_EXTRACT_INFO))
- ASSERT(NULL != i_pExtInfo_sc_handle);
- cbOffset = 58;
- if(OGG_SearchVorbisPacket(dwClipStartAddr, &cbOffset, 128,OGG_PACKET_TYPE_COMMENT))
- {
- UINT32 vendor_length;
- UINT32 user_comment_list_length;
- UINT32 length;
- UINT8 comment[OGG_TEXT_LENGTH+VORBIS_COMMENT_MAX_LEN];
- OGG_ExtendInfo ogg_extend_info;
- UINT32 i;
- memset(&ogg_extend_info,0,sizeof(OGG_ExtendInfo));
-
- if ( !AuxCache_GetBytes(dwClipStartAddr, cbOffset, sizeof(UINT32), &vendor_length))
- {
- dbg_printf(("WARNING: OGG_GetOGGInfo() Failed [2]n"));
- return TRUE;
- }
- cbOffset = cbOffset + 4 + vendor_length;
-
- if ( !AuxCache_GetBytes(dwClipStartAddr, cbOffset, sizeof(UINT32), &user_comment_list_length))
- {
- dbg_printf(("WARNING: OGG_GetOGGInfo() Failed [2]n"));
- return TRUE;
- }
- cbOffset +=4;
- for(i=0;i<user_comment_list_length;i++)
- {
- if ( !AuxCache_GetBytes(dwClipStartAddr, cbOffset, sizeof(UINT32), &length))
- {
- dbg_printf(("WARNING: OGG_GetOGGInfo() Failed [2]n"));
- return TRUE;
- }
- cbOffset +=4;
- if ( !AuxCache_GetBytes(dwClipStartAddr, cbOffset, GET_MINIMUM(length,(OGG_TEXT_LENGTH+VORBIS_COMMENT_MAX_LEN)), comment))
- {
- dbg_printf(("WARNING: OGG_GetOGGInfo() Failed [2]n"));
- return TRUE;
- }
- cbOffset +=length;
- //TODO: deal with multiple case later.
- if(!memcmp(comment, VORBIS_COMMENT_TITLE_TAG,VORBIS_COMMENT_TITLE_LEN))
- {
- memcpy(ogg_extend_info.szTitle,(comment+VORBIS_COMMENT_TITLE_LEN),GET_MINIMUM(length,OGG_TEXT_LENGTH));
- }
- else
- if(!memcmp(comment, VORBIS_COMMENT_ALBUM_TAG,VORBIS_COMMENT_ALBUM_LEN))
- {
- memcpy(ogg_extend_info.szAlbum,(comment+VORBIS_COMMENT_ALBUM_LEN),GET_MINIMUM(length,OGG_TEXT_LENGTH));
- }
- else
- if(!memcmp(comment, VORBIS_COMMENT_ARTIST_TAG,VORBIS_COMMENT_ARTIST_LEN))
- {
- memcpy(ogg_extend_info.szArtist,(comment+VORBIS_COMMENT_ARTIST_LEN),GET_MINIMUM(length,OGG_TEXT_LENGTH));
- }
- else
- if(!memcmp(comment, VORBIS_COMMENT_COPYRIGHT_TAG,VORBIS_COMMENT_COPYRIGHT_LEN))
- {
- memcpy(ogg_extend_info.szCopyright,(comment+VORBIS_COMMENT_COPYRIGHT_LEN),GET_MINIMUM(length,OGG_TEXT_LENGTH));
- }
- else
- if(!memcmp(comment, VORBIS_COMMENT_DESCRIPTION_TAG,VORBIS_COMMENT_DESCRIPTION_LEN))
- {
- memcpy(ogg_extend_info.szDescription,(comment+VORBIS_COMMENT_DESCRIPTION_LEN),GET_MINIMUM(length,OGG_TEXT_LENGTH));
- }
- else
- if(!memcmp(comment, VORBIS_COMMENT_GENRE_TAG,VORBIS_COMMENT_GENRE_LEN))
- {
- memcpy(ogg_extend_info.szGenre,(comment+VORBIS_COMMENT_GENRE_LEN),GET_MINIMUM(length,OGG_TEXT_LENGTH));
- }
- }
- sc_SetBytes(i_pExtInfo_sc_handle,0,sizeof(OGG_ExtendInfo),(BYTE *)&ogg_extend_info);
- }
- #endif //CLIPS_OGG_EXTRACT_INFO
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // OGG Clip
- /////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////
- // Forward Declarations of Virtual Methods
- BOOL OGGClip_getExtendedInfo(const struct Clip_TAG *i_pThis, WORD i_pExtInfo_sc_handle);
- BOOL OGGClip_play(Clip *i_pThis, const ClipMarker *i_pResumeMarker,BOOL bCacheOnly);
- enClipStatus OGGClip_getStatus(const Clip *i_pThis);
- void OGGClip_refresh(Clip *i_pThis);
- UINT16 OGGClip_getTime(const Clip *i_pThis);
- void OGGClip_recordMarker(const Clip *i_pThis, ClipMarker *o_pMarker);
- /////////////////////////////////////////////////////////////////////////////
- // Const Factory
- // Valid Extenions List
- BEGIN_CLIP_VALID_EXTENSIONS_MAP(OGG)
- CLIP_VALID_EXTENSIONS_ENTRY(L"OGG")
- END_CLIP_VALID_EXTENSIONS_MAP()
- // Constant Attributes
- DECLARE_CLIP_CONST_ATTR(OGG,
- DECLARE_CLIP_VTABLE(OGGClip_getExtendedInfo,
- OGGClip_play,
- GenericClip_pause,
- OGGClip_getStatus,
- GenericClip_abort,
- OGGClip_recordMarker,
- OGGClip_refresh,
- OGGClip_getTime,
- GenericClip_digest,
- GenericClip_scan
- ),
- eClipType_OGG,
- DEC_ASID_OGG, 0xFF, DEC_DISC_TYPE_OGG,
- eCA_Markable,
- NULL
- )
- /////////////////////////////////////////////////////////////////////////////
- // Public Services
- BOOL OGGClip_isKindOf(LPCWSTR i_pszFilename)
- {
- return GenericClip_isKindOf(i_pszFilename, CLIP_VALID_EXTENSIONS(OGG));
- }
- void OGGClip_construct(Clip *o_pThis, const FindData *i_pFileInfo)
- {
- GenericClip_construct(o_pThis, i_pFileInfo);
- o_pThis->m_pConstAttr= &CLIP_CONST_ATTR(OGG);
- }
- /////////////////////////////////////////////////////////////////////////////
- // Virtual Methods
- BOOL OGGClip_getExtendedInfo(const struct Clip_TAG *i_pThis, WORD i_pExtInfo_sc_handle)
- {
- dbg_printf(("OGGClip_getExtendedInfo()n"));
- return OGG_GetOGGInfo(i_pThis->m_cfiInfo.dwFileLocation, i_pExtInfo_sc_handle);
- }
- BOOL OGGClip_play(Clip *i_pThis, const ClipMarker *i_pResumeMarker, BOOL bCacheOnly)
- {
- //don't use GenericClip_play now for AC3 clips debug
- //return GenericClip_play(i_pThis, i_pResumeMarker, bCacheOnly);
- DWORD dwStartLBA;
- ULONG ulBlocksCnt;
- ULONG cbPlaybackLength;
- dbg_printf(("OGG_play()n"));
- // Cached-playback is unsupported by default
- if (bCacheOnly)
- return FALSE;
- drv_abort_play();
-
- // Kill any existing Zoom
- DEC_SetZoomScale(NO_ZOOM);
- // Configure the Decoder to the appropriate Bitstream Type
- DEC_SetDiskType((i_pThis->m_pConstAttr)->m_eBitstreamType);
- // Prepare for decoding
- DEC_prepare_to_decode();
- DEC_SetSID(DEC_SID_TYPE_AUDIO, OGG_SID);
- DEC_SetSID(DEC_SID_TYPE_VIDEO, (i_pThis->m_pConstAttr)->m_eVideoSID);
- // Select the appropriate Clock
- PE_Clips_SelectClock(eCT_Internal);
- // Calculate the Playback Start-Address
- if (NULL == i_pResumeMarker)
- {
- // Start at the beginning
- dwStartLBA= (i_pThis->m_cfiInfo).dwFileLocation;
-
- }
- else
- {
- // Playback is being resumed
- dwStartLBA= i_pResumeMarker->dwAddress;
- }
- // Calculate the Playback Length (in Bytes)
- cbPlaybackLength= ( (i_pThis->m_cfiInfo).cbFileSize - (LOGICAL_BLOCK_SIZE * (dwStartLBA - (i_pThis->m_cfiInfo).dwFileLocation)) );
-
- ulBlocksCnt= ((cbPlaybackLength + LOGICAL_BLOCK_SIZE - 1) / LOGICAL_BLOCK_SIZE);
- // Inform the Decoder of the Playback-Range
- PE_Clips_SetPlaybackRange(dwStartLBA, ulBlocksCnt, cbPlaybackLength/2);
- // Invoke playback of the Decoder & Drive
- // NOTE: The order of invocation is important, and must not be changed!
- DEC_PlaybackCommand(DEC_PLAYBACK_CMD_PLAY, NULL);
- if (!PE_Clips_Playback_Sectors(DRVCF_CDSPEED_1X | DRVF_PLAY_CD_AV_DATA, dwStartLBA, ulBlocksCnt))
- {
- tr_printf(("WARNING: OGG_play() Failed [1]n"));
- return FALSE;
- }
- // Restart the Clock
- PE_Clips_EnableClock(TRUE, TRUE,(NULL != i_pResumeMarker) ? i_pResumeMarker->uTime : 0);
- return TRUE;
- }
- #pragma argsused
- enClipStatus OGGClip_getStatus(const Clip *i_pThis)
- {
- #if 0
- if( bOGGUnsupported )
- {
- bOGGUnsupported = FALSE;
- return eCS_Error_UnsupportedFormat;
- }
- if (drv_is_play_done() && DEC_IsPlaybackFinished(FALSE))
- {
- return eCS_Finished;
- }
- switch(DEC_OGG_getStatus())
- {
- case OGG_STAT_DECODING_ERROR :
- tr_printf(("OGGClip_getStatus: eCS_Error_Decodingn"));
- return eCS_Error_Decoding;
- case OGG_STAT_FINISHED :
- return eCS_Finished;
- }
- return eCS_Busy;
- #else
- static UINT16 CurrentClipNumber = 0;
- static BOOL msg_is_sent = FALSE;
-
- if( bOGGUnsupported )
- {
- bOGGUnsupported = FALSE;
- return eCS_Error_UnsupportedFormat;
- }
- if(gns.clips.uCurrentClipNumber != CurrentClipNumber)
- {
- msg_is_sent = FALSE;
- CurrentClipNumber = gns.clips.uCurrentClipNumber;
- }
-
- if(drv_is_play_done() && DEC_IsPlaybackFinished(FALSE))
- {
- if(!msg_is_sent)
- {
- msg_is_sent = TRUE;
- return eCS_Finished;
- }
- else
- {
- return eCS_Busy;
- }
- }
- switch(DEC_OGG_getStatus())
- {
- case OGG_STAT_DECODING_ERROR :
- tr_printf(("OGGClip_getStatus: eCS_Error_Decodingn"));
- return eCS_Error_Decoding;
- case OGG_STAT_FINISHED :
- return eCS_Finished;
- }
- return eCS_Busy;
-
- #endif
- }
- #pragma argsused
- void OGGClip_refresh(Clip *i_pThis)
- {
- if (PST_PLAY == gcs.pstate)
- {
- BOOL bEnableClock= (0 != DEC_ReadCodeBufferFullness(DEC_AUDIO_CODE_BUFFER, DEC_FULLNESS_IN_BYTES));
- PE_Clips_EnableClock(bEnableClock, FALSE, 0);
- }
- }
- UINT16 OGGClip_getTime(const Clip *i_pThis)
- {
- return PE_Clips_GetClock();
- }
- void OGGClip_recordMarker(const Clip *i_pThis, ClipMarker *o_pMarker)
- {
- o_pMarker->dwAddress= PE_Clips_GetCurrLocation();
- o_pMarker->uTime= GenericClip_getTime(i_pThis);
- o_pMarker->uClipNumer = gns.clips.uCurrentClipNumber;
- return;
- }
- #endif //IS_OGG_VORBIS_CAPABLE
- //<<<Sean_1213_2004