diff options
author | cpu@google.com <cpu@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-20 03:03:43 +0000 |
---|---|---|
committer | cpu@google.com <cpu@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-12-20 03:03:43 +0000 |
commit | 0d12ef12d81a4fffda677a1b683597aa8c77d44c (patch) | |
tree | 852ef4451b5ba8259a89df843405ab893c2760fc /media | |
parent | e7b660ddd5dfa2b76796419f213d9f00d20b8e8f (diff) | |
download | chromium_src-0d12ef12d81a4fffda677a1b683597aa8c77d44c.zip chromium_src-0d12ef12d81a4fffda677a1b683597aa8c77d44c.tar.gz chromium_src-0d12ef12d81a4fffda677a1b683597aa8c77d44c.tar.bz2 |
Audio support drop 2
- First part of Windows mock stream support
- Windows unittests
Scons modifications will come next
Review URL: http://codereview.chromium.org/15087
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7341 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/audio/audio_output.h | 2 | ||||
-rw-r--r-- | media/audio/win/audio_output_win.cc | 103 | ||||
-rw-r--r-- | media/audio/win/audio_output_win_unittest.cc | 53 | ||||
-rw-r--r-- | media/build/media.vcproj | 12 | ||||
-rw-r--r-- | media/build/media_unittests.vcproj | 8 |
5 files changed, 177 insertions, 1 deletions
diff --git a/media/audio/audio_output.h b/media/audio/audio_output.h index 3a6420e..da787ea 100644 --- a/media/audio/audio_output.h +++ b/media/audio/audio_output.h @@ -124,7 +124,7 @@ class AudioManager { virtual void UnMuteAll() = 0; protected: - virtual ~AudioManager(); + virtual ~AudioManager() {} }; // Get AudioManager singleton. diff --git a/media/audio/win/audio_output_win.cc b/media/audio/win/audio_output_win.cc new file mode 100644 index 0000000..4fe06e0 --- /dev/null +++ b/media/audio/win/audio_output_win.cc @@ -0,0 +1,103 @@ +// Copyright (c) 2006-2008 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 <windows.h> + +#include "base/basictypes.h" +#include "media/audio/audio_output.h" + +// A do-nothing audio stream. It behaves like a regular audio stream but does +// not have any side effect, except possibly the creation and tear-down of +// of a thread. It is useful to test code that uses audio streams such as +// audio sources. +class AudioOutputStreamWinMock : public AudioOutputStream { + public: + AudioOutputStreamWinMock() + : callback_(NULL), + buffer_(NULL), + packet_size_(0), + left_volume_(0.0), + right_volume_(0.0) { + } + + virtual bool Open(size_t packet_size) { + if (packet_size < sizeof(int16)) + return false; + packet_size_ = packet_size; + buffer_ = new char[packet_size_]; + return true; + } + + virtual void Start(AudioSourceCallback* callback) { + callback_ = callback; + callback_->OnMoreData(this, buffer_, packet_size_); + } + + // TODO(cpu): flesh out Start and Stop methods. We need a thread to + // perform periodic callbacks. + virtual void Stop() { + } + + virtual void SetVolume(double left_level, double right_level) { + left_volume_ = left_level; + right_volume_ = right_level; + } + + virtual void GetVolume(double* left_level, double* right_level) { + *left_level = left_volume_; + *right_level = right_volume_; + } + + virtual void Close() { + callback_->OnClose(this); + callback_ = NULL; + delete this; + } + + protected: + virtual ~AudioOutputStreamWinMock() { + delete[] buffer_; + packet_size_ = 0; + } + + private: + AudioSourceCallback* callback_; + char* buffer_; + size_t packet_size_; + double left_volume_; + double right_volume_; +}; + +class AudioManagerWin : public AudioManager { + public: + virtual AudioOutputStream* MakeAudioStream(Format format, int channels, + int sample_rate, + char bits_per_sample) { + if (format == AUDIO_MOCK) + return new AudioOutputStreamWinMock(); + return NULL; + } + + virtual void MuteAll() { + } + + virtual void UnMuteAll() { + } + + protected: + virtual ~AudioManagerWin() { + } +}; + +// TODO(cpu): Decide how to manage the lifetime of the AudioManager singleton. +// Right now we are leaking it. +AudioManager* GetAudioManager() { + static AudioManagerWin* audio_manager = NULL; + if (!audio_manager) + audio_manager = new AudioManagerWin(); + return audio_manager; +} + + + diff --git a/media/audio/win/audio_output_win_unittest.cc b/media/audio/win/audio_output_win_unittest.cc new file mode 100644 index 0000000..4d3874d --- /dev/null +++ b/media/audio/win/audio_output_win_unittest.cc @@ -0,0 +1,53 @@ +// Copyright (c) 2006-2008 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 "media/audio/audio_output.h" +#include "testing/gtest/include/gtest/gtest.h" + +class SimpleSource8bitStereo : public AudioOutputStream::AudioSourceCallback { + public: + explicit SimpleSource8bitStereo(size_t bytes_to_write) + : byte_count_(bytes_to_write), callback_count_(0) { + } + + // AudioSourceCallback::OnMoreData implementation: + virtual size_t OnMoreData(AudioOutputStream* stream, + void* dest, size_t max_size) { + ++callback_count_; + return byte_count_; + } + + // AudioSourceCallback::OnClose implementation: + virtual void OnClose(AudioOutputStream* stream) { + } + + // AudioSourceCallback::OnError implementation: + virtual void OnError(AudioOutputStream* stream, int code) { + } + + // Returns how many times OnMoreData() has been called. + int callback_count() const { + return callback_count_; + } + + private: + size_t byte_count_; + int callback_count_; +}; + +// Validate that the AudioManager::AUDIO_MOCK works. +TEST(WinAudioTest, MockStream) { + AudioManager* audio_man = GetAudioManager(); + ASSERT_TRUE(NULL != audio_man); + AudioOutputStream* oas = + audio_man->MakeAudioStream(AudioManager::AUDIO_MOCK, 2, 8000, 8); + ASSERT_TRUE(NULL != oas); + EXPECT_TRUE(oas->Open(256)); + SimpleSource8bitStereo source(256); + oas->Start(&source); + EXPECT_GT(source.callback_count(), 0); + oas->Close(); +} + + diff --git a/media/build/media.vcproj b/media/build/media.vcproj index f4684bd..8b406de 100644 --- a/media/build/media.vcproj +++ b/media/build/media.vcproj @@ -153,6 +153,18 @@ > </File> </Filter> + <Filter + Name="audio" + > + <File + RelativePath="..\audio\audio_output.h" + > + </File> + <File + RelativePath="..\audio\win\audio_output_win.cc" + > + </File> + </Filter> </Files> <Globals> </Globals> diff --git a/media/build/media_unittests.vcproj b/media/build/media_unittests.vcproj index 82347fc..575e7d8 100644 --- a/media/build/media_unittests.vcproj +++ b/media/build/media_unittests.vcproj @@ -160,6 +160,14 @@ > </File> </Filter> + <Filter + Name="audio" + > + <File + RelativePath="..\audio\win\audio_output_win_unittest.cc" + > + </File> + </Filter> </Filter> </Files> <Globals> |