MythTV  master
freemheg.h
Go to the documentation of this file.
1 /* freemheg.h
2 
3  Copyright (C) David C. J. Matthews 2004 dm at prolingua.co.uk
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License
7  as published by the Free Software Foundation; either version 2
8  of the License, or (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18  Or, point your browser to http://www.gnu.org/copyleft/gpl.html
19 
20 */
21 
22 #if !defined(FREEMHEG_H)
23 #define FREEMHEG_H
24 
25 #include <QtGlobal>
26 #include <QString>
27 #include <QByteArray>
28 #include <QRegion>
29 #include <QRect>
30 #include <QSize>
31 
32 #include <chrono>
33 #include <cstdio>
34 #include <cstdlib>
35 #include <vector>
36 
37 using namespace std::chrono_literals;
38 
39 using MHPointVec = std::vector<int>; // Duplicated in BaseClasses.h
40 
41 class MHDLADisplay;
42 class MHTextDisplay;
43 class MHBitmapDisplay;
44 class MHContext;
45 class MHEG;
46 class MHStream;
47 
48 // Called to create a new instance of the module.
49 extern MHEG *MHCreateEngine(MHContext *context);
50 // Set the logging stream and options.
51 extern void MHSetLogging(FILE *logStream, unsigned int logLevel);
52 
53 // This abstract class is implemented by the MHEG Engine.
54 class MHEG
55 {
56  public:
57  virtual ~MHEG() = default;
58  virtual void SetBooting() = 0;
59  virtual void DrawDisplay(const QRegion& toDraw) = 0;
60  // Run synchronous actions and process any asynchronous events until the queues are empty.
61  // Returns the number of milliseconds until wake-up or 0 if none.
62  virtual std::chrono::milliseconds RunAll(void) = 0;
63  // Generate a UserAction event i.e. a key press.
64  virtual void GenerateUserAction(int nCode) = 0;
65  virtual void EngineEvent(int) = 0;
66  virtual void StreamStarted(MHStream*, bool bStarted = true) = 0;
67 };
68 
69 // Logging control
70 enum {
71  MHLogError = 1, // Log errors - these are errors that need to be reported to the user.
72  MHLogWarning = 2, // Log warnings - typically bad MHEG which might be an error in this program
73  MHLogNotifications = 4, // General things to log.
74  MHLogScenes = 8, // Print each application and scene
75  MHLogActions = 16, // Print each action before it is run.
76  MHLogLinks = 32, // Print each link when it is fired and each event as it is queued
77  MHLogDetail = 64 // Detailed evaluation of each action.
78 };
79 
80 #define MHLogAll (MHLogError|MHLogWarning|MHLogNotifications|MHLogScenes|MHLogActions|MHLogLinks|MHLogDetail)
81 
82 class MHRgba
83 {
84  public:
85  MHRgba(int red, int green, int blue, int alpha):
86  m_red(red), m_green(green), m_blue(blue), m_alpha(alpha) {};
87  MHRgba() = default;
88  int red() const { return m_red; }
89  int green() const { return m_green; }
90  int blue() const { return m_blue; }
91  int alpha() const { return m_alpha; }
92  private:
93  unsigned char m_red{0}, m_green{0}, m_blue{0}, m_alpha{0};
94 };
95 
96 // This abstract class provides operations that the surrounding context must provide
97 // for the MHEG engine.
98 class MHContext
99 {
100  public:
101  virtual ~MHContext() = default; // Declared to avoid warnings
102  // Interface to MHEG engine.
103 
104  // Test for an object in the carousel. Returns true if the object is present and
105  // so a call to GetCarouselData will not block and will return the data.
106  // Returns false if the object is not currently present because it has not
107  // yet appeared and also if it is not present in the containing directory.
108  virtual bool CheckCarouselObject(const QString& objectPath) = 0;
109 
110  // Get an object from the carousel. Returns true and sets the data if
111  // it was able to retrieve the named object. Blocks if the object seems
112  // to be present but has not yet appeared. Returns false if the object
113  // cannot be retrieved.
114  virtual bool GetCarouselData(const QString& objectPath, QByteArray &result) = 0;
115 
116  // Set the input register. This sets the keys that are to be handled by MHEG. Flushes the key queue.
117  virtual void SetInputRegister(int nReg) = 0;
118 
119  // An area of the screen/image needs to be redrawn.
120  virtual void RequireRedraw(const QRegion &region) = 0;
121 
122  // Creation functions for various visibles.
123  virtual MHDLADisplay *CreateDynamicLineArt(bool isBoxed, MHRgba lineColour, MHRgba fillColour) = 0;
124  virtual MHTextDisplay *CreateText(void) = 0;
125  virtual MHBitmapDisplay *CreateBitmap(bool tiled) = 0;
126  // Additional drawing functions.
127  // Draw a rectangle in the specified colour/transparency.
128  virtual void DrawRect(int xPos, int yPos, int width, int height, MHRgba colour) = 0;
129  virtual void DrawVideo(const QRect &videoRect, const QRect &displayRect) = 0;
130  virtual void DrawBackground(const QRegion &reg) = 0;
131 
132  // Tuning. Get the index corresponding to a given channel.
133  virtual int GetChannelIndex(const QString &str) = 0;
134  // Get netId etc from the channel index.
135  virtual bool GetServiceInfo(int channelId, int &netId, int &origNetId,
136  int &transportId, int &serviceId) = 0;
137  // Tune to an index returned by GetChannelIndex
138  virtual bool TuneTo(int channel, int tuneinfo) = 0;
139 
140  // Check whether we have requested a stop. Returns true and signals
141  // the m_stopped condition if we have.
142  virtual bool CheckStop(void) = 0;
143 
144  // Begin playing the specified stream
145  virtual bool BeginStream(const QString &str, MHStream* notify = nullptr) = 0;
146  // Stop playing stream
147  virtual void EndStream() = 0;
148  // Begin playing audio component
149  virtual bool BeginAudio(int tag) = 0;
150  // Stop playing audio
151  virtual void StopAudio() = 0;
152  // Begin displaying video component
153  virtual bool BeginVideo(int tag) = 0;
154  // Stop displaying video
155  virtual void StopVideo() = 0;
156  // Get current stream position in mS, -1 if unknown
157  virtual std::chrono::milliseconds GetStreamPos() = 0;
158  // Get current stream size in mS, -1 if unknown
159  virtual std::chrono::milliseconds GetStreamMaxPos() = 0;
160  // Set current stream position in mS
161  virtual std::chrono::milliseconds SetStreamPos(std::chrono::milliseconds) = 0;
162  // Play or pause a stream
163  virtual void StreamPlay(bool play = true) = 0;
164 
165  // Get the context id strings.
166  virtual const char *GetReceiverId(void) = 0;
167  virtual const char *GetDSMCCId(void) = 0;
168 
169  // InteractionChannel
170  virtual int GetICStatus() = 0; // 0= Active, 1= Inactive, 2= Disabled
171 };
172 
173 // Dynamic Line Art objects record a sequence of drawing actions.
175 {
176  public:
177  virtual ~MHDLADisplay() = default;
178  // Draw the completed drawing onto the display.
179  virtual void Draw(int x, int y) = 0;
180  // Set the box size. Also clears the drawing.
181  virtual void SetSize(int width, int height) = 0;
182  virtual void SetLineSize(int width) = 0;
183  virtual void SetLineColour(MHRgba colour) = 0;
184  virtual void SetFillColour(MHRgba colour) = 0;
185  // Clear the drawing
186  virtual void Clear() = 0;
187  // Operations to add items to the drawing.
188  virtual void DrawLine(int x1, int y1, int x2, int y2) = 0;
189  virtual void DrawBorderedRectangle(int x, int y, int width, int height) = 0;
190  virtual void DrawOval(int x, int y, int width, int height) = 0;
191  virtual void DrawArcSector(int x, int y, int width, int height, int start, int arc, bool isSector) = 0;
192  virtual void DrawPoly(bool isFilled, const MHPointVec& xArray, const MHPointVec& yArray) = 0;
193 };
194 
196  public:
197  virtual ~MHTextDisplay() = default;
198  // Draw the completed drawing onto the display. x and y give the position of the image
199  // relative to the screen. rect gives the bounding box for the image, again relative to
200  // the screen.
201  virtual void Draw(int x, int y) = 0;
202  virtual void SetSize(int width, int height) = 0;
203  virtual void SetFont(int size, bool isBold, bool isItalic) = 0;
204  // Get the size of a piece of text. If maxSize is >= 0 it sets strLen to the number
205  // of characters that will fit in that number of bits.
206  virtual QRect GetBounds(const QString &str, int &strLen, int maxSize = -1) = 0;
207  virtual void Clear(void) = 0;
208  virtual void AddText(int x, int y, const QString &, MHRgba colour) = 0;
209 };
210 
212 {
213  public:
214  virtual ~MHBitmapDisplay() = default;
215  // Draw the completed drawing onto the display. x and y give the position of the image
216  // relative to the screen. rect gives the bounding box for the image, again relative to
217  // the screen.
218  virtual void Draw(int x, int y, QRect rect, bool tiled, bool bUnder) = 0;
219  // Creation functions
220  virtual void CreateFromPNG(const unsigned char *data, int length) = 0;
221  virtual void CreateFromMPEG(const unsigned char *data, int length) = 0;
222  virtual void CreateFromJPEG(const unsigned char *data, int length) = 0;
223  // Scale the bitmap. Only used for image derived from MPEG I-frames.
224  virtual void ScaleImage(int newWidth, int newHeight) = 0;
225  // Information about the image.
226  virtual QSize GetSize() = 0;
227  virtual bool IsOpaque() = 0; // True only if the visible area is fully opaque
228 
229 };
230 
231 #endif
channel
QDomElement channel
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:501
MHSetLogging
void MHSetLogging(FILE *logStream, unsigned int logLevel)
Definition: Engine.cpp:1491
MHStream
Definition: Stream.h:32
MHLogLinks
@ MHLogLinks
Definition: freemheg.h:76
MHDLADisplay
Definition: freemheg.h:174
MHLogDetail
@ MHLogDetail
Definition: freemheg.h:77
logLevel
LogLevel_t logLevel
Definition: logging.cpp:88
x2
static int x2
Definition: mythsocket.cpp:58
MHRgba::alpha
int alpha() const
Definition: freemheg.h:91
MHLogScenes
@ MHLogScenes
Definition: freemheg.h:74
MHCreateEngine
MHEG * MHCreateEngine(MHContext *context)
Definition: Engine.cpp:43
MHLogActions
@ MHLogActions
Definition: freemheg.h:75
mythburn.FILE
int FILE
Definition: mythburn.py:139
MHLogNotifications
@ MHLogNotifications
Definition: freemheg.h:73
MHRgba::MHRgba
MHRgba(int red, int green, int blue, int alpha)
Definition: freemheg.h:85
x1
static int x1
Definition: mythsocket.cpp:57
MHBitmapDisplay
Definition: freemheg.h:211
MHRgba::blue
int blue() const
Definition: freemheg.h:90
MHLogWarning
@ MHLogWarning
Definition: freemheg.h:72
MHLogError
@ MHLogError
Definition: freemheg.h:71
Clear
#define Clear(a)
Definition: audiooutputopensles.cpp:47
MHContext
Definition: freemheg.h:98
MHRgba::red
int red() const
Definition: freemheg.h:88
MHRgba::green
int green() const
Definition: freemheg.h:89
MHEG
Definition: freemheg.h:54
MHTextDisplay
Definition: freemheg.h:195
MHRgba
Definition: freemheg.h:82
MHPointVec
std::vector< int > MHPointVec
Definition: BaseClasses.h:34