]> git.vomp.tv Git - vompclient.git/blob - dvbsubtitles.h
More compiler warning fixes
[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 };
52
53 class OSDReceiver;
54
55 class DVBSubtitleCLUT
56 {
57   public:
58     DVBSubtitleCLUT();
59     UCHAR CLUTid;
60     UCHAR version;
61     void setEntry(int bpp, UINT index, UCHAR Y, UCHAR Cr, UCHAR Cb, UCHAR T);
62     const Palette& getPalette(int bpp) const;
63   private:
64     Palette palette2;
65     Palette palette4;
66     Palette palette8;
67     const static ULONG defaultPalette2[4];
68     const static ULONG defaultPalette4[16];
69     const static ULONG defaultPalette8[256];
70 };
71
72 class DVBSubtitleRegion : public Bitmap
73 {
74   public:
75     DVBSubtitleRegion();
76     UCHAR version;
77     UCHAR level;
78     UCHAR CLUTid;
79     void setDepth(UINT);
80     struct ObjectRef
81     {
82       UINT objectID;
83       UINT horizontalPosition;
84       UINT verticalPosition;
85     };
86     typedef std::vector<struct ObjectRef> ObjectList;
87     ObjectList objects;
88 };
89
90 class DVBSubtitlePage
91 {
92   public:
93     DVBSubtitlePage();
94     ULLONG pts;
95     bool dirty;
96     UCHAR version;
97     UINT timeout;
98     UCHAR state;
99     bool serviceAcquired;
100     typedef std::map<UCHAR, DVBSubtitleCLUT> CLUTMap;
101     CLUTMap CLUTs;
102     typedef std::map<UCHAR, DVBSubtitleRegion> RegionMap;
103     RegionMap regions;
104     struct Coords { UINT x; UINT y; };
105     typedef std::map<UCHAR, Coords> DisplayMap;
106     DisplayMap currentDisplay;
107     DisplayMap pendingDisplay;
108
109     void setState(UCHAR s);
110     void updateRegionPalettes(const DVBSubtitleCLUT&);
111 };
112
113 class DVBSubtitleDisplayDefinition: public DisplayRegion
114 {
115 public:
116         DVBSubtitleDisplayDefinition();
117
118     UCHAR version;
119     bool displaywindow;
120
121 };
122
123 class DVBSubtitles : public Thread_TYPE
124 {
125   public:
126     DVBSubtitles(OSDReceiver* tosd = NULL);
127     virtual ~DVBSubtitles() {}
128     void put(const PESPacket& packet);
129     int  start();
130     void stop();
131     void show();
132     void hide();
133     void setOSDMenuVisibility(bool visible);
134
135   private:
136     OSDReceiver* osd;
137     std::deque<PESPacket> worklist;
138     typedef std::map<UINT, DVBSubtitlePage> PageMap;
139     PageMap pages;
140     UINT pageOnDisplay;
141     bool decodePacket(const PESPacket&);
142     void finishPage(const DVBSubtitlePage&);
143     DVBSubtitleDisplayDefinition dds;
144
145     bool osdMenuShowing;
146     bool running;
147     bool showing;
148     bool threadNudged;
149     cTimeMs SubtitleTimeout;
150     bool timeout_clear;
151     void nudge();
152     void lockInput();
153     void unlockInput();
154     void lockOutput();
155     void unlockOutput();
156     void threadMethod();
157     void threadPostStopCleanup() {};
158 #ifndef WIN32
159     pthread_mutex_t input_mutex;
160     pthread_mutex_t output_mutex;
161 #else
162     HANDLE input_mutex;
163     HANDLE output_mutex;
164 #endif
165 };
166
167 #endif