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 3 // found in the LICENSE file. 4 5 #include "remoting/host/host_extension_session_manager.h" 6 7 #include "remoting/base/capabilities.h" 8 #include "remoting/codec/video_encoder.h" 9 #include "remoting/host/client_session_control.h" 10 #include "remoting/host/host_extension.h" 11 #include "remoting/host/host_extension_session.h" 12 #include "third_party/webrtc/modules/desktop_capture/desktop_capturer.h" 13 namespace remoting { 14 15 HostExtensionSessionManager::HostExtensionSessionManager( 16 const std::vector<HostExtension*>& extensions, 17 ClientSessionControl* client_session_control) 18 : client_session_control_(client_session_control), 19 client_stub_(NULL), 20 extensions_(extensions) { 21 } 22 23 HostExtensionSessionManager::~HostExtensionSessionManager() { 24 } 25 26 std::string HostExtensionSessionManager::GetCapabilities() const { 27 std::string capabilities; 28 for (HostExtensions::const_iterator extension = extensions_.begin(); 29 extension != extensions_.end(); ++extension) { 30 const std::string& capability = (*extension)->capability(); 31 if (capability.empty()) { 32 continue; 33 } 34 if (!capabilities.empty()) { 35 capabilities.append(" "); 36 } 37 capabilities.append(capability); 38 } 39 return capabilities; 40 } 41 42 void HostExtensionSessionManager::OnCreateVideoCapturer( 43 scoped_ptr<webrtc::DesktopCapturer>* capturer) { 44 for (HostExtensionSessions::const_iterator it = extension_sessions_.begin(); 45 it != extension_sessions_.end(); ++it) { 46 if ((*it)->ModifiesVideoPipeline()) { 47 (*it)->OnCreateVideoCapturer(capturer); 48 } 49 } 50 } 51 52 void HostExtensionSessionManager::OnCreateVideoEncoder( 53 scoped_ptr<VideoEncoder>* encoder) { 54 for (HostExtensionSessions::const_iterator it = extension_sessions_.begin(); 55 it != extension_sessions_.end(); ++it) { 56 if ((*it)->ModifiesVideoPipeline()) { 57 (*it)->OnCreateVideoEncoder(encoder); 58 } 59 } 60 } 61 62 void HostExtensionSessionManager::OnNegotiatedCapabilities( 63 protocol::ClientStub* client_stub, 64 const std::string& capabilities) { 65 DCHECK(client_stub); 66 DCHECK(!client_stub_); 67 68 client_stub_ = client_stub; 69 70 bool reset_video_pipeline = false; 71 72 for (HostExtensions::const_iterator extension = extensions_.begin(); 73 extension != extensions_.end(); ++extension) { 74 // If the extension requires a capability that was not negotiated then do 75 // not instantiate it. 76 if (!(*extension)->capability().empty() && 77 !HasCapability(capabilities, (*extension)->capability())) { 78 continue; 79 } 80 81 scoped_ptr<HostExtensionSession> extension_session = 82 (*extension)->CreateExtensionSession( 83 client_session_control_, client_stub_); 84 DCHECK(extension_session); 85 86 if (extension_session->ModifiesVideoPipeline()) { 87 reset_video_pipeline = true; 88 } 89 90 extension_sessions_.push_back(extension_session.release()); 91 } 92 93 // Re-create the video pipeline if one or more extensions need to modify it. 94 if (reset_video_pipeline) { 95 client_session_control_->ResetVideoPipeline(); 96 } 97 } 98 99 bool HostExtensionSessionManager::OnExtensionMessage( 100 const protocol::ExtensionMessage& message) { 101 for(HostExtensionSessions::const_iterator it = extension_sessions_.begin(); 102 it != extension_sessions_.end(); ++it) { 103 if ((*it)->OnExtensionMessage( 104 client_session_control_, client_stub_, message)) { 105 return true; 106 } 107 } 108 return false; 109 } 110 111 } // namespace remoting 112