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 "h264chroma.h" | ||
36 | #include "internal.h" | ||
37 | #include "mpegutils.h" | ||
38 | #include "mpegvideo.h" | ||
39 | #include "mpegvideodec.h" | ||
40 | #include "mpeg4videodec.h" | ||
41 | #include "refstruct.h" | ||
42 | #include "thread.h" | ||
43 | #include "threadprogress.h" | ||
44 | #include "wmv2dec.h" | ||
45 | |||
46 | 636 | int ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx) | |
47 | { | ||
48 | enum ThreadingStatus thread_status; | ||
49 | |||
50 | 636 | ff_mpv_common_defaults(s); | |
51 | |||
52 | 636 | s->avctx = avctx; | |
53 | 636 | s->width = avctx->coded_width; | |
54 | 636 | s->height = avctx->coded_height; | |
55 | 636 | s->codec_id = avctx->codec->id; | |
56 | 636 | s->workaround_bugs = avctx->workaround_bugs; | |
57 | |||
58 | /* convert fourcc to upper case */ | ||
59 | 636 | s->codec_tag = ff_toupper4(avctx->codec_tag); | |
60 | |||
61 | 636 | ff_mpv_idct_init(s); | |
62 | |||
63 | 636 | ff_h264chroma_init(&s->h264chroma, 8); //for lowres | |
64 | |||
65 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 636 times.
|
636 | if (s->picture_pool) // VC-1 can call this multiple times |
66 | ✗ | return 0; | |
67 | |||
68 | 636 | thread_status = ff_thread_sync_ref(avctx, offsetof(MpegEncContext, picture_pool)); | |
69 |
2/2✓ Branch 0 taken 628 times.
✓ Branch 1 taken 8 times.
|
636 | if (thread_status != FF_THREAD_IS_COPY) { |
70 | 628 | s->picture_pool = ff_mpv_alloc_pic_pool(thread_status != FF_THREAD_NO_FRAME_THREADING); | |
71 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 628 times.
|
628 | if (!s->picture_pool) |
72 | ✗ | return AVERROR(ENOMEM); | |
73 | } | ||
74 | 636 | return 0; | |
75 | } | ||
76 | |||
77 | 18 | int ff_mpeg_update_thread_context(AVCodecContext *dst, | |
78 | const AVCodecContext *src) | ||
79 | { | ||
80 | 18 | MpegEncContext *const s1 = src->priv_data; | |
81 | 18 | MpegEncContext *const s = dst->priv_data; | |
82 | int ret; | ||
83 | |||
84 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
|
18 | if (dst == src) |
85 | ✗ | return 0; | |
86 | |||
87 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
|
18 | av_assert0(s != s1); |
88 | |||
89 | // FIXME can parameters change on I-frames? | ||
90 | // in that case dst may need a reinit | ||
91 |
2/2✓ Branch 0 taken 8 times.
✓ Branch 1 taken 10 times.
|
18 | if (!s->context_initialized) { |
92 | 8 | void *private_ctx = s->private_ctx; | |
93 | int err; | ||
94 | 8 | memcpy(s, s1, sizeof(*s)); | |
95 | |||
96 | 8 | s->context_initialized = 0; | |
97 | 8 | s->context_reinit = 0; | |
98 | 8 | s->avctx = dst; | |
99 | 8 | s->private_ctx = private_ctx; | |
100 | 8 | s->bitstream_buffer = NULL; | |
101 | 8 | s->bitstream_buffer_size = s->allocated_bitstream_buffer_size = 0; | |
102 | |||
103 |
1/2✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
|
8 | if (s1->context_initialized) { |
104 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
|
8 | if ((err = ff_mpv_common_init(s)) < 0) |
105 | ✗ | return err; | |
106 | } | ||
107 | } | ||
108 | |||
109 |
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) { |
110 | ✗ | s->height = s1->height; | |
111 | ✗ | s->width = s1->width; | |
112 | ✗ | if ((ret = ff_mpv_common_frame_size_change(s)) < 0) | |
113 | ✗ | return ret; | |
114 | } | ||
115 | |||
116 | 18 | s->quarter_sample = s1->quarter_sample; | |
117 | |||
118 | 18 | s->picture_number = s1->picture_number; | |
119 | |||
120 | 18 | ff_mpv_replace_picture(&s->cur_pic, &s1->cur_pic); | |
121 | 18 | ff_mpv_replace_picture(&s->last_pic, &s1->last_pic); | |
122 | 18 | ff_mpv_replace_picture(&s->next_pic, &s1->next_pic); | |
123 | |||
124 | 18 | s->linesize = s1->linesize; | |
125 | 18 | s->uvlinesize = s1->uvlinesize; | |
126 | |||
127 | // Error/bug resilience | ||
128 | 18 | s->workaround_bugs = s1->workaround_bugs; | |
129 | 18 | s->padding_bug_score = s1->padding_bug_score; | |
130 | |||
131 | // MPEG-4 timing info | ||
132 | 18 | memcpy(&s->last_time_base, &s1->last_time_base, | |
133 | 18 | (char *) &s1->pb_field_time + sizeof(s1->pb_field_time) - | |
134 | 18 | (char *) &s1->last_time_base); | |
135 | |||
136 | // B-frame info | ||
137 | 18 | s->max_b_frames = s1->max_b_frames; | |
138 | 18 | s->low_delay = s1->low_delay; | |
139 | |||
140 | // DivX handling (doesn't work) | ||
141 | 18 | s->divx_packed = s1->divx_packed; | |
142 | |||
143 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
|
18 | if (s1->bitstream_buffer) { |
144 | ✗ | av_fast_padded_malloc(&s->bitstream_buffer, | |
145 | &s->allocated_bitstream_buffer_size, | ||
146 | ✗ | s1->bitstream_buffer_size); | |
147 | ✗ | if (!s->bitstream_buffer) { | |
148 | ✗ | s->bitstream_buffer_size = 0; | |
149 | ✗ | return AVERROR(ENOMEM); | |
150 | } | ||
151 | ✗ | s->bitstream_buffer_size = s1->bitstream_buffer_size; | |
152 | ✗ | memcpy(s->bitstream_buffer, s1->bitstream_buffer, | |
153 | ✗ | s1->bitstream_buffer_size); | |
154 | } | ||
155 | |||
156 | // MPEG-2/interlacing info | ||
157 | 18 | memcpy(&s->progressive_sequence, &s1->progressive_sequence, | |
158 | (char *) &s1->rtp_mode - (char *) &s1->progressive_sequence); | ||
159 | |||
160 | 18 | return 0; | |
161 | } | ||
162 | |||
163 | 636 | int ff_mpv_decode_close(AVCodecContext *avctx) | |
164 | { | ||
165 | 636 | MpegEncContext *s = avctx->priv_data; | |
166 | |||
167 | 636 | ff_refstruct_pool_uninit(&s->picture_pool); | |
168 | 636 | ff_mpv_common_end(s); | |
169 | 636 | return 0; | |
170 | } | ||
171 | |||
172 | 47 | int ff_mpv_common_frame_size_change(MpegEncContext *s) | |
173 | { | ||
174 | 47 | int err = 0; | |
175 | |||
176 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
|
47 | if (!s->context_initialized) |
177 | ✗ | return AVERROR(EINVAL); | |
178 | |||
179 | 47 | ff_mpv_free_context_frame(s); | |
180 | |||
181 | 47 | ff_mpv_unref_picture(&s->last_pic); | |
182 | 47 | ff_mpv_unref_picture(&s->next_pic); | |
183 | 47 | ff_mpv_unref_picture(&s->cur_pic); | |
184 | |||
185 |
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) && |
186 | 47 | (err = av_image_check_size(s->width, s->height, 0, s->avctx)) < 0) | |
187 | ✗ | goto fail; | |
188 | |||
189 | /* set chroma shifts */ | ||
190 | 47 | err = av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt, | |
191 | &s->chroma_x_shift, | ||
192 | &s->chroma_y_shift); | ||
193 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
|
47 | if (err < 0) |
194 | ✗ | goto fail; | |
195 | |||
196 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 47 times.
|
47 | if ((err = ff_mpv_init_context_frame(s))) |
197 | ✗ | goto fail; | |
198 | |||
199 | 47 | memset(s->thread_context, 0, sizeof(s->thread_context)); | |
200 | 47 | s->thread_context[0] = s; | |
201 | |||
202 |
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) { |
203 | 47 | err = ff_mpv_init_duplicate_contexts(s); | |
204 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 47 times.
|
47 | if (err < 0) |
205 | ✗ | goto fail; | |
206 | } | ||
207 | 47 | s->context_reinit = 0; | |
208 | |||
209 | 47 | return 0; | |
210 | ✗ | fail: | |
211 | ✗ | ff_mpv_free_context_frame(s); | |
212 | ✗ | s->context_reinit = 1; | |
213 | ✗ | return err; | |
214 | } | ||
215 | |||
216 | 11253 | static int alloc_picture(MpegEncContext *s, MPVWorkPicture *dst, int reference) | |
217 | { | ||
218 | 11253 | AVCodecContext *avctx = s->avctx; | |
219 | 11253 | MPVPicture *pic = ff_refstruct_pool_get(s->picture_pool); | |
220 | int ret; | ||
221 | |||
222 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11253 times.
|
11253 | if (!pic) |
223 | ✗ | return AVERROR(ENOMEM); | |
224 | |||
225 | 11253 | dst->ptr = pic; | |
226 | |||
227 | 11253 | pic->reference = reference; | |
228 | |||
229 | /* WM Image / Screen codecs allocate internal buffers with different | ||
230 | * dimensions / colorspaces; ignore user-defined callbacks for these. */ | ||
231 |
1/2✓ Branch 0 taken 11253 times.
✗ Branch 1 not taken.
|
11253 | if (avctx->codec_id != AV_CODEC_ID_WMV3IMAGE && |
232 |
1/2✓ Branch 0 taken 11253 times.
✗ Branch 1 not taken.
|
11253 | avctx->codec_id != AV_CODEC_ID_VC1IMAGE && |
233 |
2/2✓ Branch 0 taken 11171 times.
✓ Branch 1 taken 82 times.
|
11253 | avctx->codec_id != AV_CODEC_ID_MSS2) { |
234 | 11171 | ret = ff_thread_get_buffer(avctx, pic->f, | |
235 | reference ? AV_GET_BUFFER_FLAG_REF : 0); | ||
236 | } else { | ||
237 | 82 | pic->f->width = avctx->width; | |
238 | 82 | pic->f->height = avctx->height; | |
239 | 82 | pic->f->format = avctx->pix_fmt; | |
240 | 82 | ret = avcodec_default_get_buffer2(avctx, pic->f, 0); | |
241 | } | ||
242 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11253 times.
|
11253 | if (ret < 0) |
243 | ✗ | goto fail; | |
244 | |||
245 | 11253 | ret = ff_mpv_pic_check_linesize(avctx, pic->f, &s->linesize, &s->uvlinesize); | |
246 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11253 times.
|
11253 | if (ret < 0) |
247 | ✗ | goto fail; | |
248 | |||
249 | 11253 | ret = ff_hwaccel_frame_priv_alloc(avctx, &pic->hwaccel_picture_private); | |
250 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11253 times.
|
11253 | if (ret < 0) |
251 | ✗ | goto fail; | |
252 | |||
253 | av_assert1(s->mb_width == s->buffer_pools.alloc_mb_width); | ||
254 | av_assert1(s->mb_height == s->buffer_pools.alloc_mb_height || | ||
255 | FFALIGN(s->mb_height, 2) == s->buffer_pools.alloc_mb_height); | ||
256 | av_assert1(s->mb_stride == s->buffer_pools.alloc_mb_stride); | ||
257 | 11253 | ret = ff_mpv_alloc_pic_accessories(s->avctx, dst, &s->sc, | |
258 | &s->buffer_pools, s->mb_height); | ||
259 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11253 times.
|
11253 | if (ret < 0) |
260 | ✗ | goto fail; | |
261 | |||
262 | 11253 | return 0; | |
263 | ✗ | fail: | |
264 | ✗ | ff_mpv_unref_picture(dst); | |
265 | ✗ | return ret; | |
266 | } | ||
267 | |||
268 | 21 | static int av_cold alloc_dummy_frame(MpegEncContext *s, MPVWorkPicture *dst) | |
269 | { | ||
270 | MPVPicture *pic; | ||
271 | 21 | int ret = alloc_picture(s, dst, 1); | |
272 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | if (ret < 0) |
273 | ✗ | return ret; | |
274 | |||
275 | 21 | pic = dst->ptr; | |
276 | 21 | pic->dummy = 1; | |
277 | |||
278 | 21 | ff_thread_progress_report(&pic->progress, INT_MAX); | |
279 | |||
280 | 21 | return 0; | |
281 | } | ||
282 | |||
283 | 21 | static void color_frame(AVFrame *frame, int luma) | |
284 | { | ||
285 | int h_chroma_shift, v_chroma_shift; | ||
286 | |||
287 |
2/2✓ Branch 0 taken 9888 times.
✓ Branch 1 taken 21 times.
|
9909 | for (int i = 0; i < frame->height; i++) |
288 | 9888 | memset(frame->data[0] + frame->linesize[0] * i, luma, frame->width); | |
289 | |||
290 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | if (!frame->data[1]) |
291 | ✗ | return; | |
292 | 21 | av_pix_fmt_get_chroma_sub_sample(frame->format, &h_chroma_shift, &v_chroma_shift); | |
293 |
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++) { |
294 | 4944 | memset(frame->data[1] + frame->linesize[1] * i, | |
295 | 4944 | 0x80, AV_CEIL_RSHIFT(frame->width, h_chroma_shift)); | |
296 | 4944 | memset(frame->data[2] + frame->linesize[2] * i, | |
297 | 4944 | 0x80, AV_CEIL_RSHIFT(frame->width, h_chroma_shift)); | |
298 | } | ||
299 | } | ||
300 | |||
301 | 11944 | int ff_mpv_alloc_dummy_frames(MpegEncContext *s) | |
302 | { | ||
303 | 11944 | AVCodecContext *avctx = s->avctx; | |
304 | int ret; | ||
305 | |||
306 | av_assert1(!s->last_pic.ptr || s->last_pic.ptr->f->buf[0]); | ||
307 | av_assert1(!s->next_pic.ptr || s->next_pic.ptr->f->buf[0]); | ||
308 |
4/4✓ Branch 0 taken 335 times.
✓ Branch 1 taken 11609 times.
✓ Branch 2 taken 21 times.
✓ Branch 3 taken 314 times.
|
11944 | if (!s->last_pic.ptr && s->pict_type != AV_PICTURE_TYPE_I) { |
309 |
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) |
310 | ✗ | av_log(avctx, AV_LOG_DEBUG, | |
311 | "allocating dummy last picture for B frame\n"); | ||
312 |
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 */ && |
313 |
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)) |
314 | ✗ | av_log(avctx, AV_LOG_ERROR, | |
315 | "warning: first frame is no keyframe\n"); | ||
316 | |||
317 | /* Allocate a dummy frame */ | ||
318 | 21 | ret = alloc_dummy_frame(s, &s->last_pic); | |
319 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
|
21 | if (ret < 0) |
320 | ✗ | return ret; | |
321 | |||
322 |
1/2✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
|
21 | if (!avctx->hwaccel) { |
323 |
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; |
324 | 21 | color_frame(s->last_pic.ptr->f, luma_val); | |
325 | } | ||
326 | } | ||
327 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 11944 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
11944 | if (!s->next_pic.ptr && s->pict_type == AV_PICTURE_TYPE_B) { |
328 | /* Allocate a dummy frame */ | ||
329 | ✗ | ret = alloc_dummy_frame(s, &s->next_pic); | |
330 | ✗ | if (ret < 0) | |
331 | ✗ | return ret; | |
332 | } | ||
333 | |||
334 |
4/6✓ Branch 0 taken 10706 times.
✓ Branch 1 taken 1238 times.
✓ Branch 2 taken 10706 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 10706 times.
|
11944 | av_assert0(s->pict_type == AV_PICTURE_TYPE_I || (s->last_pic.ptr && |
335 | s->last_pic.ptr->f->buf[0])); | ||
336 | |||
337 | 11944 | return 0; | |
338 | } | ||
339 | |||
340 | /** | ||
341 | * generic function called after decoding | ||
342 | * the header and before a frame is decoded. | ||
343 | */ | ||
344 | 11232 | int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx) | |
345 | { | ||
346 | int ret; | ||
347 | |||
348 | 11232 | s->mb_skipped = 0; | |
349 | |||
350 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 11232 times.
|
11232 | if (!ff_thread_can_start_frame(avctx)) { |
351 | ✗ | av_log(avctx, AV_LOG_ERROR, "Attempt to start a frame outside SETUP state\n"); | |
352 | ✗ | return AVERROR_BUG; | |
353 | } | ||
354 | |||
355 | 11232 | ff_mpv_unref_picture(&s->cur_pic); | |
356 | 11232 | ret = alloc_picture(s, &s->cur_pic, | |
357 |
3/4✓ Branch 0 taken 8567 times.
✓ Branch 1 taken 2665 times.
✓ Branch 2 taken 8567 times.
✗ Branch 3 not taken.
|
11232 | s->pict_type != AV_PICTURE_TYPE_B && !s->droppable); |
358 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11232 times.
|
11232 | if (ret < 0) |
359 | ✗ | return ret; | |
360 | |||
361 |
2/2✓ Branch 0 taken 778 times.
✓ Branch 1 taken 10454 times.
|
11232 | s->cur_pic.ptr->f->flags |= AV_FRAME_FLAG_TOP_FIELD_FIRST * !!s->top_field_first; |
362 | 22464 | s->cur_pic.ptr->f->flags |= AV_FRAME_FLAG_INTERLACED * | |
363 |
3/4✓ Branch 0 taken 2286 times.
✓ Branch 1 taken 8946 times.
✓ Branch 2 taken 2286 times.
✗ Branch 3 not taken.
|
11232 | (!s->progressive_frame && !s->progressive_sequence); |
364 | 11232 | s->cur_pic.ptr->field_picture = s->picture_structure != PICT_FRAME; | |
365 | |||
366 | 11232 | s->cur_pic.ptr->f->pict_type = s->pict_type; | |
367 |
2/2✓ Branch 0 taken 1238 times.
✓ Branch 1 taken 9994 times.
|
11232 | if (s->pict_type == AV_PICTURE_TYPE_I) |
368 | 1238 | s->cur_pic.ptr->f->flags |= AV_FRAME_FLAG_KEY; | |
369 | else | ||
370 | 9994 | s->cur_pic.ptr->f->flags &= ~AV_FRAME_FLAG_KEY; | |
371 | |||
372 |
2/2✓ Branch 0 taken 8567 times.
✓ Branch 1 taken 2665 times.
|
11232 | if (s->pict_type != AV_PICTURE_TYPE_B) { |
373 | 8567 | ff_mpv_workpic_from_pic(&s->last_pic, s->next_pic.ptr); | |
374 |
1/2✓ Branch 0 taken 8567 times.
✗ Branch 1 not taken.
|
8567 | if (!s->droppable) |
375 | 8567 | ff_mpv_workpic_from_pic(&s->next_pic, s->cur_pic.ptr); | |
376 | } | ||
377 | ff_dlog(s->avctx, "L%p N%p C%p L%p N%p C%p type:%d drop:%d\n", | ||
378 | (void*)s->last_pic.ptr, (void*)s->next_pic.ptr, (void*)s->cur_pic.ptr, | ||
379 | s->last_pic.ptr ? s->last_pic.ptr->f->data[0] : NULL, | ||
380 | s->next_pic.ptr ? s->next_pic.ptr->f->data[0] : NULL, | ||
381 | s->cur_pic.ptr ? s->cur_pic.ptr->f->data[0] : NULL, | ||
382 | s->pict_type, s->droppable); | ||
383 | |||
384 | 11232 | ret = ff_mpv_alloc_dummy_frames(s); | |
385 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11232 times.
|
11232 | if (ret < 0) |
386 | ✗ | return ret; | |
387 | |||
388 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 11232 times.
|
11232 | if (s->avctx->debug & FF_DEBUG_NOMC) |
389 | ✗ | color_frame(s->cur_pic.ptr->f, 0x80); | |
390 | |||
391 | 11232 | return 0; | |
392 | } | ||
393 | |||
394 | /* called after a frame has been decoded. */ | ||
395 | 11232 | void ff_mpv_frame_end(MpegEncContext *s) | |
396 | { | ||
397 | 11232 | emms_c(); | |
398 | |||
399 |
2/2✓ Branch 0 taken 8567 times.
✓ Branch 1 taken 2665 times.
|
11232 | if (s->cur_pic.reference) |
400 | 8567 | ff_thread_progress_report(&s->cur_pic.ptr->progress, INT_MAX); | |
401 | 11232 | } | |
402 | |||
403 | 10999 | void ff_print_debug_info(const MpegEncContext *s, const MPVPicture *p, AVFrame *pict) | |
404 | { | ||
405 | 10999 | ff_print_debug_info2(s->avctx, pict, p->mb_type, | |
406 | 10999 | p->qscale_table, p->motion_val, | |
407 | 10999 | s->mb_width, s->mb_height, s->mb_stride, s->quarter_sample); | |
408 | 10999 | } | |
409 | |||
410 | 10262 | int ff_mpv_export_qp_table(const MpegEncContext *s, AVFrame *f, | |
411 | const MPVPicture *p, int qp_type) | ||
412 | { | ||
413 | AVVideoEncParams *par; | ||
414 |
2/2✓ Branch 0 taken 6424 times.
✓ Branch 1 taken 3838 times.
|
10262 | int mult = (qp_type == FF_MPV_QSCALE_TYPE_MPEG1) ? 2 : 1; |
415 | 10262 | unsigned int nb_mb = p->mb_height * p->mb_width; | |
416 | |||
417 |
2/2✓ Branch 0 taken 10227 times.
✓ Branch 1 taken 35 times.
|
10262 | if (!(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS)) |
418 | 10227 | return 0; | |
419 | |||
420 | 35 | par = av_video_enc_params_create_side_data(f, AV_VIDEO_ENC_PARAMS_MPEG2, nb_mb); | |
421 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
|
35 | if (!par) |
422 | ✗ | return AVERROR(ENOMEM); | |
423 | |||
424 |
2/2✓ Branch 0 taken 630 times.
✓ Branch 1 taken 35 times.
|
665 | for (unsigned y = 0; y < p->mb_height; y++) |
425 |
2/2✓ Branch 0 taken 13860 times.
✓ Branch 1 taken 630 times.
|
14490 | for (unsigned x = 0; x < p->mb_width; x++) { |
426 | 13860 | const unsigned int block_idx = y * p->mb_width + x; | |
427 | 13860 | const unsigned int mb_xy = y * p->mb_stride + x; | |
428 | 13860 | AVVideoBlockParams *const b = av_video_enc_params_block(par, block_idx); | |
429 | |||
430 | 13860 | b->src_x = x * 16; | |
431 | 13860 | b->src_y = y * 16; | |
432 | 13860 | b->w = 16; | |
433 | 13860 | b->h = 16; | |
434 | |||
435 | 13860 | b->delta_qp = p->qscale_table[mb_xy] * mult; | |
436 | } | ||
437 | |||
438 | 35 | return 0; | |
439 | } | ||
440 | |||
441 | 170342 | void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h) | |
442 | { | ||
443 | 170342 | ff_draw_horiz_band(s->avctx, s->cur_pic.ptr->f, | |
444 |
2/2✓ Branch 0 taken 166884 times.
✓ Branch 1 taken 3458 times.
|
170342 | s->last_pic.ptr ? s->last_pic.ptr->f : NULL, |
445 | y, h, s->picture_structure, | ||
446 | s->first_field, s->low_delay); | ||
447 | 170342 | } | |
448 | |||
449 | 82 | void ff_mpeg_flush(AVCodecContext *avctx) | |
450 | { | ||
451 | 82 | MpegEncContext *const s = avctx->priv_data; | |
452 | |||
453 | 82 | ff_mpv_unref_picture(&s->cur_pic); | |
454 | 82 | ff_mpv_unref_picture(&s->last_pic); | |
455 | 82 | ff_mpv_unref_picture(&s->next_pic); | |
456 | |||
457 | 82 | s->mb_x = s->mb_y = 0; | |
458 | |||
459 | 82 | s->bitstream_buffer_size = 0; | |
460 | 82 | s->pp_time = 0; | |
461 | 82 | } | |
462 | |||
463 | 170342 | void ff_mpv_report_decode_progress(MpegEncContext *s) | |
464 | { | ||
465 |
5/6✓ Branch 0 taken 130714 times.
✓ Branch 1 taken 39628 times.
✓ Branch 2 taken 124131 times.
✓ Branch 3 taken 6583 times.
✓ Branch 4 taken 124131 times.
✗ Branch 5 not taken.
|
170342 | if (s->pict_type != AV_PICTURE_TYPE_B && !s->partitioned_frame && !s->er.error_occurred) |
466 | 124131 | ff_thread_progress_report(&s->cur_pic.ptr->progress, s->mb_y); | |
467 | 170342 | } | |
468 | |||
469 | |||
470 | 126300 | static inline int hpel_motion_lowres(MpegEncContext *s, | |
471 | uint8_t *dest, const uint8_t *src, | ||
472 | int field_based, int field_select, | ||
473 | int src_x, int src_y, | ||
474 | int width, int height, ptrdiff_t stride, | ||
475 | int h_edge_pos, int v_edge_pos, | ||
476 | int w, int h, const h264_chroma_mc_func *pix_op, | ||
477 | int motion_x, int motion_y) | ||
478 | { | ||
479 | 126300 | const int lowres = s->avctx->lowres; | |
480 | 126300 | const int op_index = lowres; | |
481 | 126300 | const int s_mask = (2 << lowres) - 1; | |
482 | 126300 | int emu = 0; | |
483 | int sx, sy; | ||
484 | |||
485 | av_assert2(op_index <= 3); | ||
486 | |||
487 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 126300 times.
|
126300 | if (s->quarter_sample) { |
488 | ✗ | motion_x /= 2; | |
489 | ✗ | motion_y /= 2; | |
490 | } | ||
491 | |||
492 | 126300 | sx = motion_x & s_mask; | |
493 | 126300 | sy = motion_y & s_mask; | |
494 | 126300 | src_x += motion_x >> lowres + 1; | |
495 | 126300 | src_y += motion_y >> lowres + 1; | |
496 | |||
497 | 126300 | src += src_y * stride + src_x; | |
498 | |||
499 |
1/2✓ Branch 0 taken 126300 times.
✗ Branch 1 not taken.
|
126300 | if ((unsigned)src_x > FFMAX( h_edge_pos - (!!sx) - w, 0) || |
500 |
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)) { |
501 | 298 | s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, src, | |
502 | s->linesize, s->linesize, | ||
503 | 298 | w + 1, (h + 1) << field_based, | |
504 | src_x, src_y * (1 << field_based), | ||
505 | h_edge_pos, v_edge_pos); | ||
506 | 298 | src = s->sc.edge_emu_buffer; | |
507 | 298 | emu = 1; | |
508 | } | ||
509 | |||
510 | 126300 | sx = (sx << 2) >> lowres; | |
511 | 126300 | sy = (sy << 2) >> lowres; | |
512 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 126300 times.
|
126300 | if (field_select) |
513 | ✗ | src += s->linesize; | |
514 | 126300 | pix_op[op_index](dest, src, stride, h, sx, sy); | |
515 | 126300 | return emu; | |
516 | } | ||
517 | |||
518 | /* apply one mpeg motion vector to the three components */ | ||
519 | 24814 | static av_always_inline void mpeg_motion_lowres(MpegEncContext *s, | |
520 | uint8_t *dest_y, | ||
521 | uint8_t *dest_cb, | ||
522 | uint8_t *dest_cr, | ||
523 | int field_based, | ||
524 | int bottom_field, | ||
525 | int field_select, | ||
526 | uint8_t *const *ref_picture, | ||
527 | const h264_chroma_mc_func *pix_op, | ||
528 | int motion_x, int motion_y, | ||
529 | int h, int mb_y) | ||
530 | { | ||
531 | const uint8_t *ptr_y, *ptr_cb, *ptr_cr; | ||
532 | int mx, my, src_x, src_y, uvsrc_x, uvsrc_y, sx, sy, uvsx, uvsy; | ||
533 | ptrdiff_t uvlinesize, linesize; | ||
534 | 24814 | const int lowres = s->avctx->lowres; | |
535 | 24814 | const int op_index = lowres - 1 + s->chroma_x_shift; | |
536 | 24814 | const int block_s = 8 >> lowres; | |
537 | 24814 | const int s_mask = (2 << lowres) - 1; | |
538 | 24814 | const int h_edge_pos = s->h_edge_pos >> lowres; | |
539 | 24814 | const int v_edge_pos = s->v_edge_pos >> lowres; | |
540 |
1/2✓ Branch 0 taken 24814 times.
✗ Branch 1 not taken.
|
24814 | int hc = s->chroma_y_shift ? (h+1-bottom_field)>>1 : h; |
541 | |||
542 | av_assert2(op_index <= 3); | ||
543 | |||
544 | 24814 | linesize = s->cur_pic.linesize[0] << field_based; | |
545 | 24814 | uvlinesize = s->cur_pic.linesize[1] << field_based; | |
546 | |||
547 | // FIXME obviously not perfect but qpel will not work in lowres anyway | ||
548 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24814 times.
|
24814 | if (s->quarter_sample) { |
549 | ✗ | motion_x /= 2; | |
550 | ✗ | motion_y /= 2; | |
551 | } | ||
552 | |||
553 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24814 times.
|
24814 | if (field_based) { |
554 | ✗ | motion_y += (bottom_field - field_select)*((1 << lowres)-1); | |
555 | } | ||
556 | |||
557 | 24814 | sx = motion_x & s_mask; | |
558 | 24814 | sy = motion_y & s_mask; | |
559 | 24814 | src_x = s->mb_x * 2 * block_s + (motion_x >> lowres + 1); | |
560 | 24814 | src_y = (mb_y * 2 * block_s >> field_based) + (motion_y >> lowres + 1); | |
561 | |||
562 |
1/2✓ Branch 0 taken 24814 times.
✗ Branch 1 not taken.
|
24814 | if (s->out_format == FMT_H263) { |
563 | 24814 | uvsx = ((motion_x >> 1) & s_mask) | (sx & 1); | |
564 | 24814 | uvsy = ((motion_y >> 1) & s_mask) | (sy & 1); | |
565 | 24814 | uvsrc_x = src_x >> 1; | |
566 | 24814 | uvsrc_y = src_y >> 1; | |
567 | ✗ | } else if (s->out_format == FMT_H261) { | |
568 | // even chroma mv's are full pel in H261 | ||
569 | ✗ | mx = motion_x / 4; | |
570 | ✗ | my = motion_y / 4; | |
571 | ✗ | uvsx = (2 * mx) & s_mask; | |
572 | ✗ | uvsy = (2 * my) & s_mask; | |
573 | ✗ | uvsrc_x = s->mb_x * block_s + (mx >> lowres); | |
574 | ✗ | uvsrc_y = mb_y * block_s + (my >> lowres); | |
575 | } else { | ||
576 | ✗ | if (s->chroma_y_shift) { | |
577 | ✗ | mx = motion_x / 2; | |
578 | ✗ | my = motion_y / 2; | |
579 | ✗ | uvsx = mx & s_mask; | |
580 | ✗ | uvsy = my & s_mask; | |
581 | ✗ | uvsrc_x = s->mb_x * block_s + (mx >> lowres + 1); | |
582 | ✗ | uvsrc_y = (mb_y * block_s >> field_based) + (my >> lowres + 1); | |
583 | } else { | ||
584 | ✗ | if (s->chroma_x_shift) { | |
585 | //Chroma422 | ||
586 | ✗ | mx = motion_x / 2; | |
587 | ✗ | uvsx = mx & s_mask; | |
588 | ✗ | uvsy = motion_y & s_mask; | |
589 | ✗ | uvsrc_y = src_y; | |
590 | ✗ | uvsrc_x = s->mb_x*block_s + (mx >> (lowres+1)); | |
591 | } else { | ||
592 | //Chroma444 | ||
593 | ✗ | uvsx = motion_x & s_mask; | |
594 | ✗ | uvsy = motion_y & s_mask; | |
595 | ✗ | uvsrc_x = src_x; | |
596 | ✗ | uvsrc_y = src_y; | |
597 | } | ||
598 | } | ||
599 | } | ||
600 | |||
601 | 24814 | ptr_y = ref_picture[0] + src_y * linesize + src_x; | |
602 | 24814 | ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; | |
603 | 24814 | ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; | |
604 | |||
605 |
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 || |
606 |
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)) { |
607 | 197 | s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr_y, | |
608 | linesize >> field_based, linesize >> field_based, | ||
609 | 17, 17 + field_based, | ||
610 | src_x, src_y * (1 << field_based), h_edge_pos, | ||
611 | v_edge_pos); | ||
612 | 197 | ptr_y = s->sc.edge_emu_buffer; | |
613 | if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { | ||
614 | 197 | uint8_t *ubuf = s->sc.edge_emu_buffer + 18 * s->linesize; | |
615 | 197 | uint8_t *vbuf =ubuf + 10 * s->uvlinesize; | |
616 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 197 times.
|
197 | if (s->workaround_bugs & FF_BUG_IEDGE) |
617 | ✗ | vbuf -= s->uvlinesize; | |
618 | 197 | s->vdsp.emulated_edge_mc(ubuf, ptr_cb, | |
619 | uvlinesize >> field_based, uvlinesize >> field_based, | ||
620 | 9, 9 + field_based, | ||
621 | uvsrc_x, uvsrc_y * (1 << field_based), | ||
622 | h_edge_pos >> 1, v_edge_pos >> 1); | ||
623 | 197 | s->vdsp.emulated_edge_mc(vbuf, ptr_cr, | |
624 | uvlinesize >> field_based,uvlinesize >> field_based, | ||
625 | 9, 9 + field_based, | ||
626 | uvsrc_x, uvsrc_y * (1 << field_based), | ||
627 | h_edge_pos >> 1, v_edge_pos >> 1); | ||
628 | 197 | ptr_cb = ubuf; | |
629 | 197 | ptr_cr = vbuf; | |
630 | } | ||
631 | } | ||
632 | |||
633 | // FIXME use this for field pix too instead of the obnoxious hack which changes picture.f->data | ||
634 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24814 times.
|
24814 | if (bottom_field) { |
635 | ✗ | dest_y += s->linesize; | |
636 | ✗ | dest_cb += s->uvlinesize; | |
637 | ✗ | dest_cr += s->uvlinesize; | |
638 | } | ||
639 | |||
640 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 24814 times.
|
24814 | if (field_select) { |
641 | ✗ | ptr_y += s->linesize; | |
642 | ✗ | ptr_cb += s->uvlinesize; | |
643 | ✗ | ptr_cr += s->uvlinesize; | |
644 | } | ||
645 | |||
646 | 24814 | sx = (sx << 2) >> lowres; | |
647 | 24814 | sy = (sy << 2) >> lowres; | |
648 | 24814 | pix_op[lowres - 1](dest_y, ptr_y, linesize, h, sx, sy); | |
649 | |||
650 | if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { | ||
651 | 24814 | uvsx = (uvsx << 2) >> lowres; | |
652 | 24814 | uvsy = (uvsy << 2) >> lowres; | |
653 |
1/2✓ Branch 0 taken 24814 times.
✗ Branch 1 not taken.
|
24814 | if (hc) { |
654 | 24814 | pix_op[op_index](dest_cb, ptr_cb, uvlinesize, hc, uvsx, uvsy); | |
655 | 24814 | pix_op[op_index](dest_cr, ptr_cr, uvlinesize, hc, uvsx, uvsy); | |
656 | } | ||
657 | } | ||
658 | // FIXME h261 lowres loop filter | ||
659 | 24814 | } | |
660 | |||
661 | 31575 | static inline void chroma_4mv_motion_lowres(MpegEncContext *s, | |
662 | uint8_t *dest_cb, uint8_t *dest_cr, | ||
663 | uint8_t *const *ref_picture, | ||
664 | const h264_chroma_mc_func * pix_op, | ||
665 | int mx, int my) | ||
666 | { | ||
667 | 31575 | const int lowres = s->avctx->lowres; | |
668 | 31575 | const int op_index = lowres; | |
669 | 31575 | const int block_s = 8 >> lowres; | |
670 | 31575 | const int s_mask = (2 << lowres) - 1; | |
671 | 31575 | const int h_edge_pos = s->h_edge_pos >> lowres + 1; | |
672 | 31575 | const int v_edge_pos = s->v_edge_pos >> lowres + 1; | |
673 | 31575 | int emu = 0, src_x, src_y, sx, sy; | |
674 | ptrdiff_t offset; | ||
675 | const uint8_t *ptr; | ||
676 | |||
677 | av_assert2(op_index <= 3); | ||
678 | |||
679 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 31575 times.
|
31575 | if (s->quarter_sample) { |
680 | ✗ | mx /= 2; | |
681 | ✗ | my /= 2; | |
682 | } | ||
683 | |||
684 | /* In case of 8X8, we construct a single chroma motion vector | ||
685 | with a special rounding */ | ||
686 | 31575 | mx = ff_h263_round_chroma(mx); | |
687 | 31575 | my = ff_h263_round_chroma(my); | |
688 | |||
689 | 31575 | sx = mx & s_mask; | |
690 | 31575 | sy = my & s_mask; | |
691 | 31575 | src_x = s->mb_x * block_s + (mx >> lowres + 1); | |
692 | 31575 | src_y = s->mb_y * block_s + (my >> lowres + 1); | |
693 | |||
694 | 31575 | offset = src_y * s->uvlinesize + src_x; | |
695 | 31575 | ptr = ref_picture[1] + offset; | |
696 |
1/2✓ Branch 0 taken 31575 times.
✗ Branch 1 not taken.
|
31575 | if ((unsigned) src_x > FFMAX(h_edge_pos - (!!sx) - block_s, 0) || |
697 |
2/2✓ Branch 0 taken 144 times.
✓ Branch 1 taken 31431 times.
|
31575 | (unsigned) src_y > FFMAX(v_edge_pos - (!!sy) - block_s, 0)) { |
698 | 144 | s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr, | |
699 | s->uvlinesize, s->uvlinesize, | ||
700 | 9, 9, | ||
701 | src_x, src_y, h_edge_pos, v_edge_pos); | ||
702 | 144 | ptr = s->sc.edge_emu_buffer; | |
703 | 144 | emu = 1; | |
704 | } | ||
705 | 31575 | sx = (sx << 2) >> lowres; | |
706 | 31575 | sy = (sy << 2) >> lowres; | |
707 | 31575 | pix_op[op_index](dest_cb, ptr, s->uvlinesize, block_s, sx, sy); | |
708 | |||
709 | 31575 | ptr = ref_picture[2] + offset; | |
710 |
2/2✓ Branch 0 taken 144 times.
✓ Branch 1 taken 31431 times.
|
31575 | if (emu) { |
711 | 144 | s->vdsp.emulated_edge_mc(s->sc.edge_emu_buffer, ptr, | |
712 | s->uvlinesize, s->uvlinesize, | ||
713 | 9, 9, | ||
714 | src_x, src_y, h_edge_pos, v_edge_pos); | ||
715 | 144 | ptr = s->sc.edge_emu_buffer; | |
716 | } | ||
717 | 31575 | pix_op[op_index](dest_cr, ptr, s->uvlinesize, block_s, sx, sy); | |
718 | 31575 | } | |
719 | |||
720 | /** | ||
721 | * motion compensation of a single macroblock | ||
722 | * @param s context | ||
723 | * @param dest_y luma destination pointer | ||
724 | * @param dest_cb chroma cb/u destination pointer | ||
725 | * @param dest_cr chroma cr/v destination pointer | ||
726 | * @param dir direction (0->forward, 1->backward) | ||
727 | * @param ref_picture array[3] of pointers to the 3 planes of the reference picture | ||
728 | * @param pix_op halfpel motion compensation function (average or put normally) | ||
729 | * the motion vectors are taken from s->mv and the MV type from s->mv_type | ||
730 | */ | ||
731 | 56389 | static inline void MPV_motion_lowres(MpegEncContext *s, | |
732 | uint8_t *dest_y, uint8_t *dest_cb, | ||
733 | uint8_t *dest_cr, | ||
734 | int dir, uint8_t *const *ref_picture, | ||
735 | const h264_chroma_mc_func *pix_op) | ||
736 | { | ||
737 | int mx, my; | ||
738 | int mb_x, mb_y; | ||
739 | 56389 | const int lowres = s->avctx->lowres; | |
740 | 56389 | const int block_s = 8 >>lowres; | |
741 | |||
742 | 56389 | mb_x = s->mb_x; | |
743 | 56389 | mb_y = s->mb_y; | |
744 | |||
745 |
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) { |
746 | 24814 | case MV_TYPE_16X16: | |
747 | 24814 | mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
748 | 0, 0, 0, | ||
749 | ref_picture, pix_op, | ||
750 | s->mv[dir][0][0], s->mv[dir][0][1], | ||
751 | 2 * block_s, mb_y); | ||
752 | 24814 | break; | |
753 | 31575 | case MV_TYPE_8X8: | |
754 | 31575 | mx = 0; | |
755 | 31575 | my = 0; | |
756 |
2/2✓ Branch 0 taken 126300 times.
✓ Branch 1 taken 31575 times.
|
157875 | for (int i = 0; i < 4; i++) { |
757 | 126300 | hpel_motion_lowres(s, dest_y + ((i & 1) + (i >> 1) * | |
758 | 126300 | s->linesize) * block_s, | |
759 | ref_picture[0], 0, 0, | ||
760 | 126300 | (2 * mb_x + (i & 1)) * block_s, | |
761 | 126300 | (2 * mb_y + (i >> 1)) * block_s, | |
762 | s->width, s->height, s->linesize, | ||
763 | 126300 | s->h_edge_pos >> lowres, s->v_edge_pos >> lowres, | |
764 | block_s, block_s, pix_op, | ||
765 | s->mv[dir][i][0], s->mv[dir][i][1]); | ||
766 | |||
767 | 126300 | mx += s->mv[dir][i][0]; | |
768 | 126300 | my += s->mv[dir][i][1]; | |
769 | } | ||
770 | |||
771 | if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) | ||
772 | 31575 | chroma_4mv_motion_lowres(s, dest_cb, dest_cr, ref_picture, | |
773 | pix_op, mx, my); | ||
774 | 31575 | break; | |
775 | ✗ | case MV_TYPE_FIELD: | |
776 | ✗ | if (s->picture_structure == PICT_FRAME) { | |
777 | /* top field */ | ||
778 | ✗ | mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
779 | 1, 0, s->field_select[dir][0], | ||
780 | ref_picture, pix_op, | ||
781 | s->mv[dir][0][0], s->mv[dir][0][1], | ||
782 | block_s, mb_y); | ||
783 | /* bottom field */ | ||
784 | ✗ | mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
785 | 1, 1, s->field_select[dir][1], | ||
786 | ref_picture, pix_op, | ||
787 | s->mv[dir][1][0], s->mv[dir][1][1], | ||
788 | block_s, mb_y); | ||
789 | } else { | ||
790 | ✗ | if (s->picture_structure != s->field_select[dir][0] + 1 && | |
791 | ✗ | s->pict_type != AV_PICTURE_TYPE_B && !s->first_field) { | |
792 | ✗ | ref_picture = s->cur_pic.ptr->f->data; | |
793 | } | ||
794 | ✗ | mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
795 | 0, 0, s->field_select[dir][0], | ||
796 | ref_picture, pix_op, | ||
797 | s->mv[dir][0][0], | ||
798 | s->mv[dir][0][1], 2 * block_s, mb_y >> 1); | ||
799 | } | ||
800 | ✗ | break; | |
801 | ✗ | case MV_TYPE_16X8: | |
802 | ✗ | for (int i = 0; i < 2; i++) { | |
803 | uint8_t *const *ref2picture; | ||
804 | |||
805 | ✗ | if (s->picture_structure == s->field_select[dir][i] + 1 || | |
806 | ✗ | s->pict_type == AV_PICTURE_TYPE_B || s->first_field) { | |
807 | ✗ | ref2picture = ref_picture; | |
808 | } else { | ||
809 | ✗ | ref2picture = s->cur_pic.ptr->f->data; | |
810 | } | ||
811 | |||
812 | ✗ | mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
813 | 0, 0, s->field_select[dir][i], | ||
814 | ref2picture, pix_op, | ||
815 | ✗ | s->mv[dir][i][0], s->mv[dir][i][1] + | |
816 | ✗ | 2 * block_s * i, block_s, mb_y >> 1); | |
817 | |||
818 | ✗ | dest_y += 2 * block_s * s->linesize; | |
819 | ✗ | dest_cb += (2 * block_s >> s->chroma_y_shift) * s->uvlinesize; | |
820 | ✗ | dest_cr += (2 * block_s >> s->chroma_y_shift) * s->uvlinesize; | |
821 | } | ||
822 | ✗ | break; | |
823 | ✗ | case MV_TYPE_DMV: | |
824 | ✗ | if (s->picture_structure == PICT_FRAME) { | |
825 | ✗ | for (int i = 0; i < 2; i++) { | |
826 | ✗ | for (int j = 0; j < 2; j++) { | |
827 | ✗ | mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
828 | 1, j, j ^ i, | ||
829 | ref_picture, pix_op, | ||
830 | ✗ | s->mv[dir][2 * i + j][0], | |
831 | ✗ | s->mv[dir][2 * i + j][1], | |
832 | block_s, mb_y); | ||
833 | } | ||
834 | ✗ | pix_op = s->h264chroma.avg_h264_chroma_pixels_tab; | |
835 | } | ||
836 | } else { | ||
837 | ✗ | for (int i = 0; i < 2; i++) { | |
838 | ✗ | mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, | |
839 | ✗ | 0, 0, s->picture_structure != i + 1, | |
840 | ref_picture, pix_op, | ||
841 | ✗ | s->mv[dir][2 * i][0],s->mv[dir][2 * i][1], | |
842 | 2 * block_s, mb_y >> 1); | ||
843 | |||
844 | // after put we make avg of the same block | ||
845 | ✗ | pix_op = s->h264chroma.avg_h264_chroma_pixels_tab; | |
846 | |||
847 | // opposite parity is always in the same | ||
848 | // frame if this is second field | ||
849 | ✗ | if (!s->first_field) { | |
850 | ✗ | ref_picture = s->cur_pic.ptr->f->data; | |
851 | } | ||
852 | } | ||
853 | } | ||
854 | ✗ | break; | |
855 | 56389 | default: | |
856 | av_assert2(0); | ||
857 | } | ||
858 | 56389 | } | |
859 | |||
860 | /** | ||
861 | * find the lowest MB row referenced in the MVs | ||
862 | */ | ||
863 | 60133 | static int lowest_referenced_row(MpegEncContext *s, int dir) | |
864 | { | ||
865 | 60133 | int my_max = INT_MIN, my_min = INT_MAX, qpel_shift = !s->quarter_sample; | |
866 | int off, mvs; | ||
867 | |||
868 |
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) |
869 | ✗ | goto unhandled; | |
870 | |||
871 |
1/4✓ Branch 0 taken 60133 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
|
60133 | switch (s->mv_type) { |
872 | 60133 | case MV_TYPE_16X16: | |
873 | 60133 | mvs = 1; | |
874 | 60133 | break; | |
875 | ✗ | case MV_TYPE_16X8: | |
876 | ✗ | mvs = 2; | |
877 | ✗ | break; | |
878 | ✗ | case MV_TYPE_8X8: | |
879 | ✗ | mvs = 4; | |
880 | ✗ | break; | |
881 | ✗ | default: | |
882 | ✗ | goto unhandled; | |
883 | } | ||
884 | |||
885 |
2/2✓ Branch 0 taken 60133 times.
✓ Branch 1 taken 60133 times.
|
120266 | for (int i = 0; i < mvs; i++) { |
886 | 60133 | int my = s->mv[dir][i][1]; | |
887 | 60133 | my_max = FFMAX(my_max, my); | |
888 | 60133 | my_min = FFMIN(my_min, my); | |
889 | } | ||
890 | |||
891 | 60133 | off = ((FFMAX(-my_min, my_max) << qpel_shift) + 63) >> 6; | |
892 | |||
893 | 60133 | return av_clip(s->mb_y + off, 0, s->mb_height - 1); | |
894 | ✗ | unhandled: | |
895 | ✗ | return s->mb_height - 1; | |
896 | } | ||
897 | |||
898 | /* add block[] to dest[] */ | ||
899 | 23438520 | static inline void add_dct(MpegEncContext *s, | |
900 | int16_t *block, int i, uint8_t *dest, int line_size) | ||
901 | { | ||
902 |
2/2✓ Branch 0 taken 8400751 times.
✓ Branch 1 taken 15037769 times.
|
23438520 | if (s->block_last_index[i] >= 0) { |
903 | 8400751 | s->idsp.idct_add(dest, line_size, block); | |
904 | } | ||
905 | 23438520 | } | |
906 | |||
907 | #define IS_ENCODER 0 | ||
908 | #include "mpv_reconstruct_mb_template.c" | ||
909 | |||
910 | 5144152 | void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64]) | |
911 | { | ||
912 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 5144152 times.
|
5144152 | if (s->avctx->debug & FF_DEBUG_DCT_COEFF) { |
913 | /* 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); | |
915 | ✗ | for (int i = 0; i < 6; i++) { | |
916 | ✗ | for (int j = 0; j < 64; j++) { | |
917 | ✗ | av_log(s->avctx, AV_LOG_DEBUG, "%5d", | |
918 | ✗ | block[i][s->idsp.idct_permutation[j]]); | |
919 | } | ||
920 | ✗ | av_log(s->avctx, AV_LOG_DEBUG, "\n"); | |
921 | } | ||
922 | } | ||
923 | |||
924 | av_assert2((s->out_format <= FMT_H261) == (s->out_format == FMT_H261 || s->out_format == FMT_MPEG1)); | ||
925 |
2/2✓ Branch 0 taken 5100652 times.
✓ Branch 1 taken 43500 times.
|
5144152 | if (!s->avctx->lowres) { |
926 | #if !CONFIG_SMALL | ||
927 |
2/2✓ Branch 0 taken 2722746 times.
✓ Branch 1 taken 2377906 times.
|
5100652 | if (s->out_format <= FMT_H261) |
928 | 2722746 | mpv_reconstruct_mb_internal(s, block, 0, DEFINITELY_MPEG12_H261); | |
929 | else | ||
930 | 2377906 | mpv_reconstruct_mb_internal(s, block, 0, NOT_MPEG12_H261); | |
931 | #else | ||
932 | mpv_reconstruct_mb_internal(s, block, 0, MAY_BE_MPEG12_H261); | ||
933 | #endif | ||
934 | } else | ||
935 | 43500 | mpv_reconstruct_mb_internal(s, block, 1, MAY_BE_MPEG12_H261); | |
936 | 5144152 | } | |
937 |