| OLD | NEW | 
|    1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |    1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
|    2 // Use of this source code is governed by a BSD-style license that can be |    2 // Use of this source code is governed by a BSD-style license that can be | 
|    3 // found in the LICENSE file. |    3 // found in the LICENSE file. | 
|    4  |    4  | 
|    5 #include "remoting/host/linux/audio_pipe_reader.h" |    5 #include "remoting/host/linux/audio_pipe_reader.h" | 
|    6  |    6  | 
|    7 #include <fcntl.h> |    7 #include <fcntl.h> | 
 |    8 #include <stddef.h> | 
|    8 #include <sys/stat.h> |    9 #include <sys/stat.h> | 
|    9 #include <sys/types.h> |   10 #include <sys/types.h> | 
|   10 #include <unistd.h> |   11 #include <unistd.h> | 
|   11  |   12  | 
|   12 #include "base/logging.h" |   13 #include "base/logging.h" | 
|   13 #include "base/posix/eintr_wrapper.h" |   14 #include "base/posix/eintr_wrapper.h" | 
|   14 #include "base/stl_util.h" |   15 #include "base/stl_util.h" | 
|   15  |   16  | 
|   16 namespace remoting { |   17 namespace remoting { | 
|   17  |   18  | 
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  140   timer_.Start(FROM_HERE, capture_period_, this, &AudioPipeReader::DoCapture); |  141   timer_.Start(FROM_HERE, capture_period_, this, &AudioPipeReader::DoCapture); | 
|  141 } |  142 } | 
|  142  |  143  | 
|  143 void AudioPipeReader::DoCapture() { |  144 void AudioPipeReader::DoCapture() { | 
|  144   DCHECK(task_runner_->BelongsToCurrentThread()); |  145   DCHECK(task_runner_->BelongsToCurrentThread()); | 
|  145   DCHECK(pipe_.IsValid()); |  146   DCHECK(pipe_.IsValid()); | 
|  146  |  147  | 
|  147   // Calculate how much we need read from the pipe. Pulseaudio doesn't control |  148   // Calculate how much we need read from the pipe. Pulseaudio doesn't control | 
|  148   // how much data it writes to the pipe, so we need to pace the stream. |  149   // how much data it writes to the pipe, so we need to pace the stream. | 
|  149   base::TimeDelta stream_position = base::TimeTicks::Now() - started_time_; |  150   base::TimeDelta stream_position = base::TimeTicks::Now() - started_time_; | 
|  150   int64 stream_position_bytes = stream_position.InMilliseconds() * |  151   int64_t stream_position_bytes = stream_position.InMilliseconds() * | 
|  151       kSampleBytesPerSecond / base::Time::kMillisecondsPerSecond; |  152                                   kSampleBytesPerSecond / | 
|  152   int64 bytes_to_read = stream_position_bytes - last_capture_position_; |  153                                   base::Time::kMillisecondsPerSecond; | 
 |  154   int64_t bytes_to_read = stream_position_bytes - last_capture_position_; | 
|  153  |  155  | 
|  154   std::string data = left_over_bytes_; |  156   std::string data = left_over_bytes_; | 
|  155   size_t pos = data.size(); |  157   size_t pos = data.size(); | 
|  156   left_over_bytes_.clear(); |  158   left_over_bytes_.clear(); | 
|  157   data.resize(pos + bytes_to_read); |  159   data.resize(pos + bytes_to_read); | 
|  158  |  160  | 
|  159   while (pos < data.size()) { |  161   while (pos < data.size()) { | 
|  160     int read_result = |  162     int read_result = | 
|  161         pipe_.ReadAtCurrentPos(string_as_array(&data) + pos, data.size() - pos); |  163         pipe_.ReadAtCurrentPos(string_as_array(&data) + pos, data.size() - pos); | 
|  162     if (read_result > 0) { |  164     if (read_result > 0) { | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  202       pipe_.GetPlatformFile(), false, base::MessageLoopForIO::WATCH_READ, |  204       pipe_.GetPlatformFile(), false, base::MessageLoopForIO::WATCH_READ, | 
|  203       &file_descriptor_watcher_, this); |  205       &file_descriptor_watcher_, this); | 
|  204 } |  206 } | 
|  205  |  207  | 
|  206 // static |  208 // static | 
|  207 void AudioPipeReaderTraits::Destruct(const AudioPipeReader* audio_pipe_reader) { |  209 void AudioPipeReaderTraits::Destruct(const AudioPipeReader* audio_pipe_reader) { | 
|  208   audio_pipe_reader->task_runner_->DeleteSoon(FROM_HERE, audio_pipe_reader); |  210   audio_pipe_reader->task_runner_->DeleteSoon(FROM_HERE, audio_pipe_reader); | 
|  209 } |  211 } | 
|  210  |  212  | 
|  211 }  // namespace remoting |  213 }  // namespace remoting | 
| OLD | NEW |