mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-08 13:22:53 +02:00
optimize mpeg1_encode_block()
(makeing some constant arrays global, merging put_bits(), ...) Originally committed as revision 297 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
4f0f8bfce3
commit
80feb2a23e
@ -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) {
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user