| 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 #ifndef REMOTING_HOST_AUDIO_CAPTURER_LINUX_H_ | 5 #ifndef REMOTING_HOST_AUDIO_CAPTURER_LINUX_H_ |
| 6 #define REMOTING_HOST_AUDIO_CAPTURER_LINUX_H_ | 6 #define REMOTING_HOST_AUDIO_CAPTURER_LINUX_H_ |
| 7 | 7 |
| 8 #include "base/memory/ref_counted.h" |
| 8 #include "remoting/host/audio_capturer.h" | 9 #include "remoting/host/audio_capturer.h" |
| 9 | 10 #include "remoting/host/linux/audio_pipe_reader.h" |
| 10 #include "base/message_loop.h" | |
| 11 #include "base/time.h" | |
| 12 #include "base/timer.h" | |
| 13 | 11 |
| 14 class FilePath; | 12 class FilePath; |
| 15 | 13 |
| 16 namespace remoting { | 14 namespace remoting { |
| 17 | 15 |
| 16 // Linux implementation of AudioCapturer interface which captures audio by |
| 17 // reading samples from a Pulseaudio "pipe" sink. |
| 18 class AudioCapturerLinux : public AudioCapturer, | 18 class AudioCapturerLinux : public AudioCapturer, |
| 19 public MessageLoopForIO::Watcher { | 19 public AudioPipeReader::StreamObserver { |
| 20 public: | 20 public: |
| 21 // Must be called to configure the capturer before the first instance is | 21 // Must be called to configure the capturer before the first capturer instance |
| 22 // created. | 22 // is created. |task_runner| is an IO thread that is passed to AudioPipeReader |
| 23 static void SetPipeName(const FilePath& pipe_name); | 23 // to read from the pipe. |
| 24 static void InitializePipeReader( |
| 25 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 26 const FilePath& pipe_name); |
| 24 | 27 |
| 25 explicit AudioCapturerLinux(const FilePath& pipe_name); | 28 explicit AudioCapturerLinux( |
| 29 scoped_refptr<AudioPipeReader> pipe_reader); |
| 26 virtual ~AudioCapturerLinux(); | 30 virtual ~AudioCapturerLinux(); |
| 27 | 31 |
| 28 // AudioCapturer interface. | 32 // AudioCapturer interface. |
| 29 virtual bool Start(const PacketCapturedCallback& callback) OVERRIDE; | 33 virtual bool Start(const PacketCapturedCallback& callback) OVERRIDE; |
| 30 virtual void Stop() OVERRIDE; | 34 virtual void Stop() OVERRIDE; |
| 31 virtual bool IsStarted() OVERRIDE; | 35 virtual bool IsStarted() OVERRIDE; |
| 32 | 36 |
| 33 // MessageLoopForIO::Watcher interface. | 37 // AudioPipeReader::StreamObserver interface. |
| 34 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; | 38 virtual void OnDataRead(scoped_refptr<base::RefCountedString> data) OVERRIDE; |
| 35 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; | |
| 36 | 39 |
| 37 private: | 40 private: |
| 38 void StartTimer(); | 41 scoped_refptr<AudioPipeReader> pipe_reader_; |
| 39 void DoCapture(); | |
| 40 void WaitForPipeReadable(); | |
| 41 | |
| 42 int pipe_fd_; | |
| 43 base::RepeatingTimer<AudioCapturerLinux> timer_; | |
| 44 PacketCapturedCallback callback_; | 42 PacketCapturedCallback callback_; |
| 45 | 43 |
| 46 // Time when capturing was started. | |
| 47 base::TimeTicks started_time_; | |
| 48 | |
| 49 // Stream position of the last capture. | |
| 50 int64 last_capture_samples_; | |
| 51 | |
| 52 // Bytes left from the previous read. | |
| 53 std::string left_over_bytes_; | |
| 54 | |
| 55 MessageLoopForIO::FileDescriptorWatcher file_descriptor_watcher_; | |
| 56 | |
| 57 DISALLOW_COPY_AND_ASSIGN(AudioCapturerLinux); | 44 DISALLOW_COPY_AND_ASSIGN(AudioCapturerLinux); |
| 58 }; | 45 }; |
| 59 | 46 |
| 60 } // namespace remoting | 47 } // namespace remoting |
| 61 | 48 |
| 62 #endif // REMOTING_HOST_AUDIO_CAPTURER_LINUX_H_ | 49 #endif // REMOTING_HOST_AUDIO_CAPTURER_LINUX_H_ |
| OLD | NEW |