|
| 1 | +const AV1_DATA = { |
| 2 | + src: 'av1.mp4', |
| 3 | + config: { |
| 4 | + codec: 'av01.0.04M.08', |
| 5 | + codedWidth: 320, |
| 6 | + codedHeight: 240, |
| 7 | + visibleRect: {x: 0, y: 0, width: 320, height: 240}, |
| 8 | + displayWidth: 320, |
| 9 | + displayHeight: 240, |
| 10 | + }, |
| 11 | + chunks: [ |
| 12 | + {offset: 48, size: 1938}, {offset: 1986, size: 848}, |
| 13 | + {offset: 2834, size: 3}, {offset: 2837, size: 47}, {offset: 2884, size: 3}, |
| 14 | + {offset: 2887, size: 116}, {offset: 3003, size: 3}, |
| 15 | + {offset: 3006, size: 51}, {offset: 3057, size: 25}, |
| 16 | + {offset: 3082, size: 105} |
| 17 | + ] |
| 18 | +}; |
| 19 | + |
| 20 | +const VP8_DATA = { |
| 21 | + src: 'vp8.webm', |
| 22 | + config: { |
| 23 | + codec: 'vp8', |
| 24 | + codedWidth: 320, |
| 25 | + codedHeight: 240, |
| 26 | + visibleRect: {x: 0, y: 0, width: 320, height: 240}, |
| 27 | + displayWidth: 320, |
| 28 | + displayHeight: 240, |
| 29 | + }, |
| 30 | + chunks: [ |
| 31 | + {offset: 522, size: 4826}, {offset: 5355, size: 394}, |
| 32 | + {offset: 5756, size: 621}, {offset: 6384, size: 424}, |
| 33 | + {offset: 6815, size: 532}, {offset: 7354, size: 655}, |
| 34 | + {offset: 8016, size: 670}, {offset: 8693, size: 2413}, |
| 35 | + {offset: 11113, size: 402}, {offset: 11522, size: 686} |
| 36 | + ] |
| 37 | +}; |
| 38 | + |
| 39 | +const VP9_DATA = { |
| 40 | + src: 'vp9.mp4', |
| 41 | + // TODO(sandersd): Verify that the file is actually level 1. |
| 42 | + config: { |
| 43 | + codec: 'vp09.00.10.08', |
| 44 | + codedWidth: 320, |
| 45 | + codedHeight: 240, |
| 46 | + displayAspectWidth: 320, |
| 47 | + displayAspectHeight: 240, |
| 48 | + }, |
| 49 | + chunks: [ |
| 50 | + {offset: 44, size: 3315}, {offset: 3359, size: 203}, |
| 51 | + {offset: 3562, size: 245}, {offset: 3807, size: 172}, |
| 52 | + {offset: 3979, size: 312}, {offset: 4291, size: 170}, |
| 53 | + {offset: 4461, size: 195}, {offset: 4656, size: 181}, |
| 54 | + {offset: 4837, size: 356}, {offset: 5193, size: 159} |
| 55 | + ] |
| 56 | +}; |
| 57 | + |
| 58 | +const H264_AVC_DATA = { |
| 59 | + src: 'h264.mp4', |
| 60 | + config: { |
| 61 | + codec: 'avc1.64000b', |
| 62 | + description: {offset: 9490, size: 45}, |
| 63 | + codedWidth: 320, |
| 64 | + codedHeight: 240, |
| 65 | + displayAspectWidth: 320, |
| 66 | + displayAspectHeight: 240, |
| 67 | + }, |
| 68 | + chunks: [ |
| 69 | + {offset: 48, size: 4140}, {offset: 4188, size: 604}, |
| 70 | + {offset: 4792, size: 475}, {offset: 5267, size: 561}, |
| 71 | + {offset: 5828, size: 587}, {offset: 6415, size: 519}, |
| 72 | + {offset: 6934, size: 532}, {offset: 7466, size: 523}, |
| 73 | + {offset: 7989, size: 454}, {offset: 8443, size: 528} |
| 74 | + ] |
| 75 | +}; |
| 76 | + |
| 77 | +const H264_ANNEXB_DATA = { |
| 78 | + src: 'h264.annexb', |
| 79 | + config: { |
| 80 | + codec: 'avc1.64000b', |
| 81 | + codedWidth: 320, |
| 82 | + codedHeight: 240, |
| 83 | + displayAspectWidth: 320, |
| 84 | + displayAspectHeight: 240, |
| 85 | + }, |
| 86 | + chunks: [ |
| 87 | + {offset: 0, size: 4175}, {offset: 4175, size: 602}, |
| 88 | + {offset: 4777, size: 473}, {offset: 5250, size: 559}, |
| 89 | + {offset: 5809, size: 585}, {offset: 6394, size: 517}, |
| 90 | + {offset: 6911, size: 530}, {offset: 7441, size: 521}, |
| 91 | + {offset: 7962, size: 452}, {offset: 8414, size: 526} |
| 92 | + ] |
| 93 | +}; |
| 94 | + |
| 95 | +const H265_HEVC_DATA = { |
| 96 | + src: 'h265.mp4', |
| 97 | + config: { |
| 98 | + codec: 'hev1.1.6.L60.90', |
| 99 | + description: {offset: 5821, size: 2406}, |
| 100 | + codedWidth: 320, |
| 101 | + codedHeight: 240, |
| 102 | + displayAspectWidth: 320, |
| 103 | + displayAspectHeight: 240, |
| 104 | + }, |
| 105 | + chunks: [ |
| 106 | + {offset: 44, size: 2515}, {offset: 2559, size: 279}, |
| 107 | + {offset: 2838, size: 327}, {offset: 3165, size: 329}, |
| 108 | + {offset: 3494, size: 308}, {offset: 3802, size: 292}, |
| 109 | + {offset: 4094, size: 352}, {offset: 4446, size: 296}, |
| 110 | + {offset: 4742, size: 216}, {offset: 4958, size: 344} |
| 111 | + ] |
| 112 | +}; |
| 113 | + |
| 114 | +const H265_ANNEXB_DATA = { |
| 115 | + src: 'h265.annexb', |
| 116 | + config: { |
| 117 | + codec: 'hev1.1.6.L60.90', |
| 118 | + codedWidth: 320, |
| 119 | + codedHeight: 240, |
| 120 | + displayAspectWidth: 320, |
| 121 | + displayAspectHeight: 240, |
| 122 | + }, |
| 123 | + chunks: [ |
| 124 | + {offset: 0, size: 4894}, {offset: 4894, size: 279}, |
| 125 | + {offset: 5173, size: 327}, {offset: 5500, size: 329}, |
| 126 | + {offset: 5829, size: 308}, {offset: 6137, size: 292}, |
| 127 | + {offset: 6429, size: 352}, {offset: 6781, size: 296}, |
| 128 | + {offset: 7077, size: 216}, {offset: 7293, size: 344} |
| 129 | + ] |
| 130 | +}; |
| 131 | + |
| 132 | +// Allows mutating `callbacks` after constructing the VideoDecoder, wraps calls |
| 133 | +// in t.step(). |
| 134 | +function createVideoDecoder(t, callbacks) { |
| 135 | + return new VideoDecoder({ |
| 136 | + output(frame) { |
| 137 | + if (callbacks && callbacks.output) { |
| 138 | + t.step(() => callbacks.output(frame)); |
| 139 | + } else { |
| 140 | + t.unreached_func('unexpected output()'); |
| 141 | + } |
| 142 | + }, |
| 143 | + error(e) { |
| 144 | + if (callbacks && callbacks.error) { |
| 145 | + t.step(() => callbacks.error(e)); |
| 146 | + } else { |
| 147 | + t.unreached_func('unexpected error()'); |
| 148 | + } |
| 149 | + } |
| 150 | + }); |
| 151 | +} |
| 152 | + |
| 153 | +function createCorruptChunk(index) { |
| 154 | + let bad_data = CHUNK_DATA[index]; |
| 155 | + for (var i = 0; i < bad_data.byteLength; i += 4) |
| 156 | + bad_data[i] = 0xFF; |
| 157 | + return new EncodedVideoChunk( |
| 158 | + {type: 'delta', timestamp: index, data: bad_data}); |
| 159 | +} |
| 160 | + |
| 161 | +// Create a view of an ArrayBuffer. |
| 162 | +function view(buffer, {offset, size}) { |
| 163 | + return new Uint8Array(buffer, offset, size); |
| 164 | +} |
| 165 | + |
| 166 | +async function checkImplements() { |
| 167 | + // Don't run any tests if the codec is not supported. |
| 168 | + assert_equals('function', typeof VideoDecoder.isConfigSupported); |
| 169 | + let supported = false; |
| 170 | + try { |
| 171 | + // TODO(sandersd): To properly support H.264 in AVC format, this should |
| 172 | + // include the `description`. For now this test assumes that H.264 Annex B |
| 173 | + // support is the same as H.264 AVC support. |
| 174 | + const support = await VideoDecoder.isConfigSupported({codec: CONFIG.codec}); |
| 175 | + supported = support.supported; |
| 176 | + } catch (e) { |
| 177 | + } |
| 178 | + assert_implements_optional(supported, CONFIG.codec + ' unsupported'); |
| 179 | +} |
| 180 | + |
| 181 | +let CONFIG = null; |
| 182 | +let CHUNK_DATA = null; |
| 183 | +let CHUNKS = null; |
| 184 | +promise_setup(async () => { |
| 185 | + const data = { |
| 186 | + '?av1': AV1_DATA, |
| 187 | + '?vp8': VP8_DATA, |
| 188 | + '?vp9': VP9_DATA, |
| 189 | + '?h264_avc': H264_AVC_DATA, |
| 190 | + '?h264_annexb': H264_ANNEXB_DATA, |
| 191 | + '?h265_hevc': H265_HEVC_DATA, |
| 192 | + '?h265_annexb': H265_ANNEXB_DATA |
| 193 | + }[location.search]; |
| 194 | + |
| 195 | + // Fetch the media data and prepare buffers. |
| 196 | + const response = await fetch(data.src); |
| 197 | + const buf = await response.arrayBuffer(); |
| 198 | + |
| 199 | + CONFIG = {...data.config}; |
| 200 | + if (data.config.description) { |
| 201 | + CONFIG.description = view(buf, data.config.description); |
| 202 | + } |
| 203 | + |
| 204 | + CHUNK_DATA = data.chunks.map((chunk, i) => view(buf, chunk)); |
| 205 | + |
| 206 | + CHUNKS = CHUNK_DATA.map( |
| 207 | + (data, i) => new EncodedVideoChunk( |
| 208 | + {type: i == 0 ? 'key' : 'delta', timestamp: i, duration: 1, data})); |
| 209 | +}); |
0 commit comments