| 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/gtest_prod_util.h" | 11 #include "base/gtest_prod_util.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
| 14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 15 #include "media/audio/audio_io.h" | 15 #include "media/audio/audio_io.h" |
| 16 #include "media/audio/audio_parameters.h" | 16 #include "media/audio/audio_parameters.h" |
| 17 #include "media/audio/fake_audio_consumer.h" | 17 #include "media/audio/fake_audio_consumer.h" |
| 18 #include "media/base/audio_converter.h" | 18 #include "media/base/audio_converter.h" |
| 19 | 19 |
| 20 namespace base { | 20 namespace base { |
| 21 class MessageLoopProxy; | 21 class SingleThreadTaskRunner; |
| 22 } | 22 } |
| 23 | 23 |
| 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. | 34 // Callback invoked just after VirtualAudioInputStream is closed. |
| 35 typedef base::Callback<void(VirtualAudioInputStream* vais)> | 35 typedef base::Callback<void(VirtualAudioInputStream* vais)> |
| 36 AfterCloseCallback; | 36 AfterCloseCallback; |
| 37 | 37 |
| 38 // Construct a target for audio loopback which mixes multiple data streams | 38 // Construct a target for audio loopback which mixes multiple data streams |
| 39 // into a single stream having the given |params|. |worker_loop| is the loop | 39 // into a single stream having the given |params|. |worker_task_runner| is |
| 40 // on which AudioInputCallback methods are called and may or may not be the | 40 // the task runner on which AudioInputCallback methods are called and may or |
| 41 // single thread that invokes the AudioInputStream methods. | 41 // may not be the single thread that invokes the AudioInputStream methods. |
| 42 VirtualAudioInputStream( | 42 VirtualAudioInputStream( |
| 43 const AudioParameters& params, | 43 const AudioParameters& params, |
| 44 const scoped_refptr<base::MessageLoopProxy>& worker_loop, | 44 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner, |
| 45 const AfterCloseCallback& after_close_cb); | 45 const AfterCloseCallback& after_close_cb); |
| 46 | 46 |
| 47 virtual ~VirtualAudioInputStream(); | 47 virtual ~VirtualAudioInputStream(); |
| 48 | 48 |
| 49 // AudioInputStream: | 49 // AudioInputStream: |
| 50 virtual bool Open() OVERRIDE; | 50 virtual bool Open() OVERRIDE; |
| 51 virtual void Start(AudioInputCallback* callback) OVERRIDE; | 51 virtual void Start(AudioInputCallback* callback) OVERRIDE; |
| 52 virtual void Stop() OVERRIDE; | 52 virtual void Stop() OVERRIDE; |
| 53 virtual void Close() OVERRIDE; | 53 virtual void Close() OVERRIDE; |
| 54 virtual double GetMaxVolume() OVERRIDE; | 54 virtual double GetMaxVolume() OVERRIDE; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 71 private: | 71 private: |
| 72 friend class VirtualAudioInputStreamTest; | 72 friend class VirtualAudioInputStreamTest; |
| 73 | 73 |
| 74 typedef std::map<AudioParameters, LoopbackAudioConverter*> AudioConvertersMap; | 74 typedef std::map<AudioParameters, LoopbackAudioConverter*> AudioConvertersMap; |
| 75 | 75 |
| 76 // Pulls audio data from all attached VirtualAudioOutputStreams, mixes and | 76 // Pulls audio data from all attached VirtualAudioOutputStreams, mixes and |
| 77 // converts the streams into one, and pushes the result to |callback_|. | 77 // converts the streams into one, and pushes the result to |callback_|. |
| 78 // Invoked on the worker thread. | 78 // Invoked on the worker thread. |
| 79 void PumpAudio(AudioBus* audio_bus); | 79 void PumpAudio(AudioBus* audio_bus); |
| 80 | 80 |
| 81 const scoped_refptr<base::MessageLoopProxy> worker_loop_; | 81 const scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_; |
| 82 | 82 |
| 83 AfterCloseCallback after_close_cb_; | 83 AfterCloseCallback after_close_cb_; |
| 84 | 84 |
| 85 AudioInputCallback* callback_; | 85 AudioInputCallback* callback_; |
| 86 | 86 |
| 87 // Non-const for testing. | 87 // Non-const for testing. |
| 88 scoped_ptr<uint8[]> buffer_; | 88 scoped_ptr<uint8[]> buffer_; |
| 89 AudioParameters params_; | 89 AudioParameters params_; |
| 90 | 90 |
| 91 // Guards concurrent access to the converter network: converters_, mixer_, and | 91 // Guards concurrent access to the converter network: converters_, mixer_, and |
| (...skipping 15 matching lines...) Expand all Loading... |
| 107 FakeAudioConsumer fake_consumer_; | 107 FakeAudioConsumer fake_consumer_; |
| 108 | 108 |
| 109 base::ThreadChecker thread_checker_; | 109 base::ThreadChecker thread_checker_; |
| 110 | 110 |
| 111 DISALLOW_COPY_AND_ASSIGN(VirtualAudioInputStream); | 111 DISALLOW_COPY_AND_ASSIGN(VirtualAudioInputStream); |
| 112 }; | 112 }; |
| 113 | 113 |
| 114 } // namespace media | 114 } // namespace media |
| 115 | 115 |
| 116 #endif // MEDIA_AUDIO_VIRTUAL_AUDIO_INPUT_STREAM_H_ | 116 #endif // MEDIA_AUDIO_VIRTUAL_AUDIO_INPUT_STREAM_H_ |
| OLD | NEW |