Chromium Code Reviews| 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 MEDIA_AUDIO_VIRTUAL_AUDIO_INPUT_STREAM_H_ | |
| 6 #define MEDIA_AUDIO_VIRTUAL_AUDIO_INPUT_STREAM_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 #include <set> | |
| 10 | |
| 11 #include "base/cancelable_callback.h" | |
| 12 #include "base/gtest_prod_util.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "media/audio/audio_io.h" | |
| 15 #include "media/audio/audio_manager_base.h" | |
| 16 #include "media/audio/audio_parameters.h" | |
| 17 #include "media/base/audio_converter.h" | |
| 18 | |
| 19 namespace media { | |
| 20 | |
| 21 class LoopbackAudioConverter; | |
| 22 class VirtualAudioOutputStream; | |
| 23 | |
| 24 // VirtualAudioInputStream converts and mixes audio from attached | |
| 25 // VirtualAudioOutputStreams into a single stream. It will continuously render | |
| 26 // audio until this VirtualAudioInputStream is stopped and closed. | |
| 27 class MEDIA_EXPORT VirtualAudioInputStream : public AudioInputStream { | |
| 28 public: | |
| 29 static VirtualAudioInputStream* MakeStream(AudioManagerBase* manager, | |
| 30 const AudioParameters& params); | |
| 31 | |
| 32 virtual ~VirtualAudioInputStream(); | |
| 33 | |
| 34 // AudioInputStream: | |
| 35 virtual bool Open() OVERRIDE; | |
| 36 virtual void Start(AudioInputCallback* callback) OVERRIDE; | |
| 37 virtual void Stop() OVERRIDE; | |
| 38 virtual void Close() OVERRIDE; | |
| 39 virtual double GetMaxVolume() OVERRIDE; | |
| 40 virtual void SetVolume(double volume) OVERRIDE; | |
| 41 virtual double GetVolume() OVERRIDE; | |
| 42 virtual void SetAutomaticGainControl(bool enabled) OVERRIDE; | |
| 43 virtual bool GetAutomaticGainControl() OVERRIDE; | |
| 44 | |
| 45 // Attaches a VirtualAudioOutputStream to be used as input. This | |
| 46 // VirtualAudioInputStream must outlive all attached streams, so any attached | |
| 47 // stream must be closed (which causes a detach) before | |
| 48 // VirtualAudioInputStream is destroyed. | |
| 49 virtual void AddOutputStream(VirtualAudioOutputStream* stream, | |
| 50 const AudioParameters& output_params); | |
| 51 | |
| 52 // Detaches a VirtualAudioOutputStream and removes it as input. | |
| 53 virtual void RemoveOutputStream(VirtualAudioOutputStream* stream, | |
| 54 const AudioParameters& output_params); | |
| 55 | |
| 56 protected: | |
| 57 friend class VirtualAudioInputStreamTest; | |
| 58 FRIEND_TEST_ALL_PREFIXES(AudioOutputControllerTest, | |
| 59 VirtualStreamsTriggerDeviceChange); | |
| 60 | |
| 61 typedef std::map<AudioParameters, LoopbackAudioConverter*> AudioConvertersMap; | |
| 62 | |
| 63 VirtualAudioInputStream(AudioManagerBase* manager, | |
| 64 const AudioParameters& params); | |
| 65 | |
| 66 // When Start() is called on this class, we continuously schedule this | |
| 67 // callback to render audio using any attached VirtualAudioOutputStreams until | |
| 68 // Stop() is called. | |
| 69 void ReadAudio(); | |
| 70 | |
| 71 // Helper method to make sure methods are called on the audio thread. This is | |
|
DaleCurtis
2012/12/03 19:27:28
This is risky. You're posting tasks to the audio t
justinlin
2012/12/03 21:18:42
Done.
| |
| 72 // overridden by tests. | |
| 73 virtual bool CalledOnAudioThread(); | |
| 74 | |
| 75 AudioManagerBase* audio_manager_; | |
| 76 AudioInputCallback* callback_; | |
| 77 | |
| 78 // Non-const for testing. | |
| 79 base::TimeDelta buffer_duration_ms_; | |
| 80 scoped_array<uint8> buffer_; | |
| 81 AudioParameters params_; | |
| 82 scoped_ptr<AudioBus> audio_bus_; | |
| 83 base::CancelableClosure on_more_data_cb_; | |
| 84 | |
| 85 // AudioConverters associated with the attached VirtualAudioOutputStreams, | |
| 86 // partitioned by common AudioParameters. | |
| 87 AudioConvertersMap converters_; | |
| 88 | |
| 89 // AudioConverter that takes all the audio converters and mixes them into one | |
| 90 // final audio stream. | |
| 91 AudioConverter mixer_; | |
| 92 | |
| 93 // Number of currently attached VirtualAudioOutputStreams. | |
| 94 int num_attached_outputs_streams_; | |
| 95 | |
| 96 DISALLOW_COPY_AND_ASSIGN(VirtualAudioInputStream); | |
| 97 }; | |
| 98 | |
| 99 } // namespace media | |
| 100 | |
| 101 #endif // MEDIA_AUDIO_VIRTUAL_AUDIO_INPUT_STREAM_H_ | |
| OLD | NEW |