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