OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_FACTORY_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_FACTORY_H_ |
| 7 #pragma once |
| 8 |
| 9 #include "base/compiler_specific.h" |
| 10 #include "base/logging.h" |
| 11 #include "content/common/content_export.h" |
| 12 #include "media/base/audio_renderer_sink.h" |
| 13 |
| 14 // Factory interface for AudioRendererSink implementations. |
| 15 class AudioDeviceFactoryInterface { |
| 16 public: |
| 17 virtual media::AudioRendererSink* Create() = 0; |
| 18 virtual ~AudioDeviceFactoryInterface() {} |
| 19 }; |
| 20 |
| 21 // AudioDeviceFactoryInterface implementation. |
| 22 // A reference to an instance of this class can be provided to users/clients |
| 23 // of audio devices. The user can then create the specified audio device. |
| 24 // |
| 25 // Pseudo code: |
| 26 // |
| 27 // scoped_ptr<AudioDeviceFactoryInterface> factory_; |
| 28 // scoped_ptr<MockedAudioMessageFilter> filter_; |
| 29 // scoped_ptr<AudioDeviceClient> client_; |
| 30 // |
| 31 // filter_.reset(new MockedAudioMessageFilter()); |
| 32 // factory_.reset( |
| 33 // new media::AudioDeviceFactory<AudioDevice, MockedAudioMessageFilter>( |
| 34 // filter_)); |
| 35 // client_.reset(new AudioDeviceClient(audio_params, factory_.get())); |
| 36 // |
| 37 // class AudioDeviceClient : public media::AudioRendererSink::RenderCallback { |
| 38 // public: |
| 39 // AudioDeviceClient::AudioDeviceClient(const AudioParameters& params, |
| 40 // AudioDeviceFactoryInterface* factory) |
| 41 // : audio_device_(factory->Create()) { |
| 42 // audio_device_->Initialize(params, this); |
| 43 // } |
| 44 // |
| 45 // private: |
| 46 // scoped_refptr<media::AudioRendererSink> audio_device_; |
| 47 // } |
| 48 // |
| 49 template<typename AudioDeviceImplementation, |
| 50 typename AudioMessageFilterImplementation> |
| 51 class AudioDeviceFactory |
| 52 : public AudioDeviceFactoryInterface { |
| 53 public: |
| 54 explicit AudioDeviceFactory(AudioMessageFilterImplementation* filter) |
| 55 : filter_(filter) { |
| 56 CHECK(filter_); |
| 57 } |
| 58 virtual ~AudioDeviceFactory() {} |
| 59 |
| 60 // Creates the AudioRendererSink implementation and injects the cached |
| 61 // audio message filter. |
| 62 virtual media::AudioRendererSink* Create() OVERRIDE { |
| 63 return new AudioDeviceImplementation(filter_); |
| 64 } |
| 65 |
| 66 private: |
| 67 AudioMessageFilterImplementation* filter_; |
| 68 DISALLOW_COPY_AND_ASSIGN(AudioDeviceFactory); |
| 69 }; |
| 70 |
| 71 #endif // CONTENT_RENDERER_MEDIA_AUDIO_DEVICE_FACTORY_H_ |
OLD | NEW |