comparison vp56.c @ 5711:dae0f80edbb3 libavcodec

move all model related tables into their own struct
author aurel
date Mon, 24 Sep 2007 22:29:11 +0000
parents 9792a3aa9215
children 314be1cfdcb0
comparison
equal deleted inserted replaced
5710:74e4be2d2f22 5711:dae0f80edbb3
73 } 73 }
74 74
75 static void vp56_parse_mb_type_models(vp56_context_t *s) 75 static void vp56_parse_mb_type_models(vp56_context_t *s)
76 { 76 {
77 vp56_range_coder_t *c = &s->c; 77 vp56_range_coder_t *c = &s->c;
78 vp56_model_t *model = s->modelp;
78 int i, ctx, type; 79 int i, ctx, type;
79 80
80 for (ctx=0; ctx<3; ctx++) { 81 for (ctx=0; ctx<3; ctx++) {
81 if (vp56_rac_get_prob(c, 174)) { 82 if (vp56_rac_get_prob(c, 174)) {
82 int idx = vp56_rac_gets(c, 4); 83 int idx = vp56_rac_gets(c, 4);
83 memcpy(s->mb_types_stats[ctx],vp56_pre_def_mb_type_stats[idx][ctx], 84 memcpy(model->mb_types_stats[ctx],
84 sizeof(s->mb_types_stats[ctx])); 85 vp56_pre_def_mb_type_stats[idx][ctx],
86 sizeof(model->mb_types_stats[ctx]));
85 } 87 }
86 if (vp56_rac_get_prob(c, 254)) { 88 if (vp56_rac_get_prob(c, 254)) {
87 for (type=0; type<10; type++) { 89 for (type=0; type<10; type++) {
88 for(i=0; i<2; i++) { 90 for(i=0; i<2; i++) {
89 if (vp56_rac_get_prob(c, 205)) { 91 if (vp56_rac_get_prob(c, 205)) {
91 93
92 delta = vp56_rac_get_tree(c, vp56_pmbtm_tree, 94 delta = vp56_rac_get_tree(c, vp56_pmbtm_tree,
93 vp56_mb_type_model_model); 95 vp56_mb_type_model_model);
94 if (!delta) 96 if (!delta)
95 delta = 4 * vp56_rac_gets(c, 7); 97 delta = 4 * vp56_rac_gets(c, 7);
96 s->mb_types_stats[ctx][type][i] += (delta ^ -sign) + sign; 98 model->mb_types_stats[ctx][type][i] += (delta ^ -sign) + sign;
97 } 99 }
98 } 100 }
99 } 101 }
100 } 102 }
101 } 103 }
103 /* compute MB type probability tables based on previous MB type */ 105 /* compute MB type probability tables based on previous MB type */
104 for (ctx=0; ctx<3; ctx++) { 106 for (ctx=0; ctx<3; ctx++) {
105 int p[10]; 107 int p[10];
106 108
107 for (type=0; type<10; type++) 109 for (type=0; type<10; type++)
108 p[type] = 100 * s->mb_types_stats[ctx][type][1]; 110 p[type] = 100 * model->mb_types_stats[ctx][type][1];
109 111
110 for (type=0; type<10; type++) { 112 for (type=0; type<10; type++) {
111 int p02, p34, p0234, p17, p56, p89, p5689, p156789; 113 int p02, p34, p0234, p17, p56, p89, p5689, p156789;
112 114
113 /* conservative MB type probability */ 115 /* conservative MB type probability */
114 s->mb_type_model[ctx][type][0] = 255 - (255 * s->mb_types_stats[ctx][type][0]) / (1 + s->mb_types_stats[ctx][type][0] + s->mb_types_stats[ctx][type][1]); 116 model->mb_type[ctx][type][0] = 255 - (255 * model->mb_types_stats[ctx][type][0]) / (1 + model->mb_types_stats[ctx][type][0] + model->mb_types_stats[ctx][type][1]);
115 117
116 p[type] = 0; /* same MB type => weight is null */ 118 p[type] = 0; /* same MB type => weight is null */
117 119
118 /* binary tree parsing probabilities */ 120 /* binary tree parsing probabilities */
119 p02 = p[0] + p[2]; 121 p02 = p[0] + p[2];
123 p56 = p[5] + p[6]; 125 p56 = p[5] + p[6];
124 p89 = p[8] + p[9]; 126 p89 = p[8] + p[9];
125 p5689 = p56 + p89; 127 p5689 = p56 + p89;
126 p156789 = p17 + p5689; 128 p156789 = p17 + p5689;
127 129
128 s->mb_type_model[ctx][type][1] = 1 + 255 * p0234/(1+p0234+p156789); 130 model->mb_type[ctx][type][1] = 1 + 255 * p0234/(1+p0234+p156789);
129 s->mb_type_model[ctx][type][2] = 1 + 255 * p02 / (1+p0234); 131 model->mb_type[ctx][type][2] = 1 + 255 * p02 / (1+p0234);
130 s->mb_type_model[ctx][type][3] = 1 + 255 * p17 / (1+p156789); 132 model->mb_type[ctx][type][3] = 1 + 255 * p17 / (1+p156789);
131 s->mb_type_model[ctx][type][4] = 1 + 255 * p[0] / (1+p02); 133 model->mb_type[ctx][type][4] = 1 + 255 * p[0] / (1+p02);
132 s->mb_type_model[ctx][type][5] = 1 + 255 * p[3] / (1+p34); 134 model->mb_type[ctx][type][5] = 1 + 255 * p[3] / (1+p34);
133 s->mb_type_model[ctx][type][6] = 1 + 255 * p[1] / (1+p17); 135 model->mb_type[ctx][type][6] = 1 + 255 * p[1] / (1+p17);
134 s->mb_type_model[ctx][type][7] = 1 + 255 * p56 / (1+p5689); 136 model->mb_type[ctx][type][7] = 1 + 255 * p56 / (1+p5689);
135 s->mb_type_model[ctx][type][8] = 1 + 255 * p[5] / (1+p56); 137 model->mb_type[ctx][type][8] = 1 + 255 * p[5] / (1+p56);
136 s->mb_type_model[ctx][type][9] = 1 + 255 * p[8] / (1+p89); 138 model->mb_type[ctx][type][9] = 1 + 255 * p[8] / (1+p89);
137 139
138 /* restore initial value */ 140 /* restore initial value */
139 p[type] = 100 * s->mb_types_stats[ctx][type][1]; 141 p[type] = 100 * model->mb_types_stats[ctx][type][1];
140 } 142 }
141 } 143 }
142 } 144 }
143 145
144 static vp56_mb_t vp56_parse_mb_type(vp56_context_t *s, 146 static vp56_mb_t vp56_parse_mb_type(vp56_context_t *s,
145 vp56_mb_t prev_type, int ctx) 147 vp56_mb_t prev_type, int ctx)
146 { 148 {
147 uint8_t *mb_type_model = s->mb_type_model[ctx][prev_type]; 149 uint8_t *mb_type_model = s->modelp->mb_type[ctx][prev_type];
148 vp56_range_coder_t *c = &s->c; 150 vp56_range_coder_t *c = &s->c;
149 151
150 if (vp56_rac_get_prob(c, mb_type_model[0])) 152 if (vp56_rac_get_prob(c, mb_type_model[0]))
151 return prev_type; 153 return prev_type;
152 else 154 else
499 int mb_row, mb_col, mb_row_flip, mb_offset = 0; 501 int mb_row, mb_col, mb_row_flip, mb_offset = 0;
500 int block, y, uv, stride_y, stride_uv; 502 int block, y, uv, stride_y, stride_uv;
501 int golden_frame = 0; 503 int golden_frame = 0;
502 int res; 504 int res;
503 505
506 s->modelp = &s->models;
507
504 res = s->parse_header(s, buf, buf_size, &golden_frame); 508 res = s->parse_header(s, buf, buf_size, &golden_frame);
505 if (!res) 509 if (!res)
506 return -1; 510 return -1;
507 511
508 p->reference = 1; 512 p->reference = 1;