Enable the HW VideoToolbox encoder on mac.

This CL was originally submitted by an external contributor in
https://chromium-review.googlesource.com/c/external/webrtc/+/582051.

I have rebased it to the new ObjC encoder class.

BUG=webrtc:8022

Review-Url: https://codereview.webrtc.org/3003653002
Cr-Commit-Position: refs/heads/master@{#19486}
This commit is contained in:
kthelgason
2017-08-24 04:22:58 -07:00
committed by Commit Bot
parent 1cdddc96fa
commit a4955b4d9a

View File

@ -509,11 +509,22 @@ CFStringRef ExtractProfile(const cricket::VideoCodec &codec) {
CFRelease(pixelFormat); CFRelease(pixelFormat);
pixelFormat = nullptr; pixelFormat = nullptr;
} }
OSStatus status = VTCompressionSessionCreate(nullptr, // use default allocator CFMutableDictionaryRef encoder_specs = nullptr;
#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
// Currently hw accl is supported above 360p on mac, below 360p
// the compression session will be created with hw accl disabled.
encoder_specs = CFDictionaryCreateMutable(
nullptr, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(encoder_specs,
kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder,
kCFBooleanTrue);
#endif
OSStatus status =
VTCompressionSessionCreate(nullptr, // use default allocator
_width, _width,
_height, _height,
kCMVideoCodecType_H264, kCMVideoCodecType_H264,
nullptr, // use default encoder encoder_specs, // use hardware accelerated encoder if available
sourceAttributes, sourceAttributes,
nullptr, // use default compressed data allocator nullptr, // use default compressed data allocator
compressionOutputCallback, compressionOutputCallback,
@ -523,10 +534,26 @@ CFStringRef ExtractProfile(const cricket::VideoCodec &codec) {
CFRelease(sourceAttributes); CFRelease(sourceAttributes);
sourceAttributes = nullptr; sourceAttributes = nullptr;
} }
if (encoder_specs) {
CFRelease(encoder_specs);
encoder_specs = nullptr;
}
if (status != noErr) { if (status != noErr) {
LOG(LS_ERROR) << "Failed to create compression session: " << status; LOG(LS_ERROR) << "Failed to create compression session: " << status;
return WEBRTC_VIDEO_CODEC_ERROR; return WEBRTC_VIDEO_CODEC_ERROR;
} }
#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
CFBooleanRef hwaccl_enabled = nullptr;
status = VTSessionCopyProperty(_compressionSession,
kVTCompressionPropertyKey_UsingHardwareAcceleratedVideoEncoder,
nullptr,
&hwaccl_enabled);
if (status == noErr && (CFBooleanGetValue(hwaccl_enabled))) {
LOG(LS_INFO) << "Compression session created with hw accl enabled";
} else {
LOG(LS_INFO) << "Compression session created with hw accl disabled";
}
#endif
[self configureCompressionSession]; [self configureCompressionSession];
return WEBRTC_VIDEO_CODEC_OK; return WEBRTC_VIDEO_CODEC_OK;
} }