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 "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/task_runner_util.h" | 9 #include "base/task_runner_util.h" |
| 10 #include "base/threading/thread_task_runner_handle.h" | 10 #include "base/threading/thread_task_runner_handle.h" |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 base::TimeTicks capture_started_time; | 34 base::TimeTicks capture_started_time; |
| 35 base::TimeTicks capture_ended_time; | 35 base::TimeTicks capture_ended_time; |
| 36 base::TimeDelta capture_delay; | 36 base::TimeDelta capture_delay; |
| 37 base::TimeTicks encode_started_time; | 37 base::TimeTicks encode_started_time; |
| 38 base::TimeTicks encode_ended_time; | 38 base::TimeTicks encode_ended_time; |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 struct WebrtcVideoStream::EncodedFrameWithTimestamps { | 41 struct WebrtcVideoStream::EncodedFrameWithTimestamps { |
| 42 std::unique_ptr<WebrtcVideoEncoder::EncodedFrame> frame; | 42 std::unique_ptr<WebrtcVideoEncoder::EncodedFrame> frame; |
| 43 std::unique_ptr<FrameTimestamps> timestamps; | 43 std::unique_ptr<FrameTimestamps> timestamps; |
| 44 uint32_t capturer_id; | |
|
Sergey Ulanov
2017/03/24 23:54:26
I think it's better to put this in WebrtcVideoStre
Hzj_jie
2017/03/25 02:15:49
I intended to do so, but it's a little bit complex
| |
| 44 }; | 45 }; |
| 45 | 46 |
| 46 WebrtcVideoStream::WebrtcVideoStream() | 47 WebrtcVideoStream::WebrtcVideoStream() |
| 47 : video_stats_dispatcher_(kStreamLabel), weak_factory_(this) {} | 48 : video_stats_dispatcher_(kStreamLabel), weak_factory_(this) {} |
| 48 | 49 |
| 49 WebrtcVideoStream::~WebrtcVideoStream() { | 50 WebrtcVideoStream::~WebrtcVideoStream() { |
| 50 if (stream_) { | 51 if (stream_) { |
| 51 for (const auto& track : stream_->GetVideoTracks()) { | 52 for (const auto& track : stream_->GetVideoTracks()) { |
| 52 stream_->RemoveTrack(track.get()); | 53 stream_->RemoveTrack(track.get()); |
| 53 } | 54 } |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 196 WebrtcVideoStream::EncodedFrameWithTimestamps WebrtcVideoStream::EncodeFrame( | 197 WebrtcVideoStream::EncodedFrameWithTimestamps WebrtcVideoStream::EncodeFrame( |
| 197 WebrtcVideoEncoder* encoder, | 198 WebrtcVideoEncoder* encoder, |
| 198 std::unique_ptr<webrtc::DesktopFrame> frame, | 199 std::unique_ptr<webrtc::DesktopFrame> frame, |
| 199 WebrtcVideoEncoder::FrameParams params, | 200 WebrtcVideoEncoder::FrameParams params, |
| 200 std::unique_ptr<WebrtcVideoStream::FrameTimestamps> timestamps) { | 201 std::unique_ptr<WebrtcVideoStream::FrameTimestamps> timestamps) { |
| 201 EncodedFrameWithTimestamps result; | 202 EncodedFrameWithTimestamps result; |
| 202 result.timestamps = std::move(timestamps); | 203 result.timestamps = std::move(timestamps); |
| 203 result.timestamps->encode_started_time = base::TimeTicks::Now(); | 204 result.timestamps->encode_started_time = base::TimeTicks::Now(); |
| 204 result.frame = encoder->Encode(frame.get(), params); | 205 result.frame = encoder->Encode(frame.get(), params); |
| 205 result.timestamps->encode_ended_time = base::TimeTicks::Now(); | 206 result.timestamps->encode_ended_time = base::TimeTicks::Now(); |
| 207 result.capturer_id = frame->capturer_id(); | |
| 206 return result; | 208 return result; |
| 207 } | 209 } |
| 208 | 210 |
| 209 void WebrtcVideoStream::OnFrameEncoded(EncodedFrameWithTimestamps frame) { | 211 void WebrtcVideoStream::OnFrameEncoded(EncodedFrameWithTimestamps frame) { |
| 210 DCHECK(thread_checker_.CalledOnValidThread()); | 212 DCHECK(thread_checker_.CalledOnValidThread()); |
| 211 | 213 |
| 212 HostFrameStats stats; | 214 HostFrameStats stats; |
| 213 scheduler_->OnFrameEncoded(frame.frame.get(), &stats); | 215 scheduler_->OnFrameEncoded(frame.frame.get(), &stats); |
| 214 | 216 |
| 215 if (!frame.frame) { | 217 if (!frame.frame) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 243 stats.capture_overhead_delay = (frame.timestamps->capture_ended_time - | 245 stats.capture_overhead_delay = (frame.timestamps->capture_ended_time - |
| 244 frame.timestamps->capture_started_time) - | 246 frame.timestamps->capture_started_time) - |
| 245 stats.capture_delay; | 247 stats.capture_delay; |
| 246 | 248 |
| 247 stats.encode_pending_delay = frame.timestamps->encode_started_time - | 249 stats.encode_pending_delay = frame.timestamps->encode_started_time - |
| 248 frame.timestamps->capture_ended_time; | 250 frame.timestamps->capture_ended_time; |
| 249 | 251 |
| 250 stats.encode_delay = frame.timestamps->encode_ended_time - | 252 stats.encode_delay = frame.timestamps->encode_ended_time - |
| 251 frame.timestamps->encode_started_time; | 253 frame.timestamps->encode_started_time; |
| 252 | 254 |
| 255 stats.capturer_id = frame.capturer_id; | |
| 256 | |
| 253 video_stats_dispatcher_.OnVideoFrameStats(result.frame_id, stats); | 257 video_stats_dispatcher_.OnVideoFrameStats(result.frame_id, stats); |
| 254 } | 258 } |
| 255 } | 259 } |
| 256 | 260 |
| 257 } // namespace protocol | 261 } // namespace protocol |
| 258 } // namespace remoting | 262 } // namespace remoting |
| OLD | NEW |