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