Giter Club home page Giter Club logo

Comments (3)

Meonardo avatar Meonardo commented on June 4, 2024

The issue is not fixed,
but the alternative way to achieve local front camera renderer mirror effect is:

  1. Update renderer rotationOverride according to the current orentation of the device;
  2. Update the camera output orientation in file RTCCameraVideoCapturer,
- (void)captureOutput:(AVCaptureOutput *)captureOutput
    didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
           fromConnection:(AVCaptureConnection *)connection
``` .

from janus-videoroom-ios.

fukemy avatar fukemy commented on June 4, 2024

just change to using RTCEAGLVideoView

final class WebRTCView: UIView, RTCVideoViewDelegate{
    
    var videoView = RTCEAGLVideoView(frame: .zero)
    
    var videoSize = CGSize.zero
    var isFillView = false
    
    @IBInspectable public var cornerRadius: CGFloat = 0 {
        didSet {
            layer.cornerRadius = cornerRadius
//            layer.borderWidth = cornerRadius > 0 ? 1 : 0
//            layer.borderColor = UIColor.white.cgColor
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        initView()
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
        initView()
    }
    
    func initView(){
        videoView.delegate = self
        clipsToBounds = true
        addSubview(videoView)
    }
    
    func videoView(_ videoView: RTCVideoRenderer, didChangeVideoSize size: CGSize) {
        self.videoSize = size
        setNeedsLayout()
    }

    override func layoutSubviews() {
        super.layoutSubviews()
        updateLayout()
    }
    
    func updateLayout(){
        guard videoSize.width > 0 && videoSize.height > 0 else {
            videoView.frame = bounds
            return
        }

        var videoFrame : CGRect = .zero
            
        if !isFillView{
            videoFrame = AVMakeRect(aspectRatio: videoSize, insideRect: bounds)
            let scale = videoFrame.size.aspectFitScale(in: bounds.size)
            videoFrame.size.width = videoFrame.size.width * CGFloat(scale)
            videoFrame.size.height = videoFrame.size.height * CGFloat(scale)
            
        }else{
            let newSize = aspectFill(aspectRatio: videoSize, minimumSize: bounds.size)
            videoFrame.size.width = newSize.width
            videoFrame.size.height = newSize.height
            
        }
        

        videoView.frame = videoFrame
        videoView.center = CGPoint(x: bounds.midX, y: bounds.midY)
    }
    
    func aspectFill(aspectRatio : CGSize, minimumSize: CGSize) -> CGSize {
        let mW = minimumSize.width / aspectRatio.width;
        let mH = minimumSize.height / aspectRatio.height;
        
        var temp = minimumSize
        if( mH > mW ) {
            temp.width = minimumSize.height / aspectRatio.height * aspectRatio.width;
        }
        else if( mW > mH ) {
            temp.height = minimumSize.width / aspectRatio.width * aspectRatio.height;
        }
        
        return temp;
    }
    
}


extension CGSize {
    func aspectFitScale(in container: CGSize) -> CGFloat {

        if height <= container.height && width > container.width {
            return container.width / width
        }
        if height > container.height && width > container.width {
            return min(container.width / width, container.height / height)
        }
        if height > container.height && width <= container.width {
            return container.height / height
        }
        if height <= container.height && width <= container.width {
            return min(container.width / width, container.height / height)
        }
        return 1.0
    }
}

from janus-videoroom-ios.

Meonardo avatar Meonardo commented on June 4, 2024

just change to using RTCEAGLVideoView

final class WebRTCView: UIView, RTCVideoViewDelegate{
    
    var videoView = RTCEAGLVideoView(frame: .zero)
    
    var videoSize = CGSize.zero
    var isFillView = false
    
    @IBInspectable public var cornerRadius: CGFloat = 0 {
        didSet {
            layer.cornerRadius = cornerRadius
//            layer.borderWidth = cornerRadius > 0 ? 1 : 0
//            layer.borderColor = UIColor.white.cgColor
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        initView()
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
        initView()
    }
    
    func initView(){
        videoView.delegate = self
        clipsToBounds = true
        addSubview(videoView)
    }
    
    func videoView(_ videoView: RTCVideoRenderer, didChangeVideoSize size: CGSize) {
        self.videoSize = size
        setNeedsLayout()
    }

    override func layoutSubviews() {
        super.layoutSubviews()
        updateLayout()
    }
    
    func updateLayout(){
        guard videoSize.width > 0 && videoSize.height > 0 else {
            videoView.frame = bounds
            return
        }

        var videoFrame : CGRect = .zero
            
        if !isFillView{
            videoFrame = AVMakeRect(aspectRatio: videoSize, insideRect: bounds)
            let scale = videoFrame.size.aspectFitScale(in: bounds.size)
            videoFrame.size.width = videoFrame.size.width * CGFloat(scale)
            videoFrame.size.height = videoFrame.size.height * CGFloat(scale)
            
        }else{
            let newSize = aspectFill(aspectRatio: videoSize, minimumSize: bounds.size)
            videoFrame.size.width = newSize.width
            videoFrame.size.height = newSize.height
            
        }
        

        videoView.frame = videoFrame
        videoView.center = CGPoint(x: bounds.midX, y: bounds.midY)
    }
    
    func aspectFill(aspectRatio : CGSize, minimumSize: CGSize) -> CGSize {
        let mW = minimumSize.width / aspectRatio.width;
        let mH = minimumSize.height / aspectRatio.height;
        
        var temp = minimumSize
        if( mH > mW ) {
            temp.width = minimumSize.height / aspectRatio.height * aspectRatio.width;
        }
        else if( mW > mH ) {
            temp.height = minimumSize.width / aspectRatio.width * aspectRatio.height;
        }
        
        return temp;
    }
    
}


extension CGSize {
    func aspectFitScale(in container: CGSize) -> CGFloat {

        if height <= container.height && width > container.width {
            return container.width / width
        }
        if height > container.height && width > container.width {
            return min(container.width / width, container.height / height)
        }
        if height > container.height && width <= container.width {
            return container.height / height
        }
        if height <= container.height && width <= container.width {
            return min(container.width / width, container.height / height)
        }
        return 1.0
    }
}

That's great, use RTCEAGLVideoView will work.

from janus-videoroom-ios.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.