Separate Simple Backend creation from initialization.
[chromium-blink-merge.git] / media / audio / virtual_audio_output_stream.h
blob32afe30eb0184650bfbfc438c650aabf5cd89f50
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_OUTPUT_STREAM_H_
6 #define MEDIA_AUDIO_VIRTUAL_AUDIO_OUTPUT_STREAM_H_
8 #include "base/callback.h"
9 #include "media/audio/audio_io.h"
10 #include "media/audio/audio_parameters.h"
11 #include "media/base/audio_converter.h"
13 namespace base {
14 class MessageLoopProxy;
17 namespace media {
19 class VirtualAudioInputStream;
21 // VirtualAudioOutputStream attaches to a VirtualAudioInputStream when Start()
22 // 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
24 // that we can get audio frames that match the AudioParameters that
25 // VirtualAudioInputStream expects.
26 class MEDIA_EXPORT VirtualAudioOutputStream
27 : public AudioOutputStream,
28 public AudioConverter::InputCallback {
29 public:
30 // Callback invoked just after VirtualAudioOutputStream is closed.
31 typedef base::Callback<void(VirtualAudioOutputStream* vaos)>
32 AfterCloseCallback;
34 // Construct an audio loopback pathway to the given |target| (not owned).
35 // |target| must outlive this instance.
36 VirtualAudioOutputStream(const AudioParameters& params,
37 base::MessageLoopProxy* message_loop,
38 VirtualAudioInputStream* target,
39 const AfterCloseCallback& after_close_cb);
41 virtual ~VirtualAudioOutputStream();
43 // AudioOutputStream:
44 virtual bool Open() OVERRIDE;
45 virtual void Start(AudioSourceCallback* callback) OVERRIDE;
46 virtual void Stop() OVERRIDE;
47 virtual void SetVolume(double volume) OVERRIDE;
48 virtual void GetVolume(double* volume) OVERRIDE;
49 virtual void Close() OVERRIDE;
51 private:
52 // AudioConverter::InputCallback:
53 virtual double ProvideInput(AudioBus* audio_bus,
54 base::TimeDelta buffer_delay) OVERRIDE;
56 const AudioParameters params_;
57 base::MessageLoopProxy* const message_loop_;
58 // Pointer to the VirtualAudioInputStream to attach to when Start() is called.
59 // This pointer should always be valid because VirtualAudioInputStream should
60 // outlive this class.
61 VirtualAudioInputStream* const target_input_stream_;
63 AfterCloseCallback after_close_cb_;
65 AudioSourceCallback* callback_;
66 double volume_;
68 DISALLOW_COPY_AND_ASSIGN(VirtualAudioOutputStream);
71 } // namespace media
73 #endif // MEDIA_AUDIO_VIRTUAL_AUDIO_OUTPUT_STREAM_H_