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 
31 
32 #include "avcodec.h"
33 #include "error_resilience.h"
34 #include "flv.h"
35 #include "h263.h"
36 #include "h263_parser.h"
37 #include "hwconfig.h"
38 #include "internal.h"
39 #include "mpeg_er.h"
40 #include "mpeg4video.h"
41 #include "mpeg4video_parser.h"
42 #include "mpegutils.h"
43 #include "mpegvideo.h"
44 #include "msmpeg4.h"
45 #include "qpeldsp.h"
46 #include "thread.h"
47 #include "wmv2.h"
48 
50 {
51  /* MPEG-4 Studio Profile only, not supported by hardware */
52  if (avctx->bits_per_raw_sample > 8) {
53  av_assert1(((MpegEncContext *)avctx->priv_data)->studio_profile);
54  return avctx->pix_fmt;
55  }
56 
57  if (avctx->codec->id == AV_CODEC_ID_MSS2)
58  return AV_PIX_FMT_YUV420P;
59 
60  if (CONFIG_GRAY && (avctx->flags & AV_CODEC_FLAG_GRAY)) {
63  return AV_PIX_FMT_GRAY8;
64  }
65 
66  return avctx->pix_fmt = ff_get_format(avctx, avctx->codec->pix_fmts);
67 }
68 
70 {
71  MpegEncContext *s = avctx->priv_data;
72  int ret;
73 
74  s->out_format = FMT_H263;
75 
76  // set defaults
77  ff_mpv_decode_init(s, avctx);
78 
79  s->quant_precision = 5;
80  s->decode_mb = ff_h263_decode_mb;
81  s->low_delay = 1;
82  s->unrestricted_mv = 1;
83 
84  /* select sub codec */
85  switch (avctx->codec->id) {
86  case AV_CODEC_ID_H263:
87  case AV_CODEC_ID_H263P:
88  s->unrestricted_mv = 0;
90  break;
91  case AV_CODEC_ID_MPEG4:
92  break;
94  s->h263_pred = 1;
95  s->msmpeg4_version = 1;
96  break;
98  s->h263_pred = 1;
99  s->msmpeg4_version = 2;
100  break;
102  s->h263_pred = 1;
103  s->msmpeg4_version = 3;
104  break;
105  case AV_CODEC_ID_WMV1:
106  s->h263_pred = 1;
107  s->msmpeg4_version = 4;
108  break;
109  case AV_CODEC_ID_WMV2:
110  s->h263_pred = 1;
111  s->msmpeg4_version = 5;
112  break;
113  case AV_CODEC_ID_VC1:
114  case AV_CODEC_ID_WMV3:
117  case AV_CODEC_ID_MSS2:
118  s->h263_pred = 1;
119  s->msmpeg4_version = 6;
121  break;
122  case AV_CODEC_ID_H263I:
123  break;
124  case AV_CODEC_ID_FLV1:
125  s->h263_flv = 1;
126  break;
127  default:
128  av_log(avctx, AV_LOG_ERROR, "Unsupported codec %d\n",
129  avctx->codec->id);
130  return AVERROR(ENOSYS);
131  }
132 
133  if (avctx->codec_tag == AV_RL32("L263") || avctx->codec_tag == AV_RL32("S263"))
134  if (avctx->extradata_size == 56 && avctx->extradata[0] == 1)
135  s->ehc_mode = 1;
136 
137  /* for H.263, we allocate the images after having read the header */
138  if (avctx->codec->id != AV_CODEC_ID_H263 &&
139  avctx->codec->id != AV_CODEC_ID_H263P &&
140  avctx->codec->id != AV_CODEC_ID_MPEG4) {
141  avctx->pix_fmt = h263_get_format(avctx);
143  if ((ret = ff_mpv_common_init(s)) < 0)
144  return ret;
145  }
146 
147  ff_h263dsp_init(&s->h263dsp);
148  ff_qpeldsp_init(&s->qdsp);
150 
151  return 0;
152 }
153 
155 {
156  MpegEncContext *s = avctx->priv_data;
157 
159  return 0;
160 }
161 
162 /**
163  * Return the number of bytes consumed for building the current frame.
164  */
165 static int get_consumed_bytes(MpegEncContext *s, int buf_size)
166 {
167  int pos = (get_bits_count(&s->gb) + 7) >> 3;
168 
169  if (s->divx_packed || s->avctx->hwaccel) {
170  /* We would have to scan through the whole buf to handle the weird
171  * reordering ... */
172  return buf_size;
173  } else if (s->avctx->flags & AV_CODEC_FLAG_TRUNCATED) {
174  pos -= s->parse_context.last_index;
175  // padding is not really read so this might be -1
176  if (pos < 0)
177  pos = 0;
178  return pos;
179  } else {
180  // avoid infinite loops (maybe not needed...)
181  if (pos == 0)
182  pos = 1;
183  // oops ;)
184  if (pos + 10 > buf_size)
185  pos = buf_size;
186 
187  return pos;
188  }
189 }
190 
192 {
193  const int part_mask = s->partitioned_frame
194  ? (ER_AC_END | ER_AC_ERROR) : 0x7F;
195  const int mb_size = 16 >> s->avctx->lowres;
196  int ret;
197 
198  s->last_resync_gb = s->gb;
199  s->first_slice_line = 1;
200  s->resync_mb_x = s->mb_x;
201  s->resync_mb_y = s->mb_y;
202 
203  ff_set_qscale(s, s->qscale);
204 
205  if (s->studio_profile) {
206  if ((ret = ff_mpeg4_decode_studio_slice_header(s->avctx->priv_data)) < 0)
207  return ret;
208  }
209 
210  if (s->avctx->hwaccel) {
211  const uint8_t *start = s->gb.buffer + get_bits_count(&s->gb) / 8;
212  ret = s->avctx->hwaccel->decode_slice(s->avctx, start, s->gb.buffer_end - start);
213  // ensure we exit decode loop
214  s->mb_y = s->mb_height;
215  return ret;
216  }
217 
218  if (s->partitioned_frame) {
219  const int qscale = s->qscale;
220 
221  if (CONFIG_MPEG4_DECODER && s->codec_id == AV_CODEC_ID_MPEG4)
222  if ((ret = ff_mpeg4_decode_partitions(s->avctx->priv_data)) < 0)
223  return ret;
224 
225  /* restore variables which were modified */
226  s->first_slice_line = 1;
227  s->mb_x = s->resync_mb_x;
228  s->mb_y = s->resync_mb_y;
229  ff_set_qscale(s, qscale);
230  }
231 
232  for (; s->mb_y < s->mb_height; s->mb_y++) {
233  /* per-row end of slice checks */
234  if (s->msmpeg4_version) {
235  if (s->resync_mb_y + s->slice_height == s->mb_y) {
236  ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
237  s->mb_x - 1, s->mb_y, ER_MB_END);
238 
239  return 0;
240  }
241  }
242 
243  if (s->msmpeg4_version == 1) {
244  s->last_dc[0] =
245  s->last_dc[1] =
246  s->last_dc[2] = 128;
247  }
248 
250  for (; s->mb_x < s->mb_width; s->mb_x++) {
251  int ret;
252 
254 
255  if (s->resync_mb_x == s->mb_x && s->resync_mb_y + 1 == s->mb_y)
256  s->first_slice_line = 0;
257 
258  /* DCT & quantize */
259 
260  s->mv_dir = MV_DIR_FORWARD;
261  s->mv_type = MV_TYPE_16X16;
262  ff_dlog(s, "%d %06X\n",
263  get_bits_count(&s->gb), show_bits(&s->gb, 24));
264 
265  ff_tlog(NULL, "Decoding MB at %dx%d\n", s->mb_x, s->mb_y);
266  ret = s->decode_mb(s, s->block);
267 
268  if (s->pict_type != AV_PICTURE_TYPE_B)
270 
271  if (ret < 0) {
272  const int xy = s->mb_x + s->mb_y * s->mb_stride;
273  if (ret == SLICE_END) {
274  ff_mpv_reconstruct_mb(s, s->block);
275  if (s->loop_filter)
277 
278  ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
279  s->mb_x, s->mb_y, ER_MB_END & part_mask);
280 
281  s->padding_bug_score--;
282 
283  if (++s->mb_x >= s->mb_width) {
284  s->mb_x = 0;
285  ff_mpeg_draw_horiz_band(s, s->mb_y * mb_size, mb_size);
287  s->mb_y++;
288  }
289  return 0;
290  } else if (ret == SLICE_NOEND) {
291  av_log(s->avctx, AV_LOG_ERROR,
292  "Slice mismatch at MB: %d\n", xy);
293  ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
294  s->mb_x + 1, s->mb_y,
295  ER_MB_END & part_mask);
296  return AVERROR_INVALIDDATA;
297  }
298  av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy);
299  ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
300  s->mb_x, s->mb_y, ER_MB_ERROR & part_mask);
301 
302  if (s->avctx->err_recognition & AV_EF_IGNORE_ERR)
303  continue;
304  return AVERROR_INVALIDDATA;
305  }
306 
307  ff_mpv_reconstruct_mb(s, s->block);
308  if (s->loop_filter)
310  }
311 
312  ff_mpeg_draw_horiz_band(s, s->mb_y * mb_size, mb_size);
314 
315  s->mb_x = 0;
316  }
317 
318  av_assert1(s->mb_x == 0 && s->mb_y == s->mb_height);
319 
320  // Detect incorrect padding with wrong stuffing codes used by NEC N-02B
321  if (s->codec_id == AV_CODEC_ID_MPEG4 &&
322  (s->workaround_bugs & FF_BUG_AUTODETECT) &&
323  get_bits_left(&s->gb) >= 48 &&
324  show_bits(&s->gb, 24) == 0x4010 &&
325  !s->data_partitioning)
326  s->padding_bug_score += 32;
327 
328  /* try to detect the padding bug */
329  if (s->codec_id == AV_CODEC_ID_MPEG4 &&
330  (s->workaround_bugs & FF_BUG_AUTODETECT) &&
331  get_bits_left(&s->gb) >= 0 &&
332  get_bits_left(&s->gb) < 137 &&
333  !s->data_partitioning) {
334  const int bits_count = get_bits_count(&s->gb);
335  const int bits_left = s->gb.size_in_bits - bits_count;
336 
337  if (bits_left == 0) {
338  s->padding_bug_score += 16;
339  } else if (bits_left != 1) {
340  int v = show_bits(&s->gb, 8);
341  v |= 0x7F >> (7 - (bits_count & 7));
342 
343  if (v == 0x7F && bits_left <= 8)
344  s->padding_bug_score--;
345  else if (v == 0x7F && ((get_bits_count(&s->gb) + 8) & 8) &&
346  bits_left <= 16)
347  s->padding_bug_score += 4;
348  else
349  s->padding_bug_score++;
350  }
351  }
352 
353  if (s->codec_id == AV_CODEC_ID_H263 &&
354  (s->workaround_bugs & FF_BUG_AUTODETECT) &&
355  get_bits_left(&s->gb) >= 8 &&
356  get_bits_left(&s->gb) < 300 &&
357  s->pict_type == AV_PICTURE_TYPE_I &&
358  show_bits(&s->gb, 8) == 0 &&
359  !s->data_partitioning) {
360 
361  s->padding_bug_score += 32;
362  }
363 
364  if (s->codec_id == AV_CODEC_ID_H263 &&
365  (s->workaround_bugs & FF_BUG_AUTODETECT) &&
366  get_bits_left(&s->gb) >= 64 &&
367  AV_RB64(s->gb.buffer_end - 8) == 0xCDCDCDCDFC7F0000) {
368 
369  s->padding_bug_score += 32;
370  }
371 
372  if (s->workaround_bugs & FF_BUG_AUTODETECT) {
373  if (
374  (s->padding_bug_score > -2 && !s->data_partitioning))
375  s->workaround_bugs |= FF_BUG_NO_PADDING;
376  else
377  s->workaround_bugs &= ~FF_BUG_NO_PADDING;
378  }
379 
380  // handle formats which don't have unique end markers
381  if (s->msmpeg4_version || (s->workaround_bugs & FF_BUG_NO_PADDING)) { // FIXME perhaps solve this more cleanly
382  int left = get_bits_left(&s->gb);
383  int max_extra = 7;
384 
385  /* no markers in M$ crap */
386  if (s->msmpeg4_version && s->pict_type == AV_PICTURE_TYPE_I)
387  max_extra += 17;
388 
389  /* buggy padding but the frame should still end approximately at
390  * the bitstream end */
391  if ((s->workaround_bugs & FF_BUG_NO_PADDING) &&
392  (s->avctx->err_recognition & (AV_EF_BUFFER|AV_EF_AGGRESSIVE)))
393  max_extra += 48;
394  else if ((s->workaround_bugs & FF_BUG_NO_PADDING))
395  max_extra += 256 * 256 * 256 * 64;
396 
397  if (left > max_extra)
398  av_log(s->avctx, AV_LOG_ERROR,
399  "discarding %d junk bits at end, next would be %X\n",
400  left, show_bits(&s->gb, 24));
401  else if (left < 0)
402  av_log(s->avctx, AV_LOG_ERROR, "overreading %d bits\n", -left);
403  else
404  ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y,
405  s->mb_x - 1, s->mb_y, ER_MB_END);
406 
407  return 0;
408  }
409 
410  av_log(s->avctx, AV_LOG_ERROR,
411  "slice end not reached but screenspace end (%d left %06X, score= %d)\n",
412  get_bits_left(&s->gb), show_bits(&s->gb, 24), s->padding_bug_score);
413 
414  ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y,
415  ER_MB_END & part_mask);
416 
417  return AVERROR_INVALIDDATA;
418 }
419 
420 int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
421  AVPacket *avpkt)
422 {
423  const uint8_t *buf = avpkt->data;
424  int buf_size = avpkt->size;
425  MpegEncContext *s = avctx->priv_data;
426  int ret;
427  int slice_ret = 0;
428  AVFrame *pict = data;
429 
430  /* no supplementary picture */
431  if (buf_size == 0) {
432  /* special case for last picture */
433  if (s->low_delay == 0 && s->next_picture_ptr) {
434  if ((ret = av_frame_ref(pict, s->next_picture_ptr->f)) < 0)
435  return ret;
436  s->next_picture_ptr = NULL;
437 
438  *got_frame = 1;
439  }
440 
441  return 0;
442  }
443 
444  if (s->avctx->flags & AV_CODEC_FLAG_TRUNCATED) {
445  int next;
446 
447  if (CONFIG_MPEG4_DECODER && s->codec_id == AV_CODEC_ID_MPEG4) {
448  next = ff_mpeg4_find_frame_end(&s->parse_context, buf, buf_size);
449  } else if (CONFIG_H263_DECODER && s->codec_id == AV_CODEC_ID_H263) {
450  next = ff_h263_find_frame_end(&s->parse_context, buf, buf_size);
451  } else if (CONFIG_H263P_DECODER && s->codec_id == AV_CODEC_ID_H263P) {
452  next = ff_h263_find_frame_end(&s->parse_context, buf, buf_size);
453  } else {
454  av_log(s->avctx, AV_LOG_ERROR,
455  "this codec does not support truncated bitstreams\n");
456  return AVERROR(ENOSYS);
457  }
458 
459  if (ff_combine_frame(&s->parse_context, next, (const uint8_t **)&buf,
460  &buf_size) < 0)
461  return buf_size;
462  }
463 
464 retry:
465  if (s->divx_packed && s->bitstream_buffer_size) {
466  int i;
467  for(i=0; i < buf_size-3; i++) {
468  if (buf[i]==0 && buf[i+1]==0 && buf[i+2]==1) {
469  if (buf[i+3]==0xB0) {
470  av_log(s->avctx, AV_LOG_WARNING, "Discarding excessive bitstream in packed xvid\n");
471  s->bitstream_buffer_size = 0;
472  }
473  break;
474  }
475  }
476  }
477 
478  if (s->bitstream_buffer_size && (s->divx_packed || buf_size <= MAX_NVOP_SIZE)) // divx 5.01+/xvid frame reorder
479  ret = init_get_bits8(&s->gb, s->bitstream_buffer,
480  s->bitstream_buffer_size);
481  else
482  ret = init_get_bits8(&s->gb, buf, buf_size);
483 
484  s->bitstream_buffer_size = 0;
485  if (ret < 0)
486  return ret;
487 
488  if (!s->context_initialized)
489  // we need the idct permutation for reading a custom matrix
491 
492  /* let's go :-) */
493  if (CONFIG_WMV2_DECODER && s->msmpeg4_version == 5) {
495  } else if (CONFIG_MSMPEG4_DECODER && s->msmpeg4_version) {
497  } else if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) {
498  if (s->avctx->extradata_size && s->picture_number == 0) {
499  GetBitContext gb;
500 
501  if (init_get_bits8(&gb, s->avctx->extradata, s->avctx->extradata_size) >= 0 )
503  }
504  ret = ff_mpeg4_decode_picture_header(avctx->priv_data, &s->gb, 0);
505  } else if (CONFIG_H263I_DECODER && s->codec_id == AV_CODEC_ID_H263I) {
507  } else if (CONFIG_FLV_DECODER && s->h263_flv) {
509  } else {
511  }
512 
513  if (ret < 0 || ret == FRAME_SKIPPED) {
514  if ( s->width != avctx->coded_width
515  || s->height != avctx->coded_height) {
516  av_log(s->avctx, AV_LOG_WARNING, "Reverting picture dimensions change due to header decoding failure\n");
517  s->width = avctx->coded_width;
518  s->height= avctx->coded_height;
519  }
520  }
521  if (ret == FRAME_SKIPPED)
522  return get_consumed_bytes(s, buf_size);
523 
524  /* skip if the header was thrashed */
525  if (ret < 0) {
526  av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
527  return ret;
528  }
529 
530  if (!s->context_initialized) {
531  avctx->pix_fmt = h263_get_format(avctx);
532  if ((ret = ff_mpv_common_init(s)) < 0)
533  return ret;
534  }
535 
536  if (!s->current_picture_ptr || s->current_picture_ptr->f->data[0]) {
537  int i = ff_find_unused_picture(s->avctx, s->picture, 0);
538  if (i < 0)
539  return i;
540  s->current_picture_ptr = &s->picture[i];
541  }
542 
543  avctx->has_b_frames = !s->low_delay;
544 
545  if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) {
546  if (ff_mpeg4_workaround_bugs(avctx) == 1)
547  goto retry;
548  if (s->studio_profile != (s->idsp.idct == NULL))
550  }
551 
552  /* After H.263 & MPEG-4 header decode we have the height, width,
553  * and other parameters. So then we could init the picture.
554  * FIXME: By the way H.263 decoder is evolving it should have
555  * an H263EncContext */
556  if (s->width != avctx->coded_width ||
557  s->height != avctx->coded_height ||
558  s->context_reinit) {
559  /* H.263 could change picture size any time */
560  s->context_reinit = 0;
561 
562  ret = ff_set_dimensions(avctx, s->width, s->height);
563  if (ret < 0)
564  return ret;
565 
566  ff_set_sar(avctx, avctx->sample_aspect_ratio);
567 
569  return ret;
570 
571  if (avctx->pix_fmt != h263_get_format(avctx)) {
572  av_log(avctx, AV_LOG_ERROR, "format change not supported\n");
573  avctx->pix_fmt = AV_PIX_FMT_NONE;
574  return AVERROR_UNKNOWN;
575  }
576  }
577 
578  if (s->codec_id == AV_CODEC_ID_H263 ||
579  s->codec_id == AV_CODEC_ID_H263P ||
580  s->codec_id == AV_CODEC_ID_H263I)
581  s->gob_index = H263_GOB_HEIGHT(s->height);
582 
583  // for skipping the frame
584  s->current_picture.f->pict_type = s->pict_type;
585  s->current_picture.f->key_frame = s->pict_type == AV_PICTURE_TYPE_I;
586 
587  /* skip B-frames if we don't have reference frames */
588  if (!s->last_picture_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 (s->next_p_frame_damaged) {
599  if (s->pict_type == AV_PICTURE_TYPE_B)
600  return get_consumed_bytes(s, buf_size);
601  else
602  s->next_p_frame_damaged = 0;
603  }
604 
605  if ((!s->no_rounding) || s->pict_type == AV_PICTURE_TYPE_B) {
606  s->me.qpel_put = s->qdsp.put_qpel_pixels_tab;
607  s->me.qpel_avg = s->qdsp.avg_qpel_pixels_tab;
608  } else {
609  s->me.qpel_put = s->qdsp.put_no_rnd_qpel_pixels_tab;
610  s->me.qpel_avg = s->qdsp.avg_qpel_pixels_tab;
611  }
612 
613  if ((ret = ff_mpv_frame_start(s, avctx)) < 0)
614  return ret;
615 
616  if (!s->divx_packed && !avctx->hwaccel)
617  ff_thread_finish_setup(avctx);
618 
619  if (avctx->hwaccel) {
620  ret = avctx->hwaccel->start_frame(avctx, s->gb.buffer,
621  s->gb.buffer_end - s->gb.buffer);
622  if (ret < 0 )
623  return ret;
624  }
625 
627 
628  /* the second part of the wmv2 header contains the MB skip bits which
629  * are stored in current_picture->mb_type which is not available before
630  * ff_mpv_frame_start() */
631  if (CONFIG_WMV2_DECODER && s->msmpeg4_version == 5) {
633  if (ret < 0)
634  return ret;
635  if (ret == 1)
636  goto frame_end;
637  }
638 
639  /* decode each macroblock */
640  s->mb_x = 0;
641  s->mb_y = 0;
642 
643  slice_ret = decode_slice(s);
644  while (s->mb_y < s->mb_height) {
645  if (s->msmpeg4_version) {
646  if (s->slice_height == 0 || s->mb_x != 0 || slice_ret < 0 ||
647  (s->mb_y % s->slice_height) != 0 || get_bits_left(&s->gb) < 0)
648  break;
649  } else {
650  int prev_x = s->mb_x, prev_y = s->mb_y;
651  if (ff_h263_resync(s) < 0)
652  break;
653  if (prev_y * s->mb_width + prev_x < s->mb_y * s->mb_width + s->mb_x)
654  s->er.error_occurred = 1;
655  }
656 
657  if (s->msmpeg4_version < 4 && s->h263_pred)
659 
660  if (decode_slice(s) < 0)
661  slice_ret = AVERROR_INVALIDDATA;
662  }
663 
664  if (s->msmpeg4_version && s->msmpeg4_version < 4 &&
665  s->pict_type == AV_PICTURE_TYPE_I)
666  if (!CONFIG_MSMPEG4_DECODER ||
667  ff_msmpeg4_decode_ext_header(s, buf_size) < 0)
668  s->er.error_status_table[s->mb_num - 1] = ER_MB_ERROR;
669 
670  av_assert1(s->bitstream_buffer_size == 0);
671 frame_end:
672  if (!s->studio_profile)
673  ff_er_frame_end(&s->er);
674 
675  if (avctx->hwaccel) {
676  ret = avctx->hwaccel->end_frame(avctx);
677  if (ret < 0)
678  return ret;
679  }
680 
682 
683  if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4)
684  ff_mpeg4_frame_end(avctx, buf, buf_size);
685 
686  if (!s->divx_packed && avctx->hwaccel)
687  ff_thread_finish_setup(avctx);
688 
689  av_assert1(s->current_picture.f->pict_type == s->current_picture_ptr->f->pict_type);
690  av_assert1(s->current_picture.f->pict_type == s->pict_type);
691  if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
692  if ((ret = av_frame_ref(pict, s->current_picture_ptr->f)) < 0)
693  return ret;
694  ff_print_debug_info(s, s->current_picture_ptr, pict);
695  ff_mpv_export_qp_table(s, pict, s->current_picture_ptr, FF_QSCALE_TYPE_MPEG1);
696  } else if (s->last_picture_ptr) {
697  if ((ret = av_frame_ref(pict, s->last_picture_ptr->f)) < 0)
698  return ret;
699  ff_print_debug_info(s, s->last_picture_ptr, pict);
700  ff_mpv_export_qp_table(s, pict, s->last_picture_ptr, FF_QSCALE_TYPE_MPEG1);
701  }
702 
703  if (s->last_picture_ptr || s->low_delay) {
704  if ( pict->format == AV_PIX_FMT_YUV420P
705  && (s->codec_tag == AV_RL32("GEOV") || s->codec_tag == AV_RL32("GEOX"))) {
706  int x, y, p;
708  for (p=0; p<3; p++) {
709  int w = AV_CEIL_RSHIFT(pict-> width, !!p);
710  int h = AV_CEIL_RSHIFT(pict->height, !!p);
711  int linesize = pict->linesize[p];
712  for (y=0; y<(h>>1); y++)
713  for (x=0; x<w; x++)
714  FFSWAP(int,
715  pict->data[p][x + y*linesize],
716  pict->data[p][x + (h-1-y)*linesize]);
717  }
718  }
719  *got_frame = 1;
720  }
721 
722  if (slice_ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))
723  return slice_ret;
724  else
725  return get_consumed_bytes(s, buf_size);
726 }
727 
729 #if CONFIG_H263_VAAPI_HWACCEL || CONFIG_MPEG4_VAAPI_HWACCEL
731 #endif
732 #if CONFIG_MPEG4_NVDEC_HWACCEL
734 #endif
735 #if CONFIG_MPEG4_VDPAU_HWACCEL
737 #endif
738 #if CONFIG_H263_VIDEOTOOLBOX_HWACCEL || CONFIG_MPEG4_VIDEOTOOLBOX_HWACCEL
740 #endif
743 };
744 
746 #if CONFIG_H263_VAAPI_HWACCEL
747  HWACCEL_VAAPI(h263),
748 #endif
749 #if CONFIG_MPEG4_NVDEC_HWACCEL
750  HWACCEL_NVDEC(mpeg4),
751 #endif
752 #if CONFIG_MPEG4_VDPAU_HWACCEL
753  HWACCEL_VDPAU(mpeg4),
754 #endif
755 #if CONFIG_H263_VIDEOTOOLBOX_HWACCEL
756  HWACCEL_VIDEOTOOLBOX(h263),
757 #endif
758  NULL
759 };
760 
762  .name = "h263",
763  .long_name = NULL_IF_CONFIG_SMALL("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"),
764  .type = AVMEDIA_TYPE_VIDEO,
765  .id = AV_CODEC_ID_H263,
766  .priv_data_size = sizeof(MpegEncContext),
768  .close = ff_h263_decode_end,
772  .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
773  .flush = ff_mpeg_flush,
774  .max_lowres = 3,
776  .hw_configs = ff_h263_hw_config_list,
777 };
778 
780  .name = "h263p",
781  .long_name = NULL_IF_CONFIG_SMALL("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"),
782  .type = AVMEDIA_TYPE_VIDEO,
783  .id = AV_CODEC_ID_H263P,
784  .priv_data_size = sizeof(MpegEncContext),
786  .close = ff_h263_decode_end,
790  .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
791  .flush = ff_mpeg_flush,
792  .max_lowres = 3,
794  .hw_configs = ff_h263_hw_config_list,
795 };
ff_mpv_common_init
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
Definition: mpegvideo.c:913
hwconfig.h
AVCodecContext::hwaccel
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:1355
AVCodec
AVCodec.
Definition: codec.h:197
CONFIG_MSMPEG4_DECODER
#define CONFIG_MSMPEG4_DECODER
Definition: msmpeg4.h:69
MV_TYPE_16X16
#define MV_TYPE_16X16
1 vector for the whole mb
Definition: mpegvideo.h:266
ff_mpeg4_workaround_bugs
int ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
Definition: mpeg4videodec.c:2729
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
AV_PIX_FMT_CUDA
@ AV_PIX_FMT_CUDA
HW acceleration through CUDA.
Definition: pixfmt.h:225
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
H263_GOB_HEIGHT
#define H263_GOB_HEIGHT(h)
Definition: h263.h:43
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:850
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_get_format
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: decode.c:1083
AVCodecContext::err_recognition
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:1320
ff_qpeldsp_init
av_cold void ff_qpeldsp_init(QpelDSPContext *c)
Definition: qpeldsp.c:783
get_bits_count
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:220
AVCodec::pix_fmts
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
Definition: codec.h:218
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:62
AV_CODEC_CAP_TRUNCATED
#define AV_CODEC_CAP_TRUNCATED
Definition: codec.h:53
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:303
av_frame_make_writable
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
Definition: frame.c:490
ff_mpv_common_frame_size_change
int ff_mpv_common_frame_size_change(MpegEncContext *s)
Definition: mpegvideo.c:1055
w
uint8_t w
Definition: llviddspenc.c:38
AVPacket::data
uint8_t * data
Definition: packet.h:373
data
const char data[16]
Definition: mxf.c:143
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:829
ff_init_block_index
void ff_init_block_index(MpegEncContext *s)
Definition: mpegvideo.c:2267
ff_tlog
#define ff_tlog(ctx,...)
Definition: internal.h:97
mpegvideo.h
AV_EF_BUFFER
#define AV_EF_BUFFER
detect improper bitstream length
Definition: avcodec.h:1330
AVERROR_UNKNOWN
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:73
ff_msmpeg4_decode_ext_header
int ff_msmpeg4_decode_ext_header(MpegEncContext *s, int buf_size)
Definition: msmpeg4dec.c:555
mpegutils.h
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:317
ff_mpeg4_decode_partitions
int ff_mpeg4_decode_partitions(Mpeg4DecContext *ctx)
Decode the first and second partition.
Definition: mpeg4videodec.c:975
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:388
AVCodecContext::skip_frame
enum AVDiscard skip_frame
Skip decoding for selected frames.
Definition: avcodec.h:1669
GetBitContext
Definition: get_bits.h:62
decode_slice
static int decode_slice(MpegEncContext *s)
Definition: h263dec.c:191
ff_mpeg_draw_horiz_band
void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
Definition: mpegvideo.c:2260
ff_h263dsp_init
av_cold void ff_h263dsp_init(H263DSPContext *ctx)
Definition: h263dsp.c:117
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:459
HWACCEL_VDPAU
#define HWACCEL_VDPAU(codec)
Definition: hwconfig.h:75
AVCodecContext::coded_height
int coded_height
Definition: avcodec.h:567
SLICE_END
#define SLICE_END
end marker found
Definition: mpegvideo.h:520
AV_CODEC_ID_MSMPEG4V2
@ AV_CODEC_ID_MSMPEG4V2
Definition: codec_id.h:65
ff_h263_update_motion_val
void ff_h263_update_motion_val(MpegEncContext *s)
Definition: h263.c:53
HWACCEL_VIDEOTOOLBOX
@ HWACCEL_VIDEOTOOLBOX
Definition: ffmpeg.h:63
ff_h263_decode_init_vlc
void ff_h263_decode_init_vlc(void)
Definition: ituh263dec.c:108
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: internal.h:62
ff_h263_find_frame_end
int ff_h263_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size)
Definition: h263_parser.c:30
ff_mpv_common_end
void ff_mpv_common_end(MpegEncContext *s)
Definition: mpegvideo.c:1111
ff_mpeg4_decode_studio_slice_header
int ff_mpeg4_decode_studio_slice_header(Mpeg4DecContext *ctx)
Decode the next video packet.
Definition: mpeg4videodec.c:546
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
av_cold
#define av_cold
Definition: attributes.h:90
AV_CODEC_ID_H263I
@ AV_CODEC_ID_H263I
Definition: codec_id.h:70
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:678
decode
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:481
AVCodecContext::has_b_frames
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:675
width
#define width
s
#define s(width, name)
Definition: cbs_vp9.c:257
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:51
h263_get_format
static enum AVPixelFormat h263_get_format(AVCodecContext *avctx)
Definition: h263dec.c:49
FF_BUG_NO_PADDING
#define FF_BUG_NO_PADDING
Definition: avcodec.h:1251
ff_mpeg_er_frame_start
void ff_mpeg_er_frame_start(MpegEncContext *s)
Definition: mpeg_er.c:46
AV_CODEC_ID_WMV2
@ AV_CODEC_ID_WMV2
Definition: codec_id.h:68
ff_flv_decode_picture_header
int ff_flv_decode_picture_header(MpegEncContext *s)
Definition: flvdec.c:28
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:290
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1421
ff_msmpeg4_decode_picture_header
int ff_msmpeg4_decode_picture_header(MpegEncContext *s)
Definition: msmpeg4dec.c:399
AV_CODEC_ID_MSMPEG4V1
@ AV_CODEC_ID_MSMPEG4V1
Definition: codec_id.h:64
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:66
AV_CODEC_ID_VC1IMAGE
@ AV_CODEC_ID_VC1IMAGE
Definition: codec_id.h:202
ff_h263_decode_frame
int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: h263dec.c:420
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:389
FRAME_SKIPPED
#define FRAME_SKIPPED
Return value for header parsers if frame is not coded.
Definition: mpegutils.h:33
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:54
AV_CODEC_ID_WMV3
@ AV_CODEC_ID_WMV3
Definition: codec_id.h:121
ff_find_unused_picture
int ff_find_unused_picture(AVCodecContext *avctx, Picture *picture, int shared)
Definition: mpegpicture.c:440
flush
static void flush(AVCodecContext *avctx)
Definition: aacdec_template.c:593
NULL
#define NULL
Definition: coverity.c:32
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:963
ER_AC_ERROR
#define ER_AC_ERROR
Definition: error_resilience.h:31
ff_mpv_idct_init
av_cold void ff_mpv_idct_init(MpegEncContext *s)
Definition: mpegvideo.c:331
AVCHROMA_LOC_LEFT
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition: pixfmt.h:597
ff_h263_decoder
const AVCodec ff_h263_decoder
Definition: h263dec.c:761
SLICE_NOEND
#define SLICE_NOEND
no end marker or error found but mb count exceeded
Definition: mpegvideo.h:521
ER_MB_ERROR
#define ER_MB_ERROR
Definition: error_resilience.h:38
AVHWAccel::end_frame
int(* end_frame)(AVCodecContext *avctx)
Called at the end of each frame or field picture.
Definition: avcodec.h:2134
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
ff_set_qscale
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
Definition: mpegvideo.c:2331
AV_CODEC_FLAG_TRUNCATED
#define AV_CODEC_FLAG_TRUNCATED
Input bitstream might be truncated at a random location instead of only at frame boundaries.
Definition: avcodec.h:252
ff_h263p_decoder
const AVCodec ff_h263p_decoder
Definition: h263dec.c:779
qpeldsp.h
AV_CODEC_ID_WMV1
@ AV_CODEC_ID_WMV1
Definition: codec_id.h:67
AV_PIX_FMT_GRAY8
@ AV_PIX_FMT_GRAY8
Y , 8bpp.
Definition: pixfmt.h:74
AV_EF_EXPLODE
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: avcodec.h:1331
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:542
wmv2.h
ff_h263_decode_end
av_cold int ff_h263_decode_end(AVCodecContext *avctx)
Definition: h263dec.c:154
ff_intel_h263_decode_picture_header
int ff_intel_h263_decode_picture_header(MpegEncContext *s)
Definition: intelh263dec.c:27
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:29
AVDISCARD_NONKEY
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition: defs.h:53
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_EF_IGNORE_ERR
#define AV_EF_IGNORE_ERR
ignore errors and continue
Definition: avcodec.h:1333
AV_CODEC_FLAG_GRAY
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
Definition: avcodec.h:243
AVPacket::size
int size
Definition: packet.h:374
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:116
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:212
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:327
FF_QSCALE_TYPE_MPEG1
#define FF_QSCALE_TYPE_MPEG1
Definition: internal.h:103
AV_CODEC_ID_H263
@ AV_CODEC_ID_H263
Definition: codec_id.h:54
ff_mpeg_flush
void ff_mpeg_flush(AVCodecContext *avctx)
Definition: mpegvideo.c:2300
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:376
AVCodecHWConfigInternal
Definition: hwconfig.h:29
ff_mpv_export_qp_table
int ff_mpv_export_qp_table(MpegEncContext *s, AVFrame *f, Picture *p, int qp_type)
Definition: mpegvideo.c:1420
ff_mpeg4_decode_picture_header
int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb, int header)
Decode MPEG-4 headers.
Definition: mpeg4videodec.c:3221
ff_print_debug_info
void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict)
Definition: mpegvideo.c:1413
HWACCEL_NVDEC
#define HWACCEL_NVDEC(codec)
Definition: hwconfig.h:71
AV_PIX_FMT_VAAPI
@ AV_PIX_FMT_VAAPI
Hardware acceleration through VA-API, data[3] contains a VASurfaceID.
Definition: pixfmt.h:119
ff_combine_frame
int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_size)
Combine the (truncated) bitstream to a complete frame.
Definition: parser.c:197
AV_CODEC_ID_MSS2
@ AV_CODEC_ID_MSS2
Definition: codec_id.h:217
AVCodec::id
enum AVCodecID id
Definition: codec.h:211
AV_PIX_FMT_VDPAU
@ AV_PIX_FMT_VDPAU
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition: pixfmt.h:187
ff_update_block_index
static void ff_update_block_index(MpegEncContext *s)
Definition: mpegvideo.h:750
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:165
AV_PIX_FMT_VIDEOTOOLBOX
@ AV_PIX_FMT_VIDEOTOOLBOX
hardware decoding through Videotoolbox
Definition: pixfmt.h:272
FMT_H263
@ FMT_H263
Definition: mpegutils.h:125
i
int i
Definition: input.c:406
ff_h263_hwaccel_pixfmt_list_420
enum AVPixelFormat ff_h263_hwaccel_pixfmt_list_420[]
Definition: h263dec.c:728
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:480
show_bits
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:447
ff_wmv2_decode_secondary_picture_header
int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s)
Definition: wmv2dec.c:171
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
FF_BUG_AUTODETECT
#define FF_BUG_AUTODETECT
autodetection
Definition: avcodec.h:1248
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:204
ff_h263_decode_init
av_cold int ff_h263_decode_init(AVCodecContext *avctx)
Definition: h263dec.c:69
AV_CODEC_ID_VC1
@ AV_CODEC_ID_VC1
Definition: codec_id.h:120
AVCodecContext::chroma_sample_location
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:970
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:589
ff_mpv_frame_end
void ff_mpv_frame_end(MpegEncContext *s)
Definition: mpegvideo.c:1405
AVCOL_RANGE_MPEG
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition: pixfmt.h:559
h263_parser.h
avcodec.h
msmpeg4.h
ret
ret
Definition: filter_design.txt:187
ff_mpeg4_frame_end
int ff_mpeg4_frame_end(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
Definition: mpeg4videodec.c:3405
FFSWAP
#define FFSWAP(type, a, b)
Definition: macros.h:52
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.c:1181
pos
unsigned int pos
Definition: spdifenc.c:412
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:146
ff_h263_decode_picture_header
int ff_h263_decode_picture_header(MpegEncContext *s)
Definition: ituh263dec.c:998
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_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:101
AVCodecContext
main external API structure.
Definition: avcodec.h:379
AVFrame::height
int height
Definition: frame.h:361
AV_CODEC_ID_H263P
@ AV_CODEC_ID_H263P
Definition: codec_id.h:69
AV_PICTURE_TYPE_B
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition: avutil.h:276
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:598
error_resilience.h
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
frame_end
static void frame_end(MpegEncContext *s)
Definition: mpegvideo_enc.c:1578
MAX_NVOP_SIZE
#define MAX_NVOP_SIZE
Definition: mpeg4video.h:72
ff_mpv_reconstruct_mb
void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
Definition: mpegvideo.c:2248
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:77
ff_mpeg4_find_frame_end
int ff_mpeg4_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size)
Find the end of the current frame in the bitstream.
Definition: mpeg4video_parser.c:37
AV_EF_AGGRESSIVE
#define AV_EF_AGGRESSIVE
consider things that a sane encoder should not do as an error
Definition: avcodec.h:1336
AVHWAccel::start_frame
int(* start_frame)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Called at the beginning of each frame or field picture.
Definition: avcodec.h:2095
AVCodecContext::coded_width
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:567
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
mpeg4video_parser.h
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:86
ER_MB_END
#define ER_MB_END
Definition: error_resilience.h:39
AVCodecContext::codec_tag
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:404
MV_DIR_FORWARD
#define MV_DIR_FORWARD
Definition: mpegvideo.h:262
AVPacket
This structure stores compressed data.
Definition: packet.h:350
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:406
ff_er_frame_end
void ff_er_frame_end(ERContext *s)
Definition: error_resilience.c:899
HWACCEL_VAAPI
#define HWACCEL_VAAPI(codec)
Definition: hwconfig.h:73
mpeg_er.h
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:334
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:28
ff_mpv_report_decode_progress
void ff_mpv_report_decode_progress(MpegEncContext *s)
Definition: mpegvideo.c:2345
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:66
ff_h263_hw_config_list
const AVCodecHWConfigInternal *const ff_h263_hw_config_list[]
Definition: h263dec.c:745
h
h
Definition: vp9dsp_template.c:2038
ER_AC_END
#define ER_AC_END
Definition: error_resilience.h:34
ff_h263_decode_mb
int ff_h263_decode_mb(MpegEncContext *s, int16_t block[6][64])
Definition: ituh263dec.c:696
AV_CODEC_ID_WMV3IMAGE
@ AV_CODEC_ID_WMV3IMAGE
Definition: codec_id.h:201
AV_CODEC_ID_FLV1
@ AV_CODEC_ID_FLV1
Definition: codec_id.h:71
ff_mpv_decode_init
void ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
Initialize the given MpegEncContext for decoding.
Definition: mpegvideo.c:699
AVDISCARD_NONREF
@ AVDISCARD_NONREF
discard all non reference
Definition: defs.h:50
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:81
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:749
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_wmv2_decode_picture_header
int ff_wmv2_decode_picture_header(MpegEncContext *s)
Definition: wmv2dec.c:136
video_enc_params.h
h263.h