diff options
Diffstat (limited to 'ui/qt/rtp_audio_stream.cpp')
-rw-r--r-- | ui/qt/rtp_audio_stream.cpp | 34 |
1 files changed, 27 insertions, 7 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) { |