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

Unified Diff: remoting/host/linux/audio_pipe_reader.cc

Issue 824943002: Fix AudioPipeReader to use default pipe buffer size. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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/host/linux/audio_pipe_reader.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/linux/audio_pipe_reader.cc
diff --git a/remoting/host/linux/audio_pipe_reader.cc b/remoting/host/linux/audio_pipe_reader.cc
index 76be36c2ae4d361bfa7d0aaff63e770be73ad11f..e270a34070adefe016c708590d550e85f2f45f73 100644
--- a/remoting/host/linux/audio_pipe_reader.cc
+++ b/remoting/host/linux/audio_pipe_reader.cc
@@ -21,16 +21,6 @@ const int kSampleBytesPerSecond = AudioPipeReader::kSamplingRate *
AudioPipeReader::kChannels *
AudioPipeReader::kBytesPerSample;
-// Read data from the pipe every 40ms.
-const int kCapturingPeriodMs = 40;
-
-// Size of the pipe buffer in milliseconds.
-const int kPipeBufferSizeMs = kCapturingPeriodMs * 2;
-
-// Size of the pipe buffer in bytes.
-const int kPipeBufferSizeBytes = kPipeBufferSizeMs * kSampleBytesPerSecond /
- base::Time::kMillisecondsPerSecond;
-
#if !defined(F_SETPIPE_SZ)
// F_SETPIPE_SZ is supported only starting linux 2.6.35, but we want to be able
// to compile this code on machines with older kernel.
@@ -137,12 +127,17 @@ void AudioPipeReader::TryOpenPipe() {
return;
}
- // Set buffer size for the pipe.
- if (HANDLE_EINTR(fcntl(
- pipe_.GetPlatformFile(), F_SETPIPE_SZ, kPipeBufferSizeBytes)) < 0) {
- PLOG(ERROR) << "fcntl";
+ // Get buffer size for the pipe.
+ pipe_buffer_size_ = fpathconf(pipe_.GetPlatformFile(), _PC_PIPE_BUF);
+ if (pipe_buffer_size_ < 0) {
+ PLOG(ERROR) << "fpathconf(_PC_PIPE_BUF)";
+ pipe_buffer_size_ = 4096;
}
+ // Read from the pipe twice per buffer length, to avoid starving the stream.
+ capture_period_ = base::TimeDelta::FromSeconds(1) * pipe_buffer_size_ /
+ kSampleBytesPerSecond / 2;
+
WaitForPipeReadable();
}
}
@@ -151,8 +146,7 @@ void AudioPipeReader::StartTimer() {
DCHECK(task_runner_->BelongsToCurrentThread());
started_time_ = base::TimeTicks::Now();
last_capture_position_ = 0;
- timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kCapturingPeriodMs),
- this, &AudioPipeReader::DoCapture);
+ timer_.Start(FROM_HERE, capture_period_, this, &AudioPipeReader::DoCapture);
}
void AudioPipeReader::DoCapture() {
@@ -201,8 +195,8 @@ void AudioPipeReader::DoCapture() {
// to read |bytes_to_read| bytes, but in case it's misbehaving we need to make
// sure that |stream_position_bytes| doesn't go out of sync with the current
// stream position.
- if (stream_position_bytes - last_capture_position_ > kPipeBufferSizeBytes)
- last_capture_position_ = stream_position_bytes - kPipeBufferSizeBytes;
+ if (stream_position_bytes - last_capture_position_ > pipe_buffer_size_)
+ last_capture_position_ = stream_position_bytes - pipe_buffer_size_;
DCHECK_LE(last_capture_position_, stream_position_bytes);
// Dispatch asynchronous notification to the stream observers.
« no previous file with comments | « remoting/host/linux/audio_pipe_reader.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698