Save errno for logging before potentially overwriting it.
[chromium-blink-merge.git] / content / browser / renderer_host / media / web_contents_audio_input_stream.h
blob486547ecaa217b9ad8460adfd818a40972e9f03e
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 RenderView associated with a WebContents instance. The single stream
7 // of data is produced by format-converting and mixing all audio output from a
8 // RenderView. In other words, WebContentsAudioInputStream provides tab-level
9 // audio mirroring.
11 // The implementation observes a WebContents instance (which represents a
12 // browser tab) so that it can track the replacement of RenderViews due to
13 // navigation, crash/reload, etc. events; and take appropriate actions to
14 // provide a seamless, uninterrupted mirroring experience.
16 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_AUDIO_INPUT_STREAM_H_
17 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_AUDIO_INPUT_STREAM_H_
19 #include <string>
21 #include "base/memory/ref_counted.h"
22 #include "content/common/content_export.h"
23 #include "media/audio/audio_io.h"
25 namespace base {
26 class MessageLoopProxy;
29 namespace media {
30 class AudioParameters;
31 class VirtualAudioInputStream;
34 namespace content {
36 class AudioMirroringManager;
37 class WebContentsTracker;
39 class CONTENT_EXPORT WebContentsAudioInputStream
40 : NON_EXPORTED_BASE(public media::AudioInputStream) {
41 public:
42 // media::AudioInputStream implementation
43 virtual bool Open() OVERRIDE;
44 virtual void Start(AudioInputCallback* callback) OVERRIDE;
45 virtual void Stop() OVERRIDE;
46 virtual void Close() OVERRIDE;
47 virtual double GetMaxVolume() OVERRIDE;
48 virtual void SetVolume(double volume) OVERRIDE;
49 virtual double GetVolume() OVERRIDE;
50 virtual void SetAutomaticGainControl(bool enabled) OVERRIDE;
51 virtual bool GetAutomaticGainControl() OVERRIDE;
53 // Create a new audio mirroring session, or return NULL on error. |device_id|
54 // should be in the format accepted by
55 // WebContentsCaptureUtil::ExtractTabCaptureTarget(). The caller must
56 // guarantee Close() is called on the returned object so that it may
57 // self-destruct.
58 // |worker_loop| is the loop on which AudioInputCallback methods are called
59 // and may or may not be the single thread that invokes the AudioInputStream
60 // methods.
61 static WebContentsAudioInputStream* Create(
62 const std::string& device_id,
63 const media::AudioParameters& params,
64 const scoped_refptr<base::MessageLoopProxy>& worker_loop,
65 AudioMirroringManager* audio_mirroring_manager);
67 private:
68 friend class WebContentsAudioInputStreamTest;
70 // Maintain most state and functionality in an internal ref-counted
71 // implementation class. This object must outlive a call to Close(), until
72 // the shutdown tasks running on other threads complete: The
73 // AudioMirroringManager on the IO thread, the WebContentsTracker on the UI
74 // thread, and the VirtualAudioOuputStreams on the audio thread.
75 class Impl;
77 WebContentsAudioInputStream(
78 int render_process_id, int render_view_id,
79 AudioMirroringManager* mirroring_manager,
80 const scoped_refptr<WebContentsTracker>& tracker,
81 media::VirtualAudioInputStream* mixer_stream);
83 virtual ~WebContentsAudioInputStream();
85 scoped_refptr<Impl> impl_;
87 DISALLOW_COPY_AND_ASSIGN(WebContentsAudioInputStream);
90 } // namespace content
92 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_AUDIO_INPUT_STREAM_H_