Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/fork/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
ladvoc committed Jan 16, 2025
2 parents 79627e7 + ae86a91 commit aa83fd1
Show file tree
Hide file tree
Showing 195 changed files with 355 additions and 235 deletions.
2 changes: 1 addition & 1 deletion Sources/LiveKit/Broadcast/BroadcastScreenCapturer.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Broadcast/Uploader/Atomic.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Broadcast/Uploader/LKSampleHandler.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
47 changes: 34 additions & 13 deletions Sources/LiveKit/Broadcast/Uploader/SampleUploader.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,6 +28,7 @@ private enum Constants {

class SampleUploader {
private static var imageContext = CIContext(options: nil)
private static var colorSpace = CGColorSpaceCreateDeviceRGB()

@Atomic private var isReady = false
private var connection: BroadcastUploadSocketConnection
Expand All @@ -37,6 +38,9 @@ class SampleUploader {

private let serialQueue: DispatchQueue

// Configure desired compression quality (0.0 = max compression, 1.0 = least compression)
public let compressionQuality: CGFloat = 1.0

init(connection: BroadcastUploadSocketConnection) {
self.connection = connection
serialQueue = DispatchQueue(label: "io.livekit.broadcast.sampleUploader")
Expand Down Expand Up @@ -115,14 +119,12 @@ private extension SampleUploader {

CVPixelBufferLockBaseAddress(imageBuffer, .readOnly)

let scaleFactor = 1.0
let width = CVPixelBufferGetWidth(imageBuffer) / Int(scaleFactor)
let height = CVPixelBufferGetHeight(imageBuffer) / Int(scaleFactor)
let width = CVPixelBufferGetWidth(imageBuffer)
let height = CVPixelBufferGetHeight(imageBuffer)

let orientation = CMGetAttachment(buffer, key: RPVideoSampleOrientationKey as CFString, attachmentModeOut: nil)?.uintValue ?? 0

let scaleTransform = CGAffineTransform(scaleX: CGFloat(1.0 / scaleFactor), y: CGFloat(1.0 / scaleFactor))
let bufferData = jpegData(from: imageBuffer, scale: scaleTransform)
let bufferData = jpegData(from: imageBuffer)

CVPixelBufferUnlockBaseAddress(imageBuffer, .readOnly)

Expand All @@ -144,16 +146,35 @@ private extension SampleUploader {
return serializedMessage
}

func jpegData(from buffer: CVPixelBuffer, scale scaleTransform: CGAffineTransform) -> Data? {
let image = CIImage(cvPixelBuffer: buffer).transformed(by: scaleTransform)
func jpegData(from buffer: CVPixelBuffer) -> Data? {
let image = CIImage(cvPixelBuffer: buffer)

guard let colorSpace = image.colorSpace else {
return nil
}
if #available(iOS 17.0, *) {
return Self.imageContext.jpegRepresentation(
of: image,
colorSpace: Self.colorSpace,
options: [kCGImageDestinationLossyCompressionQuality as CIImageRepresentationOption: compressionQuality]
)
} else {
// Workaround for "unsupported file format 'public.heic'"
guard let cgImage = Self.imageContext.createCGImage(image, from: image.extent) else {
return nil
}

let options: [CIImageRepresentationOption: Float] = [kCGImageDestinationLossyCompressionQuality as CIImageRepresentationOption: 1.0]
let data = NSMutableData()
guard let imageDestination = CGImageDestinationCreateWithData(data, AVFileType.jpg as CFString, 1, nil) else {
return nil
}

let options: [CFString: Any] = [kCGImageDestinationLossyCompressionQuality: compressionQuality]
CGImageDestinationAddImage(imageDestination, cgImage, options as CFDictionary)

return SampleUploader.imageContext.jpegRepresentation(of: image, colorSpace: colorSpace, options: options)
guard CGImageDestinationFinalize(imageDestination) else {
return nil
}

return data as Data
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Convenience/AudioProcessing.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Core/DataChannelPair.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Core/RTC.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Core/Room+Convenience.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Core/Room+Debug.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Core/Room+Engine.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Core/Room+EngineDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Core/Room+MulticastDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
10 changes: 7 additions & 3 deletions Sources/LiveKit/Core/Room+SignalClientDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -103,9 +103,14 @@ extension Room: SignalClientDelegate {
_state.mutate {
$0.sid = Room.Sid(from: joinResponse.room.sid)
$0.name = joinResponse.room.name
$0.serverInfo = joinResponse.serverInfo
$0.creationTime = Date(timeIntervalSince1970: TimeInterval(joinResponse.room.creationTime))
$0.maxParticipants = Int(joinResponse.room.maxParticipants)

$0.metadata = joinResponse.room.metadata
$0.isRecording = joinResponse.room.activeRecording
$0.serverInfo = joinResponse.serverInfo
$0.numParticipants = Int(joinResponse.room.numParticipants)
$0.numPublishers = Int(joinResponse.room.numPublishers)

localParticipant.set(info: joinResponse.participant, connectionState: $0.connectionState)

Expand All @@ -122,7 +127,6 @@ extension Room: SignalClientDelegate {
_state.mutate {
$0.metadata = room.metadata
$0.isRecording = room.activeRecording
$0.maxParticipants = Int(room.maxParticipants)
$0.numParticipants = Int(room.numParticipants)
$0.numPublishers = Int(room.numPublishers)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Core/Room+TransportDelegate.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
6 changes: 5 additions & 1 deletion Sources/LiveKit/Core/Room.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -62,6 +62,9 @@ public class Room: NSObject, ObservableObject, Loggable {
@objc
public var activeSpeakers: [Participant] { _state.activeSpeakers }

@objc
public var creationTime: Date? { _state.creationTime }

/// If the current room has a participant with `recorder:true` in its JWT grant.
@objc
public var isRecording: Bool { _state.isRecording }
Expand Down Expand Up @@ -125,6 +128,7 @@ public class Room: NSObject, ObservableObject, Loggable {
var remoteParticipants = [Participant.Identity: RemoteParticipant]()
var activeSpeakers = [Participant]()

var creationTime: Date?
var isRecording: Bool = false

var maxParticipants: Int = 0
Expand Down
5 changes: 2 additions & 3 deletions Sources/LiveKit/Core/SignalClient.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -139,7 +139,7 @@ actor SignalClient: Loggable {
connectionState = (reconnectMode != nil ? .reconnecting : .connecting)

do {
let socket = try await WebSocket(url: url)
let socket = try await WebSocket(url: url, connectOptions: connectOptions)

_messageLoopTask = Task.detached {
self.log("Did enter WebSocket message loop...")
Expand Down Expand Up @@ -271,7 +271,6 @@ private extension SignalClient {
_lastJoinResponse = joinResponse
_delegate.notifyDetached { await $0.signalClient(self, didReceiveConnectResponse: .join(joinResponse)) }
_connectResponseCompleter.resume(returning: .join(joinResponse))
print("creationTime: \(joinResponse.room.creationTime)")
await _restartPingTimer()

case let .reconnect(response):
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Core/Transport.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/E2EE/E2EEManager.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/E2EE/KeyProvider.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/E2EE/Options.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/E2EE/State.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Errors.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Extensions/AVAudioPCMBuffer.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Extensions/AVCaptureDevice.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Extensions/CustomStringConvertible.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Extensions/DispatchQueue.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Extensions/LKRTCRtpSender.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Extensions/Logger.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Extensions/PixelBuffer.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Extensions/Primitives.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Extensions/RTCConfiguration.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Extensions/RTCDataChannel+Util.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion Sources/LiveKit/Extensions/RTCI420Buffer.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 LiveKit
* Copyright 2025 LiveKit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit aa83fd1

Please sign in to comment.