]> git.vomp.tv Git - vompclient.git/blob - dvbsubtitles.h
Convert PlayerRadioRec to std::thread
[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, 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     UCHAR CLUTid;
47     UCHAR version;
48     void setEntry(int bpp, UINT index, UCHAR Y, UCHAR Cr, UCHAR Cb, UCHAR T);
49     const Palette& getPalette(int bpp) const;
50   private:
51     Palette palette2;
52     Palette palette4;
53     Palette palette8;
54     const static ULONG defaultPalette2[4];
55     const static ULONG defaultPalette4[16];
56     const static ULONG defaultPalette8[256];
57 };
58
59 class DVBSubtitleRegion : public Bitmap
60 {
61   public:
62     DVBSubtitleRegion();
63     UCHAR version;
64     UCHAR level;
65     UCHAR CLUTid;
66     void setDepth(UINT);
67     struct ObjectRef
68     {
69       UINT objectID;
70       UINT horizontalPosition;
71       UINT verticalPosition;
72     };
73     typedef std::vector<struct ObjectRef> ObjectList;
74     ObjectList objects;
75 };
76
77 class DVBSubtitlePage
78 {
79   public:
80     DVBSubtitlePage();
81     ULLONG pts;
82     bool dirty;
83     UCHAR version;
84     UINT timeout;
85     UCHAR state;
86     bool serviceAcquired;
87     typedef std::map<UCHAR, DVBSubtitleCLUT> CLUTMap;
88     CLUTMap CLUTs;
89     typedef std::map<UCHAR, DVBSubtitleRegion> RegionMap;
90     RegionMap regions;
91     struct Coords { UINT x; UINT y; };
92     typedef std::map<UCHAR, Coords> DisplayMap;
93     DisplayMap currentDisplay;
94     DisplayMap pendingDisplay;
95
96     void setState(UCHAR s);
97     void updateRegionPalettes(const DVBSubtitleCLUT&);
98 };
99
100 class DVBSubtitleDisplayDefinition: public DisplayRegion
101 {
102 public:
103         DVBSubtitleDisplayDefinition();
104
105     UCHAR 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<UINT, DVBSubtitlePage> PageMap;
129     PageMap pages;
130     UINT 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     std::chrono::time_point<std::chrono::system_clock> subtitleTimeoutPoint;
140     bool subtitleTimeoutPointActive{};
141     void threadMethod();
142
143     std::mutex input_mutex; // Also use as thread/cond/signal mutex, master loop etc.
144     std::mutex output_mutex;
145
146     std::thread dvbsThread;
147     std::condition_variable dvbsCond;
148
149     bool signalRecalcWLTO{};
150     bool signalStop{};
151     bool signalPause{};
152
153     FILE* DBG;
154 };
155
156 #endif