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 "mpeg4videodefs.h"
45 #include "mpegvideo.h"
46 #include "mpegvideodec.h"
47 #include "msmpeg4dec.h"
48 #include "thread.h"
49 #include "wmv2dec.h"
50 
52 #if CONFIG_H263_VAAPI_HWACCEL || CONFIG_MPEG4_VAAPI_HWACCEL
54 #endif
55 #if CONFIG_MPEG4_NVDEC_HWACCEL
57 #endif
58 #if CONFIG_MPEG4_VDPAU_HWACCEL
60 #endif
61 #if CONFIG_H263_VIDEOTOOLBOX_HWACCEL || CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL
63 #endif
66 };
67 
69 {
70  /* MPEG-4 Studio Profile only, not supported by hardware */
71  if (avctx->bits_per_raw_sample > 8) {
72  av_assert1(((MpegEncContext *)avctx->priv_data)->studio_profile);
73  return avctx->pix_fmt;
74  }
75 
76  if (CONFIG_GRAY && (avctx->flags & AV_CODEC_FLAG_GRAY)) {
79  return AV_PIX_FMT_GRAY8;
80  }
81 
82  if (avctx->codec_id == AV_CODEC_ID_H263 ||
83  avctx->codec_id == AV_CODEC_ID_H263P ||
84  avctx->codec_id == AV_CODEC_ID_MPEG4)
85  return avctx->pix_fmt = ff_get_format(avctx, h263_hwaccel_pixfmt_list_420);
86 
87  return AV_PIX_FMT_YUV420P;
88 }
89 
91 {
92  MpegEncContext *s = avctx->priv_data;
93  int ret;
94 
95  s->out_format = FMT_H263;
96 
97  // set defaults
98  ret = ff_mpv_decode_init(s, avctx);
99  if (ret < 0)
100  return ret;
101 
102  s->decode_mb = ff_h263_decode_mb;
103  s->low_delay = 1;
104 
105  // dct_unquantize defaults for H.263;
106  // they might change on a per-frame basis for MPEG-4.
107  s->dct_unquantize_intra = s->dct_unquantize_h263_intra;
108  s->dct_unquantize_inter = s->dct_unquantize_h263_inter;
109 
110  /* select sub codec */
111  switch (avctx->codec->id) {
112  case AV_CODEC_ID_H263:
113  case AV_CODEC_ID_H263P:
115  break;
116  case AV_CODEC_ID_MPEG4:
117  // dct_unquantize_inter is only used with MPEG-2 quantizers,
118  // so we can already set dct_unquantize_inter here once and for all.
119  s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter;
120  break;
122  s->h263_pred = 1;
123  s->msmpeg4_version = MSMP4_V1;
124  break;
126  s->h263_pred = 1;
127  s->msmpeg4_version = MSMP4_V2;
128  break;
130  s->h263_pred = 1;
131  s->msmpeg4_version = MSMP4_V3;
132  break;
133  case AV_CODEC_ID_WMV1:
134  s->h263_pred = 1;
135  s->msmpeg4_version = MSMP4_WMV1;
136  break;
137  case AV_CODEC_ID_WMV2:
138  s->h263_pred = 1;
139  s->msmpeg4_version = MSMP4_WMV2;
140  break;
141  case AV_CODEC_ID_H263I:
142  case AV_CODEC_ID_RV10:
143  case AV_CODEC_ID_RV20:
144  break;
145  case AV_CODEC_ID_FLV1:
146  s->h263_flv = 1;
147  break;
148  default:
149  av_log(avctx, AV_LOG_ERROR, "Unsupported codec %d\n",
150  avctx->codec->id);
151  return AVERROR(ENOSYS);
152  }
153 
154  if (avctx->codec_tag == AV_RL32("L263") || avctx->codec_tag == AV_RL32("S263"))
155  if (avctx->extradata_size == 56 && avctx->extradata[0] == 1)
156  s->ehc_mode = 1;
157 
158  /* for H.263, we allocate the images after having read the header */
159  if (avctx->codec->id != AV_CODEC_ID_H263 &&
160  avctx->codec->id != AV_CODEC_ID_H263P &&
161  avctx->codec->id != AV_CODEC_ID_MPEG4) {
162  avctx->pix_fmt = h263_get_format(avctx);
163  if ((ret = ff_mpv_common_init(s)) < 0)
164  return ret;
165  }
166 
167  ff_h263dsp_init(&s->h263dsp);
169 
170  return 0;
171 }
172 
173 /**
174  * Return the number of bytes consumed for building the current frame.
175  */
176 static int get_consumed_bytes(MpegEncContext *s, int buf_size)
177 {
178  int pos = (get_bits_count(&s->gb) + 7) >> 3;
179 
180  if (s->divx_packed || s->avctx->hwaccel) {
181  /* We would have to scan through the whole buf to handle the weird
182  * reordering ... */
183  return buf_size;
184  } else {
185  // avoid infinite loops (maybe not needed...)
186  if (pos == 0)
187  pos = 1;
188  // oops ;)
189  if (pos + 10 > buf_size)
190  pos = buf_size;
191 
192  return pos;
193  }
194 }
195 
197 {
198  const int part_mask = s->partitioned_frame
199  ? (ER_AC_END | ER_AC_ERROR) : 0x7F;
200  const int mb_size = 16 >> s->avctx->lowres;
201  int ret;
202 
203  s->last_resync_gb = s->gb;
204  s->first_slice_line = 1;
205  s->resync_mb_x = s->mb_x;
206  s->resync_mb_y = s->mb_y;
207 
208  ff_set_qscale(s, s->qscale);
209 
210  if (s->studio_profile) {
211  if ((ret = ff_mpeg4_decode_studio_slice_header(s->avctx->priv_data)) < 0)
212  return ret;
213  }
214 
215  if (s->avctx->hwaccel) {
216  const uint8_t *start = s->gb.buffer + get_bits_count(&s->gb) / 8;
217  ret = FF_HW_CALL(s->avctx, decode_slice, start, s->gb.buffer_end - start);
218  // ensure we exit decode loop
219  s->mb_y = s->mb_height;
220  return ret;
221  }
222 
223  if (s->partitioned_frame) {
224  const int qscale = s->qscale;
225 
226  if (CONFIG_MPEG4_DECODER && s->codec_id == AV_CODEC_ID_MPEG4)
227  if ((ret = ff_mpeg4_decode_partitions(s->avctx->priv_data)) < 0)
228  return ret;
229 
230  /* restore variables which were modified */
231  s->first_slice_line = 1;
232  s->mb_x = s->resync_mb_x;
233  s->mb_y = s->resync_mb_y;
234  ff_set_qscale(s, qscale);
235  }
236 
237  for (; s->mb_y < s->mb_height; s->mb_y++) {
238  /* per-row end of slice checks */
239  if (s->msmpeg4_version != MSMP4_UNUSED) {
240  if (s->resync_mb_y + s->slice_height == s->mb_y) {
241  ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
242  s->mb_x - 1, s->mb_y, ER_MB_END);
243 
244  return 0;
245  }
246  }
247 
248  if (s->msmpeg4_version == MSMP4_V1) {
249  s->last_dc[0] =
250  s->last_dc[1] =
251  s->last_dc[2] = 128;
252  }
253 
255  for (; s->mb_x < s->mb_width; s->mb_x++) {
256  int ret;
257 
258  ff_update_block_index(s, s->avctx->bits_per_raw_sample,
259  s->avctx->lowres, s->chroma_x_shift);
260 
261  if (s->resync_mb_x == s->mb_x && s->resync_mb_y + 1 == s->mb_y)
262  s->first_slice_line = 0;
263 
264  /* DCT & quantize */
265 
266  s->mv_dir = MV_DIR_FORWARD;
267  s->mv_type = MV_TYPE_16X16;
268  ff_dlog(s, "%d %06X\n",
269  get_bits_count(&s->gb), show_bits(&s->gb, 24));
270 
271  ff_tlog(NULL, "Decoding MB at %dx%d\n", s->mb_x, s->mb_y);
272  ret = s->decode_mb(s, s->block);
273 
274  if (s->h263_pred || s->h263_aic) {
275  int mb_xy = s->mb_y * s->mb_stride + s->mb_x;
276  if (!s->mb_intra) {
277  if (s->mbintra_table[mb_xy])
279  } else
280  s->mbintra_table[mb_xy] = 1;
281  }
282 
283  if (s->pict_type != AV_PICTURE_TYPE_B)
285 
286  if (ret < 0) {
287  const int xy = s->mb_x + s->mb_y * s->mb_stride;
288  if (ret == SLICE_END) {
289  ff_mpv_reconstruct_mb(s, s->block);
290  if (s->loop_filter)
292 
293  ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
294  s->mb_x, s->mb_y, ER_MB_END & part_mask);
295 
296  s->padding_bug_score--;
297 
298  if (++s->mb_x >= s->mb_width) {
299  s->mb_x = 0;
300  ff_mpeg_draw_horiz_band(s, s->mb_y * mb_size, mb_size);
302  s->mb_y++;
303  }
304  return 0;
305  } else if (ret == SLICE_NOEND) {
306  av_log(s->avctx, AV_LOG_ERROR,
307  "Slice mismatch at MB: %d\n", xy);
308  ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
309  s->mb_x + 1, s->mb_y,
310  ER_MB_END & part_mask);
311  return AVERROR_INVALIDDATA;
312  }
313  av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy);
314  ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
315  s->mb_x, s->mb_y, ER_MB_ERROR & part_mask);
316 
317  if ((s->avctx->err_recognition & AV_EF_IGNORE_ERR) && get_bits_left(&s->gb) > 0)
318  continue;
319  return AVERROR_INVALIDDATA;
320  }
321 
322  ff_mpv_reconstruct_mb(s, s->block);
323  if (s->loop_filter)
325  }
326 
327  ff_mpeg_draw_horiz_band(s, s->mb_y * mb_size, mb_size);
329 
330  s->mb_x = 0;
331  }
332 
333  av_assert1(s->mb_x == 0 && s->mb_y == s->mb_height);
334 
335  // Detect incorrect padding with wrong stuffing codes used by NEC N-02B
336  if (s->codec_id == AV_CODEC_ID_MPEG4 &&
337  (s->workaround_bugs & FF_BUG_AUTODETECT) &&
338  get_bits_left(&s->gb) >= 48 &&
339  show_bits(&s->gb, 24) == 0x4010 &&
340  !s->data_partitioning)
341  s->padding_bug_score += 32;
342 
343  /* try to detect the padding bug */
344  if (s->codec_id == AV_CODEC_ID_MPEG4 &&
345  (s->workaround_bugs & FF_BUG_AUTODETECT) &&
346  get_bits_left(&s->gb) >= 0 &&
347  get_bits_left(&s->gb) < 137 &&
348  !s->data_partitioning) {
349  const int bits_count = get_bits_count(&s->gb);
350  const int bits_left = s->gb.size_in_bits - bits_count;
351 
352  if (bits_left == 0) {
353  s->padding_bug_score += 16;
354  } else if (bits_left != 1) {
355  int v = show_bits(&s->gb, 8);
356  v |= 0x7F >> (7 - (bits_count & 7));
357 
358  if (v == 0x7F && bits_left <= 8)
359  s->padding_bug_score--;
360  else if (v == 0x7F && ((get_bits_count(&s->gb) + 8) & 8) &&
361  bits_left <= 16)
362  s->padding_bug_score += 4;
363  else
364  s->padding_bug_score++;
365  }
366  }
367 
368  if (s->codec_id == AV_CODEC_ID_H263 &&
369  (s->workaround_bugs & FF_BUG_AUTODETECT) &&
370  get_bits_left(&s->gb) >= 8 &&
371  get_bits_left(&s->gb) < 300 &&
372  s->pict_type == AV_PICTURE_TYPE_I &&
373  show_bits(&s->gb, 8) == 0 &&
374  !s->data_partitioning) {
375 
376  s->padding_bug_score += 32;
377  }
378 
379  if (s->codec_id == AV_CODEC_ID_H263 &&
380  (s->workaround_bugs & FF_BUG_AUTODETECT) &&
381  get_bits_left(&s->gb) >= 64 &&
382  AV_RB64(s->gb.buffer_end - 8) == 0xCDCDCDCDFC7F0000) {
383 
384  s->padding_bug_score += 32;
385  }
386 
387  if (s->workaround_bugs & FF_BUG_AUTODETECT) {
388  if (
389  (s->padding_bug_score > -2 && !s->data_partitioning))
390  s->workaround_bugs |= FF_BUG_NO_PADDING;
391  else
392  s->workaround_bugs &= ~FF_BUG_NO_PADDING;
393  }
394 
395  // handle formats which don't have unique end markers
396  if (s->msmpeg4_version != MSMP4_UNUSED || (s->workaround_bugs & FF_BUG_NO_PADDING)) { // FIXME perhaps solve this more cleanly
397  int left = get_bits_left(&s->gb);
398  int max_extra = 7;
399 
400  /* no markers in M$ crap */
401  if (s->msmpeg4_version != MSMP4_UNUSED && s->pict_type == AV_PICTURE_TYPE_I)
402  max_extra += 17;
403 
404  /* buggy padding but the frame should still end approximately at
405  * the bitstream end */
406  if ((s->workaround_bugs & FF_BUG_NO_PADDING) &&
407  (s->avctx->err_recognition & (AV_EF_BUFFER|AV_EF_AGGRESSIVE)))
408  max_extra += 48;
409  else if ((s->workaround_bugs & FF_BUG_NO_PADDING))
410  max_extra += 256 * 256 * 256 * 64;
411 
412  if (left > max_extra)
413  av_log(s->avctx, AV_LOG_ERROR,
414  "discarding %d junk bits at end, next would be %X\n",
415  left, show_bits(&s->gb, 24));
416  else if (left < 0)
417  av_log(s->avctx, AV_LOG_ERROR, "overreading %d bits\n", -left);
418  else
419  ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
420  s->mb_x - 1, s->mb_y, ER_MB_END);
421 
422  return 0;
423  }
424 
425  av_log(s->avctx, AV_LOG_ERROR,
426  "slice end not reached but screenspace end (%d left %06X, score= %d)\n",
427  get_bits_left(&s->gb), show_bits(&s->gb, 24), s->padding_bug_score);
428 
429  ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y,
430  ER_MB_END & part_mask);
431 
432  return AVERROR_INVALIDDATA;
433 }
434 
436  int *got_frame, AVPacket *avpkt)
437 {
438  const uint8_t *buf = avpkt->data;
439  int buf_size = avpkt->size;
440  MpegEncContext *s = avctx->priv_data;
441  int ret;
442  int slice_ret = 0;
443  int bak_width, bak_height;
444 
445  /* no supplementary picture */
446  if (buf_size == 0) {
447  /* special case for last picture */
448  if (s->low_delay == 0 && s->next_pic.ptr) {
449  if ((ret = av_frame_ref(pict, s->next_pic.ptr->f)) < 0)
450  return ret;
451  ff_mpv_unref_picture(&s->next_pic);
452 
453  *got_frame = 1;
454  } else if (s->skipped_last_frame && s->cur_pic.ptr) {
455  /* Output the last picture we decoded again if the stream ended with
456  * an NVOP */
457  if ((ret = av_frame_ref(pict, s->cur_pic.ptr->f)) < 0)
458  return ret;
459  /* Copy props from the last input packet. Otherwise, props from the last
460  * returned picture would be reused */
461  if ((ret = ff_decode_frame_props(avctx, pict)) < 0)
462  return ret;
463  ff_mpv_unref_picture(&s->cur_pic);
464 
465  *got_frame = 1;
466  }
467 
468  return 0;
469  }
470 
471 retry:
472  if (s->divx_packed && s->bitstream_buffer_size) {
473  int i;
474  for(i=0; i < buf_size-3; i++) {
475  if (buf[i]==0 && buf[i+1]==0 && buf[i+2]==1) {
476  if (buf[i+3]==0xB0) {
477  av_log(s->avctx, AV_LOG_WARNING, "Discarding excessive bitstream in packed xvid\n");
478  s->bitstream_buffer_size = 0;
479  }
480  break;
481  }
482  }
483  }
484 
485  if (s->bitstream_buffer_size && (s->divx_packed || buf_size <= MAX_NVOP_SIZE)) // divx 5.01+/xvid frame reorder
486  ret = init_get_bits8(&s->gb, s->bitstream_buffer,
487  s->bitstream_buffer_size);
488  else
489  ret = init_get_bits8(&s->gb, buf, buf_size);
490 
491  s->bitstream_buffer_size = 0;
492  if (ret < 0)
493  return ret;
494 
495  bak_width = s->width;
496  bak_height = s->height;
497 
498  /* let's go :-) */
499  if (CONFIG_WMV2_DECODER && s->msmpeg4_version == MSMP4_WMV2) {
501 #if CONFIG_MSMPEG4DEC
502  } else if (s->msmpeg4_version != MSMP4_UNUSED) {
504 #endif
505  } else if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) {
506  ret = ff_mpeg4_decode_picture_header(avctx->priv_data, &s->gb, 0, 0);
507  s->skipped_last_frame = (ret == FRAME_SKIPPED);
508  } else if (CONFIG_H263I_DECODER && s->codec_id == AV_CODEC_ID_H263I) {
510  } else if (CONFIG_FLV_DECODER && s->h263_flv) {
512  } else {
514  }
515 
516  if (ret < 0 || ret == FRAME_SKIPPED) {
517  if ( s->width != bak_width
518  || s->height != bak_height) {
519  av_log(s->avctx, AV_LOG_WARNING, "Reverting picture dimensions change due to header decoding failure\n");
520  s->width = bak_width;
521  s->height= bak_height;
522 
523  }
524  }
525  if (ret == FRAME_SKIPPED)
526  return get_consumed_bytes(s, buf_size);
527 
528  /* skip if the header was thrashed */
529  if (ret < 0) {
530  av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
531  return ret;
532  }
533 
534  if (!s->context_initialized) {
535  avctx->pix_fmt = h263_get_format(avctx);
536  if ((ret = ff_mpv_common_init(s)) < 0)
537  return ret;
538  }
539 
540  avctx->has_b_frames = !s->low_delay;
541 
542  if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) {
543  if (s->pict_type != AV_PICTURE_TYPE_B && s->mb_num/2 > get_bits_left(&s->gb))
544  return AVERROR_INVALIDDATA;
545  if (ff_mpeg4_workaround_bugs(avctx) == 1)
546  goto retry;
547  if (s->studio_profile != (s->idsp.idct == NULL))
549  if (s->mpeg_quant) {
550  s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra;
551  } else {
552  s->dct_unquantize_intra = s->dct_unquantize_h263_intra;
553  }
554  }
555 
556  /* After H.263 & MPEG-4 header decode we have the height, width,
557  * and other parameters. So then we could init the picture.
558  * FIXME: By the way H.263 decoder is evolving it should have
559  * an H263EncContext */
560  if (s->width != avctx->coded_width ||
561  s->height != avctx->coded_height ||
562  s->context_reinit) {
563  /* H.263 could change picture size any time */
564  s->context_reinit = 0;
565 
566  ret = ff_set_dimensions(avctx, s->width, s->height);
567  if (ret < 0)
568  return ret;
569 
570  ff_set_sar(avctx, avctx->sample_aspect_ratio);
571 
573  return ret;
574 
575  if (avctx->pix_fmt != h263_get_format(avctx)) {
576  av_log(avctx, AV_LOG_ERROR, "format change not supported\n");
577  avctx->pix_fmt = AV_PIX_FMT_NONE;
578  return AVERROR_UNKNOWN;
579  }
580  }
581 
582  if (s->codec_id == AV_CODEC_ID_H263 ||
583  s->codec_id == AV_CODEC_ID_H263P ||
584  s->codec_id == AV_CODEC_ID_H263I)
585  s->gob_index = H263_GOB_HEIGHT(s->height);
586 
587  /* skip B-frames if we don't have reference frames */
588  if (!s->last_pic.ptr &&
589  (s->pict_type == AV_PICTURE_TYPE_B || s->droppable))
590  return get_consumed_bytes(s, buf_size);
591  if ((avctx->skip_frame >= AVDISCARD_NONREF &&
592  s->pict_type == AV_PICTURE_TYPE_B) ||
593  (avctx->skip_frame >= AVDISCARD_NONKEY &&
594  s->pict_type != AV_PICTURE_TYPE_I) ||
595  avctx->skip_frame >= AVDISCARD_ALL)
596  return get_consumed_bytes(s, buf_size);
597 
598  if ((ret = ff_mpv_frame_start(s, avctx)) < 0)
599  return ret;
600 
601  if (!s->divx_packed && !avctx->hwaccel)
602  ff_thread_finish_setup(avctx);
603 
604  if (avctx->hwaccel) {
605  ret = FF_HW_CALL(avctx, start_frame,
606  s->gb.buffer, s->gb.buffer_end - s->gb.buffer);
607  if (ret < 0 )
608  return ret;
609  }
610 
612 
613  /* the second part of the wmv2 header contains the MB skip bits which
614  * are stored in current_picture->mb_type which is not available before
615  * ff_mpv_frame_start() */
616 #if CONFIG_WMV2_DECODER
617  if (s->msmpeg4_version == MSMP4_WMV2) {
619  if (ret < 0)
620  return ret;
621  if (ret == 1)
622  goto frame_end;
623  }
624 #endif
625 
626  /* decode each macroblock */
627  s->mb_x = 0;
628  s->mb_y = 0;
629 
630  slice_ret = decode_slice(s);
631  while (s->mb_y < s->mb_height) {
632  if (s->msmpeg4_version != MSMP4_UNUSED) {
633  if (s->slice_height == 0 || s->mb_x != 0 || slice_ret < 0 ||
634  (s->mb_y % s->slice_height) != 0 || get_bits_left(&s->gb) < 0)
635  break;
636  } else {
637  int prev_x = s->mb_x, prev_y = s->mb_y;
638  if (ff_h263_resync(s) < 0)
639  break;
640  if (prev_y * s->mb_width + prev_x < s->mb_y * s->mb_width + s->mb_x)
641  s->er.error_occurred = 1;
642  }
643 
644  if (s->msmpeg4_version < MSMP4_WMV1 && s->h263_pred)
646 
647  if (decode_slice(s) < 0)
648  slice_ret = AVERROR_INVALIDDATA;
649  }
650 
651  if (s->msmpeg4_version != MSMP4_UNUSED && s->msmpeg4_version < MSMP4_WMV1 &&
652  s->pict_type == AV_PICTURE_TYPE_I)
653  if (!CONFIG_MSMPEG4DEC ||
654  ff_msmpeg4_decode_ext_header(s, buf_size) < 0)
655  s->er.error_status_table[s->mb_num - 1] = ER_MB_ERROR;
656 
657  av_assert1(s->bitstream_buffer_size == 0);
658 frame_end:
659  if (!s->studio_profile)
660  ff_er_frame_end(&s->er, NULL);
661 
662  if (avctx->hwaccel) {
663  ret = FF_HW_SIMPLE_CALL(avctx, end_frame);
664  if (ret < 0)
665  return ret;
666  }
667 
669 
670  if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4)
671  ff_mpeg4_frame_end(avctx, buf, buf_size);
672 
673  if (!s->divx_packed && avctx->hwaccel)
674  ff_thread_finish_setup(avctx);
675 
676  av_assert1(s->pict_type == s->cur_pic.ptr->f->pict_type);
677  if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
678  if ((ret = av_frame_ref(pict, s->cur_pic.ptr->f)) < 0)
679  return ret;
680  ff_print_debug_info(s, s->cur_pic.ptr, pict);
681  ff_mpv_export_qp_table(s, pict, s->cur_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1);
682  } else if (s->last_pic.ptr) {
683  if ((ret = av_frame_ref(pict, s->last_pic.ptr->f)) < 0)
684  return ret;
685  ff_print_debug_info(s, s->last_pic.ptr, pict);
686  ff_mpv_export_qp_table(s, pict, s->last_pic.ptr, FF_MPV_QSCALE_TYPE_MPEG1);
687  }
688 
689  if (s->last_pic.ptr || s->low_delay) {
690  if ( pict->format == AV_PIX_FMT_YUV420P
691  && (s->codec_tag == AV_RL32("GEOV") || s->codec_tag == AV_RL32("GEOX"))) {
692  for (int p = 0; p < 3; p++) {
693  int h = AV_CEIL_RSHIFT(pict->height, !!p);
694 
695  pict->data[p] += (h - 1) * pict->linesize[p];
696  pict->linesize[p] *= -1;
697  }
698  }
699  *got_frame = 1;
700  }
701 
702  if (slice_ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))
703  return slice_ret;
704  else
705  return get_consumed_bytes(s, buf_size);
706 }
707 
709 #if CONFIG_H263_VAAPI_HWACCEL
710  HWACCEL_VAAPI(h263),
711 #endif
712 #if CONFIG_MPEG4_NVDEC_HWACCEL
713  HWACCEL_NVDEC(mpeg4),
714 #endif
715 #if CONFIG_MPEG4_VDPAU_HWACCEL
716  HWACCEL_VDPAU(mpeg4),
717 #endif
718 #if CONFIG_H263_VIDEOTOOLBOX_HWACCEL
719  HWACCEL_VIDEOTOOLBOX(h263),
720 #endif
721  NULL
722 };
723 
725  .p.name = "h263",
726  CODEC_LONG_NAME("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"),
727  .p.type = AVMEDIA_TYPE_VIDEO,
728  .p.id = AV_CODEC_ID_H263,
729  .priv_data_size = sizeof(MpegEncContext),
732  .close = ff_mpv_decode_close,
733  .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
735  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
737  .flush = ff_mpeg_flush,
738  .p.max_lowres = 3,
739  .hw_configs = h263_hw_config_list,
740 };
741 
743  .p.name = "h263p",
744  CODEC_LONG_NAME("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"),
745  .p.type = AVMEDIA_TYPE_VIDEO,
746  .p.id = AV_CODEC_ID_H263P,
747  .priv_data_size = sizeof(MpegEncContext),
750  .close = ff_mpv_decode_close,
751  .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 |
753  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP |
755  .flush = ff_mpeg_flush,
756  .p.max_lowres = 3,
757  .hw_configs = h263_hw_config_list,
758 };
ff_mpv_common_init
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
Definition: mpegvideo.c:687
hwconfig.h
AVCodecContext::hwaccel
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:1445
MV_TYPE_16X16
#define MV_TYPE_16X16
1 vector for the whole mb
Definition: mpegvideo.h:265
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:260
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
AV_EF_EXPLODE
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: defs.h:51
h263_hw_config_list
static const AVCodecHWConfigInternal *const h263_hw_config_list[]
Definition: h263dec.c:708
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
H263_GOB_HEIGHT
#define H263_GOB_HEIGHT(h)
Definition: h263.h:28
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:678
AVERROR
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
ff_h263_decode_mb
int ff_h263_decode_mb(MpegEncContext *s, int16_t block[6][64])
Definition: ituh263dec.c:788
ff_get_format
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1277
mpeg4videodec.h
AVCodecContext::err_recognition
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:1438
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:249
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:410
ff_mpv_report_decode_progress
void ff_mpv_report_decode_progress(MpegEncContext *s)
Definition: mpegvideo_dec.c:463
AVPacket::data
uint8_t * data
Definition: packet.h:539
ff_mpeg4_decode_studio_slice_header
int ff_mpeg4_decode_studio_slice_header(Mpeg4DecContext *ctx)
Decode the next video packet.
Definition: mpeg4videodec.c:794
ff_msmpeg4_decode_ext_header
int ff_msmpeg4_decode_ext_header(MpegEncContext *s, int buf_size)
Definition: msmpeg4dec.c:546
FFCodec
Definition: codec_internal.h:127
ff_clean_intra_table_entries
void ff_clean_intra_table_entries(MpegEncContext *s)
Clean dc, ac for the current non-intra MB.
Definition: mpegvideo.c:796
FF_HW_SIMPLE_CALL
#define FF_HW_SIMPLE_CALL(avctx, function)
Definition: hwaccel_internal.h:174
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:826
ff_init_block_index
void ff_init_block_index(MpegEncContext *s)
Definition: mpegvideo.c:820
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:94
thread.h
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:431
ff_wmv2_decode_secondary_picture_header
int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s)
Definition: wmv2dec.c:236
ff_mpeg4_frame_end
int ff_mpeg4_frame_end(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
Definition: mpeg4videodec.c:3624
ff_mpv_reconstruct_mb
void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
Definition: mpegvideo_dec.c:1106
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:460
AVCodecContext::skip_frame
enum AVDiscard skip_frame
Skip decoding for selected frames.
Definition: avcodec.h:1841
decode_slice
static int decode_slice(MpegEncContext *s)
Definition: h263dec.c:196
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:508
HWACCEL_VDPAU
#define HWACCEL_VDPAU(codec)
Definition: hwconfig.h:72
AVCodecContext::coded_height
int coded_height
Definition: avcodec.h:647
SLICE_END
#define SLICE_END
end marker found
Definition: mpegvideo.h:482
ff_h263_decode_picture_header
int ff_h263_decode_picture_header(MpegEncContext *s)
Definition: ituh263dec.c:1089
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:53
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:209
h263dec.h
av_cold
#define av_cold
Definition: attributes.h:90
AV_CODEC_ID_H263I
@ AV_CODEC_ID_H263I
Definition: codec_id.h:72
ff_mpeg4_decode_partitions
int ff_mpeg4_decode_partitions(Mpeg4DecContext *ctx)
Decode the first and second partition.
Definition: mpeg4videodec.c:1223
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:528
ff_wmv2_decode_picture_header
int ff_wmv2_decode_picture_header(MpegEncContext *s)
Definition: wmv2dec.c:205
ff_msmpeg4_decode_picture_header
int ff_msmpeg4_decode_picture_header(MpegEncContext *s)
Definition: msmpeg4dec.c:390
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:538
AVCodecContext::has_b_frames
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:737
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:896
ff_mpv_common_frame_size_change
int ff_mpv_common_frame_size_change(MpegEncContext *s)
Definition: mpegvideo_dec.c:172
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:311
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:68
FF_BUG_NO_PADDING
#define FF_BUG_NO_PADDING
Definition: avcodec.h:1371
ff_mpeg_er_frame_start
void ff_mpeg_er_frame_start(MpegEncContext *s)
Definition: mpeg_er.c:49
AV_CODEC_ID_WMV2
@ AV_CODEC_ID_WMV2
Definition: codec_id.h:70
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:1593
ff_mpeg4_workaround_bugs
int ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
Definition: mpeg4videodec.c:2978
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:296
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:461
FMT_H263
@ FMT_H263
Definition: mpegvideo.h:65
ff_mpv_unref_picture
void ff_mpv_unref_picture(MPVWorkPicture *pic)
Definition: mpegpicture.c:98
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:221
ff_h263_decode_init_vlc
void ff_h263_decode_init_vlc(void)
Definition: ituh263dec.c:137
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:410
NULL
#define NULL
Definition: coverity.c:32
bits_left
#define bits_left
Definition: bitstream.h:114
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:709
ER_AC_ERROR
#define ER_AC_ERROR
Definition: error_resilience.h:30
hwaccel_internal.h
ff_mpv_idct_init
av_cold void ff_mpv_idct_init(MpegEncContext *s)
Definition: mpegvideo.c:307
SLICE_NOEND
#define SLICE_NOEND
no end marker or error found but mb count exceeded
Definition: mpegvideo.h:483
ER_MB_ERROR
#define ER_MB_ERROR
Definition: error_resilience.h:37
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:279
ff_flv_decode_picture_header
int ff_flv_decode_picture_header(MpegEncContext *s)
Definition: flvdec.c:29
ff_set_qscale
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
Definition: mpegvideo.c:853
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:109
ff_h263_decode_frame
int ff_h263_decode_frame(AVCodecContext *avctx, AVFrame *pict, int *got_frame, AVPacket *avpkt)
Definition: h263dec.c:435
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:699
FF_MPV_QSCALE_TYPE_MPEG1
#define FF_MPV_QSCALE_TYPE_MPEG1
Definition: mpegvideodec.h:40
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:28
AVDISCARD_NONKEY
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition: defs.h:220
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
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:322
AVPacket::size
int size
Definition: packet.h:540
ff_mpeg4_clean_buffers
void ff_mpeg4_clean_buffers(MpegEncContext *s)
Definition: mpeg4video.c:57
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:401
codec_internal.h
FRAME_SKIPPED
#define FRAME_SKIPPED
Return value for header parsers if frame is not coded.
Definition: h263dec.h:29
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:609
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
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:441
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:497
AVCodecHWConfigInternal
Definition: hwconfig.h:25
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:344
ff_mpeg_flush
void ff_mpeg_flush(AVCodecContext *avctx)
Definition: mpegvideo_dec.c:449
ff_h263_decoder
const FFCodec ff_h263_decoder
Definition: h263dec.c:724
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:201
AV_PIX_FMT_VDPAU
@ AV_PIX_FMT_VDPAU
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition: pixfmt.h:194
get_consumed_bytes
static int get_consumed_bytes(MpegEncContext *s, int buf_size)
Return the number of bytes consumed for building the current frame.
Definition: h263dec.c:176
AV_PIX_FMT_VIDEOTOOLBOX
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
Definition: pixfmt.h:305
ff_print_debug_info
void ff_print_debug_info(const MpegEncContext *s, const MPVPicture *p, AVFrame *pict)
Definition: mpegvideo_dec.c:403
AV_CODEC_ID_RV10
@ AV_CODEC_ID_RV10
Definition: codec_id.h:57
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
ff_h263p_decoder
const FFCodec ff_h263p_decoder
Definition: h263dec.c:742
AVCodecContext::extradata
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition: avcodec.h:537
show_bits
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:354
ff_mpeg4_decode_picture_header
int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb, int header, int parse_only)
Decode MPEG-4 headers.
Definition: mpeg4videodec.c:3466
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
FF_BUG_AUTODETECT
#define FF_BUG_AUTODETECT
autodetection
Definition: avcodec.h:1368
ff_intel_h263_decode_picture_header
int ff_intel_h263_decode_picture_header(MpegEncContext *s)
Definition: intelh263dec.c:28
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:194
ff_h263_decode_init
av_cold int ff_h263_decode_init(AVCodecContext *avctx)
Definition: h263dec.c:90
AVCodecContext::chroma_sample_location
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:716
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:671
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:716
HWACCEL_VIDEOTOOLBOX
#define HWACCEL_VIDEOTOOLBOX(codec)
Definition: hwconfig.h:74
avcodec.h
mpeg4videodefs.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_decode_init
int ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
Initialize the given MpegEncContext for decoding.
Definition: mpegvideo_dec.c:46
pos
unsigned int pos
Definition: spdifenc.c:414
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:94
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
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:1564
AVCodecContext
main external API structure.
Definition: avcodec.h:451
AVFrame::height
int height
Definition: frame.h:482
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:281
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:755
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:171
ff_mpv_frame_end
void ff_mpv_frame_end(MpegEncContext *s)
Definition: mpegvideo_dec.c:395
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
AVCodecContext::coded_width
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:647
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AV_EF_BUFFER
#define AV_EF_BUFFER
detect improper bitstream length
Definition: defs.h:50
ER_MB_END
#define ER_MB_END
Definition: error_resilience.h:38
MAX_NVOP_SIZE
#define MAX_NVOP_SIZE
Definition: mpeg4videodefs.h:66
AVCodecContext::codec_tag
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:476
ff_tlog
#define ff_tlog(ctx,...)
Definition: internal.h:141
MV_DIR_FORWARD
#define MV_DIR_FORWARD
Definition: mpegvideo.h:261
AVPacket
This structure stores compressed data.
Definition: packet.h:516
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:478
ff_h263_resync
int ff_h263_resync(MpegEncContext *s)
Decode the group of blocks / video packet header / slice header (MPEG-4 Studio).
Definition: ituh263dec.c:217
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:455
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:51
h
h
Definition: vp9dsp_template.c:2070
ER_AC_END
#define ER_AC_END
Definition: error_resilience.h:33
AV_CODEC_ID_FLV1
@ AV_CODEC_ID_FLV1
Definition: codec_id.h:73
AVDISCARD_NONREF
@ AVDISCARD_NONREF
discard all non reference
Definition: defs.h:217
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:73
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:656
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_mpv_decode_close
int ff_mpv_decode_close(AVCodecContext *avctx)
Definition: mpegvideo_dec.c:163
h263.h