3gppttstructs.h
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:19k
- /* ***** 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 ***** */
- #ifndef _3GPPTTSTRUCTS_H_
- #define _3GPPTTSTRUCTS_H_
- /****************************************************************************
- * Includes
- */
- #include "hxtypes.h"
- #include "hxresult.h"
- #include "hxassert.h"
- #include "3gppttutils.h"
- // /These are individual flag bits in C3GPPTextSampleEntry::m_ulDisplayFlags :
- #define HX_3GPPTT_DISPLAYFLAGS_SCROLL_IN 0x00000020
- #define HX_3GPPTT_DISPLAYFLAGS_SCROLL_OUT 0x00000040
- // /8th bit set means horizontal motion (else vertical), 9th bit set means
- // from top or left, (else from bottom or right):
- #define HX_3GPPTT_DISPLAYFLAGS_SCROLL_DIR_MASK 0x00000180
- #define HX_3GPPTT_DISPLAYFLAGS_SCROLL_DIR_UP 0x00000000
- #define HX_3GPPTT_DISPLAYFLAGS_SCROLL_DIR_RTOL 0x00000080
- #define HX_3GPPTT_DISPLAYFLAGS_SCROLL_DIR_DOWN 0x00000100
- #define HX_3GPPTT_DISPLAYFLAGS_SCROLL_DIR_LTOR 0x00000180
- // /Non-scroll display flags:
- #define HX_3GPPTT_DISPLAYFLAGS_CONTINUOUS_KARAOKE 0x00000800
- #define HX_3GPPTT_DISPLAYFLAGS_WRITE_VERTICALLY 0x00020000
- #define HX_3GPPTT_JUSTIFICATION_LEFT 0
- #define HX_3GPPTT_JUSTIFICATION_TOP 0
- #define HX_3GPPTT_JUSTIFICATION_CENTER 1 /* Horiz or vert */
- #define HX_3GPPTT_JUSTIFICATION_RIGHT (-1)
- #define HX_3GPPTT_JUSTIFICATION_BOTTOM (-1)
- // /Single-bit FaceStyle flags:
- #define HX_3GPPTT_FACE_STYLE_PLAIN 0
- #define HX_3GPPTT_FACE_STYLE_BOLD 1
- #define HX_3GPPTT_FACE_STYLE_ITALIC 2
- #define HX_3GPPTT_FACE_STYLE_UNDERLINE 4
- #define HX_3GPPTT_HYPERLINK_RGB_COLOR 0x00FF0000 /* Red */
- #define HX_3GPPTT_FULLY_TRANSPARENT 0xFF000000
- // /box-type 4-cc codes
- #define HX_3GPPTT_4CC_LEN 4
- #define HX_3GPPTT_STYL_4CC "styl"
- #define HX_3GPPTT_HLIT_4CC "hlit"
- #define HX_3GPPTT_HCLR_4CC "hclr"
- #define HX_3GPPTT_KROK_4CC "krok"
- #define HX_3GPPTT_DLAY_4CC "dlay"
- #define HX_3GPPTT_HREF_4CC "href"
- #define HX_3GPPTT_TBOX_4CC "tbox"
- #define HX_3GPPTT_BLNK_4CC "blnk"
- #define HX_3GPPTT_INVALID_INDEX ((UINT16)-1)
- #define HX_3GPPTT_MAX_CHAR_OFFSET (((UINT16)-1)-1)
- #define HX_3GPPTT_INVALID_TIME ((UINT32)-1)
- #define HX_3GPPTT_INVALID_INT16 (-1)
- #define HX_3GPPTT_BLINK_HALFINTERVAL_TIME 1000 /* in milliseconds */
- //TBOX
- class C3GPPTextboxBox
- {
- public:
- C3GPPTextboxBox() : m_top(0), m_left(0), m_bottom(0), m_right(0) {}
- HX_RESULT Build(const UINT8*& pData);
- INT16 Top() const { return m_top; }
- INT16 Left() const { return m_left; }
- INT16 Bottom() const { return m_bottom; }
- INT16 Right() const { return m_right; }
- private:
- INT16 m_top;
- INT16 m_left;
- INT16 m_bottom;
- INT16 m_right;
- };
- //STYL
- class C3GPPStyleRecord
- {
- public:
- C3GPPStyleRecord()
- : m_uiStartCharOffset(0)
- , m_uiEndCharOffset(0)
- , m_uiFontID(0)
- , m_uFaceStyleFlags(0)
- , m_uFontSize(0)
- , m_textColor(0) {}
- HX_RESULT Build(const UINT8*& pData);
- UINT16 GetStartOffset() const { return m_uiStartCharOffset;}
- UINT16 GetEndOffset() const { return m_uiEndCharOffset;}
- UINT16 GetFontID() const { return m_uiFontID;}
- UINT8 GetFaceStyleFlags() const { return m_uFaceStyleFlags; }
- UINT8 GetFontSize() const { return m_uFontSize; }
- UINT32 GetTextColor() const { return m_textColor; }
- private:
- UINT16 m_uiStartCharOffset;
- UINT16 m_uiEndCharOffset;
- UINT16 m_uiFontID;
- UINT8 m_uFaceStyleFlags; // /FACE_STYLE + {_PLAIN, _BOLD, _ITALIC, _UNDERLINE}.
- UINT8 m_uFontSize;
- UINT32 m_textColor; // argb
- };
- //FTAB entry
- class C3GPPFontRecord
- {
- public:
- C3GPPFontRecord() : m_uiFontID(0) {}
- HX_RESULT Build(const UINT8*& pData);
- UINT16 GetFontID() const { return m_uiFontID; }
- const char* GetFontName() const { return m_strFont; }
- private:
- UINT16 m_uiFontID;
- SimpleString m_strFont;
-
- };
- //FTAB
- class C3GPPFontTableBox
- {
- public:
- C3GPPFontTableBox() : m_ulFontTableSizeInBytes(0) {}
- ~C3GPPFontTableBox();
- HX_RESULT Build(const UINT8*& pData);
- UINT32 GetFontTableSize() const { return m_ulFontTableSizeInBytes;}
- UINT16 GetEntryCount() const { return (UINT16)m_entries.GetCount(); }
- const C3GPPFontRecord* GetFontRecord(UINT16 idx) const
- {
- HX_ASSERT(idx < m_entries.GetCount());
- return (C3GPPFontRecord*)(m_entries.GetItem(idx));
- }
- private:
- void CleanUp();
- private:
- UINT32 m_ulFontTableSizeInBytes;
- SimpleArray m_entries;
- };
- enum TextSampleScrollDirection
- {
- scrollDirNone
- , scrollDirUp
- , scrollDirRightToLeft
- , scrollDirDown
- , scrollDirLeftToRight
- };
- // /From MP4 stsd atom class:
- class C3GPPArrayEntry
- {
- public:
- HX_RESULT Build(const UINT8*& pData)
- {
- // we don't use any of this data (just skip)
- pData += 16;
- return HXR_OK;
- }
- //UINT8 pSize[4];
- //UINT8 pDataFormat[4];
- //UINT8 pReserved[6];
- //UINT8 pDataRefIdx[2];
- };
- //TX3G
- class C3GPPTextSampleEntry
- : public C3GPPArrayEntry
- {
- public:
- C3GPPTextSampleEntry();
- HX_RESULT Build(const UINT8*& pData);
- public:
- BOOL hasScrollIn() const { return (m_ulDisplayFlags & HX_3GPPTT_DISPLAYFLAGS_SCROLL_IN); }
- BOOL hasScrollOut() const { return (m_ulDisplayFlags & HX_3GPPTT_DISPLAYFLAGS_SCROLL_OUT); }
- BOOL hasContinuousKaraoke() const { return (m_ulDisplayFlags & HX_3GPPTT_DISPLAYFLAGS_CONTINUOUS_KARAOKE); }
- BOOL hasWriteVertically() const { return (m_ulDisplayFlags & HX_3GPPTT_DISPLAYFLAGS_WRITE_VERTICALLY); }
- TextSampleScrollDirection getScrollDirection() const;
- INT8 GetHorJust() const { return m_horizontalJustification; }
- INT8 GetVerJust() const { return m_verticalJustification; }
- UINT32 GetBGColor() const { return m_bgColor; }
- const C3GPPTextboxBox& GetDefaultTextBox() const { return m_defaultTextBox; }
- const C3GPPStyleRecord& GetDefaultStyle() const { return m_defaultStyle; }
- const C3GPPFontTableBox& GetFontTable() const { return m_fontTable; }
- private:
- UINT32 m_ulDisplayFlags;
- INT8 m_horizontalJustification; // /JUSTIFICATION_LEFT, ...etc.
- INT8 m_verticalJustification; // /JUSTIFICATION_TOP, ...etc.
- UINT32 m_bgColor;
- C3GPPTextboxBox m_defaultTextBox;
- C3GPPStyleRecord m_defaultStyle;
- C3GPPFontTableBox m_fontTable;
- };
- class C3GPPTextSampleModifierBox // /extends Box(type)
- {
- public:
- enum ModifierType
- {
- STYL,
- HLIT,
- HCLR,
- KROK,
- DLAY,
- HREF,
- TBOX,
- BLNK,
- UNKNOWN
- };
- C3GPPTextSampleModifierBox() : m_ulSize(0), m_type(UNKNOWN), m_pData(0) {}
- HX_RESULT Build(const UINT8*& pData);
- const UINT8* GetData() const { return m_pData; }
- ModifierType GetType() const { return m_type; }
- UINT32 GetTotalSize() const { return m_ulSize; }
- UINT32 GetDataSize() const { HX_ASSERT(m_ulSize >= 8); return m_ulSize - 8; }
- private:
- C3GPPTextSampleModifierBox::ModifierType ReadType(const UINT8*& pData);
- UINT32 m_ulSize;
- ModifierType m_type;
- const UINT8* m_pData;
- };
- inline
- HX_RESULT C3GPPTextSampleModifierBox::Build(const UINT8*& pData)
- {
- m_ulSize = ReadUL32(pData);
- m_type = ReadType(pData);
- m_pData = pData;
- return HXR_OK;
- }
- class C3GPPTextSample
- {
- public:
-
- C3GPPTextSample(IHXBuffer* pIHXBuff);
- ~C3GPPTextSample() { HX_RELEASE(m_pIHXBuff); }
- const char* GetText() const { return m_pText; }
- UINT16 GetTextLenInBytes() const { return m_uiTextLengthInBytes; }
- const UINT8* GetModifierData() const { return m_pTextModifierData; }
- UINT16 GetModifierDataSize() const { return m_uiTextModifiersTotalSize;}
- private:
- HX_RESULT Init(IHXBuffer* pIHXBuff);
- private:
- UINT16 m_uiTextLengthInBytes;
- const char* m_pText;
- IHXBuffer* m_pIHXBuff;
- // 0 or more of these
- const UINT8* m_pTextModifierData;
- UINT16 m_uiTextModifiersTotalSize;
- };
- //STYL
- class C3GPPTextStyleBox
- {
- public:
-
- ~C3GPPTextStyleBox();
- HX_RESULT Build(const UINT8*& pData);
- UINT16 GetEntryCount() const { return (UINT16)m_entries.GetCount(); }
- const C3GPPStyleRecord* GetStyleRecord(UINT16 uiEntry) const
- {
- HX_ASSERT(uiEntry < m_entries.GetCount());
- return (const C3GPPStyleRecord*)m_entries.GetItem(uiEntry);
- }
- private:
- void CleanUp();
- private:
- SimpleArray m_entries;
- };
- //HLIT
- class C3GPPTextHighlightBox
- {
- public:
- C3GPPTextHighlightBox() : m_uiStartCharOffset(0), m_uiEndCharOffset(0) {};
- HX_RESULT Build(const UINT8*& pData)
- {
- m_uiStartCharOffset = ReadUI16(pData);
- m_uiEndCharOffset = ReadUI16(pData);
- return HXR_OK;
- }
- UINT16 GetStartOffset() const { return m_uiStartCharOffset;}
- UINT16 GetEndOffset() const { return m_uiEndCharOffset;}
- private:
- UINT16 m_uiStartCharOffset;
- UINT16 m_uiEndCharOffset;
- };
- //HCLR
- class C3GPPTextHilightColorBox
- {
- public:
- C3GPPTextHilightColorBox() : m_HighlightColorRGBA(0) {}
- HX_RESULT Build(const UINT8*& pData)
- {
- m_HighlightColorRGBA = ReadARGB(pData);
- return HXR_OK;
- }
- UINT32 GetHighlightColor() const { return m_HighlightColorRGBA; }
- private:
- // /Specifies entire sample's highlight (incl. karaoke) color:
- UINT32 m_HighlightColorRGBA;
- };
- //KROK
- class C3GPPTextKaraokeBox
- {
- public:
- //KROK entry
- class C3GPPTextKaraokeControlEntry
- {
- public:
- C3GPPTextKaraokeControlEntry()
- : m_ulHighlightEndTime(0)
- , m_uiStartCharOffset(0)
- , m_uiEndCharOffset(0) {}
-
- HX_RESULT Build(const UINT8*& pData);
- UINT16 GetStartOffset() const {return m_uiStartCharOffset; }
- UINT16 GetEndOffset() const {return m_uiEndCharOffset;}
- UINT32 GetHighlightEndTime() const {return m_ulHighlightEndTime;}
- private:
- UINT32 m_ulHighlightEndTime;
- UINT16 m_uiStartCharOffset;
- UINT16 m_uiEndCharOffset;
- };
- public:
- /*C3GPPTextKaraokeBox()
- : m_ul1stHighlightStartTime(0) {};*/
- ~C3GPPTextKaraokeBox();
- HX_RESULT Build(const UINT8*& pData);
- UINT32 Get1stHighlightStartTime() const {return m_ul1stHighlightStartTime;}
- UINT16 GetEntryCount() const { return (UINT16)m_entries.GetCount(); }
- const C3GPPTextKaraokeControlEntry* GetKaraokeControlEntry(UINT16 uiEntry) const
- {
- HX_ASSERT(uiEntry < m_entries.GetCount());
- return (C3GPPTextKaraokeControlEntry*)m_entries.GetItem(uiEntry);
- }
- private:
- void CleanUp();
- private:
- UINT32 m_ul1stHighlightStartTime;
- SimpleArray m_entries;
- };
- //DLAY
- class C3GPPTextScrollDelayBox
- {
- public:
- C3GPPTextScrollDelayBox() : m_ulScrollDelay(0) {}
- HX_RESULT Build(const UINT8*& pData)
- {
- m_ulScrollDelay = ReadUL32(pData);
- return HXR_OK;
- }
- UINT32 GetScrollDelay() const { return m_ulScrollDelay; }
- private:
- UINT32 m_ulScrollDelay; // /=delay after a Scroll In &/or before Scroll Out
- };
- // HREF
- class C3GPPTextHyperTextBox
- {
- public:
- C3GPPTextHyperTextBox() : m_uiStartCharOffset(0), m_uiEndCharOffset(0) {}
- HX_RESULT Build(const UINT8*& pData);
- const char* GetURL() const { return m_strURL;}
- const char* GetAltURL() const { return m_strAltURL;}
- bool HasURL() const { return !m_strURL.Length(); }
- bool HasAltURL() const { return !m_strAltURL.Length(); }
- const UINT16 GetStartOffset() const { return m_uiStartCharOffset;}
- const UINT16 GetEndOffset() const { return m_uiEndCharOffset;}
- private:
- UINT16 m_uiStartCharOffset;
- UINT16 m_uiEndCharOffset;
- SimpleString m_strURL;
- SimpleString m_strAltURL;
- };
- //BLNK
- class C3GPPTextBlinkBox
- {
- public:
- C3GPPTextBlinkBox() : m_uiStartCharOffset(0), m_uiEndCharOffset(0) {}
- HX_RESULT Build(const UINT8*& pData)
- {
- m_uiStartCharOffset = ReadUI16(pData);
- m_uiEndCharOffset = ReadUI16(pData);
- return HXR_OK;
- }
- const UINT16 GetStartOffset() const { return m_uiStartCharOffset; }
- const UINT16 GetEndOffset() const { return m_uiEndCharOffset; }
- private:
- UINT16 m_uiStartCharOffset;
- UINT16 m_uiEndCharOffset;
- };
- class C3GPPTextContainer
- {
- public:
- C3GPPTextContainer();
- ~C3GPPTextContainer();
- HX_RESULT Init(
- IHXPacket* pPacket,
- UINT32 ulPacketContentsBeginTime,
- UINT32 ulMaxEndTime,
- UINT16 uiStartCharOffset,
- /*OUT*/ UINT16& uiREFIndexOfLastChar);
- UINT16 GetTextByteLength() const
- {
- HX_ASSERT(!m_pTextSample || m_pTextSample->GetTextLenInBytes() >
- m_uiUnpackedStartCharOffset);
- return ( (HX_3GPPTT_INVALID_INDEX == m_uiUnpackedEndCharOffset ||
- HX_3GPPTT_MAX_CHAR_OFFSET == m_uiUnpackedEndCharOffset) ?
- (m_pTextSample? m_pTextSample->GetTextLenInBytes() -
- m_uiUnpackedStartCharOffset : 0)
- :
- // /it's not, apparently, endpoint inclusive (and it is
- // *not* NULL-terminated)
- m_uiUnpackedEndCharOffset - m_uiUnpackedStartCharOffset);
- }
- BOOL IsHyperlinked() const { return (m_pTextHyperTextBox != NULL); }
- BOOL ContainsPoint(INT16 iX, INT16 iY) const;
- HX_RESULT UpdateLowestPotentialNextTCStartOffset(
- UINT16 uiCurStartCharOffset, UINT16 uiCurEndCharOffset,
- UINT16& /*REF IN-&-OUT*/ uiLowestPotentialNextTCStartOffsetFound,
- BOOL& /*REF OUT*/ bAssignBoxToCurrent);
- // /m_pPacket pass-through methods:
- //IHXBuffer* GetBuffer() {return (m_pPacket? m_pPacket->GetBuffer():NULL); }
- UINT32 GetBeginTime() const { return m_ulBeginTime; }
- UINT32 GetEndTime() const { return m_ulEndTime; }
- UINT32 GetDuration() const { return m_ulEndTime - m_ulBeginTime; }
- UINT32 GetNextActivityTime() const; // /Next time draw or erase or move happens
- UINT32 GetPrevActivityTime()const ; // /Previous time draw or erase or move happened
- void SetPrevActivityTime(UINT32 ulAbsoluteTime); // /Converts to offset (local time)
- UINT32 GetASMRuleNumber() const { return m_pPacket? m_pPacket->GetASMRuleNumber() : 0; }
- // /All data members are unpacked and NULL-terminated where appropriate:
- IHXPacket* m_pPacket;
- C3GPPTextSample* m_pTextSample;
- UINT16 m_uiUnpackedStartCharOffset;
- UINT16 m_uiUnpackedEndCharOffset;
- UINT16 m_uiTextStyleBoxIndex;
- UINT16 m_uiTextKaraokeBoxIndex;
- HXxRect m_BoundingRectOfInitialDraw;
- C3GPPTextStyleBox* m_pTextStyleBox;
- C3GPPTextHighlightBox* m_pTextHighlightBox;
- C3GPPTextHilightColorBox* m_pTextHilightColorBox;
- C3GPPTextKaraokeBox* m_pTextKaraokeBox;
- C3GPPTextScrollDelayBox* m_pTextScrollDelayBox;
- C3GPPTextHyperTextBox* m_pTextHyperTextBox;
- C3GPPTextboxBox* m_pTextboxBox;
- C3GPPTextBlinkBox* m_pTextBlinkBox;
- UINT32 m_ulBeginTime;
- // /End time is the start time of the next packet (if any):
- UINT32 m_ulEndTime;
- // /For blinking or scrolling text, this is set to a non-invalid time
- // (i.e., not HX_3GPPTT_INVALID_TIME) and is the next time this's text
- // needs to be redrawn at another location (scroll) or on/off toggle
- // (for blinking):
- UINT32 m_ulNextDrawUpdateTimeOffset;
- // /Used for scrolling text, this is when the last draw (if any) was done;
- // if it hasn't been drawn yet, this is set to HX_3GPPTT_INVALID_TIME:
- UINT32 m_ulPrevDrawUpdateTimeOffset;
- // /A T.C. may contain one or more newline chars at its start; this keeps
- // track of how many were found (if any); init'd to HX_3GPPTT_INVALID_INT16
- // which can be used to determine if such counting was performed:
- INT16 m_lNumUTF16NewlineCharsAtStart;
- // /This keeps track of how many newlines there are, which might equal
- // the above but may be less if there are any CRLF's which are two
- // newline chars that count as only 1 newline:
- INT16 m_lNumUTF16NewlinesAtStart;
- private:
- HX_RESULT BuildSampleModifiers(BOOL& bNeedToBreakTCsUpAtNewlines);
- HX_RESULT BuildSTYL(const UINT8*& pData,
- UINT16& uiLowestPotentialNextTCStartOffsetFound,
- BOOL& bNeedToBreakTCsUpAtNewlines,
- UINT16& curEndCharOffset);
- HX_RESULT BuildHLIT(const UINT8*& pData,
- UINT16& uiLowestPotentialNextTCStartOffsetFound,
- BOOL& bNeedToBreakTCsUpAtNewlines,
- UINT16& curEndCharOffset);
- HX_RESULT BuildKROK(const UINT8*& pData,
- UINT16& uiLowestPotentialNextTCStartOffsetFound,
- BOOL& bNeedToBreakTCsUpAtNewlines,
- UINT16& curEndCharOffset);
- HX_RESULT BuildHREF(const UINT8*& pData,
- UINT16& uiLowestPotentialNextTCStartOffsetFound,
- BOOL& bNeedToBreakTCsUpAtNewlines,
- UINT16& curEndCharOffset);
- HX_RESULT BuildBLNK(const UINT8*& pData,
- UINT16& uiLowestPotentialNextTCStartOffsetFound,
- BOOL& bNeedToBreakTCsUpAtNewlines,
- UINT16& curEndCharOffset);
- HX_RESULT BuildTBOX(const UINT8*& pData);
- HX_RESULT BuildHCLR(const UINT8*& pData);
- HX_RESULT BuildDLAY(const UINT8*& pData);
- };
- #endif // _3GPPTTSTRUCTS_H_