[FFmpeg-cvslog] avcodec/hevcdec: remove duplicate extradata parsing function

James Almer git at videolan.org
Sun Apr 9 20:13:08 EEST 2017


ffmpeg | branch: master | James Almer <jamrial at gmail.com> | Sun Apr  2 15:41:10 2017 -0300| [4588063f3ecd9c97ebf61e7791be9978176cdb2b] | committer: James Almer

avcodec/hevcdec: remove duplicate extradata parsing function

Use ff_hevc_decode_extradata() instead, which correctly only tries
to decode parameter set NAL units and not any other NAL that may be
present in extradata.

Reviewed-by: nevcairiel
Signed-off-by: James Almer <jamrial at gmail.com>

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

 libavcodec/hevcdec.c | 61 ++++++----------------------------------------------
 libavcodec/hevcdec.h |  2 +-
 2 files changed, 7 insertions(+), 56 deletions(-)

diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c
index af55416ad3..7b935260d6 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -39,6 +39,7 @@
 #include "golomb.h"
 #include "hevc.h"
 #include "hevc_data.h"
+#include "hevc_parse.h"
 #include "hevcdec.h"
 #include "profiles.h"
 
@@ -2994,63 +2995,13 @@ static int verify_md5(HEVCContext *s, AVFrame *frame)
 
 static int hevc_decode_extradata(HEVCContext *s, uint8_t *buf, int length)
 {
-    AVCodecContext *avctx = s->avctx;
-    GetByteContext gb;
     int ret, i;
 
-    bytestream2_init(&gb, buf, length);
-
-    if (length > 3 && (buf[0] || buf[1] || buf[2] > 1)) {
-        /* It seems the extradata is encoded as hvcC format.
-         * Temporarily, we support configurationVersion==0 until 14496-15 3rd
-         * is finalized. When finalized, configurationVersion will be 1 and we
-         * can recognize hvcC by checking if avctx->extradata[0]==1 or not. */
-        int i, j, num_arrays, nal_len_size;
-
-        s->is_nalff = 1;
-
-        bytestream2_skip(&gb, 21);
-        nal_len_size = (bytestream2_get_byte(&gb) & 3) + 1;
-        num_arrays   = bytestream2_get_byte(&gb);
-
-        /* nal units in the hvcC always have length coded with 2 bytes,
-         * so put a fake nal_length_size = 2 while parsing them */
-        s->nal_length_size = 2;
-
-        /* Decode nal units from hvcC. */
-        for (i = 0; i < num_arrays; i++) {
-            int type = bytestream2_get_byte(&gb) & 0x3f;
-            int cnt  = bytestream2_get_be16(&gb);
-
-            for (j = 0; j < cnt; j++) {
-                // +2 for the nal size field
-                int nalsize = bytestream2_peek_be16(&gb) + 2;
-                if (bytestream2_get_bytes_left(&gb) < nalsize) {
-                    av_log(s->avctx, AV_LOG_ERROR,
-                           "Invalid NAL unit size in extradata.\n");
-                    return AVERROR_INVALIDDATA;
-                }
-
-                ret = decode_nal_units(s, gb.buffer, nalsize);
-                if (ret < 0) {
-                    av_log(avctx, AV_LOG_ERROR,
-                           "Decoding nal unit %d %d from hvcC failed\n",
-                           type, i);
-                    return ret;
-                }
-                bytestream2_skip(&gb, nalsize);
-            }
-        }
-
-        /* Now store right nal length size, that will be used to parse
-         * all other nals */
-        s->nal_length_size = nal_len_size;
-    } else {
-        s->is_nalff = 0;
-        ret = decode_nal_units(s, buf, length);
-        if (ret < 0)
-            return ret;
-    }
+    ret = ff_hevc_decode_extradata(buf, length, &s->ps, &s->is_nalff,
+                                   &s->nal_length_size, s->avctx->err_recognition,
+                                   s->apply_defdispwin, s->avctx);
+    if (ret < 0)
+        return ret;
 
     /* export stream parameters from the first SPS */
     for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) {
diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h
index e5879a5c2b..dfb12eff8b 100644
--- a/libavcodec/hevcdec.h
+++ b/libavcodec/hevcdec.h
@@ -564,7 +564,7 @@ typedef struct HEVCContext {
     uint8_t is_md5;
 
     uint8_t context_initialized;
-    uint8_t is_nalff;       ///< this flag is != 0 if bitstream is encapsulated
+    int is_nalff;           ///< this flag is != 0 if bitstream is encapsulated
                             ///< as a format defined in 14496-15
     int apply_defdispwin;
 



More information about the ffmpeg-cvslog mailing list