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