]> git.vomp.tv Git - vompclient.git/blob - dvbsubtitles.h
Vogel Media Player 2008-11-28
[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 #ifdef WIN32
25 #include "threadwin.h"
26 #else
27 #include "threadp.h"
28 #endif
29 #include "bitmap.h"
30 #include "demuxer.h"
31 #include <ctime>
32 #include <vector>
33 #include <deque>
34 #include <map>
35
36 class OSDReceiver;
37
38 class DVBSubtitleCLUT
39 {
40   public:
41     DVBSubtitleCLUT();
42     UCHAR CLUTid;
43     UCHAR version;
44     void setEntry(int bpp, UINT index, UCHAR Y, UCHAR Cr, UCHAR Cb, UCHAR T);
45     const Palette& getPalette(int bpp) const;
46   private:
47     Palette palette2;
48     Palette palette4;
49     Palette palette8;
50     const static ULONG defaultPalette2[4];
51     const static ULONG defaultPalette4[16];
52     const static ULONG defaultPalette8[256];
53 };
54
55 class DVBSubtitleRegion : public Bitmap
56 {
57   public:
58     DVBSubtitleRegion();
59     UCHAR version;
60     UCHAR level;
61     UCHAR CLUTid;
62     void setDepth(UINT);
63     struct ObjectRef
64     {
65       UINT objectID;
66       UINT horizontalPosition;
67       UINT verticalPosition;
68     };
69     typedef std::vector<struct ObjectRef> ObjectList;
70     ObjectList objects;
71 };
72
73 class DVBSubtitlePage
74 {
75   public:
76     DVBSubtitlePage();
77     ULLONG pts;
78     bool dirty;
79     UCHAR version;
80     UINT timeout;
81     UCHAR state;
82     bool serviceAcquired;
83     typedef std::map<UCHAR, DVBSubtitleCLUT> CLUTMap;
84     CLUTMap CLUTs;
85     typedef std::map<UCHAR, DVBSubtitleRegion> RegionMap;
86     RegionMap regions;
87     struct Coords { UINT x; UINT y; };
88     typedef std::map<UCHAR, Coords> DisplayMap;
89     DisplayMap currentDisplay;
90     DisplayMap pendingDisplay;
91
92     void setState(UCHAR s);
93     void updateRegionPalettes(const DVBSubtitleCLUT&);
94 };
95
96 class DVBSubtitles : public Thread_TYPE
97 {
98   public:
99     DVBSubtitles(OSDReceiver* tosd = NULL);
100     ~DVBSubtitles() {}
101     void put(const PESPacket& packet);
102     int  start();
103     void stop();
104     void show();
105     void hide();
106
107   private:
108     OSDReceiver* osd;
109     std::deque<PESPacket> worklist;
110     typedef std::map<UINT, DVBSubtitlePage> PageMap;
111     PageMap pages;
112     UINT pageOnDisplay;
113     bool decodePacket(const PESPacket&);
114     void finishPage(const DVBSubtitlePage&);
115
116     bool running;
117     bool showing;
118     bool threadNudged;
119     void nudge();
120     void lockInput();
121     void unlockInput();
122     void lockOutput();
123     void unlockOutput();
124     void threadMethod();
125     void threadPostStopCleanup() {};
126 #ifndef WIN32
127     pthread_mutex_t input_mutex;
128     pthread_mutex_t output_mutex;
129 #else
130     HANDLE input_mutex;
131     HANDLE output_mutex;
132 #endif
133 };
134
135 #endif