Skip to content

Commit

Permalink
Merge pull request #228 from shiguredo/feature/simulcast-encodings-sc…
Browse files Browse the repository at this point in the history
…ale-resolution-down-to

 scaleResolutionDownTo 追加
  • Loading branch information
zztkm authored Feb 4, 2025
2 parents b229938 + cf5cdd4 commit aeb0647
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

- [UPDATE] WebRTC m132.6834.5.7 に上げる
- @zztkm
- [ADD] サイマルキャストの映像のエンコーディングパラメーター `scaleResolutionDownTo` を追加する
- @zztkm
- [CHANGE] connect メッセージの `multistream` を true 固定で送信する処理を削除する破壊的変更
- Configration.role に .sendrecv を指定している場合に multistream を true に更新する処理を削除
- Configration.spotlightEnabled に .enabled を指定している場合に multistream を true に更新する処理を削除
Expand Down
8 changes: 8 additions & 0 deletions Sora/PeerChannel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,14 @@ extension RTCRtpSender {
oldEncoding.scaleResolutionDownBy = NSNumber(value: value)
}

if let value = encoding.scaleResolutionDownTo {
Logger.debug(
type: .peerChannel,
message: "scaleResolutionDownTo: \(value.maxWidth)x\(value.maxHeight)")
oldEncoding.scaleResolutionDownTo?.maxWidth = value.maxWidth
oldEncoding.scaleResolutionDownTo?.maxHeight = value.maxHeight
}

if let value = encoding.scalabilityMode {
Logger.debug(type: .peerChannel, message: "scalabilityMode: \(value)")
oldEncoding.scalabilityMode = value
Expand Down
37 changes: 37 additions & 0 deletions Sora/Signaling.swift
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,9 @@ public struct SignalingOffer {
/// 映像解像度を送信前に下げる度合
public let scaleResolutionDownBy: Double?

/// エンコーディングを制限する最大のサイズ
public let scaleResolutionDownTo: RTCResolutionRestriction?

/// scalability mode
public let scalabilityMode: String?

Expand All @@ -394,6 +397,10 @@ public struct SignalingOffer {
if let value = scaleResolutionDownBy {
params.scaleResolutionDownBy = NSNumber(value: value)
}
if let value = scaleResolutionDownTo {
params.scaleResolutionDownTo?.maxWidth = value.maxWidth
params.scaleResolutionDownTo?.maxHeight = value.maxHeight
}
params.scalabilityMode = scalabilityMode
return params
}
Expand Down Expand Up @@ -969,6 +976,25 @@ extension SignalingOffer.Configuration: Codable {
}
}

/// scaleResolutionDownTo を JSON デコードする専用の構造体
private struct ScaleResolutionDownTo {
fileprivate let maxWidth: Int
fileprivate let maxHeight: Int
}

extension ScaleResolutionDownTo: Codable {
enum CodingKeys: String, CodingKey {
case maxWidth
case maxHeight
}

public init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
maxWidth = try container.decode(Int.self, forKey: .maxWidth)
maxHeight = try container.decode(Int.self, forKey: .maxHeight)
}
}

/// :nodoc:
extension SignalingOffer.Encoding: Codable {
enum CodingKeys: String, CodingKey {
Expand All @@ -977,6 +1003,7 @@ extension SignalingOffer.Encoding: Codable {
case maxBitrate
case maxFramerate
case scaleResolutionDownBy
case scaleResolutionDownTo
case scalabilityMode
}

Expand All @@ -989,6 +1016,16 @@ extension SignalingOffer.Encoding: Codable {
scaleResolutionDownBy = try container.decodeIfPresent(
Double.self,
forKey: .scaleResolutionDownBy)
if let _scleResolutionDownTo = try container.decodeIfPresent(
ScaleResolutionDownTo.self, forKey: .scaleResolutionDownTo)
{
let restriction = RTCResolutionRestriction()
restriction.maxWidth = NSNumber(value: _scleResolutionDownTo.maxWidth)
restriction.maxHeight = NSNumber(value: _scleResolutionDownTo.maxHeight)
scaleResolutionDownTo = restriction
} else {
scaleResolutionDownTo = nil
}
scalabilityMode = try container.decodeIfPresent(
String.self,
forKey: .scalabilityMode)
Expand Down

0 comments on commit aeb0647

Please sign in to comment.