Support unrar64.dll
[xy_vsfilter.git] / src / subtitles / DVBSub.h
bloba61ba9405a7bb663cd2495ebcbd70d816c244e50
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 #define MAX_REGIONS 10
26 #define MAX_OBJECTS 10 // Max number of objects per region
28 class CGolombBuffer;
30 class CDVBSub : public CBaseSub
32 public:
33 CDVBSub(void);
34 ~CDVBSub(void);
36 virtual HRESULT ParseSample(IMediaSample* pSample);
37 virtual void Render(SubPicDesc& spd, REFERENCE_TIME rt, RECT& bbox);
38 virtual HRESULT GetTextureSize(POSITION pos, SIZE& MaxTextureSize, SIZE& VideoSize, POINT& VideoTopLeft);
39 virtual POSITION GetStartPosition(REFERENCE_TIME rt, double fps);
40 virtual POSITION GetNext(POSITION pos);
41 virtual REFERENCE_TIME GetStart(POSITION nPos);
42 virtual REFERENCE_TIME GetStop(POSITION nPos);
43 virtual void Reset();
44 virtual HRESULT SetYuvType(ColorType colorType, YuvRangeType yuvRangeType);
46 // EN 300-743, table 2
47 enum DVB_SEGMENT_TYPE {
48 NO_SEGMENT = 0xFFFF,
49 PAGE = 0x10,
50 REGION = 0x11,
51 CLUT = 0x12,
52 OBJECT = 0x13,
53 DISPLAY = 0x14,
54 END_OF_DISPLAY = 0x80
57 // EN 300-743, table 6
58 enum DVB_OBJECT_TYPE {
59 OT_BASIC_BITMAP = 0x00,
60 OT_BASIC_CHAR = 0x01,
61 OT_COMPOSITE_STRING = 0x02
64 enum DVB_PAGE_STATE {
65 DPS_NORMAL = 0x00,
66 DPS_ACQUISITION = 0x01,
67 DPS_MODE = 0x02,
68 DPS_RESERVED = 0x03
71 struct DVB_CLUT {
72 BYTE id;
73 BYTE version_number;
74 BYTE size;
76 HDMV_PALETTE palette[256];
78 DVB_CLUT() { memset(palette, 0, sizeof(palette)); }
81 struct DVB_DISPLAY {
82 BYTE version_number;
83 BYTE display_window_flag;
84 short width;
85 short height;
86 short horizontal_position_minimun;
87 short horizontal_position_maximum;
88 short vertical_position_minimun;
89 short vertical_position_maximum;
91 DVB_DISPLAY() {
92 // Default value (§5.1.3)
93 version_number = 0;
94 width = 720;
95 height = 576;
99 struct DVB_OBJECT {
100 short object_id;
101 BYTE object_type;
102 BYTE object_provider_flag;
103 short object_horizontal_position;
104 short object_vertical_position;
105 BYTE foreground_pixel_code;
106 BYTE background_pixel_code;
108 DVB_OBJECT() {
109 object_id = 0xFF;
110 object_type = 0;
111 object_provider_flag = 0;
112 object_horizontal_position = 0;
113 object_vertical_position = 0;
114 foreground_pixel_code = 0;
115 background_pixel_code = 0;
119 struct DVB_REGION {
120 BYTE id;
121 WORD horizAddr;
122 WORD vertAddr;
123 BYTE version_number;
124 BYTE fill_flag;
125 WORD width;
126 WORD height;
127 BYTE level_of_compatibility;
128 BYTE depth;
129 BYTE CLUT_id;
130 BYTE _8_bit_pixel_code;
131 BYTE _4_bit_pixel_code;
132 BYTE _2_bit_pixel_code;
133 int objectCount;
134 DVB_OBJECT objects[MAX_OBJECTS];
136 DVB_REGION() {
137 id = 0;
138 horizAddr = 0;
139 vertAddr = 0;
140 version_number = 0;
141 fill_flag = 0;
142 width = 0;
143 height = 0;
144 level_of_compatibility = 0;
145 depth = 0;
146 CLUT_id = 0;
147 _8_bit_pixel_code = 0;
148 _4_bit_pixel_code = 0;
149 _2_bit_pixel_code = 0;
153 class DVB_PAGE
155 public:
156 REFERENCE_TIME rtStart;
157 REFERENCE_TIME rtStop;
158 BYTE pageTimeOut;
159 BYTE pageVersionNumber;
160 BYTE pageState;
161 int regionCount;
162 DVB_REGION regions[MAX_REGIONS];
163 CAtlList<CompositionObject*> objects;
164 CAtlList<DVB_CLUT*> CLUTs;
165 bool rendered;
167 DVB_PAGE() {
168 pageTimeOut = 0;
169 pageVersionNumber = 0;
170 pageState = 0;
171 regionCount = 0;
172 rendered = false;
175 ~DVB_PAGE() {
176 CompositionObject* pObject;
177 while (objects.GetCount() > 0) {
178 pObject = objects.RemoveHead();
179 delete pObject;
182 DVB_CLUT* pCLUT;
183 while (CLUTs.GetCount() > 0) {
184 pCLUT = CLUTs.RemoveHead();
185 delete pCLUT;
190 private:
191 static const REFERENCE_TIME INVALID_TIME = _I64_MIN;
193 int m_nBufferSize;
194 int m_nBufferReadPos;
195 int m_nBufferWritePos;
196 BYTE* m_pBuffer;
197 CAtlList<DVB_PAGE*> m_Pages;
198 CAutoPtr<DVB_PAGE> m_pCurrentPage;
199 DVB_DISPLAY m_Display;
200 REFERENCE_TIME m_rtStart;
201 REFERENCE_TIME m_rtStop;
203 HRESULT AddToBuffer(BYTE* pData, int nSize);
204 DVB_PAGE* FindPage(REFERENCE_TIME rt);
205 DVB_REGION* FindRegion(DVB_PAGE* pPage, BYTE bRegionId);
206 DVB_CLUT* FindClut(DVB_PAGE* pPage, BYTE bClutId);
207 CompositionObject* FindObject(DVB_PAGE* pPage, short sObjectId);
209 HRESULT ParsePage(CGolombBuffer& gb, WORD wSegLength, CAutoPtr<DVB_PAGE>& pPage);
210 HRESULT ParseDisplay(CGolombBuffer& gb, WORD wSegLength);
211 HRESULT ParseRegion(CGolombBuffer& gb, WORD wSegLength);
212 HRESULT ParseClut(CGolombBuffer& gb, WORD wSegLength);
213 HRESULT ParseObject(CGolombBuffer& gb, WORD wSegLength);
215 HRESULT UpdateTimeStamp(REFERENCE_TIME rtStop);