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