comparison mpeg12.c @ 552:26971b5a271d libavcodec

rl vlc table optimization (not yet used)
author michaelni
date Sun, 14 Jul 2002 18:36:24 +0000
parents 6df843af36cb
children 762c67fd4078
comparison
equal deleted inserted replaced
551:b2e54bf843b8 552:26971b5a271d
31 #define SLICE_MIN_START_CODE 0x00000101 31 #define SLICE_MIN_START_CODE 0x00000101
32 #define SLICE_MAX_START_CODE 0x000001af 32 #define SLICE_MAX_START_CODE 0x000001af
33 #define EXT_START_CODE 0x000001b5 33 #define EXT_START_CODE 0x000001b5
34 #define USER_START_CODE 0x000001b2 34 #define USER_START_CODE 0x000001b2
35 35
36 #define DC_VLC_BITS 9
37 #define MV_VLC_BITS 9
38 #define MBINCR_VLC_BITS 9
39 #define MB_PAT_VLC_BITS 9
40 #define MB_PTYPE_VLC_BITS 6
41 #define MB_BTYPE_VLC_BITS 6
42 #define TEX_VLC_BITS 9
43
36 static void mpeg1_encode_block(MpegEncContext *s, 44 static void mpeg1_encode_block(MpegEncContext *s,
37 DCTELEM *block, 45 DCTELEM *block,
38 int component); 46 int component);
39 static void mpeg1_encode_motion(MpegEncContext *s, int val); 47 static void mpeg1_encode_motion(MpegEncContext *s, int val);
40 static void mpeg1_skip_picture(MpegEncContext *s, int pict_num); 48 static void mpeg1_skip_picture(MpegEncContext *s, int pict_num);
49 int n); 57 int n);
50 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred); 58 static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred);
51 59
52 static UINT16 mv_penalty[MAX_FCODE+1][MAX_MV*2+1]; 60 static UINT16 mv_penalty[MAX_FCODE+1][MAX_MV*2+1];
53 static UINT8 fcode_tab[MAX_MV*2+1]; 61 static UINT8 fcode_tab[MAX_MV*2+1];
62
63 static void init_2d_vlc_rl(RLTable *rl)
64 {
65 int i, q;
66
67 init_vlc(&rl->vlc, TEX_VLC_BITS, rl->n + 2,
68 &rl->table_vlc[0][1], 4, 2,
69 &rl->table_vlc[0][0], 4, 2);
70
71
72 rl->rl_vlc[0]= av_malloc(rl->vlc.table_size*sizeof(RL_VLC_ELEM));
73 for(i=0; i<rl->vlc.table_size; i++){
74 int code= rl->vlc.table[i][0];
75 int len = rl->vlc.table[i][1];
76 int level, run;
77
78 if(len==0){ // illegal code
79 run= 65;
80 level= MAX_LEVEL;
81 }else if(len<0){ //more bits needed
82 run= 0;
83 level= code;
84 }else{
85 if(code==rl->n){ //esc
86 run= 65;
87 level= 0;
88 }else if(code==rl->n+1){ //eob
89 run= 192;
90 level= 1;
91 }else{
92 run= rl->table_run [code] + 1;
93 level= rl->table_level[code];
94 }
95 }
96 rl->rl_vlc[0][i].len= len;
97 rl->rl_vlc[0][i].level= level;
98 rl->rl_vlc[0][i].run= run;
99 }
100 }
101
54 102
55 static void put_header(MpegEncContext *s, int header) 103 static void put_header(MpegEncContext *s, int header)
56 { 104 {
57 align_put_bits(&s->pb); 105 align_put_bits(&s->pb);
58 put_bits(&s->pb, 16, header>>16); 106 put_bits(&s->pb, 16, header>>16);
531 static VLC mbincr_vlc; 579 static VLC mbincr_vlc;
532 static VLC mb_ptype_vlc; 580 static VLC mb_ptype_vlc;
533 static VLC mb_btype_vlc; 581 static VLC mb_btype_vlc;
534 static VLC mb_pat_vlc; 582 static VLC mb_pat_vlc;
535 583
536 #define DC_VLC_BITS 9
537 #define MV_VLC_BITS 9
538 #define MBINCR_VLC_BITS 9
539 #define MB_PAT_VLC_BITS 9
540 #define MB_PTYPE_VLC_BITS 6
541 #define MB_BTYPE_VLC_BITS 6
542 #define TEX_VLC_BITS 9
543
544 void mpeg1_init_vlc(MpegEncContext *s) 584 void mpeg1_init_vlc(MpegEncContext *s)
545 { 585 {
546 static int done = 0; 586 static int done = 0;
547 587
548 if (!done) { 588 if (!done) {
570 init_vlc(&mb_btype_vlc, MB_BTYPE_VLC_BITS, 32, 610 init_vlc(&mb_btype_vlc, MB_BTYPE_VLC_BITS, 32,
571 &table_mb_btype[0][1], 2, 1, 611 &table_mb_btype[0][1], 2, 1,
572 &table_mb_btype[0][0], 2, 1); 612 &table_mb_btype[0][0], 2, 1);
573 init_rl(&rl_mpeg1); 613 init_rl(&rl_mpeg1);
574 init_rl(&rl_mpeg2); 614 init_rl(&rl_mpeg2);
575 /* cannot use generic init because we must add the EOB code */ 615
576 init_vlc(&rl_mpeg1.vlc, TEX_VLC_BITS, rl_mpeg1.n + 2, 616 init_2d_vlc_rl(&rl_mpeg1);
577 &rl_mpeg1.table_vlc[0][1], 4, 2, 617 init_2d_vlc_rl(&rl_mpeg2);
578 &rl_mpeg1.table_vlc[0][0], 4, 2);
579 init_vlc(&rl_mpeg2.vlc, TEX_VLC_BITS, rl_mpeg2.n + 2,
580 &rl_mpeg2.table_vlc[0][1], 4, 2,
581 &rl_mpeg2.table_vlc[0][0], 4, 2);
582 } 618 }
583 } 619 }
584 620
585 static inline int get_dmv(MpegEncContext *s) 621 static inline int get_dmv(MpegEncContext *s)
586 { 622 {
1414 s->mb_y = start_code; 1450 s->mb_y = start_code;
1415 s->mb_incr = 0; 1451 s->mb_incr = 0;
1416 /* start frame decoding */ 1452 /* start frame decoding */
1417 if (s->first_slice) { 1453 if (s->first_slice) {
1418 s->first_slice = 0; 1454 s->first_slice = 0;
1419 MPV_frame_start(s); 1455 MPV_frame_start(s, avctx);
1420 } 1456 }
1421 1457
1422 init_get_bits(&s->gb, buf, buf_size); 1458 init_get_bits(&s->gb, buf, buf_size);
1423 1459
1424 s->qscale = get_qscale(s); 1460 s->qscale = get_qscale(s);