6faad507e6eb582444ad0ad6050b81e95f15ce73
[enigma2.git] / 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 struct subtitle_clut_entry
12 {
13         __u8 Y, Cr, Cb, T;
14 };
15
16 struct subtitle_clut
17 {
18         unsigned char clut_id;
19         unsigned char size_2, size_4, size_8;
20         unsigned char CLUT_version_number;
21         struct subtitle_clut_entry entries_2bit[4];
22         struct subtitle_clut_entry entries_4bit[16];
23         struct subtitle_clut_entry entries_8bit[256];
24         struct subtitle_clut *next;
25 };
26
27 struct subtitle_page_region
28 {
29         int region_id;
30         int region_horizontal_address;
31         int region_vertical_address;
32         struct subtitle_page_region *next;
33 };
34
35 struct subtitle_region_object
36 {
37         int object_id;
38         int object_type;
39         int object_provider_flag;
40         
41         int object_horizontal_position;
42         int object_vertical_position;
43         
44                 // not supported right now...
45         int foreground_pixel_value;
46         int background_pixel_value;
47
48         struct subtitle_region_object *next;
49 };
50
51 struct subtitle_region
52 {
53         int region_id;
54         int region_version_number;
55         int region_height, region_width;
56         enum depth { bpp2=1, bpp4=2, bpp8=3 } region_depth;
57         ePtr<gPixmap> region_buffer;
58         
59         int clut_id;
60         
61         struct subtitle_region_object *region_objects;
62         
63         struct subtitle_region *next;
64 };
65
66 struct subtitle_page
67 {
68         int page_id;
69         time_t page_time_out;
70         int page_version_number;
71         int pcs_size;
72         struct subtitle_page_region *page_regions;
73         
74         struct subtitle_region *regions;
75
76         struct subtitle_clut *cluts;
77
78         struct subtitle_page *next;
79 };
80
81 struct bitstream
82 {
83         __u8 *data;
84         int size;
85         int avail;
86         int consumed;
87 };
88
89 struct eDVBSubtitleRegion
90 {
91         pts_t show_time;
92         int timeout;
93         ePtr<gPixmap> region;
94 };
95
96 class eDVBSubtitleParser
97         :public iObject, public ePESParser, public Object
98 {
99         DECLARE_REF(eDVBSubtitleParser);
100         struct subtitle_page *pages;
101         int current_clut_id, current_clut_page_id;
102         int screen_width, screen_height;
103         int bbox_left, bbox_top, bbox_right, bbox_bottom;
104         ePtr<iDVBPESReader> m_pes_reader;
105         ePtr<eConnection> m_read_connection;
106         pts_t show_time;
107         Signal1<void,const eDVBSubtitleRegion&> m_new_subtitle_region;
108 public:
109         eDVBSubtitleParser(iDVBDemux *demux);
110         virtual ~eDVBSubtitleParser();
111         int start(int pid);
112         void connectNewRegion(const Slot1<void, const eDVBSubtitleRegion&> &slot, ePtr<eConnection> &connection);
113 private:
114         void subtitle_process_line(struct subtitle_page *page, int object_id, int line, __u8 *data, int len);
115         int subtitle_process_pixel_data(struct subtitle_page *page, int object_id, int *linenr, int *linep, __u8 *data);
116         int subtitle_process_segment(__u8 *segment);
117         void subtitle_process_pes(__u8 *buffer, int len);
118         void subtitle_clear_screen();
119         void subtitle_redraw_all();
120         void subtitle_reset();
121         void subtitle_redraw(int page_id);
122         void processPESPacket(__u8 *pkt, int len) { subtitle_process_pes(pkt, len); }
123 };
124
125 #endif