MythTV  master
mythplayeraudioui.cpp
Go to the documentation of this file.
1 // MythTV
4 
5 #include "audioplayer.h"
6 #include "mythplayeraudioui.h"
7 #include "tv_play.h"
8 
9 #define LOC QString("PlayerAudio: ")
10 
32  PlayerContext *Context, PlayerFlags Flags)
33  : MythPlayerOverlayUI(MainWindow, Tv, Context, Flags)
34 {
35  // Register our types for signal usage
36  qRegisterMetaType<MythAudioPlayerState>();
37  qRegisterMetaType<MythAudioState>();
38 
39  // Setup audio graph
41 
42  // Connect incoming signals
50 
51  // Connect outgoing signals
54 
55  // Setup
57  auto offset = gCoreContext->GetDurSetting<std::chrono::milliseconds>("AudioSyncOffset", 0ms);
59 }
60 
63 {
64  LOG(VB_GENERAL, LOG_INFO, LOC + "Initialising audio");
65  ReinitAudio();
67 }
68 
70 {
72 }
73 
75 {
76  m_audio.Reset();
78 }
79 
81 {
82  (void)m_audio.ReinitAudio();
84 }
85 
87 {
88  return m_audioGraph;
89 }
90 
91 void MythPlayerAudioUI::SetupAudioGraph(double VideoFrameRate)
92 {
93  uint samplerate = static_cast<uint>(m_audio.GetSampleRate());
94  m_audioGraph.SetSampleRate(samplerate);
95  m_audioGraph.SetSampleCount(static_cast<unsigned>(samplerate / VideoFrameRate));
97 }
98 
100 {
103 }
104 
105 void MythPlayerAudioUI::ChangeVolume(bool Direction, int Volume)
106 {
107  uint oldvolume = m_audio.GetVolume();
108 
109  if (Volume < 0)
110  m_audio.AdjustVolume(Direction ? 2 : -2);
111  else
112  m_audio.SetVolume(Volume);
113 
114  if (!(m_browsing || m_editing))
115  {
116  uint volume = m_audio.GetVolume();
117  UpdateOSDStatus(tr("Adjust Volume"), tr("Volume"), QString::number(volume),
118  kOSDFunctionalType_PictureAdjust, "%", static_cast<int>(volume * 10),
121  }
122 
123  if (m_audio.GetVolume() != oldvolume)
125 }
126 
127 void MythPlayerAudioUI::ChangeMuteState(bool CycleChannels)
128 {
130  return;
131 
132  MuteState oldstate = m_audio.GetMuteState();
133 
134  if (CycleChannels)
136  else
138 
139  QString text;
140  MuteState mute = m_audio.GetMuteState();
141  switch (mute)
142  {
143  case kMuteOff: text = tr("Mute Off"); break;
144  case kMuteAll: text = tr("Mute On"); break;
145  case kMuteLeft: text = tr("Left Channel Muted"); break;
146  case kMuteRight: text = tr("Right Channel Muted"); break;
147  }
148 
149  UpdateOSDMessage(text);
150 
151  if (m_audio.GetMuteState() != oldstate)
153 }
154 
155 void MythPlayerAudioUI::EnableUpmix(bool Enable, bool Toggle)
156 {
157  if (!m_audio.HasAudioOut())
158  return;
159 
160  bool oldupmixing = m_audio.IsUpmixing();
161  m_audio.EnableUpmix(Enable, Toggle);
163  bool newupmixing = m_audio.IsUpmixing();
164 
165  UpdateOSDMessage(newupmixing ? tr("Upmixer On") : tr("Upmixer Off"));
166 
167  if (newupmixing != oldupmixing)
169 }
170 
172 {
174 }
175 
177 {
178  QString passthru = gCoreContext->GetBoolSetting("PassThruDeviceOverride", false) ?
179  gCoreContext->GetSetting("PassThruOutputDevice") : QString();
180  m_audio.SetAudioInfo(gCoreContext->GetSetting("AudioOutputDevice"), passthru,
181  static_cast<uint>(gCoreContext->GetNumSetting("AudioSampleRate", 44100)));
183 }
184 
185 void MythPlayerAudioUI::AdjustAudioTimecodeOffset(std::chrono::milliseconds Delta, std::chrono::milliseconds Value)
186 {
187  std::chrono::milliseconds oldwrap = m_tcWrap[TC_AUDIO];
188 
189  if ((Value >= -1000ms) && (Value <= 1000ms))
190  m_tcWrap[TC_AUDIO] = Value;
191  else
192  m_tcWrap[TC_AUDIO] += Delta;
193 
194  std::chrono::milliseconds newwrap = m_tcWrap[TC_AUDIO];
195  if (!(m_browsing || m_editing))
196  {
197  UpdateOSDStatus(tr("Adjust Audio Sync"), tr("Audio Sync"),
198  QString::number(newwrap.count()), kOSDFunctionalType_AudioSyncAdjust,
199  "ms", (newwrap / 2 + 500ms).count(), kOSDTimeout_None);
201  }
202 
203  if (newwrap != oldwrap)
204  emit AudioStateChanged({ &m_audio, newwrap });
205 }
206 
MythPlayerAudioUI::EnableUpmix
void EnableUpmix(bool Enable, bool Toggle=false)
Definition: mythplayeraudioui.cpp:155
AudioPlayer::addVisual
void addVisual(MythTV::Visual *vis)
Definition: audioplayer.cpp:26
TVPlaybackState::AudioPlayerStateChanged
void AudioPlayerStateChanged(const MythAudioPlayerState &AudioPlayerState)
Definition: tvplaybackstate.cpp:23
MythPlayerAudioUI::MythPlayerAudioUI
MythPlayerAudioUI(MythMainWindow *MainWindow, TV *Tv, PlayerContext *Context, PlayerFlags Flags)
Definition: mythplayeraudioui.cpp:31
AudioPlayer::Reset
void Reset(void)
Definition: audioplayer.cpp:84
MythPlayerAudioUI::m_audioGraph
AudioOutputGraph m_audioGraph
Definition: mythplayeraudioui.h:40
MythPlayerAudioUI::SetupAudioGraph
void SetupAudioGraph(double VideoFrameRate)
Definition: mythplayeraudioui.cpp:91
AudioPlayer::ReinitAudio
QString ReinitAudio(void)
Definition: audioplayer.cpp:105
AudioOutputGraph
Definition: audiooutputgraph.h:14
MythPlayerAudioUI::ClearAudioGraph
void ClearAudioGraph()
Definition: mythplayeraudioui.cpp:99
PlayerContext::m_tsNormal
float m_tsNormal
Time stretch speed, 1.0F for normal playback.
Definition: playercontext.h:147
TimeStretch
Definition: playgroup.cpp:93
AudioPlayer::EnableUpmix
bool EnableUpmix(bool enable, bool toggle=false)
Definition: audioplayer.cpp:352
AudioPlayer::AudioPlayerStateChanged
void AudioPlayerStateChanged(MythAudioPlayerState State)
AudioOutputGraph::SetSampleCount
void SetSampleCount(uint16_t SampleCount)
Definition: audiooutputgraph.cpp:225
mythplayeraudioui.h
kOSDTimeout_Med
@ kOSDTimeout_Med
Definition: osd.h:60
AudioPlayer::GetVolume
uint GetVolume(void)
Definition: audioplayer.cpp:215
AudioPlayer::SetStretchFactor
void SetStretchFactor(float factor)
Definition: audioplayer.cpp:370
MythPlayerAudioUI::PauseAudioUntilBuffered
void PauseAudioUntilBuffered()
Definition: mythplayeraudioui.cpp:171
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
AudioPlayer::HasAudioOut
bool HasAudioOut(void) const
Definition: audioplayer.h:52
kOSDFunctionalType_PictureAdjust
@ kOSDFunctionalType_PictureAdjust
Definition: osd.h:47
PlayerFlags
PlayerFlags
Definition: mythplayer.h:64
MythPlayerUIBase::InitialiseState
virtual void InitialiseState()
Definition: mythplayeruibase.cpp:22
AudioPlayer::SetMuted
bool SetMuted(bool mute)
Definition: audioplayer.cpp:271
AudioPlayer::GetMuteState
MuteState GetMuteState(void)
Definition: audioplayer.cpp:310
AudioPlayer::ControlsVolume
bool ControlsVolume(void) const
Definition: audioplayer.h:53
AudioOutputGraph::SetSampleRate
void SetSampleRate(uint16_t SampleRate)
Definition: audiooutputgraph.cpp:218
AudioPlayer::SetAudioInfo
void SetAudioInfo(const QString &main_device, const QString &passthru_device, uint samplerate, int codec_profile=-1)
Set audio output device parameters.
Definition: audioplayer.cpp:227
MythPlayer::m_audio
AudioPlayer m_audio
Definition: mythplayer.h:472
MythPlayerOverlayUI::UpdateOSDMessage
void UpdateOSDMessage(const QString &Message)
Definition: mythplayeroverlayui.cpp:76
AudioOutputGraph::Reset
void Reset()
Definition: audiooutputgraph.cpp:243
AudioPlayer::SetVolume
uint SetVolume(int newvolume)
Definition: audioplayer.cpp:327
kOSDTimeout_None
@ kOSDTimeout_None
Definition: osd.h:58
MythPlayerOverlayUI
Definition: mythplayeroverlayui.h:7
MythPlayerAudioUI::InitialiseState
void InitialiseState() override
Initialise audio and signal initial state.
Definition: mythplayeraudioui.cpp:62
LOC
#define LOC
Definition: mythplayeraudioui.cpp:9
MythPlayer::m_tcWrap
tctype_arr m_tcWrap
Definition: mythplayer.h:496
MythPlayerAudioUI::AudioStateChanged
void AudioStateChanged(MythAudioState State)
MythPlayerAudioUI::ResetAudio
void ResetAudio()
Definition: mythplayeraudioui.cpp:74
AudioPlayer::AdjustVolume
uint AdjustVolume(int change)
Definition: audioplayer.cpp:318
MythPlayerOverlayUI::ChangeOSDPositionUpdates
void ChangeOSDPositionUpdates(bool Enable)
Definition: mythplayeroverlayui.cpp:43
MythPlayerOverlayUI::m_editing
bool m_editing
Definition: mythplayeroverlayui.h:48
MythCoreContext::GetDurSetting
std::enable_if_t< std::chrono::__is_duration< T >::value, T > GetDurSetting(const QString &key, T defaultval=T::zero())
Definition: mythcorecontext.h:168
MythPlayerUIBase::m_painter
MythPainter * m_painter
Definition: mythplayeruibase.h:20
AudioPlayer::IsUpmixing
bool IsUpmixing(void)
Definition: audioplayer.cpp:344
AudioPlayer::IncrMuteState
MuteState IncrMuteState(void)
Definition: audioplayer.cpp:303
TVPlaybackState::AudioStateChanged
void AudioStateChanged(const MythAudioState &AudioState)
Definition: tvplaybackstate.cpp:28
MythPlayerOverlayUI::m_browsing
bool m_browsing
Definition: mythplayeroverlayui.h:47
MythPlayerAudioUI::AdjustAudioTimecodeOffset
void AdjustAudioTimecodeOffset(std::chrono::milliseconds Delta, std::chrono::milliseconds Value)
Definition: mythplayeraudioui.cpp:185
TVPlaybackState::ResetAudio
void ResetAudio()
AudioPlayer::IsMuted
bool IsMuted(void)
Definition: audioplayer.h:86
uint
unsigned int uint
Definition: compat.h:81
gCoreContext
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
Definition: mythcorecontext.cpp:55
TVPlaybackState::ChangeAudioOffset
void ChangeAudioOffset(std::chrono::milliseconds Delta, std::chrono::milliseconds Value=-9999ms)
MuteState
MuteState
Definition: volumebase.h:8
MythCoreContext::GetNumSetting
int GetNumSetting(const QString &key, int defaultval=0)
Definition: mythcorecontext.cpp:916
MythPlayerAudioUI::GetAudioGraph
const AudioOutputGraph & GetAudioGraph() const
Definition: mythplayeraudioui.cpp:86
MythCoreContext::GetBoolSetting
bool GetBoolSetting(const QString &key, bool defaultval=false)
Definition: mythcorecontext.cpp:910
AudioPlayer::removeVisual
void removeVisual(MythTV::Visual *vis)
Definition: audioplayer.cpp:40
TVPlaybackState::ChangeUpmix
void ChangeUpmix(bool Enable, bool Toggle=false)
mythcorecontext.h
AudioPlayer::GetSampleRate
int GetSampleRate(void) const
Definition: audioplayer.h:60
AudioOutputGraph::SetPainter
void SetPainter(MythPainter *Painter)
Definition: audiooutputgraph.cpp:212
kOSDFunctionalType_AudioSyncAdjust
@ kOSDFunctionalType_AudioSyncAdjust
Definition: osd.h:50
MythPlayerAudioUI::ReinitAudio
void ReinitAudio()
Definition: mythplayeraudioui.cpp:80
MythPlayerAudioUI::ChangeMuteState
void ChangeMuteState(bool CycleChannels)
Definition: mythplayeraudioui.cpp:127
MythPlayerUIBase::m_tv
TV * m_tv
Definition: mythplayeruibase.h:18
TVPlaybackState::ChangeMuteState
void ChangeMuteState(bool CycleChannels=false)
MythPlayerAudioUI::RefreshAudioState
void RefreshAudioState()
Definition: mythplayeraudioui.cpp:69
kMuteLeft
@ kMuteLeft
Definition: volumebase.h:10
TC_AUDIO
@ TC_AUDIO
Definition: mythplayer.h:57
PlayerContext
Definition: playercontext.h:49
audioplayer.h
MythPlayerOverlayUI::UpdateOSDStatus
void UpdateOSDStatus(osdInfo &Info, int Type, enum OSDTimeout Timeout)
Definition: mythplayeroverlayui.cpp:101
MythPlayer::ForceSetupAudioStream
void ForceSetupAudioStream(void)
Definition: mythplayer.cpp:2007
kMuteRight
@ kMuteRight
Definition: volumebase.h:11
MythPlayerAudioUI::SetupAudioOutput
void SetupAudioOutput(float TimeStretch)
Definition: mythplayeraudioui.cpp:176
kMuteOff
@ kMuteOff
Definition: volumebase.h:9
TVPlaybackState::ChangeVolume
void ChangeVolume(bool Direction, int Volume)
AudioPlayer::PauseAudioUntilBuffered
void PauseAudioUntilBuffered(void)
Definition: audioplayer.cpp:197
kMuteAll
@ kMuteAll
Definition: volumebase.h:12
mythmainwindow.h
TVPlaybackState::PauseAudioUntilReady
void PauseAudioUntilReady()
MythPlayerAudioUI::ChangeVolume
void ChangeVolume(bool Direction, int Volume)
Definition: mythplayeraudioui.cpp:105
MythMainWindow
Definition: mythmainwindow.h:28
TVPlaybackState::ReinitAudio
void ReinitAudio()
MythCoreContext::GetSetting
QString GetSetting(const QString &key, const QString &defaultval="")
Definition: mythcorecontext.cpp:902
tv_play.h
TV
Control TV playback.
Definition: tv_play.h:152