(
data: CanvasImageSource | AllowSharedBufferSource | Frame,
init: VideoFrameInit | VideoFrameBufferInit = {},
)
| 127 | constructor(source: CanvasImageSource, init?: VideoFrameInit); |
| 128 | constructor(data: Frame, init?: VideoFrameInit); |
| 129 | constructor( |
| 130 | data: CanvasImageSource | AllowSharedBufferSource | Frame, |
| 131 | init: VideoFrameInit | VideoFrameBufferInit = {}, |
| 132 | ) { |
| 133 | if ( |
| 134 | data instanceof ArrayBuffer |
| 135 | || (typeof SharedArrayBuffer !== 'undefined' && data instanceof SharedArrayBuffer) |
| 136 | || ArrayBuffer.isView(data) |
| 137 | ) { |
| 138 | const bufferInit = init as VideoFrameBufferInit; |
| 139 | |
| 140 | // If init is not a valid VideoFrameBufferInit, throw a TypeError. |
| 141 | if (!isValidVideoFrameBufferInit(bufferInit)) { |
| 142 | throw new TypeError('Invalid VideoFrameBufferInit'); |
| 143 | } |
| 144 | |
| 145 | // Let defaultRect be «[ "x:" → 0, "y" → 0, "width" → init.codedWidth, "height" → init.codedHeight ]». |
| 146 | const defaultRect: DOMRectInit |
| 147 | = { x: 0, y: 0, width: bufferInit.codedWidth, height: bufferInit.codedHeight }; |
| 148 | |
| 149 | // Let overrideRect be undefined. If init.visibleRect exists, assign its value to overrideRect. |
| 150 | const overrideRect = bufferInit.visibleRect; |
| 151 | |
| 152 | // Let parsedRect be the result of running the Parse Visible Rect algorithm. |
| 153 | const parsedRect = ParseVisibleRect( |
| 154 | defaultRect, overrideRect, bufferInit.codedWidth, bufferInit.codedHeight, bufferInit.format, |
| 155 | ); |
| 156 | |
| 157 | // Let optLayout be undefined. If init.layout exists, assign its value to optLayout. |
| 158 | const optLayout = bufferInit.layout; |
| 159 | |
| 160 | // Let combinedLayout be the result of running the Compute Layout and Allocation Size algorithm. |
| 161 | const combinedLayout = ComputeLayoutAndAllocationSize(parsedRect, bufferInit.format, optLayout); |
| 162 | |
| 163 | // If data.byteLength is less than combinedLayout’s allocationSize, throw a TypeError. |
| 164 | const inputByteLength = ArrayBuffer.isView(data) ? data.byteLength : data.byteLength; |
| 165 | if (inputByteLength < combinedLayout.allocationSize) { |
| 166 | throw new TypeError( |
| 167 | `Buffer is too small. Expected at least ${combinedLayout.allocationSize}, got ${inputByteLength}.`, |
| 168 | ); |
| 169 | } |
| 170 | |
| 171 | // Let resource be a new media resource containing a copy of data. |
| 172 | this.data = new BufferFrameResource( |
| 173 | toUint8Array(data).slice(), |
| 174 | combinedLayout.computedLayouts, |
| 175 | ); |
| 176 | |
| 177 | // Let frame be a new VideoFrame object initialized as follows: |
| 178 | this.codedWidth = bufferInit.codedWidth; |
| 179 | this.codedHeight = bufferInit.codedHeight; |
| 180 | |
| 181 | this.visibleRect |
| 182 | = new DOMRectReadOnlyPolyfill(parsedRect.x, parsedRect.y, parsedRect.width, parsedRect.height); |
| 183 | |
| 184 | // Assign the result of running the Parse Rotation algorithm... |
| 185 | // eslint-disable-next-line @stylistic/max-len |
| 186 | // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-member-access |
nothing calls this directly
no test coverage detected