| 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 <sys/stat.h> | 8 #include <sys/stat.h> |
| 9 #include <sys/types.h> | 9 #include <sys/types.h> |
| 10 #include <unistd.h> | 10 #include <unistd.h> |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 int64 bytes_to_read = stream_position_bytes - last_capture_position_; | 138 int64 bytes_to_read = stream_position_bytes - last_capture_position_; |
| 139 | 139 |
| 140 std::string data = left_over_bytes_; | 140 std::string data = left_over_bytes_; |
| 141 size_t pos = data.size(); | 141 size_t pos = data.size(); |
| 142 left_over_bytes_.clear(); | 142 left_over_bytes_.clear(); |
| 143 data.resize(pos + bytes_to_read); | 143 data.resize(pos + bytes_to_read); |
| 144 | 144 |
| 145 while (pos < data.size()) { | 145 while (pos < data.size()) { |
| 146 int read_result = HANDLE_EINTR( | 146 int read_result = HANDLE_EINTR( |
| 147 read(pipe_fd_, string_as_array(&data) + pos, data.size() - pos)); | 147 read(pipe_fd_, string_as_array(&data) + pos, data.size() - pos)); |
| 148 if (read_result >= 0) { | 148 if (read_result > 0) { |
| 149 pos += read_result; | 149 pos += read_result; |
| 150 } else { | 150 } else { |
| 151 if (errno != EWOULDBLOCK && errno != EAGAIN) | 151 if (read_result < 0 && errno != EWOULDBLOCK && errno != EAGAIN) |
| 152 PLOG(ERROR) << "read"; | 152 PLOG(ERROR) << "read"; |
| 153 break; | 153 break; |
| 154 } | 154 } |
| 155 } | 155 } |
| 156 | 156 |
| 157 // Stop reading from the pipe if PulseAudio isn't writing anything. | 157 // Stop reading from the pipe if PulseAudio isn't writing anything. |
| 158 if (pos == 0) { | 158 if (pos == 0) { |
| 159 WaitForPipeReadable(); | 159 WaitForPipeReadable(); |
| 160 return; | 160 return; |
| 161 } | 161 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 191 pipe_fd_, false, MessageLoopForIO::WATCH_READ, | 191 pipe_fd_, false, MessageLoopForIO::WATCH_READ, |
| 192 &file_descriptor_watcher_, this); | 192 &file_descriptor_watcher_, this); |
| 193 } | 193 } |
| 194 | 194 |
| 195 // static | 195 // static |
| 196 void AudioPipeReaderTraits::Destruct(const AudioPipeReader* audio_pipe_reader) { | 196 void AudioPipeReaderTraits::Destruct(const AudioPipeReader* audio_pipe_reader) { |
| 197 audio_pipe_reader->task_runner_->DeleteSoon(FROM_HERE, audio_pipe_reader); | 197 audio_pipe_reader->task_runner_->DeleteSoon(FROM_HERE, audio_pipe_reader); |
| 198 } | 198 } |
| 199 | 199 |
| 200 } // namespace remoting | 200 } // namespace remoting |
| OLD | NEW |