FFmpeg
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"
47 #include "mpegvideo_unquantize.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_VDPAU_HWACCEL
61 #endif
62 #if CONFIG_H263_VIDEOTOOLBOX_HWACCEL || CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL
64 #endif
67 };
68 
70 {
71  /* MPEG-4 Studio Profile only, not supported by hardware */
72  if (avctx->bits_per_raw_sample > 8) {
73  av_assert1(((MpegEncContext *)avctx->priv_data)->studio_profile);
74  return avctx->pix_fmt;
75  }
76 
77  if (CONFIG_GRAY && (avctx->flags & AV_CODEC_FLAG_GRAY)) {
80  return AV_PIX_FMT_GRAY8;
81  }
82 
83  if (avctx->codec_id == AV_CODEC_ID_H263 ||
84  avctx->codec_id == AV_CODEC_ID_H263P ||
85  avctx->codec_id == AV_CODEC_ID_MPEG4)
86  return avctx->pix_fmt = ff_get_format(avctx, h263_hwaccel_pixfmt_list_420);
87 
88  return AV_PIX_FMT_YUV420P;
89 }
90 
92 {
93  H263DecContext *const h = avctx->priv_data;
94  MPVContext *const s = &h->c;
95  MPVUnquantDSPContext unquant_dsp_ctx;
96  int ret;
97 
98  s->out_format = FMT_H263;
99 
100  // set defaults
101  ret = ff_mpv_decode_init(s, avctx);
102  if (ret < 0)
103  return ret;
104 
105  h->decode_mb = ff_h263_decode_mb;
106  s->low_delay = 1;
107 
108  s->y_dc_scale_table =
109  s->c_dc_scale_table = ff_mpeg1_dc_scale_table;
110 
111  ff_permute_scantable(h->permutated_intra_h_scantable, ff_alternate_horizontal_scan,
112  s->idsp.idct_permutation);
113  ff_permute_scantable(h->permutated_intra_v_scantable, ff_alternate_vertical_scan,
114  s->idsp.idct_permutation);
115 
116  ff_mpv_unquantize_init(&unquant_dsp_ctx,
117  avctx->flags & AV_CODEC_FLAG_BITEXACT, 0);
118  // dct_unquantize defaults for H.263;
119  // they might change on a per-frame basis for MPEG-4;
120  // dct_unquantize_inter will be unset for MSMPEG4 codecs later.
121  s->dct_unquantize_intra = unquant_dsp_ctx.dct_unquantize_h263_intra;
122  s->dct_unquantize_inter = unquant_dsp_ctx.dct_unquantize_h263_inter;
123 
124  /* select sub codec */
125  switch (avctx->codec->id) {
126  case AV_CODEC_ID_H263:
127  case AV_CODEC_ID_H263P:
129  h->decode_header = ff_h263_decode_picture_header;
130  break;
131  case AV_CODEC_ID_MPEG4:
132  break;
134  s->h263_pred = 1;
135  s->msmpeg4_version = MSMP4_V1;
136  break;
138  s->h263_pred = 1;
139  s->msmpeg4_version = MSMP4_V2;
140  break;
142  s->h263_pred = 1;
143  s->msmpeg4_version = MSMP4_V3;
144  break;
145  case AV_CODEC_ID_WMV1:
146  s->h263_pred = 1;
147  s->msmpeg4_version = MSMP4_WMV1;
148  break;
149  case AV_CODEC_ID_WMV2:
150  s->h263_pred = 1;
151  s->msmpeg4_version = MSMP4_WMV2;
152  break;
153  case AV_CODEC_ID_RV10:
154  case AV_CODEC_ID_RV20:
155  break;
156 #if CONFIG_H263I_DECODER
157  case AV_CODEC_ID_H263I:
158  h->decode_header = ff_intel_h263_decode_picture_header;
159  break;
160 #endif
161 #if CONFIG_FLV_DECODER
162  case AV_CODEC_ID_FLV1:
163  h->decode_header = ff_flv_decode_picture_header;
164  break;
165 #endif
166  default:
167  av_unreachable("Switch contains a case for every codec using ff_h263_decode_init()");
168  }
169 
170  if (avctx->codec_tag == AV_RL32("L263") || avctx->codec_tag == AV_RL32("S263"))
171  if (avctx->extradata_size == 56 && avctx->extradata[0] == 1)
172  h->ehc_mode = 1;
173 
174  /* for H.263, we allocate the images after having read the header */
175  if (avctx->codec->id != AV_CODEC_ID_H263 &&
176  avctx->codec->id != AV_CODEC_ID_H263P &&
177  avctx->codec->id != AV_CODEC_ID_MPEG4) {
178  avctx->pix_fmt = h263_get_format(avctx);
179  if ((ret = ff_mpv_common_init(s)) < 0)
180  return ret;
181  }
182 
183  ff_h263dsp_init(&s->h263dsp);
185 
186  return 0;
187 }
188 
190 {
191  if (h->c.pict_type != AV_PICTURE_TYPE_B && !h->partitioned_frame && !h->c.er.error_occurred)
192  ff_thread_progress_report(&h->c.cur_pic.ptr->progress, h->c.mb_y);
193 }
194 
195 static int decode_slice(H263DecContext *const h)
196 {
197  const int part_mask = h->partitioned_frame
198  ? (ER_AC_END | ER_AC_ERROR) : 0x7F;
199  const int mb_size = 16 >> h->c.avctx->lowres;
200  int ret;
201 
202  h->last_resync_gb = h->gb;
203  h->c.first_slice_line = 1;
204  h->c.resync_mb_x = h->c.mb_x;
205  h->c.resync_mb_y = h->c.mb_y;
206 
207  ff_set_qscale(&h->c, h->c.qscale);
208 
209 #if CONFIG_MPEG4_DECODER
210  if (h->c.studio_profile) {
212  return ret;
213  }
214 #endif
215 
216  if (h->c.avctx->hwaccel) {
217  const uint8_t *start = h->gb.buffer + get_bits_count(&h->gb) / 8;
218  ret = FF_HW_CALL(h->c.avctx, decode_slice, start,
219  get_bits_bytesize(&h->gb, 0) - get_bits_count(&h->gb) / 8);
220  // ensure we exit decode loop
221  h->c.mb_y = h->c.mb_height;
222  return ret;
223  }
224 
225 #if CONFIG_MPEG4_DECODER
226  if (h->partitioned_frame) {
227  const int qscale = h->c.qscale;
228 
229  av_assert1(h->c.codec_id == AV_CODEC_ID_MPEG4);
230 
232  if (ret < 0)
233  return ret;
234 
235  /* restore variables which were modified */
236  h->c.first_slice_line = 1;
237  h->c.mb_x = h->c.resync_mb_x;
238  h->c.mb_y = h->c.resync_mb_y;
239  ff_set_qscale(&h->c, qscale);
240  }
241 #endif
242 
243  for (; h->c.mb_y < h->c.mb_height; h->c.mb_y++) {
244  /* per-row end of slice checks */
245  if (h->c.msmpeg4_version != MSMP4_UNUSED) {
246  if (h->c.resync_mb_y + h->slice_height == h->c.mb_y) {
247  ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
248  h->c.mb_x - 1, h->c.mb_y, ER_MB_END);
249 
250  return 0;
251  }
252  }
253 
254  if (h->c.msmpeg4_version == MSMP4_V1) {
255  h->last_dc[0] =
256  h->last_dc[1] =
257  h->last_dc[2] = 128;
258  }
259 
260  ff_init_block_index(&h->c);
261  for (; h->c.mb_x < h->c.mb_width; h->c.mb_x++) {
262  int ret;
263 
264  ff_update_block_index(&h->c, h->c.avctx->bits_per_raw_sample,
265  h->c.avctx->lowres, h->c.chroma_x_shift);
266 
267  if (h->c.resync_mb_x == h->c.mb_x && h->c.resync_mb_y + 1 == h->c.mb_y)
268  h->c.first_slice_line = 0;
269 
270  /* DCT & quantize */
271 
272  h->c.mv_dir = MV_DIR_FORWARD;
273  h->c.mv_type = MV_TYPE_16X16;
274  ff_dlog(h->c.avctx, "%d %06X\n",
275  get_bits_count(&h->gb), show_bits(&h->gb, 24));
276 
277  ff_tlog(NULL, "Decoding MB at %dx%d\n", h->c.mb_x, h->c.mb_y);
278  ret = h->decode_mb(h);
279 
280  if (h->c.h263_pred || h->c.h263_aic) {
281  int mb_xy = h->c.mb_y * h->c.mb_stride + h->c.mb_x;
282  if (!h->c.mb_intra) {
284  } else
285  h->c.mbintra_table[mb_xy] = 1;
286  }
287 
288  if (h->c.pict_type != AV_PICTURE_TYPE_B)
290 
291  if (ret < 0) {
292  const int xy = h->c.mb_x + h->c.mb_y * h->c.mb_stride;
293  if (ret == SLICE_END) {
294  ff_mpv_reconstruct_mb(&h->c, h->block);
295  if (h->loop_filter)
296  ff_h263_loop_filter(&h->c);
297 
298  ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
299  h->c.mb_x, h->c.mb_y, ER_MB_END & part_mask);
300 
301  h->padding_bug_score--;
302 
303  if (++h->c.mb_x >= h->c.mb_width) {
304  h->c.mb_x = 0;
306  ff_mpeg_draw_horiz_band(&h->c, h->c.mb_y * mb_size, mb_size);
307  h->c.mb_y++;
308  }
309  return 0;
310  } else if (ret == SLICE_NOEND) {
311  av_log(h->c.avctx, AV_LOG_ERROR,
312  "Slice mismatch at MB: %d\n", xy);
313  ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
314  h->c.mb_x + 1, h->c.mb_y,
315  ER_MB_END & part_mask);
316  return AVERROR_INVALIDDATA;
317  }
318  av_log(h->c.avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy);
319  ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
320  h->c.mb_x, h->c.mb_y, ER_MB_ERROR & part_mask);
321 
322  if ((h->c.avctx->err_recognition & AV_EF_IGNORE_ERR) && get_bits_left(&h->gb) > 0)
323  continue;
324  return AVERROR_INVALIDDATA;
325  }
326 
327  ff_mpv_reconstruct_mb(&h->c, h->block);
328  if (h->loop_filter)
329  ff_h263_loop_filter(&h->c);
330  }
331 
333  ff_mpeg_draw_horiz_band(&h->c, h->c.mb_y * mb_size, mb_size);
334 
335  h->c.mb_x = 0;
336  }
337 
338  av_assert1(h->c.mb_x == 0 && h->c.mb_y == h->c.mb_height);
339 
340  // Detect incorrect padding with wrong stuffing codes used by NEC N-02B
341  if (h->c.codec_id == AV_CODEC_ID_MPEG4 &&
342  (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
343  get_bits_left(&h->gb) >= 48 &&
344  show_bits(&h->gb, 24) == 0x4010 &&
345  !h->data_partitioning)
346  h->padding_bug_score += 32;
347 
348  /* try to detect the padding bug */
349  if (h->c.codec_id == AV_CODEC_ID_MPEG4 &&
350  (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
351  get_bits_left(&h->gb) >= 0 &&
352  get_bits_left(&h->gb) < 137 &&
353  !h->data_partitioning) {
354  const int bits_count = get_bits_count(&h->gb);
355  const int bits_left = h->gb.size_in_bits - bits_count;
356 
357  if (bits_left == 0) {
358  h->padding_bug_score += 16;
359  } else if (bits_left != 1) {
360  int v = show_bits(&h->gb, 8);
361  v |= 0x7F >> (7 - (bits_count & 7));
362 
363  if (v == 0x7F && bits_left <= 8)
364  h->padding_bug_score--;
365  else if (v == 0x7F && ((get_bits_count(&h->gb) + 8) & 8) &&
366  bits_left <= 16)
367  h->padding_bug_score += 4;
368  else
369  h->padding_bug_score++;
370  }
371  }
372 
373  if (h->c.codec_id == AV_CODEC_ID_H263 &&
374  (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
375  get_bits_left(&h->gb) >= 8 &&
376  get_bits_left(&h->gb) < 300 &&
377  h->c.pict_type == AV_PICTURE_TYPE_I &&
378  show_bits(&h->gb, 8) == 0 &&
379  !h->data_partitioning) {
380 
381  h->padding_bug_score += 32;
382  }
383 
384  if (h->c.codec_id == AV_CODEC_ID_H263 &&
385  (h->c.workaround_bugs & FF_BUG_AUTODETECT) &&
386  get_bits_left(&h->gb) >= 64 &&
387  AV_RB64(h->gb.buffer + (get_bits_bytesize(&h->gb, 0) - 8)) == 0xCDCDCDCDFC7F0000) {
388 
389  h->padding_bug_score += 32;
390  }
391 
392  if (h->c.workaround_bugs & FF_BUG_AUTODETECT) {
393  if (
394  (h->padding_bug_score > -2 && !h->data_partitioning))
395  h->c.workaround_bugs |= FF_BUG_NO_PADDING;
396  else
397  h->c.workaround_bugs &= ~FF_BUG_NO_PADDING;
398  }
399 
400  // handle formats which don't have unique end markers
401  if (h->c.msmpeg4_version != MSMP4_UNUSED || (h->c.workaround_bugs & FF_BUG_NO_PADDING)) { // FIXME perhaps solve this more cleanly
402  int left = get_bits_left(&h->gb);
403  int max_extra = 7;
404 
405  /* no markers in M$ crap */
406  if (h->c.msmpeg4_version != MSMP4_UNUSED && h->c.pict_type == AV_PICTURE_TYPE_I)
407  max_extra += 17;
408 
409  /* buggy padding but the frame should still end approximately at
410  * the bitstream end */
411  if ((h->c.workaround_bugs & FF_BUG_NO_PADDING) &&
412  (h->c.avctx->err_recognition & (AV_EF_BUFFER|AV_EF_AGGRESSIVE)))
413  max_extra += 48;
414  else if ((h->c.workaround_bugs & FF_BUG_NO_PADDING))
415  max_extra += 256 * 256 * 256 * 64;
416 
417  if (left > max_extra)
418  av_log(h->c.avctx, AV_LOG_ERROR,
419  "discarding %d junk bits at end, next would be %X\n",
420  left, show_bits(&h->gb, 24));
421  else if (left < 0)
422  av_log(h->c.avctx, AV_LOG_ERROR, "overreading %d bits\n", -left);
423  else
424  ff_er_add_slice(&h->c.er, h->c.resync_mb_x, h->c.resync_mb_y,
425  h->c.mb_x - 1, h->c.mb_y, ER_MB_END);
426 
427  return 0;
428  }
429 
430  av_log(h->c.avctx, AV_LOG_ERROR,
431  "slice end not reached but screenspace end (%d left %06X, score= %d)\n",
432  get_bits_left(&h->gb), show_bits(&h->gb, 24), h->padding_bug_score);
433 
434  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,
435  ER_MB_END & part_mask);
436 
437  return AVERROR_INVALIDDATA;
438 }
439 
441  int *got_frame, AVPacket *avpkt)
442 {
443  H263DecContext *const h = avctx->priv_data;
444  MPVContext *const s = &h->c;
445  const uint8_t *buf = avpkt->data;
446  int buf_size = avpkt->size;
447  int ret;
448  int slice_ret = 0;
449  int bak_width, bak_height;
450 
451  /* no supplementary picture */
452  if (buf_size == 0) {
453  /* special case for last picture */
454  if ((!h->c.low_delay || h->skipped_last_frame) && h->c.next_pic.ptr) {
455  if ((ret = av_frame_ref(pict, h->c.next_pic.ptr->f)) < 0)
456  return ret;
457  if (h->skipped_last_frame) {
458  /* If the stream ended with an NVOP, we output the last frame
459  * in display order, but with the props from the last input
460  * packet so that the stream's end time is correct. */
461  ret = ff_decode_frame_props(avctx, pict);
462  if (ret < 0)
463  return ret;
464  }
465 
466  ff_mpv_unref_picture(&h->c.next_pic);
467 
468  *got_frame = 1;
469  }
470 
471  return 0;
472  }
473 
474  // h->gb might be overridden in ff_mpeg4_decode_picture_header() below.
475  ret = init_get_bits8(&h->gb, buf, buf_size);
476  if (ret < 0)
477  return ret;
478 
479  bak_width = h->c.width;
480  bak_height = h->c.height;
481 
482  /* let's go :-) */
483  ret = h->decode_header(h);
484  if (ret < 0 || ret == FRAME_SKIPPED) {
485  if ( h->c.width != bak_width
486  || h->c.height != bak_height) {
487  av_log(h->c.avctx, AV_LOG_WARNING, "Reverting picture dimensions change due to header decoding failure\n");
488  h->c.width = bak_width;
489  h->c.height= bak_height;
490 
491  }
492  }
493  if (ret == FRAME_SKIPPED)
494  return buf_size;
495 
496  /* skip if the header was thrashed */
497  if (ret < 0) {
498  av_log(h->c.avctx, AV_LOG_ERROR, "header damaged\n");
499  return ret;
500  }
501 
502  if (!h->c.context_initialized) {
503  avctx->pix_fmt = h263_get_format(avctx);
504  if ((ret = ff_mpv_common_init(s)) < 0)
505  return ret;
506  }
507 
508  avctx->has_b_frames = !h->c.low_delay;
509 
510 #if CONFIG_MPEG4_DECODER
511  if (avctx->codec_id == AV_CODEC_ID_MPEG4) {
512  if (h->c.pict_type != AV_PICTURE_TYPE_B && h->c.mb_num/2 > get_bits_left(&h->gb))
513  return AVERROR_INVALIDDATA;
515  if (h->c.studio_profile != (h->c.idsp.idct == NULL))
517  }
518 #endif
519 
520  /* After H.263 & MPEG-4 header decode we have the height, width,
521  * and other parameters. So then we could init the picture. */
522  if (h->c.width != avctx->coded_width ||
523  h->c.height != avctx->coded_height ||
524  h->c.context_reinit) {
525  /* H.263 could change picture size any time */
526  h->c.context_reinit = 0;
527 
528  ret = ff_set_dimensions(avctx, h->c.width, h->c.height);
529  if (ret < 0)
530  return ret;
531 
532  ff_set_sar(avctx, avctx->sample_aspect_ratio);
533 
535  return ret;
536 
537  if (avctx->pix_fmt != h263_get_format(avctx)) {
538  av_log(avctx, AV_LOG_ERROR, "format change not supported\n");
539  avctx->pix_fmt = AV_PIX_FMT_NONE;
540  return AVERROR_UNKNOWN;
541  }
542  }
543 
544  /* skip B-frames if we don't have reference frames */
545  if (!h->c.last_pic.ptr &&
546  (h->c.pict_type == AV_PICTURE_TYPE_B || h->c.droppable))
547  return buf_size;
548  if ((avctx->skip_frame >= AVDISCARD_NONREF &&
549  h->c.pict_type == AV_PICTURE_TYPE_B) ||
550  (avctx->skip_frame >= AVDISCARD_NONKEY &&
551  h->c.pict_type != AV_PICTURE_TYPE_I) ||
552  avctx->skip_frame >= AVDISCARD_ALL)
553  return buf_size;
554 
555  if ((ret = ff_mpv_frame_start(s, avctx)) < 0)
556  return ret;
557 
558  if (!h->divx_packed)
559  ff_thread_finish_setup(avctx);
560 
561  if (avctx->hwaccel) {
562  ret = FF_HW_CALL(avctx, start_frame, NULL,
563  h->gb.buffer, get_bits_bytesize(&h->gb, 0));
564  if (ret < 0 )
565  return ret;
566  }
567 
568  ff_mpv_er_frame_start_ext(s, h->partitioned_frame,
569  s->pp_time, s->pb_time);
570 
571  /* the second part of the wmv2 header contains the MB skip bits which
572  * are stored in current_picture->mb_type which is not available before
573  * ff_mpv_frame_start() */
574 #if CONFIG_WMV2_DECODER
575  if (h->c.msmpeg4_version == MSMP4_WMV2) {
577  if (ret < 0)
578  return ret;
579  if (ret == 1)
580  goto frame_end;
581  }
582 #endif
583 
584  /* decode each macroblock */
585  h->c.mb_x = 0;
586  h->c.mb_y = 0;
587 
588  slice_ret = decode_slice(h);
589  while (h->c.mb_y < h->c.mb_height) {
590  if (h->c.msmpeg4_version != MSMP4_UNUSED) {
591  if (h->slice_height == 0 || h->c.mb_x != 0 || slice_ret < 0 ||
592  (h->c.mb_y % h->slice_height) != 0 || get_bits_left(&h->gb) < 0)
593  break;
594  } else {
595  int prev_x = h->c.mb_x, prev_y = h->c.mb_y;
596  if (ff_h263_resync(h) < 0)
597  break;
598  if (prev_y * h->c.mb_width + prev_x < h->c.mb_y * h->c.mb_width + h->c.mb_x)
599  h->c.er.error_occurred = 1;
600  }
601 
602  if (h->c.msmpeg4_version < MSMP4_WMV1 && h->c.h263_pred)
604 
605  if (decode_slice(h) < 0)
606  slice_ret = AVERROR_INVALIDDATA;
607  }
608 
609  if (h->c.msmpeg4_version != MSMP4_UNUSED && h->c.msmpeg4_version < MSMP4_WMV1 &&
610  h->c.pict_type == AV_PICTURE_TYPE_I)
611  if (!CONFIG_MSMPEG4DEC ||
612  ff_msmpeg4_decode_ext_header(h, buf_size) < 0)
613  h->c.er.error_status_table[h->c.mb_num - 1] = ER_MB_ERROR;
614 
615 frame_end:
616  if (!h->c.studio_profile)
617  ff_er_frame_end(&h->c.er, NULL);
618 
619  if (avctx->hwaccel) {
620  ret = FF_HW_SIMPLE_CALL(avctx, end_frame);
621  if (ret < 0)
622  return ret;
623  }
624 
626 
627 #if CONFIG_MPEG4_DECODER
628  if (avctx->codec_id == AV_CODEC_ID_MPEG4)
629  ff_mpeg4_frame_end(avctx, avpkt);
630 #endif
631 
632  av_assert1(h->c.pict_type == h->c.cur_pic.ptr->f->pict_type);
633  if (h->c.pict_type == AV_PICTURE_TYPE_B || h->c.low_delay) {
634  if ((ret = av_frame_ref(pict, h->c.cur_pic.ptr->f)) < 0)
635  return ret;
636  ff_print_debug_info(s, h->c.cur_pic.ptr, pict);
637  ff_mpv_export_qp_table(s, pict, h->c.cur_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1);
638  } else if (h->c.last_pic.ptr) {
639  if ((ret = av_frame_ref(pict, h->c.last_pic.ptr->f)) < 0)
640  return ret;
641  ff_print_debug_info(s, h->c.last_pic.ptr, pict);
642  ff_mpv_export_qp_table(s, pict, h->c.last_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1);
643  }
644 
645  if (h->c.last_pic.ptr || h->c.low_delay) {
646  if ( pict->format == AV_PIX_FMT_YUV420P
647  && (h->c.codec_tag == AV_RL32("GEOV") || h->c.codec_tag == AV_RL32("GEOX"))) {
648  for (int p = 0; p < 3; p++) {
649  int h = AV_CEIL_RSHIFT(pict->height, !!p);
650 
651  pict->data[p] += (h - 1) * pict->linesize[p];
652  pict->linesize[p] *= -1;
653  }
654  }
655  *got_frame = 1;
656  }
657 
658  if (slice_ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))
659  return slice_ret;
660  else
661  return buf_size;
662 }
663 
665 #if CONFIG_H263_VAAPI_HWACCEL
666  HWACCEL_VAAPI(h263),
667 #endif
668 #if CONFIG_MPEG4_NVDEC_HWACCEL
669  HWACCEL_NVDEC(mpeg4),
670 #endif
671 #if CONFIG_MPEG4_VDPAU_HWACCEL
672  HWACCEL_VDPAU(mpeg4),
673 #endif
674 #if CONFIG_H263_VIDEOTOOLBOX_HWACCEL
675  HWACCEL_VIDEOTOOLBOX(h263),
676 #endif
677  NULL
678 };
679 
681  .p.name = "h263",
682  CODEC_LONG_NAME("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"),
683  .p.type = AVMEDIA_TYPE_VIDEO,
684  .p.id = AV_CODEC_ID_H263,
685  .priv_data_size = sizeof(H263DecContext),
688  .close = ff_mpv_decode_close,
689  .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
691  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
693  .flush = ff_mpeg_flush,
694  .p.max_lowres = 3,
695  .hw_configs = h263_hw_config_list,
696 };
697 
699  .p.name = "h263p",
700  CODEC_LONG_NAME("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"),
701  .p.type = AVMEDIA_TYPE_VIDEO,
702  .p.id = AV_CODEC_ID_H263P,
703  .priv_data_size = sizeof(H263DecContext),
706  .close = ff_mpv_decode_close,
707  .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
709  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
711  .flush = ff_mpeg_flush,
712  .p.max_lowres = 3,
713  .hw_configs = h263_hw_config_list,
714 };
ff_mpv_common_init
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
Definition: mpegvideo.c:359
hwconfig.h
mpegvideo_unquantize.h
AVCodecContext::hwaccel
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:1413
MV_TYPE_16X16
#define MV_TYPE_16X16
1 vector for the whole mb
Definition: mpegvideo.h:172
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:216
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:260
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
ff_mpeg4_frame_end
int ff_mpeg4_frame_end(AVCodecContext *avctx, const AVPacket *pkt)
AV_EF_EXPLODE
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: defs.h:51
ff_thread_progress_report
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...
Definition: threadprogress.c:53
ff_h263_resync
int ff_h263_resync(H263DecContext *const h)
Decode the group of blocks / video packet header / slice header (MPEG-4 Studio).
Definition: ituh263dec.c:217
h263_hw_config_list
static const AVCodecHWConfigInternal *const h263_hw_config_list[]
Definition: h263dec.c:664
report_decode_progress
static void report_decode_progress(H263DecContext *const h)
Definition: h263dec.c:189
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:694
ff_mpv_decode_init
av_cold int ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
Initialize the given MpegEncContext for decoding.
Definition: mpegvideo_dec.c:86
ff_get_format
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1208
mpeg4videodec.h
AVCodecContext::err_recognition
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:1406
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:254
ff_wmv2_decode_secondary_picture_header
int ff_wmv2_decode_secondary_picture_header(H263DecContext *const h)
Definition: wmv2dec.c:448
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:64
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:427
AVPacket::data
uint8_t * data
Definition: packet.h:588
FFCodec
Definition: codec_internal.h:127
FF_HW_SIMPLE_CALL
#define FF_HW_SIMPLE_CALL(avctx, function)
Definition: hwaccel_internal.h:176
ff_er_add_slice
void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy, int status)
Add a slice.
Definition: error_resilience.c:828
ff_init_block_index
void ff_init_block_index(MpegEncContext *s)
Definition: mpegvideo.c:472
mpegvideo.h
AVERROR_UNKNOWN
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:73
ff_set_dimensions
int ff_set_dimensions(AVCodecContext *s, int width, int height)
Check that the provided frame dimensions are valid and set them on the codec context.
Definition: utils.c:91
thread.h
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:448
ff_permute_scantable
av_cold void ff_permute_scantable(uint8_t dst[64], const uint8_t src[64], const uint8_t permutation[64])
Definition: idctdsp.c:30
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:448
AVCodecContext::skip_frame
enum AVDiscard skip_frame
Skip decoding for selected frames.
Definition: avcodec.h:1670
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:496
HWACCEL_VDPAU
#define HWACCEL_VDPAU(codec)
Definition: hwconfig.h:72
AVCodecContext::coded_height
int coded_height
Definition: avcodec.h:615
AV_CODEC_ID_MSMPEG4V2
@ AV_CODEC_ID_MSMPEG4V2
Definition: codec_id.h:67
ff_h263_update_motion_val
void ff_h263_update_motion_val(MpegEncContext *s)
Definition: h263.c:56
frame_end
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
mpegvideodec.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:210
h263dec.h
av_cold
#define av_cold
Definition: attributes.h:106
AV_CODEC_ID_H263I
@ AV_CODEC_ID_H263I
Definition: codec_id.h:72
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:544
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:523
AVCodecContext::has_b_frames
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:705
ff_er_frame_end
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...
Definition: error_resilience.c:898
ff_mpeg_flush
av_cold void ff_mpeg_flush(AVCodecContext *avctx)
Definition: mpegvideo_dec.c:452
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:347
s
#define s(width, name)
Definition: cbs_vp9.c:198
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:60
h263_get_format
static enum AVPixelFormat h263_get_format(AVCodecContext *avctx)
Definition: h263dec.c:69
ff_mpeg4_workaround_bugs
void ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
ff_msmpeg4_decode_ext_header
int ff_msmpeg4_decode_ext_header(H263DecContext *const h, int buf_size)
Definition: msmpeg4dec.c:529
FF_BUG_NO_PADDING
#define FF_BUG_NO_PADDING
Definition: avcodec.h:1339
AV_CODEC_ID_WMV2
@ AV_CODEC_ID_WMV2
Definition: codec_id.h:70
ff_mpeg1_dc_scale_table
static const uint8_t *const ff_mpeg1_dc_scale_table
Definition: mpegvideodata.h:32
AV_EF_IGNORE_ERR
#define AV_EF_IGNORE_ERR
ignore errors and continue
Definition: defs.h:53
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1561
decode.h
AV_CODEC_ID_MSMPEG4V1
@ AV_CODEC_ID_MSMPEG4V1
Definition: codec_id.h:66
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:332
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:449
FMT_H263
@ FMT_H263
Definition: mpegvideo.h:57
ff_mpv_unref_picture
void ff_mpv_unref_picture(MPVWorkPicture *pic)
Definition: mpegpicture.c:98
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:232
ff_h263_decode_init_vlc
void ff_h263_decode_init_vlc(void)
Definition: ituh263dec.c:136
ff_h263_decode_mb
int ff_h263_decode_mb(H263DecContext *const h)
Definition: ituh263dec.c:784
ff_mpv_export_qp_table
int ff_mpv_export_qp_table(const MpegEncContext *s, AVFrame *f, const MPVPicture *p, int qp_type)
Definition: mpegvideo_dec.c:413
NULL
#define NULL
Definition: coverity.c:32
bits_left
#define bits_left
Definition: bitstream.h:116
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:677
ER_AC_ERROR
#define ER_AC_ERROR
Definition: error_resilience.h:29
hwaccel_internal.h
ff_mpv_idct_init
av_cold void ff_mpv_idct_init(MpegEncContext *s)
Definition: mpegvideo.c:81
ff_mpv_decode_close
av_cold int ff_mpv_decode_close(AVCodecContext *avctx)
Definition: mpegvideo_dec.c:166
av_unreachable
#define av_unreachable(msg)
Asserts that are used as compiler optimization hints depending upon ASSERT_LEVEL and NBDEBUG.
Definition: avassert.h:108
ER_MB_ERROR
#define ER_MB_ERROR
Definition: error_resilience.h:36
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:278
ff_set_qscale
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
Definition: mpegvideo.c:505
ff_set_sar
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
ff_h263_decode_frame
int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, int *got_frame, AVPacket *avpkt)
Definition: h263dec.c:440
ff_mpv_unquantize_init
#define ff_mpv_unquantize_init(s, bitexact, q_scale_type)
Definition: mpegvideo_unquantize.h:50
ff_alternate_horizontal_scan
const uint8_t ff_alternate_horizontal_scan[64]
Definition: mpegvideodata.c:52
AV_CODEC_ID_WMV1
@ AV_CODEC_ID_WMV1
Definition: codec_id.h:69
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:81
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:743
FF_MPV_QSCALE_TYPE_MPEG1
#define FF_MPV_QSCALE_TYPE_MPEG1
Definition: mpegvideodec.h:40
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
get_bits_bytesize
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
MPVUnquantDSPContext::dct_unquantize_h263_inter
void(* dct_unquantize_h263_inter)(const MPVContext *s, int16_t *block, int n, int qscale)
Definition: mpegvideo_unquantize.h:45
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:28
ff_h263_clean_intra_table_entries
static void ff_h263_clean_intra_table_entries(MpegEncContext *s, int xy)
Definition: h263.h:47
AVDISCARD_NONKEY
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition: defs.h:231
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:550
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AV_CODEC_FLAG_GRAY
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
Definition: avcodec.h:302
AVPacket::size
int size
Definition: packet.h:589
ff_mpeg4_clean_buffers
void ff_mpeg4_clean_buffers(MpegEncContext *s)
Definition: mpeg4video.c:44
av_frame_ref
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
codec_internal.h
FRAME_SKIPPED
#define FRAME_SKIPPED
Frame is not coded.
Definition: h263dec.h:90
ff_update_block_index
static void ff_update_block_index(MpegEncContext *s, int bits_per_raw_sample, int lowres, int chroma_x_shift)
Definition: mpegvideo.h:335
AV_CODEC_ID_H263
@ AV_CODEC_ID_H263
Definition: codec_id.h:56
ff_h263dsp_init
av_cold void ff_h263dsp_init(H263DSPContext *ctx)
Definition: h263dsp.c:117
SLICE_NOEND
#define SLICE_NOEND
no end marker or error found but mb count exceeded
Definition: h263dec.h:96
FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
#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...
Definition: codec_internal.h:54
ff_mpeg_draw_horiz_band
void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
Definition: mpegvideo_dec.c:444
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:514
AVCodecHWConfigInternal
Definition: hwconfig.h:25
ff_mpeg4_decode_studio_slice_header
int ff_mpeg4_decode_studio_slice_header(H263DecContext *const h)
Decode the next video packet.
Definition: mpeg4videodec.c:808
ff_mpv_frame_start
int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
generic function called after decoding the header and before a frame is decoded.
Definition: mpegvideo_dec.c:347
ff_h263_decoder
const FFCodec ff_h263_decoder
Definition: h263dec.c:680
mpegvideodata.h
msmpeg4dec.h
flvdec.h
HWACCEL_NVDEC
#define HWACCEL_NVDEC(codec)
Definition: hwconfig.h:68
AV_PIX_FMT_VAAPI
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
Definition: pixfmt.h:126
AVCodec::id
enum AVCodecID id
Definition: codec.h:186
AV_PIX_FMT_VDPAU
@ AV_PIX_FMT_VDPAU
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition: pixfmt.h:194
AV_PIX_FMT_VIDEOTOOLBOX
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
Definition: pixfmt.h:305
MPVUnquantDSPContext::dct_unquantize_h263_intra
void(* dct_unquantize_h263_intra)(const MPVContext *s, int16_t *block, int n, int qscale)
Definition: mpegvideo_unquantize.h:43
ff_print_debug_info
void ff_print_debug_info(const MpegEncContext *s, const MPVPicture *p, AVFrame *pict)
Definition: mpegvideo_dec.c:406
AV_CODEC_ID_RV10
@ AV_CODEC_ID_RV10
Definition: codec_id.h:57
ff_h263p_decoder
const FFCodec ff_h263p_decoder
Definition: h263dec.c:698
ff_alternate_vertical_scan
const uint8_t ff_alternate_vertical_scan[64]
Definition: mpegvideodata.c:63
AVCodecContext::extradata
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition: avcodec.h:522
show_bits
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:373
ff_intel_h263_decode_picture_header
int ff_intel_h263_decode_picture_header(H263DecContext *const h)
Definition: intelh263dec.c:29
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:57
FF_BUG_AUTODETECT
#define FF_BUG_AUTODETECT
autodetection
Definition: avcodec.h:1336
AV_CODEC_ID_RV20
@ AV_CODEC_ID_RV20
Definition: codec_id.h:58
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:179
ff_h263_decode_init
av_cold int ff_h263_decode_init(AVCodecContext *avctx)
Definition: h263dec.c:91
AVCodecContext::chroma_sample_location
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:684
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:639
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:760
HWACCEL_VIDEOTOOLBOX
#define HWACCEL_VIDEOTOOLBOX(codec)
Definition: hwconfig.h:74
avcodec.h
ret
ret
Definition: filter_design.txt:187
AV_EF_AGGRESSIVE
#define AV_EF_AGGRESSIVE
consider things that a sane encoder/muxer should not do as an error
Definition: defs.h:56
wmv2dec.h
ff_mpv_er_frame_start_ext
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
ff_thread_finish_setup
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call ff_thread_finish_setup() afterwards. If some code can 't be moved
ff_h263_loop_filter
void ff_h263_loop_filter(MpegEncContext *s)
Definition: h263.c:97
left
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
Definition: snow.txt:386
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
H263DecContext
Definition: h263dec.h:43
ff_decode_frame_props
int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
Set various frame properties from the codec context / packet data.
Definition: decode.c:1571
AVCodecContext
main external API structure.
Definition: avcodec.h:439
ff_mpeg4_decode_partitions
int ff_mpeg4_decode_partitions(H263DecContext *const h)
Decode the first and second partition.
Definition: mpeg4videodec.c:1316
AVFrame::height
int height
Definition: frame.h:499
AV_CODEC_ID_H263P
@ AV_CODEC_ID_H263P
Definition: codec_id.h:71
AV_PICTURE_TYPE_B
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition: avutil.h:280
mpeg4video.h
AVCHROMA_LOC_CENTER
@ AVCHROMA_LOC_CENTER
MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0.
Definition: pixfmt.h:799
SLICE_END
#define SLICE_END
end marker found
Definition: h261dec.c:42
error_resilience.h
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
FF_HW_CALL
#define FF_HW_CALL(avctx, function,...)
Definition: hwaccel_internal.h:173
ff_mpv_frame_end
void ff_mpv_frame_end(MpegEncContext *s)
Definition: mpegvideo_dec.c:398
ff_flv_decode_picture_header
int ff_flv_decode_picture_header(H263DecContext *const h)
Definition: flvdec.c:29
AV_CODEC_CAP_DELAY
#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:76
Windows::Graphics::DirectX::Direct3D11::p
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
Definition: vsrc_gfxcapture_winrt.hpp:53
AVCodecContext::coded_width
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:615
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
ff_mpv_reconstruct_mb
void ff_mpv_reconstruct_mb(MPVContext *s, int16_t block[][64])
Definition: mpegvideo_dec.c:1124
AV_EF_BUFFER
#define AV_EF_BUFFER
detect improper bitstream length
Definition: defs.h:50
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:322
ER_MB_END
#define ER_MB_END
Definition: error_resilience.h:37
AVCodecContext::codec_tag
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:464
MV_DIR_FORWARD
#define MV_DIR_FORWARD
Definition: mpegvideo.h:168
ff_tlog
#define ff_tlog(a,...)
Definition: tableprint_vlc.h:29
AVPacket
This structure stores compressed data.
Definition: packet.h:565
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:466
HWACCEL_VAAPI
#define HWACCEL_VAAPI(codec)
Definition: hwconfig.h:70
mpeg_er.h
AVFrame::linesize
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:472
AV_CODEC_CAP_DRAW_HORIZ_BAND
#define AV_CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
Definition: codec.h:44
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
AV_CODEC_ID_MSMPEG4V3
@ AV_CODEC_ID_MSMPEG4V3
Definition: codec_id.h:68
h263_hwaccel_pixfmt_list_420
static enum AVPixelFormat h263_hwaccel_pixfmt_list_420[]
Definition: h263dec.c:52
MPVUnquantDSPContext
Definition: mpegvideo_unquantize.h:34
h
h
Definition: vp9dsp_template.c:2070
ER_AC_END
#define ER_AC_END
Definition: error_resilience.h:32
decode_slice
static int decode_slice(H263DecContext *const h)
Definition: h263dec.c:195
AV_CODEC_ID_FLV1
@ AV_CODEC_ID_FLV1
Definition: codec_id.h:73
AVDISCARD_NONREF
@ AVDISCARD_NONREF
discard all non reference
Definition: defs.h:228
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:67
AVCodecContext::sample_aspect_ratio
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:624
AV_RB64
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_RB64
Definition: bytestream.h:95
ff_h263_decode_picture_header
int ff_h263_decode_picture_header(H263DecContext *const h)
Definition: ituh263dec.c:1092
ff_mpv_common_frame_size_change
av_cold int ff_mpv_common_frame_size_change(MpegEncContext *s)
Definition: mpegvideo_dec.c:175
h263.h