Comments (3)
The issue is not fixed,
but the alternative way to achieve local front camera renderer mirror effect is:
- Update renderer
rotationOverride
according to the current orentation of the device; - Update the camera output orientation in file
RTCCameraVideoCapturer
,
- (void)captureOutput:(AVCaptureOutput *)captureOutput
didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
fromConnection:(AVCaptureConnection *)connection
``` .
from janus-videoroom-ios.
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.
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)
- Support launch container app in Broadcast extension.
- echo/noise problem with speaker HOT 7
- ios 15 now support PIP, did u tried with this project? HOT 18
- support filter effect HOT 3
- build failed HOT 7
- failed extracting 'https://github.com/Meonardo/WebRTC/releases/download/91.0.1/WebRTC-M91.0.1.xcframework.zip' which is required by binary target 'WebRTC': /Users/..../Library/Developer/Xcode/DerivedData/janus-videoroom-example-blqhidmhjqwphtfdlfbubclciaic/SourcePackages/artifacts/extract/WebRTC is not a directory HOT 2
- attemped to start and invalid broadcast session? HOT 2
- display preview camera in localView HOT 3
- how to change state of button(mic/camera/speaker) automatic HOT 2
- is this starcream bug: connected state called again after disconnect() socket HOT 3
- sharing screen as localPublisher black screen HOT 16
- Understand Code Logic HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from janus-videoroom-ios.