aboutsummaryrefslogtreecommitdiffstats
path: root/ui/qt/rtp_audio_stream.cpp
diff options
context:
space:
mode:
authorJirka Novak <j.novak@netsystem.cz>2021-01-29 16:32:38 +0100
committerAndersBroman <a.broman58@gmail.com>2021-01-31 15:21:34 +0000
commit80760302c902262f0325410db5154ace8b0bac7f (patch)
treebc9750cd5e77a2b2ff1e7cf1804f0b4e45d8116c /ui/qt/rtp_audio_stream.cpp
parenta5207b541ee21b9de3c0c07b33994fef6266d8c0 (diff)
RTP player: Doubled buffer for replay to avoid play stop caused by underruns
Patch solves issue for case when QT plays audio faster than reads it from file. The change looks strange because there is no way how to get buffer size before starting the play. So code start the play, reads buffer and stop it. Then increases buffer size and start play again. Note: You still can receive ALSA notifications like: ALSA lib pcm.c:8545:(snd_pcm_recover) underrun occurred but it do not stop audio replay.
Diffstat (limited to 'ui/qt/rtp_audio_stream.cpp')
-rw-r--r--ui/qt/rtp_audio_stream.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/ui/qt/rtp_audio_stream.cpp b/ui/qt/rtp_audio_stream.cpp
index e0b39f740a..19eb51f3c3 100644
--- a/ui/qt/rtp_audio_stream.cpp
+++ b/ui/qt/rtp_audio_stream.cpp
@@ -622,10 +622,6 @@ void RtpAudioStream::startPlaying()
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()));
start_pos = (qint64)(start_play_time_ * sample_bytes_ * audio_out_rate_);
// Round to sample_bytes_ boundary
start_pos = (start_pos / sample_bytes_) * sample_bytes_;
@@ -634,7 +630,21 @@ void RtpAudioStream::startPlaying()
start_pos *= 2;
}
if (start_pos < tempfile_->size()) {
+ int bufferSize;
+
+ // Start and stop audio with no connection to UI and store buffer size
+ tempfile_->seek(start_pos);
+ audio_output_ = new QAudioOutput(cur_out_device, format, this);
+ audio_output_->start(tempfile_);
+ bufferSize = audio_output_->bufferSize();
+ audio_output_->stop();
+
+ // Start audio again with doubled buffer size, UI is updated
tempfile_->seek(start_pos);
+ audio_output_->setBufferSize(bufferSize*2);
+ audio_output_->setNotifyInterval(100); // ~15 fps
+ connect(audio_output_, SIGNAL(stateChanged(QAudio::State)), this, SLOT(outputStateChanged(QAudio::State)));
+ connect(audio_output_, SIGNAL(notify()), this, SLOT(outputNotify()));
audio_output_->start(tempfile_);
emit startedPlaying();
// QTBUG-6548 StoppedState is not always emitted on error, force a cleanup