edith
Clone
https://git.tahinli.com/Tahinli/edith.git
0 watching0 forksRust18.3 MiBcda6d0eTahinli3 months ago476 commits
| 1 | //! Hardware encode checks. These need a built `libengine_hw.so` plus a working |
| 2 | //! VA-API driver with an H.264 encode entrypoint, so they are `#[ignore]`d by |
| 3 | //! default. Run them with: |
| 4 | //! |
| 5 | //! ```text |
| 6 | //! cargo build --workspace --release |
| 7 | //! LD_LIBRARY_PATH=target/release \ |
| 8 | //! cargo test -p engine --release --test hw_encode -- --ignored --nocapture --test-threads=1 |
| 9 | //! ``` |
| 10 | //! |
| 11 | //! The round trip goes out through the plugin and back in through the *software* |
| 12 | //! decoder (`rusty_h264` directly, not `DecodeSession`), so a bug on one side |
| 13 | //! cannot cancel out a bug on the other. |
| 14 | |
| 15 | use ; |
| 16 | |
| 17 | use ; |
| 18 | |
| 19 | const FPS: u32 = 30; |
| 20 | const BITRATE: u64 = 4_000_000; |
| 21 | |
| 22 | /// A moving diagonal gradient: something that actually costs bits, so the |
| 23 | /// encoder cannot make the whole test pass by emitting skip frames. |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | /// Encodes `count` synthetic pictures and returns the whole Annex-B stream plus |
| 38 | /// the number of access units the plugin handed back. |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | |
| 64 | |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 | |
| 83 | |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | |
| 93 | |
| 94 | |
| 95 | |
| 96 | |
| 97 | |
| 98 | |
| 99 | |
| 100 | |
| 101 | |
| 102 | |
| 103 | |
| 104 | |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | |
| 110 | |
| 111 | |
| 112 | |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | |
| 118 | |
| 119 | |
| 120 | |
| 121 | /// 322x242 is even (NV12 needs that) but neither dimension is a multiple of 16, |
| 122 | /// so the surface is padded and the encoded stream has to crop it back. This is |
| 123 | /// the 1080p case in miniature: 1080 pads to 1088. |
| 124 | |
| 125 | |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | |
| 134 | |
| 135 | |
| 136 | |
| 137 | |
| 138 | |
| 139 | |
| 140 | |
| 141 | |
| 142 | |
| 143 | /// The zero-copy path: a picture the hardware decoder wrote goes into the |
| 144 | /// hardware encoder as the buffer it was decoded into, never read back and never |
| 145 | /// written out again -- which is what makes an export of an untouched clip cost |
| 146 | /// no `vaGetImage`, no colour conversion and no upload per frame. |
| 147 | /// |
| 148 | /// Two things are checked and the second is the one that matters. That the |
| 149 | /// buffers are handed over *at all* (a driver whose export the plugin refuses |
| 150 | /// falls back to pixels, silently and correctly, which would make a speed claim |
| 151 | /// a lie). And that what came out is what went in: the encoded stream is decoded |
| 152 | /// in software and compared against the same file decoded through the read-back |
| 153 | /// path, so a wrong plane offset, a swapped object or an unsynchronised surface |
| 154 | /// -- the ways an imported buffer goes wrong -- fails here instead of shipping |
| 155 | /// as a garbled export. |
| 156 | |
| 157 | |
| 158 | |
| 159 | |
| 160 | |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | |
| 166 | |
| 167 | |
| 168 | |
| 169 | |
| 170 | |
| 171 | |
| 172 | |
| 173 | |
| 174 | |
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 | |
| 181 | |
| 182 | |
| 183 | |
| 184 | |
| 185 | |
| 186 | |
| 187 | |
| 188 | |
| 189 | |
| 190 | |
| 191 | |
| 192 | |
| 193 | |
| 194 | |
| 195 | |
| 196 | |
| 197 | |
| 198 | |
| 199 | |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | |
| 207 | |
| 208 | |
| 209 | |
| 210 | |
| 211 | |
| 212 | |
| 213 | |
| 214 | |
| 215 | |
| 216 | |
| 217 | |
| 218 | |
| 219 | /// What the process boundary costs, at the size an export is really written at. |
| 220 | /// |
| 221 | /// The encoder lives in a child now ([`engine::hwproc`]) so that a driver's |
| 222 | /// `abort()` cannot take the editor with it, and the price of that has to be |
| 223 | /// small enough that nobody would trade it back: pictures reach the child |
| 224 | /// through a shared mapping rather than down a pipe, so a frame costs one |
| 225 | /// `memcpy` and a ten-byte message. `VE_HW_INPROCESS` pins the seat the way it |
| 226 | /// used to be, which is the only honest baseline there is. |
| 227 | /// |
| 228 | /// This is the *worst* case on purpose: an untouched clip's pictures never leave |
| 229 | /// the GPU at all (`a_decoded_buffer_is_encoded_without_ever_being_read_back`, |
| 230 | /// whose descriptors cross the same socket), so nothing an export really does is |
| 231 | /// slower than this. |
| 232 | |
| 233 | |
| 234 | |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | |
| 240 | |
| 241 | |
| 242 | |
| 243 | |
| 244 | |
| 245 | |
| 246 | |
| 247 | |
| 248 | |
| 249 | |
| 250 | |
| 251 | |
| 252 | |
| 253 | |
| 254 | |
| 255 | |
| 256 | |
| 257 | |
| 258 | |
| 259 | |
| 260 | |
| 261 | |
| 262 | |
| 263 | |
| 264 | |
| 265 | |
| 266 | |
| 267 | |
| 268 | |
| 269 | /// Decode and encode resolve through two independent symbol tables, so an |
| 270 | /// encoder that cannot load must not cost us the decoder (and vice versa). |
| 271 | /// |
| 272 | /// This is the positive half only: the negative half -- a plugin built without |
| 273 | /// `vh_enc_*` -- needs a second build of the `.so` and belongs to the slice's |
| 274 | /// verifier, not here. |
| 275 | |
| 276 | |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | |
| 282 | |
| 283 | |
| 284 | |
| 285 | |
| 286 | |
| 287 | |
| 288 |