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 "base/threading/thread_checker.h"
10 #include "media/audio/audio_io.h"
11 #include "media/audio/audio_parameters.h"
12 #include "media/base/audio_converter.h"
16 class VirtualAudioInputStream
;
18 // VirtualAudioOutputStream attaches to a VirtualAudioInputStream when Start()
19 // is called and is used as an audio source. VirtualAudioOutputStream also
20 // implements an interface so it can be used as an input to AudioConverter so
21 // that we can get audio frames that match the AudioParameters that
22 // VirtualAudioInputStream expects.
23 class MEDIA_EXPORT VirtualAudioOutputStream
24 : public AudioOutputStream
,
25 public AudioConverter::InputCallback
{
27 // Callback invoked just after VirtualAudioOutputStream is closed.
28 typedef base::Callback
<void(VirtualAudioOutputStream
* vaos
)>
31 // Construct an audio loopback pathway to the given |target| (not owned).
32 // |target| must outlive this instance.
33 VirtualAudioOutputStream(const AudioParameters
& params
,
34 VirtualAudioInputStream
* target
,
35 const AfterCloseCallback
& after_close_cb
);
37 virtual ~VirtualAudioOutputStream();
40 virtual bool Open() OVERRIDE
;
41 virtual void Start(AudioSourceCallback
* callback
) OVERRIDE
;
42 virtual void Stop() OVERRIDE
;
43 virtual void SetVolume(double volume
) OVERRIDE
;
44 virtual void GetVolume(double* volume
) OVERRIDE
;
45 virtual void Close() OVERRIDE
;
48 // AudioConverter::InputCallback:
49 virtual double ProvideInput(AudioBus
* audio_bus
,
50 base::TimeDelta buffer_delay
) OVERRIDE
;
52 const AudioParameters params_
;
53 // Pointer to the VirtualAudioInputStream to attach to when Start() is called.
54 // This pointer should always be valid because VirtualAudioInputStream should
55 // outlive this class.
56 VirtualAudioInputStream
* const target_input_stream_
;
58 AfterCloseCallback after_close_cb_
;
60 AudioSourceCallback
* callback_
;
63 base::ThreadChecker thread_checker_
;
65 DISALLOW_COPY_AND_ASSIGN(VirtualAudioOutputStream
);
70 #endif // MEDIA_AUDIO_VIRTUAL_AUDIO_OUTPUT_STREAM_H_