I'm working on a Swift-based VoIP application using PJ-SIP and facing an issue with displaying the video stream in a UIView. I've set up PJSIPManager to handle SIP functionalities, and I'm trying to embed the video stream within a UIView in my UIViewController. However, the video is not being displayed as expected.
Code Setup: In my PJSIPManager, I have the following configuration:
struct PJSIPManager {
private init() {
var cfg = pjsua_config()
pjsua_config_default(&cfg)
cfg.cb.on_call_media_state = on_call_media_state
}
var vid_win: UIView? = nil
private func on_call_media_state(pjsipID: pjsua_call_id) {
// ... [media state handling code] ...
if (media[Int(mi)].type == PJMEDIA_TYPE_VIDEO) {
PJSIPManager.instance?.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.instance?.vid_win = Unmanaged<UIView>.fromOpaque(wi.hwnd.info.ios.window).takeUnretainedValue();
}
}
}
}
In my UIViewController, I'm doing the following:
override func viewDidLoad() {
super.viewDidLoad()
DispatchQueue.main.async {
if let isVideoCall = PJSIPManager.getInstance()?.isVideoCall ,isVideoCall{
if PJSIPManager.getInstance()?.vid_win != nil {
self.view.addSubview(PJSIPManager.getInstance()!.vid_win!)
}
PJSIPManager.getInstance()!.vid_win!.layer.borderColor = UIColor.red.cgColor
PJSIPManager.getInstance()!.vid_win!.layer.borderWidth = 2.0
PJSIPManager.instance?.vid_win?.isHidden = false
PJSIPManager.getInstance()!.vid_win!.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
PJSIPManager.getInstance()!.vid_win!.centerXAnchor.constraint(equalTo:self.view.centerXAnchor),
PJSIPManager.getInstance()!.vid_win!.centerYAnchor.constraint(equalTo: self.view.centerYAnchor),
PJSIPManager.getInstance()!.vid_win!.widthAnchor.constraint(equalToConstant: 100),
PJSIPManager.getInstance()!.vid_win!.heightAnchor.constraint(equalToConstant: 100)
])
}
}
}
}
With this setup, I'm not able to see the video stream.
Issue:
When I use the vid_win directly from PJSIPManager, the video doesn't play.but If I set a background color to the view, I can see the view with the background color when the call is a video call, indicating that the view is added to the view hierarchy, but it's not rendering the video stream.
How can I ensure that vid_win is correctly receiving and displaying the video stream? Are there any specific considerations in PJ-SIP for embedding video in a UIView?
I made sure that isVideoCall is true and that PJSIPManager.getInstance()?.vid_win is not nil
The problem was that i called
before
instead of the opposite