OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/video/vie_encoder.h" | 11 #include "webrtc/video/vie_encoder.h" |
12 | 12 |
13 #include <assert.h> | 13 #include <assert.h> |
14 | 14 |
15 #include <algorithm> | 15 #include <algorithm> |
16 | 16 |
17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
18 #include "webrtc/base/logging.h" | 18 #include "webrtc/base/logging.h" |
19 #include "webrtc/base/trace_event.h" | 19 #include "webrtc/base/trace_event.h" |
20 #include "webrtc/common_video/include/frame_callback.h" | 20 #include "webrtc/common_video/include/frame_callback.h" |
| 21 #include "webrtc/base/timeutils.h" |
21 #include "webrtc/common_video/include/video_image.h" | 22 #include "webrtc/common_video/include/video_image.h" |
22 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 23 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
23 #include "webrtc/modules/pacing/paced_sender.h" | 24 #include "webrtc/modules/pacing/paced_sender.h" |
24 #include "webrtc/modules/utility/include/process_thread.h" | 25 #include "webrtc/modules/utility/include/process_thread.h" |
25 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 26 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
26 #include "webrtc/modules/video_coding/include/video_coding.h" | 27 #include "webrtc/modules/video_coding/include/video_coding.h" |
27 #include "webrtc/modules/video_coding/include/video_coding_defines.h" | 28 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
28 #include "webrtc/system_wrappers/include/clock.h" | 29 #include "webrtc/system_wrappers/include/clock.h" |
29 #include "webrtc/system_wrappers/include/metrics.h" | 30 #include "webrtc/system_wrappers/include/metrics.h" |
30 #include "webrtc/system_wrappers/include/tick_util.h" | |
31 #include "webrtc/video/overuse_frame_detector.h" | 31 #include "webrtc/video/overuse_frame_detector.h" |
32 #include "webrtc/video/payload_router.h" | 32 #include "webrtc/video/payload_router.h" |
33 #include "webrtc/video/send_statistics_proxy.h" | 33 #include "webrtc/video/send_statistics_proxy.h" |
34 #include "webrtc/video_frame.h" | 34 #include "webrtc/video_frame.h" |
35 | 35 |
36 namespace webrtc { | 36 namespace webrtc { |
37 | 37 |
38 static const float kStopPaddingThresholdMs = 2000; | 38 static const float kStopPaddingThresholdMs = 2000; |
39 static const int kMinKeyFrameRequestIntervalMs = 300; | 39 static const int kMinKeyFrameRequestIntervalMs = 300; |
40 | 40 |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 } | 260 } |
261 } | 261 } |
262 | 262 |
263 // Disable padding if only sending one stream and video isn't suspended and | 263 // Disable padding if only sending one stream and video isn't suspended and |
264 // min-transmit bitrate isn't used (applied later). | 264 // min-transmit bitrate isn't used (applied later). |
265 if (!video_is_suspended && send_codec.numberOfSimulcastStreams <= 1) | 265 if (!video_is_suspended && send_codec.numberOfSimulcastStreams <= 1) |
266 pad_up_to_bitrate_bps = 0; | 266 pad_up_to_bitrate_bps = 0; |
267 | 267 |
268 // The amount of padding should decay to zero if no frames are being | 268 // The amount of padding should decay to zero if no frames are being |
269 // captured/encoded unless a min-transmit bitrate is used. | 269 // captured/encoded unless a min-transmit bitrate is used. |
270 int64_t now_ms = TickTime::MillisecondTimestamp(); | 270 int64_t now_ms = rtc::Time64(); |
271 if (now_ms - time_of_last_frame_activity_ms > kStopPaddingThresholdMs) | 271 if (now_ms - time_of_last_frame_activity_ms > kStopPaddingThresholdMs) |
272 pad_up_to_bitrate_bps = 0; | 272 pad_up_to_bitrate_bps = 0; |
273 | 273 |
274 // Pad up to min bitrate. | 274 // Pad up to min bitrate. |
275 if (pad_up_to_bitrate_bps < min_transmit_bitrate_bps) | 275 if (pad_up_to_bitrate_bps < min_transmit_bitrate_bps) |
276 pad_up_to_bitrate_bps = min_transmit_bitrate_bps; | 276 pad_up_to_bitrate_bps = min_transmit_bitrate_bps; |
277 | 277 |
278 // Padding may never exceed bitrate estimate. | 278 // Padding may never exceed bitrate estimate. |
279 if (pad_up_to_bitrate_bps > bitrate_bps) | 279 if (pad_up_to_bitrate_bps > bitrate_bps) |
280 pad_up_to_bitrate_bps = bitrate_bps; | 280 pad_up_to_bitrate_bps = bitrate_bps; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 | 314 |
315 void ViEEncoder::EncodeVideoFrame(const VideoFrame& video_frame) { | 315 void ViEEncoder::EncodeVideoFrame(const VideoFrame& video_frame) { |
316 if (!send_payload_router_->active()) { | 316 if (!send_payload_router_->active()) { |
317 // We've paused or we have no channels attached, don't waste resources on | 317 // We've paused or we have no channels attached, don't waste resources on |
318 // encoding. | 318 // encoding. |
319 return; | 319 return; |
320 } | 320 } |
321 VideoCodecType codec_type; | 321 VideoCodecType codec_type; |
322 { | 322 { |
323 rtc::CritScope lock(&data_cs_); | 323 rtc::CritScope lock(&data_cs_); |
324 time_of_last_frame_activity_ms_ = TickTime::MillisecondTimestamp(); | 324 time_of_last_frame_activity_ms_ = rtc::Time64(); |
325 if (EncoderPaused()) { | 325 if (EncoderPaused()) { |
326 TraceFrameDropStart(); | 326 TraceFrameDropStart(); |
327 return; | 327 return; |
328 } | 328 } |
329 TraceFrameDropEnd(); | 329 TraceFrameDropEnd(); |
330 codec_type = encoder_config_.codecType; | 330 codec_type = encoder_config_.codecType; |
331 } | 331 } |
332 | 332 |
333 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), | 333 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), |
334 "Encode"); | 334 "Encode"); |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 } | 404 } |
405 | 405 |
406 int32_t ViEEncoder::SendData(const uint8_t payload_type, | 406 int32_t ViEEncoder::SendData(const uint8_t payload_type, |
407 const EncodedImage& encoded_image, | 407 const EncodedImage& encoded_image, |
408 const RTPFragmentationHeader* fragmentation_header, | 408 const RTPFragmentationHeader* fragmentation_header, |
409 const RTPVideoHeader* rtp_video_hdr) { | 409 const RTPVideoHeader* rtp_video_hdr) { |
410 RTC_DCHECK(send_payload_router_); | 410 RTC_DCHECK(send_payload_router_); |
411 | 411 |
412 { | 412 { |
413 rtc::CritScope lock(&data_cs_); | 413 rtc::CritScope lock(&data_cs_); |
414 time_of_last_frame_activity_ms_ = TickTime::MillisecondTimestamp(); | 414 time_of_last_frame_activity_ms_ = rtc::Time64(); |
415 } | 415 } |
416 | 416 |
417 if (stats_proxy_) | 417 if (stats_proxy_) |
418 stats_proxy_->OnSendEncodedImage(encoded_image, rtp_video_hdr); | 418 stats_proxy_->OnSendEncodedImage(encoded_image, rtp_video_hdr); |
419 | 419 |
420 bool success = send_payload_router_->RoutePayload( | 420 bool success = send_payload_router_->RoutePayload( |
421 encoded_image._frameType, payload_type, encoded_image._timeStamp, | 421 encoded_image._frameType, payload_type, encoded_image._timeStamp, |
422 encoded_image.capture_time_ms_, encoded_image._buffer, | 422 encoded_image.capture_time_ms_, encoded_image._buffer, |
423 encoded_image._length, fragmentation_header, rtp_video_hdr); | 423 encoded_image._length, fragmentation_header, rtp_video_hdr); |
424 overuse_detector_->FrameSent(encoded_image._timeStamp); | 424 overuse_detector_->FrameSent(encoded_image._timeStamp); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 has_received_rpsi_ = true; | 475 has_received_rpsi_ = true; |
476 } | 476 } |
477 | 477 |
478 void ViEEncoder::OnReceivedIntraFrameRequest(uint32_t ssrc) { | 478 void ViEEncoder::OnReceivedIntraFrameRequest(uint32_t ssrc) { |
479 // Key frame request from remote side, signal to VCM. | 479 // Key frame request from remote side, signal to VCM. |
480 TRACE_EVENT0("webrtc", "OnKeyFrameRequest"); | 480 TRACE_EVENT0("webrtc", "OnKeyFrameRequest"); |
481 | 481 |
482 for (size_t i = 0; i < ssrcs_.size(); ++i) { | 482 for (size_t i = 0; i < ssrcs_.size(); ++i) { |
483 if (ssrcs_[i] != ssrc) | 483 if (ssrcs_[i] != ssrc) |
484 continue; | 484 continue; |
485 int64_t now_ms = TickTime::MillisecondTimestamp(); | 485 int64_t now_ms = rtc::Time64(); |
486 { | 486 { |
487 rtc::CritScope lock(&data_cs_); | 487 rtc::CritScope lock(&data_cs_); |
488 if (time_last_intra_request_ms_[i] + kMinKeyFrameRequestIntervalMs > | 488 if (time_last_intra_request_ms_[i] + kMinKeyFrameRequestIntervalMs > |
489 now_ms) { | 489 now_ms) { |
490 return; | 490 return; |
491 } | 491 } |
492 time_last_intra_request_ms_[i] = now_ms; | 492 time_last_intra_request_ms_[i] = now_ms; |
493 } | 493 } |
494 vcm_->IntraFrameRequest(static_cast<int>(i)); | 494 vcm_->IntraFrameRequest(static_cast<int>(i)); |
495 return; | 495 return; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 const uint32_t width, | 548 const uint32_t width, |
549 const uint32_t height) { | 549 const uint32_t height) { |
550 return vp_->SetTargetResolution(width, height, frame_rate); | 550 return vp_->SetTargetResolution(width, height, frame_rate); |
551 } | 551 } |
552 | 552 |
553 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { | 553 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { |
554 vp_->SetTargetFramerate(frame_rate); | 554 vp_->SetTargetFramerate(frame_rate); |
555 } | 555 } |
556 | 556 |
557 } // namespace webrtc | 557 } // namespace webrtc |
OLD | NEW |