annotate error_resilience.c @ 4027:ca4a837b896d libavcodec

fix !CMOV_IS_FAST case (iam not really happy with the fix but i didnt come up with a better one quickly)
author michael
date Mon, 16 Oct 2006 11:11:20 +0000
parents 34fdffe98bd0
children 23da44e8fd05
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 *
1739
07a484280a82 copyright year update of the files i touched and remembered, things look annoyingly unmaintained otherwise
michael
parents: 1731
diff changeset
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
5 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3781
diff changeset
6 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3781
diff changeset
7 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3781
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
9 * 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
10 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3781
diff changeset
11 * version 2.1 of the License, or (at your option) any later version.
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
12 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3781
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
14 * 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
15 * 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
16 * Lesser General Public License for more details.
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
17 *
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
18 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3781
diff changeset
19 * License along with FFmpeg; if not, write to the Free Software
3036
0b546eab515d Update licensing information: The FSF changed postal address.
diego
parents: 2979
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
21 */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
22
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
23 /**
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
24 * @file error_resilience.c
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
25 * Error resilience / concealment.
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
26 */
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
27
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
28 #include <limits.h>
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
29
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
30 #include "avcodec.h"
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
31 #include "dsputil.h"
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
32 #include "mpegvideo.h"
1144
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
33 #include "common.h"
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
34
1389
da0b3a50d209 rate distortion mb decision support
michaelni
parents: 1381
diff changeset
35 static void decode_mb(MpegEncContext *s){
da0b3a50d209 rate distortion mb decision support
michaelni
parents: 1381
diff changeset
36 s->dest[0] = s->current_picture.data[0] + (s->mb_y * 16* s->linesize ) + s->mb_x * 16;
da0b3a50d209 rate distortion mb decision support
michaelni
parents: 1381
diff changeset
37 s->dest[1] = s->current_picture.data[1] + (s->mb_y * 8 * s->uvlinesize) + s->mb_x * 8;
da0b3a50d209 rate distortion mb decision support
michaelni
parents: 1381
diff changeset
38 s->dest[2] = s->current_picture.data[2] + (s->mb_y * 8 * s->uvlinesize) + s->mb_x * 8;
da0b3a50d209 rate distortion mb decision support
michaelni
parents: 1381
diff changeset
39
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
40 MPV_decode_mb(s, s->block);
1389
da0b3a50d209 rate distortion mb decision support
michaelni
parents: 1381
diff changeset
41 }
da0b3a50d209 rate distortion mb decision support
michaelni
parents: 1381
diff changeset
42
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
43 /**
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
44 * 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
45 */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
46 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
47 {
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
48 int dc, dcu, dcv, y, i;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
49 for(i=0; i<4; i++){
1938
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1827
diff changeset
50 dc= s->dc_val[0][mb_x*2 + (i&1) + (mb_y*2 + (i>>1))*s->b8_stride];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
51 if(dc<0) dc=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
52 else if(dc>2040) dc=2040;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
53 for(y=0; y<8; y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
54 int x;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
55 for(x=0; x<8; x++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
56 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
57 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
58 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
59 }
1938
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1827
diff changeset
60 dcu = s->dc_val[1][mb_x + mb_y*s->mb_stride];
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1827
diff changeset
61 dcv = s->dc_val[2][mb_x + mb_y*s->mb_stride];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
62 if (dcu<0 ) dcu=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
63 else if(dcu>2040) dcu=2040;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
64 if (dcv<0 ) dcv=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
65 else if(dcv>2040) dcv=2040;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
66 for(y=0; y<8; y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
67 int x;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
68 for(x=0; x<8; x++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
69 dest_cb[x + y*(s->uvlinesize)]= dcu/8;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
70 dest_cr[x + y*(s->uvlinesize)]= dcv/8;
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 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
73 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
74
3781
8e79b099d354 dc_val should be signed
mru
parents: 3776
diff changeset
75 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
76 int x,y;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
77
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
78 /* horizontal filter */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
79 for(y=1; y<height-1; y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
80 int prev_dc= data[0 + y*stride];
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 for(x=1; x<width-1; x++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
83 int dc;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
84
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
85 dc= - prev_dc
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
86 + data[x + y*stride]*8
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
87 - data[x + 1 + y*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
88 dc= (dc*10923 + 32768)>>16;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
89 prev_dc= data[x + y*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
90 data[x + y*stride]= dc;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
91 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
92 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
93
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
94 /* vertical filter */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
95 for(x=1; x<width-1; x++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
96 int prev_dc= data[x];
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 for(y=1; y<height-1; y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
99 int dc;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
100
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
101 dc= - prev_dc
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
102 + data[x + y *stride]*8
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
103 - data[x + (y+1)*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
104 dc= (dc*10923 + 32768)>>16;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
105 prev_dc= data[x + y*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
106 data[x + y*stride]= dc;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
107 }
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 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
110
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
111 /**
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
112 * guess the dc of blocks which dont have a undamaged dc
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
113 * @param w width in 8 pixel blocks
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
114 * @param h height in 8 pixel blocks
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
115 */
3781
8e79b099d354 dc_val should be signed
mru
parents: 3776
diff changeset
116 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
117 int b_x, b_y;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
118
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
119 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
120 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
121 int color[4]={1024,1024,1024,1024};
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
122 int distance[4]={9999,9999,9999,9999};
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
123 int mb_index, error, j;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
124 int64_t guess, weight_sum;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
125
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
126 mb_index= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
127
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
128 error= s->error_status_table[mb_index];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
129
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
130 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
131 if(!(error&DC_ERROR)) continue; //dc-ok
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
132
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
133 /* right block */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
134 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
135 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
136 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
137 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
138 if(intra_j==0 || !(error_j&DC_ERROR)){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
139 color[0]= dc[j + b_y*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
140 distance[0]= j-b_x;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
141 break;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
142 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
143 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
144
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
145 /* left block */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
146 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
147 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
148 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
149 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
150 if(intra_j==0 || !(error_j&DC_ERROR)){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
151 color[1]= dc[j + b_y*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
152 distance[1]= b_x-j;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
153 break;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
154 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
155 }
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 /* bottom block */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
158 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
159 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
160 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
161 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
162 if(intra_j==0 || !(error_j&DC_ERROR)){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
163 color[2]= dc[b_x + j*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
164 distance[2]= j-b_y;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
165 break;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
166 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
167 }
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 /* top block */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
170 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
171 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
172 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
173 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
174 if(intra_j==0 || !(error_j&DC_ERROR)){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
175 color[3]= dc[b_x + j*stride];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
176 distance[3]= b_y-j;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
177 break;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
178 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
179 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
180
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
181 weight_sum=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
182 guess=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
183 for(j=0; j<4; j++){
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
184 int64_t weight= 256*256*256*16/distance[j];
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
185 guess+= weight*(int64_t)color[j];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
186 weight_sum+= weight;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
187 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
188 guess= (guess + weight_sum/2) / weight_sum;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
189
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
190 dc[b_x + b_y*stride]= guess;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
191 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
192 }
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
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
195 /**
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
196 * simple horizontal deblocking filter used for error resilience
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
197 * @param w width in 8 pixel blocks
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
198 * @param h height in 8 pixel blocks
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
199 */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
200 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
201 int b_x, b_y;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
202 uint8_t *cm = cropTbl + MAX_NEG_CROP;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
203
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
204 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
205 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
206 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
207 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
208 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
209 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
210 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
211 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
212 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
213 int offset= b_x*8 + b_y*stride*8;
1938
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1827
diff changeset
214 int16_t *left_mv= s->current_picture.motion_val[0][s->b8_stride*(b_y<<(1-is_luma)) + ( b_x <<(1-is_luma))];
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1827
diff changeset
215 int16_t *right_mv= s->current_picture.motion_val[0][s->b8_stride*(b_y<<(1-is_luma)) + ((b_x+1)<<(1-is_luma))];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
216
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
217 if(!(left_damage||right_damage)) continue; // both undamaged
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
218
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
219 if( (!left_intra) && (!right_intra)
4001
34fdffe98bd0 Rename ABS macro to FFABS.
diego
parents: 3947
diff changeset
220 && FFABS(left_mv[0]-right_mv[0]) + FFABS(left_mv[1]+right_mv[1]) < 2) continue;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
221
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
222 for(y=0; y<8; y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
223 int a,b,c,d;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
224
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
225 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
226 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
227 c= dst[offset + 9 + y*stride] - dst[offset + 8 + y*stride];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
228
4001
34fdffe98bd0 Rename ABS macro to FFABS.
diego
parents: 3947
diff changeset
229 d= FFABS(b) - ((FFABS(a) + FFABS(c) + 1)>>1);
847
f3c369b8ddca reversing header game
michaelni
parents: 745
diff changeset
230 d= FFMAX(d, 0);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
231 if(b<0) d= -d;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
232
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
233 if(d==0) continue;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
234
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
235 if(!(left_damage && right_damage))
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
236 d= d*16/9;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
237
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
238 if(left_damage){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
239 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
240 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
241 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
242 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
243 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
244 if(right_damage){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
245 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
246 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
247 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
248 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
249 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
250 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
251 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
252 }
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
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
255 /**
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
256 * simple vertical deblocking filter used for error resilience
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
257 * @param w width in 8 pixel blocks
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
258 * @param h height in 8 pixel blocks
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
259 */
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
260 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
261 int b_x, b_y;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
262 uint8_t *cm = cropTbl + MAX_NEG_CROP;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
263
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
264 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
265 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
266 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
267 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
268 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
269 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
270 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
271 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
272 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
273 int offset= b_x*8 + b_y*stride*8;
1938
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1827
diff changeset
274 int16_t *top_mv= s->current_picture.motion_val[0][s->b8_stride*( b_y <<(1-is_luma)) + (b_x<<(1-is_luma))];
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1827
diff changeset
275 int16_t *bottom_mv= s->current_picture.motion_val[0][s->b8_stride*((b_y+1)<<(1-is_luma)) + (b_x<<(1-is_luma))];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
276
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
277 if(!(top_damage||bottom_damage)) continue; // both undamaged
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
278
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
279 if( (!top_intra) && (!bottom_intra)
4001
34fdffe98bd0 Rename ABS macro to FFABS.
diego
parents: 3947
diff changeset
280 && FFABS(top_mv[0]-bottom_mv[0]) + FFABS(top_mv[1]+bottom_mv[1]) < 2) continue;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
281
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
282 for(x=0; x<8; x++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
283 int a,b,c,d;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
284
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
285 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
286 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
287 c= dst[offset + x + 9*stride] - dst[offset + x + 8*stride];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
288
4001
34fdffe98bd0 Rename ABS macro to FFABS.
diego
parents: 3947
diff changeset
289 d= FFABS(b) - ((FFABS(a) + FFABS(c)+1)>>1);
847
f3c369b8ddca reversing header game
michaelni
parents: 745
diff changeset
290 d= FFMAX(d, 0);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
291 if(b<0) d= -d;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
292
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
293 if(d==0) continue;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
294
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
295 if(!(top_damage && bottom_damage))
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
296 d= d*16/9;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
297
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
298 if(top_damage){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
299 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
300 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
301 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
302 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
303 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
304 if(bottom_damage){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
305 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
306 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
307 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
308 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
309 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
310 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
311 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
312 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
313 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
314
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
315 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
316 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
317 #define MV_FROZEN 3
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
318 #define MV_CHANGED 2
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
319 #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
320 const int mb_stride = s->mb_stride;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
321 const int mb_width = s->mb_width;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
322 const int mb_height= s->mb_height;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
323 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
324 int mb_x, mb_y;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
325
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
326 num_avail=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
327 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
328 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
329 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
330 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
331
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
332 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
333 if(!(error&MV_ERROR)) f=MV_FROZEN; //inter with undamaged MV
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
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 fixed[mb_xy]= f;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
336 if(f==MV_FROZEN)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
337 num_avail++;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
338 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
339
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
340 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
341 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
342 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
343 const int mb_xy= mb_x + mb_y*s->mb_stride;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
344
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
345 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
346 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
347
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
348 s->mv_dir = MV_DIR_FORWARD;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
349 s->mb_intra=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
350 s->mv_type = MV_TYPE_16X16;
2628
511e3afc43e1 Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents: 2570
diff changeset
351 s->mb_skipped=0;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
352
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
353 s->dsp.clear_blocks(s->block[0]);
745
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 s->mb_x= mb_x;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
356 s->mb_y= mb_y;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
357 s->mv[0][0][0]= 0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
358 s->mv[0][0][1]= 0;
1389
da0b3a50d209 rate distortion mb decision support
michaelni
parents: 1381
diff changeset
359 decode_mb(s);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
360 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
361 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
362 return;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
363 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
364
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
365 for(depth=0;; depth++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
366 int changed, pass, none_left;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
367
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
368 none_left=1;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
369 changed=1;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
370 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
371 int mb_x, mb_y;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
372 int score_sum=0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
373
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
374 changed=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
375 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
376 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
377 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
378 int mv_predictor[8][2]={{0}};
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
379 int pred_count=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
380 int j;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
381 int best_score=256*256*256*64;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
382 int best_pred=0;
1938
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1827
diff changeset
383 const int mot_stride= s->b8_stride;
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1827
diff changeset
384 const int mot_index= mb_x*2 + mb_y*2*mot_stride;
1668
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1598
diff changeset
385 int prev_x= s->current_picture.motion_val[0][mot_index][0];
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1598
diff changeset
386 int prev_y= s->current_picture.motion_val[0][mot_index][1];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
387
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
388 if((mb_x^mb_y^pass)&1) continue;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
389
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
390 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
391 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
392 assert(s->last_picture_ptr && s->last_picture_ptr->data[0]);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
393
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
394 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
395 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
396 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
397 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
398 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
399 if(j==0) continue;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
400
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
401 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
402 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
403 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
404 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
405 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
406 if(j==0 && pass>1) continue;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
407
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
408 none_left=0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
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_x>0 && fixed[mb_xy-1]){
1668
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1598
diff changeset
411 mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - 2][0];
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1598
diff changeset
412 mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - 2][1];
745
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_x+1<mb_width && fixed[mb_xy+1]){
1668
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1598
diff changeset
416 mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + 2][0];
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1598
diff changeset
417 mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + 2][1];
745
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 }
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
420 if(mb_y>0 && fixed[mb_xy-mb_stride]){
1668
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1598
diff changeset
421 mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - mot_stride*2][0];
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1598
diff changeset
422 mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - mot_stride*2][1];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
423 pred_count++;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
424 }
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
425 if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){
1668
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1598
diff changeset
426 mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + mot_stride*2][0];
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1598
diff changeset
427 mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + mot_stride*2][1];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
428 pred_count++;
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 if(pred_count==0) continue;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
431
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
432 if(pred_count>1){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
433 int sum_x=0, sum_y=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
434 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
435
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
436 for(j=0; j<pred_count; j++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
437 sum_x+= mv_predictor[j][0];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
438 sum_y+= mv_predictor[j][1];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
439 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
440
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
441 /* mean */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
442 mv_predictor[pred_count][0] = sum_x/j;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
443 mv_predictor[pred_count][1] = sum_y/j;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
444
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
445 /* median */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
446 if(pred_count>=3){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
447 min_y= min_x= 99999;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
448 max_y= max_x=-99999;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
449 }else{
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
450 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
451 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
452 for(j=0; j<pred_count; j++){
847
f3c369b8ddca reversing header game
michaelni
parents: 745
diff changeset
453 max_x= FFMAX(max_x, mv_predictor[j][0]);
f3c369b8ddca reversing header game
michaelni
parents: 745
diff changeset
454 max_y= FFMAX(max_y, mv_predictor[j][1]);
f3c369b8ddca reversing header game
michaelni
parents: 745
diff changeset
455 min_x= FFMIN(min_x, mv_predictor[j][0]);
f3c369b8ddca reversing header game
michaelni
parents: 745
diff changeset
456 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
457 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
458 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
459 mv_predictor[pred_count+1][1] = sum_y - max_y - min_y;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
460
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
461 if(pred_count==4){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
462 mv_predictor[pred_count+1][0] /= 2;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
463 mv_predictor[pred_count+1][1] /= 2;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
464 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
465 pred_count+=2;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
466 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
467
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
468 /* zero MV */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
469 pred_count++;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
470
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
471 /* last MV */
1668
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1598
diff changeset
472 mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index][0];
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1598
diff changeset
473 mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index][1];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
474 pred_count++;
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
475
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
476 s->mv_dir = MV_DIR_FORWARD;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
477 s->mb_intra=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
478 s->mv_type = MV_TYPE_16X16;
2628
511e3afc43e1 Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents: 2570
diff changeset
479 s->mb_skipped=0;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
480
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
481 s->dsp.clear_blocks(s->block[0]);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
482
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
483 s->mb_x= mb_x;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
484 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
485
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
486 for(j=0; j<pred_count; j++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
487 int score=0;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
488 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
489
1668
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1598
diff changeset
490 s->current_picture.motion_val[0][mot_index][0]= s->mv[0][0][0]= mv_predictor[j][0];
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1598
diff changeset
491 s->current_picture.motion_val[0][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
492
1389
da0b3a50d209 rate distortion mb decision support
michaelni
parents: 1381
diff changeset
493 decode_mb(s);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
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_x>0 && fixed[mb_xy-1]){
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++)
4001
34fdffe98bd0 Rename ABS macro to FFABS.
diego
parents: 3947
diff changeset
498 score += FFABS(src[k*s->linesize-1 ]-src[k*s->linesize ]);
745
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_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
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++)
4001
34fdffe98bd0 Rename ABS macro to FFABS.
diego
parents: 3947
diff changeset
503 score += FFABS(src[k*s->linesize+15]-src[k*s->linesize+16]);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
504 }
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
505 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
506 int k;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
507 for(k=0; k<16; k++)
4001
34fdffe98bd0 Rename ABS macro to FFABS.
diego
parents: 3947
diff changeset
508 score += FFABS(src[k-s->linesize ]-src[k ]);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
509 }
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
510 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
511 int k;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
512 for(k=0; k<16; k++)
4001
34fdffe98bd0 Rename ABS macro to FFABS.
diego
parents: 3947
diff changeset
513 score += FFABS(src[k+s->linesize*15]-src[k+s->linesize*16]);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
514 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
515
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
516 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
517 best_score= score;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
518 best_pred= j;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
519 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
520 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
521 score_sum+= best_score;
1668
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1598
diff changeset
522 //FIXME no need to set s->current_picture.motion_val[0][mot_index][0] explicit
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1598
diff changeset
523 s->current_picture.motion_val[0][mot_index][0]= s->mv[0][0][0]= mv_predictor[best_pred][0];
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1598
diff changeset
524 s->current_picture.motion_val[0][mot_index][1]= s->mv[0][0][1]= mv_predictor[best_pred][1];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
525
1389
da0b3a50d209 rate distortion mb decision support
michaelni
parents: 1381
diff changeset
526 decode_mb(s);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
527
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
528
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
529 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
530 fixed[mb_xy]=MV_CHANGED;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
531 changed++;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
532 }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
533 fixed[mb_xy]=MV_UNCHANGED;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
534 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
535 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
536
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
537 // printf(".%d/%d", changed, score_sum); fflush(stdout);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
538 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
539
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
540 if(none_left)
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
541 return;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
542
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
543 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
544 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
545 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
546 fixed[mb_xy]=MV_FROZEN;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
547 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
548 // printf(":"); fflush(stdout);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
549 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
550 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
551
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
552 static int is_intra_more_likely(MpegEncContext *s){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
553 int is_intra_likely, i, j, undamaged_count, skip_amount, mb_x, mb_y;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
554
1138
e10e841c9bf0 field pic decoding cleanup
michaelni
parents: 1106
diff changeset
555 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
556
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
557 undamaged_count=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
558 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
559 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
560 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
561 if(!((error&DC_ERROR) && (error&MV_ERROR)))
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
562 undamaged_count++;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
563 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
564
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
565 if(undamaged_count < 5) return 0; //allmost all MBs damaged -> use temporal prediction
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
566
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
567 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
568 is_intra_likely=0;
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=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
571 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
572 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
573 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
574 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
575
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
576 error= s->error_status_table[mb_xy];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
577 if((error&DC_ERROR) && (error&MV_ERROR))
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
578 continue; //skip damaged
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
579
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
580 j++;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
581 if((j%skip_amount) != 0) continue; //skip a few to speed things up
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
582
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
583 if(s->pict_type==I_TYPE){
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
584 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
585 uint8_t *last_mb_ptr= s->last_picture.data [0] + mb_x*16 + mb_y*16*s->linesize;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
586
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
587 is_intra_likely += s->dsp.sad[0](NULL, last_mb_ptr, mb_ptr , s->linesize, 16);
1708
dea5b2946999 interlaced motion estimation
michael
parents: 1704
diff changeset
588 is_intra_likely -= s->dsp.sad[0](NULL, last_mb_ptr, last_mb_ptr+s->linesize*16, s->linesize, 16);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
589 }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
590 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
591 is_intra_likely++;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
592 else
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
593 is_intra_likely--;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
594 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
595 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
596 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
597 //printf("is_intra_likely: %d type:%d\n", is_intra_likely, s->pict_type);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
598 return is_intra_likely > 0;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
599 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
600
1144
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
601 void ff_er_frame_start(MpegEncContext *s){
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
602 if(!s->error_resilience) return;
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
603
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
604 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
605 s->error_count= 3*s->mb_num;
1144
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
606 }
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
607
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
608 /**
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
609 * adds a slice.
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
610 * @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
611 * @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
612 * error of the same type occured
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
613 */
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
614 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
615 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
616 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
617 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
618 const int end_xy = s->mb_index2xy[end_i];
1144
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
619 int mask= -1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
620
1144
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
621 if(!s->error_resilience) return;
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
622
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
623 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
624 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
625 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
626 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
627 }
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
628 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
629 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
630 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
631 }
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
632 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
633 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
634 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
635 }
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
636
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 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
638
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
639 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
640 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
641 }else{
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
642 int i;
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
643 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
644 s->error_status_table[ i ] &= mask;
1144
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
645 }
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
646 }
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
647
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
648 if(end_i == s->mb_num)
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
649 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
650 else{
1144
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
651 s->error_status_table[end_xy] &= mask;
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
652 s->error_status_table[end_xy] |= status;
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
653 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
654
1175
d2fd27d01df8 fixing slice decoding, dunno why the regression tests didnt catch that ...
michaelni
parents: 1144
diff changeset
655 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
656
2095
5ab35105671a support skiping of mb rows during decoding
michael
parents: 1952
diff changeset
657 if(start_xy > 0 && s->avctx->thread_count <= 1 && s->avctx->skip_top*s->mb_width < start_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
658 int prev_status= s->error_status_table[ s->mb_index2xy[start_i - 1] ];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
659
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
660 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
661 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
662 }
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
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
665 void ff_er_frame_end(MpegEncContext *s){
2444
a3e29f9ab677 count errors instead of printing 2^31
michael
parents: 2357
diff changeset
666 int i, mb_x, mb_y, error, error_type, dc_error, mv_error, ac_error;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
667 int distance;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
668 int threshold_part[4]= {100,100,100};
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
669 int threshold= 50;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
670 int is_intra_likely;
2357
30d8b99e00f3 reset ref_index
michael
parents: 2095
diff changeset
671 int size = s->b8_stride * 2 * s->mb_height;
30d8b99e00f3 reset ref_index
michael
parents: 2095
diff changeset
672 Picture *pic= s->current_picture_ptr;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
673
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
674 if(!s->error_resilience || s->error_count==0 ||
2095
5ab35105671a support skiping of mb rows during decoding
michael
parents: 1952
diff changeset
675 s->error_count==3*s->mb_width*(s->avctx->skip_top + s->avctx->skip_bottom)) return;
1144
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
676
1668
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1598
diff changeset
677 if(s->current_picture.motion_val[0] == NULL){
1598
932d306bf1dc av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 1417
diff changeset
678 av_log(s->avctx, AV_LOG_ERROR, "Warning MVs not available\n");
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
679
1731
c3579468d42c memleak fix
michael
parents: 1708
diff changeset
680 for(i=0; i<2; i++){
1952
2ede7cc1fe4e 10l (segfault fix)
michael
parents: 1938
diff changeset
681 pic->ref_index[i]= av_mallocz(size * sizeof(uint8_t));
2570
682c57163e60 alignment fix
michael
parents: 2444
diff changeset
682 pic->motion_val_base[i]= av_mallocz((size+4) * 2 * sizeof(uint16_t));
682c57163e60 alignment fix
michael
parents: 2444
diff changeset
683 pic->motion_val[i]= pic->motion_val_base[i]+4;
1731
c3579468d42c memleak fix
michael
parents: 1708
diff changeset
684 }
c3579468d42c memleak fix
michael
parents: 1708
diff changeset
685 pic->motion_subsample_log2= 3;
c3579468d42c memleak fix
michael
parents: 1708
diff changeset
686 s->current_picture= *s->current_picture_ptr;
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
687 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
688
2357
30d8b99e00f3 reset ref_index
michael
parents: 2095
diff changeset
689 for(i=0; i<2; i++){
30d8b99e00f3 reset ref_index
michael
parents: 2095
diff changeset
690 if(pic->ref_index[i])
30d8b99e00f3 reset ref_index
michael
parents: 2095
diff changeset
691 memset(pic->ref_index[i], 0, size * sizeof(uint8_t));
30d8b99e00f3 reset ref_index
michael
parents: 2095
diff changeset
692 }
30d8b99e00f3 reset ref_index
michael
parents: 2095
diff changeset
693
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
694 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
695 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
696 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
697 int status= s->error_status_table[mb_x + mb_y*s->mb_stride];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
698
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
699 av_log(s->avctx, AV_LOG_DEBUG, "%2X ", 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
700 }
1598
932d306bf1dc av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents: 1417
diff changeset
701 av_log(s->avctx, AV_LOG_DEBUG, "\n");
1144
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
702 }
21c85c4ab2f0 error resilience cleanup (its faster too...)
michaelni
parents: 1138
diff changeset
703 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
704
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
705 #if 1
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
706 /* handle overlapping slices */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
707 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
708 int end_ok=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
709
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
710 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
711 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
712 int error= s->error_status_table[mb_xy];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
713
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
714 if(error&(1<<error_type))
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
715 end_ok=1;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
716 if(error&(8<<error_type))
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
717 end_ok=1;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
718
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
719 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
720 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
721
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
722 if(error&VP_START)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
723 end_ok=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
724 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
725 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
726 #endif
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
727 #if 1
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
728 /* handle slices with partitions of different length */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
729 if(s->partitioned_frame){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
730 int end_ok=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
731
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
732 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
733 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
734 int error= s->error_status_table[mb_xy];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
735
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
736 if(error&AC_END)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
737 end_ok=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
738 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
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(!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
742 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
743
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
744 if(error&VP_START)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
745 end_ok=0;
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 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
748 #endif
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
749 /* handle missing slices */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
750 if(s->error_resilience>=4){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
751 int end_ok=1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
752
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
753 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
754 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
755 int error1= s->error_status_table[mb_xy ];
1285
6e039762d5cb motion vector vissualization for mpeg1/2
michaelni
parents: 1177
diff changeset
756 int error2= s->error_status_table[s->mb_index2xy[i+1]];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
757
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
758 if(error1&VP_START)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
759 end_ok=1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
760
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
761 if( error2==(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END)
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
762 && error1!=(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END)
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
763 && ((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
764 end_ok=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
765 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
766
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
767 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
768 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
769 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
770 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
771
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
772 #if 1
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
773 /* backward mark errors */
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 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
776 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
777 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
778 int error= s->error_status_table[mb_xy];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
779
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
780 if(!s->mbskip_table[mb_xy]) //FIXME partition specific
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
781 distance++;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
782 if(error&(1<<error_type))
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
783 distance= 0;
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(s->partitioned_frame){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
786 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
787 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
788 }else{
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
789 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
790 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
791 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
792
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
793 if(error&VP_START)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
794 distance= 9999999;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
795 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
796 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
797 #endif
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
798
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
799 /* forward mark errors */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
800 error=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
801 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
802 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
803 int old_error= s->error_status_table[mb_xy];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
804
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
805 if(old_error&VP_START)
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
806 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
807 else{
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
808 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
809 s->error_status_table[mb_xy]|= error;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
810 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
811 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
812 #if 1
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
813 /* handle not partitioned case */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
814 if(!s->partitioned_frame){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
815 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
816 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
817 error= s->error_status_table[mb_xy];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
818 if(error&(AC_ERROR|DC_ERROR|MV_ERROR))
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
819 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
820 s->error_status_table[mb_xy]= error;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
821 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
822 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
823 #endif
2444
a3e29f9ab677 count errors instead of printing 2^31
michael
parents: 2357
diff changeset
824
a3e29f9ab677 count errors instead of printing 2^31
michael
parents: 2357
diff changeset
825 dc_error= ac_error= mv_error=0;
a3e29f9ab677 count errors instead of printing 2^31
michael
parents: 2357
diff changeset
826 for(i=0; i<s->mb_num; i++){
a3e29f9ab677 count errors instead of printing 2^31
michael
parents: 2357
diff changeset
827 const int mb_xy= s->mb_index2xy[i];
a3e29f9ab677 count errors instead of printing 2^31
michael
parents: 2357
diff changeset
828 error= s->error_status_table[mb_xy];
a3e29f9ab677 count errors instead of printing 2^31
michael
parents: 2357
diff changeset
829 if(error&DC_ERROR) dc_error ++;
a3e29f9ab677 count errors instead of printing 2^31
michael
parents: 2357
diff changeset
830 if(error&AC_ERROR) ac_error ++;
a3e29f9ab677 count errors instead of printing 2^31
michael
parents: 2357
diff changeset
831 if(error&MV_ERROR) mv_error ++;
a3e29f9ab677 count errors instead of printing 2^31
michael
parents: 2357
diff changeset
832 }
a3e29f9ab677 count errors instead of printing 2^31
michael
parents: 2357
diff changeset
833 av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors\n", dc_error, ac_error, mv_error);
a3e29f9ab677 count errors instead of printing 2^31
michael
parents: 2357
diff changeset
834
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
835 is_intra_likely= is_intra_more_likely(s);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
836
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
837 /* set unknown mb-type to most likely */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
838 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
839 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
840 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
841 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
842 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
843
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
844 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
845 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
846 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
847 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
848 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
849
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
850 /* handle inter blocks with damaged AC */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
851 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
852 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
853 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
854 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
855 error= s->error_status_table[mb_xy];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
856
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
857 if(IS_INTRA(mb_type)) continue; //intra
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
858 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
859 if(!(error&AC_ERROR)) continue; //undamaged inter
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
860
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
861 s->mv_dir = MV_DIR_FORWARD;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
862 s->mb_intra=0;
2628
511e3afc43e1 Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents: 2570
diff changeset
863 s->mb_skipped=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
864 if(IS_8X8(mb_type)){
1938
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1827
diff changeset
865 int mb_index= mb_x*2 + mb_y*2*s->b8_stride;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
866 int j;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
867 s->mv_type = MV_TYPE_8X8;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
868 for(j=0; j<4; j++){
1938
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1827
diff changeset
869 s->mv[0][j][0] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->b8_stride ][0];
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1827
diff changeset
870 s->mv[0][j][1] = s->current_picture.motion_val[0][ mb_index + (j&1) + (j>>1)*s->b8_stride ][1];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
871 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
872 }else{
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
873 s->mv_type = MV_TYPE_16X16;
1938
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1827
diff changeset
874 s->mv[0][0][0] = s->current_picture.motion_val[0][ mb_x*2 + mb_y*2*s->b8_stride ][0];
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1827
diff changeset
875 s->mv[0][0][1] = s->current_picture.motion_val[0][ mb_x*2 + mb_y*2*s->b8_stride ][1];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
876 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
877
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
878 s->dsp.clear_blocks(s->block[0]);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
879
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
880 s->mb_x= mb_x;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
881 s->mb_y= mb_y;
1389
da0b3a50d209 rate distortion mb decision support
michaelni
parents: 1381
diff changeset
882 decode_mb(s);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
883 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
884 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
885
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
886 /* guess MVs */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
887 if(s->pict_type==B_TYPE){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
888 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
889 for(mb_x=0; mb_x<s->mb_width; mb_x++){
1938
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1827
diff changeset
890 int xy= mb_x*2 + mb_y*2*s->b8_stride;
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
891 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
892 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
893 error= s->error_status_table[mb_xy];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
894
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
895 if(IS_INTRA(mb_type)) continue;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
896 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
897 if(!(error&AC_ERROR)) continue; //undamaged inter
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
898
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
899 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
900 s->mb_intra=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
901 s->mv_type = MV_TYPE_16X16;
2628
511e3afc43e1 Ministry of English Composition, reporting for duty (and the word is "skipped", not "skiped"; "skiped" would rhyme with "hyped")
melanson
parents: 2570
diff changeset
902 s->mb_skipped=0;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
903
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
904 if(s->pp_time){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
905 int time_pp= s->pp_time;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
906 int time_pb= s->pb_time;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
907
1668
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1598
diff changeset
908 s->mv[0][0][0] = s->next_picture.motion_val[0][xy][0]*time_pb/time_pp;
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1598
diff changeset
909 s->mv[0][0][1] = s->next_picture.motion_val[0][xy][1]*time_pb/time_pp;
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1598
diff changeset
910 s->mv[1][0][0] = s->next_picture.motion_val[0][xy][0]*(time_pb - time_pp)/time_pp;
30746f429df6 move motion_val & mb_type to AVFrame patch by (Wolfgang Hesseler <qv at multimediaware dot com>)
michael
parents: 1598
diff changeset
911 s->mv[1][0][1] = s->next_picture.motion_val[0][xy][1]*(time_pb - time_pp)/time_pp;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
912 }else{
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
913 s->mv[0][0][0]= 0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
914 s->mv[0][0][1]= 0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
915 s->mv[1][0][0]= 0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
916 s->mv[1][0][1]= 0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
917 }
853
eacc2dd8fd9d * using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents: 847
diff changeset
918
eacc2dd8fd9d * using DSPContext - so each codec could use its local (sub)set of CPU extension
kabi
parents: 847
diff changeset
919 s->dsp.clear_blocks(s->block[0]);
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
920 s->mb_x= mb_x;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
921 s->mb_y= mb_y;
1389
da0b3a50d209 rate distortion mb decision support
michaelni
parents: 1381
diff changeset
922 decode_mb(s);
745
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 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
925 }else
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
926 guess_mv(s);
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
927
1381
f07e17427140 initial XvMC support
iive
parents: 1285
diff changeset
928 #ifdef HAVE_XVMC
f07e17427140 initial XvMC support
iive
parents: 1285
diff changeset
929 /* the filters below are not XvMC compatible, skip them */
f07e17427140 initial XvMC support
iive
parents: 1285
diff changeset
930 if(s->avctx->xvmc_acceleration) goto ec_clean;
f07e17427140 initial XvMC support
iive
parents: 1285
diff changeset
931 #endif
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
932 /* fill DC for inter blocks */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
933 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
934 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
935 int dc, dcu, dcv, y, n;
3781
8e79b099d354 dc_val should be signed
mru
parents: 3776
diff changeset
936 int16_t *dc_ptr;
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
937 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
938 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
939 const int mb_type= s->current_picture.mb_type[mb_xy];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
940
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
941 error= s->error_status_table[mb_xy];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
942
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
943 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
944 // if(error&MV_ERROR) continue; //inter data damaged FIXME is this good?
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
945
903
22ee74da2cd3 cleanup
michaelni
parents: 853
diff changeset
946 dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
22ee74da2cd3 cleanup
michaelni
parents: 853
diff changeset
947 dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize;
22ee74da2cd3 cleanup
michaelni
parents: 853
diff changeset
948 dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
949
1938
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1827
diff changeset
950 dc_ptr= &s->dc_val[0][mb_x*2 + mb_y*2*s->b8_stride];
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
951 for(n=0; n<4; n++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
952 dc=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
953 for(y=0; y<8; y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
954 int x;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
955 for(x=0; x<8; x++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
956 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
957 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
958 }
1938
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1827
diff changeset
959 dc_ptr[(n&1) + (n>>1)*s->b8_stride]= (dc+4)>>3;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
960 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
961
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
962 dcu=dcv=0;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
963 for(y=0; y<8; y++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
964 int x;
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
965 for(x=0; x<8; x++){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
966 dcu+=dest_cb[x + y*(s->uvlinesize)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
967 dcv+=dest_cr[x + y*(s->uvlinesize)];
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
968 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
969 }
1938
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1827
diff changeset
970 s->dc_val[1][mb_x + mb_y*s->mb_stride]= (dcu+4)>>3;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
971 s->dc_val[2][mb_x + mb_y*s->mb_stride]= (dcv+4)>>3;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
972 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
973 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
974 #if 1
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
975 /* guess DC for damaged blocks */
1938
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1827
diff changeset
976 guess_dc(s, s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride, 1);
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1827
diff changeset
977 guess_dc(s, s->dc_val[1], s->mb_width , s->mb_height , s->mb_stride, 0);
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1827
diff changeset
978 guess_dc(s, s->dc_val[2], s->mb_width , s->mb_height , s->mb_stride, 0);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
979 #endif
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
980 /* filter luma DC */
1938
e2501e6e7ff7 unify table indexing (motion_val,dc_val,ac_val,coded_block changed)
michael
parents: 1827
diff changeset
981 filter181(s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
982
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
983 #if 1
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
984 /* render DC only intra */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
985 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
986 for(mb_x=0; mb_x<s->mb_width; mb_x++){
1064
b32afefe7d33 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 904
diff changeset
987 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
988 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
989 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
990
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
991 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
992
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
993 if(IS_INTER(mb_type)) continue;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
994 if(!(error&AC_ERROR)) continue; //undamaged
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
995
903
22ee74da2cd3 cleanup
michaelni
parents: 853
diff changeset
996 dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
22ee74da2cd3 cleanup
michaelni
parents: 853
diff changeset
997 dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize;
22ee74da2cd3 cleanup
michaelni
parents: 853
diff changeset
998 dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
999
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
1000 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
1001 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
1002 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
1003 #endif
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
1004
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
1005 if(s->avctx->error_concealment&FF_EC_DEBLOCK){
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
1006 /* filter horizontal block boundaries */
903
22ee74da2cd3 cleanup
michaelni
parents: 853
diff changeset
1007 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
1008 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
1009 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
1010
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
1011 /* filter vertical block boundaries */
903
22ee74da2cd3 cleanup
michaelni
parents: 853
diff changeset
1012 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
1013 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
1014 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
1015 }
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
1016
1417
89dacc2b9bf0 avoid warning
bellard
parents: 1389
diff changeset
1017 #ifdef HAVE_XVMC
1381
f07e17427140 initial XvMC support
iive
parents: 1285
diff changeset
1018 ec_clean:
1417
89dacc2b9bf0 avoid warning
bellard
parents: 1389
diff changeset
1019 #endif
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
1020 /* clean a few tables */
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
1021 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
1022 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
1023 int error= s->error_status_table[mb_xy];
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
1024
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
1025 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
1026 s->mbskip_table[mb_xy]=0;
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
1027 }
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
1028 s->mbintra_table[mb_xy]=1;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2628
diff changeset
1029 }
745
25d7fb7c89be better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
diff changeset
1030 }