RTCMTLVideoView camera preview

andrew.n

Member
@Max is there an option to show the camera preview, before starting a stream? Right now I use another component for that but I have some issues for device rotation and I tough it will be easier to work only with a single RTCMTLVideoView during streaming but also before starting the stream.
 

Max

Administrator
Staff member
Good day.
Please look at the Media Devices Swift example. You can use WCSApi2.getMediaAccess() method (see example code):
Code:
    @IBAction func testPressed(_ sender: Any) {
        if (testButton.title(for: .normal) == "TEST") {
            let constraints = FPWCSApi2MediaConstraints(audio: true, video: true)!
            do {
                try WCSApi2.getMediaAccess(constraints, localDisplay.videoView)
            } catch {
                print(error)
            }
            testButton.setTitle("RELEASE", for: .normal)
        } else {
            WCSApi2.releaseLocalMedia(display: localDisplay.videoView);
            testButton.setTitle("TEST", for: .normal)
        }
    }
 

andrew.n

Member
@Max Sometimes, when releasing the local media, the camera is still in use (green indicator on the dynamic island is still active)
Code:
private func setupWCSLocalMedia(active: Bool) {
    guard let videoView = self.videoView else { return }
    if active {
        let constraints = FPWCSApi2MediaConstraints(audio: true, video: true)!
        try? WCSApi2.getMediaAccess(constraints, videoView)
    } else {
        _ = WCSApi2.releaseLocalMedia(display: videoView)
    }
}
When opening the screen, I check for permissions and after I have access to both microphone & camera, I set media access as active, after that I start the broadcasting, then when the broadcast ended, I want to resume the local view. Should I manual manage to set it active when opening the screen, stop when broadcast start, and start again when broadcast ending?
I tried this to manage, and it happen when doing the start/stop multiple times, and leave the screen, the camera is still used even if the calls to set it active and not active, are equals.
 

Max

Administrator
Staff member
Please build the Media Devices Swift example and try to reproduce the issue pressing Test then Release button. If the issue is not reproduced, please check the return value of releaseLocalMedia method. It returns true if the display found in resources acquired by previous getMediaAccess call and false if not.
The camera itself should be released if video renderer is closed:
Code:
        if (r.view == display) {
            [r close];
            r.view = nil;
            ret = true;
            [localMediaResources removeObject:r];
            break;
        }
So seems like when you start/stop multiple times you do not close the video renderer (videoView) occasionally.
 

andrew.n

Member
@Max videoView is of type RTCMTLVideoView which also is of type RTCVideoRenderer, but close function is not available.
How to you get the "r" reference that you mentioned in your answer?
 

Max

Administrator
Staff member
How to you get the "r" reference that you mentioned in your answer?
This it the internal SDK code. In internal close method, WebRTC library function RTCVideoTrack.removeRenderer is called to remove the RTCVideoRenderer from the media track. This should release the device camera.
Seems in your case the code is not called. Please build the Media Devices Swift example and try to reproduce the issue pressing Test then Release button. If the issue is not reproduced, please modify the example code to reproduce it and send us the code using this form.
 

Max

Administrator
Staff member
any though regarding the ticket I submitted? Did you saw the issue? Is under development?
We did not received any steps to reproduce or code example to reproduce the issue from you, so we don't raise ticket yet. Please use this form to send.
 

andrew.n

Member
:| I sent it on October 20th... so basically to reproduce you have to press Test -> Connect -> Publish -> Play and after that you just have to press "Disconnect". What happens is that the local view is still showing camera preview.. even if you press "Release" it still displays... this is also what happens when I close the stream.. the view is not released...
 

Max

Administrator
Staff member
We reproduced the problem and raised the ticket WCS-3965. Will let you know about progress here.
 
Top