FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/mpv_reconstruct_mb_template.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 127 140 90.7%
Functions: 3 3 100.0%
Branches: 97 118 82.2%

Line Branch Exec Source
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[] */
28 4985312 static inline void put_dct(MpegEncContext *s,
29 int16_t *block, int i, uint8_t *dest, int line_size, int qscale)
30 {
31 4985312 s->dct_unquantize_intra(s, block, i, qscale);
32 4985312 s->idsp.idct_put(dest, line_size, block);
33 4985312 }
34
35 23159592 static inline void add_dequant_dct(MpegEncContext *s,
36 int16_t *block, int i, uint8_t *dest, int line_size, int qscale)
37 {
38
2/2
✓ Branch 0 taken 9165340 times.
✓ Branch 1 taken 13994252 times.
23159592 if (s->block_last_index[i] >= 0) {
39 9165340 s->dct_unquantize_inter(s, block, i, qscale);
40
41 9165340 s->idsp.idct_add(dest, line_size, block);
42 }
43 23159592 }
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 */
55 static av_always_inline
56 10075044 void 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 10075044 const int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
61
62 10075044 s->cur_pic.qscale_table[mb_xy] = s->qscale;
63
64 /* update DC predictors for P macroblocks */
65
2/2
✓ Branch 0 taken 8045966 times.
✓ Branch 1 taken 2029078 times.
10075044 if (!s->mb_intra) {
66
6/6
✓ Branch 0 taken 5651657 times.
✓ Branch 1 taken 2394309 times.
✓ Branch 2 taken 2286869 times.
✓ Branch 3 taken 3364788 times.
✓ Branch 4 taken 103314 times.
✓ Branch 5 taken 2183555 times.
8045966 if (is_mpeg12 != DEFINITELY_MPEG12_H261 && (s->h263_pred || s->h263_aic)) {
67
2/2
✓ Branch 0 taken 378907 times.
✓ Branch 1 taken 3089195 times.
3468102 if (s->mbintra_table[mb_xy])
68 378907 ff_clean_intra_table_entries(s);
69 } else {
70 4577864 s->last_dc[0] =
71 4577864 s->last_dc[1] =
72 4577864 s->last_dc[2] = 128 << s->intra_dc_precision;
73 }
74
6/6
✓ Branch 0 taken 1688077 times.
✓ Branch 1 taken 341001 times.
✓ Branch 2 taken 1239099 times.
✓ Branch 3 taken 448978 times.
✓ Branch 4 taken 28866 times.
✓ Branch 5 taken 1210233 times.
2029078 } else if (is_mpeg12 != DEFINITELY_MPEG12_H261 && (s->h263_pred || s->h263_aic))
75 477844 s->mbintra_table[mb_xy] = 1;
76
77 #if IS_ENCODER
78
3/6
✓ Branch 0 taken 4917932 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4917932 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4917932 times.
✗ Branch 5 not taken.
4917932 if ((s->avctx->flags & AV_CODEC_FLAG_PSNR) || s->frame_skip_threshold || s->frame_skip_factor ||
79
4/4
✓ Branch 0 taken 4049170 times.
✓ Branch 1 taken 868762 times.
✓ Branch 2 taken 1236485 times.
✓ Branch 3 taken 2812685 times.
4917932 !((s->intra_only || s->pict_type == AV_PICTURE_TYPE_B) &&
80
2/2
✓ Branch 0 taken 1019789 times.
✓ Branch 1 taken 1085458 times.
2105247 s->avctx->mb_decision != FF_MB_DECISION_RD)) // FIXME precalc
81 #endif /* IS_ENCODER */
82 {
83 8989586 uint8_t *dest_y = s->dest[0], *dest_cb = s->dest[1], *dest_cr = s->dest[2];
84 int dct_linesize, dct_offset;
85 8989586 const int linesize = s->cur_pic.linesize[0]; //not s->linesize as this would be wrong for field pics
86 8989586 const int uvlinesize = s->cur_pic.linesize[1];
87
2/2
✓ Branch 0 taken 43500 times.
✓ Branch 1 taken 8946086 times.
8989586 const int block_size = lowres_flag ? 8 >> s->avctx->lowres : 8;
88
89 /* avoid copy if macroblock skipped in last frame too */
90 /* skip only during decoding as we might trash the buffers during encoding a bit */
91 if (!IS_ENCODER) {
92 5157112 uint8_t *mbskip_ptr = &s->mbskip_table[mb_xy];
93
94
2/2
✓ Branch 0 taken 388002 times.
✓ Branch 1 taken 4769110 times.
5157112 if (s->mb_skipped) {
95 388002 s->mb_skipped = 0;
96 av_assert2(s->pict_type!=AV_PICTURE_TYPE_I);
97 388002 *mbskip_ptr = 1;
98
2/2
✓ Branch 0 taken 1128834 times.
✓ Branch 1 taken 3640276 times.
4769110 } else if (!s->cur_pic.reference) {
99 1128834 *mbskip_ptr = 1;
100 } else{
101 3640276 *mbskip_ptr = 0; /* not skipped */
102 }
103 }
104
105 8989586 dct_linesize = linesize << s->interlaced_dct;
106
2/2
✓ Branch 0 taken 8794660 times.
✓ Branch 1 taken 194926 times.
8989586 dct_offset = s->interlaced_dct ? linesize : linesize * block_size;
107
108
2/2
✓ Branch 0 taken 7829270 times.
✓ Branch 1 taken 1160316 times.
8989586 if (!s->mb_intra) {
109 /* motion handling */
110 /* decoding or more than one mb_type (MC was already done otherwise) */
111
112 #if !IS_ENCODER
113
2/2
✓ Branch 0 taken 2128292 times.
✓ Branch 1 taken 2394309 times.
4522601 if (HAVE_THREADS && is_mpeg12 != DEFINITELY_MPEG12_H261 &&
114
2/2
✓ Branch 0 taken 60133 times.
✓ Branch 1 taken 2068159 times.
2128292 s->avctx->active_thread_type & FF_THREAD_FRAME) {
115
1/2
✓ Branch 0 taken 60133 times.
✗ Branch 1 not taken.
60133 if (s->mv_dir & MV_DIR_FORWARD) {
116 60133 ff_thread_progress_await(&s->last_pic.ptr->progress,
117 lowest_referenced_row(s, 0));
118 }
119
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 60133 times.
60133 if (s->mv_dir & MV_DIR_BACKWARD) {
120 ff_thread_progress_await(&s->next_pic.ptr->progress,
121 lowest_referenced_row(s, 1));
122 }
123 }
124
125
2/2
✓ Branch 0 taken 41123 times.
✓ Branch 1 taken 4481478 times.
4522601 if (lowres_flag) {
126 41123 const h264_chroma_mc_func *op_pix = s->h264chroma.put_h264_chroma_pixels_tab;
127
128
2/2
✓ Branch 0 taken 37429 times.
✓ Branch 1 taken 3694 times.
41123 if (s->mv_dir & MV_DIR_FORWARD) {
129 37429 MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, s->last_pic.data, op_pix);
130 37429 op_pix = s->h264chroma.avg_h264_chroma_pixels_tab;
131 }
132
2/2
✓ Branch 0 taken 18960 times.
✓ Branch 1 taken 22163 times.
41123 if (s->mv_dir & MV_DIR_BACKWARD) {
133 18960 MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 1, s->next_pic.data, op_pix);
134 }
135 } else {
136 const op_pixels_func (*op_pix)[4];
137 const qpel_mc_func (*op_qpix)[16];
138
139
5/6
✓ Branch 0 taken 2087169 times.
✓ Branch 1 taken 2394309 times.
✓ Branch 2 taken 799438 times.
✓ Branch 3 taken 1287731 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 799438 times.
4481478 if ((is_mpeg12 == DEFINITELY_MPEG12_H261 || !s->no_rounding) || s->pict_type == AV_PICTURE_TYPE_B) {
140 3682040 op_pix = s->hdsp.put_pixels_tab;
141 3682040 op_qpix = s->qdsp.put_qpel_pixels_tab;
142 } else {
143 799438 op_pix = s->hdsp.put_no_rnd_pixels_tab;
144 799438 op_qpix = s->qdsp.put_no_rnd_qpel_pixels_tab;
145 }
146
2/2
✓ Branch 0 taken 4173877 times.
✓ Branch 1 taken 307601 times.
4481478 if (s->mv_dir & MV_DIR_FORWARD) {
147 4173877 ff_mpv_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_pic.data, op_pix, op_qpix);
148 4173877 op_pix = s->hdsp.avg_pixels_tab;
149 4173877 op_qpix = s->qdsp.avg_qpel_pixels_tab;
150 }
151
2/2
✓ Branch 0 taken 935146 times.
✓ Branch 1 taken 3546332 times.
4481478 if (s->mv_dir & MV_DIR_BACKWARD) {
152 935146 ff_mpv_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_pic.data, op_pix, op_qpix);
153 }
154 }
155
156 /* skip dequant / idct if we are really late ;) */
157
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4522601 times.
4522601 if (s->avctx->skip_idct) {
158 if( (s->avctx->skip_idct >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B)
159 ||(s->avctx->skip_idct >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I)
160 || s->avctx->skip_idct >= AVDISCARD_ALL)
161 return;
162 }
163
164 /* add dct residue */
165
7/8
✓ Branch 0 taken 41123 times.
✓ Branch 1 taken 4481478 times.
✓ Branch 2 taken 41123 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2087169 times.
✓ Branch 5 taken 2394309 times.
✓ Branch 6 taken 1759424 times.
✓ Branch 7 taken 368868 times.
4522601 if (!(IS_MPEG12_H261(s) || s->msmpeg4_version != MSMP4_UNUSED ||
166
4/4
✓ Branch 0 taken 1383593 times.
✓ Branch 1 taken 375831 times.
✓ Branch 2 taken 61534 times.
✓ Branch 3 taken 1322059 times.
1759424 (s->codec_id == AV_CODEC_ID_MPEG4 && !s->mpeg_quant)))
167 #endif /* !IS_ENCODER */
168 {
169 3744034 add_dequant_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale);
170 3744034 add_dequant_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale);
171 3744034 add_dequant_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale);
172 3744034 add_dequant_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale);
173
174 437365 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
175 av_assert2(IS_ENCODER || s->chroma_y_shift);
176
2/2
✓ Branch 0 taken 2958975 times.
✓ Branch 1 taken 347694 times.
3306669 if (!IS_ENCODER || s->chroma_y_shift) {
177 3396340 add_dequant_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale);
178 3396340 add_dequant_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale);
179 } else {
180 347694 dct_linesize >>= 1;
181 347694 dct_offset >>= 1;
182 347694 add_dequant_dct(s, block[4], 4, dest_cb, dct_linesize, s->chroma_qscale);
183 347694 add_dequant_dct(s, block[5], 5, dest_cr, dct_linesize, s->chroma_qscale);
184 347694 add_dequant_dct(s, block[6], 6, dest_cb + dct_offset, dct_linesize, s->chroma_qscale);
185 347694 add_dequant_dct(s, block[7], 7, dest_cr + dct_offset, dct_linesize, s->chroma_qscale);
186 }
187 }
188 }
189 #if !IS_ENCODER
190
5/6
✓ Branch 0 taken 1690927 times.
✓ Branch 1 taken 2394309 times.
✓ Branch 2 taken 1690927 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1500778 times.
✓ Branch 5 taken 190149 times.
4085236 else if (is_mpeg12 == DEFINITELY_MPEG12_H261 || lowres_flag || (s->codec_id != AV_CODEC_ID_WMV2)) {
191 3895087 add_dct(s, block[0], 0, dest_y , dct_linesize);
192 3895087 add_dct(s, block[1], 1, dest_y + block_size, dct_linesize);
193 3895087 add_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize);
194 3895087 add_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize);
195
196 3895087 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
197
2/2
✓ Branch 0 taken 3828136 times.
✓ Branch 1 taken 66951 times.
3895087 if (s->chroma_y_shift) {//Chroma420
198 3828136 add_dct(s, block[4], 4, dest_cb, uvlinesize);
199 3828136 add_dct(s, block[5], 5, dest_cr, uvlinesize);
200 } else {
201 //chroma422
202 66951 dct_linesize = uvlinesize << s->interlaced_dct;
203
2/2
✓ Branch 0 taken 65730 times.
✓ Branch 1 taken 1221 times.
66951 dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize*block_size;
204
205 66951 add_dct(s, block[4], 4, dest_cb, dct_linesize);
206 66951 add_dct(s, block[5], 5, dest_cr, dct_linesize);
207 66951 add_dct(s, block[6], 6, dest_cb+dct_offset, dct_linesize);
208 66951 add_dct(s, block[7], 7, dest_cr+dct_offset, dct_linesize);
209
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 66951 times.
66951 if (!s->chroma_x_shift) {//Chroma444
210 add_dct(s, block[8], 8, dest_cb+block_size, dct_linesize);
211 add_dct(s, block[9], 9, dest_cr+block_size, dct_linesize);
212 add_dct(s, block[10], 10, dest_cb+block_size+dct_offset, dct_linesize);
213 add_dct(s, block[11], 11, dest_cr+block_size+dct_offset, dct_linesize);
214 }
215 }
216 } //fi gray
217 } else if (CONFIG_WMV2_DECODER) {
218 190149 ff_wmv2_add_mb(s, block, dest_y, dest_cb, dest_cr);
219 }
220 #endif /* !IS_ENCODER */
221 } else {
222 #if !IS_ENCODER
223 /* Only MPEG-4 Simple Studio Profile is supported in > 8-bit mode.
224 TODO: Integrate 10-bit properly into mpegvideo.c so that ER works properly */
225
2/2
✓ Branch 0 taken 293510 times.
✓ Branch 1 taken 341001 times.
634511 if (is_mpeg12 != DEFINITELY_MPEG12_H261 && CONFIG_MPEG4_DECODER &&
226 /* s->codec_id == AV_CODEC_ID_MPEG4 && */
227
2/2
✓ Branch 0 taken 1350 times.
✓ Branch 1 taken 292160 times.
293510 s->avctx->bits_per_raw_sample > 8) {
228 1350 ff_mpeg4_decode_studio(s, dest_y, dest_cb, dest_cr, block_size,
229 uvlinesize, dct_linesize, dct_offset);
230
4/4
✓ Branch 0 taken 2377 times.
✓ Branch 1 taken 630784 times.
✓ Branch 2 taken 292160 times.
✓ Branch 3 taken 341001 times.
633161 } else if (!IS_MPEG12_H261(s))
231 #endif /* !IS_ENCODER */
232 {
233 /* dct only in intra block */
234 817965 put_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale);
235 817965 put_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale);
236 817965 put_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale);
237 817965 put_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale);
238
239 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
240
2/2
✓ Branch 0 taken 779204 times.
✓ Branch 1 taken 38761 times.
817965 if (s->chroma_y_shift) {
241 779204 put_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale);
242 779204 put_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale);
243 } else {
244 38761 dct_offset >>=1;
245 38761 dct_linesize >>=1;
246 38761 put_dct(s, block[4], 4, dest_cb, dct_linesize, s->chroma_qscale);
247 38761 put_dct(s, block[5], 5, dest_cr, dct_linesize, s->chroma_qscale);
248 38761 put_dct(s, block[6], 6, dest_cb + dct_offset, dct_linesize, s->chroma_qscale);
249 38761 put_dct(s, block[7], 7, dest_cr + dct_offset, dct_linesize, s->chroma_qscale);
250 }
251 }
252 }
253 #if !IS_ENCODER
254 else {
255 341001 s->idsp.idct_put(dest_y, dct_linesize, block[0]);
256 341001 s->idsp.idct_put(dest_y + block_size, dct_linesize, block[1]);
257 341001 s->idsp.idct_put(dest_y + dct_offset, dct_linesize, block[2]);
258 341001 s->idsp.idct_put(dest_y + dct_offset + block_size, dct_linesize, block[3]);
259
260 if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
261
2/2
✓ Branch 0 taken 286842 times.
✓ Branch 1 taken 54159 times.
341001 if (s->chroma_y_shift) {
262 286842 s->idsp.idct_put(dest_cb, uvlinesize, block[4]);
263 286842 s->idsp.idct_put(dest_cr, uvlinesize, block[5]);
264 } else {
265 54159 dct_linesize = uvlinesize << s->interlaced_dct;
266
2/2
✓ Branch 0 taken 54119 times.
✓ Branch 1 taken 40 times.
54159 dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize*block_size;
267
268 54159 s->idsp.idct_put(dest_cb, dct_linesize, block[4]);
269 54159 s->idsp.idct_put(dest_cr, dct_linesize, block[5]);
270 54159 s->idsp.idct_put(dest_cb + dct_offset, dct_linesize, block[6]);
271 54159 s->idsp.idct_put(dest_cr + dct_offset, dct_linesize, block[7]);
272
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 54159 times.
54159 if (!s->chroma_x_shift) { //Chroma444
273 s->idsp.idct_put(dest_cb + block_size, dct_linesize, block[8]);
274 s->idsp.idct_put(dest_cr + block_size, dct_linesize, block[9]);
275 s->idsp.idct_put(dest_cb + block_size + dct_offset, dct_linesize, block[10]);
276 s->idsp.idct_put(dest_cr + block_size + dct_offset, dct_linesize, block[11]);
277 }
278 }
279 } //gray
280 }
281 #endif /* !IS_ENCODER */
282 }
283 }
284 4917932 }
285
286