History

avcodec/mpv_reconstruct_mb_template: Merge template into its users

A large part of this template is decoder-only. This makes the complexity of the IS_ENCODER-checks not worth it. So simply merge the template into both its users.

Andreas Rheinhardt committed 2 years ago

Commit b05ec7f1 parent fc64b2e3 files · +294 −277Browse files

Unified · Split

3 files
  1. libavcodec/mpegvideo_dec.c +216 −2
  2. libavcodec/mpegvideo_enc.c +78 −3
  3. libavcodec/mpv_reconstruct_mb_template.c +0 −272
libavcodec/mpegvideo_dec.c+216−2
@@ -904,11 +904,225 @@ static inline void add_dct(MpegEncContext *s, · 903 unmodified lines
904 }904 }
905}905}
906 906
907#define IS_ENCODER 0907/* put block[] to dest[] */
908#include "mpv_reconstruct_mb_template.c"908static inline void put_dct(MpegEncContext *s,
909 int16_t *block, int i, uint8_t *dest, int line_size, int qscale)
910{
911 s->dct_unquantize_intra(s, block, i, qscale);
912 s->idsp.idct_put(dest, line_size, block);
913}
914
915static inline void add_dequant_dct(MpegEncContext *s,
916 int16_t *block, int i, uint8_t *dest, int line_size, int qscale)
917{
918 if (s->block_last_index[i] >= 0) {
919 s->dct_unquantize_inter(s, block, i, qscale);
920
921 s->idsp.idct_add(dest, line_size, block);
922 }
923}
924
925#define NOT_MPEG12_H261 0
926#define MAY_BE_MPEG12_H261 1
927#define DEFINITELY_MPEG12_H261 2
928
929/* generic function called after a macroblock has been parsed by the decoder.
930
931 Important variables used:
932 s->mb_intra : true if intra macroblock
933 s->mv_dir : motion vector direction
934 s->mv_type : motion vector type
935 s->mv : motion vector
936 s->interlaced_dct : true if interlaced dct used (mpeg2)
937 */
938static av_always_inline
939void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
940 int lowres_flag, int is_mpeg12)
941{
942#define IS_MPEG12_H261(s) (is_mpeg12 == MAY_BE_MPEG12_H261 ? ((s)->out_format <= FMT_H261) : is_mpeg12)
943 {
944 uint8_t *dest_y = s->dest[0], *dest_cb = s->dest[1], *dest_cr = s->dest[2];
945 int dct_linesize, dct_offset;
946 const int linesize = s->cur_pic.linesize[0]; //not s->linesize as this would be wrong for field pics
947 const int uvlinesize = s->cur_pic.linesize[1];
948 const int block_size = lowres_flag ? 8 >> s->avctx->lowres : 8;
949
950 dct_linesize = linesize << s->interlaced_dct;
951 dct_offset = s->interlaced_dct ? linesize : linesize * block_size;
952
953 if (!s->mb_intra) {
954 /* motion handling */
955 if (HAVE_THREADS && is_mpeg12 != DEFINITELY_MPEG12_H261 &&
956 s->avctx->active_thread_type & FF_THREAD_FRAME) {
957 if (s->mv_dir & MV_DIR_FORWARD) {
958 ff_thread_progress_await(&s->last_pic.ptr->progress,
959 lowest_referenced_row(s, 0));
960 }
961 if (s->mv_dir & MV_DIR_BACKWARD) {
962 ff_thread_progress_await(&s->next_pic.ptr->progress,
963 lowest_referenced_row(s, 1));
964 }
965 }
966
967 if (lowres_flag) {
968 const h264_chroma_mc_func *op_pix = s->h264chroma.put_h264_chroma_pixels_tab;
969
970 if (s->mv_dir & MV_DIR_FORWARD) {
971 MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, s->last_pic.data, op_pix);
972 op_pix = s->h264chroma.avg_h264_chroma_pixels_tab;
973 }
974 if (s->mv_dir & MV_DIR_BACKWARD) {
975 MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 1, s->next_pic.data, op_pix);
976 }
977 } else {
978 const op_pixels_func (*op_pix)[4];
979 const qpel_mc_func (*op_qpix)[16];
980
981 if ((is_mpeg12 == DEFINITELY_MPEG12_H261 || !s->no_rounding) || s->pict_type == AV_PICTURE_TYPE_B) {
982 op_pix = s->hdsp.put_pixels_tab;
983 op_qpix = s->qdsp.put_qpel_pixels_tab;
984 } else {
985 op_pix = s->hdsp.put_no_rnd_pixels_tab;
986 op_qpix = s->qdsp.put_no_rnd_qpel_pixels_tab;
987 }
988 if (s->mv_dir & MV_DIR_FORWARD) {
989 ff_mpv_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_pic.data, op_pix, op_qpix);
990 op_pix = s->hdsp.avg_pixels_tab;
991 op_qpix = s->qdsp.avg_qpel_pixels_tab;
992 }
993 if (s->mv_dir & MV_DIR_BACKWARD) {
994 ff_mpv_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_pic.data, op_pix, op_qpix);
995 }
996 }
997
998 /* skip dequant / idct if we are really late ;) */
999 if (s->avctx->skip_idct) {
1000 if( (s->avctx->skip_idct >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B)
1001 ||(s->avctx->skip_idct >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I)
1002 || s->avctx->skip_idct >= AVDISCARD_ALL)
1003 return;
1004 }
1005
1006 /* add dct residue */
1007 if (!(IS_MPEG12_H261(s) || s->msmpeg4_version != MSMP4_UNUSED ||
1008 (s->codec_id == AV_CODEC_ID_MPEG4 && !s->mpeg_quant))) {
1009 add_dequant_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale);
1010 add_dequant_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale);
1011 add_dequant_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale);
1012 add_dequant_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale);
1013
1014 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
1015 av_assert2(s->chroma_y_shift);
1016 add_dequant_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale);
1017 add_dequant_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale);
1018 }
1019 } else if (is_mpeg12 == DEFINITELY_MPEG12_H261 || lowres_flag || (s->codec_id != AV_CODEC_ID_WMV2)) {
1020 add_dct(s, block[0], 0, dest_y , dct_linesize);
1021 add_dct(s, block[1], 1, dest_y + block_size, dct_linesize);
1022 add_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize);
1023 add_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize);
1024
1025 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
1026 if (s->chroma_y_shift) {//Chroma420
1027 add_dct(s, block[4], 4, dest_cb, uvlinesize);
1028 add_dct(s, block[5], 5, dest_cr, uvlinesize);
1029 } else {
1030 //chroma422
1031 dct_linesize = uvlinesize << s->interlaced_dct;
1032 dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize*block_size;
1033
1034 add_dct(s, block[4], 4, dest_cb, dct_linesize);
1035 add_dct(s, block[5], 5, dest_cr, dct_linesize);
1036 add_dct(s, block[6], 6, dest_cb+dct_offset, dct_linesize);
1037 add_dct(s, block[7], 7, dest_cr+dct_offset, dct_linesize);
1038 if (!s->chroma_x_shift) {//Chroma444
1039 add_dct(s, block[8], 8, dest_cb+block_size, dct_linesize);
1040 add_dct(s, block[9], 9, dest_cr+block_size, dct_linesize);
1041 add_dct(s, block[10], 10, dest_cb+block_size+dct_offset, dct_linesize);
1042 add_dct(s, block[11], 11, dest_cr+block_size+dct_offset, dct_linesize);
1043 }
1044 }
1045 } //fi gray
1046 } else if (CONFIG_WMV2_DECODER) {
1047 ff_wmv2_add_mb(s, block, dest_y, dest_cb, dest_cr);
1048 }
1049 } else {
1050 /* Only MPEG-4 Simple Studio Profile is supported in > 8-bit mode.
1051 TODO: Integrate 10-bit properly into mpegvideo.c so that ER works properly */
1052 if (is_mpeg12 != DEFINITELY_MPEG12_H261 && CONFIG_MPEG4_DECODER &&
1053 /* s->codec_id == AV_CODEC_ID_MPEG4 && */
1054 s->avctx->bits_per_raw_sample > 8) {
1055 ff_mpeg4_decode_studio(s, dest_y, dest_cb, dest_cr, block_size,
1056 uvlinesize, dct_linesize, dct_offset);
1057 } else if (!IS_MPEG12_H261(s)) {
1058 /* dct only in intra block */
1059 put_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale);
1060 put_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale);
1061 put_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale);
1062 put_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale);
1063
1064 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
1065 if (s->chroma_y_shift) {
1066 put_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale);
1067 put_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale);
1068 } else {
1069 dct_offset >>=1;
1070 dct_linesize >>=1;
1071 put_dct(s, block[4], 4, dest_cb, dct_linesize, s->chroma_qscale);
1072 put_dct(s, block[5], 5, dest_cr, dct_linesize, s->chroma_qscale);
1073 put_dct(s, block[6], 6, dest_cb + dct_offset, dct_linesize, s->chroma_qscale);
1074 put_dct(s, block[7], 7, dest_cr + dct_offset, dct_linesize, s->chroma_qscale);
1075 }
1076 }
1077 } else {
1078 s->idsp.idct_put(dest_y, dct_linesize, block[0]);
1079 s->idsp.idct_put(dest_y + block_size, dct_linesize, block[1]);
1080 s->idsp.idct_put(dest_y + dct_offset, dct_linesize, block[2]);
1081 s->idsp.idct_put(dest_y + dct_offset + block_size, dct_linesize, block[3]);
1082
1083 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
1084 if (s->chroma_y_shift) {
1085 s->idsp.idct_put(dest_cb, uvlinesize, block[4]);
1086 s->idsp.idct_put(dest_cr, uvlinesize, block[5]);
1087 } else {
1088 dct_linesize = uvlinesize << s->interlaced_dct;
1089 dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize*block_size;
1090
1091 s->idsp.idct_put(dest_cb, dct_linesize, block[4]);
1092 s->idsp.idct_put(dest_cr, dct_linesize, block[5]);
1093 s->idsp.idct_put(dest_cb + dct_offset, dct_linesize, block[6]);
1094 s->idsp.idct_put(dest_cr + dct_offset, dct_linesize, block[7]);
1095 if (!s->chroma_x_shift) { //Chroma444
1096 s->idsp.idct_put(dest_cb + block_size, dct_linesize, block[8]);
1097 s->idsp.idct_put(dest_cr + block_size, dct_linesize, block[9]);
1098 s->idsp.idct_put(dest_cb + block_size + dct_offset, dct_linesize, block[10]);
1099 s->idsp.idct_put(dest_cr + block_size + dct_offset, dct_linesize, block[11]);
1100 }
1101 }
1102 } //gray
1103 }
1104 }
1105 }
1106}
909 1107
910void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])1108void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
911{1109{
1110 const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
1111 uint8_t *mbskip_ptr = &s->mbskip_table[mb_xy];
1112
1113 s->cur_pic.qscale_table[mb_xy] = s->qscale;
1114
1115 /* avoid copy if macroblock skipped in last frame too */
1116 if (s->mb_skipped) {
1117 s->mb_skipped = 0;
1118 av_assert2(s->pict_type!=AV_PICTURE_TYPE_I);
1119 *mbskip_ptr = 1;
1120 } else if (!s->cur_pic.reference) {
1121 *mbskip_ptr = 1;
1122 } else{
1123 *mbskip_ptr = 0; /* not skipped */
1124 }
1125
912 if (s->avctx->debug & FF_DEBUG_DCT_COEFF) {1126 if (s->avctx->debug & FF_DEBUG_DCT_COEFF) {
913 /* print DCT coefficients */1127 /* print DCT coefficients */
914 av_log(s->avctx, AV_LOG_DEBUG, "DCT coeffs of MB at %dx%d:\n", s->mb_x, s->mb_y);1128 av_log(s->avctx, AV_LOG_DEBUG, "DCT coeffs of MB at %dx%d:\n", s->mb_x, s->mb_y);
libavcodec/mpegvideo_enc.c+78−3
@@ -1095,11 +1095,33 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx) · 1094 unmodified lines
1095 return 0;1095 return 0;
1096}1096}
1097 1097
1098#define IS_ENCODER 11098/* put block[] to dest[] */
1099#include "mpv_reconstruct_mb_template.c"1099static inline void put_dct(MpegEncContext *s,
1100 int16_t *block, int i, uint8_t *dest, int line_size, int qscale)
1101{
1102 s->dct_unquantize_intra(s, block, i, qscale);
1103 s->idsp.idct_put(dest, line_size, block);
1104}
1100 1105
1106static inline void add_dequant_dct(MpegEncContext *s,
1107 int16_t *block, int i, uint8_t *dest, int line_size, int qscale)
1108{
1109 if (s->block_last_index[i] >= 0) {
1110 s->dct_unquantize_inter(s, block, i, qscale);
1111
1112 s->idsp.idct_add(dest, line_size, block);
1113 }
1114}
1115
1116/**
1117 * Performs dequantization and IDCT (if necessary)
1118 */
1101static void mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])1119static void mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
1102{1120{
1121 const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
1122
1123 s->cur_pic.qscale_table[mb_xy] = s->qscale;
1124
1103 if (s->avctx->debug & FF_DEBUG_DCT_COEFF) {1125 if (s->avctx->debug & FF_DEBUG_DCT_COEFF) {
1104 /* print DCT coefficients */1126 /* print DCT coefficients */
1105 av_log(s->avctx, AV_LOG_DEBUG, "DCT coeffs of MB at %dx%d:\n", s->mb_x, s->mb_y);1127 av_log(s->avctx, AV_LOG_DEBUG, "DCT coeffs of MB at %dx%d:\n", s->mb_x, s->mb_y);
@@ -1112,7 +1134,60 @@ static void mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64]) · 6 unmodified lines
1112 }1134 }
1113 }1135 }
1114 1136
1115 mpv_reconstruct_mb_internal(s, block, 0, MAY_BE_MPEG12_H261);1137 if ((s->avctx->flags & AV_CODEC_FLAG_PSNR) || s->frame_skip_threshold || s->frame_skip_factor ||
1138 !((s->intra_only || s->pict_type == AV_PICTURE_TYPE_B) &&
1139 s->avctx->mb_decision != FF_MB_DECISION_RD)) { // FIXME precalc
1140 uint8_t *dest_y = s->dest[0], *dest_cb = s->dest[1], *dest_cr = s->dest[2];
1141 int dct_linesize, dct_offset;
1142 const int linesize = s->cur_pic.linesize[0];
1143 const int uvlinesize = s->cur_pic.linesize[1];
1144 const int block_size = 8;
1145
1146 dct_linesize = linesize << s->interlaced_dct;
1147 dct_offset = s->interlaced_dct ? linesize : linesize * block_size;
1148
1149 if (!s->mb_intra) {
1150 /* No MC, as that was already done otherwise */
1151 add_dequant_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale);
1152 add_dequant_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale);
1153 add_dequant_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale);
1154 add_dequant_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale);
1155
1156 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
1157 if (s->chroma_y_shift) {
1158 add_dequant_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale);
1159 add_dequant_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale);
1160 } else {
1161 dct_linesize >>= 1;
1162 dct_offset >>= 1;
1163 add_dequant_dct(s, block[4], 4, dest_cb, dct_linesize, s->chroma_qscale);
1164 add_dequant_dct(s, block[5], 5, dest_cr, dct_linesize, s->chroma_qscale);
1165 add_dequant_dct(s, block[6], 6, dest_cb + dct_offset, dct_linesize, s->chroma_qscale);
1166 add_dequant_dct(s, block[7], 7, dest_cr + dct_offset, dct_linesize, s->chroma_qscale);
1167 }
1168 }
1169 } else {
1170 /* dct only in intra block */
1171 put_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale);
1172 put_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale);
1173 put_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale);
1174 put_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale);
1175
1176 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
1177 if (s->chroma_y_shift) {
1178 put_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale);
1179 put_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale);
1180 } else {
1181 dct_offset >>=1;
1182 dct_linesize >>=1;
1183 put_dct(s, block[4], 4, dest_cb, dct_linesize, s->chroma_qscale);
1184 put_dct(s, block[5], 5, dest_cr, dct_linesize, s->chroma_qscale);
1185 put_dct(s, block[6], 6, dest_cb + dct_offset, dct_linesize, s->chroma_qscale);
1186 put_dct(s, block[7], 7, dest_cr + dct_offset, dct_linesize, s->chroma_qscale);
1187 }
1188 }
1189 }
1190 }
1116}1191}
1117 1192
1118static int get_sae(const uint8_t *src, int ref, int stride)1193static int get_sae(const uint8_t *src, int ref, int stride)
libavcodec/mpv_reconstruct_mb_template.c+0−272
@@ -1,272 +0,0 @@
1/*
2 * MPEG macroblock reconstruction
3 * Copyright (c) 2000,2001 Fabrice Bellard
4 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#define NOT_MPEG12_H261 0
24#define MAY_BE_MPEG12_H261 1
25#define DEFINITELY_MPEG12_H261 2
26
27/* put block[] to dest[] */
28static inline void put_dct(MpegEncContext *s,
29 int16_t *block, int i, uint8_t *dest, int line_size, int qscale)
30{
31 s->dct_unquantize_intra(s, block, i, qscale);
32 s->idsp.idct_put(dest, line_size, block);
33}
34
35static inline void add_dequant_dct(MpegEncContext *s,
36 int16_t *block, int i, uint8_t *dest, int line_size, int qscale)
37{
38 if (s->block_last_index[i] >= 0) {
39 s->dct_unquantize_inter(s, block, i, qscale);
40
41 s->idsp.idct_add(dest, line_size, block);
42 }
43}
44
45/* generic function called after a macroblock has been parsed by the
46 decoder or after it has been encoded by the encoder.
47
48 Important variables used:
49 s->mb_intra : true if intra macroblock
50 s->mv_dir : motion vector direction
51 s->mv_type : motion vector type
52 s->mv : motion vector
53 s->interlaced_dct : true if interlaced dct used (mpeg2)
54 */
55static av_always_inline
56void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
57 int lowres_flag, int is_mpeg12)
58{
59#define IS_MPEG12_H261(s) (is_mpeg12 == MAY_BE_MPEG12_H261 ? ((s)->out_format <= FMT_H261) : is_mpeg12)
60 const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
61
62 s->cur_pic.qscale_table[mb_xy] = s->qscale;
63
64#if IS_ENCODER
65 if ((s->avctx->flags & AV_CODEC_FLAG_PSNR) || s->frame_skip_threshold || s->frame_skip_factor ||
66 !((s->intra_only || s->pict_type == AV_PICTURE_TYPE_B) &&
67 s->avctx->mb_decision != FF_MB_DECISION_RD)) // FIXME precalc
68#endif /* IS_ENCODER */
69 {
70 uint8_t *dest_y = s->dest[0], *dest_cb = s->dest[1], *dest_cr = s->dest[2];
71 int dct_linesize, dct_offset;
72 const int linesize = s->cur_pic.linesize[0]; //not s->linesize as this would be wrong for field pics
73 const int uvlinesize = s->cur_pic.linesize[1];
74 const int block_size = lowres_flag ? 8 >> s->avctx->lowres : 8;
75
76 /* avoid copy if macroblock skipped in last frame too */
77 /* skip only during decoding as we might trash the buffers during encoding a bit */
78 if (!IS_ENCODER) {
79 uint8_t *mbskip_ptr = &s->mbskip_table[mb_xy];
80
81 if (s->mb_skipped) {
82 s->mb_skipped = 0;
83 av_assert2(s->pict_type!=AV_PICTURE_TYPE_I);
84 *mbskip_ptr = 1;
85 } else if (!s->cur_pic.reference) {
86 *mbskip_ptr = 1;
87 } else{
88 *mbskip_ptr = 0; /* not skipped */
89 }
90 }
91
92 dct_linesize = linesize << s->interlaced_dct;
93 dct_offset = s->interlaced_dct ? linesize : linesize * block_size;
94
95 if (!s->mb_intra) {
96 /* motion handling */
97 /* decoding or more than one mb_type (MC was already done otherwise) */
98
99#if !IS_ENCODER
100 if (HAVE_THREADS && is_mpeg12 != DEFINITELY_MPEG12_H261 &&
101 s->avctx->active_thread_type & FF_THREAD_FRAME) {
102 if (s->mv_dir & MV_DIR_FORWARD) {
103 ff_thread_progress_await(&s->last_pic.ptr->progress,
104 lowest_referenced_row(s, 0));
105 }
106 if (s->mv_dir & MV_DIR_BACKWARD) {
107 ff_thread_progress_await(&s->next_pic.ptr->progress,
108 lowest_referenced_row(s, 1));
109 }
110 }
111
112 if (lowres_flag) {
113 const h264_chroma_mc_func *op_pix = s->h264chroma.put_h264_chroma_pixels_tab;
114
115 if (s->mv_dir & MV_DIR_FORWARD) {
116 MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, s->last_pic.data, op_pix);
117 op_pix = s->h264chroma.avg_h264_chroma_pixels_tab;
118 }
119 if (s->mv_dir & MV_DIR_BACKWARD) {
120 MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 1, s->next_pic.data, op_pix);
121 }
122 } else {
123 const op_pixels_func (*op_pix)[4];
124 const qpel_mc_func (*op_qpix)[16];
125
126 if ((is_mpeg12 == DEFINITELY_MPEG12_H261 || !s->no_rounding) || s->pict_type == AV_PICTURE_TYPE_B) {
127 op_pix = s->hdsp.put_pixels_tab;
128 op_qpix = s->qdsp.put_qpel_pixels_tab;
129 } else {
130 op_pix = s->hdsp.put_no_rnd_pixels_tab;
131 op_qpix = s->qdsp.put_no_rnd_qpel_pixels_tab;
132 }
133 if (s->mv_dir & MV_DIR_FORWARD) {
134 ff_mpv_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_pic.data, op_pix, op_qpix);
135 op_pix = s->hdsp.avg_pixels_tab;
136 op_qpix = s->qdsp.avg_qpel_pixels_tab;
137 }
138 if (s->mv_dir & MV_DIR_BACKWARD) {
139 ff_mpv_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_pic.data, op_pix, op_qpix);
140 }
141 }
142
143 /* skip dequant / idct if we are really late ;) */
144 if (s->avctx->skip_idct) {
145 if( (s->avctx->skip_idct >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B)
146 ||(s->avctx->skip_idct >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I)
147 || s->avctx->skip_idct >= AVDISCARD_ALL)
148 return;
149 }
150
151 /* add dct residue */
152 if (!(IS_MPEG12_H261(s) || s->msmpeg4_version != MSMP4_UNUSED ||
153 (s->codec_id == AV_CODEC_ID_MPEG4 && !s->mpeg_quant)))
154#endif /* !IS_ENCODER */
155 {
156 add_dequant_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale);
157 add_dequant_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale);
158 add_dequant_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale);
159 add_dequant_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale);
160
161 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
162 av_assert2(IS_ENCODER || s->chroma_y_shift);
163 if (!IS_ENCODER || s->chroma_y_shift) {
164 add_dequant_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale);
165 add_dequant_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale);
166 } else {
167 dct_linesize >>= 1;
168 dct_offset >>= 1;
169 add_dequant_dct(s, block[4], 4, dest_cb, dct_linesize, s->chroma_qscale);
170 add_dequant_dct(s, block[5], 5, dest_cr, dct_linesize, s->chroma_qscale);
171 add_dequant_dct(s, block[6], 6, dest_cb + dct_offset, dct_linesize, s->chroma_qscale);
172 add_dequant_dct(s, block[7], 7, dest_cr + dct_offset, dct_linesize, s->chroma_qscale);
173 }
174 }
175 }
176#if !IS_ENCODER
177 else if (is_mpeg12 == DEFINITELY_MPEG12_H261 || lowres_flag || (s->codec_id != AV_CODEC_ID_WMV2)) {
178 add_dct(s, block[0], 0, dest_y , dct_linesize);
179 add_dct(s, block[1], 1, dest_y + block_size, dct_linesize);
180 add_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize);
181 add_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize);
182
183 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
184 if (s->chroma_y_shift) {//Chroma420
185 add_dct(s, block[4], 4, dest_cb, uvlinesize);
186 add_dct(s, block[5], 5, dest_cr, uvlinesize);
187 } else {
188 //chroma422
189 dct_linesize = uvlinesize << s->interlaced_dct;
190 dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize*block_size;
191
192 add_dct(s, block[4], 4, dest_cb, dct_linesize);
193 add_dct(s, block[5], 5, dest_cr, dct_linesize);
194 add_dct(s, block[6], 6, dest_cb+dct_offset, dct_linesize);
195 add_dct(s, block[7], 7, dest_cr+dct_offset, dct_linesize);
196 if (!s->chroma_x_shift) {//Chroma444
197 add_dct(s, block[8], 8, dest_cb+block_size, dct_linesize);
198 add_dct(s, block[9], 9, dest_cr+block_size, dct_linesize);
199 add_dct(s, block[10], 10, dest_cb+block_size+dct_offset, dct_linesize);
200 add_dct(s, block[11], 11, dest_cr+block_size+dct_offset, dct_linesize);
201 }
202 }
203 } //fi gray
204 } else if (CONFIG_WMV2_DECODER) {
205 ff_wmv2_add_mb(s, block, dest_y, dest_cb, dest_cr);
206 }
207#endif /* !IS_ENCODER */
208 } else {
209#if !IS_ENCODER
210 /* Only MPEG-4 Simple Studio Profile is supported in > 8-bit mode.
211 TODO: Integrate 10-bit properly into mpegvideo.c so that ER works properly */
212 if (is_mpeg12 != DEFINITELY_MPEG12_H261 && CONFIG_MPEG4_DECODER &&
213 /* s->codec_id == AV_CODEC_ID_MPEG4 && */
214 s->avctx->bits_per_raw_sample > 8) {
215 ff_mpeg4_decode_studio(s, dest_y, dest_cb, dest_cr, block_size,
216 uvlinesize, dct_linesize, dct_offset);
217 } else if (!IS_MPEG12_H261(s))
218#endif /* !IS_ENCODER */
219 {
220 /* dct only in intra block */
221 put_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale);
222 put_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale);
223 put_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale);
224 put_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale);
225
226 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
227 if (s->chroma_y_shift) {
228 put_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale);
229 put_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale);
230 } else {
231 dct_offset >>=1;
232 dct_linesize >>=1;
233 put_dct(s, block[4], 4, dest_cb, dct_linesize, s->chroma_qscale);
234 put_dct(s, block[5], 5, dest_cr, dct_linesize, s->chroma_qscale);
235 put_dct(s, block[6], 6, dest_cb + dct_offset, dct_linesize, s->chroma_qscale);
236 put_dct(s, block[7], 7, dest_cr + dct_offset, dct_linesize, s->chroma_qscale);
237 }
238 }
239 }
240#if !IS_ENCODER
241 else {
242 s->idsp.idct_put(dest_y, dct_linesize, block[0]);
243 s->idsp.idct_put(dest_y + block_size, dct_linesize, block[1]);
244 s->idsp.idct_put(dest_y + dct_offset, dct_linesize, block[2]);
245 s->idsp.idct_put(dest_y + dct_offset + block_size, dct_linesize, block[3]);
246
247 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
248 if (s->chroma_y_shift) {
249 s->idsp.idct_put(dest_cb, uvlinesize, block[4]);
250 s->idsp.idct_put(dest_cr, uvlinesize, block[5]);
251 } else {
252 dct_linesize = uvlinesize << s->interlaced_dct;
253 dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize*block_size;
254
255 s->idsp.idct_put(dest_cb, dct_linesize, block[4]);
256 s->idsp.idct_put(dest_cr, dct_linesize, block[5]);
257 s->idsp.idct_put(dest_cb + dct_offset, dct_linesize, block[6]);
258 s->idsp.idct_put(dest_cr + dct_offset, dct_linesize, block[7]);
259 if (!s->chroma_x_shift) { //Chroma444
260 s->idsp.idct_put(dest_cb + block_size, dct_linesize, block[8]);
261 s->idsp.idct_put(dest_cr + block_size, dct_linesize, block[9]);
262 s->idsp.idct_put(dest_cb + block_size + dct_offset, dct_linesize, block[10]);
263 s->idsp.idct_put(dest_cr + block_size + dct_offset, dct_linesize, block[11]);
264 }
265 }
266 } //gray
267 }
268#endif /* !IS_ENCODER */
269 }
270 }
271}
272

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t