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

Side by Side Diff: remoting/host/audio_capturer_linux.cc

Issue 10911271: Remove CommandLine dependency from the Linux's AudioCapturer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « remoting/host/audio_capturer_linux.h ('k') | remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "remoting/host/audio_capturer_linux.h" 5 #include "remoting/host/audio_capturer_linux.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <sys/stat.h> 8 #include <sys/stat.h>
9 #include <sys/types.h> 9 #include <sys/types.h>
10 #include <unistd.h> 10 #include <unistd.h>
11 11
12 #include "base/command_line.h"
13 #include "base/eintr_wrapper.h" 12 #include "base/eintr_wrapper.h"
14 #include "base/file_path.h" 13 #include "base/file_path.h"
14 #include "base/lazy_instance.h"
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "remoting/proto/audio.pb.h" 17 #include "remoting/proto/audio.pb.h"
18 #include "remoting/host/chromoting_host_context.h"
18 19
19 namespace remoting { 20 namespace remoting {
20 21
21 namespace { 22 namespace {
22 23
23 const char kAudioPipeOptionName[] = "audio-pipe-name";
24
25 // PulseAudio's module-pipe-sink must be configured to use the following 24 // PulseAudio's module-pipe-sink must be configured to use the following
26 // parameters for the sink we read from. 25 // parameters for the sink we read from.
27 const AudioPacket_SamplingRate kSamplingRate = AudioPacket::SAMPLING_RATE_44100; 26 const AudioPacket_SamplingRate kSamplingRate = AudioPacket::SAMPLING_RATE_44100;
28 const int kChannels = 2; 27 const int kChannels = 2;
29 const int kBytesPerSample = 2; 28 const int kBytesPerSample = 2;
30 29
31 // Read data from the pipe every 40ms. 30 // Read data from the pipe every 40ms.
32 const int kCapturingPeriodMs = 40; 31 const int kCapturingPeriodMs = 40;
33 32
34 #if !defined(F_SETPIPE_SZ) 33 #if !defined(F_SETPIPE_SZ)
35 // F_SETPIPE_SZ is supported only starting linux 2.6.35, but we want to be able 34 // F_SETPIPE_SZ is supported only starting linux 2.6.35, but we want to be able
36 // to compile this code on machines with older kernel. 35 // to compile this code on machines with older kernel.
37 #define F_SETPIPE_SZ 1031 36 #define F_SETPIPE_SZ 1031
38 #endif // defined(F_SETPIPE_SZ) 37 #endif // defined(F_SETPIPE_SZ)
39 38
39 // Pipename used to capture audio stream from.
40 // TODO(sergeyu): Pass this to AudioCapturerLinux constructor once we have
41 // Linux-specific DesktopEnvironmentFactory
42 base::LazyInstance<FilePath>::Leaky
43 g_audio_pipe_name = LAZY_INSTANCE_INITIALIZER;
44
40 const int IsPacketOfSilence(const std::string& data) { 45 const int IsPacketOfSilence(const std::string& data) {
41 const int64* int_buf = reinterpret_cast<const int64*>(data.data()); 46 const int64* int_buf = reinterpret_cast<const int64*>(data.data());
42 for (size_t i = 0; i < data.size() / sizeof(int64); i++) { 47 for (size_t i = 0; i < data.size() / sizeof(int64); i++) {
43 if (int_buf[i] != 0) 48 if (int_buf[i] != 0)
44 return false; 49 return false;
45 } 50 }
46 for (size_t i = data.size() - data.size() % sizeof(int64); 51 for (size_t i = data.size() - data.size() % sizeof(int64);
47 i < data.size(); i++) { 52 i < data.size(); i++) {
48 if (data.data()[i] != 0) 53 if (data.data()[i] != 0)
49 return false; 54 return false;
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
168 callback_.Run(packet.Pass()); 173 callback_.Run(packet.Pass());
169 } 174 }
170 175
171 void AudioCapturerLinux::WaitForPipeReadable() { 176 void AudioCapturerLinux::WaitForPipeReadable() {
172 timer_.Stop(); 177 timer_.Stop();
173 MessageLoopForIO::current()->WatchFileDescriptor( 178 MessageLoopForIO::current()->WatchFileDescriptor(
174 pipe_fd_, false, MessageLoopForIO::WATCH_READ, 179 pipe_fd_, false, MessageLoopForIO::WATCH_READ,
175 &file_descriptor_watcher_, this); 180 &file_descriptor_watcher_, this);
176 } 181 }
177 182
183 void AudioCapturerLinux::SetPipeName(const FilePath& pipe_name) {
184 g_audio_pipe_name.Get() = pipe_name;
185 }
186
178 bool AudioCapturer::IsSupported() { 187 bool AudioCapturer::IsSupported() {
179 CommandLine* cl = CommandLine::ForCurrentProcess(); 188 return !g_audio_pipe_name.Get().empty();
180 return !cl->GetSwitchValuePath(kAudioPipeOptionName).empty();
181 } 189 }
182 190
183 scoped_ptr<AudioCapturer> AudioCapturer::Create() { 191 scoped_ptr<AudioCapturer> AudioCapturer::Create() {
184 CommandLine* cl = CommandLine::ForCurrentProcess(); 192 FilePath path = g_audio_pipe_name.Get();
185 FilePath path = cl->GetSwitchValuePath(kAudioPipeOptionName);
186 if (path.empty()) 193 if (path.empty())
187 return scoped_ptr<AudioCapturer>(); 194 return scoped_ptr<AudioCapturer>();
188 return scoped_ptr<AudioCapturer>(new AudioCapturerLinux(path)); 195 return scoped_ptr<AudioCapturer>(new AudioCapturerLinux(path));
189 } 196 }
190 197
191 } // namespace remoting 198 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/host/audio_capturer_linux.h ('k') | remoting/host/remoting_me2me_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698