Merge MPC-HC code(01b8dbf34d6a486fa1cd02d7a123249fec1e4160) [PART 2] (DVBSub)
[xy_vsfilter.git] / src / subtitles / DVBSub.h
blobcfb8e0a5722525ca4594593e935d4c9614970be7
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();
45 // EN 300-743, table 2
46 enum DVB_SEGMENT_TYPE {
47 NO_SEGMENT = 0xFFFF,
48 PAGE = 0x10,
49 REGION = 0x11,
50 CLUT = 0x12,
51 OBJECT = 0x13,
52 DISPLAY = 0x14,
53 END_OF_DISPLAY = 0x80
56 // EN 300-743, table 6
57 enum DVB_OBJECT_TYPE {
58 OT_BASIC_BITMAP = 0x00,
59 OT_BASIC_CHAR = 0x01,
60 OT_COMPOSITE_STRING = 0x02
63 enum DVB_PAGE_STATE {
64 DPS_NORMAL = 0x00,
65 DPS_ACQUISITION = 0x01,
66 DPS_MODE = 0x02,
67 DPS_RESERVED = 0x03
70 struct DVB_CLUT {
71 BYTE id;
72 BYTE version_number;
73 BYTE size;
75 HDMV_PALETTE palette[256];
77 DVB_CLUT() { memset(palette, 0, sizeof(palette)); }
80 struct DVB_DISPLAY {
81 BYTE version_number;
82 BYTE display_window_flag;
83 short width;
84 short height;
85 short horizontal_position_minimun;
86 short horizontal_position_maximum;
87 short vertical_position_minimun;
88 short vertical_position_maximum;
90 DVB_DISPLAY() {
91 // Default value (§5.1.3)
92 version_number = 0;
93 width = 720;
94 height = 576;
98 struct DVB_OBJECT {
99 short object_id;
100 BYTE object_type;
101 BYTE object_provider_flag;
102 short object_horizontal_position;
103 short object_vertical_position;
104 BYTE foreground_pixel_code;
105 BYTE background_pixel_code;
107 DVB_OBJECT() {
108 object_id = 0xFF;
109 object_type = 0;
110 object_provider_flag = 0;
111 object_horizontal_position = 0;
112 object_vertical_position = 0;
113 foreground_pixel_code = 0;
114 background_pixel_code = 0;
118 struct DVB_REGION {
119 BYTE id;
120 WORD horizAddr;
121 WORD vertAddr;
122 BYTE version_number;
123 BYTE fill_flag;
124 WORD width;
125 WORD height;
126 BYTE level_of_compatibility;
127 BYTE depth;
128 BYTE CLUT_id;
129 BYTE _8_bit_pixel_code;
130 BYTE _4_bit_pixel_code;
131 BYTE _2_bit_pixel_code;
132 int objectCount;
133 DVB_OBJECT objects[MAX_OBJECTS];
135 DVB_REGION() {
136 id = 0;
137 horizAddr = 0;
138 vertAddr = 0;
139 version_number = 0;
140 fill_flag = 0;
141 width = 0;
142 height = 0;
143 level_of_compatibility = 0;
144 depth = 0;
145 CLUT_id = 0;
146 _8_bit_pixel_code = 0;
147 _4_bit_pixel_code = 0;
148 _2_bit_pixel_code = 0;
152 class DVB_PAGE
154 public:
155 REFERENCE_TIME rtStart;
156 REFERENCE_TIME rtStop;
157 BYTE pageTimeOut;
158 BYTE pageVersionNumber;
159 BYTE pageState;
160 int regionCount;
161 DVB_REGION regions[MAX_REGIONS];
162 CAtlList<CompositionObject*> objects;
163 CAtlList<DVB_CLUT*> CLUTs;
164 bool rendered;
166 DVB_PAGE() {
167 pageTimeOut = 0;
168 pageVersionNumber = 0;
169 pageState = 0;
170 regionCount = 0;
171 rendered = false;
174 ~DVB_PAGE() {
175 CompositionObject* pObject;
176 while (objects.GetCount() > 0) {
177 pObject = objects.RemoveHead();
178 delete pObject;
181 DVB_CLUT* pCLUT;
182 while (CLUTs.GetCount() > 0) {
183 pCLUT = CLUTs.RemoveHead();
184 delete pCLUT;
189 private:
190 static const REFERENCE_TIME INVALID_TIME = _I64_MIN;
192 int m_nBufferSize;
193 int m_nBufferReadPos;
194 int m_nBufferWritePos;
195 BYTE* m_pBuffer;
196 CAtlList<DVB_PAGE*> m_Pages;
197 CAutoPtr<DVB_PAGE> m_pCurrentPage;
198 DVB_DISPLAY m_Display;
199 REFERENCE_TIME m_rtStart;
200 REFERENCE_TIME m_rtStop;
202 HRESULT AddToBuffer(BYTE* pData, int nSize);
203 DVB_PAGE* FindPage(REFERENCE_TIME rt);
204 DVB_REGION* FindRegion(DVB_PAGE* pPage, BYTE bRegionId);
205 DVB_CLUT* FindClut(DVB_PAGE* pPage, BYTE bClutId);
206 CompositionObject* FindObject(DVB_PAGE* pPage, short sObjectId);
208 HRESULT ParsePage(CGolombBuffer& gb, WORD wSegLength, CAutoPtr<DVB_PAGE>& pPage);
209 HRESULT ParseDisplay(CGolombBuffer& gb, WORD wSegLength);
210 HRESULT ParseRegion(CGolombBuffer& gb, WORD wSegLength);
211 HRESULT ParseClut(CGolombBuffer& gb, WORD wSegLength);
212 HRESULT ParseObject(CGolombBuffer& gb, WORD wSegLength);
214 HRESULT UpdateTimeStamp(REFERENCE_TIME rtStop);