diff options
author | kxing@chromium.org <kxing@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-22 00:56:55 +0000 |
---|---|---|
committer | kxing@chromium.org <kxing@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-22 00:56:55 +0000 |
commit | 91d3a7dcafdbc2c4cf4d12c79a98a5e70cb9244e (patch) | |
tree | 022647b8dae8ff3adc8c0955436ab91d991c55f4 | |
parent | efac095a6203050f0c17a4efca9cf3ec01d26850 (diff) | |
download | chromium_src-91d3a7dcafdbc2c4cf4d12c79a98a5e70cb9244e.zip chromium_src-91d3a7dcafdbc2c4cf4d12c79a98a5e70cb9244e.tar.gz chromium_src-91d3a7dcafdbc2c4cf4d12c79a98a5e70cb9244e.tar.bz2 |
Silence detection test for the Windows audio capturer.
BUG=
Review URL: https://chromiumcodereview.appspot.com/10823440
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152704 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | remoting/host/audio_capturer_win.cc | 49 | ||||
-rw-r--r-- | remoting/host/audio_capturer_win.h | 54 | ||||
-rw-r--r-- | remoting/host/audio_capturer_win_unittest.cc | 29 | ||||
-rw-r--r-- | remoting/remoting.gyp | 1 |
4 files changed, 87 insertions, 46 deletions
diff --git a/remoting/host/audio_capturer_win.cc b/remoting/host/audio_capturer_win.cc index 4dfc174..6479afa 100644 --- a/remoting/host/audio_capturer_win.cc +++ b/remoting/host/audio_capturer_win.cc @@ -2,26 +2,17 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "remoting/host/audio_capturer_win.h" + #include <windows.h> -#include <audioclient.h> #include <avrt.h> -#include <mmdeviceapi.h> #include <mmreg.h> #include <mmsystem.h> #include <algorithm> #include <stdlib.h> -#include "base/basictypes.h" #include "base/logging.h" -#include "base/memory/scoped_ptr.h" -#include "base/message_loop.h" -#include "base/timer.h" -#include "base/win/scoped_co_mem.h" -#include "base/win/scoped_com_initializer.h" -#include "base/win/scoped_comptr.h" -#include "remoting/host/audio_capturer.h" -#include "remoting/proto/audio.pb.h" namespace { const int kChannels = 2; @@ -46,41 +37,6 @@ const int kMaxExpectedTimerLag = 30; namespace remoting { -class AudioCapturerWin : public AudioCapturer { - public: - AudioCapturerWin(); - virtual ~AudioCapturerWin(); - - // AudioCapturer interface. - virtual bool Start(const PacketCapturedCallback& callback) OVERRIDE; - virtual void Stop() OVERRIDE; - virtual bool IsRunning() OVERRIDE; - - private: - // Receives all packets from the audio capture endpoint buffer and pushes them - // to the network. - void DoCapture(); - - static bool IsPacketOfSilence(const int16* samples, int number_of_samples); - - PacketCapturedCallback callback_; - - AudioPacket::SamplingRate sampling_rate_; - - scoped_ptr<base::RepeatingTimer<AudioCapturerWin> > capture_timer_; - base::TimeDelta audio_device_period_; - - base::win::ScopedCoMem<WAVEFORMATEX> wave_format_ex_; - base::win::ScopedComPtr<IAudioCaptureClient> audio_capture_client_; - base::win::ScopedComPtr<IAudioClient> audio_client_; - base::win::ScopedComPtr<IMMDevice> mm_device_; - scoped_ptr<base::win::ScopedCOMInitializer> com_initializer_; - - base::ThreadChecker thread_checker_; - - DISALLOW_COPY_AND_ASSIGN(AudioCapturerWin); -}; - AudioCapturerWin::AudioCapturerWin() : sampling_rate_(AudioPacket::SAMPLING_RATE_INVALID) { thread_checker_.DetachFromThread(); @@ -313,6 +269,7 @@ void AudioCapturerWin::DoCapture() { // Detects whether there is audio playing in a packet of samples. // Windows can give nonzero samples, even when there is no audio playing, so // extremely low amplitude samples are counted as silence. +// static bool AudioCapturerWin::IsPacketOfSilence( const int16* samples, int number_of_samples) { for (int i = 0; i < number_of_samples; i++) { diff --git a/remoting/host/audio_capturer_win.h b/remoting/host/audio_capturer_win.h new file mode 100644 index 0000000..bfd9803 --- /dev/null +++ b/remoting/host/audio_capturer_win.h @@ -0,0 +1,54 @@ +// 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. + +#include <audioclient.h> +#include <mmdeviceapi.h> + +#include "base/basictypes.h" +#include "base/memory/scoped_ptr.h" +#include "base/timer.h" +#include "base/win/scoped_co_mem.h" +#include "base/win/scoped_com_initializer.h" +#include "base/win/scoped_comptr.h" +#include "remoting/host/audio_capturer.h" +#include "remoting/proto/audio.pb.h" + +namespace remoting { + +class AudioCapturerWin : public AudioCapturer { + public: + AudioCapturerWin(); + virtual ~AudioCapturerWin(); + + // AudioCapturer interface. + virtual bool Start(const PacketCapturedCallback& callback) OVERRIDE; + virtual void Stop() OVERRIDE; + virtual bool IsRunning() OVERRIDE; + + static bool IsPacketOfSilence(const int16* samples, int number_of_samples); + + private: + // Receives all packets from the audio capture endpoint buffer and pushes them + // to the network. + void DoCapture(); + + PacketCapturedCallback callback_; + + AudioPacket::SamplingRate sampling_rate_; + + scoped_ptr<base::RepeatingTimer<AudioCapturerWin> > capture_timer_; + base::TimeDelta audio_device_period_; + + base::win::ScopedCoMem<WAVEFORMATEX> wave_format_ex_; + base::win::ScopedComPtr<IAudioCaptureClient> audio_capture_client_; + base::win::ScopedComPtr<IAudioClient> audio_client_; + base::win::ScopedComPtr<IMMDevice> mm_device_; + scoped_ptr<base::win::ScopedCOMInitializer> com_initializer_; + + base::ThreadChecker thread_checker_; + + DISALLOW_COPY_AND_ASSIGN(AudioCapturerWin); +}; + +} // namespace remoting diff --git a/remoting/host/audio_capturer_win_unittest.cc b/remoting/host/audio_capturer_win_unittest.cc new file mode 100644 index 0000000..5b71ae4 --- /dev/null +++ b/remoting/host/audio_capturer_win_unittest.cc @@ -0,0 +1,29 @@ +// 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. + +#include "remoting/host/audio_capturer_win.h" + +#include "base/basictypes.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace remoting { + +TEST(AudioCapturerWinTest, SilenceTest) { + int16 samples1[] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + int16 samples2[] = {65, 73, 83, 89, 92, -1, 5, 9, 123, 0}; + int16 samples3[] = {0, 0, 0, 0, 1, 0, 0, -1, 0, 0}; + // MSVC++ doesn't allow allocating arrays of size 0. + int16 samples4[] = {0}; + + ASSERT_TRUE( + AudioCapturerWin::IsPacketOfSilence(samples1, arraysize(samples1))); + ASSERT_FALSE( + AudioCapturerWin::IsPacketOfSilence(samples2, arraysize(samples2))); + ASSERT_TRUE( + AudioCapturerWin::IsPacketOfSilence(samples3, arraysize(samples3))); + ASSERT_TRUE( + AudioCapturerWin::IsPacketOfSilence(samples4, 0)); +} + +} // namespace remoting diff --git a/remoting/remoting.gyp b/remoting/remoting.gyp index 88971cbd0..7c0a157 100644 --- a/remoting/remoting.gyp +++ b/remoting/remoting.gyp @@ -1737,6 +1737,7 @@ 'base/util_unittest.cc', 'client/key_event_mapper_unittest.cc', 'client/plugin/mac_key_event_processor_unittest.cc', + 'host/audio_capturer_win_unittest.cc', 'host/chromoting_host_context_unittest.cc', 'host/chromoting_host_unittest.cc', 'host/client_session_unittest.cc', |