annotate error_resilience.c @ 1220:78a51075aacb libavcodec

10l
author michaelni
date Sun, 27 Apr 2003 13:44:01 +0000
parents fea03d2c4946
children 6e039762d5cb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
1 /*
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
2 * Error resilience / concealment
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
3 *
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
4 * Copyright (c) 2002 Michael Niedermayer <michaelni@gmx.at>
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
5 *
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
6 * This library is free software; you can redistribute it and/or
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
8 * License as published by the Free Software Foundation; either
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
9 * version 2 of the License, or (at your option) any later version.
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
10 *
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
11 * This library is distributed in the hope that it will be useful,
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
14 * Lesser General Public License for more details.
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
15 *
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
17 * License along with this library; if not, write to the Free Software
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
19 */
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
20
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
21 /**
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
22 * @file error_resilience.c
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
23 * Error resilience / concealment.
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
24 */
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
25
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
26 #include <limits.h>
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
27
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
28 #include "avcodec.h"
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
29 #include "dsputil.h"
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
30 #include "mpegvideo.h"
1144
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
31 #include "common.h"
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
32
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
33 /**
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
34 * replaces the current MB with a flat dc only version.
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
35 */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
36 static void put_dc(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int mb_x, int mb_y)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
37 {
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
38 int dc, dcu, dcv, y, i;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
39 for(i=0; i<4; i++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
40 dc= s->dc_val[0][mb_x*2+1 + (i&1) + (mb_y*2+1 + (i>>1))*(s->mb_width*2+2)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
41 if(dc<0) dc=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
42 else if(dc>2040) dc=2040;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
43 for(y=0; y<8; y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
44 int x;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
45 for(x=0; x<8; x++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
46 dest_y[x + (i&1)*8 + (y + (i>>1)*8)*s->linesize]= dc/8;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
47 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
48 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
49 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
50 dcu = s->dc_val[1][mb_x+1 + (mb_y+1)*(s->mb_width+2)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
51 dcv = s->dc_val[2][mb_x+1 + (mb_y+1)*(s->mb_width+2)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
52 if (dcu<0 ) dcu=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
53 else if(dcu>2040) dcu=2040;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
54 if (dcv<0 ) dcv=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
55 else if(dcv>2040) dcv=2040;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
56 for(y=0; y<8; y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
57 int x;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
58 for(x=0; x<8; x++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
59 dest_cb[x + y*(s->uvlinesize)]= dcu/8;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
60 dest_cr[x + y*(s->uvlinesize)]= dcv/8;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
61 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
62 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
63 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
64
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
65 static void filter181(int16_t *data, int width, int height, int stride){
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
66 int x,y;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
67
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
68 /* horizontal filter */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
69 for(y=1; y<height-1; y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
70 int prev_dc= data[0 + y*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
71
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
72 for(x=1; x<width-1; x++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
73 int dc;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
74
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
75 dc= - prev_dc
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
76 + data[x + y*stride]*8
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
77 - data[x + 1 + y*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
78 dc= (dc*10923 + 32768)>>16;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
79 prev_dc= data[x + y*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
80 data[x + y*stride]= dc;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
81 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
82 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
83
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
84 /* vertical filter */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
85 for(x=1; x<width-1; x++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
86 int prev_dc= data[x];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
87
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
88 for(y=1; y<height-1; y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
89 int dc;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
90
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
91 dc= - prev_dc
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
92 + data[x + y *stride]*8
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
93 - data[x + (y+1)*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
94 dc= (dc*10923 + 32768)>>16;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
95 prev_dc= data[x + y*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
96 data[x + y*stride]= dc;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
97 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
98 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
99 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
100
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
101 /**
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
102 * guess the dc of blocks which dont have a undamaged dc
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
103 * @param w width in 8 pixel blocks
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
104 * @param h height in 8 pixel blocks
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
105 */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
106 static void guess_dc(MpegEncContext *s, int16_t *dc, int w, int h, int stride, int is_luma){
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
107 int b_x, b_y;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
108
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
109 for(b_y=0; b_y<h; b_y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
110 for(b_x=0; b_x<w; b_x++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
111 int color[4]={1024,1024,1024,1024};
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
112 int distance[4]={9999,9999,9999,9999};
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
113 int mb_index, error, j;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
114 int64_t guess, weight_sum;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
115
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
116 mb_index= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
117
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
118 error= s->error_status_table[mb_index];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
119
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
120 if(IS_INTER(s->current_picture.mb_type[mb_index])) continue; //inter
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
121 if(!(error&DC_ERROR)) continue; //dc-ok
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
122
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
123 /* right block */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
124 for(j=b_x+1; j<w; j++){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
125 int mb_index_j= (j>>is_luma) + (b_y>>is_luma)*s->mb_stride;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
126 int error_j= s->error_status_table[mb_index_j];
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
127 int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
128 if(intra_j==0 || !(error_j&DC_ERROR)){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
129 color[0]= dc[j + b_y*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
130 distance[0]= j-b_x;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
131 break;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
132 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
133 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
134
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
135 /* left block */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
136 for(j=b_x-1; j>=0; j--){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
137 int mb_index_j= (j>>is_luma) + (b_y>>is_luma)*s->mb_stride;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
138 int error_j= s->error_status_table[mb_index_j];
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
139 int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
140 if(intra_j==0 || !(error_j&DC_ERROR)){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
141 color[1]= dc[j + b_y*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
142 distance[1]= b_x-j;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
143 break;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
144 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
145 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
146
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
147 /* bottom block */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
148 for(j=b_y+1; j<h; j++){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
149 int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_stride;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
150 int error_j= s->error_status_table[mb_index_j];
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
151 int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
152 if(intra_j==0 || !(error_j&DC_ERROR)){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
153 color[2]= dc[b_x + j*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
154 distance[2]= j-b_y;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
155 break;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
156 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
157 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
158
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
159 /* top block */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
160 for(j=b_y-1; j>=0; j--){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
161 int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_stride;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
162 int error_j= s->error_status_table[mb_index_j];
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
163 int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
164 if(intra_j==0 || !(error_j&DC_ERROR)){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
165 color[3]= dc[b_x + j*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
166 distance[3]= b_y-j;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
167 break;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
168 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
169 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
170
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
171 weight_sum=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
172 guess=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
173 for(j=0; j<4; j++){
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
174 int64_t weight= 256*256*256*16/distance[j];
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
175 guess+= weight*(int64_t)color[j];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
176 weight_sum+= weight;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
177 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
178 guess= (guess + weight_sum/2) / weight_sum;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
179
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
180 dc[b_x + b_y*stride]= guess;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
181 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
182 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
183 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
184
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
185 /**
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
186 * simple horizontal deblocking filter used for error resilience
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
187 * @param w width in 8 pixel blocks
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
188 * @param h height in 8 pixel blocks
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
189 */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
190 static void h_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int stride, int is_luma){
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
191 int b_x, b_y;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
192 uint8_t *cm = cropTbl + MAX_NEG_CROP;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
193
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
194 for(b_y=0; b_y<h; b_y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
195 for(b_x=0; b_x<w-1; b_x++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
196 int y;
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
197 int left_status = s->error_status_table[( b_x >>is_luma) + (b_y>>is_luma)*s->mb_stride];
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
198 int right_status= s->error_status_table[((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride];
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
199 int left_intra= IS_INTRA(s->current_picture.mb_type [( b_x >>is_luma) + (b_y>>is_luma)*s->mb_stride]);
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
200 int right_intra= IS_INTRA(s->current_picture.mb_type [((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride]);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
201 int left_damage = left_status&(DC_ERROR|AC_ERROR|MV_ERROR);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
202 int right_damage= right_status&(DC_ERROR|AC_ERROR|MV_ERROR);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
203 int offset= b_x*8 + b_y*stride*8;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
204 int16_t *left_mv= s->motion_val[s->block_wrap[0]*((b_y<<(1-is_luma)) + 1) + ( b_x <<(1-is_luma))];
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
205 int16_t *right_mv= s->motion_val[s->block_wrap[0]*((b_y<<(1-is_luma)) + 1) + ((b_x+1)<<(1-is_luma))];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
206
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
207 if(!(left_damage||right_damage)) continue; // both undamaged
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
208
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
209 if( (!left_intra) && (!right_intra)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
210 && ABS(left_mv[0]-right_mv[0]) + ABS(left_mv[1]+right_mv[1]) < 2) continue;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
211
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
212 for(y=0; y<8; y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
213 int a,b,c,d;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
214
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
215 a= dst[offset + 7 + y*stride] - dst[offset + 6 + y*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
216 b= dst[offset + 8 + y*stride] - dst[offset + 7 + y*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
217 c= dst[offset + 9 + y*stride] - dst[offset + 8 + y*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
218
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
219 d= ABS(b) - ((ABS(a) + ABS(c) + 1)>>1);
847
f3c369b8ddca reversing header game
michaelni
parents: 745
diff changeset
220 d= FFMAX(d, 0);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
221 if(b<0) d= -d;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
222
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
223 if(d==0) continue;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
224
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
225 if(!(left_damage && right_damage))
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
226 d= d*16/9;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
227
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
228 if(left_damage){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
229 dst[offset + 7 + y*stride] = cm[dst[offset + 7 + y*stride] + ((d*7)>>4)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
230 dst[offset + 6 + y*stride] = cm[dst[offset + 6 + y*stride] + ((d*5)>>4)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
231 dst[offset + 5 + y*stride] = cm[dst[offset + 5 + y*stride] + ((d*3)>>4)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
232 dst[offset + 4 + y*stride] = cm[dst[offset + 4 + y*stride] + ((d*1)>>4)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
233 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
234 if(right_damage){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
235 dst[offset + 8 + y*stride] = cm[dst[offset + 8 + y*stride] - ((d*7)>>4)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
236 dst[offset + 9 + y*stride] = cm[dst[offset + 9 + y*stride] - ((d*5)>>4)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
237 dst[offset + 10+ y*stride] = cm[dst[offset +10 + y*stride] - ((d*3)>>4)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
238 dst[offset + 11+ y*stride] = cm[dst[offset +11 + y*stride] - ((d*1)>>4)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
239 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
240 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
241 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
242 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
243 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
244
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
245 /**
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
246 * simple vertical deblocking filter used for error resilience
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
247 * @param w width in 8 pixel blocks
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
248 * @param h height in 8 pixel blocks
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
249 */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
250 static void v_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int stride, int is_luma){
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
251 int b_x, b_y;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
252 uint8_t *cm = cropTbl + MAX_NEG_CROP;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
253
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
254 for(b_y=0; b_y<h-1; b_y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
255 for(b_x=0; b_x<w; b_x++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
256 int x;
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
257 int top_status = s->error_status_table[(b_x>>is_luma) + ( b_y >>is_luma)*s->mb_stride];
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
258 int bottom_status= s->error_status_table[(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride];
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
259 int top_intra= IS_INTRA(s->current_picture.mb_type [(b_x>>is_luma) + ( b_y >>is_luma)*s->mb_stride]);
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
260 int bottom_intra= IS_INTRA(s->current_picture.mb_type [(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride]);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
261 int top_damage = top_status&(DC_ERROR|AC_ERROR|MV_ERROR);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
262 int bottom_damage= bottom_status&(DC_ERROR|AC_ERROR|MV_ERROR);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
263 int offset= b_x*8 + b_y*stride*8;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
264 int16_t *top_mv= s->motion_val[s->block_wrap[0]*(( b_y <<(1-is_luma)) + 1) + (b_x<<(1-is_luma))];
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
265 int16_t *bottom_mv= s->motion_val[s->block_wrap[0]*(((b_y+1)<<(1-is_luma)) + 1) + (b_x<<(1-is_luma))];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
266
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
267 if(!(top_damage||bottom_damage)) continue; // both undamaged
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
268
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
269 if( (!top_intra) && (!bottom_intra)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
270 && ABS(top_mv[0]-bottom_mv[0]) + ABS(top_mv[1]+bottom_mv[1]) < 2) continue;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
271
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
272 for(x=0; x<8; x++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
273 int a,b,c,d;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
274
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
275 a= dst[offset + x + 7*stride] - dst[offset + x + 6*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
276 b= dst[offset + x + 8*stride] - dst[offset + x + 7*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
277 c= dst[offset + x + 9*stride] - dst[offset + x + 8*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
278
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
279 d= ABS(b) - ((ABS(a) + ABS(c)+1)>>1);
847
f3c369b8ddca reversing header game
michaelni
parents: 745
diff changeset
280 d= FFMAX(d, 0);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
281 if(b<0) d= -d;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
282
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
283 if(d==0) continue;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
284
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
285 if(!(top_damage && bottom_damage))
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
286 d= d*16/9;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
287
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
288 if(top_damage){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
289 dst[offset + x + 7*stride] = cm[dst[offset + x + 7*stride] + ((d*7)>>4)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
290 dst[offset + x + 6*stride] = cm[dst[offset + x + 6*stride] + ((d*5)>>4)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
291 dst[offset + x + 5*stride] = cm[dst[offset + x + 5*stride] + ((d*3)>>4)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
292 dst[offset + x + 4*stride] = cm[dst[offset + x + 4*stride] + ((d*1)>>4)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
293 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
294 if(bottom_damage){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
295 dst[offset + x + 8*stride] = cm[dst[offset + x + 8*stride] - ((d*7)>>4)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
296 dst[offset + x + 9*stride] = cm[dst[offset + x + 9*stride] - ((d*5)>>4)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
297 dst[offset + x + 10*stride] = cm[dst[offset + x + 10*stride] - ((d*3)>>4)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
298 dst[offset + x + 11*stride] = cm[dst[offset + x + 11*stride] - ((d*1)>>4)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
299 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
300 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
301 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
302 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
303 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
304
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
305 static void guess_mv(MpegEncContext *s){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
306 uint8_t fixed[s->mb_stride * s->mb_height];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
307 #define MV_FROZEN 3
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
308 #define MV_CHANGED 2
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
309 #define MV_UNCHANGED 1
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
310 const int mb_stride = s->mb_stride;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
311 const int mb_width = s->mb_width;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
312 const int mb_height= s->mb_height;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
313 int i, depth, num_avail;
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
314 int mb_x, mb_y;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
315
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
316 num_avail=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
317 for(i=0; i<s->mb_num; i++){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
318 const int mb_xy= s->mb_index2xy[ i ];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
319 int f=0;
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
320 int error= s->error_status_table[mb_xy];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
321
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
322 if(IS_INTRA(s->current_picture.mb_type[mb_xy])) f=MV_FROZEN; //intra //FIXME check
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
323 if(!(error&MV_ERROR)) f=MV_FROZEN; //inter with undamaged MV
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
324
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
325 fixed[mb_xy]= f;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
326 if(f==MV_FROZEN)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
327 num_avail++;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
328 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
329
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
330 if((!(s->avctx->error_concealment&FF_EC_GUESS_MVS)) || num_avail <= mb_width/2){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
331 for(mb_y=0; mb_y<s->mb_height; mb_y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
332 for(mb_x=0; mb_x<s->mb_width; mb_x++){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
333 const int mb_xy= mb_x + mb_y*s->mb_stride;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
334
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
335 if(IS_INTRA(s->current_picture.mb_type[mb_xy])) continue;
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
336 if(!(s->error_status_table[mb_xy]&MV_ERROR)) continue;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
337
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
338 s->mv_dir = MV_DIR_FORWARD;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
339 s->mb_intra=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
340 s->mv_type = MV_TYPE_16X16;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
341 s->mb_skiped=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
342
853
eacc2dd8fd9d * using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents: 847
diff changeset
343 s->dsp.clear_blocks(s->block[0]);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
344
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
345 s->mb_x= mb_x;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
346 s->mb_y= mb_y;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
347 s->mv[0][0][0]= 0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
348 s->mv[0][0][1]= 0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
349 MPV_decode_mb(s, s->block);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
350 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
351 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
352 return;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
353 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
354
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
355 for(depth=0;; depth++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
356 int changed, pass, none_left;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
357
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
358 none_left=1;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
359 changed=1;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
360 for(pass=0; (changed || pass<2) && pass<10; pass++){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
361 int mb_x, mb_y;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
362 int score_sum=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
363
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
364 changed=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
365 for(mb_y=0; mb_y<s->mb_height; mb_y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
366 for(mb_x=0; mb_x<s->mb_width; mb_x++){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
367 const int mb_xy= mb_x + mb_y*s->mb_stride;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
368 int mv_predictor[8][2]={{0}};
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
369 int pred_count=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
370 int j;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
371 int best_score=256*256*256*64;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
372 int best_pred=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
373 const int mot_stride= mb_width*2+2;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
374 const int mot_index= mb_x*2 + 1 + (mb_y*2+1)*mot_stride;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
375 int prev_x= s->motion_val[mot_index][0];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
376 int prev_y= s->motion_val[mot_index][1];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
377
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
378 if((mb_x^mb_y^pass)&1) continue;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
379
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
380 if(fixed[mb_xy]==MV_FROZEN) continue;
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
381 assert(!IS_INTRA(s->current_picture.mb_type[mb_xy]));
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
382 assert(s->last_picture_ptr && s->last_picture_ptr->data[0]);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
383
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
384 j=0;
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
385 if(mb_x>0 && fixed[mb_xy-1 ]==MV_FROZEN) j=1;
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
386 if(mb_x+1<mb_width && fixed[mb_xy+1 ]==MV_FROZEN) j=1;
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
387 if(mb_y>0 && fixed[mb_xy-mb_stride]==MV_FROZEN) j=1;
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
388 if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]==MV_FROZEN) j=1;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
389 if(j==0) continue;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
390
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
391 j=0;
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
392 if(mb_x>0 && fixed[mb_xy-1 ]==MV_CHANGED) j=1;
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
393 if(mb_x+1<mb_width && fixed[mb_xy+1 ]==MV_CHANGED) j=1;
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
394 if(mb_y>0 && fixed[mb_xy-mb_stride]==MV_CHANGED) j=1;
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
395 if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]==MV_CHANGED) j=1;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
396 if(j==0 && pass>1) continue;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
397
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
398 none_left=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
399
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
400 if(mb_x>0 && fixed[mb_xy-1]){
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
401 mv_predictor[pred_count][0]= s->motion_val[mot_index - 2][0];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
402 mv_predictor[pred_count][1]= s->motion_val[mot_index - 2][1];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
403 pred_count++;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
404 }
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
405 if(mb_x+1<mb_width && fixed[mb_xy+1]){
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
406 mv_predictor[pred_count][0]= s->motion_val[mot_index + 2][0];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
407 mv_predictor[pred_count][1]= s->motion_val[mot_index + 2][1];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
408 pred_count++;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
409 }
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
410 if(mb_y>0 && fixed[mb_xy-mb_stride]){
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
411 mv_predictor[pred_count][0]= s->motion_val[mot_index - mot_stride*2][0];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
412 mv_predictor[pred_count][1]= s->motion_val[mot_index - mot_stride*2][1];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
413 pred_count++;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
414 }
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
415 if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
416 mv_predictor[pred_count][0]= s->motion_val[mot_index + mot_stride*2][0];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
417 mv_predictor[pred_count][1]= s->motion_val[mot_index + mot_stride*2][1];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
418 pred_count++;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
419 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
420 if(pred_count==0) continue;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
421
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
422 if(pred_count>1){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
423 int sum_x=0, sum_y=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
424 int max_x, max_y, min_x, min_y;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
425
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
426 for(j=0; j<pred_count; j++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
427 sum_x+= mv_predictor[j][0];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
428 sum_y+= mv_predictor[j][1];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
429 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
430
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
431 /* mean */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
432 mv_predictor[pred_count][0] = sum_x/j;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
433 mv_predictor[pred_count][1] = sum_y/j;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
434
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
435 /* median */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
436 if(pred_count>=3){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
437 min_y= min_x= 99999;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
438 max_y= max_x=-99999;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
439 }else{
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
440 min_x=min_y=max_x=max_y=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
441 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
442 for(j=0; j<pred_count; j++){
847
f3c369b8ddca reversing header game
michaelni
parents: 745
diff changeset
443 max_x= FFMAX(max_x, mv_predictor[j][0]);
f3c369b8ddca reversing header game
michaelni
parents: 745
diff changeset
444 max_y= FFMAX(max_y, mv_predictor[j][1]);
f3c369b8ddca reversing header game
michaelni
parents: 745
diff changeset
445 min_x= FFMIN(min_x, mv_predictor[j][0]);
f3c369b8ddca reversing header game
michaelni
parents: 745
diff changeset
446 min_y= FFMIN(min_y, mv_predictor[j][1]);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
447 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
448 mv_predictor[pred_count+1][0] = sum_x - max_x - min_x;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
449 mv_predictor[pred_count+1][1] = sum_y - max_y - min_y;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
450
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
451 if(pred_count==4){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
452 mv_predictor[pred_count+1][0] /= 2;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
453 mv_predictor[pred_count+1][1] /= 2;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
454 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
455 pred_count+=2;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
456 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
457
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
458 /* zero MV */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
459 pred_count++;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
460
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
461 /* last MV */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
462 mv_predictor[pred_count][0]= s->motion_val[mot_index][0];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
463 mv_predictor[pred_count][1]= s->motion_val[mot_index][1];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
464 pred_count++;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
465
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
466 s->mv_dir = MV_DIR_FORWARD;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
467 s->mb_intra=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
468 s->mv_type = MV_TYPE_16X16;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
469 s->mb_skiped=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
470
853
eacc2dd8fd9d * using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents: 847
diff changeset
471 s->dsp.clear_blocks(s->block[0]);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
472
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
473 s->mb_x= mb_x;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
474 s->mb_y= mb_y;
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
475
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
476 for(j=0; j<pred_count; j++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
477 int score=0;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
478 uint8_t *src= s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
479
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
480 s->motion_val[mot_index][0]= s->mv[0][0][0]= mv_predictor[j][0];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
481 s->motion_val[mot_index][1]= s->mv[0][0][1]= mv_predictor[j][1];
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
482
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
483 MPV_decode_mb(s, s->block);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
484
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
485 if(mb_x>0 && fixed[mb_xy-1]){
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
486 int k;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
487 for(k=0; k<16; k++)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
488 score += ABS(src[k*s->linesize-1 ]-src[k*s->linesize ]);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
489 }
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
490 if(mb_x+1<mb_width && fixed[mb_xy+1]){
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
491 int k;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
492 for(k=0; k<16; k++)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
493 score += ABS(src[k*s->linesize+15]-src[k*s->linesize+16]);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
494 }
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
495 if(mb_y>0 && fixed[mb_xy-mb_stride]){
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
496 int k;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
497 for(k=0; k<16; k++)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
498 score += ABS(src[k-s->linesize ]-src[k ]);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
499 }
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
500 if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
501 int k;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
502 for(k=0; k<16; k++)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
503 score += ABS(src[k+s->linesize*15]-src[k+s->linesize*16]);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
504 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
505
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
506 if(score <= best_score){ // <= will favor the last MV
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
507 best_score= score;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
508 best_pred= j;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
509 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
510 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
511 score_sum+= best_score;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
512 //FIXME no need to set s->motion_val[mot_index][0] explicit
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
513 s->motion_val[mot_index][0]= s->mv[0][0][0]= mv_predictor[best_pred][0];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
514 s->motion_val[mot_index][1]= s->mv[0][0][1]= mv_predictor[best_pred][1];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
515
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
516 MPV_decode_mb(s, s->block);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
517
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
518
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
519 if(s->mv[0][0][0] != prev_x || s->mv[0][0][1] != prev_y){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
520 fixed[mb_xy]=MV_CHANGED;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
521 changed++;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
522 }else
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
523 fixed[mb_xy]=MV_UNCHANGED;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
524 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
525 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
526
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
527 // printf(".%d/%d", changed, score_sum); fflush(stdout);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
528 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
529
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
530 if(none_left)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
531 return;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
532
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
533 for(i=0; i<s->mb_num; i++){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
534 int mb_xy= s->mb_index2xy[i];
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
535 if(fixed[mb_xy])
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
536 fixed[mb_xy]=MV_FROZEN;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
537 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
538 // printf(":"); fflush(stdout);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
539 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
540 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
541
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
542 static int is_intra_more_likely(MpegEncContext *s){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
543 int is_intra_likely, i, j, undamaged_count, skip_amount, mb_x, mb_y;
904
06776293eabb use spatial error concealment if we dont have a previous frame
michaelni
parents: 903
diff changeset
544
1138
e10e841c9bf0 field pic decoding cleanup
michaelni
parents: 1106
diff changeset
545 if(s->last_picture_ptr==NULL) return 1; //no previous frame available -> use spatial prediction
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
546
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
547 undamaged_count=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
548 for(i=0; i<s->mb_num; i++){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
549 const int mb_xy= s->mb_index2xy[i];
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
550 const int error= s->error_status_table[mb_xy];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
551 if(!((error&DC_ERROR) && (error&MV_ERROR)))
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
552 undamaged_count++;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
553 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
554
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
555 if(undamaged_count < 5) return 0; //allmost all MBs damaged -> use temporal prediction
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
556
847
f3c369b8ddca reversing header game
michaelni
parents: 745
diff changeset
557 skip_amount= FFMAX(undamaged_count/50, 1); //check only upto 50 MBs
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
558 is_intra_likely=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
559
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
560 j=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
561 for(mb_y= 0; mb_y<s->mb_height-1; mb_y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
562 for(mb_x= 0; mb_x<s->mb_width; mb_x++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
563 int error;
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
564 const int mb_xy= mb_x + mb_y*s->mb_stride;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
565
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
566 error= s->error_status_table[mb_xy];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
567 if((error&DC_ERROR) && (error&MV_ERROR))
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
568 continue; //skip damaged
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
569
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
570 j++;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
571 if((j%skip_amount) != 0) continue; //skip a few to speed things up
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
572
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
573 if(s->pict_type==I_TYPE){
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
574 uint8_t *mb_ptr = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
575 uint8_t *last_mb_ptr= s->last_picture.data [0] + mb_x*16 + mb_y*16*s->linesize;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
576
853
eacc2dd8fd9d * using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents: 847
diff changeset
577 is_intra_likely += s->dsp.pix_abs16x16(last_mb_ptr, mb_ptr , s->linesize);
eacc2dd8fd9d * using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents: 847
diff changeset
578 is_intra_likely -= s->dsp.pix_abs16x16(last_mb_ptr, last_mb_ptr+s->linesize*16, s->linesize);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
579 }else{
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
580 if(IS_INTRA(s->current_picture.mb_type[mb_xy]))
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
581 is_intra_likely++;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
582 else
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
583 is_intra_likely--;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
584 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
585 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
586 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
587 //printf("is_intra_likely: %d type:%d\n", is_intra_likely, s->pict_type);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
588 return is_intra_likely > 0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
589 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
590
1144
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
591 void ff_er_frame_start(MpegEncContext *s){
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
592 if(!s->error_resilience) return;
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
593
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
594 memset(s->error_status_table, MV_ERROR|AC_ERROR|DC_ERROR|VP_START|AC_END|DC_END|MV_END, s->mb_stride*s->mb_height*sizeof(uint8_t));
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
595 s->error_count= 3*s->mb_num;
1144
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
596 }
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
597
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
598 /**
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
599 * adds a slice.
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
600 * @param endx x component of the last macroblock, can be -1 for the last of the previous line
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
601 * @param status the status at the end (MV_END, AC_ERROR, ...), it is assumed that no earlier end or
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
602 * error of the same type occured
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
603 */
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
604 void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int endy, int status){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
605 const int start_i= clip(startx + starty * s->mb_width , 0, s->mb_num-1);
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
606 const int end_i = clip(endx + endy * s->mb_width , 0, s->mb_num);
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
607 const int start_xy= s->mb_index2xy[start_i];
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
608 const int end_xy = s->mb_index2xy[end_i];
1144
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
609 int mask= -1;
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
610
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
611 if(!s->error_resilience) return;
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
612
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
613 mask &= ~VP_START;
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
614 if(status & (AC_ERROR|AC_END)){
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
615 mask &= ~(AC_ERROR|AC_END);
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
616 s->error_count -= end_i - start_i + 1;
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
617 }
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
618 if(status & (DC_ERROR|DC_END)){
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
619 mask &= ~(DC_ERROR|DC_END);
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
620 s->error_count -= end_i - start_i + 1;
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
621 }
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
622 if(status & (MV_ERROR|MV_END)){
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
623 mask &= ~(MV_ERROR|MV_END);
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
624 s->error_count -= end_i - start_i + 1;
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
625 }
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
626
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
627 if(status & (AC_ERROR|DC_ERROR|MV_ERROR)) s->error_count= INT_MAX;
1144
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
628
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
629 if(mask == ~0x7F){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
630 memset(&s->error_status_table[start_xy], 0, (end_xy - start_xy) * sizeof(uint8_t));
1144
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
631 }else{
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
632 int i;
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
633 for(i=start_xy; i<end_xy; i++){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
634 s->error_status_table[ i ] &= mask;
1144
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
635 }
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
636 }
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
637
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
638 if(end_i == s->mb_num)
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
639 s->error_count= INT_MAX;
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
640 else{
1144
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
641 s->error_status_table[end_xy] &= mask;
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
642 s->error_status_table[end_xy] |= status;
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
643 }
1175
d2fd27d01df8 fixing slice decoding, dunno why the regression tests didnt catch that ...
michaelni
parents: 1144
diff changeset
644
d2fd27d01df8 fixing slice decoding, dunno why the regression tests didnt catch that ...
michaelni
parents: 1144
diff changeset
645 s->error_status_table[start_xy] |= VP_START;
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
646
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
647 if(start_xy > 0){
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
648 int prev_status= s->error_status_table[ s->mb_index2xy[start_i - 1] ];
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
649
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
650 prev_status &= ~ VP_START;
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
651 if(prev_status != (MV_END|DC_END|AC_END)) s->error_count= INT_MAX;
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
652 }
1144
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
653 }
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
654
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
655 void ff_er_frame_end(MpegEncContext *s){
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
656 int i, mb_x, mb_y, error, error_type;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
657 int distance;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
658 int threshold_part[4]= {100,100,100};
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
659 int threshold= 50;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
660 int is_intra_likely;
1144
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
661
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
662 if(!s->error_resilience || s->error_count==0) return;
1144
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
663
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
664 fprintf(stderr, "concealing errors\n");
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
665
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
666 if(s->motion_val == NULL){
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
667 int size = (2 * s->mb_width + 2) * (2 * s->mb_height + 2);
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
668
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
669 fprintf(stderr, "Warning MVs not available\n");
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
670
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
671 s->motion_val= av_mallocz(size * 2 * sizeof(int16_t));
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
672 }
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
673
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
674 if(s->avctx->debug&FF_DEBUG_ER){
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
675 for(mb_y=0; mb_y<s->mb_height; mb_y++){
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
676 for(mb_x=0; mb_x<s->mb_width; mb_x++){
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
677 int status= s->error_status_table[mb_x + mb_y*s->mb_stride];
1144
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
678
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
679 printf("%2X ", status);
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
680 }
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
681 printf("\n");
1144
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
682 }
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
683 }
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
684
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
685 #if 1
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
686 /* handle overlapping slices */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
687 for(error_type=1; error_type<=3; error_type++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
688 int end_ok=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
689
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
690 for(i=s->mb_num-1; i>=0; i--){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
691 const int mb_xy= s->mb_index2xy[i];
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
692 int error= s->error_status_table[mb_xy];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
693
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
694 if(error&(1<<error_type))
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
695 end_ok=1;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
696 if(error&(8<<error_type))
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
697 end_ok=1;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
698
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
699 if(!end_ok)
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
700 s->error_status_table[mb_xy]|= 1<<error_type;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
701
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
702 if(error&VP_START)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
703 end_ok=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
704 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
705 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
706 #endif
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
707 #if 1
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
708 /* handle slices with partitions of different length */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
709 if(s->partitioned_frame){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
710 int end_ok=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
711
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
712 for(i=s->mb_num-1; i>=0; i--){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
713 const int mb_xy= s->mb_index2xy[i];
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
714 int error= s->error_status_table[mb_xy];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
715
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
716 if(error&AC_END)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
717 end_ok=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
718 if((error&MV_END) || (error&DC_END) || (error&AC_ERROR))
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
719 end_ok=1;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
720
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
721 if(!end_ok)
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
722 s->error_status_table[mb_xy]|= AC_ERROR;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
723
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
724 if(error&VP_START)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
725 end_ok=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
726 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
727 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
728 #endif
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
729 /* handle missing slices */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
730 if(s->error_resilience>=4){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
731 int end_ok=1;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
732
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
733 for(i=s->mb_num-2; i>=s->mb_width+100; i--){ //FIXME +100 hack
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
734 const int mb_xy= s->mb_index2xy[i];
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
735 int error1= s->error_status_table[mb_xy ];
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
736 int error2= s->error_status_table[mb_xy+1];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
737
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
738 if(error1&VP_START)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
739 end_ok=1;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
740
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
741 if( error2==(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
742 && error1!=(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
743 && ((error1&AC_END) || (error1&DC_END) || (error1&MV_END))){ //end & uninited
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
744 end_ok=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
745 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
746
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
747 if(!end_ok)
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
748 s->error_status_table[mb_xy]|= DC_ERROR|AC_ERROR|MV_ERROR;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
749 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
750 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
751
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
752 #if 1
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
753 /* backward mark errors */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
754 distance=9999999;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
755 for(error_type=1; error_type<=3; error_type++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
756 for(i=s->mb_num-1; i>=0; i--){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
757 const int mb_xy= s->mb_index2xy[i];
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
758 int error= s->error_status_table[mb_xy];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
759
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
760 if(!s->mbskip_table[mb_xy]) //FIXME partition specific
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
761 distance++;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
762 if(error&(1<<error_type))
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
763 distance= 0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
764
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
765 if(s->partitioned_frame){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
766 if(distance < threshold_part[error_type-1])
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
767 s->error_status_table[mb_xy]|= 1<<error_type;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
768 }else{
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
769 if(distance < threshold)
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
770 s->error_status_table[mb_xy]|= 1<<error_type;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
771 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
772
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
773 if(error&VP_START)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
774 distance= 9999999;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
775 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
776 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
777 #endif
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
778
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
779 /* forward mark errors */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
780 error=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
781 for(i=0; i<s->mb_num; i++){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
782 const int mb_xy= s->mb_index2xy[i];
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
783 int old_error= s->error_status_table[mb_xy];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
784
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
785 if(old_error&VP_START)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
786 error= old_error& (DC_ERROR|AC_ERROR|MV_ERROR);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
787 else{
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
788 error|= old_error& (DC_ERROR|AC_ERROR|MV_ERROR);
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
789 s->error_status_table[mb_xy]|= error;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
790 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
791 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
792 #if 1
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
793 /* handle not partitioned case */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
794 if(!s->partitioned_frame){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
795 for(i=0; i<s->mb_num; i++){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
796 const int mb_xy= s->mb_index2xy[i];
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
797 error= s->error_status_table[mb_xy];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
798 if(error&(AC_ERROR|DC_ERROR|MV_ERROR))
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
799 error|= AC_ERROR|DC_ERROR|MV_ERROR;
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
800 s->error_status_table[mb_xy]= error;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
801 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
802 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
803 #endif
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
804 is_intra_likely= is_intra_more_likely(s);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
805
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
806 /* set unknown mb-type to most likely */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
807 for(i=0; i<s->mb_num; i++){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
808 const int mb_xy= s->mb_index2xy[i];
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
809 error= s->error_status_table[mb_xy];
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
810 if(!((error&DC_ERROR) && (error&MV_ERROR)))
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
811 continue;
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
812
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
813 if(is_intra_likely)
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
814 s->current_picture.mb_type[mb_xy]= MB_TYPE_INTRA4x4;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
815 else
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
816 s->current_picture.mb_type[mb_xy]= MB_TYPE_16x16 | MB_TYPE_L0;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
817 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
818
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
819 /* handle inter blocks with damaged AC */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
820 for(mb_y=0; mb_y<s->mb_height; mb_y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
821 for(mb_x=0; mb_x<s->mb_width; mb_x++){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
822 const int mb_xy= mb_x + mb_y * s->mb_stride;
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
823 const int mb_type= s->current_picture.mb_type[mb_xy];
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
824 error= s->error_status_table[mb_xy];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
825
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
826 if(IS_INTRA(mb_type)) continue; //intra
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
827 if(error&MV_ERROR) continue; //inter with damaged MV
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
828 if(!(error&AC_ERROR)) continue; //undamaged inter
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
829
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
830 s->mv_dir = MV_DIR_FORWARD;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
831 s->mb_intra=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
832 s->mb_skiped=0;
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
833 if(IS_8X8(mb_type)){
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
834 int mb_index= mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
835 int j;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
836 s->mv_type = MV_TYPE_8X8;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
837 for(j=0; j<4; j++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
838 s->mv[0][j][0] = s->motion_val[ mb_index + (j&1) + (j>>1)*s->block_wrap[0] ][0];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
839 s->mv[0][j][1] = s->motion_val[ mb_index + (j&1) + (j>>1)*s->block_wrap[0] ][1];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
840 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
841 }else{
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
842 s->mv_type = MV_TYPE_16X16;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
843 s->mv[0][0][0] = s->motion_val[ mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0] ][0];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
844 s->mv[0][0][1] = s->motion_val[ mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0] ][1];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
845 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
846
853
eacc2dd8fd9d * using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents: 847
diff changeset
847 s->dsp.clear_blocks(s->block[0]);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
848
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
849 s->mb_x= mb_x;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
850 s->mb_y= mb_y;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
851 MPV_decode_mb(s, s->block);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
852 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
853 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
854
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
855 /* guess MVs */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
856 if(s->pict_type==B_TYPE){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
857 for(mb_y=0; mb_y<s->mb_height; mb_y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
858 for(mb_x=0; mb_x<s->mb_width; mb_x++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
859 int xy= mb_x*2+1 + (mb_y*2+1)*s->block_wrap[0];
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
860 const int mb_xy= mb_x + mb_y * s->mb_stride;
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
861 const int mb_type= s->current_picture.mb_type[mb_xy];
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
862 error= s->error_status_table[mb_xy];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
863
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
864 if(IS_INTRA(mb_type)) continue;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
865 if(!(error&MV_ERROR)) continue; //inter with undamaged MV
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
866 if(!(error&AC_ERROR)) continue; //undamaged inter
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
867
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
868 s->mv_dir = MV_DIR_FORWARD|MV_DIR_BACKWARD;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
869 s->mb_intra=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
870 s->mv_type = MV_TYPE_16X16;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
871 s->mb_skiped=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
872
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
873 if(s->pp_time){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
874 int time_pp= s->pp_time;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
875 int time_pb= s->pb_time;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
876
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
877 s->mv[0][0][0] = s->motion_val[xy][0]*time_pb/time_pp;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
878 s->mv[0][0][1] = s->motion_val[xy][1]*time_pb/time_pp;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
879 s->mv[1][0][0] = s->motion_val[xy][0]*(time_pb - time_pp)/time_pp;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
880 s->mv[1][0][1] = s->motion_val[xy][1]*(time_pb - time_pp)/time_pp;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
881 }else{
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
882 s->mv[0][0][0]= 0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
883 s->mv[0][0][1]= 0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
884 s->mv[1][0][0]= 0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
885 s->mv[1][0][1]= 0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
886 }
853
eacc2dd8fd9d * using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents: 847
diff changeset
887
eacc2dd8fd9d * using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents: 847
diff changeset
888 s->dsp.clear_blocks(s->block[0]);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
889 s->mb_x= mb_x;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
890 s->mb_y= mb_y;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
891 MPV_decode_mb(s, s->block);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
892 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
893 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
894 }else
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
895 guess_mv(s);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
896
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
897 /* fill DC for inter blocks */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
898 for(mb_y=0; mb_y<s->mb_height; mb_y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
899 for(mb_x=0; mb_x<s->mb_width; mb_x++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
900 int dc, dcu, dcv, y, n;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
901 int16_t *dc_ptr;
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
902 uint8_t *dest_y, *dest_cb, *dest_cr;
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
903 const int mb_xy= mb_x + mb_y * s->mb_stride;
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
904 const int mb_type= s->current_picture.mb_type[mb_xy];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
905
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
906 error= s->error_status_table[mb_xy];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
907
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
908 if(IS_INTRA(mb_type) && s->partitioned_frame) continue;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
909 // if(error&MV_ERROR) continue; //inter data damaged FIXME is this good?
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
910
903
22ee74da2cd3 cleanup
michaelni
parents: 853
diff changeset
911 dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
22ee74da2cd3 cleanup
michaelni
parents: 853
diff changeset
912 dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize;
22ee74da2cd3 cleanup
michaelni
parents: 853
diff changeset
913 dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
914
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
915 dc_ptr= &s->dc_val[0][mb_x*2+1 + (mb_y*2+1)*(s->mb_width*2+2)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
916 for(n=0; n<4; n++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
917 dc=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
918 for(y=0; y<8; y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
919 int x;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
920 for(x=0; x<8; x++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
921 dc+= dest_y[x + (n&1)*8 + (y + (n>>1)*8)*s->linesize];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
922 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
923 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
924 dc_ptr[(n&1) + (n>>1)*(s->mb_width*2+2)]= (dc+4)>>3;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
925 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
926
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
927 dcu=dcv=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
928 for(y=0; y<8; y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
929 int x;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
930 for(x=0; x<8; x++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
931 dcu+=dest_cb[x + y*(s->uvlinesize)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
932 dcv+=dest_cr[x + y*(s->uvlinesize)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
933 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
934 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
935 s->dc_val[1][mb_x+1 + (mb_y+1)*(s->mb_width+2)]= (dcu+4)>>3;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
936 s->dc_val[2][mb_x+1 + (mb_y+1)*(s->mb_width+2)]= (dcv+4)>>3;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
937 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
938 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
939 #if 1
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
940 /* guess DC for damaged blocks */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
941 guess_dc(s, s->dc_val[0] + s->mb_width*2+3, s->mb_width*2, s->mb_height*2, s->mb_width*2+2, 1);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
942 guess_dc(s, s->dc_val[1] + s->mb_width +3, s->mb_width , s->mb_height , s->mb_width +2, 0);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
943 guess_dc(s, s->dc_val[2] + s->mb_width +3, s->mb_width , s->mb_height , s->mb_width +2, 0);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
944 #endif
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
945 /* filter luma DC */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
946 filter181(s->dc_val[0] + s->mb_width*2+3, s->mb_width*2, s->mb_height*2, s->mb_width*2+2);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
947
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
948 #if 1
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
949 /* render DC only intra */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
950 for(mb_y=0; mb_y<s->mb_height; mb_y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
951 for(mb_x=0; mb_x<s->mb_width; mb_x++){
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
952 uint8_t *dest_y, *dest_cb, *dest_cr;
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
953 const int mb_xy= mb_x + mb_y * s->mb_stride;
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
954 const int mb_type= s->current_picture.mb_type[mb_xy];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
955
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
956 error= s->error_status_table[mb_xy];
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
957
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
958 if(IS_INTER(mb_type)) continue;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
959 if(!(error&AC_ERROR)) continue; //undamaged
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
960
903
22ee74da2cd3 cleanup
michaelni
parents: 853
diff changeset
961 dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
22ee74da2cd3 cleanup
michaelni
parents: 853
diff changeset
962 dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize;
22ee74da2cd3 cleanup
michaelni
parents: 853
diff changeset
963 dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
964
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
965 put_dc(s, dest_y, dest_cb, dest_cr, mb_x, mb_y);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
966 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
967 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
968 #endif
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
969
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
970 if(s->avctx->error_concealment&FF_EC_DEBLOCK){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
971 /* filter horizontal block boundaries */
903
22ee74da2cd3 cleanup
michaelni
parents: 853
diff changeset
972 h_block_filter(s, s->current_picture.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1);
22ee74da2cd3 cleanup
michaelni
parents: 853
diff changeset
973 h_block_filter(s, s->current_picture.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0);
22ee74da2cd3 cleanup
michaelni
parents: 853
diff changeset
974 h_block_filter(s, s->current_picture.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
975
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
976 /* filter vertical block boundaries */
903
22ee74da2cd3 cleanup
michaelni
parents: 853
diff changeset
977 v_block_filter(s, s->current_picture.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1);
22ee74da2cd3 cleanup
michaelni
parents: 853
diff changeset
978 v_block_filter(s, s->current_picture.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0);
22ee74da2cd3 cleanup
michaelni
parents: 853
diff changeset
979 v_block_filter(s, s->current_picture.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
980 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
981
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
982 /* clean a few tables */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
983 for(i=0; i<s->mb_num; i++){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
984 const int mb_xy= s->mb_index2xy[i];
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
985 int error= s->error_status_table[mb_xy];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
986
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
987 if(s->pict_type!=B_TYPE && (error&(DC_ERROR|MV_ERROR|AC_ERROR))){
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
988 s->mbskip_table[mb_xy]=0;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
989 }
1177
fea03d2c4946 simplified adressing of most mb based arrays (mb_x + mb_y*s->mb_stride) now instead of mb_x + mb_y*mb_width and 1+mb_x + (1+mb_y)*(mb_width+2) and ... mixture
michaelni
parents: 1175
diff changeset
990 s->mbintra_table[mb_xy]=1;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
991 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
992 }