@@ -94,7 +94,7 @@ public class StreamBridge: NSObject, AVPictureInPictureSampleBufferPlaybackDeleg
9494
9595 var isCancel = false
9696 let semaphore = DispatchSemaphore ( value: 1 )
97- var param : UnsafeMutableRawPointer !
97+ var param : UnsafeMutableRawPointer ?
9898
9999 var nameCStr : [ CChar ] ? = nil
100100 var userBreak = false
@@ -523,7 +523,9 @@ public class StreamBridge: NSObject, AVPictureInPictureSampleBufferPlaybackDeleg
523523 public func onStop( ) {
524524 isCancel = true
525525 stream? . isLive = false
526- run_quit ( param)
526+ if let param {
527+ run_quit ( param)
528+ }
527529 sound? . stop ( )
528530 stream = nil
529531 }
@@ -532,7 +534,9 @@ public class StreamBridge: NSObject, AVPictureInPictureSampleBufferPlaybackDeleg
532534 userBreak = interactive
533535 isCancel = true
534536 stream? . isLive = false
535- run_quit ( param)
537+ if let param {
538+ run_quit ( param)
539+ }
536540 sound? . stop ( )
537541 stream = nil
538542 pipController = nil
@@ -541,19 +545,27 @@ public class StreamBridge: NSObject, AVPictureInPictureSampleBufferPlaybackDeleg
541545
542546 public func onSeek( _ pos: Double ) {
543547 let pos64 : Int64 = Int64 ( pos * 1000000 )
544- run_seek ( param, pos64)
548+ if let param {
549+ run_seek ( param, pos64)
550+ }
545551 }
546552
547553 public func onSeekChapter( _ inc: Int ) {
548- run_seek_chapter ( param, Int32 ( inc) )
554+ if let param {
555+ run_seek_chapter ( param, Int32 ( inc) )
556+ }
549557 }
550558
551559 public func onPause( _ state: Bool ) async {
552- run_pause ( param, state ? 1 : 0 )
560+ if let param {
561+ run_pause ( param, state ? 1 : 0 )
562+ }
553563 }
554564
555565 public func onCycleCh( _ tag: Int ) {
556- run_cycle_ch ( param, Int32 ( tag) )
566+ if let param {
567+ run_cycle_ch ( param, Int32 ( tag) )
568+ }
557569 }
558570
559571 public func run( ) async -> Bool {
@@ -639,28 +651,28 @@ public class StreamBridge: NSObject, AVPictureInPictureSampleBufferPlaybackDeleg
639651 nameCStr. withUnsafeMutableBufferPointer { itemname in
640652 let latency = AVAudioSession . sharedInstance ( ) . outputLatency
641653 print ( latency)
642- self . param = make_arg (
654+ param = make_arg (
643655 itemname. baseAddress,
644656 latency,
645657 partial_start,
646658 start_skip,
647659 stop_limit,
648660 aribText ? 1 : 0 ,
649- self . selfref,
650- self . read_packet,
651- self . seek,
652- self . cancel,
653- self . draw_pict,
654- self . setDuration,
655- self . setSoundOnly,
656- self . sound_play,
657- self . sound_stop,
658- self . wait_stop,
659- self . wait_start,
660- self . send_pause,
661- self . skip_media,
662- self . cc_draw,
663- self . change_lang)
661+ selfref,
662+ read_packet,
663+ seek,
664+ cancel,
665+ draw_pict,
666+ setDuration,
667+ setSoundOnly,
668+ sound_play,
669+ sound_stop,
670+ wait_stop,
671+ wait_start,
672+ send_pause,
673+ skip_media,
674+ cc_draw,
675+ change_lang)
664676
665677 Task {
666678 do {
@@ -670,15 +682,16 @@ public class StreamBridge: NSObject, AVPictureInPictureSampleBufferPlaybackDeleg
670682 }
671683
672684 initDoneSender. send ( true )
673- run_play ( self . param)
674- self . sound? . play ( )
685+ run_play ( param! )
686+ sound? . play ( )
675687 let task = Task {
676688 while true {
677689 try await Task . sleep ( for: . seconds( 1 ) )
678690 updateMediaInfo ( )
679691 }
680692 }
681- var ret = Int ( run_finish ( self . param) )
693+ var ret = Int ( run_finish ( param!) )
694+ param = nil
682695 if userBreak {
683696 ret = 1
684697 }
@@ -758,15 +771,21 @@ public class StreamBridge: NSObject, AVPictureInPictureSampleBufferPlaybackDeleg
758771 case . newDeviceAvailable:
759772 let latency = AVAudioSession . sharedInstance ( ) . outputLatency
760773 print ( latency)
761- set_latency ( param, latency)
774+ if let param {
775+ set_latency ( param, latency)
776+ }
762777 break
763778 case . oldDeviceUnavailable:
764779 if audioSessionPortDescription? . portType == . headphones || audioSessionPortDescription? . portType == . bluetoothA2DP {
765- run_pause ( param, 1 )
780+ if let param {
781+ run_pause ( param, 1 )
782+ }
766783 }
767784 let latency = AVAudioSession . sharedInstance ( ) . outputLatency
768785 print ( latency)
769- set_latency ( param, latency)
786+ if let param {
787+ set_latency ( param, latency)
788+ }
770789 break
771790 default :
772791 break
@@ -788,15 +807,19 @@ public class StreamBridge: NSObject, AVPictureInPictureSampleBufferPlaybackDeleg
788807 let wasSuspendedKey = wasSuspendedKeyValue. boolValue
789808 print ( wasSuspendedKey)
790809 if !wasSuspendedKey {
791- run_pause ( param, 1 )
810+ if let param {
811+ run_pause ( param, 1 )
812+ }
792813 }
793814 case . ended:
794815 guard let optionsValue = userInfo [ AVAudioSessionInterruptionOptionKey] as? UInt else {
795816 break
796817 }
797818 let options = AVAudioSession . InterruptionOptions ( rawValue: optionsValue)
798819 if options. contains ( . shouldResume) {
799- run_pause ( param, 0 )
820+ if let param {
821+ run_pause ( param, 0 )
822+ }
800823 }
801824 default :
802825 break
@@ -814,7 +837,9 @@ public class StreamBridge: NSObject, AVPictureInPictureSampleBufferPlaybackDeleg
814837 commandCenter. togglePlayPauseCommand. addTarget { [ weak self] event in
815838 guard let self = self else { return . commandFailed}
816839 Task {
817- run_pause ( self . param, self . pause ? 0 : 1 )
840+ if let param = self . param {
841+ run_pause ( param, self . pause ? 0 : 1 )
842+ }
818843 let t = self . soundPTS. isNaN ? self . videoPTS : self . soundPTS
819844 self . playPos = t
820845 }
@@ -827,7 +852,9 @@ public class StreamBridge: NSObject, AVPictureInPictureSampleBufferPlaybackDeleg
827852 return . commandFailed
828853 }
829854 Task {
830- run_pause ( self . param, 1 )
855+ if let param = self . param {
856+ run_pause ( param, 1 )
857+ }
831858 let t = self . soundPTS. isNaN ? self . videoPTS : self . soundPTS
832859 self . playPos = t
833860 }
@@ -840,7 +867,9 @@ public class StreamBridge: NSObject, AVPictureInPictureSampleBufferPlaybackDeleg
840867 return . commandFailed
841868 }
842869 Task {
843- run_pause ( self . param, 0 )
870+ if let param = self . param {
871+ run_pause ( param, 0 )
872+ }
844873 let t = self . soundPTS. isNaN ? self . videoPTS : self . soundPTS
845874 self . playPos = t
846875 }
@@ -856,14 +885,18 @@ public class StreamBridge: NSObject, AVPictureInPictureSampleBufferPlaybackDeleg
856885 var pos = self . soundPTS. isNaN ? self . videoPTS : self . soundPTS
857886 pos += Double ( truncating: interval)
858887 let pos64 : Int64 = Int64 ( pos * 1000000 )
859- run_seek ( self . param, pos64)
888+ if let param = self . param {
889+ run_seek ( param, pos64)
890+ }
860891 return . success
861892 }
862893 commandCenter. skipForwardCommand. preferredIntervals = [ NSNumber ( value: skip_nextsec) ]
863894
864895 commandCenter. nextTrackCommand. addTarget { [ weak self] event in
865896 guard let self = self else { return . commandFailed}
866- run_seek_chapter ( self . param, Int32 ( 1 ) )
897+ if let param = self . param {
898+ run_seek_chapter ( param, Int32 ( 1 ) )
899+ }
867900 return . success
868901 }
869902
@@ -876,14 +909,18 @@ public class StreamBridge: NSObject, AVPictureInPictureSampleBufferPlaybackDeleg
876909 var pos = self . soundPTS. isNaN ? self . videoPTS : self . soundPTS
877910 pos -= Double ( truncating: interval)
878911 let pos64 : Int64 = Int64 ( pos * 1000000 )
879- run_seek ( self . param, pos64)
912+ if let param = self . param {
913+ run_seek ( param, pos64)
914+ }
880915 return . success
881916 }
882917 commandCenter. skipBackwardCommand. preferredIntervals = [ NSNumber ( value: skip_prevsec) ]
883918
884919 commandCenter. previousTrackCommand. addTarget { [ weak self] event in
885920 guard let self = self else { return . commandFailed}
886- run_seek_chapter ( self . param, Int32 ( - 1 ) )
921+ if let param = self . param {
922+ run_seek_chapter ( param, Int32 ( - 1 ) )
923+ }
887924 return . success
888925 }
889926
@@ -892,7 +929,9 @@ public class StreamBridge: NSObject, AVPictureInPictureSampleBufferPlaybackDeleg
892929 if let event = remoteEvent as? MPChangePlaybackPositionCommandEvent {
893930 let pos = event. positionTime
894931 let pos64 : Int64 = Int64 ( pos * 1000000 )
895- run_seek ( self . param, pos64)
932+ if let param = self . param {
933+ run_seek ( param, pos64)
934+ }
896935 return . success
897936 }
898937 return . commandFailed
@@ -950,9 +989,13 @@ public class StreamBridge: NSObject, AVPictureInPictureSampleBufferPlaybackDeleg
950989
951990 public func pictureInPictureController( _ pictureInPictureController: AVPictureInPictureController , skipByInterval skipInterval: CMTime ) async {
952991 Task {
953- run_pause ( param, 1 )
992+ if let param {
993+ run_pause ( param, 1 )
994+ }
954995 onSeek ( playPos + skipInterval. seconds)
955- run_pause ( param, 0 )
996+ if let param {
997+ run_pause ( param, 0 )
998+ }
956999 }
9571000 }
9581001
0 commit comments