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