Skip to content

Commit 5178c76

Browse files
authored
Merge pull request #99 from AgoraIO/dev/settings
Dev/settings
2 parents 04b064a + 4477683 commit 5178c76

21 files changed

Lines changed: 452 additions & 247 deletions

File tree

iOS/APIExample.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@
9898
03DF1D9324CFC29700DF7151 /* ExternalAudio.mm in Sources */ = {isa = PBXBuildFile; fileRef = 03DF1D8B24CFC29700DF7151 /* ExternalAudio.mm */; };
9999
03DF1D9424CFC29700DF7151 /* AudioController.m in Sources */ = {isa = PBXBuildFile; fileRef = 03DF1D8D24CFC29700DF7151 /* AudioController.m */; };
100100
03F8733224C8696600EDB1A3 /* EntryViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03F8733124C8696600EDB1A3 /* EntryViewController.swift */; };
101+
7F76DCA92571794C00E8B7BC /* SettingsCells.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7F76DCA82571794C00E8B7BC /* SettingsCells.swift */; };
102+
7FDE65A2257E5DCA002AC81F /* UITypeAlias.swift in Sources */ = {isa = PBXBuildFile; fileRef = A7BD765F247CC6920062A6B3 /* UITypeAlias.swift */; };
101103
03FB5B3625642E7C00F04ED0 /* LiveStreaming.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 03FB5B3225642E7C00F04ED0 /* LiveStreaming.storyboard */; };
102104
03FB5B3725642E7C00F04ED0 /* LiveStreaming.swift in Sources */ = {isa = PBXBuildFile; fileRef = 03FB5B3425642E7C00F04ED0 /* LiveStreaming.swift */; };
103105
7FBE1D542576A904005A8619 /* pvc_jnqd.bundle in Resources */ = {isa = PBXBuildFile; fileRef = 7FBE1D502576A904005A8619 /* pvc_jnqd.bundle */; };
@@ -288,6 +290,7 @@
288290
09E72C5D1AABD812866E41A6 /* Pods_Agora_ScreenShare_Extension.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Agora_ScreenShare_Extension.framework; sourceTree = BUILT_PRODUCTS_DIR; };
289291
3C49960D6F11D44FA9A62337 /* Pods-APIExample-Mac.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-APIExample-Mac.debug.xcconfig"; path = "Target Support Files/Pods-APIExample-Mac/Pods-APIExample-Mac.debug.xcconfig"; sourceTree = "<group>"; };
290292
3EA7D4B4D7C9540659392B7F /* Pods-APIExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-APIExample.debug.xcconfig"; path = "Target Support Files/Pods-APIExample/Pods-APIExample.debug.xcconfig"; sourceTree = "<group>"; };
293+
7F76DCA82571794C00E8B7BC /* SettingsCells.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsCells.swift; sourceTree = "<group>"; };
291294
7FBE1D502576A904005A8619 /* pvc_jnqd.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; name = pvc_jnqd.bundle; path = Pods/AgoraRtcEngine_iOS/AgoraRtcKit.framework/AgoraResources/pvc_jnqd.bundle; sourceTree = SOURCE_ROOT; };
292295
7FBE1D512576A904005A8619 /* srmetal.metallib */ = {isa = PBXFileReference; lastKnownFileType = "archive.metal-library"; name = srmetal.metallib; path = Pods/AgoraRtcEngine_iOS/AgoraRtcKit.framework/AgoraResources/srmetal.metallib; sourceTree = SOURCE_ROOT; };
293296
7FBE1D522576A904005A8619 /* pvc_kernels.metallib */ = {isa = PBXFileReference; lastKnownFileType = "archive.metal-library"; name = pvc_kernels.metallib; path = Pods/AgoraRtcEngine_iOS/AgoraRtcKit.framework/AgoraResources/pvc_kernels.metallib; sourceTree = SOURCE_ROOT; };
@@ -330,6 +333,7 @@
330333
isa = PBXGroup;
331334
children = (
332335
0318857824CD667A00C699EB /* SettingsViewController.swift */,
336+
7F76DCA82571794C00E8B7BC /* SettingsCells.swift */,
333337
);
334338
path = Settings;
335339
sourceTree = "<group>";
@@ -1021,6 +1025,7 @@
10211025
isa = PBXSourcesBuildPhase;
10221026
buildActionMask = 2147483647;
10231027
files = (
1028+
7FDE65A2257E5DCA002AC81F /* UITypeAlias.swift in Sources */,
10241029
0339BEC72520A612007D4FDD /* GlobalSettings.swift in Sources */,
10251030
0339BEC525206635007D4FDD /* KeyCenter.swift in Sources */,
10261031
0339BEC425205D1A007D4FDD /* AgoraAudioTube.mm in Sources */,
@@ -1060,6 +1065,7 @@
10601065
03B12DA8251125A500E55818 /* VideoView.swift in Sources */,
10611066
0339D6D424E91BAA008739CD /* QuickSwitchChannelVCItem.swift in Sources */,
10621067
036C42B624D2A3C600A59000 /* AgoraMetalShader.metal in Sources */,
1068+
7F76DCA92571794C00E8B7BC /* SettingsCells.swift in Sources */,
10631069
033A9EE5252D5C6900BC26E1 /* VideoMetadata.swift in Sources */,
10641070
036C42BF24D5853200A59000 /* AgoraMediaRawData.m in Sources */,
10651071
036C42B024D2955D00A59000 /* AgoraCameraSourcePush.swift in Sources */,
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"info" : {
3-
"version" : 1,
4-
"author" : "xcode"
3+
"author" : "xcode",
4+
"version" : 1
55
}
6-
}
6+
}

iOS/APIExample/Base.lproj/Main.storyboard

Lines changed: 123 additions & 22 deletions
Large diffs are not rendered by default.

iOS/APIExample/Common/GlobalSettings.swift

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,58 @@ let SCREEN_SHARE_BROADCASTER_UID_MAX:UInt = 2000
1616
let SCREEN_SHARE_UID = UInt.random(in: SCREEN_SHARE_UID_MIN...SCREEN_SHARE_UID_MAX)
1717
let SCREEN_SHARE_BROADCASTER_UID = UInt.random(in: SCREEN_SHARE_BROADCASTER_UID_MIN...SCREEN_SHARE_BROADCASTER_UID_MAX)
1818

19+
struct SettingItemOption {
20+
var idx: Int
21+
var label:String
22+
var value:Any
23+
}
24+
25+
class SettingItem {
26+
var selected: Int
27+
var options: [SettingItemOption]
28+
func selectedOption() -> SettingItemOption {
29+
return options[selected]
30+
}
31+
32+
init(selected: Int, options: [SettingItemOption]) {
33+
self.selected = selected
34+
self.options = options
35+
}
36+
}
37+
1938
class GlobalSettings {
2039
// The region for connection. This advanced feature applies to scenarios that have regional restrictions.
2140
// For the regions that Agora supports, see https://docs.agora.io/en/Interactive%20Broadcast/API%20Reference/oc/Constants/AgoraAreaCode.html. After specifying the region, the SDK connects to the Agora servers within that region.
2241
var area:AgoraAreaCode = .GLOB
2342
static let shared = GlobalSettings()
43+
var settings:[String:SettingItem] = [
44+
"resolution": SettingItem(selected: 3, options: [
45+
SettingItemOption(idx: 0, label: "90x90", value: CGSize(width: 90, height: 90)),
46+
SettingItemOption(idx: 1, label: "160x120", value: CGSize(width: 160, height: 120)),
47+
SettingItemOption(idx: 2, label: "320x240", value: CGSize(width: 320, height: 240)),
48+
SettingItemOption(idx: 3, label: "640x360", value: CGSize(width: 640, height: 360)),
49+
SettingItemOption(idx: 4, label: "1280x720", value: CGSize(width: 1280, height: 720))
50+
]),
51+
"fps": SettingItem(selected: 3, options: [
52+
SettingItemOption(idx: 0, label: "10fps", value: AgoraVideoFrameRate.fps10),
53+
SettingItemOption(idx: 1, label: "15fps", value: AgoraVideoFrameRate.fps15),
54+
SettingItemOption(idx: 2, label: "24fps", value: AgoraVideoFrameRate.fps24),
55+
SettingItemOption(idx: 3, label: "30fps", value: AgoraVideoFrameRate.fps30),
56+
SettingItemOption(idx: 4, label: "60fps", value: AgoraVideoFrameRate.fps60)
57+
]),
58+
"orientation": SettingItem(selected: 0, options: [
59+
SettingItemOption(idx: 0, label: "adaptive".localized, value: AgoraVideoOutputOrientationMode.adaptative),
60+
SettingItemOption(idx: 1, label: "fixed portrait".localized, value: AgoraVideoOutputOrientationMode.fixedPortrait),
61+
SettingItemOption(idx: 2, label: "fixed landscape".localized, value: AgoraVideoOutputOrientationMode.fixedLandscape)
62+
]),
63+
"area": SettingItem(selected: 0, options: [
64+
SettingItemOption(idx: 0, label: "adaptive".localized, value: AgoraAreaCode.GLOB),
65+
SettingItemOption(idx: 1, label: "fixed portrait".localized, value: AgoraVideoOutputOrientationMode.fixedPortrait),
66+
SettingItemOption(idx: 2, label: "fixed landscape".localized, value: AgoraVideoOutputOrientationMode.fixedLandscape)
67+
])
68+
]
69+
70+
func getSetting(key:String) -> SettingItem? {
71+
return settings[key]
72+
}
2473
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
//
2+
// SettingsCells.swift
3+
// APIExample
4+
//
5+
// Created by ZQZ on 2020/11/28.
6+
// Copyright © 2020 Agora Corp. All rights reserved.
7+
//
8+
9+
import Foundation
10+
11+
class SettingsBaseCell : UITableViewCell
12+
{
13+
var configs:SettingsBaseParam?
14+
weak var delegate:SettingsViewControllerDelegate?
15+
func configure(configs:SettingsBaseParam){
16+
self.configs = configs
17+
}
18+
}
19+
20+
class SettingsBaseParam: NSObject
21+
{
22+
var key:String
23+
var label:String
24+
var type:String
25+
26+
init(key:String, label:String, type:String) {
27+
self.key = key
28+
self.label = label
29+
self.type = type
30+
}
31+
}
32+
33+
class SettingsSliderCell : SettingsBaseCell
34+
{
35+
@IBOutlet weak var settingLabel: UILabel!
36+
@IBOutlet weak var settingSlider: UISlider!
37+
@IBOutlet weak var settingValue: UILabel!
38+
39+
@IBAction func onSliderValueChanged(sender:UISlider){
40+
let val = (sender.value*100).rounded()/100
41+
settingValue.text = "\(val)"
42+
guard let configs = self.configs as? SettingsSliderParam else {return}
43+
delegate?.didChangeValue(type: "SettingsSliderCell", key: configs.key, value: val)
44+
}
45+
46+
override func configure(configs: SettingsBaseParam) {
47+
super.configure(configs: configs)
48+
49+
guard let param = configs as? SettingsSliderParam else {return}
50+
settingLabel.text = param.label
51+
settingSlider.value = param.value
52+
settingSlider.minimumValue = param.minimumValue
53+
settingSlider.maximumValue = param.maximumValue
54+
settingValue.text = "\(settingSlider.value)"
55+
}
56+
}
57+
58+
class SettingsSliderParam: SettingsBaseParam {
59+
var value:Float
60+
var minimumValue:Float
61+
var maximumValue:Float
62+
init(key:String, label:String, value:Float, minimumValue:Float, maximumValue:Float) {
63+
self.value = value
64+
self.minimumValue = minimumValue
65+
self.maximumValue = maximumValue
66+
super.init(key: key, label: label, type: "SliderCell")
67+
}
68+
}
69+
70+
71+
class SettingsLabelCell : SettingsBaseCell
72+
{
73+
@IBOutlet weak var settingLabel: UILabel!
74+
@IBOutlet weak var settingValue: UILabel!
75+
76+
override func configure(configs: SettingsBaseParam) {
77+
super.configure(configs: configs)
78+
79+
guard let param = configs as? SettingsLabelParam else {return}
80+
settingLabel.text = param.label
81+
settingValue.text = param.value
82+
}
83+
}
84+
85+
class SettingsLabelParam: SettingsBaseParam {
86+
var value:String
87+
init(key:String, label:String, value:String) {
88+
self.value = value
89+
super.init(key: key, label: label, type: "LabelCell")
90+
}
91+
}
92+
93+
class SettingsSelectCell : SettingsBaseCell
94+
{
95+
@IBOutlet weak var settingLabel: UILabel!
96+
@IBOutlet weak var settingBtn: UIButton!
97+
98+
override func configure(configs: SettingsBaseParam) {
99+
super.configure(configs: configs)
100+
101+
guard let param = configs as? SettingsSelectParam else {return}
102+
settingLabel.text = param.label
103+
settingBtn.setTitle(param.value, for: .normal)
104+
}
105+
106+
func getSelectAction(_ option:SettingItemOption) -> UIAlertAction{
107+
return UIAlertAction(title: "\(option.label)", style: .default, handler: {[unowned self] action in
108+
guard let param = self.configs as? SettingsSelectParam else {return}
109+
self.settingBtn.setTitle(option.label, for: .normal)
110+
param.settingItem.selected = option.idx
111+
self.delegate?.didChangeValue(type: "SettingsSelectCell", key: param.key, value: param.settingItem)
112+
})
113+
}
114+
115+
@IBAction func onSelect(_ sender:UIButton) {
116+
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
117+
guard let param = configs as? SettingsSelectParam else {return}
118+
for option in param.settingItem.options {
119+
alert.addAction(getSelectAction(option))
120+
}
121+
alert.addCancelAction()
122+
param.context?.present(alert, animated: true, completion: nil)
123+
}
124+
}
125+
126+
class SettingsSelectParam: SettingsBaseParam {
127+
var value:String
128+
var settingItem:SettingItem
129+
weak var context:UIViewController?;
130+
init(key:String, label:String, settingItem:SettingItem, context:UIViewController) {
131+
self.settingItem = settingItem
132+
self.context = context
133+
self.value = settingItem.selectedOption().label
134+
super.init(key: key, label: label, type: "SelectCell")
135+
}
136+
}

iOS/APIExample/Common/Settings/SettingsViewController.swift

Lines changed: 1 addition & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,66 +10,7 @@ import Foundation
1010
import UIKit
1111

1212
protocol SettingsViewControllerDelegate: AnyObject {
13-
func didChangeValue(key:String, value: AnyObject)
14-
}
15-
16-
class SettingsBaseCell : UITableViewCell
17-
{
18-
var configs:SettingsBaseParam?
19-
weak var delegate:SettingsViewControllerDelegate?
20-
func configure(configs:SettingsBaseParam){
21-
self.configs = configs
22-
}
23-
}
24-
25-
class SettingsBaseParam: NSObject
26-
{
27-
var key:String
28-
var label:String
29-
var type:String
30-
31-
init(key:String, label:String, type:String) {
32-
self.key = key
33-
self.label = label
34-
self.type = type
35-
}
36-
}
37-
38-
class SettingsSliderCell : SettingsBaseCell
39-
{
40-
@IBOutlet weak var settingLabel: AGLabel!
41-
@IBOutlet weak var settingSlider: UISlider!
42-
@IBOutlet weak var settingValue: AGLabel!
43-
44-
@IBAction func onSliderValueChanged(sender:UISlider){
45-
let val = (sender.value*100).rounded()/100
46-
settingValue.text = "\(val)"
47-
guard let configs = self.configs as? SettingsSliderParam else {return}
48-
delegate?.didChangeValue(key: configs.key, value: val as AnyObject)
49-
}
50-
51-
override func configure(configs: SettingsBaseParam) {
52-
super.configure(configs: configs)
53-
54-
guard let param = configs as? SettingsSliderParam else {return}
55-
settingLabel.text = param.label
56-
settingSlider.value = param.value
57-
settingSlider.minimumValue = param.minimumValue
58-
settingSlider.maximumValue = param.maximumValue
59-
settingValue.text = "\(settingSlider.value)"
60-
}
61-
}
62-
63-
class SettingsSliderParam: SettingsBaseParam {
64-
var value:Float
65-
var minimumValue:Float
66-
var maximumValue:Float
67-
init(key:String, label:String, value:Float, minimumValue:Float, maximumValue:Float) {
68-
self.value = value
69-
self.minimumValue = minimumValue
70-
self.maximumValue = maximumValue
71-
super.init(key: key, label: label, type: "SliderCell")
72-
}
13+
func didChangeValue(type:String, key:String, value: Any)
7314
}
7415

7516
class SettingsViewController : UITableViewController

iOS/APIExample/Common/VideoView.xib

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="16097.2" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="17506" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES">
33
<device id="retina6_1" orientation="portrait" appearance="light"/>
44
<dependencies>
55
<deployment identifier="iOS"/>
6-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="16087"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17505"/>
77
<capability name="Named colors" minToolsVersion="9.0"/>
88
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
99
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@@ -34,10 +34,11 @@
3434
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="tmV-Lc-ye5">
3535
<rect key="frame" x="10" y="852" width="0.0" height="0.0"/>
3636
<fontDescription key="fontDescription" type="system" pointSize="9"/>
37-
<nil key="textColor"/>
37+
<color key="textColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
3838
<nil key="highlightedColor"/>
3939
</label>
4040
</subviews>
41+
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
4142
<color key="backgroundColor" name="videoBackground"/>
4243
<constraints>
4344
<constraint firstItem="z6G-aL-Ut4" firstAttribute="top" secondItem="vUN-kp-3ea" secondAttribute="top" id="65z-Qr-jbs"/>
@@ -51,7 +52,6 @@
5152
<constraint firstItem="jNO-yh-cWz" firstAttribute="centerX" secondItem="vUN-kp-3ea" secondAttribute="centerX" id="tnR-4i-aTA"/>
5253
<constraint firstItem="vUN-kp-3ea" firstAttribute="trailing" secondItem="z6G-aL-Ut4" secondAttribute="trailing" id="vMm-b5-ZoF"/>
5354
</constraints>
54-
<viewLayoutGuide key="safeArea" id="vUN-kp-3ea"/>
5555
<connections>
5656
<outlet property="infoLabel" destination="2sO-zb-ccE" id="P4i-71-J0G"/>
5757
<outlet property="placeholderLabel" destination="jNO-yh-cWz" id="FTU-Vl-aoH"/>

iOS/APIExample/Examples/Advanced/CustomVideoRender/CustomVideoRender.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ class CustomVideoRenderMain: BaseViewController {
5858
agoraKit.setLogFile(LogUtils.sdkLogPath())
5959

6060
// get channel name from configs
61-
guard let channelName = configs["channelName"] as? String else {return}
61+
guard let channelName = configs["channelName"] as? String,
62+
let resolution = GlobalSettings.shared.getSetting(key: "resolution")?.selectedOption().value as? CGSize,
63+
let fps = GlobalSettings.shared.getSetting(key: "fps")?.selectedOption().value as? AgoraVideoFrameRate,
64+
let orientation = GlobalSettings.shared.getSetting(key: "orientation")?.selectedOption().value as? AgoraVideoOutputOrientationMode else {return}
6265

6366
// make myself a broadcaster
6467
agoraKit.setChannelProfile(.liveBroadcasting)
@@ -67,10 +70,10 @@ class CustomVideoRenderMain: BaseViewController {
6770

6871
// enable video module and set up video encoding configs
6972
agoraKit.enableVideo()
70-
agoraKit.setVideoEncoderConfiguration(AgoraVideoEncoderConfiguration(size: AgoraVideoDimension640x360,
71-
frameRate: .fps15,
72-
bitrate: AgoraVideoBitrateStandard,
73-
orientationMode: .adaptative))
73+
agoraKit.setVideoEncoderConfiguration(AgoraVideoEncoderConfiguration(size: resolution,
74+
frameRate: fps,
75+
bitrate: AgoraVideoBitrateStandard,
76+
orientationMode: orientation))
7477

7578

7679
// set up your own render

0 commit comments

Comments
 (0)