aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerald Combs <gerald@wireshark.org>2017-07-21 11:03:04 -0700
committerGerald Combs <gerald@wireshark.org>2017-07-21 21:09:26 +0000
commit28dce11948523f80d6eb76ef6a1d95df78f9c870 (patch)
treeac3518af49b250160fb68d500ab3a38c92ddaaa1
parentd22b54a00587d6a4a5227b93f0461ab4549ea94c (diff)
Qt RTP: Add the default device and adjust sample rates.
In the RTP player dialog, list the default audio device first, ensure it's selected by default and ensure that the list items are unique. According to http://code.qt.io/cgit/qt/qtmultimedia.git/tree/src/plugins/windowsaudio/qwindowsaudiodeviceinfo.cpp?h=5.9 the default device on Windows uses the special WAVE_MAPPER id, which appears to support various sample rates even when the underlying hardware doesn't. Ensuring the names are unique fixes an issue I'm seeing on a test machine here. When decoding, check to see if our sample rate is supported by our output device and adjust accordingly. Bug: 13906 Change-Id: Iddc0beb2459bfac42276ff29d227c2619b0a8d90 Reviewed-on: https://code.wireshark.org/review/22756 Petri-Dish: Gerald Combs <gerald@wireshark.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Gerald Combs <gerald@wireshark.org>
-rw-r--r--ui/qt/rtp_audio_stream.cpp34
-rw-r--r--ui/qt/rtp_audio_stream.h1
-rw-r--r--ui/qt/rtp_player_dialog.cpp27
-rw-r--r--ui/qt/rtp_player_dialog.h1
4 files changed, 45 insertions, 18 deletions
diff --git a/ui/qt/rtp_audio_stream.cpp b/ui/qt/rtp_audio_stream.cpp
index fde66c8127..e7d71245c6 100644
--- a/ui/qt/rtp_audio_stream.cpp
+++ b/ui/qt/rtp_audio_stream.cpp
@@ -229,6 +229,12 @@ void RtpAudioStream::decode()
size_t decoded_bytes = decode_rtp_packet(rtp_packet, &decode_buff, decoders_hash_, &channels, &sample_rate);
+ unsigned rtp_clock_rate = sample_rate;
+ if (rtp_packet->info->info_payload_type == PT_G722) {
+ // G.722 sample rate is 16kHz, but RTP clock rate is 8kHz for historic reasons.
+ rtp_clock_rate = 8000;
+ }
+
if (decoded_bytes == 0 || sample_rate == 0) {
// We didn't decode anything. Clean up and prep for the next packet.
last_sequence = rtp_packet->info->info_seq_num;
@@ -236,7 +242,27 @@ void RtpAudioStream::decode()
continue;
}
- if (audio_out_rate_ == 0) { // First non-zero wins
+ if (audio_out_rate_ == 0) {
+ // Use the first non-zero rate we find. Ajust it to match our audio hardware.
+ 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(sample_rate);
+ format.setSampleSize(sample_bytes_ * 8); // bits
+ format.setSampleType(QAudioFormat::SignedInt);
+ format.setChannelCount(1);
+ format.setCodec("audio/pcm");
+
+ if (!cur_out_device.isFormatSupported(format)) {
+ sample_rate = cur_out_device.nearestFormat(format).sampleRate();
+ }
+
audio_out_rate_ = sample_rate;
RTP_STREAM_DEBUG("Audio sample rate is %u", audio_out_rate_);
@@ -253,12 +279,6 @@ void RtpAudioStream::decode()
}
last_sequence = rtp_packet->info->info_seq_num;
- unsigned rtp_clock_rate = sample_rate;
- if (rtp_packet->info->info_payload_type == PT_G722) {
- // G.722 sample rate is 16kHz, but RTP clock rate is 8kHz for historic reasons.
- rtp_clock_rate = 8000;
- }
-
double rtp_time = (double)(rtp_packet->info->info_timestamp-start_timestamp)/rtp_clock_rate - start_rtp_time;
double arrive_time;
if (timing_mode_ == RtpTimestamp) {
diff --git a/ui/qt/rtp_audio_stream.h b/ui/qt/rtp_audio_stream.h
index d4cfa22290..c06bd4adad 100644
--- a/ui/qt/rtp_audio_stream.h
+++ b/ui/qt/rtp_audio_stream.h
@@ -186,6 +186,7 @@ private:
void writeSilence(int samples);
const QString formatDescription(const QAudioFormat & format);
+ QString currentOutputDevice();
private slots:
void outputStateChanged(QAudio::State new_state);
diff --git a/ui/qt/rtp_player_dialog.cpp b/ui/qt/rtp_player_dialog.cpp
index 89f974bf9f..a4beb688d8 100644
--- a/ui/qt/rtp_player_dialog.cpp
+++ b/ui/qt/rtp_player_dialog.cpp
@@ -148,19 +148,19 @@ RtpPlayerDialog::RtpPlayerDialog(QWidget &parent, CaptureFile &cf) :
ui->playButton->setIcon(StockIcon("media-playback-start"));
ui->stopButton->setIcon(StockIcon("media-playback-stop"));
- QString default_out_name = QAudioDeviceInfo::defaultOutputDevice().deviceName();
+ // Ordered, unique device names starting with the system default
+ QMap<QString, bool> out_device_map; // true == default device
+ out_device_map.insert(QAudioDeviceInfo::defaultOutputDevice().deviceName(), true);
foreach (QAudioDeviceInfo out_device, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) {
- QString out_name = out_device.deviceName();
+ if (!out_device_map.contains(out_device.deviceName())) {
+ out_device_map.insert(out_device.deviceName(), false);
+ }
+ }
+
+ foreach (QString out_name, out_device_map.keys()) {
ui->outputDeviceComboBox->addItem(out_name);
- if (out_name == default_out_name) {
-#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
- ui->outputDeviceComboBox->setCurrentText(out_name);
-#else
- int new_index = ui->outputDeviceComboBox->findText(default_out_name);
- if (new_index >= 0) {
- ui->outputDeviceComboBox->setCurrentIndex(new_index);
- }
-#endif
+ if (out_device_map.value(out_name)) {
+ ui->outputDeviceComboBox->setCurrentIndex(ui->outputDeviceComboBox->count() - 1);
}
}
if (ui->outputDeviceComboBox->count() < 1) {
@@ -742,6 +742,11 @@ QString RtpPlayerDialog::currentOutputDeviceName()
return ui->outputDeviceComboBox->currentText();
}
+void RtpPlayerDialog::on_outputDeviceComboBox_currentIndexChanged(const QString &)
+{
+ rescanPackets();
+}
+
void RtpPlayerDialog::on_jitterSpinBox_valueChanged(double)
{
rescanPackets();
diff --git a/ui/qt/rtp_player_dialog.h b/ui/qt/rtp_player_dialog.h
index 44e2142e87..1c3e3cfb36 100644
--- a/ui/qt/rtp_player_dialog.h
+++ b/ui/qt/rtp_player_dialog.h
@@ -114,6 +114,7 @@ private slots:
void on_actionMoveRight1_triggered();
void on_actionGoToPacket_triggered();
void on_streamTreeWidget_itemSelectionChanged();
+ void on_outputDeviceComboBox_currentIndexChanged(const QString &);
void on_jitterSpinBox_valueChanged(double);
void on_timingComboBox_currentIndexChanged(int);
void on_todCheckBox_toggled(bool checked);