From dbeec845e62f01808bcdffe00ee96a5e9eef5792 Mon Sep 17 00:00:00 2001 From: shogo4405 Date: Mon, 7 Oct 2024 01:35:53 +0900 Subject: [PATCH] make the bufferTime public. --- Examples/iOS/IngestViewController.swift | 4 ++-- Examples/iOSSwiftUI/Model/ViewModel.swift | 4 ++-- Sources/IO/IOStream.swift | 10 ++++++++++ Sources/IO/IOTellyUnit.swift | 9 +++++++++ Sources/IO/MediaLink.swift | 1 - Sources/RTMP/RTMPConnection.swift | 2 +- Sources/RTMP/RTMPMuxer.swift | 2 +- 7 files changed, 25 insertions(+), 7 deletions(-) diff --git a/Examples/iOS/IngestViewController.swift b/Examples/iOS/IngestViewController.swift index de8f77706..3318dc4ec 100644 --- a/Examples/iOS/IngestViewController.swift +++ b/Examples/iOS/IngestViewController.swift @@ -302,9 +302,9 @@ extension IngestViewController: IOStreamRecorderDelegate { } func recorder(_ recorder: IOStreamRecorder, finishWriting writer: AVAssetWriter) { - PHPhotoLibrary.shared().performChanges({() -> Void in + PHPhotoLibrary.shared().performChanges({() in PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: writer.outputURL) - }, completionHandler: { _, error -> Void in + }, completionHandler: { _, error in do { try FileManager.default.removeItem(at: writer.outputURL) } catch { diff --git a/Examples/iOSSwiftUI/Model/ViewModel.swift b/Examples/iOSSwiftUI/Model/ViewModel.swift index 8b368eac4..7925de856 100644 --- a/Examples/iOSSwiftUI/Model/ViewModel.swift +++ b/Examples/iOSSwiftUI/Model/ViewModel.swift @@ -241,9 +241,9 @@ extension ViewModel: IOStreamRecorderDelegate { } func recorder(_ recorder: IOStreamRecorder, finishWriting writer: AVAssetWriter) { - PHPhotoLibrary.shared().performChanges({() -> Void in + PHPhotoLibrary.shared().performChanges({() in PHAssetChangeRequest.creationRequestForAssetFromVideo(atFileURL: writer.outputURL) - }, completionHandler: { _, error -> Void in + }, completionHandler: { _, error in do { try FileManager.default.removeItem(at: writer.outputURL) } catch { diff --git a/Sources/IO/IOStream.swift b/Sources/IO/IOStream.swift index 5f1c46791..c03621318 100644 --- a/Sources/IO/IOStream.swift +++ b/Sources/IO/IOStream.swift @@ -93,6 +93,16 @@ open class IOStream: NSObject { return mixer.videoIO.screen } + /// Specifies the buffer time before starting to display the stream. + public var bufferTime: Double { + get { + telly.bufferTime + } + set { + telly.bufferTime = newValue + } + } + /// Specifies the adaptibe bitrate strategy. public var bitrateStrategy: any IOStreamBitRateStrategyConvertible = IOStreamBitRateStrategy() { didSet { diff --git a/Sources/IO/IOTellyUnit.swift b/Sources/IO/IOTellyUnit.swift index 0f51fb1b9..cbcedf6fa 100644 --- a/Sources/IO/IOTellyUnit.swift +++ b/Sources/IO/IOTellyUnit.swift @@ -10,6 +10,15 @@ protocol IOTellyUnitDelegate: AnyObject { final class IOTellyUnit { var isRunning: Atomic = .init(false) + var bufferTime: Double { + get { + mediaLink.bufferTime + } + set { + mediaLink.bufferTime = newValue + } + } + var audioFormat: AVAudioFormat? { didSet { delegate?.tellyUnit(self, didSetAudioFormat: audioFormat) diff --git a/Sources/IO/MediaLink.swift b/Sources/IO/MediaLink.swift index 441e6f7b0..5af4bcabd 100644 --- a/Sources/IO/MediaLink.swift +++ b/Sources/IO/MediaLink.swift @@ -70,7 +70,6 @@ final class MediaLink { if isBuffering { bufferingTime = bufferQueue?.duration.seconds ?? 0 if bufferTime <= bufferingTime { - bufferTime += 0.1 isBuffering = false } } diff --git a/Sources/RTMP/RTMPConnection.swift b/Sources/RTMP/RTMPConnection.swift index 43bd90715..270287846 100644 --- a/Sources/RTMP/RTMPConnection.swift +++ b/Sources/RTMP/RTMPConnection.swift @@ -350,7 +350,7 @@ public class RTMPConnection { call("releaseStream", responder: nil, arguments: fcPublishName) call("FCPublish", responder: nil, arguments: fcPublishName) } - let responder = RTMPResponder(result: { data -> Void in + let responder = RTMPResponder(result: { data in guard let id = data[0] as? Double else { return } diff --git a/Sources/RTMP/RTMPMuxer.swift b/Sources/RTMP/RTMPMuxer.swift index 2374bd7cb..1de36c3ad 100644 --- a/Sources/RTMP/RTMPMuxer.swift +++ b/Sources/RTMP/RTMPMuxer.swift @@ -94,7 +94,7 @@ final class RTMPMuxer { if audioFormat == nil { audioFormat = message.makeAudioFormat() } - payload.withUnsafeBytes { (buffer: UnsafeRawBufferPointer) -> Void in + payload.withUnsafeBytes { (buffer: UnsafeRawBufferPointer) in guard let baseAddress = buffer.baseAddress, let audioBuffer else { return }