43
43
static void decode_mb(MpegEncContext *s, int ref){
44
s->dest[0] = s->current_picture.data[0] + (s->mb_y * 16* s->linesize ) + s->mb_x * 16;
45
s->dest[1] = s->current_picture.data[1] + (s->mb_y * (16>>s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16>>s->chroma_x_shift);
46
s->dest[2] = s->current_picture.data[2] + (s->mb_y * (16>>s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16>>s->chroma_x_shift);
44
s->dest[0] = s->current_picture.f.data[0] + (s->mb_y * 16 * s->linesize) + s->mb_x * 16;
45
s->dest[1] = s->current_picture.f.data[1] + (s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16 >> s->chroma_x_shift);
46
s->dest[2] = s->current_picture.f.data[2] + (s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16 >> s->chroma_x_shift);
48
48
if(CONFIG_H264_DECODER && s->codec_id == CODEC_ID_H264){
49
49
H264Context *h= (void*)s;
50
50
h->mb_xy= s->mb_x + s->mb_y*s->mb_stride;
51
51
memset(h->non_zero_count_cache, 0, sizeof(h->non_zero_count_cache));
53
if(ref >= h->ref_count[0]) //FIXME it is posible albeit uncommon that slice references differ between slices, we take the easy approuch and ignore it for now. If this turns out to have any relevance in practice then correct remapping should be added
53
/* FIXME: It is posible albeit uncommon that slice references
54
* differ between slices. We take the easy approach and ignore
55
* it for now. If this turns out to have any relevance in
56
* practice then correct remapping should be added. */
57
if (ref >= h->ref_count[0])
55
fill_rectangle(&s->current_picture.ref_index[0][4*h->mb_xy], 2, 2, 2, ref, 1);
59
fill_rectangle(&s->current_picture.f.ref_index[0][4*h->mb_xy], 2, 2, 2, ref, 1);
56
60
fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1);
57
61
fill_rectangle(h->mv_cache[0][ scan8[0] ], 4, 4, 8, pack16to32(s->mv[0][0][0],s->mv[0][0][1]), 4);
58
62
assert(!FRAME_MBAFF);
83
* replaces the current MB with a flat dc only version.
87
* Replace the current MB with a flat dc-only version.
85
89
static void put_dc(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int mb_x, int mb_y)
167
171
error= s->error_status_table[mb_index];
169
if(IS_INTER(s->current_picture.mb_type[mb_index])) continue; //inter
170
if(!(error&DC_ERROR)) continue; //dc-ok
173
if(IS_INTER(s->current_picture.f.mb_type[mb_index])) continue; //inter
174
if(!(error&ER_DC_ERROR)) continue; //dc-ok
172
176
/* right block */
173
177
for(j=b_x+1; j<w; j++){
174
178
int mb_index_j= (j>>is_luma) + (b_y>>is_luma)*s->mb_stride;
175
179
int error_j= s->error_status_table[mb_index_j];
176
int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
177
if(intra_j==0 || !(error_j&DC_ERROR)){
180
int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]);
181
if(intra_j==0 || !(error_j&ER_DC_ERROR)){
178
182
color[0]= dc[j + b_y*stride];
179
183
distance[0]= j-b_x;
185
189
for(j=b_x-1; j>=0; j--){
186
190
int mb_index_j= (j>>is_luma) + (b_y>>is_luma)*s->mb_stride;
187
191
int error_j= s->error_status_table[mb_index_j];
188
int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
189
if(intra_j==0 || !(error_j&DC_ERROR)){
192
int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]);
193
if(intra_j==0 || !(error_j&ER_DC_ERROR)){
190
194
color[1]= dc[j + b_y*stride];
191
195
distance[1]= b_x-j;
197
201
for(j=b_y+1; j<h; j++){
198
202
int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_stride;
199
203
int error_j= s->error_status_table[mb_index_j];
200
int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
201
if(intra_j==0 || !(error_j&DC_ERROR)){
204
int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]);
205
if(intra_j==0 || !(error_j&ER_DC_ERROR)){
202
206
color[2]= dc[b_x + j*stride];
203
207
distance[2]= j-b_y;
209
213
for(j=b_y-1; j>=0; j--){
210
214
int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_stride;
211
215
int error_j= s->error_status_table[mb_index_j];
212
int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]);
213
if(intra_j==0 || !(error_j&DC_ERROR)){
216
int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]);
217
if(intra_j==0 || !(error_j&ER_DC_ERROR)){
214
218
color[3]= dc[b_x + j*stride];
215
219
distance[3]= b_y-j;
249
253
int left_status = s->error_status_table[( b_x >>is_luma) + (b_y>>is_luma)*s->mb_stride];
250
254
int right_status= s->error_status_table[((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride];
251
int left_intra= IS_INTRA(s->current_picture.mb_type [( b_x >>is_luma) + (b_y>>is_luma)*s->mb_stride]);
252
int right_intra= IS_INTRA(s->current_picture.mb_type [((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride]);
253
int left_damage = left_status&(DC_ERROR|AC_ERROR|MV_ERROR);
254
int right_damage= right_status&(DC_ERROR|AC_ERROR|MV_ERROR);
255
int left_intra = IS_INTRA(s->current_picture.f.mb_type[( b_x >> is_luma) + (b_y >> is_luma) * s->mb_stride]);
256
int right_intra = IS_INTRA(s->current_picture.f.mb_type[((b_x + 1) >> is_luma) + (b_y >> is_luma) * s->mb_stride]);
257
int left_damage = left_status&ER_MB_ERROR;
258
int right_damage= right_status&ER_MB_ERROR;
255
259
int offset= b_x*8 + b_y*stride*8;
256
int16_t *left_mv= s->current_picture.motion_val[0][mvy_stride*b_y + mvx_stride* b_x ];
257
int16_t *right_mv= s->current_picture.motion_val[0][mvy_stride*b_y + mvx_stride*(b_x+1)];
260
int16_t *left_mv= s->current_picture.f.motion_val[0][mvy_stride*b_y + mvx_stride* b_x ];
261
int16_t *right_mv= s->current_picture.f.motion_val[0][mvy_stride*b_y + mvx_stride*(b_x+1)];
259
263
if(!(left_damage||right_damage)) continue; // both undamaged
312
316
int top_status = s->error_status_table[(b_x>>is_luma) + ( b_y >>is_luma)*s->mb_stride];
313
317
int bottom_status= s->error_status_table[(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride];
314
int top_intra= IS_INTRA(s->current_picture.mb_type [(b_x>>is_luma) + ( b_y >>is_luma)*s->mb_stride]);
315
int bottom_intra= IS_INTRA(s->current_picture.mb_type [(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride]);
316
int top_damage = top_status&(DC_ERROR|AC_ERROR|MV_ERROR);
317
int bottom_damage= bottom_status&(DC_ERROR|AC_ERROR|MV_ERROR);
318
int top_intra = IS_INTRA(s->current_picture.f.mb_type[(b_x >> is_luma) + ( b_y >> is_luma) * s->mb_stride]);
319
int bottom_intra = IS_INTRA(s->current_picture.f.mb_type[(b_x >> is_luma) + ((b_y + 1) >> is_luma) * s->mb_stride]);
320
int top_damage = top_status&ER_MB_ERROR;
321
int bottom_damage= bottom_status&ER_MB_ERROR;
318
322
int offset= b_x*8 + b_y*stride*8;
319
int16_t *top_mv= s->current_picture.motion_val[0][mvy_stride* b_y + mvx_stride*b_x];
320
int16_t *bottom_mv= s->current_picture.motion_val[0][mvy_stride*(b_y+1) + mvx_stride*b_x];
323
int16_t *top_mv = s->current_picture.f.motion_val[0][mvy_stride * b_y + mvx_stride * b_x];
324
int16_t *bottom_mv = s->current_picture.f.motion_val[0][mvy_stride * (b_y + 1) + mvx_stride * b_x];
322
326
if(!(top_damage||bottom_damage)) continue; // both undamaged
377
381
int error= s->error_status_table[mb_xy];
379
if(IS_INTRA(s->current_picture.mb_type[mb_xy])) f=MV_FROZEN; //intra //FIXME check
380
if(!(error&MV_ERROR)) f=MV_FROZEN; //inter with undamaged MV
383
if(IS_INTRA(s->current_picture.f.mb_type[mb_xy])) f=MV_FROZEN; //intra //FIXME check
384
if(!(error&ER_MV_ERROR)) f=MV_FROZEN; //inter with undamaged MV
389
393
for(mb_x=0; mb_x<s->mb_width; mb_x++){
390
394
const int mb_xy= mb_x + mb_y*s->mb_stride;
392
if(IS_INTRA(s->current_picture.mb_type[mb_xy])) continue;
393
if(!(s->error_status_table[mb_xy]&MV_ERROR)) continue;
396
if(IS_INTRA(s->current_picture.f.mb_type[mb_xy])) continue;
397
if(!(s->error_status_table[mb_xy]&ER_MV_ERROR)) continue;
395
s->mv_dir = s->last_picture.data[0] ? MV_DIR_FORWARD : MV_DIR_BACKWARD;
399
s->mv_dir = s->last_picture.f.data[0] ? MV_DIR_FORWARD : MV_DIR_BACKWARD;
397
401
s->mv_type = MV_TYPE_16X16;
434
438
if((mb_x^mb_y^pass)&1) continue;
436
440
if(fixed[mb_xy]==MV_FROZEN) continue;
437
assert(!IS_INTRA(s->current_picture.mb_type[mb_xy]));
438
assert(s->last_picture_ptr && s->last_picture_ptr->data[0]);
441
assert(!IS_INTRA(s->current_picture.f.mb_type[mb_xy]));
442
assert(s->last_picture_ptr && s->last_picture_ptr->f.data[0]);
441
445
if(mb_x>0 && fixed[mb_xy-1 ]==MV_FROZEN) j=1;
456
460
if(mb_x>0 && fixed[mb_xy-1]){
457
mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - mot_step][0];
458
mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - mot_step][1];
459
ref [pred_count] = s->current_picture.ref_index[0][4*(mb_xy-1)];
461
mv_predictor[pred_count][0]= s->current_picture.f.motion_val[0][mot_index - mot_step][0];
462
mv_predictor[pred_count][1]= s->current_picture.f.motion_val[0][mot_index - mot_step][1];
463
ref [pred_count] = s->current_picture.f.ref_index[0][4*(mb_xy-1)];
462
466
if(mb_x+1<mb_width && fixed[mb_xy+1]){
463
mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + mot_step][0];
464
mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + mot_step][1];
465
ref [pred_count] = s->current_picture.ref_index[0][4*(mb_xy+1)];
467
mv_predictor[pred_count][0]= s->current_picture.f.motion_val[0][mot_index + mot_step][0];
468
mv_predictor[pred_count][1]= s->current_picture.f.motion_val[0][mot_index + mot_step][1];
469
ref [pred_count] = s->current_picture.f.ref_index[0][4*(mb_xy+1)];
468
472
if(mb_y>0 && fixed[mb_xy-mb_stride]){
469
mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - mot_stride*mot_step][0];
470
mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - mot_stride*mot_step][1];
471
ref [pred_count] = s->current_picture.ref_index[0][4*(mb_xy-s->mb_stride)];
473
mv_predictor[pred_count][0]= s->current_picture.f.motion_val[0][mot_index - mot_stride*mot_step][0];
474
mv_predictor[pred_count][1]= s->current_picture.f.motion_val[0][mot_index - mot_stride*mot_step][1];
475
ref [pred_count] = s->current_picture.f.ref_index[0][4*(mb_xy-s->mb_stride)];
474
478
if(mb_y+1<mb_height && fixed[mb_xy+mb_stride]){
475
mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index + mot_stride*mot_step][0];
476
mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + mot_stride*mot_step][1];
477
ref [pred_count] = s->current_picture.ref_index[0][4*(mb_xy+s->mb_stride)];
479
mv_predictor[pred_count][0]= s->current_picture.f.motion_val[0][mot_index + mot_stride*mot_step][0];
480
mv_predictor[pred_count][1]= s->current_picture.f.motion_val[0][mot_index + mot_stride*mot_step][1];
481
ref [pred_count] = s->current_picture.f.ref_index[0][4*(mb_xy+s->mb_stride)];
480
484
if(pred_count==0) continue;
534
538
ff_thread_await_progress((AVFrame *) s->last_picture_ptr,
537
if (!s->last_picture.motion_val[0] ||
538
!s->last_picture.ref_index[0])
541
if (!s->last_picture.f.motion_val[0] ||
542
!s->last_picture.f.ref_index[0])
539
543
goto skip_last_mv;
540
prev_x = s->last_picture.motion_val[0][mot_index][0];
541
prev_y = s->last_picture.motion_val[0][mot_index][1];
542
prev_ref = s->last_picture.ref_index[0][4*mb_xy];
544
prev_x = s->last_picture.f.motion_val[0][mot_index][0];
545
prev_y = s->last_picture.f.motion_val[0][mot_index][1];
546
prev_ref = s->last_picture.f.ref_index[0][4*mb_xy];
544
prev_x = s->current_picture.motion_val[0][mot_index][0];
545
prev_y = s->current_picture.motion_val[0][mot_index][1];
546
prev_ref = s->current_picture.ref_index[0][4*mb_xy];
548
prev_x = s->current_picture.f.motion_val[0][mot_index][0];
549
prev_y = s->current_picture.f.motion_val[0][mot_index][1];
550
prev_ref = s->current_picture.f.ref_index[0][4*mb_xy];
566
570
for(j=0; j<pred_count; j++){
568
uint8_t *src= s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
572
uint8_t *src = s->current_picture.f.data[0] + mb_x*16 + mb_y*16*s->linesize;
570
s->current_picture.motion_val[0][mot_index][0]= s->mv[0][0][0]= mv_predictor[j][0];
571
s->current_picture.motion_val[0][mot_index][1]= s->mv[0][0][1]= mv_predictor[j][1];
574
s->current_picture.f.motion_val[0][mot_index][0] = s->mv[0][0][0] = mv_predictor[j][0];
575
s->current_picture.f.motion_val[0][mot_index][1] = s->mv[0][0][1] = mv_predictor[j][1];
573
577
if(ref[j]<0) //predictor intra or otherwise not available
608
612
for(i=0; i<mot_step; i++)
609
613
for(j=0; j<mot_step; j++){
610
s->current_picture.motion_val[0][mot_index+i+j*mot_stride][0]= s->mv[0][0][0];
611
s->current_picture.motion_val[0][mot_index+i+j*mot_stride][1]= s->mv[0][0][1];
614
s->current_picture.f.motion_val[0][mot_index + i + j * mot_stride][0] = s->mv[0][0][0];
615
s->current_picture.f.motion_val[0][mot_index + i + j * mot_stride][1] = s->mv[0][0][1];
614
618
decode_mb(s, ref[best_pred]);
640
644
static int is_intra_more_likely(MpegEncContext *s){
641
645
int is_intra_likely, i, j, undamaged_count, skip_amount, mb_x, mb_y;
643
if(!s->last_picture_ptr || !s->last_picture_ptr->data[0]) return 1; //no previous frame available -> use spatial prediction
647
if (!s->last_picture_ptr || !s->last_picture_ptr->f.data[0]) return 1; //no previous frame available -> use spatial prediction
645
649
undamaged_count=0;
646
650
for(i=0; i<s->mb_num; i++){
647
651
const int mb_xy= s->mb_index2xy[i];
648
652
const int error= s->error_status_table[mb_xy];
649
if(!((error&DC_ERROR) && (error&MV_ERROR)))
653
if(!((error&ER_DC_ERROR) && (error&ER_MV_ERROR)))
650
654
undamaged_count++;
653
657
if(s->codec_id == CODEC_ID_H264){
654
658
H264Context *h= (void*)s;
655
if(h->ref_count[0] <= 0 || !h->ref_list[0][0].data[0])
659
if (h->list_count <= 0 || h->ref_count[0] <= 0 || !h->ref_list[0][0].f.data[0])
672
676
const int mb_xy= mb_x + mb_y*s->mb_stride;
674
678
error= s->error_status_table[mb_xy];
675
if((error&DC_ERROR) && (error&MV_ERROR))
679
if((error&ER_DC_ERROR) && (error&ER_MV_ERROR))
676
680
continue; //skip damaged
679
683
if((j%skip_amount) != 0) continue; //skip a few to speed things up
681
685
if(s->pict_type==AV_PICTURE_TYPE_I){
682
uint8_t *mb_ptr = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
683
uint8_t *last_mb_ptr= s->last_picture.data [0] + mb_x*16 + mb_y*16*s->linesize;
686
uint8_t *mb_ptr = s->current_picture.f.data[0] + mb_x*16 + mb_y*16*s->linesize;
687
uint8_t *last_mb_ptr= s->last_picture.f.data [0] + mb_x*16 + mb_y*16*s->linesize;
685
689
if (s->avctx->codec_id == CODEC_ID_H264) {
691
695
is_intra_likely += s->dsp.sad[0](NULL, last_mb_ptr, mb_ptr , s->linesize, 16);
692
696
is_intra_likely -= s->dsp.sad[0](NULL, last_mb_ptr, last_mb_ptr+s->linesize*16, s->linesize, 16);
694
if(IS_INTRA(s->current_picture.mb_type[mb_xy]))
698
if (IS_INTRA(s->current_picture.f.mb_type[mb_xy]))
695
699
is_intra_likely++;
697
701
is_intra_likely--;
705
709
void ff_er_frame_start(MpegEncContext *s){
706
if(!s->error_recognition) return;
710
if(!s->err_recognition) return;
708
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));
712
memset(s->error_status_table, ER_MB_ERROR|VP_START|ER_MB_END, s->mb_stride*s->mb_height*sizeof(uint8_t));
709
713
s->error_count= 3*s->mb_num;
710
714
s->error_occurred = 0;
715
719
* @param endx x component of the last macroblock, can be -1 for the last of the previous line
716
* @param status the status at the end (MV_END, AC_ERROR, ...), it is assumed that no earlier end or
720
* @param status the status at the end (ER_MV_END, ER_AC_ERROR, ...), it is assumed that no earlier end or
717
721
* error of the same type occurred
719
723
void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int endy, int status){
734
if(!s->error_recognition) return;
738
if(!s->err_recognition) return;
736
740
mask &= ~VP_START;
737
if(status & (AC_ERROR|AC_END)){
738
mask &= ~(AC_ERROR|AC_END);
739
s->error_count -= end_i - start_i + 1;
741
if(status & (DC_ERROR|DC_END)){
742
mask &= ~(DC_ERROR|DC_END);
743
s->error_count -= end_i - start_i + 1;
745
if(status & (MV_ERROR|MV_END)){
746
mask &= ~(MV_ERROR|MV_END);
741
if(status & (ER_AC_ERROR|ER_AC_END)){
742
mask &= ~(ER_AC_ERROR|ER_AC_END);
743
s->error_count -= end_i - start_i + 1;
745
if(status & (ER_DC_ERROR|ER_DC_END)){
746
mask &= ~(ER_DC_ERROR|ER_DC_END);
747
s->error_count -= end_i - start_i + 1;
749
if(status & (ER_MV_ERROR|ER_MV_END)){
750
mask &= ~(ER_MV_ERROR|ER_MV_END);
747
751
s->error_count -= end_i - start_i + 1;
750
if(status & (AC_ERROR|DC_ERROR|MV_ERROR)) {
754
if(status & ER_MB_ERROR) {
751
755
s->error_occurred = 1;
752
756
s->error_count= INT_MAX;
787
791
int size = s->b8_stride * 2 * s->mb_height;
788
792
Picture *pic= s->current_picture_ptr;
790
if(!s->error_recognition || s->error_count==0 || s->avctx->lowres ||
794
if(!s->err_recognition || s->error_count==0 || s->avctx->lowres ||
791
795
s->avctx->hwaccel ||
792
796
s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU ||
793
s->picture_structure != PICT_FRAME || // we dont support ER of field pictures yet, though it should not crash if enabled
797
s->picture_structure != PICT_FRAME || // we do not support ER of field pictures yet, though it should not crash if enabled
794
798
s->error_count==3*s->mb_width*(s->avctx->skip_top + s->avctx->skip_bottom)) return;
796
if(s->current_picture.motion_val[0] == NULL){
800
if (s->current_picture.f.motion_val[0] == NULL) {
797
801
av_log(s->avctx, AV_LOG_ERROR, "Warning MVs not available\n");
799
803
for(i=0; i<2; i++){
800
pic->ref_index[i]= av_mallocz(s->mb_stride * s->mb_height * 4 * sizeof(uint8_t));
804
pic->f.ref_index[i] = av_mallocz(s->mb_stride * s->mb_height * 4 * sizeof(uint8_t));
801
805
pic->motion_val_base[i]= av_mallocz((size+4) * 2 * sizeof(uint16_t));
802
pic->motion_val[i]= pic->motion_val_base[i]+4;
806
pic->f.motion_val[i] = pic->motion_val_base[i] + 4;
804
pic->motion_subsample_log2= 3;
808
pic->f.motion_subsample_log2 = 3;
805
809
s->current_picture= *s->current_picture_ptr;
845
849
const int mb_xy= s->mb_index2xy[i];
846
850
int error= s->error_status_table[mb_xy];
850
if((error&MV_END) || (error&DC_END) || (error&AC_ERROR))
854
if((error&ER_MV_END) || (error&ER_DC_END) || (error&ER_AC_ERROR))
854
s->error_status_table[mb_xy]|= AC_ERROR;
858
s->error_status_table[mb_xy]|= ER_AC_ERROR;
856
860
if(error&VP_START)
870
874
if(error1&VP_START)
873
if( error2==(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END)
874
&& error1!=(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END)
875
&& ((error1&AC_END) || (error1&DC_END) || (error1&MV_END))){ //end & uninit
877
if( error2==(VP_START|ER_MB_ERROR|ER_MB_END)
878
&& error1!=(VP_START|ER_MB_ERROR|ER_MB_END)
879
&& ((error1&ER_AC_END) || (error1&ER_DC_END) || (error1&ER_MV_END))){ //end & uninit
880
s->error_status_table[mb_xy]|= DC_ERROR|AC_ERROR|MV_ERROR;
884
s->error_status_table[mb_xy]|= ER_MB_ERROR;
913
917
int old_error= s->error_status_table[mb_xy];
915
919
if(old_error&VP_START)
916
error= old_error& (DC_ERROR|AC_ERROR|MV_ERROR);
920
error= old_error& ER_MB_ERROR;
918
error|= old_error& (DC_ERROR|AC_ERROR|MV_ERROR);
922
error|= old_error& ER_MB_ERROR;
919
923
s->error_status_table[mb_xy]|= error;
925
929
for(i=0; i<s->mb_num; i++){
926
930
const int mb_xy= s->mb_index2xy[i];
927
931
error= s->error_status_table[mb_xy];
928
if(error&(AC_ERROR|DC_ERROR|MV_ERROR))
929
error|= AC_ERROR|DC_ERROR|MV_ERROR;
932
if(error&ER_MB_ERROR)
930
934
s->error_status_table[mb_xy]= error;
935
939
for(i=0; i<s->mb_num; i++){
936
940
const int mb_xy= s->mb_index2xy[i];
937
941
error= s->error_status_table[mb_xy];
938
if(error&DC_ERROR) dc_error ++;
939
if(error&AC_ERROR) ac_error ++;
940
if(error&MV_ERROR) mv_error ++;
942
if(error&ER_DC_ERROR) dc_error ++;
943
if(error&ER_AC_ERROR) ac_error ++;
944
if(error&ER_MV_ERROR) mv_error ++;
942
946
av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors\n", dc_error, ac_error, mv_error);
947
951
for(i=0; i<s->mb_num; i++){
948
952
const int mb_xy= s->mb_index2xy[i];
949
953
error= s->error_status_table[mb_xy];
950
if(!((error&DC_ERROR) && (error&MV_ERROR)))
954
if(!((error&ER_DC_ERROR) && (error&ER_MV_ERROR)))
953
957
if(is_intra_likely)
954
s->current_picture.mb_type[mb_xy]= MB_TYPE_INTRA4x4;
958
s->current_picture.f.mb_type[mb_xy] = MB_TYPE_INTRA4x4;
956
s->current_picture.mb_type[mb_xy]= MB_TYPE_16x16 | MB_TYPE_L0;
960
s->current_picture.f.mb_type[mb_xy] = MB_TYPE_16x16 | MB_TYPE_L0;
959
963
// change inter to intra blocks if no reference frames are available
960
if (!s->last_picture.data[0] && !s->next_picture.data[0])
964
if (!s->last_picture.f.data[0] && !s->next_picture.f.data[0])
961
965
for(i=0; i<s->mb_num; i++){
962
966
const int mb_xy= s->mb_index2xy[i];
963
if(!IS_INTRA(s->current_picture.mb_type[mb_xy]))
964
s->current_picture.mb_type[mb_xy]= MB_TYPE_INTRA4x4;
967
if (!IS_INTRA(s->current_picture.f.mb_type[mb_xy]))
968
s->current_picture.f.mb_type[mb_xy] = MB_TYPE_INTRA4x4;
967
971
/* handle inter blocks with damaged AC */
968
972
for(mb_y=0; mb_y<s->mb_height; mb_y++){
969
973
for(mb_x=0; mb_x<s->mb_width; mb_x++){
970
974
const int mb_xy= mb_x + mb_y * s->mb_stride;
971
const int mb_type= s->current_picture.mb_type[mb_xy];
972
int dir = !s->last_picture.data[0];
975
const int mb_type= s->current_picture.f.mb_type[mb_xy];
976
int dir = !s->last_picture.f.data[0];
973
977
error= s->error_status_table[mb_xy];
975
979
if(IS_INTRA(mb_type)) continue; //intra
976
if(error&MV_ERROR) continue; //inter with damaged MV
977
if(!(error&AC_ERROR)) continue; //undamaged inter
980
if(error&ER_MV_ERROR) continue; //inter with damaged MV
981
if(!(error&ER_AC_ERROR)) continue; //undamaged inter
979
983
s->mv_dir = dir ? MV_DIR_BACKWARD : MV_DIR_FORWARD;
985
989
s->mv_type = MV_TYPE_8X8;
986
990
for(j=0; j<4; j++){
987
s->mv[0][j][0] = s->current_picture.motion_val[dir][ mb_index + (j&1) + (j>>1)*s->b8_stride ][0];
988
s->mv[0][j][1] = s->current_picture.motion_val[dir][ mb_index + (j&1) + (j>>1)*s->b8_stride ][1];
991
s->mv[0][j][0] = s->current_picture.f.motion_val[dir][mb_index + (j & 1) + (j >> 1) * s->b8_stride][0];
992
s->mv[0][j][1] = s->current_picture.f.motion_val[dir][mb_index + (j & 1) + (j >> 1) * s->b8_stride][1];
991
995
s->mv_type = MV_TYPE_16X16;
992
s->mv[0][0][0] = s->current_picture.motion_val[dir][ mb_x*2 + mb_y*2*s->b8_stride ][0];
993
s->mv[0][0][1] = s->current_picture.motion_val[dir][ mb_x*2 + mb_y*2*s->b8_stride ][1];
996
s->mv[0][0][0] = s->current_picture.f.motion_val[dir][ mb_x*2 + mb_y*2*s->b8_stride ][0];
997
s->mv[0][0][1] = s->current_picture.f.motion_val[dir][ mb_x*2 + mb_y*2*s->b8_stride ][1];
996
1000
s->dsp.clear_blocks(s->block[0]);
1007
1011
for(mb_x=0; mb_x<s->mb_width; mb_x++){
1008
1012
int xy= mb_x*2 + mb_y*2*s->b8_stride;
1009
1013
const int mb_xy= mb_x + mb_y * s->mb_stride;
1010
const int mb_type= s->current_picture.mb_type[mb_xy];
1014
const int mb_type= s->current_picture.f.mb_type[mb_xy];
1011
1015
error= s->error_status_table[mb_xy];
1013
1017
if(IS_INTRA(mb_type)) continue;
1014
if(!(error&MV_ERROR)) continue; //inter with undamaged MV
1015
if(!(error&AC_ERROR)) continue; //undamaged inter
1018
if(!(error&ER_MV_ERROR)) continue; //inter with undamaged MV
1019
if(!(error&ER_AC_ERROR)) continue; //undamaged inter
1017
1021
s->mv_dir = MV_DIR_FORWARD|MV_DIR_BACKWARD;
1018
if(!s->last_picture.data[0]) s->mv_dir &= ~MV_DIR_FORWARD;
1019
if(!s->next_picture.data[0]) s->mv_dir &= ~MV_DIR_BACKWARD;
1022
if(!s->last_picture.f.data[0]) s->mv_dir &= ~MV_DIR_FORWARD;
1023
if(!s->next_picture.f.data[0]) s->mv_dir &= ~MV_DIR_BACKWARD;
1021
1025
s->mv_type = MV_TYPE_16X16;
1022
1026
s->mb_skipped=0;
1031
1035
ff_thread_await_progress((AVFrame *) s->next_picture_ptr,
1034
s->mv[0][0][0] = s->next_picture.motion_val[0][xy][0]*time_pb/time_pp;
1035
s->mv[0][0][1] = s->next_picture.motion_val[0][xy][1]*time_pb/time_pp;
1036
s->mv[1][0][0] = s->next_picture.motion_val[0][xy][0]*(time_pb - time_pp)/time_pp;
1037
s->mv[1][0][1] = s->next_picture.motion_val[0][xy][1]*(time_pb - time_pp)/time_pp;
1038
s->mv[0][0][0] = s->next_picture.f.motion_val[0][xy][0] * time_pb / time_pp;
1039
s->mv[0][0][1] = s->next_picture.f.motion_val[0][xy][1] * time_pb / time_pp;
1040
s->mv[1][0][0] = s->next_picture.f.motion_val[0][xy][0] * (time_pb - time_pp) / time_pp;
1041
s->mv[1][0][1] = s->next_picture.f.motion_val[0][xy][1] * (time_pb - time_pp) / time_pp;
1039
1043
s->mv[0][0][0]= 0;
1040
1044
s->mv[0][0][1]= 0;
1061
1065
int16_t *dc_ptr;
1062
1066
uint8_t *dest_y, *dest_cb, *dest_cr;
1063
1067
const int mb_xy= mb_x + mb_y * s->mb_stride;
1064
const int mb_type= s->current_picture.mb_type[mb_xy];
1068
const int mb_type = s->current_picture.f.mb_type[mb_xy];
1066
1070
error= s->error_status_table[mb_xy];
1068
1072
if(IS_INTRA(mb_type) && s->partitioned_frame) continue;
1069
// if(error&MV_ERROR) continue; //inter data damaged FIXME is this good?
1073
// if(error&ER_MV_ERROR) continue; //inter data damaged FIXME is this good?
1071
dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
1072
dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize;
1073
dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize;
1075
dest_y = s->current_picture.f.data[0] + mb_x * 16 + mb_y * 16 * s->linesize;
1076
dest_cb = s->current_picture.f.data[1] + mb_x * 8 + mb_y * 8 * s->uvlinesize;
1077
dest_cr = s->current_picture.f.data[2] + mb_x * 8 + mb_y * 8 * s->uvlinesize;
1075
1079
dc_ptr= &s->dc_val[0][mb_x*2 + mb_y*2*s->b8_stride];
1076
1080
for(n=0; n<4; n++){
1110
1114
for(mb_x=0; mb_x<s->mb_width; mb_x++){
1111
1115
uint8_t *dest_y, *dest_cb, *dest_cr;
1112
1116
const int mb_xy= mb_x + mb_y * s->mb_stride;
1113
const int mb_type= s->current_picture.mb_type[mb_xy];
1117
const int mb_type = s->current_picture.f.mb_type[mb_xy];
1115
1119
error= s->error_status_table[mb_xy];
1117
1121
if(IS_INTER(mb_type)) continue;
1118
if(!(error&AC_ERROR)) continue; //undamaged
1122
if(!(error&ER_AC_ERROR)) continue; //undamaged
1120
dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
1121
dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize;
1122
dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize;
1124
dest_y = s->current_picture.f.data[0] + mb_x * 16 + mb_y * 16 * s->linesize;
1125
dest_cb = s->current_picture.f.data[1] + mb_x * 8 + mb_y * 8 * s->uvlinesize;
1126
dest_cr = s->current_picture.f.data[2] + mb_x * 8 + mb_y * 8 * s->uvlinesize;
1124
1128
put_dc(s, dest_y, dest_cb, dest_cr, mb_x, mb_y);
1128
1132
if(s->avctx->error_concealment&FF_EC_DEBLOCK){
1129
1133
/* filter horizontal block boundaries */
1130
h_block_filter(s, s->current_picture.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1);
1131
h_block_filter(s, s->current_picture.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0);
1132
h_block_filter(s, s->current_picture.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0);
1134
h_block_filter(s, s->current_picture.f.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1);
1135
h_block_filter(s, s->current_picture.f.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0);
1136
h_block_filter(s, s->current_picture.f.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0);
1134
1138
/* filter vertical block boundaries */
1135
v_block_filter(s, s->current_picture.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1);
1136
v_block_filter(s, s->current_picture.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0);
1137
v_block_filter(s, s->current_picture.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0);
1139
v_block_filter(s, s->current_picture.f.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1);
1140
v_block_filter(s, s->current_picture.f.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0);
1141
v_block_filter(s, s->current_picture.f.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0);
1143
1147
const int mb_xy= s->mb_index2xy[i];
1144
1148
int error= s->error_status_table[mb_xy];
1146
if(s->pict_type!=AV_PICTURE_TYPE_B && (error&(DC_ERROR|MV_ERROR|AC_ERROR))){
1150
if(s->pict_type!=AV_PICTURE_TYPE_B && (error&(ER_DC_ERROR|ER_MV_ERROR|ER_AC_ERROR))){
1147
1151
s->mbskip_table[mb_xy]=0;
1149
1153
s->mbintra_table[mb_xy]=1;