Repository: flutter
Issue: [camera] Camera startImageStream image orientation differs on iOS and android
Labels: platform-android,p: camera,package,has reproducible steps,P2,found in release: 2.5,found in release: 2.6,team-android,triaged-android

## Steps to Reproduce

When using the `startImageStream` method on the `CameraController` from the camera plugin I am noticing some behavioural differences between iOS and android.

*Devices used for testing:*
**iOS:** iPhone XR
**Android:** Samsung A21s (SM A217F, android-arm64)

**Expected results:** <!-- what did you want to see? -->

When I lock the orientation to `portraitUp`, and set the resolution to `high` I would expect the image stream to deliver images in this orientation, with width: 720 and height: 1280.

So when using the code from the "Code Sample" section, I would expect android to print:
```
I/flutter (23413): Image | width: 720, height: 1280
```
And on iOS to print:
```
flutter: Image | width: 720, height: 1280
```

**Actual results:** <!-- what did you see? -->

On iOS the orientation is correct, but on android the image is some sort of landscape (I presume `landscapeLeft`). And it is printing:
```
I/flutter (23413): Image | width: 1280, height: 720
```

Please look at the code below. I suspect this is a bug since iOS is working flawlessy and android is messing up. But maybe I'm doing something wrong? Or this is just expected behaviour?

In any case, this may seem like a minor issue but I find it increasingly frustrating as now every single piece of logic I write surrounding the camera needs to be rigorously tested for both iOS and android due to such massive differences in the received output. It feels very unprofessional, and this eats up a tonne of development time. I've also had to make numerous `if iOS ... else ...` condition checks which doesn't feel like the right thing to do. I understand android and iOS produce vastly different file types. But I feel like the library should at least make an attempt at normalising the output so developers can use flutter free of concerns about android and iOS specific implementations.

Thanks!

Note: before this is marked as duplicate, this issue is specifically about the `startImageStream` method in the camera plugin version `0.9.4+5`. All other issues I have found up until now are either about other functions (like preview, video, etc.) or about older versions of the camera plugin. All of which have since been closed (for example: https://github.com/flutter/flutter/issues/29951 and https://github.com/flutter/flutter/issues/76210). None of the issues about newer versions of the camera plugin mention the discrepancy between iOS and android specifically for the `startImageStream` method.

<details>
<summary>Code sample</summary>

Using dependencies:
```yaml
dependencies:
  camera: ^0.9.4+5
```

Below is the minimal code for a test scanner widget to illustrate the issue:
```dart
import 'package:camera/camera.dart';
import 'package:flutter/material.dart';

class TestScanner extends StatefulWidget {
  const TestScanner();

  @override
  _TestScannerState createState() => _TestScannerState();
}

class _TestScannerState extends State<TestScanner> {
  late final CameraDescription _camera;
  CameraController? _controller;

  Future<void> setupCamera() async {
    try {
      _camera = (await availableCameras()).firstWhere((c) => c.lensDirection == CameraLensDirection.back);
      _controller = CameraController(
        _camera,
        ResolutionPreset.high,
        enableAudio: false,
      );
      await _controller?.initialize();
      if (!mounted) {
        return;
      } else {
        setState(() {});
      }
      await _controller?.startImageStream((image) {
        print('Image  | width: ${image.width}, height: ${image.height}');
      });
    } catch (e) {
      print('Camera Exception: $e');
    }
  }

  @override
  void initState() {
    super.initState();
    setupCamera();
  }

  @override
  Widget build(BuildContext context) {
    return Container();
  }

  @override
  void dispose() {
    _controller?.stopImageStream().then((_) {
      _controller?.dispose();
    });
    super.dispose();
  }
}
```

</details>

<details>
  <summary>Logs</summary>

<!--
      Run your application with `flutter run --verbose` and attach all the
      log output below between the lines with the backticks. If there is an
      exception, please see if the error message includes enough information
      to explain how to solve the issue.
-->

Full unfiltered output of running the `TestScanner` widget on the android device for a few seconds.
```
[+2863 ms] I/ViewRootImpl@e56d4bd[MainActivity]( 6453): ViewPostIme pointer 0
[  +55 ms] I/ViewRootImpl@e56d4bd[MainActivity]( 6453): ViewPostIme pointer 1
[ +208 ms] I/Camera  ( 6453): close
[  +10 ms] W/Camera  ( 6453): The selected imageFormatGroup is not supported by Android. Defaulting to yuv420
[  +24 ms] I/CameraManagerGlobal( 6453): Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_OPEN for client com.example API Level 2
[   +5 ms] I/Camera  ( 6453): startPreview
[ +133 ms] I/Camera  ( 6453): CameraCaptureSession onConfigured
[        ] I/Camera  ( 6453): Updating builder settings
[        ] D/Camera  ( 6453): Updating builder with feature: ExposureLockFeature
[        ] D/Camera  ( 6453): Updating builder with feature: ExposurePointFeature
[        ] D/Camera  ( 6453): Updating builder with feature: ZoomLevelFeature
[        ] D/Camera  ( 6453): Updating builder with feature: AutoFocusFeature
[        ] D/Camera  ( 6453): Updating builder with feature: NoiseReductionFeature
[        ] I/Camera  ( 6453): updateNoiseReduction | currentSetting: fast
[        ] D/Camera  ( 6453): Updating builder with feature: FocusPointFeature
[        ] D/Camera  ( 6453): Updating builder with feature: ResolutionFeature
[        ] D/Camera  ( 6453): Updating builder with feature: SensorOrientationFeature
[        ] D/Camera  ( 6453): Updating builder with feature: FlashFeature
[        ] D/Camera  ( 6453): Updating builder with feature: ExposureOffsetFeature
[        ] D/Camera  ( 6453): Updating builder with feature: FpsRangeFeature
[        ] I/Camera  ( 6453): refreshPreviewCaptureSession
[        ] I/Camera  ( 6453): closeCaptureSession
[ +537 ms] I/CameraManagerGlobal( 6453): Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_ACTIVE for client com.example API Level 2
[  +31 ms] I/CameraManagerGlobal( 6453): Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_IDLE for client com.example API Level 2
[ +154 ms] I/Camera  ( 6453): startPreviewWithImageStream
[        ] I/Camera  ( 6453): CameraCaptureSession onConfigured
[        ] I/Camera  ( 6453): Updating builder settings
[        ] W/toryapp.wms.de( 6453): Long monitor contention with owner main (6453) at void android.hardware.camera2.impl.CameraDeviceImpl.waitUntilIdle()(CameraDeviceImpl.java:1283) waiters=0 in void android.hardware.camera2.impl.CameraDeviceImpl$4.run() for 715ms
[        ] D/Camera  ( 6453): Updating builder with feature: ExposureLockFeature
[        ] D/Camera  ( 6453): Updating builder with feature: ExposurePointFeature
[        ] I/Choreographer( 6453): Skipped 43 frames!  The application may be doing too much work on its main thread.
[        ] D/Camera  ( 6453): Updating builder with feature: ZoomLevelFeature
[        ] D/Camera  ( 6453): Updating builder with feature: AutoFocusFeature
[        ] D/Camera  ( 6453): Updating builder with feature: NoiseReductionFeature
[        ] I/Camera  ( 6453): updateNoiseReduction | currentSetting: fast
[        ] D/Camera  ( 6453): Updating builder with feature: FocusPointFeature
[        ] D/Camera  ( 6453): Updating builder with feature: ResolutionFeature
[        ] D/Camera  ( 6453): Updating builder with feature: SensorOrientationFeature
[        ] D/Camera  ( 6453): Updating builder with feature: FlashFeature
[        ] D/Camera  ( 6453): Updating builder with feature: ExposureOffsetFeature
[        ] D/Camera  ( 6453): Updating builder with feature: FpsRangeFeature
[        ] I/Camera  ( 6453): refreshPreviewCaptureSession
[  +17 ms] I/Camera  ( 6453): CameraCaptureSession onClosed
[ +338 ms] I/CameraManagerGlobal( 6453): Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_ACTIVE for client com.example API Level 2
[  +37 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[ +119 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[  +21 ms] W/System  ( 6453): A resource failed to call release.
[  +40 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[  +56 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[  +62 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[  +61 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[  +57 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[  +61 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[  +54 ms] W/System  ( 6453): A resource failed to call release.
[        ] W/System  ( 6453): A resource failed to call release.
[   +8 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[  +55 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[  +58 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[  +70 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[  +48 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[  +58 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[  +65 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[  +58 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[  +56 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[  +64 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[   +4 ms] I/ViewRootImpl@e56d4bd[MainActivity]( 6453): ViewPostIme pointer 0
[  +51 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[  +28 ms] I/ViewRootImpl@e56d4bd[MainActivity]( 6453): ViewPostIme pointer 1
[  +29 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[  +71 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[  +54 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[  +67 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[  +54 ms] I/Camera  ( 6453): startPreview
[        ] I/Camera  ( 6453): closeCaptureSession
[   +3 ms] I/flutter ( 6453): Image  | width: 1280, height: 720
[ +405 ms] I/CameraManagerGlobal( 6453): Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_IDLE for client com.example API Level 2
[ +168 ms] W/toryapp.wms.de( 6453): Long monitor contention with owner main (6453) at void android.hardware.camera2.impl.CameraDeviceImpl.waitUntilIdle()(CameraDeviceImpl.java:1283) waiters=0 in void android.hardware.camera2.impl.CameraDeviceImpl$4.run() for 569ms
[        ] I/Camera  ( 6453): CameraCaptureSession onConfigured
[        ] I/Camera  ( 6453): Updating builder settings
[        ] D/Camera  ( 6453): Updating builder with feature: ExposureLockFeature
[        ] W/toryapp.wms.de( 6453): Long monitor contention with owner main (6453) at void android.hardware.camera2.impl.CameraDeviceImpl.waitUntilIdle()(CameraDeviceImpl.java:1283) waiters=1 in void android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.onCaptureStarted(android.hardware.camera2.impl.CaptureResultExtras, long) for 559ms
[        ] D/Camera  ( 6453): Updating builder with feature: ExposurePointFeature
[        ] D/Camera  ( 6453): Updating builder with feature: ZoomLevelFeature
[        ] D/Camera  ( 6453): Updating builder with feature: AutoFocusFeature
[        ] D/Camera  ( 6453): Updating builder with feature: NoiseReductionFeature
[        ] I/Camera  ( 6453): updateNoiseReduction | currentSetting: fast
[        ] D/Camera  ( 6453): Updating builder with feature: FocusPointFeature
[        ] D/Camera  ( 6453): Updating builder with feature: ResolutionFeature
[        ] D/Camera  ( 6453): Updating builder with feature: SensorOrientationFeature
[        ] D/Camera  ( 6453): Updating builder with feature: FlashFeature
[        ] D/Camera  ( 6453): Updating builder with feature: ExposureOffsetFeature
[        ] D/Camera  ( 6453): Updating builder with feature: FpsRangeFeature
[        ] I/Camera  ( 6453): dispose
[        ] I/Camera  ( 6453): close
[        ] I/Camera  ( 6453): closeCaptureSession
[        ] I/Camera  ( 6453): refreshPreviewCaptureSession
[ +260 ms] W/toryapp.wms.de( 6453): Long monitor contention with owner main (6453) at void android.hardware.camera2.impl.CameraDeviceImpl.close()(CameraDeviceImpl.java:1334) waiters=1 in void android.hardware.camera2.impl.CameraDeviceImpl$CameraDeviceCallbacks.onResultReceived(android.hardware.camera2.impl.CameraMetadataNative, android.hardware.camera2.impl.CaptureResultExtras, android.hardware.camera2.impl.PhysicalCaptureResultInfo[]) for 257ms
[        ] I/Camera  ( 6453): open | onClosed
[   +5 ms] I/Camera  ( 6453): CameraCaptureSession onClosed
[   +1 ms] I/CameraManagerGlobal( 6453): Camera 0 facing CAMERA_FACING_BACK state now CAMERA_STATE_CLOSED for client com.example API Level 2
```

<!--
     Run `flutter analyze` and attach any output of that command below.
     If there are any analysis errors, try resolving them before filing this issue.
-->

```
Analyzing Mobile.nosync...                                              
No issues found! (ran in 7.1s)
```

<!-- Finally, paste the output of running `flutter doctor -v` here. -->

```
[✓] Flutter (Channel stable, 2.5.3, on macOS 11.6 20G165
    darwin-x64, locale en-BE)
    • Flutter version 2.5.3 at /Users/Reinert/.flutter-sdk
    • Upstream repository
      https://github.com/flutter/flutter.git
    • Framework revision 18116933e7 (5 weeks ago),
      2021-10-15 10:46:35 -0700
    • Engine revision d3ea636dc5
    • Dart version 2.14.4

[✓] Android toolchain - develop for Android devices
    (Android SDK version 30.0.2)
    • Android SDK at /Users/Reinert/Library/Android/sdk
    • Platform android-30, build-tools 30.0.2
    • ANDROID_HOME = /Users/Reinert/Library/Android/sdk
    • Java binary at: /Users/Reinert/Library/Application
      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203
      .7784292/Android
      Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      11.0.10+0-b96-7281165)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Xcode 13.0, Build version 13A233
    • CocoaPods version 1.10.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google
      Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2020.3)
    • Android Studio at /Users/Reinert/Library/Application
      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203
      .7784292/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
      11.0.10+0-b96-7281165)

[✓] Android Studio (version 2020.3)
    • Android Studio at /Users/Reinert/Library/Application
      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/203
      .7784292/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
      11.0.10+0-b96-7281165)

[✓] Android Studio (version 3.5)
    • Android Studio at /Users/Reinert/Library/Application
      Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/191
      .5791312/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
      1.8.0_202-release-1483-b49-5587405)

[✓] VS Code (version 1.62.3)
    • VS Code at /Applications/Visual Studio
      Code.app/Contents
    • Flutter extension version 3.28.0

[✓] Connected device (2 available)
    • RedMobile (mobile) • 00008020-00055DE21492002E • ios
      • iOS 15.1 19B74
    • Chrome (web)       • chrome                    •
      web-javascript • Google Chrome 95.0.4638.69
    ! Error: RedMobile is busy: Fetching debug symbols for
      RedMobile. Xcode will continue when RedMobile is
      finished. (code -10)

• No issues found!
```

</details>