OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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 #include "content/browser/renderer_host/media/audio_output_service_context.h" |
| 6 |
| 7 #include <algorithm> |
| 8 #include <memory> |
| 9 #include <utility> |
| 10 |
| 11 #include "base/memory/ptr_util.h" |
| 12 #include "content/browser/media/media_internals.h" |
| 13 #include "content/browser/renderer_host/media/audio_output_impl.h" |
| 14 #include "content/browser/renderer_host/media/audio_output_service_impl.h" |
| 15 #include "content/public/browser/browser_thread.h" |
| 16 #include "content/public/browser/content_browser_client.h" |
| 17 #include "content/public/browser/render_frame_host.h" |
| 18 #include "content/public/common/content_client.h" |
| 19 #include "media/mojo/interfaces/audio_output.mojom.h" |
| 20 |
| 21 namespace content { |
| 22 |
| 23 AudioOutputServiceContext::AudioOutputServiceContext( |
| 24 int render_process_id, |
| 25 media::AudioManager* audio_manager, |
| 26 MediaStreamManager* media_stream_manager, |
| 27 AudioMirroringManager* mirroring_manager, |
| 28 const std::string& salt) |
| 29 : render_process_id_(render_process_id), |
| 30 audio_manager_(audio_manager), |
| 31 media_stream_manager_(media_stream_manager), |
| 32 mirroring_manager_(mirroring_manager), |
| 33 salt_(salt), |
| 34 authorization_handler_(audio_manager_, |
| 35 media_stream_manager_, |
| 36 render_process_id_, |
| 37 salt_), |
| 38 services_() {} |
| 39 |
| 40 AudioOutputServiceContext::~AudioOutputServiceContext() { |
| 41 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 42 } |
| 43 |
| 44 void AudioOutputServiceContext::ServiceHadConnectionError( |
| 45 AudioOutputServiceImpl* service) { |
| 46 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 47 |
| 48 auto it = std::find_if( |
| 49 services_.begin(), services_.end(), |
| 50 [service](const std::unique_ptr<AudioOutputServiceImpl>& other_service) { |
| 51 return service == other_service.get(); |
| 52 }); |
| 53 if (it == services_.end()) |
| 54 return; |
| 55 std::swap(*it, services_.back()); |
| 56 services_.pop_back(); |
| 57 } |
| 58 |
| 59 void AudioOutputServiceContext::CreateService( |
| 60 int frame_host_id, |
| 61 mojo::InterfaceRequest<media::mojom::AudioOutputService> request) { |
| 62 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 63 |
| 64 services_.push_back(base::MakeUnique<AudioOutputServiceImpl>( |
| 65 this, frame_host_id, |
| 66 base::Bind(&AudioOutputServiceContext::ServiceHadConnectionError, |
| 67 base::Unretained(this)), |
| 68 std::move(request))); |
| 69 } |
| 70 |
| 71 AudioOutputDelegate::UniquePtr AudioOutputServiceContext::CreateDelegate( |
| 72 const std::string& unique_device_id, |
| 73 int render_frame_id, |
| 74 AudioOutputDelegate::EventHandler* handler, |
| 75 const media::AudioParameters& params) { |
| 76 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 77 int stream_id = next_stream_id_++; |
| 78 MediaObserver* const media_observer = |
| 79 GetContentClient()->browser()->GetMediaObserver(); |
| 80 |
| 81 MediaInternals* const media_internals = MediaInternals::GetInstance(); |
| 82 std::unique_ptr<media::AudioLog> audio_log = media_internals->CreateAudioLog( |
| 83 media::AudioLogFactory::AUDIO_OUTPUT_CONTROLLER); |
| 84 media_internals->SetWebContentsTitleForAudioLogEntry( |
| 85 stream_id, render_process_id_, render_frame_id, audio_log.get()); |
| 86 |
| 87 return AudioOutputDelegate::Create( |
| 88 handler, audio_manager_, std::move(audio_log), mirroring_manager_, |
| 89 media_observer, stream_id, render_frame_id, render_process_id_, params, |
| 90 unique_device_id); |
| 91 } |
| 92 |
| 93 } // namespace content |
OLD | NEW |