MythTV  master
audioplayer.h
Go to the documentation of this file.
1 #ifndef AUDIOPLAYER_H
2 #define AUDIOPLAYER_H
3 
4 #include "mythplayerstate.h"
5 
6 #include <QCoreApplication>
7 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
8 #include <QMutex>
9 #else
10 #include <QRecursiveMutex>
11 #endif
12 
13 #include <cstdint>
14 #include <vector>
15 
16 using std::vector;
17 
18 class MythPlayer;
19 class AudioOutput;
20 struct AVCodecContext;
21 struct AVPacket;
22 
23 namespace MythTV
24 {
25  class Visual;
26 }
27 
28 class MTV_PUBLIC AudioPlayer : public QObject
29 {
30  Q_OBJECT
31 
32  signals:
33  void AudioPlayerStateChanged(MythAudioPlayerState State);
34 
35  public:
36  AudioPlayer(MythPlayer *parent, bool muted);
37  ~AudioPlayer() override;
38 
39  void addVisual(MythTV::Visual *vis);
40  void removeVisual(MythTV::Visual *vis);
41 
42  void Reset(void);
43  void DeleteOutput(void);
44  QString ReinitAudio(void);
45  void SetAudioOutput(AudioOutput *ao);
46  void SetAudioInfo(const QString &main_device,
47  const QString &passthru_device,
48  uint samplerate,
49  int codec_profile = -1);
50  void SetAudioParams(AudioFormat format, int orig_channels, int channels,
51  AVCodecID codec, int samplerate, bool passthru,
52  int codec_profile = -1);
53  void SetEffDsp(int dsprate);
54 
55  void CheckFormat(void);
56  void SetNoAudio(void) { m_noAudioOut = true; }
57  bool HasAudioIn(void) const { return !m_noAudioIn; }
58  bool HasAudioOut(void) const { return !m_noAudioOut; }
59  bool ControlsVolume(void) const { return m_controlsVolume; }
60 
61  bool Pause(bool pause);
62  bool IsPaused(void);
63  void PauseAudioUntilBuffered(void);
64  AVCodecID GetCodec(void) const { return m_state.m_codec; }
65  int GetOrigChannels(void) const { return m_state.m_origChannels; }
66  int GetSampleRate(void) const { return m_state.m_sampleRate; }
67  uint GetVolume(void);
68  uint AdjustVolume(int change);
69  uint SetVolume(int newvolume);
70  float GetStretchFactor(void) const { return m_stretchFactor; }
71  void SetStretchFactor(float factor);
72  bool IsUpmixing(void);
73  bool EnableUpmix(bool enable, bool toggle = false);
74  bool CanUpmix(void);
75  bool CanPassthrough(int samplerate, int channels, AVCodecID codec, int profile);
76  bool CanDownmix(void);
77  bool CanAC3(void);
78  bool CanDTS(void);
79  bool CanEAC3(void);
80  bool CanTrueHD(void);
81  bool CanDTSHD(void);
82  uint GetMaxChannels(void);
83  int GetMaxHDRate(void);
84  std::chrono::milliseconds GetAudioTime(void);
85  AudioFormat GetFormat(void) const { return m_state.m_format; }
86  bool CanProcess(AudioFormat fmt);
87  uint32_t CanProcess(void);
88  int DecodeAudio(AVCodecContext *ctx,
89  uint8_t *buffer, int &data_size,
90  const AVPacket *pkt);
91 
92  bool IsMuted(void) { return GetMuteState() == kMuteAll; }
93  bool SetMuted(bool mute);
94  MuteState GetMuteState(void);
95  MuteState SetMuteState(MuteState mstate);
96  MuteState IncrMuteState(void);
97 
98  void AddAudioData(char *buffer, int len, std::chrono::milliseconds timecode, int frames);
99  bool NeedDecodingBeforePassthrough(void);
100  std::chrono::milliseconds LengthLastData(void);
101  bool GetBufferStatus(uint &fill, uint &total);
102  bool IsBufferAlmostFull(void);
103  std::chrono::milliseconds GetAudioBufferedTime(void);
104 
108  AudioOutput *GetAudioOutput(void) const { return m_audioOutput; }
109 
110  private:
111  void AddVisuals(void);
112  void RemoveVisuals(void);
113  void ResetVisuals(void);
114 
115  private:
116  MythPlayer *m_parent {nullptr};
117  AudioOutput *m_audioOutput {nullptr};
118  MythAudioPlayerState m_state { };
119  float m_stretchFactor {1.0F};
120 #if QT_VERSION < QT_VERSION_CHECK(5,14,0)
121  QMutex m_lock {QMutex::Recursive};
122 #else
123  QRecursiveMutex m_lock;
124 #endif
125  bool m_mutedOnCreation {false};
126  QString m_mainDevice;
128  bool m_noAudioIn {false};
129  bool m_noAudioOut {true};
130  bool m_controlsVolume {true};
131  vector<MythTV::Visual*> m_visuals;
132 };
133 
134 #endif // AUDIOPLAYER_H
mythplayerstate.h
AudioPlayer::SetNoAudio
void SetNoAudio(void)
Definition: audioplayer.h:56
AudioPlayer
Definition: audioplayer.h:28
AudioPlayer::HasAudioOut
bool HasAudioOut(void) const
Definition: audioplayer.h:58
AudioPlayer::m_mainDevice
QString m_mainDevice
Definition: audioplayer.h:126
MythPlayer
Definition: mythplayer.h:86
AudioPlayer::ControlsVolume
bool ControlsVolume(void) const
Definition: audioplayer.h:59
AudioPlayer::GetOrigChannels
int GetOrigChannels(void) const
Definition: audioplayer.h:65
AudioPlayer::GetFormat
AudioFormat GetFormat(void) const
Definition: audioplayer.h:85
AudioPlayer::m_lock
QRecursiveMutex m_lock
Definition: audioplayer.h:123
MuteState
MuteState
Definition: volumebase.h:6
MythTV::Visual
Definition: visual.h:16
AudioOutput
Definition: audiooutput.h:26
MythTV
Definition: output.h:27
hardwareprofile.scan.profile
profile
Definition: scan.py:99
State
State
Definition: zmserver.h:68
AudioPlayer::HasAudioIn
bool HasAudioIn(void) const
Definition: audioplayer.h:57
AudioPlayer::IsMuted
bool IsMuted(void)
Definition: audioplayer.h:92
uint
unsigned int uint
Definition: compat.h:140
MTV_PUBLIC
#define MTV_PUBLIC
Definition: mythtvexp.h:15
AudioPlayer::GetAudioOutput
AudioOutput * GetAudioOutput(void) const
Return internal AudioOutput object.
Definition: audioplayer.h:108
AudioPlayer::m_visuals
vector< MythTV::Visual * > m_visuals
Definition: audioplayer.h:131
AudioPlayer::GetCodec
AVCodecID GetCodec(void) const
Definition: audioplayer.h:64
AudioPlayer::GetSampleRate
int GetSampleRate(void) const
Definition: audioplayer.h:66
AudioPlayer::GetStretchFactor
float GetStretchFactor(void) const
Definition: audioplayer.h:70
AudioPlayer::m_passthruDevice
QString m_passthruDevice
Definition: audioplayer.h:127
kMuteAll
@ kMuteAll
Definition: volumebase.h:10
AudioFormat
AudioFormat
Definition: audiooutputsettings.h:25
MythAudioPlayerState
Definition: mythplayerstate.h:31