ios – Swift PJ-SIP Integration: Issue Displaying Video Stream in UIView


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 let videoWindow = PJSIPManager.getInstance()?.vid_win {
                self.view.addSubview(videoWindow)
                videoWindow.backgroundColor = .red
                 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’m not able to see the video stream.

Issue:

When I use the vid_win directly from PJSIPManager, the video doesn’t show up.but If I replace vid_win with a newly created UIView instance (self.videoView = UIView()), I can see the red view, 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

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img