summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorcpu@google.com <cpu@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-13 23:56:56 +0000
committercpu@google.com <cpu@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-13 23:56:56 +0000
commit7cecfb2fa8bd8bb4254f8d83ad0ce5d23961f98c (patch)
tree5240f4628db2efff362da4c52c69b8cb29853db6 /media
parentb62d1a8c6795a9feefe4a2e688463c56ce46a6bd (diff)
downloadchromium_src-7cecfb2fa8bd8bb4254f8d83ad0ce5d23961f98c.zip
chromium_src-7cecfb2fa8bd8bb4254f8d83ad0ce5d23961f98c.tar.gz
chromium_src-7cecfb2fa8bd8bb4254f8d83ad0ce5d23961f98c.tar.bz2
Low level windows audio support (part 1 of 2)
- Windows specific changes to AudioManager Allows testing for mock streams This this the first part of the code that adds support for audio using waveXXX API. Since is relatively lot of code I will do two CLs, unfortunately the complexity is not evenly split. Review URL: http://codereview.chromium.org/17401 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7987 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/audio/audio_output.h20
-rw-r--r--media/audio/win/audio_manager_win.h41
-rw-r--r--media/audio/win/audio_output_win.cc97
3 files changed, 125 insertions, 33 deletions
diff --git a/media/audio/audio_output.h b/media/audio/audio_output.h
index da787ea..37235a2 100644
--- a/media/audio/audio_output.h
+++ b/media/audio/audio_output.h
@@ -33,6 +33,7 @@
// 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.
@@ -106,6 +107,13 @@ class AudioManager {
AUDIO_MOCK // Creates a dummy AudioOutputStream object.
};
+ // Telephone quality sample rate, mostly for speech-only audio.
+ static const int kTelephoneSampleRate = 8000;
+ // CD sampling rate is 44.1 KHz or conveniently 2x2x3x3x5x5x7x7.
+ static const int kAudioCDSampleRate = 44100;
+ // Digital Audio Tape sample rate.
+ static const int kAudioDATSampleRate = 48000;
+
// Factory for all the supported stream formats. At this moment |channels|
// can be 1 (mono) or 2 (stereo). The |sample_rate| is in hertz and can be
// any value supported by the underlying platform. For some future formats
@@ -123,13 +131,19 @@ class AudioManager {
virtual void MuteAll() = 0;
virtual void UnMuteAll() = 0;
+ // For testing purposes only. Returns the internal buffer of the last
+ // AUDIO_MOCK AudioOutputStream closed. Returns NULL if none closed yet.
+ // The buffer size is the same as passed to AudioOutputStream::Open().
+ virtual const void* GetLastMockBuffer() = 0;
+
+ // Get AudioManager singleton.
+ // TODO(cpu): Define threading requirements for interacting with AudioManager.
+ static AudioManager* GetAudioManager();
+
protected:
virtual ~AudioManager() {}
};
-// Get AudioManager singleton.
-// TODO(cpu): Define threading requirements for interacting with AudioManager.
-AudioManager* GetAudioManager();
#endif // MEDIA_AUDIO_AUDIO_OUTPUT_H_
diff --git a/media/audio/win/audio_manager_win.h b/media/audio/win/audio_manager_win.h
new file mode 100644
index 0000000..df9e076
--- /dev/null
+++ b/media/audio/win/audio_manager_win.h
@@ -0,0 +1,41 @@
+// 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.
+
+#ifndef MEDIA_AUDIO_AUDIO_MANAGER_WIN_H_
+#define MEDIA_AUDIO_AUDIO_MANAGER_WIN_H_
+
+#include <windows.h>
+
+#include "base/basictypes.h"
+#include "media/audio/audio_output.h"
+
+class PCMWaveOutAudioOutputStream;
+class AudioOutputStreamMockWin;
+
+// Windows implementation of the AudioManager singleton. This class is internal
+// to the audio output and only internal users can call methods not exposed by
+// the AudioManager class.
+class AudioManagerWin : public AudioManager {
+ public:
+ AudioManagerWin() {}
+ // Implementation of AudioManager.
+ virtual AudioOutputStream* MakeAudioStream(Format format, int channels,
+ int sample_rate,
+ char bits_per_sample);
+ virtual void MuteAll();
+ virtual void UnMuteAll();
+ virtual const void* GetLastMockBuffer();
+
+ // 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 ReleaseStream(AudioOutputStreamMockWin* stream);
+
+ private:
+ virtual ~AudioManagerWin();
+ DISALLOW_COPY_AND_ASSIGN(AudioManagerWin);
+};
+
+#endif // MEDIA_AUDIO_AUDIO_MANAGER_WIN_H_
+
diff --git a/media/audio/win/audio_output_win.cc b/media/audio/win/audio_output_win.cc
index 4fe06e0..5685ee7 100644
--- a/media/audio/win/audio_output_win.cc
+++ b/media/audio/win/audio_output_win.cc
@@ -3,22 +3,31 @@
// found in the LICENSE file.
#include <windows.h>
+#include <mmsystem.h>
#include "base/basictypes.h"
#include "media/audio/audio_output.h"
+#include "media/audio/win/audio_manager_win.h"
+#include "media/audio/win/waveout_output_win.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 {
+class AudioOutputStreamMockWin : public AudioOutputStream {
public:
- AudioOutputStreamWinMock()
- : callback_(NULL),
+ explicit AudioOutputStreamMockWin(AudioManagerWin* manager)
+ : manager_(manager),
+ callback_(NULL),
buffer_(NULL),
packet_size_(0),
- left_volume_(0.0),
- right_volume_(0.0) {
+ left_volume_(1.0),
+ right_volume_(1.0) {
+ }
+
+ virtual ~AudioOutputStreamMockWin() {
+ delete[] buffer_;
+ packet_size_ = 0;
}
virtual bool Open(size_t packet_size) {
@@ -31,6 +40,7 @@ class AudioOutputStreamWinMock : public AudioOutputStream {
virtual void Start(AudioSourceCallback* callback) {
callback_ = callback;
+ memset(buffer_, 0, packet_size_);
callback_->OnMoreData(this, buffer_, packet_size_);
}
@@ -52,16 +62,15 @@ class AudioOutputStreamWinMock : public AudioOutputStream {
virtual void Close() {
callback_->OnClose(this);
callback_ = NULL;
- delete this;
+ manager_->ReleaseStream(this);
}
- protected:
- virtual ~AudioOutputStreamWinMock() {
- delete[] buffer_;
- packet_size_ = 0;
+ char* buffer() {
+ return buffer_;
}
private:
+ AudioManagerWin* manager_;
AudioSourceCallback* callback_;
char* buffer_;
size_t packet_size_;
@@ -69,35 +78,63 @@ class AudioOutputStreamWinMock : public AudioOutputStream {
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;
- }
+namespace {
+AudioOutputStreamMockWin* g_last_mock_stream = NULL;
- virtual void MuteAll() {
- }
+void ReplaceLastMockStream(AudioOutputStreamMockWin* newer) {
+ if (g_last_mock_stream)
+ delete g_last_mock_stream;
+ g_last_mock_stream = newer;
+}
- virtual void UnMuteAll() {
+} // namespace.
+
+// 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 (format == AUDIO_MOCK) {
+ return new AudioOutputStreamMockWin(this);
+ } else if (format == AUDIO_PCM_LINEAR) {
+ return new PCMWaveOutAudioOutputStream(this, channels, sample_rate,
+ bits_per_sample, WAVE_MAPPER);
}
+ return NULL;
+}
- protected:
- virtual ~AudioManagerWin() {
- }
-};
+void AudioManagerWin::ReleaseStream(PCMWaveOutAudioOutputStream* stream) {
+ if (stream)
+ delete stream;
+}
+
+void AudioManagerWin::ReleaseStream(AudioOutputStreamMockWin *stream) {
+ // Note that we keep the last mock stream so GetLastMockBuffer() works.
+ ReplaceLastMockStream(stream);
+}
+
+const void* AudioManagerWin::GetLastMockBuffer() {
+ return (g_last_mock_stream) ? g_last_mock_stream->buffer() : NULL;
+}
+
+void AudioManagerWin::MuteAll() {
+}
+
+void AudioManagerWin::UnMuteAll() {
+}
+
+AudioManagerWin::~AudioManagerWin() {
+ ReplaceLastMockStream(NULL);
+}
// TODO(cpu): Decide how to manage the lifetime of the AudioManager singleton.
// Right now we are leaking it.
-AudioManager* GetAudioManager() {
+AudioManager* AudioManager::GetAudioManager() {
static AudioManagerWin* audio_manager = NULL;
if (!audio_manager)
audio_manager = new AudioManagerWin();
return audio_manager;
}
-
-
-