iOS: RTCCameraVideoCapturer tags every frame 90 degrees wrong when the display is not mounted in the device's portrait frame (iPhone Duo inner display); use AVCaptureDevice.RotationCoordinator

Aperta
#147 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
43/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
ios, objective-c
Ambito
mobile

Direzione di ricerca

Start in the iOS camera capturer at captureOutput:didOutputSampleBuffer:fromConnection: and updateOrientation, which the issue identifies as the sources of the frame rotation tag. Review the rotation coordinator guidance and the existing orientation table, then check the capture rotation behavior on the iPhone Duo inner display, across folding and unfolding, and with external cameras. Done means frames stay upright in the preview and remotely, while the existing fallback behavior remains covered on older iOS versions and external cameras.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Versions: StreamWebRTC 145.17.0 (through @stream-io/react-native-webrtc 145.4.1 and @stream-io/video-react-native-sdk 1.46.3). The same code is in 145.25.0 and 156.0.7. iOS 27.1, iPhone Duo. App built with Xcode 27.1 (iOS 27.1 SDK), UIRequiresFullScreenIgnoredStartingWithVersion~iphone set so the app runs full screen on the inner display, landscape allowed during a call.

Steps

  1. Open the iPhone Duo and start a call on the inner display with the front camera, holding the device so the inner display is in landscape (its natural way).
  2. Look at the local preview and at the remote side.

Expected: the local preview and the remote side are upright.

Actual: the video is rotated 90 degrees, in the local preview and on the remote side alike. From the code below, every pose of the open device is a quarter turn off, and folding mid-call does not trigger a re-read.

Cause

  • captureOutput:didOutputSampleBuffer:fromConnection: derives the frame's RTCVideoRotation from a fixed table keyed on the interface orientation read in updateOrientation (connectedScenes.anyObject.interfaceOrientation): portrait 90, portraitUpsideDown 270, landscapeLeft front 0 / back 180, landscapeRight front 180 / back 0.
  • The table assumes the display and the device body share one frame of reference. The iPhone Duo's inner display is mounted a quarter turn off the body. When the device is closed, portrait has the charging port down; when it is open, landscape-right has the port down. So on the inner display every interface orientation maps to a tag that is 90 degrees off.
  • Folding or unfolding posts no UIDeviceOrientationDidChangeNotification, so updateOrientation is not re-run when the app moves between displays either.
  • WebKit hit the same problem with the same kind of table and fixed it for this device (WebKit PR 79476, "always presented at a 90 degree shift").

Suggested fix

On iOS 17 and later, tag frames from Apple's rotation coordinator instead of the table:

// once per device (recreate on a camera switch)
_coordinator = [[AVCaptureDeviceRotationCoordinator alloc] initWithDevice:device previewLayer:nil];
// KVO on videoRotationAngleForHorizonLevelCapture (delivered on the main queue)

// per frame (or cached on change)
CGFloat angle = _coordinator.videoRotationAngleForHorizonLevelCapture - connection.videoRotationAngle;
long quarter = (((lround(angle / 90.0)) % 4) + 4) % 4;
RTCVideoRotation rotation = (RTCVideoRotation)(quarter * 90);
  • Subtract the connection's own videoRotationAngle. Apple's guidance (Developer Forums thread 813548) is that the coordinator's angle is relative to the unrotated sensor, and iPhone 17 front cameras have a different sensor rotation (the coordinator returns 0 in portrait there, 90 on earlier iPhones).
  • Apple's iPhone Duo camera talk (Tech Talk 111465) says the rotation coordinator "will update when your app moves displays", which covers fold and unfold.
  • Keep the current table as the fallback before iOS 17 and for AVCaptureDeviceTypeExternal (the coordinator returns 0 for external cameras).

Workaround we use meanwhile

A frame processor registered through react-native-webrtc's ProcessorProvider (track._setVideoEffect). On devices that have AVCaptureDeviceTypeBuiltInInnerUltraWideCamera it re-tags each frame with the angle above when it differs from the capturer's tag. It changes only the rotation tag, never pixels. It would be better in the capturer itself.

Related, separate

When the camera restarts during a Picture in Picture or background-to-foreground transition, updateOrientation runs once at startCaptureWithDevice: and can read portrait from a scene that has not settled. Nothing moves the device, so no device-orientation notification follows, and frames stay tagged portrait until the phone is physically turned. The coordinator also covers this case. Without it, pick the foregroundActive window scene rather than anyObject, read effectiveGeometry.interfaceOrientation (iOS 16 and later), and re-sample when the scene activates.

Lingua principale
C++
Stelle
9
Fork
6
Merge medio
18h 4m
PR unite (30g)
25

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di GetStream/webrtc

Tutte le issue di GetStream/webrtc

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.