1 // Copyright (c) 2013 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 // An AudioInputStream which provides a loop-back of all audio output generated
6 // by the entire RenderFrame tree associated with a WebContents instance. The
7 // single stream of data is produced by format-converting and mixing all audio
8 // output streams. As the RenderFrameHost tree mutates (e.g., due to page
9 // navigations, or crashes/reloads), the stream will continue without
10 // interruption. In other words, WebContentsAudioInputStream provides tab-level
13 #ifndef CONTENT_BROWSER_MEDIA_CAPTURE_WEB_CONTENTS_AUDIO_INPUT_STREAM_H_
14 #define CONTENT_BROWSER_MEDIA_CAPTURE_WEB_CONTENTS_AUDIO_INPUT_STREAM_H_
18 #include "base/memory/ref_counted.h"
19 #include "content/common/content_export.h"
20 #include "media/audio/audio_io.h"
23 class SingleThreadTaskRunner
;
27 class AudioParameters
;
28 class VirtualAudioInputStream
;
33 class AudioMirroringManager
;
34 class WebContentsTracker
;
36 class CONTENT_EXPORT WebContentsAudioInputStream
37 : NON_EXPORTED_BASE(public media::AudioInputStream
) {
39 // media::AudioInputStream implementation
41 void Start(AudioInputCallback
* callback
) override
;
43 void Close() override
;
44 double GetMaxVolume() override
;
45 void SetVolume(double volume
) override
;
46 double GetVolume() override
;
47 bool SetAutomaticGainControl(bool enabled
) override
;
48 bool GetAutomaticGainControl() override
;
49 bool IsMuted() override
;
51 // Create a new audio mirroring session, or return NULL on error. |device_id|
52 // should be in the format accepted by
53 // WebContentsCaptureUtil::ExtractTabCaptureTarget(). The caller must
54 // guarantee Close() is called on the returned object so that it may
56 // |worker_task_runner| is the task runner on which AudioInputCallback methods
57 // are called and may or may not be the single thread that invokes the
58 // AudioInputStream methods.
59 static WebContentsAudioInputStream
* Create(
60 const std::string
& device_id
,
61 const media::AudioParameters
& params
,
62 const scoped_refptr
<base::SingleThreadTaskRunner
>& worker_task_runner
,
63 AudioMirroringManager
* audio_mirroring_manager
);
66 friend class WebContentsAudioInputStreamTest
;
68 // Maintain most state and functionality in an internal ref-counted
69 // implementation class. This object must outlive a call to Close(), until
70 // the shutdown tasks running on other threads complete: The
71 // AudioMirroringManager on the IO thread, the WebContentsTracker on the UI
72 // thread, and the VirtualAudioOuputStreams on the audio thread.
75 WebContentsAudioInputStream(
76 int render_process_id
, int main_render_frame_id
,
77 AudioMirroringManager
* mirroring_manager
,
78 const scoped_refptr
<WebContentsTracker
>& tracker
,
79 media::VirtualAudioInputStream
* mixer_stream
);
81 ~WebContentsAudioInputStream() override
;
83 scoped_refptr
<Impl
> impl_
;
85 DISALLOW_COPY_AND_ASSIGN(WebContentsAudioInputStream
);
88 } // namespace content
90 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_WEB_CONTENTS_AUDIO_INPUT_STREAM_H_