Thanks to visit codestin.com
Credit goes to github.com

Skip to content

WebRTC screen capture incorrect on devices where 0° rotation is landscape #1852

@lukasharing-hl

Description

@lukasharing-hl

Describe the bug
The isDeviceOrientationPortrait() method in OrientationAwareScreenCapturer.java incorrectly assumes that Surface.ROTATION_0 (0° rotation) always corresponds to portrait orientation. This assumption is false for devices where the natural orientation is landscape, such as tablets, embedded devices, and custom hardware.

This causes WebRTC screen capture to create virtual displays with incorrect dimensions (e.g., 800x1280 instead of 1280x800), resulting in rotated/letterboxed video streams.

Root cause (current implementation):

private boolean isDeviceOrientationPortrait() {
    final int surfaceRotation = windowManager.getDefaultDisplay().getRotation();
    return surfaceRotation != Surface.ROTATION_90 && surfaceRotation != Surface.ROTATION_270;
}

This assumes 0° and 180° rotations are always portrait, which is incorrect for landscape-native devices.

To Reproduce

  1. Use a device where the natural orientation is landscape (e.g., tablet, embedded device with landscape display)
  2. Ensure the device reports 0° rotation in landscape mode
  3. Start WebRTC screen capture using navigator.mediaDevices.getDisplayMedia()
  4. Observe that the virtual display is created with portrait dimensions instead of landscape
  5. Check adb shell dumpsys display - you'll see virtual displays like:
    textDisplayDeviceInfo{"WebRTC_ScreenCapture": ..., 800 x 1280, ...}
    instead of:
    textDisplayDeviceInfo{"WebRTC_ScreenCapture": ..., 1280 x 800, ...}

Expected behavior
WebRTC should create virtual displays with the correct orientation dimensions regardless of the device's natural orientation. For a 1280x800 landscape display, the virtual display should be 1280x800, not 800x1280.

Platform information

  • Flutter version:
[✓] Flutter (Channel stable, 3.27.1, on macOS 15.4.1 24E263 darwin-arm64, locale en-US)
    • Flutter version 3.27.1 on channel stable at /Users/lukasharing/fvm/versions/3.27.1
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 17025dd882 (5 months ago), 2024-12-17 03:23:09 +0900
    • Engine revision cb4b5fff73
    • Dart version 3.6.0
    • DevTools version 2.40.2

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at /Users/lukasharing/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0
    • ANDROID_HOME = /Users/lukasharing/Library/Android/sdk
    • Java binary at: /Users/lukasharing/Library/Java/JavaVirtualMachines/jbr-17.0.12/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment JBR-17.0.12+1-1207.37-nomod (build 17.0.12+1-b1207.37)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.3)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16E140
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 21.0.6+-13368085-b895.109)

[✓] VS Code (version 1.100.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.110.0

[✓] Connected device (4 available)
    • Luky’s iPhone1 (mobile)         • 00008120-001A7DD10E60C01E • ios            • iOS 18.5 22F76
    • macOS (desktop)                 • macos                     • darwin-arm64   • macOS 15.4.1 24E263 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad     • darwin         • macOS 15.4.1 24E263 darwin-arm64
    • Chrome (web)                    • chrome                    • web-javascript • Google Chrome 136.0.7103.114

[✓] Network resources
    • All expected network resources are available.

• No issues found!
  • Plugin version: 0.14.1
  • OS: Android
  • OS version: Android 10+ (affects all Android versions)
  • Device type: Embedded device with natural landscape orientation (1280x800 display)

Additional context:
This issue affects any device where the manufacturer has set the natural orientation to landscape, which is common in:

  • Tablets and larger Android devices
  • Embedded systems and kiosks
  • Custom hardware with landscape displays
  • Industrial Android devices

The fix is minimal, low-risk, and improves compatibility across the Android ecosystem.

Note: I'm currently experiencing compilation issues with my Flutter version due to the SurfaceTextureRenderer callback changes described in #1812, but I'm planning to update my project to resolve the compatibility issue (as mentioned in #1834). The bug is evident from code inspection - the current logic assumes 0° rotation always means portrait orientation, which is incorrect for landscape-native devices. If you encounter similar compilation problems, try updating to a compatible Flutter/plugin version combination.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions