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..a6a70c83da6ecf743cfd08aeb86ac1b890abd946 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,11 +127,9 @@ void AudioPipeReader::TryOpenPipe() { |
return; |
} |
- // Set buffer size for the pipe. |
- if (HANDLE_EINTR(fcntl( |
- pipe_.GetPlatformFile(), F_SETPIPE_SZ, kPipeBufferSizeBytes)) < 0) { |
- PLOG(ERROR) << "fcntl"; |
- } |
+ pipe_buffer_size_ = fpathconf(pipe_.GetPlatformFile(), _PC_PIPE_BUF); |
Lambros
2014/12/23 23:07:18
I don't think this call can fail, can it?
Sergey Ulanov
2014/12/24 00:01:28
it shouldn't, but it's still better to check if it
|
+ capture_period_ = base::TimeDelta::FromSeconds(1) * pipe_buffer_size_ / |
+ kSampleBytesPerSecond / 2; |
Lambros
2014/12/23 23:07:18
I'm curious to know why we divide by 2? Is it simp
Sergey Ulanov
2014/12/24 00:01:26
Yes. We need to capture more often than the buffer
|
WaitForPipeReadable(); |
} |
@@ -151,8 +139,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 +188,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. |