[FFmpeg-devel] [PATCH 1/3] lavc/h274: fix PRNG definition

Michael Niedermayer michael at niedermayer.cc
Wed Sep 27 22:07:55 EEST 2023


On Wed, Sep 27, 2023 at 03:56:15PM +0200, Niklas Haas wrote:
> From: Niklas Haas <git at haasn.dev>
> 
> The spec specifies x^31 + x^3 + 1 as the polynomial, but the diagram in
> Figure 1-1 omits the +1 offset. The initial implementation was based on
> the diagram, but this is wrong (produces subtly incorrect results).
> ---
>  libavcodec/h274.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libavcodec/h274.c b/libavcodec/h274.c
> index a69f9411429..fc111cdb50d 100644
> --- a/libavcodec/h274.c
> +++ b/libavcodec/h274.c
> @@ -38,7 +38,7 @@ static void prng_shift(uint32_t *state)
>  {
>      // Primitive polynomial x^31 + x^3 + 1 (modulo 2)
>      uint32_t x = *state;
> -    uint8_t feedback = (x >> 2) ^ (x >> 30);
> +    uint8_t feedback = 1u ^ (x >> 2) ^ (x >> 30);
>      *state = (x << 1) | (feedback & 1u);

where can i find the text describing this that you refer to ?

thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Rewriting code that is poorly written but fully understood is good.
Rewriting code that one doesnt understand is a sign that one is less smart
than the original author, trying to rewrite it will not make it better.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20230927/d7c389ba/attachment.sig>


More information about the ffmpeg-devel mailing list