ARDSettingsStore.m (3505B)
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 11 #import "ARDSettingsStore.h" 12 13 static NSString *const kVideoResolutionKey = @"rtc_video_resolution_key"; 14 static NSString *const kVideoCodecKey = @"rtc_video_codec_info_key"; 15 static NSString *const kBitrateKey = @"rtc_max_bitrate_key"; 16 static NSString *const kAudioOnlyKey = @"rtc_audio_only_key"; 17 static NSString *const kCreateAecDumpKey = @"rtc_create_aec_dump_key"; 18 static NSString *const kUseManualAudioConfigKey = 19 @"rtc_use_manual_audio_config_key"; 20 21 NS_ASSUME_NONNULL_BEGIN 22 @interface ARDSettingsStore () { 23 NSUserDefaults *_storage; 24 } 25 @property(nonatomic, strong, readonly) NSUserDefaults *storage; 26 @end 27 28 @implementation ARDSettingsStore 29 30 + (void)setDefaultsForVideoResolution:(NSString *)videoResolution 31 videoCodec:(NSData *)videoCodec 32 bitrate:(nullable NSNumber *)bitrate 33 audioOnly:(BOOL)audioOnly 34 createAecDump:(BOOL)createAecDump 35 useManualAudioConfig:(BOOL)useManualAudioConfig { 36 NSMutableDictionary<NSString *, id> *defaultsDictionary = [@{ 37 kAudioOnlyKey : @(audioOnly), 38 kCreateAecDumpKey : @(createAecDump), 39 kUseManualAudioConfigKey : @(useManualAudioConfig) 40 } mutableCopy]; 41 42 if (videoResolution) { 43 defaultsDictionary[kVideoResolutionKey] = videoResolution; 44 } 45 if (videoCodec) { 46 defaultsDictionary[kVideoCodecKey] = videoCodec; 47 } 48 if (bitrate) { 49 defaultsDictionary[kBitrateKey] = bitrate; 50 } 51 [[NSUserDefaults standardUserDefaults] registerDefaults:defaultsDictionary]; 52 } 53 54 - (NSUserDefaults *)storage { 55 if (!_storage) { 56 _storage = [NSUserDefaults standardUserDefaults]; 57 } 58 return _storage; 59 } 60 61 - (NSString *)videoResolution { 62 return [self.storage objectForKey:kVideoResolutionKey]; 63 } 64 65 - (void)setVideoResolution:(NSString *)resolution { 66 [self.storage setObject:resolution forKey:kVideoResolutionKey]; 67 [self.storage synchronize]; 68 } 69 70 - (NSData *)videoCodec { 71 return [self.storage objectForKey:kVideoCodecKey]; 72 } 73 74 - (void)setVideoCodec:(NSData *)videoCodec { 75 [self.storage setObject:videoCodec forKey:kVideoCodecKey]; 76 [self.storage synchronize]; 77 } 78 79 - (nullable NSNumber *)maxBitrate { 80 return [self.storage objectForKey:kBitrateKey]; 81 } 82 83 - (void)setMaxBitrate:(nullable NSNumber *)value { 84 [self.storage setObject:value forKey:kBitrateKey]; 85 [self.storage synchronize]; 86 } 87 88 - (BOOL)audioOnly { 89 return [self.storage boolForKey:kAudioOnlyKey]; 90 } 91 92 - (void)setAudioOnly:(BOOL)audioOnly { 93 [self.storage setBool:audioOnly forKey:kAudioOnlyKey]; 94 [self.storage synchronize]; 95 } 96 97 - (BOOL)createAecDump { 98 return [self.storage boolForKey:kCreateAecDumpKey]; 99 } 100 101 - (void)setCreateAecDump:(BOOL)createAecDump { 102 [self.storage setBool:createAecDump forKey:kCreateAecDumpKey]; 103 [self.storage synchronize]; 104 } 105 106 - (BOOL)useManualAudioConfig { 107 return [self.storage boolForKey:kUseManualAudioConfigKey]; 108 } 109 110 - (void)setUseManualAudioConfig:(BOOL)useManualAudioConfig { 111 [self.storage setBool:useManualAudioConfig forKey:kUseManualAudioConfigKey]; 112 [self.storage synchronize]; 113 } 114 115 @end 116 NS_ASSUME_NONNULL_END