* Copies the frame's pixel data to a destination buffer. Returns the layout of the planes in the destination * buffer.
(destination: AllowSharedBufferSource, options: VideoFrameCopyToOptions = {})
| 288 | * buffer. |
| 289 | */ |
| 290 | async copyTo(destination: AllowSharedBufferSource, options: VideoFrameCopyToOptions = {}): Promise<PlaneLayout[]> { |
| 291 | // 1. If [[Detached]] is true, return a promise rejected with a InvalidStateError DOMException. |
| 292 | this.ensureNotClosed(); |
| 293 | |
| 294 | // 2. If [[format]] is null, return a promise rejected with a NotSupportedError DOMException. |
| 295 | if (this.format === null) { |
| 296 | throw new Error('NotSupportedError: VideoFrame format is null'); |
| 297 | } |
| 298 | |
| 299 | // 3. Let combinedLayout be the result of running the Parse VideoFrameCopyToOptions algorithm with options. |
| 300 | const combinedLayout = ParseVideoFrameCopyToOptions(this, options); |
| 301 | |
| 302 | // 4. If destination.byteLength is less than combinedLayout’s allocationSize, return a promise rejected with |
| 303 | // // eslint-disable-next-line @stylistic/max-len |
| 304 | const destBytes = toUint8Array(destination); |
| 305 | if (destBytes.byteLength < combinedLayout.allocationSize) { |
| 306 | throw new TypeError( |
| 307 | `Destination buffer too small. Required: ${combinedLayout.allocationSize},` |
| 308 | + ` Available: ${destBytes.byteLength}`, |
| 309 | ); |
| 310 | } |
| 311 | |
| 312 | // 5. If options.format is equal to one of RGBA, RGBX, BGRA, BGRX then: |
| 313 | if (options.format && ['RGBA', 'RGBX', 'BGRA', 'BGRX'].includes(options.format)) { |
| 314 | // Let newOptions be the result of running the Clone Configuration algorithm with options. |
| 315 | // Assign undefined to newOptions.format. |
| 316 | const newOptions = { ...options }; |
| 317 | delete newOptions.format; |
| 318 | |
| 319 | // Let rgbFrame be the result of running the Convert to RGB frame algorithm with this, options.format, |
| 320 | // and options.colorSpace. |
| 321 | const rgbFrame = await ConvertToRGBFrame(this, options.format, options.colorSpace); |
| 322 | |
| 323 | // Return the result of calling copyTo() on rgbFrame with destination and newOptions. |
| 324 | try { |
| 325 | const result = await rgbFrame.copyTo(destination, newOptions); |
| 326 | rgbFrame.close(); |
| 327 | return result; |
| 328 | } catch (e) { |
| 329 | rgbFrame.close(); |
| 330 | throw e; |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | // 6. Let p be a new Promise. (Implicit) |
| 335 | // 7. Let copyStepsQueue be the result of starting a new parallel queue. (Implicit) |
| 336 | // 8. Let planeLayouts be a new list. |
| 337 | const planeLayouts: PlaneLayout[] = []; |
| 338 | |
| 339 | // Enqueue the following steps to copyStepsQueue: (fuck the queuing part) |
| 340 | |
| 341 | // Let resource be the media resource referenced by [[resource reference]]. |
| 342 | // (this.data) |
| 343 | |
| 344 | // Let numPlanes be the number of planes as defined by [[format]]. |
| 345 | const info = getPixelFormatInfo(this.format); |
| 346 | if (!info) throw new TypeError('Unknown format'); |
| 347 | const numPlanes = info.planes.length; |
nothing calls this directly
no test coverage detected