Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(446)

Side by Side Diff: remoting/host/linux/audio_pipe_reader.h

Issue 11316010: Fix AudioCapturer implementation to read from audio pipe even when there are no active clients. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/audio_capturer_linux.cc ('k') | remoting/host/linux/audio_pipe_reader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
5 #ifndef REMOTING_HOST_LINUX_AUDIO_PIPE_READER_H_
6 #define REMOTING_HOST_LINUX_AUDIO_PIPE_READER_H_
7
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/ref_counted_memory.h"
10 #include "base/message_loop.h"
11 #include "base/observer_list_threadsafe.h"
12 #include "base/time.h"
13 #include "base/timer.h"
14
15 class FilePath;
16
17 namespace remoting {
18
19 // AudioPipeReader class reads from a named pipe to which an audio server (e.g.
20 // pulseaudio) writes the sound that's being played back and then sends data to
21 // all registered observers.
22 class AudioPipeReader
23 : public base::RefCountedThreadSafe<AudioPipeReader>,
24 public MessageLoopForIO::Watcher {
25 public:
26 class StreamObserver {
27 public:
28 virtual void OnDataRead(scoped_refptr<base::RefCountedString> data) = 0;
29 };
30
31 // |task_runner| defines the IO thread on which the object will be reading
32 // data from the pipe.
33 AudioPipeReader(
34 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
35 const FilePath& pipe_name);
36
37 // Register or unregister an observer. Each observer receives data on the
38 // thread on which it was registered and guaranteed not to be called after
39 // RemoveObserver().
40 void AddObserver(StreamObserver* observer);
41 void RemoveObserver(StreamObserver* observer);
42
43 // MessageLoopForIO::Watcher interface.
44 virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
45 virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
46
47 private:
48 friend class base::RefCountedThreadSafe<AudioPipeReader>;
49 virtual ~AudioPipeReader();
50
51 void StartOnAudioThread(const FilePath& pipe_name);
52 void StartTimer();
53 void DoCapture();
54 void WaitForPipeReadable();
55
56 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
57
58 int pipe_fd_;
59 base::RepeatingTimer<AudioPipeReader> timer_;
60 scoped_refptr<ObserverListThreadSafe<StreamObserver> > observers_;
61
62 // Time when capturing was started.
63 base::TimeTicks started_time_;
64
65 // Stream position of the last capture.
66 int64 last_capture_samples_;
67
68 // Bytes left from the previous read.
69 std::string left_over_bytes_;
70
71 MessageLoopForIO::FileDescriptorWatcher file_descriptor_watcher_;
72
73 DISALLOW_COPY_AND_ASSIGN(AudioPipeReader);
74 };
75
76 } // namespace remoting
77
78 #endif // REMOTING_HOST_LINUX_AUDIO_PIPE_READER_H_
OLDNEW
« no previous file with comments | « remoting/host/audio_capturer_linux.cc ('k') | remoting/host/linux/audio_pipe_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698