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.
5 #include "remoting/host/host_extension_session_manager.h"
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"
15 HostExtensionSessionManager::HostExtensionSessionManager(
16 const std::vector
<HostExtension
*>& extensions
,
17 ClientSessionControl
* client_session_control
)
18 : client_session_control_(client_session_control
),
20 extensions_(extensions
) {
23 HostExtensionSessionManager::~HostExtensionSessionManager() {
26 std::string
HostExtensionSessionManager::GetCapabilities() {
27 std::string capabilities
;
28 for (HostExtensionList::const_iterator extension
= extensions_
.begin();
29 extension
!= extensions_
.end(); ++extension
) {
30 std::string capability
= (*extension
)->capability();
31 if (capability
.empty()) {
34 if (!capabilities
.empty()) {
35 capabilities
.append(" ");
37 capabilities
.append(capability
);
42 scoped_ptr
<webrtc::DesktopCapturer
>
43 HostExtensionSessionManager::OnCreateVideoCapturer(
44 scoped_ptr
<webrtc::DesktopCapturer
> capturer
) {
45 for(HostExtensionSessionList::const_iterator it
= extension_sessions_
.begin();
46 it
!= extension_sessions_
.end(); ++it
) {
47 if ((*it
)->ModifiesVideoPipeline()) {
48 capturer
= (*it
)->OnCreateVideoCapturer(capturer
.Pass());
51 return capturer
.Pass();
54 scoped_ptr
<VideoEncoder
> HostExtensionSessionManager::OnCreateVideoEncoder(
55 scoped_ptr
<VideoEncoder
> encoder
) {
56 for(HostExtensionSessionList::const_iterator it
= extension_sessions_
.begin();
57 it
!= extension_sessions_
.end(); ++it
) {
58 if ((*it
)->ModifiesVideoPipeline()) {
59 encoder
= (*it
)->OnCreateVideoEncoder(encoder
.Pass());
62 return encoder
.Pass();
65 void HostExtensionSessionManager::OnNegotiatedCapabilities(
66 protocol::ClientStub
* client_stub
,
67 const std::string
& capabilities
) {
69 DCHECK(!client_stub_
);
71 client_stub_
= client_stub
;
73 bool reset_video_pipeline
= false;
75 for (HostExtensionList::const_iterator extension
= extensions_
.begin();
76 extension
!= extensions_
.end(); ++extension
) {
77 // If the extension requires a capability that was not negotiated then do
78 // not instantiate it.
79 if (!(*extension
)->capability().empty() &&
80 !HasCapability(capabilities
, (*extension
)->capability())) {
84 scoped_ptr
<HostExtensionSession
> extension_session
=
85 (*extension
)->CreateExtensionSession(
86 client_session_control_
, client_stub_
);
87 DCHECK(extension_session
);
89 if (extension_session
->ModifiesVideoPipeline()) {
90 reset_video_pipeline
= true;
93 extension_sessions_
.push_back(extension_session
.release());
96 // Re-create the video pipeline if one or more extensions need to modify it.
97 if (reset_video_pipeline
) {
98 client_session_control_
->ResetVideoPipeline();
102 bool HostExtensionSessionManager::OnExtensionMessage(
103 const protocol::ExtensionMessage
& message
) {
104 for(HostExtensionSessionList::const_iterator it
= extension_sessions_
.begin();
105 it
!= extension_sessions_
.end(); ++it
) {
106 if ((*it
)->OnExtensionMessage(
107 client_session_control_
, client_stub_
, message
)) {
114 } // namespace remoting