Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(631)

Unified Diff: remoting/client/audio_player.cc

Issue 11697009: Drop audio packets in the chromoting client less agressively. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « remoting/client/audio_player.h ('k') | remoting/client/audio_player_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/client/audio_player.cc
diff --git a/remoting/client/audio_player.cc b/remoting/client/audio_player.cc
index f2ec27b569293612933f0b0514b64659e06405c4..a26f1bc18bb83fb62204306aaad0ab776691d6ad 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);
}
}
« no previous file with comments | « remoting/client/audio_player.h ('k') | remoting/client/audio_player_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698