Skip to content

Commit ad2357b

Browse files
authored
Transceiver leak (only for video tracks) (#775)
Resolves #420 This time restricting to video tracks (where it really matters), due to reproducible crashes in the audio stack.
1 parent c23bf05 commit ad2357b

4 files changed

Lines changed: 16 additions & 2 deletions

File tree

.changes/transceiver-refix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
patch type="fixed" "Restrict transceiver memory leak fix to video tracks"

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ let package = Package(
1919
],
2020
dependencies: [
2121
// LK-Prefixed Dynamic WebRTC XCFramework
22-
.package(url: "https://github.com/livekit/webrtc-xcframework.git", exact: "137.7151.04"),
22+
.package(url: "https://github.com/livekit/webrtc-xcframework.git", exact: "137.7151.05"),
2323
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.29.0"),
2424
.package(url: "https://github.com/apple/swift-log.git", from: "1.6.2"),
2525
.package(url: "https://github.com/apple/swift-collections.git", from: "1.1.0"),

Package@swift-6.0.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let package = Package(
2020
],
2121
dependencies: [
2222
// LK-Prefixed Dynamic WebRTC XCFramework
23-
.package(url: "https://github.com/livekit/webrtc-xcframework.git", exact: "137.7151.04"),
23+
.package(url: "https://github.com/livekit/webrtc-xcframework.git", exact: "137.7151.05"),
2424
.package(url: "https://github.com/apple/swift-protobuf.git", from: "1.29.0"),
2525
.package(url: "https://github.com/apple/swift-log.git", from: "1.6.2"),
2626
.package(url: "https://github.com/apple/swift-collections.git", from: "1.1.0"),

Sources/LiveKit/Core/Transport.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,19 @@ extension Transport {
326326
guard _pc.removeTrack(sender) else {
327327
throw LiveKitError(.webRTC, message: "Failed to remove track")
328328
}
329+
330+
releaseTransceiver(sender: sender)
331+
}
332+
333+
// Try to stop the transceiver and free the resources
334+
// Workaround: https://groups.google.com/g/discuss-webrtc/c/WDsGuVucBjQ?pli=1
335+
private func releaseTransceiver(sender: LKRTCRtpSender) {
336+
if let transceiver = _pc.transceivers.first(where: { $0.sender == sender }),
337+
transceiver.mediaType == .video, !transceiver.isStopped
338+
{
339+
log("Stopping video transceiver", .debug)
340+
transceiver.stopInternal()
341+
}
329342
}
330343

331344
func dataChannel(for label: String,

0 commit comments

Comments
 (0)