Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / content / browser / media / capture / web_contents_audio_input_stream.h
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.
12
13 #ifndef CONTENT_BROWSER_MEDIA_CAPTURE_WEB_CONTENTS_AUDIO_INPUT_STREAM_H_
14 #define CONTENT_BROWSER_MEDIA_CAPTURE_WEB_CONTENTS_AUDIO_INPUT_STREAM_H_
15
16 #include <string>
17
18 #include "base/memory/ref_counted.h"
19 #include "content/common/content_export.h"
20 #include "media/audio/audio_io.h"
21
22 namespace base {
23 class SingleThreadTaskRunner;
24 }
25
26 namespace media {
27 class AudioParameters;
28 class VirtualAudioInputStream;
29 }
30
31 namespace content {
32
33 class AudioMirroringManager;
34 class WebContentsTracker;
35
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   void SetAutomaticGainControl(bool enabled) override;
48   bool GetAutomaticGainControl() override;
49   bool IsMuted() override;
50
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);
64
65  private:
66   friend class WebContentsAudioInputStreamTest;
67
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;
74
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);
80
81   ~WebContentsAudioInputStream() override;
82
83   scoped_refptr<Impl> impl_;
84
85   DISALLOW_COPY_AND_ASSIGN(WebContentsAudioInputStream);
86 };
87
88 }  // namespace content
89
90 #endif  // CONTENT_BROWSER_MEDIA_CAPTURE_WEB_CONTENTS_AUDIO_INPUT_STREAM_H_