Index: content/renderer/media/audio_device_factory.h |
diff --git a/content/renderer/media/audio_device_factory.h b/content/renderer/media/audio_device_factory.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..289a85dc3decdb895c813c63b380df6892feb596 |
--- /dev/null |
+++ b/content/renderer/media/audio_device_factory.h |
@@ -0,0 +1,71 @@ |
+// 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. |
+ |
+#ifndef CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_FACTORY_H_ |
+#define CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_FACTORY_H_ |
+#pragma once |
+ |
+#include "base/compiler_specific.h" |
+#include "base/logging.h" |
+#include "content/common/content_export.h" |
+#include "media/base/audio_renderer_sink.h" |
+ |
+// Factory interface for AudioRendererSink implementations. |
+class AudioDeviceFactoryInterface { |
+ public: |
+ virtual media::AudioRendererSink* Create() = 0; |
+ virtual ~AudioDeviceFactoryInterface() {} |
+}; |
+ |
+// AudioDeviceFactoryInterface implementation. |
+// A reference to an instance of this class can be provided to users/clients |
+// of audio devices. The user can then create the specified audio device. |
+// |
+// Pseudo code: |
+// |
+// scoped_ptr<AudioDeviceFactoryInterface> factory_; |
+// scoped_ptr<MockedAudioMessageFilter> filter_; |
+// scoped_ptr<AudioDeviceClient> client_; |
+// |
+// filter_.reset(new MockedAudioMessageFilter()); |
+// factory_.reset( |
+// new media::AudioDeviceFactory<AudioDevice, MockedAudioMessageFilter>( |
+// filter_)); |
+// client_.reset(new AudioDeviceClient(audio_params, factory_.get())); |
+// |
+// class AudioDeviceClient : public media::AudioRendererSink::RenderCallback { |
+// public: |
+// AudioDeviceClient::AudioDeviceClient(const AudioParameters& params, |
+// AudioDeviceFactoryInterface* factory) |
+// : audio_device_(factory->Create()) { |
+// audio_device_->Initialize(params, this); |
+// } |
+// |
+// private: |
+// scoped_refptr<media::AudioRendererSink> audio_device_; |
+// } |
+// |
+template<typename AudioDeviceImplementation, |
+ typename AudioMessageFilterImplementation> |
+class AudioDeviceFactory |
+ : public AudioDeviceFactoryInterface { |
+ public: |
+ explicit AudioDeviceFactory(AudioMessageFilterImplementation* filter) |
+ : filter_(filter) { |
+ CHECK(filter_); |
+ } |
+ virtual ~AudioDeviceFactory() {} |
+ |
+ // Creates the AudioRendererSink implementation and injects the cached |
+ // audio message filter. |
+ virtual media::AudioRendererSink* Create() OVERRIDE { |
+ return new AudioDeviceImplementation(filter_); |
+ } |
+ |
+ private: |
+ AudioMessageFilterImplementation* filter_; |
+ DISALLOW_COPY_AND_ASSIGN(AudioDeviceFactory); |
+}; |
+ |
+#endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_FACTORY_H_ |