Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: webrtc/sdk/objc/Framework/Classes/VideoToolbox/RTCVideoEncoderH264.mm

Issue 3003653002: Enable the HW VideoToolbox encoder on mac. (Closed)
Patch Set: Make sure to compile this only on mac Created 3 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 491 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 CFTypeRef values[attributesSize] = {kCFBooleanTrue, ioSurfaceValue, pixelForma t}; 502 CFTypeRef values[attributesSize] = {kCFBooleanTrue, ioSurfaceValue, pixelForma t};
503 CFDictionaryRef sourceAttributes = CreateCFTypeDictionary(keys, values, attrib utesSize); 503 CFDictionaryRef sourceAttributes = CreateCFTypeDictionary(keys, values, attrib utesSize);
504 if (ioSurfaceValue) { 504 if (ioSurfaceValue) {
505 CFRelease(ioSurfaceValue); 505 CFRelease(ioSurfaceValue);
506 ioSurfaceValue = nullptr; 506 ioSurfaceValue = nullptr;
507 } 507 }
508 if (pixelFormat) { 508 if (pixelFormat) {
509 CFRelease(pixelFormat); 509 CFRelease(pixelFormat);
510 pixelFormat = nullptr; 510 pixelFormat = nullptr;
511 } 511 }
512 OSStatus status = VTCompressionSessionCreate(nullptr, // use default allocato r 512 CFMutableDictionaryRef encoder_specs = nullptr;
513 _width, 513 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
514 _height, 514 // Currently hw accl is supported above 360p on mac, below 360p
515 kCMVideoCodecType_H264, 515 // the compression session will be created with hw accl disabled.
516 nullptr, // use default encoder 516 encoder_specs = CFDictionaryCreateMutable(
517 sourceAttributes, 517 nullptr, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBac ks);
518 nullptr, // use default compress ed data allocator 518 CFDictionarySetValue(encoder_specs,
519 compressionOutputCallback, 519 kVTVideoEncoderSpecification_EnableHardwareAcceleratedVid eoEncoder,
520 nullptr, 520 kCFBooleanTrue);
521 &_compressionSession); 521 #endif
522 OSStatus status =
523 VTCompressionSessionCreate(nullptr, // use default allocator
524 _width,
525 _height,
526 kCMVideoCodecType_H264,
527 encoder_specs, // use hardware accelerated enc oder if available
528 sourceAttributes,
529 nullptr, // use default compressed data alloca tor
530 compressionOutputCallback,
531 nullptr,
532 &_compressionSession);
522 if (sourceAttributes) { 533 if (sourceAttributes) {
523 CFRelease(sourceAttributes); 534 CFRelease(sourceAttributes);
524 sourceAttributes = nullptr; 535 sourceAttributes = nullptr;
525 } 536 }
537 if (encoder_specs) {
538 CFRelease(encoder_specs);
539 encoder_specs = nullptr;
540 }
526 if (status != noErr) { 541 if (status != noErr) {
527 LOG(LS_ERROR) << "Failed to create compression session: " << status; 542 LOG(LS_ERROR) << "Failed to create compression session: " << status;
528 return WEBRTC_VIDEO_CODEC_ERROR; 543 return WEBRTC_VIDEO_CODEC_ERROR;
529 } 544 }
545 #if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
546 CFBooleanRef hwaccl_enabled = nullptr;
547 status = VTSessionCopyProperty(_compressionSession,
548 kVTCompressionPropertyKey_UsingHardwareAccelera tedVideoEncoder,
549 nullptr,
550 &hwaccl_enabled);
551 if (status == noErr && (CFBooleanGetValue(hwaccl_enabled))) {
552 LOG(LS_INFO) << "Compression session created with hw accl enabled";
553 } else {
554 LOG(LS_INFO) << "Compression session created with hw accl disabled";
555 }
556 #endif
530 [self configureCompressionSession]; 557 [self configureCompressionSession];
531 return WEBRTC_VIDEO_CODEC_OK; 558 return WEBRTC_VIDEO_CODEC_OK;
532 } 559 }
533 560
534 - (void)configureCompressionSession { 561 - (void)configureCompressionSession {
535 RTC_DCHECK(_compressionSession); 562 RTC_DCHECK(_compressionSession);
536 SetVTSessionProperty(_compressionSession, kVTCompressionPropertyKey_RealTime, true); 563 SetVTSessionProperty(_compressionSession, kVTCompressionPropertyKey_RealTime, true);
537 SetVTSessionProperty(_compressionSession, kVTCompressionPropertyKey_ProfileLev el, _profile); 564 SetVTSessionProperty(_compressionSession, kVTCompressionPropertyKey_ProfileLev el, _profile);
538 SetVTSessionProperty(_compressionSession, kVTCompressionPropertyKey_AllowFrame Reordering, false); 565 SetVTSessionProperty(_compressionSession, kVTCompressionPropertyKey_AllowFrame Reordering, false);
539 [self setEncoderBitrateBps:_targetBitrateBps]; 566 [self setEncoderBitrateBps:_targetBitrateBps];
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 } 698 }
672 _bitrateAdjuster->Update(frame.buffer.length); 699 _bitrateAdjuster->Update(frame.buffer.length);
673 } 700 }
674 701
675 - (RTCVideoEncoderQpThresholds *)scalingSettings { 702 - (RTCVideoEncoderQpThresholds *)scalingSettings {
676 return [[RTCVideoEncoderQpThresholds alloc] initWithThresholdsLow:kLowH264QpTh reshold 703 return [[RTCVideoEncoderQpThresholds alloc] initWithThresholdsLow:kLowH264QpTh reshold
677 high:kHighH264QpT hreshold]; 704 high:kHighH264QpT hreshold];
678 } 705 }
679 706
680 @end 707 @end
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698