Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * Common mpeg video decoding code | ||
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 | #include <limits.h> | ||
24 | |||
25 | #include "config_components.h" | ||
26 | |||
27 | #include "libavutil/avassert.h" | ||
28 | #include "libavutil/emms.h" | ||
29 | #include "libavutil/imgutils.h" | ||
30 | #include "libavutil/internal.h" | ||
31 | #include "libavutil/video_enc_params.h" | ||
32 | |||
33 | #include "avcodec.h" | ||
34 | #include "decode.h" | ||
35 | #include "h263.h" | ||
36 | #include "h264chroma.h" | ||
37 | #include "internal.h" | ||
38 | #include "mpegutils.h" | ||
39 | #include "mpegvideo.h" | ||
40 | #include "mpegvideodec.h" | ||
41 | #include "mpeg4videodec.h" | ||
42 | #include "libavutil/refstruct.h" | ||
43 | #include "thread.h" | ||
44 | #include "threadprogress.h" | ||
45 | #include "wmv2dec.h" | ||
46 | |||
47 | 636 | av_cold int ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx) | |
48 | { | ||
49 | enum ThreadingStatus thread_status; | ||
50 | |||
51 | 636 | ff_mpv_common_defaults(s); | |
52 | |||
53 | 636 | s->avctx = avctx; | |
54 | 636 | s->width = avctx->coded_width; | |
55 | 636 | s->height = avctx->coded_height; | |
56 | 636 | s->codec_id = avctx->codec->id; | |
57 | 636 | s->workaround_bugs = avctx->workaround_bugs; | |
58 | |||
59 | /* convert fourcc to upper case */ | ||
60 | 636 | s->codec_tag = ff_toupper4(avctx->codec_tag); | |
61 | |||
62 | 636 | ff_mpv_idct_init(s); | |
63 | |||
64 | 636 | ff_h264chroma_init(&s->h264chroma, 8); //for lowres | |
65 | |||
66 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 636 times.
|
636 | if (s->picture_pool) // VC-1 can call this multiple times |
67 | ✗ | return 0; | |
68 | |||
69 | 636 | thread_status = ff_thread_sync_ref(avctx, offsetof(MpegEncContext, picture_pool)); | |
70 |
2/2✓ Branch 0 taken 628 times.
✓ Branch 1 taken 8 times.
|
636 | if (thread_status != FF_THREAD_IS_COPY) { |
71 | 628 | s->picture_pool = ff_mpv_alloc_pic_pool(thread_status != FF_THREAD_NO_FRAME_THREADING); | |
72 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 628 times.
|
628 | if (!s->picture_pool) |
73 | ✗ | return AVERROR(ENOMEM); | |
74 | } | ||
75 | 636 | return 0; | |
76 | } | ||
77 | |||
78 | 18 | int ff_mpeg_update_thread_context(AVCodecContext *dst, | |
79 | const AVCodecContext *src) | ||
80 | { | ||
81 | 18 | MpegEncContext *const s1 = src->priv_data; | |
82 | 18 | MpegEncContext *const s = dst->priv_data; | |
83 | int ret; | ||
84 | |||
85 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
|
18 | if (dst == src) |
86 | ✗ | return 0; | |
87 | |||
88 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
|
18 | av_assert0(s != s1); |
89 | |||
90 | // FIXME can parameters change on I-frames? | ||
91 | // in that case dst may need a reinit | ||
92 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 10 times.
|
18 | if (!s->context_initialized) { |
93 | 8 | void *private_ctx = s->private_ctx; | |
94 | int err; | ||
95 | 8 | memcpy(s, s1, sizeof(*s)); | |
96 | |||
97 | 8 | s->context_initialized = 0; | |
98 | 8 | s->context_reinit = 0; | |
99 | 8 | s->avctx = dst; | |
100 | 8 | s->private_ctx = private_ctx; | |
101 | |||
102 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | if (s1->context_initialized) { |
103 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
|
8 | if ((err = ff_mpv_common_init(s)) < 0) |
104 | ✗ | return err; | |
105 | } | ||
106 | } | ||
107 | |||
108 |
3/6✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 18 times.
|
18 | if (s->height != s1->height || s->width != s1->width || s->context_reinit) { |
109 | ✗ | s->height = s1->height; | |
110 | ✗ | s->width = s1->width; | |
111 | ✗ | if ((ret = ff_mpv_common_frame_size_change(s)) < 0) | |
112 | ✗ | return ret; | |
113 | } | ||
114 | |||
115 | 18 | s->quarter_sample = s1->quarter_sample; | |
116 | |||
117 | 18 | s->picture_number = s1->picture_number; | |
118 | |||
119 | 18 | ff_mpv_replace_picture(&s->cur_pic, &s1->cur_pic); | |
120 | 18 | ff_mpv_replace_picture(&s->last_pic, &s1->last_pic); | |
121 | 18 | ff_mpv_replace_picture(&s->next_pic, &s1->next_pic); | |
122 | |||
123 | 18 | s->linesize = s1->linesize; | |
124 | 18 | s->uvlinesize = s1->uvlinesize; | |
125 | |||
126 | // Error/bug resilience | ||
127 | 18 | s->workaround_bugs = s1->workaround_bugs; | |
128 | 18 | s->padding_bug_score = s1->padding_bug_score; | |
129 | |||
130 | // MPEG-4 timing info | ||
131 | 18 | memcpy(&s->last_time_base, &s1->last_time_base, | |
132 | 18 | (char *) &s1->pb_field_time + sizeof(s1->pb_field_time) - | |
133 | 18 | (char *) &s1->last_time_base); | |
134 | |||
135 | // B-frame info | ||
136 | 18 | s->low_delay = s1->low_delay; | |
137 | |||
138 | // MPEG-2/interlacing info | ||
139 | 18 | memcpy(&s->progressive_sequence, &s1->progressive_sequence, | |
140 | 18 | (char *) &s1->first_field + sizeof(s1->first_field) - (char *) &s1->progressive_sequence); | |
141 | |||
142 | 18 | return 0; | |
143 | } | ||
144 | |||
145 | 636 | av_cold int ff_mpv_decode_close(AVCodecContext *avctx) | |
146 | { | ||
147 | 636 | MpegEncContext *s = avctx->priv_data; | |
148 | |||
149 | 636 | av_refstruct_pool_uninit(&s->picture_pool); | |
150 | 636 | ff_mpv_common_end(s); | |
151 | 636 | return 0; | |
152 | } | ||
153 | |||
154 | 47 | av_cold int ff_mpv_common_frame_size_change(MpegEncContext *s) | |
155 | { | ||
156 | 47 | int err = 0; | |
157 | |||
158 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
|
47 | if (!s->context_initialized) |
159 | ✗ | return AVERROR(EINVAL); | |
160 | |||
161 | 47 | ff_mpv_free_context_frame(s); | |
162 | |||
163 | 47 | ff_mpv_unref_picture(&s->last_pic); | |
164 | 47 | ff_mpv_unref_picture(&s->next_pic); | |
165 | 47 | ff_mpv_unref_picture(&s->cur_pic); | |
166 | |||
167 |
2/6✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 47 times.
|
94 | if ((s->width || s->height) && |
168 | 47 | (err = av_image_check_size(s->width, s->height, 0, s->avctx)) < 0) | |
169 | ✗ | goto fail; | |
170 | |||
171 | /* set chroma shifts */ | ||
172 | 47 | err = av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt, | |
173 | &s->chroma_x_shift, | ||
174 | &s->chroma_y_shift); | ||
175 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
|
47 | if (err < 0) |
176 | ✗ | goto fail; | |
177 | |||
178 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 47 times.
|
47 | if ((err = ff_mpv_init_context_frame(s))) |
179 | ✗ | goto fail; | |
180 | |||
181 | 47 | memset(s->thread_context, 0, sizeof(s->thread_context)); | |
182 | 47 | s->thread_context[0] = s; | |
183 | |||
184 |
2/4✓ Branch 0 taken 47 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 47 times.
✗ Branch 3 not taken.
|
47 | if (s->width && s->height) { |
185 | 47 | err = ff_mpv_init_duplicate_contexts(s); | |
186 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
|
47 | if (err < 0) |
187 | ✗ | goto fail; | |
188 | } | ||
189 | 47 | s->context_reinit = 0; | |
190 | |||
191 | 47 | return 0; | |
192 | ✗ | fail: | |
193 | ✗ | ff_mpv_free_context_frame(s); | |
194 | ✗ | s->context_reinit = 1; | |
195 | ✗ | return err; | |
196 | } | ||
197 | |||
198 | 11257 | static int alloc_picture(MpegEncContext *s, MPVWorkPicture *dst, int reference) | |
199 | { | ||
200 | 11257 | AVCodecContext *avctx = s->avctx; | |
201 | 11257 | MPVPicture *pic = av_refstruct_pool_get(s->picture_pool); | |
202 | int ret; | ||
203 | |||
204 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11257 times.
|
11257 | if (!pic) |
205 | ✗ | return AVERROR(ENOMEM); | |
206 | |||
207 | 11257 | dst->ptr = pic; | |
208 | |||
209 | 11257 | pic->reference = reference; | |
210 | |||
211 | /* WM Image / Screen codecs allocate internal buffers with different | ||
212 | * dimensions / colorspaces; ignore user-defined callbacks for these. */ | ||
213 |
1/2✓ Branch 0 taken 11257 times.
✗ Branch 1 not taken.
|
11257 | if (avctx->codec_id != AV_CODEC_ID_WMV3IMAGE && |
214 |
1/2✓ Branch 0 taken 11257 times.
✗ Branch 1 not taken.
|
11257 | avctx->codec_id != AV_CODEC_ID_VC1IMAGE && |
215 |
2/2✓ Branch 0 taken 11175 times.
✓ Branch 1 taken 82 times.
|
11257 | avctx->codec_id != AV_CODEC_ID_MSS2) { |
216 | 11175 | ret = ff_thread_get_buffer(avctx, pic->f, | |
217 | reference ? AV_GET_BUFFER_FLAG_REF : 0); | ||
218 | } else { | ||
219 | 82 | pic->f->width = avctx->width; | |
220 | 82 | pic->f->height = avctx->height; | |
221 | 82 | pic->f->format = avctx->pix_fmt; | |
222 | 82 | ret = avcodec_default_get_buffer2(avctx, pic->f, 0); | |
223 | } | ||
224 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11257 times.
|
11257 | if (ret < 0) |
225 | ✗ | goto fail; | |
226 | |||
227 | 11257 | ret = ff_mpv_pic_check_linesize(avctx, pic->f, &s->linesize, &s->uvlinesize); | |
228 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11257 times.
|
11257 | if (ret < 0) |
229 | ✗ | goto fail; | |
230 | |||
231 | 11257 | ret = ff_hwaccel_frame_priv_alloc(avctx, &pic->hwaccel_picture_private); | |
232 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11257 times.
|
11257 | if (ret < 0) |
233 | ✗ | goto fail; | |
234 | |||
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); | ||
239 | 11257 | ret = ff_mpv_alloc_pic_accessories(s->avctx, dst, &s->sc, | |
240 | &s->buffer_pools, s->mb_height); | ||
241 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11257 times.
|
11257 | if (ret < 0) |
242 | ✗ | goto fail; | |
243 | |||
244 | 11257 | return 0; | |
245 | ✗ | fail: | |
246 | ✗ | ff_mpv_unref_picture(dst); | |
247 | ✗ | return ret; | |
248 | } | ||
249 | |||
250 | 21 | static int av_cold alloc_dummy_frame(MpegEncContext *s, MPVWorkPicture *dst) | |
251 | { | ||
252 | MPVPicture *pic; | ||
253 | 21 | int ret = alloc_picture(s, dst, 1); | |
254 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | if (ret < 0) |
255 | ✗ | return ret; | |
256 | |||
257 | 21 | pic = dst->ptr; | |
258 | 21 | pic->dummy = 1; | |
259 | |||
260 | 21 | ff_thread_progress_report(&pic->progress, INT_MAX); | |
261 | |||
262 | 21 | return 0; | |
263 | } | ||
264 | |||
265 | 21 | static void color_frame(AVFrame *frame, int luma) | |
266 | { | ||
267 | int h_chroma_shift, v_chroma_shift; | ||
268 | |||
269 |
2/2✓ Branch 0 taken 9888 times.
✓ Branch 1 taken 21 times.
|
9909 | for (int i = 0; i < frame->height; i++) |
270 | 9888 | memset(frame->data[0] + frame->linesize[0] * i, luma, frame->width); | |
271 | |||
272 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | if (!frame->data[1]) |
273 | ✗ | return; | |
274 | 21 | av_pix_fmt_get_chroma_sub_sample(frame->format, &h_chroma_shift, &v_chroma_shift); | |
275 |
2/2✓ Branch 0 taken 4944 times.
✓ Branch 1 taken 21 times.
|
4965 | for (int i = 0; i < AV_CEIL_RSHIFT(frame->height, v_chroma_shift); i++) { |
276 | 4944 | memset(frame->data[1] + frame->linesize[1] * i, | |
277 | 4944 | 0x80, AV_CEIL_RSHIFT(frame->width, h_chroma_shift)); | |
278 | 4944 | memset(frame->data[2] + frame->linesize[2] * i, | |
279 | 4944 | 0x80, AV_CEIL_RSHIFT(frame->width, h_chroma_shift)); | |
280 | } | ||
281 | } | ||
282 | |||
283 | 11945 | int ff_mpv_alloc_dummy_frames(MpegEncContext *s) | |
284 | { | ||
285 | 11945 | AVCodecContext *avctx = s->avctx; | |
286 | int ret; | ||
287 | |||
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]); | ||
290 |
4/4✓ Branch 0 taken 335 times.
✓ Branch 1 taken 11610 times.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 314 times.
|
11945 | if (!s->last_pic.ptr && s->pict_type != AV_PICTURE_TYPE_I) { |
291 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
21 | if (s->pict_type == AV_PICTURE_TYPE_B && s->next_pic.ptr) |
292 | ✗ | av_log(avctx, AV_LOG_DEBUG, | |
293 | "allocating dummy last picture for B frame\n"); | ||
294 |
2/2✓ Branch 0 taken 15 times.
✓ Branch 1 taken 6 times.
|
21 | else if (s->codec_id != AV_CODEC_ID_H261 /* H.261 has no keyframes */ && |
295 |
2/4✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 15 times.
|
15 | (s->picture_structure == PICT_FRAME || s->first_field)) |
296 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
297 | "warning: first frame is no keyframe\n"); | ||
298 | |||
299 | /* Allocate a dummy frame */ | ||
300 | 21 | ret = alloc_dummy_frame(s, &s->last_pic); | |
301 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | if (ret < 0) |
302 | ✗ | return ret; | |
303 | |||
304 |
1/2✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
|
21 | if (!avctx->hwaccel) { |
305 |
2/4✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
|
21 | int luma_val = s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == AV_CODEC_ID_H263 ? 16 : 0x80; |
306 | 21 | color_frame(s->last_pic.ptr->f, luma_val); | |
307 | } | ||
308 | } | ||
309 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 11945 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
11945 | if (!s->next_pic.ptr && s->pict_type == AV_PICTURE_TYPE_B) { |
310 | /* Allocate a dummy frame */ | ||
311 | ✗ | ret = alloc_dummy_frame(s, &s->next_pic); | |
312 | ✗ | if (ret < 0) | |
313 | ✗ | return ret; | |
314 | } | ||
315 | |||
316 |
4/6✓ Branch 0 taken 10707 times.
✓ Branch 1 taken 1238 times.
✓ Branch 2 taken 10707 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10707 times.
|
11945 | av_assert0(s->pict_type == AV_PICTURE_TYPE_I || (s->last_pic.ptr && |
317 | s->last_pic.ptr->f->buf[0])); | ||
318 | |||
319 | 11945 | return 0; | |
320 | } | ||
321 | |||
322 | /** | ||
323 | * generic function called after decoding | ||
324 | * the header and before a frame is decoded. | ||
325 | */ | ||
326 | 11236 | int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx) | |
327 | { | ||
328 | int ret; | ||
329 | |||
330 | 11236 | s->mb_skipped = 0; | |
331 | |||
332 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 11236 times.
|
11236 | if (!ff_thread_can_start_frame(avctx)) { |
333 | ✗ | av_log(avctx, AV_LOG_ERROR, "Attempt to start a frame outside SETUP state\n"); | |
334 | ✗ | return AVERROR_BUG; | |
335 | } | ||
336 | |||
337 | 11236 | ff_mpv_unref_picture(&s->cur_pic); | |
338 | 11236 | ret = alloc_picture(s, &s->cur_pic, | |
339 |
3/4✓ Branch 0 taken 8619 times.
✓ Branch 1 taken 2617 times.
✓ Branch 2 taken 8619 times.
✗ Branch 3 not taken.
|
11236 | s->pict_type != AV_PICTURE_TYPE_B && !s->droppable); |
340 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11236 times.
|
11236 | if (ret < 0) |
341 | ✗ | return ret; | |
342 | |||
343 |
2/2✓ Branch 0 taken 778 times.
✓ Branch 1 taken 10458 times.
|
11236 | s->cur_pic.ptr->f->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST * !!s->top_field_first; |
344 | 22472 | s->cur_pic.ptr->f->flags |= AV_FRAME_FLAG_INTERLACED * | |
345 |
3/4✓ Branch 0 taken 2483 times.
✓ Branch 1 taken 8753 times.
✓ Branch 2 taken 2483 times.
✗ Branch 3 not taken.
|
11236 | (!s->progressive_frame && !s->progressive_sequence); |
346 | 11236 | s->cur_pic.ptr->field_picture = s->picture_structure != PICT_FRAME; | |
347 | |||
348 | 11236 | s->cur_pic.ptr->f->pict_type = s->pict_type; | |
349 |
2/2✓ Branch 0 taken 1238 times.
✓ Branch 1 taken 9998 times.
|
11236 | if (s->pict_type == AV_PICTURE_TYPE_I) |
350 | 1238 | s->cur_pic.ptr->f->flags |= AV_FRAME_FLAG_KEY; | |
351 | else | ||
352 | 9998 | s->cur_pic.ptr->f->flags &= ~AV_FRAME_FLAG_KEY; | |
353 | |||
354 |
2/2✓ Branch 0 taken 8619 times.
✓ Branch 1 taken 2617 times.
|
11236 | if (s->pict_type != AV_PICTURE_TYPE_B) { |
355 | 8619 | ff_mpv_workpic_from_pic(&s->last_pic, s->next_pic.ptr); | |
356 |
1/2✓ Branch 0 taken 8619 times.
✗ Branch 1 not taken.
|
8619 | if (!s->droppable) |
357 | 8619 | ff_mpv_workpic_from_pic(&s->next_pic, s->cur_pic.ptr); | |
358 | } | ||
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); | ||
365 | |||
366 | 11236 | ret = ff_mpv_alloc_dummy_frames(s); | |
367 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11236 times.
|
11236 | if (ret < 0) |
368 | ✗ | return ret; | |
369 | |||
370 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11236 times.
|
11236 | if (s->avctx->debug & FF_DEBUG_NOMC) |
371 | ✗ | color_frame(s->cur_pic.ptr->f, 0x80); | |
372 | |||
373 | 11236 | return 0; | |
374 | } | ||
375 | |||
376 | /* called after a frame has been decoded. */ | ||
377 | 11236 | void ff_mpv_frame_end(MpegEncContext *s) | |
378 | { | ||
379 | 11236 | emms_c(); | |
380 | |||
381 |
2/2✓ Branch 0 taken 8619 times.
✓ Branch 1 taken 2617 times.
|
11236 | if (s->cur_pic.reference) |
382 | 8619 | ff_thread_progress_report(&s->cur_pic.ptr->progress, INT_MAX); | |
383 | 11236 | } | |
384 | |||
385 | 11038 | void ff_print_debug_info(const MpegEncContext *s, const MPVPicture *p, AVFrame *pict) | |
386 | { | ||
387 | 11038 | ff_print_debug_info2(s->avctx, pict, p->mb_type, | |
388 | 11038 | p->qscale_table, p->motion_val, | |
389 | 11038 | p->mb_width, p->mb_height, p->mb_stride, s->quarter_sample); | |
390 | 11038 | } | |
391 | |||
392 | 10266 | int ff_mpv_export_qp_table(const MpegEncContext *s, AVFrame *f, | |
393 | const MPVPicture *p, int qp_type) | ||
394 | { | ||
395 | AVVideoEncParams *par; | ||
396 |
2/2✓ Branch 0 taken 6431 times.
✓ Branch 1 taken 3835 times.
|
10266 | int mult = (qp_type == FF_MPV_QSCALE_TYPE_MPEG1) ? 2 : 1; |
397 | 10266 | unsigned int nb_mb = p->mb_height * p->mb_width; | |
398 | |||
399 |
2/2✓ Branch 0 taken 10224 times.
✓ Branch 1 taken 42 times.
|
10266 | if (!(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS)) |
400 | 10224 | return 0; | |
401 | |||
402 | 42 | par = av_video_enc_params_create_side_data(f, AV_VIDEO_ENC_PARAMS_MPEG2, nb_mb); | |
403 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
|
42 | if (!par) |
404 | ✗ | return AVERROR(ENOMEM); | |
405 | |||
406 |
2/2✓ Branch 0 taken 756 times.
✓ Branch 1 taken 42 times.
|
798 | for (unsigned y = 0; y < p->mb_height; y++) |
407 |
2/2✓ Branch 0 taken 16632 times.
✓ Branch 1 taken 756 times.
|
17388 | for (unsigned x = 0; x < p->mb_width; x++) { |
408 | 16632 | const unsigned int block_idx = y * p->mb_width + x; | |
409 | 16632 | const unsigned int mb_xy = y * p->mb_stride + x; | |
410 | 16632 | AVVideoBlockParams *const b = av_video_enc_params_block(par, block_idx); | |
411 | |||
412 | 16632 | b->src_x = x * 16; | |
413 | 16632 | b->src_y = y * 16; | |
414 | 16632 | b->w = 16; | |
415 | 16632 | b->h = 16; | |
416 | |||
417 | 16632 | b->delta_qp = p->qscale_table[mb_xy] * mult; | |
418 | } | ||
419 | |||
420 | 42 | return 0; | |
421 | } | ||
422 | |||
423 | 170410 | void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h) | |
424 | { | ||
425 | 170410 | ff_draw_horiz_band(s->avctx, s->cur_pic.ptr->f, | |
426 |
2/2✓ Branch 0 taken 166951 times.
✓ Branch 1 taken 3459 times.
|
170410 | s->last_pic.ptr ? s->last_pic.ptr->f : NULL, |
427 | y, h, s->picture_structure, | ||
428 | s->first_field, s->low_delay); | ||
429 | 170410 | } | |
430 | |||
431 | 82 | av_cold void ff_mpeg_flush(AVCodecContext *avctx) | |
432 | { | ||
433 | 82 | MpegEncContext *const s = avctx->priv_data; | |
434 | |||
435 | 82 | ff_mpv_unref_picture(&s->cur_pic); | |
436 | 82 | ff_mpv_unref_picture(&s->last_pic); | |
437 | 82 | ff_mpv_unref_picture(&s->next_pic); | |
438 | |||
439 | 82 | s->mb_x = s->mb_y = 0; | |
440 | |||
441 | 82 | s->pp_time = 0; | |
442 | 82 | } | |
443 | |||
444 | 170410 | void ff_mpv_report_decode_progress(MpegEncContext *s) | |
445 | { | ||
446 |
5/6✓ Branch 0 taken 131271 times.
✓ Branch 1 taken 39139 times.
✓ Branch 2 taken 124688 times.
✓ Branch 3 taken 6583 times.
✓ Branch 4 taken 124688 times.
✗ Branch 5 not taken.
|
170410 | if (s->pict_type != AV_PICTURE_TYPE_B && !s->partitioned_frame && !s->er.error_occurred) |
447 | 124688 | ff_thread_progress_report(&s->cur_pic.ptr->progress, s->mb_y); | |
448 | 170410 | } | |
449 | |||
450 | |||
451 | 126300 | static inline int hpel_motion_lowres(MpegEncContext *s, | |
452 | uint8_t *dest, const uint8_t *src, | ||
453 | int field_based, int field_select, | ||
454 | int src_x, int src_y, | ||
455 | int width, int height, ptrdiff_t stride, | ||
456 | int h_edge_pos, int v_edge_pos, | ||
457 | int w, int h, const h264_chroma_mc_func *pix_op, | ||
458 | int motion_x, int motion_y) | ||
459 | { | ||
460 | 126300 | const int lowres = s->avctx->lowres; | |
461 | 126300 | const int op_index = lowres; | |
462 | 126300 | const int s_mask = (2 << lowres) - 1; | |
463 | 126300 | int emu = 0; | |
464 | int sx, sy; | ||
465 | |||
466 | av_assert2(op_index <= 3); | ||
467 | |||
468 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 126300 times.
|
126300 | if (s->quarter_sample) { |
469 | ✗ | motion_x /= 2; | |
470 | ✗ | motion_y /= 2; | |
471 | } | ||
472 | |||
473 | 126300 | sx = motion_x & s_mask; | |
474 | 126300 | sy = motion_y & s_mask; | |
475 | 126300 | src_x += motion_x >> lowres + 1; | |
476 | 126300 | src_y += motion_y >> lowres + 1; | |
477 | |||
478 | 126300 | src += src_y * stride + src_x; | |
479 | |||
480 |
1/2✓ Branch 0 taken 126300 times.
✗ Branch 1 not taken.
|
126300 | if ((unsigned)src_x > FFMAX( h_edge_pos - (!!sx) - w, 0) || |
481 |
2/2✓ Branch 0 taken 298 times.
✓ Branch 1 taken 126002 times.
|
126300 | (unsigned)src_y > FFMAX((v_edge_pos >> field_based) - (!!sy) - h, 0)) { |
482 | 298 | s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, src, | |
483 | s->linesize, s->linesize, | ||
484 | 298 | w + 1, (h + 1) << field_based, | |
485 | src_x, src_y * (1 << field_based), | ||
486 | h_edge_pos, v_edge_pos); | ||
487 | 298 | src = s->sc.edge_emu_buffer; | |
488 | 298 | emu = 1; | |
489 | } | ||
490 | |||
491 | 126300 | sx = (sx << 2) >> lowres; | |
492 | 126300 | sy = (sy << 2) >> lowres; | |
493 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 126300 times.
|
126300 | if (field_select) |
494 | ✗ | src += s->linesize; | |
495 | 126300 | pix_op[op_index](dest, src, stride, h, sx, sy); | |
496 | 126300 | return emu; | |
497 | } | ||
498 | |||
499 | /* apply one mpeg motion vector to the three components */ | ||
500 | 24814 | static av_always_inline void mpeg_motion_lowres(MpegEncContext *s, | |
501 | uint8_t *dest_y, | ||
502 | uint8_t *dest_cb, | ||
503 | uint8_t *dest_cr, | ||
504 | int field_based, | ||
505 | int bottom_field, | ||
506 | int field_select, | ||
507 | uint8_t *const *ref_picture, | ||
508 | const h264_chroma_mc_func *pix_op, | ||
509 | int motion_x, int motion_y, | ||
510 | int h, int mb_y) | ||
511 | { | ||
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; | ||
514 | ptrdiff_t uvlinesize, linesize; | ||
515 | 24814 | const int lowres = s->avctx->lowres; | |
516 | 24814 | const int op_index = lowres - 1 + s->chroma_x_shift; | |
517 | 24814 | const int block_s = 8 >> lowres; | |
518 | 24814 | const int s_mask = (2 << lowres) - 1; | |
519 | 24814 | const int h_edge_pos = s->h_edge_pos >> lowres; | |
520 | 24814 | const int v_edge_pos = s->v_edge_pos >> lowres; | |
521 |
1/2✓ Branch 0 taken 24814 times.
✗ Branch 1 not taken.
|
24814 | int hc = s->chroma_y_shift ? (h+1-bottom_field)>>1 : h; |
522 | |||
523 | av_assert2(op_index <= 3); | ||
524 | |||
525 | 24814 | linesize = s->cur_pic.linesize[0] << field_based; | |
526 | 24814 | uvlinesize = s->cur_pic.linesize[1] << field_based; | |
527 | |||
528 | // FIXME obviously not perfect but qpel will not work in lowres anyway | ||
529 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24814 times.
|
24814 | if (s->quarter_sample) { |
530 | ✗ | motion_x /= 2; | |
531 | ✗ | motion_y /= 2; | |
532 | } | ||
533 | |||
534 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24814 times.
|
24814 | if (field_based) { |
535 | ✗ | motion_y += (bottom_field - field_select)*((1 << lowres)-1); | |
536 | } | ||
537 | |||
538 | 24814 | sx = motion_x & s_mask; | |
539 | 24814 | sy = motion_y & s_mask; | |
540 | 24814 | src_x = s->mb_x * 2 * block_s + (motion_x >> lowres + 1); | |
541 | 24814 | src_y = (mb_y * 2 * block_s >> field_based) + (motion_y >> lowres + 1); | |
542 | |||
543 |
1/2✓ Branch 0 taken 24814 times.
✗ Branch 1 not taken.
|
24814 | if (s->out_format == FMT_H263) { |
544 | 24814 | uvsx = ((motion_x >> 1) & s_mask) | (sx & 1); | |
545 | 24814 | uvsy = ((motion_y >> 1) & s_mask) | (sy & 1); | |
546 | 24814 | uvsrc_x = src_x >> 1; | |
547 | 24814 | uvsrc_y = src_y >> 1; | |
548 | ✗ | } else if (s->out_format == FMT_H261) { | |
549 | // even chroma mv's are full pel in H261 | ||
550 | ✗ | mx = motion_x / 4; | |
551 | ✗ | my = motion_y / 4; | |
552 | ✗ | uvsx = (2 * mx) & s_mask; | |
553 | ✗ | uvsy = (2 * my) & s_mask; | |
554 | ✗ | uvsrc_x = s->mb_x * block_s + (mx >> lowres); | |
555 | ✗ | uvsrc_y = mb_y * block_s + (my >> lowres); | |
556 | } else { | ||
557 | ✗ | if (s->chroma_y_shift) { | |
558 | ✗ | mx = motion_x / 2; | |
559 | ✗ | my = motion_y / 2; | |
560 | ✗ | uvsx = mx & s_mask; | |
561 | ✗ | uvsy = my & s_mask; | |
562 | ✗ | uvsrc_x = s->mb_x * block_s + (mx >> lowres + 1); | |
563 | ✗ | uvsrc_y = (mb_y * block_s >> field_based) + (my >> lowres + 1); | |
564 | } else { | ||
565 | ✗ | if (s->chroma_x_shift) { | |
566 | //Chroma422 | ||
567 | ✗ | mx = motion_x / 2; | |
568 | ✗ | uvsx = mx & s_mask; | |
569 | ✗ | uvsy = motion_y & s_mask; | |
570 | ✗ | uvsrc_y = src_y; | |
571 | ✗ | uvsrc_x = s->mb_x*block_s + (mx >> (lowres+1)); | |
572 | } else { | ||
573 | //Chroma444 | ||
574 | ✗ | uvsx = motion_x & s_mask; | |
575 | ✗ | uvsy = motion_y & s_mask; | |
576 | ✗ | uvsrc_x = src_x; | |
577 | ✗ | uvsrc_y = src_y; | |
578 | } | ||
579 | } | ||
580 | } | ||
581 | |||
582 | 24814 | ptr_y = ref_picture[0] + src_y * linesize + src_x; | |
583 | 24814 | ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; | |
584 | 24814 | ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; | |
585 | |||
586 |
3/4✓ Branch 0 taken 24814 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 24712 times.
✓ Branch 3 taken 102 times.
|
24814 | if ((unsigned) src_x > FFMAX( h_edge_pos - (!!sx) - 2 * block_s, 0) || uvsrc_y<0 || |
587 |
2/2✓ Branch 0 taken 95 times.
✓ Branch 1 taken 24617 times.
|
24712 | (unsigned) src_y > FFMAX((v_edge_pos >> field_based) - (!!sy) - FFMAX(h, hc<<s->chroma_y_shift), 0)) { |
588 | 197 | s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr_y, | |
589 | linesize >> field_based, linesize >> field_based, | ||
590 | 17, 17 + field_based, | ||
591 | src_x, src_y * (1 << field_based), h_edge_pos, | ||
592 | v_edge_pos); | ||
593 | 197 | ptr_y = s->sc.edge_emu_buffer; | |
594 | if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { | ||
595 | 197 | uint8_t *ubuf = s->sc.edge_emu_buffer + 18 * s->linesize; | |
596 | 197 | uint8_t *vbuf =ubuf + 10 * s->uvlinesize; | |
597 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 197 times.
|
197 | if (s->workaround_bugs & FF_BUG_IEDGE) |
598 | ✗ | vbuf -= s->uvlinesize; | |
599 | 197 | s->vdsp.emulated_edge_mc(ubuf, ptr_cb, | |
600 | uvlinesize >> field_based, uvlinesize >> field_based, | ||
601 | 9, 9 + field_based, | ||
602 | uvsrc_x, uvsrc_y * (1 << field_based), | ||
603 | h_edge_pos >> 1, v_edge_pos >> 1); | ||
604 | 197 | s->vdsp.emulated_edge_mc(vbuf, ptr_cr, | |
605 | uvlinesize >> field_based,uvlinesize >> field_based, | ||
606 | 9, 9 + field_based, | ||
607 | uvsrc_x, uvsrc_y * (1 << field_based), | ||
608 | h_edge_pos >> 1, v_edge_pos >> 1); | ||
609 | 197 | ptr_cb = ubuf; | |
610 | 197 | ptr_cr = vbuf; | |
611 | } | ||
612 | } | ||
613 | |||
614 | // FIXME use this for field pix too instead of the obnoxious hack which changes picture.f->data | ||
615 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24814 times.
|
24814 | if (bottom_field) { |
616 | ✗ | dest_y += s->linesize; | |
617 | ✗ | dest_cb += s->uvlinesize; | |
618 | ✗ | dest_cr += s->uvlinesize; | |
619 | } | ||
620 | |||
621 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24814 times.
|
24814 | if (field_select) { |
622 | ✗ | ptr_y += s->linesize; | |
623 | ✗ | ptr_cb += s->uvlinesize; | |
624 | ✗ | ptr_cr += s->uvlinesize; | |
625 | } | ||
626 | |||
627 | 24814 | sx = (sx << 2) >> lowres; | |
628 | 24814 | sy = (sy << 2) >> lowres; | |
629 | 24814 | pix_op[lowres - 1](dest_y, ptr_y, linesize, h, sx, sy); | |
630 | |||
631 | if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { | ||
632 | 24814 | uvsx = (uvsx << 2) >> lowres; | |
633 | 24814 | uvsy = (uvsy << 2) >> lowres; | |
634 |
1/2✓ Branch 0 taken 24814 times.
✗ Branch 1 not taken.
|
24814 | if (hc) { |
635 | 24814 | pix_op[op_index](dest_cb, ptr_cb, uvlinesize, hc, uvsx, uvsy); | |
636 | 24814 | pix_op[op_index](dest_cr, ptr_cr, uvlinesize, hc, uvsx, uvsy); | |
637 | } | ||
638 | } | ||
639 | // FIXME h261 lowres loop filter | ||
640 | 24814 | } | |
641 | |||
642 | 31575 | static inline void chroma_4mv_motion_lowres(MpegEncContext *s, | |
643 | uint8_t *dest_cb, uint8_t *dest_cr, | ||
644 | uint8_t *const *ref_picture, | ||
645 | const h264_chroma_mc_func * pix_op, | ||
646 | int mx, int my) | ||
647 | { | ||
648 | 31575 | const int lowres = s->avctx->lowres; | |
649 | 31575 | const int op_index = lowres; | |
650 | 31575 | const int block_s = 8 >> lowres; | |
651 | 31575 | const int s_mask = (2 << lowres) - 1; | |
652 | 31575 | const int h_edge_pos = s->h_edge_pos >> lowres + 1; | |
653 | 31575 | const int v_edge_pos = s->v_edge_pos >> lowres + 1; | |
654 | 31575 | int emu = 0, src_x, src_y, sx, sy; | |
655 | ptrdiff_t offset; | ||
656 | const uint8_t *ptr; | ||
657 | |||
658 | av_assert2(op_index <= 3); | ||
659 | |||
660 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31575 times.
|
31575 | if (s->quarter_sample) { |
661 | ✗ | mx /= 2; | |
662 | ✗ | my /= 2; | |
663 | } | ||
664 | |||
665 | /* In case of 8X8, we construct a single chroma motion vector | ||
666 | with a special rounding */ | ||
667 | 31575 | mx = ff_h263_round_chroma(mx); | |
668 | 31575 | my = ff_h263_round_chroma(my); | |
669 | |||
670 | 31575 | sx = mx & s_mask; | |
671 | 31575 | sy = my & s_mask; | |
672 | 31575 | src_x = s->mb_x * block_s + (mx >> lowres + 1); | |
673 | 31575 | src_y = s->mb_y * block_s + (my >> lowres + 1); | |
674 | |||
675 | 31575 | offset = src_y * s->uvlinesize + src_x; | |
676 | 31575 | ptr = ref_picture[1] + offset; | |
677 |
1/2✓ Branch 0 taken 31575 times.
✗ Branch 1 not taken.
|
31575 | if ((unsigned) src_x > FFMAX(h_edge_pos - (!!sx) - block_s, 0) || |
678 |
2/2✓ Branch 0 taken 144 times.
✓ Branch 1 taken 31431 times.
|
31575 | (unsigned) src_y > FFMAX(v_edge_pos - (!!sy) - block_s, 0)) { |
679 | 144 | s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr, | |
680 | s->uvlinesize, s->uvlinesize, | ||
681 | 9, 9, | ||
682 | src_x, src_y, h_edge_pos, v_edge_pos); | ||
683 | 144 | ptr = s->sc.edge_emu_buffer; | |
684 | 144 | emu = 1; | |
685 | } | ||
686 | 31575 | sx = (sx << 2) >> lowres; | |
687 | 31575 | sy = (sy << 2) >> lowres; | |
688 | 31575 | pix_op[op_index](dest_cb, ptr, s->uvlinesize, block_s, sx, sy); | |
689 | |||
690 | 31575 | ptr = ref_picture[2] + offset; | |
691 |
2/2✓ Branch 0 taken 144 times.
✓ Branch 1 taken 31431 times.
|
31575 | if (emu) { |
692 | 144 | s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr, | |
693 | s->uvlinesize, s->uvlinesize, | ||
694 | 9, 9, | ||
695 | src_x, src_y, h_edge_pos, v_edge_pos); | ||
696 | 144 | ptr = s->sc.edge_emu_buffer; | |
697 | } | ||
698 | 31575 | pix_op[op_index](dest_cr, ptr, s->uvlinesize, block_s, sx, sy); | |
699 | 31575 | } | |
700 | |||
701 | /** | ||
702 | * motion compensation of a single macroblock | ||
703 | * @param s context | ||
704 | * @param dest_y luma destination pointer | ||
705 | * @param dest_cb chroma cb/u destination pointer | ||
706 | * @param dest_cr chroma cr/v destination pointer | ||
707 | * @param dir direction (0->forward, 1->backward) | ||
708 | * @param ref_picture array[3] of pointers to the 3 planes of the reference picture | ||
709 | * @param pix_op halfpel motion compensation function (average or put normally) | ||
710 | * the motion vectors are taken from s->mv and the MV type from s->mv_type | ||
711 | */ | ||
712 | 56389 | static inline void MPV_motion_lowres(MpegEncContext *s, | |
713 | uint8_t *dest_y, uint8_t *dest_cb, | ||
714 | uint8_t *dest_cr, | ||
715 | int dir, uint8_t *const *ref_picture, | ||
716 | const h264_chroma_mc_func *pix_op) | ||
717 | { | ||
718 | int mx, my; | ||
719 | int mb_x, mb_y; | ||
720 | 56389 | const int lowres = s->avctx->lowres; | |
721 | 56389 | const int block_s = 8 >>lowres; | |
722 | |||
723 | 56389 | mb_x = s->mb_x; | |
724 | 56389 | mb_y = s->mb_y; | |
725 | |||
726 |
2/6✓ Branch 0 taken 24814 times.
✓ Branch 1 taken 31575 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
56389 | switch (s->mv_type) { |
727 | 24814 | case MV_TYPE_16X16: | |
728 | 24814 | mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
729 | 0, 0, 0, | ||
730 | ref_picture, pix_op, | ||
731 | s->mv[dir][0][0], s->mv[dir][0][1], | ||
732 | 2 * block_s, mb_y); | ||
733 | 24814 | break; | |
734 | 31575 | case MV_TYPE_8X8: | |
735 | 31575 | mx = 0; | |
736 | 31575 | my = 0; | |
737 |
2/2✓ Branch 0 taken 126300 times.
✓ Branch 1 taken 31575 times.
|
157875 | for (int i = 0; i < 4; i++) { |
738 | 126300 | hpel_motion_lowres(s, dest_y + ((i & 1) + (i >> 1) * | |
739 | 126300 | s->linesize) * block_s, | |
740 | ref_picture[0], 0, 0, | ||
741 | 126300 | (2 * mb_x + (i & 1)) * block_s, | |
742 | 126300 | (2 * mb_y + (i >> 1)) * block_s, | |
743 | s->width, s->height, s->linesize, | ||
744 | 126300 | s->h_edge_pos >> lowres, s->v_edge_pos >> lowres, | |
745 | block_s, block_s, pix_op, | ||
746 | s->mv[dir][i][0], s->mv[dir][i][1]); | ||
747 | |||
748 | 126300 | mx += s->mv[dir][i][0]; | |
749 | 126300 | my += s->mv[dir][i][1]; | |
750 | } | ||
751 | |||
752 | if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) | ||
753 | 31575 | chroma_4mv_motion_lowres(s, dest_cb, dest_cr, ref_picture, | |
754 | pix_op, mx, my); | ||
755 | 31575 | break; | |
756 | ✗ | case MV_TYPE_FIELD: | |
757 | ✗ | if (s->picture_structure == PICT_FRAME) { | |
758 | /* top field */ | ||
759 | ✗ | mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
760 | 1, 0, s->field_select[dir][0], | ||
761 | ref_picture, pix_op, | ||
762 | s->mv[dir][0][0], s->mv[dir][0][1], | ||
763 | block_s, mb_y); | ||
764 | /* bottom field */ | ||
765 | ✗ | mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
766 | 1, 1, s->field_select[dir][1], | ||
767 | ref_picture, pix_op, | ||
768 | s->mv[dir][1][0], s->mv[dir][1][1], | ||
769 | block_s, mb_y); | ||
770 | } else { | ||
771 | ✗ | if (s->picture_structure != s->field_select[dir][0] + 1 && | |
772 | ✗ | s->pict_type != AV_PICTURE_TYPE_B && !s->first_field) { | |
773 | ✗ | ref_picture = s->cur_pic.ptr->f->data; | |
774 | } | ||
775 | ✗ | mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
776 | 0, 0, s->field_select[dir][0], | ||
777 | ref_picture, pix_op, | ||
778 | s->mv[dir][0][0], | ||
779 | s->mv[dir][0][1], 2 * block_s, mb_y >> 1); | ||
780 | } | ||
781 | ✗ | break; | |
782 | ✗ | case MV_TYPE_16X8: | |
783 | ✗ | for (int i = 0; i < 2; i++) { | |
784 | uint8_t *const *ref2picture; | ||
785 | |||
786 | ✗ | if (s->picture_structure == s->field_select[dir][i] + 1 || | |
787 | ✗ | s->pict_type == AV_PICTURE_TYPE_B || s->first_field) { | |
788 | ✗ | ref2picture = ref_picture; | |
789 | } else { | ||
790 | ✗ | ref2picture = s->cur_pic.ptr->f->data; | |
791 | } | ||
792 | |||
793 | ✗ | mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
794 | 0, 0, s->field_select[dir][i], | ||
795 | ref2picture, pix_op, | ||
796 | ✗ | s->mv[dir][i][0], s->mv[dir][i][1] + | |
797 | ✗ | 2 * block_s * i, block_s, mb_y >> 1); | |
798 | |||
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; | |
802 | } | ||
803 | ✗ | break; | |
804 | ✗ | case MV_TYPE_DMV: | |
805 | ✗ | if (s->picture_structure == PICT_FRAME) { | |
806 | ✗ | for (int i = 0; i < 2; i++) { | |
807 | ✗ | for (int j = 0; j < 2; j++) { | |
808 | ✗ | mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
809 | 1, j, j ^ i, | ||
810 | ref_picture, pix_op, | ||
811 | ✗ | s->mv[dir][2 * i + j][0], | |
812 | ✗ | s->mv[dir][2 * i + j][1], | |
813 | block_s, mb_y); | ||
814 | } | ||
815 | ✗ | pix_op = s->h264chroma.avg_h264_chroma_pixels_tab; | |
816 | } | ||
817 | } else { | ||
818 | ✗ | for (int i = 0; i < 2; i++) { | |
819 | ✗ | mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
820 | ✗ | 0, 0, s->picture_structure != i + 1, | |
821 | ref_picture, pix_op, | ||
822 | ✗ | s->mv[dir][2 * i][0],s->mv[dir][2 * i][1], | |
823 | 2 * block_s, mb_y >> 1); | ||
824 | |||
825 | // after put we make avg of the same block | ||
826 | ✗ | pix_op = s->h264chroma.avg_h264_chroma_pixels_tab; | |
827 | |||
828 | // opposite parity is always in the same | ||
829 | // frame if this is second field | ||
830 | ✗ | if (!s->first_field) { | |
831 | ✗ | ref_picture = s->cur_pic.ptr->f->data; | |
832 | } | ||
833 | } | ||
834 | } | ||
835 | ✗ | break; | |
836 | 56389 | default: | |
837 | av_assert2(0); | ||
838 | } | ||
839 | 56389 | } | |
840 | |||
841 | /** | ||
842 | * find the lowest MB row referenced in the MVs | ||
843 | */ | ||
844 | 60133 | static int lowest_referenced_row(MpegEncContext *s, int dir) | |
845 | { | ||
846 | 60133 | int my_max = INT_MIN, my_min = INT_MAX, qpel_shift = !s->quarter_sample; | |
847 | int off, mvs; | ||
848 | |||
849 |
2/4✓ Branch 0 taken 60133 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 60133 times.
|
60133 | if (s->picture_structure != PICT_FRAME || s->mcsel) |
850 | ✗ | goto unhandled; | |
851 | |||
852 |
1/4✓ Branch 0 taken 60133 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
60133 | switch (s->mv_type) { |
853 | 60133 | case MV_TYPE_16X16: | |
854 | 60133 | mvs = 1; | |
855 | 60133 | break; | |
856 | ✗ | case MV_TYPE_16X8: | |
857 | ✗ | mvs = 2; | |
858 | ✗ | break; | |
859 | ✗ | case MV_TYPE_8X8: | |
860 | ✗ | mvs = 4; | |
861 | ✗ | break; | |
862 | ✗ | default: | |
863 | ✗ | goto unhandled; | |
864 | } | ||
865 | |||
866 |
2/2✓ Branch 0 taken 60133 times.
✓ Branch 1 taken 60133 times.
|
120266 | for (int i = 0; i < mvs; i++) { |
867 | 60133 | int my = s->mv[dir][i][1]; | |
868 | 60133 | my_max = FFMAX(my_max, my); | |
869 | 60133 | my_min = FFMIN(my_min, my); | |
870 | } | ||
871 | |||
872 | 60133 | off = ((FFMAX(-my_min, my_max) << qpel_shift) + 63) >> 6; | |
873 | |||
874 | 60133 | return av_clip(s->mb_y + off, 0, s->mb_height - 1); | |
875 | ✗ | unhandled: | |
876 | ✗ | return s->mb_height - 1; | |
877 | } | ||
878 | |||
879 | /* add block[] to dest[] */ | ||
880 | 23105814 | static inline void add_dct(MpegEncContext *s, | |
881 | int16_t *block, int i, uint8_t *dest, int line_size) | ||
882 | { | ||
883 |
2/2✓ Branch 0 taken 8317938 times.
✓ Branch 1 taken 14787876 times.
|
23105814 | if (s->block_last_index[i] >= 0) { |
884 | 8317938 | s->idsp.idct_add(dest, line_size, block); | |
885 | } | ||
886 | 23105814 | } | |
887 | |||
888 | /* put block[] to dest[] */ | ||
889 | 1758666 | static inline void put_dct(MpegEncContext *s, | |
890 | int16_t *block, int i, uint8_t *dest, int line_size, int qscale) | ||
891 | { | ||
892 | 1758666 | s->dct_unquantize_intra(s, block, i, qscale); | |
893 | 1758666 | s->idsp.idct_put(dest, line_size, block); | |
894 | 1758666 | } | |
895 | |||
896 | 2942796 | static inline void add_dequant_dct(MpegEncContext *s, | |
897 | int16_t *block, int i, uint8_t *dest, int line_size, int qscale) | ||
898 | { | ||
899 |
2/2✓ Branch 0 taken 1108259 times.
✓ Branch 1 taken 1834537 times.
|
2942796 | if (s->block_last_index[i] >= 0) { |
900 | 1108259 | s->dct_unquantize_inter(s, block, i, qscale); | |
901 | |||
902 | 1108259 | s->idsp.idct_add(dest, line_size, block); | |
903 | } | ||
904 | 2942796 | } | |
905 | |||
906 | #define NOT_MPEG12_H261 0 | ||
907 | #define MAY_BE_MPEG12_H261 1 | ||
908 | #define DEFINITELY_MPEG12_H261 2 | ||
909 | |||
910 | /* generic function called after a macroblock has been parsed by the decoder. | ||
911 | |||
912 | Important variables used: | ||
913 | s->mb_intra : true if intra macroblock | ||
914 | s->mv_dir : motion vector direction | ||
915 | s->mv_type : motion vector type | ||
916 | s->mv : motion vector | ||
917 | s->interlaced_dct : true if interlaced dct used (mpeg2) | ||
918 | */ | ||
919 | static av_always_inline | ||
920 | 5142214 | void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64], | |
921 | int lowres_flag, int is_mpeg12) | ||
922 | { | ||
923 | #define IS_MPEG12_H261(s) (is_mpeg12 == MAY_BE_MPEG12_H261 ? ((s)->out_format <= FMT_H261) : is_mpeg12) | ||
924 | 5142214 | uint8_t *dest_y = s->dest[0], *dest_cb = s->dest[1], *dest_cr = s->dest[2]; | |
925 | int dct_linesize, dct_offset; | ||
926 | 5142214 | const int linesize = s->cur_pic.linesize[0]; //not s->linesize as this would be wrong for field pics | |
927 | 5142214 | const int uvlinesize = s->cur_pic.linesize[1]; | |
928 |
2/2✓ Branch 0 taken 43500 times.
✓ Branch 1 taken 5098714 times.
|
5142214 | const int block_size = lowres_flag ? 8 >> s->avctx->lowres : 8; |
929 | |||
930 | 5142214 | dct_linesize = linesize << s->interlaced_dct; | |
931 |
2/2✓ Branch 0 taken 4959279 times.
✓ Branch 1 taken 182935 times.
|
5142214 | dct_offset = s->interlaced_dct ? linesize : linesize * block_size; |
932 | |||
933 |
2/2✓ Branch 0 taken 4509267 times.
✓ Branch 1 taken 632947 times.
|
5142214 | if (!s->mb_intra) { |
934 | /* motion handling */ | ||
935 |
2/2✓ Branch 0 taken 2129717 times.
✓ Branch 1 taken 2379550 times.
|
4509267 | if (HAVE_THREADS && is_mpeg12 != DEFINITELY_MPEG12_H261 && |
936 |
2/2✓ Branch 0 taken 60133 times.
✓ Branch 1 taken 2069584 times.
|
2129717 | s->avctx->active_thread_type & FF_THREAD_FRAME) { |
937 |
1/2✓ Branch 0 taken 60133 times.
✗ Branch 1 not taken.
|
60133 | if (s->mv_dir & MV_DIR_FORWARD) { |
938 | 60133 | ff_thread_progress_await(&s->last_pic.ptr->progress, | |
939 | lowest_referenced_row(s, 0)); | ||
940 | } | ||
941 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 60133 times.
|
60133 | if (s->mv_dir & MV_DIR_BACKWARD) { |
942 | ✗ | ff_thread_progress_await(&s->next_pic.ptr->progress, | |
943 | lowest_referenced_row(s, 1)); | ||
944 | } | ||
945 | } | ||
946 | |||
947 |
2/2✓ Branch 0 taken 41123 times.
✓ Branch 1 taken 4468144 times.
|
4509267 | if (lowres_flag) { |
948 | 41123 | const h264_chroma_mc_func *op_pix = s->h264chroma.put_h264_chroma_pixels_tab; | |
949 | |||
950 |
2/2✓ Branch 0 taken 37429 times.
✓ Branch 1 taken 3694 times.
|
41123 | if (s->mv_dir & MV_DIR_FORWARD) { |
951 | 37429 | MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, s->last_pic.data, op_pix); | |
952 | 37429 | op_pix = s->h264chroma.avg_h264_chroma_pixels_tab; | |
953 | } | ||
954 |
2/2✓ Branch 0 taken 18960 times.
✓ Branch 1 taken 22163 times.
|
41123 | if (s->mv_dir & MV_DIR_BACKWARD) { |
955 | 18960 | MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 1, s->next_pic.data, op_pix); | |
956 | } | ||
957 | } else { | ||
958 | const op_pixels_func (*op_pix)[4]; | ||
959 | const qpel_mc_func (*op_qpix)[16]; | ||
960 | |||
961 |
5/6✓ Branch 0 taken 2088594 times.
✓ Branch 1 taken 2379550 times.
✓ Branch 2 taken 804834 times.
✓ Branch 3 taken 1283760 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 804834 times.
|
4468144 | if ((is_mpeg12 == DEFINITELY_MPEG12_H261 || !s->no_rounding) || s->pict_type == AV_PICTURE_TYPE_B) { |
962 | 3663310 | op_pix = s->hdsp.put_pixels_tab; | |
963 | 3663310 | op_qpix = s->qdsp.put_qpel_pixels_tab; | |
964 | } else { | ||
965 | 804834 | op_pix = s->hdsp.put_no_rnd_pixels_tab; | |
966 | 804834 | op_qpix = s->qdsp.put_no_rnd_qpel_pixels_tab; | |
967 | } | ||
968 |
2/2✓ Branch 0 taken 4164500 times.
✓ Branch 1 taken 303644 times.
|
4468144 | if (s->mv_dir & MV_DIR_FORWARD) { |
969 | 4164500 | ff_mpv_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_pic.data, op_pix, op_qpix); | |
970 | 4164500 | op_pix = s->hdsp.avg_pixels_tab; | |
971 | 4164500 | op_qpix = s->qdsp.avg_qpel_pixels_tab; | |
972 | } | ||
973 |
2/2✓ Branch 0 taken 928015 times.
✓ Branch 1 taken 3540129 times.
|
4468144 | if (s->mv_dir & MV_DIR_BACKWARD) { |
974 | 928015 | ff_mpv_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_pic.data, op_pix, op_qpix); | |
975 | } | ||
976 | } | ||
977 | |||
978 | /* skip dequant / idct if we are really late ;) */ | ||
979 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 4509267 times.
|
4509267 | if (s->avctx->skip_idct) { |
980 | ✗ | if ( (s->avctx->skip_idct >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) | |
981 | ✗ | ||(s->avctx->skip_idct >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) | |
982 | ✗ | || s->avctx->skip_idct >= AVDISCARD_ALL) | |
983 | ✗ | return; | |
984 | } | ||
985 | |||
986 | /* add dct residue */ | ||
987 |
7/8✓ Branch 0 taken 41123 times.
✓ Branch 1 taken 4468144 times.
✓ Branch 2 taken 41123 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2088594 times.
✓ Branch 5 taken 2379550 times.
✓ Branch 6 taken 1760849 times.
✓ Branch 7 taken 368868 times.
|
4509267 | if (!(IS_MPEG12_H261(s) || s->msmpeg4_version != MSMP4_UNUSED || |
988 |
4/4✓ Branch 0 taken 1385018 times.
✓ Branch 1 taken 375831 times.
✓ Branch 2 taken 114635 times.
✓ Branch 3 taken 1270383 times.
|
1760849 | (s->codec_id == AV_CODEC_ID_MPEG4 && !s->mpeg_quant))) { |
989 | 490466 | add_dequant_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale); | |
990 | 490466 | add_dequant_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale); | |
991 | 490466 | add_dequant_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale); | |
992 | 490466 | add_dequant_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale); | |
993 | |||
994 | 490466 | if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { | |
995 | av_assert2(s->chroma_y_shift); | ||
996 | 490466 | add_dequant_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale); | |
997 | 490466 | add_dequant_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale); | |
998 | } | ||
999 |
5/6✓ Branch 0 taken 1639251 times.
✓ Branch 1 taken 2379550 times.
✓ Branch 2 taken 1639251 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 1449102 times.
✓ Branch 5 taken 190149 times.
|
4018801 | } else if (is_mpeg12 == DEFINITELY_MPEG12_H261 || lowres_flag || (s->codec_id != AV_CODEC_ID_WMV2)) { |
1000 | 3828652 | add_dct(s, block[0], 0, dest_y , dct_linesize); | |
1001 | 3828652 | add_dct(s, block[1], 1, dest_y + block_size, dct_linesize); | |
1002 | 3828652 | add_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize); | |
1003 | 3828652 | add_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize); | |
1004 | |||
1005 | 3828652 | if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { | |
1006 |
2/2✓ Branch 0 taken 3761701 times.
✓ Branch 1 taken 66951 times.
|
3828652 | if (s->chroma_y_shift) {//Chroma420 |
1007 | 3761701 | add_dct(s, block[4], 4, dest_cb, uvlinesize); | |
1008 | 3761701 | add_dct(s, block[5], 5, dest_cr, uvlinesize); | |
1009 | } else { | ||
1010 | //chroma422 | ||
1011 | 66951 | dct_linesize = uvlinesize << s->interlaced_dct; | |
1012 |
2/2✓ Branch 0 taken 65730 times.
✓ Branch 1 taken 1221 times.
|
66951 | dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize*block_size; |
1013 | |||
1014 | 66951 | add_dct(s, block[4], 4, dest_cb, dct_linesize); | |
1015 | 66951 | add_dct(s, block[5], 5, dest_cr, dct_linesize); | |
1016 | 66951 | add_dct(s, block[6], 6, dest_cb + dct_offset, dct_linesize); | |
1017 | 66951 | add_dct(s, block[7], 7, dest_cr + dct_offset, dct_linesize); | |
1018 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 66951 times.
|
66951 | if (!s->chroma_x_shift) {//Chroma444 |
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); | |
1023 | } | ||
1024 | } | ||
1025 | } //fi gray | ||
1026 | } else if (CONFIG_WMV2_DECODER) { | ||
1027 | 190149 | ff_wmv2_add_mb(s, block, dest_y, dest_cb, dest_cr); | |
1028 | } | ||
1029 | } else { | ||
1030 | /* Only MPEG-4 Simple Studio Profile is supported in > 8-bit mode. | ||
1031 | TODO: Integrate 10-bit properly into mpegvideo.c so that ER works properly */ | ||
1032 |
2/2✓ Branch 0 taken 294461 times.
✓ Branch 1 taken 338486 times.
|
632947 | if (is_mpeg12 != DEFINITELY_MPEG12_H261 && CONFIG_MPEG4_DECODER && |
1033 | /* s->codec_id == AV_CODEC_ID_MPEG4 && */ | ||
1034 |
2/2✓ Branch 0 taken 1350 times.
✓ Branch 1 taken 293111 times.
|
294461 | s->avctx->bits_per_raw_sample > 8) { |
1035 | 1350 | ff_mpeg4_decode_studio(s, dest_y, dest_cb, dest_cr, block_size, | |
1036 | uvlinesize, dct_linesize, dct_offset); | ||
1037 |
4/4✓ Branch 0 taken 2377 times.
✓ Branch 1 taken 629220 times.
✓ Branch 2 taken 293111 times.
✓ Branch 3 taken 338486 times.
|
631597 | } else if (!IS_MPEG12_H261(s)) { |
1038 | /* dct only in intra block */ | ||
1039 | 293111 | put_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale); | |
1040 | 293111 | put_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale); | |
1041 | 293111 | put_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale); | |
1042 | 293111 | put_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale); | |
1043 | |||
1044 | if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { | ||
1045 |
1/2✓ Branch 0 taken 293111 times.
✗ Branch 1 not taken.
|
293111 | if (s->chroma_y_shift) { |
1046 | 293111 | put_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale); | |
1047 | 293111 | put_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale); | |
1048 | } else { | ||
1049 | ✗ | dct_offset >>= 1; | |
1050 | ✗ | dct_linesize >>= 1; | |
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); | |
1055 | } | ||
1056 | } | ||
1057 | } else { | ||
1058 | 338486 | s->idsp.idct_put(dest_y, dct_linesize, block[0]); | |
1059 | 338486 | s->idsp.idct_put(dest_y + block_size, dct_linesize, block[1]); | |
1060 | 338486 | s->idsp.idct_put(dest_y + dct_offset, dct_linesize, block[2]); | |
1061 | 338486 | s->idsp.idct_put(dest_y + dct_offset + block_size, dct_linesize, block[3]); | |
1062 | |||
1063 | if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { | ||
1064 |
2/2✓ Branch 0 taken 284327 times.
✓ Branch 1 taken 54159 times.
|
338486 | if (s->chroma_y_shift) { |
1065 | 284327 | s->idsp.idct_put(dest_cb, uvlinesize, block[4]); | |
1066 | 284327 | s->idsp.idct_put(dest_cr, uvlinesize, block[5]); | |
1067 | } else { | ||
1068 | 54159 | dct_linesize = uvlinesize << s->interlaced_dct; | |
1069 |
2/2✓ Branch 0 taken 54119 times.
✓ Branch 1 taken 40 times.
|
54159 | dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize*block_size; |
1070 | |||
1071 | 54159 | s->idsp.idct_put(dest_cb, dct_linesize, block[4]); | |
1072 | 54159 | s->idsp.idct_put(dest_cr, dct_linesize, block[5]); | |
1073 | 54159 | s->idsp.idct_put(dest_cb + dct_offset, dct_linesize, block[6]); | |
1074 | 54159 | s->idsp.idct_put(dest_cr + dct_offset, dct_linesize, block[7]); | |
1075 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 54159 times.
|
54159 | if (!s->chroma_x_shift) { //Chroma444 |
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]); | |
1080 | } | ||
1081 | } | ||
1082 | } //gray | ||
1083 | } | ||
1084 | } | ||
1085 | } | ||
1086 | |||
1087 | 5142214 | void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64]) | |
1088 | { | ||
1089 | 5142214 | const int mb_xy = s->mb_y * s->mb_stride + s->mb_x; | |
1090 | 5142214 | uint8_t *mbskip_ptr = &s->mbskip_table[mb_xy]; | |
1091 | |||
1092 | 5142214 | s->cur_pic.qscale_table[mb_xy] = s->qscale; | |
1093 | |||
1094 | /* avoid copy if macroblock skipped in last frame too */ | ||
1095 |
2/2✓ Branch 0 taken 387911 times.
✓ Branch 1 taken 4754303 times.
|
5142214 | if (s->mb_skipped) { |
1096 | 387911 | s->mb_skipped = 0; | |
1097 | av_assert2(s->pict_type != AV_PICTURE_TYPE_I); | ||
1098 | 387911 | *mbskip_ptr = 1; | |
1099 |
2/2✓ Branch 0 taken 1117924 times.
✓ Branch 1 taken 3636379 times.
|
4754303 | } else if (!s->cur_pic.reference) { |
1100 | 1117924 | *mbskip_ptr = 1; | |
1101 | } else{ | ||
1102 | 3636379 | *mbskip_ptr = 0; /* not skipped */ | |
1103 | } | ||
1104 | |||
1105 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5142214 times.
|
5142214 | if (s->avctx->debug & FF_DEBUG_DCT_COEFF) { |
1106 | /* print DCT coefficients */ | ||
1107 | ✗ | av_log(s->avctx, AV_LOG_DEBUG, "DCT coeffs of MB at %dx%d:\n", s->mb_x, s->mb_y); | |
1108 | ✗ | for (int i = 0; i < 6; i++) { | |
1109 | ✗ | for (int j = 0; j < 64; j++) { | |
1110 | ✗ | av_log(s->avctx, AV_LOG_DEBUG, "%5d", | |
1111 | ✗ | block[i][s->idsp.idct_permutation[j]]); | |
1112 | } | ||
1113 | ✗ | av_log(s->avctx, AV_LOG_DEBUG, "\n"); | |
1114 | } | ||
1115 | } | ||
1116 | |||
1117 | av_assert2((s->out_format <= FMT_H261) == (s->out_format == FMT_H261 || s->out_format == FMT_MPEG1)); | ||
1118 |
2/2✓ Branch 0 taken 5098714 times.
✓ Branch 1 taken 43500 times.
|
5142214 | if (!s->avctx->lowres) { |
1119 | #if !CONFIG_SMALL | ||
1120 |
2/2✓ Branch 0 taken 2718036 times.
✓ Branch 1 taken 2380678 times.
|
5098714 | if (s->out_format <= FMT_H261) |
1121 | 2718036 | mpv_reconstruct_mb_internal(s, block, 0, DEFINITELY_MPEG12_H261); | |
1122 | else | ||
1123 | 2380678 | mpv_reconstruct_mb_internal(s, block, 0, NOT_MPEG12_H261); | |
1124 | #else | ||
1125 | mpv_reconstruct_mb_internal(s, block, 0, MAY_BE_MPEG12_H261); | ||
1126 | #endif | ||
1127 | } else | ||
1128 | 43500 | mpv_reconstruct_mb_internal(s, block, 1, MAY_BE_MPEG12_H261); | |
1129 | 5142214 | } | |
1130 |