stream_encoder.c | stream_encoder.c | |||
---|---|---|---|---|
skipping to change at line 60 | skipping to change at line 60 | |||
/// Total number of bytes in buffer[] | /// Total number of bytes in buffer[] | |||
size_t buffer_size; | size_t buffer_size; | |||
/// Buffer to hold Stream Header, Block Header, and Stream Footer. | /// Buffer to hold Stream Header, Block Header, and Stream Footer. | |||
/// Block Header has biggest maximum size. | /// Block Header has biggest maximum size. | |||
uint8_t buffer[LZMA_BLOCK_HEADER_SIZE_MAX]; | uint8_t buffer[LZMA_BLOCK_HEADER_SIZE_MAX]; | |||
}; | }; | |||
static lzma_ret | static lzma_ret | |||
block_encoder_init(lzma_coder *coder, lzma_allocator *allocator) | block_encoder_init(lzma_coder *coder, const lzma_allocator *allocator) | |||
{ | { | |||
// Prepare the Block options. Even though Block encoder doesn't need | // Prepare the Block options. Even though Block encoder doesn't need | |||
// compressed_size, uncompressed_size, and header_size to be | // compressed_size, uncompressed_size, and header_size to be | |||
// initialized, it is a good idea to do it here, because this way | // initialized, it is a good idea to do it here, because this way | |||
// we catch if someone gave us Filter ID that cannot be used in | // we catch if someone gave us Filter ID that cannot be used in | |||
// Blocks/Streams. | // Blocks/Streams. | |||
coder->block_options.compressed_size = LZMA_VLI_UNKNOWN; | coder->block_options.compressed_size = LZMA_VLI_UNKNOWN; | |||
coder->block_options.uncompressed_size = LZMA_VLI_UNKNOWN; | coder->block_options.uncompressed_size = LZMA_VLI_UNKNOWN; | |||
return_if_error(lzma_block_header_size(&coder->block_options)); | return_if_error(lzma_block_header_size(&coder->block_options)); | |||
// Initialize the actual Block encoder. | // Initialize the actual Block encoder. | |||
return lzma_block_encoder_init(&coder->block_encoder, allocator, | return lzma_block_encoder_init(&coder->block_encoder, allocator, | |||
&coder->block_options); | &coder->block_options); | |||
} | } | |||
static lzma_ret | static lzma_ret | |||
stream_encode(lzma_coder *coder, lzma_allocator *allocator, | stream_encode(lzma_coder *coder, const lzma_allocator *allocator, | |||
const uint8_t *restrict in, size_t *restrict in_pos, | const uint8_t *restrict in, size_t *restrict in_pos, | |||
size_t in_size, uint8_t *restrict out, | size_t in_size, uint8_t *restrict out, | |||
size_t *restrict out_pos, size_t out_size, lzma_action actio n) | size_t *restrict out_pos, size_t out_size, lzma_action actio n) | |||
{ | { | |||
// Main loop | // Main loop | |||
while (*out_pos < out_size) | while (*out_pos < out_size) | |||
switch (coder->sequence) { | switch (coder->sequence) { | |||
case SEQ_STREAM_HEADER: | case SEQ_STREAM_HEADER: | |||
case SEQ_BLOCK_HEADER: | case SEQ_BLOCK_HEADER: | |||
case SEQ_STREAM_FOOTER: | case SEQ_STREAM_FOOTER: | |||
skipping to change at line 146 | skipping to change at line 146 | |||
if (lzma_block_header_encode(&coder->block_options, | if (lzma_block_header_encode(&coder->block_options, | |||
coder->buffer) != LZMA_OK) | coder->buffer) != LZMA_OK) | |||
return LZMA_PROG_ERROR; | return LZMA_PROG_ERROR; | |||
coder->buffer_size = coder->block_options.header_size; | coder->buffer_size = coder->block_options.header_size; | |||
coder->sequence = SEQ_BLOCK_HEADER; | coder->sequence = SEQ_BLOCK_HEADER; | |||
break; | break; | |||
} | } | |||
case SEQ_BLOCK_ENCODE: { | case SEQ_BLOCK_ENCODE: { | |||
static const lzma_action convert[4] = { | static const lzma_action convert[LZMA_ACTION_MAX + 1] = { | |||
LZMA_RUN, | LZMA_RUN, | |||
LZMA_SYNC_FLUSH, | LZMA_SYNC_FLUSH, | |||
LZMA_FINISH, | LZMA_FINISH, | |||
LZMA_FINISH, | LZMA_FINISH, | |||
LZMA_FINISH, | ||||
}; | }; | |||
const lzma_ret ret = coder->block_encoder.code( | const lzma_ret ret = coder->block_encoder.code( | |||
coder->block_encoder.coder, allocator, | coder->block_encoder.coder, allocator, | |||
in, in_pos, in_size, | in, in_pos, in_size, | |||
out, out_pos, out_size, convert[action]); | out, out_pos, out_size, convert[action]); | |||
if (ret != LZMA_STREAM_END || action == LZMA_SYNC_FLUSH) | if (ret != LZMA_STREAM_END || action == LZMA_SYNC_FLUSH) | |||
return ret; | return ret; | |||
// Add a new Index Record. | // Add a new Index Record. | |||
skipping to change at line 207 | skipping to change at line 208 | |||
default: | default: | |||
assert(0); | assert(0); | |||
return LZMA_PROG_ERROR; | return LZMA_PROG_ERROR; | |||
} | } | |||
return LZMA_OK; | return LZMA_OK; | |||
} | } | |||
static void | static void | |||
stream_encoder_end(lzma_coder *coder, lzma_allocator *allocator) | stream_encoder_end(lzma_coder *coder, const lzma_allocator *allocator) | |||
{ | { | |||
lzma_next_end(&coder->block_encoder, allocator); | lzma_next_end(&coder->block_encoder, allocator); | |||
lzma_next_end(&coder->index_encoder, allocator); | lzma_next_end(&coder->index_encoder, allocator); | |||
lzma_index_end(coder->index, allocator); | lzma_index_end(coder->index, allocator); | |||
for (size_t i = 0; coder->filters[i].id != LZMA_VLI_UNKNOWN; ++i) | for (size_t i = 0; coder->filters[i].id != LZMA_VLI_UNKNOWN; ++i) | |||
lzma_free(coder->filters[i].options, allocator); | lzma_free(coder->filters[i].options, allocator); | |||
lzma_free(coder, allocator); | lzma_free(coder, allocator); | |||
return; | return; | |||
} | } | |||
static lzma_ret | static lzma_ret | |||
stream_encoder_update(lzma_coder *coder, lzma_allocator *allocator, | stream_encoder_update(lzma_coder *coder, const lzma_allocator *allocator, | |||
const lzma_filter *filters, | const lzma_filter *filters, | |||
const lzma_filter *reversed_filters) | const lzma_filter *reversed_filters) | |||
{ | { | |||
if (coder->sequence <= SEQ_BLOCK_INIT) { | if (coder->sequence <= SEQ_BLOCK_INIT) { | |||
// There is no incomplete Block waiting to be finished, | // There is no incomplete Block waiting to be finished, | |||
// thus we can change the whole filter chain. Start by | // thus we can change the whole filter chain. Start by | |||
// trying to initialize the Block encoder with the new | // trying to initialize the Block encoder with the new | |||
// chain. This way we detect if the chain is valid. | // chain. This way we detect if the chain is valid. | |||
coder->block_encoder_is_initialized = false; | coder->block_encoder_is_initialized = false; | |||
coder->block_options.filters = (lzma_filter *)(filters); | coder->block_options.filters = (lzma_filter *)(filters); | |||
skipping to change at line 259 | skipping to change at line 260 | |||
} | } | |||
// Free the copy of the old chain and make a copy of the new chain. | // Free the copy of the old chain and make a copy of the new chain. | |||
for (size_t i = 0; coder->filters[i].id != LZMA_VLI_UNKNOWN; ++i) | for (size_t i = 0; coder->filters[i].id != LZMA_VLI_UNKNOWN; ++i) | |||
lzma_free(coder->filters[i].options, allocator); | lzma_free(coder->filters[i].options, allocator); | |||
return lzma_filters_copy(filters, coder->filters, allocator); | return lzma_filters_copy(filters, coder->filters, allocator); | |||
} | } | |||
static lzma_ret | static lzma_ret | |||
stream_encoder_init(lzma_next_coder *next, lzma_allocator *allocator, | stream_encoder_init(lzma_next_coder *next, const lzma_allocator *allocator, | |||
const lzma_filter *filters, lzma_check check) | const lzma_filter *filters, lzma_check check) | |||
{ | { | |||
lzma_next_coder_init(&stream_encoder_init, next, allocator); | lzma_next_coder_init(&stream_encoder_init, next, allocator); | |||
if (filters == NULL) | if (filters == NULL) | |||
return LZMA_PROG_ERROR; | return LZMA_PROG_ERROR; | |||
if (next->coder == NULL) { | if (next->coder == NULL) { | |||
next->coder = lzma_alloc(sizeof(lzma_coder), allocator); | next->coder = lzma_alloc(sizeof(lzma_coder), allocator); | |||
if (next->coder == NULL) | if (next->coder == NULL) | |||
skipping to change at line 320 | skipping to change at line 321 | |||
extern LZMA_API(lzma_ret) | extern LZMA_API(lzma_ret) | |||
lzma_stream_encoder(lzma_stream *strm, | lzma_stream_encoder(lzma_stream *strm, | |||
const lzma_filter *filters, lzma_check check) | const lzma_filter *filters, lzma_check check) | |||
{ | { | |||
lzma_next_strm_init(stream_encoder_init, strm, filters, check); | lzma_next_strm_init(stream_encoder_init, strm, filters, check); | |||
strm->internal->supported_actions[LZMA_RUN] = true; | strm->internal->supported_actions[LZMA_RUN] = true; | |||
strm->internal->supported_actions[LZMA_SYNC_FLUSH] = true; | strm->internal->supported_actions[LZMA_SYNC_FLUSH] = true; | |||
strm->internal->supported_actions[LZMA_FULL_FLUSH] = true; | strm->internal->supported_actions[LZMA_FULL_FLUSH] = true; | |||
strm->internal->supported_actions[LZMA_FULL_BARRIER] = true; | ||||
strm->internal->supported_actions[LZMA_FINISH] = true; | strm->internal->supported_actions[LZMA_FINISH] = true; | |||
return LZMA_OK; | return LZMA_OK; | |||
} | } | |||
End of changes. 8 change blocks. | ||||
6 lines changed or deleted | 8 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |