niexinxin
niexinxin

Reputation: 73

How to make the RTCEAGLVideoView no deform full screen display

I'm displaying a RTCVideoTrack with RTCEAGLVideoView, and want it to be full screen, but it always deforms.I have tried to use AVMakeRectWithAspectRatioInsideRect method to display this view, there's no distortion but no full screen either, here is my code.

RTCEAGLVideoView *remoteVideoView = [[RTCEAGLVideoView alloc] initWithFrame:self.backView.bounds];
remoteVideoView.contentMode = UIViewContentModeScaleAspectFill;
_remoteVideoView = remoteVideoView;
[remoteVideoView renderFrame:nil];
[remoteVideoTrack addRenderer:remoteVideoView];
remoteVideoView.delegate = self;
self.remoteVideoTrack = remoteVideoTrack;
[self.backView addSubview:remoteVideoView];

when didChangeVideoSize delegate called:

- (void)videoView:(RTCEAGLVideoView*)videoView didChangeVideoSize:(CGSize)size {
    if (videoView == _remoteVideoView) {
        _remoteVideoSize = size;
    }
    CGRect bounds = self.view.bounds;
    if (_remoteVideoSize.width > 0 && _remoteVideoSize.height > 0) {
        // Aspect fill remote video into bounds.
        CGRect remoteVideoFrame =
        AVMakeRectWithAspectRatioInsideRect(_remoteVideoSize, bounds);
        CGFloat scale = 1;
        if (remoteVideoFrame.size.width > remoteVideoFrame.size.height) {
            // Scale by height.
            scale = bounds.size.height / remoteVideoFrame.size.height;
        } else {
            // Scale by width.
            scale = bounds.size.width / remoteVideoFrame.size.width;
        }
        remoteVideoFrame.size.height *= scale;
        remoteVideoFrame.size.width *= scale;
        _remoteVideoView.frame = remoteVideoFrame;
        _remoteVideoView.center =
        CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
    } else {
        _remoteVideoView.frame = bounds;
    }
}

I am wondering if the method of renderFrame can do something helpful, but i can't find how to create a RTCI420Frame property.

Upvotes: 6

Views: 2290

Answers (1)

Daljeet
Daljeet

Reputation: 1595

You can use RTCMTLVideoView to set contentMode(full screen).

Import:

#import <WebRTC/RTCMTLVideoView.h>

Use this code here:

#if defined(RTC_SUPPORTS_METAL)
       
 RTCMTLVideoView *mtlVideoView = [[RTCMTLVideoView alloc] initWithFrame:CGRectZero];
 mtlVideoView.videoContentMode = UIViewContentModeScaleAspectFill;
    
#else

//Here you can create RTCEAGLVideoView

Upvotes: 7

Related Questions