FFmpeg
Loading...
Searching...
No Matches
h263dec.c
Go to the documentation of this file.
1/*
2 * H.263 decoder
3 * Copyright (c) 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/**
24 * @file
25 * H.263 decoder.
26 */
27
28#define UNCHECKED_BITSTREAM_READER 1
29
30#include "config_components.h"
31
32#include "avcodec.h"
33#include "codec_internal.h"
34#include "decode.h"
35#include "error_resilience.h"
36#include "flvdec.h"
37#include "h263.h"
38#include "h263dec.h"
39#include "hwaccel_internal.h"
40#include "hwconfig.h"
41#include "mpeg_er.h"
42#include "mpeg4video.h"
43#include "mpeg4videodec.h"
44#include "mpegvideo.h"
45#include "mpegvideodata.h"
46#include "mpegvideodec.h"
48#include "msmpeg4dec.h"
49#include "thread.h"
50#include "wmv2dec.h"
51
53#if CONFIG_H263_VAAPI_HWACCEL || CONFIG_MPEG4_VAAPI_HWACCEL
55#endif
56#if CONFIG_MPEG4_NVDEC_HWACCEL
58#endif
59#if CONFIG_MPEG4_NVDEC_CUARRAY_HWACCEL
61#endif
62#if CONFIG_MPEG4_VDPAU_HWACCEL
64#endif
65#if CONFIG_H263_VIDEOTOOLBOX_HWACCEL || CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL
67#endif
70};
71
73{
74 /* MPEG-4 Studio Profile only, not supported by hardware */
75 if (avctx->bits_per_raw_sample > 8) {
76 av_assert1(((MpegEncContext *)avctx->priv_data)->studio_profile);
77 return avctx->pix_fmt;
78 }
79
80 if (CONFIG_GRAY && (avctx->flags & AV_CODEC_FLAG_GRAY)) {
83 return AV_PIX_FMT_GRAY8;
84 }
85
86 if (avctx->codec_id == AV_CODEC_ID_H263 ||
87 avctx->codec_id == AV_CODEC_ID_H263P ||
90
91 return AV_PIX_FMT_YUV420P;
92}
93
95{
96 H263DecContext *const h = avctx->priv_data;
97 MPVContext *const s = &h->c;
98 MPVUnquantDSPContext unquant_dsp_ctx;
99 int ret;
100
101 s->out_format = FMT_H263;
102
103 // set defaults
104 ret = ff_mpv_decode_init(s, avctx);
105 if (ret < 0)
106 return ret;
107
108 h->decode_mb = ff_h263_decode_mb;
109 s->low_delay = 1;
110
111 s->y_dc_scale_table =
112 s->c_dc_scale_table = ff_mpeg1_dc_scale_table;
113
114 ff_permute_scantable(h->permutated_intra_h_scantable, ff_alternate_horizontal_scan,
115 s->idsp.idct_permutation);
116 ff_permute_scantable(h->permutated_intra_v_scantable, ff_alternate_vertical_scan,
117 s->idsp.idct_permutation);
118
119 ff_mpv_unquantize_init(&unquant_dsp_ctx,
120 avctx->flags & AV_CODEC_FLAG_BITEXACT, 0);
121 // dct_unquantize defaults for H.263;
122 // they might change on a per-frame basis for MPEG-4;
123 // dct_unquantize_inter will be unset for MSMPEG4 codecs later.
124 s->dct_unquantize_intra = unquant_dsp_ctx.dct_unquantize_h263_intra;
125 s->dct_unquantize_inter = unquant_dsp_ctx.dct_unquantize_h263_inter;
126
127 /* select sub codec */
128 switch (avctx->codec->id) {
129 case AV_CODEC_ID_H263:
132 h->decode_header = ff_h263_decode_picture_header;
133 break;
135 break;
137 s->h263_pred = 1;
138 s->msmpeg4_version = MSMP4_V1;
139 break;
141 s->h263_pred = 1;
142 s->msmpeg4_version = MSMP4_V2;
143 break;
145 s->h263_pred = 1;
146 s->msmpeg4_version = MSMP4_V3;
147 break;
148 case AV_CODEC_ID_WMV1:
149 s->h263_pred = 1;
150 s->msmpeg4_version = MSMP4_WMV1;
151 break;
152 case AV_CODEC_ID_WMV2:
153 s->h263_pred = 1;
154 s->msmpeg4_version = MSMP4_WMV2;
155 break;
156 case AV_CODEC_ID_RV10:
157 case AV_CODEC_ID_RV20:
158 break;
159#if CONFIG_H263I_DECODER
161 h->decode_header = ff_intel_h263_decode_picture_header;
162 break;
163#endif
164#if CONFIG_FLV_DECODER
165 case AV_CODEC_ID_FLV1:
166 h->decode_header = ff_flv_decode_picture_header;
167 break;
168#endif
169 default:
170 av_unreachable("Switch contains a case for every codec using ff_h263_decode_init()");
171 }
172
173 if (avctx->codec_tag == AV_RL32("L263") || avctx->codec_tag == AV_RL32("S263"))
174 if (avctx->extradata_size == 56 && avctx->extradata[0] == 1)
175 h->ehc_mode = 1;
176
177 /* for H.263, we allocate the images after having read the header */
178 if (avctx->codec->id != AV_CODEC_ID_H263 &&
179 avctx->codec->id != AV_CODEC_ID_H263P &&
180 avctx->codec->id != AV_CODEC_ID_MPEG4) {
181 avctx->pix_fmt = h263_get_format(avctx);
182 if ((ret = ff_mpv_common_init(s)) < 0)
183 return ret;
184 }
185
186 ff_h263dsp_init(&s->h263dsp);
188
189 return 0;
190}
191
193{
194 if (h->c.pict_type != AV_PICTURE_TYPE_B && !h->partitioned_frame && !h->c.er.error_occurred)
195 ff_thread_progress_report(&h->c.cur_pic.ptr->progress, h->c.mb_y);
196}
197
198static int decode_slice(H263DecContext *const h)
199{
200 const int part_mask = h->partitioned_frame
201 ? (ER_AC_END | ER_AC_ERROR) : 0x7F;
202 const int mb_size = 16 >> h->c.avctx->lowres;
203 int ret;
204
205 h->last_resync_gb = h->gb;
206 h->c.first_slice_line = 1;
207 h->c.resync_mb_x = h->c.mb_x;
208 h->c.resync_mb_y = h->c.mb_y;
209
210 ff_set_qscale(&h->c, h->c.qscale);
211
212#if CONFIG_MPEG4_DECODER
213 if (h->c.studio_profile) {
214 if ((ret = ff_mpeg4_decode_studio_slice_header(h)) < 0)
215 return ret;
216 }
217#endif
218
219 if (h->c.avctx->hwaccel) {
220 const uint8_t *start = h->gb.buffer + get_bits_count(&h->gb) / 8;
221 ret = FF_HW_CALL(h->c.avctx, decode_slice, start,
222 get_bits_bytesize(&h->gb, 0) - get_bits_count(&h->gb) / 8);
223 // ensure we exit decode loop
224 h->c.mb_y = h->c.mb_height;
225 return ret;
226 }
227
228#if CONFIG_MPEG4_DECODER
229 if (h->partitioned_frame) {
230 const int qscale = h->c.qscale;
231
232 av_assert1(h->c.codec_id == AV_CODEC_ID_MPEG4);
233
235 if (ret < 0)
236 return ret;
237
238 /* restore variables which were modified */
239 h->c.first_slice_line = 1;
240 h->c.mb_x = h->c.resync_mb_x;
241 h->c.mb_y = h->c.resync_mb_y;
242 ff_set_qscale(&h->c, qscale);
243 }
244#endif
245
246 for (; h->c.mb_y < h->c.mb_height; h->c.mb_y++) {
247 /* per-row end of slice checks */
248 if (h->c.msmpeg4_version != MSMP4_UNUSED) {
249 if (h->c.resync_mb_y + h->slice_height == h->c.mb_y) {
250 ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
251 h->c.mb_x - 1, h->c.mb_y, ER_MB_END);
252
253 return 0;
254 }
255 }
256
257 if (h->c.msmpeg4_version == MSMP4_V1) {
258 h->last_dc[0] =
259 h->last_dc[1] =
260 h->last_dc[2] = 128;
261 }
262
264 for (; h->c.mb_x < h->c.mb_width; h->c.mb_x++) {
265 int ret;
266
267 ff_update_block_index(&h->c, h->c.avctx->bits_per_raw_sample,
268 h->c.avctx->lowres, h->c.chroma_x_shift);
269
270 if (h->c.resync_mb_x == h->c.mb_x && h->c.resync_mb_y + 1 == h->c.mb_y)
271 h->c.first_slice_line = 0;
272
273 /* DCT & quantize */
274
275 h->c.mv_dir = MV_DIR_FORWARD;
276 h->c.mv_type = MV_TYPE_16X16;
277 ff_dlog(h->c.avctx, "%d %06X\n",
278 get_bits_count(&h->gb), show_bits(&h->gb, 24));
279
280 ff_tlog(NULL, "Decoding MB at %dx%d\n", h->c.mb_x, h->c.mb_y);
281 ret = h->decode_mb(h);
282
283 if (h->c.h263_pred || h->c.h263_aic) {
284 int mb_xy = h->c.mb_y * h->c.mb_stride + h->c.mb_x;
285 if (!h->c.mb_intra) {
287 } else
288 h->c.mbintra_table[mb_xy] = 1;
289 }
290
291 if (h->c.pict_type != AV_PICTURE_TYPE_B)
293
294 if (ret < 0) {
295 const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
296 if (ret == SLICE_END) {
297 ff_mpv_reconstruct_mb(&h->c, h->block);
298 if (h->loop_filter)
300
301 ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
302 h->c.mb_x, h->c.mb_y, ER_MB_END & part_mask);
303
304 h->padding_bug_score--;
305
306 if (++h->c.mb_x >= h->c.mb_width) {
307 h->c.mb_x = 0;
309 ff_mpeg_draw_horiz_band(&h->c, h->c.mb_y * mb_size, mb_size);
310 h->c.mb_y++;
311 }
312 return 0;
313 } else if (ret == SLICE_NOEND) {
314 av_log(h->c.avctx, AV_LOG_ERROR,
315 "Slice mismatch at MB: %d\n", xy);
316 ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
317 h->c.mb_x + 1, h->c.mb_y,
318 ER_MB_END & part_mask);
319 return AVERROR_INVALIDDATA;
320 }
321 av_log(h->c.avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy);
322 ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
323 h->c.mb_x, h->c.mb_y, ER_MB_ERROR & part_mask);
324
325 if ((h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) && get_bits_left(&h->gb) > 0)
326 continue;
327 return AVERROR_INVALIDDATA;
328 }
329
330 ff_mpv_reconstruct_mb(&h->c, h->block);
331 if (h->loop_filter)
333 }
334
336 ff_mpeg_draw_horiz_band(&h->c, h->c.mb_y * mb_size, mb_size);
337
338 h->c.mb_x = 0;
339 }
340
341 av_assert1(h->c.mb_x == 0 && h->c.mb_y == h->c.mb_height);
342
343 // Detect incorrect padding with wrong stuffing codes used by NEC N-02B
344 if (h->c.codec_id == AV_CODEC_ID_MPEG4 &&
345 (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
346 get_bits_left(&h->gb) >= 48 &&
347 show_bits(&h->gb, 24) == 0x4010 &&
348 !h->data_partitioning)
349 h->padding_bug_score += 32;
350
351 /* try to detect the padding bug */
352 if (h->c.codec_id == AV_CODEC_ID_MPEG4 &&
353 (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
354 get_bits_left(&h->gb) >= 0 &&
355 get_bits_left(&h->gb) < 137 &&
356 !h->data_partitioning) {
357 const int bits_count = get_bits_count(&h->gb);
358 const int bits_left = h->gb.size_in_bits - bits_count;
359
360 if (bits_left == 0) {
361 h->padding_bug_score += 16;
362 } else if (bits_left != 1) {
363 int v = show_bits(&h->gb, 8);
364 v |= 0x7F >> (7 - (bits_count & 7));
365
366 if (v == 0x7F && bits_left <= 8)
367 h->padding_bug_score--;
368 else if (v == 0x7F && ((get_bits_count(&h->gb) + 8) & 8) &&
369 bits_left <= 16)
370 h->padding_bug_score += 4;
371 else
372 h->padding_bug_score++;
373 }
374 }
375
376 if (h->c.codec_id == AV_CODEC_ID_H263 &&
377 (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
378 get_bits_left(&h->gb) >= 8 &&
379 get_bits_left(&h->gb) < 300 &&
380 h->c.pict_type == AV_PICTURE_TYPE_I &&
381 show_bits(&h->gb, 8) == 0 &&
382 !h->data_partitioning) {
383
384 h->padding_bug_score += 32;
385 }
386
387 if (h->c.codec_id == AV_CODEC_ID_H263 &&
388 (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
389 get_bits_left(&h->gb) >= 64 &&
390 AV_RB64(h->gb.buffer + (get_bits_bytesize(&h->gb, 0) - 8)) == 0xCDCDCDCDFC7F0000) {
391
392 h->padding_bug_score += 32;
393 }
394
395 if (h->c.workaround_bugs & FF_BUG_AUTODETECT) {
396 if (
397 (h->padding_bug_score > -2 && !h->data_partitioning))
398 h->c.workaround_bugs |= FF_BUG_NO_PADDING;
399 else
400 h->c.workaround_bugs &= ~FF_BUG_NO_PADDING;
401 }
402
403 // handle formats which don't have unique end markers
404 if (h->c.msmpeg4_version != MSMP4_UNUSED || (h->c.workaround_bugs & FF_BUG_NO_PADDING)) { // FIXME perhaps solve this more cleanly
405 int left = get_bits_left(&h->gb);
406 int max_extra = 7;
407
408 /* no markers in M$ crap */
409 if (h->c.msmpeg4_version != MSMP4_UNUSED && h->c.pict_type == AV_PICTURE_TYPE_I)
410 max_extra += 17;
411
412 /* buggy padding but the frame should still end approximately at
413 * the bitstream end */
414 if ((h->c.workaround_bugs & FF_BUG_NO_PADDING) &&
415 (h->c.avctx->err_recognition & (AV_EF_BUFFER|AV_EF_AGGRESSIVE)))
416 max_extra += 48;
417 else if ((h->c.workaround_bugs & FF_BUG_NO_PADDING))
418 max_extra += 256 * 256 * 256 * 64;
419
420 if (left > max_extra)
421 av_log(h->c.avctx, AV_LOG_ERROR,
422 "discarding %d junk bits at end, next would be %X\n",
423 left, show_bits(&h->gb, 24));
424 else if (left < 0)
425 av_log(h->c.avctx, AV_LOG_ERROR, "overreading %d bits\n", -left);
426 else
427 ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
428 h->c.mb_x - 1, h->c.mb_y, ER_MB_END);
429
430 return 0;
431 }
432
433 av_log(h->c.avctx, AV_LOG_ERROR,
434 "slice end not reached but screenspace end (%d left %06X, score= %d)\n",
435 get_bits_left(&h->gb), show_bits(&h->gb, 24), h->padding_bug_score);
436
437 ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y, h->c.mb_x, h->c.mb_y,
438 ER_MB_END & part_mask);
439
440 return AVERROR_INVALIDDATA;
441}
442
444 int *got_frame, AVPacket *avpkt)
445{
446 H263DecContext *const h = avctx->priv_data;
447 MPVContext *const s = &h->c;
448 const uint8_t *buf = avpkt->data;
449 int buf_size = avpkt->size;
450 int ret;
451 int slice_ret = 0;
452 int bak_width, bak_height;
453
454 /* no supplementary picture */
455 if (buf_size == 0) {
456 /* special case for last picture */
457 if ((!h->c.low_delay || h->skipped_last_frame) && h->c.next_pic.ptr) {
458 if ((ret = av_frame_ref(pict, h->c.next_pic.ptr->f)) < 0)
459 return ret;
460 if (h->skipped_last_frame) {
461 /* If the stream ended with an NVOP, we output the last frame
462 * in display order, but with the props from the last input
463 * packet so that the stream's end time is correct. */
464 ret = ff_decode_frame_props(avctx, pict);
465 if (ret < 0)
466 return ret;
467 }
468
469 ff_mpv_unref_picture(&h->c.next_pic);
470
471 *got_frame = 1;
472 }
473
474 return 0;
475 }
476
477 // h->gb might be overridden in ff_mpeg4_decode_picture_header() below.
478 ret = init_get_bits8(&h->gb, buf, buf_size);
479 if (ret < 0)
480 return ret;
481
482 bak_width = h->c.width;
483 bak_height = h->c.height;
484
485 /* let's go :-) */
486 ret = h->decode_header(h);
487 if (ret < 0 || ret == FRAME_SKIPPED) {
488 if ( h->c.width != bak_width
489 || h->c.height != bak_height) {
490 av_log(h->c.avctx, AV_LOG_WARNING, "Reverting picture dimensions change due to header decoding failure\n");
491 h->c.width = bak_width;
492 h->c.height= bak_height;
493
494 }
495 }
496 if (ret == FRAME_SKIPPED)
497 return buf_size;
498
499 /* skip if the header was thrashed */
500 if (ret < 0) {
501 av_log(h->c.avctx, AV_LOG_ERROR, "header damaged\n");
502 return ret;
503 }
504
505 if (!h->c.context_initialized) {
506 avctx->pix_fmt = h263_get_format(avctx);
507 if ((ret = ff_mpv_common_init(s)) < 0)
508 return ret;
509 }
510
511 avctx->has_b_frames = !h->c.low_delay;
512
513#if CONFIG_MPEG4_DECODER
514 if (avctx->codec_id == AV_CODEC_ID_MPEG4) {
515 if (h->c.pict_type != AV_PICTURE_TYPE_B && h->c.mb_num/2 > get_bits_left(&h->gb))
516 return AVERROR_INVALIDDATA;
518 if (h->c.studio_profile != (h->c.idsp.idct == NULL))
520 }
521#endif
522
523 /* After H.263 & MPEG-4 header decode we have the height, width,
524 * and other parameters. So then we could init the picture. */
525 if (h->c.width != avctx->coded_width ||
526 h->c.height != avctx->coded_height ||
527 h->c.context_reinit) {
528 /* H.263 could change picture size any time */
529 h->c.context_reinit = 0;
530
531 ret = ff_set_dimensions(avctx, h->c.width, h->c.height);
532 if (ret < 0)
533 return ret;
534
535 ff_set_sar(avctx, avctx->sample_aspect_ratio);
536
538 return ret;
539
540 if (avctx->pix_fmt != h263_get_format(avctx)) {
541 av_log(avctx, AV_LOG_ERROR, "format change not supported\n");
542 avctx->pix_fmt = AV_PIX_FMT_NONE;
543 return AVERROR_UNKNOWN;
544 }
545 }
546
547 /* skip B-frames if we don't have reference frames */
548 if (!h->c.last_pic.ptr &&
549 (h->c.pict_type == AV_PICTURE_TYPE_B || h->c.droppable))
550 return buf_size;
551 if ((avctx->skip_frame >= AVDISCARD_NONREF &&
552 h->c.pict_type == AV_PICTURE_TYPE_B) ||
553 (avctx->skip_frame >= AVDISCARD_NONKEY &&
554 h->c.pict_type != AV_PICTURE_TYPE_I) ||
555 avctx->skip_frame >= AVDISCARD_ALL)
556 return buf_size;
557
558 if ((ret = ff_mpv_frame_start(s, avctx)) < 0)
559 return ret;
560
561 if (!h->divx_packed)
563
564 if (avctx->hwaccel) {
565 ret = FF_HW_CALL(avctx, start_frame, NULL,
566 h->gb.buffer, get_bits_bytesize(&h->gb, 0));
567 if (ret < 0 )
568 return ret;
569 }
570
571 ff_mpv_er_frame_start_ext(s, h->partitioned_frame,
572 s->pp_time, s->pb_time);
573
574 /* the second part of the wmv2 header contains the MB skip bits which
575 * are stored in current_picture->mb_type which is not available before
576 * ff_mpv_frame_start() */
577#if CONFIG_WMV2_DECODER
578 if (h->c.msmpeg4_version == MSMP4_WMV2) {
580 if (ret < 0)
581 return ret;
582 if (ret == 1)
583 goto frame_end;
584 }
585#endif
586
587 /* decode each macroblock */
588 h->c.mb_x = 0;
589 h->c.mb_y = 0;
590
591 slice_ret = decode_slice(h);
592 while (h->c.mb_y < h->c.mb_height) {
593 if (h->c.msmpeg4_version != MSMP4_UNUSED) {
594 if (h->slice_height == 0 || h->c.mb_x != 0 || slice_ret < 0 ||
595 (h->c.mb_y % h->slice_height) != 0 || get_bits_left(&h->gb) < 0)
596 break;
597 } else {
598 int prev_x = h->c.mb_x, prev_y = h->c.mb_y;
599 if (ff_h263_resync(h) < 0)
600 break;
601 if (prev_y * h->c.mb_width + prev_x < h->c.mb_y * h->c.mb_width + h->c.mb_x)
602 h->c.er.error_occurred = 1;
603 }
604
605 if (h->c.msmpeg4_version < MSMP4_WMV1 && h->c.h263_pred)
607
608 if (decode_slice(h) < 0)
609 slice_ret = AVERROR_INVALIDDATA;
610 }
611
612 if (h->c.msmpeg4_version != MSMP4_UNUSED && h->c.msmpeg4_version < MSMP4_WMV1 &&
613 h->c.pict_type == AV_PICTURE_TYPE_I)
614 if (!CONFIG_MSMPEG4DEC ||
615 ff_msmpeg4_decode_ext_header(h, buf_size) < 0)
616 h->c.er.error_status_table[h->c.mb_num - 1] = ER_MB_ERROR;
617
619 if (!h->c.studio_profile)
620 ff_er_frame_end(&h->c.er, NULL);
621
622 if (avctx->hwaccel) {
623 ret = FF_HW_SIMPLE_CALL(avctx, end_frame);
624 if (ret < 0)
625 return ret;
626 }
627
629
630#if CONFIG_MPEG4_DECODER
631 if (avctx->codec_id == AV_CODEC_ID_MPEG4)
632 ff_mpeg4_frame_end(avctx, avpkt);
633#endif
634
635 av_assert1(h->c.pict_type == h->c.cur_pic.ptr->f->pict_type);
636 if (h->c.pict_type == AV_PICTURE_TYPE_B || h->c.low_delay) {
637 if ((ret = av_frame_ref(pict, h->c.cur_pic.ptr->f)) < 0)
638 return ret;
639 ff_print_debug_info(s, h->c.cur_pic.ptr, pict);
640 ff_mpv_export_qp_table(s, pict, h->c.cur_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1);
641 } else if (h->c.last_pic.ptr) {
642 if ((ret = av_frame_ref(pict, h->c.last_pic.ptr->f)) < 0)
643 return ret;
644 ff_print_debug_info(s, h->c.last_pic.ptr, pict);
645 ff_mpv_export_qp_table(s, pict, h->c.last_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1);
646 }
647
648 if (h->c.last_pic.ptr || h->c.low_delay) {
649 if ( pict->format == AV_PIX_FMT_YUV420P
650 && (h->c.codec_tag == AV_RL32("GEOV") || h->c.codec_tag == AV_RL32("GEOX"))) {
651 for (int p = 0; p < 3; p++) {
652 int h = AV_CEIL_RSHIFT(pict->height, !!p);
653
654 pict->data[p] += (h - 1) * pict->linesize[p];
655 pict->linesize[p] *= -1;
656 }
657 }
658 *got_frame = 1;
659 }
660
661 if (slice_ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))
662 return slice_ret;
663 else
664 return buf_size;
665}
666
668#if CONFIG_H263_VAAPI_HWACCEL
669 HWACCEL_VAAPI(h263),
670#endif
671#if CONFIG_MPEG4_NVDEC_HWACCEL
672 HWACCEL_NVDEC(mpeg4),
673#endif
674#if CONFIG_MPEG4_NVDEC_CUARRAY_HWACCEL
676#endif
677#if CONFIG_MPEG4_VDPAU_HWACCEL
678 HWACCEL_VDPAU(mpeg4),
679#endif
680#if CONFIG_H263_VIDEOTOOLBOX_HWACCEL
682#endif
683 NULL
684};
685
687 .p.name = "h263",
688 CODEC_LONG_NAME("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"),
689 .p.type = AVMEDIA_TYPE_VIDEO,
690 .p.id = AV_CODEC_ID_H263,
691 .priv_data_size = sizeof(H263DecContext),
694 .close = ff_mpv_decode_close,
697 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
699 .flush = ff_mpeg_flush,
700 .p.max_lowres = 3,
701 .hw_configs = h263_hw_config_list,
702};
703
705 .p.name = "h263p",
706 CODEC_LONG_NAME("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"),
707 .p.type = AVMEDIA_TYPE_VIDEO,
708 .p.id = AV_CODEC_ID_H263P,
709 .priv_data_size = sizeof(H263DecContext),
712 .close = ff_mpv_decode_close,
715 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
717 .flush = ff_mpeg_flush,
718 .p.max_lowres = 3,
719 .hw_configs = h263_hw_config_list,
720};
const FFCodec ff_h263p_decoder
Definition h263dec.c:704
const FFCodec ff_h263_decoder
Definition h263dec.c:686
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition avassert.h:58
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
Definition avassert.h:109
Libavcodec external API header.
#define FF_BUG_AUTODETECT
autodetection
Definition avcodec.h:1346
#define FF_BUG_NO_PADDING
Definition avcodec.h:1349
#define bits_left
Definition bitstream.h:116
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define s(width, name)
Definition cbs_vp9.c:198
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters even if the frame is skipped due to the skip_frame sett...
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define AV_CEIL_RSHIFT(a, b)
Definition common.h:60
#define NULL
Definition coverity.c:32
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
Set various frame properties from the codec context / packet data.
Definition decode.c:1598
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition decode.c:1229
int ff_set_sar(AVCodecContext *avctx, AVRational sar)
Check that the provided sample aspect ratio is valid and set it on the codec context.
Definition utils.c:106
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Definition utils.c:91
#define AV_EF_IGNORE_ERR
ignore errors and continue
Definition defs.h:53
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition defs.h:51
#define AV_EF_BUFFER
detect improper bitstream length
Definition defs.h:50
#define AV_EF_AGGRESSIVE
consider things that a sane encoder/muxer should not do as an error
Definition defs.h:56
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy, int status)
Add a slice.
void ff_er_frame_end(ERContext *s, int *decode_error_flags)
Indicate that a frame has finished decoding and perform error concealment in case it has been enabled...
#define ER_AC_ERROR
#define ER_MB_END
#define ER_AC_END
#define ER_MB_ERROR
static int decode_slice(AVCodecContext *c, void *arg)
Definition ffv1dec.c:449
static int get_bits_left(GetBitContext *gb)
Definition get_bits.h:688
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition get_bits.h:544
static int get_bits_count(const GetBitContext *s)
Definition get_bits.h:254
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition get_bits.h:373
static int get_bits_bytesize(const GetBitContext *s, int round_up)
Get the size of the GetBitContext's buffer in bytes.
Definition get_bits.h:268
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
Definition codec.h:41
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition avcodec.h:322
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition codec.h:79
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
Definition avcodec.h:302
@ AV_CODEC_ID_MSMPEG4V1
Definition codec_id.h:64
@ AV_CODEC_ID_FLV1
Definition codec_id.h:71
@ AV_CODEC_ID_WMV2
Definition codec_id.h:68
@ AV_CODEC_ID_MSMPEG4V2
Definition codec_id.h:65
@ AV_CODEC_ID_WMV1
Definition codec_id.h:67
@ AV_CODEC_ID_RV10
Definition codec_id.h:55
@ AV_CODEC_ID_RV20
Definition codec_id.h:56
@ AV_CODEC_ID_H263
Definition codec_id.h:54
@ AV_CODEC_ID_MPEG4
Definition codec_id.h:62
@ AV_CODEC_ID_H263I
Definition codec_id.h:70
@ AV_CODEC_ID_H263P
Definition codec_id.h:69
@ AV_CODEC_ID_MSMPEG4V3
Definition codec_id.h:66
@ AVDISCARD_ALL
discard all
Definition defs.h:232
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition defs.h:231
@ AVDISCARD_NONREF
discard all non reference
Definition defs.h:228
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition error.h:73
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition frame.c:278
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
@ AV_PICTURE_TYPE_I
Intra.
Definition avutil.h:278
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition avutil.h:280
void ff_h263_update_motion_val(MpegEncContext *s)
Definition h263.c:56
void ff_h263_loop_filter(MpegEncContext *s)
Definition h263.c:97
static void ff_h263_clean_intra_table_entries(MpegEncContext *s, int xy)
Definition h263.h:47
void ff_h263_decode_init_vlc(void)
Definition ituh263dec.c:136
int ff_h263_decode_picture_header(H263DecContext *const h)
int ff_intel_h263_decode_picture_header(H263DecContext *const h)
#define SLICE_NOEND
no end marker or error found but mb count exceeded
Definition h263dec.h:96
int ff_h263_decode_mb(H263DecContext *const h)
Definition ituh263dec.c:784
#define FRAME_SKIPPED
Frame is not coded.
Definition h263dec.h:90
int ff_h263_resync(H263DecContext *const h)
Decode the group of blocks / video packet header / slice header (MPEG-4 Studio).
Definition ituh263dec.c:217
#define FF_HW_SIMPLE_CALL(avctx, function)
#define FF_HW_CALL(avctx, function,...)
#define HWACCEL_NVDEC_CUARRAY(codec)
Definition hwconfig.h:70
#define HWACCEL_VDPAU(codec)
Definition hwconfig.h:74
#define HWACCEL_NVDEC(codec)
Definition hwconfig.h:68
#define HWACCEL_VAAPI(codec)
Definition hwconfig.h:72
#define HWACCEL_VIDEOTOOLBOX(codec)
Definition hwconfig.h:76
#define AV_RL32(p)
#define AV_RB64(p)
int ff_flv_decode_picture_header(H263DecContext *const h)
Definition flvdec.c:29
#define SLICE_END
end marker found
Definition h261dec.c:42
av_cold int ff_h263_decode_init(AVCodecContext *avctx)
Definition h263dec.c:94
static int decode_slice(H263DecContext *const h)
Definition h263dec.c:198
static enum AVPixelFormat h263_get_format(AVCodecContext *avctx)
Definition h263dec.c:72
int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, int *got_frame, AVPacket *avpkt)
Definition h263dec.c:443
static enum AVPixelFormat h263_hwaccel_pixfmt_list_420[]
Definition h263dec.c:52
static void report_decode_progress(H263DecContext *const h)
Definition h263dec.c:192
static const AVCodecHWConfigInternal *const h263_hw_config_list[]
Definition h263dec.c:667
av_cold void ff_h263dsp_init(H263DSPContext *ctx)
Definition h263dsp.c:117
av_cold void ff_permute_scantable(uint8_t dst[64], const uint8_t src[64], const uint8_t permutation[64])
Definition idctdsp.c:30
Multithreading API for decoders.
#define av_cold
Definition attributes.h:117
void ff_mpeg4_clean_buffers(MpegEncContext *s)
Definition mpeg4video.c:44
int ff_mpeg4_decode_partitions(H263DecContext *const h)
Decode the first and second partition.
int ff_mpeg4_decode_studio_slice_header(H263DecContext *const h)
Decode the next video packet.
int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt)
void ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
static void ff_mpv_er_frame_start_ext(MPVContext *const s, int partitioned_frame, uint16_t pp_time, uint16_t pb_time)
Definition mpeg_er.h:27
void ff_mpv_unref_picture(MPVWorkPicture *pic)
Definition mpegpicture.c:98
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
Definition mpegvideo.c:359
av_cold void ff_mpv_idct_init(MpegEncContext *s)
Definition mpegvideo.c:81
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
Definition mpegvideo.c:505
void ff_init_block_index(MpegEncContext *s)
Definition mpegvideo.c:472
mpegvideo header.
static void ff_update_block_index(MpegEncContext *s, int bits_per_raw_sample, int lowres, int chroma_x_shift)
Definition mpegvideo.h:335
#define MV_DIR_FORWARD
Definition mpegvideo.h:168
#define MV_TYPE_16X16
1 vector for the whole mb
Definition mpegvideo.h:172
@ FMT_H263
Definition mpegvideo.h:57
int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
generic function called after decoding the header and before a frame is decoded.
av_cold void ff_mpeg_flush(AVCodecContext *avctx)
void ff_mpv_frame_end(MpegEncContext *s)
int ff_mpv_export_qp_table(const MpegEncContext *s, AVFrame *f, const MPVPicture *p, int qp_type)
void ff_print_debug_info(const MpegEncContext *s, const MPVPicture *p, AVFrame *pict)
av_cold int ff_mpv_decode_close(AVCodecContext *avctx)
void ff_mpv_reconstruct_mb(MPVContext *s, int16_t block[][64])
av_cold int ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
Initialize the given MpegEncContext for decoding.
void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
av_cold int ff_mpv_common_frame_size_change(MpegEncContext *s)
#define ff_mpv_unquantize_init(s, bitexact, q_scale_type)
const uint8_t ff_alternate_horizontal_scan[64]
const uint8_t ff_alternate_vertical_scan[64]
static const uint8_t *const ff_mpeg1_dc_scale_table
mpegvideo decoder header.
#define FF_MPV_QSCALE_TYPE_MPEG1
int ff_msmpeg4_decode_ext_header(H263DecContext *const h, int buf_size)
Definition msmpeg4dec.c:529
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
Definition pixfmt.h:805
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:766
@ AVCOL_RANGE_UNSPECIFIED
Definition pixfmt.h:749
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
Definition pixfmt.h:305
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition pixfmt.h:81
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition pixfmt.h:260
@ AV_PIX_FMT_CUARRAY
hardware decoding through openharmony
Definition pixfmt.h:506
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
Definition pixfmt.h:126
@ AV_PIX_FMT_VDPAU
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition pixfmt.h:194
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
main external API structure.
Definition avcodec.h:443
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:643
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition avcodec.h:681
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition avcodec.h:468
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
Definition avcodec.h:628
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition avcodec.h:1423
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition avcodec.h:709
const struct AVCodec * codec
Definition avcodec.h:452
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition avcodec.h:1571
int flags
AV_CODEC_FLAG_*.
Definition avcodec.h:500
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition avcodec.h:526
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition avcodec.h:688
enum AVCodecID codec_id
Definition avcodec.h:453
int extradata_size
Definition avcodec.h:527
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition avcodec.h:619
void * priv_data
Definition avcodec.h:470
enum AVDiscard skip_frame
Skip decoding for selected frames.
Definition avcodec.h:1667
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition avcodec.h:1416
enum AVCodecID id
Definition codec.h:189
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition frame.h:493
int height
Definition frame.h:544
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition frame.h:517
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition frame.h:559
This structure stores compressed data.
Definition packet.h:580
int size
Definition packet.h:604
uint8_t * data
Definition packet.h:603
void(* dct_unquantize_h263_inter)(const MPVContext *s, int16_t *block, int n, int qscale)
void(* dct_unquantize_h263_intra)(const MPVContext *s, int16_t *block, int n, int qscale)
MpegEncContext.
Definition mpegvideo.h:67
static int64_t frame_end(const SyncQueue *sq, SyncQueueFrame frame, int nb_samples)
Compute the end timestamp of a frame.
Definition sync_queue.c:118
#define ff_dlog(a,...)
#define ff_tlog(a,...)
#define av_log(a,...)
void ff_thread_progress_report(ThreadProgress *pro, int n)
This function is a no-op in no-op mode; otherwise it notifies other threads that a certain level of p...
static double c[64]
int ff_wmv2_decode_secondary_picture_header(H263DecContext *const h)
Definition wmv2dec.c:452