a problem for brotli working on-the-fly #116

Closed
opened 2026-01-29 20:35:35 +00:00 by claunia · 7 comments
Owner

Originally created by @RenterRen on GitHub (May 27, 2016).

In my scene, I will not finish compressing when I run my program. so,BrotliCompressor object is only one. And on the client, I call the BrotliStateInit(&s) just for once.
So, like this:
while(1)
{
I read 500 bytes to compress------->send to the client--->client decompress the data---->
}
after client decompress the data, the decompressed data is not 500, sometimes,it may be 200, sometimes,it may be 800, How can I resolve the problem?

Originally created by @RenterRen on GitHub (May 27, 2016). In my scene, I will not finish compressing when I run my program. so,BrotliCompressor object is only one. And on the client, I call the BrotliStateInit(&s) just for once. So, like this: while(1) { I read 500 bytes to compress------->send to the client--->client decompress the data----> } after client decompress the data, the decompressed data is not 500, sometimes,it may be 200, sometimes,it may be 800, How can I resolve the problem?
Author
Owner

@eustas commented on GitHub (May 27, 2016):

When you compress block you need to set "force_flush" parameter to "true".
Moreover, after block is flushed, you need to append empty metadata block (WriteMetadata) to make sure that output is byte-aligned.

Sorry for confusing API. In two weeks API will be updated to make things like that more straightforward.

Best regards,
Eugene.

@eustas commented on GitHub (May 27, 2016): When you compress block you need to set "force_flush" parameter to "true". Moreover, after block is flushed, you need to append empty metadata block (WriteMetadata) to make sure that output is byte-aligned. Sorry for confusing API. In two weeks API will be updated to make things like that more straightforward. Best regards, Eugene.
Author
Owner

@RenterRen commented on GitHub (May 30, 2016):

@eustas Do you mean that I need call the Api like this below:
WriteMetaBlock(0, NULL, true, encoded_size, encoded_buffer);

if I set the parameter of is_last true, means this is the last frame, but I hava no last frame In my system, If I call this, how about next data,data is not finished!

@RenterRen commented on GitHub (May 30, 2016): @eustas Do you mean that I need call the Api like this below: WriteMetaBlock(0, NULL, true, encoded_size, encoded_buffer); if I set the parameter of is_last true, means this is the last frame, but I hava no last frame In my system, If I call this, how about next data,data is not finished!
Author
Owner

@eustas commented on GitHub (May 30, 2016):

No, just something like this:

while (true) {
...
 c->CopyInputToRingBuffer(input_size, input);
...
 c->WriteBrotliData(/* is last */ false, /* force flush */ true, &output_size, output);
...
 c->WriteMetaBlock(/* input size */ 0, /* input */ nullptr, /* is last */ false, &output_size, output);
...
}
@eustas commented on GitHub (May 30, 2016): No, just something like this: ``` while (true) { ... c->CopyInputToRingBuffer(input_size, input); ... c->WriteBrotliData(/* is last */ false, /* force flush */ true, &output_size, output); ... c->WriteMetaBlock(/* input size */ 0, /* input */ nullptr, /* is last */ false, &output_size, output); ... } ```
Author
Owner

@RenterRen commented on GitHub (Jun 12, 2016):

@eustas
Hi eustas:
I write the code like yours:

while (true) {
CopyOneBlockToRingBuffer(in, &compressor, &in_bytes, &final_block)
out_bytes = 0;
compressor.WriteBrotliData(false,true,&out_bytes, &output)
printf("bbbbbbbbbbbbbbbbbbbb:%d\n",out_bytes);
compressor.WriteMetaBlock( 0,NULL, false, &out_bytes, output);
printf("ttttttttttttttttttt:%d\n",out_bytes);
}

The test result is this:

bbbbbbbbbbbbbbbbbbbb:16126
ttttttttttttttttttt:0
bbbbbbbbbbbbbbbbbbbb:13349
ttttttttttttttttttt:0
bbbbbbbbbbbbbbbbbbbb:12419
ttttttttttttttttttt:0

How to fix it????
Best Regars:

@RenterRen commented on GitHub (Jun 12, 2016): @eustas Hi eustas: I write the code like yours: while (true) { CopyOneBlockToRingBuffer(in, &compressor, &in_bytes, &final_block) out_bytes = 0; compressor.WriteBrotliData(false,true,&out_bytes, &output) printf("bbbbbbbbbbbbbbbbbbbb:%d\n",out_bytes); compressor.WriteMetaBlock( 0,NULL, false, &out_bytes, output); printf("ttttttttttttttttttt:%d\n",out_bytes); } The test result is this: bbbbbbbbbbbbbbbbbbbb:16126 ttttttttttttttttttt:0 bbbbbbbbbbbbbbbbbbbb:13349 ttttttttttttttttttt:0 bbbbbbbbbbbbbbbbbbbb:12419 ttttttttttttttttttt:0 How to fix it???? Best Regars:
Author
Owner

@eustas commented on GitHub (Jun 13, 2016):

Sorry for misguiding you. Use WriteMetadata instead of WriteMetaBlock.
And pay attention that unlike WriteBrotliData output buffer is provided by client, not by encoder.

@eustas commented on GitHub (Jun 13, 2016): Sorry for misguiding you. Use WriteMetadata instead of WriteMetaBlock. And pay attention that unlike WriteBrotliData output buffer is provided by client, not by encoder.
Author
Owner

@RenterRen commented on GitHub (Jun 13, 2016):

@eustas

Thanks your support, It seems to work!!!

@RenterRen commented on GitHub (Jun 13, 2016): @eustas Thanks your support, It seems to work!!!
Author
Owner

@eustas commented on GitHub (Jun 13, 2016):

You are welcome.
Soon we will publish v0.4 with more clear interface...

@eustas commented on GitHub (Jun 13, 2016): You are welcome. Soon we will publish v0.4 with more clear interface...
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/brotli#116