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