MythTV  master
audiogeneralsettings.cpp
Go to the documentation of this file.
1 
2 // -*- Mode: c++ -*-
3 
4 // Standard UNIX C headers
5 #include <chrono> // for milliseconds
6 #include <thread> // for sleep_for
7 #include <fcntl.h>
8 #include <sys/types.h>
9 #include <sys/stat.h>
10 
11 // Qt headers
12 #include <QCoreApplication>
13 #include <QDir>
14 #include <QEvent>
15 #include <utility>
16 
17 // MythTV headers
18 #include "mythconfig.h"
19 #include "mythcorecontext.h"
20 #include "mythdbcon.h"
21 #include "audiooutpututil.h"
22 #include "audiogeneralsettings.h"
23 #include "mythdialogbox.h"
24 #include "mythlogging.h"
25 #include "mythmainwindow.h"
26 
27 extern "C" {
28 #include "libavformat/avformat.h"
29 }
30 
32  HostComboBoxSetting("AudioOutputDevice", true), m_parent(parent)
33 {
34  setLabel(tr("Audio output device"));
35 #ifdef USING_ALSA
36  QString dflt = "ALSA:default";
37 #elif USING_PULSEOUTPUT
38  QString dflt = "PulseAudio:default";
39 #elif CONFIG_DARWIN
40  QString dflt = "CoreAudio:";
41 #elif _WIN32
42  QString dflt = "Windows:";
43 #elif ANDROID
44  QString dflt = "OpenSLES:";
45 #else
46  QString dflt = "NULL";
47 #endif
48  QString current = gCoreContext->GetSetting(QString("AudioOutputDevice"),
49  dflt);
51 
52  connect(this, SIGNAL(valueChanged(StandardSetting *)),
53  this, SLOT(AudioDescriptionHelp(StandardSetting *)));
54 }
55 
57 {
58  AudioRescan();
60 }
61 
63 {
65 
66  if (vect.empty())
67  return;
68 
69  QString value = getValue();
71 
72  // Adding the current value first avoids marking the setting as changed
73  addSelection(value, value, true);
74  for (const auto & it : qAsConst(vect))
75  {
76  if (value != it.m_name)
77  addSelection(it.m_name, it.m_name);
78  }
79 }
80 
82 {
83  QString desc = m_parent->AudioDeviceMap().value(setting->getValue()).m_desc;
84  setHelpText(desc);
85 }
86 
88  GroupSetting *groupSetting)
89  : StandardSettingDialog(parent, name, groupSetting)
90 {
91 }
92 
94 {
95  SetBusyPopupMessage(tr("Scanning for available audio devices"));
97 }
98 
100 {
102 
103  auto *settings = dynamic_cast<AudioConfigSettings*>(GetGroupSettings());
104  if (settings == nullptr)
105  return;
106  settings->CheckConfiguration();
107 }
108 
110 {
111  setLabel(tr("Audio System"));
112 
114  // Rescan button
115 
116  auto *rescan = new ButtonStandardSetting("rescan");
117  rescan->setLabel(tr("Rescan"));
118  rescan->setHelpText(tr("Rescan for available audio devices. "
119  "Current entry will be checked and "
120  "capability entries populated."));
121  addChild(rescan);
122  connect(rescan, SIGNAL(clicked()), SLOT(AudioRescan()));
123 
124  // digital settings
126  m_triggerDigital->setLabel(tr("Digital Audio Capabilities"));
133 
138 
139  //Advanced Settings
140  auto *advancedSettings = new GroupSetting();
141  advancedSettings->setLabel(tr("Advanced Audio Settings"));
142  advancedSettings->setHelpText(tr("Enable extra audio settings. Under most "
143  "usage all options should be left alone"));
144  addChild(advancedSettings);
146  advancedSettings->addChild(m_passThroughOverride);
148  advancedSettings->addChild(m_passThroughDeviceOverride);
150  connect(m_passThroughOverride, SIGNAL(valueChanged(bool)),
152 
153  StandardSetting *srcqualityoverride = SRCQualityOverride();
154  srcqualityoverride->addTargetedChild("1", SRCQuality());
155  addChild(srcqualityoverride);
156 
157  advancedSettings->addChild(Audio48kOverride());
158 #if USING_ALSA
159  advancedSettings->addChild(SPDIFRateOverride());
160 #endif
161 
162  advancedSettings->addChild(HBRPassthrough());
163 
164  advancedSettings->addChild(m_mpcm = MPCM());
165 
166  addChild(m_audioTest = new AudioTest());
167 
168  // Set slots
169  connect(m_maxAudioChannels, SIGNAL(valueChanged(StandardSetting *)),
170  this, SLOT(UpdateVisibility(StandardSetting *)));
171  connect(m_outputDevice, SIGNAL(valueChanged(StandardSetting *)),
172  this, SLOT(UpdateCapabilities()));
173  connect(m_ac3PassThrough, SIGNAL(valueChanged(StandardSetting *)),
174  this, SLOT(UpdateCapabilitiesAC3()));
175 
176  connect(m_dtsPassThrough, SIGNAL(valueChanged(StandardSetting *)),
177  this, SLOT(UpdateCapabilities()));
178  connect(m_eac3PassThrough, SIGNAL(valueChanged(StandardSetting *)),
179  this, SLOT(UpdateCapabilities()));
181  this, SLOT(UpdateCapabilities()));
182  connect(m_dtsHDPassThrough, SIGNAL(valueChanged(StandardSetting *)),
183  this, SLOT(UpdateCapabilities()));
184  //Slot for audio test
185  connect(m_outputDevice, SIGNAL(valueChanged(StandardSetting *)),
186  this, SLOT(UpdateAudioTest()));
187  connect(m_maxAudioChannels, SIGNAL(valueChanged(StandardSetting *)),
188  this, SLOT(UpdateAudioTest()));
189 }
190 
192 {
193  QString name = m_outputDevice->getValue();
195  AudioOutput::GetAudioDeviceConfig(name, name, true);
196  if (adc)
197  {
198  if (adc->m_settings.IsInvalid())
199  {
200  QString msg = tr("%1 is invalid or not useable.").arg(name);
201 
202  ShowOkPopup(msg);
203 
204  LOG(VB_GENERAL, LOG_ERR, QString("Audio device %1 isn't usable")
205  .arg(name));
206  }
207  delete adc;
208  }
209 
210  if (!CheckPassthrough())
211  {
212  QString pt_name = m_passThroughDeviceOverride->getValue();
213  QString pt_msg = tr("Passthrough device is invalid or not useable. Check "
214  "configuration in Advanced Settings:") +
215  pt_name;
216 
217  ShowOkPopup(pt_msg);
218 
219  LOG(VB_GENERAL, LOG_ERR, QString("Audio device %1 isn't usable")
220  .arg(pt_name));
221  }
222 }
223 
225 {
227  AudioRescan();
228  // If this is the initial setup where there was nothing on the DB,
229  // set changed so that user can save.
230  if (gCoreContext->GetSetting(QString("AudioOutputDevice"),"").isEmpty())
231  setChanged(true);
232 }
233 
235 {
236  if (!m_slotLock.tryLock())
237  return;
238 
240 
241  m_audioDevs.clear();
242  for (const auto & dev : qAsConst(*list))
243  m_audioDevs.insert(dev.m_name, dev);
244 
245  m_devices = *list;
246  delete list;
247 
248  QString name = m_outputDevice->getValue();
249  if (!m_audioDevs.contains(name))
250  {
251  // Scan for possible custom entry that isn't in the list
253  AudioOutput::GetAudioDeviceConfig(name, name, true);
254  m_audioDevs.insert(name, *adc);
255  m_devices.append(*adc);
256  delete adc;
257  }
259  m_slotLock.unlock();
261 }
262 
264 {
266  return;
267 
268  int cur_speakers = m_maxAudioChannels->getValue().toInt();
269  m_audioUpmix->setEnabled(cur_speakers > 2);
270  m_audioUpmixType->setEnabled(cur_speakers > 2);
271 }
272 
274  bool restore, bool AC3)
275 {
276  int max_speakers = 8;
277  int realmax_speakers = 8;
278 
279  bool invalid = false;
280  QString out;
281 
282  if (m_outputDevice)
283  out = m_outputDevice->getValue();
284 
285  if (!out.isEmpty())
286  {
287  restore = out != m_lastAudioDevice;
288  m_lastAudioDevice = out;
289  }
290 
291  AudioOutputSettings settings;
292  AudioOutputSettings settingsdigital;
293 
294  // Test if everything is set yet
298  return settings;
299 
300  if (!m_slotLock.tryLock()) // Doing a rescan of channels
301  return settings;
302 
303  bool bAC3 = true;
304  //bool bDTS = true;
305  bool bLPCM = true;
306  bool bEAC3 = true;
307  bool bTRUEHD = true;
308  bool bDTSHD = true;
309 
310  if (!m_audioDevs.contains(out))
311  {
312  LOG(VB_AUDIO, LOG_ERR, QString("Update not found (%1)").arg(out));
313  invalid = true;
314  }
315  else
316  {
317  bool bForceDigital = m_passThroughOverride->boolValue();
318 
319  settings = m_audioDevs.value(out).m_settings;
320  settingsdigital = bForceDigital ?
322  .m_settings : settings;
323 
324  realmax_speakers = max_speakers = settings.BestSupportedChannels();
325 
326  bAC3 = settingsdigital.canFeature(FEATURE_AC3) &&
328  //bDTS = settingsdigital.canFeature(FEATURE_DTS) &&
329  // m_dtsPassThrough->boolValue();
330  bLPCM = settings.canFeature(FEATURE_LPCM) &&
331  !gCoreContext->GetBoolSetting("StereoPCM", false);
332  bEAC3 = settingsdigital.canFeature(FEATURE_EAC3) &&
333  !gCoreContext->GetBoolSetting("Audio48kOverride", false);
334  bTRUEHD = settingsdigital.canFeature(FEATURE_TRUEHD) &&
335  !gCoreContext->GetBoolSetting("Audio48kOverride", false) &&
336  gCoreContext->GetBoolSetting("HBRPassthru", true);
337  bDTSHD = settingsdigital.canFeature(FEATURE_DTSHD) &&
338  !gCoreContext->GetBoolSetting("Audio48kOverride", false);
339 
340  if (max_speakers > 2 && !bLPCM)
341  max_speakers = 2;
342  if (max_speakers == 2 && bAC3)
343  {
344  max_speakers = 6;
345  if (AC3)
346  {
347  restore = true;
348  }
349  }
350  }
351 
352  m_triggerDigital->setEnabled(invalid || settingsdigital.canFeature(
358 
359  int cur_speakers = m_maxAudioChannels->getValue().toInt();
360  if (cur_speakers > m_maxSpeakers)
361  {
363  }
364  if (restore)
365  {
366  cur_speakers = m_maxSpeakers;
367  }
368 
369  if (cur_speakers > max_speakers)
370  {
371  LOG(VB_AUDIO, LOG_INFO, QString("Reset device %1").arg(out));
372  cur_speakers = max_speakers;
373  }
374 
375  // Remove everything and re-add available channels
376  bool chansChanged = m_maxAudioChannels->haveChanged();
378  for (int i = 1; i <= max_speakers; i++)
379  {
380  if (invalid || settings.IsSupportedChannels(i) ||
381  settingsdigital.IsSupportedChannels(i))
382  {
383  QString txt;
384 
385  switch (i)
386  {
387  case 2:
388  txt = QCoreApplication::translate("(Common)", "Stereo");
389  break;
390  case 6:
391  txt = QCoreApplication::translate("(Common)", "5.1");
392  break;
393  case 8:
394  txt = QCoreApplication::translate("(Common)", "7.1");
395  break;
396  default:
397  continue;
398  }
399  m_maxAudioChannels->addSelection(txt, QString::number(i),
400  i == cur_speakers);
401  }
402  }
403  m_maxAudioChannels->setChanged(chansChanged);
404 
405  setMPCMEnabled(settings.canPassthrough() >= 0);
406 
407  // Return values is used by audio test
408  // where we mainly are interested by the number of channels
409  // if we support AC3 and/or LPCM
410  settings.SetBestSupportedChannels(cur_speakers);
411  settings.setFeature(bAC3, FEATURE_AC3);
412  settings.setFeature(bLPCM && realmax_speakers > 2, FEATURE_LPCM);
413 
414  m_slotLock.unlock();
415  return settings;
416 }
417 
419 {
420  return UpdateCapabilities(false, true);
421 }
422 
423 
425 {
426  QString name = "MaxChannels";
427 
428  auto *gc = new HostComboBoxSetting(name, false);
429 
430  gc->setLabel(tr("Speaker configuration"));
431 
432  gc->addSelection(QCoreApplication::translate("(Common)", "Stereo"),
433  "2", true); // default
434 
435  gc->setHelpText(tr("Select the maximum number of audio "
436  "channels supported by your receiver "
437  "and speakers."));
438  return gc;
439 }
440 
442 {
443  auto *gc = new HostCheckBoxSetting("AudioDefaultUpmix");
444 
445  gc->setLabel(tr("Upconvert stereo to 5.1 surround"));
446 
447  gc->setValue(true);
448 
449  gc->setHelpText(tr("If enabled, MythTV will upconvert stereo "
450  "to 5.1 audio. You can enable or disable "
451  "the upconversion during playback at any time."));
452  return gc;
453 }
454 
456 {
457  auto *gc = new HostComboBoxSetting("AudioUpmixType", false);
458 
459  gc->setLabel(tr("Upmix Quality"));
460 
461  gc->addSelection(tr("Passive"), "0");
462  gc->addSelection(tr("Hall", "Upmix Quality"), "3");
463  gc->addSelection(tr("Good", "Upmix Quality"), "1");
464  gc->addSelection(tr("Best", "Upmix Quality"), "2", true); // default
465 
466  gc->setHelpText(tr("Set the audio surround-upconversion quality."));
467 
468  return gc;
469 }
470 
472 {
473  auto *gc = new HostCheckBoxSetting("AC3PassThru");
474 
475  gc->setLabel(tr("Dolby Digital"));
476 
477  gc->setValue(false);
478 
479  gc->setHelpText(tr("Enable if your amplifier or sound decoder "
480  "supports AC-3/Dolby Digital. You must use a digital "
481  "connection. Uncheck if using an analog connection."));
482  return gc;
483 }
484 
486 {
487  auto *gc = new HostCheckBoxSetting("DTSPassThru");
488 
489  gc->setLabel(tr("DTS"));
490 
491  gc->setValue(false);
492 
493  gc->setHelpText(tr("Enable if your amplifier or sound decoder supports "
494  "DTS. You must use a digital connection. Uncheck "
495  "if using an analog connection"));
496  return gc;
497 }
498 
500 {
501  auto *gc = new HostCheckBoxSetting("EAC3PassThru");
502 
503  gc->setLabel(tr("E-AC-3"));
504 
505  gc->setValue(false);
506 
507  gc->setHelpText(tr("Enable if your amplifier or sound decoder supports "
508  "E-AC-3 (DD+). You must use a HDMI connection."));
509  return gc;
510 }
511 
513 {
514  auto *gc = new HostCheckBoxSetting("TrueHDPassThru");
515 
516  gc->setLabel(tr("TrueHD"));
517 
518  gc->setValue(false);
519 
520  gc->setHelpText(tr("Enable if your amplifier or sound decoder supports "
521  "Dolby TrueHD. You must use a HDMI connection."));
522  return gc;
523 }
524 
526 {
527  auto *gc = new HostCheckBoxSetting("DTSHDPassThru");
528 
529  gc->setLabel(tr("DTS-HD"));
530 
531  gc->setValue(false);
532 
533  gc->setHelpText(tr("Enable if your amplifier or sound decoder supports "
534  "DTS-HD. You must use a HDMI connection."));
535  return gc;
536 }
537 
539 {
540  bool ok = true;
541 
543  {
544  QString name = m_passThroughDeviceOverride->getValue();
546  AudioOutput::GetAudioDeviceConfig(name, name, true);
547  if (adc->m_settings.IsInvalid())
548  {
549  LOG(VB_GENERAL, LOG_ERR,
550  QString("Passthru device %1 isn't usable "
551  "Check audio configuration").arg(name));
552  ok = false;
553  }
554  // add it to list of known devices
555  m_audioDevs.insert(name, *adc);
556  m_devices.append(*adc);
557  delete adc;
558  }
559  return ok;
560 }
561 
562 #ifdef USING_OSS
564  const QDir& dir, bool absPath = true)
565 
566 {
567  for (const auto & fi : dir.entryInfoList())
568  {
569  if (absPath)
570  comboBox->addSelection( fi.absoluteFilePath() );
571  else
572  comboBox->addSelection( fi.fileName() );
573  }
574 }
575 #endif
576 
578 {
579  AudioOutputSettings settings = UpdateCapabilities(false);
580  QString out = m_outputDevice->getValue();
581  QString passthrough =
584  int channels = m_maxAudioChannels->getValue().toInt();
585 
586  m_audioTest->UpdateCapabilities(out, passthrough, channels, settings);
587 }
588 
589 ChannelChangedEvent::ChannelChangedEvent(QString channame, bool fulltest)
590  : QEvent(kEventType),
591  m_channel(std::move(channame)),
592  m_fulltest(fulltest)
593 {
594 }
595 
597  QString main, QString passthrough,
598  int channels,
599  AudioOutputSettings &settings,
600  bool hd) :
601  MThread("AudioTest"),
602  m_parent(parent), m_channels(channels), m_device(std::move(main)),
603  m_passthrough(std::move(passthrough)), m_hd(hd)
604 {
605  m_format = hd ? settings.BestSupportedFormat() : FORMAT_S16;
606  m_samplerate = hd ? settings.BestSupportedRate() : 48000;
607 
610  AV_CODEC_ID_NONE, m_samplerate,
612  true, false, 0, &settings);
613  if (result().isEmpty())
614  {
615  m_audioOutput->Pause(true);
616  }
617 }
618 
619 QEvent::Type ChannelChangedEvent::kEventType =
620  static_cast<QEvent::Type>(QEvent::registerEventType());
621 
623 {
624  cancel();
625  wait();
626  delete m_audioOutput;
627 }
628 
630 {
631  m_interrupted = true;
632 }
633 
635 {
636  QString errMsg;
637  if (!m_audioOutput)
638  errMsg = tr("Unable to create AudioOutput.");
639  else
640  errMsg = m_audioOutput->GetError();
641  return errMsg;
642 }
643 
645 {
646  m_channel = channel;
647 }
648 
650 {
651  RunProlog();
652  m_interrupted = false;
653  int smptelayout[7][8] = {
654  { 0, 1, 1 }, //stereo
655  { }, //not used
656  { }, //not used
657  { 0, 2, 1, 4, 3 }, //5.0
658  { 0, 2, 1, 5, 4, 3 }, //5.1
659  { 0, 2, 1, 6, 4, 5, 3 }, //6.1
660  { 0, 2, 1, 7, 5, 4, 6, 3 }, //7.1
661  };
662 
663  if (m_audioOutput)
664  {
665  char *frames_in = new char[static_cast<unsigned long>(m_channels) * 1024 * sizeof(int32_t) + 15];
666  char *frames = reinterpret_cast<char *>(reinterpret_cast<long>(frames_in + 15) & ~0xf);
667 
668  m_audioOutput->Pause(false);
669 
670  int begin = 0;
671  int end = m_channels;
672  if (m_channel >= 0)
673  {
674  begin = m_channel;
675  end = m_channel + 1;
676  }
677  while (!m_interrupted)
678  {
679  for (int i = begin; i < end && !m_interrupted; i++)
680  {
681  int current = smptelayout[m_channels - 2][i];
682 
683  if (m_parent)
684  {
685  QString channel;
686 
687  switch(current)
688  {
689  case 0:
690  channel = "frontleft";
691  break;
692  case 1:
693  channel = "frontright";
694  break;
695  case 2:
696  channel = "center";
697  break;
698  case 3:
699  channel = "lfe";
700  break;
701  case 4:
702  if (m_channels == 6)
703  channel = "surroundleft";
704  else if (m_channels == 7)
705  channel = "rearright";
706  else
707  channel = "rearleft";
708  break;
709  case 5:
710  if (m_channels == 6)
711  channel = "surroundright";
712  else if (m_channels == 7)
713  channel = "surroundleft";
714  else
715  channel = "rearright";
716  break;
717  case 6:
718  if (m_channels == 7)
719  channel = "surroundright";
720  else
721  channel = "surroundleft";
722  break;
723  case 7:
724  channel = "surroundright";
725  break;
726  }
727  QCoreApplication::postEvent(
729  m_channel < 0));
730  LOG(VB_AUDIO, LOG_INFO, QString("AudioTest: %1 (%2->%3)")
731  .arg(channel).arg(i).arg(current));
732  }
733 
734  // play sample sound for about 3s
735  int top = m_samplerate / 1000 * 3;
736  for (int j = 0; j < top && !m_interrupted; j++)
737  {
739  current, 1000,
740  m_hd ? 32 : 16);
741  if (!m_audioOutput->AddFrames(frames, 1000 , -1))
742  {
743  LOG(VB_AUDIO, LOG_ERR, "AddData() Audio buffer "
744  "overflow, audio data lost!");
745  }
746  std::this_thread::sleep_for(std::chrono::milliseconds(m_audioOutput->LengthLastData()));
747  }
748  m_audioOutput->Drain();
749  m_audioOutput->Pause(true);
750  std::this_thread::sleep_for(std::chrono::milliseconds(500)); // .5s pause
751  m_audioOutput->Pause(false);
752  }
753  if (m_channel >= 0)
754  break;
755  }
756  m_audioOutput->Pause(true);
757 
758  delete[] frames_in;
759  }
760  RunEpilog();
761 }
762 
764 {
765  int channels = 2;
766 
767  m_channels = gCoreContext->GetNumSetting("TestingChannels", channels);
768  setLabel(tr("Audio Configuration Testing"));
769  setHelpText(tr("Will play a test pattern on all configured "
770  "speakers"));
771 
773  m_frontleft->setLabel(tr("Front Left"));
774  m_frontleft->setHelpText(tr("Start front left channel test"));
776  connect(m_frontleft,
777  SIGNAL(clicked()), this, SLOT(toggle()));
778 
779  m_frontright = new ButtonStandardSetting(m_channels == 2 ? "1" : "2");
780  m_frontright->setLabel(tr("Front Right"));
781  m_frontright->setHelpText(tr("Start front right channel test"));
783  connect(m_frontright,
784  SIGNAL(clicked()), this, SLOT(toggle()));
785 
787  m_rearleft->setLabel(tr("Rear Left"));
788  m_rearleft->setHelpText(tr("Start rear left channel test"));
790  connect(m_rearleft,
791  SIGNAL(clicked()), this, SLOT(toggle()));
792 
794  m_rearright->setLabel(tr("Rear Right"));
795  m_rearright->setHelpText(tr("Start rear right channel test"));
797  connect(m_rearright,
798  SIGNAL(clicked()), this, SLOT(toggle()));
799 
800  m_lfe = new ButtonStandardSetting(m_channels == 6 ? "5" :
801  m_channels == 7 ? "6" : "7");
802  m_lfe->setLabel(tr("LFE"));
803  m_lfe->setHelpText(tr("Start LFE channel test"));
804  addChild(m_lfe);
805  connect(m_lfe,
806  SIGNAL(clicked()), this, SLOT(toggle()));
807 
809  m_channels == 7 ? "5" : "6");
810  m_surroundleft->setLabel(tr("Surround Left"));
811  m_surroundleft->setHelpText(tr("Start surround left channel test"));
813  connect(m_surroundleft,
814  SIGNAL(clicked()), this, SLOT(toggle()));
815 
817  m_surroundright->setLabel(tr("Surround Right"));
818  m_surroundright->setHelpText(tr("Start surround right channel test"));
820  connect(m_surroundright,
821  SIGNAL(clicked()), this, SLOT(toggle()));
822 
823  m_center = new ButtonStandardSetting("1");
824  m_center->setLabel(tr("Center"));
825  m_center->setHelpText(tr("Start center channel test"));
827  connect(m_center,
828  SIGNAL(clicked()), this, SLOT(toggle()));
829 
830  m_startButton = new ButtonStandardSetting("start");
831  m_startButton->setLabel(tr("Test All"));
832  m_startButton->setHelpText(tr("Start all channels test"));
834  connect(m_startButton, SIGNAL(clicked()), this, SLOT(toggle()));
835 
837  m_hd->setLabel(tr("Use Highest Quality Mode"));
838  m_hd->setHelpText(tr("Use the highest audio quality settings "
839  "supported by your audio card. This will be "
840  "a good place to start troubleshooting "
841  "potential errors"));
842  addChild(m_hd);
843  connect(m_hd, SIGNAL(valueChanged(QString)), this, SLOT(togglequality()));
844 }
845 
847 {
848  if (m_at)
849  {
850  m_at->cancel();
851  m_at->wait();
852  delete m_at;
853  }
854 }
855 
856 
858  const QString &passthrough,
859  int channels,
860  const AudioOutputSettings &settings)
861 {
862  m_main = main;
863  m_passthrough = passthrough;
864  m_channels = channels;
865  m_settings = settings;
868  m_lfe->setEnabled(m_channels >= 6);
872 }
873 
875 {
876  if (this->sender() == m_startButton)
877  {
878  if (m_at && m_at->isRunning())
879  cancelTest();
880  else
881  {
882  prepareTest();
883  m_at->setChannel(-1);
884  m_at->start();
885  m_startButton->setLabel(QCoreApplication::translate("(Common)",
886  "Stop"));
887  }
888  return;
889  }
890  if (m_at && m_at->isRunning())
891  {
892  m_at->cancel();
893  m_at->wait();
894  }
895 
896  prepareTest();
897 
898  int channel = 1;
899 
900  if (this->sender() == m_frontleft)
901  channel = 0;
902  else if (this->sender() == m_frontright)
903  channel = (m_channels == 2) ? 1 : 2;
904  else if (this->sender() == m_rearleft)
905  channel = 5;
906  else if (this->sender() == m_rearright)
907  channel = 4;
908  else if (this->sender() == m_lfe)
909  channel = ((m_channels == 6) ? 5 :((m_channels == 7) ? 6 : 7));
910  else if (this->sender() == m_surroundleft)
911  channel = ((m_channels == 6) ? 4 : ((m_channels == 7) ? 5 : 6));
912  else if (this->sender() == m_surroundright)
913  channel = 3;
914  else if (this->sender() == m_center)
915  channel = 1;
916 
918 
919  m_at->start();
920 }
921 
923 {
924  cancelTest();
925  m_quality = m_hd->boolValue();
926 }
927 
929 {
930  if (m_at && m_at->isRunning())
931  {
932  m_at->cancel();
933  m_startButton->setLabel(tr("Test All"));
934  }
935 }
936 
938 {
939  cancelTest();
940  if (m_at)
941  {
942  m_at->cancel();
943  m_at->wait();
944  delete m_at;
945  }
946 
949  if (!m_at->result().isEmpty())
950  {
951  QString msg = tr("Audio device is invalid or not useable.");
953 
954  auto *mcd = new MythConfirmationDialog(mainStack,
955  msg, false);
956 
957  if (mcd->Create())
958  mainStack->AddScreen(mcd);
959  else
960  delete mcd;
961  }
962 }
963 
964 bool AudioTest::event(QEvent *event)
965 {
966  if (event->type() != ChannelChangedEvent::kEventType)
967  return QObject::event(event); //not handled
968 
969  auto *cce = dynamic_cast<ChannelChangedEvent*>(event);
970  if (cce == nullptr)
971  return false;
972 
973  QString channel = cce->m_channel;
974 
975  if (!cce->m_fulltest)
976  return false;
977 
978  bool fl = false;
979  bool fr = false;
980  bool c = false;
981  bool lfe = false;
982  bool sl = false;
983  bool sr = false;
984  bool rl = false;
985  bool rr = false;
986 
987  if (channel == "frontleft")
988  {
989  fl = true;
990  }
991  else if (channel == "frontright")
992  {
993  fr = true;
994  }
995  else if (channel == "center")
996  {
997  c = true;
998  }
999  else if (channel == "lfe")
1000  {
1001  lfe = true;
1002  }
1003  else if (channel == "surroundleft")
1004  {
1005  sl = true;
1006  }
1007  else if (channel == "surroundright")
1008  {
1009  sr = true;
1010  }
1011  else if (channel == "rearleft")
1012  {
1013  rl = true;
1014  }
1015  else if (channel == "rearright")
1016  {
1017  rr = true;
1018  }
1019  if (m_frontleft)
1020  m_frontleft->setEnabled(fl);
1021  if (m_frontright)
1022  m_frontright->setEnabled(fr);
1023  if (m_center)
1024  m_center->setEnabled(c);
1025  if (m_surroundleft)
1027  if (m_surroundright)
1029  if (m_rearleft)
1030  m_rearleft->setEnabled(rl);
1031  if (m_rearright)
1032  m_rearright->setEnabled(rr);
1033  if (m_lfe)
1034  m_lfe->setEnabled(lfe);
1035  return false;
1036 }
1037 
1038 
1040 {
1041  auto *gc = new HostCheckBoxSetting("MythControlsVolume");
1042 
1043  gc->setLabel(tr("Use internal volume controls"));
1044 
1045  gc->setValue(true);
1046 
1047  gc->setHelpText(tr("If enabled, MythTV will control the PCM and "
1048  "master mixer volume. Disable this option if you "
1049  "prefer to control the volume externally (for "
1050  "example, using your amplifier) or if you use an "
1051  "external mixer program."));
1052 
1053  gc->addTargetedChild("1", MixerDevice());
1054  gc->addTargetedChild("1", MixerControl());
1055  gc->addTargetedChild("1", MixerVolume());
1056  gc->addTargetedChild("1", PCMVolume());
1057  return gc;
1058 }
1059 
1061 {
1062  auto *gc = new HostComboBoxSetting("MixerDevice", true);
1063  gc->setLabel(tr("Mixer device"));
1064 
1065 #ifdef USING_OSS
1066  QDir dev("/dev", "mixer*", QDir::Name, QDir::System);
1067  fillSelectionsFromDir(gc, dev);
1068 
1069  dev.setPath("/dev/sound");
1070  if (dev.exists())
1071  {
1072  fillSelectionsFromDir(gc, dev);
1073  }
1074 #endif
1075 #ifdef USING_ALSA
1076  gc->addSelection("ALSA:default", "ALSA:default");
1077 #endif
1078 #ifdef _WIN32
1079  gc->addSelection("DirectX:", "DirectX:");
1080  gc->addSelection("Windows:", "Windows:");
1081 #endif
1082 #ifdef ANDROID
1083  gc->addSelection("OpenSLES:", "OpenSLES:");
1084 #endif
1085 #if !defined(_WIN32)
1086  gc->addSelection(tr("software"), "software");
1087 #endif
1088 
1089  gc->setHelpText(tr("Setting the mixer device to \"%1\" lets MythTV control "
1090  "the volume of all audio at the expense of a slight "
1091  "quality loss.")
1092  .arg(tr("software")));
1093 
1094  return gc;
1095 }
1096 
1098  {QT_TR_NOOP("PCM"),
1099  QT_TR_NOOP("Master")};
1100 
1102 {
1103  auto *gc = new HostComboBoxSetting("MixerControl", true);
1104 
1105  gc->setLabel(tr("Mixer controls"));
1106 
1107  for (auto & control : kMixerControlControls)
1108  gc->addSelection(tr(control), control);
1109 
1110  gc->setHelpText(tr("Changing the volume adjusts the selected mixer."));
1111 
1112  return gc;
1113 }
1114 
1116 {
1117  auto *gs = new HostSpinBoxSetting("MasterMixerVolume", 0, 100, 1);
1118 
1119  gs->setLabel(tr("Master mixer volume"));
1120 
1121  gs->setValue(70);
1122 
1123  gs->setHelpText(tr("Initial volume for the Master mixer. This affects "
1124  "all sound created by the audio device. Note: Do not "
1125  "set this too low."));
1126  return gs;
1127 }
1128 
1130 {
1131  auto *gs = new HostSpinBoxSetting("PCMMixerVolume", 0, 100, 1);
1132 
1133  gs->setLabel(tr("PCM mixer volume"));
1134 
1135  gs->setValue(70);
1136 
1137  gs->setHelpText(tr("Initial volume for PCM output. Using the volume "
1138  "keys in MythTV will adjust this parameter."));
1139  return gs;
1140 }
1141 
1143 {
1144  auto *gc = new HostCheckBoxSetting("StereoPCM");
1145 
1146  gc->setLabel(tr("Stereo PCM Only"));
1147 
1148  gc->setValue(false);
1149 
1150  gc->setHelpText(tr("Enable if your amplifier or sound decoder only "
1151  "supports 2 channel PCM (typically an old HDMI 1.0 "
1152  "device). Multichannel audio will be re-encoded to "
1153  "AC-3 when required"));
1154  return gc;
1155 }
1156 
1158 {
1159  auto *gc = new HostCheckBoxSetting("SRCQualityOverride");
1160 
1161  gc->setLabel(tr("Override SRC quality"));
1162 
1163  gc->setValue(false);
1164 
1165  gc->setHelpText(tr("Enable to override audio sample rate "
1166  "conversion quality."));
1167  return gc;
1168 }
1169 
1171 {
1172  auto *gc = new HostComboBoxSetting("SRCQuality", false);
1173 
1174  gc->setLabel(tr("Sample rate conversion"));
1175 
1176  gc->addSelection(tr("Disabled", "Sample rate conversion"), "-1");
1177  gc->addSelection(tr("Fastest", "Sample rate conversion"), "0");
1178  gc->addSelection(tr("Good", "Sample rate conversion"), "1", true); // default
1179  gc->addSelection(tr("Best", "Sample rate conversion"), "2");
1180 
1181  gc->setHelpText(tr("Set the quality of audio sample-rate "
1182  "conversion. \"%1\" (default) provides the best "
1183  "compromise between CPU usage and quality. \"%2\" "
1184  "lets the audio device handle sample-rate conversion.")
1185  .arg(tr("Good", "Sample rate conversion"))
1186  .arg(tr("Disabled", "Sample rate conversion")));
1187 
1188  return gc;
1189 }
1190 
1192 {
1193  auto *gc = new HostCheckBoxSetting("Audio48kOverride");
1194 
1195  gc->setLabel(tr("Force audio device output to 48kHz"));
1196  gc->setValue(false);
1197 
1198  gc->setHelpText(tr("Force audio sample rate to 48kHz. Some audio devices "
1199  "will report various rates, but they ultimately "
1200  "crash."));
1201  return gc;
1202 }
1203 
1205 {
1206  auto *gc = new HostCheckBoxSetting("PassThruDeviceOverride");
1207 
1208  gc->setLabel(tr("Separate digital output device"));
1209 
1210  gc->setValue(false);
1211 
1212  gc->setHelpText(tr("Use a distinct digital output device from default. "
1213  "(default is not checked)"));
1214  return gc;
1215 }
1216 
1218 {
1219  auto *gc = new HostComboBoxSetting("PassThruOutputDevice",
1220  true);
1221 
1222  gc->setLabel(tr("Digital output device"));
1223  //TODO Is default not equivalent to PassThroughOverride off? if so
1224  //PassThruDeviceOverridedsetting could be removed
1225  gc->addSelection(QCoreApplication::translate("(Common)", "Default"),
1226  "Default");
1227 #ifdef _WIN32
1228  gc->addSelection("DirectX:Primary Sound Driver");
1229 #else
1230  gc->addSelection("ALSA:iec958:{ AES0 0x02 }",
1231  "ALSA:iec958:{ AES0 0x02 }");
1232  gc->addSelection("ALSA:hdmi", "ALSA:hdmi");
1233  gc->addSelection("ALSA:plughw:0,3", "ALSA:plughw:0,3");
1234 #endif
1235 
1236  gc->setHelpText(tr("Audio output device to use for digital audio. This "
1237  "value is currently only used with ALSA and DirectX "
1238  "sound output."));
1239  return gc;
1240 }
1241 
1243 {
1244  auto *gc = new HostCheckBoxSetting("SPDIFRateOverride");
1245 
1246  gc->setLabel(tr("SPDIF 48kHz rate override"));
1247 
1248  gc->setValue(false);
1249 
1250  gc->setHelpText(tr("ALSA only. By default, let ALSA determine the "
1251  "passthrough sampling rate. If checked set the sampling "
1252  "rate to 48kHz for passthrough. (default is not "
1253  "checked)"));
1254  return gc;
1255 }
1256 
1258 {
1259  auto *gc = new HostCheckBoxSetting("HBRPassthru");
1260 
1261  gc->setLabel(tr("HBR passthrough support"));
1262 
1263  gc->setValue(true);
1264 
1265  gc->setHelpText(tr("HBR support is required for TrueHD and DTS-HD "
1266  "passthrough. If unchecked, Myth will limit the "
1267  "passthrough bitrate to 6.144Mbit/s. This will "
1268  "disable True-HD passthrough, however will allow "
1269  "DTS-HD content to be sent as DTS-HD Hi-Res. (default "
1270  "is checked)"));
1271  return gc;
1272 }
1273 
1275 {
1276  m_mpcm->setEnabled(flag);
1277 }
1278 // vim:set sw=4 ts=4 expandtab:
void RunEpilog(void)
Cleans up a thread's resources, call this if you reimplement run().
Definition: mthread.cpp:215
HostCheckBoxSetting * m_ac3PassThrough
static void fillSelectionsFromDir(HostComboBoxSetting *comboBox, const QDir &dir, bool absPath=true)
static const char * kMixerControlControls[]
~AudioTest() override
ButtonStandardSetting * m_rearright
static HostCheckBoxSetting * HBRPassthrough()
ChannelChangedEvent(QString channame, bool fulltest)
This is a wrapper around QThread that does several additional things.
Definition: mthread.h:46
QVector< AudioDeviceConfig > ADCVect
Definition: audiooutput.h:47
bool event(QEvent *event) override
static HostComboBoxSetting * PassThroughOutputDevice()
VERBOSE_PREAMBLE Most true
Definition: verbosedefs.h:91
AudioOutput * m_audioOutput
HostComboBoxSetting * m_audioUpmixType
Dialog asking for user confirmation.
void UpdateVisibility(StandardSetting *)
void edit(MythScreenType *screen) override
bool IsSupportedChannels(int channels)
MythConfirmationDialog * ShowOkPopup(const QString &message, QObject *parent, const char *slot, bool showCancel)
Non-blocking version of MythPopupBox::showOkPopup()
AudioDeviceComboBox(AudioConfigSettings *parent)
bool canFeature(DigitalFeature arg) const
return DigitalFeature mask.
TransMythUICheckBoxSetting * m_hd
AudioConfigSettings * m_parent
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)
Definition: audiooutput.cpp:58
static HostCheckBoxSetting * SRCQualityOverride()
virtual int64_t LengthLastData(void) const
Definition: audiooutput.h:128
virtual void Drain(void)=0
virtual void Load(void)
Definition: element.h:83
bool wait(unsigned long time=ULONG_MAX)
Wait for the MThread to exit, with a maximum timeout.
Definition: mthread.cpp:311
void addSelection(const QString &label, QString value=QString(), bool select=false)
virtual void setHelpText(const QString &str)
void SetBestSupportedChannels(int channels)
Force set the greatest number of channels supported by the audio device.
void setChanged(bool changed)
HostCheckBoxSetting * m_dtsPassThrough
MythCoreContext * gCoreContext
This global variable contains the MythCoreContext instance for the app.
MythScreenStack * GetMainStack()
void Init(void) override
Used after calling Load() to assign data to widgets and other UI initilisation which is prohibited in...
static HostCheckBoxSetting * TrueHDPassThrough()
AudioOutputSettings m_settings
Definition: audiooutput.h:34
AudioTestThread(QObject *parent, QString main, QString passthrough, int channels, AudioOutputSettings &settings, bool hd)
static HostCheckBoxSetting * MPCM()
ButtonStandardSetting * m_lfe
virtual QString getValue(void) const
AudioOutputSettings UpdateCapabilitiesAC3(void)
void run() override
Runs the Qt event loop unless we have a QRunnable, in which case we run the runnable run instead.
static HostCheckBoxSetting * PassThroughOverride()
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
AudioFormat BestSupportedFormat()
ButtonStandardSetting * m_startButton
static char * GeneratePinkFrames(char *frames, int channels, int channel, int count, int bits=16)
static HostComboBoxSetting * MaxAudioChannels()
virtual void Pause(bool paused)=0
virtual void setLabel(QString str)
static HostSpinBoxSetting * PCMVolume()
QDateTime current(bool stripped)
Returns current Date and Time in UTC.
Definition: mythdate.cpp:10
QString GetSetting(const QString &key, const QString &defaultval="")
void setFeature(DigitalFeature arg)
set the provided digital feature possible values are:
void setChannel(int channel)
static HostComboBoxSetting * MixerDevice()
void valueChanged(const QString &newValue)
ButtonStandardSetting * m_frontright
bool haveChanged()
Return true if the setting have changed or any of its children.
bool isRunning(void) const
Definition: mthread.cpp:274
HostCheckBoxSetting * m_mpcm
HostCheckBoxSetting * m_eac3PassThrough
static HostComboBoxSetting * MixerControl()
virtual void setEnabled(bool enabled)
static HostComboBoxSetting * SRCQuality()
void Load(void) override
Load data which will ultimately be displayed on-screen or used to determine what appears on-screen (S...
void SetBusyPopupMessage(const QString &message)
static HostSpinBoxSetting * MixerVolume()
static AudioDeviceConfig * GetAudioDeviceConfig(QString &name, QString &desc, bool willsuspendpa=false)
AudioDeviceComboBox * m_outputDevice
AudioTestThread * m_at
static HostComboBoxSetting * AudioUpmixType()
virtual void addChild(StandardSetting *child)
MythMainWindow * GetMythMainWindow(void)
HostComboBoxSetting * m_passThroughDeviceOverride
void Init(void) override
Used after calling Load() to assign data to widgets and other UI initilisation which is prohibited in...
int GetNumSetting(const QString &key, int defaultval=0)
void AudioDescriptionHelp(StandardSetting *setting)
AudioOutputSettings UpdateCapabilities(bool restore=true, bool AC3=false)
AudioOutputSettings m_settings
bool GetBoolSetting(const QString &key, bool defaultval=false)
static HostCheckBoxSetting * SPDIFRateOverride()
HostCheckBoxSetting * m_audioUpmix
static HostCheckBoxSetting * DTSPassThrough()
GroupSetting()=default
static HostCheckBoxSetting * EAC3PassThrough()
void edit(MythScreenType *screen) override
void RunProlog(void)
Sets up a thread, call this if you reimplement run().
Definition: mthread.cpp:202
HostCheckBoxSetting * m_passThroughOverride
void start(QThread::Priority p=QThread::InheritPriority)
Tell MThread to start running the thread in the near future.
Definition: mthread.cpp:294
ButtonStandardSetting * m_surroundleft
GroupSetting * GetGroupSettings(void) const
static HostCheckBoxSetting * AudioUpmix()
AudioConfigScreen(MythScreenStack *parent, const char *name, GroupSetting *groupSetting)
static HostCheckBoxSetting * Audio48kOverride()
AudioOutput::ADCVect & AudioDeviceVect(void)
HostCheckBoxSetting * m_dtsHDPassThrough
static HostCheckBoxSetting * DTSHDPassThrough()
Screen in which all other widgets are contained and rendered.
HostCheckBoxSetting * m_trueHDPassThrough
ButtonStandardSetting * m_frontleft
ButtonStandardSetting * m_rearleft
static ADCVect * GetOutputList(void)
void togglequality(void)
static HostCheckBoxSetting * AC3PassThrough()
void addTargetedChild(const QString &value, StandardSetting *setting)
void Load(void) override
Load data which will ultimately be displayed on-screen or used to determine what appears on-screen (S...
ButtonStandardSetting * m_surroundright
AudioOutput::ADCVect m_devices
static HostCheckBoxSetting * MythControlsVolume()
QString GetError(void) const
Definition: audiooutput.h:145
void UpdateCapabilities(const QString &main, const QString &passthrough, int channels, const AudioOutputSettings &settings)
HostComboBoxSetting * m_maxAudioChannels
ADCMap & AudioDeviceMap(void)
GroupSetting * m_triggerDigital
bool IsInvalid() const
return true if class instance is marked invalid.
ButtonStandardSetting * m_center
virtual bool AddFrames(void *buffer, int frames, int64_t timecode)=0
Add frames to the audiobuffer for playback.
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23