| 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 10 matching lines...) Expand all Loading... |
| 21 #include "RTCUIApplication.h" | 21 #include "RTCUIApplication.h" |
| 22 #endif | 22 #endif |
| 23 #include "libyuv/convert_from.h" | 23 #include "libyuv/convert_from.h" |
| 24 #include "webrtc/base/checks.h" | 24 #include "webrtc/base/checks.h" |
| 25 #include "webrtc/base/logging.h" | 25 #include "webrtc/base/logging.h" |
| 26 #include "webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu.h" | 26 #include "webrtc/modules/video_coding/codecs/h264/h264_video_toolbox_nalu.h" |
| 27 #include "webrtc/system_wrappers/include/clock.h" | 27 #include "webrtc/system_wrappers/include/clock.h" |
| 28 | 28 |
| 29 namespace internal { | 29 namespace internal { |
| 30 | 30 |
| 31 // The ratio between kVTCompressionPropertyKey_DataRateLimits and |
| 32 // kVTCompressionPropertyKey_AverageBitRate. The data rate limit is set higher |
| 33 // than the average bit rate to avoid undershooting the target. |
| 34 const float kLimitToAverageBitRateFactor = 1.5f; |
| 35 |
| 31 // Convenience function for creating a dictionary. | 36 // Convenience function for creating a dictionary. |
| 32 inline CFDictionaryRef CreateCFDictionary(CFTypeRef* keys, | 37 inline CFDictionaryRef CreateCFDictionary(CFTypeRef* keys, |
| 33 CFTypeRef* values, | 38 CFTypeRef* values, |
| 34 size_t size) { | 39 size_t size) { |
| 35 return CFDictionaryCreate(kCFAllocatorDefault, keys, values, size, | 40 return CFDictionaryCreate(kCFAllocatorDefault, keys, values, size, |
| 36 &kCFTypeDictionaryKeyCallBacks, | 41 &kCFTypeDictionaryKeyCallBacks, |
| 37 &kCFTypeDictionaryValueCallBacks); | 42 &kCFTypeDictionaryValueCallBacks); |
| 38 } | 43 } |
| 39 | 44 |
| 40 // Copies characters from a CFStringRef into a std::string. | 45 // Copies characters from a CFStringRef into a std::string. |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 512 } | 517 } |
| 513 } | 518 } |
| 514 | 519 |
| 515 void H264VideoToolboxEncoder::SetEncoderBitrateBps(uint32_t bitrate_bps) { | 520 void H264VideoToolboxEncoder::SetEncoderBitrateBps(uint32_t bitrate_bps) { |
| 516 if (compression_session_) { | 521 if (compression_session_) { |
| 517 internal::SetVTSessionProperty(compression_session_, | 522 internal::SetVTSessionProperty(compression_session_, |
| 518 kVTCompressionPropertyKey_AverageBitRate, | 523 kVTCompressionPropertyKey_AverageBitRate, |
| 519 bitrate_bps); | 524 bitrate_bps); |
| 520 | 525 |
| 521 // TODO(tkchin): Add a helper method to set array value. | 526 // TODO(tkchin): Add a helper method to set array value. |
| 522 int64_t bytes_per_second_value = bitrate_bps / 8; | 527 int64_t data_limit_bytes_per_second_value = static_cast<int64_t>( |
| 528 bitrate_bps * internal::kLimitToAverageBitRateFactor / 8); |
| 523 CFNumberRef bytes_per_second = | 529 CFNumberRef bytes_per_second = |
| 524 CFNumberCreate(kCFAllocatorDefault, | 530 CFNumberCreate(kCFAllocatorDefault, |
| 525 kCFNumberSInt64Type, | 531 kCFNumberSInt64Type, |
| 526 &bytes_per_second_value); | 532 &data_limit_bytes_per_second_value); |
| 527 int64_t one_second_value = 1; | 533 int64_t one_second_value = 1; |
| 528 CFNumberRef one_second = | 534 CFNumberRef one_second = |
| 529 CFNumberCreate(kCFAllocatorDefault, | 535 CFNumberCreate(kCFAllocatorDefault, |
| 530 kCFNumberSInt64Type, | 536 kCFNumberSInt64Type, |
| 531 &one_second_value); | 537 &one_second_value); |
| 532 const void* nums[2] = { bytes_per_second, one_second }; | 538 const void* nums[2] = { bytes_per_second, one_second }; |
| 533 CFArrayRef data_rate_limits = | 539 CFArrayRef data_rate_limits = |
| 534 CFArrayCreate(nullptr, nums, 2, &kCFTypeArrayCallBacks); | 540 CFArrayCreate(nullptr, nums, 2, &kCFTypeArrayCallBacks); |
| 535 OSStatus status = | 541 OSStatus status = |
| 536 VTSessionSetProperty(compression_session_, | 542 VTSessionSetProperty(compression_session_, |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 if (result != 0) { | 628 if (result != 0) { |
| 623 LOG(LS_ERROR) << "Encode callback failed: " << result; | 629 LOG(LS_ERROR) << "Encode callback failed: " << result; |
| 624 return; | 630 return; |
| 625 } | 631 } |
| 626 bitrate_adjuster_.Update(frame._size); | 632 bitrate_adjuster_.Update(frame._size); |
| 627 } | 633 } |
| 628 | 634 |
| 629 } // namespace webrtc | 635 } // namespace webrtc |
| 630 | 636 |
| 631 #endif // defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED) | 637 #endif // defined(WEBRTC_VIDEO_TOOLBOX_SUPPORTED) |
| OLD | NEW |