audio_capturer_linux.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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
  3. // found in the LICENSE file.
  4. #ifndef REMOTING_HOST_AUDIO_CAPTURER_LINUX_H_
  5. #define REMOTING_HOST_AUDIO_CAPTURER_LINUX_H_
  6. #include "base/memory/ref_counted.h"
  7. #include "base/task/single_thread_task_runner.h"
  8. #include "remoting/host/audio_capturer.h"
  9. #include "remoting/host/audio_silence_detector.h"
  10. #include "remoting/host/linux/audio_pipe_reader.h"
  11. namespace base {
  12. class FilePath;
  13. }
  14. namespace remoting {
  15. // Linux implementation of AudioCapturer interface which captures audio by
  16. // reading samples from a Pulseaudio "pipe" sink.
  17. class AudioCapturerLinux : public AudioCapturer,
  18. public AudioPipeReader::StreamObserver {
  19. public:
  20. // Must be called to configure the capturer before the first capturer instance
  21. // is created. |task_runner| is an IO thread that is passed to AudioPipeReader
  22. // to read from the pipe.
  23. static void InitializePipeReader(
  24. scoped_refptr<base::SingleThreadTaskRunner> task_runner,
  25. const base::FilePath& pipe_name);
  26. explicit AudioCapturerLinux(
  27. scoped_refptr<AudioPipeReader> pipe_reader);
  28. AudioCapturerLinux(const AudioCapturerLinux&) = delete;
  29. AudioCapturerLinux& operator=(const AudioCapturerLinux&) = delete;
  30. ~AudioCapturerLinux() override;
  31. // AudioCapturer interface.
  32. bool Start(const PacketCapturedCallback& callback) override;
  33. // AudioPipeReader::StreamObserver interface.
  34. void OnDataRead(scoped_refptr<base::RefCountedString> data) override;
  35. private:
  36. scoped_refptr<AudioPipeReader> pipe_reader_;
  37. PacketCapturedCallback callback_;
  38. AudioSilenceDetector silence_detector_;
  39. };
  40. } // namespace remoting
  41. #endif // REMOTING_HOST_AUDIO_CAPTURER_LINUX_H_