aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/rtp_audio_stream.cpp
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2016-12-02 15:52:02 -0800
committerGerald Combs <gerald@wireshark.org>2016-12-06 22:36:55 +0000
commitd59653f8d52efbf3ab32f95043cd718965e57406 (patch)
tree14e868a73180a3eccbed1d3715bb64a2c92f6928 /ui/qt/rtp_audio_stream.cpp
parent263fea9723ea3487c0d98b0720ab2d656f780fe1 (diff)
Qt: Make the RTP player output device selectable.
Add a combobox for selecting the output device and populate it with our available devices. Let the user know if our output format isn't supported. Ping-Bug: 13105 Change-Id: I299c7d0f191bb66d93896338036000e2c377781f Reviewed-on: https://code.wireshark.org/review/19046 Petri-Dish: Gerald Combs <gerald@wireshark.org> Reviewed-by: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Gerald Combs <gerald@wireshark.org>
Diffstat (limited to 'ui/qt/rtp_audio_stream.cpp')
-rw-r--r--ui/qt/rtp_audio_stream.cpp42
1 files changed, 41 insertions, 1 deletions
diff --git a/ui/qt/rtp_audio_stream.cpp b/ui/qt/rtp_audio_stream.cpp
index 798d73fcbe..fee1ebc391 100644
--- a/ui/qt/rtp_audio_stream.cpp
+++ b/ui/qt/rtp_audio_stream.cpp
@@ -42,6 +42,7 @@
#include <QAudioOutput>
#include <QDir>
#include <QTemporaryFile>
+#include <QVariant>
// To do:
// - Only allow one rtp_stream_info_t per RtpAudioStream?
@@ -521,10 +522,41 @@ QAudio::State RtpAudioStream::outputState() const
return audio_output_->state();
}
+const QString RtpAudioStream::formatDescription(const QAudioFormat &format)
+{
+ QString fmt_descr = QString("%1 Hz, ").arg(format.sampleRate());
+ switch (format.sampleType()) {
+ case QAudioFormat::SignedInt:
+ fmt_descr += "Int";
+ break;
+ case QAudioFormat::UnSignedInt:
+ fmt_descr += "UInt";
+ break;
+ case QAudioFormat::Float:
+ fmt_descr += "Float";
+ break;
+ default:
+ fmt_descr += "Unknown";
+ break;
+ }
+ fmt_descr += QString::number(format.sampleSize());
+ fmt_descr += format.byteOrder() == QAudioFormat::BigEndian ? "BE" : "LE";
+
+ return fmt_descr;
+}
+
void RtpAudioStream::startPlaying()
{
if (audio_output_) return;
+ QAudioDeviceInfo cur_out_device = QAudioDeviceInfo::defaultOutputDevice();
+ QString cur_out_name = parent()->property("currentOutputDeviceName").toString();
+ foreach (QAudioDeviceInfo out_device, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) {
+ if (cur_out_name == out_device.deviceName()) {
+ cur_out_device = out_device;
+ }
+ }
+
QAudioFormat format;
format.setSampleRate(audio_out_rate_);
format.setSampleSize(sample_bytes_ * 8); // bits
@@ -536,7 +568,15 @@ void RtpAudioStream::startPlaying()
// tempfile_->fileName().toUtf8().constData(),
// (int) tempfile_->size(), audio_out_rate_);
- audio_output_ = new QAudioOutput(format, this);
+ if (!cur_out_device.isFormatSupported(format)) {
+ QString playback_error = tr("%1 does not support PCM at %2. Preferred format is %3")
+ .arg(cur_out_device.deviceName())
+ .arg(formatDescription(format))
+ .arg(formatDescription(cur_out_device.nearestFormat(format)));
+ emit playbackError(playback_error);
+ }
+
+ audio_output_ = new QAudioOutput(cur_out_device, format, this);
audio_output_->setNotifyInterval(65); // ~15 fps
connect(audio_output_, SIGNAL(stateChanged(QAudio::State)), this, SLOT(outputStateChanged(QAudio::State)));
connect(audio_output_, SIGNAL(notify()), this, SLOT(outputNotify()));