13#if QT_VERSION >= QT_VERSION_CHECK(6,5,0)
14#include <QtSystemDetection>
16#include <QCoreApplication>
24#include "libmythbase/mythconfig.h"
36#include "libavformat/avformat.h"
44 QString dflt =
"OpenSLES:";
45#elif CONFIG_AUDIO_ALSA
46 QString dflt =
"ALSA:default";
47#elif CONFIG_AUDIO_PULSEOUTPUT
48 QString dflt =
"PulseAudio:default";
49#elif defined(Q_OS_DARWIN)
50 QString dflt =
"CoreAudio:";
51#elif defined(Q_OS_WINDOWS)
52 QString dflt =
"Windows:";
54 QString dflt =
"NULL";
82 for (
const auto & it : std::as_const(vect))
84 if (value != it.m_name)
112 if (settings ==
nullptr)
114 settings->CheckConfiguration();
119 m_passThroughOverride(PassThroughOverride()),
120 m_passThroughDeviceOverride(PassThroughOutputDevice())
128 rescan->setLabel(tr(
"Rescan"));
129 rescan->setHelpText(tr(
"Rescan for available audio devices. "
130 "Current entry will be checked and "
131 "capability entries populated."));
151 advancedSettings->setLabel(tr(
"Advanced Audio Settings"));
152 advancedSettings->setHelpText(tr(
"Enable extra audio settings. Under most "
153 "usage all options should be left alone"));
209 QString msg = tr(
"%1 is invalid or not useable.").arg(name);
213 LOG(VB_GENERAL, LOG_ERR, QString(
"Audio device %1 isn't usable")
222 QString pt_msg = tr(
"Passthrough device is invalid or not useable. Check "
223 "configuration in Advanced Settings:") +
228 LOG(VB_GENERAL, LOG_ERR, QString(
"Audio device %1 isn't usable")
251 for (
const auto & dev : std::as_const(*list))
283 bool restore,
bool AC3)
285 int max_speakers = 8;
286 int realmax_speakers = 8;
288 bool invalid =
false;
321 LOG(VB_AUDIO, LOG_ERR, QString(
"Update not found (%1)").arg(out));
329 settingsdigital = bForceDigital ?
331 .m_settings : settings;
349 if (max_speakers > 2 && !bLPCM)
351 if (max_speakers == 2 && bAC3)
378 if (cur_speakers > max_speakers)
380 LOG(VB_AUDIO, LOG_INFO, QString(
"Reset device %1").arg(out));
381 cur_speakers = max_speakers;
387 for (
int i = 1; i <= max_speakers; i++)
397 txt = QCoreApplication::translate(
"(Common)",
"Stereo");
400 txt = QCoreApplication::translate(
"(Common)",
"5.1");
403 txt = QCoreApplication::translate(
"(Common)",
"7.1");
444 QString name =
"MaxChannels";
448 gc->setLabel(tr(
"Speaker configuration"));
450 gc->addSelection(QCoreApplication::translate(
"(Common)",
"Stereo"),
453 gc->setHelpText(tr(
"Select the maximum number of audio "
454 "channels supported by your receiver "
463 gc->setLabel(tr(
"Upconvert stereo to 5.1 surround"));
467 gc->setHelpText(tr(
"If enabled, MythTV will upconvert stereo "
468 "to 5.1 audio. You can enable or disable "
469 "the upconversion during playback at any time."));
477 gc->setLabel(tr(
"Upmix Quality"));
479 gc->addSelection(tr(
"Passive"),
"0");
480 gc->addSelection(tr(
"Hall",
"Upmix Quality"),
"3");
481 gc->addSelection(tr(
"Good",
"Upmix Quality"),
"1");
482 gc->addSelection(tr(
"Best",
"Upmix Quality"),
"2",
true);
484 gc->setHelpText(tr(
"Set the audio surround-upconversion quality."));
493 gc->setLabel(tr(
"Dolby Digital"));
497 gc->setHelpText(tr(
"Enable if your amplifier or sound decoder "
498 "supports AC-3/Dolby Digital. You must use a digital "
499 "connection. Uncheck if using an analog connection."));
507 gc->setLabel(tr(
"DTS"));
511 gc->setHelpText(tr(
"Enable if your amplifier or sound decoder supports "
512 "DTS. You must use a digital connection. Uncheck "
513 "if using an analog connection"));
521 gc->setLabel(tr(
"E-AC-3"));
525 gc->setHelpText(tr(
"Enable if your amplifier or sound decoder supports "
526 "E-AC-3 (DD+). You must use a HDMI connection."));
534 gc->setLabel(tr(
"TrueHD"));
538 gc->setHelpText(tr(
"Enable if your amplifier or sound decoder supports "
539 "Dolby TrueHD. You must use a HDMI connection."));
547 gc->setLabel(tr(
"DTS-HD"));
551 gc->setHelpText(tr(
"Enable if your amplifier or sound decoder supports "
552 "DTS-HD. You must use a HDMI connection."));
567 LOG(VB_GENERAL, LOG_ERR,
568 QString(
"Passthru device %1 isn't usable "
569 "Check audio configuration").arg(name));
582 const QDir& dir,
bool absPath =
true)
585 QFileInfoList entries = dir.entryInfoList();
586 for (
const auto & fi : std::as_const(entries))
600 QString passthrough =
609 : QEvent(kEventType),
610 m_channel(
std::move(channame)),
616 QString
main, QString passthrough,
621 m_parent(parent), m_channels(channels), m_device(
std::move(
main)),
622 m_passthrough(
std::move(passthrough)), m_hd(hd),
623 m_samplerate(hd ? settings.BestSupportedRate() : 48000),
624 m_format(hd ? settings.BestSupportedFormat() :
FORMAT_S16)
630 true,
false, 0, &settings);
638 static_cast<QEvent::Type
>(QEvent::registerEventType());
661 std::array<std::array<int,8>,7> smptelayout {{
666 { 0, 2, 1, 5, 4, 3 },
667 { 0, 2, 1, 6, 4, 5, 3 },
668 { 0, 2, 1, 7, 5, 4, 6, 3 },
673 char *frames =
new (std::align_val_t(16))
char[
m_channels * 1024_UZ *
sizeof(int32_t)];
697 channel =
"frontleft";
700 channel =
"frontright";
710 channel =
"surroundleft";
712 channel =
"rearright";
714 channel =
"rearleft";
718 channel =
"surroundright";
720 channel =
"surroundleft";
722 channel =
"rearright";
726 channel =
"surroundright";
728 channel =
"surroundleft";
731 channel =
"surroundright";
734 QCoreApplication::postEvent(
737 LOG(VB_AUDIO, LOG_INFO, QString(
"AudioTest: %1 (%2->%3)")
738 .arg(channel).arg(i).arg(
current));
749 LOG(VB_AUDIO, LOG_ERR,
"AddData() Audio buffer "
750 "overflow, audio data lost!");
756 std::this_thread::sleep_for(500ms);
764 ::operator
delete[] (frames, std::align_val_t(16));
774 setLabel(tr(
"Audio Configuration Testing"));
775 setHelpText(tr(
"Will play a test pattern on all configured "
807 QString surroundleft;
861 "supported by your audio card. This will be "
862 "a good place to start troubleshooting "
863 "potential errors"));
881 const QString &passthrough,
931 else if (this->sender() ==
m_lfe)
953 else if (this->sender() ==
m_center)
992 QString msg = tr(
"Audio device is invalid or not useable.");
1008 return QObject::event(
event);
1012 return GroupSetting::event(
event);
1014 QString channel = cce->m_channel;
1016 if (!cce->m_fulltest)
1017 return GroupSetting::event(
event);
1028 if (channel ==
"frontleft")
1032 else if (channel ==
"frontright")
1036 else if (channel ==
"center")
1040 else if (channel ==
"lfe")
1044 else if (channel ==
"surroundleft")
1048 else if (channel ==
"surroundright")
1052 else if (channel ==
"rearleft")
1056 else if (channel ==
"rearright")
1076 return GroupSetting::event(
event);
1084 gc->setLabel(tr(
"Use internal volume controls"));
1088 gc->setHelpText(tr(
"If enabled, MythTV will control the PCM and "
1089 "master mixer volume. Disable this option if you "
1090 "prefer to control the volume externally (for "
1091 "example, using your amplifier) or if you use an "
1092 "external mixer program."));
1104 gc->setLabel(tr(
"Mixer device"));
1107 QDir dev(
"/dev",
"mixer*", QDir::Name, QDir::System);
1110 dev.setPath(
"/dev/sound");
1116#if CONFIG_AUDIO_ALSA
1117 gc->addSelection(
"ALSA:default",
"ALSA:default");
1120 gc->addSelection(
"DirectX:",
"DirectX:");
1121 gc->addSelection(
"Windows:",
"Windows:");
1124 gc->addSelection(
"OpenSLES:",
"OpenSLES:");
1127 gc->addSelection(tr(
"software"),
"software");
1130 gc->setHelpText(tr(
"Setting the mixer device to \"%1\" lets MythTV control "
1131 "the volume of all audio at the expense of a slight "
1133 .arg(tr(
"software")));
1140 QT_TR_NOOP(
"Master")};
1146 gc->setLabel(tr(
"Mixer controls"));
1149 gc->addSelection(tr(control), control);
1151 gc->setHelpText(tr(
"Changing the volume adjusts the selected mixer."));
1160 gs->setLabel(tr(
"Master mixer volume"));
1164 gs->setHelpText(tr(
"Initial volume for the Master mixer. This affects "
1165 "all sound created by the audio device. Note: Do not "
1166 "set this too low."));
1174 gs->setLabel(tr(
"PCM mixer volume"));
1178 gs->setHelpText(tr(
"Initial volume for PCM output. Using the volume "
1179 "keys in MythTV will adjust this parameter."));
1187 gc->setLabel(tr(
"Stereo PCM Only"));
1189 gc->setValue(
false);
1191 gc->setHelpText(tr(
"Enable if your amplifier or sound decoder only "
1192 "supports 2 channel PCM (typically an old HDMI 1.0 "
1193 "device). Multichannel audio will be re-encoded to "
1194 "AC-3 when required"));
1202 gc->setLabel(tr(
"Override SRC quality"));
1204 gc->setValue(
false);
1206 gc->setHelpText(tr(
"Enable to override audio sample rate "
1207 "conversion quality."));
1215 gc->setLabel(tr(
"Sample rate conversion"));
1217 gc->addSelection(tr(
"Disabled",
"Sample rate conversion"),
"-1");
1218 gc->addSelection(tr(
"Fastest",
"Sample rate conversion"),
"0");
1219 gc->addSelection(tr(
"Good",
"Sample rate conversion"),
"1",
true);
1220 gc->addSelection(tr(
"Best",
"Sample rate conversion"),
"2");
1222 gc->setHelpText(tr(
"Set the quality of audio sample-rate "
1223 "conversion. \"%1\" (default) provides the best "
1224 "compromise between CPU usage and quality. \"%2\" "
1225 "lets the audio device handle sample-rate conversion.")
1226 .arg(tr(
"Good",
"Sample rate conversion"),
1227 tr(
"Disabled",
"Sample rate conversion")));
1236 gc->setLabel(tr(
"Force audio device output to 48kHz"));
1237 gc->setValue(
false);
1239 gc->setHelpText(tr(
"Force audio sample rate to 48kHz. Some audio devices "
1240 "will report various rates, but they ultimately "
1249 gc->setLabel(tr(
"Separate digital output device"));
1251 gc->setValue(
false);
1253 gc->setHelpText(tr(
"Use a distinct digital output device from default. "
1254 "(default is not checked)"));
1263 gc->setLabel(tr(
"Digital output device"));
1266 gc->addSelection(QCoreApplication::translate(
"(Common)",
"Default"),
1269 gc->addSelection(
"DirectX:Primary Sound Driver");
1271 gc->addSelection(
"ALSA:iec958:{ AES0 0x02 }",
1272 "ALSA:iec958:{ AES0 0x02 }");
1273 gc->addSelection(
"ALSA:hdmi",
"ALSA:hdmi");
1274 gc->addSelection(
"ALSA:plughw:0,3",
"ALSA:plughw:0,3");
1277 gc->setHelpText(tr(
"Audio output device to use for digital audio. This "
1278 "value is currently only used with ALSA and DirectX "
1287 gc->setLabel(tr(
"SPDIF 48kHz rate override"));
1289 gc->setValue(
false);
1291 gc->setHelpText(tr(
"ALSA only. By default, let ALSA determine the "
1292 "passthrough sampling rate. If checked set the sampling "
1293 "rate to 48kHz for passthrough. (default is not "
1302 gc->setLabel(tr(
"HBR passthrough support"));
1306 gc->setHelpText(tr(
"HBR support is required for TrueHD and DTS-HD "
1307 "passthrough. If unchecked, Myth will limit the "
1308 "passthrough bitrate to 6.144Mbit/s. This will "
1309 "disable True-HD passthrough, however will allow "
1310 "DTS-HD content to be sent as DTS-HD Hi-Res. (default "
void Load(void) override
Load data which will ultimately be displayed on-screen or used to determine what appears on-screen (S...
AudioConfigScreen(MythScreenStack *parent, const char *name, GroupSetting *groupSetting)
void Init(void) override
Used after calling Load() to assign data to widgets and other UI initilisation which is prohibited in...
void UpdateVisibility(StandardSetting *)
AudioDeviceComboBox * m_outputDevice
HostCheckBoxSetting * m_passThroughOverride
ADCMap & AudioDeviceMap(void)
AudioOutputSettings UpdateCapabilitiesAC3(void)
HostComboBoxSetting * m_audioUpmixType
static const std::array< const char *, 2 > kMixerControlControls
static HostComboBoxSetting * PassThroughOutputDevice()
HostCheckBoxSetting * m_trueHDPassThrough
static HostComboBoxSetting * MixerDevice()
static HostCheckBoxSetting * AudioUpmix()
static HostCheckBoxSetting * DTSPassThrough()
static HostCheckBoxSetting * SRCQualityOverride()
static HostCheckBoxSetting * TrueHDPassThrough()
HostCheckBoxSetting * m_dtsPassThrough
void CheckConfiguration(void)
static HostCheckBoxSetting * EAC3PassThrough()
static HostComboBoxSetting * AudioUpmixType()
static HostCheckBoxSetting * AC3PassThrough()
static HostCheckBoxSetting * HBRPassthrough()
HostComboBoxSetting * m_passThroughDeviceOverride
HostCheckBoxSetting * m_dtsHDPassThrough
static HostComboBoxSetting * MixerControl()
static HostCheckBoxSetting * Audio48kOverride()
HostCheckBoxSetting * m_ac3PassThrough
static HostComboBoxSetting * MaxAudioChannels()
QString m_lastAudioDevice
static HostCheckBoxSetting * MPCM()
HostCheckBoxSetting * m_mpcm
GroupSetting * m_triggerDigital
HostCheckBoxSetting * m_eac3PassThrough
static HostCheckBoxSetting * DTSHDPassThrough()
HostComboBoxSetting * m_maxAudioChannels
static HostCheckBoxSetting * MythControlsVolume()
AudioOutput::ADCVect m_devices
AudioOutputSettings UpdateCapabilities(bool restore=true, bool AC3=false)
static HostCheckBoxSetting * SPDIFRateOverride()
static HostSpinBoxSetting * PCMVolume()
void setMPCMEnabled(bool flag)
AudioOutput::ADCVect & AudioDeviceVect(void)
static HostComboBoxSetting * SRCQuality()
static HostSpinBoxSetting * MixerVolume()
HostCheckBoxSetting * m_audioUpmix
static HostCheckBoxSetting * PassThroughOverride()
void AudioDescriptionHelp(StandardSetting *setting)
void edit(MythScreenType *screen) override
AudioConfigSettings * m_parent
AudioDeviceComboBox(AudioConfigSettings *parent)
bool IsSupportedChannels(int channels)
int BestSupportedChannels()
bool canFeature(DigitalFeature arg) const
return DigitalFeature mask.
void SetBestSupportedChannels(int channels)
Force set the greatest number of channels supported by the audio device.
void setFeature(DigitalFeature arg)
set the provided digital feature possible values are:
int canPassthrough() const
bool IsInvalid() const
return true if class instance is marked invalid.
AudioOutputSettings m_settings
virtual void Drain(void)=0
static AudioOutput * OpenAudio(const QString &main_device, const QString &passthru_device, AudioFormat format, int channels, AVCodecID codec, int samplerate, AudioOutputSource source, bool set_initial_vol, bool passthru, int upmixer_startup=0, AudioOutputSettings *custom=nullptr)
virtual std::chrono::milliseconds LengthLastData(void) const
static ADCVect * GetOutputList(void)
QVector< AudioDeviceConfig > ADCVect
static AudioDeviceConfig * GetAudioDeviceConfig(QString &name, const QString &desc, bool willsuspendpa=false)
virtual void Pause(bool paused)=0
bool playPinkNoise(char *frames, int channels, int channel, int count, int bits)
Generates and plays pink noise from a speaker for testing.
void setChannel(int channel)
void run() override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
AudioTestThread(QObject *parent, QString main, QString passthrough, int channels, AudioOutputSettings &settings, bool hd)
AudioOutput * m_audioOutput
~AudioTestThread() override
ButtonStandardSetting * m_startButton
ButtonStandardSetting * m_frontright
ButtonStandardSetting * m_lfe
ButtonStandardSetting * m_surroundleft
ButtonStandardSetting * m_frontleft
TransMythUICheckBoxSetting * m_hd
ButtonStandardSetting * m_center
ButtonStandardSetting * m_surroundright
void togglequality(const QString &)
ButtonStandardSetting * m_rearright
bool event(QEvent *event) override
ButtonStandardSetting * m_rearleft
AudioOutputSettings m_settings
void UpdateCapabilities(const QString &main, const QString &passthrough, int channels, const AudioOutputSettings &settings)
ChannelChangedEvent(QString channame, bool fulltest)
static const Type kEventType
This is a wrapper around QThread that does several additional things.
bool isRunning(void) const
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
bool wait(std::chrono::milliseconds time=std::chrono::milliseconds::max())
Wait for the MThread to exit, with a maximum timeout.
Dialog asking for user confirmation.
QString GetSetting(const QString &key, const QString &defaultval="")
int GetNumSetting(const QString &key, int defaultval=0)
bool GetBoolSetting(const QString &key, bool defaultval=false)
MythScreenStack * GetMainStack()
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Screen in which all other widgets are contained and rendered.
void SetBusyPopupMessage(const QString &message)
void addSelection(const QString &label, QString value=QString(), bool select=false)
void edit(MythScreenType *screen) override
void Init(void) override
Used after calling Load() to assign data to widgets and other UI initilisation which is prohibited in...
void Load(void) override
Load data which will ultimately be displayed on-screen or used to determine what appears on-screen (S...
GroupSetting * GetGroupSettings(void) const
virtual void addChild(StandardSetting *child)
void addTargetedChild(const QString &value, StandardSetting *setting)
virtual void setHelpText(const QString &str)
bool haveChanged()
Return true if the setting have changed or any of its children.
void valueChanged(const QString &newValue)
virtual QString getValue(void) const
virtual void setEnabled(bool enabled)
virtual void setLabel(QString str)
void setChanged(bool changed)
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
MythConfirmationDialog * ShowOkPopup(const QString &message, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
MythMainWindow * GetMythMainWindow(void)
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
uint fillSelectionsFromDir(const QDir &dir, uint minor_min, uint minor_max, const QString &card, const QRegularExpression &driver, bool allow_duplicates, V2CaptureDeviceList *pList, const QString &cardType)
VERBOSE_PREAMBLE Most true