flutter surface crop bug

Open
#1,402 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
18/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
android, java

Research direction

The report concerns the Android VideoOutput class, which requests a surface producer from Flutter's TextureRegistry, and the workaround that reflectively builds a legacy SurfaceTextureSurfaceProducer in place of ImageReaderSurfaceProducer. Start by reproducing the green edge on a cropped or rotated video, then check how the surface producer type changes crop and rotation handling. Done means the crop and rotation render correctly without reflection, or the reflective workaround is confirmed as the supported path.

Written by the indexing model from the issue text.

Description

flutter's new renderer FlutterRenderer.createSurfaceProducer now return ImageReaderSurfaceProducer. this new surface producer do NOT process crop & rotation properly. some video report crop & rotation to surface, but not correctly processed, leave 'green edge' on video output.

my workaround:

    VideoOutput(TextureRegistry textureRegistryReference, TextureUpdateCallback textureUpdateCallback) {
        this.textureUpdateCallback = textureUpdateCallback;

        surfaceProducer = createSurfaceProducer(textureRegistryReference);
        surfaceProducer.setCallback(this);
    }

    static TextureRegistry.SurfaceProducer createSurfaceProducer(TextureRegistry textureRegistryReference) {
        if (textureRegistryReference instanceof FlutterRenderer) {
            try {
                return createSurfaceProducerFromRenderer((FlutterRenderer) textureRegistryReference);
            } catch (Throwable e) {
                Log.i(TAG, "create surface producer from FlutterRenderer failed", e);
            }
        } else {
            Log.i(TAG, "textureRegistryReference is not FlutterRenderer");
        }
        return textureRegistryReference.createSurfaceProducer();
    }

    static TextureRegistry.SurfaceProducer createSurfaceProducerFromRenderer(FlutterRenderer renderer) throws NoSuchFieldException, IllegalAccessException, ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException {
        final Field flutterJNIField = FlutterRenderer.class.getDeclaredField("flutterJNI");
        final Field handlerField = FlutterRenderer.class.getDeclaredField("handler");
        final Class<?> surfaceTextureSurfaceProducerType = Class.forName("io.flutter.embedding.engine.renderer.SurfaceTextureSurfaceProducer");
        Constructor<?> surfaceTextureSurfaceProducerConstructor = surfaceTextureSurfaceProducerType.getDeclaredConstructor(
                long.class,
                Handler.class,
                FlutterJNI.class,
                TextureRegistry.SurfaceTextureEntry.class);

        flutterJNIField.setAccessible(true);
        handlerField.setAccessible(true);
        surfaceTextureSurfaceProducerConstructor.setAccessible(true);

        FlutterJNI flutterJNI = (FlutterJNI) flutterJNIField.get(renderer);
        Handler handler = (Handler) handlerField.get(renderer);

        TextureRegistry.SurfaceTextureEntry texture = renderer.createSurfaceTexture();
        TextureRegistry.SurfaceProducer producer = (TextureRegistry.SurfaceProducer) surfaceTextureSurfaceProducerConstructor.newInstance(texture.id(), handler, flutterJNI, texture);
        Log.d(TAG, "create legacy surface producer from flutter renderer");
        return producer;
    }
Dominant language
Dart
Stars
1.9k
Forks
530
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from media-kit/media-kit

All issues in media-kit/media-kit

Similar issues

More Dart issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.