]> git.vomp.tv Git - vompclient.git/blob - dvbsubtitles.h
Fix skip and fast forward
[vompclient.git] / dvbsubtitles.h
1 /*
2     Copyright 2008 Mark Calderbank
3
4     This file is part of VOMP.
5
6     VOMP 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 2 of the License, or
9     (at your option) any later version.
10
11     VOMP 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.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software Foundation, Inc.,
18     51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20
21 #ifndef DVBSUBTITLES_H
22 #define DVBSUBTITLES_H
23
24 #include "threadsystem.h"
25
26 #include "bitmap.h"
27 #include "demuxer.h"
28 #include <ctime>
29 #include <vector>
30 #include <deque>
31 #include <map>
32
33 class OSDReceiver;
34
35 class DVBSubtitleCLUT
36 {
37   public:
38     DVBSubtitleCLUT();
39     UCHAR CLUTid;
40     UCHAR version;
41     void setEntry(int bpp, UINT index, UCHAR Y, UCHAR Cr, UCHAR Cb, UCHAR T);
42     const Palette& getPalette(int bpp) const;
43   private:
44     Palette palette2;
45     Palette palette4;
46     Palette palette8;
47     const static ULONG defaultPalette2[4];
48     const static ULONG defaultPalette4[16];
49     const static ULONG defaultPalette8[256];
50 };
51
52 class DVBSubtitleRegion : public Bitmap
53 {
54   public:
55     DVBSubtitleRegion();
56     UCHAR version;
57     UCHAR level;
58     UCHAR CLUTid;
59     void setDepth(UINT);
60     struct ObjectRef
61     {
62       UINT objectID;
63       UINT horizontalPosition;
64       UINT verticalPosition;
65     };
66     typedef std::vector<struct ObjectRef> ObjectList;
67     ObjectList objects;
68 };
69
70 class DVBSubtitlePage
71 {
72   public:
73     DVBSubtitlePage();
74     ULLONG pts;
75     bool dirty;
76     UCHAR version;
77     UINT timeout;
78     UCHAR state;
79     bool serviceAcquired;
80     typedef std::map<UCHAR, DVBSubtitleCLUT> CLUTMap;
81     CLUTMap CLUTs;
82     typedef std::map<UCHAR, DVBSubtitleRegion> RegionMap;
83     RegionMap regions;
84     struct Coords { UINT x; UINT y; };
85     typedef std::map<UCHAR, Coords> DisplayMap;
86     DisplayMap currentDisplay;
87     DisplayMap pendingDisplay;
88
89     void setState(UCHAR s);
90     void updateRegionPalettes(const DVBSubtitleCLUT&);
91 };
92
93 class DVBSubtitles : public Thread_TYPE
94 {
95   public:
96     DVBSubtitles(OSDReceiver* tosd = NULL);
97     ~DVBSubtitles() {}
98     void put(const PESPacket& packet);
99     int  start();
100     void stop();
101     void show();
102     void hide();
103
104   private:
105     OSDReceiver* osd;
106     std::deque<PESPacket> worklist;
107     typedef std::map<UINT, DVBSubtitlePage> PageMap;
108     PageMap pages;
109     UINT pageOnDisplay;
110     bool decodePacket(const PESPacket&);
111     void finishPage(const DVBSubtitlePage&);
112
113     bool running;
114     bool showing;
115     bool threadNudged;
116     void nudge();
117     void lockInput();
118     void unlockInput();
119     void lockOutput();
120     void unlockOutput();
121     void threadMethod();
122     void threadPostStopCleanup() {};
123 #ifndef WIN32
124     pthread_mutex_t input_mutex;
125     pthread_mutex_t output_mutex;
126 #else
127     HANDLE input_mutex;
128     HANDLE output_mutex;
129 #endif
130 };
131
132 #endif