]> git.vomp.tv Git - vompclient.git/blob - dvbsubtitles.h
Fix text corruption in channel number display on live tv
[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 #ifndef WIN32
29 #include <inttypes.h>
30 #else
31 typedef unsigned long long      uint64_t;
32 #endif
33 #include <ctime>
34 #include <vector>
35 #include <deque>
36 #include <map>
37
38 class cTimeMs {
39   private:
40     uint64_t begin;
41     bool isFirstCheck;
42   public:
43     cTimeMs(int Ms = 0);
44         ///< Creates a timer with ms resolution and an initial timeout of Ms.
45         ///< If Ms is negative the timer is not initialized with the current
46         ///< time.
47     static uint64_t Now(void);
48     void Set(int Ms = 0);
49     bool TimedOut(void);
50     uint64_t Elapsed(void);
51     bool initted;
52 };
53
54 class OSDReceiver;
55
56 class DVBSubtitleCLUT
57 {
58   public:
59     DVBSubtitleCLUT();
60     UCHAR CLUTid;
61     UCHAR version;
62     void setEntry(int bpp, UINT index, UCHAR Y, UCHAR Cr, UCHAR Cb, UCHAR T);
63     const Palette& getPalette(int bpp) const;
64   private:
65     Palette palette2;
66     Palette palette4;
67     Palette palette8;
68     const static ULONG defaultPalette2[4];
69     const static ULONG defaultPalette4[16];
70     const static ULONG defaultPalette8[256];
71 };
72
73 class DVBSubtitleRegion : public Bitmap
74 {
75   public:
76     DVBSubtitleRegion();
77     UCHAR version;
78     UCHAR level;
79     UCHAR CLUTid;
80     void setDepth(UINT);
81     struct ObjectRef
82     {
83       UINT objectID;
84       UINT horizontalPosition;
85       UINT verticalPosition;
86     };
87     typedef std::vector<struct ObjectRef> ObjectList;
88     ObjectList objects;
89 };
90
91 class DVBSubtitlePage
92 {
93   public:
94     DVBSubtitlePage();
95     ULLONG pts;
96     bool dirty;
97     UCHAR version;
98     UINT timeout;
99     UCHAR state;
100     bool serviceAcquired;
101     typedef std::map<UCHAR, DVBSubtitleCLUT> CLUTMap;
102     CLUTMap CLUTs;
103     typedef std::map<UCHAR, DVBSubtitleRegion> RegionMap;
104     RegionMap regions;
105     struct Coords { UINT x; UINT y; };
106     typedef std::map<UCHAR, Coords> DisplayMap;
107     DisplayMap currentDisplay;
108     DisplayMap pendingDisplay;
109
110     void setState(UCHAR s);
111     void updateRegionPalettes(const DVBSubtitleCLUT&);
112 };
113
114 class DVBSubtitleDisplayDefinition: public DisplayRegion
115 {
116 public:
117         DVBSubtitleDisplayDefinition();
118
119     UCHAR version;
120     bool displaywindow;
121
122 };
123
124 class DVBSubtitles : public Thread_TYPE
125 {
126   public:
127     DVBSubtitles(OSDReceiver* tosd = NULL);
128     virtual ~DVBSubtitles() {}
129     void put(const PESPacket& packet);
130     int  start();
131     void stop();
132     void show();
133     void hide();
134     void setOSDMenuVisibility(bool visible);
135
136   private:
137     OSDReceiver* osd;
138     std::deque<PESPacket> worklist;
139     typedef std::map<UINT, DVBSubtitlePage> PageMap;
140     PageMap pages;
141     UINT pageOnDisplay;
142     bool decodePacket(const PESPacket&);
143     void finishPage(const DVBSubtitlePage&);
144     DVBSubtitleDisplayDefinition dds;
145
146     bool osdMenuShowing;
147     bool running;
148     bool showing;
149     bool threadNudged;
150     cTimeMs SubtitleTimeout;
151     bool timeout_clear;
152     void nudge();
153     void lockInput();
154     void unlockInput();
155     void lockOutput();
156     void unlockOutput();
157     void threadMethod();
158     void threadPostStopCleanup() {};
159 #ifndef WIN32
160     pthread_mutex_t input_mutex;
161     pthread_mutex_t output_mutex;
162 #else
163     HANDLE input_mutex;
164     HANDLE output_mutex;
165 #endif
166 };
167
168 #endif