ARDSettingsModel.m 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright 2016 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 "ARDSettingsModel+Private.h"
  11. #import "ARDSettingsStore.h"
  12. #import "WebRTC/RTCMediaConstraints.h"
  13. NS_ASSUME_NONNULL_BEGIN
  14. static NSArray<NSString *> *videoResolutionsStaticValues() {
  15. return @[ @"480x360", @"640x480", @"960x540", @"1280x720" ];
  16. }
  17. static NSArray<NSString *> *videoCodecsStaticValues() {
  18. return @[ @"H264", @"VP8", @"VP9" ];
  19. }
  20. @interface ARDSettingsModel () {
  21. ARDSettingsStore *_settingsStore;
  22. }
  23. @end
  24. @implementation ARDSettingsModel
  25. - (NSArray<NSString *> *)availableVideoResolutions {
  26. return videoResolutionsStaticValues();
  27. }
  28. - (NSString *)currentVideoResolutionSettingFromStore {
  29. NSString *resolution = [[self settingsStore] videoResolution];
  30. if (!resolution) {
  31. resolution = [self defaultVideoResolutionSetting];
  32. // To ensure consistency add the default to the store.
  33. [[self settingsStore] setVideoResolution:resolution];
  34. }
  35. return resolution;
  36. }
  37. - (NSString *)readableResolution:(NSString *)resolution {
  38. NSString *readableResolution = NSLocalizedString(@"Unknown", nil);
  39. if ([resolution isEqualToString:videoResolutionsStaticValues()[0]]) {
  40. readableResolution = NSLocalizedString(@"Low", @"TRANSLATORS this is a video quality option (Video quality : Low)");
  41. } else if ([resolution isEqualToString:videoResolutionsStaticValues()[1]]) {
  42. readableResolution = NSLocalizedString(@"Normal", @"TRANSLATORS this is a video quality option (Video quality : Normal)");
  43. } else if ([resolution isEqualToString:videoResolutionsStaticValues()[2]]) {
  44. readableResolution = NSLocalizedString(@"High", @"TRANSLATORS this is a video quality option (Video quality : High)");
  45. } else if ([resolution isEqualToString:videoResolutionsStaticValues()[3]]) {
  46. readableResolution = NSLocalizedString(@"HD", @"TRANSLATORS this is a video quality option (Video quality : HD)");
  47. }
  48. return readableResolution;
  49. }
  50. - (BOOL)storeVideoResolutionSetting:(NSString *)resolution {
  51. if (![[self availableVideoResolutions] containsObject:resolution]) {
  52. return NO;
  53. }
  54. [[self settingsStore] setVideoResolution:resolution];
  55. return YES;
  56. }
  57. - (BOOL)videoDisabledSettingFromStore {
  58. BOOL videoDisabled = [[self settingsStore] videoDisabledDefault];
  59. if (!videoDisabled) {
  60. [[self settingsStore] setVideoDisabledDefault:NO];
  61. }
  62. return videoDisabled;
  63. }
  64. - (void)storeVideoDisabledDefault:(BOOL)disabled {
  65. [[self settingsStore] setVideoDisabledDefault:disabled];
  66. }
  67. - (NSArray<NSString *> *)availableVideoCodecs {
  68. return videoCodecsStaticValues();
  69. }
  70. - (NSString *)currentVideoCodecSettingFromStore {
  71. NSString *videoCodec = [[self settingsStore] videoCodec];
  72. if (!videoCodec) {
  73. videoCodec = [self defaultVideoCodecSetting];
  74. [[self settingsStore] setVideoCodec:videoCodec];
  75. }
  76. return videoCodec;
  77. }
  78. - (BOOL)storeVideoCodecSetting:(NSString *)videoCodec {
  79. if (![[self availableVideoCodecs] containsObject:videoCodec]) {
  80. return NO;
  81. }
  82. [[self settingsStore] setVideoCodec:videoCodec];
  83. return YES;
  84. }
  85. - (nullable NSNumber *)currentMaxBitrateSettingFromStore {
  86. return [[self settingsStore] maxBitrate];
  87. }
  88. - (void)storeMaxBitrateSetting:(nullable NSNumber *)bitrate {
  89. [[self settingsStore] setMaxBitrate:bitrate];
  90. }
  91. #pragma mark - Testable
  92. - (ARDSettingsStore *)settingsStore {
  93. if (!_settingsStore) {
  94. _settingsStore = [[ARDSettingsStore alloc] init];
  95. }
  96. return _settingsStore;
  97. }
  98. - (int)currentVideoResolutionWidthFromStore {
  99. NSString *resolution = [self currentVideoResolutionSettingFromStore];
  100. return [self videoResolutionComponentAtIndex:0 inString:resolution];
  101. }
  102. - (int)currentVideoResolutionHeightFromStore {
  103. NSString *resolution = [self currentVideoResolutionSettingFromStore];
  104. return [self videoResolutionComponentAtIndex:1 inString:resolution];
  105. }
  106. #pragma mark -
  107. - (NSString *)defaultVideoResolutionSetting {
  108. return videoResolutionsStaticValues()[1];
  109. }
  110. - (int)videoResolutionComponentAtIndex:(int)index inString:(NSString *)resolution {
  111. if (index != 0 && index != 1) {
  112. return 0;
  113. }
  114. NSArray<NSString *> *components = [resolution componentsSeparatedByString:@"x"];
  115. if (components.count != 2) {
  116. return 0;
  117. }
  118. return components[index].intValue;
  119. }
  120. - (NSString *)defaultVideoCodecSetting {
  121. return videoCodecsStaticValues()[0];
  122. }
  123. @end
  124. NS_ASSUME_NONNULL_END