AlexKMDev / WebRTC

Unofficial builds of Google WebRTC iOS Framework
https://webrtc.org/native-code/ios/
Other
292 stars 76 forks source link

LocalVideoStream Rotate #14

Closed x3mall1986 closed 7 years ago

x3mall1986 commented 7 years ago

Hello. Help me plz. When i rotate the device my localVideoStream View rotate, but video stream from camera is inverted. How to change orientation for this localVideoStream when I rotate device?

obaskanderi commented 7 years ago

I ran into a similar issue. If you're using a RTCCameraPreviewView for your local video stream you could try something like this:

if let previewLayer = localVideoView.layer as? AVCaptureVideoPreviewLayer,
   let connection = previewLayer.connection,
   connection.isVideoOrientationSupported {
   switch UIDevice.current.orientation {
   case .landscapeLeft:
      connection.videoOrientation = .landscapeLeft
      localVideoView.transform = CGAffineTransform.init(scaleX: 1, y: -1)
      break
   case .landscapeRight:
      connection.videoOrientation = .landscapeRight
      localVideoView.transform = CGAffineTransform.init(scaleX: 1, y: -1)
      break
   case .portrait:
      connection.videoOrientation = .portrait
      localVideoView.transform = CGAffineTransform.identity
      break
   case .portraitUpsideDown:
      connection.videoOrientation = .portraitUpsideDown
      localVideoView.transform = CGAffineTransform.identity
      break
   default:
      print("unsupport orientation")
   }
 }

Basically need to translate UIDeviceOrientation to AVCaptureVideoOrientation and perform the transform so localVideoView is rotated correctly.

Hope this helps.

Also just found that there is a feature request related to this issue:

https://bugs.chromium.org/p/webrtc/issues/detail?id=6749

danlniel commented 7 years ago

Yea the behaviour is a bit different with android, Whenever you rotate the app even though your app set autoRotate false, The view created always rendering agian, For now like @obaskanderi said, we can manipulate the view by change rotation or y axis.

AlexKMDev commented 7 years ago

I assume it's fixed in the upstream.