Mailbox support for texture layers.
[chromium-blink-merge.git] / media / audio / virtual_audio_input_stream.h
blobfcb87a4db10bd58955a988f492ee6fa4ff7cf5d1
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.
5 #ifndef MEDIA_AUDIO_VIRTUAL_AUDIO_INPUT_STREAM_H_
6 #define MEDIA_AUDIO_VIRTUAL_AUDIO_INPUT_STREAM_H_
8 #include <map>
9 #include <set>
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"
19 namespace media {
21 class LoopbackAudioConverter;
22 class VirtualAudioOutputStream;
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(
30 AudioManagerBase* manager,
31 const AudioParameters& params,
32 base::MessageLoopProxy* message_loop);
34 virtual ~VirtualAudioInputStream();
36 // AudioInputStream:
37 virtual bool Open() OVERRIDE;
38 virtual void Start(AudioInputCallback* callback) OVERRIDE;
39 virtual void Stop() OVERRIDE;
40 virtual void Close() OVERRIDE;
41 virtual double GetMaxVolume() OVERRIDE;
42 virtual void SetVolume(double volume) OVERRIDE;
43 virtual double GetVolume() OVERRIDE;
44 virtual void SetAutomaticGainControl(bool enabled) OVERRIDE;
45 virtual bool GetAutomaticGainControl() OVERRIDE;
47 // Attaches a VirtualAudioOutputStream to be used as input. This
48 // VirtualAudioInputStream must outlive all attached streams, so any attached
49 // stream must be closed (which causes a detach) before
50 // VirtualAudioInputStream is destroyed.
51 virtual void AddOutputStream(VirtualAudioOutputStream* stream,
52 const AudioParameters& output_params);
54 // Detaches a VirtualAudioOutputStream and removes it as input.
55 virtual void RemoveOutputStream(VirtualAudioOutputStream* stream,
56 const AudioParameters& output_params);
58 protected:
59 friend class VirtualAudioInputStreamTest;
60 FRIEND_TEST_ALL_PREFIXES(AudioOutputControllerTest,
61 VirtualStreamsTriggerDeviceChange);
63 typedef std::map<AudioParameters, LoopbackAudioConverter*> AudioConvertersMap;
65 VirtualAudioInputStream(AudioManagerBase* manager,
66 const AudioParameters& params,
67 base::MessageLoopProxy* message_loop);
69 // When Start() is called on this class, we continuously schedule this
70 // callback to render audio using any attached VirtualAudioOutputStreams until
71 // Stop() is called.
72 void ReadAudio();
74 AudioManagerBase* audio_manager_;
75 base::MessageLoopProxy* message_loop_;
76 AudioInputCallback* callback_;
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_;
85 // AudioConverters associated with the attached VirtualAudioOutputStreams,
86 // partitioned by common AudioParameters.
87 AudioConvertersMap converters_;
89 // AudioConverter that takes all the audio converters and mixes them into one
90 // final audio stream.
91 AudioConverter mixer_;
93 // Number of currently attached VirtualAudioOutputStreams.
94 int num_attached_outputs_streams_;
96 DISALLOW_COPY_AND_ASSIGN(VirtualAudioInputStream);
99 } // namespace media
101 #endif // MEDIA_AUDIO_VIRTUAL_AUDIO_INPUT_STREAM_H_