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

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::ACCEPTED: 133 case Session::ACCEPTED:
103 case Session::CONNECTED: 134 case Session::CONNECTED:
104 // Don't care about these events. 135 // Don't care about these events.
105 break; 136 break;
106 case Session::AUTHENTICATING: 137 case Session::AUTHENTICATING:
107 handler_->OnConnectionAuthenticating(this); 138 event_handler_->OnConnectionAuthenticating(this);
108 break; 139 break;
109 case Session::AUTHENTICATED: 140 case Session::AUTHENTICATED:
110 // Initialize channels. 141 // Initialize channels.
111 control_dispatcher_.reset(new HostControlDispatcher()); 142 control_dispatcher_.reset(new HostControlDispatcher());
112 control_dispatcher_->Init(session_.get(), 143 control_dispatcher_->Init(session_.get(),
113 session_->config().control_config(), this); 144 session_->config().control_config(), this);
114 145
115 event_dispatcher_.reset(new HostEventDispatcher()); 146 event_dispatcher_.reset(new HostEventDispatcher());
116 event_dispatcher_->Init(session_.get(), session_->config().event_config(), 147 event_dispatcher_->Init(session_.get(), session_->config().event_config(),
117 this); 148 this);
118 event_dispatcher_->set_on_input_event_callback( 149 event_dispatcher_->set_on_input_event_callback(
119 base::Bind(&IceConnectionToClient::OnInputEventReceived, 150 base::Bind(&IceConnectionToClient::OnInputEventReceived,
120 base::Unretained(this))); 151 base::Unretained(this)));
121 152
122 video_dispatcher_.reset(new HostVideoDispatcher()); 153 video_dispatcher_.reset(new HostVideoDispatcher());
123 video_dispatcher_->Init(session_.get(), session_->config().video_config(), 154 video_dispatcher_->Init(session_.get(), session_->config().video_config(),
124 this); 155 this);
125 156
126 audio_writer_ = AudioWriter::Create(session_->config()); 157 audio_writer_ = AudioWriter::Create(session_->config());
127 if (audio_writer_.get()) { 158 if (audio_writer_.get()) {
128 audio_writer_->Init(session_.get(), session_->config().audio_config(), 159 audio_writer_->Init(session_.get(), session_->config().audio_config(),
129 this); 160 this);
130 } 161 }
131 162
132 // Notify the handler after initializing the channels, so that 163 // Notify the handler after initializing the channels, so that
133 // ClientSession can get a client clipboard stub. 164 // ClientSession can get a client clipboard stub.
134 handler_->OnConnectionAuthenticated(this); 165 event_handler_->OnConnectionAuthenticated(this);
135 break; 166 break;
136 167
137 case Session::CLOSED: 168 case Session::CLOSED:
138 Close(OK); 169 Close(OK);
139 break; 170 break;
140 171
141 case Session::FAILED: 172 case Session::FAILED:
142 Close(session_->error()); 173 Close(session_->error());
143 break; 174 break;
144 } 175 }
145 } 176 }
146 177
147 void IceConnectionToClient::OnSessionRouteChange( 178 void IceConnectionToClient::OnSessionRouteChange(
148 const std::string& channel_name, 179 const std::string& channel_name,
149 const TransportRoute& route) { 180 const TransportRoute& route) {
150 handler_->OnRouteChange(this, channel_name, route); 181 event_handler_->OnRouteChange(this, channel_name, route);
151 } 182 }
152 183
153 void IceConnectionToClient::OnChannelInitialized( 184 void IceConnectionToClient::OnChannelInitialized(
154 ChannelDispatcherBase* channel_dispatcher) { 185 ChannelDispatcherBase* channel_dispatcher) {
155 DCHECK(thread_checker_.CalledOnValidThread()); 186 DCHECK(thread_checker_.CalledOnValidThread());
156 187
157 NotifyIfChannelsReady(); 188 NotifyIfChannelsReady();
158 } 189 }
159 190
160 void IceConnectionToClient::OnChannelError( 191 void IceConnectionToClient::OnChannelError(
(...skipping 12 matching lines...) Expand all
173 if (!control_dispatcher_ || !control_dispatcher_->is_connected()) 204 if (!control_dispatcher_ || !control_dispatcher_->is_connected())
174 return; 205 return;
175 if (!event_dispatcher_ || !event_dispatcher_->is_connected()) 206 if (!event_dispatcher_ || !event_dispatcher_->is_connected())
176 return; 207 return;
177 if (!video_dispatcher_ || !video_dispatcher_->is_connected()) 208 if (!video_dispatcher_ || !video_dispatcher_->is_connected())
178 return; 209 return;
179 if ((!audio_writer_ || !audio_writer_->is_connected()) && 210 if ((!audio_writer_ || !audio_writer_->is_connected()) &&
180 session_->config().is_audio_enabled()) { 211 session_->config().is_audio_enabled()) {
181 return; 212 return;
182 } 213 }
183 handler_->OnConnectionChannelsConnected(this); 214 event_handler_->OnConnectionChannelsConnected(this);
184 } 215 }
185 216
186 void IceConnectionToClient::Close(ErrorCode error) { 217 void IceConnectionToClient::Close(ErrorCode error) {
187 CloseChannels(); 218 CloseChannels();
188 handler_->OnConnectionClosed(this, error); 219 event_handler_->OnConnectionClosed(this, error);
189 } 220 }
190 221
191 void IceConnectionToClient::CloseChannels() { 222 void IceConnectionToClient::CloseChannels() {
192 control_dispatcher_.reset(); 223 control_dispatcher_.reset();
193 event_dispatcher_.reset(); 224 event_dispatcher_.reset();
194 video_dispatcher_.reset(); 225 video_dispatcher_.reset();
195 audio_writer_.reset(); 226 audio_writer_.reset();
196 } 227 }
197 228
198 } // namespace protocol 229 } // namespace protocol
199 } // namespace remoting 230 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/protocol/ice_connection_to_client.h ('k') | remoting/protocol/ice_connection_to_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698