MCPcopy Create free account
hub / github.com/Vanilagy/webcodecs-polyfill / InitializeFrameWithResource

Function InitializeFrameWithResource

src/video_frame.ts:944–1011  ·  view source on GitHub ↗
(
	init: VideoFrameInit,
	frame: VideoFramePolyfill,
	resource: Frame,
	codedWidth: number,
	codedHeight: number,
	baseRotation: number,
	baseFlip: boolean,
	defaultDisplayWidth: number,
	defaultDisplayHeight: number,
	timestamp: number,
)

Source from the content-addressed store, hash-verified

942};
943
944const InitializeFrameWithResource = (
945 init: VideoFrameInit,
946 frame: VideoFramePolyfill,
947 resource: Frame,
948 codedWidth: number,
949 codedHeight: number,
950 baseRotation: number,
951 baseFlip: boolean,
952 defaultDisplayWidth: number,
953 defaultDisplayHeight: number,
954 timestamp: number,
955) => {
956 // 1. Let format be null.
957 let format: VideoPixelFormat | null = null;
958 // 2. If resource uses a recognized VideoPixelFormat, assign that format.
959 format = toPixelFormat(resource.format as AVPixelFormat) as VideoPixelFormat;
960
961 // 3. Let validInit be the result of running the Validate VideoFrameInit algorithm.
962 if (!ValidateVideoFrameInit(init, format, codedWidth, codedHeight)) {
963 throw new TypeError('Invalid VideoFrameInit');
964 }
965
966 // 4. Assign a new reference for resource to frame’s [[resource reference]].
967 frame.data = resource;
968
969 // 5. If init.alpha is discard, assign format’s equivalent opaque format to format.
970 if (init.alpha === 'discard' && format) {
971 format = getEquivalentOpaqueFormat(format) as VideoPixelFormat;
972 }
973
974 // 6. Assign format to [[format]].
975 // @ts-expect-error Write to readonly
976 frame.format = format;
977 // 7. Assign codedWidth and codedHeight...
978 // @ts-expect-error Write to readonly
979 frame.codedWidth = codedWidth;
980 // @ts-expect-error Write to readonly
981 frame.codedHeight = codedHeight;
982
983 // 8. Let defaultVisibleRect be a new DOMRect...
984 const defaultVisibleRect = new DOMRectReadOnlyPolyfill(0, 0, codedWidth, codedHeight);
985
986 // 9. Run the Initialize Visible Rect, Orientation, and Display Size algorithm.
987 InitializeVisibleRectOrientationAndDisplaySize(
988 init, frame, defaultVisibleRect, baseRotation, baseFlip, defaultDisplayWidth, defaultDisplayHeight,
989 );
990
991 // 10. Assign init.duration to frame's [[duration]].
992 // @ts-expect-error Write to readonly
993 frame.duration = init.duration != null ? Math.trunc(init.duration) : null;
994
995 // 11. Assign init.timestamp to frame's [[timestamp]].
996 // @ts-expect-error Write to readonly
997 frame.timestamp = Math.trunc(timestamp);
998
999 // 12. If resource has a known VideoColorSpace, assign its value...
1000 // @ts-expect-error Write to readonly
1001 frame.colorSpace = new VideoColorSpacePolyfill({

Callers 1

constructorMethod · 0.85

Calls 7

toPixelFormatFunction · 0.85
ValidateVideoFrameInitFunction · 0.85
unmapColorPrimariesFunction · 0.85
unmapMatrixCoefficientsFunction · 0.85

Tested by

no test coverage detected