[FFmpeg-cvslog] avcodec/hevc: Move skipped_bytes_pos_nal to HEVCNAL, simplify code

Michael Niedermayer git at videolan.org
Mon Jul 13 01:16:54 CEST 2015


ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Mon Jul 13 00:43:25 2015 +0200| [ad92410d900b985cdabc499f0badaad72dd5ea2d] | committer: Michael Niedermayer

avcodec/hevc: Move skipped_bytes_pos_nal to HEVCNAL, simplify code

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

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

 libavcodec/hevc.c       |   11 ++++-------
 libavcodec/hevc.h       |    3 +--
 libavcodec/hevc_parse.c |   14 +++++---------
 3 files changed, 10 insertions(+), 18 deletions(-)

diff --git a/libavcodec/hevc.c b/libavcodec/hevc.c
index a77672c..63a2c2f 100644
--- a/libavcodec/hevc.c
+++ b/libavcodec/hevc.c
@@ -2781,7 +2781,7 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length)
 
     /* decode the NAL units */
     for (i = 0; i < s->pkt.nb_nals; i++) {
-        s->skipped_bytes_pos = s->skipped_bytes_pos_nal[i];
+        s->skipped_bytes_pos = s->pkt.nals[i].skipped_bytes_pos_nal;
 
         ret = decode_nal_unit(s, &s->pkt.nals[i]);
         if (ret < 0) {
@@ -2971,11 +2971,6 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx)
 
     av_freep(&s->md5_ctx);
 
-    for(i=0; i < s->pkt.nals_allocated; i++) {
-        av_freep(&s->skipped_bytes_pos_nal[i]);
-    }
-    av_freep(&s->skipped_bytes_pos_nal);
-
     av_freep(&s->cabac_state);
 
     for (i = 0; i < 3; i++) {
@@ -3014,8 +3009,10 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx)
         s->HEVClc = NULL;
     av_freep(&s->HEVClcList[0]);
 
-    for (i = 0; i < s->pkt.nals_allocated; i++)
+    for (i = 0; i < s->pkt.nals_allocated; i++) {
         av_freep(&s->pkt.nals[i].rbsp_buffer);
+        av_freep(&s->pkt.nals[i].skipped_bytes_pos_nal);
+    }
     av_freep(&s->pkt.nals);
     s->pkt.nals_allocated = 0;
 
diff --git a/libavcodec/hevc.h b/libavcodec/hevc.h
index 1699a24..8ae1ace 100644
--- a/libavcodec/hevc.h
+++ b/libavcodec/hevc.h
@@ -762,6 +762,7 @@ typedef struct HEVCNAL {
 
     int skipped_bytes;
     int skipped_bytes_pos_size_nal;
+    int *skipped_bytes_pos_nal;
 } HEVCNAL;
 
 /* an input packet split into unescaped NAL units */
@@ -903,8 +904,6 @@ typedef struct HEVCContext {
     int *skipped_bytes_pos;
     int skipped_bytes_pos_size;
 
-    int **skipped_bytes_pos_nal;
-
     const uint8_t *data;
 
     HEVCPacket pkt;
diff --git a/libavcodec/hevc_parse.c b/libavcodec/hevc_parse.c
index 01c28d8..453a656 100644
--- a/libavcodec/hevc_parse.c
+++ b/libavcodec/hevc_parse.c
@@ -218,29 +218,25 @@ int ff_hevc_split_packet(HEVCContext *s, HEVCPacket *pkt, const uint8_t *buf, in
             memset(pkt->nals + pkt->nals_allocated, 0,
                    (new_size - pkt->nals_allocated) * sizeof(*pkt->nals));
 
-            tmp = av_realloc_array(s->skipped_bytes_pos_nal, new_size, sizeof(*s->skipped_bytes_pos_nal));
-            if (!tmp)
-                return AVERROR(ENOMEM);
-            s->skipped_bytes_pos_nal = tmp;
-
             nal = &pkt->nals[pkt->nb_nals];
             nal->skipped_bytes_pos_size_nal = 1024; // initial buffer size
-            s->skipped_bytes_pos_nal[pkt->nals_allocated] = av_malloc_array(nal->skipped_bytes_pos_size_nal, sizeof(*s->skipped_bytes_pos));
-            if (!s->skipped_bytes_pos_nal[pkt->nals_allocated])
+            nal->skipped_bytes_pos_nal = av_malloc_array(nal->skipped_bytes_pos_size_nal, sizeof(*s->skipped_bytes_pos));
+            if (!nal->skipped_bytes_pos_nal)
                 return AVERROR(ENOMEM);
 
             pkt->nals_allocated = new_size;
         }
         nal = &pkt->nals[pkt->nb_nals];
         s->skipped_bytes_pos_size = nal->skipped_bytes_pos_size_nal;
-        s->skipped_bytes_pos = s->skipped_bytes_pos_nal[pkt->nb_nals];
+        s->skipped_bytes_pos = nal->skipped_bytes_pos_nal;
 
         consumed = ff_hevc_extract_rbsp(s, buf, extract_length, nal);
         if (consumed < 0)
             return consumed;
 
         nal->skipped_bytes_pos_size_nal = s->skipped_bytes_pos_size;
-        s->skipped_bytes_pos_nal[pkt->nb_nals++] = s->skipped_bytes_pos;
+        nal->skipped_bytes_pos_nal      = s->skipped_bytes_pos;
+        pkt->nb_nals++;
 
         ret = init_get_bits8(&nal->gb, nal->data, nal->size);
         if (ret < 0)



More information about the ffmpeg-cvslog mailing list