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

Side by Side Diff: remoting/host/linux/pulseaudio_pipe_sink_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
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_PULSEAUDIO_PIPE_SINK_READER_H_
6 #define REMOTING_HOST_LINUX_PULSEAUDIO_PIPE_SINK_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 // PulseaudioPipeSinkReader class reads from a named pipe to which pulseaudio
Wez 2012/10/31 00:56:28 nit: Suggest "PulseaudioPipeSinkReader reads raw a
Sergey Ulanov 2012/10/31 18:41:24 Done.
20 // writes the sound that's being played back and then sends data to all
21 // registered observers. ObserverListThreadSafe is used to send data to the
Wez 2012/10/31 00:56:28 nit: Move this comment to the |observers_| member,
Sergey Ulanov 2012/10/31 18:41:24 I think that it's important for calling code on wh
22 // observers so each of them receives data on the thread on which it is
23 // registered.
24 class PulseaudioPipeSinkReader
25 : public base::RefCountedThreadSafe<PulseaudioPipeSinkReader>,
26 public MessageLoopForIO::Watcher {
27 public:
28 class StreamObserver {
29 public:
30 virtual void OnDataRead(scoped_refptr<base::RefCountedString> data) = 0;
31 };
32
33 // |task_runner| defines the IO thread on which the object will be reading
34 // data from the pipe.
35 PulseaudioPipeSinkReader(
36 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
37 const FilePath& pipe_name);
38
39 // Functions to register and unregister observers.
Wez 2012/10/31 00:56:28 nit: Suggest "Register or unregister an observer.
Sergey Ulanov 2012/10/31 18:41:24 Done.
40 void AddCapturer(StreamObserver* observer);
41 void RemoveCapturer(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<PulseaudioPipeSinkReader>;
49 virtual ~PulseaudioPipeSinkReader();
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<PulseaudioPipeSinkReader> 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(PulseaudioPipeSinkReader);
74 };
75
76 } // namespace remoting
77
78 #endif // REMOTING_HOST_LINUX_PULSEAUDIO_PIPE_SINK_READER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698