MythTV  master
videovisual.cpp
Go to the documentation of this file.
1 #include "mythrender_base.h"
2 #include "mythplayer.h"
3 #include "videovisual.h"
4 
6 
8 {
9  QStringList result;
10  for (auto *factory = VideoVisualFactory::VideoVisualFactories();
11  factory; factory = factory->next())
12  {
13  if (factory->SupportedRenderer(type))
14  result << factory->name();
15  }
16  result.sort();
17  return result;
18 }
19 
20 VideoVisual* VideoVisual::Create(const QString &name,
21  AudioPlayer *audio, MythRender *render)
22 {
23  if (!audio || !render || name.isEmpty())
24  return nullptr;
25 
26  for (auto *factory = VideoVisualFactory::VideoVisualFactories();
27  factory; factory = factory->next())
28  {
29  if (name.isEmpty())
30  return factory->Create(audio, render);
31  if (factory->name() == name)
32  return factory->Create(audio, render);
33  }
34  return nullptr;
35 }
36 
38  : m_audio(audio), m_render(render)
39 {
41  mutex()->lock();
42  if (m_audio)
43  m_audio->addVisual(this);
44  mutex()->unlock();
45 }
46 
48 {
49  mutex()->lock();
50  if (m_audio)
51  m_audio->removeVisual(this);
52  DeleteNodes();
53  mutex()->unlock();
54 }
55 
57 {
58  QDateTime now = MythDate::current();
59  int64_t result = m_lastUpdate.time().msecsTo(now.time());
60  m_lastUpdate = now;
61  return result;
62 }
63 
64 // caller holds lock
66 {
67  while (!m_nodes.empty())
68  {
69  delete m_nodes.back();
70  m_nodes.pop_back();
71  }
72 }
73 
74 // caller holds lock
76 {
77  DeleteNodes();
78 }
79 
80 // caller holds lock
82 {
83  int64_t timestamp = m_audio->GetAudioTime();
84  while (m_nodes.size() > 1)
85  {
86  if (m_nodes.front()->m_offset > timestamp)
87  break;
88  delete m_nodes.front();
89  m_nodes.pop_front();
90  }
91 
92  if (m_nodes.isEmpty())
93  return nullptr;
94 
95  return m_nodes.first();
96 }
97 
98 // TODO Add MMX path
99 static inline void stereo16_from_stereofloat32(
100  short *l, short *r, const float *s, unsigned long cnt)
101 {
102  const float f((1 << 15) - 1);
103  while (cnt--)
104  {
105  *l++ = short(f * *s++);
106  *r++ = short(f * *s++);
107  }
108 }
109 
110 // TODO Add MMX path
111 static inline void mono16_from_monofloat32(
112  short *l, const float *s, unsigned long cnt)
113 {
114  const float f((1 << 15) - 1);
115  while (cnt--)
116  *l++ = short(f * *s++);
117 }
118 
119 // caller holds lock
120 void VideoVisual::add(const void *b, unsigned long b_len, unsigned long w, int c,
121  int p)
122 {
123  if (!m_disabled && m_nodes.size() > 500)
124  {
125  LOG(VB_GENERAL, LOG_ERR, DESC +
126  QString("Over 500 nodes buffered - disabling visualiser."));
127  DeleteNodes();
128  m_disabled = true;
129  }
130 
131  if (m_disabled)
132  return;
133 
134  long len = b_len;
135  short *l = nullptr;
136  short *r = nullptr;
137 
138  len /= c;
139  len /= (p / 8);
140 
141  if (len > 512)
142  len = 512;
143 
144  long cnt = len;
145 
146  if (c == 2)
147  {
148  l = new short[len];
149  r = new short[len];
150 
151  if (p == 8)
152  stereo16_from_stereopcm8(l, r, (uchar *) b, cnt);
153  else if (p == 16)
154  stereo16_from_stereopcm16(l, r, (short *) b, cnt);
155  else if (p == 32)
156  stereo16_from_stereofloat32(l, r, reinterpret_cast<const float * >(b), cnt);
157  else
158  len = 0;
159  }
160  else if (c == 1)
161  {
162  l = new short[len];
163 
164  if (p == 8)
165  mono16_from_monopcm8(l, (uchar *) b, cnt);
166  else if (p == 16)
167  mono16_from_monopcm16(l, (short *) b, cnt);
168  else if (p == 32)
169  mono16_from_monofloat32(l, reinterpret_cast<const float * >(b), cnt);
170  else
171  len = 0;
172  }
173  else
174  len = 0;
175 
176  m_nodes.append(new VisualNode(l, r, len, w));
177 }
AudioPlayer::addVisual
void addVisual(MythTV::Visual *vis)
Definition: audioplayer.cpp:25
VideoVisualFactory::VideoVisualFactories
static VideoVisualFactory * VideoVisualFactories()
Definition: videovisual.h:85
mono16_from_monopcm8
static void mono16_from_monopcm8(short *l, const uchar *c, long cnt)
Definition: videovisualdefs.h:151
VideoVisual::SetLastUpdate
int64_t SetLastUpdate(void)
Definition: videovisual.cpp:56
VideoVisualFactory::g_videoVisualFactory
static VideoVisualFactory * g_videoVisualFactory
Definition: videovisual.h:96
mono16_from_monofloat32
static void mono16_from_monofloat32(short *l, const float *s, unsigned long cnt)
Definition: videovisual.cpp:111
VideoVisual::m_lastUpdate
QDateTime m_lastUpdate
Definition: videovisual.h:70
AudioPlayer
Definition: audioplayer.h:25
VisualNode
Definition: videovisual.h:23
VideoVisual::prepare
void prepare() override
Definition: videovisual.cpp:75
VideoVisual::Create
static VideoVisual * Create(const QString &name, AudioPlayer *audio, MythRender *render)
Definition: videovisual.cpp:20
VideoVisual::m_disabled
bool m_disabled
Definition: videovisual.h:66
VideoVisual::m_nodes
QList< VisualNode * > m_nodes
Definition: videovisual.h:69
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
mythplayer.h
VideoVisual::add
void add(const void *b, unsigned long b_len, unsigned long w, int c, int p) override
Definition: videovisual.cpp:120
MythDate::current
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:10
AudioPlayer::GetAudioTime
int64_t GetAudioTime(void)
Definition: audioplayer.cpp:335
mythrender_base.h
stereo16_from_stereofloat32
static void stereo16_from_stereofloat32(short *l, short *r, const float *s, unsigned long cnt)
Definition: videovisual.cpp:99
DESC
#define DESC
Definition: videovisual.h:17
mono16_from_monopcm16
static void mono16_from_monopcm16(short *l, const short *s, long cnt)
Definition: videovisualdefs.h:180
hardwareprofile.config.p
p
Definition: config.py:33
VideoVisualFactory
Definition: videovisual.h:74
VideoVisualFactory::next
VideoVisualFactory * next() const
Definition: videovisual.h:89
MythTV::Visual::mutex
QMutex * mutex()
Definition: visual.h:25
stereo16_from_stereopcm16
static void stereo16_from_stereopcm16(short *l, short *r, const short *s, long cnt)
Definition: videovisualdefs.h:113
RenderType
RenderType
Definition: mythrender_base.h:16
f
QTextStream t & f
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:603
VideoVisual::GetVisualiserList
static QStringList GetVisualiserList(RenderType type)
Definition: videovisual.cpp:7
VideoVisual::m_audio
AudioPlayer * m_audio
Definition: videovisual.h:64
AudioPlayer::removeVisual
void removeVisual(MythTV::Visual *vis)
Definition: audioplayer.cpp:39
stereo16_from_stereopcm8
static void stereo16_from_stereopcm8(short *l, short *r, const uchar *c, long cnt)
Definition: videovisualdefs.h:75
MythRender
Definition: mythrender_base.h:24
VideoVisual::DeleteNodes
void DeleteNodes(void)
Definition: videovisual.cpp:65
videovisual.h
VideoVisual
Definition: videovisual.h:41
VideoVisual::GetNode
VisualNode * GetNode(void)
Definition: videovisual.cpp:81
VideoVisual::~VideoVisual
~VideoVisual() override
Definition: videovisual.cpp:47
VideoVisual::VideoVisual
VideoVisual(AudioPlayer *audio, MythRender *render)
Definition: videovisual.cpp:37