[FFmpeg-devel] [PATCH 1/9] hevc: reduce allocation for split_cu_flag

Christophe Gisquet christophe.gisquet at gmail.com
Thu Jul 10 08:47:48 CEST 2014


Allocate this flag with a CU granularity. Furthermore, its prediction only
requires one line of flags to be stored, so for simplicity's sake, store
only current and previous CTB lines.

Reduces allocation by around 2MB for a 1080p stream.
---
 libavcodec/hevc.c | 5 +++--
 libavcodec/hevc.h | 2 +-
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/libavcodec/hevc.c b/libavcodec/hevc.c
index 99298a8..f8a495f 100644
--- a/libavcodec/hevc.c
+++ b/libavcodec/hevc.c
@@ -85,7 +85,6 @@ static int pic_arrays_init(HEVCContext *s, const HEVCSPS *sps)
     int log2_min_cb_size = sps->log2_min_cb_size;
     int width            = sps->width;
     int height           = sps->height;
-    int pic_size         = width * height;
     int pic_size_in_ctb  = ((width  >> log2_min_cb_size) + 1) *
                            ((height >> log2_min_cb_size) + 1);
     int ctb_count        = sps->ctb_width * sps->ctb_height;
@@ -96,7 +95,7 @@ static int pic_arrays_init(HEVCContext *s, const HEVCSPS *sps)
 
     s->sao           = av_mallocz_array(ctb_count, sizeof(*s->sao));
     s->deblock       = av_mallocz_array(ctb_count, sizeof(*s->deblock));
-    s->split_cu_flag = av_malloc(pic_size);
+    s->split_cu_flag = av_malloc(16*sps->min_cb_width);
     if (!s->sao || !s->deblock || !s->split_cu_flag)
         goto fail;
 
@@ -1909,6 +1908,8 @@ static int hls_coding_quadtree(HEVCContext *s, int x0, int y0,
     HEVCLocalContext *lc = s->HEVClc;
     const int cb_size    = 1 << log2_cb_size;
     int ret;
+    int log2_min_cb_size = s->sps->log2_min_cb_size;
+    int min_cb_width     = s->sps->min_cb_width;
     int qp_block_mask = (1<<(s->sps->log2_ctb_size - s->pps->diff_cu_qp_delta_depth)) - 1;
 
     lc->ct.depth = cb_depth;
diff --git a/libavcodec/hevc.h b/libavcodec/hevc.h
index 5f964c3..44d6a6c 100644
--- a/libavcodec/hevc.h
+++ b/libavcodec/hevc.h
@@ -80,7 +80,7 @@
 /**
  * Value of the luma sample at position (x, y) in the 2D array tab.
  */
-#define SAMPLE(tab, x, y) ((tab)[(y) * s->sps->width + (x)])
+#define SAMPLE(tab, x, y) ((tab)[(((y)>>log2_min_cb_size)&15) * min_cb_width + ((x)>>log2_min_cb_size)])
 #define SAMPLE_CTB(tab, x, y) ((tab)[(y) * min_cb_width + (x)])
 #define SAMPLE_CBF(tab, x, y) ((tab)[((y) & ((1<<log2_trafo_size)-1)) * MAX_CU_SIZE + ((x) & ((1<<log2_trafo_size)-1))])
 
-- 
1.9.2.msysgit.0



More information about the ffmpeg-devel mailing list