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/webrtc_video_stream.h" | 5 #include "remoting/protocol/webrtc_video_stream.h" |
| 6 | 6 |
| 7 #include <utility> | |
| 8 | |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 9 #include "base/task_runner_util.h" | 11 #include "base/task_runner_util.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 11 #include "remoting/base/constants.h" | 13 #include "remoting/base/constants.h" |
| 12 #include "remoting/codec/webrtc_video_encoder_vpx.h" | 14 #include "remoting/codec/webrtc_video_encoder_vpx.h" |
| 13 #include "remoting/protocol/frame_stats.h" | 15 #include "remoting/protocol/frame_stats.h" |
| 14 #include "remoting/protocol/host_video_stats_dispatcher.h" | 16 #include "remoting/protocol/host_video_stats_dispatcher.h" |
| 15 #include "remoting/protocol/webrtc_dummy_video_capturer.h" | 17 #include "remoting/protocol/webrtc_dummy_video_capturer.h" |
| 16 #include "remoting/protocol/webrtc_frame_scheduler_simple.h" | 18 #include "remoting/protocol/webrtc_frame_scheduler_simple.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 | 69 |
| 68 scoped_refptr<webrtc::PeerConnectionFactoryInterface> peer_connection_factory( | 70 scoped_refptr<webrtc::PeerConnectionFactoryInterface> peer_connection_factory( |
| 69 webrtc_transport->peer_connection_factory()); | 71 webrtc_transport->peer_connection_factory()); |
| 70 peer_connection_ = webrtc_transport->peer_connection(); | 72 peer_connection_ = webrtc_transport->peer_connection(); |
| 71 DCHECK(peer_connection_factory); | 73 DCHECK(peer_connection_factory); |
| 72 DCHECK(peer_connection_); | 74 DCHECK(peer_connection_); |
| 73 | 75 |
| 74 encode_task_runner_ = std::move(encode_task_runner); | 76 encode_task_runner_ = std::move(encode_task_runner); |
| 75 capturer_ = std::move(desktop_capturer); | 77 capturer_ = std::move(desktop_capturer); |
| 76 webrtc_transport_ = webrtc_transport; | 78 webrtc_transport_ = webrtc_transport; |
| 77 // TODO(isheriff): make this codec independent | 79 |
| 78 encoder_ = WebrtcVideoEncoderVpx::CreateForVP8(); | 80 webrtc_transport_->video_encoder_factory()->SetEncoderCreatedCallback( |
|
Sergey Ulanov
2017/03/31 19:23:11
Maybe call it "EncoderSelectedCallback"? That woul
Yuwei
2017/04/03 22:29:10
Done.
| |
| 81 base::Bind(&WebrtcVideoStream::OnEncoderCreated, | |
| 82 weak_factory_.GetWeakPtr())); | |
| 83 | |
| 79 capturer_->Start(this); | 84 capturer_->Start(this); |
| 80 | 85 |
| 81 // Set video stream constraints. | 86 // Set video stream constraints. |
| 82 webrtc::FakeConstraints video_constraints; | 87 webrtc::FakeConstraints video_constraints; |
| 83 video_constraints.AddMandatory( | 88 video_constraints.AddMandatory( |
| 84 webrtc::MediaConstraintsInterface::kMinFrameRate, 5); | 89 webrtc::MediaConstraintsInterface::kMinFrameRate, 5); |
| 85 | 90 |
| 86 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> src = | 91 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> src = |
| 87 peer_connection_factory->CreateVideoSource(new WebrtcDummyVideoCapturer(), | 92 peer_connection_factory->CreateVideoSource(new WebrtcDummyVideoCapturer(), |
| 88 &video_constraints); | 93 &video_constraints); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 155 : frame->dpi(); | 160 : frame->dpi(); |
| 156 | 161 |
| 157 if (!frame_size_.equals(frame->size()) || !frame_dpi_.equals(dpi)) { | 162 if (!frame_size_.equals(frame->size()) || !frame_dpi_.equals(dpi)) { |
| 158 frame_size_ = frame->size(); | 163 frame_size_ = frame->size(); |
| 159 frame_dpi_ = dpi; | 164 frame_dpi_ = dpi; |
| 160 if (observer_) | 165 if (observer_) |
| 161 observer_->OnVideoSizeChanged(this, frame_size_, frame_dpi_); | 166 observer_->OnVideoSizeChanged(this, frame_size_, frame_dpi_); |
| 162 } | 167 } |
| 163 } | 168 } |
| 164 | 169 |
| 170 if (!encoder_) { | |
| 171 LOG(WARNING) << "Encoder has not been created yet."; | |
|
Yuwei
2017/03/29 01:08:33
I'm not sure whether this is very safe but IIUC th
Sergey Ulanov
2017/03/31 19:23:11
I think we need to fix this in WebrtcFrameSchedule
Yuwei
2017/04/03 22:29:10
Done.
| |
| 172 return; | |
| 173 } | |
| 174 | |
| 165 base::PostTaskAndReplyWithResult( | 175 base::PostTaskAndReplyWithResult( |
| 166 encode_task_runner_.get(), FROM_HERE, | 176 encode_task_runner_.get(), FROM_HERE, |
| 167 base::Bind(&WebrtcVideoStream::EncodeFrame, encoder_.get(), | 177 base::Bind(&WebrtcVideoStream::EncodeFrame, encoder_.get(), |
| 168 base::Passed(std::move(frame)), frame_params, | 178 base::Passed(std::move(frame)), frame_params, |
| 169 base::Passed(std::move(captured_frame_timestamps_))), | 179 base::Passed(std::move(captured_frame_timestamps_))), |
| 170 base::Bind(&WebrtcVideoStream::OnFrameEncoded, | 180 base::Bind(&WebrtcVideoStream::OnFrameEncoded, |
| 171 weak_factory_.GetWeakPtr())); | 181 weak_factory_.GetWeakPtr())); |
| 172 } | 182 } |
| 173 | 183 |
| 174 void WebrtcVideoStream::OnChannelInitialized( | 184 void WebrtcVideoStream::OnChannelInitialized( |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 247 stats.encode_pending_delay = frame.timestamps->encode_started_time - | 257 stats.encode_pending_delay = frame.timestamps->encode_started_time - |
| 248 frame.timestamps->capture_ended_time; | 258 frame.timestamps->capture_ended_time; |
| 249 | 259 |
| 250 stats.encode_delay = frame.timestamps->encode_ended_time - | 260 stats.encode_delay = frame.timestamps->encode_ended_time - |
| 251 frame.timestamps->encode_started_time; | 261 frame.timestamps->encode_started_time; |
| 252 | 262 |
| 253 video_stats_dispatcher_.OnVideoFrameStats(result.frame_id, stats); | 263 video_stats_dispatcher_.OnVideoFrameStats(result.frame_id, stats); |
| 254 } | 264 } |
| 255 } | 265 } |
| 256 | 266 |
| 267 void WebrtcVideoStream::OnEncoderCreated(webrtc::VideoCodecType codec_type) { | |
| 268 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 269 if (codec_type == webrtc::kVideoCodecVP8) { | |
| 270 encoder_ = WebrtcVideoEncoderVpx::CreateForVP8(); | |
| 271 } else if (codec_type == webrtc::kVideoCodecVP9) { | |
| 272 encoder_ = WebrtcVideoEncoderVpx::CreateForVP9(); | |
| 273 } else { | |
| 274 LOG(FATAL) << "Unknown codec type: " << codec_type; | |
| 275 } | |
| 276 } | |
| 277 | |
| 257 } // namespace protocol | 278 } // namespace protocol |
| 258 } // namespace remoting | 279 } // namespace remoting |
| OLD | NEW |