Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/oapv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,7 @@ static int enc_frame(oapve_ctx_t *ctx, oapv_bs_t *bs)
/****************************************************/

for(int i = 0; i < ctx->num_tiles; i++) {
oapv_assert_gv(bs_tile_pos + ctx->tile[i].bs_size <= bs->end, ret, OAPV_ERR_OUT_OF_BS_BUF, ERR);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is for encoding process, so that the tile[i].bs_size has correct number.
If the address is located in outside of available bitstream buffer, enc_tile() returns error.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the check at enc_tile() happens after enc_tile_comp where the buffer overrun can happen.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, each individual tile buffer (tile[i].bs_size) may be fit, but when assembling all encoded tiles into common "bs" we need to check if the sum of tiles doesn't exceed the common "bs" size. I.e. those are different checks.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

oapv_mcpy(bs_tile_pos, ctx->tile[i].bs_buf, ctx->tile[i].bs_size);
bs_tile_pos = bs_tile_pos + ctx->tile[i].bs_size;
ctx->fh.tile_size[i] = ctx->tile[i].bs_size - OAPV_TILE_SIZE_LEN;
Expand Down
32 changes: 20 additions & 12 deletions src/oapv_vlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,31 @@
#if ENABLE_ENCODER
///////////////////////////////////////////////////////////////////////////////
#define BSW_FLUSH_4BYTE(bs) { \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is called anywhere. It will be removed.

*(bs)->cur++ = ((bs)->code >> 24) & 0xFF; \
*(bs)->cur++ = ((bs)->code >> 16) & 0xFF; \
*(bs)->cur++ = ((bs)->code >> 8) & 0xFF; \
*(bs)->cur++ = ((bs)->code) & 0xFF; \
if ((bs)->cur + 4 <= (bs)->end) { \
*(bs)->cur++ = ((bs)->code >> 24) & 0xFF; \
*(bs)->cur++ = ((bs)->code >> 16) & 0xFF; \
*(bs)->cur++ = ((bs)->code >> 8) & 0xFF; \
*(bs)->cur++ = ((bs)->code) & 0xFF; \
} else { \
(bs)->cur += 4; \
} \
(bs)->code = 0; \
(bs)->leftbits = 32; \
}

#define BSW_FLUSH_8BYTE(bs) { \

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is called anywhere. It will be removed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is called in BSW_WRITE_64BITS and BSW_WRITE_64BITS is called in oapve_vlc_ac_coef and oapve_vlc_ac_coef is called in enc_tile_comp, or am I missing something?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, one branch in vlc loop code, it makes noticeable speed-down.
It is assumed that the input buffer should be allocated large enough.
This code should be reconsidered.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to suggest to merge this PR without BSW_WRITE_XX changes.
I think we can reconsider BSW_WRITE_XX code changes if some noticeable issue occurs.

*(bs)->cur++ = ((bs)->code >> 56) & 0xFF; \
*(bs)->cur++ = ((bs)->code >> 48) & 0xFF; \
*(bs)->cur++ = ((bs)->code >> 40) & 0xFF; \
*(bs)->cur++ = ((bs)->code >> 32) & 0xFF; \
*(bs)->cur++ = ((bs)->code >> 24) & 0xFF; \
*(bs)->cur++ = ((bs)->code >> 16) & 0xFF; \
*(bs)->cur++ = ((bs)->code >> 8) & 0xFF; \
*(bs)->cur++ = ((bs)->code) & 0xFF; \
if ((bs)->cur + 8 <= (bs)->end) { \
*(bs)->cur++ = ((bs)->code >> 56) & 0xFF; \
*(bs)->cur++ = ((bs)->code >> 48) & 0xFF; \
*(bs)->cur++ = ((bs)->code >> 40) & 0xFF; \
*(bs)->cur++ = ((bs)->code >> 32) & 0xFF; \
*(bs)->cur++ = ((bs)->code >> 24) & 0xFF; \
*(bs)->cur++ = ((bs)->code >> 16) & 0xFF; \
*(bs)->cur++ = ((bs)->code >> 8) & 0xFF; \
*(bs)->cur++ = ((bs)->code) & 0xFF; \
} else { \
(bs)->cur += 8; \
} \
(bs)->code = 0; \
(bs)->leftbits = 64; \
}
Expand Down