Screen recorder app is throwing error on Custom Rom

Viewed 184

I am quite new to Android Custom Rom development. I am wondering about checking what seems to be the issue on the codec itself. I have the debug log and a copy of the app itself, however there's no way for me to like change an app source code manually when it's installed already.

I am currently on an Android 12 GSI which I am trying to modify some files and make it work on another device.

Here's the debug log:

10-24 03:57:39.788 24987 24987 D RecordingService: onStartCommand com.android.systemui.screenrecord.START
10-24 03:57:39.788 24987 24987 D RecordingService: recording with audio sourceNONE
10-24 03:57:39.790 24987 24987 D ScreenMediaRecorder: start recording
10-24 03:57:39.792 1479 1508 I InputManager-JNI: Setting show touches feature to disabled.
10-24 03:57:39.795 1479 1601 I InputReader: Reconfiguring input devices, changes=SHOW_TOUCHES |
10-24 03:57:39.798 1035 1203 W StagefrightRecorder: stop while neither recording nor paused
10-24 03:57:39.811 24987 24987 W System.err: java.lang.IllegalArgumentException: unsupported size
10-24 03:57:39.811 24987 24987 W System.err: at android.media.MediaCodecInfo$VideoCapabilities.getSupportedFrameRatesFor(MediaCodecInfo.java:1676)
10-24 03:57:39.811 24987 24987 W System.err: at com.android.systemui.screenrecord.ScreenMediaRecorder.getSupportedSize(ScreenMediaRecorder.java:254)
10-24 03:57:39.811 24987 24987 W System.err: at com.android.systemui.screenrecord.ScreenMediaRecorder.prepare(ScreenMediaRecorder.java:130)
10-24 03:57:39.811 24987 24987 W System.err: at com.android.systemui.screenrecord.ScreenMediaRecorder.start(ScreenMediaRecorder.java:270)
10-24 03:57:39.811 24987 24987 W System.err: at com.android.systemui.screenrecord.RecordingService.startRecording(RecordingService.java:235)
10-24 03:57:39.811 24987 24987 W System.err: at com.android.systemui.screenrecord.RecordingService.onStartCommand(RecordingService.java:146)
10-24 03:57:39.812 24987 24987 W System.err: at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4643)
10-24 03:57:39.812 24987 24987 W System.err: at android.app.ActivityThread.access$2000(ActivityThread.java:247)
10-24 03:57:39.812 24987 24987 W System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2095)
10-24 03:57:39.812 24987 24987 W System.err: at android.os.Handler.dispatchMessage(Handler.java:106)
10-24 03:57:39.812 24987 24987 W System.err: at android.os.Looper.loopOnce(Looper.java:201)
10-24 03:57:39.812 24987 24987 W System.err: at android.os.Looper.loop(Looper.java:288)
10-24 03:57:39.812 24987 24987 W System.err: at android.app.ActivityThread.main(ActivityThread.java:7842)
10-24 03:57:39.812 24987 24987 W System.err: at java.lang.reflect.Method.invoke(Native Method)
10-24 03:57:39.812 24987 24987 W System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)

Totally unrelated but I am looking into same problem with scrcpy which is a screen mirroring tool on multiplatform for pcs. Went onto the same recording issue until I change manually the encoder by defaulting it to use 'c2.android.avc.encoder'.

I have only a debug log but I don't have a way of tracing the said 'unsupported size'. I went on the google source code and looked at it exactly here:

android.media.MediaCodecInfo$VideoCapabilities.getSupportedFrameRatesFor(MediaCodecInfo.java:1676)

and found this Function:

private int[] getSupportedSize(final int screenWidth, final int screenHeight, int refreshRate) {
        double maxScale = 0;
        MediaCodecList codecList = new MediaCodecList(MediaCodecList.REGULAR_CODECS);
        MediaCodecInfo.VideoCapabilities maxInfo = null;
        for (MediaCodecInfo codec : codecList.getCodecInfos()) {
            String videoType = MediaFormat.MIMETYPE_VIDEO_AVC;
            String[] types = codec.getSupportedTypes();
            for (String t : types) {
                if (!t.equalsIgnoreCase(videoType)) {
                    continue;
                }
                MediaCodecInfo.CodecCapabilities capabilities =
                        codec.getCapabilitiesForType(videoType);
                if (capabilities != null && capabilities.getVideoCapabilities() != null) {
                    MediaCodecInfo.VideoCapabilities vc = capabilities.getVideoCapabilities();
                    int width = vc.getSupportedWidths().getUpper();
                    int height = vc.getSupportedHeights().getUpper();
                    int screenWidthAligned = screenWidth;
                    if (screenWidthAligned % vc.getWidthAlignment() != 0) {
                        screenWidthAligned -= (screenWidthAligned % vc.getWidthAlignment());
                    }
                    int screenHeightAligned = screenHeight;
                    if (screenHeightAligned % vc.getHeightAlignment() != 0) {
                        screenHeightAligned -= (screenHeightAligned % vc.getHeightAlignment());
                    }
                    if (width >= screenWidthAligned && height >= screenHeightAligned
                            && vc.isSizeSupported(screenWidthAligned, screenHeightAligned)) {
                        // Desired size is supported, now get the rate
                        int maxRate = vc.getSupportedFrameRatesFor(screenWidthAligned,
                                screenHeightAligned).getUpper().intValue();
                        if (maxRate < refreshRate) {
                            refreshRate = maxRate;
                        }
                        Log.d(TAG, "Screen size supported at rate " + refreshRate);
                        return new int[]{screenWidthAligned, screenHeightAligned, refreshRate};
                    }
                    // Otherwise, continue searching
                    double scale = Math.min(((double) width / screenWidth),
                            ((double) height / screenHeight));
                    if (scale > maxScale) {
                        maxScale = Math.min(1, scale);
                        maxInfo = vc;
                    }
                }
            }
        }
        // Resize for max supported size
        int scaledWidth = (int) (screenWidth * maxScale);
        int scaledHeight = (int) (screenHeight * maxScale);
        if (scaledWidth % maxInfo.getWidthAlignment() != 0) {
            scaledWidth -= (scaledWidth % maxInfo.getWidthAlignment());
        }
        if (scaledHeight % maxInfo.getHeightAlignment() != 0) {
            scaledHeight -= (scaledHeight % maxInfo.getHeightAlignment());
        }
        // Find max supported rate for size
        int maxRate = maxInfo.getSupportedFrameRatesFor(scaledWidth, scaledHeight)
                .getUpper().intValue();
        if (maxRate < refreshRate) {
            refreshRate = maxRate;
        }
        Log.d(TAG, "Resized by " + maxScale + ": " + scaledWidth + ", " + scaledHeight
                + ", " + refreshRate);
        return new int[]{scaledWidth, scaledHeight, refreshRate};
    }

So where can I start probing the error causing the unsupported size error?

0 Answers
Related