Source/ThirdParty/libwebrtc/ChangeLog

 12019-06-05 Youenn Fablet <youenn@apple.com>
 2
 3 Call was negotiated with H264 Base Profile 42e01f but encoded in High Profile
 4 https://bugs.webkit.org/show_bug.cgi?id=195124
 5 <rdar://problem/48453085>
 6
 7 Reviewed by NOBODY (OOPS!).
 8
 9 Use VTB directly instead of VCP when baseline is requested.
 10 For platforms supporting the VCP-in-VTB API, use VCP for high profile, VTB for baseline.
 11 For platforms not supporting the VCP-in-VTB API, use regular VTB for both baseline and high profile.
 12 On MacOS, if VTB session creation fails, use VCP as a fallback.
 13 Keep VTB-only code path for non internal builds.
 14
 15 * Source/webrtc/sdk/WebKit/EncoderUtilities.h: Removed.
 16 * Source/webrtc/sdk/WebKit/VideoProcessingSoftLink.h:
 17 * Source/webrtc/sdk/objc/components/video_codec/RTCVideoEncoderH264.mm:
 18 (-[RTCSingleVideoEncoderH264 initWithCodecInfo:simulcastIndex:]):
 19 (-[RTCSingleVideoEncoderH264 hasCompressionSession]):
 20 (-[RTCSingleVideoEncoderH264 encode:codecSpecificInfo:frameTypes:]):
 21 (-[RTCSingleVideoEncoderH264 resetCompressionSessionIfNeededWithFrame:]):
 22 (-[RTCSingleVideoEncoderH264 resetCompressionSessionWithPixelFormat:]):
 23 (-[RTCSingleVideoEncoderH264 configureCompressionSession]):
 24 (-[RTCSingleVideoEncoderH264 destroyCompressionSession]):
 25 (-[RTCSingleVideoEncoderH264 setEncoderBitrateBps:]):
 26 * Source/webrtc/sdk/objc/components/video_codec/helpers.cc:
 27 * Source/webrtc/sdk/objc/components/video_codec/helpers.h:
 28
1292019-05-28 Youenn Fablet <youenn@apple.com>
230
331 createAnswer() SDP Rejected by setLocalDescription()

Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/EncoderUtilities.h

1 /*
2  * Copyright (C) 2018 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #pragma once
27 
28 #include "VideoProcessingSoftLink.h"
29 
30 #if ENABLE_VCP_ENCODER
31 
32 #define CompressionSessionRef VCPCompressionSessionRef
33 #define CompressionSessionSetProperty webrtc::VCPCompressionSessionSetProperty
34 #define CompressionSessionGetPixelBufferPool webrtc::VCPCompressionSessionGetPixelBufferPool
35 #define CompressionSessionEncodeFrame webrtc::VCPCompressionSessionEncodeFrame
36 #define CompressionSessionCreate webrtc::VCPCompressionSessionCreate
37 #define kCodecTypeH264 kVCPCodecType4CC_H264
38 #define CompressionSessionInvalidate webrtc::VCPCompressionSessionInvalidate
39 
40 #else
41 
42 #define CompressionSessionRef VTCompressionSessionRef
43 #define CompressionSessionSetProperty VTSessionSetProperty
44 #define CompressionSessionGetPixelBufferPool VTCompressionSessionGetPixelBufferPool
45 #define CompressionSessionEncodeFrame VTCompressionSessionEncodeFrame
46 #define CompressionSessionCreate VTCompressionSessionCreate
47 #define kCodecTypeH264 kCMVideoCodecType_H264
48 #define CompressionSessionInvalidate VTCompressionSessionInvalidate
49 
50 #endif

Source/ThirdParty/libwebrtc/Source/webrtc/sdk/WebKit/VideoProcessingSoftLink.h

3737#define ENABLE_VCP_ENCODER 0
3838#define ENABLE_VCP_VTB_ENCODER 0
3939#elif (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE)
40 #define ENABLE_VCP_ENCODER __MAC_OS_X_VERSION_MAX_ALLOWED < 101500
 40#define ENABLE_VCP_ENCODER 1
4141#define ENABLE_VCP_VTB_ENCODER __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500
4242#elif (defined(TARGET_OS_MAC) && TARGET_OS_MAC)
43 #define ENABLE_VCP_ENCODER (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101300 && __MAC_OS_X_VERSION_MAX_ALLOWED < 101500)
44 #define ENABLE_VCP_VTB_ENCODER __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500
 43//#define ENABLE_VCP_ENCODER __MAC_OS_X_VERSION_MIN_REQUIRED >= 101300
 44//#define ENABLE_VCP_VTB_ENCODER __MAC_OS_X_VERSION_MIN_REQUIRED >= 101500
4545#endif
4646
4747#endif

@@SOFT_LINK_FUNCTION_FOR_HEADER(webrtc, VideoProcessing, VCPCompressionSessionCrea
145145SOFT_LINK_FUNCTION_FOR_HEADER(webrtc, VideoProcessing, VCPCompressionSessionInvalidate, void, (VCPCompressionSessionRef session), (session))
146146#define VCPCompressionSessionInvalidate softLink_VideoProcessing_VCPCompressionSessionInvalidate
147147
 148#else
 149using VCPCompressionSessionRef = void*;
148150#endif // ENABLE_VCP_ENCODER
149151
150152#endif // __APPLE__

Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/RTCVideoEncoderH264.mm

3131#include "system_wrappers/include/clock.h"
3232#include "third_party/libyuv/include/libyuv/convert_from.h"
3333
34 #include "sdk/WebKit/EncoderUtilities.h"
3534#include "sdk/WebKit/WebKitUtilities.h"
3635
3736#import <dlfcn.h>

4039VT_EXPORT const CFStringRef kVTVideoEncoderSpecification_Usage;
4140VT_EXPORT const CFStringRef kVTCompressionPropertyKey_Usage;
4241
43 #if !ENABLE_VCP_ENCODER && !defined(WEBRTC_IOS) && !ENABLE_VCP_VTB_ENCODER
 42#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS) && !ENABLE_VCP_ENCODER
4443static inline bool isStandardFrameSize(int32_t width, int32_t height)
4544{
4645 // FIXME: Envision relaxing this rule, something like width and height dividable by 4 or 8 should be good enough.

@@@implementation RTCSingleVideoEncoderH264 {
318317 RTCVideoEncoderCallback _callback;
319318 int32_t _width;
320319 int32_t _height;
321  CompressionSessionRef _compressionSession;
 320 bool _useVCP;
 321 VTCompressionSessionRef _compressionSession;
 322 VCPCompressionSessionRef _vcpCompressionSession;
322323 CVPixelBufferPoolRef _pixelBufferPool;
323324 RTCVideoCodecMode _mode;
324325

@@- (instancetype)initWithCodecInfo:(RTCVideoCodecInfo *)codecInfo simulcastIndex:
343344 _bitrateAdjuster.reset(new webrtc::BitrateAdjuster(.5, .95));
344345 _packetizationMode = RTCH264PacketizationModeNonInterleaved;
345346 _profile = ExtractProfile([codecInfo nativeSdpVideoFormat]);
 347#if ENABLE_VCP_VTB_ENCODER
 348 _useVCP = [(__bridge NSString *)_profile containsString: @"High"];
 349#else
 350 _useVCP = false;
 351#endif
346352 _simulcastIndex = index;
347353 RTC_LOG(LS_INFO) << "Using profile " << CFStringToString(_profile);
348354 RTC_CHECK([codecInfo.name isEqualToString:kRTCVideoCodecH264Name]);

@@- (NSInteger)startEncodeWithSettings:(RTCVideoEncoderSettings *)settings
376382 return [self resetCompressionSessionWithPixelFormat:kNV12PixelFormat];
377383}
378384
 385- (bool)hasCompressionSession
 386{
 387 return _compressionSession || _vcpCompressionSession;
 388}
 389
379390- (NSInteger)encode:(RTCVideoFrame *)frame
380391 codecSpecificInfo:(nullable id<RTCCodecSpecificInfo>)codecSpecificInfo
381392 frameTypes:(NSArray<NSNumber *> *)frameTypes {
382393 RTC_DCHECK_EQ(frame.width, _width);
383394 RTC_DCHECK_EQ(frame.height, _height);
384  if (!_callback || !_compressionSession) {
 395 if (!_callback || ![self hasCompressionSession]) {
385396 return WEBRTC_VIDEO_CODEC_UNINITIALIZED;
386397 }
387398 BOOL isKeyframeRequired = NO;

@@- (NSInteger)encode:(RTCVideoFrame *)frame
474485 // Update the bitrate if needed.
475486 [self setBitrateBps:_bitrateAdjuster->GetAdjustedBitrateBps()];
476487
477  OSStatus status = CompressionSessionEncodeFrame(_compressionSession,
 488 OSStatus status;
 489 if (_compressionSession) {
 490 status = VTCompressionSessionEncodeFrame(_compressionSession,
 491 pixelBuffer,
 492 presentationTimeStamp,
 493 kCMTimeInvalid,
 494 frameProperties,
 495 encodeParams.release(),
 496 nullptr);
 497 } else {
 498#if ENABLE_VCP_ENCODER
 499 status = webrtc::VCPCompressionSessionEncodeFrame(_vcpCompressionSession,
478500 pixelBuffer,
479501 presentationTimeStamp,
480502 kCMTimeInvalid,
481503 frameProperties,
482504 encodeParams.release(),
483505 nullptr);
 506#else
 507 status = 1;
 508#endif
 509 }
484510 if (frameProperties) {
485511 CFRelease(frameProperties);
486512 }

@@- (BOOL)resetCompressionSessionIfNeededWithFrame:(RTCVideoFrame *)frame {
540566 // configured with, make sure the compression session is reset using the correct pixel format.
541567 OSType framePixelFormat = [self pixelFormatOfFrame:frame];
542568
543  if (_compressionSession) {
 569 if ([self hasCompressionSession]) {
544570#if defined(WEBRTC_WEBKIT_BUILD)
545571 if (!_pixelBufferPool) {
546572 return NO;

@@- (int)resetCompressionSessionWithPixelFormat:(OSType)framePixelFormat {
618644#endif
619645 CFDictionarySetValue(encoderSpecs, kVTCompressionPropertyKey_RealTime, kCFBooleanTrue);
620646
621 #if ENABLE_VCP_ENCODER || ENABLE_VCP_VTB_ENCODER
622  int usageValue = 1;
623  auto usage = CFNumberCreate(nullptr, kCFNumberIntType, &usageValue);
624  CFDictionarySetValue(encoderSpecs, kVTCompressionPropertyKey_Usage, usage);
625  CFRelease(usage);
 647#if ENABLE_VCP_ENCODER
 648 if (_useVCP) {
 649 int usageValue = 1;
 650 auto usage = CFNumberCreate(nullptr, kCFNumberIntType, &usageValue);
 651 CFDictionarySetValue(encoderSpecs, kVTCompressionPropertyKey_Usage, usage);
 652 CFRelease(usage);
 653 }
626654#endif
627655#if ENABLE_VCP_VTB_ENCODER
 656 if (_useVCP) {
628657 CFDictionarySetValue(encoderSpecs, kVTVideoEncoderList_EncoderID, CFSTR("com.apple.videotoolbox.videoencoder.h264.rtvc"));
 658 }
629659#endif
630660 OSStatus status =
631  CompressionSessionCreate(nullptr, // use default allocator
 661 VTCompressionSessionCreate(nullptr, // use default allocator
632662 _width,
633663 _height,
634  kCodecTypeH264,
 664 kCMVideoCodecType_H264,
635665 encoderSpecs, // use hardware accelerated encoder if available
636666 sourceAttributes,
637667 nullptr, // use default compressed data allocator
638668 compressionOutputCallback,
639669 nullptr,
640670 &_compressionSession);
641  if (sourceAttributes) {
642  CFRelease(sourceAttributes);
643  sourceAttributes = nullptr;
644  }
645  if (encoderSpecs) {
646  CFRelease(encoderSpecs);
647  encoderSpecs = nullptr;
648  }
649671
650 #if ENABLE_VCP_ENCODER || defined(WEBRTC_IOS)
651  if (status != noErr) {
652  RTC_LOG(LS_ERROR) << "Failed to create compression session: " << status;
653  return WEBRTC_VIDEO_CODEC_ERROR;
654  }
655 #endif
656672#if defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
657  CFBooleanRef hwaccl_enabled = nullptr;
658  if (status == noErr) {
659  status = VTSessionCopyProperty(_compressionSession,
 673#if ENABLE_VCP_ENCODER
 674 if (!_useVCP) {
 675 CFBooleanRef hwaccl_enabled = nullptr;
 676 if (status == noErr) {
 677 status = VTSessionCopyProperty(_compressionSession,
660678 kVTCompressionPropertyKey_UsingHardwareAcceleratedVideoEncoder,
661679 nullptr,
662680 &hwaccl_enabled);
 681 }
 682 if (status == noErr && (CFBooleanGetValue(hwaccl_enabled))) {
 683 RTC_LOG(LS_INFO) << "Compression session created with hw accl enabled";
 684 } else {
 685 [self destroyCompressionSession];
 686
 687 // Use VCP instead.
 688 int usageValue = 1;
 689 auto usage = CFNumberCreate(nullptr, kCFNumberIntType, &usageValue);
 690 CFDictionarySetValue(encoderSpecs, kVTCompressionPropertyKey_Usage, usage);
 691 CFRelease(usage);
 692
 693 RTC_LOG(LS_INFO) << "Compression session created with VCP";
 694 status =
 695 webrtc::VCPCompressionSessionCreate(nullptr, // use default allocator
 696 _width,
 697 _height,
 698 kVCPCodecType4CC_H264,
 699 encoderSpecs,
 700 sourceAttributes,
 701 nullptr, // use default compressed data allocator
 702 compressionOutputCallback,
 703 nullptr,
 704 &_vcpCompressionSession);
 705 }
663706 }
664  if (status == noErr && (CFBooleanGetValue(hwaccl_enabled))) {
665  RTC_LOG(LS_INFO) << "Compression session created with hw accl enabled";
666  } else {
667  RTC_LOG(LS_INFO) << "Compression session created with hw accl disabled";
 707#else
 708 if (status != noErr) {
 709 if (encoderSpecs) {
 710 CFRelease(encoderSpecs);
 711 encoderSpecs = nullptr;
 712 }
 713 if (sourceAttributes) {
 714 CFRelease(sourceAttributes);
 715 sourceAttributes = nullptr;
 716 }
668717
669 #if !ENABLE_VCP_ENCODER && !ENABLE_VCP_VTB_ENCODER && !defined(WEBRTC_IOS)
670718 if (!isStandardFrameSize(_width, _height)) {
671719 _disableEncoding = true;
672720 RTC_LOG(LS_ERROR) << "Using H264 software encoder with non standard size is not supported";
673721 return WEBRTC_VIDEO_CODEC_ERROR;
674722 }
 723 [self destroyCompressionSession];
675724
676725 CFDictionaryRef ioSurfaceValue = CreateCFTypeDictionary(nullptr, nullptr, 0);
677726 int64_t pixelFormatType = framePixelFormat;

@@- (int)resetCompressionSessionWithPixelFormat:(OSType)framePixelFormat {
687736 kCFBooleanTrue,
688737 ioSurfaceValue,
689738 pixelFormat};
690  CFDictionaryRef sourceAttributes = CreateCFTypeDictionary(keys, values, attributesSize);
 739 sourceAttributes = CreateCFTypeDictionary(keys, values, attributesSize);
691740
692741 if (ioSurfaceValue) {
693742 CFRelease(ioSurfaceValue);

@@- (int)resetCompressionSessionWithPixelFormat:(OSType)framePixelFormat {
698747 pixelFormat = nullptr;
699748 }
700749
701  CFMutableDictionaryRef encoderSpecs = CFDictionaryCreateMutable(nullptr, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
 750 encoderSpecs = CFDictionaryCreateMutable(nullptr, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
702751 CFDictionarySetValue(encoderSpecs, kVTVideoEncoderSpecification_EnableHardwareAcceleratedVideoEncoder, kCFBooleanFalse);
703752 int usageValue = 1;
704753 CFNumberRef usage = CFNumberCreate(nullptr, kCFNumberIntType, &usageValue);
705754 CFDictionarySetValue(encoderSpecs, kVTVideoEncoderSpecification_Usage, usage);
706 
707755 if (usage) {
708756 CFRelease(usage);
709757 usage = nullptr;
710758 }
711 
712  [self destroyCompressionSession];
713 
714  OSStatus status =
715  CompressionSessionCreate(nullptr, // use default allocator
 759 status = VTCompressionSessionCreate(nullptr, // use default allocator
716760 _width,
717761 _height,
718  kCodecTypeH264,
719  encoderSpecs,
 762 kCMVideoCodecType_H264,
 763 encoderSpecs, // use hardware accelerated encoder if available
720764 sourceAttributes,
721765 nullptr, // use default compressed data allocator
722766 compressionOutputCallback,
723767 nullptr,
724768 &_compressionSession);
725  if (sourceAttributes) {
726  CFRelease(sourceAttributes);
727  sourceAttributes = nullptr;
728  }
729  if (encoderSpecs) {
730  CFRelease(encoderSpecs);
731  encoderSpecs = nullptr;
732  }
733  if (status != noErr) {
734  return WEBRTC_VIDEO_CODEC_ERROR;
735  }
736 #endif
 769
737770 }
738 #endif
 771#endif // ENABLE_VCP_ENCODER
 772#endif // defined(WEBRTC_MAC) && !defined(WEBRTC_IOS)
 773 if (sourceAttributes) {
 774 CFRelease(sourceAttributes);
 775 sourceAttributes = nullptr;
 776 }
 777 if (encoderSpecs) {
 778 CFRelease(encoderSpecs);
 779 encoderSpecs = nullptr;
 780 }
 781
 782 if (status != noErr) {
 783 RTC_LOG(LS_ERROR) << "Failed to create compression session: " << status;
 784 return WEBRTC_VIDEO_CODEC_ERROR;
 785 }
 786
739787 [self configureCompressionSession];
740788
741789#if !defined(WEBRTC_WEBKIT_BUILD)
742790 // The pixel buffer pool is dependent on the compression session so if the session is reset, the
743791 // pool should be reset as well.
744  _pixelBufferPool = CompressionSessionGetPixelBufferPool(_compressionSession);
 792 if (_compressionSession)
 793 _pixelBufferPool = VTCompressionSessionGetPixelBufferPool(_compressionSession);
 794#if ENABLE_VCP_ENCODER
 795 else
 796 _pixelBufferPool = webrtc::VCPCompressionSessionGetPixelBufferPool(_compressionSession);
 797#endif
745798#endif
746799 return WEBRTC_VIDEO_CODEC_OK;
747800}
748801
749802- (void)configureCompressionSession {
750  RTC_DCHECK(_compressionSession);
751  SetVTSessionProperty(_compressionSession, kVTCompressionPropertyKey_RealTime, true);
752  SetVTSessionProperty(_compressionSession, kVTCompressionPropertyKey_ProfileLevel, _profile);
753  SetVTSessionProperty(_compressionSession, kVTCompressionPropertyKey_AllowFrameReordering, false);
 803 RTC_DCHECK([self hasCompressionSession]);
 804 SetVTSessionProperty(_compressionSession, _vcpCompressionSession, kVTCompressionPropertyKey_RealTime, true);
 805 SetVTSessionProperty(_compressionSession, _vcpCompressionSession, kVTCompressionPropertyKey_ProfileLevel, _profile);
 806 SetVTSessionProperty(_compressionSession, _vcpCompressionSession, kVTCompressionPropertyKey_AllowFrameReordering, false);
754807#if ENABLE_VCP_ENCODER
755  SetVTSessionProperty(_compressionSession, kVTCompressionPropertyKey_Usage, 1);
 808 if (_useVCP) {
 809 SetVTSessionProperty(_compressionSession, _vcpCompressionSession, kVTCompressionPropertyKey_Usage, 1);
 810 }
756811#endif
757812 [self setEncoderBitrateBps:_targetBitrateBps];
758813 // TODO(tkchin): Look at entropy mode and colorspace matrices.

@@- (void)configureCompressionSession {
764819 // 1);
765820
766821 // Set a relatively large value for keyframe emission (7200 frames or 4 minutes).
767  SetVTSessionProperty(_compressionSession, kVTCompressionPropertyKey_MaxKeyFrameInterval, 7200);
 822 SetVTSessionProperty(_compressionSession, _vcpCompressionSession, kVTCompressionPropertyKey_MaxKeyFrameInterval, 7200);
768823 SetVTSessionProperty(
769  _compressionSession, kVTCompressionPropertyKey_MaxKeyFrameIntervalDuration, 240);
 824 _compressionSession, _vcpCompressionSession, kVTCompressionPropertyKey_MaxKeyFrameIntervalDuration, 240);
770825}
771826
772827- (void)destroyCompressionSession {
773828 if (_compressionSession) {
774  CompressionSessionInvalidate(_compressionSession);
 829 VTCompressionSessionInvalidate(_compressionSession);
775830 CFRelease(_compressionSession);
776831 _compressionSession = nullptr;
777  _pixelBufferPool = nullptr;
778832 }
 833#if ENABLE_VCP_ENCODER
 834 if (_vcpCompressionSession) {
 835 webrtc::VCPCompressionSessionInvalidate(_vcpCompressionSession);
 836 CFRelease(_vcpCompressionSession);
 837 _vcpCompressionSession = nullptr;
 838 }
 839#endif
 840 _pixelBufferPool = nullptr;
779841}
780842
781843- (NSString *)implementationName {

@@- (void)setBitrateBps:(uint32_t)bitrateBps {
789851}
790852
791853- (void)setEncoderBitrateBps:(uint32_t)bitrateBps {
792  if (_compressionSession) {
793  SetVTSessionProperty(_compressionSession, kVTCompressionPropertyKey_AverageBitRate, bitrateBps);
 854 if ([self hasCompressionSession]) {
 855 SetVTSessionProperty(_compressionSession, _vcpCompressionSession, kVTCompressionPropertyKey_AverageBitRate, bitrateBps);
794856
795857 // TODO(tkchin): Add a helper method to set array value.
796858 int64_t dataLimitBytesPerSecondValue =

@@- (void)setEncoderBitrateBps:(uint32_t)bitrateBps {
802864 CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &oneSecondValue);
803865 const void *nums[2] = {bytesPerSecond, oneSecond};
804866 CFArrayRef dataRateLimits = CFArrayCreate(nullptr, nums, 2, &kCFTypeArrayCallBacks);
805  OSStatus status = CompressionSessionSetProperty(
806  _compressionSession, kVTCompressionPropertyKey_DataRateLimits, dataRateLimits);
 867
 868 OSStatus status = noErr;
 869 if (_compressionSession)
 870 VTSessionSetProperty(_compressionSession, kVTCompressionPropertyKey_DataRateLimits, dataRateLimits);
 871#if ENABLE_VCP_ENCODER
 872 else
 873 webrtc::VCPCompressionSessionSetProperty(_vcpCompressionSession, kVTCompressionPropertyKey_DataRateLimits, dataRateLimits);
 874#endif
 875 if (status != noErr) {
 876 RTC_LOG(LS_ERROR) << "VTSessionSetProperty failed to set: " << kVTCompressionPropertyKey_DataRateLimits
 877 << ": " << status;
 878 }
 879
807880 if (bytesPerSecond) {
808881 CFRelease(bytesPerSecond);
809882 }

@@- (void)setEncoderBitrateBps:(uint32_t)bitrateBps {
813886 if (dataRateLimits) {
814887 CFRelease(dataRateLimits);
815888 }
816  if (status != noErr) {
817  RTC_LOG(LS_ERROR) << "Failed to set data rate limit";
818  }
819 
820889 _encoderBitrateBps = bitrateBps;
821890 }
822891}

Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/helpers.cc

@@std::string CFStringToString(const CFStringRef cf_string) {
3535}
3636
3737// Convenience function for setting a VT property.
38 void SetVTSessionProperty(CompressionSessionRef session,
 38void SetVTSessionProperty(VTCompressionSessionRef session, VCPCompressionSessionRef vcpSession,
3939 CFStringRef key,
4040 int32_t value) {
4141 CFNumberRef cfNum =
4242 CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &value);
43  OSStatus status = CompressionSessionSetProperty(session, key, cfNum);
 43 OSStatus status = noErr;
 44 if (session)
 45 status = VTSessionSetProperty(session, key, cfNum);
 46#if ENABLE_VCP_ENCODER
 47 else
 48 status = webrtc::VCPCompressionSessionSetProperty(vcpSession, key, cfNum);
 49#endif
4450 CFRelease(cfNum);
4551 if (status != noErr) {
4652 std::string key_string = CFStringToString(key);

@@void SetVTSessionProperty(CompressionSessionRef session,
5056}
5157
5258// Convenience function for setting a VT property.
53 void SetVTSessionProperty(CompressionSessionRef session,
 59void SetVTSessionProperty(VTCompressionSessionRef session, VCPCompressionSessionRef vcpSession,
5460 CFStringRef key,
5561 uint32_t value) {
5662 int64_t value_64 = value;
5763 CFNumberRef cfNum =
5864 CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &value_64);
59  OSStatus status = CompressionSessionSetProperty(session, key, cfNum);
 65 OSStatus status = noErr;
 66 if (session)
 67 status = VTSessionSetProperty(session, key, cfNum);
 68#if ENABLE_VCP_ENCODER
 69 else
 70 status = webrtc::VCPCompressionSessionSetProperty(vcpSession, key, cfNum);
 71#endif
6072 CFRelease(cfNum);
6173 if (status != noErr) {
6274 std::string key_string = CFStringToString(key);

@@void SetVTSessionProperty(CompressionSessionRef session,
6678}
6779
6880// Convenience function for setting a VT property.
69 void SetVTSessionProperty(CompressionSessionRef session, CFStringRef key, bool value) {
 81void SetVTSessionProperty(VTCompressionSessionRef session, VCPCompressionSessionRef vcpSession, CFStringRef key, bool value) {
7082 CFBooleanRef cf_bool = (value) ? kCFBooleanTrue : kCFBooleanFalse;
71  OSStatus status = CompressionSessionSetProperty(session, key, cf_bool);
 83 OSStatus status = noErr;
 84 if (session)
 85 status = VTSessionSetProperty(session, key, cf_bool);
 86#if ENABLE_VCP_ENCODER
 87 else
 88 status = webrtc::VCPCompressionSessionSetProperty(vcpSession, key, cf_bool);
 89#endif
7290 if (status != noErr) {
7391 std::string key_string = CFStringToString(key);
7492 RTC_LOG(LS_ERROR) << "VTSessionSetProperty failed to set: " << key_string

@@void SetVTSessionProperty(CompressionSessionRef session, CFStringRef key, bool v
7795}
7896
7997// Convenience function for setting a VT property.
80 void SetVTSessionProperty(CompressionSessionRef session,
 98void SetVTSessionProperty(VTCompressionSessionRef session, VCPCompressionSessionRef vcpSession,
8199 CFStringRef key,
82100 CFStringRef value) {
83  OSStatus status = CompressionSessionSetProperty(session, key, value);
 101 OSStatus status = noErr;
 102 if (session)
 103 status = VTSessionSetProperty(session, key, value);
 104#if ENABLE_VCP_ENCODER
 105 else
 106 status = webrtc::VCPCompressionSessionSetProperty(vcpSession, key, value);
 107#endif
84108 if (status != noErr) {
85109 std::string key_string = CFStringToString(key);
86110 std::string val_string = CFStringToString(value);

Source/ThirdParty/libwebrtc/Source/webrtc/sdk/objc/components/video_codec/helpers.h

1616#include <VideoToolbox/VideoToolbox.h>
1717#include <string>
1818
19 #include "sdk/WebKit/EncoderUtilities.h"
 19#include "sdk/WebKit/VideoProcessingSoftLink.h"
2020
2121// Convenience function for creating a dictionary.
2222inline CFDictionaryRef CreateCFTypeDictionary(CFTypeRef* keys,

@@inline CFDictionaryRef CreateCFTypeDictionary(CFTypeRef* keys,
3131std::string CFStringToString(const CFStringRef cf_string);
3232
3333// Convenience function for setting a VT property.
34 void SetVTSessionProperty(CompressionSessionRef session, CFStringRef key, int32_t value);
 34void SetVTSessionProperty(VTCompressionSessionRef session, VCPCompressionSessionRef vcpSession,CFStringRef key, int32_t value);
3535
3636// Convenience function for setting a VT property.
37 void SetVTSessionProperty(CompressionSessionRef session,
 37void SetVTSessionProperty(VTCompressionSessionRef session, VCPCompressionSessionRef vcpSession,
3838 CFStringRef key,
3939 uint32_t value);
4040
4141// Convenience function for setting a VT property.
42 void SetVTSessionProperty(CompressionSessionRef session, CFStringRef key, bool value);
 42void SetVTSessionProperty(VTCompressionSessionRef session, VCPCompressionSessionRef vcpSession, CFStringRef key, bool value);
4343
4444// Convenience function for setting a VT property.
45 void SetVTSessionProperty(CompressionSessionRef session,
 45void SetVTSessionProperty(VTCompressionSessionRef session, VCPCompressionSessionRef vcpSession,
4646 CFStringRef key,
4747 CFStringRef value);
4848

LayoutTests/ChangeLog

 12019-06-05 Youenn Fablet <youenn@apple.com>
 2
 3 Call was negotiated with H264 Base Profile 42e01f but encoded in High Profile
 4 https://bugs.webkit.org/show_bug.cgi?id=195124
 5 <rdar://problem/48453085>
 6
 7 Reviewed by NOBODY (OOPS!).
 8
 9 * webrtc/video-h264-expected.txt: Added.
 10 * webrtc/video-h264.html: Added.
 11
1122019-06-04 Youenn Fablet <youenn@apple.com>
213
314 Layout test landed flaky in 245873 [ Release ] http/wpt/service-workers/service-worker-networkprocess-crash.html is a flaky failure

LayoutTests/webrtc/video-h264-expected.txt

 1
 2
 3PASS Baseline H264
 4PASS High H264
 5

LayoutTests/webrtc/video-h264.html

 1<!doctype html>
 2<html>
 3 <head>
 4 <meta charset="utf-8">
 5 <title>Testing H264 baseline and high profile</title>
 6 <script src="../resources/testharness.js"></script>
 7 <script src="../resources/testharnessreport.js"></script>
 8 </head>
 9 <body>
 10 <video id="video" autoplay=""></video>
 11 <canvas id="canvas" width="640" height="480"></canvas>
 12 <script src ="routines.js"></script>
 13 <script>
 14function grabFrameData(x, y, w, h)
 15{
 16 canvas.width = video.videoWidth;
 17 canvas.height = video.videoHeight;
 18
 19 canvas.getContext('2d').drawImage(video, x, y, w, h, x, y, w, h);
 20 return canvas.getContext('2d').getImageData(x, y, w, h).data;
 21}
 22
 23function testImage()
 24{
 25 const data = grabFrameData(10, 325, 250, 1);
 26
 27 var index = 20;
 28 assert_true(data[index] < 100);
 29 assert_true(data[index + 1] < 100);
 30 assert_true(data[index + 2] < 100);
 31
 32 index = 80;
 33 assert_true(data[index] > 200);
 34 assert_true(data[index + 1] > 200);
 35 assert_true(data[index + 2] > 200);
 36
 37 index += 80;
 38 assert_true(data[index] > 200);
 39 assert_true(data[index + 1] > 200);
 40 assert_true(data[index + 2] < 100);
 41}
 42
 43promise_test(async (test) => {
 44 if (window.testRunner)
 45 testRunner.setUserMediaPermission(true);
 46
 47 const localStream = await navigator.mediaDevices.getUserMedia({video: true});
 48 const stream = await new Promise((resolve, reject) => {
 49 createConnections((firstConnection) => {
 50 firstConnection.addTrack(localStream.getVideoTracks()[0], localStream);
 51 }, (secondConnection) => {
 52 secondConnection.ontrack = (trackEvent) => {
 53 resolve(trackEvent.streams[0]);
 54 };
 55 }, { observeOffer : (offer) => {
 56 offer.sdp = offer.sdp.replace("640c1f", "42e01f");
 57 return offer;
 58 }
 59 });
 60 setTimeout(() => reject("Test timed out"), 5000);
 61 });
 62
 63 video.srcObject = stream;
 64 await video.play();
 65
 66 testImage();
 67}, "Baseline H264");
 68
 69promise_test(async (test) => {
 70 if (window.testRunner)
 71 testRunner.setUserMediaPermission(true);
 72
 73 const localStream = await navigator.mediaDevices.getUserMedia({video: true});
 74 const stream = await new Promise((resolve, reject) => {
 75 createConnections((firstConnection) => {
 76 firstConnection.addTrack(localStream.getVideoTracks()[0], localStream);
 77 }, (secondConnection) => {
 78 secondConnection.ontrack = (trackEvent) => {
 79 resolve(trackEvent.streams[0]);
 80 };
 81 }, { observeOffer : (offer) => {
 82 offer.sdp = offer.sdp.replace("42e01f", "640c1f");
 83 return offer;
 84 }
 85 });
 86 setTimeout(() => reject("Test timed out"), 5000);
 87 });
 88
 89 video.srcObject = stream;
 90 await video.play();
 91
 92 testImage();
 93}, "High H264");
 94 </script>
 95 </body>
 96</html>