Permalink
Browse files

libmythtv: Add visualiser support to AudioPlayer.

  • Loading branch information...
1 parent 0affac2 commit a2c424c76165ab22105270cddb8e5a79bf554837 Mark Kendall committed Mar 18, 2011
Showing with 66 additions and 0 deletions.
  1. +53 −0 mythtv/libs/libmythtv/audioplayer.cpp
  2. +13 −0 mythtv/libs/libmythtv/audioplayer.h
View
53 mythtv/libs/libmythtv/audioplayer.cpp
@@ -18,6 +18,55 @@ AudioPlayer::AudioPlayer(MythPlayer *parent, bool muted)
AudioPlayer::~AudioPlayer()
{
DeleteOutput();
+ m_visuals.clear();
+}
+
+void AudioPlayer::addVisual(MythTV::Visual *vis)
+{
+ if (!m_audioOutput)
+ return;
+
+ QMutexLocker lock(&m_lock);
+ Visuals::iterator it = std::find(m_visuals.begin(), m_visuals.end(), vis);
+ if (it == m_visuals.end())
+ {
+ m_visuals.push_back(vis);
+ m_audioOutput->addVisual(vis);
+ }
+}
+
+void AudioPlayer::removeVisual(MythTV::Visual *vis)
+{
+ if (!m_audioOutput)
+ return;
+
+ QMutexLocker lock(&m_lock);
+ Visuals::iterator it = std::find(m_visuals.begin(), m_visuals.end(), vis);
+ if (it != m_visuals.end())
+ {
+ m_visuals.erase(it);
+ m_audioOutput->removeVisual(vis);
+ }
+}
+
+void AudioPlayer::AddVisuals(void)
+{
+ if (!m_audioOutput)
+ return;
+
+ QMutexLocker lock(&m_lock);
+ for (uint i = 0; i < m_visuals.size(); i++)
+ m_audioOutput->addVisual(m_visuals[i]);
+}
+
+void AudioPlayer::RemoveVisuals(void)
+{
+ if (!m_audioOutput)
+ return;
+
+ QMutexLocker lock(&m_lock);
+ for (uint i = 0; i < m_visuals.size(); i++)
+ m_audioOutput->removeVisual(m_visuals[i]);
}
void AudioPlayer::Reset(void)
@@ -31,6 +80,7 @@ void AudioPlayer::Reset(void)
void AudioPlayer::DeleteOutput(void)
{
+ RemoveVisuals();
QMutexLocker locker(&m_lock);
if (m_audioOutput)
{
@@ -81,6 +131,7 @@ QString AudioPlayer::ReinitAudio(void)
{
errMsg = m_audioOutput->GetError();
}
+ AddVisuals();
}
else if (want_audio && !m_no_audio_in)
{
@@ -150,7 +201,9 @@ void AudioPlayer::PauseAudioUntilBuffered()
void AudioPlayer::SetAudioOutput(AudioOutput *ao)
{
m_lock.lock();
+ RemoveVisuals();
m_audioOutput = ao;
+ AddVisuals();
m_lock.unlock();
}
View
13 mythtv/libs/libmythtv/audioplayer.h
@@ -6,12 +6,20 @@
class MythPlayer;
class AudioOutput;
+namespace MythTV
+{
+ class Visual;
+}
+
class MTV_PUBLIC AudioPlayer
{
public:
AudioPlayer(MythPlayer *parent, bool muted);
~AudioPlayer();
+ void addVisual(MythTV::Visual *vis);
+ void removeVisual(MythTV::Visual *vis);
+
void Reset(void);
void DeleteOutput(void);
QString ReinitAudio(void);
@@ -63,6 +71,10 @@ class MTV_PUBLIC AudioPlayer
bool IsBufferAlmostFull(void);
private:
+ void AddVisuals(void);
+ void RemoveVisuals(void);
+
+ private:
MythPlayer *m_parent;
AudioOutput *m_audioOutput;
int m_channels;
@@ -79,6 +91,7 @@ class MTV_PUBLIC AudioPlayer
QString m_passthru_device;
bool m_no_audio_in;
bool m_no_audio_out;
+ vector<MythTV::Visual*> m_visuals;
};
#endif // AUDIOPLAYER_H

0 comments on commit a2c424c

Please sign in to comment.