Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Sources/LumeEngine/LumePlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ public final class LumePlayer {
/// layer tree directly (UIKit/AppKit).
public var displayLayer: LumeDisplayLayer? { session?.renderer.displayLayer }

/// The current session's colour sampler (see `VideoSampleTap`); nil with
/// nothing loaded. Each `load` starts a new one, enabled only when the
/// configuration's `videoSampling` is set.
public var videoSamples: VideoSampleTap? { session?.renderer.videoSamples }

/// The sample of the frame on screen now; nil while sampling is off.
/// Main actor — prefer `videoSamples` for anything per frame.
public var currentVideoSample: VideoSampleTap.Sample? { session?.currentVideoSample() }

/// tvOS: switch the TV to each loaded stream's refresh rate and dynamic
/// range (Match Content) while it plays in a `LumePlayerView`, which
/// supplies the window; `stop()` and the view going away hand the display
Expand Down
20 changes: 19 additions & 1 deletion Sources/LumeEngineCore/Render/SystemRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,23 @@ public final class SystemRenderer: @unchecked Sendable {
/// (see `pumpAudio`); nil feeds every frame.
private let audioOutputRoute: AudioOutputRoute?

public init(muted: Bool = false, audioOutputRoute: AudioOutputRoute? = nil) {
/// Colour readings of the frames handed to the display, off unless
/// enabled (see `VideoSampleTap`). Read
/// `videoSamples.sample(atOrBefore: currentTime)` for what is on screen.
public let videoSamples: VideoSampleTap

/// - Parameter videoSampling: starts `videoSamples` enabled with this
/// grid; nil leaves it off (it can still be enabled at runtime).
public init(
muted: Bool = false,
audioOutputRoute: AudioOutputRoute? = nil,
videoSampling: VideoSampleTap.Configuration? = nil
) {
self.audioOutputRoute = audioOutputRoute
videoSamples = VideoSampleTap(
configuration: videoSampling ?? VideoSampleTap.Configuration(),
enabled: videoSampling != nil
)
displayLayer = AVSampleBufferDisplayLayer()
displayLayer.videoGravity = .resizeAspect
videoRenderer = displayLayer.sampleBufferRenderer
Expand Down Expand Up @@ -335,6 +350,7 @@ public final class SystemRenderer: @unchecked Sendable {
videoCadence.restart()
lock.unlock()

videoSamples.flush(acceptingSerial: serial)
videoRenderer.flush()
audioRenderer.flush()
}
Expand Down Expand Up @@ -408,6 +424,7 @@ public final class SystemRenderer: @unchecked Sendable {
synchronizer.setRate(0, time: .zero)
videoRenderer.flush()
audioRenderer.flush()
videoSamples.flush()
}

// MARK: Pumps (render queues)
Expand All @@ -432,6 +449,7 @@ public final class SystemRenderer: @unchecked Sendable {
do {
let sample = try SampleBufferBuilder.video(from: frame, formatCache: &videoFormatCache)
videoRenderer.enqueue(sample)
videoSamples.offer(frame)
lock.lock()
lastEnqueuedVideoPTS = frame.pts
if !MediaTime.isValid(firstEnqueuedVideoPTS) { firstEnqueuedVideoPTS = frame.pts }
Expand Down
Loading
Loading