Skip to content

Commit

Permalink
report track stats option
Browse files Browse the repository at this point in the history
  • Loading branch information
hiroshihorie committed Nov 27, 2023
1 parent 353b12a commit 95db12f
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 44 deletions.
10 changes: 8 additions & 2 deletions Sources/LiveKit/Participant/RemoteParticipant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,15 @@ public class RemoteParticipant: Participant {

switch rtcTrack.kind {
case "audio":
track = RemoteAudioTrack(name: publication.name, source: publication.source, track: rtcTrack)
track = RemoteAudioTrack(name: publication.name,
source: publication.source,
track: rtcTrack,
reportStatistics: room._state.options.reportRemoteTrackStatistics)
case "video":
track = RemoteVideoTrack(name: publication.name, source: publication.source, track: rtcTrack)
track = RemoteVideoTrack(name: publication.name,
source: publication.source,
track: rtcTrack,
reportStatistics: room._state.options.reportRemoteTrackStatistics)
default:
let error = TrackError.type(message: "Unsupported type: \(rtcTrack.kind.description)")
delegates.notify(label: { "participant.didFailToSubscribe trackSid: \(sid)" }) {
Expand Down
14 changes: 7 additions & 7 deletions Sources/LiveKit/Track/Capturers/BufferCapturer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,15 @@ public extension LocalVideoTrack {
/// Creates a track that can directly capture `CVPixelBuffer` or `CMSampleBuffer` for convienience
static func createBufferTrack(name: String = Track.screenShareVideoName,
source: VideoTrack.Source = .screenShareVideo,
options: BufferCaptureOptions = BufferCaptureOptions()) -> LocalVideoTrack
options: BufferCaptureOptions = BufferCaptureOptions(),
reportStatistics: Bool = false) -> LocalVideoTrack
{
let videoSource = Engine.createVideoSource(forScreenShare: source == .screenShareVideo)
let capturer = BufferCapturer(delegate: videoSource, options: options)
return LocalVideoTrack(
name: name,
source: source,
capturer: capturer,
videoSource: videoSource
)
return LocalVideoTrack(name: name,
source: source,
capturer: capturer,
videoSource: videoSource,
reportStatistics: reportStatistics)
}
}
14 changes: 7 additions & 7 deletions Sources/LiveKit/Track/Capturers/CameraCapturer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -243,16 +243,16 @@ public extension LocalVideoTrack {

@objc
static func createCameraTrack(name: String? = nil,
options: CameraCaptureOptions? = nil) -> LocalVideoTrack
options: CameraCaptureOptions? = nil,
reportStatistics: Bool = false) -> LocalVideoTrack
{
let videoSource = Engine.createVideoSource(forScreenShare: false)
let capturer = CameraCapturer(delegate: videoSource, options: options ?? CameraCaptureOptions())
return LocalVideoTrack(
name: name ?? Track.cameraName,
source: .camera,
capturer: capturer,
videoSource: videoSource
)
return LocalVideoTrack(name: name ?? Track.cameraName,
source: .camera,
capturer: capturer,
videoSource: videoSource,
reportStatistics: reportStatistics)
}
}

Expand Down
14 changes: 7 additions & 7 deletions Sources/LiveKit/Track/Capturers/InAppCapturer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ public extension LocalVideoTrack {
/// Creates a track that captures in-app screen only (due to limitation of ReplayKit)
@available(macOS 11.0, iOS 11.0, *)
static func createInAppScreenShareTrack(name: String = Track.screenShareVideoName,
options: ScreenShareCaptureOptions = ScreenShareCaptureOptions()) -> LocalVideoTrack
options: ScreenShareCaptureOptions = ScreenShareCaptureOptions(),
reportStatistics: Bool = false) -> LocalVideoTrack
{
let videoSource = Engine.createVideoSource(forScreenShare: true)
let capturer = InAppScreenCapturer(delegate: videoSource, options: options)
return LocalVideoTrack(
name: name,
source: .screenShareVideo,
capturer: capturer,
videoSource: videoSource
)
return LocalVideoTrack(name: name,
source: .screenShareVideo,
capturer: capturer,
videoSource: videoSource,
reportStatistics: reportStatistics)
}
}
14 changes: 7 additions & 7 deletions Sources/LiveKit/Track/Capturers/MacOSScreenCapturer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,16 @@ import Foundation
@objc
static func createMacOSScreenShareTrack(name: String = Track.screenShareVideoName,
source: MacOSScreenCaptureSource,
options: ScreenShareCaptureOptions = ScreenShareCaptureOptions()) -> LocalVideoTrack
options: ScreenShareCaptureOptions = ScreenShareCaptureOptions(),
reportStatistics: Bool = false) -> LocalVideoTrack
{
let videoSource = Engine.createVideoSource(forScreenShare: true)
let capturer = MacOSScreenCapturer(delegate: videoSource, captureSource: source, options: options)
return LocalVideoTrack(
name: name,
source: .screenShareVideo,
capturer: capturer,
videoSource: videoSource
)
return LocalVideoTrack(name: name,
source: .screenShareVideo,
capturer: capturer,
videoSource: videoSource,
reportStatistics: reportStatistics)
}
}

Expand Down
9 changes: 6 additions & 3 deletions Sources/LiveKit/Track/Local/LocalAudioTrack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ import Foundation
public class LocalAudioTrack: Track, LocalTrack, AudioTrack {
init(name: String,
source: Track.Source,
track: LKRTCMediaStreamTrack)
track: LKRTCMediaStreamTrack,
reportStatistics: Bool)
{
super.init(name: name,
kind: .audio,
source: source,
track: track)
track: track,
reportStatistics: reportStatistics)
}

public static func createTrack(name: String = Track.microphoneName,
Expand All @@ -54,7 +56,8 @@ public class LocalAudioTrack: Track, LocalTrack, AudioTrack {

return LocalAudioTrack(name: name,
source: .microphone,
track: rtcTrack)
track: rtcTrack,
reportStatistics: true)
}

@discardableResult
Expand Down
9 changes: 6 additions & 3 deletions Sources/LiveKit/Track/Local/LocalVideoTrack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public class LocalVideoTrack: Track, LocalTrack, VideoTrack {
init(name: String,
source: Track.Source,
capturer: VideoCapturer,
videoSource: LKRTCVideoSource)
videoSource: LKRTCVideoSource,
reportStatistics: Bool)
{
let rtcTrack = Engine.createVideoTrack(source: videoSource)
rtcTrack.isEnabled = true
Expand All @@ -39,7 +40,8 @@ public class LocalVideoTrack: Track, LocalTrack, VideoTrack {
super.init(name: name,
kind: .video,
source: source,
track: rtcTrack)
track: rtcTrack,
reportStatistics: reportStatistics)
}

public func mute() async throws {
Expand Down Expand Up @@ -83,6 +85,7 @@ public extension LocalVideoTrack {
LocalVideoTrack(name: name,
source: source,
capturer: capturer,
videoSource: videoSource)
videoSource: videoSource,
reportStatistics: _state.reportStatistics)
}
}
6 changes: 4 additions & 2 deletions Sources/LiveKit/Track/Remote/RemoteAudioTrack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@ public class RemoteAudioTrack: Track, RemoteTrack, AudioTrack {

init(name: String,
source: Track.Source,
track: LKRTCMediaStreamTrack)
track: LKRTCMediaStreamTrack,
reportStatistics: Bool)
{
super.init(name: name,
kind: .audio,
source: source,
track: track)
track: track,
reportStatistics: reportStatistics)
}

public func add(audioRenderer: AudioRenderer) {
Expand Down
6 changes: 4 additions & 2 deletions Sources/LiveKit/Track/Remote/RemoteVideoTrack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ import Foundation
public class RemoteVideoTrack: Track, RemoteTrack, VideoTrack {
init(name: String,
source: Track.Source,
track: LKRTCMediaStreamTrack)
track: LKRTCMediaStreamTrack,
reportStatistics: Bool)
{
super.init(name: name,
kind: .video,
source: source,
track: track)
track: track,
reportStatistics: reportStatistics)
}
}

Expand Down
8 changes: 6 additions & 2 deletions Sources/LiveKit/Track/Track.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,14 @@ public class Track: NSObject, Loggable {
init(name: String,
kind: Kind,
source: Source,
track: LKRTCMediaStreamTrack)
track: LKRTCMediaStreamTrack,
reportStatistics: Bool)
{
_state = StateSync(State(
name: name,
kind: kind,
source: source
source: source,
reportStatistics: reportStatistics
))

mediaTrack = track
Expand Down Expand Up @@ -173,6 +175,8 @@ public class Track: NSObject, Loggable {
statisticsTimer.handler = { [weak self] in
self?.onStatsTimer()
}

resumeOrSuspendStatisticsTimer()
}

deinit {
Expand Down
11 changes: 9 additions & 2 deletions Sources/LiveKit/Types/Options/RoomOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ public class RoomOptions: NSObject {
/// E2EE Options
public let e2eeOptions: E2EEOptions?

@objc
public let reportRemoteTrackStatistics: Bool

public init(defaultCameraCaptureOptions: CameraCaptureOptions = CameraCaptureOptions(),
defaultScreenShareCaptureOptions: ScreenShareCaptureOptions = ScreenShareCaptureOptions(),
defaultAudioCaptureOptions: AudioCaptureOptions = AudioCaptureOptions(),
Expand All @@ -76,7 +79,8 @@ public class RoomOptions: NSObject {
dynacast: Bool = false,
stopLocalTrackOnUnpublish: Bool = true,
suspendLocalVideoTracksInBackground: Bool = true,
e2eeOptions: E2EEOptions? = nil)
e2eeOptions: E2EEOptions? = nil,
reportTrackStatistics: Bool = false)
{
self.defaultCameraCaptureOptions = defaultCameraCaptureOptions
self.defaultScreenShareCaptureOptions = defaultScreenShareCaptureOptions
Expand All @@ -89,6 +93,7 @@ public class RoomOptions: NSObject {
self.stopLocalTrackOnUnpublish = stopLocalTrackOnUnpublish
self.suspendLocalVideoTracksInBackground = suspendLocalVideoTracksInBackground
self.e2eeOptions = e2eeOptions
reportRemoteTrackStatistics = reportTrackStatistics
}

// MARK: - Equal
Expand All @@ -104,7 +109,8 @@ public class RoomOptions: NSObject {
adaptiveStream == other.adaptiveStream &&
dynacast == other.dynacast &&
stopLocalTrackOnUnpublish == other.stopLocalTrackOnUnpublish &&
suspendLocalVideoTracksInBackground == other.suspendLocalVideoTracksInBackground
suspendLocalVideoTracksInBackground == other.suspendLocalVideoTracksInBackground &&
reportRemoteTrackStatistics == other.reportRemoteTrackStatistics
}

override public var hash: Int {
Expand All @@ -119,6 +125,7 @@ public class RoomOptions: NSObject {
hasher.combine(dynacast)
hasher.combine(stopLocalTrackOnUnpublish)
hasher.combine(suspendLocalVideoTracksInBackground)
hasher.combine(reportRemoteTrackStatistics)
return hasher.finalize()
}
}

0 comments on commit 95db12f

Please sign in to comment.