25 #include "config_components.h"
92 if (!
s->context_initialized) {
95 memcpy(
s, s1,
sizeof(*
s));
97 s->context_initialized = 0;
98 s->context_reinit = 0;
108 if (
s->height != s1->
height ||
s->width != s1->
width ||
s->context_reinit) {
158 if (!
s->context_initialized)
167 if ((
s->width ||
s->height) &&
181 memset(
s->thread_context, 0,
sizeof(
s->thread_context));
182 s->thread_context[0] =
s;
184 if (
s->width &&
s->height) {
189 s->context_reinit = 0;
194 s->context_reinit = 1;
235 av_assert1(
s->mb_width ==
s->buffer_pools.alloc_mb_width);
236 av_assert1(
s->mb_height ==
s->buffer_pools.alloc_mb_height ||
237 FFALIGN(
s->mb_height, 2) ==
s->buffer_pools.alloc_mb_height);
238 av_assert1(
s->mb_stride ==
s->buffer_pools.alloc_mb_stride);
240 &
s->buffer_pools,
s->mb_height);
267 int h_chroma_shift, v_chroma_shift;
269 for (
int i = 0;
i <
frame->height;
i++)
288 av_assert1(!
s->last_pic.ptr ||
s->last_pic.ptr->f->buf[0]);
289 av_assert1(!
s->next_pic.ptr ||
s->next_pic.ptr->f->buf[0]);
293 "allocating dummy last picture for B frame\n");
297 "warning: first frame is no keyframe\n");
317 s->last_pic.ptr->f->buf[0]));
345 (!
s->progressive_frame && !
s->progressive_sequence);
346 s->cur_pic.ptr->field_picture =
s->picture_structure !=
PICT_FRAME;
348 s->cur_pic.ptr->f->pict_type =
s->pict_type;
359 ff_dlog(
s->avctx,
"L%p N%p C%p L%p N%p C%p type:%d drop:%d\n",
360 (
void*)
s->last_pic.ptr, (
void*)
s->next_pic.ptr, (
void*)
s->cur_pic.ptr,
361 s->last_pic.ptr ?
s->last_pic.ptr->f->data[0] :
NULL,
362 s->next_pic.ptr ?
s->next_pic.ptr->f->data[0] :
NULL,
363 s->cur_pic.ptr ?
s->cur_pic.ptr->f->data[0] :
NULL,
364 s->pict_type,
s->droppable);
381 if (
s->cur_pic.reference)
406 for (
unsigned y = 0; y < p->
mb_height; y++)
407 for (
unsigned x = 0; x < p->
mb_width; x++) {
408 const unsigned int block_idx = y * p->
mb_width + x;
409 const unsigned int mb_xy = y * p->
mb_stride + x;
426 s->last_pic.ptr ?
s->last_pic.ptr->f :
NULL,
427 y,
h,
s->picture_structure,
428 s->first_field,
s->low_delay);
439 s->mb_x =
s->mb_y = 0;
452 uint8_t *
dest,
const uint8_t *
src,
454 int src_x,
int src_y,
458 int motion_x,
int motion_y)
460 const int lowres =
s->avctx->lowres;
461 const int op_index =
lowres;
462 const int s_mask = (2 <<
lowres) - 1;
468 if (
s->quarter_sample) {
473 sx = motion_x & s_mask;
474 sy = motion_y & s_mask;
475 src_x += motion_x >>
lowres + 1;
476 src_y += motion_y >>
lowres + 1;
482 s->vdsp.emulated_edge_mc(
s->sc.edge_emu_buffer,
src,
483 s->linesize,
s->linesize,
484 w + 1, (
h + 1) << field_based,
485 src_x, src_y * (1 << field_based),
487 src =
s->sc.edge_emu_buffer;
507 uint8_t *
const *ref_picture,
509 int motion_x,
int motion_y,
512 const uint8_t *ptr_y, *ptr_cb, *ptr_cr;
513 int mx,
my, src_x, src_y, uvsrc_x, uvsrc_y, sx, sy, uvsx, uvsy;
515 const int lowres =
s->avctx->lowres;
516 const int op_index =
lowres - 1 +
s->chroma_x_shift;
517 const int block_s = 8 >>
lowres;
518 const int s_mask = (2 <<
lowres) - 1;
521 int hc =
s->chroma_y_shift ? (
h+1-bottom_field)>>1 :
h;
525 linesize =
s->cur_pic.linesize[0] << field_based;
526 uvlinesize =
s->cur_pic.linesize[1] << field_based;
529 if (
s->quarter_sample) {
538 sx = motion_x & s_mask;
539 sy = motion_y & s_mask;
540 src_x =
s->mb_x * 2 * block_s + (motion_x >>
lowres + 1);
541 src_y = (
mb_y * 2 * block_s >> field_based) + (motion_y >>
lowres + 1);
544 uvsx = ((motion_x >> 1) & s_mask) | (sx & 1);
545 uvsy = ((motion_y >> 1) & s_mask) | (sy & 1);
546 uvsrc_x = src_x >> 1;
547 uvsrc_y = src_y >> 1;
552 uvsx = (2 *
mx) & s_mask;
553 uvsy = (2 *
my) & s_mask;
554 uvsrc_x =
s->mb_x * block_s + (
mx >>
lowres);
557 if (
s->chroma_y_shift) {
562 uvsrc_x =
s->mb_x * block_s + (
mx >>
lowres + 1);
563 uvsrc_y = (
mb_y * block_s >> field_based) + (
my >>
lowres + 1);
565 if (
s->chroma_x_shift) {
569 uvsy = motion_y & s_mask;
571 uvsrc_x =
s->mb_x*block_s + (
mx >> (
lowres+1));
574 uvsx = motion_x & s_mask;
575 uvsy = motion_y & s_mask;
582 ptr_y = ref_picture[0] + src_y *
linesize + src_x;
583 ptr_cb = ref_picture[1] + uvsrc_y *
uvlinesize + uvsrc_x;
584 ptr_cr = ref_picture[2] + uvsrc_y *
uvlinesize + uvsrc_x;
586 if ((
unsigned) src_x >
FFMAX(
h_edge_pos - (!!sx) - 2 * block_s, 0) || uvsrc_y<0 ||
588 s->vdsp.emulated_edge_mc(
s->sc.edge_emu_buffer, ptr_y,
590 17, 17 + field_based,
591 src_x, src_y * (1 << field_based),
h_edge_pos,
593 ptr_y =
s->sc.edge_emu_buffer;
595 uint8_t *ubuf =
s->sc.edge_emu_buffer + 18 *
s->linesize;
596 uint8_t *vbuf =ubuf + 10 *
s->uvlinesize;
598 vbuf -=
s->uvlinesize;
599 s->vdsp.emulated_edge_mc(ubuf, ptr_cb,
602 uvsrc_x, uvsrc_y * (1 << field_based),
604 s->vdsp.emulated_edge_mc(vbuf, ptr_cr,
607 uvsrc_x, uvsrc_y * (1 << field_based),
616 dest_y +=
s->linesize;
617 dest_cb +=
s->uvlinesize;
618 dest_cr +=
s->uvlinesize;
622 ptr_y +=
s->linesize;
623 ptr_cb +=
s->uvlinesize;
624 ptr_cr +=
s->uvlinesize;
632 uvsx = (uvsx << 2) >>
lowres;
633 uvsy = (uvsy << 2) >>
lowres;
635 pix_op[op_index](dest_cb, ptr_cb,
uvlinesize, hc, uvsx, uvsy);
636 pix_op[op_index](dest_cr, ptr_cr,
uvlinesize, hc, uvsx, uvsy);
643 uint8_t *dest_cb, uint8_t *dest_cr,
644 uint8_t *
const *ref_picture,
648 const int lowres =
s->avctx->lowres;
649 const int op_index =
lowres;
650 const int block_s = 8 >>
lowres;
651 const int s_mask = (2 <<
lowres) - 1;
654 int emu = 0, src_x, src_y, sx, sy;
660 if (
s->quarter_sample) {
672 src_x =
s->mb_x * block_s + (
mx >>
lowres + 1);
673 src_y =
s->mb_y * block_s + (
my >>
lowres + 1);
675 offset = src_y *
s->uvlinesize + src_x;
676 ptr = ref_picture[1] +
offset;
679 s->vdsp.emulated_edge_mc(
s->sc.edge_emu_buffer, ptr,
680 s->uvlinesize,
s->uvlinesize,
683 ptr =
s->sc.edge_emu_buffer;
688 pix_op[op_index](dest_cb, ptr,
s->uvlinesize, block_s, sx, sy);
690 ptr = ref_picture[2] +
offset;
692 s->vdsp.emulated_edge_mc(
s->sc.edge_emu_buffer, ptr,
693 s->uvlinesize,
s->uvlinesize,
696 ptr =
s->sc.edge_emu_buffer;
698 pix_op[op_index](dest_cr, ptr,
s->uvlinesize, block_s, sx, sy);
713 uint8_t *dest_y, uint8_t *dest_cb,
715 int dir, uint8_t *
const *ref_picture,
720 const int lowres =
s->avctx->lowres;
721 const int block_s = 8 >>
lowres;
726 switch (
s->mv_type) {
731 s->mv[dir][0][0],
s->mv[dir][0][1],
737 for (
int i = 0;
i < 4;
i++) {
739 s->linesize) * block_s,
740 ref_picture[0], 0, 0,
741 (2 *
mb_x + (
i & 1)) * block_s,
742 (2 *
mb_y + (
i >> 1)) * block_s,
743 s->width,
s->height,
s->linesize,
745 block_s, block_s, pix_op,
746 s->mv[dir][
i][0],
s->mv[dir][
i][1]);
748 mx +=
s->mv[dir][
i][0];
749 my +=
s->mv[dir][
i][1];
760 1, 0,
s->field_select[dir][0],
762 s->mv[dir][0][0],
s->mv[dir][0][1],
766 1, 1,
s->field_select[dir][1],
768 s->mv[dir][1][0],
s->mv[dir][1][1],
771 if (
s->picture_structure !=
s->field_select[dir][0] + 1 &&
773 ref_picture =
s->cur_pic.ptr->f->data;
776 0, 0,
s->field_select[dir][0],
779 s->mv[dir][0][1], 2 * block_s,
mb_y >> 1);
783 for (
int i = 0;
i < 2;
i++) {
784 uint8_t *
const *ref2picture;
786 if (
s->picture_structure ==
s->field_select[dir][
i] + 1 ||
788 ref2picture = ref_picture;
790 ref2picture =
s->cur_pic.ptr->f->data;
794 0, 0,
s->field_select[dir][
i],
796 s->mv[dir][
i][0],
s->mv[dir][
i][1] +
797 2 * block_s *
i, block_s,
mb_y >> 1);
799 dest_y += 2 * block_s *
s->linesize;
800 dest_cb += (2 * block_s >>
s->chroma_y_shift) *
s->uvlinesize;
801 dest_cr += (2 * block_s >>
s->chroma_y_shift) *
s->uvlinesize;
806 for (
int i = 0;
i < 2;
i++) {
807 for (
int j = 0; j < 2; j++) {
811 s->mv[dir][2 *
i + j][0],
812 s->mv[dir][2 *
i + j][1],
815 pix_op =
s->h264chroma.avg_h264_chroma_pixels_tab;
818 for (
int i = 0;
i < 2;
i++) {
820 0, 0,
s->picture_structure !=
i + 1,
822 s->mv[dir][2 *
i][0],
s->mv[dir][2 *
i][1],
823 2 * block_s,
mb_y >> 1);
826 pix_op =
s->h264chroma.avg_h264_chroma_pixels_tab;
830 if (!
s->first_field) {
831 ref_picture =
s->cur_pic.ptr->f->data;
846 int my_max = INT_MIN, my_min = INT_MAX, qpel_shift = !
s->quarter_sample;
852 switch (
s->mv_type) {
866 for (
int i = 0;
i < mvs;
i++) {
867 int my =
s->mv[dir][
i][1];
872 off = ((
FFMAX(-my_min, my_max) << qpel_shift) + 63) >> 6;
874 return av_clip(
s->mb_y + off, 0,
s->mb_height - 1);
876 return s->mb_height - 1;
881 int16_t *
block,
int i, uint8_t *
dest,
int line_size)
883 if (
s->block_last_index[
i] >= 0) {
899 if (
s->block_last_index[
i] >= 0) {
906 #define NOT_MPEG12_H261 0
907 #define MAY_BE_MPEG12_H261 1
908 #define DEFINITELY_MPEG12_H261 2
921 int lowres_flag,
int is_mpeg12)
923 #define IS_MPEG12_H261(s) (is_mpeg12 == MAY_BE_MPEG12_H261 ? ((s)->out_format <= FMT_H261) : is_mpeg12)
924 uint8_t *dest_y =
s->dest[0], *dest_cb =
s->dest[1], *dest_cr =
s->dest[2];
925 int dct_linesize, dct_offset;
926 const int linesize =
s->cur_pic.linesize[0];
928 const int block_size = lowres_flag ? 8 >>
s->avctx->lowres : 8;
930 dct_linesize =
linesize <<
s->interlaced_dct;
952 op_pix =
s->h264chroma.avg_h264_chroma_pixels_tab;
962 op_pix =
s->hdsp.put_pixels_tab;
963 op_qpix =
s->qdsp.put_qpel_pixels_tab;
965 op_pix =
s->hdsp.put_no_rnd_pixels_tab;
966 op_qpix =
s->qdsp.put_no_rnd_qpel_pixels_tab;
969 ff_mpv_motion(
s, dest_y, dest_cb, dest_cr, 0,
s->last_pic.data, op_pix, op_qpix);
970 op_pix =
s->hdsp.avg_pixels_tab;
971 op_qpix =
s->qdsp.avg_qpel_pixels_tab;
974 ff_mpv_motion(
s, dest_y, dest_cb, dest_cr, 1,
s->next_pic.data, op_pix, op_qpix);
979 if (
s->avctx->skip_idct) {
1002 add_dct(
s,
block[2], 2, dest_y + dct_offset , dct_linesize);
1003 add_dct(
s,
block[3], 3, dest_y + dct_offset + block_size, dct_linesize);
1006 if (
s->chroma_y_shift) {
1016 add_dct(
s,
block[6], 6, dest_cb + dct_offset, dct_linesize);
1017 add_dct(
s,
block[7], 7, dest_cr + dct_offset, dct_linesize);
1018 if (!
s->chroma_x_shift) {
1019 add_dct(
s,
block[8], 8, dest_cb + block_size, dct_linesize);
1020 add_dct(
s,
block[9], 9, dest_cr + block_size, dct_linesize);
1021 add_dct(
s,
block[10], 10, dest_cb + block_size + dct_offset, dct_linesize);
1022 add_dct(
s,
block[11], 11, dest_cr + block_size + dct_offset, dct_linesize);
1026 }
else if (CONFIG_WMV2_DECODER) {
1034 s->avctx->bits_per_raw_sample > 8) {
1040 put_dct(
s,
block[1], 1, dest_y + block_size, dct_linesize,
s->qscale);
1041 put_dct(
s,
block[2], 2, dest_y + dct_offset , dct_linesize,
s->qscale);
1042 put_dct(
s,
block[3], 3, dest_y + dct_offset + block_size, dct_linesize,
s->qscale);
1045 if (
s->chroma_y_shift) {
1051 put_dct(
s,
block[4], 4, dest_cb, dct_linesize,
s->chroma_qscale);
1052 put_dct(
s,
block[5], 5, dest_cr, dct_linesize,
s->chroma_qscale);
1053 put_dct(
s,
block[6], 6, dest_cb + dct_offset, dct_linesize,
s->chroma_qscale);
1054 put_dct(
s,
block[7], 7, dest_cr + dct_offset, dct_linesize,
s->chroma_qscale);
1058 s->idsp.idct_put(dest_y, dct_linesize,
block[0]);
1059 s->idsp.idct_put(dest_y + block_size, dct_linesize,
block[1]);
1060 s->idsp.idct_put(dest_y + dct_offset, dct_linesize,
block[2]);
1061 s->idsp.idct_put(dest_y + dct_offset + block_size, dct_linesize,
block[3]);
1064 if (
s->chroma_y_shift) {
1071 s->idsp.idct_put(dest_cb, dct_linesize,
block[4]);
1072 s->idsp.idct_put(dest_cr, dct_linesize,
block[5]);
1073 s->idsp.idct_put(dest_cb + dct_offset, dct_linesize,
block[6]);
1074 s->idsp.idct_put(dest_cr + dct_offset, dct_linesize,
block[7]);
1075 if (!
s->chroma_x_shift) {
1076 s->idsp.idct_put(dest_cb + block_size, dct_linesize,
block[8]);
1077 s->idsp.idct_put(dest_cr + block_size, dct_linesize,
block[9]);
1078 s->idsp.idct_put(dest_cb + block_size + dct_offset, dct_linesize,
block[10]);
1079 s->idsp.idct_put(dest_cr + block_size + dct_offset, dct_linesize,
block[11]);
1089 const int mb_xy =
s->mb_y *
s->mb_stride +
s->mb_x;
1090 uint8_t *mbskip_ptr = &
s->mbskip_table[mb_xy];
1092 s->cur_pic.qscale_table[mb_xy] =
s->qscale;
1095 if (
s->mb_skipped) {
1099 }
else if (!
s->cur_pic.reference) {
1108 for (
int i = 0;
i < 6;
i++) {
1109 for (
int j = 0; j < 64; j++) {
1111 block[
i][
s->idsp.idct_permutation[j]]);
1118 if (!
s->avctx->lowres) {