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

Abierto
#147 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
43/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
ios, objective-c
Área
mobile

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
C++
Estrellas
9
Forks
6
Merge medio
18 h 4 min
PR fusionados (30 d)
25

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de GetStream/webrtc

Todos los issues de GetStream/webrtc

Issues similares

Más issues de C++

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.