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