Skip to content

Commit

Permalink
Fix exit_symbol() requirement of bitstream conformance
Browse files Browse the repository at this point in the history
  • Loading branch information
chai51 committed Nov 27, 2024
1 parent fc3f455 commit 799beca
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -32868,7 +32868,7 @@ <h4 id="exit-process-for-symbol-decoder">Exit process for symbol decoder</h4>
<p>It is a requirement of bitstream conformance that SymbolMaxBits is greater than or
equal to -14 whenever this process is invoked.</p>

<p>The variable trailingBitPosition is set equal to get_position() - Min(15, SymbolMaxBits+15).</p>
<p>The variable trailingBitPosition is set equal to get_position() - Min(14, SymbolMaxBits+14).</p>

<p>The bitstream position indicator is advanced by Max(0,SymbolMaxBits).
(This skips over any trailing bits that have not already been read during symbol decode.)</p>
Expand Down

3 comments on commit 799beca

@chai51
Copy link

@chai51 chai51 commented on 799beca Nov 27, 2024

Choose a reason for hiding this comment

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

requirement of bitstream conformance that the bit at position trailingBitPosition is equal to 1. [1] The variable trailingBitPosition is set equal to get_position() - Min(14, SymbolMaxBits+14).

[1] https://aomedia.googlesource.com/aom/+/refs/heads/main/aom_dsp/entdec.c , trace variable dec->tell_offs

@wantehchang
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @chai51,

Thank you for the proposed change. I am not familiar this part of the AV1 specification. I worked out two examples where there are no encoded symbols in the input, the input consists of trailing bits only.

Assume get_position() is initiallly 0.

Example 1:

    init_symbol(sz=1)  // Input is 0x80, i.e., one byte of trailing bits
    exit_symbol()

In init_symbol(sz=1), numBits is Min(1 * 8, 15) = 8. f(8) is read, so get_position() becomes 8. SymbolMaxBits is 8 * 1 - 15 = -7.
In exit_symbol(), get_position() - Min(15, SymbolMaxBits+15) is 8 - Min(15, -7+15) = 8 - 8 = 0, which is the position of the 1 bit in the trailing bits.,

Example 2:

    init_symbol(sz=3)  // Input is 0x80, 0x00, 0x00, i.e., three bytes of trailing bits
    exit_symbol

In init_symbol(sz=3), numBits is Min(3 * 8, 15) = 15. f(15) is read, so get_position() becomes 15. SymbolMaxBits is 8 * 3 - 15 = 9.
In exit_symbol(), get_position() - Min(15, SymbolMaxBits+15) is 15 - Min(15, 9+15) = 15 - 15 = 0, which is the position of the 1 bit in the trailing bits.,

So the trailingBitPosition definition in the spec, get_position() - Min(15, SymbolMaxBits+15), is correct for these two examples. Your proposed change, get_position() - Min(14, SymbolMaxBits+14), would be incorrect for these two examples.

@chai51
Copy link

@chai51 chai51 commented on 799beca Nov 30, 2024

Choose a reason for hiding this comment

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

Thank you. I misunderstood earlier. Thank you for your correction. Now the problem has been solved.

Please sign in to comment.