Skip to content

Commit

Permalink
Handle mediaServicesWereReset notification with lock queue
Browse files Browse the repository at this point in the history
  • Loading branch information
levs42 committed Aug 6, 2024
1 parent 130e6f3 commit cfa815a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
8 changes: 0 additions & 8 deletions Sources/IO/IOCaptureSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,6 @@ final class IOCaptureSession {
return
}
let error = AVError(_nsError: errorValue)
switch error.code {
#if os(iOS) || os(tvOS)
case .mediaServicesWereReset:
startRunningIfNeeded()
#endif
default:
break
}
delegate?.captureSession(self, sessionRuntimeError: session, error: error)
}

Expand Down
12 changes: 12 additions & 0 deletions Sources/IO/IOMixer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ protocol IOMixerDelegate: AnyObject {
@available(tvOS 17.0, *)
func mixer(_ mixer: IOMixer, sessionInterruptionEnded session: AVCaptureSession)
#endif
#if os(iOS) || os(tvOS)
@available(tvOS 17.0, *)
func mixer(_ mixer: IOMixer, mediaServicesWereReset error: AVError)
#endif
}

/// An object that mixies audio and video for streaming.
Expand Down Expand Up @@ -164,6 +168,14 @@ extension IOMixer: IOCaptureSessionDelegate {
break
}
#endif
switch error.code {
#if os(iOS) || os(tvOS)
case .mediaServicesWereReset:
delegate?.mixer(self, mediaServicesWereReset: error)
#endif
default:
break
}
}

#if os(iOS) || os(tvOS) || os(visionOS)
Expand Down
14 changes: 13 additions & 1 deletion Sources/IO/IOStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,9 @@ open class IOStream: NSObject {
/// Configurations for the AVCaptureSession.
@available(tvOS 17.0, *)
public func configuration(_ lambda: (_ session: AVCaptureSession) throws -> Void) rethrows {
try mixer.session.configuration(lambda)
try lockQueue.sync {
try mixer.session.configuration(lambda)
}
}

/// A handler that receives stream readyState will update.
Expand Down Expand Up @@ -519,6 +521,16 @@ extension IOStream: IOMixerDelegate {
delegate?.stream(self, sessionInterruptionEnded: session)
}
#endif

#if os(iOS) || os(tvOS)
@available(tvOS 17.0, *)
func mixer(_ mixer: IOMixer, mediaServicesWereReset error: AVError) {
lockQueue.async {
self.mixer.session.startRunningIfNeeded()
}
}
#endif

}

extension IOStream: IOTellyUnitDelegate {
Expand Down

0 comments on commit cfa815a

Please sign in to comment.