Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1035)

Side by Side Diff: remoting/protocol/ice_connection_to_client.cc

Issue 1472873005: Add VideoStream interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@move_video_pump
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/protocol/ice_connection_to_client.h" 5 #include "remoting/protocol/ice_connection_to_client.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/location.h" 8 #include "base/location.h"
9 #include "net/base/io_buffer.h" 9 #include "net/base/io_buffer.h"
10 #include "remoting/codec/video_encoder.h"
11 #include "remoting/codec/video_encoder_verbatim.h"
12 #include "remoting/codec/video_encoder_vpx.h"
10 #include "remoting/protocol/audio_writer.h" 13 #include "remoting/protocol/audio_writer.h"
11 #include "remoting/protocol/clipboard_stub.h" 14 #include "remoting/protocol/clipboard_stub.h"
12 #include "remoting/protocol/host_control_dispatcher.h" 15 #include "remoting/protocol/host_control_dispatcher.h"
13 #include "remoting/protocol/host_event_dispatcher.h" 16 #include "remoting/protocol/host_event_dispatcher.h"
14 #include "remoting/protocol/host_stub.h" 17 #include "remoting/protocol/host_stub.h"
15 #include "remoting/protocol/host_video_dispatcher.h" 18 #include "remoting/protocol/host_video_dispatcher.h"
16 #include "remoting/protocol/input_stub.h" 19 #include "remoting/protocol/input_stub.h"
20 #include "remoting/protocol/video_frame_pump.h"
17 21
18 namespace remoting { 22 namespace remoting {
19 namespace protocol { 23 namespace protocol {
20 24
25 namespace {
26
27 scoped_ptr<VideoEncoder> CreateVideoEncoder(
28 const protocol::SessionConfig& config) {
29 const protocol::ChannelConfig& video_config = config.video_config();
30
31 if (video_config.codec == protocol::ChannelConfig::CODEC_VP8) {
32 return VideoEncoderVpx::CreateForVP8().Pass();
33 } else if (video_config.codec == protocol::ChannelConfig::CODEC_VP9) {
34 return VideoEncoderVpx::CreateForVP9().Pass();
35 } else if (video_config.codec == protocol::ChannelConfig::CODEC_VERBATIM) {
36 return make_scoped_ptr(new VideoEncoderVerbatim());
37 }
38
39 NOTREACHED();
40 return nullptr;
41 }
42
43 } // namespace
44
21 IceConnectionToClient::IceConnectionToClient( 45 IceConnectionToClient::IceConnectionToClient(
22 scoped_ptr<protocol::Session> session) 46 scoped_ptr<protocol::Session> session,
23 : handler_(nullptr), session_(session.Pass()) { 47 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner)
48 : event_handler_(nullptr),
49 session_(session.Pass()),
50 video_encode_task_runner_(video_encode_task_runner) {
24 session_->SetEventHandler(this); 51 session_->SetEventHandler(this);
25 } 52 }
26 53
27 IceConnectionToClient::~IceConnectionToClient() { 54 IceConnectionToClient::~IceConnectionToClient() {}
28 }
29 55
30 void IceConnectionToClient::SetEventHandler( 56 void IceConnectionToClient::SetEventHandler(
31 ConnectionToClient::EventHandler* event_handler) { 57 ConnectionToClient::EventHandler* event_handler) {
32 DCHECK(thread_checker_.CalledOnValidThread()); 58 DCHECK(thread_checker_.CalledOnValidThread());
33 handler_ = event_handler; 59 event_handler_ = event_handler;
34 } 60 }
35 61
36 protocol::Session* IceConnectionToClient::session() { 62 protocol::Session* IceConnectionToClient::session() {
37 DCHECK(thread_checker_.CalledOnValidThread()); 63 DCHECK(thread_checker_.CalledOnValidThread());
38 return session_.get(); 64 return session_.get();
39 } 65 }
40 66
41 void IceConnectionToClient::Disconnect(ErrorCode error) { 67 void IceConnectionToClient::Disconnect(ErrorCode error) {
42 DCHECK(thread_checker_.CalledOnValidThread()); 68 DCHECK(thread_checker_.CalledOnValidThread());
43 69
44 CloseChannels(); 70 CloseChannels();
45 71
46 // This should trigger OnConnectionClosed() event and this object 72 // This should trigger OnConnectionClosed() event and this object
47 // may be destroyed as the result. 73 // may be destroyed as the result.
48 session_->Close(error); 74 session_->Close(error);
49 } 75 }
50 76
51 void IceConnectionToClient::OnInputEventReceived(int64_t timestamp) { 77 void IceConnectionToClient::OnInputEventReceived(int64_t timestamp) {
52 DCHECK(thread_checker_.CalledOnValidThread()); 78 DCHECK(thread_checker_.CalledOnValidThread());
53 handler_->OnInputEventReceived(this, timestamp); 79 event_handler_->OnInputEventReceived(this, timestamp);
54 } 80 }
55 81
56 VideoStub* IceConnectionToClient::video_stub() { 82 scoped_ptr<VideoStream> IceConnectionToClient::StartVideoStream(
83 scoped_ptr<webrtc::DesktopCapturer> desktop_capturer) {
57 DCHECK(thread_checker_.CalledOnValidThread()); 84 DCHECK(thread_checker_.CalledOnValidThread());
58 return video_dispatcher_.get(); 85
86 scoped_ptr<VideoEncoder> video_encoder =
87 CreateVideoEncoder(session_->config());
88 event_handler_->OnCreateVideoEncoder(&video_encoder);
89 DCHECK(video_encoder);
90
91 scoped_ptr<VideoFramePump> pump(
92 new VideoFramePump(video_encode_task_runner_, desktop_capturer.Pass(),
93 video_encoder.Pass(), video_dispatcher_.get()));
94 video_dispatcher_->set_video_feedback_stub(pump->video_feedback_stub());
95 return pump.Pass();
59 } 96 }
60 97
61 AudioStub* IceConnectionToClient::audio_stub() { 98 AudioStub* IceConnectionToClient::audio_stub() {
62 DCHECK(thread_checker_.CalledOnValidThread()); 99 DCHECK(thread_checker_.CalledOnValidThread());
63 return audio_writer_.get(); 100 return audio_writer_.get();
64 } 101 }
65 102
66 // Return pointer to ClientStub. 103 // Return pointer to ClientStub.
67 ClientStub* IceConnectionToClient::client_stub() { 104 ClientStub* IceConnectionToClient::client_stub() {
68 DCHECK(thread_checker_.CalledOnValidThread()); 105 DCHECK(thread_checker_.CalledOnValidThread());
69 return control_dispatcher_.get(); 106 return control_dispatcher_.get();
70 } 107 }
71 108
72 void IceConnectionToClient::set_clipboard_stub( 109 void IceConnectionToClient::set_clipboard_stub(
73 protocol::ClipboardStub* clipboard_stub) { 110 protocol::ClipboardStub* clipboard_stub) {
74 DCHECK(thread_checker_.CalledOnValidThread()); 111 DCHECK(thread_checker_.CalledOnValidThread());
75 control_dispatcher_->set_clipboard_stub(clipboard_stub); 112 control_dispatcher_->set_clipboard_stub(clipboard_stub);
76 } 113 }
77 114
78 void IceConnectionToClient::set_host_stub(protocol::HostStub* host_stub) { 115 void IceConnectionToClient::set_host_stub(protocol::HostStub* host_stub) {
79 DCHECK(thread_checker_.CalledOnValidThread()); 116 DCHECK(thread_checker_.CalledOnValidThread());
80 control_dispatcher_->set_host_stub(host_stub); 117 control_dispatcher_->set_host_stub(host_stub);
81 } 118 }
82 119
83 void IceConnectionToClient::set_input_stub(protocol::InputStub* input_stub) { 120 void IceConnectionToClient::set_input_stub(protocol::InputStub* input_stub) {
84 DCHECK(thread_checker_.CalledOnValidThread()); 121 DCHECK(thread_checker_.CalledOnValidThread());
85 event_dispatcher_->set_input_stub(input_stub); 122 event_dispatcher_->set_input_stub(input_stub);
86 } 123 }
87 124
88 void IceConnectionToClient::set_video_feedback_stub(
89 VideoFeedbackStub* video_feedback_stub) {
90 DCHECK(thread_checker_.CalledOnValidThread());
91 video_dispatcher_->set_video_feedback_stub(video_feedback_stub);
92 }
93
94 void IceConnectionToClient::OnSessionStateChange(Session::State state) { 125 void IceConnectionToClient::OnSessionStateChange(Session::State state) {
95 DCHECK(thread_checker_.CalledOnValidThread()); 126 DCHECK(thread_checker_.CalledOnValidThread());
96 127
97 DCHECK(handler_); 128 DCHECK(event_handler_);
98 switch(state) { 129 switch(state) {
99 case Session::INITIALIZING: 130 case Session::INITIALIZING:
100 case Session::CONNECTING: 131 case Session::CONNECTING:
101 case Session::ACCEPTING: 132 case Session::ACCEPTING:
102 case Session::CONNECTED: 133 case Session::CONNECTED:
103 // Don't care about these events. 134 // Don't care about these events.
104 break; 135 break;
105 case Session::AUTHENTICATING: 136 case Session::AUTHENTICATING:
106 handler_->OnConnectionAuthenticating(this); 137 event_handler_->OnConnectionAuthenticating(this);
107 break; 138 break;
108 case Session::AUTHENTICATED: 139 case Session::AUTHENTICATED:
109 // Initialize channels. 140 // Initialize channels.
110 control_dispatcher_.reset(new HostControlDispatcher()); 141 control_dispatcher_.reset(new HostControlDispatcher());
111 control_dispatcher_->Init(session_.get(), 142 control_dispatcher_->Init(session_.get(),
112 session_->config().control_config(), this); 143 session_->config().control_config(), this);
113 144
114 event_dispatcher_.reset(new HostEventDispatcher()); 145 event_dispatcher_.reset(new HostEventDispatcher());
115 event_dispatcher_->Init(session_.get(), session_->config().event_config(), 146 event_dispatcher_->Init(session_.get(), session_->config().event_config(),
116 this); 147 this);
117 event_dispatcher_->set_on_input_event_callback( 148 event_dispatcher_->set_on_input_event_callback(
118 base::Bind(&IceConnectionToClient::OnInputEventReceived, 149 base::Bind(&IceConnectionToClient::OnInputEventReceived,
119 base::Unretained(this))); 150 base::Unretained(this)));
120 151
121 video_dispatcher_.reset(new HostVideoDispatcher()); 152 video_dispatcher_.reset(new HostVideoDispatcher());
122 video_dispatcher_->Init(session_.get(), session_->config().video_config(), 153 video_dispatcher_->Init(session_.get(), session_->config().video_config(),
123 this); 154 this);
124 155
125 audio_writer_ = AudioWriter::Create(session_->config()); 156 audio_writer_ = AudioWriter::Create(session_->config());
126 if (audio_writer_.get()) { 157 if (audio_writer_.get()) {
127 audio_writer_->Init(session_.get(), session_->config().audio_config(), 158 audio_writer_->Init(session_.get(), session_->config().audio_config(),
128 this); 159 this);
129 } 160 }
130 161
131 // Notify the handler after initializing the channels, so that 162 // Notify the handler after initializing the channels, so that
132 // ClientSession can get a client clipboard stub. 163 // ClientSession can get a client clipboard stub.
133 handler_->OnConnectionAuthenticated(this); 164 event_handler_->OnConnectionAuthenticated(this);
134 break; 165 break;
135 166
136 case Session::CLOSED: 167 case Session::CLOSED:
137 Close(OK); 168 Close(OK);
138 break; 169 break;
139 170
140 case Session::FAILED: 171 case Session::FAILED:
141 Close(session_->error()); 172 Close(session_->error());
142 break; 173 break;
143 } 174 }
144 } 175 }
145 176
146 void IceConnectionToClient::OnSessionRouteChange( 177 void IceConnectionToClient::OnSessionRouteChange(
147 const std::string& channel_name, 178 const std::string& channel_name,
148 const TransportRoute& route) { 179 const TransportRoute& route) {
149 handler_->OnRouteChange(this, channel_name, route); 180 event_handler_->OnRouteChange(this, channel_name, route);
150 } 181 }
151 182
152 void IceConnectionToClient::OnChannelInitialized( 183 void IceConnectionToClient::OnChannelInitialized(
153 ChannelDispatcherBase* channel_dispatcher) { 184 ChannelDispatcherBase* channel_dispatcher) {
154 DCHECK(thread_checker_.CalledOnValidThread()); 185 DCHECK(thread_checker_.CalledOnValidThread());
155 186
156 NotifyIfChannelsReady(); 187 NotifyIfChannelsReady();
157 } 188 }
158 189
159 void IceConnectionToClient::OnChannelError( 190 void IceConnectionToClient::OnChannelError(
(...skipping 12 matching lines...) Expand all
172 if (!control_dispatcher_ || !control_dispatcher_->is_connected()) 203 if (!control_dispatcher_ || !control_dispatcher_->is_connected())
173 return; 204 return;
174 if (!event_dispatcher_ || !event_dispatcher_->is_connected()) 205 if (!event_dispatcher_ || !event_dispatcher_->is_connected())
175 return; 206 return;
176 if (!video_dispatcher_ || !video_dispatcher_->is_connected()) 207 if (!video_dispatcher_ || !video_dispatcher_->is_connected())
177 return; 208 return;
178 if ((!audio_writer_ || !audio_writer_->is_connected()) && 209 if ((!audio_writer_ || !audio_writer_->is_connected()) &&
179 session_->config().is_audio_enabled()) { 210 session_->config().is_audio_enabled()) {
180 return; 211 return;
181 } 212 }
182 handler_->OnConnectionChannelsConnected(this); 213 event_handler_->OnConnectionChannelsConnected(this);
183 } 214 }
184 215
185 void IceConnectionToClient::Close(ErrorCode error) { 216 void IceConnectionToClient::Close(ErrorCode error) {
186 CloseChannels(); 217 CloseChannels();
187 handler_->OnConnectionClosed(this, error); 218 event_handler_->OnConnectionClosed(this, error);
188 } 219 }
189 220
190 void IceConnectionToClient::CloseChannels() { 221 void IceConnectionToClient::CloseChannels() {
191 control_dispatcher_.reset(); 222 control_dispatcher_.reset();
192 event_dispatcher_.reset(); 223 event_dispatcher_.reset();
193 video_dispatcher_.reset(); 224 video_dispatcher_.reset();
194 audio_writer_.reset(); 225 audio_writer_.reset();
195 } 226 }
196 227
197 } // namespace protocol 228 } // namespace protocol
198 } // namespace remoting 229 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698