| 1277 | |
| 1278 | |
| 1279 | static unsigned long long |
| 1280 | FIO_compressZstdFrame(FIO_ctx_t* const fCtx, |
| 1281 | FIO_prefs_t* const prefs, |
| 1282 | const cRess_t* ressPtr, |
| 1283 | const char* srcFileName, U64 fileSize, |
| 1284 | int compressionLevel, U64* readsize) |
| 1285 | { |
| 1286 | cRess_t const ress = *ressPtr; |
| 1287 | FILE* const srcFile = ress.srcFile; |
| 1288 | FILE* const dstFile = ress.dstFile; |
| 1289 | U64 compressedfilesize = 0; |
| 1290 | ZSTD_EndDirective directive = ZSTD_e_continue; |
| 1291 | |
| 1292 | /* stats */ |
| 1293 | ZSTD_frameProgression previous_zfp_update = { 0, 0, 0, 0, 0, 0 }; |
| 1294 | ZSTD_frameProgression previous_zfp_correction = { 0, 0, 0, 0, 0, 0 }; |
| 1295 | typedef enum { noChange, slower, faster } speedChange_e; |
| 1296 | speedChange_e speedChange = noChange; |
| 1297 | unsigned flushWaiting = 0; |
| 1298 | unsigned inputPresented = 0; |
| 1299 | unsigned inputBlocked = 0; |
| 1300 | unsigned lastJobID = 0; |
| 1301 | |
| 1302 | DISPLAYLEVEL(6, "compression using zstd format \n"); |
| 1303 | |
| 1304 | /* init */ |
| 1305 | if (fileSize != UTIL_FILESIZE_UNKNOWN) { |
| 1306 | CHECK(ZSTD_CCtx_setPledgedSrcSize(ress.cctx, fileSize)); |
| 1307 | } else if (prefs->streamSrcSize > 0) { |
| 1308 | /* unknown source size; use the declared stream size */ |
| 1309 | CHECK( ZSTD_CCtx_setPledgedSrcSize(ress.cctx, prefs->streamSrcSize) ); |
| 1310 | } |
| 1311 | (void)srcFileName; |
| 1312 | |
| 1313 | /* Main compression loop */ |
| 1314 | do { |
| 1315 | size_t stillToFlush; |
| 1316 | /* Fill input Buffer */ |
| 1317 | size_t const inSize = fread(ress.srcBuffer, (size_t)1, ress.srcBufferSize, srcFile); |
| 1318 | ZSTD_inBuffer inBuff = { ress.srcBuffer, inSize, 0 }; |
| 1319 | DISPLAYLEVEL(6, "fread %u bytes from source \n", (unsigned)inSize); |
| 1320 | *readsize += inSize; |
| 1321 | |
| 1322 | if ((inSize == 0) || (*readsize == fileSize)) |
| 1323 | directive = ZSTD_e_end; |
| 1324 | |
| 1325 | stillToFlush = 1; |
| 1326 | while ((inBuff.pos != inBuff.size) /* input buffer must be entirely ingested */ |
| 1327 | || (directive == ZSTD_e_end && stillToFlush != 0) ) { |
| 1328 | |
| 1329 | size_t const oldIPos = inBuff.pos; |
| 1330 | ZSTD_outBuffer outBuff = { ress.dstBuffer, ress.dstBufferSize, 0 }; |
| 1331 | size_t const toFlushNow = ZSTD_toFlushNow(ress.cctx); |
| 1332 | CHECK_V(stillToFlush, ZSTD_compressStream2(ress.cctx, &outBuff, &inBuff, directive)); |
| 1333 | |
| 1334 | /* count stats */ |
| 1335 | inputPresented++; |
| 1336 | if (oldIPos == inBuff.pos) inputBlocked++; /* input buffer is full and can't take any more : input speed is faster than consumption rate */ |
no test coverage detected