diff options
author | Gerald Combs <gerald@wireshark.org> | 2022-05-23 18:59:35 -0700 |
---|---|---|
committer | Gerald Combs <gerald@wireshark.org> | 2022-07-21 20:09:52 +0000 |
commit | b8d85227f6cfacb66237a6399f28cef0e94d1cb1 (patch) | |
tree | f8d6b0f329228f3ca186dded48d26331a828f537 /ui/qt/rtp_audio_stream.cpp | |
parent | d2b6b89b94bd3e18520c472affae9cd4a03283e2 (diff) |
Qt: Update the RTP stream UI to support Qt6Multimedia.
Fixes #18115
Diffstat (limited to 'ui/qt/rtp_audio_stream.cpp')
-rw-r--r-- | ui/qt/rtp_audio_stream.cpp | 80 |
1 files changed, 75 insertions, 5 deletions
diff --git a/ui/qt/rtp_audio_stream.cpp b/ui/qt/rtp_audio_stream.cpp index 83b3c248ea..a1cb42c2f9 100644 --- a/ui/qt/rtp_audio_stream.cpp +++ b/ui/qt/rtp_audio_stream.cpp @@ -31,6 +31,10 @@ #include <ui/qt/utils/rtp_audio_routing_filter.h> #include <ui/qt/utils/rtp_audio_file.h> +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +#include <QAudioDevice> +#include <QAudioSink> +#endif #include <QAudioFormat> #include <QAudioOutput> #include <QVariant> @@ -54,13 +58,13 @@ RtpAudioStream::RtpAudioStream(QObject *parent, rtpstream_id_t *id, bool stereo_ , audio_out_rate_(0) , audio_requested_out_rate_(0) , audio_resampler_(0) - , audio_output_(NULL) , max_sample_val_(1) , max_sample_val_used_(1) , color_(0) , jitter_buffer_size_(50) , timing_mode_(RtpAudioStream::JitterBuffer) , start_play_time_(0) + , audio_output_(NULL) { rtpstream_id_copy(id, &id_); memset(&rtpstream_, 0, sizeof(rtpstream_)); @@ -181,7 +185,11 @@ void RtpAudioStream::setAudioRouting(AudioRouting audio_routing) audio_routing_ = audio_routing; } +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +void RtpAudioStream::decode(QAudioDevice out_device) +#else void RtpAudioStream::decode(QAudioDeviceInfo out_device) +#endif { if (rtp_packets_.size() < 1) return; @@ -200,7 +208,11 @@ void RtpAudioStream::decode(QAudioDeviceInfo out_device) } // Side effect: it creates and initiates resampler if needed +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +quint32 RtpAudioStream::calculateAudioOutRate(QAudioDevice out_device, unsigned int sample_rate, unsigned int requested_out_rate) +#else quint32 RtpAudioStream::calculateAudioOutRate(QAudioDeviceInfo out_device, unsigned int sample_rate, unsigned int requested_out_rate) +#endif { quint32 out_rate; @@ -208,19 +220,30 @@ quint32 RtpAudioStream::calculateAudioOutRate(QAudioDeviceInfo out_device, unsig // our audio hardware. QAudioFormat format; format.setSampleRate(sample_rate); +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + // Must match rtp_media.h. + format.setSampleFormat(QAudioFormat::Int16); +#else format.setSampleSize(SAMPLE_BYTES * 8); // bits format.setSampleType(QAudioFormat::SignedInt); +#endif if (stereo_required_) { format.setChannelCount(2); } else { format.setChannelCount(1); } +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) format.setCodec("audio/pcm"); +#endif if (!out_device.isFormatSupported(format) && (requested_out_rate==0) ) { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + out_rate = out_device.preferredFormat().sampleRate(); +#else out_rate = out_device.nearestFormat(format).sampleRate(); +#endif audio_resampler_ = speex_resampler_init(1, sample_rate, out_rate, 10, NULL); RTP_STREAM_DEBUG("Started resampling from %u to (out) %u Hz.", sample_rate, out_rate); } else { @@ -240,7 +263,11 @@ quint32 RtpAudioStream::calculateAudioOutRate(QAudioDeviceInfo out_device, unsig return out_rate; } +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +void RtpAudioStream::decodeAudio(QAudioDevice out_device) +#else void RtpAudioStream::decodeAudio(QAudioDeviceInfo out_device) +#endif { // XXX This is more messy than it should be. @@ -607,10 +634,10 @@ const QVector<double> RtpAudioStream::insertedSilenceSamples(int y_offset) quint32 RtpAudioStream::nearestPacket(double timestamp, bool is_relative) { - if (packet_timestamps_.keys().count() < 1) return 0; + if (packet_timestamps_.size() < 1) return 0; if (!is_relative) timestamp -= start_abs_offset_; - QMap<double, quint32>::const_iterator it = packet_timestamps_.lowerBound(timestamp); + QMap<double, quint32>::iterator it = packet_timestamps_.lowerBound(timestamp); if (it == packet_timestamps_.end()) return 0; return it.value(); } @@ -624,12 +651,35 @@ QAudio::State RtpAudioStream::outputState() const const QString RtpAudioStream::formatDescription(const QAudioFormat &format) { QString fmt_descr = QString("%1 Hz, ").arg(format.sampleRate()); +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + switch (format.sampleFormat()) { + case QAudioFormat::UInt8: + fmt_descr += "UInt8"; + break; + case QAudioFormat::Int16: + fmt_descr += "Int16"; + break; + case QAudioFormat::Int32: + fmt_descr += "Int32"; + break; + case QAudioFormat::Float: + fmt_descr += "Float"; + break; + default: + fmt_descr += "Unknown"; + break; + } +#else switch (format.sampleType()) { case QAudioFormat::SignedInt: fmt_descr += "Int"; + fmt_descr += QString::number(format.sampleSize()); + fmt_descr += format.byteOrder() == QAudioFormat::BigEndian ? "BE" : "LE"; break; case QAudioFormat::UnSignedInt: fmt_descr += "UInt"; + fmt_descr += QString::number(format.sampleSize()); + fmt_descr += format.byteOrder() == QAudioFormat::BigEndian ? "BE" : "LE"; break; case QAudioFormat::Float: fmt_descr += "Float"; @@ -638,8 +688,7 @@ const QString RtpAudioStream::formatDescription(const QAudioFormat &format) fmt_descr += "Unknown"; break; } - fmt_descr += QString::number(format.sampleSize()); - fmt_descr += format.byteOrder() == QAudioFormat::BigEndian ? "BE" : "LE"; +#endif return fmt_descr; } @@ -660,7 +709,11 @@ QString RtpAudioStream::getIDAsQString() return str; } +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) +bool RtpAudioStream::prepareForPlay(QAudioDevice out_device) +#else bool RtpAudioStream::prepareForPlay(QAudioDeviceInfo out_device) +#endif { qint64 start_pos; qint64 size; @@ -683,24 +736,36 @@ bool RtpAudioStream::prepareForPlay(QAudioDeviceInfo out_device) QAudioFormat format; format.setSampleRate(audio_out_rate_); +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + // Must match rtp_media.h. + format.setSampleFormat(QAudioFormat::Int16); +#else format.setSampleSize(SAMPLE_BYTES * 8); // bits format.setSampleType(QAudioFormat::SignedInt); +#endif if (stereo_required_) { format.setChannelCount(2); } else { format.setChannelCount(1); } +#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) format.setCodec("audio/pcm"); +#endif // RTP_STREAM_DEBUG("playing %s %d samples @ %u Hz", // sample_file_->fileName().toUtf8().constData(), // (int) sample_file_->size(), audio_out_rate_); if (!out_device.isFormatSupported(format)) { +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + QString playback_error = tr("%1 does not support PCM at %2. Preferred format is %3") + .arg(out_device.description(), formatDescription(format), formatDescription(out_device.preferredFormat())); +#else QString playback_error = tr("%1 does not support PCM at %2. Preferred format is %3") .arg(out_device.deviceName()) .arg(formatDescription(format)) .arg(formatDescription(out_device.nearestFormat(format))); +#endif emit playbackError(playback_error); } @@ -718,8 +783,13 @@ bool RtpAudioStream::prepareForPlay(QAudioDeviceInfo out_device) temp_file_ = new AudioRoutingFilter(audio_file_, stereo_required_, audio_routing_); temp_file_->seek(start_pos); if (audio_output_) delete audio_output_; +#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) + audio_output_ = new QAudioSink(out_device, format, this); + connect(audio_output_, &QAudioSink::stateChanged, this, &RtpAudioStream::outputStateChanged); +#else audio_output_ = new QAudioOutput(out_device, format, this); connect(audio_output_, &QAudioOutput::stateChanged, this, &RtpAudioStream::outputStateChanged); +#endif return true; } else { // Report stopped audio if start position is later than stream ends |