mp4desc.cpp
来自「symbian 下的helix player源代码」· C++ 代码 · 共 802 行 · 第 1/2 页
CPP
802 行
/* ***** 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 ***** */
/****************************************************************************
* Defines
*/
#define _ATTEMPT_ALTERNATE_PARSING_MODES
#define _ATTEMPT_PREOCR_SYNTAX
#define _ALLOW_SHORT_SLCONFIG
#define _SHORTCUT_ON_DECCONFIG
/****************************************************************************
* Includes
*/
#include "mp4desc.h"
#include "netbyte.h"
/****************************************************************************
* Statics
*/
inline static int swapEndian(UCHAR* pInOut, UINT32 ulLen)
{
UINT32 i = 0, j = 0;
UCHAR c;
for (j = ulLen-1; i < ulLen/2; ++i, --j)
{
c = pInOut[i];
pInOut[i] = pInOut[j];
pInOut[j] = c;
}
return 0;
}
inline static ULONG32 GetUL32(UINT8 *pData)
{
return (*pData << 24) |
(*(pData + 1) << 16) |
(*(pData + 2) << 8 ) |
*(pData + 3);
}
inline static UINT16 GetUI16(UINT8 *pData)
{
return (*pData << 8) |
*(pData + 1);
}
inline static ULONG32 GetUI24(UINT8 *pData)
{
return (*pData << 16) |
(*(pData + 1) << 8) |
*(pData + 2);
}
inline static ULONG32 RoundUp(double x)
{
ULONG32 rx = (ULONG32) x;
if (rx != x)
{
rx++;
}
return rx;
}
/****************************************************************************
* MP4BaseDescriptor
*/
/****************************************************************************
* Public functions
*/
MP4BaseDescriptor::DescType MP4BaseDescriptor::GetDescType(UINT8 uTag)
{
DescType eDescType = DTYP_UNKNOWN;
if (uTag == 0x03)
{
eDescType = DTYP_ESTREAM;
}
else if (uTag == 0x04)
{
eDescType = DTYP_DECODER_CONFIG;
}
else if (uTag == 0x05)
{
eDescType = DTYP_DECODER_INFO_SHORT;
}
else if (uTag == 0x06)
{
eDescType = DTYP_SL_CONFIG;
}
return eDescType;
}
/****************************************************************************
* Protected functions
*/
UINT8 MP4BaseDescriptor::GetTag(UINT8* &pData,
ULONG32 &ulDataSize,
BOOL bAdvance)
{
UINT8 uTag;
ULONG32 ulTagSize = 0;
uTag = pData[ulTagSize];
ulTagSize++;
if (bAdvance)
{
pData += ulTagSize;
ulDataSize -= ulTagSize;
}
return uTag;
}
ULONG32 MP4BaseDescriptor::GetSize(UINT8* &pData,
ULONG32 &ulDataSize,
BOOL bAdvance)
{
ULONG32 ulSize = 0;
ULONG32 ulFieldSize = 0;
while (ulDataSize > ulFieldSize)
{
ulSize = (ulSize << 7);
ulSize += (pData[ulFieldSize] & 0x7f);
if ((pData[ulFieldSize] & 0x80) == 0)
{
ulFieldSize++;
break;
}
ulFieldSize++;
}
if (bAdvance)
{
pData += ulFieldSize;
ulDataSize -= ulFieldSize;
}
return ulSize;
}
/****************************************************************************
* SLConfigPredefined
*/
/****************************************************************************
* Constructor/Destructor
*/
/****************************************************************************
* Public functions
*/
HX_RESULT SLConfigPredefined::Unpack(UINT8* &pData,
ULONG32 &ulSize,
ULONG32 ulFlags)
{
LD bitInfo;
HX_RESULT retVal = HXR_INVALID_PARAMETER;
if (ulSize >= 14)
{
retVal = HXR_OK;
initbuffer(pData, &bitInfo);
m_bUseAccessUnitStartFlag = getbits1(&bitInfo);
m_bUseAccessUnitEndFlag = getbits1(&bitInfo);
m_bUseRandomAccessPointFlag = getbits1(&bitInfo);
m_bUsePaddingFlag = getbits1(&bitInfo);
m_bUseTimeStampsFlag = getbits1(&bitInfo);
m_bUseWallClockTimeStampFlag = getbits1(&bitInfo);
m_bUseIdleFlag = getbits1(&bitInfo);
m_bDurationFlag = getbits1(&bitInfo);
pData++;
m_ulTimeStampResolution = GetUL32(pData);
pData += 4;
m_ulOCRResolution = GetUL32(pData);
pData += 4;
m_uTimeStampLength = *(pData++);
m_uOCRLength = *(pData++);
m_AU_Length = *(pData++);
m_uInstantBitrateLength = *(pData++);
initbuffer(pData, &bitInfo);
m_uDegradationPriorityLength = getbits(4, &bitInfo);
m_uSeqNumLength = getbits(4, &bitInfo);
pData++;
ulSize -= 14;
}
if ((retVal == HXR_OK) &&
m_bDurationFlag)
{
retVal = HXR_INVALID_PARAMETER;
if (ulSize >= 8)
{
m_ulTimeScale = GetUL32(pData);
pData += 4;
m_uAccessUnitDuration = GetUI16(pData);
pData += 2;
m_uCompositionUnitDuration = GetUI16(pData);
pData += 2;
ulSize -= 8;
}
}
if ((retVal == HXR_OK) &&
(!m_bUseTimeStampsFlag))
{
retVal = HXR_INVALID_PARAMETER;
ULONG32 ulSegmentSize = RoundUp(8.0 + m_uTimeStampLength / 4.0);
m_ullStartDecodingTimeStamp = 0;
m_ullStartCompositionTimeStamp = 0;
if ((m_uTimeStampLength < 64) &&
(ulSize >= ulSegmentSize) &&
(sizeof(double) == 8))
{
memcpy(&m_dWallClockTimeStamp, pData, 8); /* Flawfinder: ignore */
if (!TestBigEndian())
{
swapEndian((UINT8*) &m_dWallClockTimeStamp, 8);
}
// initialization of m_ullStartDecodingTimeStamp
// and m_ullStartCompositionTimeStamp needed
HX_ASSERT(HXR_OK == HXR_NOTIMPL);
pData += ulSegmentSize;
ulSize -= ulSegmentSize;
retVal = HXR_NOTIMPL;
}
}
return retVal;
}
/****************************************************************************
* SLConfigDescriptor
*/
/****************************************************************************
* Constructor/Destructor
*/
SLConfigDescriptor::SLConfigDescriptor(void)
: m_uLength(0)
, m_pPredefined(NULL)
, m_bOCRstreamFlag(FALSE)
{
;
}
SLConfigDescriptor::~SLConfigDescriptor()
{
HX_DELETE(m_pPredefined);
}
/****************************************************************************
* Public functions
*/
HX_RESULT SLConfigDescriptor::Unpack(UINT8* &pData,
ULONG32 &ulSize,
ULONG32 ulFlags)
{
HX_RESULT retVal = HXR_INVALID_PARAMETER;
if (ulSize >= 3)
{
m_uTag = GetTag(pData, ulSize, TRUE);
retVal = HXR_OK;
}
if (retVal == HXR_OK)
{
retVal = HXR_INVALID_PARAMETER;
if (ulSize >= 2)
{
m_uLength = (UINT8) GetSize(pData, ulSize, TRUE);
if (ulSize >= 1)
{
m_uPredefined = *(pData++);
ulSize--;
retVal = HXR_OK;
}
}
}
if ((retVal == HXR_OK) &&
(m_uPredefined == 0))
{
retVal = HXR_OUTOFMEMORY;
m_pPredefined = new SLConfigPredefined;
if (m_pPredefined)
{
retVal = m_pPredefined->Unpack(pData, ulSize);
}
}
if (retVal == HXR_OK)
{
#ifndef _ALLOW_SHORT_SLCONFIG
retVal = HXR_INVALID_PARAMETER;
#endif // _ALLOW_SHORT_SLCONFIG
if (ulSize >= 1)
{
m_bOCRstreamFlag = ((((*pData) >> 7) & 0x01) == 1);
m_uReserved = ((*(pData++)) & 0x7F);
ulSize--;
retVal = HXR_OK;
}
}
if ((retVal == HXR_OK) &&
(m_bOCRstreamFlag))
{
retVal = HXR_INVALID_PARAMETER;
if (ulSize >= 2)
{
m_OCR_ES_Id = GetUI16(pData);
pData += 2;
ulSize -= 2;
retVal = HXR_OK;
}
}
return retVal;
}
/****************************************************************************
* DecoderSpecifcInfo
*/
/****************************************************************************
* Constructor/Destructor
*/
DecoderSpecifcInfo::DecoderSpecifcInfo(void)
: m_ulLength(0)
, m_pData(NULL)
{
;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?