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.

91 lines
3.6 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 "RTCMediaConstraints+Private.h"
  11. #import "helpers/NSString+StdString.h"
  12. #include <memory>
  13. NSString *const kRTCMediaConstraintsAudioNetworkAdaptorConfig =
  14. @(webrtc::MediaConstraints::kAudioNetworkAdaptorConfig);
  15. NSString *const kRTCMediaConstraintsIceRestart = @(webrtc::MediaConstraints::kIceRestart);
  16. NSString *const kRTCMediaConstraintsOfferToReceiveAudio =
  17. @(webrtc::MediaConstraints::kOfferToReceiveAudio);
  18. NSString *const kRTCMediaConstraintsOfferToReceiveVideo =
  19. @(webrtc::MediaConstraints::kOfferToReceiveVideo);
  20. NSString *const kRTCMediaConstraintsVoiceActivityDetection =
  21. @(webrtc::MediaConstraints::kVoiceActivityDetection);
  22. NSString *const kRTCMediaConstraintsValueTrue = @(webrtc::MediaConstraints::kValueTrue);
  23. NSString *const kRTCMediaConstraintsValueFalse = @(webrtc::MediaConstraints::kValueFalse);
  24. @implementation RTCMediaConstraints {
  25. NSDictionary<NSString *, NSString *> *_mandatory;
  26. NSDictionary<NSString *, NSString *> *_optional;
  27. }
  28. - (instancetype)initWithMandatoryConstraints:
  29. (NSDictionary<NSString *, NSString *> *)mandatory
  30. optionalConstraints:
  31. (NSDictionary<NSString *, NSString *> *)optional {
  32. if (self = [super init]) {
  33. _mandatory = [[NSDictionary alloc] initWithDictionary:mandatory
  34. copyItems:YES];
  35. _optional = [[NSDictionary alloc] initWithDictionary:optional
  36. copyItems:YES];
  37. }
  38. return self;
  39. }
  40. - (NSString *)description {
  41. return [NSString stringWithFormat:@"RTCMediaConstraints:\n%@\n%@",
  42. _mandatory,
  43. _optional];
  44. }
  45. #pragma mark - Private
  46. - (std::unique_ptr<webrtc::MediaConstraints>)nativeConstraints {
  47. webrtc::MediaConstraints::Constraints mandatory =
  48. [[self class] nativeConstraintsForConstraints:_mandatory];
  49. webrtc::MediaConstraints::Constraints optional =
  50. [[self class] nativeConstraintsForConstraints:_optional];
  51. webrtc::MediaConstraints *nativeConstraints =
  52. new webrtc::MediaConstraints(mandatory, optional);
  53. return std::unique_ptr<webrtc::MediaConstraints>(nativeConstraints);
  54. }
  55. + (webrtc::MediaConstraints::Constraints)nativeConstraintsForConstraints:
  56. (NSDictionary<NSString *, NSString *> *)constraints {
  57. webrtc::MediaConstraints::Constraints nativeConstraints;
  58. for (NSString *key in constraints) {
  59. NSAssert([key isKindOfClass:[NSString class]],
  60. @"%@ is not an NSString.", key);
  61. NSString *value = [constraints objectForKey:key];
  62. NSAssert([value isKindOfClass:[NSString class]],
  63. @"%@ is not an NSString.", value);
  64. if ([kRTCMediaConstraintsAudioNetworkAdaptorConfig isEqualToString:key]) {
  65. // This value is base64 encoded.
  66. NSData *charData = [[NSData alloc] initWithBase64EncodedString:value options:0];
  67. std::string configValue =
  68. std::string(reinterpret_cast<const char *>(charData.bytes), charData.length);
  69. nativeConstraints.push_back(webrtc::MediaConstraints::Constraint(key.stdString, configValue));
  70. } else {
  71. nativeConstraints.push_back(
  72. webrtc::MediaConstraints::Constraint(key.stdString, value.stdString));
  73. }
  74. }
  75. return nativeConstraints;
  76. }
  77. @end