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 |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
141 timestamp_(0), | 141 timestamp_(0), |
142 feedback_mode_(false), | 142 feedback_mode_(false), |
143 qp_max_(56), // Setting for max quantizer. | 143 qp_max_(56), // Setting for max quantizer. |
144 cpu_speed_default_(-6), | 144 cpu_speed_default_(-6), |
145 rc_max_intra_target_(0), | 145 rc_max_intra_target_(0), |
146 token_partitions_(VP8_ONE_TOKENPARTITION), | 146 token_partitions_(VP8_ONE_TOKENPARTITION), |
147 down_scale_requested_(false), | 147 down_scale_requested_(false), |
148 down_scale_bitrate_(0), | 148 down_scale_bitrate_(0), |
149 tl0_frame_dropper_(), | 149 tl0_frame_dropper_(), |
150 tl1_frame_dropper_(kTl1MaxTimeToDropFrames), | 150 tl1_frame_dropper_(kTl1MaxTimeToDropFrames), |
151 key_frame_request_(kMaxSimulcastStreams, false) { | 151 key_frame_request_(kMaxSimulcastStreams, false), |
152 quality_scaler_enabled_(false) { | |
152 uint32_t seed = static_cast<uint32_t>(TickTime::MillisecondTimestamp()); | 153 uint32_t seed = static_cast<uint32_t>(TickTime::MillisecondTimestamp()); |
153 srand(seed); | 154 srand(seed); |
154 | 155 |
155 picture_id_.reserve(kMaxSimulcastStreams); | 156 picture_id_.reserve(kMaxSimulcastStreams); |
156 last_key_frame_picture_id_.reserve(kMaxSimulcastStreams); | 157 last_key_frame_picture_id_.reserve(kMaxSimulcastStreams); |
157 temporal_layers_.reserve(kMaxSimulcastStreams); | 158 temporal_layers_.reserve(kMaxSimulcastStreams); |
158 raw_images_.reserve(kMaxSimulcastStreams); | 159 raw_images_.reserve(kMaxSimulcastStreams); |
159 encoded_images_.reserve(kMaxSimulcastStreams); | 160 encoded_images_.reserve(kMaxSimulcastStreams); |
160 send_stream_.reserve(kMaxSimulcastStreams); | 161 send_stream_.reserve(kMaxSimulcastStreams); |
161 cpu_speed_.assign(kMaxSimulcastStreams, -6); // Set default to -6. | 162 cpu_speed_.assign(kMaxSimulcastStreams, -6); // Set default to -6. |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
576 stream_bitrates[stream_idx], inst->maxBitrate, inst->maxFramerate, | 577 stream_bitrates[stream_idx], inst->maxBitrate, inst->maxFramerate, |
577 &configurations_[i]); | 578 &configurations_[i]); |
578 } | 579 } |
579 } | 580 } |
580 | 581 |
581 rps_.Init(); | 582 rps_.Init(); |
582 quality_scaler_.Init(codec_.qpMax / QualityScaler::kDefaultLowQpDenominator, | 583 quality_scaler_.Init(codec_.qpMax / QualityScaler::kDefaultLowQpDenominator, |
583 false); | 584 false); |
584 quality_scaler_.ReportFramerate(codec_.maxFramerate); | 585 quality_scaler_.ReportFramerate(codec_.maxFramerate); |
585 | 586 |
587 // Only apply scaling to improve for single-layer streams. The scaling metrics | |
588 // use frame drops as a signal and is only applicable when we drop frames. | |
589 quality_scaler_enabled_ = encoders_.size() == 1 && | |
590 configurations_[0].rc_dropframe_thresh > 0 && | |
591 codec_.codecSpecific.VP8.automaticResizeOn; | |
592 | |
586 return InitAndSetControlSettings(); | 593 return InitAndSetControlSettings(); |
587 } | 594 } |
588 | 595 |
589 int VP8EncoderImpl::SetCpuSpeed(int width, int height) { | 596 int VP8EncoderImpl::SetCpuSpeed(int width, int height) { |
590 #if defined(WEBRTC_ARCH_ARM) || defined(WEBRTC_ARCH_ARM64) | 597 #if defined(WEBRTC_ARCH_ARM) || defined(WEBRTC_ARCH_ARM64) |
591 // On mobile platform, always set to -12 to leverage between cpu usage | 598 // On mobile platform, always set to -12 to leverage between cpu usage |
592 // and video quality. | 599 // and video quality. |
593 return -12; | 600 return -12; |
594 #else | 601 #else |
595 // For non-ARM, increase encoding complexity (i.e., use lower speed setting) | 602 // For non-ARM, increase encoding complexity (i.e., use lower speed setting) |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
697 const std::vector<VideoFrameType>* frame_types) { | 704 const std::vector<VideoFrameType>* frame_types) { |
698 TRACE_EVENT1("webrtc", "VP8::Encode", "timestamp", frame.timestamp()); | 705 TRACE_EVENT1("webrtc", "VP8::Encode", "timestamp", frame.timestamp()); |
699 | 706 |
700 if (!inited_) | 707 if (!inited_) |
701 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; | 708 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; |
702 if (frame.IsZeroSize()) | 709 if (frame.IsZeroSize()) |
703 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; | 710 return WEBRTC_VIDEO_CODEC_ERR_PARAMETER; |
704 if (encoded_complete_callback_ == NULL) | 711 if (encoded_complete_callback_ == NULL) |
705 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; | 712 return WEBRTC_VIDEO_CODEC_UNINITIALIZED; |
706 | 713 |
707 // Only apply scaling to improve for single-layer streams. The scaling metrics | 714 if (quality_scaler_enabled_) |
708 // use frame drops as a signal and is only applicable when we drop frames. | |
709 const bool use_quality_scaler = encoders_.size() == 1 && | |
710 configurations_[0].rc_dropframe_thresh > 0 && | |
711 codec_.codecSpecific.VP8.automaticResizeOn; | |
712 if (use_quality_scaler) | |
713 quality_scaler_.OnEncodeFrame(frame); | 715 quality_scaler_.OnEncodeFrame(frame); |
714 const VideoFrame& input_image = | 716 const VideoFrame& input_image = |
715 use_quality_scaler ? quality_scaler_.GetScaledFrame(frame) : frame; | 717 quality_scaler_enabled_ ? quality_scaler_.GetScaledFrame(frame) : frame; |
716 | 718 |
717 if (use_quality_scaler && (input_image.width() != codec_.width || | 719 if (quality_scaler_enabled_ && (input_image.width() != codec_.width || |
718 input_image.height() != codec_.height)) { | 720 input_image.height() != codec_.height)) { |
719 int ret = UpdateCodecFrameSize(input_image); | 721 int ret = UpdateCodecFrameSize(input_image); |
720 if (ret < 0) | 722 if (ret < 0) |
721 return ret; | 723 return ret; |
722 } | 724 } |
723 | 725 |
724 // Since we are extracting raw pointers from |input_image| to | 726 // Since we are extracting raw pointers from |input_image| to |
725 // |raw_images_[0]|, the resolution of these frames must match. Note that | 727 // |raw_images_[0]|, the resolution of these frames must match. Note that |
726 // |input_image| might be scaled from |frame|. In that case, the resolution of | 728 // |input_image| might be scaled from |frame|. In that case, the resolution of |
727 // |raw_images_[0]| should have been updated in UpdateCodecFrameSize. | 729 // |raw_images_[0]| should have been updated in UpdateCodecFrameSize. |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1001 encoded_images_[encoder_idx]._length, | 1003 encoded_images_[encoder_idx]._length, |
1002 encoded_images_[encoder_idx]._timeStamp, qp); | 1004 encoded_images_[encoder_idx]._timeStamp, qp); |
1003 if (send_stream_[stream_idx]) { | 1005 if (send_stream_[stream_idx]) { |
1004 if (encoded_images_[encoder_idx]._length > 0) { | 1006 if (encoded_images_[encoder_idx]._length > 0) { |
1005 TRACE_COUNTER_ID1("webrtc", "EncodedFrameSize", encoder_idx, | 1007 TRACE_COUNTER_ID1("webrtc", "EncodedFrameSize", encoder_idx, |
1006 encoded_images_[encoder_idx]._length); | 1008 encoded_images_[encoder_idx]._length); |
1007 encoded_images_[encoder_idx]._encodedHeight = | 1009 encoded_images_[encoder_idx]._encodedHeight = |
1008 codec_.simulcastStream[stream_idx].height; | 1010 codec_.simulcastStream[stream_idx].height; |
1009 encoded_images_[encoder_idx]._encodedWidth = | 1011 encoded_images_[encoder_idx]._encodedWidth = |
1010 codec_.simulcastStream[stream_idx].width; | 1012 codec_.simulcastStream[stream_idx].width; |
1013 encoded_images_[encoder_idx] | |
1014 .adapt_reason_.quality_limited_resolution_available = | |
1015 quality_scaler_enabled_; | |
1016 if (quality_scaler_enabled_) { | |
1017 encoded_images_[encoder_idx] | |
1018 .adapt_reason_.quality_limited_resolution = | |
1019 quality_scaler_.downscale_shift() > 0; | |
stefan-webrtc
2015/09/16 07:36:57
Would it be more useful to log the number of times
stefan-webrtc
2015/09/16 07:37:35
To clarify, I think it would be useful to know as
åsapersson
2015/09/17 14:24:45
Added the average number of times a frame is scale
| |
1020 } | |
1011 encoded_complete_callback_->Encoded(encoded_images_[encoder_idx], | 1021 encoded_complete_callback_->Encoded(encoded_images_[encoder_idx], |
1012 &codec_specific, &frag_info); | 1022 &codec_specific, &frag_info); |
1013 } else if (codec_.mode == kScreensharing) { | 1023 } else if (codec_.mode == kScreensharing) { |
1014 result = WEBRTC_VIDEO_CODEC_TARGET_BITRATE_OVERSHOOT; | 1024 result = WEBRTC_VIDEO_CODEC_TARGET_BITRATE_OVERSHOOT; |
1015 } | 1025 } |
1016 } else { | 1026 } else { |
1017 // Required in case padding is applied to dropped frames. | 1027 // Required in case padding is applied to dropped frames. |
1018 encoded_images_[encoder_idx]._length = 0; | 1028 encoded_images_[encoder_idx]._length = 0; |
1019 encoded_images_[encoder_idx]._frameType = kSkipFrame; | 1029 encoded_images_[encoder_idx]._frameType = kSkipFrame; |
1020 codec_specific.codecType = kVideoCodecVP8; | 1030 codec_specific.codecType = kVideoCodecVP8; |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1393 return -1; | 1403 return -1; |
1394 } | 1404 } |
1395 if (vpx_codec_control(copy->decoder_, VP8_SET_REFERENCE, ref_frame_) | 1405 if (vpx_codec_control(copy->decoder_, VP8_SET_REFERENCE, ref_frame_) |
1396 != VPX_CODEC_OK) { | 1406 != VPX_CODEC_OK) { |
1397 return -1; | 1407 return -1; |
1398 } | 1408 } |
1399 return 0; | 1409 return 0; |
1400 } | 1410 } |
1401 | 1411 |
1402 } // namespace webrtc | 1412 } // namespace webrtc |
OLD | NEW |