10c16b537SWarner Losh /* 2*5ff13fbcSAllan Jude * Copyright (c) Yann Collet, Facebook, Inc. 30c16b537SWarner Losh * All rights reserved. 40c16b537SWarner Losh * 50c16b537SWarner Losh * This source code is licensed under both the BSD-style license (found in the 60c16b537SWarner Losh * LICENSE file in the root directory of this source tree) and the GPLv2 (found 70c16b537SWarner Losh * in the COPYING file in the root directory of this source tree). 80c16b537SWarner Losh * You may select, at your option, one of the above-listed licenses. 90c16b537SWarner Losh */ 100c16b537SWarner Losh 110c16b537SWarner Losh #ifndef ZSTDMT_COMPRESS_H 120c16b537SWarner Losh #define ZSTDMT_COMPRESS_H 130c16b537SWarner Losh 140c16b537SWarner Losh #if defined (__cplusplus) 150c16b537SWarner Losh extern "C" { 160c16b537SWarner Losh #endif 170c16b537SWarner Losh 180c16b537SWarner Losh 190c16b537SWarner Losh /* Note : This is an internal API. 202b9c00cbSConrad Meyer * These APIs used to be exposed with ZSTDLIB_API, 210c16b537SWarner Losh * because it used to be the only way to invoke MT compression. 22f7cd7fe5SConrad Meyer * Now, you must use ZSTD_compress2 and ZSTD_compressStream2() instead. 232b9c00cbSConrad Meyer * 242b9c00cbSConrad Meyer * This API requires ZSTD_MULTITHREAD to be defined during compilation, 252b9c00cbSConrad Meyer * otherwise ZSTDMT_createCCtx*() will fail. 262b9c00cbSConrad Meyer */ 272b9c00cbSConrad Meyer 280c16b537SWarner Losh /* === Dependencies === */ 29f7cd7fe5SConrad Meyer #include "../common/zstd_deps.h" /* size_t */ 300c16b537SWarner Losh #define ZSTD_STATIC_LINKING_ONLY /* ZSTD_parameters */ 3137f1f268SConrad Meyer #include "../zstd.h" /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTDLIB_API */ 320c16b537SWarner Losh 330c16b537SWarner Losh 34a0483764SConrad Meyer /* === Constants === */ 35*5ff13fbcSAllan Jude #ifndef ZSTDMT_NBWORKERS_MAX /* a different value can be selected at compile time */ 36*5ff13fbcSAllan Jude # define ZSTDMT_NBWORKERS_MAX ((sizeof(void*)==4) /*32-bit*/ ? 64 : 256) 37a0483764SConrad Meyer #endif 38*5ff13fbcSAllan Jude #ifndef ZSTDMT_JOBSIZE_MIN /* a different value can be selected at compile time */ 39*5ff13fbcSAllan Jude # define ZSTDMT_JOBSIZE_MIN (512 KB) 40a0483764SConrad Meyer #endif 414d3f1eafSConrad Meyer #define ZSTDMT_JOBLOG_MAX (MEM_32bits() ? 29 : 30) 42a0483764SConrad Meyer #define ZSTDMT_JOBSIZE_MAX (MEM_32bits() ? (512 MB) : (1024 MB)) 43a0483764SConrad Meyer 44a0483764SConrad Meyer 45f7cd7fe5SConrad Meyer /* ======================================================== 46f7cd7fe5SConrad Meyer * === Private interface, for use by ZSTD_compress.c === 47f7cd7fe5SConrad Meyer * === Not exposed in libzstd. Never invoke directly === 48f7cd7fe5SConrad Meyer * ======================================================== */ 49f7cd7fe5SConrad Meyer 500c16b537SWarner Losh /* === Memory management === */ 510c16b537SWarner Losh typedef struct ZSTDMT_CCtx_s ZSTDMT_CCtx; 522b9c00cbSConrad Meyer /* Requires ZSTD_MULTITHREAD to be defined during compilation, otherwise it will return NULL. */ 53f7cd7fe5SConrad Meyer ZSTDMT_CCtx* ZSTDMT_createCCtx_advanced(unsigned nbWorkers, 54f7cd7fe5SConrad Meyer ZSTD_customMem cMem, 55f7cd7fe5SConrad Meyer ZSTD_threadPool *pool); 56f7cd7fe5SConrad Meyer size_t ZSTDMT_freeCCtx(ZSTDMT_CCtx* mtctx); 570c16b537SWarner Losh 58f7cd7fe5SConrad Meyer size_t ZSTDMT_sizeof_CCtx(ZSTDMT_CCtx* mtctx); 590c16b537SWarner Losh 600c16b537SWarner Losh /* === Streaming functions === */ 610c16b537SWarner Losh 62f7cd7fe5SConrad Meyer size_t ZSTDMT_nextInputSizeHint(const ZSTDMT_CCtx* mtctx); 630c16b537SWarner Losh 64f7cd7fe5SConrad Meyer /*! ZSTDMT_initCStream_internal() : 65f7cd7fe5SConrad Meyer * Private use only. Init streaming operation. 66f7cd7fe5SConrad Meyer * expects params to be valid. 67f7cd7fe5SConrad Meyer * must receive dict, or cdict, or none, but not both. 68*5ff13fbcSAllan Jude * mtctx can be freshly constructed or reused from a prior compression. 69*5ff13fbcSAllan Jude * If mtctx is reused, memory allocations from the prior compression may not be freed, 70*5ff13fbcSAllan Jude * even if they are not needed for the current compression. 71f7cd7fe5SConrad Meyer * @return : 0, or an error code */ 72*5ff13fbcSAllan Jude size_t ZSTDMT_initCStream_internal(ZSTDMT_CCtx* mtctx, 73f7cd7fe5SConrad Meyer const void* dict, size_t dictSize, ZSTD_dictContentType_e dictContentType, 740c16b537SWarner Losh const ZSTD_CDict* cdict, 75f7cd7fe5SConrad Meyer ZSTD_CCtx_params params, unsigned long long pledgedSrcSize); 760c16b537SWarner Losh 770c16b537SWarner Losh /*! ZSTDMT_compressStream_generic() : 7819fcbaf1SConrad Meyer * Combines ZSTDMT_compressStream() with optional ZSTDMT_flushStream() or ZSTDMT_endStream() 790c16b537SWarner Losh * depending on flush directive. 800c16b537SWarner Losh * @return : minimum amount of data still to be flushed 810c16b537SWarner Losh * 0 if fully flushed 8219fcbaf1SConrad Meyer * or an error code 8319fcbaf1SConrad Meyer * note : needs to be init using any ZSTD_initCStream*() variant */ 84f7cd7fe5SConrad Meyer size_t ZSTDMT_compressStream_generic(ZSTDMT_CCtx* mtctx, 850c16b537SWarner Losh ZSTD_outBuffer* output, 860c16b537SWarner Losh ZSTD_inBuffer* input, 870c16b537SWarner Losh ZSTD_EndDirective endOp); 880c16b537SWarner Losh 890f743729SConrad Meyer /*! ZSTDMT_toFlushNow() 900f743729SConrad Meyer * Tell how many bytes are ready to be flushed immediately. 910f743729SConrad Meyer * Probe the oldest active job (not yet entirely flushed) and check its output buffer. 920f743729SConrad Meyer * If return 0, it means there is no active job, 930f743729SConrad Meyer * or, it means oldest job is still active, but everything produced has been flushed so far, 940f743729SConrad Meyer * therefore flushing is limited by speed of oldest job. */ 950f743729SConrad Meyer size_t ZSTDMT_toFlushNow(ZSTDMT_CCtx* mtctx); 960f743729SConrad Meyer 9719fcbaf1SConrad Meyer /*! ZSTDMT_updateCParams_whileCompressing() : 9819fcbaf1SConrad Meyer * Updates only a selected set of compression parameters, to remain compatible with current frame. 9919fcbaf1SConrad Meyer * New parameters will be applied to next compression job. */ 10019fcbaf1SConrad Meyer void ZSTDMT_updateCParams_whileCompressing(ZSTDMT_CCtx* mtctx, const ZSTD_CCtx_params* cctxParams); 10119fcbaf1SConrad Meyer 1020f743729SConrad Meyer /*! ZSTDMT_getFrameProgression(): 10319fcbaf1SConrad Meyer * tells how much data has been consumed (input) and produced (output) for current frame. 10419fcbaf1SConrad Meyer * able to count progression inside worker threads. 10519fcbaf1SConrad Meyer */ 10619fcbaf1SConrad Meyer ZSTD_frameProgression ZSTDMT_getFrameProgression(ZSTDMT_CCtx* mtctx); 10719fcbaf1SConrad Meyer 1080c16b537SWarner Losh 1090c16b537SWarner Losh #if defined (__cplusplus) 1100c16b537SWarner Losh } 1110c16b537SWarner Losh #endif 1120c16b537SWarner Losh 1130c16b537SWarner Losh #endif /* ZSTDMT_COMPRESS_H */ 114