MythTV  master
mhi.h
Go to the documentation of this file.
1 #ifndef _MHI_H_
2 #define _MHI_H_
3 
4 // Misc header
5 #include <ft2build.h>
6 #include FT_FREETYPE_H
7 
8 // STL headers
9 #include <list>
10 #include <vector>
11 using namespace std;
12 
13 // Qt headers
14 #include <QWaitCondition>
15 #include <QRunnable>
16 #include <QString>
17 #include <QMutex>
18 #include <QImage>
19 #include <QList>
20 #include <QRect>
21 #include <QPair>
22 #include <QMap> // for QMap
23 #include <QRegion> // for QRegion
24 #include <QSize> // for QSize
25 
26 // MythTV headers
27 #include "mythconfig.h"
28 #include "../libmythfreemheg/freemheg.h"
29 #include "mhegic.h"
30 #include "mythdeque.h"
31 
32 class MythPainter;
33 class InteractiveScreen;
34 class DSMCCPacket;
35 class MHIImageData;
36 class MHIContext;
37 class MythAVCopy;
38 class Dsmcc;
39 class InteractiveTV;
40 class MHStream;
41 class MThread;
42 class QByteArray;
43 
47 class MHIContext : public MHContext, public QRunnable
48 {
49  public:
50  explicit MHIContext(InteractiveTV *parent);
51  virtual ~MHIContext();
52 
53  void QueueDSMCCPacket(unsigned char *data, int length, int componentTag,
54  unsigned carouselId, int dataBroadcastId);
55  // A NetworkBootInfo sub-descriptor is present in the PMT.
56  void SetNetBootInfo(const unsigned char *data, uint length);
58  void Restart(int chanid, int sourceid, bool isLive);
59  // Offer a key press. Returns true if it accepts it.
60  // This will depend on the current profile.
61  bool OfferKey(const QString& key);
63  void UpdateOSD(InteractiveScreen *osdWindow, MythPainter *osdPainter);
65  void Reinit(const QRect &videoRect, const QRect &dispRect, float aspect);
66 
68  void StopEngine(void);
69 
70  // Test for an object in the carousel.
71  // Returns true if the object is present and
72  // so a call to GetCarouselData will not block and will return the data.
73  // Returns false if the object is not currently present because it has not
74  // yet appeared and also if it is not present in the containing directory.
75  bool CheckCarouselObject(QString objectPath) override; // MHContext
76 
77  // Get an object from the carousel. Returns true and sets the data if
78  // it was able to retrieve the named object. Blocks if the object seems
79  // to be present but has not yet appeared. Returns false if the object
80  // cannot be retrieved.
81  bool GetCarouselData(QString objectPath, QByteArray &result) override; // MHContext
82 
83  // Set the input register. This sets the keys that are to be handled
84  // by MHEG. Flushes the key queue.
85  void SetInputRegister(int num) override; // MHContext
86 
88  void RequireRedraw(const QRegion &region) override; // MHContext
89 
91  bool CheckStop(void) override // MHContext
92  { return m_stop; }
93 
95  void GetInitialStreams(int &audioTag, int &videoTag);
96 
98  MHDLADisplay *CreateDynamicLineArt(
99  bool isBoxed, MHRgba lineColour, MHRgba fillColour) override; // MHContext
100  MHTextDisplay *CreateText(void) override; // MHContext
101  MHBitmapDisplay *CreateBitmap(bool tiled) override; // MHContext
103  void DrawRect(int xPos, int yPos, int width, int height,
104  MHRgba colour) override; // MHContext
105  void DrawBackground(const QRegion &reg) override; // MHContext
106  void DrawVideo(const QRect &videoRect, const QRect &dispRect) override; // MHContext
107 
108  void DrawImage(int x, int y, const QRect &rect, const QImage &image,
109  bool bScaled = false, bool bUnder = false);
110 
111  int GetChannelIndex(const QString &str) override; // MHContext
113  bool GetServiceInfo(int channelId, int &netId, int &origNetId,
114  int &transportId, int &serviceId) override; // MHContext
115  bool TuneTo(int channel, int tuneinfo) override; // MHContext
116 
118  bool BeginStream(const QString &str, MHStream* notify) override; // MHContext
119  void EndStream() override; // MHContext
120  // Called when the stream starts or stops
121  bool StreamStarted(bool bStarted = true);
123  bool BeginAudio(int tag) override; // MHContext
125  void StopAudio() override; // MHContext
127  bool BeginVideo(int tag) override; // MHContext
129  void StopVideo() override; // MHContext
130  // Get current stream position, -1 if unknown
131  long GetStreamPos() override; // MHContext
132  // Get current stream size, -1 if unknown
133  long GetStreamMaxPos() override; // MHContext
134  // Set current stream position
135  long SetStreamPos(long) override; // MHContext
136  // Play or pause a stream
137  void StreamPlay(bool) override; // MHContext
138 
139  // Get the context id strings. The format of these strings is specified
140  // by the UK MHEG profile.
141  const char *GetReceiverId(void) override // MHContext
142  { return "MYT001001"; } // Version number?
143  const char *GetDSMCCId(void) override // MHContext
144  { return "DSMMYT001"; } // DSMCC version.
145 
146  // InteractionChannel
147  // 0= Active, 1= Inactive, 2= Disabled
148  int GetICStatus() override; // MHContext
149 
150  // Operations used by the display classes
151  // Add an item to the display vector
152  void AddToDisplay(const QImage &image, const QRect &rect, bool bUnder = false);
153  int ScaleX(int, bool roundup = false) const;
154  int ScaleY(int, bool roundup = false) const;
155  QRect Scale(const QRect &r) const;
156  int ScaleVideoX(int, bool roundup = false) const;
157  int ScaleVideoY(int, bool roundup = false) const;
158  QRect ScaleVideo(const QRect &r) const;
159 
160  FT_Face GetFontFace(void) { return m_face; }
161  bool IsFaceLoaded(void) { return m_face_loaded; }
162  bool LoadFont(const QString& name);
163  bool ImageUpdated(void) { return m_updated; }
164 
165  static const int StdDisplayWidth = 720;
166  static const int StdDisplayHeight = 576;
167 
168  protected:
169  void run(void) override; // QRunnable
170  void ProcessDSMCCQueue(void);
171  void NetworkBootRequested(void);
172  void ClearDisplay(void);
173  void ClearQueue(void);
174  bool LoadChannelCache();
175  bool GetDSMCCObject(const QString &objectPath, QByteArray &result);
176  bool CheckAccess(const QString &objectPath, QByteArray &cert);
177 
179 
180  Dsmcc *m_dsmcc; // Pointer to the DSMCC object carousel.
181  QMutex m_dsmccLock;
183 
184  MHInteractionChannel m_ic; // Interaction channel
186 
187  QMutex m_keyLock;
190 
191  MHEG *m_engine; // Pointer to the MHEG engine
192 
193  mutable QMutex m_runLock;
194  QWaitCondition m_engine_wait; // protected by m_runLock
195  bool m_stop; // protected by m_runLock
197  bool m_updated;
198 
199  list<MHIImageData*> m_display; // List of items to display
200 
201  FT_Face m_face;
203 
205 
208  bool m_isLive;
210 
213  QList<int> m_tuneinfo;
214 
216  vector<unsigned char> m_nbiData;
217 
218  QRect m_videoRect, m_videoDisplayRect;
220 
221  // Channel index database cache
222  typedef QPair< int, int > Val_t; // transportid, chanid
223  typedef QPair< int, int > Key_t; // networkid, serviceid
224  typedef QMap< Key_t, Val_t > ChannelCache_t;
227  static inline int Tid(ChannelCache_t::const_iterator it) { return it->first; }
228  static inline int Cid(ChannelCache_t::const_iterator it) { return it->second; }
229  static inline int Nid(ChannelCache_t::const_iterator it) { return it.key().first; }
230  static inline int Sid(ChannelCache_t::const_iterator it) { return it.key().second; }
231 };
232 
233 // Object for drawing text.
234 class MHIText : public MHTextDisplay
235 {
236  public:
237  explicit MHIText(MHIContext *parent);
238  virtual ~MHIText() = default;
239 
240  void Draw(int x, int y) override; // MHTextDisplay
241  void Clear(void) override; // MHTextDisplay
242  void AddText(int x, int y, const QString &, MHRgba colour) override; // MHTextDisplay
243 
244  void SetSize(int width, int height) override; // MHTextDisplay
245  void SetFont(int size, bool isBold, bool isItalic) override; // MHTextDisplay
246 
247  QRect GetBounds(const QString &str, int &strLen, int maxSize = -1) override; // MHTextDisplay
248 
249  public:
251  QImage m_image;
255  int m_width;
256  int m_height;
257 };
258 
263 {
264  private:
265  MHIBitmap(const MHIBitmap &) = delete; // not copyable
266  MHIBitmap &operator=(const MHIBitmap &) = delete; // not copyable
267 
268  public:
269  MHIBitmap(MHIContext *parent, bool tiled);
270  virtual ~MHIBitmap();
271 
273  void CreateFromPNG(const unsigned char *data, int length) override; // MHBitmapDisplay
274 
276  void CreateFromMPEG(const unsigned char *data, int length) override; // MHBitmapDisplay
277 
279  void CreateFromJPEG(const unsigned char *data, int length) override; // MHBitmapDisplay
280 
290  void Draw(int x, int y, QRect rect, bool tiled, bool bUnder) override; // MHBitmapDisplay
291 
293  void ScaleImage(int newWidth, int newHeight) override; // MHBitmapDisplay
294 
295  // Gets
296  QSize GetSize(void) override { return m_image.size(); } // MHBitmapDisplay
297  bool IsOpaque(void) override { return !m_image.isNull() && m_opaque; } // MHBitmapDisplay
298 
299  public:
301  bool m_tiled;
302  QImage m_image;
303  bool m_opaque;
305 };
306 
310 class MHIDLA : public MHDLADisplay
311 {
312  public:
313  MHIDLA(MHIContext *parent, bool isBoxed,
314  MHRgba lineColour, MHRgba fillColour)
315  : m_parent(parent), m_width(0),
316  m_height(0), m_boxed(isBoxed),
317  m_boxLineColour(lineColour), m_boxFillColour(fillColour),
318  m_lineWidth(0) {}
320  void Draw(int x, int y) override; // MHDLADisplay
322  void SetSize(int width, int height) override // MHDLADisplay
323  {
324  m_width = width;
325  m_height = height;
326  Clear();
327  }
328  void SetLineSize(int width) override // MHDLADisplay
329  { m_lineWidth = width; }
330  void SetLineColour(MHRgba colour) override // MHDLADisplay
331  { m_lineColour = colour; }
332  void SetFillColour(MHRgba colour) override // MHDLADisplay
333  { m_fillColour = colour; }
334 
336  void Clear(void) override; // MHDLADisplay
337 
338  // add items to the drawing.
339  void DrawLine(int x1, int y1, int x2, int y2) override; // MHDLADisplay
340  void DrawBorderedRectangle(int x, int y, int width, int height) override; // MHDLADisplay
341  void DrawOval(int x, int y, int width, int height) override; // MHDLADisplay
342  void DrawArcSector(int x, int y, int width, int height,
343  int start, int arc, bool isSector) override; // MHDLADisplay
344  void DrawPoly(bool isFilled, int nPoints, const int *xArray, const int *yArray) override; // MHDLADisplay
345 
346  protected:
347  void DrawRect(int x, int y, int width, int height, MHRgba colour);
348  void DrawLineSub(int x1, int y1, int x2, int y2, bool swapped);
349 
350  protected:
352  QImage m_image;
353  int m_width;
354  int m_height;
355  bool m_boxed;
361 };
362 
367 {
368  public:
369  DSMCCPacket(unsigned char *data, int length, int tag,
370  unsigned car, int dbid)
371  : m_data(data), m_length(length),
372  m_componentTag(tag), m_carouselId(car),
373  m_dataBroadcastId(dbid)
374  {
375  }
376 
378  {
379  free(m_data);
380  }
381 
382  public:
383  unsigned char *m_data;
384  int m_length;
386  unsigned m_carouselId;
388 };
389 
390 #endif // _MHI_H_
unsigned m_carouselId
Definition: mhi.h:386
int m_height
Height of the drawing.
Definition: mhi.h:354
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
bool m_face_loaded
Definition: mhi.h:202
QMutex m_dsmccLock
Definition: mhi.h:181
int m_currentChannel
Definition: mhi.h:206
ChannelCache_t m_channelCache
Definition: mhi.h:225
bool m_boxed
Does it have a border?
Definition: mhi.h:355
Data for items in the interactive television display stack.
Definition: mhi.cpp:66
MHStream * m_notify
Definition: mhi.h:185
MThread * m_engineThread
Definition: mhi.h:204
static int Tid(ChannelCache_t::const_iterator it)
Definition: mhi.h:227
int m_currentStream
Definition: mhi.h:207
static int Nid(ChannelCache_t::const_iterator it)
Definition: mhi.h:229
Object for displaying Dynamic Line Art.
Definition: mhi.h:310
MythAVCopy Copy AVFrame<->frame, performing the required conversion if any.
Definition: mythavutil.h:114
int m_keyProfile
Definition: mhi.h:189
FT_Face GetFontFace(void)
Definition: mhi.h:160
Data for the queued DSMCC tables.
Definition: mhi.h:366
Definition: dsmcc.h:75
bool m_tiled
Definition: mhi.h:301
bool m_stop
Definition: mhi.h:195
const char * GetReceiverId(void) override
Definition: mhi.h:141
unsigned int uint
Definition: compat.h:140
bool m_isLive
Definition: mhi.h:208
QWaitCondition m_engine_wait
Definition: mhi.h:194
QMutex m_display_lock
Definition: mhi.h:196
bool ImageUpdated(void)
Definition: mhi.h:163
QRect m_displayRect
Definition: mhi.h:219
MHIContext * m_parent
Definition: mhi.h:250
MHRgba m_lineColour
Current line colour.
Definition: mhi.h:358
static int Sid(ChannelCache_t::const_iterator it)
Definition: mhi.h:230
unsigned char r
Definition: ParseText.cpp:329
int m_length
Definition: mhi.h:384
QList< int > m_tuneinfo
Definition: mhi.h:213
bool IsFaceLoaded(void)
Definition: mhi.h:161
int m_width
Definition: mhi.h:255
QPair< int, int > Key_t
Definition: mhi.h:223
unsigned char * m_data
Definition: mhi.h:383
void SetLineColour(MHRgba colour) override
Definition: mhi.h:330
static int run(MythMediaDevice *dev=nullptr, bool startRandomShow=false)
Contains various utility functions for interactive television.
Definition: mhi.h:47
Definition: freemheg.h:48
MHRgba m_boxFillColour
Fill colour for the background.
Definition: mhi.h:357
int m_dataBroadcastId
Definition: mhi.h:387
bool CheckStop(void) override
Check whether we have requested a stop.
Definition: mhi.h:91
static int x2
Definition: mythsocket.cpp:61
MythDeque< int > m_keyQueue
Definition: mhi.h:188
int m_width
Width of the drawing.
Definition: mhi.h:353
bool m_opaque
Definition: mhi.h:303
QPair< int, int > Val_t
Definition: mhi.h:222
MHIDLA(MHIContext *parent, bool isBoxed, MHRgba lineColour, MHRgba fillColour)
Definition: mhi.h:313
QMutex m_channelMutex
Definition: mhi.h:226
DSMCCPacket(unsigned char *data, int length, int tag, unsigned car, int dbid)
Definition: mhi.h:369
uint m_lastNbiVersion
Definition: mhi.h:215
Dsmcc * m_dsmcc
Definition: mhi.h:180
~DSMCCPacket()
Definition: mhi.h:377
const char * name
Definition: ParseText.cpp:328
InteractiveTV * m_parent
Definition: mhi.h:178
FT_Face m_face
Definition: mhi.h:201
bool m_fontBold
Definition: mhi.h:254
static int Cid(ChannelCache_t::const_iterator it)
Definition: mhi.h:228
const char * GetDSMCCId(void) override
Definition: mhi.h:143
int m_audioTag
Definition: mhi.h:211
MHIContext * m_parent
Definition: mhi.h:351
int m_height
Definition: mhi.h:256
int m_lineWidth
Current line width.
Definition: mhi.h:360
QRect m_videoRect
Definition: mhi.h:218
MHRgba m_fillColour
Current fill colour.
Definition: mhi.h:359
vector< unsigned char > m_nbiData
Definition: mhi.h:216
QSize GetSize(void) override
Definition: mhi.h:296
bool IsOpaque(void) override
Definition: mhi.h:297
Definition: mhi.h:234
MHEG * m_engine
Definition: mhi.h:191
QImage m_image
Definition: mhi.h:302
MythAVCopy * m_copyCtx
Definition: mhi.h:304
MHIContext * m_parent
Definition: mhi.h:300
MythDeque< DSMCCPacket * > m_dsmccQueue
Definition: mhi.h:182
int m_videoTag
Definition: mhi.h:212
MHInteractionChannel m_ic
Definition: mhi.h:184
MHRgba m_boxLineColour
Line colour for the background.
Definition: mhi.h:356
QMap< Key_t, Val_t > ChannelCache_t
Definition: mhi.h:224
Object for drawing bitmaps.
Definition: mhi.h:262
list< MHIImageData * > m_display
Definition: mhi.h:199
bool m_updated
Definition: mhi.h:197
QMutex m_keyLock
Definition: mhi.h:187
int m_fontsize
Definition: mhi.h:252
void SetSize(int width, int height) override
Set the box size. Also clears the drawing.
Definition: mhi.h:322
int m_currentSource
Definition: mhi.h:209
void SetFillColour(MHRgba colour) override
Definition: mhi.h:332
int m_componentTag
Definition: mhi.h:385
QImage m_image
Definition: mhi.h:251
#define Clear(a)
QMutex m_runLock
Definition: mhi.h:193
This is the interface between an MHEG engine and a MythTV TV object.
Definition: interactivetv.h:12
bool m_fontItalic
Definition: mhi.h:253
static int x1
Definition: mythsocket.cpp:60
void SetLineSize(int width) override
Definition: mhi.h:328
QImage m_image
Definition: mhi.h:352