I am engaged on a Swift-based VoIP software utilizing PJ-SIP and going through a problem with displaying the video stream in a UIView. I’ve arrange PJSIPManager to deal with SIP functionalities, and I am making an attempt to embed the video stream inside a UIView in my UIViewController. Nonetheless, the video will not be being displayed as anticipated.
Code Setup:
In my PJSIPManager, I’ve the next configuration:
struct PJSIPManager {
non-public init() {
var cfg = pjsua_config()
pjsua_config_default(&cfg)
cfg.cb.on_call_media_state = on_call_media_state
}
var vid_win: UIView? = nil
non-public func on_call_media_state(pjsipID: pjsua_call_id) {
// ... [media state handling code] ...
if (media[Int(mi)].sort == PJMEDIA_TYPE_VIDEO) {
PJSIPManager.occasion?.isVideoCall = true
let wid = media[Int(mi)].stream.vid.win_in;
var wi = pjsua_vid_win_info();
if (pjsua_vid_win_get_info(wid, &wi) == PJ_SUCCESS.rawValue) {
PJSIPManager.occasion?.vid_win = Unmanaged<UIView>.fromOpaque(wi.hwnd.information.ios.window).takeUnretainedValue();
}
}
}
}
In my UIViewController, I am doing the next:
override func viewDidLoad() {
tremendous.viewDidLoad()
DispatchQueue.essential.async {
if let isVideoCall = PJSIPManager.getInstance()?.isVideoCall, isVideoCall {
if let videoWindow = PJSIPManager.getInstance()?.vid_win {
self.view.addSubview(videoWindow)
videoWindow.backgroundColor = .pink
self.videoView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
self.videoView.centerXAnchor.constraint(equalTo:self.view.centerXAnchor),
self.videoView.centerYAnchor.constraint(equalTo: self.view.centerYAnchor),
self.videoView.widthAnchor.constraint(equalToConstant: 100),
self.videoView.heightAnchor.constraint(equalToConstant: 100)
])
}
}
}
}
With this setup, I am not capable of see the video stream.
Challenge:
Once I use the vid_win straight from PJSIPManager, the video would not present up.however If I exchange vid_win with a newly created UIView occasion (self.videoView = UIView()), I can see the pink view, indicating that the view is added to the view hierarchy, but it surely’s not rendering the video stream.
How can I be sure that vid_win is accurately receiving and displaying the video stream?
Are there any particular concerns in PJ-SIP for embedding video in a UIView?
I made certain that isVideoCall is true and that PJSIPManager.getInstance()?.vid_win will not be nil