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