-
Describe the bugDuring the migration to 2.0.0 our main thread started hanging for ~10s during startup. The issue is similar to #1581. I've found that the block occurs during session.commitConfiguration() call and is related only to
The block doesn't occur in two cases:
I tried to reproduce this issue with the iOS example and realized that Task in IngestViewControlleroverride func viewDidLoad() {
logger.info("viewDidLoad")
super.viewDidLoad()
Task {
if let orientation = DeviceUtil.videoOrientation(by: UIApplication.shared.statusBarOrientation) {
await mixer.setVideoOrientation(orientation)
}
await mixer.setMonitoringEnabled(DeviceUtil.isHeadphoneConnected())
var videoMixerSettings = await mixer.videoMixerSettings
videoMixerSettings.mode = .offscreen
await mixer.setVideoMixerSettings(videoMixerSettings)
await netStreamSwitcher.setPreference(Preference.default)
if let stream = await netStreamSwitcher.stream {
await mixer.addOutput(stream)
if let view = view as? (any HKStreamOutput) {
await stream.addOutput(view)
}
}
// code from viewWillAppear:
let back = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: currentPosition)
try? await mixer.attachVideo(back, track: 0)
try? await mixer.attachAudio(AVCaptureDevice.default(for: .audio))
let front = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .front)
try? await mixer.attachVideo(front, track: 1) { videoUnit in
videoUnit.isVideoMirrored = true
}
}
// ... I wanted to get your opinion about a fix where Examplefunc viewDidLoad() {
await attach()
await mixer.addOutput(stream)
}
func viewWillAppear() {
await attach()
}
func attach() async {
await mixer.attachAudio(AVCaptureDevice.default(for: .audio), track: 0)
} This fix might be beneficial for the iOS example to avoid potential race condition between tasks in To ReproduceProvided in the description Expected behaviorTo avoid main thread blocking Version2.0.0-rc.2 Smartphone info.18.1, 15 Pro Max Additional contextNo response ScreenshotsNo response Relevant log output2024-11-08 5:44:20 PM +0000 before session.commitConfiguration()
2024-11-08 5:44:29 PM +0000 after session.commitConfiguration() |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
A strong option at this point would be to stop HK’s automatic calls and have developers call startCapturing/stopCapturing in alignment with the lifecycle. However, this may be confusing as it differs from the previous ease of use. |
Beta Was this translation helpful? Give feedback.
-
When launching the Example app from Xcode, it takes a long time to start up, which is bothersome. However, during a normal launch, it doesn’t seem to lock the main thread, and it starts up smoothly, so I don’t think there’s an issue. Is this specifically about launching from Xcode, or are you referring to starting up the app in general? |
Beta Was this translation helpful? Give feedback.
-
Thank you for the response! I would prefer manual
The example that I provided for |
Beta Was this translation helpful? Give feedback.
-
This issue occurs in both HaishinKit 1.9.x and 2.0.x. It has been confirmed on iOS 18.0 and iOS 18.1.
At step 4, a 10-second freeze occurs. Since the freeze duration is consistently around 10 seconds, it seems to be related to some process on the OS side. To avoid this issue safely, I believe it’s better to manage |
Beta Was this translation helpful? Give feedback.
This issue occurs in both HaishinKit 1.9.x and 2.0.x. It has been confirmed on iOS 18.0 and iOS 18.1.
A simple way to reproduce the issue, independent of HaishinKit, is as follows:
AVCaptureMultiCamSession
.session.startRunning()
.session.addOutput()
.At step 4, a 10-second freeze occurs. Since the freeze duration is consistently around 10 seconds, it seems to be related to some process on the OS side.
To avoid this issue safely, I believe it’s better to manage
session.startRunning()
consciously on the user side instead of triggering it automatically.