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

Đang mở
#147 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
43/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
ios, objective-c
Lĩnh vực
mobile

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
C++
Star
9
Fork
6
Merge trung bình
18 giờ 4 phút
Pull request đã merge (30 ngày)
25

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của GetStream/webrtc

Tất cả issue của GetStream/webrtc

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.