Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Subject: Re: [FFmpeg-devel] [PATCH] avcodec/golomb: Factor writing golomb codes out
Date: Wed, 5 Jan 2022 22:25:23 +0100
Message-ID: <AM7PR03MB66608B0191969283B6B1F31B8F4B9@AM7PR03MB6660.eurprd03.prod.outlook.com> (raw)
In-Reply-To: <AM7PR03MB666019EB9576AE91BE1B5CEA8F499@AM7PR03MB6660.eurprd03.prod.outlook.com>

Andreas Rheinhardt:
> Most users only want to either read or write golomb codes, not both.
> By splitting these headers one avoids having unnecesssary
> (get|put)_hits.h inclusions.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavcodec/ffv1enc.c      |   2 +-
>  libavcodec/flacenc.c      |   2 +-
>  libavcodec/golomb.h       | 132 ------------------------------
>  libavcodec/hevc_ps_enc.c  |   2 +-
>  libavcodec/jpeglsenc.c    |   2 +-
>  libavcodec/put_golomb.h   | 168 ++++++++++++++++++++++++++++++++++++++
>  libavcodec/sonic.c        |   1 +
>  libavcodec/tests/golomb.c |   1 +
>  8 files changed, 174 insertions(+), 136 deletions(-)
>  create mode 100644 libavcodec/put_golomb.h
> 
> diff --git a/libavcodec/ffv1enc.c b/libavcodec/ffv1enc.c
> index 69b9065343..d29f62bf56 100644
> --- a/libavcodec/ffv1enc.c
> +++ b/libavcodec/ffv1enc.c
> @@ -36,8 +36,8 @@
>  #include "encode.h"
>  #include "internal.h"
>  #include "put_bits.h"
> +#include "put_golomb.h"
>  #include "rangecoder.h"
> -#include "golomb.h"
>  #include "mathops.h"
>  #include "ffv1.h"
>  
> diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c
> index 595928927d..9f6f449323 100644
> --- a/libavcodec/flacenc.c
> +++ b/libavcodec/flacenc.c
> @@ -30,7 +30,7 @@
>  #include "bswapdsp.h"
>  #include "encode.h"
>  #include "put_bits.h"
> -#include "golomb.h"
> +#include "put_golomb.h"
>  #include "internal.h"
>  #include "lpc.h"
>  #include "flac.h"
> diff --git a/libavcodec/golomb.h b/libavcodec/golomb.h
> index 4d531cf805..8233871137 100644
> --- a/libavcodec/golomb.h
> +++ b/libavcodec/golomb.h
> @@ -33,7 +33,6 @@
>  #include <stdint.h>
>  
>  #include "get_bits.h"
> -#include "put_bits.h"
>  
>  #define INVALID_VLC           0x80000000
>  
> @@ -615,135 +614,4 @@ static inline int get_te(GetBitContext *s, int r, char *file, const char *func,
>  #define get_te0_golomb(a, r) get_te(a, r, __FILE__, __func__, __LINE__)
>  
>  #endif /* TRACE */
> -
> -/**
> - * write unsigned exp golomb code. 2^16 - 2 at most
> - */
> -static inline void set_ue_golomb(PutBitContext *pb, int i)
> -{
> -    av_assert2(i >= 0);
> -    av_assert2(i <= 0xFFFE);
> -
> -    if (i < 256)
> -        put_bits(pb, ff_ue_golomb_len[i], i + 1);
> -    else {
> -        int e = av_log2(i + 1);
> -        put_bits(pb, 2 * e + 1, i + 1);
> -    }
> -}
> -
> -/**
> - * write unsigned exp golomb code. 2^32-2 at most.
> - */
> -static inline void set_ue_golomb_long(PutBitContext *pb, uint32_t i)
> -{
> -    av_assert2(i <= (UINT32_MAX - 1));
> -
> -    if (i < 256)
> -        put_bits(pb, ff_ue_golomb_len[i], i + 1);
> -    else {
> -        int e = av_log2(i + 1);
> -        put_bits64(pb, 2 * e + 1, i + 1);
> -    }
> -}
> -
> -/**
> - * write truncated unsigned exp golomb code.
> - */
> -static inline void set_te_golomb(PutBitContext *pb, int i, int range)
> -{
> -    av_assert2(range >= 1);
> -    av_assert2(i <= range);
> -
> -    if (range == 2)
> -        put_bits(pb, 1, i ^ 1);
> -    else
> -        set_ue_golomb(pb, i);
> -}
> -
> -/**
> - * write signed exp golomb code. 16 bits at most.
> - */
> -static inline void set_se_golomb(PutBitContext *pb, int i)
> -{
> -    i = 2 * i - 1;
> -    if (i < 0)
> -        i ^= -1;    //FIXME check if gcc does the right thing
> -    set_ue_golomb(pb, i);
> -}
> -
> -/**
> - * write unsigned golomb rice code (ffv1).
> - */
> -static inline void set_ur_golomb(PutBitContext *pb, int i, int k, int limit,
> -                                 int esc_len)
> -{
> -    int e;
> -
> -    av_assert2(i >= 0);
> -
> -    e = i >> k;
> -    if (e < limit)
> -        put_bits(pb, e + k + 1, (1 << k) + av_mod_uintp2(i, k));
> -    else
> -        put_bits(pb, limit + esc_len, i - limit + 1);
> -}
> -
> -/**
> - * write unsigned golomb rice code (jpegls).
> - */
> -static inline void set_ur_golomb_jpegls(PutBitContext *pb, int i, int k,
> -                                        int limit, int esc_len)
> -{
> -    int e;
> -
> -    av_assert2(i >= 0);
> -
> -    e = (i >> k) + 1;
> -    if (e < limit) {
> -        while (e > 31) {
> -            put_bits(pb, 31, 0);
> -            e -= 31;
> -        }
> -        put_bits(pb, e, 1);
> -        if (k)
> -            put_sbits(pb, k, i);
> -    } else {
> -        while (limit > 31) {
> -            put_bits(pb, 31, 0);
> -            limit -= 31;
> -        }
> -        put_bits(pb, limit, 1);
> -        put_bits(pb, esc_len, i - 1);
> -    }
> -}
> -
> -/**
> - * write signed golomb rice code (ffv1).
> - */
> -static inline void set_sr_golomb(PutBitContext *pb, int i, int k, int limit,
> -                                 int esc_len)
> -{
> -    int v;
> -
> -    v  = -2 * i - 1;
> -    v ^= (v >> 31);
> -
> -    set_ur_golomb(pb, v, k, limit, esc_len);
> -}
> -
> -/**
> - * write signed golomb rice code (flac).
> - */
> -static inline void set_sr_golomb_flac(PutBitContext *pb, int i, int k,
> -                                      int limit, int esc_len)
> -{
> -    int v;
> -
> -    v  = -2 * i - 1;
> -    v ^= (v >> 31);
> -
> -    set_ur_golomb_jpegls(pb, v, k, limit, esc_len);
> -}
> -
>  #endif /* AVCODEC_GOLOMB_H */
> diff --git a/libavcodec/hevc_ps_enc.c b/libavcodec/hevc_ps_enc.c
> index 47f252dd2c..72641b2ffb 100644
> --- a/libavcodec/hevc_ps_enc.c
> +++ b/libavcodec/hevc_ps_enc.c
> @@ -18,7 +18,7 @@
>   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
>   */
>  
> -#include "golomb.h"
> +#include "put_golomb.h"
>  #include "hevc_ps.h"
>  #include "put_bits.h"
>  
> diff --git a/libavcodec/jpeglsenc.c b/libavcodec/jpeglsenc.c
> index beae3bb77f..83b2350a15 100644
> --- a/libavcodec/jpeglsenc.c
> +++ b/libavcodec/jpeglsenc.c
> @@ -32,7 +32,7 @@
>  #include "encode.h"
>  #include "get_bits.h"
>  #include "put_bits.h"
> -#include "golomb.h"
> +#include "put_golomb.h"
>  #include "internal.h"
>  #include "mathops.h"
>  #include "mjpeg.h"
> diff --git a/libavcodec/put_golomb.h b/libavcodec/put_golomb.h
> new file mode 100644
> index 0000000000..9ca911fc3c
> --- /dev/null
> +++ b/libavcodec/put_golomb.h
> @@ -0,0 +1,168 @@
> +/*
> + * exp golomb vlc writing stuff
> + * Copyright (c) 2003 Michael Niedermayer <michaelni@gmx.at>
> + * Copyright (c) 2004 Alex Beregszaszi
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +/**
> + * @file
> + * @brief
> + *     exp golomb vlc writing stuff
> + * @author Michael Niedermayer <michaelni@gmx.at> and Alex Beregszaszi
> + */
> +
> +#ifndef AVCODEC_PUT_GOLOMB_H
> +#define AVCODEC_PUT_GOLOMB_H
> +
> +#include <stdint.h>
> +#include "put_bits.h"
> +
> +extern const uint8_t ff_ue_golomb_len[256];
> +
> +/**
> + * write unsigned exp golomb code. 2^16 - 2 at most
> + */
> +static inline void set_ue_golomb(PutBitContext *pb, int i)
> +{
> +    av_assert2(i >= 0);
> +    av_assert2(i <= 0xFFFE);
> +
> +    if (i < 256)
> +        put_bits(pb, ff_ue_golomb_len[i], i + 1);
> +    else {
> +        int e = av_log2(i + 1);
> +        put_bits(pb, 2 * e + 1, i + 1);
> +    }
> +}
> +
> +/**
> + * write unsigned exp golomb code. 2^32-2 at most.
> + */
> +static inline void set_ue_golomb_long(PutBitContext *pb, uint32_t i)
> +{
> +    av_assert2(i <= (UINT32_MAX - 1));
> +
> +    if (i < 256)
> +        put_bits(pb, ff_ue_golomb_len[i], i + 1);
> +    else {
> +        int e = av_log2(i + 1);
> +        put_bits64(pb, 2 * e + 1, i + 1);
> +    }
> +}
> +
> +/**
> + * write truncated unsigned exp golomb code.
> + */
> +static inline void set_te_golomb(PutBitContext *pb, int i, int range)
> +{
> +    av_assert2(range >= 1);
> +    av_assert2(i <= range);
> +
> +    if (range == 2)
> +        put_bits(pb, 1, i ^ 1);
> +    else
> +        set_ue_golomb(pb, i);
> +}
> +
> +/**
> + * write signed exp golomb code. 16 bits at most.
> + */
> +static inline void set_se_golomb(PutBitContext *pb, int i)
> +{
> +    i = 2 * i - 1;
> +    if (i < 0)
> +        i ^= -1;    //FIXME check if gcc does the right thing
> +    set_ue_golomb(pb, i);
> +}
> +
> +/**
> + * write unsigned golomb rice code (ffv1).
> + */
> +static inline void set_ur_golomb(PutBitContext *pb, int i, int k, int limit,
> +                                 int esc_len)
> +{
> +    int e;
> +
> +    av_assert2(i >= 0);
> +
> +    e = i >> k;
> +    if (e < limit)
> +        put_bits(pb, e + k + 1, (1 << k) + av_mod_uintp2(i, k));
> +    else
> +        put_bits(pb, limit + esc_len, i - limit + 1);
> +}
> +
> +/**
> + * write unsigned golomb rice code (jpegls).
> + */
> +static inline void set_ur_golomb_jpegls(PutBitContext *pb, int i, int k,
> +                                        int limit, int esc_len)
> +{
> +    int e;
> +
> +    av_assert2(i >= 0);
> +
> +    e = (i >> k) + 1;
> +    if (e < limit) {
> +        while (e > 31) {
> +            put_bits(pb, 31, 0);
> +            e -= 31;
> +        }
> +        put_bits(pb, e, 1);
> +        if (k)
> +            put_sbits(pb, k, i);
> +    } else {
> +        while (limit > 31) {
> +            put_bits(pb, 31, 0);
> +            limit -= 31;
> +        }
> +        put_bits(pb, limit, 1);
> +        put_bits(pb, esc_len, i - 1);
> +    }
> +}
> +
> +/**
> + * write signed golomb rice code (ffv1).
> + */
> +static inline void set_sr_golomb(PutBitContext *pb, int i, int k, int limit,
> +                                 int esc_len)
> +{
> +    int v;
> +
> +    v  = -2 * i - 1;
> +    v ^= (v >> 31);
> +
> +    set_ur_golomb(pb, v, k, limit, esc_len);
> +}
> +
> +/**
> + * write signed golomb rice code (flac).
> + */
> +static inline void set_sr_golomb_flac(PutBitContext *pb, int i, int k,
> +                                      int limit, int esc_len)
> +{
> +    int v;
> +
> +    v  = -2 * i - 1;
> +    v ^= (v >> 31);
> +
> +    set_ur_golomb_jpegls(pb, v, k, limit, esc_len);
> +}
> +
> +#endif /* AVCODEC_PUT_GOLOMB_H */
> diff --git a/libavcodec/sonic.c b/libavcodec/sonic.c
> index 63a613f77d..cf1cfb1460 100644
> --- a/libavcodec/sonic.c
> +++ b/libavcodec/sonic.c
> @@ -23,6 +23,7 @@
>  #include "get_bits.h"
>  #include "golomb.h"
>  #include "internal.h"
> +#include "put_golomb.h"
>  #include "rangecoder.h"
>  
>  
> diff --git a/libavcodec/tests/golomb.c b/libavcodec/tests/golomb.c
> index 85b8a9390b..061cc013ce 100644
> --- a/libavcodec/tests/golomb.c
> +++ b/libavcodec/tests/golomb.c
> @@ -27,6 +27,7 @@
>  #include "libavcodec/get_bits.h"
>  #include "libavcodec/golomb.h"
>  #include "libavcodec/put_bits.h"
> +#include "libavcodec/put_golomb.h"
>  
>  #define COUNT 8191
>  #define SIZE (COUNT * 4)
> 

Will apply tomorrow unless there are objections.

- Andreas
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

      reply	other threads:[~2022-01-05 21:25 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-03 11:50 Andreas Rheinhardt
2022-01-05 21:25 ` Andreas Rheinhardt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=AM7PR03MB66608B0191969283B6B1F31B8F4B9@AM7PR03MB6660.eurprd03.prod.outlook.com \
    --to=andreas.rheinhardt@outlook.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git