OLD | NEW |
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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/location.h" | 10 #include "base/location.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "net/base/io_buffer.h" | 12 #include "net/base/io_buffer.h" |
| 13 #include "remoting/codec/audio_encoder.h" |
| 14 #include "remoting/codec/audio_encoder_opus.h" |
13 #include "remoting/codec/video_encoder.h" | 15 #include "remoting/codec/video_encoder.h" |
| 16 #include "remoting/protocol/audio_pump.h" |
| 17 #include "remoting/protocol/audio_source.h" |
14 #include "remoting/protocol/audio_writer.h" | 18 #include "remoting/protocol/audio_writer.h" |
15 #include "remoting/protocol/clipboard_stub.h" | 19 #include "remoting/protocol/clipboard_stub.h" |
16 #include "remoting/protocol/host_control_dispatcher.h" | 20 #include "remoting/protocol/host_control_dispatcher.h" |
17 #include "remoting/protocol/host_event_dispatcher.h" | 21 #include "remoting/protocol/host_event_dispatcher.h" |
18 #include "remoting/protocol/host_stub.h" | 22 #include "remoting/protocol/host_stub.h" |
19 #include "remoting/protocol/host_video_dispatcher.h" | 23 #include "remoting/protocol/host_video_dispatcher.h" |
20 #include "remoting/protocol/input_stub.h" | 24 #include "remoting/protocol/input_stub.h" |
21 #include "remoting/protocol/transport_context.h" | 25 #include "remoting/protocol/transport_context.h" |
22 #include "remoting/protocol/video_frame_pump.h" | 26 #include "remoting/protocol/video_frame_pump.h" |
23 | 27 |
24 namespace remoting { | 28 namespace remoting { |
25 namespace protocol { | 29 namespace protocol { |
26 | 30 |
| 31 namespace { |
| 32 |
| 33 std::unique_ptr<AudioEncoder> CreateAudioEncoder( |
| 34 const protocol::SessionConfig& config) { |
| 35 const protocol::ChannelConfig& audio_config = config.audio_config(); |
| 36 |
| 37 if (audio_config.codec == protocol::ChannelConfig::CODEC_OPUS) { |
| 38 return base::WrapUnique(new AudioEncoderOpus()); |
| 39 } |
| 40 |
| 41 NOTREACHED(); |
| 42 return nullptr; |
| 43 } |
| 44 |
| 45 } // namespace |
| 46 |
27 IceConnectionToClient::IceConnectionToClient( | 47 IceConnectionToClient::IceConnectionToClient( |
28 std::unique_ptr<protocol::Session> session, | 48 std::unique_ptr<protocol::Session> session, |
29 scoped_refptr<TransportContext> transport_context, | 49 scoped_refptr<TransportContext> transport_context, |
30 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner) | 50 scoped_refptr<base::SingleThreadTaskRunner> video_encode_task_runner, |
| 51 scoped_refptr<base::SingleThreadTaskRunner> audio_task_runner) |
31 : event_handler_(nullptr), | 52 : event_handler_(nullptr), |
32 session_(std::move(session)), | 53 session_(std::move(session)), |
33 video_encode_task_runner_(video_encode_task_runner), | 54 video_encode_task_runner_(video_encode_task_runner), |
| 55 audio_task_runner_(audio_task_runner), |
34 transport_(transport_context, this), | 56 transport_(transport_context, this), |
35 control_dispatcher_(new HostControlDispatcher()), | 57 control_dispatcher_(new HostControlDispatcher()), |
36 event_dispatcher_(new HostEventDispatcher()), | 58 event_dispatcher_(new HostEventDispatcher()), |
37 video_dispatcher_(new HostVideoDispatcher()) { | 59 video_dispatcher_(new HostVideoDispatcher()) { |
38 session_->SetEventHandler(this); | 60 session_->SetEventHandler(this); |
39 session_->SetTransport(&transport_); | 61 session_->SetTransport(&transport_); |
40 } | 62 } |
41 | 63 |
42 IceConnectionToClient::~IceConnectionToClient() {} | 64 IceConnectionToClient::~IceConnectionToClient() {} |
43 | 65 |
(...skipping 28 matching lines...) Expand all Loading... |
72 std::unique_ptr<VideoEncoder> video_encoder = | 94 std::unique_ptr<VideoEncoder> video_encoder = |
73 VideoEncoder::Create(session_->config()); | 95 VideoEncoder::Create(session_->config()); |
74 | 96 |
75 std::unique_ptr<VideoFramePump> pump( | 97 std::unique_ptr<VideoFramePump> pump( |
76 new VideoFramePump(video_encode_task_runner_, std::move(desktop_capturer), | 98 new VideoFramePump(video_encode_task_runner_, std::move(desktop_capturer), |
77 std::move(video_encoder), video_dispatcher_.get())); | 99 std::move(video_encoder), video_dispatcher_.get())); |
78 video_dispatcher_->set_video_feedback_stub(pump->video_feedback_stub()); | 100 video_dispatcher_->set_video_feedback_stub(pump->video_feedback_stub()); |
79 return std::move(pump); | 101 return std::move(pump); |
80 } | 102 } |
81 | 103 |
82 AudioStub* IceConnectionToClient::audio_stub() { | 104 std::unique_ptr<AudioStream> IceConnectionToClient::StartAudioStream( |
| 105 std::unique_ptr<AudioSource> audio_source) { |
83 DCHECK(thread_checker_.CalledOnValidThread()); | 106 DCHECK(thread_checker_.CalledOnValidThread()); |
84 return audio_writer_.get(); | 107 |
| 108 // Audio channel is disabled. |
| 109 if (!audio_writer_) |
| 110 return nullptr; |
| 111 |
| 112 std::unique_ptr<AudioEncoder> audio_encoder = |
| 113 CreateAudioEncoder(session_->config()); |
| 114 |
| 115 return base::WrapUnique( |
| 116 new AudioPump(audio_task_runner_, std::move(audio_source), |
| 117 std::move(audio_encoder), audio_writer_.get())); |
85 } | 118 } |
86 | 119 |
87 // Return pointer to ClientStub. | 120 // Return pointer to ClientStub. |
88 ClientStub* IceConnectionToClient::client_stub() { | 121 ClientStub* IceConnectionToClient::client_stub() { |
89 DCHECK(thread_checker_.CalledOnValidThread()); | 122 DCHECK(thread_checker_.CalledOnValidThread()); |
90 return control_dispatcher_.get(); | 123 return control_dispatcher_.get(); |
91 } | 124 } |
92 | 125 |
93 void IceConnectionToClient::set_clipboard_stub( | 126 void IceConnectionToClient::set_clipboard_stub( |
94 protocol::ClipboardStub* clipboard_stub) { | 127 protocol::ClipboardStub* clipboard_stub) { |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 return; | 216 return; |
184 if (!event_dispatcher_ || !event_dispatcher_->is_connected()) | 217 if (!event_dispatcher_ || !event_dispatcher_->is_connected()) |
185 return; | 218 return; |
186 if (!video_dispatcher_ || !video_dispatcher_->is_connected()) | 219 if (!video_dispatcher_ || !video_dispatcher_->is_connected()) |
187 return; | 220 return; |
188 if ((!audio_writer_ || !audio_writer_->is_connected()) && | 221 if ((!audio_writer_ || !audio_writer_->is_connected()) && |
189 session_->config().is_audio_enabled()) { | 222 session_->config().is_audio_enabled()) { |
190 return; | 223 return; |
191 } | 224 } |
192 event_handler_->OnConnectionChannelsConnected(this); | 225 event_handler_->OnConnectionChannelsConnected(this); |
193 event_handler_->CreateVideoStreams(this); | 226 event_handler_->CreateMediaStreams(this); |
194 } | 227 } |
195 | 228 |
196 void IceConnectionToClient::CloseChannels() { | 229 void IceConnectionToClient::CloseChannels() { |
197 control_dispatcher_.reset(); | 230 control_dispatcher_.reset(); |
198 event_dispatcher_.reset(); | 231 event_dispatcher_.reset(); |
199 video_dispatcher_.reset(); | 232 video_dispatcher_.reset(); |
200 audio_writer_.reset(); | 233 audio_writer_.reset(); |
201 } | 234 } |
202 | 235 |
203 } // namespace protocol | 236 } // namespace protocol |
204 } // namespace remoting | 237 } // namespace remoting |
OLD | NEW |