MythTV  master
output.h
Go to the documentation of this file.
1 // -*- Mode: c++ -*-
2 // Copyright (c) 2000-2001 Brad Hughes <bhughes@trolltech.com>
3 //
4 // Use, modification and distribution is allowed without limitation,
5 // warranty, or liability of any kind.
6 //
7 
8 #ifndef OUTPUT_H
9 #define OUTPUT_H
10 
11 class OutputListeners;
12 class OutputEvent;
13 
14 #include <vector>
15 
16 #include <QMutex>
17 #include <QList>
18 
19 #include "mythobservable.h"
20 #include "mythexp.h"
21 
22 using namespace std::chrono_literals;
23 
24 class QObject;
25 class Buffer;
26 
27 namespace MythTV {
28 class Visual;
29 }
30 
32 {
33  public:
34  explicit OutputEvent(Type type) :
35  MythEvent(type) {}
36  OutputEvent(std::chrono::seconds s, unsigned long w, int b, int f, int p, int c) :
37  MythEvent(Info), m_elaspedSeconds(s), m_writtenBytes(w),
38  m_brate(b), m_freq(f), m_prec(p), m_chan(c) {}
39  explicit OutputEvent(const QString &e) :
40  MythEvent(Error)
41  {
42  QByteArray tmp = e.toUtf8();
43  m_errorMsg = new QString(tmp.constData());
44  }
45 
46  ~OutputEvent() override
47  {
48  delete m_errorMsg;
49  }
50 
51  const QString *errorMessage() const { return m_errorMsg; }
52 
53  const std::chrono::seconds &elapsedSeconds() const { return m_elaspedSeconds; }
54  const unsigned long &writtenBytes() const { return m_writtenBytes; }
55  const int &bitrate() const { return m_brate; }
56  const int &frequency() const { return m_freq; }
57  const int &precision() const { return m_prec; }
58  const int &channels() const { return m_chan; }
59 
60  MythEvent *clone(void) const override // MythEvent
61  { return new OutputEvent(*this); }
62 
63  static Type Playing;
64  static Type Buffering;
65  static Type Info;
66  static Type Paused;
67  static Type Stopped;
68  static Type Error;
69 
70  private:
72  m_elaspedSeconds(o.m_elaspedSeconds),
73  m_writtenBytes(o.m_writtenBytes),
74  m_brate(o.m_brate), m_freq(o.m_freq),
75  m_prec(o.m_prec), m_chan(o.m_chan)
76  {
77  if (o.m_errorMsg)
78  {
79  m_errorMsg = new QString(*o.m_errorMsg);
80  }
81  }
82 
83  // No implicit copying.
84  public:
85  OutputEvent &operator=(const OutputEvent &other) = delete;
86  OutputEvent(OutputEvent &&) = delete;
87  OutputEvent &operator=(OutputEvent &&) = delete;
88 
89  private:
90  QString *m_errorMsg {nullptr};
91 
92  std::chrono::seconds m_elaspedSeconds {0s};
93  unsigned long m_writtenBytes {0};
94  int m_brate {0};
95  int m_freq {0};
96  int m_prec {0};
97  int m_chan {0};
98 };
99 
100 using Visuals = std::vector<MythTV::Visual*>;
101 
103 {
104 public:
105  OutputListeners() = default;
106  ~OutputListeners() override = default;
107 
108  bool hasVisual(void) { return !m_visuals.empty(); }
109  void addVisual(MythTV::Visual *v);
110  void removeVisual(MythTV::Visual *v);
111 
112  QMutex *mutex() { return &m_mtx; }
113 
114  void setBufferSize(unsigned int sz) { m_bufsize = sz; }
115  unsigned int bufferSize() const { return m_bufsize; }
116 
117 protected:
118  void error(const QString &e);
119  void dispatchVisual(uchar *b, unsigned long b_len,
120  std::chrono::milliseconds timecode, int chan, int prec);
121  void prepareVisuals();
122 
123 private:
124  Q_DISABLE_COPY(OutputListeners)
125 
126  QMutex m_mtx;
127  Visuals m_visuals;
128 
129  unsigned int m_bufsize {0};
130 };
131 
132 
133 #endif // OUTPUT_H
MPUBLIC
#define MPUBLIC
Definition: mythexp.h:10
OutputEvent::Buffering
static Type Buffering
Definition: output.h:64
error
static void error(const char *str,...)
Definition: vbi.cpp:42
OutputEvent
Definition: output.h:31
OutputEvent::OutputEvent
OutputEvent(Type type)
Definition: output.h:34
OutputEvent::Stopped
static Type Stopped
Definition: output.h:67
mythexp.h
MythObservable
Superclass for making an object have a set of listeners.
Definition: mythobservable.h:11
MythEvent
This class is used as a container for messages.
Definition: mythevent.h:16
OutputListeners
Definition: output.h:102
OutputEvent::elapsedSeconds
const std::chrono::seconds & elapsedSeconds() const
Definition: output.h:53
OutputListeners::hasVisual
bool hasVisual(void)
Definition: output.h:108
tmp
static guint32 * tmp
Definition: goom_core.cpp:31
OutputEvent::~OutputEvent
~OutputEvent() override
Definition: output.h:46
MythTV::Visual
Definition: visual.h:16
OutputEvent::Error
static Type Error
Definition: output.h:68
MythTV
Definition: output.h:27
OutputEvent::Playing
static Type Playing
Definition: output.h:63
OutputEvent::precision
const int & precision() const
Definition: output.h:57
OutputEvent::OutputEvent
OutputEvent(const QString &e)
Definition: output.h:39
OutputEvent::clone
MythEvent * clone(void) const override
Definition: output.h:60
hardwareprofile.config.p
p
Definition: config.py:33
OutputEvent::m_errorMsg
QString * m_errorMsg
Definition: output.h:90
OutputListeners::setBufferSize
void setBufferSize(unsigned int sz)
Definition: output.h:114
OutputEvent::errorMessage
const QString * errorMessage() const
Definition: output.h:51
OutputEvent::OutputEvent
OutputEvent(const OutputEvent &o)
Definition: output.h:71
OutputListeners::mutex
QMutex * mutex()
Definition: output.h:112
OutputEvent::Paused
static Type Paused
Definition: output.h:66
OutputEvent::frequency
const int & frequency() const
Definition: output.h:56
Buffer
Definition: MythExternControl.h:36
OutputEvent::OutputEvent
OutputEvent(std::chrono::seconds s, unsigned long w, int b, int f, int p, int c)
Definition: output.h:36
OutputEvent::bitrate
const int & bitrate() const
Definition: output.h:55
OutputEvent::Info
static Type Info
Definition: output.h:65
Visuals
std::vector< MythTV::Visual * > Visuals
Definition: output.h:100
OutputListeners::bufferSize
unsigned int bufferSize() const
Definition: output.h:115
OutputEvent::writtenBytes
const unsigned long & writtenBytes() const
Definition: output.h:54
OutputEvent::channels
const int & channels() const
Definition: output.h:58
mythobservable.h