Support turbo2.
[vuplus_dvbapp] / lib / dvb / subtitle.h
1 #ifndef __lib_dvb_subtitle_h
2 #define __lib_dvb_subtitle_h
3
4 #include <lib/base/object.h>
5 #include <lib/dvb/idvb.h>
6 #include <lib/dvb/pesparse.h>
7 #include <lib/gdi/gpixmap.h>
8
9 typedef unsigned char __u8;
10
11 enum {
12         FONTCOLOR_WHITE = 1,
13         FONTCOLOR_YELLOW,
14         FONTCOLOR_GREEN,
15         FONTCOLOR_CYAN,
16         FONTCOLOR_BLUE,
17         FONTCOLOR_MAGNETA,
18         FONTCOLOR_RED,
19         FONTCOLOR_BLACK,
20 };
21
22 enum {
23         BGCOLOR_BLACK = 0,
24         BGCOLOR_RED,
25         BGCOLOR_MAGNETA,
26         BGCOLOR_BLUE,
27         BGCOLOR_CYAN,
28         BGCOLOR_GREEN,
29         BGCOLOR_YELLOW,
30         BGCOLOR_WHITE,
31 };
32
33 struct subtitle_clut_entry
34 {
35         __u8 Y, Cr, Cb, T;
36         __u8 valid;
37 };
38
39 struct subtitle_clut
40 {
41         unsigned char clut_id;
42         unsigned char CLUT_version_number;
43         subtitle_clut_entry entries_2bit[4];
44         subtitle_clut_entry entries_4bit[16];
45         subtitle_clut_entry entries_8bit[256];
46         subtitle_clut *next;
47 };
48
49 struct subtitle_page_region
50 {
51         int region_id;
52         int region_horizontal_address;
53         int region_vertical_address;
54         subtitle_page_region *next;
55 };
56
57 struct subtitle_region_object
58 {
59         int object_id;
60         int object_type;
61         int object_provider_flag;
62
63         int object_horizontal_position;
64         int object_vertical_position;
65
66                 // not supported right now...
67         int foreground_pixel_value;
68         int background_pixel_value;
69
70         subtitle_region_object *next;
71 };
72
73 struct subtitle_region
74 {
75         int region_id;
76         int version_number;
77         int height, width;
78         enum tDepth { bpp2=1, bpp4=2, bpp8=3 } depth;
79
80         ePtr<gPixmap> buffer;
81
82         int clut_id;
83
84         subtitle_region_object *objects;
85
86         subtitle_region *next;
87
88         bool committed;
89 };
90
91 struct subtitle_page
92 {
93         int page_id;
94         time_t page_time_out;
95         int page_version_number;
96         int state;
97         int pcs_size;
98         subtitle_page_region *page_regions;
99
100         subtitle_region *regions;
101
102         subtitle_clut *cluts;
103
104         subtitle_page *next;
105 };
106
107 struct bitstream
108 {
109         __u8 *data;
110         int size;
111         int avail;
112         int consumed;
113 };
114
115 struct eDVBSubtitleRegion
116 {
117         ePtr<gPixmap> m_pixmap;
118         ePoint m_position;
119         eDVBSubtitleRegion &operator=(const eDVBSubtitleRegion &s)
120         {
121                 m_pixmap = s.m_pixmap;
122                 m_position = s.m_position;
123                 return *this;
124         }
125 };
126
127 struct eDVBSubtitlePage
128 {
129         std::list<eDVBSubtitleRegion> m_regions;
130         pts_t m_show_time;
131         eSize m_display_size;
132 };
133
134 class eDVBSubtitleParser
135         :public iObject, public ePESParser, public Object
136 {
137         DECLARE_REF(eDVBSubtitleParser);
138         subtitle_page *m_pages;
139         ePtr<iDVBPESReader> m_pes_reader;
140         ePtr<eConnection> m_read_connection;
141         pts_t m_show_time;
142         Signal1<void,const eDVBSubtitlePage&> m_new_subtitle_page;
143         int m_composition_page_id, m_ancillary_page_id;
144         bool m_seen_eod;
145         eSize m_display_size;
146 public:
147         eDVBSubtitleParser(iDVBDemux *demux);
148         virtual ~eDVBSubtitleParser();
149         int start(int pid, int composition_page_id, int ancillary_page_id);
150         int stop();
151         void connectNewPage(const Slot1<void, const eDVBSubtitlePage&> &slot, ePtr<eConnection> &connection);
152 private:
153         void subtitle_process_line(subtitle_region *region, subtitle_region_object *object, int line, __u8 *data, int len);
154         int subtitle_process_pixel_data(subtitle_region *region, subtitle_region_object *object, int *linenr, int *linep, __u8 *data);
155         int subtitle_process_segment(__u8 *segment);
156         void subtitle_process_pes(__u8 *buffer, int len);
157         void subtitle_redraw_all();
158         void subtitle_reset();
159         void subtitle_redraw(int page_id);
160         void processPESPacket(__u8 *pkt, int len) { subtitle_process_pes(pkt, len); }
161 };
162
163 #endif