2 * This file is part of Libav.
4 * Libav is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * Libav is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with Libav; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 #include "error_resilience.h"
20 #include "mpegvideo.h"
23 static void set_erpic(ERPicture
*dst
, Picture
*src
)
36 for (i
= 0; i
< 2; i
++) {
37 dst
->motion_val
[i
] = src
->motion_val
[i
];
38 dst
->ref_index
[i
] = src
->ref_index
[i
];
41 dst
->mb_type
= src
->mb_type
;
42 dst
->field_picture
= src
->field_picture
;
45 void ff_mpeg_er_frame_start(MpegEncContext
*s
)
47 ERContext
*er
= &s
->er
;
49 set_erpic(&er
->cur_pic
, s
->current_picture_ptr
);
50 set_erpic(&er
->next_pic
, s
->next_picture_ptr
);
51 set_erpic(&er
->last_pic
, s
->last_picture_ptr
);
53 er
->pp_time
= s
->pp_time
;
54 er
->pb_time
= s
->pb_time
;
55 er
->quarter_sample
= s
->quarter_sample
;
56 er
->partitioned_frame
= s
->partitioned_frame
;
58 ff_er_frame_start(er
);
61 static void mpeg_er_decode_mb(void *opaque
, int ref
, int mv_dir
, int mv_type
,
62 int (*mv
)[2][4][2], int mb_x
, int mb_y
,
63 int mb_intra
, int mb_skipped
)
65 MpegEncContext
*s
= opaque
;
69 s
->mb_intra
= mb_intra
;
70 s
->mb_skipped
= mb_skipped
;
73 memcpy(s
->mv
, mv
, sizeof(*mv
));
75 ff_init_block_index(s
);
76 ff_update_block_index(s
);
78 s
->bdsp
.clear_blocks(s
->block
[0]);
80 s
->dest
[0] = s
->current_picture
.f
->data
[0] +
81 s
->mb_y
* 16 * s
->linesize
+
83 s
->dest
[1] = s
->current_picture
.f
->data
[1] +
84 s
->mb_y
* (16 >> s
->chroma_y_shift
) * s
->uvlinesize
+
85 s
->mb_x
* (16 >> s
->chroma_x_shift
);
86 s
->dest
[2] = s
->current_picture
.f
->data
[2] +
87 s
->mb_y
* (16 >> s
->chroma_y_shift
) * s
->uvlinesize
+
88 s
->mb_x
* (16 >> s
->chroma_x_shift
);
91 av_log(s
->avctx
, AV_LOG_DEBUG
,
92 "Interlaced error concealment is not fully implemented\n");
93 ff_mpv_decode_mb(s
, s
->block
);
96 int ff_mpeg_er_init(MpegEncContext
*s
)
98 ERContext
*er
= &s
->er
;
99 int mb_array_size
= s
->mb_height
* s
->mb_stride
;
102 er
->avctx
= s
->avctx
;
104 er
->mb_index2xy
= s
->mb_index2xy
;
105 er
->mb_num
= s
->mb_num
;
106 er
->mb_width
= s
->mb_width
;
107 er
->mb_height
= s
->mb_height
;
108 er
->mb_stride
= s
->mb_stride
;
109 er
->b8_stride
= s
->b8_stride
;
111 er
->er_temp_buffer
= av_malloc(s
->mb_height
* s
->mb_stride
);
112 er
->error_status_table
= av_mallocz(mb_array_size
);
113 if (!er
->er_temp_buffer
|| !er
->error_status_table
)
116 er
->mbskip_table
= s
->mbskip_table
;
117 er
->mbintra_table
= s
->mbintra_table
;
119 for (i
= 0; i
< FF_ARRAY_ELEMS(s
->dc_val
); i
++)
120 er
->dc_val
[i
] = s
->dc_val
[i
];
122 er
->decode_mb
= mpeg_er_decode_mb
;
127 av_freep(&er
->er_temp_buffer
);
128 av_freep(&er
->error_status_table
);
129 return AVERROR(ENOMEM
);