Commit c71fbec1 authored by michaelni's avatar michaelni

optimize mpeg1_encode_block()

(makeing some constant arrays global, merging put_bits(), ...)


git-svn-id: file:///var/local/repositories/ffmpeg/trunk@297 9553f0bf-9b14-0410-a0b8-cfaf0461ba5b
parent 268d0972
...@@ -52,7 +52,8 @@ static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred); ...@@ -52,7 +52,8 @@ static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred);
static void put_header(MpegEncContext *s, int header) static void put_header(MpegEncContext *s, int header)
{ {
align_put_bits(&s->pb); 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 */ /* put sequence header if needed */
...@@ -183,11 +184,18 @@ static void mpeg1_skip_picture(MpegEncContext *s, int pict_num) ...@@ -183,11 +184,18 @@ static void mpeg1_skip_picture(MpegEncContext *s, int pict_num)
void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number) void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number)
{ {
static int done; static int done=0;
if (!done) { if (!done) {
int i;
done = 1; done = 1;
init_rl(&rl_mpeg1); 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); mpeg1_encode_sequence_header(s);
...@@ -347,7 +355,7 @@ static void mpeg1_encode_block(MpegEncContext *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 alevel, level, last_non_zero, dc, diff, i, j, run, last_index, sign;
int code, component; int code, component;
RLTable *rl = &rl_mpeg1; // RLTable *rl = &rl_mpeg1;
last_index = s->block_last_index[n]; last_index = s->block_last_index[n];
...@@ -376,6 +384,7 @@ static void mpeg1_encode_block(MpegEncContext *s, ...@@ -376,6 +384,7 @@ static void mpeg1_encode_block(MpegEncContext *s,
/* now quantify & encode AC coefs */ /* now quantify & encode AC coefs */
last_non_zero = i - 1; last_non_zero = i - 1;
for(;i<=last_index;i++) { for(;i<=last_index;i++) {
j = zigzag_direct[i]; j = zigzag_direct[i];
level = block[j]; level = block[j];
...@@ -387,17 +396,38 @@ static void mpeg1_encode_block(MpegEncContext *s, ...@@ -387,17 +396,38 @@ static void mpeg1_encode_block(MpegEncContext *s,
/* encode using VLC */ /* encode using VLC */
if (level != 0) { if (level != 0) {
run = i - last_non_zero - 1; 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; sign = 0;
alevel = level; alevel = level;
if (alevel < 0) { if (alevel < 0) {
sign = 1; sign = 1;
alevel = -alevel; alevel = -alevel;
} }
code = get_rl_index(rl, 0, run, alevel); #endif
put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); // code = get_rl_index(rl, 0, run, alevel);
if (code != rl->n) { if (alevel > mpeg1_max_level[0][run])
put_bits(&s->pb, 1, sign); 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 { } 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 */ /* escape: only clip in this case */
put_bits(&s->pb, 6, run); put_bits(&s->pb, 6, run);
if (alevel < 128) { if (alevel < 128) {
......
...@@ -161,6 +161,9 @@ static const INT8 mpeg1_run[111] = { ...@@ -161,6 +161,9 @@ static const INT8 mpeg1_run[111] = {
25, 26, 27, 28, 29, 30, 31, 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 = { static RLTable rl_mpeg1 = {
111, 111,
111, 111,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment