App crash when streaming in spatial format (v2.0.0-rc.0) #1605
-
Hi, I came across a problem of app crashing when trying to stream in spatial format from private class LivePageModel: ObservableObject {
@Published var isSpatialCamera: Bool = false
@Published var stream: RTMPStream?
private let mixer = MediaMixer()
private let connection = RTMPConnection()
private let session = AVAudioSession.sharedInstance()
public var mthkView = MTHKView(frame: .zero)
//other methods
//init camera
public func initCamera() {
Task { @MainActor in
LBLogger.with(kHaishinKitIdentifier).level = .trace
do {
try session.setCategory(
.playAndRecord, mode: .default, options: [.defaultToSpeaker, .allowBluetooth])
try session.setActive(true)
var camera: AVCaptureDevice? = nil
if let videoDevice = AVCaptureDevice.default(
.builtInDualWideCamera, for: .video, position: .back)
{
camera = videoDevice
} else if let videoDevice = AVCaptureDevice.default(
.builtInWideAngleCamera, for: .video, position: .back)
{
camera = videoDevice
}
guard let videoDevice = camera, let audioDevice = AVCaptureDevice.default(for: .audio)
else {
throw CameraLoadState.cameraNotFound
}
for format in videoDevice.formats {
if format.isSpatialVideoCaptureSupported {
try videoDevice.lockForConfiguration()
videoDevice.activeFormat = format
videoDevice.unlockForConfiguration()
self.isSpatialCamera = true
print("spatial camera locked and set")
break
}
}
stream = RTMPStream(connection: connection)
let videoSettings = VideoCodecSettings(
videoSize: .init(width: 1920, height: 1080),
bitRate: 4 * 1000 * 1000, //4Mbps
profileLevel: kVTProfileLevel_HEVC_Main_AutoLevel as String
)
await stream?.setVideoSettings(videoSettings)
await mixer.setFrameRate(30)
await mixer.setVideoOrientation(.landscapeRight)
await mixer.setSessionPreset(.hd1920x1080)
try await mixer.attachAudio(audioDevice)
try await mixer.attachVideo(videoDevice) { videoUnit in
videoUnit.preferredVideoStabilizationMode = .cinematicExtendedEnhanced
}
await mixer.addOutput(stream!)
await stream!.addOutput(mthkView)
cameraLoadState = .loaded
} catch let err as CameraLoadState {
cameraLoadState = err
} catch {
cameraLoadState = .unknownError
}
}
}
//start stream
public func startStream() {
Task {
do {
let result: RTMPResponse = try await connection.connect("rtmp://0.0.0.0:1935/stream")
print("--> rtmp connect status: \(result)")
let pubResult: RTMPResponse = try await stream.publish(
"\(stream_id)?user=\(AuthModel.shared.getUserId())&pass=\(AuthModel.shared.getAccessToken())"
) //<-- passing user and pass as query parameter for `MediaMTX` server to handle authentication.
print("--> rtmp publish status: \(pubResult)")
} catch RTMPConnection.Error.requestFailed(let response) {
print("--> rtmp connection error: \(String(describing: response.status))")
} catch RTMPStream.Error.requestFailed(let response) {
print("--> rtmp publish error: \(String(describing: response.status))")
} catch {
print("--> rtmp unknown error: \(error)")
}
}
}
} and here is the error Log:
and then there is the crash that points to this line: HaishinKit.swift/Sources/RTMP/RTMPChunk.swift Line 283 in 6f41038 |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Thank you for the report. It was crashing with larger data. This has been fixed in commit 697c793. |
Beta Was this translation helpful? Give feedback.
-
It's a simple issue that has already been fixed, so I will close it. |
Beta Was this translation helpful? Give feedback.
Thank you for the report. It was crashing with larger data. This has been fixed in commit 697c793.