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/base/timeutils.h" |
20 #include "webrtc/common_video/include/video_image.h" | 21 #include "webrtc/common_video/include/video_image.h" |
21 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 22 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
22 #include "webrtc/frame_callback.h" | 23 #include "webrtc/frame_callback.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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 } | 409 } |
410 | 410 |
411 int32_t ViEEncoder::SendData(const uint8_t payload_type, | 411 int32_t ViEEncoder::SendData(const uint8_t payload_type, |
412 const EncodedImage& encoded_image, | 412 const EncodedImage& encoded_image, |
413 const RTPFragmentationHeader* fragmentation_header, | 413 const RTPFragmentationHeader* fragmentation_header, |
414 const RTPVideoHeader* rtp_video_hdr) { | 414 const RTPVideoHeader* rtp_video_hdr) { |
415 RTC_DCHECK(send_payload_router_); | 415 RTC_DCHECK(send_payload_router_); |
416 | 416 |
417 { | 417 { |
418 rtc::CritScope lock(&data_cs_); | 418 rtc::CritScope lock(&data_cs_); |
419 time_of_last_frame_activity_ms_ = TickTime::MillisecondTimestamp(); | 419 time_of_last_frame_activity_ms_ = rtc::Time64(); |
420 } | 420 } |
421 | 421 |
422 if (stats_proxy_) | 422 if (stats_proxy_) |
423 stats_proxy_->OnSendEncodedImage(encoded_image, rtp_video_hdr); | 423 stats_proxy_->OnSendEncodedImage(encoded_image, rtp_video_hdr); |
424 | 424 |
425 bool success = send_payload_router_->RoutePayload( | 425 bool success = send_payload_router_->RoutePayload( |
426 encoded_image._frameType, payload_type, encoded_image._timeStamp, | 426 encoded_image._frameType, payload_type, encoded_image._timeStamp, |
427 encoded_image.capture_time_ms_, encoded_image._buffer, | 427 encoded_image.capture_time_ms_, encoded_image._buffer, |
428 encoded_image._length, fragmentation_header, rtp_video_hdr); | 428 encoded_image._length, fragmentation_header, rtp_video_hdr); |
429 overuse_detector_->FrameSent(encoded_image._timeStamp); | 429 overuse_detector_->FrameSent(encoded_image._timeStamp); |
(...skipping 27 matching lines...) Expand all Loading... |
457 has_received_rpsi_ = true; | 457 has_received_rpsi_ = true; |
458 } | 458 } |
459 | 459 |
460 void ViEEncoder::OnReceivedIntraFrameRequest(uint32_t ssrc) { | 460 void ViEEncoder::OnReceivedIntraFrameRequest(uint32_t ssrc) { |
461 // Key frame request from remote side, signal to VCM. | 461 // Key frame request from remote side, signal to VCM. |
462 TRACE_EVENT0("webrtc", "OnKeyFrameRequest"); | 462 TRACE_EVENT0("webrtc", "OnKeyFrameRequest"); |
463 | 463 |
464 for (size_t i = 0; i < ssrcs_.size(); ++i) { | 464 for (size_t i = 0; i < ssrcs_.size(); ++i) { |
465 if (ssrcs_[i] != ssrc) | 465 if (ssrcs_[i] != ssrc) |
466 continue; | 466 continue; |
467 int64_t now_ms = TickTime::MillisecondTimestamp(); | 467 int64_t now_ms = rtc::Time64(); |
468 { | 468 { |
469 rtc::CritScope lock(&data_cs_); | 469 rtc::CritScope lock(&data_cs_); |
470 if (time_last_intra_request_ms_[i] + kMinKeyFrameRequestIntervalMs > | 470 if (time_last_intra_request_ms_[i] + kMinKeyFrameRequestIntervalMs > |
471 now_ms) { | 471 now_ms) { |
472 return; | 472 return; |
473 } | 473 } |
474 time_last_intra_request_ms_[i] = now_ms; | 474 time_last_intra_request_ms_[i] = now_ms; |
475 } | 475 } |
476 vcm_->IntraFrameRequest(static_cast<int>(i)); | 476 vcm_->IntraFrameRequest(static_cast<int>(i)); |
477 return; | 477 return; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
530 const uint32_t width, | 530 const uint32_t width, |
531 const uint32_t height) { | 531 const uint32_t height) { |
532 return vp_->SetTargetResolution(width, height, frame_rate); | 532 return vp_->SetTargetResolution(width, height, frame_rate); |
533 } | 533 } |
534 | 534 |
535 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { | 535 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { |
536 vp_->SetTargetFramerate(frame_rate); | 536 vp_->SetTargetFramerate(frame_rate); |
537 } | 537 } |
538 | 538 |
539 } // namespace webrtc | 539 } // namespace webrtc |
OLD | NEW |