Skip to content

Commit

Permalink
Merge pull request #8 from AgoraIO-Community/dual-stream
Browse files Browse the repository at this point in the history
Add Dual Stream Mode
  • Loading branch information
maxxfrazer authored Jan 19, 2021
2 parents 0a6f612 + e58b107 commit f5cb407
Show file tree
Hide file tree
Showing 38 changed files with 282 additions and 60 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: swiftlint

on:
push:
branches:
- "main"
pull_request:
branches:
- "*"

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: GitHub Action for SwiftLint
uses: norio-nomura/[email protected]
4 changes: 3 additions & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
line_length:
ignores_comments: true
ignores_comments: true
excluded:
- Agora-*-Example
4 changes: 2 additions & 2 deletions AgoraUIKit_iOS.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'AgoraUIKit_iOS'
s.version = '1.1.0'
s.version = '1.2.0'
s.summary = 'Agora video session UIKit template.'

s.description = <<-DESC
Expand All @@ -24,7 +24,7 @@ Use this Pod to create a video UIKit view that can be easily added to your iOS a
s.swift_versions = ['5.0']

s.source_files = 'Sources/Agora-UIKit/*'
s.dependency 'AgoraRtcEngine_iOS', '~> 3.0'
s.dependency 'AgoraRtcEngine_iOS', '~> 3.2'

s.static_framework = true
end
4 changes: 2 additions & 2 deletions AgoraUIKit_macOS.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'AgoraUIKit_macOS'
s.version = '1.1.0'
s.version = '1.2.0'
s.summary = 'Agora video session AppKit template.'

s.description = <<-DESC
Expand All @@ -24,7 +24,7 @@ Use this Pod to create a video AppKit view that can be easily added to your macO
s.swift_versions = ['5.0']

s.source_files = 'Sources/Agora-UIKit/*'
s.dependency 'AgoraRtcEngine_macOS', '~> 3.0'
s.dependency 'AgoraRtcEngine_macOS', '~> 3.2'

s.static_framework = true
end
3 changes: 3 additions & 0 deletions Sources/Agora-UIKit/AgoraCollectionViewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ extension AgoraVideoViewer: MPCollectionViewDelegate, MPCollectionViewDataSource
self.agkit.setupLocalVideo(newVid.canvas)
} else {
self.agkit.setupRemoteVideo(newVid.canvas)
if newVid.uid != myActiveSpeaker && self.agoraSettings.usingDualStream {
self.agkit.setRemoteVideoStream(newVid.uid, type: .low)
}
}
}

Expand Down
18 changes: 18 additions & 0 deletions Sources/Agora-UIKit/AgoraSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,26 @@ public struct AgoraSettings {
public var videoConfiguration: AgoraVideoEncoderConfiguration = AgoraVideoEncoderConfiguration()
/// Colors for views inside AgoraVideoViewer
public var colors: AgoraViewerColors = AgoraViewerColors()

/// Full string for low bitrate stream parameter, including key of `che.video.lowBitRateStreamParameter`.
/// Set this property before initialising AgoraVideoViewer.
public var lowBitRateStream: String? = AgoraSettings.defaultLowBitrateParam

/// Whether we are using dual stream mode, which helps to reduce Agora costs.
public var usingDualStream: Bool {
get { self.lowBitRateStream != nil }
set { self.lowBitRateStream = newValue ? AgoraSettings.defaultLowBitrateParam : nil }
}

/// Maximum number of videos in the grid view before the low bitrate is adopted.
public var gridThresholdHighBitrate: Int = 4

/// Create a new AgoraSettings object
public init() {}

static private let defaultLowBitrateParam = "{\"che.video.lowBitRateStreamParameter\":" +
"{\"width\":160,\"height\":120,\"frameRate\":5,\"bitRate\":45}" +
"}"
}

/// Colors for views inside AgoraVideoViewer
Expand Down
14 changes: 13 additions & 1 deletion Sources/Agora-UIKit/AgoraVideoViewer+Ordering.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ extension AgoraVideoViewer {
.width, .height, .maxYMargin, .minYMargin, .maxXMargin, .minXMargin
]
#endif
if self.agoraSettings.usingDualStream && self.userID != keyVals.key {
self.agkit.setRemoteVideoStream(
keyVals.key,
type: self.agoraSettings.gridThresholdHighBitrate > 2 ? .high : .low
)
}
}
}

Expand All @@ -66,7 +72,7 @@ extension AgoraVideoViewer {
// We take on a grid of 4x4 (16).
let maxSqrt = ceil(sqrt(CGFloat(vidCounts)))
let multDim = 1 / maxSqrt
for (idx, (_, videoSessionView)) in self.userVideosForGrid.enumerated() {
for (idx, (videoID, videoSessionView)) in self.userVideosForGrid.enumerated() {
self.backgroundVideoHolder.addSubview(videoSessionView)
videoSessionView.frame.size = CGSize(
width: backgroundVideoHolder.frame.width * multDim,
Expand Down Expand Up @@ -97,6 +103,12 @@ extension AgoraVideoViewer {
#else
videoSessionView.autoresizingMask = [.width, .height, .maxYMargin, .minYMargin, .maxXMargin, .minXMargin]
#endif
if self.agoraSettings.usingDualStream && videoID != self.userID {
self.agkit.setRemoteVideoStream(
videoID,
type: vidCounts <= self.agoraSettings.gridThresholdHighBitrate ? .high : .low
)
}
}
}
}
6 changes: 6 additions & 0 deletions Sources/Agora-UIKit/AgoraVideoViewer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ open class AgoraVideoViewer: MPView {
)
engine.enableAudioVolumeIndication(1000, smooth: 3, report_vad: true)
engine.setChannelProfile(.liveBroadcasting)
if self.agoraSettings.usingDualStream {
engine.enableDualStreamMode(true)
if let bitrateStream = self.agoraSettings.lowBitRateStream {
engine.setParameters(bitrateStream)
}
}
engine.setClientRole(self.userRole)
return engine
}()
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a title="Classes Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="index.html">AgoraUIKit_iOS 1.1.0 Docs</a> (100% documented)</p>
<p><a href="index.html">AgoraUIKit_iOS 1.2.0 Docs</a> (100% documented)</p>
<p class="header-right">
<form role="search" action="search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
Expand Down Expand Up @@ -187,7 +187,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2021 <a class="link" href="https://github.com/AgoraIO-Community/iOS-UIKit" target="_blank" rel="external">Max Cobb</a>. All rights reserved. (Last updated: 2021-01-04)</p>
<p>&copy; 2021 <a class="link" href="https://github.com/AgoraIO-Community/iOS-UIKit" target="_blank" rel="external">Max Cobb</a>. All rights reserved. (Last updated: 2021-01-18)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/AgoraVideoViewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a title="AgoraVideoViewer Class Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="../index.html">AgoraUIKit_iOS 1.1.0 Docs</a> (100% documented)</p>
<p><a href="../index.html">AgoraUIKit_iOS 1.2.0 Docs</a> (100% documented)</p>
<p class="header-right">
<form role="search" action="../search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
Expand Down Expand Up @@ -2690,7 +2690,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2021 <a class="link" href="https://github.com/AgoraIO-Community/iOS-UIKit" target="_blank" rel="external">Max Cobb</a>. All rights reserved. (Last updated: 2021-01-04)</p>
<p>&copy; 2021 <a class="link" href="https://github.com/AgoraIO-Community/iOS-UIKit" target="_blank" rel="external">Max Cobb</a>. All rights reserved. (Last updated: 2021-01-18)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/AgoraVideoViewer/Style.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a title="Style Enumeration Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="../../index.html">AgoraUIKit_iOS 1.1.0 Docs</a> (100% documented)</p>
<p><a href="../../index.html">AgoraUIKit_iOS 1.2.0 Docs</a> (100% documented)</p>
<p class="header-right">
<form role="search" action="../../search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
Expand Down Expand Up @@ -217,7 +217,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2021 <a class="link" href="https://github.com/AgoraIO-Community/iOS-UIKit" target="_blank" rel="external">Max Cobb</a>. All rights reserved. (Last updated: 2021-01-04)</p>
<p>&copy; 2021 <a class="link" href="https://github.com/AgoraIO-Community/iOS-UIKit" target="_blank" rel="external">Max Cobb</a>. All rights reserved. (Last updated: 2021-01-18)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
4 changes: 2 additions & 2 deletions docs/Classes/AgoraVideoViewer/TokenError.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a title="TokenError Enumeration Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="../../index.html">AgoraUIKit_iOS 1.1.0 Docs</a> (100% documented)</p>
<p><a href="../../index.html">AgoraUIKit_iOS 1.2.0 Docs</a> (100% documented)</p>
<p class="header-right">
<form role="search" action="../../search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
Expand Down Expand Up @@ -191,7 +191,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2021 <a class="link" href="https://github.com/AgoraIO-Community/iOS-UIKit" target="_blank" rel="external">Max Cobb</a>. All rights reserved. (Last updated: 2021-01-04)</p>
<p>&copy; 2021 <a class="link" href="https://github.com/AgoraIO-Community/iOS-UIKit" target="_blank" rel="external">Max Cobb</a>. All rights reserved. (Last updated: 2021-01-18)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
4 changes: 2 additions & 2 deletions docs/Protocols.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a title="Protocols Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="index.html">AgoraUIKit_iOS 1.1.0 Docs</a> (100% documented)</p>
<p><a href="index.html">AgoraUIKit_iOS 1.2.0 Docs</a> (100% documented)</p>
<p class="header-right">
<form role="search" action="search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
Expand Down Expand Up @@ -132,7 +132,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2021 <a class="link" href="https://github.com/AgoraIO-Community/iOS-UIKit" target="_blank" rel="external">Max Cobb</a>. All rights reserved. (Last updated: 2021-01-04)</p>
<p>&copy; 2021 <a class="link" href="https://github.com/AgoraIO-Community/iOS-UIKit" target="_blank" rel="external">Max Cobb</a>. All rights reserved. (Last updated: 2021-01-18)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
4 changes: 2 additions & 2 deletions docs/Protocols/AgoraVideoViewerDelegate.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a title="AgoraVideoViewerDelegate Protocol Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="../index.html">AgoraUIKit_iOS 1.1.0 Docs</a> (100% documented)</p>
<p><a href="../index.html">AgoraUIKit_iOS 1.2.0 Docs</a> (100% documented)</p>
<p class="header-right">
<form role="search" action="../search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
Expand Down Expand Up @@ -418,7 +418,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2021 <a class="link" href="https://github.com/AgoraIO-Community/iOS-UIKit" target="_blank" rel="external">Max Cobb</a>. All rights reserved. (Last updated: 2021-01-04)</p>
<p>&copy; 2021 <a class="link" href="https://github.com/AgoraIO-Community/iOS-UIKit" target="_blank" rel="external">Max Cobb</a>. All rights reserved. (Last updated: 2021-01-18)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
4 changes: 2 additions & 2 deletions docs/Structs.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a title="Structures Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="index.html">AgoraUIKit_iOS 1.1.0 Docs</a> (100% documented)</p>
<p><a href="index.html">AgoraUIKit_iOS 1.2.0 Docs</a> (100% documented)</p>
<p class="header-right">
<form role="search" action="search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
Expand Down Expand Up @@ -214,7 +214,7 @@ <h4>Declaration</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2021 <a class="link" href="https://github.com/AgoraIO-Community/iOS-UIKit" target="_blank" rel="external">Max Cobb</a>. All rights reserved. (Last updated: 2021-01-04)</p>
<p>&copy; 2021 <a class="link" href="https://github.com/AgoraIO-Community/iOS-UIKit" target="_blank" rel="external">Max Cobb</a>. All rights reserved. (Last updated: 2021-01-18)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
4 changes: 2 additions & 2 deletions docs/Structs/AgoraConnectionData.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<a title="AgoraConnectionData Structure Reference"></a>
<header>
<div class="content-wrapper">
<p><a href="../index.html">AgoraUIKit_iOS 1.1.0 Docs</a> (100% documented)</p>
<p><a href="../index.html">AgoraUIKit_iOS 1.2.0 Docs</a> (100% documented)</p>
<p class="header-right">
<form role="search" action="../search.json">
<input type="text" placeholder="Search documentation" data-typeahead>
Expand Down Expand Up @@ -168,7 +168,7 @@ <h4>Parameters</h4>
</section>
</section>
<section id="footer">
<p>&copy; 2021 <a class="link" href="https://github.com/AgoraIO-Community/iOS-UIKit" target="_blank" rel="external">Max Cobb</a>. All rights reserved. (Last updated: 2021-01-04)</p>
<p>&copy; 2021 <a class="link" href="https://github.com/AgoraIO-Community/iOS-UIKit" target="_blank" rel="external">Max Cobb</a>. All rights reserved. (Last updated: 2021-01-18)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.13.6</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</article>
Expand Down
Loading

0 comments on commit f5cb407

Please sign in to comment.