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

Unverified Commit f25bfd89 authored by Simon Chan's avatar Simon Chan
Browse files

feat(scrcpy): support new list encoders format

parent cc5d5291
Loading
Loading
Loading
Loading
+11 −21
Original line number Diff line number Diff line
import type { ScrcpyEncoder } from "../../base/index.js";

export function parseEncoder(line: string): ScrcpyEncoder | undefined {
    let match = line.match(
        /^\s+--video-codec=(\S+)\s+--video-encoder='([^']+)'$/,
    );
    if (match) {
        return {
            type: "video",
            codec: match[1]!,
            name: match[2]!,
        };
    }
const EncoderRegex =
    /^\s+--(video|audio)-codec=(\S+)\s+--\1-encoder='([^']+)'$/;

    match = line.match(/^\s+--audio-codec=(\S+)\s+--audio-encoder='([^']+)'$/);
    if (match) {
        return {
            type: "audio",
            codec: match[1]!,
            name: match[2]!,
        };
export function parseEncoder(line: string): ScrcpyEncoder | undefined {
    const match = line.match(EncoderRegex);
    return match
        ? {
              type: match[1]! as "video" | "audio",
              name: match[3]!,
              codec: match[2]!,
          }

    return undefined;
        : undefined;
}
+2 −1
Original line number Diff line number Diff line
@@ -6,5 +6,6 @@ export {
    LockOrientation,
    NewDisplay,
    Orientation,
    type Init,
} from "./init.js";
export type { Init } from "./init.js";
export { parseEncoder } from "./parse-encoder.js";
+31 −0
Original line number Diff line number Diff line
import type { ScrcpyEncoder } from "../../base/index.js";

const EncoderRegex =
    /^\s+--(video|audio)-codec=(\S+)\s+--\1-encoder=(\S+)(?:\s*\((sw|hw|hybrid)\))?(?:\s*\[vendor\])?(?:\s*\(alias for (\S+)\))?$/;

function toHardwareType(value: string): ScrcpyEncoder["hardwareType"] {
    switch (value) {
        case "sw":
            return "software";
        case "hw":
            return "hardware";
        case "hybrid":
            return "hybrid";
        default:
            throw new Error(`Unknown hardware type: ${value}`);
    }
}

export function parseEncoder(line: string): ScrcpyEncoder | undefined {
    const match = line.match(EncoderRegex);
    return match
        ? {
              type: match[1]! as "video" | "audio",
              name: match[3]!,
              codec: match[2]!,
              hardwareType: match[4] ? toHardwareType(match[4]) : undefined,
              vendor: !!match[5],
              aliasFor: match[6],
          }
        : undefined;
}
+4 −1
Original line number Diff line number Diff line
export interface ScrcpyEncoder {
    type: "video" | "audio";
    codec?: string;
    name: string;
    codec?: string;
    hardwareType?: "hardware" | "software" | "hybrid" | undefined;
    vendor?: boolean | undefined;
    aliasFor?: string | undefined;
}