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 "mythexp.h"
16 #include "mythconfig.h"
17 
18 #include <QString>
19 
20 extern "C" {
21 #include "libavcodec/avcodec.h" // to get codec id
22 }
23 #include "eldutils.h"
24 
33 };
34 
37  FEATURE_AC3 = 1 << 0,
38  FEATURE_DTS = 1 << 1,
39  FEATURE_LPCM = 1 << 2,
40  FEATURE_EAC3 = 1 << 3,
41  FEATURE_TRUEHD = 1 << 4,
42  FEATURE_DTSHD = 1 << 5,
43  FEATURE_AAC = 1 << 6,
44 };
45 
46 using rate_array = std::array<const int,12>;
47 using format_array = std::array<const AudioFormat,6>;
48 
50 {
51  public:
52  explicit AudioOutputSettings(bool invalid = false);
55  AudioOutputSettings& operator=(const AudioOutputSettings& /*rhs*/);
56  AudioOutputSettings *GetCleaned(bool newcopy = false);
57  AudioOutputSettings *GetUsers(bool newcopy = false);
58 
59  int GetNextRate();
60  void AddSupportedRate(int rate);
61  bool IsSupportedRate(int rate);
62  int NearestSupportedRate(int rate);
63  int BestSupportedRate();
64  AudioFormat GetNextFormat();
65  void AddSupportedFormat(AudioFormat format);
66  bool IsSupportedFormat(AudioFormat format);
67  AudioFormat BestSupportedFormat();
68  static int FormatToBits(AudioFormat format);
69  static const char* FormatToString(AudioFormat format);
70  static int SampleSize(AudioFormat format);
71  static AudioFormat AVSampleFormatToFormat(AVSampleFormat format, int bits = 0);
72  static AVSampleFormat FormatToAVSampleFormat(AudioFormat format);
73  void AddSupportedChannels(int channels);
74  bool IsSupportedChannels(int channels);
75  int BestSupportedChannels();
76 
77  void setPassthrough(int val) { m_passthrough = val; };
78  int canPassthrough() const { return m_passthrough; };
90  { return (m_features & arg) != 0U; };
91  bool canFeature(unsigned int arg) const
92  { return (m_features & arg) != 0U; };
93 
98  bool canAC3() const { return canFeature(FEATURE_AC3); };
103  bool canDTS() const { return canFeature(FEATURE_DTS); };
108  bool canLPCM() const { return canFeature(FEATURE_LPCM); };
114  bool IsInvalid() const { return m_invalid; };
115 
126  void setFeature(DigitalFeature arg) { m_features |= arg; };
127  void setFeature(unsigned int arg) { m_features |= arg; };
128 
132  void setFeature(bool val, DigitalFeature arg);
133  void setFeature(bool val, int arg);
134 
139  void SetBestSupportedChannels(int channels);
140 
145  int GetMaxHDRate() const;
146 
151  static QString FeaturesToString(DigitalFeature arg);
152  QString FeaturesToString(void) const
153  { return FeaturesToString((DigitalFeature)m_features); };
154 
158  static QString GetPassthroughParams(int codec, int codec_profile,
159  int &samplerate, int &channels,
160  bool canDTSHDMA);
161 
162  // ELD related methods
163 
167  bool hasELD() const;
168  bool hasValidELD();
172  void setELD(QByteArray *ba);
176  eld &getELD(void) { return m_eld; };
180  int BestSupportedChannelsELD();
184  int BestSupportedPCMChannelsELD();
185 
186  private:
187  void SortSupportedChannels();
188 
194  int m_passthrough {-1};
195 
196  unsigned int m_features {FEATURE_NONE};
197 
198  bool m_invalid {false};
205  bool m_hasEld {false};
207 
208  std::vector<int> m_rates;
209  std::vector<int> m_channels;
210  std::vector<AudioFormat> m_formats;
211  rate_array::iterator m_srIt { };
212  format_array::iterator m_sfIt { };
213 
214  static const rate_array kStdRates;
215  static const format_array kStdFormats;
216 };
217 
218 #endif // AUDIO_OUTPUT_SETTINGS_H
FORMAT_U8
@ FORMAT_U8
Definition: audiooutputsettings.h:27
FORMAT_NONE
@ FORMAT_NONE
Definition: audiooutputsettings.h:26
MPUBLIC
#define MPUBLIC
Definition: mythexp.h:10
AudioOutputSettings::setPassthrough
void setPassthrough(int val)
Definition: audiooutputsettings.h:77
FORMAT_S16
@ FORMAT_S16
Definition: audiooutputsettings.h:28
AudioOutputSettings::m_eld
eld m_eld
Definition: audiooutputsettings.h:206
mythexp.h
eld
Definition: eldutils.h:38
AudioOutputSettings::FeaturesToString
QString FeaturesToString(void) const
Definition: audiooutputsettings.h:152
FEATURE_AC3
@ FEATURE_AC3
Definition: audiooutputsettings.h:37
AudioOutputSettings::kStdRates
static const rate_array kStdRates
Definition: audiooutputsettings.h:214
rate_array
std::array< const int, 12 > rate_array
Definition: audiooutputsettings.h:46
arg
arg(title).arg(filename).arg(doDelete))
FEATURE_TRUEHD
@ FEATURE_TRUEHD
Definition: audiooutputsettings.h:41
AudioOutputSettings::m_channels
std::vector< int > m_channels
Definition: audiooutputsettings.h:209
FEATURE_EAC3
@ FEATURE_EAC3
Definition: audiooutputsettings.h:40
eldutils.h
AudioOutputSettings::m_rates
std::vector< int > m_rates
Definition: audiooutputsettings.h:208
FEATURE_NONE
@ FEATURE_NONE
Definition: audiooutputsettings.h:36
AudioOutputSettings::canPassthrough
int canPassthrough() const
Definition: audiooutputsettings.h:78
FEATURE_DTS
@ FEATURE_DTS
Definition: audiooutputsettings.h:38
AudioOutputSettings::kStdFormats
static const format_array kStdFormats
Definition: audiooutputsettings.h:215
FORMAT_S24
@ FORMAT_S24
Definition: audiooutputsettings.h:30
FEATURE_AAC
@ FEATURE_AAC
Definition: audiooutputsettings.h:43
FORMAT_FLT
@ FORMAT_FLT
Definition: audiooutputsettings.h:32
format_array
std::array< const AudioFormat, 6 > format_array
Definition: audiooutputsettings.h:47
FEATURE_LPCM
@ FEATURE_LPCM
Definition: audiooutputsettings.h:39
FORMAT_S32
@ FORMAT_S32
Definition: audiooutputsettings.h:31
AudioOutputSettings::canDTS
bool canDTS() const
return true if device can or may support DTS (deprecated, see canFeature())
Definition: audiooutputsettings.h:103
AudioOutputSettings::canFeature
bool canFeature(DigitalFeature arg) const
return DigitalFeature mask.
Definition: audiooutputsettings.h:89
AudioOutputSettings::setFeature
void setFeature(unsigned int arg)
Definition: audiooutputsettings.h:127
AudioOutputSettings::setFeature
void setFeature(DigitalFeature arg)
set the provided digital feature possible values are:
Definition: audiooutputsettings.h:126
AudioOutputSettings::IsInvalid
bool IsInvalid() const
return true if class instance is marked invalid.
Definition: audiooutputsettings.h:114
AudioOutputSettings::canFeature
bool canFeature(unsigned int arg) const
Definition: audiooutputsettings.h:91
AudioOutputSettings::m_formats
std::vector< AudioFormat > m_formats
Definition: audiooutputsettings.h:210
AudioOutputSettings
Definition: audiooutputsettings.h:50
DigitalFeature
DigitalFeature
Definition: audiooutputsettings.h:35
AudioOutputSettings::canLPCM
bool canLPCM() const
return true if device supports multichannels PCM (deprecated, see canFeature())
Definition: audiooutputsettings.h:108
AudioFormat
AudioFormat
Definition: audiooutputsettings.h:25
AudioOutputSettings::getELD
eld & getELD(void)
retrieve ELD data
Definition: audiooutputsettings.h:176
FEATURE_DTSHD
@ FEATURE_DTSHD
Definition: audiooutputsettings.h:42
FORMAT_S24LSB
@ FORMAT_S24LSB
Definition: audiooutputsettings.h:29
AudioOutputSettings::AudioOutputSettings
AudioOutputSettings(const AudioOutputSettings &)=default
AudioOutputSettings::canAC3
bool canAC3() const
return true if device can or may support AC3 (deprecated, see canFeature())
Definition: audiooutputsettings.h:98