[FFmpeg-cvslog] avcodec/mjpegenc: Simplify by moving assert into ff_mjpeg_encode_huffman_close()

Michael Niedermayer git at videolan.org
Fri Feb 10 02:06:24 EET 2017


ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Fri Feb 10 00:18:34 2017 +0100| [ce6e7a2db1a4fc0c0294b23e3d62a492af0d0359] | committer: Michael Niedermayer

avcodec/mjpegenc: Simplify by moving assert into ff_mjpeg_encode_huffman_close()

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

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

 libavcodec/mjpegenc_common.c  | 28 ++++++++++++----------------
 libavcodec/mjpegenc_huffman.c | 12 ++++--------
 libavcodec/mjpegenc_huffman.h |  6 +++---
 3 files changed, 19 insertions(+), 27 deletions(-)

diff --git a/libavcodec/mjpegenc_common.c b/libavcodec/mjpegenc_common.c
index 722ad5e..70b036d 100644
--- a/libavcodec/mjpegenc_common.c
+++ b/libavcodec/mjpegenc_common.c
@@ -444,22 +444,18 @@ static void ff_mjpeg_build_optimal_huffman(MJpegContext *m)
         ff_mjpeg_encode_huffman_increment(ctx[table_id], code);
     }
 
-    ret = ff_mjpeg_encode_huffman_close(&dc_luminance_ctx,
-                                        m->bits_dc_luminance,
-                                        m->val_dc_luminance, 12);
-    av_assert0(!ret);
-    ret = ff_mjpeg_encode_huffman_close(&dc_chrominance_ctx,
-                                        m->bits_dc_chrominance,
-                                        m->val_dc_chrominance, 12);
-    av_assert0(!ret);
-    ret = ff_mjpeg_encode_huffman_close(&ac_luminance_ctx,
-                                        m->bits_ac_luminance,
-                                        m->val_ac_luminance, 256);
-    av_assert0(!ret);
-    ret = ff_mjpeg_encode_huffman_close(&ac_chrominance_ctx,
-                                        m->bits_ac_chrominance,
-                                        m->val_ac_chrominance, 256);
-    av_assert0(!ret);
+    ff_mjpeg_encode_huffman_close(&dc_luminance_ctx,
+                                  m->bits_dc_luminance,
+                                  m->val_dc_luminance, 12);
+    ff_mjpeg_encode_huffman_close(&dc_chrominance_ctx,
+                                  m->bits_dc_chrominance,
+                                  m->val_dc_chrominance, 12);
+    ff_mjpeg_encode_huffman_close(&ac_luminance_ctx,
+                                  m->bits_ac_luminance,
+                                  m->val_ac_luminance, 256);
+    ff_mjpeg_encode_huffman_close(&ac_chrominance_ctx,
+                                  m->bits_ac_chrominance,
+                                  m->val_ac_chrominance, 256);
 
     ff_mjpeg_build_huffman_codes(m->huff_size_dc_luminance,
                                  m->huff_code_dc_luminance,
diff --git a/libavcodec/mjpegenc_huffman.c b/libavcodec/mjpegenc_huffman.c
index e1d300b..ebf1311 100644
--- a/libavcodec/mjpegenc_huffman.c
+++ b/libavcodec/mjpegenc_huffman.c
@@ -22,6 +22,7 @@
 #include <string.h>
 #include <stdint.h>
 #include <stdlib.h>
+#include "libavutil/avassert.h"
 #include "libavutil/common.h"
 #include "libavutil/error.h"
 #include "libavutil/qsort.h"
@@ -154,10 +155,9 @@ void ff_mjpeg_encode_huffman_init(MJpegEncHuffmanContext *s)
  * @param bits      output array where the ith character represents how many input values have i length encoding
  * @param val       output array of input values sorted by their encoded length
  * @param max_nval  maximum number of distinct input values
- * @return int      Return code, 0 if succeeded.
  */
-int ff_mjpeg_encode_huffman_close(MJpegEncHuffmanContext *s, uint8_t bits[17],
-                                  uint8_t val[], int max_nval)
+void ff_mjpeg_encode_huffman_close(MJpegEncHuffmanContext *s, uint8_t bits[17],
+                                   uint8_t val[], int max_nval)
 {
     int i, j;
     int nval = 0;
@@ -167,9 +167,7 @@ int ff_mjpeg_encode_huffman_close(MJpegEncHuffmanContext *s, uint8_t bits[17],
     for (i = 0; i < 256; i++) {
         if (s->val_count[i]) nval++;
     }
-    if (nval > max_nval) {
-        return AVERROR(EINVAL);
-    }
+    av_assert0 (nval <= max_nval);
 
     j = 0;
     for (i = 0; i < 256; i++) {
@@ -189,6 +187,4 @@ int ff_mjpeg_encode_huffman_close(MJpegEncHuffmanContext *s, uint8_t bits[17],
         val[i] = distincts[i].code;
         bits[distincts[i].length]++;
     }
-
-    return 0;
 }
diff --git a/libavcodec/mjpegenc_huffman.h b/libavcodec/mjpegenc_huffman.h
index ec6251b..a4c53d0 100644
--- a/libavcodec/mjpegenc_huffman.h
+++ b/libavcodec/mjpegenc_huffman.h
@@ -38,9 +38,9 @@ static inline void ff_mjpeg_encode_huffman_increment(MJpegEncHuffmanContext *s,
 {
     s->val_count[val]++;
 }
-int ff_mjpeg_encode_huffman_close(MJpegEncHuffmanContext *s,
-                                  uint8_t bits[17], uint8_t val[],
-                                  int max_nval);
+void ff_mjpeg_encode_huffman_close(MJpegEncHuffmanContext *s,
+                                   uint8_t bits[17], uint8_t val[],
+                                   int max_nval);
 
 
 /**



More information about the ffmpeg-cvslog mailing list