Chromium Code Reviews| Index: content/browser/renderer_host/media/web_contents_audio_input_stream.h |
| diff --git a/content/browser/renderer_host/media/web_contents_audio_input_stream.h b/content/browser/renderer_host/media/web_contents_audio_input_stream.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e6e9012a0a6841fecc94d09f9bafb2fd1b452acd |
| --- /dev/null |
| +++ b/content/browser/renderer_host/media/web_contents_audio_input_stream.h |
| @@ -0,0 +1,94 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_AUDIO_INPUT_STREAM_H_ |
| +#define CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_AUDIO_INPUT_STREAM_H_ |
| + |
| +#include <set> |
| +#include <string> |
| + |
| +#include "base/memory/ref_counted.h" |
| +#include "base/synchronization/lock.h" |
| +#include "base/threading/thread_checker.h" |
| +#include "content/browser/renderer_host/media/web_contents_capture_util.h" |
| +#include "content/common/content_export.h" |
| +#include "media/audio/audio_io.h" |
| + |
| +namespace media { |
| +class DivertedAudioOutputStream; |
| +} |
| + |
| +namespace content { |
| + |
| +class AudioRendererHost; |
| + |
| +class CONTENT_EXPORT WebContentsAudioInputStream |
| + : NON_EXPORTED_BASE(public media::AudioInputStream), |
| + public base::RefCountedThreadSafe<WebContentsAudioInputStream> { |
| + public: |
| + // Construct from the a |device_id| string of the form: |
| + // "render_process_id:render_view_id" |
| + static WebContentsAudioInputStream* Create(const std::string& device_id); |
| + |
| + // media::AudioInputStream implementation |
| + virtual bool Open() OVERRIDE; |
| + virtual void Start(AudioInputCallback* callback) OVERRIDE; |
| + virtual void Stop() OVERRIDE; |
| + virtual void Close() OVERRIDE; |
| + virtual double GetMaxVolume() OVERRIDE; |
| + virtual void SetVolume(double volume) OVERRIDE; |
| + virtual double GetVolume() OVERRIDE; |
| + virtual void SetAutomaticGainControl(bool enabled) OVERRIDE; |
| + virtual bool GetAutomaticGainControl() OVERRIDE; |
| + |
| + // Begin pulling data from the given AudioOutputStream. Caller retains |
| + // ownership. |
| + void AddAudioOutputStream(media::DivertedAudioOutputStream* aos); |
| + |
| + // Stop pulling data from the given AudioOutputStream. After this method |
| + // returns, the caller can safely destroy the AOS. |
| + void RemoveAudioOutputStream(media::DivertedAudioOutputStream* aos); |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<WebContentsAudioInputStream>; |
| + |
| + enum State { |
| + kConstructed, |
| + kOpened, |
| + kRecording, |
| + kClosed |
| + }; |
| + |
| + WebContentsAudioInputStream(int render_process_id, int render_view_id); |
| + |
| + virtual ~WebContentsAudioInputStream(); |
| + |
| + // Called by RenderViewTracker when the the target of the audio mirroring has |
| + // changed. |
| + void OnTargetChanged(int render_process_id, int render_view_id); |
| + |
| + // Ensures calls to the media::AudioInputStream methods all occur from the |
| + // same thread. |
| + base::ThreadChecker thread_checker_; |
| + |
| + State state_; |
| + |
| + // Current audio mirroring target. |
| + int target_render_process_id_; |
| + int target_render_view_id_; |
| + scoped_refptr<AudioRendererHost> target_host_; |
|
Alpha Left Google
2012/11/26 22:59:59
Owning AudioRendererHost scares me.. AudioRenderer
miu
2012/11/28 05:05:01
Done.
|
| + |
| + // Tracks swapping of render views to maintain mirroring of the correct |
| + // render view. |
| + scoped_refptr<WebContentsCaptureUtil::RenderViewTracker> tracker_; |
| + |
| + base::Lock streams_lock_; |
| + std::set<media::DivertedAudioOutputStream*> streams_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WebContentsAudioInputStream); |
| +}; |
| + |
| +} // namespace content |
| + |
| +#endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_AUDIO_INPUT_STREAM_H_ |