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