MythTV  master
audiooutputsettings.h
Go to the documentation of this file.
1 /* -*- Mode: c++ -*-
2  *
3  * Copyright (C) foobum@gmail.com 2010
4  * Copyright (C) Jean-Yves Avenard 2010
5  *
6  * Licensed under the GPL v2 or a later version at your choosing.
7  */
8 
9 #ifndef AUDIO_OUTPUT_SETTINGS_H
10 #define AUDIO_OUTPUT_SETTINGS_H
11 
12 #include <array>
13 #include <vector>
14 
15 #include "libmyth/mythexp.h"
16 
17 #include <QString>
18 
19 extern "C" {
20 #include "libavcodec/avcodec.h" // to get codec id
21 }
22 #include "eldutils.h"
23 
24 enum AudioFormat : std::uint8_t {
32 };
33 
34 enum DigitalFeature : std::uint8_t {
36  FEATURE_AC3 = 1 << 0,
37  FEATURE_DTS = 1 << 1,
38  FEATURE_LPCM = 1 << 2,
39  FEATURE_EAC3 = 1 << 3,
40  FEATURE_TRUEHD = 1 << 4,
41  FEATURE_DTSHD = 1 << 5,
42  FEATURE_AAC = 1 << 6,
43 };
44 
45 using rate_array = std::array<const int,12>;
46 using format_array = std::array<const AudioFormat,6>;
47 
49 {
50  public:
51  explicit AudioOutputSettings(bool invalid = false);
52  AudioOutputSettings(const AudioOutputSettings&) = default;
54  AudioOutputSettings& operator=(const AudioOutputSettings& /*rhs*/);
55  AudioOutputSettings *GetCleaned(bool newcopy = false);
56  AudioOutputSettings *GetUsers(bool newcopy = false);
57 
58  int GetNextRate();
59  void AddSupportedRate(int rate);
60  bool IsSupportedRate(int rate);
61  int NearestSupportedRate(int rate);
62  int BestSupportedRate();
63  AudioFormat GetNextFormat();
64  void AddSupportedFormat(AudioFormat format);
65  bool IsSupportedFormat(AudioFormat format);
66  AudioFormat BestSupportedFormat();
67  static int FormatToBits(AudioFormat format);
68  static const char* FormatToString(AudioFormat format);
69  static int SampleSize(AudioFormat format);
70  static AudioFormat AVSampleFormatToFormat(AVSampleFormat format, int bits = 0);
71  static AVSampleFormat FormatToAVSampleFormat(AudioFormat format);
72  void AddSupportedChannels(int channels);
73  bool IsSupportedChannels(int channels);
74  int BestSupportedChannels();
75 
76  void setPassthrough(int val) { m_passthrough = val; };
77  int canPassthrough() const { return m_passthrough; };
88  bool canFeature(DigitalFeature arg) const
89  { return (m_features & arg) != 0U; };
90  bool canFeature(unsigned int arg) const
91  { return (m_features & arg) != 0U; };
92 
97  bool canAC3() const { return canFeature(FEATURE_AC3); };
102  bool canDTS() const { return canFeature(FEATURE_DTS); };
107  bool canLPCM() const { return canFeature(FEATURE_LPCM); };
113  bool IsInvalid() const { return m_invalid; };
114 
125  void setFeature(DigitalFeature arg) { m_features |= arg; };
126  void setFeature(unsigned int arg) { m_features |= arg; };
127 
131  void setFeature(bool val, DigitalFeature arg);
132  void setFeature(bool val, int arg);
133 
138  void SetBestSupportedChannels(int channels);
139 
144  int GetMaxHDRate() const;
145 
150  static QString FeaturesToString(DigitalFeature arg);
151  QString FeaturesToString(void) const
152  { return FeaturesToString((DigitalFeature)m_features); };
153 
157  static QString GetPassthroughParams(int codec, int codec_profile,
158  int &samplerate, int &channels,
159  bool canDTSHDMA);
160 
161  // ELD related methods
162 
166  bool hasELD() const;
167  bool hasValidELD();
171  void setELD(QByteArray *ba);
175  eld &getELD(void) { return m_eld; };
179  int BestSupportedChannelsELD();
183  int BestSupportedPCMChannelsELD();
184 
185  private:
186  void SortSupportedChannels();
187 
193  int m_passthrough {-1};
194 
195  unsigned int m_features {FEATURE_NONE};
196 
197  bool m_invalid {false};
204  bool m_hasEld {false};
206 
207  std::vector<int> m_rates;
208  std::vector<int> m_channels;
209  std::vector<AudioFormat> m_formats;
210  rate_array::iterator m_srIt { };
211  format_array::iterator m_sfIt { };
212 
213  static const rate_array kStdRates;
214  static const format_array kStdFormats;
215 };
216 
217 #endif // AUDIO_OUTPUT_SETTINGS_H
MPUBLIC
#define MPUBLIC
Definition: mythexp.h:10
AudioOutputSettings::setPassthrough
void setPassthrough(int val)
Definition: audiooutputsettings.h:76
FEATURE_DTS
@ FEATURE_DTS
Definition: audiooutputsettings.h:37
FORMAT_S16
@ FORMAT_S16
Definition: audiooutputsettings.h:27
AudioOutputSettings::m_eld
eld m_eld
Definition: audiooutputsettings.h:205
FORMAT_S24
@ FORMAT_S24
Definition: audiooutputsettings.h:29
mythexp.h
eld
Definition: eldutils.h:37
AudioOutputSettings::FeaturesToString
QString FeaturesToString(void) const
Definition: audiooutputsettings.h:151
FORMAT_S32
@ FORMAT_S32
Definition: audiooutputsettings.h:30
FEATURE_NONE
@ FEATURE_NONE
Definition: audiooutputsettings.h:35
AudioOutputSettings::kStdRates
static const rate_array kStdRates
Definition: audiooutputsettings.h:213
rate_array
std::array< const int, 12 > rate_array
Definition: audiooutputsettings.h:45
FEATURE_TRUEHD
@ FEATURE_TRUEHD
Definition: audiooutputsettings.h:40
AudioOutputSettings::m_channels
std::vector< int > m_channels
Definition: audiooutputsettings.h:208
FEATURE_LPCM
@ FEATURE_LPCM
Definition: audiooutputsettings.h:38
FEATURE_AAC
@ FEATURE_AAC
Definition: audiooutputsettings.h:42
eldutils.h
FORMAT_U8
@ FORMAT_U8
Definition: audiooutputsettings.h:26
FORMAT_S24LSB
@ FORMAT_S24LSB
Definition: audiooutputsettings.h:28
DigitalFeature
DigitalFeature
Definition: audiooutputsettings.h:34
AudioOutputSettings::m_rates
std::vector< int > m_rates
Definition: audiooutputsettings.h:207
FORMAT_NONE
@ FORMAT_NONE
Definition: audiooutputsettings.h:25
AudioOutputSettings::canPassthrough
int canPassthrough() const
Definition: audiooutputsettings.h:77
AudioOutputSettings::kStdFormats
static const format_array kStdFormats
Definition: audiooutputsettings.h:214
format_array
std::array< const AudioFormat, 6 > format_array
Definition: audiooutputsettings.h:46
AudioOutputSettings::canDTS
bool canDTS() const
return true if device can or may support DTS (deprecated, see canFeature())
Definition: audiooutputsettings.h:102
AudioOutputSettings::canFeature
bool canFeature(DigitalFeature arg) const
return DigitalFeature mask.
Definition: audiooutputsettings.h:88
AudioOutputSettings::setFeature
void setFeature(unsigned int arg)
Definition: audiooutputsettings.h:126
FEATURE_DTSHD
@ FEATURE_DTSHD
Definition: audiooutputsettings.h:41
AudioOutputSettings::setFeature
void setFeature(DigitalFeature arg)
set the provided digital feature possible values are:
Definition: audiooutputsettings.h:125
AudioOutputSettings::IsInvalid
bool IsInvalid() const
return true if class instance is marked invalid.
Definition: audiooutputsettings.h:113
AudioOutputSettings::canFeature
bool canFeature(unsigned int arg) const
Definition: audiooutputsettings.h:90
AudioOutputSettings::m_formats
std::vector< AudioFormat > m_formats
Definition: audiooutputsettings.h:209
AudioOutputSettings
Definition: audiooutputsettings.h:48
AudioFormat
AudioFormat
Definition: audiooutputsettings.h:24
FEATURE_AC3
@ FEATURE_AC3
Definition: audiooutputsettings.h:36
FEATURE_EAC3
@ FEATURE_EAC3
Definition: audiooutputsettings.h:39
AudioOutputSettings::canLPCM
bool canLPCM() const
return true if device supports multichannels PCM (deprecated, see canFeature())
Definition: audiooutputsettings.h:107
FORMAT_FLT
@ FORMAT_FLT
Definition: audiooutputsettings.h:31
AudioOutputSettings::getELD
eld & getELD(void)
retrieve ELD data
Definition: audiooutputsettings.h:175
AudioOutputSettings::canAC3
bool canAC3() const
return true if device can or may support AC3 (deprecated, see canFeature())
Definition: audiooutputsettings.h:97