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  foreach (auto & it, 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  foreach (auto & dev, *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  foreach (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 
590  QString main, QString passthrough,
591  int channels,
592  AudioOutputSettings &settings,
593  bool hd) :
594  MThread("AudioTest"),
595  m_parent(parent), m_channels(channels), m_device(std::move(main)),
596  m_passthrough(std::move(passthrough)), m_hd(hd)
597 {
598  m_format = hd ? settings.BestSupportedFormat() : FORMAT_S16;
599  m_samplerate = hd ? settings.BestSupportedRate() : 48000;
600 
603  AV_CODEC_ID_NONE, m_samplerate,
605  true, false, 0, &settings);
606  if (result().isEmpty())
607  {
608  m_audioOutput->Pause(true);
609  }
610 }
611 
612 QEvent::Type ChannelChangedEvent::kEventType =
613  (QEvent::Type) QEvent::registerEventType();
614 
616 {
617  cancel();
618  wait();
619  delete m_audioOutput;
620 }
621 
623 {
624  m_interrupted = true;
625 }
626 
628 {
629  QString errMsg;
630  if (!m_audioOutput)
631  errMsg = tr("Unable to create AudioOutput.");
632  else
633  errMsg = m_audioOutput->GetError();
634  return errMsg;
635 }
636 
638 {
639  m_channel = channel;
640 }
641 
643 {
644  RunProlog();
645  m_interrupted = false;
646  int smptelayout[7][8] = {
647  { 0, 1, 1 }, //stereo
648  { }, //not used
649  { }, //not used
650  { 0, 2, 1, 4, 3 }, //5.0
651  { 0, 2, 1, 5, 4, 3 }, //5.1
652  { 0, 2, 1, 6, 4, 5, 3 }, //6.1
653  { 0, 2, 1, 7, 5, 4, 6, 3 }, //7.1
654  };
655 
656  if (m_audioOutput)
657  {
658  char *frames_in = new char[m_channels * 1024 * sizeof(int32_t) + 15];
659  char *frames = (char *)(((long)frames_in + 15) & ~0xf);
660 
661  m_audioOutput->Pause(false);
662 
663  int begin = 0;
664  int end = m_channels;
665  if (m_channel >= 0)
666  {
667  begin = m_channel;
668  end = m_channel + 1;
669  }
670  while (!m_interrupted)
671  {
672  for (int i = begin; i < end && !m_interrupted; i++)
673  {
674  int current = smptelayout[m_channels - 2][i];
675 
676  if (m_parent)
677  {
678  QString channel;
679 
680  switch(current)
681  {
682  case 0:
683  channel = "frontleft";
684  break;
685  case 1:
686  channel = "frontright";
687  break;
688  case 2:
689  channel = "center";
690  break;
691  case 3:
692  channel = "lfe";
693  break;
694  case 4:
695  if (m_channels == 6)
696  channel = "surroundleft";
697  else if (m_channels == 7)
698  channel = "rearright";
699  else
700  channel = "rearleft";
701  break;
702  case 5:
703  if (m_channels == 6)
704  channel = "surroundright";
705  else if (m_channels == 7)
706  channel = "surroundleft";
707  else
708  channel = "rearright";
709  break;
710  case 6:
711  if (m_channels == 7)
712  channel = "surroundright";
713  else
714  channel = "surroundleft";
715  break;
716  case 7:
717  channel = "surroundright";
718  break;
719  }
720  QCoreApplication::postEvent(
721  m_parent, new ChannelChangedEvent(channel,
722  m_channel < 0));
723  LOG(VB_AUDIO, LOG_INFO, QString("AudioTest: %1 (%2->%3)")
724  .arg(channel).arg(i).arg(current));
725  }
726 
727  // play sample sound for about 3s
728  int top = m_samplerate / 1000 * 3;
729  for (int j = 0; j < top && !m_interrupted; j++)
730  {
732  current, 1000,
733  m_hd ? 32 : 16);
734  if (!m_audioOutput->AddFrames(frames, 1000 , -1))
735  {
736  LOG(VB_AUDIO, LOG_ERR, "AddData() Audio buffer "
737  "overflow, audio data lost!");
738  }
739  std::this_thread::sleep_for(std::chrono::milliseconds(m_audioOutput->LengthLastData()));
740  }
741  m_audioOutput->Drain();
742  m_audioOutput->Pause(true);
743  std::this_thread::sleep_for(std::chrono::milliseconds(500)); // .5s pause
744  m_audioOutput->Pause(false);
745  }
746  if (m_channel >= 0)
747  break;
748  }
749  m_audioOutput->Pause(true);
750 
751  delete[] frames_in;
752  }
753  RunEpilog();
754 }
755 
757 {
758  int channels = 2;
759 
760  m_channels = gCoreContext->GetNumSetting("TestingChannels", channels);
761  setLabel(tr("Audio Configuration Testing"));
762  setHelpText(tr("Will play a test pattern on all configured "
763  "speakers"));
764 
766  m_frontleft->setLabel(tr("Front Left"));
767  m_frontleft->setHelpText(tr("Start front left channel test"));
769  connect(m_frontleft,
770  SIGNAL(clicked()), this, SLOT(toggle()));
771 
772  m_frontright = new ButtonStandardSetting(m_channels == 2 ? "1" : "2");
773  m_frontright->setLabel(tr("Front Right"));
774  m_frontright->setHelpText(tr("Start front right channel test"));
776  connect(m_frontright,
777  SIGNAL(clicked()), this, SLOT(toggle()));
778 
780  m_rearleft->setLabel(tr("Rear Left"));
781  m_rearleft->setHelpText(tr("Start rear left channel test"));
783  connect(m_rearleft,
784  SIGNAL(clicked()), this, SLOT(toggle()));
785 
787  m_rearright->setLabel(tr("Rear Right"));
788  m_rearright->setHelpText(tr("Start rear right channel test"));
790  connect(m_rearright,
791  SIGNAL(clicked()), this, SLOT(toggle()));
792 
793  m_lfe = new ButtonStandardSetting(m_channels == 6 ? "5" :
794  m_channels == 7 ? "6" : "7");
795  m_lfe->setLabel(tr("LFE"));
796  m_lfe->setHelpText(tr("Start LFE channel test"));
797  addChild(m_lfe);
798  connect(m_lfe,
799  SIGNAL(clicked()), this, SLOT(toggle()));
800 
802  m_channels == 7 ? "5" : "6");
803  m_surroundleft->setLabel(tr("Surround Left"));
804  m_surroundleft->setHelpText(tr("Start surround left channel test"));
806  connect(m_surroundleft,
807  SIGNAL(clicked()), this, SLOT(toggle()));
808 
810  m_surroundright->setLabel(tr("Surround Right"));
811  m_surroundright->setHelpText(tr("Start surround right channel test"));
813  connect(m_surroundright,
814  SIGNAL(clicked()), this, SLOT(toggle()));
815 
816  m_center = new ButtonStandardSetting("1");
817  m_center->setLabel(tr("Center"));
818  m_center->setHelpText(tr("Start center channel test"));
820  connect(m_center,
821  SIGNAL(clicked()), this, SLOT(toggle()));
822 
823  m_startButton = new ButtonStandardSetting("start");
824  m_startButton->setLabel(tr("Test All"));
825  m_startButton->setHelpText(tr("Start all channels test"));
827  connect(m_startButton, SIGNAL(clicked()), this, SLOT(toggle()));
828 
830  m_hd->setLabel(tr("Use Highest Quality Mode"));
831  m_hd->setHelpText(tr("Use the highest audio quality settings "
832  "supported by your audio card. This will be "
833  "a good place to start troubleshooting "
834  "potential errors"));
835  addChild(m_hd);
836  connect(m_hd, SIGNAL(valueChanged(QString)), this, SLOT(togglequality()));
837 }
838 
840 {
841  if (m_at)
842  {
843  m_at->cancel();
844  m_at->wait();
845  delete m_at;
846  }
847 }
848 
849 
851  const QString &passthrough,
852  int channels,
853  const AudioOutputSettings &settings)
854 {
855  m_main = main;
856  m_passthrough = passthrough;
857  m_channels = channels;
858  m_settings = settings;
861  m_lfe->setEnabled(m_channels >= 6);
865 }
866 
868 {
869  if (this->sender() == m_startButton)
870  {
871  if (m_at && m_at->isRunning())
872  cancelTest();
873  else
874  {
875  prepareTest();
876  m_at->setChannel(-1);
877  m_at->start();
878  m_startButton->setLabel(QCoreApplication::translate("(Common)",
879  "Stop"));
880  }
881  return;
882  }
883  if (m_at && m_at->isRunning())
884  {
885  m_at->cancel();
886  m_at->wait();
887  }
888 
889  prepareTest();
890 
891  int channel = 1;
892 
893  if (this->sender() == m_frontleft)
894  channel = 0;
895  else if (this->sender() == m_frontright)
896  channel = (m_channels == 2) ? 1 : 2;
897  else if (this->sender() == m_rearleft)
898  channel = 5;
899  else if (this->sender() == m_rearright)
900  channel = 4;
901  else if (this->sender() == m_lfe)
902  channel = ((m_channels == 6) ? 5 :((m_channels == 7) ? 6 : 7));
903  else if (this->sender() == m_surroundleft)
904  channel = ((m_channels == 6) ? 4 : ((m_channels == 7) ? 5 : 6));
905  else if (this->sender() == m_surroundright)
906  channel = 3;
907  else if (this->sender() == m_center)
908  channel = 1;
909 
910  m_at->setChannel(channel);
911 
912  m_at->start();
913 }
914 
916 {
917  cancelTest();
918  m_quality = m_hd->boolValue();
919 }
920 
922 {
923  if (m_at && m_at->isRunning())
924  {
925  m_at->cancel();
926  m_startButton->setLabel(tr("Test All"));
927  }
928 }
929 
931 {
932  cancelTest();
933  if (m_at)
934  {
935  m_at->cancel();
936  m_at->wait();
937  delete m_at;
938  }
939 
942  if (!m_at->result().isEmpty())
943  {
944  QString msg = tr("Audio device is invalid or not useable.");
946 
947  auto *mcd = new MythConfirmationDialog(mainStack,
948  msg, false);
949 
950  if (mcd->Create())
951  mainStack->AddScreen(mcd);
952  else
953  delete mcd;
954  }
955 }
956 
957 bool AudioTest::event(QEvent *event)
958 {
959  if (event->type() != ChannelChangedEvent::kEventType)
960  return QObject::event(event); //not handled
961 
962  auto *cce = (ChannelChangedEvent*)(event);
963  QString channel = cce->m_channel;
964 
965  if (!cce->m_fulltest)
966  return false;
967 
968  bool fl = false;
969  bool fr = false;
970  bool c = false;
971  bool lfe = false;
972  bool sl = false;
973  bool sr = false;
974  bool rl = false;
975  bool rr = false;
976 
977  if (channel == "frontleft")
978  {
979  fl = true;
980  }
981  else if (channel == "frontright")
982  {
983  fr = true;
984  }
985  else if (channel == "center")
986  {
987  c = true;
988  }
989  else if (channel == "lfe")
990  {
991  lfe = true;
992  }
993  else if (channel == "surroundleft")
994  {
995  sl = true;
996  }
997  else if (channel == "surroundright")
998  {
999  sr = true;
1000  }
1001  else if (channel == "rearleft")
1002  {
1003  rl = true;
1004  }
1005  else if (channel == "rearright")
1006  {
1007  rr = true;
1008  }
1009  if (m_frontleft)
1010  m_frontleft->setEnabled(fl);
1011  if (m_frontright)
1012  m_frontright->setEnabled(fr);
1013  if (m_center)
1014  m_center->setEnabled(c);
1015  if (m_surroundleft)
1017  if (m_surroundright)
1019  if (m_rearleft)
1020  m_rearleft->setEnabled(rl);
1021  if (m_rearright)
1022  m_rearright->setEnabled(rr);
1023  if (m_lfe)
1024  m_lfe->setEnabled(lfe);
1025  return false;
1026 }
1027 
1028 
1030 {
1031  auto *gc = new HostCheckBoxSetting("MythControlsVolume");
1032 
1033  gc->setLabel(tr("Use internal volume controls"));
1034 
1035  gc->setValue(true);
1036 
1037  gc->setHelpText(tr("If enabled, MythTV will control the PCM and "
1038  "master mixer volume. Disable this option if you "
1039  "prefer to control the volume externally (for "
1040  "example, using your amplifier) or if you use an "
1041  "external mixer program."));
1042 
1043  gc->addTargetedChild("1", MixerDevice());
1044  gc->addTargetedChild("1", MixerControl());
1045  gc->addTargetedChild("1", MixerVolume());
1046  gc->addTargetedChild("1", PCMVolume());
1047  return gc;
1048 }
1049 
1051 {
1052  auto *gc = new HostComboBoxSetting("MixerDevice", true);
1053  gc->setLabel(tr("Mixer device"));
1054 
1055 #ifdef USING_OSS
1056  QDir dev("/dev", "mixer*", QDir::Name, QDir::System);
1057  fillSelectionsFromDir(gc, dev);
1058 
1059  dev.setPath("/dev/sound");
1060  if (dev.exists())
1061  {
1062  fillSelectionsFromDir(gc, dev);
1063  }
1064 #endif
1065 #ifdef USING_ALSA
1066  gc->addSelection("ALSA:default", "ALSA:default");
1067 #endif
1068 #ifdef _WIN32
1069  gc->addSelection("DirectX:", "DirectX:");
1070  gc->addSelection("Windows:", "Windows:");
1071 #endif
1072 #ifdef ANDROID
1073  gc->addSelection("OpenSLES:", "OpenSLES:");
1074 #endif
1075 #if !defined(_WIN32)
1076  gc->addSelection(tr("software"), "software");
1077 #endif
1078 
1079  gc->setHelpText(tr("Setting the mixer device to \"%1\" lets MythTV control "
1080  "the volume of all audio at the expense of a slight "
1081  "quality loss.")
1082  .arg(tr("software")));
1083 
1084  return gc;
1085 }
1086 
1088  {QT_TR_NOOP("PCM"),
1089  QT_TR_NOOP("Master")};
1090 
1092 {
1093  auto *gc = new HostComboBoxSetting("MixerControl", true);
1094 
1095  gc->setLabel(tr("Mixer controls"));
1096 
1097  for (auto & control : kMixerControlControls)
1098  gc->addSelection(tr(control), control);
1099 
1100  gc->setHelpText(tr("Changing the volume adjusts the selected mixer."));
1101 
1102  return gc;
1103 }
1104 
1106 {
1107  auto *gs = new HostSpinBoxSetting("MasterMixerVolume", 0, 100, 1);
1108 
1109  gs->setLabel(tr("Master mixer volume"));
1110 
1111  gs->setValue(70);
1112 
1113  gs->setHelpText(tr("Initial volume for the Master mixer. This affects "
1114  "all sound created by the audio device. Note: Do not "
1115  "set this too low."));
1116  return gs;
1117 }
1118 
1120 {
1121  auto *gs = new HostSpinBoxSetting("PCMMixerVolume", 0, 100, 1);
1122 
1123  gs->setLabel(tr("PCM mixer volume"));
1124 
1125  gs->setValue(70);
1126 
1127  gs->setHelpText(tr("Initial volume for PCM output. Using the volume "
1128  "keys in MythTV will adjust this parameter."));
1129  return gs;
1130 }
1131 
1133 {
1134  auto *gc = new HostCheckBoxSetting("StereoPCM");
1135 
1136  gc->setLabel(tr("Stereo PCM Only"));
1137 
1138  gc->setValue(false);
1139 
1140  gc->setHelpText(tr("Enable if your amplifier or sound decoder only "
1141  "supports 2 channel PCM (typically an old HDMI 1.0 "
1142  "device). Multichannel audio will be re-encoded to "
1143  "AC-3 when required"));
1144  return gc;
1145 }
1146 
1148 {
1149  auto *gc = new HostCheckBoxSetting("SRCQualityOverride");
1150 
1151  gc->setLabel(tr("Override SRC quality"));
1152 
1153  gc->setValue(false);
1154 
1155  gc->setHelpText(tr("Enable to override audio sample rate "
1156  "conversion quality."));
1157  return gc;
1158 }
1159 
1161 {
1162  auto *gc = new HostComboBoxSetting("SRCQuality", false);
1163 
1164  gc->setLabel(tr("Sample rate conversion"));
1165 
1166  gc->addSelection(tr("Disabled", "Sample rate conversion"), "-1");
1167  gc->addSelection(tr("Fastest", "Sample rate conversion"), "0");
1168  gc->addSelection(tr("Good", "Sample rate conversion"), "1", true); // default
1169  gc->addSelection(tr("Best", "Sample rate conversion"), "2");
1170 
1171  gc->setHelpText(tr("Set the quality of audio sample-rate "
1172  "conversion. \"%1\" (default) provides the best "
1173  "compromise between CPU usage and quality. \"%2\" "
1174  "lets the audio device handle sample-rate conversion.")
1175  .arg(tr("Good", "Sample rate conversion"))
1176  .arg(tr("Disabled", "Sample rate conversion")));
1177 
1178  return gc;
1179 }
1180 
1182 {
1183  auto *gc = new HostCheckBoxSetting("Audio48kOverride");
1184 
1185  gc->setLabel(tr("Force audio device output to 48kHz"));
1186  gc->setValue(false);
1187 
1188  gc->setHelpText(tr("Force audio sample rate to 48kHz. Some audio devices "
1189  "will report various rates, but they ultimately "
1190  "crash."));
1191  return gc;
1192 }
1193 
1195 {
1196  auto *gc = new HostCheckBoxSetting("PassThruDeviceOverride");
1197 
1198  gc->setLabel(tr("Separate digital output device"));
1199 
1200  gc->setValue(false);
1201 
1202  gc->setHelpText(tr("Use a distinct digital output device from default. "
1203  "(default is not checked)"));
1204  return gc;
1205 }
1206 
1208 {
1209  auto *gc = new HostComboBoxSetting("PassThruOutputDevice",
1210  true);
1211 
1212  gc->setLabel(tr("Digital output device"));
1213  //TODO Is default not equivalent to PassThroughOverride off? if so
1214  //PassThruDeviceOverridedsetting could be removed
1215  gc->addSelection(QCoreApplication::translate("(Common)", "Default"),
1216  "Default");
1217 #ifdef _WIN32
1218  gc->addSelection("DirectX:Primary Sound Driver");
1219 #else
1220  gc->addSelection("ALSA:iec958:{ AES0 0x02 }",
1221  "ALSA:iec958:{ AES0 0x02 }");
1222  gc->addSelection("ALSA:hdmi", "ALSA:hdmi");
1223  gc->addSelection("ALSA:plughw:0,3", "ALSA:plughw:0,3");
1224 #endif
1225 
1226  gc->setHelpText(tr("Audio output device to use for digital audio. This "
1227  "value is currently only used with ALSA and DirectX "
1228  "sound output."));
1229  return gc;
1230 }
1231 
1233 {
1234  auto *gc = new HostCheckBoxSetting("SPDIFRateOverride");
1235 
1236  gc->setLabel(tr("SPDIF 48kHz rate override"));
1237 
1238  gc->setValue(false);
1239 
1240  gc->setHelpText(tr("ALSA only. By default, let ALSA determine the "
1241  "passthrough sampling rate. If checked set the sampling "
1242  "rate to 48kHz for passthrough. (default is not "
1243  "checked)"));
1244  return gc;
1245 }
1246 
1248 {
1249  auto *gc = new HostCheckBoxSetting("HBRPassthru");
1250 
1251  gc->setLabel(tr("HBR passthrough support"));
1252 
1253  gc->setValue(true);
1254 
1255  gc->setHelpText(tr("HBR support is required for TrueHD and DTS-HD "
1256  "passthrough. If unchecked, Myth will limit the "
1257  "passthrough bitrate to 6.144Mbit/s. This will "
1258  "disable True-HD passthrough, however will allow "
1259  "DTS-HD content to be sent as DTS-HD Hi-Res. (default "
1260  "is checked)"));
1261  return gc;
1262 }
1263 
1265 {
1266  m_mpcm->setEnabled(flag);
1267 }
1268 // 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()
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 *)
bool IsInvalid()
return true if class instance is marked invalid.
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()
Definition: element.h:83
AudioDeviceComboBox(AudioConfigSettings *parent)
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)
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)
bool canFeature(DigitalFeature arg)
return DigitalFeature mask.
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)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
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()
const char * frames[3]
Definition: element.c:46
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
ButtonStandardSetting * m_center
virtual bool AddFrames(void *buffer, int frames, int64_t timecode)=0
Add frames to the audiobuffer for playback.