Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(684)

Unified Diff: content/browser/renderer_host/media/web_contents_audio_input_stream.h

Issue 11413078: Tab Audio Capture: Browser-side connect/disconnect functionality. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor tweaks and added some useful comments. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..8a55b9e51b63e03c134d8a2ef338c2eaddefa041
--- /dev/null
+++ b/content/browser/renderer_host/media/web_contents_audio_input_stream.h
@@ -0,0 +1,96 @@
+// 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 <map>
+#include <string>
+
+#include "base/memory/ref_counted.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"
+#include "media/audio/audio_parameters.h"
+
+namespace content {
+
+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,
+ const media::AudioParameters& params);
+
+ // 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 |callback|, which is providing data in the format
+ // specified by |params|.
+ void AddInput(media::AudioOutputStream::AudioSourceCallback* callback,
+ const media::AudioParameters& params);
+
+ // Stop pulling data from |callback|. After this method returns, the caller
+ // can safely destroy the callback.
+ void RemoveInput(media::AudioOutputStream::AudioSourceCallback* callback);
+
+ private:
+ friend class base::RefCountedThreadSafe<WebContentsAudioInputStream>;
+
+ enum State {
+ kConstructed,
+ kOpened,
+ kRecording,
+ kClosed
+ };
+
+ WebContentsAudioInputStream(int render_process_id, int render_view_id,
+ const media::AudioParameters& params);
+
+ 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);
+
+ // Parameters for audio produced by this instance.
+ const media::AudioParameters params_;
+
+ // 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_;
+
+ // Tracks swapping of render views to maintain mirroring of the correct
+ // render view.
+ scoped_refptr<WebContentsCaptureUtil::RenderViewTracker> tracker_;
+
+ // Current set of sources of audio data and associated audio parameters.
+ typedef std::map<media::AudioOutputStream::AudioSourceCallback*,
+ media::AudioParameters> SourceParamsMap;
+ SourceParamsMap source_params_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebContentsAudioInputStream);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_AUDIO_INPUT_STREAM_H_

Powered by Google App Engine
This is Rietveld 408576698