Skip to content

[camera_android_camerax] Add support for NV21 image format #9644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

camsim99
Copy link
Contributor

...wip :) might not even compile yet tbh

Fixes flutter/flutter#145961.

Pre-Review Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

Footnotes

  1. Regular contributors who have demonstrated familiarity with the repository guidelines only need to comment if the PR is not auto-exempted by repo tooling. 2 3

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for the NV21 image format in the Android CameraX implementation. This is achieved by adding a new Java utility class to perform the YUV_420_888 to NV21 conversion, and exposing it to Dart via Pigeon. The changes in the Dart layer correctly use this new utility when the camera is initialized for NV21 image streaming.

My review focuses on several critical issues that will prevent the code from compiling, such as incorrect package names, missing imports, and typos in the new Java files. I've also pointed out an incorrect configuration in the Pigeon file. Addressing these points will be necessary to get the PR into a mergeable state.

// Note: the code in this file is taken directly from the official Google MLKit example:
// https://github.com/googlesamples/mlkit

package io.flutter.plugins.camera.media;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The package declaration io.flutter.plugins.camera.media does not match the file's directory structure. To ensure the class is correctly resolved and to maintain consistency, it should be io.flutter.plugins.camerax.

Suggested change
package io.flutter.plugins.camera.media;
package io.flutter.plugins.camerax;

Comment on lines +10 to +12
import android.media.Image;
import androidx.annotation.NonNull;
import java.nio.ByteBuffer;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This file is missing imports for List and PlaneProxy, which will cause compilation errors.

Suggested change
import android.media.Image;
import androidx.annotation.NonNull;
import java.nio.ByteBuffer;
import android.media.Image;
import androidx.annotation.NonNull;
import androidx.camera.core.ImageProxy.PlaneProxy;
import java.nio.ByteBuffer;
import java.util.List;

Comment on lines +7 to +8
import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.annotation.NonNull;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This file is missing imports for java.util.List and java.nio.ByteBuffer, which will cause compilation errors.

import androidx.camera.core.ImageProxy.PlaneProxy;
import androidx.annotation.NonNull;
import java.nio.ByteBuffer;
import java.util.List;


@NonNull
@Override
public bytes[] getNv21Plane(@NonNull List<PlaneProxy> planeProxyList, long imageWidth, long imageHeight) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The return type bytes[] is not a valid Java type. This should be byte[] to match the expected type for image data buffers.

  public byte[] getNv21Plane(@NonNull List<PlaneProxy> planeProxyList, long imageWidth, long imageHeight) {

/// TODO(camsim99)
@ProxyApi(
kotlinOptions: KotlinProxyApiOptions(
fullClassName: 'androidx.camera.core.PlaneProxyUtils',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The fullClassName androidx.camera.core.PlaneProxyUtils appears to be incorrect, as this class does not exist in the AndroidX library. This should point to the new native utility class you've added, which is io.flutter.plugins.camerax.PlaneProxyUtils.

    fullClassName: 'io.flutter.plugins.camerax.PlaneProxyUtils',

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[camera_android_camerax] Cannot set imageFormatGroup to ImageFormatGroup.nv21
1 participant