Support unrar64.dll
[xy_vsfilter.git] / src / subtitles / HdmvSub.h
blobc0736c2298df4813125ccadff16c5f7ccfd26707
1 /*
2 * (C) 2006-2012 see Authors.txt
4 * This file is part of MPC-HC.
6 * MPC-HC is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * MPC-HC is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #pragma once
23 #include "BaseSub.h"
25 class CGolombBuffer;
27 class CHdmvSub : public CBaseSub
29 public:
31 static const REFERENCE_TIME INVALID_TIME = _I64_MIN;
33 enum HDMV_SEGMENT_TYPE {
34 NO_SEGMENT = 0xFFFF,
35 PALETTE = 0x14,
36 OBJECT = 0x15,
37 PRESENTATION_SEG = 0x16,
38 WINDOW_DEF = 0x17,
39 INTERACTIVE_SEG = 0x18,
40 END_OF_DISPLAY = 0x80,
41 HDMV_SUB1 = 0x81,
42 HDMV_SUB2 = 0x82
46 struct VIDEO_DESCRIPTOR {
47 short nVideoWidth;
48 short nVideoHeight;
49 BYTE bFrameRate; // <= Frame rate here!
52 struct COMPOSITION_DESCRIPTOR {
53 short nNumber;
54 BYTE bState;
57 struct SEQUENCE_DESCRIPTOR {
58 BYTE bFirstIn : 1;
59 BYTE bLastIn : 1;
60 BYTE bReserved : 6;
63 struct HDMV_CLUT {
64 BYTE id;
65 BYTE version_number;
66 BYTE size;
68 HDMV_PALETTE palette[256];
70 HDMV_CLUT():id(0),version_number(0),size(0) { memset(palette, 0, sizeof(palette)); }
73 struct HDMV_PRESENTATION_SEGMENT {
74 REFERENCE_TIME rtStart;
75 REFERENCE_TIME rtStop;
77 VIDEO_DESCRIPTOR video_descriptor;
78 COMPOSITION_DESCRIPTOR composition_descriptor;
80 byte palette_update_flag;
81 HDMV_CLUT CLUT;
83 int objectCount;
85 CAtlList<CompositionObject*> objects;
87 ~HDMV_PRESENTATION_SEGMENT() {
88 CompositionObject* pObject;
89 while (objects.GetCount() > 0) {
90 pObject = objects.RemoveHead();
91 delete pObject;
96 CHdmvSub();
97 ~CHdmvSub();
99 HRESULT ParseSample(IMediaSample* pSample);
102 POSITION GetStartPosition(REFERENCE_TIME rt, double fps);
103 POSITION GetNext(POSITION pos) {
104 m_pPresentationSegments.GetNext(pos);
105 return pos;
109 virtual REFERENCE_TIME GetStart(POSITION nPos) {
110 HDMV_PRESENTATION_SEGMENT* pPresentationSegment = m_pPresentationSegments.GetAt(nPos);
111 return pPresentationSegment != NULL ? pPresentationSegment->rtStart : INVALID_TIME;
113 virtual REFERENCE_TIME GetStop(POSITION nPos) {
114 HDMV_PRESENTATION_SEGMENT* pPresentationSegment = m_pPresentationSegments.GetAt(nPos);
115 return pPresentationSegment != NULL ? pPresentationSegment->rtStop : INVALID_TIME;
118 void Render(SubPicDesc& spd, REFERENCE_TIME rt, RECT& bbox);
119 HRESULT GetTextureSize(POSITION pos, SIZE& MaxTextureSize, SIZE& VideoSize, POINT& VideoTopLeft);
120 void Reset();
121 virtual HRESULT SetYuvType(ColorType colorType, YuvRangeType yuvRangeType);
122 private:
124 HDMV_SEGMENT_TYPE m_nCurSegment;
125 BYTE* m_pSegBuffer;
126 int m_nTotalSegBuffer;
127 int m_nSegBufferPos;
128 int m_nSegSize;
130 HDMV_PRESENTATION_SEGMENT* m_pCurrentPresentationSegment;
131 CAtlList<HDMV_PRESENTATION_SEGMENT*> m_pPresentationSegments;
133 HDMV_CLUT m_CLUTs[256];
134 CompositionObject m_compositionObjects[64];
137 int ParsePresentationSegment(REFERENCE_TIME rt, CGolombBuffer* pGBuffer);
138 void EnqueuePresentationSegment(REFERENCE_TIME rt);
140 void ParsePalette(CGolombBuffer* pGBuffer, unsigned short nSize);
141 void ParseObject(CGolombBuffer* pGBuffer, unsigned short nUnitSize);
143 void ParseVideoDescriptor(CGolombBuffer* pGBuffer, VIDEO_DESCRIPTOR* pVideoDescriptor);
144 void ParseCompositionDescriptor(CGolombBuffer* pGBuffer, COMPOSITION_DESCRIPTOR* pCompositionDescriptor);
145 void ParseCompositionObject(CGolombBuffer* pGBuffer, CompositionObject* pCompositionObject);
147 void AllocSegment(int nSize);
149 HDMV_PRESENTATION_SEGMENT* FindPresentationSegment(REFERENCE_TIME rt);
150 CompositionObject* FindObject(HDMV_PRESENTATION_SEGMENT* pPresentationSegment, short sObjectId);