Supervised user import: Listen for profile creation/deletion
[chromium-blink-merge.git] / content / browser / media / capture / web_contents_audio_input_stream.h
blobff8074d4f0e30001a5edbb85070716508d51beea
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.
4 //
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
11 // audio mirroring.
13 #ifndef CONTENT_BROWSER_MEDIA_CAPTURE_WEB_CONTENTS_AUDIO_INPUT_STREAM_H_
14 #define CONTENT_BROWSER_MEDIA_CAPTURE_WEB_CONTENTS_AUDIO_INPUT_STREAM_H_
16 #include <string>
18 #include "base/memory/ref_counted.h"
19 #include "content/common/content_export.h"
20 #include "media/audio/audio_io.h"
22 namespace base {
23 class SingleThreadTaskRunner;
26 namespace media {
27 class AudioParameters;
28 class VirtualAudioInputStream;
31 namespace content {
33 class AudioMirroringManager;
34 class WebContentsTracker;
36 class CONTENT_EXPORT WebContentsAudioInputStream
37 : NON_EXPORTED_BASE(public media::AudioInputStream) {
38 public:
39 // media::AudioInputStream implementation
40 bool Open() override;
41 void Start(AudioInputCallback* callback) override;
42 void Stop() 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
55 // self-destruct.
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);
65 private:
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.
73 class Impl;
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_