OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_AUDIO_VIRTUAL_AUDIO_INPUT_STREAM_H_ | 5 #ifndef MEDIA_AUDIO_VIRTUAL_AUDIO_INPUT_STREAM_H_ |
6 #define MEDIA_AUDIO_VIRTUAL_AUDIO_INPUT_STREAM_H_ | 6 #define MEDIA_AUDIO_VIRTUAL_AUDIO_INPUT_STREAM_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 | 10 |
11 #include "base/cancelable_callback.h" | 11 #include "base/cancelable_callback.h" |
12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "media/audio/audio_io.h" | 14 #include "media/audio/audio_io.h" |
15 #include "media/audio/audio_manager_base.h" | |
16 #include "media/audio/audio_parameters.h" | 15 #include "media/audio/audio_parameters.h" |
17 #include "media/base/audio_converter.h" | 16 #include "media/base/audio_converter.h" |
18 | 17 |
18 namespace base { | |
19 class MessageLoopProxy; | |
20 } | |
21 | |
19 namespace media { | 22 namespace media { |
20 | 23 |
21 class LoopbackAudioConverter; | 24 class LoopbackAudioConverter; |
22 class VirtualAudioOutputStream; | 25 class VirtualAudioOutputStream; |
23 | 26 |
24 // VirtualAudioInputStream converts and mixes audio from attached | 27 // VirtualAudioInputStream converts and mixes audio from attached |
25 // VirtualAudioOutputStreams into a single stream. It will continuously render | 28 // VirtualAudioOutputStreams into a single stream. It will continuously render |
26 // audio until this VirtualAudioInputStream is stopped and closed. | 29 // audio until this VirtualAudioInputStream is stopped and closed. |
27 class MEDIA_EXPORT VirtualAudioInputStream : public AudioInputStream { | 30 class MEDIA_EXPORT VirtualAudioInputStream : public AudioInputStream { |
28 public: | 31 public: |
29 static VirtualAudioInputStream* MakeStream( | 32 // Callback invoked just after VirtualAudioInputStream is closed. It is safe |
30 AudioManagerBase* manager, | 33 // for the callback to delete this. |
31 const AudioParameters& params, | 34 typedef base::Callback<void(VirtualAudioInputStream* vais)> |
DaleCurtis
2013/01/17 01:15:52
I think "It is safe for the callback to delete thi
miu
2013/01/17 05:33:55
I took out the "safe to delete this" text. It's a
| |
32 base::MessageLoopProxy* message_loop); | 35 AfterCloseCallback; |
36 | |
37 // Construct a target for audio loopback which mixes multiple data streams | |
38 // into a single stream having the given |params|. | |
39 VirtualAudioInputStream(const AudioParameters& params, | |
40 base::MessageLoopProxy* message_loop, | |
41 const AfterCloseCallback& after_close_cb); | |
33 | 42 |
34 virtual ~VirtualAudioInputStream(); | 43 virtual ~VirtualAudioInputStream(); |
35 | 44 |
36 // AudioInputStream: | 45 // AudioInputStream: |
37 virtual bool Open() OVERRIDE; | 46 virtual bool Open() OVERRIDE; |
38 virtual void Start(AudioInputCallback* callback) OVERRIDE; | 47 virtual void Start(AudioInputCallback* callback) OVERRIDE; |
39 virtual void Stop() OVERRIDE; | 48 virtual void Stop() OVERRIDE; |
40 virtual void Close() OVERRIDE; | 49 virtual void Close() OVERRIDE; |
41 virtual double GetMaxVolume() OVERRIDE; | 50 virtual double GetMaxVolume() OVERRIDE; |
42 virtual void SetVolume(double volume) OVERRIDE; | 51 virtual void SetVolume(double volume) OVERRIDE; |
43 virtual double GetVolume() OVERRIDE; | 52 virtual double GetVolume() OVERRIDE; |
44 virtual void SetAutomaticGainControl(bool enabled) OVERRIDE; | 53 virtual void SetAutomaticGainControl(bool enabled) OVERRIDE; |
45 virtual bool GetAutomaticGainControl() OVERRIDE; | 54 virtual bool GetAutomaticGainControl() OVERRIDE; |
46 | 55 |
47 // Attaches a VirtualAudioOutputStream to be used as input. This | 56 // Attaches a VirtualAudioOutputStream to be used as input. This |
48 // VirtualAudioInputStream must outlive all attached streams, so any attached | 57 // VirtualAudioInputStream must outlive all attached streams, so any attached |
49 // stream must be closed (which causes a detach) before | 58 // stream must be closed (which causes a detach) before |
50 // VirtualAudioInputStream is destroyed. | 59 // VirtualAudioInputStream is destroyed. |
51 virtual void AddOutputStream(VirtualAudioOutputStream* stream, | 60 virtual void AddOutputStream(VirtualAudioOutputStream* stream, |
52 const AudioParameters& output_params); | 61 const AudioParameters& output_params); |
53 | 62 |
54 // Detaches a VirtualAudioOutputStream and removes it as input. | 63 // Detaches a VirtualAudioOutputStream and removes it as input. |
55 virtual void RemoveOutputStream(VirtualAudioOutputStream* stream, | 64 virtual void RemoveOutputStream(VirtualAudioOutputStream* stream, |
56 const AudioParameters& output_params); | 65 const AudioParameters& output_params); |
57 | 66 |
58 protected: | 67 private: |
59 friend class VirtualAudioInputStreamTest; | 68 friend class VirtualAudioInputStreamTest; |
60 FRIEND_TEST_ALL_PREFIXES(AudioOutputControllerTest, | |
61 VirtualStreamsTriggerDeviceChange); | |
62 | 69 |
63 typedef std::map<AudioParameters, LoopbackAudioConverter*> AudioConvertersMap; | 70 typedef std::map<AudioParameters, LoopbackAudioConverter*> AudioConvertersMap; |
64 | 71 |
65 VirtualAudioInputStream(AudioManagerBase* manager, | |
66 const AudioParameters& params, | |
67 base::MessageLoopProxy* message_loop); | |
68 | |
69 // When Start() is called on this class, we continuously schedule this | 72 // When Start() is called on this class, we continuously schedule this |
70 // callback to render audio using any attached VirtualAudioOutputStreams until | 73 // callback to render audio using any attached VirtualAudioOutputStreams until |
71 // Stop() is called. | 74 // Stop() is called. |
72 void ReadAudio(); | 75 void ReadAudio(); |
73 | 76 |
74 AudioManagerBase* audio_manager_; | 77 base::MessageLoopProxy* const message_loop_; |
75 base::MessageLoopProxy* message_loop_; | 78 |
79 AfterCloseCallback after_close_cb_; | |
80 | |
76 AudioInputCallback* callback_; | 81 AudioInputCallback* callback_; |
77 | 82 |
78 // Non-const for testing. | 83 // Non-const for testing. |
79 base::TimeDelta buffer_duration_ms_; | 84 base::TimeDelta buffer_duration_; |
80 scoped_array<uint8> buffer_; | 85 scoped_array<uint8> buffer_; |
81 AudioParameters params_; | 86 AudioParameters params_; |
82 scoped_ptr<AudioBus> audio_bus_; | 87 scoped_ptr<AudioBus> audio_bus_; |
83 base::CancelableClosure on_more_data_cb_; | 88 base::CancelableClosure on_more_data_cb_; |
84 | 89 |
85 // AudioConverters associated with the attached VirtualAudioOutputStreams, | 90 // AudioConverters associated with the attached VirtualAudioOutputStreams, |
86 // partitioned by common AudioParameters. | 91 // partitioned by common AudioParameters. |
87 AudioConvertersMap converters_; | 92 AudioConvertersMap converters_; |
88 | 93 |
89 // AudioConverter that takes all the audio converters and mixes them into one | 94 // AudioConverter that takes all the audio converters and mixes them into one |
90 // final audio stream. | 95 // final audio stream. |
91 AudioConverter mixer_; | 96 AudioConverter mixer_; |
92 | 97 |
93 // Number of currently attached VirtualAudioOutputStreams. | 98 // Number of currently attached VirtualAudioOutputStreams. |
94 int num_attached_outputs_streams_; | 99 int num_attached_output_streams_; |
95 | 100 |
96 DISALLOW_COPY_AND_ASSIGN(VirtualAudioInputStream); | 101 DISALLOW_COPY_AND_ASSIGN(VirtualAudioInputStream); |
97 }; | 102 }; |
98 | 103 |
99 } // namespace media | 104 } // namespace media |
100 | 105 |
101 #endif // MEDIA_AUDIO_VIRTUAL_AUDIO_INPUT_STREAM_H_ | 106 #endif // MEDIA_AUDIO_VIRTUAL_AUDIO_INPUT_STREAM_H_ |
OLD | NEW |