raformat.h
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:10k
- /* ***** BEGIN LICENSE BLOCK *****
- * Version: RCSL 1.0/RPSL 1.0
- *
- * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved.
- *
- * The contents of this file, and the files included with this file, are
- * subject to the current version of the RealNetworks Public Source License
- * Version 1.0 (the "RPSL") available at
- * http://www.helixcommunity.org/content/rpsl unless you have licensed
- * the file under the RealNetworks Community Source License Version 1.0
- * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl,
- * in which case the RCSL will apply. You may also obtain the license terms
- * directly from RealNetworks. You may not use this file except in
- * compliance with the RPSL or, if you have a valid RCSL with RealNetworks
- * applicable to this file, the RCSL. Please see the applicable RPSL or
- * RCSL for the rights, obligations and limitations governing use of the
- * contents of the file.
- *
- * This file is part of the Helix DNA Technology. RealNetworks is the
- * developer of the Original Code and owns the copyrights in the portions
- * it created.
- *
- * This file, and the files included with this file, is distributed and made
- * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
- * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES,
- * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
- * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
- *
- * Technology Compatibility Kit Test Suite(s) Location:
- * http://www.helixcommunity.org/content/tck
- *
- * Contributor(s):
- *
- * ***** END LICENSE BLOCK ***** */
- #ifndef _RAFORMAT_H_
- #define _RAFORMAT_H_
- /****************************************************************************
- * Includes
- */
- #include "netbyte.h"
- #include "hxtypes.h"
- #include "hxresult.h"
- #include "hxcom.h"
- #include "hxtick.h"
- #include "hxbuffer.h"
- #include "hxstring.h"
- #include "hxcodec.h"
- #include "hxcomm.h"
- #include "hxausvc.h"
- #include "ihxpckts.h"
- #include "hxmon.h"
- #include "hxerror.h"
- #include "hxengin.h"
- #include "raparser.h"
- #include "cinterl.h"
- #include "codec.h"
- #include "hxcore.h"
- #include "hxupgrd.h"
- #include "hxslist.h"
- #include "raformat.h"
- #include "rmfftype.h"
- #include "hxassert.h"
- #include "hxheap.h"
- #include "errdbg.h"
- /****************************************************************************
- * Defines
- */
- #define RA_FORMAT_ID RA_FILE_MAGIC_NUMBER // = { '.', 'r', 'a', 'xFD' };
- #define RA_SWITCH_FORMAT_ID 0x2E5241FDL // = { '.', 'R', 'A', 'xFD' }
- #define RA_TIME_FUDGE 5
- #ifdef _RAFLOW_LOG
- #define RA_FLOW_FILE "C:\raflow.txt"
- #else // _RAFLOW_LOG
- #define RA_FLOW_FILE NULL
- #endif // _RAFLOW_LOG
- #define MAX_TS_DBG_RANGE 10000
- enum AUDIO_STATE
- {
- AUDIO_NORMAL,
- AUDIO_CROSSFADE,
- AUDIO_DRYNOTIFICATION,
- AUDIO_END_OF_PACKETS
- };
- class CRealAudioPacketFeeder;
- class CInterleave;
- class CCodec;
- struct IHXCommonClassFactory;
- struct IHXPlayer;
- #include "raibufs.h"
- /////////////////////////////////////////////////////////////////////////////
- //
- // Class:
- //
- // CRaFormat
- //
- // Purpose:
- //
- // Implementation of a RealAudio File Format reader.
- //
- _INTERFACE IHXRealAudioSync;
- _INTERFACE IHXErrorMessages;
- #define INCREMENT_FLOAT_TS(x, y) {
- (x) += (y);
- if ((x) > 4294967295.0)
- {
- (x) -= 4294967296.0;
- if ((x) < 0.0)
- {
- (x) = 0.0;
- }
- }
- }
- class CRaFormat
- {
- public:
- // former SUBSTREAM_PROPS structure members
- UINT32 m_ulLastPacketTime;
- UINT32 m_ulBytesWrite;
- IHXRealAudioSync* m_pAudioSync;
- BOOL m_bRegistered;
- CRaFormat(IUnknown* m_pContext,
- IHXCommonClassFactory* pCommonClassFactory,
- IHXErrorMessages* pErrorMessages,
- UINT16* pRuleToFlagMap,
- UINT16 uStreamNumber);
- virtual ~CRaFormat();
- HX_RESULT NewReadRAHeader (Byte* buffer,
- UINT32 ulLength,
- BOOL bForceStartTrackTime,
- BOOL bForceEndTrackTime,
- UINT32 ulTrackStartTime,
- UINT32 ulTrackEndTime,
- UINT32* pBytesRead,
- char* pAllCodecs,
- UINT32 ulAllCodecsBufLen);
- HX_RESULT OnPacket(IHXPacket* pPacket, LONG32 lTimeOffset, UINT16* rule_to_flag_map);
- HX_RESULT OnSeek(UINT32 ulOldTime, UINT32 ulNewTime);
- HX_RESULT GetAudioData(HXAudioData& audioData, // out
- UINT32& ulActualTimestamp, // out
- AUDIO_STATE audioState, // in
- UINT32 ulSpliceToActualTime, // in
- UINT32 ulSpliceToStreamTime); // in
- HX_RESULT GenerateLostAudioData (UINT32 ulForceEndTime,
- HXAudioData& audioData,
- UINT32& ulActualTimestamp,
- UINT32 ulSpliceToActualTime,
- UINT32 ulSpliceToStreamTime);
- #if defined(HELIX_FEATURE_STATS)
- HX_RESULT UpdateStatistics(IHXRegistry* pRegistry, UINT32 ulRegistryID,
- UINT32& ulCodecRegID, UINT32& ulCodecTextRegID, UINT32& ulCodec4CCRegID,
- UINT32& ulRateRegID, UINT32& ulChannelsRegID, UINT32& ulSurroundRegID);
- #endif // HELIX_FEATURE_STATS
- HX_RESULT UpdatePacketTimeOffset(INT32 lTimeOffset);
- HX_RESULT UpdatePlayTimes(IHXValues* pProps);
- BOOL IsStreamDone(void);
- BOOL IsActive();
- void SetupForNextTimeRange();
-
- void GetAudioFormat(HXAudioFormat& audioFmt);
- #if defined(HELIX_FEATURE_SETSRCPROPS)
- BOOL IsInterleaved() { return (m_StreamParam.IsInterleaved ? TRUE : FALSE); }
- UINT32 GetBitRate() { return m_StreamParam.ulBytesPerMin * 8 / 60; }
- UINT32 GetSamplesPerSecond() { return m_StreamParam.ulSampleRate; }
- UINT32 GetBitsPerSample() { return (UINT32) m_StreamParam.uSampleSize; }
- UINT32 GetNumChannels() { return (UINT32) m_StreamParam.uChannels; }
- #endif /* #if defined(HELIX_FEATURE_SETSRCPROPS) */
- char* GetCodecName() { return m_StreamParam.codecID; }
- char* GetInterleaverName() { return m_StreamParam.interleaverID; }
- void OnEndofPackets(void);
- void LossOccured(void);
- double ConvertBytesToMs(UINT32 ulBytes);
- BOOL ClipAudioBuffer(HXAudioData* pAudioData,
- UINT32& ulActualTime,
- UINT32 ulAudioTime,
- BOOL bFromStart);
- void OverrideFactory(IHXCommonClassFactory* pCommonClassFactory);
- void SetCrossFadeEndTime(UINT32 ulTimestamp);
- void DiscardTillEndOfCrossFade(UINT32 ulTimestamp);
- HX_RESULT GetNextAudioDataTime(UINT32& ulStart, UINT32& ulEnd);
- UINT32 GetCurrentTimeRangeEnd();
- void ThrowUpgrade(const char* pszStr);
-
- inline UINT16 GetInterleaveFactor()
- { return m_StreamParam.uInterleaveFactor;}
- inline UINT32 GetSuperBlockTime()
- { return m_IBufs.GetSuperBlockTime();}
- inline double GetMSPerBlock()
- {return m_IBufs.GetMSPerBlock();}
- inline void ForceInterleaved(BOOL bIsInterleaved)
- {
- m_bForceInterleaved = TRUE;
- m_StreamParam.IsInterleaved = bIsInterleaved;
- };
- inline void SetProtocolInfo(BOOL bIsPNM, INT32 lProtocolVersion)
- {
- if (bIsPNM && lProtocolVersion < 10)
- {
- m_IBufs.SetTimeStampsInTenths(TRUE);
- }
- }
- protected:
- // packet loss treatment
- virtual CRealAudioPacketFeeder* CreatePacketFeeder(void);
- // decoding
- HX_RESULT InitDecoder(CStreamParam& param, CCodec** pCodec);
- HX_RESULT DecodeAudioData(HXAudioData& audioData,
- UINT32& ulActualTimestamp,
- ULONG32 ulSpliceToActualTime,
- ULONG32 ulSpliceToStreamTime,
- BOOL bFlushCodec = FALSE);
- virtual CCodec* CreateDecoder(char* pCodecID);
- virtual HX_RESULT DecodeAudioBlock(Byte* pData,
- UINT32 ulInSize,
- Byte* pAudioBuf,
- UINT32* pOutSize,
- UINT32 ulDataFlags);
- // adjust offset
- UINT32 ConvertMsToBytes(UINT32 ulMs);
- BOOL GetDropBlock(UINT32 ulAudioTime);
- void SpliceAudioData(HXAudioData &pAudioData,
- UINT32 &ulActualTimestamp,
- UINT32 ulSpliceToActualTime,
- UINT32 ulSpliceToStreamTime);
- BOOL AdjustAudioData(HXAudioData &audioData,
- UINT32& ulActualTimestamp,
- UINT32 ulTrackEndTime = NO_TIME_SET);
- BOOL ClipAudioData(HXAudioData &audioData,
- UINT32 &ulActualTimestamp,
- UINT32 ulDurationToClip,
- BOOL bFromFront);
-
- HX_RESULT LoadDecoderAndInitDeInterleaver();
- BOOL ClipAndAdjust(INT32 lExtraInMs,
- HXAudioData& audioData,
- UINT32& ulActualTimestamp,
- BOOL bFromFront,
- UINT32& ulDuration,
- UINT32& ulSize);
- IHXCommonClassFactory* m_pCommonClassFactory;
- IHXCommonClassFactory* m_pCachingClassFactory;
- IHXUpgradeCollection* m_pUpgradeCollection;
- IHXErrorMessages* m_pErrorMessages;
- IUnknown* m_pContext;
- UINT16* m_pRuleToFlagMap;
- CRealAudioPacketFeeder* m_pPacketFeeder;
- CCodec* m_pCodec;
- UINT32 m_ulAudioBufSize; //
- UINT32 m_ulNextAudioTime;
- UINT32 m_ulNextActualAudioTime;
- INT32 m_lTimeOffset;
- UINT32 m_ulTrackStartTime;
- UINT32 m_ulTrackEndTime;
- UINT32 m_ulForceDiscardUntilTime;
- UINT32 m_ulMaxBlockGap;
- UINT32 m_ulMinExpectedDecodedBlockSize;
- UINT32 m_ulCodecDelay;
- double m_fCodecDelay;
- BOOL m_bPCMStreamStart;
- UINT32 m_ulCrossFadeEndTime;
- CStreamParam m_StreamParam;
- CInterleaveBufs m_IBufs;
- HX_BITFIELD m_bForceInterleaved:1;
- HX_BITFIELD m_bFirstPacket:1;
- HX_BITFIELD m_bDeterminedAdjustment:1;
- HX_BITFIELD m_bForceStartTrackTime:1;
- HX_BITFIELD m_bForceEndTrackTime:1;
- HX_BITFIELD m_bAdjustTimestamps:1;
- HX_BITFIELD m_bEndOfPackets:1;
- BOOL m_bSecure;
-
- UINT16 m_uStreamNumber;
- BOOL m_bIsVBR;
- };
- #endif // ndef _RAFORMAT_H_