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