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