[FFmpeg-cvslog] avcodec/put_bits: Fix LZW warning

Steinar H. Gunderson git at videolan.org
Mon Jul 20 20:57:23 EEST 2020


ffmpeg | branch: master | Steinar H. Gunderson <steinar+ffmpeg at gunderson.no> | Sun Jul 19 20:29:29 2020 +0200| [80286671c5594957d74120b3b5f47b774e98c661] | committer: Michael Niedermayer

avcodec/put_bits: Fix LZW warning

lzwenc stores a function pointer to either put_bits or put_bits_le;
however, after the recent change, the function pointer's prototype
would depend on BitBuf. BitBuf is defined in put_bits.h, whose
definition depends on whether BITSTREAM_WRITER_LE is #defined or not.
For safety, we set a boolean flag for little/big endian instead,
which also allows the definition to be inlined.

Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=80286671c5594957d74120b3b5f47b774e98c661
---

 libavcodec/gif.c     |  4 ++--
 libavcodec/lzw.h     |  6 ++----
 libavcodec/lzwenc.c  | 28 ++++++++++++++++++----------
 libavcodec/tiffenc.c |  4 ++--
 4 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/libavcodec/gif.c b/libavcodec/gif.c
index e2242d0438..e92dfa65d7 100644
--- a/libavcodec/gif.c
+++ b/libavcodec/gif.c
@@ -344,7 +344,7 @@ static int gif_image_write_image(AVCodecContext *avctx,
     bytestream_put_byte(bytestream, 0x08);
 
     ff_lzw_encode_init(s->lzw, s->buf, s->buf_size,
-                       12, FF_LZW_GIF, put_bits);
+                       12, FF_LZW_GIF, 1);
 
     ptr = buf + y_start*linesize + x_start;
     if (honor_transparency) {
@@ -366,7 +366,7 @@ static int gif_image_write_image(AVCodecContext *avctx,
             ptr += linesize;
         }
     }
-    len += ff_lzw_encode_flush(s->lzw, flush_put_bits);
+    len += ff_lzw_encode_flush(s->lzw);
 
     ptr = s->buf;
     while (len > 0) {
diff --git a/libavcodec/lzw.h b/libavcodec/lzw.h
index 6af8a6b83a..dae4d05225 100644
--- a/libavcodec/lzw.h
+++ b/libavcodec/lzw.h
@@ -54,10 +54,8 @@ struct LZWEncodeState;
 extern const int ff_lzw_encode_state_size;
 
 void ff_lzw_encode_init(struct LZWEncodeState *s, uint8_t *outbuf, int outsize,
-                        int maxbits, enum FF_LZW_MODES mode,
-                        void (*lzw_put_bits)(struct PutBitContext *, int, unsigned int));
+                        int maxbits, enum FF_LZW_MODES mode, int little_endian);
 int ff_lzw_encode(struct LZWEncodeState * s, const uint8_t * inbuf, int insize);
-int ff_lzw_encode_flush(struct LZWEncodeState *s,
-                        void (*lzw_flush_put_bits)(struct PutBitContext *));
+int ff_lzw_encode_flush(struct LZWEncodeState *s);
 
 #endif /* AVCODEC_LZW_H */
diff --git a/libavcodec/lzwenc.c b/libavcodec/lzwenc.c
index 03080ee587..e693d74272 100644
--- a/libavcodec/lzwenc.c
+++ b/libavcodec/lzwenc.c
@@ -60,7 +60,7 @@ typedef struct LZWEncodeState {
     int output_bytes;        ///< Number of written bytes
     int last_code;           ///< Value of last output code or LZW_PREFIX_EMPTY
     enum FF_LZW_MODES mode;  ///< TIFF or GIF
-    void (*put_bits)(PutBitContext *, int, unsigned); ///< GIF is LE while TIFF is BE
+    int little_endian;       ///< GIF is LE while TIFF is BE
 }LZWEncodeState;
 
 
@@ -113,7 +113,10 @@ static inline int hashOffset(const int head)
 static inline void writeCode(LZWEncodeState * s, int c)
 {
     av_assert2(0 <= c && c < 1 << s->bits);
-    s->put_bits(&s->pb, s->bits, c);
+    if (s->little_endian)
+        put_bits_le(&s->pb, s->bits, c);
+    else
+        put_bits(&s->pb, s->bits, c);
 }
 
 
@@ -200,8 +203,7 @@ static int writtenBytes(LZWEncodeState *s){
  * @param maxbits Maximum length of code
  */
 void ff_lzw_encode_init(LZWEncodeState *s, uint8_t *outbuf, int outsize,
-                        int maxbits, enum FF_LZW_MODES mode,
-                        void (*lzw_put_bits)(PutBitContext *, int, unsigned))
+                        int maxbits, enum FF_LZW_MODES mode, int little_endian)
 {
     s->clear_code = 256;
     s->end_code = 257;
@@ -214,7 +216,7 @@ void ff_lzw_encode_init(LZWEncodeState *s, uint8_t *outbuf, int outsize,
     s->last_code = LZW_PREFIX_EMPTY;
     s->bits = 9;
     s->mode = mode;
-    s->put_bits = lzw_put_bits;
+    s->little_endian = little_endian;
 }
 
 /**
@@ -257,16 +259,22 @@ int ff_lzw_encode(LZWEncodeState * s, const uint8_t * inbuf, int insize)
  * @param s LZW state
  * @return Number of bytes written or -1 on error
  */
-int ff_lzw_encode_flush(LZWEncodeState *s,
-                        void (*lzw_flush_put_bits)(PutBitContext *))
+int ff_lzw_encode_flush(LZWEncodeState *s)
 {
     if (s->last_code != -1)
         writeCode(s, s->last_code);
     writeCode(s, s->end_code);
-    if (s->mode == FF_LZW_GIF)
-        s->put_bits(&s->pb, 1, 0);
+    if (s->little_endian) {
+        if (s->mode == FF_LZW_GIF)
+            put_bits_le(&s->pb, 1, 0);
 
-    lzw_flush_put_bits(&s->pb);
+        flush_put_bits_le(&s->pb);
+    } else {
+        if (s->mode == FF_LZW_GIF)
+            put_bits(&s->pb, 1, 0);
+
+        flush_put_bits(&s->pb);
+    }
     s->last_code = -1;
 
     return writtenBytes(s);
diff --git a/libavcodec/tiffenc.c b/libavcodec/tiffenc.c
index a122f51de4..6661e59d31 100644
--- a/libavcodec/tiffenc.c
+++ b/libavcodec/tiffenc.c
@@ -421,7 +421,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
             if (s->compr == TIFF_LZW) {
                 ff_lzw_encode_init(s->lzws, ptr,
                                    s->buf_size - (*s->buf - s->buf_start),
-                                   12, FF_LZW_TIFF, put_bits);
+                                   12, FF_LZW_TIFF, 0);
             }
             s->strip_offsets[i / s->rps] = ptr - pkt->data;
         }
@@ -440,7 +440,7 @@ static int encode_frame(AVCodecContext *avctx, AVPacket *pkt,
         ptr                     += ret;
         if (s->compr == TIFF_LZW &&
             (i == s->height - 1 || i % s->rps == s->rps - 1)) {
-            ret = ff_lzw_encode_flush(s->lzws, flush_put_bits);
+            ret = ff_lzw_encode_flush(s->lzws);
             s->strip_sizes[(i / s->rps)] += ret;
             ptr                          += ret;
         }



More information about the ffmpeg-cvslog mailing list