Skip to content

Commit

Permalink
chore: reconfig when width and height changed
Browse files Browse the repository at this point in the history
  • Loading branch information
guoxianzhe committed May 9, 2024
1 parent afce122 commit 95047cb
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions ts/Decoder/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ export class WebCodecsDecoder {
private renderers: WebCodecsRenderer[] = [];
private _cacheContext: RendererCacheContext;
private pendingFrame: VideoFrame | null = null;
private _currentCodecType: VideoCodecType | undefined;
private _currentCodecConfig: {
codecType: VideoCodecType | undefined;
codedWidth: number | undefined;
codedHeight: number | undefined;
} | null = null;

private _base_ts = 0;
private _base_ts_ntp = 1;
Expand Down Expand Up @@ -81,7 +85,11 @@ export class WebCodecsDecoder {
'codec is not in frameCodecMapping,failed to configure decoder, fallback to native decoder'
);
}
this._currentCodecType = frameInfo.codecType;
this._currentCodecConfig = {
codecType: frameInfo.codecType,
codedWidth: frameInfo.width,
codedHeight: frameInfo.height,
};
this._decoder!.configure({
codec: codec,
codedWidth: frameInfo.width,
Expand Down Expand Up @@ -109,7 +117,11 @@ export class WebCodecsDecoder {
}

handleCodecIsChanged(frameInfo: EncodedVideoFrameInfo) {
if (this._currentCodecType !== frameInfo.codecType) {
if (
this._currentCodecConfig?.codecType !== frameInfo.codecType ||
this._currentCodecConfig?.codedWidth !== frameInfo.width ||
this._currentCodecConfig?.codedHeight !== frameInfo.height
) {
logInfo('codecType is changed, reconfigure decoder');
this._decoder.reset();
this.decoderConfigure(frameInfo);
Expand Down

0 comments on commit 95047cb

Please sign in to comment.