You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
8.7 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2015 The WebRTC project authors. All Rights Reserved.
  3. *
  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
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #import <Foundation/Foundation.h>
  11. #include <vector>
  12. #include "rtc_base/gunit.h"
  13. #import "api/peerconnection/RTCConfiguration+Private.h"
  14. #import "api/peerconnection/RTCConfiguration.h"
  15. #import "api/peerconnection/RTCIceServer.h"
  16. #import "api/peerconnection/RTCIntervalRange.h"
  17. #import "helpers/NSString+StdString.h"
  18. @interface RTCConfigurationTest : NSObject
  19. - (void)testConversionToNativeConfiguration;
  20. - (void)testNativeConversionToConfiguration;
  21. @end
  22. @implementation RTCConfigurationTest
  23. - (void)testConversionToNativeConfiguration {
  24. NSArray *urlStrings = @[ @"stun:stun1.example.net" ];
  25. RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:urlStrings];
  26. RTCIntervalRange *range = [[RTCIntervalRange alloc] initWithMin:0 max:100];
  27. RTCConfiguration *config = [[RTCConfiguration alloc] init];
  28. config.iceServers = @[ server ];
  29. config.iceTransportPolicy = RTCIceTransportPolicyRelay;
  30. config.bundlePolicy = RTCBundlePolicyMaxBundle;
  31. config.rtcpMuxPolicy = RTCRtcpMuxPolicyNegotiate;
  32. config.tcpCandidatePolicy = RTCTcpCandidatePolicyDisabled;
  33. config.candidateNetworkPolicy = RTCCandidateNetworkPolicyLowCost;
  34. const int maxPackets = 60;
  35. const int timeout = 1;
  36. const int interval = 2;
  37. config.audioJitterBufferMaxPackets = maxPackets;
  38. config.audioJitterBufferFastAccelerate = YES;
  39. config.iceConnectionReceivingTimeout = timeout;
  40. config.iceBackupCandidatePairPingInterval = interval;
  41. config.continualGatheringPolicy =
  42. RTCContinualGatheringPolicyGatherContinually;
  43. config.shouldPruneTurnPorts = YES;
  44. config.iceRegatherIntervalRange = range;
  45. config.cryptoOptions = [[RTCCryptoOptions alloc] initWithSrtpEnableGcmCryptoSuites:YES
  46. srtpEnableAes128Sha1_32CryptoCipher:YES
  47. srtpEnableEncryptedRtpHeaderExtensions:YES
  48. sframeRequireFrameEncryption:YES];
  49. config.rtcpAudioReportIntervalMs = 2500;
  50. config.rtcpVideoReportIntervalMs = 3750;
  51. std::unique_ptr<webrtc::PeerConnectionInterface::RTCConfiguration>
  52. nativeConfig([config createNativeConfiguration]);
  53. EXPECT_TRUE(nativeConfig.get());
  54. EXPECT_EQ(1u, nativeConfig->servers.size());
  55. webrtc::PeerConnectionInterface::IceServer nativeServer =
  56. nativeConfig->servers.front();
  57. EXPECT_EQ(1u, nativeServer.urls.size());
  58. EXPECT_EQ("stun:stun1.example.net", nativeServer.urls.front());
  59. EXPECT_EQ(webrtc::PeerConnectionInterface::kRelay, nativeConfig->type);
  60. EXPECT_EQ(webrtc::PeerConnectionInterface::kBundlePolicyMaxBundle,
  61. nativeConfig->bundle_policy);
  62. EXPECT_EQ(webrtc::PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
  63. nativeConfig->rtcp_mux_policy);
  64. EXPECT_EQ(webrtc::PeerConnectionInterface::kTcpCandidatePolicyDisabled,
  65. nativeConfig->tcp_candidate_policy);
  66. EXPECT_EQ(webrtc::PeerConnectionInterface::kCandidateNetworkPolicyLowCost,
  67. nativeConfig->candidate_network_policy);
  68. EXPECT_EQ(maxPackets, nativeConfig->audio_jitter_buffer_max_packets);
  69. EXPECT_EQ(true, nativeConfig->audio_jitter_buffer_fast_accelerate);
  70. EXPECT_EQ(timeout, nativeConfig->ice_connection_receiving_timeout);
  71. EXPECT_EQ(interval, nativeConfig->ice_backup_candidate_pair_ping_interval);
  72. EXPECT_EQ(webrtc::PeerConnectionInterface::GATHER_CONTINUALLY,
  73. nativeConfig->continual_gathering_policy);
  74. EXPECT_EQ(true, nativeConfig->prune_turn_ports);
  75. EXPECT_EQ(range.min, nativeConfig->ice_regather_interval_range->min());
  76. EXPECT_EQ(range.max, nativeConfig->ice_regather_interval_range->max());
  77. EXPECT_EQ(true, nativeConfig->crypto_options->srtp.enable_gcm_crypto_suites);
  78. EXPECT_EQ(true, nativeConfig->crypto_options->srtp.enable_aes128_sha1_32_crypto_cipher);
  79. EXPECT_EQ(true, nativeConfig->crypto_options->srtp.enable_encrypted_rtp_header_extensions);
  80. EXPECT_EQ(true, nativeConfig->crypto_options->sframe.require_frame_encryption);
  81. EXPECT_EQ(2500, nativeConfig->audio_rtcp_report_interval_ms());
  82. EXPECT_EQ(3750, nativeConfig->video_rtcp_report_interval_ms());
  83. }
  84. - (void)testNativeConversionToConfiguration {
  85. NSArray *urlStrings = @[ @"stun:stun1.example.net" ];
  86. RTCIceServer *server = [[RTCIceServer alloc] initWithURLStrings:urlStrings];
  87. RTCIntervalRange *range = [[RTCIntervalRange alloc] initWithMin:0 max:100];
  88. RTCConfiguration *config = [[RTCConfiguration alloc] init];
  89. config.iceServers = @[ server ];
  90. config.iceTransportPolicy = RTCIceTransportPolicyRelay;
  91. config.bundlePolicy = RTCBundlePolicyMaxBundle;
  92. config.rtcpMuxPolicy = RTCRtcpMuxPolicyNegotiate;
  93. config.tcpCandidatePolicy = RTCTcpCandidatePolicyDisabled;
  94. config.candidateNetworkPolicy = RTCCandidateNetworkPolicyLowCost;
  95. const int maxPackets = 60;
  96. const int timeout = 1;
  97. const int interval = 2;
  98. config.audioJitterBufferMaxPackets = maxPackets;
  99. config.audioJitterBufferFastAccelerate = YES;
  100. config.iceConnectionReceivingTimeout = timeout;
  101. config.iceBackupCandidatePairPingInterval = interval;
  102. config.continualGatheringPolicy =
  103. RTCContinualGatheringPolicyGatherContinually;
  104. config.shouldPruneTurnPorts = YES;
  105. config.iceRegatherIntervalRange = range;
  106. config.cryptoOptions = [[RTCCryptoOptions alloc] initWithSrtpEnableGcmCryptoSuites:YES
  107. srtpEnableAes128Sha1_32CryptoCipher:NO
  108. srtpEnableEncryptedRtpHeaderExtensions:NO
  109. sframeRequireFrameEncryption:NO];
  110. config.rtcpAudioReportIntervalMs = 1500;
  111. config.rtcpVideoReportIntervalMs = 2150;
  112. webrtc::PeerConnectionInterface::RTCConfiguration *nativeConfig =
  113. [config createNativeConfiguration];
  114. RTCConfiguration *newConfig = [[RTCConfiguration alloc]
  115. initWithNativeConfiguration:*nativeConfig];
  116. EXPECT_EQ([config.iceServers count], newConfig.iceServers.count);
  117. RTCIceServer *newServer = newConfig.iceServers[0];
  118. RTCIceServer *origServer = config.iceServers[0];
  119. EXPECT_EQ(origServer.urlStrings.count, server.urlStrings.count);
  120. std::string origUrl = origServer.urlStrings.firstObject.UTF8String;
  121. std::string url = newServer.urlStrings.firstObject.UTF8String;
  122. EXPECT_EQ(origUrl, url);
  123. EXPECT_EQ(config.iceTransportPolicy, newConfig.iceTransportPolicy);
  124. EXPECT_EQ(config.bundlePolicy, newConfig.bundlePolicy);
  125. EXPECT_EQ(config.rtcpMuxPolicy, newConfig.rtcpMuxPolicy);
  126. EXPECT_EQ(config.tcpCandidatePolicy, newConfig.tcpCandidatePolicy);
  127. EXPECT_EQ(config.candidateNetworkPolicy, newConfig.candidateNetworkPolicy);
  128. EXPECT_EQ(config.audioJitterBufferMaxPackets, newConfig.audioJitterBufferMaxPackets);
  129. EXPECT_EQ(config.audioJitterBufferFastAccelerate, newConfig.audioJitterBufferFastAccelerate);
  130. EXPECT_EQ(config.iceConnectionReceivingTimeout, newConfig.iceConnectionReceivingTimeout);
  131. EXPECT_EQ(config.iceBackupCandidatePairPingInterval,
  132. newConfig.iceBackupCandidatePairPingInterval);
  133. EXPECT_EQ(config.continualGatheringPolicy, newConfig.continualGatheringPolicy);
  134. EXPECT_EQ(config.shouldPruneTurnPorts, newConfig.shouldPruneTurnPorts);
  135. EXPECT_EQ(config.iceRegatherIntervalRange.min, newConfig.iceRegatherIntervalRange.min);
  136. EXPECT_EQ(config.iceRegatherIntervalRange.max, newConfig.iceRegatherIntervalRange.max);
  137. EXPECT_EQ(config.cryptoOptions.srtpEnableGcmCryptoSuites,
  138. newConfig.cryptoOptions.srtpEnableGcmCryptoSuites);
  139. EXPECT_EQ(config.cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher,
  140. newConfig.cryptoOptions.srtpEnableAes128Sha1_32CryptoCipher);
  141. EXPECT_EQ(config.cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions,
  142. newConfig.cryptoOptions.srtpEnableEncryptedRtpHeaderExtensions);
  143. EXPECT_EQ(config.cryptoOptions.sframeRequireFrameEncryption,
  144. newConfig.cryptoOptions.sframeRequireFrameEncryption);
  145. EXPECT_EQ(config.rtcpAudioReportIntervalMs, newConfig.rtcpAudioReportIntervalMs);
  146. EXPECT_EQ(config.rtcpVideoReportIntervalMs, newConfig.rtcpVideoReportIntervalMs);
  147. }
  148. - (void)testDefaultValues {
  149. RTCConfiguration *config = [[RTCConfiguration alloc] init];
  150. EXPECT_EQ(config.cryptoOptions, nil);
  151. }
  152. @end
  153. TEST(RTCConfigurationTest, NativeConfigurationConversionTest) {
  154. @autoreleasepool {
  155. RTCConfigurationTest *test = [[RTCConfigurationTest alloc] init];
  156. [test testConversionToNativeConfiguration];
  157. [test testNativeConversionToConfiguration];
  158. [test testDefaultValues];
  159. }
  160. }