3gppttstructs.cpp

来自「symbian 下的helix player源代码」· C++ 代码 · 共 1,345 行 · 第 1/3 页

CPP
1,345
字号
/* ***** BEGIN LICENSE BLOCK ***** 
 * Version: RCSL 1.0/RPSL 1.0 
 *  
 * Portions Copyright (c) 1995-2003 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 ***** */ 

/****************************************************************************
 *  Includes
 */
#include <string.h> // /for memset, strncmp, stricmp
#include "hlxclib/memory.h" // /for memset, memcpy

#include "chxpckts.h" // /For IHXPacket
#include "hxwintyp.h" // /For HXxRect

#if defined(_SYMBIAN) // /                                                     -----vvvvvvvvvvvvvvvvvvvvvvvvvv-----
#include <utf.h>  // /For CnvUtfConverter::ConvertToUnicodeFromUtf8();
#endif // /_SYMBIAN                                                            _____^^^^^^^^^^^^^^^^^^^^^^^^^^_____

#include "3gppttstructs.h"
#include "3gppttutils.h"

#include "hxheap.h"
#ifdef _DEBUG
#undef HX_THIS_FILE
static const char HX_THIS_FILE[] = __FILE__;
#endif

// for DPRINTF
//#define INCLUDE_DPRINTF
#if(INCLUDE_DPRINTF)
#   include "debug.h"
#   define D_TIMEDTEXT D_INFO
#else
#   define DPRINTF(a,b)
#endif

HX_RESULT C3GPPTextboxBox::Build(const UINT8*& pData)
{
    DPRINTF(D_TIMEDTEXT, ("C3GPPTextboxBox::Build()\n"));
    m_top = ReadUI16(pData);
    m_left = ReadUI16(pData);
    m_bottom = ReadUI16(pData);
    m_right = ReadUI16(pData);
    return HXR_OK;
}


HX_RESULT C3GPPStyleRecord::Build(const UINT8*& pData)
{
    DPRINTF(D_TIMEDTEXT, ("C3GPPStyleRecord::Build()\n"));
    m_uiStartCharOffset = ReadUI16(pData);
    m_uiEndCharOffset = ReadUI16(pData);
    m_uiFontID = ReadUI16(pData);
    m_uFaceStyleFlags = *pData++;
    m_uFontSize = *pData++;
    m_textColor = ReadARGB(pData);
    return HXR_OK;
}

HX_RESULT C3GPPFontRecord::Build(const UINT8*& pData)
{
    DPRINTF(D_TIMEDTEXT, ("C3GPPFontRecord::Build()\n"));
    m_uiFontID = ReadUI16(pData);
    UINT8 cchFontName = *pData++;
    HX_RESULT hr = m_strFont.Set((const char*)pData, cchFontName);
    if(SUCCEEDED(hr))
    {
        pData += cchFontName;
    }

    return hr;
}

HX_RESULT C3GPPTextHyperTextBox::Build(const UINT8*& pData) 
{ 
    DPRINTF(D_TIMEDTEXT, ("C3GPPTextHyperTextBox::Build()\n"));
    m_uiStartCharOffset = ReadUI16(pData);
    m_uiEndCharOffset = ReadUI16(pData);
    UINT8 cchURL = *pData++;
 
    HX_RESULT hr = m_strURL.Set((const char*)pData, cchURL);
    if(SUCCEEDED(hr))
    {
        pData += cchURL;
        cchURL = *pData++;

        hr = m_strAltURL.Set((const char*)pData, cchURL);
        if(SUCCEEDED(hr))
        {
            pData += cchURL;
        }
    }

    return hr;
}


HX_RESULT C3GPPTextSampleEntry::Build(const UINT8*& pData)
{
    DPRINTF(D_TIMEDTEXT, ("C3GPPTextSampleEntry::Build()\n"));
    HX_RESULT hr = C3GPPArrayEntry::Build(pData);
    if(SUCCEEDED(hr))
    {
        m_ulDisplayFlags = ReadUL32(pData);
        m_horizontalJustification   = *pData++;
        m_verticalJustification     = *pData++;
        m_bgColor = ReadARGB(pData);

        hr = m_defaultTextBox.Build(pData);
        if(SUCCEEDED(hr))
        {
            hr = m_defaultStyle.Build(pData);
            if(SUCCEEDED(hr))
            {
                hr = m_fontTable.Build(pData);
            }
        }
    }

    return hr;
}

C3GPPTextSampleEntry::C3GPPTextSampleEntry()
: m_ulDisplayFlags(0)
, m_horizontalJustification(0)
, m_verticalJustification(0)
, m_bgColor(0)
{  
}



TextSampleScrollDirection
C3GPPTextSampleEntry::getScrollDirection() const
{
    TextSampleScrollDirection retval = scrollDirNone;

    if (hasScrollIn()  ||  hasScrollOut())
    {
        switch (m_ulDisplayFlags & HX_3GPPTT_DISPLAYFLAGS_SCROLL_DIR_MASK)
        {
            case HX_3GPPTT_DISPLAYFLAGS_SCROLL_DIR_UP:
                retval = scrollDirUp;
                break;
            case HX_3GPPTT_DISPLAYFLAGS_SCROLL_DIR_RTOL:
                retval = scrollDirRightToLeft;
                break;
            case HX_3GPPTT_DISPLAYFLAGS_SCROLL_DIR_DOWN:
                retval = scrollDirDown;
                break;
            case HX_3GPPTT_DISPLAYFLAGS_SCROLL_DIR_LTOR:
                retval = scrollDirLeftToRight;
                break;
            default:
                // /Should be one of the above:
                HX_ASSERT(m_ulDisplayFlags & HX_3GPPTT_DISPLAYFLAGS_SCROLL_DIR_MASK);
                retval = scrollDirNone;
                break;
        }
    }

    return retval;
}



C3GPPTextSampleModifierBox::ModifierType C3GPPTextSampleModifierBox::ReadType(const UINT8*& pData)
{
    const char* pchType = (const char*)pData;
    pData += 4;

    ModifierType type = UNKNOWN;

    if      (!strncmp(pchType, "styl", 4) )
    {
        type = STYL;
    }
    else if (!strncmp(pchType, "hlit", 4) )
    {
        type = HLIT;
    }
    else if (!strncmp(pchType, "hclr", 4) )
    {
        type = HCLR;
    }
    else if (!strncmp(pchType, "krok", 4) )
    {
        type = KROK;
    }
    else if (!strncmp(pchType, "dlay", 4) )
    {
        type = DLAY;
    }
    else if (!strncmp(pchType, "href", 4) )
    {
        type = HREF;
    }
    else if (!strncmp(pchType, "tbox", 4) )
    {
        type = TBOX;
    }
    else if (!strncmp(pchType, "blnk", 4) )
    {
        type = BLNK;
    }

    return type;
}

HX_RESULT C3GPPTextSample::Init(IHXBuffer* pIHXBuff)
{
    HX_ASSERT(pIHXBuff);
    m_pIHXBuff->AddRef();

    const UINT8* pPackedBuff  = m_pIHXBuff->GetBuffer();
    HX_ASSERT(pPackedBuff);

    UINT32 cbSampleTotal = m_pIHXBuff->GetSize();
    m_uiTextLengthInBytes = ReadUI16(pPackedBuff);

    UINT32 cbSampleTextBox = 2 + m_uiTextLengthInBytes; //size field + text

    HX_ASSERT(cbSampleTotal >= cbSampleTextBox);
    if (m_uiTextLengthInBytes && (cbSampleTotal > 2) )
    {
        // /NOTE: The spec says:
        //   "Authors should limit the string in each text sample to not more
        //    than 2048 bytes, for maximum terminal interoperability."
        // and it also says:
        //   "Any unrecognised box found in the text sample should be skipped
        //    and ignored, and processing continue as if it were not there."
        m_pText = (const char*) pPackedBuff;

        

        m_uiTextModifiersTotalSize = UINT16(cbSampleTotal - cbSampleTextBox);

        DPRINTF(D_TIMEDTEXT, ("C3GPPTextSample::Init(): %.*s;\n", 200, m_pText));

        if (m_uiTextModifiersTotalSize)
        {
            // text modifiers follow
            m_pTextModifierData = pPackedBuff +  m_uiTextLengthInBytes;
            
        }
    }    
    return HXR_OK;
}

C3GPPTextSample::C3GPPTextSample(IHXBuffer* pIHXBuff) 
: m_pText(NULL)
, m_uiTextLengthInBytes(0)
, m_pTextModifierData(NULL)
, m_uiTextModifiersTotalSize(0)
, m_pIHXBuff(pIHXBuff)
{
    Init(pIHXBuff);
}

HX_RESULT C3GPPTextStyleBox::Build(const UINT8*& pData)
{
    DPRINTF(D_TIMEDTEXT, ("C3GPPTextStyleBox::Build()\n"));
    HX_RESULT hr = HXR_OK;

    UINT16 entryCount = ReadUI16(pData);
    HX_ASSERT(m_entries.GetCount() == 0);

    DPRINTF(D_TIMEDTEXT, ("C3GPPTextStyleBox::Build(): %u entries\n", entryCount));
    hr = m_entries.Reset(entryCount);
    if(SUCCEEDED(hr))
    {
        for(UINT16 idx = 0; idx < entryCount; ++idx)
        {
            C3GPPStyleRecord* pEntry = new C3GPPStyleRecord();
            if(!pEntry)
            {
                return HXR_OUTOFMEMORY;
            }

            hr = pEntry->Build(pData);
            if(FAILED(hr))
            {
                HX_DELETE(pEntry);
                break;
            }
            m_entries[idx] = pEntry;
        }
    }

    return hr;
}

C3GPPFontTableBox::~C3GPPFontTableBox()
{
    CleanUp();
}

void C3GPPFontTableBox::CleanUp()
{
    for ( UINT32 idx = 0; idx != m_entries.GetCount(); ++idx )
    {
	C3GPPFontRecord*& pEntry = (C3GPPFontRecord*&)(m_entries[idx]);
	delete pEntry;
    }

    m_entries.Reset(0);
}


HX_RESULT C3GPPFontTableBox::Build(const UINT8*& pData)
{
    DPRINTF(D_TIMEDTEXT, ("C3GPPFontTableBox::Build()\n"));
    HX_RESULT hr = HXR_OK;

    m_ulFontTableSizeInBytes = ReadUL32(pData);

    // skip ftab
    HX_ASSERT(!strncmp((const char*)pData, "ftab", 4));
    pData += 4;

    UINT16 entryCount = ReadUI16(pData);
    HX_ASSERT(m_entries.GetCount() == 0);

    DPRINTF(D_TIMEDTEXT, ("C3GPPFontTableBox::Build(): %u entries\n", entryCount));

    hr = m_entries.Reset(entryCount);
    if(SUCCEEDED(hr))
    {
        for(UINT16 idx = 0; idx < entryCount; ++idx)
        {
            C3GPPFontRecord* pEntry = new C3GPPFontRecord();
            if(!pEntry)
            {
                return HXR_OUTOFMEMORY;
            }

            hr = pEntry->Build(pData);
            if(FAILED(hr))
            {
                HX_ASSERT(false);
                HX_DELETE(pEntry);
                break;
            }
            HX_ASSERT(0 == m_entries[idx]);
            m_entries[idx] = pEntry;
        }
    }

    return hr;
}

C3GPPTextStyleBox::~C3GPPTextStyleBox()
{
    CleanUp();
}

void C3GPPTextStyleBox::CleanUp()
{
    for ( INT32 idx = 0; idx != m_entries.GetCount(); ++idx )
    {
	C3GPPStyleRecord*& pEntry = (C3GPPStyleRecord*&)(m_entries[idx]);
	delete pEntry;
    }
    m_entries.Reset(0);
}


HX_RESULT C3GPPTextKaraokeBox::Build(const UINT8*& pData)
{
    DPRINTF(D_TIMEDTEXT, ("C3GPPTextKaraokeBox::Build()\n"));

    HX_RESULT hr = HXR_OK;

    m_ul1stHighlightStartTime = ReadUL32(pData);
    UINT16 entryCount = ReadUI16(pData);
    HX_ASSERT(m_entries.GetCount() == 0);

    DPRINTF(D_TIMEDTEXT, ("C3GPPTextKaraokeBox::Build(): %u entries\n", entryCount));
    hr = m_entries.Reset(entryCount);
    if(SUCCEEDED(hr))
    {
        for(UINT16 idx = 0; idx < entryCount; ++idx)
        {
            C3GPPTextKaraokeControlEntry* pEntry = new C3GPPTextKaraokeControlEntry();
            if(!pEntry)
            {
                return HXR_OUTOFMEMORY;
            }

            hr = pEntry->Build(pData);
            if(FAILED(hr))
            {
                HX_ASSERT(false);
                HX_DELETE(pEntry);
                break;
            }
            m_entries[idx] = pEntry;
        }
    }

    return hr;
}

C3GPPTextKaraokeBox::~C3GPPTextKaraokeBox()
{
    CleanUp();
}

void C3GPPTextKaraokeBox::CleanUp()
{
    for ( INT32 idx = 0; idx != m_entries.GetCount(); ++idx )
    {
	C3GPPTextKaraokeControlEntry*& pEntry = (C3GPPTextKaraokeControlEntry*&)(m_entries[idx]);
	delete pEntry;
    }
    m_entries.Reset(0);
}

HX_RESULT C3GPPTextKaraokeBox::C3GPPTextKaraokeControlEntry::Build(const UINT8*& pData)

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?