diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2002-02-13 04:19:10 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2002-02-13 04:19:10 +0000 |
commit | 80feb2a23ec6cc2ce459404041485a6dfaaffbe6 (patch) | |
tree | 70878efeb5d0e6e017be6bff95d83584139fbc98 /libavcodec | |
parent | 4f0f8bfce3012005422b6e7b09dfa57c07f783eb (diff) | |
download | ffmpeg-80feb2a23ec6cc2ce459404041485a6dfaaffbe6.tar.gz |
optimize mpeg1_encode_block()
(makeing some constant arrays global, merging put_bits(), ...)
Originally committed as revision 297 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec')
-rw-r--r-- | libavcodec/mpeg12.c | 44 | ||||
-rw-r--r-- | libavcodec/mpeg12data.h | 3 |
2 files changed, 40 insertions, 7 deletions
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c index 758124eea6..76c1b61343 100644 --- a/libavcodec/mpeg12.c +++ b/libavcodec/mpeg12.c @@ -52,7 +52,8 @@ static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred); static void put_header(MpegEncContext *s, int header) { align_put_bits(&s->pb); - put_bits(&s->pb, 32, header); + put_bits(&s->pb, 16, header>>16); + put_bits(&s->pb, 16, header&0xFFFF); } /* put sequence header if needed */ @@ -183,11 +184,18 @@ static void mpeg1_skip_picture(MpegEncContext *s, int pict_num) void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number) { - static int done; + static int done=0; if (!done) { + int i; done = 1; init_rl(&rl_mpeg1); + + for(i=0; i<64; i++) + { + mpeg1_max_level[0][i]= rl_mpeg1.max_level[0][i]; + mpeg1_index_run[0][i]= rl_mpeg1.index_run[0][i]; + } } mpeg1_encode_sequence_header(s); @@ -347,7 +355,7 @@ static void mpeg1_encode_block(MpegEncContext *s, { int alevel, level, last_non_zero, dc, diff, i, j, run, last_index, sign; int code, component; - RLTable *rl = &rl_mpeg1; +// RLTable *rl = &rl_mpeg1; last_index = s->block_last_index[n]; @@ -376,6 +384,7 @@ static void mpeg1_encode_block(MpegEncContext *s, /* now quantify & encode AC coefs */ last_non_zero = i - 1; + for(;i<=last_index;i++) { j = zigzag_direct[i]; level = block[j]; @@ -387,17 +396,38 @@ static void mpeg1_encode_block(MpegEncContext *s, /* encode using VLC */ if (level != 0) { run = i - last_non_zero - 1; +#ifdef ARCH_X86 + asm volatile( + "movl %2, %1 \n\t" + "movl %1, %0 \n\t" + "addl %1, %1 \n\t" + "sbbl %1, %1 \n\t" + "xorl %1, %0 \n\t" + "subl %1, %0 \n\t" + "andl $1, %1 \n\t" + : "=&r" (alevel), "=&r" (sign) + : "g" (level) + ); +#else sign = 0; alevel = level; if (alevel < 0) { sign = 1; alevel = -alevel; } - code = get_rl_index(rl, 0, run, alevel); - put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); - if (code != rl->n) { - put_bits(&s->pb, 1, sign); +#endif +// code = get_rl_index(rl, 0, run, alevel); + if (alevel > mpeg1_max_level[0][run]) + code= 111; /*rl->n*/ + else + code= mpeg1_index_run[0][run] + alevel - 1; + + if (code < 111 /* rl->n */) { + /* store the vlc & sign at once */ + put_bits(&s->pb, mpeg1_vlc[code][1]+1, (mpeg1_vlc[code][0]<<1) + sign); } else { + /* escape seems to be pretty rare <5% so i dont optimize it */ + put_bits(&s->pb, mpeg1_vlc[111/*rl->n*/][1], mpeg1_vlc[111/*rl->n*/][0]); /* escape: only clip in this case */ put_bits(&s->pb, 6, run); if (alevel < 128) { diff --git a/libavcodec/mpeg12data.h b/libavcodec/mpeg12data.h index f7d29a5cbb..4261986d24 100644 --- a/libavcodec/mpeg12data.h +++ b/libavcodec/mpeg12data.h @@ -161,6 +161,9 @@ static const INT8 mpeg1_run[111] = { 25, 26, 27, 28, 29, 30, 31, }; +static UINT8 mpeg1_index_run[2][64]; +static INT8 mpeg1_max_level[2][64]; + static RLTable rl_mpeg1 = { 111, 111, |