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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 | 71 |
| 70 scoped_refptr<webrtc::PeerConnectionFactoryInterface> peer_connection_factory( | 72 scoped_refptr<webrtc::PeerConnectionFactoryInterface> peer_connection_factory( |
| 71 webrtc_transport->peer_connection_factory()); | 73 webrtc_transport->peer_connection_factory()); |
| 72 peer_connection_ = webrtc_transport->peer_connection(); | 74 peer_connection_ = webrtc_transport->peer_connection(); |
| 73 DCHECK(peer_connection_factory); | 75 DCHECK(peer_connection_factory); |
| 74 DCHECK(peer_connection_); | 76 DCHECK(peer_connection_); |
| 75 | 77 |
| 76 encode_task_runner_ = std::move(encode_task_runner); | 78 encode_task_runner_ = std::move(encode_task_runner); |
| 77 capturer_ = std::move(desktop_capturer); | 79 capturer_ = std::move(desktop_capturer); |
| 78 webrtc_transport_ = webrtc_transport; | 80 webrtc_transport_ = webrtc_transport; |
| 79 // TODO(isheriff): make this codec independent | 81 |
| 80 encoder_ = WebrtcVideoEncoderVpx::CreateForVP8(); | 82 webrtc_transport_->video_encoder_factory()->RegisterEncoderSelectedCallback( |
| 83 base::Bind(&WebrtcVideoStream::OnEncoderCreated, | |
| 84 weak_factory_.GetWeakPtr())); | |
| 85 | |
| 81 capturer_->Start(this); | 86 capturer_->Start(this); |
| 82 | 87 |
| 83 // Set video stream constraints. | 88 // Set video stream constraints. |
| 84 webrtc::FakeConstraints video_constraints; | 89 webrtc::FakeConstraints video_constraints; |
| 85 video_constraints.AddMandatory( | 90 video_constraints.AddMandatory( |
| 86 webrtc::MediaConstraintsInterface::kMinFrameRate, 5); | 91 webrtc::MediaConstraintsInterface::kMinFrameRate, 5); |
| 87 | 92 |
| 88 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> src = | 93 rtc::scoped_refptr<webrtc::VideoTrackSourceInterface> src = |
| 89 peer_connection_factory->CreateVideoSource(new WebrtcDummyVideoCapturer(), | 94 peer_connection_factory->CreateVideoSource(new WebrtcDummyVideoCapturer(), |
| 90 &video_constraints); | 95 &video_constraints); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 : frame->dpi(); | 162 : frame->dpi(); |
| 158 | 163 |
| 159 if (!frame_size_.equals(frame->size()) || !frame_dpi_.equals(dpi)) { | 164 if (!frame_size_.equals(frame->size()) || !frame_dpi_.equals(dpi)) { |
| 160 frame_size_ = frame->size(); | 165 frame_size_ = frame->size(); |
| 161 frame_dpi_ = dpi; | 166 frame_dpi_ = dpi; |
| 162 if (observer_) | 167 if (observer_) |
| 163 observer_->OnVideoSizeChanged(this, frame_size_, frame_dpi_); | 168 observer_->OnVideoSizeChanged(this, frame_size_, frame_dpi_); |
| 164 } | 169 } |
| 165 } | 170 } |
| 166 | 171 |
| 172 if (!encoder_) { | |
|
Sergey Ulanov
2017/04/04 00:21:25
Don't need this anymore. Replace with a DCHECK()?
Yuwei
2017/04/04 00:50:48
Done.
| |
| 173 LOG(ERROR) << "Encoder is not ready to accept frames."; | |
| 174 return; | |
| 175 } | |
| 176 | |
| 167 base::PostTaskAndReplyWithResult( | 177 base::PostTaskAndReplyWithResult( |
| 168 encode_task_runner_.get(), FROM_HERE, | 178 encode_task_runner_.get(), FROM_HERE, |
| 169 base::Bind(&WebrtcVideoStream::EncodeFrame, encoder_.get(), | 179 base::Bind(&WebrtcVideoStream::EncodeFrame, encoder_.get(), |
| 170 base::Passed(std::move(frame)), frame_params, | 180 base::Passed(std::move(frame)), frame_params, |
| 171 base::Passed(std::move(captured_frame_stats_))), | 181 base::Passed(std::move(captured_frame_stats_))), |
| 172 base::Bind(&WebrtcVideoStream::OnFrameEncoded, | 182 base::Bind(&WebrtcVideoStream::OnFrameEncoded, |
| 173 weak_factory_.GetWeakPtr())); | 183 weak_factory_.GetWeakPtr())); |
| 174 } | 184 } |
| 175 | 185 |
| 176 void WebrtcVideoStream::OnChannelInitialized( | 186 void WebrtcVideoStream::OnChannelInitialized( |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 | 264 |
| 255 stats.encode_delay = | 265 stats.encode_delay = |
| 256 frame.stats->encode_ended_time - frame.stats->encode_started_time; | 266 frame.stats->encode_ended_time - frame.stats->encode_started_time; |
| 257 | 267 |
| 258 stats.capturer_id = frame.stats->capturer_id; | 268 stats.capturer_id = frame.stats->capturer_id; |
| 259 | 269 |
| 260 video_stats_dispatcher_.OnVideoFrameStats(result.frame_id, stats); | 270 video_stats_dispatcher_.OnVideoFrameStats(result.frame_id, stats); |
| 261 } | 271 } |
| 262 } | 272 } |
| 263 | 273 |
| 274 void WebrtcVideoStream::OnEncoderCreated(webrtc::VideoCodecType codec_type) { | |
| 275 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 276 if (codec_type == webrtc::kVideoCodecVP8) { | |
| 277 encoder_ = WebrtcVideoEncoderVpx::CreateForVP8(); | |
| 278 } else if (codec_type == webrtc::kVideoCodecVP9) { | |
| 279 encoder_ = WebrtcVideoEncoderVpx::CreateForVP9(); | |
| 280 } else { | |
| 281 LOG(FATAL) << "Unknown codec type: " << codec_type; | |
| 282 } | |
| 283 } | |
| 284 | |
| 264 } // namespace protocol | 285 } // namespace protocol |
| 265 } // namespace remoting | 286 } // namespace remoting |
| OLD | NEW |