Skip to content

Commit

Permalink
chore: optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
guoxianzhe committed Dec 18, 2024
1 parent 0526a92 commit 70ae97f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
IRtcEngineEventHandler,
IRtcEngineEx,
LogFilterType,
RenderModeType,
RtcConnection,
RtcStats,
VideoSourceType,
Expand Down Expand Up @@ -195,6 +196,7 @@ export default class VideoDecoder
useWebCodecsDecoder: true,
enableFps: true,
sourceType: VideoSourceType.VideoSourceRemote,
renderMode: RenderModeType.RenderModeFit,
})
)
: undefined}
Expand All @@ -206,6 +208,7 @@ export default class VideoDecoder
useWebCodecsDecoder: true,
enableFps: true,
sourceType: VideoSourceType.VideoSourceRemote,
renderMode: RenderModeType.RenderModeFit,
})
)
: undefined}
Expand Down
18 changes: 2 additions & 16 deletions ts/Renderer/WebCodecsRenderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ export class WebCodecsRenderer extends IRenderer {
if (!this.offscreenCanvas || !frame) return;
this.updateRenderMode();
this.rotateCanvas({
width: _codecConfig.codedWidth,
height: _codecConfig.codedHeight,
rotation: _codecConfig.rotation,
});
if (!this.gl) return;
Expand All @@ -127,7 +125,7 @@ export class WebCodecsRenderer extends IRenderer {
this.gl.drawingBufferWidth,
this.gl.drawingBufferHeight
);
this.gl.clearColor(1.0, 0.0, 0.0, 1.0);
this.gl.clearColor(0.0, 0.0, 0.0, 0.0);
this.gl.clear(this.gl.COLOR_BUFFER_BIT);
// Draw the frame.
this.gl.drawArrays(this.gl.TRIANGLE_FAN, 0, 4);
Expand All @@ -136,20 +134,8 @@ export class WebCodecsRenderer extends IRenderer {
this.getFps();
}

protected override rotateCanvas({ width, height, rotation }: VideoFrame) {
protected override rotateCanvas({ rotation }: VideoFrame) {
if (!this.offscreenCanvas || !this.canvas) return;

if (rotation === 0 || rotation === 180) {
this.offscreenCanvas.width = width!;
this.offscreenCanvas.height = height!;
} else if (rotation === 90 || rotation === 270) {
this.offscreenCanvas.height = width!;
this.offscreenCanvas.width = height!;
} else {
throw new Error(
`Invalid rotation: ${rotation}, only 0, 90, 180, 270 are supported`
);
}
this.canvas.style.transform += ` rotateZ(${rotation}deg)`;
}
}

0 comments on commit 70ae97f

Please sign in to comment.