Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue displaying LocalStream in mirror or flipped mode in macOS Swift. #107

Open
MuhammadBilal164 opened this issue Oct 24, 2024 · 0 comments

Comments

@MuhammadBilal164
Copy link

MuhammadBilal164 commented Oct 24, 2024

i am capturing video from this method. I am using RTCMTLNSVideoView to display the video. my issue is that i am unable to flip the video.
` func enableMyMedia(callback:@escaping () -> Void){
DispatchQueue.global(qos: .userInitiated).async {
if(PeerConnectionService.localStream == nil){
let _localStream = self.peerConnectionFactory.mediaStream(withStreamId:self.getStreamUniqueId());
let constraints = RTCMediaConstraints(mandatoryConstraints: [:], optionalConstraints: [ "offerToReceiveAudio": "true",
"offerToReceiveVideo": "true",
"googCpuOveruseDetection": "true",
"googHighStartBitrate": "true",
"googScreencastMinBitrate": "true",
"googCpuUnderuseThreshold": "55", // Optional - adjust according to needs
"googUseHardwareH264": "false"])
let audioSource = self.peerConnectionFactory.audioSource(with: constraints)
let audioTrack = self.peerConnectionFactory.audioTrack(with: audioSource, trackId: self.getUniqueId());
_localStream.addAudioTrack(audioTrack);
if(self.isAudio == false){
self.videoSource = nil;
self.videoSource = self.peerConnectionFactory.videoSource()

      self.localVideoTrack = self.peerConnectionFactory.videoTrack(with: self.videoSource!, trackId: self.getUniqueId())
      
      self.videoCapturer = RTCCameraVideoCapturer(delegate: self.videoSource!)
      
      
      if let localVideoTrack = self.localVideoTrack {
          _localStream.addVideoTrack(localVideoTrack)
      } else {
          print("localVideoTrack is nil")
      }
                
      let devices = RTCCameraVideoCapturer.captureDevices()
      if let selectedDevice = devices.first(where: { $0.position == .front || $0.position == .back || $0.position == .unspecified }){
          let formats = RTCCameraVideoCapturer.supportedFormats(for: selectedDevice)
        let selectedFormat = formats.first { format in
            let dimensions = CMVideoFormatDescriptionGetDimensions(format.formatDescription)
            return dimensions.width <= 640 && dimensions.height <= 480 // Limit resolution to 480p
        }

        
          
          if let format = selectedFormat {
              let maxFrameRateRange = format.videoSupportedFrameRateRanges.min { $0.minFrameRate < $1.minFrameRate }
              if let frameRate = maxFrameRateRange?.minFrameRate {
                  let fps = max(frameRate, 10) // Example to limit to 15 fps
                DispatchQueue.main.async {
                  self.videoCapturer?.startCapture(with: selectedDevice, format: format, fps: Int(fps))
                  
                }
              }
          }
      }
      }
      
    PeerConnectionService.localStream = _localStream;
    
    callback()
  }else{
    callback()
    
  }
}

}`

showing video on RTCMTLNSVideoView like this
func renderVideoCall() {

let renderer = RTCMTLNSVideoView(frame: self.view.frame)
renderer.wantsLayer = true
renderer.clipsToBounds = true
renderer.layer?.setAffineTransform(CGAffineTransform(scaleX: -1.0, y: 1.0))
print("Renderer layer class: \(String(describing: renderer.layer?.className))")

// Add renderer to view
self.view.addSubview(renderer)
self.localVideoTrack = self.localStream?.videoTracks[0]
if let videoTrack = self.localVideoTrack {
  videoTrack.add(renderer)
  print("Video track successfully added to renderer.")
} else {
  print("Video track is nil.")
}
self.view.needsDisplay = true

}

But its not working

@MuhammadBilal164 MuhammadBilal164 changed the title Video is showing mirror in webrtc macOS Issue displaying LocalStream in mirror or flipped mode in macOS Swift. Oct 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant