/* Copyright 2015 Google Inc. All Rights Reserved. Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT */ /* Brotli state for partial streaming decoding. */ #ifndef BROTLI_DEC_STATE_H_ #define BROTLI_DEC_STATE_H_ #include <brotli/decode.h> #include <brotli/shared_dictionary.h> #include <brotli/types.h> #include "../common/constants.h" #include "../common/dictionary.h" #include "../common/platform.h" #include "../common/transform.h" #include "bit_reader.h" #include "huffman.h" #if defined(__cplusplus) || defined(c_plusplus) extern "C" { #endif /* Graphviz diagram that describes state transitions: digraph States { graph [compound=true] concentrate=true node [shape="box"] UNINITED -> {LARGE_WINDOW_BITS -> INITIALIZE} subgraph cluster_metablock_workflow { style="rounded" label=< <B>METABLOCK CYCLE</B> > METABLOCK_BEGIN -> METABLOCK_HEADER METABLOCK_HEADER:sw -> METADATA METABLOCK_HEADER:s -> UNCOMPRESSED METABLOCK_HEADER:se -> METABLOCK_DONE:ne METADATA:s -> METABLOCK_DONE:w UNCOMPRESSED:s -> METABLOCK_DONE:n METABLOCK_DONE:e -> METABLOCK_BEGIN:e [constraint="false"] } INITIALIZE -> METABLOCK_BEGIN METABLOCK_DONE -> DONE subgraph cluster_compressed_metablock { style="rounded" label=< <B>COMPRESSED METABLOCK</B> > subgraph cluster_command { style="rounded" label=< <B>HOT LOOP</B> > _METABLOCK_DONE_PORT_ [shape=point style=invis] { // Set different shape for nodes returning from "compressed metablock". node [shape=invhouse]; CMD_INNER CMD_POST_DECODE_LITERALS; CMD_POST_WRAP_COPY; CMD_INNER_WRITE; CMD_POST_WRITE_1; } CMD_BEGIN -> CMD_INNER -> CMD_POST_DECODE_LITERALS -> CMD_POST_WRAP_COPY // IO ("write") nodes are not in the hot loop! CMD_INNER_WRITE [style=dashed] CMD_INNER -> CMD_INNER_WRITE CMD_POST_WRITE_1 [style=dashed] CMD_POST_DECODE_LITERALS -> CMD_POST_WRITE_1 CMD_POST_WRITE_2 [style=dashed] CMD_POST_WRAP_COPY -> CMD_POST_WRITE_2 CMD_POST_WRITE_1 -> CMD_BEGIN:s [constraint="false"] CMD_INNER_WRITE -> {CMD_INNER CMD_POST_DECODE_LITERALS} [constraint="false"] CMD_BEGIN:ne -> CMD_POST_DECODE_LITERALS [constraint="false"] CMD_POST_WRAP_COPY -> CMD_BEGIN [constraint="false"] CMD_POST_DECODE_LITERALS -> CMD_BEGIN:ne [constraint="false"] CMD_POST_WRITE_2 -> CMD_POST_WRAP_COPY [constraint="false"] {rank=same; CMD_BEGIN; CMD_INNER; CMD_POST_DECODE_LITERALS; CMD_POST_WRAP_COPY} {rank=same; CMD_INNER_WRITE; CMD_POST_WRITE_1; CMD_POST_WRITE_2} {CMD_INNER CMD_POST_DECODE_LITERALS CMD_POST_WRAP_COPY} -> _METABLOCK_DONE_PORT_ [style=invis] {CMD_INNER_WRITE CMD_POST_WRITE_1} -> _METABLOCK_DONE_PORT_ [constraint="false" style=invis] } BEFORE_COMPRESSED_METABLOCK_HEADER:s -> HUFFMAN_CODE_0:n HUFFMAN_CODE_0 -> HUFFMAN_CODE_1 -> HUFFMAN_CODE_2 -> HUFFMAN_CODE_3 HUFFMAN_CODE_0 -> METABLOCK_HEADER_2 -> CONTEXT_MODES -> CONTEXT_MAP_1 CONTEXT_MAP_1 -> CONTEXT_MAP_2 -> TREE_GROUP TREE_GROUP -> BEFORE_COMPRESSED_METABLOCK_BODY:e BEFORE_COMPRESSED_METABLOCK_BODY:s -> CMD_BEGIN:n HUFFMAN_CODE_3:e -> HUFFMAN_CODE_0:ne [constraint="false"] {rank=same; HUFFMAN_CODE_0; HUFFMAN_CODE_1; HUFFMAN_CODE_2; HUFFMAN_CODE_3} {rank=same; METABLOCK_HEADER_2; CONTEXT_MODES; CONTEXT_MAP_1; CONTEXT_MAP_2; TREE_GROUP} } METABLOCK_HEADER:e -> BEFORE_COMPRESSED_METABLOCK_HEADER:n _METABLOCK_DONE_PORT_ -> METABLOCK_DONE:se [constraint="false" ltail=cluster_command] UNINITED [shape=Mdiamond]; DONE [shape=Msquare]; } */ BrotliRunningState; BrotliRunningMetablockHeaderState; BrotliRunningUncompressedState; BrotliRunningTreeGroupState; BrotliRunningContextMapState; BrotliRunningHuffmanState; BrotliRunningDecodeUint8State; BrotliRunningReadBlockLengthState; /* BrotliDecoderState addon, used for Compound Dictionary functionality. */ BrotliDecoderCompoundDictionary; BrotliMetablockHeaderArena; BrotliMetablockBodyArena; struct BrotliDecoderStateStruct { … }; BrotliDecoderStateInternal; #define BrotliDecoderState … BROTLI_INTERNAL BROTLI_BOOL BrotliDecoderStateInit(BrotliDecoderState* s, brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque); BROTLI_INTERNAL void BrotliDecoderStateCleanup(BrotliDecoderState* s); BROTLI_INTERNAL void BrotliDecoderStateMetablockBegin(BrotliDecoderState* s); BROTLI_INTERNAL void BrotliDecoderStateCleanupAfterMetablock( BrotliDecoderState* s); BROTLI_INTERNAL BROTLI_BOOL BrotliDecoderHuffmanTreeGroupInit( BrotliDecoderState* s, HuffmanTreeGroup* group, brotli_reg_t alphabet_size_max, brotli_reg_t alphabet_size_limit, brotli_reg_t ntrees); #define BROTLI_DECODER_ALLOC(S, L) … #define BROTLI_DECODER_FREE(S, X) … /* Literal/Command/Distance block size maximum; same as maximum metablock size; used as block size when there is no block switching. */ #define BROTLI_BLOCK_SIZE_CAP … #if defined(__cplusplus) || defined(c_plusplus) } /* extern "C" */ #endif #endif /* BROTLI_DEC_STATE_H_ */