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
40 virtual bool Open() OVERRIDE;
41 virtual void Start(AudioInputCallback* callback) OVERRIDE;
42 virtual void Stop() OVERRIDE;
43 virtual void Close() OVERRIDE;
44 virtual double GetMaxVolume() OVERRIDE;
45 virtual void SetVolume(double volume) OVERRIDE;
46 virtual double GetVolume() OVERRIDE;
47 virtual void SetAutomaticGainControl(bool enabled) OVERRIDE;
48 virtual bool GetAutomaticGainControl() OVERRIDE;
50 // Create a new audio mirroring session, or return NULL on error. |device_id|
51 // should be in the format accepted by
52 // WebContentsCaptureUtil::ExtractTabCaptureTarget(). The caller must
53 // guarantee Close() is called on the returned object so that it may
55 // |worker_task_runner| is the task runner on which AudioInputCallback methods
56 // are called and may or may not be the single thread that invokes the
57 // AudioInputStream methods.
58 static WebContentsAudioInputStream* Create(
59 const std::string& device_id,
60 const media::AudioParameters& params,
61 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner,
62 AudioMirroringManager* audio_mirroring_manager);
65 friend class WebContentsAudioInputStreamTest;
67 // Maintain most state and functionality in an internal ref-counted
68 // implementation class. This object must outlive a call to Close(), until
69 // the shutdown tasks running on other threads complete: The
70 // AudioMirroringManager on the IO thread, the WebContentsTracker on the UI
71 // thread, and the VirtualAudioOuputStreams on the audio thread.
74 WebContentsAudioInputStream(
75 int render_process_id, int main_render_frame_id,
76 AudioMirroringManager* mirroring_manager,
77 const scoped_refptr<WebContentsTracker>& tracker,
78 media::VirtualAudioInputStream* mixer_stream);
80 virtual ~WebContentsAudioInputStream();
82 scoped_refptr<Impl> impl_;
84 DISALLOW_COPY_AND_ASSIGN(WebContentsAudioInputStream);
87 } // namespace content
89 #endif // CONTENT_BROWSER_MEDIA_CAPTURE_WEB_CONTENTS_AUDIO_INPUT_STREAM_H_