FFmpeg  2.6.9
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
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 "libavutil/cpu.h"
31 #include "avcodec.h"
32 #include "error_resilience.h"
33 #include "flv.h"
34 #include "h263.h"
35 #include "h263_parser.h"
36 #include "internal.h"
37 #include "mpeg_er.h"
38 #include "mpeg4video.h"
39 #include "mpeg4video_parser.h"
40 #include "mpegvideo.h"
41 #include "msmpeg4.h"
42 #include "qpeldsp.h"
43 #include "vdpau_internal.h"
44 #include "thread.h"
45 
47 {
48  if (avctx->codec->id == AV_CODEC_ID_MSS2)
49  return AV_PIX_FMT_YUV420P;
50 
51  return avctx->pix_fmt = ff_get_format(avctx, avctx->codec->pix_fmts);
52 }
53 
55 {
56  MpegEncContext *s = avctx->priv_data;
57  int ret;
58 
59  s->out_format = FMT_H263;
60 
61  // set defaults
63  ff_mpv_decode_init(s, avctx);
64 
65  s->quant_precision = 5;
67  s->low_delay = 1;
68  s->unrestricted_mv = 1;
69 
70  /* select sub codec */
71  switch (avctx->codec->id) {
72  case AV_CODEC_ID_H263:
73  case AV_CODEC_ID_H263P:
74  s->unrestricted_mv = 0;
76  break;
77  case AV_CODEC_ID_MPEG4:
78  break;
80  s->h263_pred = 1;
81  s->msmpeg4_version = 1;
82  break;
84  s->h263_pred = 1;
85  s->msmpeg4_version = 2;
86  break;
88  s->h263_pred = 1;
89  s->msmpeg4_version = 3;
90  break;
91  case AV_CODEC_ID_WMV1:
92  s->h263_pred = 1;
93  s->msmpeg4_version = 4;
94  break;
95  case AV_CODEC_ID_WMV2:
96  s->h263_pred = 1;
97  s->msmpeg4_version = 5;
98  break;
99  case AV_CODEC_ID_VC1:
100  case AV_CODEC_ID_WMV3:
103  case AV_CODEC_ID_MSS2:
104  s->h263_pred = 1;
105  s->msmpeg4_version = 6;
107  break;
108  case AV_CODEC_ID_H263I:
109  break;
110  case AV_CODEC_ID_FLV1:
111  s->h263_flv = 1;
112  break;
113  default:
114  av_log(avctx, AV_LOG_ERROR, "Unsupported codec %d\n",
115  avctx->codec->id);
116  return AVERROR(ENOSYS);
117  }
118  s->codec_id = avctx->codec->id;
119 
120  if (avctx->codec_tag == AV_RL32("L263") || avctx->codec_tag == AV_RL32("S263"))
121  if (avctx->extradata_size == 56 && avctx->extradata[0] == 1)
122  s->ehc_mode = 1;
123 
124  /* for h263, we allocate the images after having read the header */
125  if (avctx->codec->id != AV_CODEC_ID_H263 &&
126  avctx->codec->id != AV_CODEC_ID_H263P &&
127  avctx->codec->id != AV_CODEC_ID_MPEG4) {
128  avctx->pix_fmt = h263_get_format(avctx);
129  ff_mpv_idct_init(s);
130  if ((ret = ff_mpv_common_init(s)) < 0)
131  return ret;
132  }
133 
135  ff_qpeldsp_init(&s->qdsp);
137 
138  return 0;
139 }
140 
142 {
143  MpegEncContext *s = avctx->priv_data;
144 
146  return 0;
147 }
148 
149 /**
150  * Return the number of bytes consumed for building the current frame.
151  */
152 static int get_consumed_bytes(MpegEncContext *s, int buf_size)
153 {
154  int pos = (get_bits_count(&s->gb) + 7) >> 3;
155 
156  if (s->divx_packed || s->avctx->hwaccel) {
157  /* We would have to scan through the whole buf to handle the weird
158  * reordering ... */
159  return buf_size;
160  } else if (s->flags & CODEC_FLAG_TRUNCATED) {
161  pos -= s->parse_context.last_index;
162  // padding is not really read so this might be -1
163  if (pos < 0)
164  pos = 0;
165  return pos;
166  } else {
167  // avoid infinite loops (maybe not needed...)
168  if (pos == 0)
169  pos = 1;
170  // oops ;)
171  if (pos + 10 > buf_size)
172  pos = buf_size;
173 
174  return pos;
175  }
176 }
177 
179 {
180  const int part_mask = s->partitioned_frame
181  ? (ER_AC_END | ER_AC_ERROR) : 0x7F;
182  const int mb_size = 16 >> s->avctx->lowres;
183  int ret;
184 
185  s->last_resync_gb = s->gb;
186  s->first_slice_line = 1;
187  s->resync_mb_x = s->mb_x;
188  s->resync_mb_y = s->mb_y;
189 
190  ff_set_qscale(s, s->qscale);
191 
192  if (s->avctx->hwaccel) {
193  const uint8_t *start = s->gb.buffer + get_bits_count(&s->gb) / 8;
194  ret = s->avctx->hwaccel->decode_slice(s->avctx, start, s->gb.buffer_end - start);
195  // ensure we exit decode loop
196  s->mb_y = s->mb_height;
197  return ret;
198  }
199 
200  if (s->partitioned_frame) {
201  const int qscale = s->qscale;
202 
204  if ((ret = ff_mpeg4_decode_partitions(s->avctx->priv_data)) < 0)
205  return ret;
206 
207  /* restore variables which were modified */
208  s->first_slice_line = 1;
209  s->mb_x = s->resync_mb_x;
210  s->mb_y = s->resync_mb_y;
211  ff_set_qscale(s, qscale);
212  }
213 
214  for (; s->mb_y < s->mb_height; s->mb_y++) {
215  /* per-row end of slice checks */
216  if (s->msmpeg4_version) {
217  if (s->resync_mb_y + s->slice_height == s->mb_y) {
219  s->mb_x - 1, s->mb_y, ER_MB_END);
220 
221  return 0;
222  }
223  }
224 
225  if (s->msmpeg4_version == 1) {
226  s->last_dc[0] =
227  s->last_dc[1] =
228  s->last_dc[2] = 128;
229  }
230 
232  for (; s->mb_x < s->mb_width; s->mb_x++) {
233  int ret;
234 
236 
237  if (s->resync_mb_x == s->mb_x && s->resync_mb_y + 1 == s->mb_y)
238  s->first_slice_line = 0;
239 
240  /* DCT & quantize */
241 
242  s->mv_dir = MV_DIR_FORWARD;
243  s->mv_type = MV_TYPE_16X16;
244  av_dlog(s, "%d %d %06X\n",
245  ret, get_bits_count(&s->gb), show_bits(&s->gb, 24));
246 
247  tprintf(NULL, "Decoding MB at %dx%d\n", s->mb_x, s->mb_y);
248  ret = s->decode_mb(s, s->block);
249 
250  if (s->pict_type != AV_PICTURE_TYPE_B)
252 
253  if (ret < 0) {
254  const int xy = s->mb_x + s->mb_y * s->mb_stride;
255  if (ret == SLICE_END) {
256  ff_mpv_decode_mb(s, s->block);
257  if (s->loop_filter)
259 
261  s->mb_x, s->mb_y, ER_MB_END & part_mask);
262 
263  s->padding_bug_score--;
264 
265  if (++s->mb_x >= s->mb_width) {
266  s->mb_x = 0;
267  ff_mpeg_draw_horiz_band(s, s->mb_y * mb_size, mb_size);
269  s->mb_y++;
270  }
271  return 0;
272  } else if (ret == SLICE_NOEND) {
274  "Slice mismatch at MB: %d\n", xy);
276  s->mb_x + 1, s->mb_y,
277  ER_MB_END & part_mask);
278  return AVERROR_INVALIDDATA;
279  }
280  av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy);
282  s->mb_x, s->mb_y, ER_MB_ERROR & part_mask);
283 
285  continue;
286  return AVERROR_INVALIDDATA;
287  }
288 
289  ff_mpv_decode_mb(s, s->block);
290  if (s->loop_filter)
292  }
293 
294  ff_mpeg_draw_horiz_band(s, s->mb_y * mb_size, mb_size);
296 
297  s->mb_x = 0;
298  }
299 
300  av_assert1(s->mb_x == 0 && s->mb_y == s->mb_height);
301 
302  if (s->codec_id == AV_CODEC_ID_MPEG4 &&
304  get_bits_left(&s->gb) >= 48 &&
305  show_bits(&s->gb, 24) == 0x4010 &&
306  !s->data_partitioning)
307  s->padding_bug_score += 32;
308 
309  /* try to detect the padding bug */
310  if (s->codec_id == AV_CODEC_ID_MPEG4 &&
312  get_bits_left(&s->gb) >= 0 &&
313  get_bits_left(&s->gb) < 137 &&
314  !s->data_partitioning) {
315  const int bits_count = get_bits_count(&s->gb);
316  const int bits_left = s->gb.size_in_bits - bits_count;
317 
318  if (bits_left == 0) {
319  s->padding_bug_score += 16;
320  } else if (bits_left != 1) {
321  int v = show_bits(&s->gb, 8);
322  v |= 0x7F >> (7 - (bits_count & 7));
323 
324  if (v == 0x7F && bits_left <= 8)
325  s->padding_bug_score--;
326  else if (v == 0x7F && ((get_bits_count(&s->gb) + 8) & 8) &&
327  bits_left <= 16)
328  s->padding_bug_score += 4;
329  else
330  s->padding_bug_score++;
331  }
332  }
333 
334  if (s->codec_id == AV_CODEC_ID_H263 &&
336  get_bits_left(&s->gb) >= 8 &&
337  get_bits_left(&s->gb) < 300 &&
339  show_bits(&s->gb, 8) == 0 &&
340  !s->data_partitioning) {
341 
342  s->padding_bug_score += 32;
343  }
344 
345  if (s->codec_id == AV_CODEC_ID_H263 &&
347  get_bits_left(&s->gb) >= 64 &&
348  AV_RB64(s->gb.buffer_end - 8) == 0xCDCDCDCDFC7F0000) {
349 
350  s->padding_bug_score += 32;
351  }
352 
354  if (
355  (s->padding_bug_score > -2 && !s->data_partitioning))
357  else
359  }
360 
361  // handle formats which don't have unique end markers
362  if (s->msmpeg4_version || (s->workaround_bugs & FF_BUG_NO_PADDING)) { // FIXME perhaps solve this more cleanly
363  int left = get_bits_left(&s->gb);
364  int max_extra = 7;
365 
366  /* no markers in M$ crap */
368  max_extra += 17;
369 
370  /* buggy padding but the frame should still end approximately at
371  * the bitstream end */
372  if ((s->workaround_bugs & FF_BUG_NO_PADDING) &&
374  max_extra += 48;
375  else if ((s->workaround_bugs & FF_BUG_NO_PADDING))
376  max_extra += 256 * 256 * 256 * 64;
377 
378  if (left > max_extra)
380  "discarding %d junk bits at end, next would be %X\n",
381  left, show_bits(&s->gb, 24));
382  else if (left < 0)
383  av_log(s->avctx, AV_LOG_ERROR, "overreading %d bits\n", -left);
384  else
386  s->mb_x - 1, s->mb_y, ER_MB_END);
387 
388  return 0;
389  }
390 
392  "slice end not reached but screenspace end (%d left %06X, score= %d)\n",
393  get_bits_left(&s->gb), show_bits(&s->gb, 24), s->padding_bug_score);
394 
395  ff_er_add_slice(&s->er, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y,
396  ER_MB_END & part_mask);
397 
398  return AVERROR_INVALIDDATA;
399 }
400 
401 int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
402  AVPacket *avpkt)
403 {
404  const uint8_t *buf = avpkt->data;
405  int buf_size = avpkt->size;
406  MpegEncContext *s = avctx->priv_data;
407  int ret;
408  int slice_ret = 0;
409  AVFrame *pict = data;
410 
411  s->flags = avctx->flags;
412  s->flags2 = avctx->flags2;
413 
414  /* no supplementary picture */
415  if (buf_size == 0) {
416  /* special case for last picture */
417  if (s->low_delay == 0 && s->next_picture_ptr) {
418  if ((ret = av_frame_ref(pict, s->next_picture_ptr->f)) < 0)
419  return ret;
420  s->next_picture_ptr = NULL;
421 
422  *got_frame = 1;
423  }
424 
425  return 0;
426  }
427 
428  if (s->flags & CODEC_FLAG_TRUNCATED) {
429  int next;
430 
432  next = ff_mpeg4_find_frame_end(&s->parse_context, buf, buf_size);
433  } else if (CONFIG_H263_DECODER && s->codec_id == AV_CODEC_ID_H263) {
434  next = ff_h263_find_frame_end(&s->parse_context, buf, buf_size);
435  } else if (CONFIG_H263P_DECODER && s->codec_id == AV_CODEC_ID_H263P) {
436  next = ff_h263_find_frame_end(&s->parse_context, buf, buf_size);
437  } else {
439  "this codec does not support truncated bitstreams\n");
440  return AVERROR(ENOSYS);
441  }
442 
443  if (ff_combine_frame(&s->parse_context, next, (const uint8_t **)&buf,
444  &buf_size) < 0)
445  return buf_size;
446  }
447 
448 retry:
449  if (s->divx_packed && s->bitstream_buffer_size) {
450  int i;
451  for(i=0; i < buf_size-3; i++) {
452  if (buf[i]==0 && buf[i+1]==0 && buf[i+2]==1) {
453  if (buf[i+3]==0xB0) {
454  av_log(s->avctx, AV_LOG_WARNING, "Discarding excessive bitstream in packed xvid\n");
455  s->bitstream_buffer_size = 0;
456  }
457  break;
458  }
459  }
460  }
461 
462  if (s->bitstream_buffer_size && (s->divx_packed || buf_size < 20)) // divx 5.01+/xvid frame reorder
463  ret = init_get_bits8(&s->gb, s->bitstream_buffer,
465  else
466  ret = init_get_bits8(&s->gb, buf, buf_size);
467 
468  s->bitstream_buffer_size = 0;
469  if (ret < 0)
470  return ret;
471 
472  if (!s->context_initialized)
473  // we need the idct permutaton for reading a custom matrix
474  ff_mpv_idct_init(s);
475 
476  /* let's go :-) */
477  if (CONFIG_WMV2_DECODER && s->msmpeg4_version == 5) {
479  } else if (CONFIG_MSMPEG4_DECODER && s->msmpeg4_version) {
481  } else if (CONFIG_MPEG4_DECODER && avctx->codec_id == AV_CODEC_ID_MPEG4) {
482  if (s->avctx->extradata_size && s->picture_number == 0) {
483  GetBitContext gb;
484 
485  if (init_get_bits8(&gb, s->avctx->extradata, s->avctx->extradata_size) >= 0 )
487  }
488  ret = ff_mpeg4_decode_picture_header(avctx->priv_data, &s->gb);
489  } else if (CONFIG_H263I_DECODER && s->codec_id == AV_CODEC_ID_H263I) {
491  } else if (CONFIG_FLV_DECODER && s->h263_flv) {
493  } else {
495  }
496 
497  if (ret < 0 || ret == FRAME_SKIPPED) {
498  if ( s->width != avctx->coded_width
499  || s->height != avctx->coded_height) {
500  av_log(s->avctx, AV_LOG_WARNING, "Reverting picture dimensions change due to header decoding failure\n");
501  s->width = avctx->coded_width;
502  s->height= avctx->coded_height;
503  }
504  }
505  if (ret == FRAME_SKIPPED)
506  return get_consumed_bytes(s, buf_size);
507 
508  /* skip if the header was thrashed */
509  if (ret < 0) {
510  av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
511  return ret;
512  }
513 
514  if (!s->context_initialized) {
515  avctx->pix_fmt = h263_get_format(avctx);
516  if ((ret = ff_mpv_common_init(s)) < 0)
517  return ret;
518  }
519 
520  if (!s->current_picture_ptr || s->current_picture_ptr->f->data[0]) {
521  int i = ff_find_unused_picture(s, 0);
522  if (i < 0)
523  return i;
524  s->current_picture_ptr = &s->picture[i];
525  }
526 
527  avctx->has_b_frames = !s->low_delay;
528 
530  if (ff_mpeg4_workaround_bugs(avctx) == 1)
531  goto retry;
532  }
533 
534  /* After H263 & mpeg4 header decode we have the height, width,
535  * and other parameters. So then we could init the picture.
536  * FIXME: By the way H263 decoder is evolving it should have
537  * an H263EncContext */
538  if (s->width != avctx->coded_width ||
539  s->height != avctx->coded_height ||
540  s->context_reinit) {
541  /* H.263 could change picture size any time */
542  s->context_reinit = 0;
543 
544  ret = ff_set_dimensions(avctx, s->width, s->height);
545  if (ret < 0)
546  return ret;
547 
548  ff_set_sar(avctx, avctx->sample_aspect_ratio);
549 
550  if ((ret = ff_mpv_common_frame_size_change(s)))
551  return ret;
552 
553  if (avctx->pix_fmt != h263_get_format(avctx)) {
554  av_log(avctx, AV_LOG_ERROR, "format change not supported\n");
555  avctx->pix_fmt = AV_PIX_FMT_NONE;
556  return AVERROR_UNKNOWN;
557  }
558  }
559 
560  if (s->codec_id == AV_CODEC_ID_H263 ||
561  s->codec_id == AV_CODEC_ID_H263P ||
564 
565  // for skipping the frame
568 
569  /* skip B-frames if we don't have reference frames */
570  if (!s->last_picture_ptr &&
571  (s->pict_type == AV_PICTURE_TYPE_B || s->droppable))
572  return get_consumed_bytes(s, buf_size);
573  if ((avctx->skip_frame >= AVDISCARD_NONREF &&
574  s->pict_type == AV_PICTURE_TYPE_B) ||
575  (avctx->skip_frame >= AVDISCARD_NONKEY &&
576  s->pict_type != AV_PICTURE_TYPE_I) ||
577  avctx->skip_frame >= AVDISCARD_ALL)
578  return get_consumed_bytes(s, buf_size);
579 
580  if (s->next_p_frame_damaged) {
581  if (s->pict_type == AV_PICTURE_TYPE_B)
582  return get_consumed_bytes(s, buf_size);
583  else
584  s->next_p_frame_damaged = 0;
585  }
586 
587  if ((!s->no_rounding) || s->pict_type == AV_PICTURE_TYPE_B) {
590  } else {
593  }
594 
595  if ((ret = ff_mpv_frame_start(s, avctx)) < 0)
596  return ret;
597 
598  if (!s->divx_packed && !avctx->hwaccel)
599  ff_thread_finish_setup(avctx);
600 
603  goto frame_end;
604  }
605 
606  if (avctx->hwaccel) {
607  ret = avctx->hwaccel->start_frame(avctx, s->gb.buffer,
608  s->gb.buffer_end - s->gb.buffer);
609  if (ret < 0 )
610  return ret;
611  }
612 
614 
615  /* the second part of the wmv2 header contains the MB skip bits which
616  * are stored in current_picture->mb_type which is not available before
617  * ff_mpv_frame_start() */
618  if (CONFIG_WMV2_DECODER && s->msmpeg4_version == 5) {
620  if (ret < 0)
621  return ret;
622  if (ret == 1)
623  goto frame_end;
624  }
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) {
633  if (s->slice_height == 0 || s->mb_x != 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 < 4 && s->h263_pred)
646 
647  if (decode_slice(s) < 0)
648  slice_ret = AVERROR_INVALIDDATA;
649  }
650 
651  if (s->msmpeg4_version && s->msmpeg4_version < 4 &&
653  if (!CONFIG_MSMPEG4_DECODER ||
654  ff_msmpeg4_decode_ext_header(s, buf_size) < 0)
656 
658 frame_end:
659  ff_er_frame_end(&s->er);
660 
661  if (avctx->hwaccel) {
662  ret = avctx->hwaccel->end_frame(avctx);
663  if (ret < 0)
664  return ret;
665  }
666 
667  ff_mpv_frame_end(s);
668 
670  ff_mpeg4_frame_end(avctx, buf, buf_size);
671 
672  if (!s->divx_packed && avctx->hwaccel)
673  ff_thread_finish_setup(avctx);
674 
677  if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
678  if ((ret = av_frame_ref(pict, s->current_picture_ptr->f)) < 0)
679  return ret;
682  } else if (s->last_picture_ptr) {
683  if ((ret = av_frame_ref(pict, s->last_picture_ptr->f)) < 0)
684  return ret;
687  }
688 
689  if (s->last_picture_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  int x, y, p;
694  for (p=0; p<3; p++) {
695  int w = FF_CEIL_RSHIFT(pict-> width, !!p);
696  int h = FF_CEIL_RSHIFT(pict->height, !!p);
697  int linesize = pict->linesize[p];
698  for (y=0; y<(h>>1); y++)
699  for (x=0; x<w; x++)
700  FFSWAP(int,
701  pict->data[p][x + y*linesize],
702  pict->data[p][x + (h-1-y)*linesize]);
703  }
704  }
705  *got_frame = 1;
706  }
707 
708  if (slice_ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE))
709  return ret;
710  else
711  return get_consumed_bytes(s, buf_size);
712 }
713 
715 #if CONFIG_H263_VAAPI_HWACCEL || CONFIG_MPEG4_VAAPI_HWACCEL
717 #endif
718 #if CONFIG_H263_VDPAU_HWACCEL || CONFIG_MPEG4_VDPAU_HWACCEL
720 #endif
723 };
724 
726  .name = "h263",
727  .long_name = NULL_IF_CONFIG_SMALL("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"),
728  .type = AVMEDIA_TYPE_VIDEO,
729  .id = AV_CODEC_ID_H263,
730  .priv_data_size = sizeof(MpegEncContext),
732  .close = ff_h263_decode_end,
734  .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 |
736  .flush = ff_mpeg_flush,
737  .max_lowres = 3,
739 };
740 
742  .name = "h263p",
743  .long_name = NULL_IF_CONFIG_SMALL("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"),
744  .type = AVMEDIA_TYPE_VIDEO,
745  .id = AV_CODEC_ID_H263P,
746  .priv_data_size = sizeof(MpegEncContext),
748  .close = ff_h263_decode_end,
750  .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 |
752  .flush = ff_mpeg_flush,
753  .max_lowres = 3,
755 };
int bitstream_buffer_size
Definition: mpegvideo.h:548
#define NULL
Definition: coverity.c:32
const struct AVCodec * codec
Definition: avcodec.h:1248
discard all frames except keyframes
Definition: avcodec.h:666
void ff_init_block_index(MpegEncContext *s)
Definition: mpegvideo.c:3378
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:3338
float v
qpel_mc_func avg_qpel_pixels_tab[2][16]
Definition: qpeldsp.h:74
int picture_number
Definition: mpegvideo.h:262
const char * s
Definition: avisynth_c.h:669
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
mpeg2/4, h264 default
Definition: pixfmt.h:528
This structure describes decoded (raw) audio or video data.
Definition: frame.h:163
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1422
#define SLICE_NOEND
no end marker or error found but mb count exceeded
Definition: mpegvideo.h:633
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:181
qpel_mc_func put_no_rnd_qpel_pixels_tab[2][16]
Definition: qpeldsp.h:75
#define ER_MB_END
#define AV_RB64
Definition: intreadwrite.h:164
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:229
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
static int decode_slice(MpegEncContext *s)
Definition: h263dec.c:178
#define CODEC_CAP_TRUNCATED
Definition: avcodec.h:788
void ff_er_frame_end(ERContext *s)
int msmpeg4_version
0=not msmpeg4, 1=mp41, 2=mp42, 3=mp43/divx3 4=wmv1/7 5=wmv2/8
Definition: mpegvideo.h:568
av_cold void ff_h263dsp_init(H263DSPContext *ctx)
Definition: h263dsp.c:117
int size
Definition: avcodec.h:1161
uint8_t * bitstream_buffer
Definition: mpegvideo.h:547
enum AVCodecID codec_id
Definition: mpegvideo.h:244
HW decoding through VA API, Picture.data[3] contains a vaapi_render_state struct which contains the b...
Definition: pixfmt.h:131
#define AV_EF_AGGRESSIVE
consider things that a sane encoder should not do as an error
Definition: avcodec.h:2626
const uint8_t * buffer
Definition: get_bits.h:55
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:1621
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1442
int ff_mpeg4_frame_end(AVCodecContext *avctx, const uint8_t *buf, int buf_size)
mpegvideo header.
av_dlog(ac->avr,"%d samples - audio_convert: %s to %s (%s)\n", len, av_get_sample_fmt_name(ac->in_fmt), av_get_sample_fmt_name(ac->out_fmt), use_generic?ac->func_descr_generic:ac->func_descr)
discard all
Definition: avcodec.h:667
int ff_mpeg4_workaround_bugs(AVCodecContext *avctx)
int padding_bug_score
used to detect the VERY common padding bug in MPEG4
Definition: mpegvideo.h:543
int mb_num
number of MBs of a picture
Definition: mpegvideo.h:268
QpelDSPContext qdsp
Definition: mpegvideo.h:372
AVCodec.
Definition: avcodec.h:3173
int qscale
QP.
Definition: mpegvideo.h:341
int quant_precision
Definition: mpegvideo.h:532
int ff_h263_decode_mb(MpegEncContext *s, int16_t block[6][64])
Definition: ituh263dec.c:605
#define FF_QSCALE_TYPE_MPEG1
Definition: avcodec.h:946
enum AVDiscard skip_frame
Skip decoding for selected frames.
Definition: avcodec.h:2939
void ff_mpeg4_clean_buffers(MpegEncContext *s)
Definition: mpeg4video.c:45
struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:2642
void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
Definition: mpegvideo.c:3371
int context_reinit
Definition: mpegvideo.h:677
static enum AVPixelFormat h263_get_format(AVCodecContext *avctx)
Definition: h263dec.c:46
void ff_h263_decode_init_vlc(void)
Definition: ituh263dec.c:103
uint8_t
#define av_cold
Definition: attributes.h:74
enum OutputFormat out_format
output format
Definition: mpegvideo.h:236
int ff_mpv_common_frame_size_change(MpegEncContext *s)
Definition: mpegvideo.c:1533
Multithreading support functions.
#define CODEC_CAP_HWACCEL_VDPAU
Codec can export data for HW decoding (VDPAU).
Definition: avcodec.h:832
#define ER_MB_ERROR
qpel_mc_func(* qpel_put)[16]
Definition: mpegvideo.h:200
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:278
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:1353
int no_rounding
apply no rounding to motion compensation (MPEG4, msmpeg4, ...) for b-frames rounding mode is always 0...
Definition: mpegvideo.h:419
void ff_mpv_decode_mb(MpegEncContext *s, int16_t block[12][64])
Definition: mpegvideo.c:3359
int ff_intel_h263_decode_picture_header(MpegEncContext *s)
Definition: intelh263dec.c:25
Picture current_picture
copy of the current picture structure.
Definition: mpegvideo.h:315
GetBitContext last_resync_gb
used to search for the next resync marker
Definition: mpegvideo.h:492
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:787
quarterpel DSP functions
uint8_t * data
Definition: avcodec.h:1160
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:212
#define FF_BUG_NO_PADDING
Definition: avcodec.h:2514
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:244
int flags2
AVCodecContext.flags2.
Definition: mpegvideo.h:248
av_cold void ff_mpv_idct_init(MpegEncContext *s)
Definition: mpegvideo.c:427
int mb_height
number of MBs horizontally & vertically
Definition: mpegvideo.h:264
int lowres
low resolution decoding, 1-> 1/2 size, 2->1/4 size
Definition: avcodec.h:2735
#define CONFIG_H263I_DECODER
Definition: config.h:637
int codec_tag
internal codec_tag upper case converted from avctx codec_tag
Definition: mpegvideo.h:254
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
int ff_wmv2_decode_picture_header(MpegEncContext *s)
Definition: wmv2dec.c:119
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:1965
#define av_log(a,...)
static void ff_update_block_index(MpegEncContext *s)
Definition: mpegvideo.h:821
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
Definition: mpegvideo.c:3470
#define CONFIG_H263P_DECODER
Definition: config.h:638
#define AV_EF_IGNORE_ERR
ignore errors and continue
Definition: avcodec.h:2623
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:588
enum AVCodecID id
Definition: avcodec.h:3187
H263DSPContext h263dsp
Definition: mpegvideo.h:374
#define CODEC_FLAG_TRUNCATED
Definition: avcodec.h:745
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:175
int has_b_frames
Size of the frame reordering buffer in the decoder.
Definition: avcodec.h:1531
int last_dc[3]
last DC values for MPEG1
Definition: mpegvideo.h:320
void ff_er_add_slice(ERContext *s, int startx, int starty, int endx, int endy, int status)
Add a slice.
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: avcodec.h:2621
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: avcodec.h:822
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:231
int partitioned_frame
is current frame partitioned
Definition: mpegvideo.h:537
#define AVERROR(e)
Definition: error.h:43
AVCodec ff_h263_decoder
Definition: h263dec.c:725
int unrestricted_mv
mv can point outside of the coded picture
Definition: mpegvideo.h:360
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:180
ERContext er
Definition: mpegvideo.h:679
int capabilities
Codec capabilities.
Definition: avcodec.h:3192
int ff_wmv2_decode_secondary_picture_header(MpegEncContext *s)
Definition: wmv2dec.c:139
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1333
#define FF_BUG_AUTODETECT
autodetection
Definition: avcodec.h:2508
const char * name
Name of the codec implementation.
Definition: avcodec.h:3180
int low_delay
no reordering needed / has no b-frames
Definition: mpegvideo.h:538
qpel_mc_func put_qpel_pixels_tab[2][16]
Definition: qpeldsp.h:73
GetBitContext gb
Definition: mpegvideo.h:578
int(* decode_mb)(struct MpegEncContext *s, int16_t block[6][64])
Definition: mpegvideo.h:629
void ff_mpv_common_end(MpegEncContext *s)
Definition: mpegvideo.c:1609
Libavcodec external API header.
int ff_flv_decode_picture_header(MpegEncContext *s)
Definition: flvdec.c:27
void ff_mpeg_flush(AVCodecContext *avctx)
Definition: mpegvideo.c:3439
static void frame_end(MpegEncContext *s)
int resync_mb_x
x position of last resync marker
Definition: mpegvideo.h:490
uint8_t * error_status_table
#define ER_AC_ERROR
void ff_h263_loop_filter(MpegEncContext *s)
Definition: h263.c:139
int err_recognition
Definition: mpegvideo.h:495
int ff_mpv_export_qp_table(MpegEncContext *s, AVFrame *f, Picture *p, int qp_type)
Definition: mpegvideo.c:2609
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
Definition: avcodec.h:3194
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:234
#define CONFIG_MPEG4_DECODER
Definition: config.h:672
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:2610
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:53
#define CODEC_CAP_DRAW_HORIZ_BAND
Decoder can use draw_horiz_band callback.
Definition: avcodec.h:781
int ff_h263_get_gob_height(MpegEncContext *s)
Get the GOB height based on picture height.
Definition: h263.c:375
static int get_consumed_bytes(MpegEncContext *s, int buf_size)
Return the number of bytes consumed for building the current frame.
Definition: h263dec.c:152
int last_index
Definition: parser.h:31
float y
int next_p_frame_damaged
set if the next p frame is damaged, to avoid showing trashed b frames
Definition: mpegvideo.h:494
ret
Definition: avfilter.c:974
Picture * current_picture_ptr
pointer to the current picture
Definition: mpegvideo.h:319
void ff_mpeg_er_frame_start(MpegEncContext *s)
Definition: mpeg_er.c:46
#define FF_CEIL_RSHIFT(a, b)
Definition: common.h:57
int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb)
Decode mpeg4 headers.
int size_in_bits
Definition: get_bits.h:57
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:287
int ff_msmpeg4_decode_ext_header(MpegEncContext *s, int buf_size)
Definition: msmpeg4dec.c:551
AVCodec ff_h263p_decoder
Definition: h263dec.c:741
#define AV_RL32
Definition: intreadwrite.h:146
MotionEstContext me
Definition: mpegvideo.h:417
int ff_h263_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: h263dec.c:401
void ff_mpv_decode_defaults(MpegEncContext *s)
Set the given MpegEncContext to defaults for decoding.
Definition: mpegvideo.c:1113
av_cold int ff_h263_decode_end(AVCodecContext *avctx)
Definition: h263dec.c:141
static void flush(AVCodecContext *avctx)
Definition: aacdec.c:502
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
Definition: utils.c:1197
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:224
#define MV_TYPE_16X16
1 vector for the whole mb
Definition: mpegvideo.h:401
int first_slice_line
used in mpeg4 too to handle resync markers
Definition: mpegvideo.h:566
void ff_h263_update_motion_val(MpegEncContext *s)
Definition: h263.c:46
int h263_flv
use flv h263 header
Definition: mpegvideo.h:242
enum AVCodecID codec_id
Definition: avcodec.h:1256
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:191
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:441
main external API structure.
Definition: avcodec.h:1239
int height
picture size. must be a multiple of 16
Definition: mpegvideo.h:232
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:1271
void * buf
Definition: avisynth_c.h:595
void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict)
Definition: mpegvideo.c:2602
#define SLICE_END
end marker found
Definition: mpegvideo.h:632
Picture * picture
main picture buffer
Definition: mpegvideo.h:271
int data_partitioning
data partitioning flag from header
Definition: mpegvideo.h:536
int extradata_size
Definition: avcodec.h:1354
#define CONFIG_H263_DECODER
Definition: config.h:636
int ff_mpeg4_decode_partitions(Mpeg4DecContext *ctx)
Decode the first and second partition.
int coded_height
Definition: avcodec.h:1422
struct AVFrame * f
Definition: mpegvideo.h:104
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition: pixfmt.h:216
#define CONFIG_MPEG4_VDPAU_DECODER
Definition: config.h:674
int context_initialized
Definition: mpegvideo.h:259
int slice_height
in macroblocks
Definition: mpegvideo.h:565
#define CONFIG_FLV_DECODER
Definition: config.h:629
int ff_h263_decode_picture_header(MpegEncContext *s)
Definition: ituh263dec.c:871
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:1844
#define MV_DIR_FORWARD
Definition: mpegvideo.h:397
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:349
int h263_pred
use mpeg4/h263 ac/dc predictions
Definition: mpegvideo.h:237
av_cold int ff_h263_decode_init(AVCodecContext *avctx)
Definition: h263dec.c:54
int ff_h263_resync(MpegEncContext *s)
Decode the group of blocks / video packet header.
Definition: ituh263dec.c:207
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
Definition: frame.c:420
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:174
qpel_mc_func(* qpel_avg)[16]
Definition: mpegvideo.h:201
MpegEncContext.
Definition: mpegvideo.h:213
Picture * next_picture_ptr
pointer to the next picture (for bidir pred)
Definition: mpegvideo.h:318
struct AVCodecContext * avctx
Definition: mpegvideo.h:230
static int decode(AVCodecContext *avctx, void *data, int *got_sub, AVPacket *avpkt)
Definition: ccaption_dec.c:520
discard all non reference
Definition: avcodec.h:663
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:68
#define tprintf(p,...)
Definition: get_bits.h:692
common internal api header.
int mb_stride
mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 ...
Definition: mpegvideo.h:265
void ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
Definition: mpegvideo.c:1118
const uint8_t * buffer_end
Definition: get_bits.h:55
enum AVPixelFormat ff_h263_hwaccel_pixfmt_list_420[]
Definition: h263dec.c:714
Picture * last_picture_ptr
pointer to the previous picture.
Definition: mpegvideo.h:317
Bi-dir predicted.
Definition: avutil.h:269
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
void * priv_data
Definition: avcodec.h:1281
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
Definition: mpegvideo.c:1372
void ff_mpv_frame_end(MpegEncContext *s)
Definition: mpegvideo.c:2071
void ff_vdpau_mpeg4_decode_picture(Mpeg4DecContext *s, const uint8_t *buf, int buf_size)
int resync_mb_y
y position of last resync marker
Definition: mpegvideo.h:491
int16_t(* block)[64]
points to one of the following blocks
Definition: mpegvideo.h:627
ParseContext parse_context
Definition: mpegvideo.h:497
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:229
#define CONFIG_WMV2_DECODER
Definition: config.h:770
int flags2
CODEC_FLAG2_*.
Definition: avcodec.h:1340
int height
Definition: frame.h:212
int flags
AVCodecContext.flags (HQ, MV4, ...)
Definition: mpegvideo.h:247
void INT64 start
Definition: avisynth_c.h:595
int workaround_bugs
workaround bugs in encoders which cannot be detected automatically
Definition: mpegvideo.h:253
#define FRAME_SKIPPED
return value for header parsers if frame is not coded
Definition: mpegvideo.h:58
int ff_msmpeg4_decode_picture_header(MpegEncContext *s)
Definition: msmpeg4dec.c:396
mpeg1, jpeg, h263
Definition: pixfmt.h:529
#define ER_AC_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.
av_cold void ff_qpeldsp_init(QpelDSPContext *c)
Definition: qpeldsp.c:783
#define FFSWAP(type, a, b)
Definition: common.h:84
#define CONFIG_MSMPEG4_DECODER
Definition: msmpeg4.h:59
int(* decode_slice)(AVCodecContext *avctx, const uint8_t *buf, uint32_t buf_size)
Callback for each slice.
Definition: avcodec.h:3352
int ff_find_unused_picture(MpegEncContext *s, int shared)
Definition: mpegvideo.c:1810
int ff_h263_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size)
Definition: h263_parser.c:30
#define AV_EF_BUFFER
detect improper bitstream length
Definition: avcodec.h:2620
int(* end_frame)(AVCodecContext *avctx)
Called at the end of each frame or field picture.
Definition: avcodec.h:3363
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
This structure stores compressed data.
Definition: avcodec.h:1137
void ff_mpv_report_decode_progress(MpegEncContext *s)
Definition: mpegvideo.c:3484
static int width