| 1127 | }; |
| 1128 | |
| 1129 | const isValidVideoFrameBufferInit = (init: VideoFrameBufferInit): boolean => { |
| 1130 | // Check for required fields (WebIDL 'required') |
| 1131 | if (init.format === undefined) return false; |
| 1132 | if (init.codedWidth === undefined) return false; |
| 1133 | if (init.codedHeight === undefined) return false; |
| 1134 | if (init.timestamp === undefined) return false; |
| 1135 | |
| 1136 | // Check logical constraints (Algorithm: "To check if a VideoFrameBufferInit is a valid...") |
| 1137 | if (init.codedWidth === 0 || init.codedHeight === 0) return false; |
| 1138 | if (init.visibleRect) { |
| 1139 | const r = init.visibleRect; |
| 1140 | if ((r.x || 0) < 0 || (r.y || 0) < 0 || (r.width || 0) < 0 || (r.height || 0) < 0) return false; |
| 1141 | if ((r.y || 0) + (r.height || 0) > init.codedHeight) return false; |
| 1142 | if ((r.x || 0) + (r.width || 0) > init.codedWidth) return false; |
| 1143 | } |
| 1144 | if ((init.displayWidth !== undefined && init.displayHeight === undefined) |
| 1145 | || (init.displayWidth === undefined && init.displayHeight !== undefined)) { |
| 1146 | return false; |
| 1147 | } |
| 1148 | if (init.displayWidth === 0 || init.displayHeight === 0) return false; |
| 1149 | return true; |
| 1150 | }; |
| 1151 | |
| 1152 | type PlaneInfo = { |
| 1153 | sampleWidth: number; |