RootEncoder-iOS
RootEncoder-iOS copied to clipboard
Memory Leak and App Crash Due to WebView and Stream Filter Integration
I'm experiencing an issue where the app crashes due to excessive memory consumption. The issue occurs when integrating a WKWebView which load the content dynamically and streaming video via RtmpStream. The crash seems to happen because of the combination of the web view and the video filter applied to the stream.
Issue Details: The RtmpStream is also running simultaneously, resulting in high memory usage. This high memory consumption leads to the app crashing, likely due to the combination of the web view content and the video streaming filters.
class YTLiveStremViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
appDelegate.myOrientation = .landscapeLeft
setupUI()
getPermissions()
SocketConnectionManager.socketEmit(type: .joinMatch, param: "match_id_\(matchID)")
wkWebView.navigationDelegate = self
NotificationCenter.default.addObserver(self, selector: #selector(refreshTicker(_:)), name: NSNotification.Name(rawValue: "REFRESH_TICKER"), object: nil)
}
override func viewDidAppear(_ animated: Bool) {
wkWebView.backgroundColor = UIColor.clear
wkWebView.isOpaque = false
wkWebView.contentMode = .scaleToFill
self.view.addSubview(wkWebView)
NSLayoutConstraint.activate([
wkWebView.topAnchor.constraint(equalTo: self.cameraPreviewView.topAnchor, constant: 0),
wkWebView.bottomAnchor.constraint(equalTo: self.cameraPreviewView.bottomAnchor, constant: -4),
wkWebView.leftAnchor.constraint(equalTo: self.cameraPreviewView.leftAnchor, constant: 8),
wkWebView.rightAnchor.constraint(equalTo: self.cameraPreviewView.rightAnchor, constant: 8)
])
print("MYURL","\(CacheManager.config?.scorecardUrl ?? "")\(matchID)")
if let myurl = URL(string: "tickerurl//:") {
let myrequest = URLRequest(url: myurl)
wkWebView.load(myrequest)
}
}
func setupStream() {
rtmpStream = RtmpStream(connectChecker: self)
let _ = rtmpStream.prepareAudio(sampleRate: 32000, isStereo: true, bitrate: 128 * 1000) &&
rtmpStream.prepareVideo(width: 640, height: 480, bitrate: 1200 * 1000)
rtmpStream.startPreview(view: self.cameraPreviewView.Metalview)
let filterView = ViewFilterRender(view: wkWebView)
rtmpStream?.metalInterface.setFilter(baseFilterRender: filterView)
filterView.setScale(percentX: 100, percentY: 100)
filterView.translateTo(translation: .CENTER)
}
@IBAction func startstream(_ sender: Any) {
DispatchQueue.main.async {
self.rtmpStream.startStream(endpoint: self.streamKeyFull)
}
}
}