| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/media/capture/web_contents_audio_muter.h" | 5 #include "content/browser/media/capture/web_contents_audio_muter.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "content/browser/media/capture/audio_mirroring_manager.h" | 9 #include "content/browser/media/capture/audio_mirroring_manager.h" |
| 10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/browser_thread.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // TODO(miu): media::FakeAudioOutputStream does pretty much the same thing as | 26 // TODO(miu): media::FakeAudioOutputStream does pretty much the same thing as |
| 27 // this class, but requires construction/destruction via media::AudioManagerBase | 27 // this class, but requires construction/destruction via media::AudioManagerBase |
| 28 // on the audio thread. Once that's fixed, this class will no longer be needed. | 28 // on the audio thread. Once that's fixed, this class will no longer be needed. |
| 29 // http://crbug.com/416278 | 29 // http://crbug.com/416278 |
| 30 class AudioDiscarder : public media::AudioOutputStream { | 30 class AudioDiscarder : public media::AudioOutputStream { |
| 31 public: | 31 public: |
| 32 explicit AudioDiscarder(const media::AudioParameters& params) | 32 explicit AudioDiscarder(const media::AudioParameters& params) |
| 33 : consumer_(media::AudioManager::Get()->GetWorkerTaskRunner(), params) {} | 33 : consumer_(media::AudioManager::Get()->GetWorkerTaskRunner(), params) {} |
| 34 | 34 |
| 35 // AudioOutputStream implementation. | 35 // AudioOutputStream implementation. |
| 36 virtual bool Open() OVERRIDE { return true; } | 36 virtual bool Open() override { return true; } |
| 37 virtual void Start(AudioSourceCallback* callback) OVERRIDE { | 37 virtual void Start(AudioSourceCallback* callback) override { |
| 38 consumer_.Start(base::Bind(&AudioDiscarder::FetchAudioData, callback)); | 38 consumer_.Start(base::Bind(&AudioDiscarder::FetchAudioData, callback)); |
| 39 } | 39 } |
| 40 virtual void Stop() OVERRIDE { consumer_.Stop(); } | 40 virtual void Stop() override { consumer_.Stop(); } |
| 41 virtual void SetVolume(double volume) OVERRIDE {} | 41 virtual void SetVolume(double volume) override {} |
| 42 virtual void GetVolume(double* volume) OVERRIDE { *volume = 0; } | 42 virtual void GetVolume(double* volume) override { *volume = 0; } |
| 43 virtual void Close() OVERRIDE { delete this; } | 43 virtual void Close() override { delete this; } |
| 44 | 44 |
| 45 private: | 45 private: |
| 46 virtual ~AudioDiscarder() {} | 46 virtual ~AudioDiscarder() {} |
| 47 | 47 |
| 48 static void FetchAudioData(AudioSourceCallback* callback, | 48 static void FetchAudioData(AudioSourceCallback* callback, |
| 49 media::AudioBus* audio_bus) { | 49 media::AudioBus* audio_bus) { |
| 50 callback->OnMoreData(audio_bus, 0); | 50 callback->OnMoreData(audio_bus, 0); |
| 51 } | 51 } |
| 52 | 52 |
| 53 // Calls FetchAudioData() at regular intervals and discards the data. | 53 // Calls FetchAudioData() at regular intervals and discards the data. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 70 | 70 |
| 71 private: | 71 private: |
| 72 friend class base::RefCountedThreadSafe<MuteDestination>; | 72 friend class base::RefCountedThreadSafe<MuteDestination>; |
| 73 | 73 |
| 74 typedef AudioMirroringManager::SourceFrameRef SourceFrameRef; | 74 typedef AudioMirroringManager::SourceFrameRef SourceFrameRef; |
| 75 | 75 |
| 76 virtual ~MuteDestination() {} | 76 virtual ~MuteDestination() {} |
| 77 | 77 |
| 78 virtual void QueryForMatches( | 78 virtual void QueryForMatches( |
| 79 const std::set<SourceFrameRef>& candidates, | 79 const std::set<SourceFrameRef>& candidates, |
| 80 const MatchesCallback& results_callback) OVERRIDE { | 80 const MatchesCallback& results_callback) override { |
| 81 BrowserThread::PostTask( | 81 BrowserThread::PostTask( |
| 82 BrowserThread::UI, | 82 BrowserThread::UI, |
| 83 FROM_HERE, | 83 FROM_HERE, |
| 84 base::Bind(&MuteDestination::QueryForMatchesOnUIThread, | 84 base::Bind(&MuteDestination::QueryForMatchesOnUIThread, |
| 85 this, | 85 this, |
| 86 candidates, | 86 candidates, |
| 87 media::BindToCurrentLoop(results_callback))); | 87 media::BindToCurrentLoop(results_callback))); |
| 88 } | 88 } |
| 89 | 89 |
| 90 void QueryForMatchesOnUIThread(const std::set<SourceFrameRef>& candidates, | 90 void QueryForMatchesOnUIThread(const std::set<SourceFrameRef>& candidates, |
| 91 const MatchesCallback& results_callback) { | 91 const MatchesCallback& results_callback) { |
| 92 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 92 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 93 std::set<SourceFrameRef> matches; | 93 std::set<SourceFrameRef> matches; |
| 94 // Add each ID to |matches| if it maps to a RenderFrameHost that maps to the | 94 // Add each ID to |matches| if it maps to a RenderFrameHost that maps to the |
| 95 // WebContents being muted. | 95 // WebContents being muted. |
| 96 for (std::set<SourceFrameRef>::const_iterator i = candidates.begin(); | 96 for (std::set<SourceFrameRef>::const_iterator i = candidates.begin(); |
| 97 i != candidates.end(); ++i) { | 97 i != candidates.end(); ++i) { |
| 98 WebContents* const contents_containing_frame = | 98 WebContents* const contents_containing_frame = |
| 99 WebContents::FromRenderFrameHost( | 99 WebContents::FromRenderFrameHost( |
| 100 RenderFrameHost::FromID(i->first, i->second)); | 100 RenderFrameHost::FromID(i->first, i->second)); |
| 101 if (contents_containing_frame == web_contents_) | 101 if (contents_containing_frame == web_contents_) |
| 102 matches.insert(*i); | 102 matches.insert(*i); |
| 103 } | 103 } |
| 104 results_callback.Run(matches); | 104 results_callback.Run(matches); |
| 105 } | 105 } |
| 106 | 106 |
| 107 virtual media::AudioOutputStream* AddInput( | 107 virtual media::AudioOutputStream* AddInput( |
| 108 const media::AudioParameters& params) OVERRIDE { | 108 const media::AudioParameters& params) override { |
| 109 return new AudioDiscarder(params); | 109 return new AudioDiscarder(params); |
| 110 } | 110 } |
| 111 | 111 |
| 112 WebContents* const web_contents_; | 112 WebContents* const web_contents_; |
| 113 | 113 |
| 114 DISALLOW_COPY_AND_ASSIGN(MuteDestination); | 114 DISALLOW_COPY_AND_ASSIGN(MuteDestination); |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 WebContentsAudioMuter::WebContentsAudioMuter(WebContents* web_contents) | 117 WebContentsAudioMuter::WebContentsAudioMuter(WebContents* web_contents) |
| 118 : destination_(new MuteDestination(web_contents)), is_muting_(false) { | 118 : destination_(new MuteDestination(web_contents)), is_muting_(false) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 144 is_muting_ = false; | 144 is_muting_ = false; |
| 145 BrowserThread::PostTask( | 145 BrowserThread::PostTask( |
| 146 BrowserThread::IO, | 146 BrowserThread::IO, |
| 147 FROM_HERE, | 147 FROM_HERE, |
| 148 base::Bind(&AudioMirroringManager::StopMirroring, | 148 base::Bind(&AudioMirroringManager::StopMirroring, |
| 149 base::Unretained(AudioMirroringManager::GetInstance()), | 149 base::Unretained(AudioMirroringManager::GetInstance()), |
| 150 destination_)); | 150 destination_)); |
| 151 } | 151 } |
| 152 | 152 |
| 153 } // namespace content | 153 } // namespace content |
| OLD | NEW |