-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for `VP9`, `AV1`, `VP8`, `H264` codecs. v2 compatible version of #176
- Loading branch information
1 parent
d4044d9
commit bb81f19
Showing
21 changed files
with
599 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright 2023 LiveKit | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import Foundation | ||
|
||
@_implementationOnly import WebRTC | ||
|
||
extension LKRTCRtpSender: Loggable { | ||
// ... | ||
func _set(subscribedQualities qualities: [Livekit_SubscribedQuality]) { | ||
let _parameters = parameters | ||
let encodings = _parameters.encodings | ||
|
||
var didUpdate = false | ||
|
||
// For SVC mode... | ||
if let firstEncoding = encodings.first, | ||
let _ = ScalabilityMode.fromString(firstEncoding.scalabilityMode) | ||
{ | ||
let _enabled = qualities.highest != .off | ||
if firstEncoding.isActive != _enabled { | ||
firstEncoding.isActive = _enabled | ||
didUpdate = true | ||
} | ||
} else { | ||
// For Simulcast... | ||
for e in qualities { | ||
guard let rid = e.quality.asRID else { continue } | ||
guard let encodingforRID = encodings.first(where: { $0.rid == rid }) else { continue } | ||
|
||
if encodingforRID.isActive != e.enabled { | ||
didUpdate = true | ||
encodingforRID.isActive = e.enabled | ||
log("Setting layer \(e.quality) to \(e.enabled)", .info) | ||
} | ||
} | ||
|
||
// Non simulcast streams don't have RIDs, handle here. | ||
if encodings.count == 1, qualities.count >= 1 { | ||
let firstEncoding = encodings.first! | ||
let firstQuality = qualities.first! | ||
|
||
if firstEncoding.isActive != firstQuality.enabled { | ||
didUpdate = true | ||
firstEncoding.isActive = firstQuality.enabled | ||
log("Setting layer \(firstQuality.quality) to \(firstQuality.enabled)", .info) | ||
} | ||
} | ||
} | ||
|
||
if didUpdate { | ||
parameters = _parameters | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2023 LiveKit | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import Foundation | ||
|
||
@_implementationOnly import WebRTC | ||
|
||
extension LKRTCRtpTransceiver: Loggable { | ||
/// Attempts to set preferred video codec. | ||
func set(preferredVideoCodec codec: VideoCodec, exceptCodec: VideoCodec? = nil) { | ||
// Get list of supported codecs... | ||
let allVideoCodecs = Engine.videoSenderCapabilities.codecs | ||
|
||
// Get the RTCRtpCodecCapability of the preferred codec | ||
let preferredCodecCapability = allVideoCodecs.first { $0.name.lowercased() == codec.id } | ||
|
||
// Get list of capabilities other than the preferred one | ||
let otherCapabilities = allVideoCodecs.filter { | ||
$0.name.lowercased() != codec.id && $0.name.lowercased() != exceptCodec?.id | ||
} | ||
|
||
// Bring preferredCodecCapability to the front and combine all capabilities | ||
let combinedCapabilities = [preferredCodecCapability] + otherCapabilities | ||
|
||
// Codecs not set in codecPreferences will not be negotiated in the offer | ||
codecPreferences = combinedCapabilities.compactMap { $0 } | ||
|
||
log("codecPreferences set: \(codecPreferences.map { String(describing: $0) }.joined(separator: ", "))") | ||
|
||
assert(codecPreferences.first?.name.lowercased() == codec.id, "Preferred codec is not first in the list") | ||
} | ||
} |
Oops, something went wrong.