OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_AUDIO_INPUT_STREAM_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_AUDIO_INPUT_STREAM_H_ |
| 7 |
| 8 #include <map> |
| 9 #include <string> |
| 10 |
| 11 #include "base/memory/ref_counted.h" |
| 12 #include "base/threading/thread_checker.h" |
| 13 #include "content/browser/renderer_host/media/web_contents_capture_util.h" |
| 14 #include "content/common/content_export.h" |
| 15 #include "media/audio/audio_io.h" |
| 16 #include "media/audio/audio_parameters.h" |
| 17 |
| 18 namespace content { |
| 19 |
| 20 class CONTENT_EXPORT WebContentsAudioInputStream |
| 21 : NON_EXPORTED_BASE(public media::AudioInputStream), |
| 22 public base::RefCountedThreadSafe<WebContentsAudioInputStream> { |
| 23 public: |
| 24 // Construct from the a |device_id| string of the form: |
| 25 // "render_process_id:render_view_id" |
| 26 static WebContentsAudioInputStream* Create( |
| 27 const std::string& device_id, |
| 28 const media::AudioParameters& params); |
| 29 |
| 30 // media::AudioInputStream implementation |
| 31 virtual bool Open() OVERRIDE; |
| 32 virtual void Start(AudioInputCallback* callback) OVERRIDE; |
| 33 virtual void Stop() OVERRIDE; |
| 34 virtual void Close() OVERRIDE; |
| 35 virtual double GetMaxVolume() OVERRIDE; |
| 36 virtual void SetVolume(double volume) OVERRIDE; |
| 37 virtual double GetVolume() OVERRIDE; |
| 38 virtual void SetAutomaticGainControl(bool enabled) OVERRIDE; |
| 39 virtual bool GetAutomaticGainControl() OVERRIDE; |
| 40 |
| 41 // Begin pulling data from |callback|, which is providing data in the format |
| 42 // specified by |params|. |
| 43 void AddInput(media::AudioOutputStream::AudioSourceCallback* callback, |
| 44 const media::AudioParameters& params); |
| 45 |
| 46 // Stop pulling data from |callback|. After this method returns, the caller |
| 47 // can safely destroy the callback. |
| 48 void RemoveInput(media::AudioOutputStream::AudioSourceCallback* callback); |
| 49 |
| 50 private: |
| 51 friend class base::RefCountedThreadSafe<WebContentsAudioInputStream>; |
| 52 |
| 53 enum State { |
| 54 kConstructed, |
| 55 kOpened, |
| 56 kRecording, |
| 57 kClosed |
| 58 }; |
| 59 |
| 60 WebContentsAudioInputStream(int render_process_id, int render_view_id, |
| 61 const media::AudioParameters& params); |
| 62 |
| 63 virtual ~WebContentsAudioInputStream(); |
| 64 |
| 65 // Called by RenderViewTracker when the the target of the audio mirroring has |
| 66 // changed. |
| 67 void OnTargetChanged(int render_process_id, int render_view_id); |
| 68 |
| 69 // Parameters for audio produced by this instance. |
| 70 const media::AudioParameters params_; |
| 71 |
| 72 // Ensures calls to the media::AudioInputStream methods all occur from the |
| 73 // same thread. |
| 74 base::ThreadChecker thread_checker_; |
| 75 |
| 76 State state_; |
| 77 |
| 78 // Current audio mirroring target. |
| 79 int target_render_process_id_; |
| 80 int target_render_view_id_; |
| 81 |
| 82 // Tracks swapping of render views to maintain mirroring of the correct |
| 83 // render view. |
| 84 scoped_refptr<WebContentsCaptureUtil::RenderViewTracker> tracker_; |
| 85 |
| 86 // Current set of sources of audio data and associated audio parameters. |
| 87 typedef std::map<media::AudioOutputStream::AudioSourceCallback*, |
| 88 media::AudioParameters> SourceParamsMap; |
| 89 SourceParamsMap source_params_; |
| 90 |
| 91 DISALLOW_COPY_AND_ASSIGN(WebContentsAudioInputStream); |
| 92 }; |
| 93 |
| 94 } // namespace content |
| 95 |
| 96 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_WEB_CONTENTS_AUDIO_INPUT_STREAM_H
_ |
OLD | NEW |