]> git.vomp.tv Git - vompclient.git/blob - src/dvbsubtitles.h
CWFs
[vompclient.git] / src / 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, see <https://www.gnu.org/licenses/>.
18 */
19
20 #ifndef DVBSUBTITLES_H
21 #define DVBSUBTITLES_H
22
23 #include <ctime>
24 #include <vector>
25 #include <deque>
26 #include <map>
27 #include <chrono>
28 #include <mutex>
29 #include <thread>
30 #include <condition_variable>
31 #ifndef WIN32
32 #include <inttypes.h>
33 #else
34 typedef unsigned long long uint64_t;
35 #endif
36
37 #include "bitmap.h"
38 #include "demuxer.h"
39
40 class OSDReceiver;
41
42 class DVBSubtitleCLUT
43 {
44   public:
45     DVBSubtitleCLUT();
46     u1 CLUTid;
47     u1 version;
48     void setEntry(int bpp, u4 index, u1 Y, u1 Cr, u1 Cb, u1 T);
49     const Palette& getPalette(int bpp) const;
50   private:
51     Palette palette2;
52     Palette palette4;
53     Palette palette8;
54     const static u4 defaultPalette2[4];
55     const static u4 defaultPalette4[16];
56     const static u4 defaultPalette8[256];
57 };
58
59 class DVBSubtitleRegion : public Bitmap
60 {
61   public:
62     DVBSubtitleRegion();
63     u1 version;
64     u1 level;
65     u1 CLUTid;
66     void setDepth(u4);
67     struct ObjectRef
68     {
69       u4 objectID;
70       u4 horizontalPosition;
71       u4 verticalPosition;
72     };
73     typedef std::vector<struct ObjectRef> ObjectList;
74     ObjectList objects;
75 };
76
77 class DVBSubtitlePage
78 {
79   public:
80     DVBSubtitlePage();
81     u8 pts;
82     bool dirty;
83     u1 version;
84     u4 timeout;
85     u1 state;
86     bool serviceAcquired;
87     typedef std::map<u1, DVBSubtitleCLUT> CLUTMap;
88     CLUTMap CLUTs;
89     typedef std::map<u1, DVBSubtitleRegion> RegionMap;
90     RegionMap regions;
91     struct Coords { u4 x; u4 y; };
92     typedef std::map<u1, Coords> DisplayMap;
93     DisplayMap currentDisplay;
94     DisplayMap pendingDisplay;
95
96     void setState(u1 s);
97     void updateRegionPalettes(const DVBSubtitleCLUT&);
98 };
99
100 class DVBSubtitleDisplayDefinition: public DisplayRegion
101 {
102 public:
103         DVBSubtitleDisplayDefinition();
104
105     u1 version;
106     bool displaywindow;
107
108 };
109
110 class DVBSubtitles
111 {
112   public:
113     DVBSubtitles(OSDReceiver* tosd = NULL);
114     virtual ~DVBSubtitles() {}
115     void put(const PESPacket& packet);
116     void start();
117     void stop();
118     void show();
119     void hide();
120     void pause();
121     void unPause();
122     void setOSDMenuVisibility(bool visible);
123     bool isShowing() { return showing; }
124
125   private:
126     OSDReceiver* osd;
127     std::deque<PESPacket> worklist;
128     typedef std::map<u4, DVBSubtitlePage> PageMap;
129     PageMap pages;
130     u4 pageOnDisplay;
131     bool decodePacket(const PESPacket&);
132     void finishPage(const DVBSubtitlePage&);
133     void clearDisplayedPages();
134     DVBSubtitleDisplayDefinition dds;
135
136     bool osdMenuShowing;
137     bool running;
138     bool showing;
139     bool paused{};
140     std::chrono::time_point<std::chrono::system_clock> subtitleTimeoutPoint;
141     bool subtitleTimeoutPointActive{};
142     void threadMethod();
143
144     std::mutex input_mutex; // Also use as thread/cond/signal mutex, master loop etc.
145     std::mutex output_mutex;
146
147     std::thread dvbsThread;
148     std::condition_variable dvbsCond;
149
150     bool signalRecalcWLTO{};
151     bool signalStop{};
152     bool signalPause{};
153
154 //    FILE* DBG;
155 };
156
157 #endif