| 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 #include "remoting/host/audio_capturer_linux.h" | 5 #include "remoting/host/audio_capturer_linux.h" |
| 6 | 6 |
| 7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "remoting/proto/audio.pb.h" | 10 #include "remoting/proto/audio.pb.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 g_pulseaudio_pipe_sink_reader.Get() = pipe_reader; | 30 g_pulseaudio_pipe_sink_reader.Get() = pipe_reader; |
| 31 } | 31 } |
| 32 | 32 |
| 33 AudioCapturerLinux::AudioCapturerLinux( | 33 AudioCapturerLinux::AudioCapturerLinux( |
| 34 scoped_refptr<AudioPipeReader> pipe_reader) | 34 scoped_refptr<AudioPipeReader> pipe_reader) |
| 35 : pipe_reader_(pipe_reader), | 35 : pipe_reader_(pipe_reader), |
| 36 silence_detector_(0) { | 36 silence_detector_(0) { |
| 37 } | 37 } |
| 38 | 38 |
| 39 AudioCapturerLinux::~AudioCapturerLinux() { | 39 AudioCapturerLinux::~AudioCapturerLinux() { |
| 40 pipe_reader_->RemoveObserver(this); |
| 40 } | 41 } |
| 41 | 42 |
| 42 bool AudioCapturerLinux::Start(const PacketCapturedCallback& callback) { | 43 bool AudioCapturerLinux::Start(const PacketCapturedCallback& callback) { |
| 43 callback_ = callback; | 44 callback_ = callback; |
| 44 silence_detector_.Reset(AudioPipeReader::kSamplingRate, | 45 silence_detector_.Reset(AudioPipeReader::kSamplingRate, |
| 45 AudioPipeReader::kChannels); | 46 AudioPipeReader::kChannels); |
| 46 pipe_reader_->AddObserver(this); | 47 pipe_reader_->AddObserver(this); |
| 47 return true; | 48 return true; |
| 48 } | 49 } |
| 49 | 50 |
| 50 void AudioCapturerLinux::Stop() { | |
| 51 pipe_reader_->RemoveObserver(this); | |
| 52 callback_.Reset(); | |
| 53 } | |
| 54 | |
| 55 bool AudioCapturerLinux::IsStarted() { | |
| 56 return !callback_.is_null(); | |
| 57 } | |
| 58 | |
| 59 void AudioCapturerLinux::OnDataRead( | 51 void AudioCapturerLinux::OnDataRead( |
| 60 scoped_refptr<base::RefCountedString> data) { | 52 scoped_refptr<base::RefCountedString> data) { |
| 61 DCHECK(!callback_.is_null()); | 53 DCHECK(!callback_.is_null()); |
| 62 | 54 |
| 63 if (silence_detector_.IsSilence( | 55 if (silence_detector_.IsSilence( |
| 64 reinterpret_cast<const int16*>(data->data().data()), | 56 reinterpret_cast<const int16*>(data->data().data()), |
| 65 data->data().size() / sizeof(int16))) { | 57 data->data().size() / sizeof(int16))) { |
| 66 return; | 58 return; |
| 67 } | 59 } |
| 68 | 60 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 81 | 73 |
| 82 scoped_ptr<AudioCapturer> AudioCapturer::Create() { | 74 scoped_ptr<AudioCapturer> AudioCapturer::Create() { |
| 83 scoped_refptr<AudioPipeReader> reader = | 75 scoped_refptr<AudioPipeReader> reader = |
| 84 g_pulseaudio_pipe_sink_reader.Get(); | 76 g_pulseaudio_pipe_sink_reader.Get(); |
| 85 if (!reader.get()) | 77 if (!reader.get()) |
| 86 return nullptr; | 78 return nullptr; |
| 87 return make_scoped_ptr(new AudioCapturerLinux(reader)); | 79 return make_scoped_ptr(new AudioCapturerLinux(reader)); |
| 88 } | 80 } |
| 89 | 81 |
| 90 } // namespace remoting | 82 } // namespace remoting |
| OLD | NEW |