Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 5c3048ee authored by Simon Chan's avatar Simon Chan
Browse files

feat(scrcpy): support types of codec options

parent 655c2832
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ const useClasses = makeStyles({
    },
    hex: {
        marginLeft: '40px',
        fontVariantLigatures: 'none',
    },
});

+21 −1
Original line number Diff line number Diff line
@@ -288,6 +288,8 @@ class ScrcpyPageState {
        Constructor: TinyH264Decoder,
    }];
    decoder: H264Decoder | undefined = undefined;
    fpsCounterIntervalId: any = undefined;
    fps = 0;

    displays: number[] = [];
    updateDisplays = async () => {
@@ -388,6 +390,14 @@ class ScrcpyPageState {
            },
        });

        if (this.running) {
            result.push({
                key: 'fps',
                text: `FPS: ${this.fps}`,
                disabled: true,
            });
        }

        return result;
    }

@@ -723,8 +733,15 @@ class ScrcpyPageState {

            const decoderDefinition = this.decoders.find(x => x.key === this.settings.decoder) ?? this.decoders[0];
            const decoder = new decoderDefinition.Constructor();

            runInAction(() => {
                this.decoder = decoder;

                let lastFrameCount = 0;
                this.fpsCounterIntervalId = setInterval(action(() => {
                    this.fps = decoder.frameRendered - lastFrameCount;
                    lastFrameCount = decoder.frameRendered;
                }), 1000);
            });

            const options = new ScrcpyOptions1_24({
@@ -802,6 +819,9 @@ class ScrcpyPageState {
        this.decoder?.dispose();
        this.decoder = undefined;

        this.fps = 0;
        clearTimeout(this.fpsCounterIntervalId);

        this.client = undefined;
        this.running = false;
    }
+90 −89
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ Scrcpy server has no backward compatibility on options input format. Currently t
| 1.21      | `ScrcpyOptions1_21` |
| 1.22      | `ScrcpyOptions1_22` |
| 1.23      | `ScrcpyOptions1_23` |
| 1.24      | `ScrcpyOptions1_24` |

You must use the correct type according to the server version.

+345 −330
Original line number Diff line number Diff line
@@ -27,10 +27,22 @@ export enum ScrcpyVideoOrientation {

export interface CodecOptionsInit {
    profile: AndroidCodecProfile;

    level: AndroidCodecLevel;

    iFrameInterval: number;
    repeatPreviousFrameAfter: number;
    maxPtsGapToEncoder: number;
}

function toDashCase(input: string) {
    return input.replace(/([A-Z])/g, '-$1').toLowerCase();
}

const CODEC_OPTION_TYPES: Partial<Record<keyof CodecOptionsInit, 'long' | 'float' | 'string'>> = {
    repeatPreviousFrameAfter: 'long',
    maxPtsGapToEncoder: 'long',
};

export class CodecOptions implements ScrcpyOptionValue {
    public value: Partial<CodecOptionsInit>;

@@ -47,7 +59,10 @@ export class CodecOptions implements ScrcpyOptionValue {
        }

        return entries
            .map(([key, value]) => `${key}=${value}`)
            .map(([key, value]) => {
                const type = CODEC_OPTION_TYPES[key as keyof CodecOptionsInit];
                return `${toDashCase(key)}${type ? `:${type}` : ''}=${value}`;
            })
            .join(',');
    }
}