开启WebRTC的一些“试用特性” (FieldTrials)

在使用Android/iOS端的WebRTC SDK时,我们一定会创建和初始化PeerConnectionFactory。

在Android上,PeerConnectionFactory提供了initialize方法,参数是InitializationOptions :

public static void initialize(PeerConnectionFactory.InitializationOptions options)

它有一个成员变量:

String fieldTrials;

可以通过以下方法来设置:

public PeerConnectionFactory.InitializationOptions.Builder setFieldTrials(String fieldTrials)

例如:

String VIDEO_FLEXFEC_FIELDTRIAL = "WebRTC-FlexFEC-03-Advertised/Enabled/WebRTC-FlexFEC-03/Enabled/";
String VIDEO_VP8_INTEL_HW_ENCODER_FIELDTRIAL = "WebRTC-IntelVP8/Enabled/";
String DISABLE_WEBRTC_AGC_FIELDTRIAL = "WebRTC-Audio-MinimizeResamplingOnMobile/Enabled/";

String strFieldTrails = "";
strFieldTrails += VIDEO_FLEXFEC_FIELDTRIAL;
strFieldTrails += VIDEO_VP8_INTEL_HW_ENCODER_FIELDTRIAL;
strFieldTrails += DISABLE_WEBRTC_AGC_FIELDTRIAL;

PeerConnectionFactory.initialize(
    PeerConnectionFactory.InitializationOptions.builder(context)
        .setFieldTrials(strFieldTrails)
        .createInitializationOptions());

通过这个方法,我们可以让Android端的WebRTC启用某些试用特性。Android端的试用特性主要包括以下一些(不一定全):

WebRTC-H264Simulcast
WebRTC-FlexFEC-03
WebRTC-FlexFEC-03-Advertised
WebRTC-IncreasedReceivebuffers
WebRTC-SupportVP9SVC
WebRTC-VP8-Forced-Fallback-Encoder-v2
WebRTC-Video-BalancedDegradation
WebRTC-SimulcastScreenshare

设置的格式一般为: 名称/Enabled(Disabled)/  。如果有设置值的,格式一般为:  名称/值/


在iOS上的设置方法和Android不同,可以在初始化RTCPeerConnectionFactory的时候,使用 RTCInitFieldTrialDictionary() 来进行设置:

RTCDefaultVideoDecoderFactory *decoderFactory = [[RTCDefaultVideoDecoderFactory alloc] init];
RTCDefaultVideoEncoderFactory *encoderFactory = [[RTCDefaultVideoEncoderFactory alloc] init];

_factory = [[RTCPeerConnectionFactory alloc] initWithEncoderFactory:encoderFactory decoderFactory:decoderFactory];

NSDictionary *fieldTrials = @{
                               kRTCFieldTrialFlexFec03AdvertisedKey       :kRTCFieldTrialEnabledValue,
                               kRTCFieldTrialFlexFec03Key                 :kRTCFieldTrialEnabledValue,
                               kRTCFieldTrialImprovedBitrateEstimateKey   :kRTCFieldTrialEnabledValue,
                               kRTCFieldTrialMinimizeResamplingOnMobileKey:kRTCFieldTrialEnabledValue
                               };
RTCInitFieldTrialDictionary(fieldTrials);

在WebRTC源码中这个文件中:\src\sdk\objc\api\peerconnection\RTCFieldTrials.mm,你可以找到定义的一些针对iOS的试用特性,摘抄如下:

NSString * const kRTCFieldTrialAudioSendSideBweKey = @"WebRTC-Audio-SendSideBwe";
NSString * const kRTCFieldTrialAudioSendSideBweForVideoKey = @"WebRTC-Audio-SendSideBwe-For-Video";
NSString * const kRTCFieldTrialAudioForceNoTWCCKey = @"WebRTC-Audio-ForceNoTWCC";
NSString * const kRTCFieldTrialAudioForceABWENoTWCCKey = @"WebRTC-Audio-ABWENoTWCC";
NSString * const kRTCFieldTrialSendSideBweWithOverheadKey = @"WebRTC-SendSideBwe-WithOverhead";
NSString * const kRTCFieldTrialFlexFec03AdvertisedKey = @"WebRTC-FlexFEC-03-Advertised";
NSString * const kRTCFieldTrialFlexFec03Key = @"WebRTC-FlexFEC-03";
NSString * const kRTCFieldTrialImprovedBitrateEstimateKey = @"WebRTC-ImprovedBitrateEstimate";
NSString * const kRTCFieldTrialMedianSlopeFilterKey = @"WebRTC-BweMedianSlopeFilter";
NSString * const kRTCFieldTrialTrendlineFilterKey = @"WebRTC-BweTrendlineFilter";
NSString * const kRTCFieldTrialH264HighProfileKey = @"WebRTC-H264HighProfile";
NSString * const kRTCFieldTrialMinimizeResamplingOnMobileKey =
    @"WebRTC-Audio-MinimizeResamplingOnMobile";
NSString * const kRTCFieldTrialEnabledValue = @"Enabled";

可以看到,iOS提供的与Android的并不全都相同,我不确定是因为平台原因还是开发团队差异?

针对上面的所有试用特性,撰写此文时,我还在逐一测试具体的效果,感兴趣的朋友不妨自己亲自试试看。

 

 

你可能感兴趣的:(webrtc)