[FFmpeg-cvslog] h264: do not reinitialize the global cabac tables at each slice header

Anton Khirnov git at videolan.org
Wed Sep 25 10:41:23 CEST 2013


ffmpeg | branch: master | Anton Khirnov <anton at khirnov.net> | Sun Aug 11 12:14:44 2013 +0200| [cab8c5f8e140c96ba3725ab709d823abfd1e31a5] | committer: Anton Khirnov

h264: do not reinitialize the global cabac tables at each slice header

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

 libavcodec/cabac.c |    6 ++++++
 libavcodec/h264.c  |    3 ++-
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/libavcodec/cabac.c b/libavcodec/cabac.c
index 50f086e..e1cd811 100644
--- a/libavcodec/cabac.c
+++ b/libavcodec/cabac.c
@@ -137,6 +137,10 @@ void ff_init_cabac_decoder(CABACContext *c, const uint8_t *buf, int buf_size){
 void ff_init_cabac_states(void)
 {
     int i, j;
+    static int initialized = 0;
+
+    if (initialized)
+        return;
 
     for(i=0; i<64; i++){
         for(j=0; j<4; j++){ //FIXME check if this is worth the 1 shift we save
@@ -158,4 +162,6 @@ void ff_init_cabac_states(void)
     for(i=0; i< 63; i++){
       ff_h264_last_coeff_flag_offset_8x8[i] = last_coeff_flag_offset_8x8[i];
     }
+
+    initialized = 1;
 }
diff --git a/libavcodec/h264.c b/libavcodec/h264.c
index 274c738..5ff55ce 100644
--- a/libavcodec/h264.c
+++ b/libavcodec/h264.c
@@ -1548,6 +1548,8 @@ av_cold int ff_h264_decode_init(AVCodecContext *avctx)
 
     ff_h264_decode_init_vlc();
 
+    ff_init_cabac_states();
+
     h->pixel_shift        = 0;
     h->sps.bit_depth_luma = avctx->bits_per_raw_sample = 8;
 
@@ -4244,7 +4246,6 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg)
         align_get_bits(&h->gb);
 
         /* init cabac */
-        ff_init_cabac_states();
         ff_init_cabac_decoder(&h->cabac,
                               h->gb.buffer + get_bits_count(&h->gb) / 8,
                               (get_bits_left(&h->gb) + 7) / 8);



More information about the ffmpeg-cvslog mailing list