Loading libraries/scrcpy/src/client.ts +7 −4 Original line number Diff line number Diff line Loading @@ -2,9 +2,9 @@ import { Adb, AdbBufferedStream, AdbLegacyShell, AdbShell, DataEventEmitter } fr import { PromiseResolver } from '@yume-chan/async'; import { EventEmitter } from '@yume-chan/event'; import Struct from '@yume-chan/struct'; import { AndroidKeyEventAction, AndroidMotionEventAction, ScrcpyControlMessageType, ScrcpyInjectKeyCodeControlMessage, ScrcpyInjectTextControlMessage, ScrcpyInjectTouchControlMessage } from './message'; import { H264EncodingInfo, ScrcpyOptions } from "./options"; import { ScrcpyInjectScrollControlMessage1_22 } from "./options/1_22"; import type { H264EncodingInfo } from "./decoder"; import { type AndroidKeyEventAction, AndroidMotionEventAction, ScrcpyControlMessageType, ScrcpyInjectKeyCodeControlMessage, ScrcpyInjectTextControlMessage, ScrcpyInjectTouchControlMessage } from './message'; import type { ScrcpyInjectScrollControlMessage1_22, ScrcpyOptions } from "./options"; import { pushServer, PushServerOptions } from "./push-server"; import { decodeUtf8 } from "./utils"; Loading Loading @@ -315,7 +315,10 @@ export class ScrcpyClient { public async pressBackOrTurnOnScreen(action: AndroidKeyEventAction) { const controlStream = this.checkControlStream('pressBackOrTurnOnScreen'); const buffer = this.options!.serializeBackOrScreenOnControlMessage(action, this.device); const buffer = this.options!.serializeBackOrScreenOnControlMessage({ type: ScrcpyControlMessageType.BackOrScreenOn, action, }); if (buffer) { await controlStream.write(buffer); } Loading libraries/scrcpy/src/decoder/common.ts 0 → 100644 +36 −0 Original line number Diff line number Diff line import type { Disposable } from "@yume-chan/event"; import type { AndroidCodecLevel, AndroidCodecProfile } from "../codec"; export interface H264EncodingInfo { profileIndex: number; constraintSet: number; levelIndex: number; encodedWidth: number; encodedHeight: number; cropLeft: number; cropRight: number; cropTop: number; cropBottom: number; croppedWidth: number; croppedHeight: number; } export interface H264Decoder extends Disposable { readonly maxProfile: AndroidCodecProfile; readonly maxLevel: AndroidCodecLevel; readonly renderer: HTMLElement; changeEncoding(size: H264EncodingInfo): void; feedData(data: ArrayBuffer): void; } export interface H264DecoderConstructor { new(): H264Decoder; } libraries/scrcpy/src/decoder/index.ts +1 −20 Original line number Diff line number Diff line import { Disposable } from "@yume-chan/event"; import type { AndroidCodecLevel, AndroidCodecProfile } from "../codec"; import type { H264EncodingInfo } from "../options"; export interface H264Decoder extends Disposable { readonly maxProfile: AndroidCodecProfile; readonly maxLevel: AndroidCodecLevel; readonly renderer: HTMLElement; changeEncoding(size: H264EncodingInfo): void; feedData(data: ArrayBuffer): void; } export interface H264DecoderConstructor { new(): H264Decoder; } export * from './common'; export * from './tinyh264'; export * from './web-codecs'; libraries/scrcpy/src/decoder/tinyh264/index.ts +7 −8 Original line number Diff line number Diff line import { PromiseResolver } from "@yume-chan/async"; import type { H264Decoder } from ".."; import { AndroidCodecLevel, AndroidCodecProfile } from "../../codec"; import type { H264EncodingInfo } from '../../options'; import type { H264Decoder, H264EncodingInfo } from '../common'; import { createTinyH264Wrapper, TinyH264Wrapper } from "./wrapper"; let cachedInitializePromise: Promise<{ YuvBuffer: typeof import('yuv-buffer'), YuvCanvas: typeof import('yuv-canvas').default; }> | undefined; Loading @@ -22,15 +21,15 @@ export class TinyH264Decoder implements H264Decoder { public readonly maxLevel = AndroidCodecLevel.Level4; private _element: HTMLCanvasElement; public get renderer() { return this._element; } private _renderer: HTMLCanvasElement; public get renderer() { return this._renderer; } private _yuvCanvas: import('yuv-canvas').default | undefined; private _initializer: PromiseResolver<TinyH264Wrapper> | undefined; public constructor() { initialize(); this._element = document.createElement('canvas'); this._renderer = document.createElement('canvas'); } public async changeEncoding(size: H264EncodingInfo) { Loading @@ -40,15 +39,15 @@ export class TinyH264Decoder implements H264Decoder { const { YuvBuffer, YuvCanvas } = await initialize(); if (!this._yuvCanvas) { this._yuvCanvas = YuvCanvas.attach(this._element);; this._yuvCanvas = YuvCanvas.attach(this._renderer);; } const { encodedWidth, encodedHeight } = size; const chromaWidth = encodedWidth / 2; const chromaHeight = encodedHeight / 2; this._element.width = size.croppedWidth; this._element.height = size.croppedHeight; this._renderer.width = size.croppedWidth; this._renderer.height = size.croppedHeight; const format = YuvBuffer.format({ width: encodedWidth, height: encodedHeight, Loading libraries/scrcpy/src/decoder/web-codecs/index.ts +7 −8 Original line number Diff line number Diff line import type { ValueOrPromise } from "@yume-chan/struct"; import type { H264Decoder } from ".."; import { AndroidCodecLevel, AndroidCodecProfile } from "../../codec"; import type { H264EncodingInfo } from "../../options"; import type { H264Decoder, H264EncodingInfo } from "../common"; function toHex(value: number) { return value.toString(16).padStart(2, '0').toUpperCase(); Loading @@ -12,16 +11,16 @@ export class WebCodecsDecoder implements H264Decoder { public readonly maxLevel = AndroidCodecLevel.Level5; private _element: HTMLCanvasElement; public get renderer() { return this._element; } private _renderer: HTMLCanvasElement; public get renderer() { return this._renderer; } private context: CanvasRenderingContext2D; private decoder: VideoDecoder; public constructor() { this._element = document.createElement('canvas'); this._renderer = document.createElement('canvas'); this.context = this._element.getContext('2d')!; this.context = this._renderer.getContext('2d')!; this.decoder = new VideoDecoder({ output: (frame) => { this.context.drawImage(frame, 0, 0); Loading @@ -34,8 +33,8 @@ export class WebCodecsDecoder implements H264Decoder { public changeEncoding(encoding: H264EncodingInfo): ValueOrPromise<void> { const { profileIndex, constraintSet, levelIndex } = encoding; this._element.width = encoding.croppedWidth; this._element.height = encoding.croppedHeight; this._renderer.width = encoding.croppedWidth; this._renderer.height = encoding.croppedHeight; // https://www.rfc-editor.org/rfc/rfc6381#section-3.3 // ISO Base Media File Format Name Space Loading Loading
libraries/scrcpy/src/client.ts +7 −4 Original line number Diff line number Diff line Loading @@ -2,9 +2,9 @@ import { Adb, AdbBufferedStream, AdbLegacyShell, AdbShell, DataEventEmitter } fr import { PromiseResolver } from '@yume-chan/async'; import { EventEmitter } from '@yume-chan/event'; import Struct from '@yume-chan/struct'; import { AndroidKeyEventAction, AndroidMotionEventAction, ScrcpyControlMessageType, ScrcpyInjectKeyCodeControlMessage, ScrcpyInjectTextControlMessage, ScrcpyInjectTouchControlMessage } from './message'; import { H264EncodingInfo, ScrcpyOptions } from "./options"; import { ScrcpyInjectScrollControlMessage1_22 } from "./options/1_22"; import type { H264EncodingInfo } from "./decoder"; import { type AndroidKeyEventAction, AndroidMotionEventAction, ScrcpyControlMessageType, ScrcpyInjectKeyCodeControlMessage, ScrcpyInjectTextControlMessage, ScrcpyInjectTouchControlMessage } from './message'; import type { ScrcpyInjectScrollControlMessage1_22, ScrcpyOptions } from "./options"; import { pushServer, PushServerOptions } from "./push-server"; import { decodeUtf8 } from "./utils"; Loading Loading @@ -315,7 +315,10 @@ export class ScrcpyClient { public async pressBackOrTurnOnScreen(action: AndroidKeyEventAction) { const controlStream = this.checkControlStream('pressBackOrTurnOnScreen'); const buffer = this.options!.serializeBackOrScreenOnControlMessage(action, this.device); const buffer = this.options!.serializeBackOrScreenOnControlMessage({ type: ScrcpyControlMessageType.BackOrScreenOn, action, }); if (buffer) { await controlStream.write(buffer); } Loading
libraries/scrcpy/src/decoder/common.ts 0 → 100644 +36 −0 Original line number Diff line number Diff line import type { Disposable } from "@yume-chan/event"; import type { AndroidCodecLevel, AndroidCodecProfile } from "../codec"; export interface H264EncodingInfo { profileIndex: number; constraintSet: number; levelIndex: number; encodedWidth: number; encodedHeight: number; cropLeft: number; cropRight: number; cropTop: number; cropBottom: number; croppedWidth: number; croppedHeight: number; } export interface H264Decoder extends Disposable { readonly maxProfile: AndroidCodecProfile; readonly maxLevel: AndroidCodecLevel; readonly renderer: HTMLElement; changeEncoding(size: H264EncodingInfo): void; feedData(data: ArrayBuffer): void; } export interface H264DecoderConstructor { new(): H264Decoder; }
libraries/scrcpy/src/decoder/index.ts +1 −20 Original line number Diff line number Diff line import { Disposable } from "@yume-chan/event"; import type { AndroidCodecLevel, AndroidCodecProfile } from "../codec"; import type { H264EncodingInfo } from "../options"; export interface H264Decoder extends Disposable { readonly maxProfile: AndroidCodecProfile; readonly maxLevel: AndroidCodecLevel; readonly renderer: HTMLElement; changeEncoding(size: H264EncodingInfo): void; feedData(data: ArrayBuffer): void; } export interface H264DecoderConstructor { new(): H264Decoder; } export * from './common'; export * from './tinyh264'; export * from './web-codecs';
libraries/scrcpy/src/decoder/tinyh264/index.ts +7 −8 Original line number Diff line number Diff line import { PromiseResolver } from "@yume-chan/async"; import type { H264Decoder } from ".."; import { AndroidCodecLevel, AndroidCodecProfile } from "../../codec"; import type { H264EncodingInfo } from '../../options'; import type { H264Decoder, H264EncodingInfo } from '../common'; import { createTinyH264Wrapper, TinyH264Wrapper } from "./wrapper"; let cachedInitializePromise: Promise<{ YuvBuffer: typeof import('yuv-buffer'), YuvCanvas: typeof import('yuv-canvas').default; }> | undefined; Loading @@ -22,15 +21,15 @@ export class TinyH264Decoder implements H264Decoder { public readonly maxLevel = AndroidCodecLevel.Level4; private _element: HTMLCanvasElement; public get renderer() { return this._element; } private _renderer: HTMLCanvasElement; public get renderer() { return this._renderer; } private _yuvCanvas: import('yuv-canvas').default | undefined; private _initializer: PromiseResolver<TinyH264Wrapper> | undefined; public constructor() { initialize(); this._element = document.createElement('canvas'); this._renderer = document.createElement('canvas'); } public async changeEncoding(size: H264EncodingInfo) { Loading @@ -40,15 +39,15 @@ export class TinyH264Decoder implements H264Decoder { const { YuvBuffer, YuvCanvas } = await initialize(); if (!this._yuvCanvas) { this._yuvCanvas = YuvCanvas.attach(this._element);; this._yuvCanvas = YuvCanvas.attach(this._renderer);; } const { encodedWidth, encodedHeight } = size; const chromaWidth = encodedWidth / 2; const chromaHeight = encodedHeight / 2; this._element.width = size.croppedWidth; this._element.height = size.croppedHeight; this._renderer.width = size.croppedWidth; this._renderer.height = size.croppedHeight; const format = YuvBuffer.format({ width: encodedWidth, height: encodedHeight, Loading
libraries/scrcpy/src/decoder/web-codecs/index.ts +7 −8 Original line number Diff line number Diff line import type { ValueOrPromise } from "@yume-chan/struct"; import type { H264Decoder } from ".."; import { AndroidCodecLevel, AndroidCodecProfile } from "../../codec"; import type { H264EncodingInfo } from "../../options"; import type { H264Decoder, H264EncodingInfo } from "../common"; function toHex(value: number) { return value.toString(16).padStart(2, '0').toUpperCase(); Loading @@ -12,16 +11,16 @@ export class WebCodecsDecoder implements H264Decoder { public readonly maxLevel = AndroidCodecLevel.Level5; private _element: HTMLCanvasElement; public get renderer() { return this._element; } private _renderer: HTMLCanvasElement; public get renderer() { return this._renderer; } private context: CanvasRenderingContext2D; private decoder: VideoDecoder; public constructor() { this._element = document.createElement('canvas'); this._renderer = document.createElement('canvas'); this.context = this._element.getContext('2d')!; this.context = this._renderer.getContext('2d')!; this.decoder = new VideoDecoder({ output: (frame) => { this.context.drawImage(frame, 0, 0); Loading @@ -34,8 +33,8 @@ export class WebCodecsDecoder implements H264Decoder { public changeEncoding(encoding: H264EncodingInfo): ValueOrPromise<void> { const { profileIndex, constraintSet, levelIndex } = encoding; this._element.width = encoding.croppedWidth; this._element.height = encoding.croppedHeight; this._renderer.width = encoding.croppedWidth; this._renderer.height = encoding.croppedHeight; // https://www.rfc-editor.org/rfc/rfc6381#section-3.3 // ISO Base Media File Format Name Space Loading