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" |
11 #include "content/public/browser/render_frame_host.h" | 11 #include "content/public/browser/render_frame_host.h" |
12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
13 #include "media/audio/audio_io.h" | 13 #include "media/audio/audio_io.h" |
14 #include "media/audio/audio_manager.h" | 14 #include "media/audio/audio_manager.h" |
15 #include "media/audio/fake_audio_consumer.h" | 15 #include "media/audio/fake_audio_worker.h" |
16 #include "media/base/bind_to_current_loop.h" | 16 #include "media/base/bind_to_current_loop.h" |
17 | 17 |
18 namespace content { | 18 namespace content { |
19 | 19 |
20 namespace { | 20 namespace { |
21 | 21 |
22 // An AudioOutputStream that pumps audio data, but does nothing with it. | 22 // An AudioOutputStream that pumps audio data, but does nothing with it. |
23 // Pumping the audio data is necessary because video playback is synchronized to | 23 // Pumping the audio data is necessary because video playback is synchronized to |
24 // the audio stream and will freeze otherwise. | 24 // the audio stream and will freeze otherwise. |
25 // | 25 // |
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 : worker_(media::AudioManager::Get()->GetWorkerTaskRunner(), params), |
| 34 audio_bus_(media::AudioBus::Create(params)) {} |
34 | 35 |
35 // AudioOutputStream implementation. | 36 // AudioOutputStream implementation. |
36 bool Open() override { return true; } | 37 bool Open() override { return true; } |
37 void Start(AudioSourceCallback* callback) override { | 38 void Start(AudioSourceCallback* callback) override { |
38 consumer_.Start(base::Bind(&AudioDiscarder::FetchAudioData, callback)); | 39 worker_.Start(base::Bind(&AudioDiscarder::FetchAudioData, |
| 40 base::Unretained(this), |
| 41 callback)); |
39 } | 42 } |
40 void Stop() override { consumer_.Stop(); } | 43 void Stop() override { worker_.Stop(); } |
41 void SetVolume(double volume) override {} | 44 void SetVolume(double volume) override {} |
42 void GetVolume(double* volume) override { *volume = 0; } | 45 void GetVolume(double* volume) override { *volume = 0; } |
43 void Close() override { delete this; } | 46 void Close() override { delete this; } |
44 | 47 |
45 private: | 48 private: |
46 ~AudioDiscarder() override {} | 49 ~AudioDiscarder() override {} |
47 | 50 |
48 static void FetchAudioData(AudioSourceCallback* callback, | 51 void FetchAudioData(AudioSourceCallback* callback) { |
49 media::AudioBus* audio_bus) { | 52 callback->OnMoreData(audio_bus_.get(), 0); |
50 callback->OnMoreData(audio_bus, 0); | |
51 } | 53 } |
52 | 54 |
53 // Calls FetchAudioData() at regular intervals and discards the data. | 55 // Calls FetchAudioData() at regular intervals and discards the data. |
54 media::FakeAudioConsumer consumer_; | 56 media::FakeAudioWorker worker_; |
| 57 scoped_ptr<media::AudioBus> audio_bus_; |
55 | 58 |
56 DISALLOW_COPY_AND_ASSIGN(AudioDiscarder); | 59 DISALLOW_COPY_AND_ASSIGN(AudioDiscarder); |
57 }; | 60 }; |
58 | 61 |
59 } // namespace | 62 } // namespace |
60 | 63 |
61 // A simple AudioMirroringManager::MirroringDestination implementation that | 64 // A simple AudioMirroringManager::MirroringDestination implementation that |
62 // identifies the audio streams rendered by a WebContents and provides | 65 // identifies the audio streams rendered by a WebContents and provides |
63 // AudioDiscarders to AudioMirroringManager. | 66 // AudioDiscarders to AudioMirroringManager. |
64 class WebContentsAudioMuter::MuteDestination | 67 class WebContentsAudioMuter::MuteDestination |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 is_muting_ = false; | 146 is_muting_ = false; |
144 BrowserThread::PostTask( | 147 BrowserThread::PostTask( |
145 BrowserThread::IO, | 148 BrowserThread::IO, |
146 FROM_HERE, | 149 FROM_HERE, |
147 base::Bind(&AudioMirroringManager::StopMirroring, | 150 base::Bind(&AudioMirroringManager::StopMirroring, |
148 base::Unretained(AudioMirroringManager::GetInstance()), | 151 base::Unretained(AudioMirroringManager::GetInstance()), |
149 destination_)); | 152 destination_)); |
150 } | 153 } |
151 | 154 |
152 } // namespace content | 155 } // namespace content |
OLD | NEW |