From d3dd31fb151f067389f3423ee6de09f8c5251ed9 Mon Sep 17 00:00:00 2001 From: "satish@chromium.org" Date: Mon, 12 Jul 2010 20:11:04 +0000 Subject: Rename a header and some methods to make way for subsequent audio recording additions. Renaming audio_output.h to audio_io.h as future patches will add audio recording code to this file. Also renamed a couple of methods to make it clear that these are for audio playback/output and similar methods will be added for audio capture/recording soon. BUG=none TEST=no change in functionality. Review URL: http://codereview.chromium.org/2962006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52125 0039d316-1c4b-4281-b951-d872f2087c98 --- media/audio/audio_io.h | 164 ++++++++++++++++++++++++ media/audio/audio_output.h | 164 ------------------------ media/audio/audio_output_controller.cc | 2 +- media/audio/audio_output_controller.h | 2 +- media/audio/audio_output_controller_unittest.cc | 14 +- media/audio/fake_audio_output_stream.h | 2 +- media/audio/linux/alsa_output.cc | 2 +- media/audio/linux/alsa_output.h | 2 +- media/audio/linux/alsa_output_unittest.cc | 23 ++-- media/audio/linux/audio_manager_linux.cc | 13 +- media/audio/linux/audio_manager_linux.h | 12 +- media/audio/mac/audio_manager_mac.cc | 13 +- media/audio/mac/audio_manager_mac.h | 12 +- media/audio/mac/audio_output_mac.cc | 2 +- media/audio/mac/audio_output_mac.h | 2 +- media/audio/mac/audio_output_mac_unittest.cc | 24 ++-- media/audio/openbsd/audio_manager_openbsd.cc | 11 +- media/audio/openbsd/audio_manager_openbsd.h | 10 +- media/audio/simple_sources.cc | 2 +- media/audio/simple_sources.h | 2 +- media/audio/simple_sources_unittest.cc | 6 +- media/audio/win/audio_manager_win.cc | 94 ++++++++++++++ media/audio/win/audio_manager_win.h | 12 +- media/audio/win/audio_output_win.cc | 92 ------------- media/audio/win/audio_output_win_unittest.cc | 106 ++++++++------- media/audio/win/waveout_output_win.cc | 4 +- media/audio/win/waveout_output_win.h | 2 +- 27 files changed, 400 insertions(+), 394 deletions(-) create mode 100644 media/audio/audio_io.h delete mode 100644 media/audio/audio_output.h create mode 100644 media/audio/win/audio_manager_win.cc delete mode 100644 media/audio/win/audio_output_win.cc (limited to 'media/audio') diff --git a/media/audio/audio_io.h b/media/audio/audio_io.h new file mode 100644 index 0000000..990f7c1 --- /dev/null +++ b/media/audio/audio_io.h @@ -0,0 +1,164 @@ +// Copyright (c) 2010 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 MEDIA_AUDIO_AUDIO_IO_H_ +#define MEDIA_AUDIO_AUDIO_IO_H_ + +#include "base/basictypes.h" + +// Low-level audio output support. To make sound there are 3 objects involved: +// - AudioSource : produces audio samples on a pull model. Implements +// the AudioSourceCallback interface. +// - AudioOutputStream : uses the AudioSource to render audio on a given +// channel, format and sample frequency configuration. Data from the +// AudioSource is delivered in a 'pull' model. +// - AudioManager : factory for the AudioOutputStream objects, manager +// of the hardware resources and mixer control. +// +// The number and configuration of AudioOutputStream does not need to match the +// physically available hardware resources. For example you can have: +// +// MonoPCMSource1 --> MonoPCMStream1 --> | | --> audio left channel +// StereoPCMSource -> StereoPCMStream -> | mixer | +// MonoPCMSource2 --> MonoPCMStream2 --> | | --> audio right channel +// +// This facility's objective is mix and render audio with low overhead using +// the OS basic audio support, abstracting as much as possible the +// idiosyncrasies of each platform. Non-goals: +// - Positional, 3d audio +// - Dependence on non-default libraries such as DirectX 9, 10, XAudio +// - Digital signal processing or effects +// - Extra features if a specific hardware is installed (EAX, X-fi) +// +// The primary client of this facility is audio coming from several tabs. +// Specifically for this case we avoid supporting complex formats such as MP3 +// or WMA. Complex format decoding should be done by the renderers. + + +// Models an audio stream that gets rendered to the audio hardware output. +// Because we support more audio streams than physically available channels +// a given AudioOutputStream might or might not talk directly to hardware. +class AudioOutputStream { + public: + // Audio sources must implement AudioSourceCallback. This interface will be + // called in a random thread which very likely is a high priority thread. Do + // not rely on using this thread TLS or make calls that alter the thread + // itself such as creating Windows or initializing COM. + class AudioSourceCallback { + public: + virtual ~AudioSourceCallback() {} + + // Provide more data by filling |dest| up to |max_size| bytes. The provided + // buffer size is usually what is specified in Open(). The source + // will return the number of bytes it filled. The expected structure of + // |dest| is platform and format specific. + // |pending_bytes| is the number of bytes will be played before the + // requested data is played. + virtual uint32 OnMoreData(AudioOutputStream* stream, void* dest, + uint32 max_size, uint32 pending_bytes) = 0; + + // The stream is done with this callback. After this call the audio source + // can go away or be destroyed. + virtual void OnClose(AudioOutputStream* stream) = 0; + + // There was an error while playing a buffer. Audio source cannot be + // destroyed yet. No direct action needed by the AudioStream, but it is + // a good place to stop accumulating sound data since is is likely that + // playback will not continue. |code| is an error code that is platform + // specific. + virtual void OnError(AudioOutputStream* stream, int code) = 0; + }; + + // Open the stream. |packet_size| is the requested buffer allocation which + // the audio source thinks it can usually fill without blocking. Internally + // two or three buffers of |packet_size| size are created, one will be + // locked for playback and one will be ready to be filled in the call to + // AudioSourceCallback::OnMoreData(). + // The number of buffers is controlled by AUDIO_PCM_LOW_LATENCY. See more + // information below. + // + // TODO(ajwong): Streams are not reusable, so try to move packet_size into the + // constructor. + virtual bool Open(uint32 packet_size) = 0; + + // Starts playing audio and generating AudioSourceCallback::OnMoreData(). + // Since implementor of AudioOutputStream may have internal buffers, right + // after calling this method initial buffers are fetched. + // + // The output stream does not take ownership of this callback. + virtual void Start(AudioSourceCallback* callback) = 0; + + // Stops playing audio. Effect might not be instantaneous as the hardware + // might have locked audio data that is processing. + virtual void Stop() = 0; + + // Sets the relative volume, with range [0.0, 1.0] inclusive. + virtual void SetVolume(double volume) = 0; + + // Gets the relative volume, with range [0.0, 1.0] inclusive. + virtual void GetVolume(double* volume) = 0; + + // Close the stream. This also generates AudioSourceCallback::OnClose(). + // After calling this method, the object should not be used anymore. + virtual void Close() = 0; + + protected: + virtual ~AudioOutputStream() {} +}; + +// Manages all audio resources. In particular it owns the AudioOutputStream +// objects. Provides some convenience functions that avoid the need to provide +// iterators over the existing streams. +class AudioManager { + public: + enum Format { + AUDIO_PCM_LINEAR = 0, // PCM is 'raw' amplitude samples. + AUDIO_PCM_LOW_LATENCY, // Linear PCM, low latency requested. + AUDIO_MOCK, // Creates a dummy AudioOutputStream object. + AUDIO_LAST_FORMAT // Only used for validation of format. + }; + + // Telephone quality sample rate, mostly for speech-only audio. + static const uint32 kTelephoneSampleRate = 8000; + // CD sampling rate is 44.1 KHz or conveniently 2x2x3x3x5x5x7x7. + static const uint32 kAudioCDSampleRate = 44100; + // Digital Audio Tape sample rate. + static const uint32 kAudioDATSampleRate = 48000; + + // Returns true if the OS reports existence of audio devices. This does not + // guarantee that the existing devices support all formats and sample rates. + virtual bool HasAudioOutputDevices() = 0; + + // Factory for all the supported stream formats. The |channels| can be 1 to 5. + // The |sample_rate| is in hertz and can be any value supported by the + // platform. For some future formats the |sample_rate| and |bits_per_sample| + // can take special values. + // Returns NULL if the combination of the parameters is not supported, or if + // we have reached some other platform specific limit. + // + // AUDIO_PCM_LOW_LATENCY can be passed to this method and it has two effects: + // 1- Instead of triple buffered the audio will be double buffered. + // 2- A low latency driver or alternative audio subsystem will be used when + // available. + // + // Do not free the returned AudioOutputStream. It is owned by AudioManager. + virtual AudioOutputStream* MakeAudioOutputStream(Format format, int channels, + int sample_rate, + char bits_per_sample) = 0; + + // Muting continues playback but effectively the volume is set to zero. + // Un-muting returns the volume to the previous level. + virtual void MuteAll() = 0; + virtual void UnMuteAll() = 0; + + // Get AudioManager singleton. + // TODO(cpu): Define threading requirements for interacting with AudioManager. + static AudioManager* GetAudioManager(); + + protected: + virtual ~AudioManager() {} +}; + + +#endif // MEDIA_AUDIO_AUDIO_IO_H_ diff --git a/media/audio/audio_output.h b/media/audio/audio_output.h deleted file mode 100644 index 6b87a68..0000000 --- a/media/audio/audio_output.h +++ /dev/null @@ -1,164 +0,0 @@ -// Copyright (c) 2010 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 MEDIA_AUDIO_AUDIO_OUTPUT_H_ -#define MEDIA_AUDIO_AUDIO_OUTPUT_H_ - -#include "base/basictypes.h" - -// Low-level audio output support. To make sound there are 3 objects involved: -// - AudioSource : produces audio samples on a pull model. Implements -// the AudioSourceCallback interface. -// - AudioOutputStream : uses the AudioSource to render audio on a given -// channel, format and sample frequency configuration. Data from the -// AudioSource is delivered in a 'pull' model. -// - AudioManager : factory for the AudioOutputStream objects, manager -// of the hardware resources and mixer control. -// -// The number and configuration of AudioOutputStream does not need to match the -// physically available hardware resources. For example you can have: -// -// MonoPCMSource1 --> MonoPCMStream1 --> | | --> audio left channel -// StereoPCMSource -> StereoPCMStream -> | mixer | -// MonoPCMSource2 --> MonoPCMStream2 --> | | --> audio right channel -// -// This facility's objective is mix and render audio with low overhead using -// the OS basic audio support, abstracting as much as possible the -// idiosyncrasies of each platform. Non-goals: -// - Positional, 3d audio -// - Dependence on non-default libraries such as DirectX 9, 10, XAudio -// - Digital signal processing or effects -// - Extra features if a specific hardware is installed (EAX, X-fi) -// -// The primary client of this facility is audio coming from several tabs. -// Specifically for this case we avoid supporting complex formats such as MP3 -// or WMA. Complex format decoding should be done by the renderers. - - -// Models an audio stream that gets rendered to the audio hardware output. -// Because we support more audio streams than physically available channels -// a given AudioOutputStream might or might not talk directly to hardware. -class AudioOutputStream { - public: - // Audio sources must implement AudioSourceCallback. This interface will be - // called in a random thread which very likely is a high priority thread. Do - // not rely on using this thread TLS or make calls that alter the thread - // itself such as creating Windows or initializing COM. - class AudioSourceCallback { - public: - virtual ~AudioSourceCallback() {} - - // Provide more data by filling |dest| up to |max_size| bytes. The provided - // buffer size is usually what is specified in Open(). The source - // will return the number of bytes it filled. The expected structure of - // |dest| is platform and format specific. - // |pending_bytes| is the number of bytes will be played before the - // requested data is played. - virtual uint32 OnMoreData(AudioOutputStream* stream, void* dest, - uint32 max_size, uint32 pending_bytes) = 0; - - // The stream is done with this callback. After this call the audio source - // can go away or be destroyed. - virtual void OnClose(AudioOutputStream* stream) = 0; - - // There was an error while playing a buffer. Audio source cannot be - // destroyed yet. No direct action needed by the AudioStream, but it is - // a good place to stop accumulating sound data since is is likely that - // playback will not continue. |code| is an error code that is platform - // specific. - virtual void OnError(AudioOutputStream* stream, int code) = 0; - }; - - // Open the stream. |packet_size| is the requested buffer allocation which - // the audio source thinks it can usually fill without blocking. Internally - // two or three buffers of |packet_size| size are created, one will be - // locked for playback and one will be ready to be filled in the call to - // AudioSourceCallback::OnMoreData(). - // The number of buffers is controlled by AUDIO_PCM_LOW_LATENCY. See more - // information below. - // - // TODO(ajwong): Streams are not reusable, so try to move packet_size into the - // constructor. - virtual bool Open(uint32 packet_size) = 0; - - // Starts playing audio and generating AudioSourceCallback::OnMoreData(). - // Since implementor of AudioOutputStream may have internal buffers, right - // after calling this method initial buffers are fetched. - // - // The output stream does not take ownership of this callback. - virtual void Start(AudioSourceCallback* callback) = 0; - - // Stops playing audio. Effect might not be instantaneous as the hardware - // might have locked audio data that is processing. - virtual void Stop() = 0; - - // Sets the relative volume, with range [0.0, 1.0] inclusive. - virtual void SetVolume(double volume) = 0; - - // Gets the relative volume, with range [0.0, 1.0] inclusive. - virtual void GetVolume(double* volume) = 0; - - // Close the stream. This also generates AudioSourceCallback::OnClose(). - // After calling this method, the object should not be used anymore. - virtual void Close() = 0; - - protected: - virtual ~AudioOutputStream() {} -}; - -// Manages all audio resources. In particular it owns the AudioOutputStream -// objects. Provides some convenience functions that avoid the need to provide -// iterators over the existing streams. -class AudioManager { - public: - enum Format { - AUDIO_PCM_LINEAR = 0, // PCM is 'raw' amplitude samples. - AUDIO_PCM_LOW_LATENCY, // Linear PCM, low latency requested. - AUDIO_MOCK, // Creates a dummy AudioOutputStream object. - AUDIO_LAST_FORMAT // Only used for validation of format. - }; - - // Telephone quality sample rate, mostly for speech-only audio. - static const uint32 kTelephoneSampleRate = 8000; - // CD sampling rate is 44.1 KHz or conveniently 2x2x3x3x5x5x7x7. - static const uint32 kAudioCDSampleRate = 44100; - // Digital Audio Tape sample rate. - static const uint32 kAudioDATSampleRate = 48000; - - // Returns true if the OS reports existence of audio devices. This does not - // guarantee that the existing devices support all formats and sample rates. - virtual bool HasAudioDevices() = 0; - - // Factory for all the supported stream formats. The |channels| can be 1 to 5. - // The |sample_rate| is in hertz and can be any value supported by the - // platform. For some future formats the |sample_rate| and |bits_per_sample| - // can take special values. - // Returns NULL if the combination of the parameters is not supported, or if - // we have reached some other platform specific limit. - // - // AUDIO_PCM_LOW_LATENCY can be passed to this method and it has two effects: - // 1- Instead of triple buffered the audio will be double buffered. - // 2- A low latency driver or alternative audio subsystem will be used when - // available. - // - // Do not free the returned AudioOutputStream. It is owned by AudioManager. - virtual AudioOutputStream* MakeAudioStream(Format format, int channels, - int sample_rate, - char bits_per_sample) = 0; - - // Muting continues playback but effectively the volume is set to zero. - // Un-muting returns the volume to the previous level. - virtual void MuteAll() = 0; - virtual void UnMuteAll() = 0; - - // Get AudioManager singleton. - // TODO(cpu): Define threading requirements for interacting with AudioManager. - static AudioManager* GetAudioManager(); - - protected: - virtual ~AudioManager() {} -}; - - -#endif // MEDIA_AUDIO_AUDIO_OUTPUT_H_ diff --git a/media/audio/audio_output_controller.cc b/media/audio/audio_output_controller.cc index 62cf148..ffdfaa1 100644 --- a/media/audio/audio_output_controller.cc +++ b/media/audio/audio_output_controller.cc @@ -163,7 +163,7 @@ void AudioOutputController::DoCreate(AudioManager::Format format, int channels, DCHECK_EQ(kEmpty, state_); // Create the stream in the first place. - stream_ = AudioManager::GetAudioManager()->MakeAudioStream( + stream_ = AudioManager::GetAudioManager()->MakeAudioOutputStream( format, channels, sample_rate, bits_per_sample); if (!stream_) { diff --git a/media/audio/audio_output_controller.h b/media/audio/audio_output_controller.h index d1111da..10e3d03 100644 --- a/media/audio/audio_output_controller.h +++ b/media/audio/audio_output_controller.h @@ -10,7 +10,7 @@ #include "base/scoped_ptr.h" #include "base/thread.h" #include "base/time.h" -#include "media/audio/audio_output.h" +#include "media/audio/audio_io.h" #include "media/audio/simple_sources.h" // An AudioOutputController controls an AudioOutputStream and provides data diff --git a/media/audio/audio_output_controller_unittest.cc b/media/audio/audio_output_controller_unittest.cc index b3d4233..0783b09 100644 --- a/media/audio/audio_output_controller_unittest.cc +++ b/media/audio/audio_output_controller_unittest.cc @@ -55,10 +55,10 @@ class MockAudioOutputControllerSyncReader DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerSyncReader); }; -static bool HasAudioDevices() { +static bool HasAudioOutputDevices() { AudioManager* audio_man = AudioManager::GetAudioManager(); CHECK(audio_man); - return audio_man->HasAudioDevices(); + return audio_man->HasAudioOutputDevices(); } static bool IsRunningHeadless() { @@ -75,7 +75,7 @@ ACTION_P3(SignalEvent, event, count, limit) { } TEST(AudioOutputControllerTest, CreateAndClose) { - if (!HasAudioDevices() || IsRunningHeadless()) + if (!HasAudioOutputDevices() || IsRunningHeadless()) return; MockAudioOutputControllerEventHandler event_handler; @@ -95,7 +95,7 @@ TEST(AudioOutputControllerTest, CreateAndClose) { } TEST(AudioOutputControllerTest, PlayAndClose) { - if (!HasAudioDevices() || IsRunningHeadless()) + if (!HasAudioOutputDevices() || IsRunningHeadless()) return; MockAudioOutputControllerEventHandler event_handler; @@ -140,7 +140,7 @@ TEST(AudioOutputControllerTest, PlayAndClose) { } TEST(AudioOutputControllerTest, PlayPauseClose) { - if (!HasAudioDevices() || IsRunningHeadless()) + if (!HasAudioOutputDevices() || IsRunningHeadless()) return; MockAudioOutputControllerEventHandler event_handler; @@ -196,7 +196,7 @@ TEST(AudioOutputControllerTest, PlayPauseClose) { } TEST(AudioOutputControllerTest, HardwareBufferTooLarge) { - if (!HasAudioDevices() || IsRunningHeadless()) + if (!HasAudioOutputDevices() || IsRunningHeadless()) return; // Create an audio device with a very large hardware buffer size. @@ -214,7 +214,7 @@ TEST(AudioOutputControllerTest, HardwareBufferTooLarge) { } TEST(AudioOutputControllerTest, CloseTwice) { - if (!HasAudioDevices() || IsRunningHeadless()) + if (!HasAudioOutputDevices() || IsRunningHeadless()) return; MockAudioOutputControllerEventHandler event_handler; diff --git a/media/audio/fake_audio_output_stream.h b/media/audio/fake_audio_output_stream.h index 59afec7..000e5bf 100644 --- a/media/audio/fake_audio_output_stream.h +++ b/media/audio/fake_audio_output_stream.h @@ -12,7 +12,7 @@ #include #include "base/scoped_ptr.h" -#include "media/audio/audio_output.h" +#include "media/audio/audio_io.h" class FakeAudioOutputStream : public AudioOutputStream { public: diff --git a/media/audio/linux/alsa_output.cc b/media/audio/linux/alsa_output.cc index b4c4dd2..0440ecf 100644 --- a/media/audio/linux/alsa_output.cc +++ b/media/audio/linux/alsa_output.cc @@ -339,7 +339,7 @@ void AlsaPcmOutputStream::Close() { // Signal to the manager that we're closed and can be removed. Since // we just posted a CloseTask to the message loop, we won't be deleted // immediately, but it will happen soon afterwards. - manager()->ReleaseStream(this); + manager()->ReleaseOutputStream(this); } void AlsaPcmOutputStream::Start(AudioSourceCallback* callback) { diff --git a/media/audio/linux/alsa_output.h b/media/audio/linux/alsa_output.h index 5f54d3b..eaea5a2 100644 --- a/media/audio/linux/alsa_output.h +++ b/media/audio/linux/alsa_output.h @@ -36,7 +36,7 @@ #include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "base/thread.h" -#include "media/audio/audio_output.h" +#include "media/audio/audio_io.h" #include "testing/gtest/include/gtest/gtest_prod.h" namespace media { diff --git a/media/audio/linux/alsa_output_unittest.cc b/media/audio/linux/alsa_output_unittest.cc index 44a395b..8ae871ce4 100644 --- a/media/audio/linux/alsa_output_unittest.cc +++ b/media/audio/linux/alsa_output_unittest.cc @@ -70,14 +70,15 @@ class MockAudioSourceCallback : public AudioOutputStream::AudioSourceCallback { class MockAudioManagerLinux : public AudioManagerLinux { public: MOCK_METHOD0(Init, void()); - MOCK_METHOD0(HasAudioDevices, bool()); - MOCK_METHOD4(MakeAudioStream, AudioOutputStream*(Format format, int channels, - int sample_rate, - char bits_per_sample)); + MOCK_METHOD0(HasAudioOutputDevices, bool()); + MOCK_METHOD4(MakeAudioOutputStream, AudioOutputStream*(Format format, + int channels, + int sample_rate, + char bits_per_sample)); MOCK_METHOD0(MuteAll, void()); MOCK_METHOD0(UnMuteAll, void()); - MOCK_METHOD1(ReleaseStream, void(AlsaPcmOutputStream* stream)); + MOCK_METHOD1(ReleaseOutputStream, void(AlsaPcmOutputStream* stream)); }; class AlsaPcmOutputStreamTest : public testing::Test { @@ -249,7 +250,7 @@ TEST_F(AlsaPcmOutputStreamTest, LatencyFloor) { EXPECT_CALL(mock_alsa_wrapper_, PcmClose(kFakeHandle)).WillOnce(Return(0)); EXPECT_CALL(mock_alsa_wrapper_, PcmName(kFakeHandle)) .WillOnce(Return(kTestDeviceName)); - EXPECT_CALL(mock_manager_, ReleaseStream(test_stream_.get())); + EXPECT_CALL(mock_manager_, ReleaseOutputStream(test_stream_.get())); test_stream_->Close(); message_loop_.RunAllPending(); @@ -285,7 +286,7 @@ TEST_F(AlsaPcmOutputStreamTest, LatencyFloor) { .WillOnce(Return(0)); EXPECT_CALL(mock_alsa_wrapper_, PcmName(kFakeHandle)) .WillOnce(Return(kTestDeviceName)); - EXPECT_CALL(mock_manager_, ReleaseStream(test_stream_.get())); + EXPECT_CALL(mock_manager_, ReleaseOutputStream(test_stream_.get())); test_stream_->Close(); message_loop_.RunAllPending(); @@ -336,7 +337,7 @@ TEST_F(AlsaPcmOutputStreamTest, OpenClose) { .WillOnce(Return(0)); EXPECT_CALL(mock_alsa_wrapper_, PcmName(kFakeHandle)) .WillOnce(Return(kTestDeviceName)); - EXPECT_CALL(mock_manager_, ReleaseStream(test_stream_.get())); + EXPECT_CALL(mock_manager_, ReleaseOutputStream(test_stream_.get())); test_stream_->Close(); message_loop_.RunAllPending(); @@ -366,7 +367,7 @@ TEST_F(AlsaPcmOutputStreamTest, PcmOpenFailed) { EXPECT_FALSE(test_stream_->buffer_.get()); // Close the stream since we opened it to make destruction happy. - EXPECT_CALL(mock_manager_, ReleaseStream(test_stream_.get())); + EXPECT_CALL(mock_manager_, ReleaseOutputStream(test_stream_.get())); test_stream_->Close(); message_loop_.RunAllPending(); } @@ -400,7 +401,7 @@ TEST_F(AlsaPcmOutputStreamTest, PcmSetParamsFailed) { EXPECT_FALSE(test_stream_->buffer_.get()); // Close the stream since we opened it to make destruction happy. - EXPECT_CALL(mock_manager_, ReleaseStream(test_stream_.get())); + EXPECT_CALL(mock_manager_, ReleaseOutputStream(test_stream_.get())); test_stream_->Close(); message_loop_.RunAllPending(); } @@ -457,7 +458,7 @@ TEST_F(AlsaPcmOutputStreamTest, StartStop) { test_stream_->Start(&mock_callback); message_loop_.RunAllPending(); - EXPECT_CALL(mock_manager_, ReleaseStream(test_stream_.get())); + EXPECT_CALL(mock_manager_, ReleaseOutputStream(test_stream_.get())); EXPECT_CALL(mock_callback, OnClose(test_stream_.get())); EXPECT_CALL(mock_alsa_wrapper_, PcmClose(kFakeHandle)) .WillOnce(Return(0)); diff --git a/media/audio/linux/audio_manager_linux.cc b/media/audio/linux/audio_manager_linux.cc index 9fa4799..c3cf942 100644 --- a/media/audio/linux/audio_manager_linux.cc +++ b/media/audio/linux/audio_manager_linux.cc @@ -19,15 +19,16 @@ AudioManagerLinux* g_audio_manager = NULL; } // namespace // Implementation of AudioManager. -bool AudioManagerLinux::HasAudioDevices() { +bool AudioManagerLinux::HasAudioOutputDevices() { // TODO(ajwong): Make this actually query audio devices. return true; } -AudioOutputStream* AudioManagerLinux::MakeAudioStream(Format format, - int channels, - int sample_rate, - char bits_per_sample) { +AudioOutputStream* AudioManagerLinux::MakeAudioOutputStream( + Format format, + int channels, + int sample_rate, + char bits_per_sample) { // Early return for testing hook. Do this before checking for // |initialized_|. if (format == AudioManager::AUDIO_MOCK) { @@ -81,7 +82,7 @@ void AudioManagerLinux::UnMuteAll() { NOTIMPLEMENTED(); } -void AudioManagerLinux::ReleaseStream(AlsaPcmOutputStream* stream) { +void AudioManagerLinux::ReleaseOutputStream(AlsaPcmOutputStream* stream) { if (stream) { AutoLock l(lock_); active_streams_.erase(stream); diff --git a/media/audio/linux/audio_manager_linux.h b/media/audio/linux/audio_manager_linux.h index 32f09a8..d9229585 100644 --- a/media/audio/linux/audio_manager_linux.h +++ b/media/audio/linux/audio_manager_linux.h @@ -11,7 +11,7 @@ #include "base/ref_counted.h" #include "base/scoped_ptr.h" #include "base/thread.h" -#include "media/audio/audio_output.h" +#include "media/audio/audio_io.h" class AlsaPcmOutputStream; class AlsaWrapper; @@ -24,14 +24,14 @@ class AudioManagerLinux : public AudioManager { virtual void Init(); // Implementation of AudioManager. - virtual bool HasAudioDevices(); - virtual AudioOutputStream* MakeAudioStream(Format format, int channels, - int sample_rate, - char bits_per_sample); + virtual bool HasAudioOutputDevices(); + virtual AudioOutputStream* MakeAudioOutputStream(Format format, int channels, + int sample_rate, + char bits_per_sample); virtual void MuteAll(); virtual void UnMuteAll(); - virtual void ReleaseStream(AlsaPcmOutputStream* stream); + virtual void ReleaseOutputStream(AlsaPcmOutputStream* stream); protected: // Friend function for invoking the destructor at exit. diff --git a/media/audio/mac/audio_manager_mac.cc b/media/audio/mac/audio_manager_mac.cc index ee5943a..2cc5b39 100644 --- a/media/audio/mac/audio_manager_mac.cc +++ b/media/audio/mac/audio_manager_mac.cc @@ -9,7 +9,7 @@ #include "media/audio/mac/audio_manager_mac.h" #include "media/audio/mac/audio_output_mac.h" -bool AudioManagerMac::HasAudioDevices() { +bool AudioManagerMac::HasAudioOutputDevices() { AudioDeviceID output_device_id = kAudioObjectUnknown; AudioObjectPropertyAddress property_address = { kAudioHardwarePropertyDefaultOutputDevice, // mSelector @@ -27,9 +27,11 @@ bool AudioManagerMac::HasAudioDevices() { output_device_id != kAudioObjectUnknown; } -AudioOutputStream* AudioManagerMac::MakeAudioStream(Format format, int channels, - int sample_rate, - char bits_per_sample) { +AudioOutputStream* AudioManagerMac::MakeAudioOutputStream( + Format format, + int channels, + int sample_rate, + char bits_per_sample) { if (format == AUDIO_MOCK) return FakeAudioOutputStream::MakeFakeStream(); else if (format != AUDIO_PCM_LINEAR) @@ -47,7 +49,8 @@ void AudioManagerMac::UnMuteAll() { } // Called by the stream when it has been released by calling Close(). -void AudioManagerMac::ReleaseStream(PCMQueueOutAudioOutputStream* stream) { +void AudioManagerMac::ReleaseOutputStream( + PCMQueueOutAudioOutputStream* stream) { delete stream; } diff --git a/media/audio/mac/audio_manager_mac.h b/media/audio/mac/audio_manager_mac.h index 51ee58a..492481d 100644 --- a/media/audio/mac/audio_manager_mac.h +++ b/media/audio/mac/audio_manager_mac.h @@ -6,7 +6,7 @@ #define MEDIA_AUDIO_MAC_AUDIO_MANAGER_MAC_H_ #include "base/basictypes.h" -#include "media/audio/audio_output.h" +#include "media/audio/audio_io.h" class PCMQueueOutAudioOutputStream; @@ -18,16 +18,16 @@ class AudioManagerMac : public AudioManager { AudioManagerMac() {}; // Implementation of AudioManager. - virtual bool HasAudioDevices(); - virtual AudioOutputStream* MakeAudioStream(Format format, int channels, - int sample_rate, - char bits_per_sample); + virtual bool HasAudioOutputDevices(); + virtual AudioOutputStream* MakeAudioOutputStream(Format format, int channels, + int sample_rate, + char bits_per_sample); virtual void MuteAll(); virtual void UnMuteAll(); // Mac-only method to free a stream created in MakeAudioStream. // It is called internally by the audio stream when it has been closed. - void ReleaseStream(PCMQueueOutAudioOutputStream* stream); + void ReleaseOutputStream(PCMQueueOutAudioOutputStream* stream); private: friend void DestroyAudioManagerMac(void*); diff --git a/media/audio/mac/audio_output_mac.cc b/media/audio/mac/audio_output_mac.cc index 57c76cb..cd7c8eba 100644 --- a/media/audio/mac/audio_output_mac.cc +++ b/media/audio/mac/audio_output_mac.cc @@ -143,7 +143,7 @@ void PCMQueueOutAudioOutputStream::Close() { } // Inform the audio manager that we have been closed. This can cause our // destruction. - manager_->ReleaseStream(this); + manager_->ReleaseOutputStream(this); } void PCMQueueOutAudioOutputStream::Stop() { diff --git a/media/audio/mac/audio_output_mac.h b/media/audio/mac/audio_output_mac.h index 0f58cae..7e86107 100644 --- a/media/audio/mac/audio_output_mac.h +++ b/media/audio/mac/audio_output_mac.h @@ -8,7 +8,7 @@ #include #include -#include "media/audio/audio_output.h" +#include "media/audio/audio_io.h" #include "base/basictypes.h" diff --git a/media/audio/mac/audio_output_mac_unittest.cc b/media/audio/mac/audio_output_mac_unittest.cc index ee589f5..d48e47f 100644 --- a/media/audio/mac/audio_output_mac_unittest.cc +++ b/media/audio/mac/audio_output_mac_unittest.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. #include "base/basictypes.h" -#include "media/audio/audio_output.h" +#include "media/audio/audio_io.h" #include "media/audio/simple_sources.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -51,10 +51,11 @@ TEST(MacAudioTest, SineWaveAudio16MonoTest) { TEST(MacAudioTest, PCMWaveStreamGetAndClose) { AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); - if (!audio_man->HasAudioDevices()) + if (!audio_man->HasAudioOutputDevices()) return; AudioOutputStream* oas = - audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 2, 8000, 16); + audio_man->MakeAudioOutputStream(AudioManager::AUDIO_PCM_LINEAR, 2, + 8000, 16); ASSERT_TRUE(NULL != oas); oas->Close(); } @@ -63,10 +64,11 @@ TEST(MacAudioTest, PCMWaveStreamGetAndClose) { TEST(MacAudioTest, PCMWaveStreamOpenAndClose) { AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); - if (!audio_man->HasAudioDevices()) + if (!audio_man->HasAudioOutputDevices()) return; AudioOutputStream* oas = - audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 2, 8000, 16); + audio_man->MakeAudioOutputStream(AudioManager::AUDIO_PCM_LINEAR, 2, + 8000, 16); ASSERT_TRUE(NULL != oas); EXPECT_TRUE(oas->Open(1024)); oas->Close(); @@ -79,10 +81,10 @@ TEST(MacAudioTest, PCMWaveStreamOpenAndClose) { TEST(MacAudioTest, PCMWaveStreamPlay200HzTone44KssMono) { AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); - if (!audio_man->HasAudioDevices()) + if (!audio_man->HasAudioOutputDevices()) return; AudioOutputStream* oas = - audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, + audio_man->MakeAudioOutputStream(AudioManager::AUDIO_PCM_LINEAR, 1, AudioManager::kAudioCDSampleRate, 16); ASSERT_TRUE(NULL != oas); @@ -112,10 +114,10 @@ TEST(MacAudioTest, PCMWaveStreamPlay200HzTone44KssMono) { TEST(MacAudioTest, PCMWaveStreamPlay200HzTone22KssMono) { AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); - if (!audio_man->HasAudioDevices()) + if (!audio_man->HasAudioOutputDevices()) return; AudioOutputStream* oas = - audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, + audio_man->MakeAudioOutputStream(AudioManager::AUDIO_PCM_LINEAR, 1, AudioManager::kAudioCDSampleRate/2, 16); ASSERT_TRUE(NULL != oas); @@ -139,10 +141,10 @@ static void ClearBuffer(AudioOutputStream* strea, void* dest, TEST(MacAudioTest, PCMWaveStreamPendingBytes) { AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); - if (!audio_man->HasAudioDevices()) + if (!audio_man->HasAudioOutputDevices()) return; AudioOutputStream* oas = - audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, + audio_man->MakeAudioOutputStream(AudioManager::AUDIO_PCM_LINEAR, 1, AudioManager::kAudioCDSampleRate, 16); ASSERT_TRUE(NULL != oas); diff --git a/media/audio/openbsd/audio_manager_openbsd.cc b/media/audio/openbsd/audio_manager_openbsd.cc index 41dc93bb..641b181 100644 --- a/media/audio/openbsd/audio_manager_openbsd.cc +++ b/media/audio/openbsd/audio_manager_openbsd.cc @@ -12,15 +12,16 @@ AudioManagerOpenBSD* g_audio_manager = NULL; } // namespace // Implementation of AudioManager. -bool AudioManagerOpenBSD::HasAudioDevices() { +bool AudioManagerOpenBSD::HasAudioOutputDevices() { NOTIMPLEMENTED(); return false; } -AudioOutputStream* AudioManagerOpenBSD::MakeAudioStream(Format format, - int channels, - int sample_rate, - char bits_per_sample) { +AudioOutputStream* AudioManagerOpenBSD::MakeAudioOutputStream( + Format format, + int channels, + int sample_rate, + char bits_per_sample) { NOTIMPLEMENTED(); return NULL; } diff --git a/media/audio/openbsd/audio_manager_openbsd.h b/media/audio/openbsd/audio_manager_openbsd.h index 1766a77d..ffa352d 100644 --- a/media/audio/openbsd/audio_manager_openbsd.h +++ b/media/audio/openbsd/audio_manager_openbsd.h @@ -5,7 +5,7 @@ #ifndef MEDIA_AUDIO_OPENBSD_AUDIO_MANAGER_OPENBSD_H_ #define MEDIA_AUDIO_OPENBSD_AUDIO_MANAGER_OPENBSD_H_ -#include "media/audio/audio_output.h" +#include "media/audio/audio_io.h" class AudioManagerOpenBSD : public AudioManager { public: @@ -15,10 +15,10 @@ class AudioManagerOpenBSD : public AudioManager { virtual void Init(); // Implementation of AudioManager. - virtual bool HasAudioDevices(); - virtual AudioOutputStream* MakeAudioStream(Format format, int channels, - int sample_rate, - char bits_per_sample); + virtual bool HasAudioOutputDevices(); + virtual AudioOutputStream* MakeAudioOutputStream(Format format, int channels, + int sample_rate, + char bits_per_sample); virtual void MuteAll(); virtual void UnMuteAll(); diff --git a/media/audio/simple_sources.cc b/media/audio/simple_sources.cc index d1669daa..70d67b5 100644 --- a/media/audio/simple_sources.cc +++ b/media/audio/simple_sources.cc @@ -10,7 +10,7 @@ #include "base/basictypes.h" #include "base/logging.h" #include "base/ref_counted.h" -#include "media/audio/audio_output.h" +#include "media/audio/audio_io.h" #include "media/base/data_buffer.h" ////////////////////////////////////////////////////////////////////////////// diff --git a/media/audio/simple_sources.h b/media/audio/simple_sources.h index 5c7765c..d94c2ed 100644 --- a/media/audio/simple_sources.h +++ b/media/audio/simple_sources.h @@ -8,7 +8,7 @@ #include #include "base/lock.h" -#include "media/audio/audio_output.h" +#include "media/audio/audio_io.h" #include "media/base/seekable_buffer.h" // An audio source that produces a pure sinusoidal tone. diff --git a/media/audio/simple_sources_unittest.cc b/media/audio/simple_sources_unittest.cc index 118ec6f..7ddc23f 100644 --- a/media/audio/simple_sources_unittest.cc +++ b/media/audio/simple_sources_unittest.cc @@ -76,9 +76,9 @@ TEST(SimpleSources, SineWaveAudio16MonoTest) { AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); AudioOutputStream* oas = - audio_man->MakeAudioStream(AudioManager::AUDIO_MOCK, 1, - AudioManager::kTelephoneSampleRate, - bytes_per_sample * 2); + audio_man->MakeAudioOutputStream(AudioManager::AUDIO_MOCK, 1, + AudioManager::kTelephoneSampleRate, + bytes_per_sample * 2); ASSERT_TRUE(NULL != oas); EXPECT_TRUE(oas->Open(samples * bytes_per_sample)); diff --git a/media/audio/win/audio_manager_win.cc b/media/audio/win/audio_manager_win.cc new file mode 100644 index 0000000..81a59f5 --- /dev/null +++ b/media/audio/win/audio_manager_win.cc @@ -0,0 +1,94 @@ +// 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_io.h" + +#include +#include + +#include "base/at_exit.h" +#include "base/basictypes.h" +#include "media/audio/fake_audio_output_stream.h" +#include "media/audio/win/audio_manager_win.h" +#include "media/audio/win/waveout_output_win.h" + +namespace { + +// The next 3 constants are some sensible limits to prevent integer overflow +// at this layer. +// Up to 6 channels can be passed to the driver. +// This should work, given the right drivers, but graceful error handling is +// needed. +// In theory 7.1 could also be supported, but it has not been tested. +// The 192 Khz constant is the frequency of quicktime lossless audio codec. +// MP4 is limited to 96 Khz, and mp3 is limited to 48 Khz. +// OGG vorbis was initially limited to 96 Khz, but recent tools are unlimited. +// 192 Khz is also the limit on most PC audio hardware. The minimum is 100 Hz. +// Humans range is 20 to 20000 Hz. Below 20 can be felt (woofer). + +const int kMaxChannels = 6; +const int kMaxSampleRate = 192000; +const int kMaxBitsPerSample = 64; + +AudioManagerWin* g_audio_manager = NULL; + +} // namespace. + +bool AudioManagerWin::HasAudioOutputDevices() { + return (::waveOutGetNumDevs() != 0); +} + +// Factory for the implementations of AudioOutputStream. Two implementations +// should suffice most windows user's needs. +// - PCMWaveOutAudioOutputStream: Based on the waveOutWrite API (in progress) +// - PCMDXSoundAudioOutputStream: Based on DirectSound or XAudio (future work). +AudioOutputStream* AudioManagerWin::MakeAudioOutputStream( + Format format, + int channels, + int sample_rate, + char bits_per_sample) { + if ((channels > kMaxChannels) || (channels <= 0) || + (sample_rate > kMaxSampleRate) || (sample_rate <= 0) || + (bits_per_sample > kMaxBitsPerSample) || (bits_per_sample <= 0)) + return NULL; + + if (format == AUDIO_MOCK) { + return FakeAudioOutputStream::MakeFakeStream(); + } else if (format == AUDIO_PCM_LINEAR) { + return new PCMWaveOutAudioOutputStream(this, channels, sample_rate, 3, + bits_per_sample, WAVE_MAPPER); + } else if (format == AUDIO_PCM_LOW_LATENCY) { + // TODO(cpu): waveout cannot hit 20ms latency. Use other method. + return new PCMWaveOutAudioOutputStream(this, channels, sample_rate, 2, + bits_per_sample, WAVE_MAPPER); + } + return NULL; +} + +void AudioManagerWin::ReleaseOutputStream(PCMWaveOutAudioOutputStream* stream) { + if (stream) + delete stream; +} + +void AudioManagerWin::MuteAll() { +} + +void AudioManagerWin::UnMuteAll() { +} + +AudioManagerWin::~AudioManagerWin() { +} + +void DestroyAudioManagerWin(void* param) { + delete g_audio_manager; + g_audio_manager = NULL; +} + +AudioManager* AudioManager::GetAudioManager() { + if (!g_audio_manager) { + g_audio_manager = new AudioManagerWin(); + base::AtExitManager::RegisterCallback(&DestroyAudioManagerWin, NULL); + } + return g_audio_manager; +} diff --git a/media/audio/win/audio_manager_win.h b/media/audio/win/audio_manager_win.h index f060fc4..df6ab10 100644 --- a/media/audio/win/audio_manager_win.h +++ b/media/audio/win/audio_manager_win.h @@ -8,7 +8,7 @@ #include #include "base/basictypes.h" -#include "media/audio/audio_output.h" +#include "media/audio/audio_io.h" class PCMWaveOutAudioOutputStream; @@ -19,16 +19,16 @@ class AudioManagerWin : public AudioManager { public: AudioManagerWin() {} // Implementation of AudioManager. - virtual bool HasAudioDevices(); - virtual AudioOutputStream* MakeAudioStream(Format format, int channels, - int sample_rate, - char bits_per_sample); + virtual bool HasAudioOutputDevices(); + virtual AudioOutputStream* MakeAudioOutputStream(Format format, int channels, + int sample_rate, + char bits_per_sample); virtual void MuteAll(); virtual void UnMuteAll(); // Windows-only methods to free a stream created in MakeAudioStream. These // are called internally by the audio stream when it has been closed. - void ReleaseStream(PCMWaveOutAudioOutputStream* stream); + void ReleaseOutputStream(PCMWaveOutAudioOutputStream* stream); private: friend void DestroyAudioManagerWin(void *); diff --git a/media/audio/win/audio_output_win.cc b/media/audio/win/audio_output_win.cc deleted file mode 100644 index ebfd915..0000000 --- a/media/audio/win/audio_output_win.cc +++ /dev/null @@ -1,92 +0,0 @@ -// 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 -#include - -#include "base/at_exit.h" -#include "base/basictypes.h" -#include "media/audio/fake_audio_output_stream.h" -#include "media/audio/win/audio_manager_win.h" -#include "media/audio/win/waveout_output_win.h" - -namespace { - -// The next 3 constants are some sensible limits to prevent integer overflow -// at this layer. -// Up to 6 channels can be passed to the driver. -// This should work, given the right drivers, but graceful error handling is -// needed. -// In theory 7.1 could also be supported, but it has not been tested. -// The 192 Khz constant is the frequency of quicktime lossless audio codec. -// MP4 is limited to 96 Khz, and mp3 is limited to 48 Khz. -// OGG vorbis was initially limited to 96 Khz, but recent tools are unlimited. -// 192 Khz is also the limit on most PC audio hardware. The minimum is 100 Hz. -// Humans range is 20 to 20000 Hz. Below 20 can be felt (woofer). - -const int kMaxChannels = 6; -const int kMaxSampleRate = 192000; -const int kMaxBitsPerSample = 64; - -AudioManagerWin* g_audio_manager = NULL; - -} // namespace. - -bool AudioManagerWin::HasAudioDevices() { - return (::waveOutGetNumDevs() != 0); -} - -// Factory for the implementations of AudioOutputStream. Two implementations -// should suffice most windows user's needs. -// - PCMWaveOutAudioOutputStream: Based on the waveOutWrite API (in progress) -// - PCMDXSoundAudioOutputStream: Based on DirectSound or XAudio (future work). -AudioOutputStream* AudioManagerWin::MakeAudioStream(Format format, int channels, - int sample_rate, - char bits_per_sample) { - if ((channels > kMaxChannels) || (channels <= 0) || - (sample_rate > kMaxSampleRate) || (sample_rate <= 0) || - (bits_per_sample > kMaxBitsPerSample) || (bits_per_sample <= 0)) - return NULL; - - if (format == AUDIO_MOCK) { - return FakeAudioOutputStream::MakeFakeStream(); - } else if (format == AUDIO_PCM_LINEAR) { - return new PCMWaveOutAudioOutputStream(this, channels, sample_rate, 3, - bits_per_sample, WAVE_MAPPER); - } else if (format == AUDIO_PCM_LOW_LATENCY) { - // TODO(cpu): waveout cannot hit 20ms latency. Use other method. - return new PCMWaveOutAudioOutputStream(this, channels, sample_rate, 2, - bits_per_sample, WAVE_MAPPER); - } - return NULL; -} - -void AudioManagerWin::ReleaseStream(PCMWaveOutAudioOutputStream* stream) { - if (stream) - delete stream; -} - -void AudioManagerWin::MuteAll() { -} - -void AudioManagerWin::UnMuteAll() { -} - -AudioManagerWin::~AudioManagerWin() { -} - -void DestroyAudioManagerWin(void* param) { - delete g_audio_manager; - g_audio_manager = NULL; -} - -AudioManager* AudioManager::GetAudioManager() { - if (!g_audio_manager) { - g_audio_manager = new AudioManagerWin(); - base::AtExitManager::RegisterCallback(&DestroyAudioManagerWin, NULL); - } - return g_audio_manager; -} diff --git a/media/audio/win/audio_output_win_unittest.cc b/media/audio/win/audio_output_win_unittest.cc index 6a06274..bb90e75 100644 --- a/media/audio/win/audio_output_win_unittest.cc +++ b/media/audio/win/audio_output_win_unittest.cc @@ -10,7 +10,7 @@ #include "base/file_util.h" #include "base/path_service.h" #include "base/sync_socket.h" -#include "media/audio/audio_output.h" +#include "media/audio/audio_io.h" #include "media/audio/simple_sources.h" #include "testing/gmock/include/gmock/gmock.h" #include "testing/gtest/include/gtest/gtest.h" @@ -206,7 +206,7 @@ TEST(WinAudioTest, MockStreamBasicCallbacks) { AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); AudioOutputStream* oas = - audio_man->MakeAudioStream(AudioManager::AUDIO_MOCK, 2, 8000, 8); + audio_man->MakeAudioOutputStream(AudioManager::AUDIO_MOCK, 2, 8000, 8); ASSERT_TRUE(NULL != oas); EXPECT_TRUE(oas->Open(256)); TestSourceBasic source; @@ -232,10 +232,10 @@ TEST(WinAudioTest, PCMWaveStreamGetAndClose) { return; AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); - if (!audio_man->HasAudioDevices()) + if (!audio_man->HasAudioOutputDevices()) return; - AudioOutputStream* oas = - audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 2, 8000, 16); + AudioOutputStream* oas = audio_man->MakeAudioOutputStream( + AudioManager::AUDIO_PCM_LINEAR, 2, 8000, 16); ASSERT_TRUE(NULL != oas); oas->Close(); } @@ -246,15 +246,16 @@ TEST(WinAudioTest, SanityOnMakeParams) { return; AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); - if (!audio_man->HasAudioDevices()) + if (!audio_man->HasAudioOutputDevices()) return; AudioManager::Format fmt = AudioManager::AUDIO_PCM_LINEAR; - EXPECT_TRUE(NULL == audio_man->MakeAudioStream(fmt, 8, 8000, 16)); - EXPECT_TRUE(NULL == audio_man->MakeAudioStream(fmt, 1, 1024 * 1024, 16)); - EXPECT_TRUE(NULL == audio_man->MakeAudioStream(fmt, 2, 8000, 80)); - EXPECT_TRUE(NULL == audio_man->MakeAudioStream(fmt, -2, 8000, 16)); - EXPECT_TRUE(NULL == audio_man->MakeAudioStream(fmt, 2, -8000, 16)); - EXPECT_TRUE(NULL == audio_man->MakeAudioStream(fmt, 2, -8000, -16)); + EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream(fmt, 8, 8000, 16)); + EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream(fmt, 1, 1024 * 1024, + 16)); + EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream(fmt, 2, 8000, 80)); + EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream(fmt, -2, 8000, 16)); + EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream(fmt, 2, -8000, 16)); + EXPECT_TRUE(NULL == audio_man->MakeAudioOutputStream(fmt, 2, -8000, -16)); } // Test that it can be opened and closed. @@ -263,10 +264,10 @@ TEST(WinAudioTest, PCMWaveStreamOpenAndClose) { return; AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); - if (!audio_man->HasAudioDevices()) + if (!audio_man->HasAudioOutputDevices()) return; - AudioOutputStream* oas = - audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 2, 8000, 16); + AudioOutputStream* oas = audio_man->MakeAudioOutputStream( + AudioManager::AUDIO_PCM_LINEAR, 2, 8000, 16); ASSERT_TRUE(NULL != oas); EXPECT_TRUE(oas->Open(1024)); oas->Close(); @@ -278,10 +279,10 @@ TEST(WinAudioTest, PCMWaveStreamOpenLimit) { return; AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); - if (!audio_man->HasAudioDevices()) + if (!audio_man->HasAudioOutputDevices()) return; - AudioOutputStream* oas = - audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 2, 8000, 16); + AudioOutputStream* oas = audio_man->MakeAudioOutputStream( + AudioManager::AUDIO_PCM_LINEAR, 2, 8000, 16); ASSERT_TRUE(NULL != oas); EXPECT_FALSE(oas->Open(1024 * 1024 * 1024)); oas->Close(); @@ -294,10 +295,10 @@ TEST(WinAudioTest, PCMWaveStreamTripleBuffer) { return; AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); - if (!audio_man->HasAudioDevices()) + if (!audio_man->HasAudioOutputDevices()) return; - AudioOutputStream* oas = - audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, 16000, 16); + AudioOutputStream* oas = audio_man->MakeAudioOutputStream( + AudioManager::AUDIO_PCM_LINEAR, 1, 16000, 16); ASSERT_TRUE(NULL != oas); TestSourceTripleBuffer test_triple_buffer; EXPECT_TRUE(oas->Open(512)); @@ -318,10 +319,10 @@ TEST(WinAudioTest, PCMWaveSlowSource) { return; AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); - if (!audio_man->HasAudioDevices()) + if (!audio_man->HasAudioOutputDevices()) return; - AudioOutputStream* oas = - audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, 16000, 16); + AudioOutputStream* oas = audio_man->MakeAudioOutputStream( + AudioManager::AUDIO_PCM_LINEAR, 1, 16000, 16); ASSERT_TRUE(NULL != oas); TestSourceLaggy test_laggy(2, 90); EXPECT_TRUE(oas->Open(512)); @@ -344,11 +345,10 @@ TEST(WinAudioTest, PCMWaveStreamPlaySlowLoop) { return; AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); - if (!audio_man->HasAudioDevices()) + if (!audio_man->HasAudioOutputDevices()) return; - AudioOutputStream* oas = - audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, - AudioManager::kAudioCDSampleRate, 16); + AudioOutputStream* oas = audio_man->MakeAudioOutputStream( + AudioManager::AUDIO_PCM_LINEAR, 1, AudioManager::kAudioCDSampleRate, 16); ASSERT_TRUE(NULL != oas); SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, @@ -375,11 +375,10 @@ TEST(WinAudioTest, PCMWaveStreamPlay200HzTone44Kss) { return; AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); - if (!audio_man->HasAudioDevices()) + if (!audio_man->HasAudioOutputDevices()) return; - AudioOutputStream* oas = - audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, - AudioManager::kAudioCDSampleRate, 16); + AudioOutputStream* oas = audio_man->MakeAudioOutputStream( + AudioManager::AUDIO_PCM_LINEAR, 1, AudioManager::kAudioCDSampleRate, 16); ASSERT_TRUE(NULL != oas); SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, @@ -403,11 +402,11 @@ TEST(WinAudioTest, PCMWaveStreamPlay200HzTone22Kss) { return; AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); - if (!audio_man->HasAudioDevices()) + if (!audio_man->HasAudioOutputDevices()) return; - AudioOutputStream* oas = - audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, - AudioManager::kAudioCDSampleRate/2, 16); + AudioOutputStream* oas = audio_man->MakeAudioOutputStream( + AudioManager::AUDIO_PCM_LINEAR, 1, AudioManager::kAudioCDSampleRate/2, + 16); ASSERT_TRUE(NULL != oas); SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, @@ -449,10 +448,10 @@ TEST(WinAudioTest, PushSourceFile16KHz) { AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); - if (!audio_man->HasAudioDevices()) + if (!audio_man->HasAudioOutputDevices()) return; - AudioOutputStream* oas = - audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, 16000, 16); + AudioOutputStream* oas = audio_man->MakeAudioOutputStream( + AudioManager::AUDIO_PCM_LINEAR, 1, 16000, 16); ASSERT_TRUE(NULL != oas); // compute buffer size for 100ms of audio. Which is 3200 bytes. @@ -493,11 +492,10 @@ TEST(WinAudioTest, PCMWaveStreamPlayTwice200HzTone44Kss) { return; AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); - if (!audio_man->HasAudioDevices()) + if (!audio_man->HasAudioOutputDevices()) return; - AudioOutputStream* oas = - audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, - AudioManager::kAudioCDSampleRate, 16); + AudioOutputStream* oas = audio_man->MakeAudioOutputStream( + AudioManager::AUDIO_PCM_LINEAR, 1, AudioManager::kAudioCDSampleRate, 16); ASSERT_TRUE(NULL != oas); SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, @@ -532,11 +530,11 @@ TEST(WinAudioTest, PCMWaveStreamPlay200HzTone44KssLowLatency) { return; AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); - if (!audio_man->HasAudioDevices()) + if (!audio_man->HasAudioOutputDevices()) return; - AudioOutputStream* oas = - audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LOW_LATENCY, 1, - AudioManager::kAudioCDSampleRate, 16); + AudioOutputStream* oas = audio_man->MakeAudioOutputStream( + AudioManager::AUDIO_PCM_LOW_LATENCY, 1, AudioManager::kAudioCDSampleRate, + 16); ASSERT_TRUE(NULL != oas); SineWaveAudioSource source(SineWaveAudioSource::FORMAT_16BIT_LINEAR_PCM, 1, @@ -559,11 +557,10 @@ TEST(WinAudioTest, PCMWaveStreamPendingBytes) { return; AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); - if (!audio_man->HasAudioDevices()) + if (!audio_man->HasAudioOutputDevices()) return; - AudioOutputStream* oas = - audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LINEAR, 1, - AudioManager::kAudioCDSampleRate, 16); + AudioOutputStream* oas = audio_man->MakeAudioOutputStream( + AudioManager::AUDIO_PCM_LINEAR, 1, AudioManager::kAudioCDSampleRate, 16); ASSERT_TRUE(NULL != oas); NiceMock source; @@ -678,13 +675,12 @@ TEST(WinAudioTest, SyncSocketBasic) { AudioManager* audio_man = AudioManager::GetAudioManager(); ASSERT_TRUE(NULL != audio_man); - if (!audio_man->HasAudioDevices()) + if (!audio_man->HasAudioOutputDevices()) return; int sample_rate = AudioManager::kAudioCDSampleRate; - AudioOutputStream* oas = - audio_man->MakeAudioStream(AudioManager::AUDIO_PCM_LOW_LATENCY, 1, - sample_rate, 16); + AudioOutputStream* oas = audio_man->MakeAudioOutputStream( + AudioManager::AUDIO_PCM_LOW_LATENCY, 1, sample_rate, 16); ASSERT_TRUE(NULL != oas); // compute buffer size for 20ms of audio, 882 samples (mono). diff --git a/media/audio/win/waveout_output_win.cc b/media/audio/win/waveout_output_win.cc index 59f4c1c..cbd0ddc 100644 --- a/media/audio/win/waveout_output_win.cc +++ b/media/audio/win/waveout_output_win.cc @@ -10,7 +10,7 @@ #include "base/basictypes.h" #include "base/logging.h" -#include "media/audio/audio_output.h" +#include "media/audio/audio_io.h" #include "media/audio/audio_util.h" #include "media/audio/win/audio_manager_win.h" @@ -209,7 +209,7 @@ void PCMWaveOutAudioOutputStream::Close() { // Tell the audio manager that we have been released. This can result in // the manager destroying us in-place so this needs to be the last thing // we do on this function. - manager_->ReleaseStream(this); + manager_->ReleaseOutputStream(this); } void PCMWaveOutAudioOutputStream::SetVolume(double volume) { diff --git a/media/audio/win/waveout_output_win.h b/media/audio/win/waveout_output_win.h index df35542..d9b47c0 100644 --- a/media/audio/win/waveout_output_win.h +++ b/media/audio/win/waveout_output_win.h @@ -10,7 +10,7 @@ #include "base/basictypes.h" #include "base/scoped_handle_win.h" -#include "media/audio/audio_output.h" +#include "media/audio/audio_io.h" class AudioManagerWin; -- cgit v1.1