Skip to content

Commit

Permalink
fixed #1209
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo4405 committed Jun 11, 2023
1 parent 442077e commit 2e6df4a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Sources/Media/IOMixer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ protocol IOMixerDelegate: AnyObject {
func mixer(_ mixer: IOMixer, sessionWasInterrupted session: AVCaptureSession, reason: AVCaptureSession.InterruptionReason)
func mixer(_ mixer: IOMixer, sessionInterruptionEnded session: AVCaptureSession, reason: AVCaptureSession.InterruptionReason)
#endif
func mixerSessionWillResume(_ mixer: IOMixer)
}

/// An object that mixies audio and video for streaming.
Expand Down Expand Up @@ -323,6 +324,11 @@ extension IOMixer: Running {
isRunning.mutate { $0 = session.isRunning }
}

func startCaptureSession() {
session.startRunning()
isRunning.mutate { $0 = session.isRunning }
}

private func addSessionObservers(_ session: AVCaptureSession) {
NotificationCenter.default.addObserver(self, selector: #selector(sessionRuntimeError(_:)), name: .AVCaptureSessionRuntimeError, object: session)
#if os(iOS)
Expand Down Expand Up @@ -438,8 +444,7 @@ extension IOMixer: Running {
guard isRunning.value && !session.isRunning else {
return
}
session.startRunning()
isRunning.mutate { $0 = session.isRunning }
delegate?.mixerSessionWillResume(self)
}
}
#else
Expand Down
6 changes: 6 additions & 0 deletions Sources/RTMP/RTMPStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,12 @@ extension RTMPStream: IOMixerDelegate {
delegate?.stream(self, didOutput: audio, presentationTimeStamp: presentationTimeStamp)
}

func mixerSessionWillResume(_ mixer: IOMixer) {
lockQueue.async {
mixer.startCaptureSession()
}
}

#if os(iOS)
func mixer(_ mixer: IOMixer, sessionWasInterrupted session: AVCaptureSession, reason: AVCaptureSession.InterruptionReason) {
delegate?.stream(self, sessionWasInterrupted: session, reason: reason)
Expand Down

0 comments on commit 2e6df4a

Please sign in to comment.