| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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/renderer_host/media/audio_renderer_host.h" | 5 #include "content/browser/renderer_host/media/audio_renderer_host.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/memory/shared_memory.h" | 14 #include "base/memory/shared_memory.h" |
| 15 #include "base/metrics/histogram.h" | 15 #include "base/metrics/histogram.h" |
| 16 #include "base/process/process.h" | 16 #include "base/process/process.h" |
| 17 #include "content/browser/bad_message.h" | 17 #include "content/browser/bad_message.h" |
| 18 #include "content/browser/browser_main_loop.h" | 18 #include "content/browser/browser_main_loop.h" |
| 19 #include "content/browser/child_process_security_policy_impl.h" | 19 #include "content/browser/child_process_security_policy_impl.h" |
| 20 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 20 #include "content/browser/loader/resource_dispatcher_host_impl.h" |
| 21 #include "content/browser/media/audio_stream_monitor.h" | 21 #include "content/browser/media/audio_stream_monitor.h" |
| 22 #include "content/browser/media/capture/audio_mirroring_manager.h" | 22 #include "content/browser/media/capture/audio_mirroring_manager.h" |
| 23 #include "content/browser/media/media_internals.h" | 23 #include "content/browser/media/media_internals.h" |
| 24 #include "content/browser/media/media_web_contents_observer.h" |
| 24 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | 25 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
| 25 #include "content/browser/renderer_host/media/audio_sync_reader.h" | 26 #include "content/browser/renderer_host/media/audio_sync_reader.h" |
| 26 #include "content/browser/renderer_host/media/media_stream_manager.h" | 27 #include "content/browser/renderer_host/media/media_stream_manager.h" |
| 27 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" | 28 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" |
| 28 #include "content/browser/renderer_host/render_widget_host_impl.h" | 29 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 29 #include "content/common/media/audio_messages.h" | 30 #include "content/common/media/audio_messages.h" |
| 30 #include "content/public/browser/content_browser_client.h" | 31 #include "content/public/browser/content_browser_client.h" |
| 31 #include "content/public/browser/media_device_id.h" | 32 #include "content/public/browser/media_device_id.h" |
| 32 #include "content/public/browser/media_observer.h" | 33 #include "content/public/browser/media_observer.h" |
| 33 #include "content/public/browser/render_frame_host.h" | 34 #include "content/public/browser/render_frame_host.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 base::SharedMemory* shared_memory() { | 176 base::SharedMemory* shared_memory() { |
| 176 return shared_memory_.get(); | 177 return shared_memory_.get(); |
| 177 } | 178 } |
| 178 | 179 |
| 179 media::AudioOutputController::SyncReader* reader() const { | 180 media::AudioOutputController::SyncReader* reader() const { |
| 180 return reader_.get(); | 181 return reader_.get(); |
| 181 } | 182 } |
| 182 | 183 |
| 183 bool playing() const { return playing_; } | 184 bool playing() const { return playing_; } |
| 184 void set_playing(bool playing) { playing_ = playing; } | 185 void set_playing(bool playing) { playing_ = playing; } |
| 186 void update_last_pause_time() { last_pause_time_ = base::TimeTicks::Now(); } |
| 187 base::TimeTicks last_pause_time() { return last_pause_time_; } |
| 185 | 188 |
| 186 private: | 189 private: |
| 187 // media::AudioOutputController::EventHandler implementation. | 190 // media::AudioOutputController::EventHandler implementation. |
| 188 void OnCreated() override; | 191 void OnCreated() override; |
| 189 void OnPlaying() override; | 192 void OnPlaying() override; |
| 190 void OnPaused() override; | 193 void OnPaused() override; |
| 191 void OnError() override; | 194 void OnError() override; |
| 192 | 195 |
| 193 AudioRendererHost* const host_; | 196 AudioRendererHost* const host_; |
| 194 const int stream_id_; | 197 const int stream_id_; |
| 195 | 198 |
| 196 // The routing ID of the source RenderFrame. | 199 // The routing ID of the source RenderFrame. |
| 197 const int render_frame_id_; | 200 const int render_frame_id_; |
| 198 | 201 |
| 199 // Shared memory for transmission of the audio data. Used by |reader_|. | 202 // Shared memory for transmission of the audio data. Used by |reader_|. |
| 200 const scoped_ptr<base::SharedMemory> shared_memory_; | 203 const scoped_ptr<base::SharedMemory> shared_memory_; |
| 201 | 204 |
| 202 // The synchronous reader to be used by |controller_|. | 205 // The synchronous reader to be used by |controller_|. |
| 203 const scoped_ptr<media::AudioOutputController::SyncReader> reader_; | 206 const scoped_ptr<media::AudioOutputController::SyncReader> reader_; |
| 204 | 207 |
| 205 // The AudioOutputController that manages the audio stream. | 208 // The AudioOutputController that manages the audio stream. |
| 206 const scoped_refptr<media::AudioOutputController> controller_; | 209 const scoped_refptr<media::AudioOutputController> controller_; |
| 207 | 210 |
| 208 bool playing_; | 211 bool playing_; |
| 212 |
| 213 base::TimeTicks last_pause_time_; |
| 209 }; | 214 }; |
| 210 | 215 |
| 211 AudioRendererHost::AudioEntry::AudioEntry( | 216 AudioRendererHost::AudioEntry::AudioEntry( |
| 212 AudioRendererHost* host, | 217 AudioRendererHost* host, |
| 213 int stream_id, | 218 int stream_id, |
| 214 int render_frame_id, | 219 int render_frame_id, |
| 215 const media::AudioParameters& params, | 220 const media::AudioParameters& params, |
| 216 const std::string& output_device_id, | 221 const std::string& output_device_id, |
| 217 scoped_ptr<base::SharedMemory> shared_memory, | 222 scoped_ptr<base::SharedMemory> shared_memory, |
| 218 scoped_ptr<media::AudioOutputController::SyncReader> reader) | 223 scoped_ptr<media::AudioOutputController::SyncReader> reader) |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 | 635 |
| 631 void AudioRendererHost::OnPlayStream(int stream_id) { | 636 void AudioRendererHost::OnPlayStream(int stream_id) { |
| 632 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 637 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 633 | 638 |
| 634 AudioEntry* entry = LookupById(stream_id); | 639 AudioEntry* entry = LookupById(stream_id); |
| 635 if (!entry) { | 640 if (!entry) { |
| 636 SendErrorMessage(stream_id); | 641 SendErrorMessage(stream_id); |
| 637 return; | 642 return; |
| 638 } | 643 } |
| 639 | 644 |
| 645 if (entry->controller()->GetAudioParameters().effects() & |
| 646 media::AudioParameters::FOCUSABLE) { |
| 647 MediaWebContentsObserver::HasAudioFocus( |
| 648 render_process_id_, entry->render_frame_id(), |
| 649 base::Bind(&AudioRendererHost::OnFocusAvailable, this, stream_id, |
| 650 base::TimeTicks::Now())); |
| 651 } else { |
| 652 entry->controller()->Play(); |
| 653 audio_log_->OnStarted(stream_id); |
| 654 } |
| 655 } |
| 656 |
| 657 void AudioRendererHost::OnFocusAvailable(int stream_id, |
| 658 base::TimeTicks play_time) { |
| 659 // Abort the playback if: |
| 660 // - The entry has been destroyed while focus was requested. |
| 661 // - A subsequent pause has come through. |
| 662 // |
| 663 // A focus request never fails via this path. If it's denied a pause request |
| 664 // will be issues directly to the player. |
| 665 AudioEntry* entry = LookupById(stream_id); |
| 666 if (!entry || play_time < entry->last_pause_time()) |
| 667 return; |
| 668 |
| 640 entry->controller()->Play(); | 669 entry->controller()->Play(); |
| 641 audio_log_->OnStarted(stream_id); | 670 audio_log_->OnStarted(stream_id); |
| 642 } | 671 } |
| 643 | 672 |
| 644 void AudioRendererHost::OnPauseStream(int stream_id) { | 673 void AudioRendererHost::OnPauseStream(int stream_id) { |
| 645 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 674 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 646 | 675 |
| 647 AudioEntry* entry = LookupById(stream_id); | 676 AudioEntry* entry = LookupById(stream_id); |
| 648 if (!entry) { | 677 if (!entry) { |
| 649 SendErrorMessage(stream_id); | 678 SendErrorMessage(stream_id); |
| 650 return; | 679 return; |
| 651 } | 680 } |
| 652 | 681 |
| 682 entry->update_last_pause_time(); |
| 653 entry->controller()->Pause(); | 683 entry->controller()->Pause(); |
| 654 audio_log_->OnStopped(stream_id); | 684 audio_log_->OnStopped(stream_id); |
| 655 } | 685 } |
| 656 | 686 |
| 657 void AudioRendererHost::OnSetVolume(int stream_id, double volume) { | 687 void AudioRendererHost::OnSetVolume(int stream_id, double volume) { |
| 658 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 688 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 659 | 689 |
| 660 AudioEntry* entry = LookupById(stream_id); | 690 AudioEntry* entry = LookupById(stream_id); |
| 661 if (!entry) { | 691 if (!entry) { |
| 662 SendErrorMessage(stream_id); | 692 SendErrorMessage(stream_id); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 callback.Run(false, device_info); | 891 callback.Run(false, device_info); |
| 862 } | 892 } |
| 863 | 893 |
| 864 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { | 894 bool AudioRendererHost::IsAuthorizationStarted(int stream_id) { |
| 865 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 895 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 866 const auto& i = authorizations_.find(stream_id); | 896 const auto& i = authorizations_.find(stream_id); |
| 867 return i != authorizations_.end(); | 897 return i != authorizations_.end(); |
| 868 } | 898 } |
| 869 | 899 |
| 870 } // namespace content | 900 } // namespace content |
| OLD | NEW |