| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 15 matching lines...) Expand all Loading... |
| 26 #include "webrtc/base/logging.h" | 26 #include "webrtc/base/logging.h" |
| 27 #include "webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu.h" | 27 #include "webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu.h" |
| 28 #include "webrtc/system_wrappers/include/clock.h" | 28 #include "webrtc/system_wrappers/include/clock.h" |
| 29 | 29 |
| 30 namespace internal { | 30 namespace internal { |
| 31 | 31 |
| 32 // The ratio between kVTCompressionPropertyKey_DataRateLimits and | 32 // The ratio between kVTCompressionPropertyKey_DataRateLimits and |
| 33 // kVTCompressionPropertyKey_AverageBitRate. The data rate limit is set higher | 33 // kVTCompressionPropertyKey_AverageBitRate. The data rate limit is set higher |
| 34 // than the average bit rate to avoid undershooting the target. | 34 // than the average bit rate to avoid undershooting the target. |
| 35 const float kLimitToAverageBitRateFactor = 1.5f; | 35 const float kLimitToAverageBitRateFactor = 1.5f; |
| 36 // These thresholds deviate from the default h264 QP thresholds, as they |
| 37 // have been found to work better on devices that support VideoToolbox |
| 38 const int kLowH264QpThreshold = 28; |
| 39 const int kHighH264QpThreshold = 39; |
| 36 | 40 |
| 37 // Convenience function for creating a dictionary. | 41 // Convenience function for creating a dictionary. |
| 38 inline CFDictionaryRef CreateCFDictionary(CFTypeRef* keys, | 42 inline CFDictionaryRef CreateCFDictionary(CFTypeRef* keys, |
| 39 CFTypeRef* values, | 43 CFTypeRef* values, |
| 40 size_t size) { | 44 size_t size) { |
| 41 return CFDictionaryCreate(kCFAllocatorDefault, keys, values, size, | 45 return CFDictionaryCreate(kCFAllocatorDefault, keys, values, size, |
| 42 &kCFTypeDictionaryKeyCallBacks, | 46 &kCFTypeDictionaryKeyCallBacks, |
| 43 &kCFTypeDictionaryValueCallBacks); | 47 &kCFTypeDictionaryValueCallBacks); |
| 44 } | 48 } |
| 45 | 49 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 DestroyCompressionSession(); | 229 DestroyCompressionSession(); |
| 226 } | 230 } |
| 227 | 231 |
| 228 int H264VideoToolboxEncoder::InitEncode(const VideoCodec* codec_settings, | 232 int H264VideoToolboxEncoder::InitEncode(const VideoCodec* codec_settings, |
| 229 int number_of_cores, | 233 int number_of_cores, |
| 230 size_t max_payload_size) { | 234 size_t max_payload_size) { |
| 231 RTC_DCHECK(codec_settings); | 235 RTC_DCHECK(codec_settings); |
| 232 RTC_DCHECK_EQ(codec_settings->codecType, kVideoCodecH264); | 236 RTC_DCHECK_EQ(codec_settings->codecType, kVideoCodecH264); |
| 233 { | 237 { |
| 234 rtc::CritScope lock(&quality_scaler_crit_); | 238 rtc::CritScope lock(&quality_scaler_crit_); |
| 235 quality_scaler_.Init(QualityScaler::kLowH264QpThreshold, | 239 quality_scaler_.Init(internal::kLowH264QpThreshold, |
| 236 QualityScaler::kBadH264QpThreshold, | 240 internal::kHighH264QpThreshold, |
| 237 codec_settings->startBitrate, codec_settings->width, | 241 codec_settings->startBitrate, codec_settings->width, |
| 238 codec_settings->height, codec_settings->maxFramerate); | 242 codec_settings->height, codec_settings->maxFramerate); |
| 239 QualityScaler::Resolution res = quality_scaler_.GetScaledResolution(); | 243 QualityScaler::Resolution res = quality_scaler_.GetScaledResolution(); |
| 240 // TODO(tkchin): We may need to enforce width/height dimension restrictions | 244 // TODO(tkchin): We may need to enforce width/height dimension restrictions |
| 241 // to match what the encoder supports. | 245 // to match what the encoder supports. |
| 242 width_ = res.width; | 246 width_ = res.width; |
| 243 height_ = res.height; | 247 height_ = res.height; |
| 244 } | 248 } |
| 245 // We can only set average bitrate on the HW encoder. | 249 // We can only set average bitrate on the HW encoder. |
| 246 target_bitrate_bps_ = codec_settings->startBitrate; | 250 target_bitrate_bps_ = codec_settings->startBitrate; |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 627 if (result != 0) { | 631 if (result != 0) { |
| 628 LOG(LS_ERROR) << "Encode callback failed: " << result; | 632 LOG(LS_ERROR) << "Encode callback failed: " << result; |
| 629 return; | 633 return; |
| 630 } | 634 } |
| 631 bitrate_adjuster_.Update(frame._size); | 635 bitrate_adjuster_.Update(frame._size); |
| 632 } | 636 } |
| 633 | 637 |
| 634 } // namespace webrtc | 638 } // namespace webrtc |
| 635 | 639 |
| 636 #endif // defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED) | 640 #endif // defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED) |
| OLD | NEW |