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 | |
| 28 : public AudioInputStream { | |
| 29 public: | |
| 30 static VirtualAudioInputStream* MakeStream(AudioManagerBase* manager, | |
| 31 const AudioParameters& params); | |
| 32 | |
| 33 // AudioInputStream: | |
| 34 virtual bool Open() OVERRIDE; | |
| 35 virtual void Start(AudioInputCallback* callback) OVERRIDE; | |
| 36 virtual void Stop() OVERRIDE; | |
| 37 virtual void Close() OVERRIDE; | |
| 38 virtual double GetMaxVolume() OVERRIDE; | |
| 39 virtual void SetVolume(double volume) OVERRIDE; | |
| 40 virtual double GetVolume() OVERRIDE; | |
| 41 virtual void SetAutomaticGainControl(bool enabled) OVERRIDE; | |
| 42 virtual bool GetAutomaticGainControl() OVERRIDE; | |
| 43 | |
| 44 // Attaches a VirtualAudioOutputStream to be used as input. This | |
| 45 // VirtualAudioInputStream must outlive all attached streams, so any attached | |
| 46 // stream must be closed (which causes a detach) before | |
| 47 // VirtualAudioInputStream is destroyed. | |
| 48 void AddOutputStream( | |
| 49 VirtualAudioOutputStream* stream, const AudioParameters& params); | |
| 50 | |
| 51 // Detaches a VirtualAudioOutputStream and removes it as input. | |
| 52 void RemoveOutputStream(VirtualAudioOutputStream* stream); | |
| 53 | |
| 54 protected: | |
| 55 friend class VirtualAudioInputStreamTest; | |
| 56 FRIEND_TEST_ALL_PREFIXES(AudioOutputControllerTest, | |
| 57 VirtualStreamsTriggerDeviceChange); | |
| 58 | |
| 59 typedef std::map<AudioParameters, LoopbackAudioConverter*> AudioConvertersMap; | |
| 60 typedef std::map<AudioOutputStream*, AudioParameters> OutputStreamParams; | |
| 61 | |
| 62 VirtualAudioInputStream(AudioManagerBase* manager, | |
| 63 const AudioParameters& params); | |
| 64 | |
| 65 virtual ~VirtualAudioInputStream(); | |
| 66 | |
| 67 // When Start() is called on this class, we continuously schedule this | |
| 68 // callback to render audio using any attached VirtualAudioOutputStreams until | |
| 69 // Stop() is called. | |
| 70 void DoCallback(); | |
|
Alpha Left Google
2012/11/28 21:26:51
Give a more meaningful name other than DoCallback.
| |
| 71 | |
| 72 AudioManagerBase* audio_manager_; | |
| 73 AudioInputCallback* callback_; | |
| 74 const int buffer_duration_ms_; | |
| 75 base::Time next_read_time_; | |
| 76 scoped_array<uint8> buffer_; | |
| 77 AudioParameters params_; | |
| 78 scoped_ptr<AudioBus> audio_bus_; | |
| 79 base::CancelableClosure on_more_data_cb_; | |
| 80 | |
| 81 // AudioConverters associated with the attached VirtualAudioOutputStreams, | |
| 82 // partitioned by common AudioParameters. | |
| 83 AudioConvertersMap converters_; | |
| 84 | |
| 85 // AudioConverter that takes all the audio converters and mixes them into one | |
| 86 // final audio stream. | |
| 87 AudioConverter mixer_; | |
| 88 | |
| 89 // Maps attached output streams to their parameters. We need this later to | |
| 90 // remove the virtual output stream from the right AudioConverter. | |
| 91 OutputStreamParams output_params_; | |
| 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_FAKE_AUDIO_INPUT_STREAM_H_ | |
| OLD | NEW |