[FFmpeg-devel] [PATCH 3/6] put_bits: make avpriv_align_put_bits() inline

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Mon Oct 26 16:21:26 EET 2020


Anton Khirnov:
> This function is so extremely simple that it is preferable to make it
> inline rather than deal with all the complications arising from it being
> an exported symbol.
> 
> Keep avpriv_align_put_bits() around until the next major bump to
> preserve ABI compatibility.
> ---
>  libavcodec/aacenc.c     |  4 ++--
>  libavcodec/bitstream.c  |  4 +++-
>  libavcodec/flvenc.c     |  2 +-
>  libavcodec/h261enc.c    |  2 +-
>  libavcodec/ituh263enc.c |  2 +-
>  libavcodec/jpeglsenc.c  |  2 +-
>  libavcodec/mpeg12enc.c  |  2 +-
>  libavcodec/mpeg4audio.h |  2 +-
>  libavcodec/msmpeg4enc.c |  2 +-
>  libavcodec/put_bits.h   | 23 ++++++++++++++++++-----
>  libavcodec/rv10enc.c    |  2 +-
>  libavcodec/svq1enc.c    |  2 +-
>  libavcodec/vc2enc.c     | 14 +++++++-------
>  libavcodec/version.h    |  4 +++-
>  libavcodec/wmaenc.c     |  4 ++--
>  libavcodec/xsubenc.c    |  2 +-
>  16 files changed, 45 insertions(+), 28 deletions(-)
> 
> diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c
> index e65b76cd74..e477089f5c 100644
> --- a/libavcodec/aacenc.c
> +++ b/libavcodec/aacenc.c
> @@ -83,7 +83,7 @@ static void put_pce(PutBitContext *pb, AVCodecContext *avctx)
>          }
>      }
>  
> -    avpriv_align_put_bits(pb);
> +    align_put_bits(pb);
>      put_bits(pb, 8, strlen(aux_data));
>      avpriv_put_string(pb, aux_data, 0);
>  }
> @@ -522,7 +522,7 @@ static void put_bitstream_info(AACEncContext *s, const char *name)
>          put_bits(&s->pb, 8, namelen - 14);
>      put_bits(&s->pb, 4, 0); //extension type - filler
>      padbits = -put_bits_count(&s->pb) & 7;
> -    avpriv_align_put_bits(&s->pb);
> +    align_put_bits(&s->pb);
>      for (i = 0; i < namelen - 2; i++)
>          put_bits(&s->pb, 8, name[i]);
>      put_bits(&s->pb, 12 - padbits, 0);
> diff --git a/libavcodec/bitstream.c b/libavcodec/bitstream.c
> index 77c2b9ce05..ea0299047f 100644
> --- a/libavcodec/bitstream.c
> +++ b/libavcodec/bitstream.c
> @@ -45,10 +45,12 @@ const uint8_t ff_log2_run[41]={
>  24,
>  };
>  
> +#if FF_API_AVPRIV_PUT_BITS
>  void avpriv_align_put_bits(PutBitContext *s)
>  {
> -    put_bits(s, s->bit_left & 7, 0);
> +    align_put_bits(s);
>  }
> +#endif
>  
>  void avpriv_put_string(PutBitContext *pb, const char *string,
>                         int terminate_string)
> diff --git a/libavcodec/flvenc.c b/libavcodec/flvenc.c
> index c1227277b3..b85e4667c4 100644
> --- a/libavcodec/flvenc.c
> +++ b/libavcodec/flvenc.c
> @@ -28,7 +28,7 @@ void ff_flv_encode_picture_header(MpegEncContext *s, int picture_number)
>  {
>      int format;
>  
> -    avpriv_align_put_bits(&s->pb);
> +    align_put_bits(&s->pb);
>  
>      put_bits(&s->pb, 17, 1);
>      /* 0: H.263 escape codes 1: 11-bit escape codes */
> diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c
> index 196c37b543..909bc23bb4 100644
> --- a/libavcodec/h261enc.c
> +++ b/libavcodec/h261enc.c
> @@ -55,7 +55,7 @@ void ff_h261_encode_picture_header(MpegEncContext *s, int picture_number)
>      H261Context *h = (H261Context *)s;
>      int format, temp_ref;
>  
> -    avpriv_align_put_bits(&s->pb);
> +    align_put_bits(&s->pb);
>  
>      /* Update the pointer to last GOB */
>      s->ptr_lastgob = put_bits_ptr(&s->pb);
> diff --git a/libavcodec/ituh263enc.c b/libavcodec/ituh263enc.c
> index ee09f2974c..b1b78218a5 100644
> --- a/libavcodec/ituh263enc.c
> +++ b/libavcodec/ituh263enc.c
> @@ -124,7 +124,7 @@ void ff_h263_encode_picture_header(MpegEncContext * s, int picture_number)
>      coded_frame_rate= 1800000;
>      coded_frame_rate_base= (1000+best_clock_code)*best_divisor;
>  
> -    avpriv_align_put_bits(&s->pb);
> +    align_put_bits(&s->pb);
>  
>      /* Update the pointer to last GOB */
>      s->ptr_lastgob = put_bits_ptr(&s->pb);
> diff --git a/libavcodec/jpeglsenc.c b/libavcodec/jpeglsenc.c
> index 0725457a94..10a3bd0f61 100644
> --- a/libavcodec/jpeglsenc.c
> +++ b/libavcodec/jpeglsenc.c
> @@ -403,7 +403,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
>              put_bits(&pb, 8, v);
>          }
>      }
> -    avpriv_align_put_bits(&pb);
> +    align_put_bits(&pb);
>      av_freep(&buf2);
>  
>      /* End of image */
> diff --git a/libavcodec/mpeg12enc.c b/libavcodec/mpeg12enc.c
> index f246427eeb..46c3424de9 100644
> --- a/libavcodec/mpeg12enc.c
> +++ b/libavcodec/mpeg12enc.c
> @@ -233,7 +233,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
>  
>  static void put_header(MpegEncContext *s, int header)
>  {
> -    avpriv_align_put_bits(&s->pb);
> +    align_put_bits(&s->pb);
>      put_bits(&s->pb, 16, header >> 16);
>      put_sbits(&s->pb, 16, header);
>  }
> diff --git a/libavcodec/mpeg4audio.h b/libavcodec/mpeg4audio.h
> index c4cdc1508c..b274e92b62 100644
> --- a/libavcodec/mpeg4audio.h
> +++ b/libavcodec/mpeg4audio.h
> @@ -165,7 +165,7 @@ static inline int ff_copy_pce_data(PutBitContext *pb, GetBitContext *gb)
>          ff_pce_copy_bits(pb, gb, 16);
>      if (bits)
>          ff_pce_copy_bits(pb, gb, bits);
> -    avpriv_align_put_bits(pb);
> +    align_put_bits(pb);
>      align_get_bits(gb);
>      comment_size = ff_pce_copy_bits(pb, gb, 8);
>      for (; comment_size > 0; comment_size--)
> diff --git a/libavcodec/msmpeg4enc.c b/libavcodec/msmpeg4enc.c
> index 144468b24f..2c61735d9d 100644
> --- a/libavcodec/msmpeg4enc.c
> +++ b/libavcodec/msmpeg4enc.c
> @@ -225,7 +225,7 @@ void ff_msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number)
>  {
>      find_best_tables(s);
>  
> -    avpriv_align_put_bits(&s->pb);
> +    align_put_bits(&s->pb);
>      put_bits(&s->pb, 2, s->pict_type - 1);
>  
>      put_bits(&s->pb, 5, s->qscale);
> diff --git a/libavcodec/put_bits.h b/libavcodec/put_bits.h
> index 3ba9549948..7d17cba18b 100644
> --- a/libavcodec/put_bits.h
> +++ b/libavcodec/put_bits.h
> @@ -33,6 +33,8 @@
>  #include "libavutil/intreadwrite.h"
>  #include "libavutil/avassert.h"
>  
> +#include "version.h"
> +
>  #if ARCH_X86_64
>  // TODO: Benchmark and optionally enable on other 64-bit architectures.
>  typedef uint64_t BitBuf;
> @@ -145,15 +147,14 @@ static inline void flush_put_bits_le(PutBitContext *s)
>      s->bit_buf  = 0;
>  }
>  
> +#if FF_API_AVPRIV_PUT_BITS
> +void avpriv_align_put_bits(PutBitContext *s);
> +#endif
> +
>  #ifdef BITSTREAM_WRITER_LE
> -#define avpriv_align_put_bits align_put_bits_unsupported_here
>  #define avpriv_put_string ff_put_string_unsupported_here
>  #define avpriv_copy_bits avpriv_copy_bits_unsupported_here
>  #else
> -/**
> - * Pad the bitstream with zeros up to the next byte boundary.
> - */
> -void avpriv_align_put_bits(PutBitContext *s);
>  
>  /**
>   * Put the string string in the bitstream.
> @@ -385,6 +386,18 @@ static inline void set_put_bits_buffer_size(PutBitContext *s, int size)
>      s->size_in_bits = 8*size;
>  }
>  
> +#ifdef BITSTREAM_WRITER_LE
> +#define align_put_bits align_put_bits_unsupported_here

Unnecessary: The code below also works for LE writers, now that the LE
version of put_bits() is called.

> +#else
> +/**
> + * Pad the bitstream with zeros up to the next byte boundary.
> + */
> +static inline void align_put_bits(PutBitContext *s)
> +{
> +    put_bits(s, s->bit_left & 7, 0);
> +}
> +#endif
> +
>  #undef AV_WBBUF
>  #undef AV_WLBUF
>  
> diff --git a/libavcodec/rv10enc.c b/libavcodec/rv10enc.c
> index 55538148f2..42316836c5 100644
> --- a/libavcodec/rv10enc.c
> +++ b/libavcodec/rv10enc.c
> @@ -33,7 +33,7 @@ int ff_rv10_encode_picture_header(MpegEncContext *s, int picture_number)
>  {
>      int full_frame= 0;
>  
> -    avpriv_align_put_bits(&s->pb);
> +    align_put_bits(&s->pb);
>  
>      put_bits(&s->pb, 1, 1);     /* marker */
>  
> diff --git a/libavcodec/svq1enc.c b/libavcodec/svq1enc.c
> index 4bf9eb9a0f..9e249aefe4 100644
> --- a/libavcodec/svq1enc.c
> +++ b/libavcodec/svq1enc.c
> @@ -647,7 +647,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
>          }
>      }
>  
> -    // avpriv_align_put_bits(&s->pb);
> +    // align_put_bits(&s->pb);
>      while (put_bits_count(&s->pb) & 31)
>          put_bits(&s->pb, 1, 0);
>  
> diff --git a/libavcodec/vc2enc.c b/libavcodec/vc2enc.c
> index 2efb0f70ad..cd25884a63 100644
> --- a/libavcodec/vc2enc.c
> +++ b/libavcodec/vc2enc.c
> @@ -229,7 +229,7 @@ static void encode_parse_info(VC2EncContext *s, enum DiracParseCodes pcode)
>  {
>      uint32_t cur_pos, dist;
>  
> -    avpriv_align_put_bits(&s->pb);
> +    align_put_bits(&s->pb);
>  
>      cur_pos = put_bits_count(&s->pb) >> 3;
>  
> @@ -399,7 +399,7 @@ static void encode_source_params(VC2EncContext *s)
>  /* VC-2 11 - sequence_header() */
>  static void encode_seq_header(VC2EncContext *s)
>  {
> -    avpriv_align_put_bits(&s->pb);
> +    align_put_bits(&s->pb);
>      encode_parse_params(s);
>      put_vc2_ue_uint(&s->pb, s->base_vf);
>      encode_source_params(s);
> @@ -409,7 +409,7 @@ static void encode_seq_header(VC2EncContext *s)
>  /* VC-2 12.1 - picture_header() */
>  static void encode_picture_header(VC2EncContext *s)
>  {
> -    avpriv_align_put_bits(&s->pb);
> +    align_put_bits(&s->pb);
>      put_bits32(&s->pb, s->picture_number++);
>  }
>  
> @@ -509,15 +509,15 @@ static void encode_transform_params(VC2EncContext *s)
>  static void encode_wavelet_transform(VC2EncContext *s)
>  {
>      encode_transform_params(s);
> -    avpriv_align_put_bits(&s->pb);
> +    align_put_bits(&s->pb);
>  }
>  
>  /* VC-2 12 - picture_parse() */
>  static void encode_picture_start(VC2EncContext *s)
>  {
> -    avpriv_align_put_bits(&s->pb);
> +    align_put_bits(&s->pb);
>      encode_picture_header(s);
> -    avpriv_align_put_bits(&s->pb);
> +    align_put_bits(&s->pb);
>      encode_wavelet_transform(s);
>  }
>  
> @@ -753,7 +753,7 @@ static int encode_hq_slice(AVCodecContext *avctx, void *arg)
>                                 quants[level][orientation]);
>              }
>          }
> -        avpriv_align_put_bits(pb);
> +        align_put_bits(pb);
>          bytes_len = (put_bits_count(pb) >> 3) - bytes_start - 1;
>          if (p == 2) {
>              int len_diff = slice_bytes_max - (put_bits_count(pb) >> 3);
> diff --git a/libavcodec/version.h b/libavcodec/version.h
> index 02ffa95749..78c4dd64ee 100644
> --- a/libavcodec/version.h
> +++ b/libavcodec/version.h
> @@ -144,6 +144,8 @@
>  #ifndef FF_API_UNUSED_CODEC_CAPS
>  #define FF_API_UNUSED_CODEC_CAPS   (LIBAVCODEC_VERSION_MAJOR < 59)
>  #endif
> -
> +#ifndef FF_API_AVPRIV_PUT_BITS
> +#define FF_API_AVPRIV_PUT_BITS     (LIBAVCODEC_VERSION_MAJOR < 59)
> +#endif
>  

Why are you adding this instead of checking for LIBAVCODEC_VERSION_MAJOR
< 59? After all, avpriv functions don't require a deprecation period and
so there is no reason to postpone removing them to version 60.

>  #endif /* AVCODEC_VERSION_H */
> diff --git a/libavcodec/wmaenc.c b/libavcodec/wmaenc.c
> index 091bc2ac3b..6a7e23d016 100644
> --- a/libavcodec/wmaenc.c
> +++ b/libavcodec/wmaenc.c
> @@ -343,7 +343,7 @@ static int encode_block(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE],
>                           s->coef_vlcs[tindex]->huffcodes[1]);
>          }
>          if (s->version == 1 && s->avctx->channels >= 2)
> -            avpriv_align_put_bits(&s->pb);
> +            align_put_bits(&s->pb);
>      }
>      return 0;
>  }
> @@ -358,7 +358,7 @@ static int encode_frame(WMACodecContext *s, float (*src_coefs)[BLOCK_MAX_SIZE],
>      else if (encode_block(s, src_coefs, total_gain) < 0)
>          return INT_MAX;
>  
> -    avpriv_align_put_bits(&s->pb);
> +    align_put_bits(&s->pb);
>  
>      return put_bits_count(&s->pb) / 8 - s->avctx->block_align;
>  }
> diff --git a/libavcodec/xsubenc.c b/libavcodec/xsubenc.c
> index 349c1bca3c..58be5e6deb 100644
> --- a/libavcodec/xsubenc.c
> +++ b/libavcodec/xsubenc.c
> @@ -90,7 +90,7 @@ static int xsub_encode_rle(PutBitContext *pb, const uint8_t *bitmap,
>          if (color != PADDING_COLOR && (PADDING + (w&1)))
>              put_xsub_rle(pb, PADDING + (w&1), PADDING_COLOR);
>  
> -        avpriv_align_put_bits(pb);
> +        align_put_bits(pb);
>  
>          bitmap += linesize;
>      }
> 



More information about the ffmpeg-devel mailing list