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_OUTPUT_STREAM_H_ | 5 #ifndef MEDIA_AUDIO_VIRTUAL_AUDIO_OUTPUT_STREAM_H_ |
6 #define MEDIA_AUDIO_VIRTUAL_AUDIO_OUTPUT_STREAM_H_ | 6 #define MEDIA_AUDIO_VIRTUAL_AUDIO_OUTPUT_STREAM_H_ |
7 | 7 |
8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/threading/thread_checker.h" |
9 #include "media/audio/audio_io.h" | 10 #include "media/audio/audio_io.h" |
10 #include "media/audio/audio_parameters.h" | 11 #include "media/audio/audio_parameters.h" |
11 #include "media/base/audio_converter.h" | 12 #include "media/base/audio_converter.h" |
12 | 13 |
13 namespace base { | |
14 class MessageLoopProxy; | |
15 } | |
16 | |
17 namespace media { | 14 namespace media { |
18 | 15 |
19 class VirtualAudioInputStream; | 16 class VirtualAudioInputStream; |
20 | 17 |
21 // VirtualAudioOutputStream attaches to a VirtualAudioInputStream when Start() | 18 // VirtualAudioOutputStream attaches to a VirtualAudioInputStream when Start() |
22 // is called and is used as an audio source. VirtualAudioOutputStream also | 19 // is called and is used as an audio source. VirtualAudioOutputStream also |
23 // implements an interface so it can be used as an input to AudioConverter so | 20 // implements an interface so it can be used as an input to AudioConverter so |
24 // that we can get audio frames that match the AudioParameters that | 21 // that we can get audio frames that match the AudioParameters that |
25 // VirtualAudioInputStream expects. | 22 // VirtualAudioInputStream expects. |
26 class MEDIA_EXPORT VirtualAudioOutputStream | 23 class MEDIA_EXPORT VirtualAudioOutputStream |
27 : public AudioOutputStream, | 24 : public AudioOutputStream, |
28 public AudioConverter::InputCallback { | 25 public AudioConverter::InputCallback { |
29 public: | 26 public: |
30 // Callback invoked just after VirtualAudioOutputStream is closed. | 27 // Callback invoked just after VirtualAudioOutputStream is closed. |
31 typedef base::Callback<void(VirtualAudioOutputStream* vaos)> | 28 typedef base::Callback<void(VirtualAudioOutputStream* vaos)> |
32 AfterCloseCallback; | 29 AfterCloseCallback; |
33 | 30 |
34 // Construct an audio loopback pathway to the given |target| (not owned). | 31 // Construct an audio loopback pathway to the given |target| (not owned). |
35 // |target| must outlive this instance. | 32 // |target| must outlive this instance. |
36 VirtualAudioOutputStream(const AudioParameters& params, | 33 VirtualAudioOutputStream(const AudioParameters& params, |
37 base::MessageLoopProxy* message_loop, | |
38 VirtualAudioInputStream* target, | 34 VirtualAudioInputStream* target, |
39 const AfterCloseCallback& after_close_cb); | 35 const AfterCloseCallback& after_close_cb); |
40 | 36 |
41 virtual ~VirtualAudioOutputStream(); | 37 virtual ~VirtualAudioOutputStream(); |
42 | 38 |
43 // AudioOutputStream: | 39 // AudioOutputStream: |
44 virtual bool Open() OVERRIDE; | 40 virtual bool Open() OVERRIDE; |
45 virtual void Start(AudioSourceCallback* callback) OVERRIDE; | 41 virtual void Start(AudioSourceCallback* callback) OVERRIDE; |
46 virtual void Stop() OVERRIDE; | 42 virtual void Stop() OVERRIDE; |
47 virtual void SetVolume(double volume) OVERRIDE; | 43 virtual void SetVolume(double volume) OVERRIDE; |
48 virtual void GetVolume(double* volume) OVERRIDE; | 44 virtual void GetVolume(double* volume) OVERRIDE; |
49 virtual void Close() OVERRIDE; | 45 virtual void Close() OVERRIDE; |
50 | 46 |
51 private: | 47 private: |
52 // AudioConverter::InputCallback: | 48 // AudioConverter::InputCallback: |
53 virtual double ProvideInput(AudioBus* audio_bus, | 49 virtual double ProvideInput(AudioBus* audio_bus, |
54 base::TimeDelta buffer_delay) OVERRIDE; | 50 base::TimeDelta buffer_delay) OVERRIDE; |
55 | 51 |
56 const AudioParameters params_; | 52 const AudioParameters params_; |
57 base::MessageLoopProxy* const message_loop_; | |
58 // Pointer to the VirtualAudioInputStream to attach to when Start() is called. | 53 // Pointer to the VirtualAudioInputStream to attach to when Start() is called. |
59 // This pointer should always be valid because VirtualAudioInputStream should | 54 // This pointer should always be valid because VirtualAudioInputStream should |
60 // outlive this class. | 55 // outlive this class. |
61 VirtualAudioInputStream* const target_input_stream_; | 56 VirtualAudioInputStream* const target_input_stream_; |
62 | 57 |
63 AfterCloseCallback after_close_cb_; | 58 AfterCloseCallback after_close_cb_; |
64 | 59 |
65 AudioSourceCallback* callback_; | 60 AudioSourceCallback* callback_; |
66 double volume_; | 61 double volume_; |
67 | 62 |
| 63 base::ThreadChecker thread_checker_; |
| 64 |
68 DISALLOW_COPY_AND_ASSIGN(VirtualAudioOutputStream); | 65 DISALLOW_COPY_AND_ASSIGN(VirtualAudioOutputStream); |
69 }; | 66 }; |
70 | 67 |
71 } // namespace media | 68 } // namespace media |
72 | 69 |
73 #endif // MEDIA_AUDIO_VIRTUAL_AUDIO_OUTPUT_STREAM_H_ | 70 #endif // MEDIA_AUDIO_VIRTUAL_AUDIO_OUTPUT_STREAM_H_ |
OLD | NEW |