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

Unified 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, 2 months 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 side-by-side diff with in-line comments
Download patch
Index: remoting/host/linux/pulseaudio_pipe_sink_reader.h
diff --git a/remoting/host/linux/pulseaudio_pipe_sink_reader.h b/remoting/host/linux/pulseaudio_pipe_sink_reader.h
new file mode 100644
index 0000000000000000000000000000000000000000..4307f7d0a53593624e8d7b07a0761e730f458dab
--- /dev/null
+++ b/remoting/host/linux/pulseaudio_pipe_sink_reader.h
@@ -0,0 +1,78 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef REMOTING_HOST_LINUX_PULSEAUDIO_PIPE_SINK_READER_H_
+#define REMOTING_HOST_LINUX_PULSEAUDIO_PIPE_SINK_READER_H_
+
+#include "base/memory/ref_counted.h"
+#include "base/memory/ref_counted_memory.h"
+#include "base/message_loop.h"
+#include "base/observer_list_threadsafe.h"
+#include "base/time.h"
+#include "base/timer.h"
+
+class FilePath;
+
+namespace remoting {
+
+// 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.
+// writes the sound that's being played back and then sends data to all
+// 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
+// observers so each of them receives data on the thread on which it is
+// registered.
+class PulseaudioPipeSinkReader
+ : public base::RefCountedThreadSafe<PulseaudioPipeSinkReader>,
+ public MessageLoopForIO::Watcher {
+ public:
+ class StreamObserver {
+ public:
+ virtual void OnDataRead(scoped_refptr<base::RefCountedString> data) = 0;
+ };
+
+ // |task_runner| defines the IO thread on which the object will be reading
+ // data from the pipe.
+ PulseaudioPipeSinkReader(
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner,
+ const FilePath& pipe_name);
+
+ // 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.
+ void AddCapturer(StreamObserver* observer);
+ void RemoveCapturer(StreamObserver* observer);
+
+ // MessageLoopForIO::Watcher interface.
+ virtual void OnFileCanReadWithoutBlocking(int fd) OVERRIDE;
+ virtual void OnFileCanWriteWithoutBlocking(int fd) OVERRIDE;
+
+ private:
+ friend class base::RefCountedThreadSafe<PulseaudioPipeSinkReader>;
+ virtual ~PulseaudioPipeSinkReader();
+
+ void StartOnAudioThread(const FilePath& pipe_name);
+ void StartTimer();
+ void DoCapture();
+ void WaitForPipeReadable();
+
+ scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
+
+ int pipe_fd_;
+ base::RepeatingTimer<PulseaudioPipeSinkReader> timer_;
+ scoped_refptr<ObserverListThreadSafe<StreamObserver> > observers_;
+
+ // Time when capturing was started.
+ base::TimeTicks started_time_;
+
+ // Stream position of the last capture.
+ int64 last_capture_samples_;
+
+ // Bytes left from the previous read.
+ std::string left_over_bytes_;
+
+ MessageLoopForIO::FileDescriptorWatcher file_descriptor_watcher_;
+
+ DISALLOW_COPY_AND_ASSIGN(PulseaudioPipeSinkReader);
+};
+
+} // namespace remoting
+
+#endif // REMOTING_HOST_LINUX_PULSEAUDIO_PIPE_SINK_READER_H_

Powered by Google App Engine
This is Rietveld 408576698