summaryrefslogtreecommitdiffstats
path: root/remoting/client/audio_player.cc
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-29 00:53:25 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-12-29 00:53:25 +0000
commitb5528a2437b6874af7fc4a57dee3d6be940f02c2 (patch)
treebab2ef797cddae977e1fa23b0a028e6be3c0d303 /remoting/client/audio_player.cc
parent1113942f8b03fa1dff2144066ca012aaadc38ec9 (diff)
downloadchromium_src-b5528a2437b6874af7fc4a57dee3d6be940f02c2.zip
chromium_src-b5528a2437b6874af7fc4a57dee3d6be940f02c2.tar.gz
chromium_src-b5528a2437b6874af7fc4a57dee3d6be940f02c2.tar.bz2
Drop audio packets in the chromoting client less agressively.
Previously chromoting client would drop all queued audio samples when amount of data in the buffer exceeds 150ms. Because of that it wouldn't always have enough data buffered which results in audible gliches. Fixed AudioPlayer so that it drops just enough packets to keep the buffer size under the limit. BUG=164308 Review URL: https://chromiumcodereview.appspot.com/11697009 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@174753 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting/client/audio_player.cc')
-rw-r--r--remoting/client/audio_player.cc28
1 files changed, 17 insertions, 11 deletions
diff --git a/remoting/client/audio_player.cc b/remoting/client/audio_player.cc
index f2ec27b..a26f1bc 100644
--- a/remoting/client/audio_player.cc
+++ b/remoting/client/audio_player.cc
@@ -11,7 +11,7 @@
// The number of channels in the audio stream (only supporting stereo audio
// for now).
-const int kChannels = 2u;
+const int kChannels = 2;
const int kSampleSizeBytes = 2;
// If queue grows bigger than 150ms we start dropping packets.
@@ -22,7 +22,7 @@ namespace remoting {
AudioPlayer::AudioPlayer()
: sampling_rate_(AudioPacket::SAMPLING_RATE_INVALID),
start_failed_(false),
- queued_samples_(0),
+ queued_bytes_(0),
bytes_consumed_(0) {
}
@@ -63,13 +63,19 @@ void AudioPlayer::ProcessAudioPacket(scoped_ptr<AudioPacket> packet) {
base::AutoLock auto_lock(lock_);
- if (queued_samples_ > kMaxQueueLatencyMs * sampling_rate_ /
- base::Time::kMillisecondsPerSecond) {
- ResetQueue();
- }
-
- queued_samples_ += packet->data(0).size() / (kChannels * kSampleSizeBytes);
+ queued_bytes_ += packet->data(0).size();
queued_packets_.push_back(packet.release());
+
+ int max_buffer_size_ =
+ kMaxQueueLatencyMs * sampling_rate_ * kSampleSizeBytes * kChannels /
+ base::Time::kMillisecondsPerSecond;
+ while (queued_bytes_ > max_buffer_size_) {
+ queued_bytes_ -= queued_packets_.front()->data(0).size() - bytes_consumed_;
+ DCHECK_GE(queued_bytes_, 0);
+ delete queued_packets_.front();
+ queued_packets_.pop_front();
+ bytes_consumed_ = 0;
+ }
}
// static
@@ -83,7 +89,7 @@ void AudioPlayer::AudioPlayerCallback(void* samples,
void AudioPlayer::ResetQueue() {
lock_.AssertAcquired();
STLDeleteElements(&queued_packets_);
- queued_samples_ = 0;
+ queued_bytes_ = 0;
bytes_consumed_ = 0;
}
@@ -123,8 +129,8 @@ void AudioPlayer::FillWithSamples(void* samples, uint32 buffer_size) {
next_sample += bytes_to_copy;
bytes_consumed_ += bytes_to_copy;
bytes_extracted += bytes_to_copy;
- queued_samples_ -= bytes_to_copy / kSampleSizeBytes / kChannels;
- DCHECK_GE(queued_samples_, 0);
+ queued_bytes_ -= bytes_to_copy;
+ DCHECK_GE(queued_bytes_, 0);
}
}