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_LINUX_AUDIO_PIPE_READER_H_ | 5 #ifndef REMOTING_HOST_LINUX_AUDIO_PIPE_READER_H_ |
6 #define REMOTING_HOST_LINUX_AUDIO_PIPE_READER_H_ | 6 #define REMOTING_HOST_LINUX_AUDIO_PIPE_READER_H_ |
7 | 7 |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/ref_counted_memory.h" | 9 #include "base/memory/ref_counted_memory.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/observer_list_threadsafe.h" | 11 #include "base/observer_list_threadsafe.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "base/timer.h" | 13 #include "base/timer.h" |
14 | 14 |
| 15 namespace base { |
15 class FilePath; | 16 class FilePath; |
| 17 } |
16 | 18 |
17 namespace remoting { | 19 namespace remoting { |
18 | 20 |
19 struct AudioPipeReaderTraits; | 21 struct AudioPipeReaderTraits; |
20 | 22 |
21 // AudioPipeReader class reads from a named pipe to which an audio server (e.g. | 23 // AudioPipeReader class reads from a named pipe to which an audio server (e.g. |
22 // pulseaudio) writes the sound that's being played back and then sends data to | 24 // pulseaudio) writes the sound that's being played back and then sends data to |
23 // all registered observers. | 25 // all registered observers. |
24 class AudioPipeReader | 26 class AudioPipeReader |
25 : public base::RefCountedThreadSafe<AudioPipeReader, AudioPipeReaderTraits>, | 27 : public base::RefCountedThreadSafe<AudioPipeReader, AudioPipeReaderTraits>, |
26 public MessageLoopForIO::Watcher { | 28 public MessageLoopForIO::Watcher { |
27 public: | 29 public: |
28 class StreamObserver { | 30 class StreamObserver { |
29 public: | 31 public: |
30 virtual void OnDataRead(scoped_refptr<base::RefCountedString> data) = 0; | 32 virtual void OnDataRead(scoped_refptr<base::RefCountedString> data) = 0; |
31 }; | 33 }; |
32 | 34 |
33 // |task_runner| specifies the IO thread to use to read data from the pipe. | 35 // |task_runner| specifies the IO thread to use to read data from the pipe. |
34 static scoped_refptr<AudioPipeReader> Create( | 36 static scoped_refptr<AudioPipeReader> Create( |
35 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 37 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
36 const FilePath& pipe_name); | 38 const base::FilePath& pipe_name); |
37 | 39 |
38 // Register or unregister an observer. Each observer receives data on the | 40 // Register or unregister an observer. Each observer receives data on the |
39 // thread on which it was registered and guaranteed not to be called after | 41 // thread on which it was registered and guaranteed not to be called after |
40 // RemoveObserver(). | 42 // RemoveObserver(). |
41 void AddObserver(StreamObserver* observer); | 43 void AddObserver(StreamObserver* observer); |
42 void RemoveObserver(StreamObserver* observer); | 44 void RemoveObserver(StreamObserver* observer); |
43 | 45 |
44 // MessageLoopForIO::Watcher interface. | 46 // MessageLoopForIO::Watcher interface. |
45 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; | 47 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE; |
46 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; | 48 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE; |
47 | 49 |
48 private: | 50 private: |
49 friend class base::DeleteHelper<AudioPipeReader>; | 51 friend class base::DeleteHelper<AudioPipeReader>; |
50 friend class base::RefCountedThreadSafe<AudioPipeReader>; | 52 friend class base::RefCountedThreadSafe<AudioPipeReader>; |
51 friend struct AudioPipeReaderTraits; | 53 friend struct AudioPipeReaderTraits; |
52 | 54 |
53 AudioPipeReader(scoped_refptr<base::SingleThreadTaskRunner> task_runner); | 55 AudioPipeReader(scoped_refptr<base::SingleThreadTaskRunner> task_runner); |
54 virtual ~AudioPipeReader(); | 56 virtual ~AudioPipeReader(); |
55 | 57 |
56 void StartOnAudioThread(const FilePath& pipe_name); | 58 void StartOnAudioThread(const base::FilePath& pipe_name); |
57 void StartTimer(); | 59 void StartTimer(); |
58 void DoCapture(); | 60 void DoCapture(); |
59 void WaitForPipeReadable(); | 61 void WaitForPipeReadable(); |
60 | 62 |
61 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 63 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
62 | 64 |
63 int pipe_fd_; | 65 int pipe_fd_; |
64 base::RepeatingTimer<AudioPipeReader> timer_; | 66 base::RepeatingTimer<AudioPipeReader> timer_; |
65 scoped_refptr<ObserverListThreadSafe<StreamObserver> > observers_; | 67 scoped_refptr<ObserverListThreadSafe<StreamObserver> > observers_; |
66 | 68 |
(...skipping 14 matching lines...) Expand all Loading... |
81 }; | 83 }; |
82 | 84 |
83 // Destroys |audio_pipe_reader| on the audio thread. | 85 // Destroys |audio_pipe_reader| on the audio thread. |
84 struct AudioPipeReaderTraits { | 86 struct AudioPipeReaderTraits { |
85 static void Destruct(const AudioPipeReader* audio_pipe_reader); | 87 static void Destruct(const AudioPipeReader* audio_pipe_reader); |
86 }; | 88 }; |
87 | 89 |
88 } // namespace remoting | 90 } // namespace remoting |
89 | 91 |
90 #endif // REMOTING_HOST_LINUX_AUDIO_PIPE_READER_H_ | 92 #endif // REMOTING_HOST_LINUX_AUDIO_PIPE_READER_H_ |
OLD | NEW |