94 uint8_t *dest_cr,
int mb_x,
int mb_y)
96 int dc, dcu, dcv, y, i;
97 for (i = 0; i < 4; i++) {
98 dc = s->
dc_val[0][mb_x * 2 + (i & 1) + (mb_y * 2 + (i >> 1)) * s->
b8_stride];
103 for (y = 0; y < 8; y++) {
105 for (x = 0; x < 8; x++)
106 dest_y[x + (i & 1) * 8 + (y + (i >> 1) * 8) * s->
linesize] = dc / 8;
119 for (y = 0; y < 8; y++) {
121 for (x = 0; x < 8; x++) {
133 for (y = 1; y < height - 1; y++) {
134 int prev_dc = data[0 + y *
stride];
136 for (x = 1; x < width - 1; x++) {
139 data[x + y *
stride] * 8 -
141 dc = (dc * 10923 + 32768) >> 16;
142 prev_dc = data[x + y *
stride];
143 data[x + y *
stride] = dc;
148 for (x = 1; x < width - 1; x++) {
149 int prev_dc = data[x];
151 for (y = 1; y < height - 1; y++) {
155 data[x + y *
stride] * 8 -
156 data[x + (y + 1) * stride];
157 dc = (dc * 10923 + 32768) >> 16;
158 prev_dc = data[x + y *
stride];
159 data[x + y *
stride] = dc;
170 int h,
int stride,
int is_luma)
174 for (b_y = 0; b_y < h; b_y++) {
175 for (b_x = 0; b_x < w; b_x++) {
176 int color[4] = { 1024, 1024, 1024, 1024 };
177 int distance[4] = { 9999, 9999, 9999, 9999 };
178 int mb_index, error, j;
179 int64_t guess, weight_sum;
180 mb_index = (b_x >> is_luma) + (b_y >> is_luma) * s->
mb_stride;
189 for (j = b_x + 1; j < w; j++) {
190 int mb_index_j = (j >> is_luma) + (b_y >> is_luma) * s->
mb_stride;
193 if (intra_j == 0 || !(error_j & ER_DC_ERROR)) {
194 color[0] = dc[j + b_y *
stride];
195 distance[0] = j - b_x;
201 for (j = b_x - 1; j >= 0; j--) {
202 int mb_index_j = (j >> is_luma) + (b_y >> is_luma) * s->
mb_stride;
205 if (intra_j == 0 || !(error_j & ER_DC_ERROR)) {
206 color[1] = dc[j + b_y *
stride];
207 distance[1] = b_x - j;
213 for (j = b_y + 1; j < h; j++) {
214 int mb_index_j = (b_x >> is_luma) + (j >> is_luma) * s->
mb_stride;
218 if (intra_j == 0 || !(error_j & ER_DC_ERROR)) {
219 color[2] = dc[b_x + j *
stride];
220 distance[2] = j - b_y;
226 for (j = b_y - 1; j >= 0; j--) {
227 int mb_index_j = (b_x >> is_luma) + (j >> is_luma) * s->
mb_stride;
230 if (intra_j == 0 || !(error_j & ER_DC_ERROR)) {
231 color[3] = dc[b_x + j *
stride];
232 distance[3] = b_y - j;
239 for (j = 0; j < 4; j++) {
240 int64_t weight = 256 * 256 * 256 * 16 / distance[j];
241 guess += weight * (int64_t) color[j];
242 weight_sum += weight;
244 guess = (guess + weight_sum / 2) / weight_sum;
245 dc[b_x + b_y *
stride] = guess;
256 int h,
int stride,
int is_luma)
258 int b_x, b_y, mvx_stride, mvy_stride;
261 mvx_stride >>= is_luma;
262 mvy_stride *= mvx_stride;
264 for (b_y = 0; b_y < h; b_y++) {
265 for (b_x = 0; b_x < w - 1; b_x++) {
273 int offset = b_x * 8 + b_y * stride * 8;
276 if (!(left_damage || right_damage))
278 if ((!left_intra) && (!right_intra) &&
279 FFABS(left_mv[0] - right_mv[0]) +
280 FFABS(left_mv[1] + right_mv[1]) < 2)
283 for (y = 0; y < 8; y++) {
286 a = dst[offset + 7 + y *
stride] - dst[offset + 6 + y *
stride];
287 b = dst[offset + 8 + y *
stride] - dst[offset + 7 + y *
stride];
288 c = dst[offset + 9 + y *
stride] - dst[offset + 8 + y *
stride];
298 if (!(left_damage && right_damage))
302 dst[offset + 7 + y *
stride] = cm[dst[offset + 7 + y *
stride] + ((d * 7) >> 4)];
303 dst[offset + 6 + y *
stride] = cm[dst[offset + 6 + y *
stride] + ((d * 5) >> 4)];
304 dst[offset + 5 + y *
stride] = cm[dst[offset + 5 + y *
stride] + ((d * 3) >> 4)];
305 dst[offset + 4 + y *
stride] = cm[dst[offset + 4 + y *
stride] + ((d * 1) >> 4)];
308 dst[offset + 8 + y *
stride] = cm[dst[offset + 8 + y *
stride] - ((d * 7) >> 4)];
309 dst[offset + 9 + y *
stride] = cm[dst[offset + 9 + y *
stride] - ((d * 5) >> 4)];
310 dst[offset + 10+ y *
stride] = cm[dst[offset + 10 + y *
stride] - ((d * 3) >> 4)];
311 dst[offset + 11+ y *
stride] = cm[dst[offset + 11 + y *
stride] - ((d * 1) >> 4)];
326 int b_x, b_y, mvx_stride, mvy_stride;
329 mvx_stride >>= is_luma;
330 mvy_stride *= mvx_stride;
332 for (b_y = 0; b_y < h - 1; b_y++) {
333 for (b_x = 0; b_x < w; b_x++) {
341 int offset = b_x * 8 + b_y * stride * 8;
346 if (!(top_damage || bottom_damage))
349 if ((!top_intra) && (!bottom_intra) &&
350 FFABS(top_mv[0] - bottom_mv[0]) +
351 FFABS(top_mv[1] + bottom_mv[1]) < 2)
354 for (x = 0; x < 8; x++) {
357 a = dst[offset + x + 7 *
stride] - dst[offset + x + 6 *
stride];
358 b = dst[offset + x + 8 *
stride] - dst[offset + x + 7 *
stride];
359 c = dst[offset + x + 9 *
stride] - dst[offset + x + 8 *
stride];
369 if (!(top_damage && bottom_damage))
373 dst[offset + x + 7 *
stride] = cm[dst[offset + x + 7 *
stride] + ((d * 7) >> 4)];
374 dst[offset + x + 6 *
stride] = cm[dst[offset + x + 6 *
stride] + ((d * 5) >> 4)];
375 dst[offset + x + 5 *
stride] = cm[dst[offset + x + 5 *
stride] + ((d * 3) >> 4)];
376 dst[offset + x + 4 *
stride] = cm[dst[offset + x + 4 *
stride] + ((d * 1) >> 4)];
379 dst[offset + x + 8 *
stride] = cm[dst[offset + x + 8 *
stride] - ((d * 7) >> 4)];
380 dst[offset + x + 9 *
stride] = cm[dst[offset + x + 9 *
stride] - ((d * 5) >> 4)];
381 dst[offset + x + 10 *
stride] = cm[dst[offset + x + 10 *
stride] - ((d * 3) >> 4)];
382 dst[offset + x + 11 *
stride] = cm[dst[offset + x + 11 *
stride] - ((d * 1) >> 4)];
394 #define MV_UNCHANGED 1
398 int i, depth, num_avail;
399 int mb_x, mb_y, mot_step, mot_stride;
404 for (i = 0; i < s->
mb_num; i++) {
420 num_avail <= mb_width / 2) {
421 for (mb_y = 0; mb_y < s->
mb_height; mb_y++) {
425 for (mb_x = 0; mb_x < s->
mb_width; mb_x++) {
426 const int mb_xy = mb_x + mb_y * s->
mb_stride;
453 for (depth = 0; ; depth++) {
454 int changed,
pass, none_left;
458 for (pass = 0; (changed || pass < 2) && pass < 10; pass++) {
463 for (mb_y = 0; mb_y < s->
mb_height; mb_y++) {
467 for (mb_x = 0; mb_x < s->
mb_width; mb_x++) {
468 const int mb_xy = mb_x + mb_y * s->
mb_stride;
469 int mv_predictor[8][2] = { { 0 } };
473 int best_score = 256 * 256 * 256 * 64;
475 const int mot_index = (mb_x + mb_y * mot_stride) * mot_step;
476 int prev_x, prev_y, prev_ref;
480 if ((mb_x ^ mb_y ^ pass) & 1)
489 if (mb_x > 0 && fixed[mb_xy - 1] ==
MV_FROZEN)
491 if (mb_x + 1 < mb_width && fixed[mb_xy + 1] ==
MV_FROZEN)
493 if (mb_y > 0 && fixed[mb_xy - mb_stride] ==
MV_FROZEN)
495 if (mb_y + 1 < mb_height && fixed[mb_xy + mb_stride] ==
MV_FROZEN)
501 if (mb_x > 0 && fixed[mb_xy - 1 ] ==
MV_CHANGED)
503 if (mb_x + 1 < mb_width && fixed[mb_xy + 1 ] ==
MV_CHANGED)
505 if (mb_y > 0 && fixed[mb_xy - mb_stride] ==
MV_CHANGED)
507 if (mb_y + 1 < mb_height && fixed[mb_xy + mb_stride] ==
MV_CHANGED)
509 if (j == 0 && pass > 1)
514 if (mb_x > 0 && fixed[mb_xy - 1]) {
515 mv_predictor[pred_count][0] =
517 mv_predictor[pred_count][1] =
523 if (mb_x + 1 < mb_width && fixed[mb_xy + 1]) {
524 mv_predictor[pred_count][0] =
526 mv_predictor[pred_count][1] =
532 if (mb_y > 0 && fixed[mb_xy - mb_stride]) {
533 mv_predictor[pred_count][0] =
535 mv_predictor[pred_count][1] =
541 if (mb_y + 1<mb_height && fixed[mb_xy + mb_stride]) {
542 mv_predictor[pred_count][0] =
544 mv_predictor[pred_count][1] =
553 if (pred_count > 1) {
554 int sum_x = 0, sum_y = 0, sum_r = 0;
555 int max_x, max_y, min_x, min_y, max_r, min_r;
557 for (j = 0; j < pred_count; j++) {
558 sum_x += mv_predictor[j][0];
559 sum_y += mv_predictor[j][1];
561 if (j && ref[j] != ref[j - 1])
562 goto skip_mean_and_median;
566 mv_predictor[pred_count][0] = sum_x / j;
567 mv_predictor[pred_count][1] = sum_y / j;
568 ref[pred_count] = sum_r / j;
571 if (pred_count >= 3) {
572 min_y = min_x = min_r = 99999;
573 max_y = max_x = max_r = -99999;
575 min_x = min_y = max_x = max_y = min_r = max_r = 0;
577 for (j = 0; j < pred_count; j++) {
578 max_x =
FFMAX(max_x, mv_predictor[j][0]);
579 max_y =
FFMAX(max_y, mv_predictor[j][1]);
580 max_r =
FFMAX(max_r, ref[j]);
581 min_x =
FFMIN(min_x, mv_predictor[j][0]);
582 min_y =
FFMIN(min_y, mv_predictor[j][1]);
583 min_r =
FFMIN(min_r, ref[j]);
585 mv_predictor[pred_count + 1][0] = sum_x - max_x - min_x;
586 mv_predictor[pred_count + 1][1] = sum_y - max_y - min_y;
587 ref[pred_count + 1] = sum_r - max_r - min_r;
589 if (pred_count == 4) {
590 mv_predictor[pred_count + 1][0] /= 2;
591 mv_predictor[pred_count + 1][1] /= 2;
592 ref[pred_count + 1] /= 2;
597 skip_mean_and_median:
621 mv_predictor[pred_count][0] = prev_x;
622 mv_predictor[pred_count][1] = prev_y;
623 ref[pred_count] = prev_ref;
637 for (j = 0; j < pred_count; j++) {
640 mb_x * 16 + mb_y * 16 * s->
linesize;
643 s->
mv[0][0][0] = mv_predictor[j][0];
645 s->
mv[0][0][1] = mv_predictor[j][1];
653 if (mb_x > 0 && fixed[mb_xy - 1]) {
655 for (k = 0; k < 16; k++)
659 if (mb_x + 1 < mb_width && fixed[mb_xy + 1]) {
661 for (k = 0; k < 16; k++)
665 if (mb_y > 0 && fixed[mb_xy - mb_stride]) {
667 for (k = 0; k < 16; k++)
670 if (mb_y + 1 < mb_height && fixed[mb_xy + mb_stride]) {
672 for (k = 0; k < 16; k++)
677 if (score <= best_score) {
682 score_sum += best_score;
683 s->
mv[0][0][0] = mv_predictor[best_pred][0];
684 s->
mv[0][0][1] = mv_predictor[best_pred][1];
686 for (i = 0; i < mot_step; i++)
687 for (j = 0; j < mot_step; j++) {
695 if (s->
mv[0][0][0] != prev_x || s->
mv[0][0][1] != prev_y) {
707 for (i = 0; i < s->
mb_num; i++) {
717 int is_intra_likely, i, j, undamaged_count, skip_amount, mb_x, mb_y;
723 for (i = 0; i < s->
mb_num; i++) {
737 if (undamaged_count < 5)
746 skip_amount =
FFMAX(undamaged_count / 50, 1);
750 for (mb_y = 0; mb_y < s->
mb_height - 1; mb_y++) {
751 for (mb_x = 0; mb_x < s->
mb_width; mb_x++) {
753 const int mb_xy = mb_x + mb_y * s->
mb_stride;
761 if ((j % skip_amount) != 0)
766 mb_x * 16 + mb_y * 16 * s->
linesize;
768 mb_x * 16 + mb_y * 16 * s->
linesize;
776 is_intra_likely += s->
dsp.
sad[0](
NULL, last_mb_ptr, mb_ptr,
778 is_intra_likely -= s->
dsp.
sad[0](
NULL, last_mb_ptr,
789 return is_intra_likely > 0;
811 int endx,
int endy,
int status)
813 const int start_i = av_clip(startx + starty * s->
mb_width, 0, s->
mb_num - 1);
814 const int end_i = av_clip(endx + endy * s->
mb_width, 0, s->
mb_num);
822 if (start_i > end_i || start_xy > end_xy) {
824 "internal error, slice end before start\n");
852 (end_xy - start_xy) *
sizeof(
uint8_t));
855 for (i = start_xy; i < end_xy; i++)
880 int i, mb_x, mb_y, error, error_type, dc_error, mv_error, ac_error;
882 int threshold_part[4] = { 100, 100, 100 };
908 for (i = 0; i < 2; i++) {
918 for (mb_y = 0; mb_y < s->
mb_height; mb_y++) {
919 for (mb_x = 0; mb_x < s->
mb_width; mb_x++) {
929 for (error_type = 1; error_type <= 3; error_type++) {
932 for (i = s->
mb_num - 1; i >= 0; i--) {
936 if (error & (1 << error_type))
938 if (error & (8 << error_type))
953 for (i = s->
mb_num - 1; i >= 0; i--) {
1000 for (error_type = 1; error_type <= 3; error_type++) {
1001 for (i = s->
mb_num - 1; i >= 0; i--) {
1007 if (error & (1 << error_type))
1011 if (distance < threshold_part[error_type - 1])
1014 if (distance < threshold)
1025 for (i = 0; i < s->
mb_num; i++) {
1039 for (i = 0; i < s->
mb_num; i++) {
1048 dc_error = ac_error = mv_error = 0;
1049 for (i = 0; i < s->
mb_num; i++) {
1060 dc_error, ac_error, mv_error);
1065 for (i = 0; i < s->
mb_num; i++) {
1071 if (is_intra_likely)
1079 for (i = 0; i < s->
mb_num; i++) {
1086 for (mb_y = 0; mb_y < s->
mb_height; mb_y++) {
1090 for (mb_x = 0; mb_x < s->
mb_width; mb_x++) {
1091 const int mb_xy = mb_x + mb_y * s->
mb_stride;
1110 int mb_index = mb_x * 2 + mb_y * 2 * s->
b8_stride;
1113 for (j = 0; j < 4; j++) {
1133 for (mb_y = 0; mb_y < s->
mb_height; mb_y++) {
1137 for (mb_x = 0; mb_x < s->
mb_width; mb_x++) {
1138 int xy = mb_x * 2 + mb_y * 2 * s->
b8_stride;
1139 const int mb_xy = mb_x + mb_y * s->
mb_stride;
1195 for (mb_y = 0; mb_y < s->
mb_height; mb_y++) {
1196 for (mb_x = 0; mb_x < s->
mb_width; mb_x++) {
1197 int dc, dcu, dcv, y, n;
1199 uint8_t *dest_y, *dest_cb, *dest_cr;
1200 const int mb_xy = mb_x + mb_y * s->
mb_stride;
1215 for (n = 0; n < 4; n++) {
1217 for (y = 0; y < 8; y++) {
1219 for (x = 0; x < 8; x++)
1220 dc += dest_y[x + (n & 1) * 8 +
1223 dc_ptr[(n & 1) + (n >> 1) * s->
b8_stride] = (dc + 4) >> 3;
1227 for (y = 0; y < 8; y++) {
1229 for (x = 0; x < 8; x++) {
1248 for (mb_y = 0; mb_y < s->
mb_height; mb_y++) {
1249 for (mb_x = 0; mb_x < s->
mb_width; mb_x++) {
1250 uint8_t *dest_y, *dest_cb, *dest_cr;
1251 const int mb_xy = mb_x + mb_y * s->
mb_stride;
1265 put_dc(s, dest_y, dest_cb, dest_cr, mb_x, mb_y);
1289 for (i = 0; i < s->
mb_num; i++) {
static void guess_dc(MpegEncContext *s, int16_t *dc, int w, int h, int stride, int is_luma)
guess the dc of blocks which do not have an undamaged dc
const struct AVCodec * codec
void ff_init_block_index(MpegEncContext *s)
static void h_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int stride, int is_luma)
simple horizontal deblocking filter used for error resilience
#define VP_START
current MB is the first after a resync marker
static void filter181(int16_t *data, int width, int height, int stride)
#define CODEC_CAP_HWACCEL_VDPAU
int16_t(*[2] motion_val_base)[2]
static void decode_mb(MpegEncContext *s, int ref)
int16_t mv_cache[2][5 *8][2]
Motion vector cache.
int mb_num
number of MBs of a picture
static av_always_inline uint32_t pack16to32(int a, int b)
struct AVHWAccel * hwaccel
Hardware accelerator in use.
Picture ref_list[2][48]
0..15: frame refs, 16..47: mbaff field refs.
uint8_t motion_subsample_log2
log2 of the size of the block which a single vector in motion_val represents: (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)
unsigned int ref_count[2]
num_ref_idx_l0/1_active_minus1 + 1
Picture current_picture
copy of the current picture structure.
uint16_t pp_time
time distance between the last 2 p,s,i frames
int mb_height
number of MBs horizontally & vertically
static void ff_update_block_index(MpegEncContext *s)
uint8_t * error_status_table
table of the error status of each MB
H.264 / AVC / MPEG4 part10 codec.
int16_t * dc_val[3]
used for mpeg4 DC prediction, all 3 arrays must be continuous
Multithreading support functions.
static const uint16_t mask[17]
int mb_skipped
MUST BE SET only during DECODING.
void ff_h264_hl_decode_mb(H264Context *h)
int partitioned_frame
is current frame partitioned
int error_concealment
error concealment flags
int capabilities
Codec capabilities.
void av_log(void *avcl, int level, const char *fmt,...)
int quarter_sample
1->qpel, 0->half pel ME/MC
static const uint8_t scan8[16 *3+3]
static float distance(float x, float y, int band)
static void put_dc(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int mb_x, int mb_y)
Replace the current MB with a flat dc-only version.
useful rectangle filling function
void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int endy, int status)
Add a slice.
uint8_t * mbskip_table
used to avoid copy if macroblock skipped (for black regions for example) and used for b-frame encodin...
Picture * current_picture_ptr
pointer to the current picture
static void set_mv_strides(MpegEncContext *s, int *mv_step, int *stride)
static void fill_rectangle(SDL_Surface *screen, int x, int y, int w, int h, int color)
void ff_er_frame_end(MpegEncContext *s)
int skip_top
Number of macroblock rows at the top which are skipped.
uint8_t * mbintra_table
used to avoid setting {ac, dc, cbp}-pred stuff to zero on inter MB decoding
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
int xvmc_acceleration
XVideo Motion Acceleration.
int * mb_index2xy
mb_index -> mb_x + mb_y*mb_stride
uint32_t * mb_type
macroblock type table mb_type_base + mb_width + 2
#define MV_TYPE_16X16
1 vector for the whole mb
void ff_thread_await_progress(AVFrame *f, int n, int field)
Wait for earlier decoding threads to finish reference pictures.
int linesize[AV_NUM_DATA_POINTERS]
Size, in bytes, of the data for each picture/channel plane.
int16_t(*[2] motion_val)[2]
motion vector table
static void guess_mv(MpegEncContext *s)
#define CONFIG_H264_DECODER
void ff_er_frame_start(MpegEncContext *s)
int8_t * ref_index[2]
motion reference frame index the order in which these are stored can depend on the codec...
DSPContext dsp
pointers for accelerated dsp functions
static void v_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int stride, int is_luma)
simple vertical deblocking filter used for error resilience
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
DCTELEM(* block)[64]
points to one of the following blocks
int skip_bottom
Number of macroblock rows at the bottom which are skipped.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int mv[2][4][2]
motion vectors for a macroblock first coordinate : 0 = forward 1 = backward second " : depend...
int b8_stride
2*mb_width+1 used for some 8x8 block arrays to allow simple addressing
void(* clear_blocks)(DCTELEM *blocks)
Picture * next_picture_ptr
pointer to the next picture (for bidir pred)
struct AVCodecContext * avctx
int mb_stride
mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 ...
Picture last_picture
copy of the previous picture structure.
Picture * last_picture_ptr
pointer to the previous picture.
static const uint8_t color[]
void ff_MPV_decode_mb(MpegEncContext *s, DCTELEM block[12][64])
uint8_t non_zero_count_cache[15 *8]
non zero coeff count cache.
Picture next_picture
copy of the next picture structure.
int linesize
line size, in bytes, may be different from width
static int is_intra_more_likely(MpegEncContext *s)
#define MV_TYPE_8X8
4 vectors (h263, mpeg4 4MV)
#define CONFIG_MPEG_XVMC_DECODER
int uvlinesize
line size, for chroma in bytes, may be different from width
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
uint16_t pb_time
time distance between the last b and p,s,i frame
int8_t ref_cache[2][5 *8]
if(!(ptr_align%ac->ptr_align)&&samples_align >=aligned_len)