| 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 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 namespace media { | 24 namespace media { |
| 25 | 25 |
| 26 class LoopbackAudioConverter; | 26 class LoopbackAudioConverter; |
| 27 class VirtualAudioOutputStream; | 27 class VirtualAudioOutputStream; |
| 28 | 28 |
| 29 // VirtualAudioInputStream converts and mixes audio from attached | 29 // VirtualAudioInputStream converts and mixes audio from attached |
| 30 // VirtualAudioOutputStreams into a single stream. It will continuously render | 30 // VirtualAudioOutputStreams into a single stream. It will continuously render |
| 31 // audio until this VirtualAudioInputStream is stopped and closed. | 31 // audio until this VirtualAudioInputStream is stopped and closed. |
| 32 class MEDIA_EXPORT VirtualAudioInputStream : public AudioInputStream { | 32 class MEDIA_EXPORT VirtualAudioInputStream : public AudioInputStream { |
| 33 public: | 33 public: |
| 34 // Callback invoked just after VirtualAudioInputStream is closed. | |
| 35 typedef base::Callback<void(VirtualAudioInputStream* vais)> | |
| 36 AfterCloseCallback; | |
| 37 | |
| 38 // Construct a target for audio loopback which mixes multiple data streams | 34 // Construct a target for audio loopback which mixes multiple data streams |
| 39 // into a single stream having the given |params|. |worker_task_runner| is | 35 // into a single stream having the given |params|. |worker_task_runner| is |
| 40 // the task runner on which AudioInputCallback methods are called and may or | 36 // the task runner on which AudioInputCallback methods are called and may or |
| 41 // may not be the single thread that invokes the AudioInputStream methods. | 37 // may not be the single thread that invokes the AudioInputStream methods. |
| 42 VirtualAudioInputStream( | 38 VirtualAudioInputStream( |
| 43 const AudioParameters& params, | 39 const AudioParameters& params, |
| 44 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner, | 40 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner, |
| 45 const AfterCloseCallback& after_close_cb); | 41 bool delete_on_close); |
| 46 | 42 |
| 47 ~VirtualAudioInputStream() override; | 43 ~VirtualAudioInputStream() override; |
| 48 | 44 |
| 49 // AudioInputStream: | 45 // AudioInputStream: |
| 50 bool Open() override; | 46 bool Open() override; |
| 51 void Start(AudioInputCallback* callback) override; | 47 void Start(AudioInputCallback* callback) override; |
| 52 void Stop() override; | 48 void Stop() override; |
| 53 void Close() override; | 49 void Close() override; |
| 54 double GetMaxVolume() override; | 50 double GetMaxVolume() override; |
| 55 void SetVolume(double volume) override; | 51 void SetVolume(double volume) override; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 74 | 70 |
| 75 typedef std::map<AudioParameters, LoopbackAudioConverter*> AudioConvertersMap; | 71 typedef std::map<AudioParameters, LoopbackAudioConverter*> AudioConvertersMap; |
| 76 | 72 |
| 77 // Pulls audio data from all attached VirtualAudioOutputStreams, mixes and | 73 // Pulls audio data from all attached VirtualAudioOutputStreams, mixes and |
| 78 // converts the streams into one, and pushes the result to |callback_|. | 74 // converts the streams into one, and pushes the result to |callback_|. |
| 79 // Invoked on the worker thread. | 75 // Invoked on the worker thread. |
| 80 void PumpAudio(); | 76 void PumpAudio(); |
| 81 | 77 |
| 82 const scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_; | 78 const scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_; |
| 83 | 79 |
| 84 AfterCloseCallback after_close_cb_; | 80 const bool delete_on_close_; |
| 85 | 81 |
| 86 AudioInputCallback* callback_; | 82 AudioInputCallback* callback_; |
| 87 | 83 |
| 88 // Non-const for testing. | 84 // Non-const for testing. |
| 89 scoped_ptr<uint8[]> buffer_; | 85 scoped_ptr<uint8[]> buffer_; |
| 90 AudioParameters params_; | 86 AudioParameters params_; |
| 91 | 87 |
| 92 // Guards concurrent access to the converter network: converters_, mixer_, and | 88 // Guards concurrent access to the converter network: converters_, mixer_, and |
| 93 // num_attached_output_streams_. | 89 // num_attached_output_streams_. |
| 94 base::Lock converter_network_lock_; | 90 base::Lock converter_network_lock_; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 110 scoped_ptr<AudioBus> audio_bus_; | 106 scoped_ptr<AudioBus> audio_bus_; |
| 111 | 107 |
| 112 base::ThreadChecker thread_checker_; | 108 base::ThreadChecker thread_checker_; |
| 113 | 109 |
| 114 DISALLOW_COPY_AND_ASSIGN(VirtualAudioInputStream); | 110 DISALLOW_COPY_AND_ASSIGN(VirtualAudioInputStream); |
| 115 }; | 111 }; |
| 116 | 112 |
| 117 } // namespace media | 113 } // namespace media |
| 118 | 114 |
| 119 #endif // MEDIA_AUDIO_VIRTUAL_AUDIO_INPUT_STREAM_H_ | 115 #endif // MEDIA_AUDIO_VIRTUAL_AUDIO_INPUT_STREAM_H_ |
| OLD | NEW |