Closed akolov closed 7 years ago
I'm having this exact same problem. The stack trace starts around NetStream.attachCamera, and the final breakpoint is shown as session.startRunning() in AVMixer:Runnable extension. I have tried to figure this out myself, but Xcode's "Uncaught exception of type NSException" isn't exactly helpful ;)
I also have a problem, that when I use LFView as a preview, then close the view controller. If I open another view controller and try to use LFView again, the preview is just a black view. Although this doesn't generally throw an exception, and the rtmp stream does in fact broadcast (just with a blank preview).
With both of these facts in mind, I have been looking for leaks (i.e. I assume that the first LFView isn't getting deallocated before the new one is initialised), but looking at your latest commits it seems you have made changes to address this, yet the problem still exists.
The two problems may be unrelated, just that I have them occurring in the same view and both are somewhat intermittent, makes me suspect that they are connected.
@brycesteve yes, I'm getting black screen sometimes as well, especially right after camera/microphone permission requests.
Yes. I'm trying to fix this issue and #175, #131.
fixed this issue :) I will release 0.5.11 in a few days.
Please call RTMPStream.dispose() method at "viewWillDisappear" RTMPStream#dispose method can destroy an AVCaptureSession safety :)
import lf
import UIKit
import XCGLogger
import AVFoundation
let sampleRate:Double = 44_100
final class LiveViewController: UIViewController {
var rtmpConnection:RTMPConnection = RTMPConnection()
var rtmpStream:RTMPStream!
@IBOutlet var lfView:GLLFView?
var currentPosition:AVCaptureDevicePosition = AVCaptureDevicePosition.back
override func viewDidLoad() {
super.viewDidLoad()
rtmpStream = RTMPStream(connection: rtmpConnection)
rtmpStream.syncOrientation = true
rtmpStream.captureSettings = [
"sessionPreset": AVCaptureSessionPreset1280x720,
"continuousAutofocus": true,
"continuousExposure": true,
]
rtmpStream.videoSettings = [
"width": 1280,
"height": 720,
]
rtmpStream.audioSettings = [
"sampleRate": sampleRate
]
}
override func viewWillAppear(_ animated: Bool) {
logger.info("viewWillAppear")
super.viewWillAppear(animated)
rtmpStream.attachAudio(AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeAudio), automaticallyConfiguresApplicationAudioSession: false)
rtmpStream.attachCamera(DeviceUtil.device(withPosition: currentPosition))
lfView?.attachStream(rtmpStream)
}
override func viewWillDisappear(_ animated: Bool) {
logger.info("viewWillDisappear")
super.viewWillDisappear(animated)
rtmpStream.close()
rtmpStream.dispose()
}
}
Released 0.5.11
Experiencing the similar crash. Stack trace from firebase crashlytics:
Fatal Exception: NSGenericException
0 CoreFoundation 0xa248 __exceptionPreprocess
1 libobjc.A.dylib 0x17a68 objc_exception_throw
2 AVFCapture 0x2a1f8 -[AVCaptureSession startRunning]
3 HaishinKit 0x1ad7c thunk for @escaping @callee_guaranteed () -> () (<compiler-generated>)
4 libdispatch.dylib 0x24b4 _dispatch_call_block_and_release
5 libdispatch.dylib 0x3fdc _dispatch_client_callout
6 libdispatch.dylib 0x15b8c _dispatch_root_queue_drain
7 libdispatch.dylib 0x16284 _dispatch_worker_thread2
8 libsystem_pthread.dylib 0xdbc _pthread_wqthread
9 libsystem_pthread.dylib 0xb98 start_wqthread
The following code
crashes sometimes with the Exception while calling
attachCamera
methodBacktrace:
I suspect some race condition in AVMixer? I'm using lf.swift version 0.5.8