FFmpeg  4.4.9
h261dec.c
Go to the documentation of this file.
1 /*
2  * H.261 decoder
3  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
4  * Copyright (c) 2004 Maarten Daniels
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.261 decoder.
26  */
27 
28 #include "libavutil/avassert.h"
29 #include "libavutil/thread.h"
30 #include "avcodec.h"
31 #include "mpeg_er.h"
32 #include "mpegutils.h"
33 #include "mpegvideo.h"
34 #include "h263.h"
35 #include "h261.h"
36 #include "internal.h"
37 
38 #define H261_MBA_VLC_BITS 8
39 #define H261_MTYPE_VLC_BITS 6
40 #define H261_MV_VLC_BITS 7
41 #define H261_CBP_VLC_BITS 9
42 #define TCOEFF_VLC_BITS 9
43 #define MBA_STUFFING 33
44 #define MBA_STARTCODE 34
45 
50 
52 {
54  ff_h261_mba_bits, 1, 1,
55  ff_h261_mba_code, 1, 1, 540);
57  ff_h261_mtype_bits, 1, 1,
58  ff_h261_mtype_code, 1, 1, 80);
60  &ff_h261_mv_tab[0][1], 2, 1,
61  &ff_h261_mv_tab[0][0], 2, 1, 144);
63  &ff_h261_cbp_tab[0][1], 2, 1,
64  &ff_h261_cbp_tab[0][0], 2, 1, 512);
66 }
67 
69 {
70  static AVOnce init_static_once = AV_ONCE_INIT;
71  H261Context *h = avctx->priv_data;
72  MpegEncContext *const s = &h->s;
73 
74  // set defaults
75  ff_mpv_decode_init(s, avctx);
76 
77  s->out_format = FMT_H261;
78  s->low_delay = 1;
79  avctx->pix_fmt = AV_PIX_FMT_YUV420P;
80 
81  h->gob_start_code_skipped = 0;
82 
83  ff_thread_once(&init_static_once, h261_decode_init_static);
84 
85  return 0;
86 }
87 
88 /**
89  * Decode the group of blocks header or slice header.
90  * @return <0 if an error occurred
91  */
93 {
94  unsigned int val;
95  MpegEncContext *const s = &h->s;
96 
97  if (!h->gob_start_code_skipped) {
98  /* Check for GOB Start Code */
99  val = show_bits(&s->gb, 15);
100  if (val)
101  return -1;
102 
103  /* We have a GBSC */
104  skip_bits(&s->gb, 16);
105  }
106 
107  h->gob_start_code_skipped = 0;
108 
109  h->gob_number = get_bits(&s->gb, 4); /* GN */
110  s->qscale = get_bits(&s->gb, 5); /* GQUANT */
111 
112  /* Check if gob_number is valid */
113  if (s->mb_height == 18) { // CIF
114  if ((h->gob_number <= 0) || (h->gob_number > 12))
115  return -1;
116  } else { // QCIF
117  if ((h->gob_number != 1) && (h->gob_number != 3) &&
118  (h->gob_number != 5))
119  return -1;
120  }
121 
122  /* GEI */
123  if (skip_1stop_8data_bits(&s->gb) < 0)
124  return AVERROR_INVALIDDATA;
125 
126  if (s->qscale == 0) {
127  av_log(s->avctx, AV_LOG_ERROR, "qscale has forbidden 0 value\n");
128  if (s->avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_COMPLIANT))
129  return -1;
130  }
131 
132  /* For the first transmitted macroblock in a GOB, MBA is the absolute
133  * address. For subsequent macroblocks, MBA is the difference between
134  * the absolute addresses of the macroblock and the last transmitted
135  * macroblock. */
136  h->current_mba = 0;
137  h->mba_diff = 0;
138 
139  return 0;
140 }
141 
142 /**
143  * Decode the group of blocks / video packet header.
144  * @return <0 if no resync found
145  */
147 {
148  MpegEncContext *const s = &h->s;
149  int ret;
150 
151  if (h->gob_start_code_skipped) {
152  ret = h261_decode_gob_header(h);
153  if (ret >= 0)
154  return 0;
155  } else {
156  if (show_bits(&s->gb, 15) == 0) {
157  ret = h261_decode_gob_header(h);
158  if (ret >= 0)
159  return 0;
160  }
161  // OK, it is not where it is supposed to be ...
162  }
163 
164  return -1;
165 }
166 
167 /**
168  * Decode skipped macroblocks.
169  * @return 0
170  */
171 static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2)
172 {
173  MpegEncContext *const s = &h->s;
174  int i;
175 
176  s->mb_intra = 0;
177 
178  for (i = mba1; i < mba2; i++) {
179  int j, xy;
180 
181  s->mb_x = ((h->gob_number - 1) % 2) * 11 + i % 11;
182  s->mb_y = ((h->gob_number - 1) / 2) * 3 + i / 11;
183  xy = s->mb_x + s->mb_y * s->mb_stride;
186 
187  for (j = 0; j < 6; j++)
188  s->block_last_index[j] = -1;
189 
190  s->mv_dir = MV_DIR_FORWARD;
191  s->mv_type = MV_TYPE_16X16;
192  s->current_picture.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0;
193  s->mv[0][0][0] = 0;
194  s->mv[0][0][1] = 0;
195  s->mb_skipped = 1;
196  h->mtype &= ~MB_TYPE_H261_FIL;
197 
198  if (s->current_picture.motion_val[0]) {
199  int b_stride = 2*s->mb_width + 1;
200  int b_xy = 2 * s->mb_x + (2 * s->mb_y) * b_stride;
201  s->current_picture.motion_val[0][b_xy][0] = s->mv[0][0][0];
202  s->current_picture.motion_val[0][b_xy][1] = s->mv[0][0][1];
203  }
204 
205  ff_mpv_reconstruct_mb(s, s->block);
206  }
207 
208  return 0;
209 }
210 
211 static const int mvmap[17] = {
212  0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16
213 };
214 
215 static int decode_mv_component(GetBitContext *gb, int v)
216 {
217  int mv_diff = get_vlc2(gb, h261_mv_vlc.table, H261_MV_VLC_BITS, 2);
218 
219  /* check if mv_diff is valid */
220  if (mv_diff < 0)
221  return v;
222 
223  mv_diff = mvmap[mv_diff];
224 
225  if (mv_diff && !get_bits1(gb))
226  mv_diff = -mv_diff;
227 
228  v += mv_diff;
229  if (v <= -16)
230  v += 32;
231  else if (v >= 16)
232  v -= 32;
233 
234  return v;
235 }
236 
237 /**
238  * Decode a macroblock.
239  * @return <0 if an error occurred
240  */
241 static int h261_decode_block(H261Context *h, int16_t *block, int n, int coded)
242 {
243  MpegEncContext *const s = &h->s;
244  int level, i, j, run;
245  RLTable *rl = &ff_h261_rl_tcoeff;
246  const uint8_t *scan_table;
247 
248  /* For the variable length encoding there are two code tables, one being
249  * used for the first transmitted LEVEL in INTER, INTER + MC and
250  * INTER + MC + FIL blocks, the second for all other LEVELs except the
251  * first one in INTRA blocks which is fixed length coded with 8 bits.
252  * NOTE: The two code tables only differ in one VLC so we handle that
253  * manually. */
254  scan_table = s->intra_scantable.permutated;
255  if (s->mb_intra) {
256  /* DC coef */
257  level = get_bits(&s->gb, 8);
258  // 0 (00000000b) and -128 (10000000b) are FORBIDDEN
259  if ((level & 0x7F) == 0) {
260  av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n",
261  level, s->mb_x, s->mb_y);
262  return -1;
263  }
264  /* The code 1000 0000 is not used, the reconstruction level of 1024
265  * being coded as 1111 1111. */
266  if (level == 255)
267  level = 128;
268  block[0] = level;
269  i = 1;
270  } else if (coded) {
271  // Run Level Code
272  // EOB Not possible for first level when cbp is available (that's why the table is different)
273  // 0 1 1s
274  // * * 0*
275  int check = show_bits(&s->gb, 2);
276  i = 0;
277  if (check & 0x2) {
278  skip_bits(&s->gb, 2);
279  block[0] = (check & 0x1) ? -1 : 1;
280  i = 1;
281  }
282  } else {
283  i = 0;
284  }
285  if (!coded) {
286  s->block_last_index[n] = i - 1;
287  return 0;
288  }
289  {
290  OPEN_READER(re, &s->gb);
291  i--; // offset by -1 to allow direct indexing of scan_table
292  for (;;) {
293  UPDATE_CACHE(re, &s->gb);
294  GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TCOEFF_VLC_BITS, 2, 0);
295  if (run == 66) {
296  if (level) {
297  CLOSE_READER(re, &s->gb);
298  av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n",
299  s->mb_x, s->mb_y);
300  return -1;
301  }
302  /* escape */
303  /* The remaining combinations of (run, level) are encoded with a
304  * 20-bit word consisting of 6 bits escape, 6 bits run and 8 bits
305  * level. */
306  run = SHOW_UBITS(re, &s->gb, 6) + 1;
307  SKIP_CACHE(re, &s->gb, 6);
308  level = SHOW_SBITS(re, &s->gb, 8);
309  SKIP_COUNTER(re, &s->gb, 6 + 8);
310  } else if (level == 0) {
311  break;
312  } else {
313  if (SHOW_UBITS(re, &s->gb, 1))
314  level = -level;
315  SKIP_COUNTER(re, &s->gb, 1);
316  }
317  i += run;
318  if (i >= 64) {
319  CLOSE_READER(re, &s->gb);
320  av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d\n",
321  s->mb_x, s->mb_y);
322  return -1;
323  }
324  j = scan_table[i];
325  block[j] = level;
326  }
327  CLOSE_READER(re, &s->gb);
328  }
329  s->block_last_index[n] = i;
330  return 0;
331 }
332 
334 {
335  MpegEncContext *const s = &h->s;
336  int i, cbp, xy;
337 
338  cbp = 63;
339  // Read mba
340  do {
341  h->mba_diff = get_vlc2(&s->gb, h261_mba_vlc.table,
342  H261_MBA_VLC_BITS, 2);
343 
344  /* Check for slice end */
345  /* NOTE: GOB can be empty (no MB data) or exist only of MBA_stuffing */
346  if (h->mba_diff == MBA_STARTCODE) { // start code
347  h->gob_start_code_skipped = 1;
348  return SLICE_END;
349  }
350  } while (h->mba_diff == MBA_STUFFING); // stuffing
351 
352  if (h->mba_diff < 0) {
353  if (get_bits_left(&s->gb) <= 7)
354  return SLICE_END;
355 
356  av_log(s->avctx, AV_LOG_ERROR, "illegal mba at %d %d\n", s->mb_x, s->mb_y);
357  return SLICE_ERROR;
358  }
359 
360  h->mba_diff += 1;
361  h->current_mba += h->mba_diff;
362 
363  if (h->current_mba > MBA_STUFFING)
364  return SLICE_ERROR;
365 
366  s->mb_x = ((h->gob_number - 1) % 2) * 11 + ((h->current_mba - 1) % 11);
367  s->mb_y = ((h->gob_number - 1) / 2) * 3 + ((h->current_mba - 1) / 11);
368  xy = s->mb_x + s->mb_y * s->mb_stride;
371 
372  // Read mtype
373  h->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2);
374  if (h->mtype < 0) {
375  av_log(s->avctx, AV_LOG_ERROR, "Invalid mtype index %d\n",
376  h->mtype);
377  return SLICE_ERROR;
378  }
380  h->mtype = ff_h261_mtype_map[h->mtype];
381 
382  // Read mquant
383  if (IS_QUANT(h->mtype))
384  ff_set_qscale(s, get_bits(&s->gb, 5));
385 
386  s->mb_intra = IS_INTRA4x4(h->mtype);
387 
388  // Read mv
389  if (IS_16X16(h->mtype)) {
390  /* Motion vector data is included for all MC macroblocks. MVD is
391  * obtained from the macroblock vector by subtracting the vector
392  * of the preceding macroblock. For this calculation the vector
393  * of the preceding macroblock is regarded as zero in the
394  * following three situations:
395  * 1) evaluating MVD for macroblocks 1, 12 and 23;
396  * 2) evaluating MVD for macroblocks in which MBA does not represent a difference of 1;
397  * 3) MTYPE of the previous macroblock was not MC. */
398  if ((h->current_mba == 1) || (h->current_mba == 12) ||
399  (h->current_mba == 23) || (h->mba_diff != 1)) {
400  h->current_mv_x = 0;
401  h->current_mv_y = 0;
402  }
403 
404  h->current_mv_x = decode_mv_component(&s->gb, h->current_mv_x);
405  h->current_mv_y = decode_mv_component(&s->gb, h->current_mv_y);
406  } else {
407  h->current_mv_x = 0;
408  h->current_mv_y = 0;
409  }
410 
411  // Read cbp
412  if (HAS_CBP(h->mtype))
413  cbp = get_vlc2(&s->gb, h261_cbp_vlc.table, H261_CBP_VLC_BITS, 1) + 1;
414 
415  if (s->mb_intra) {
416  s->current_picture.mb_type[xy] = MB_TYPE_INTRA;
417  goto intra;
418  }
419 
420  //set motion vectors
421  s->mv_dir = MV_DIR_FORWARD;
422  s->mv_type = MV_TYPE_16X16;
423  s->current_picture.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0;
424  s->mv[0][0][0] = h->current_mv_x * 2; // gets divided by 2 in motion compensation
425  s->mv[0][0][1] = h->current_mv_y * 2;
426 
427  if (s->current_picture.motion_val[0]) {
428  int b_stride = 2*s->mb_width + 1;
429  int b_xy = 2 * s->mb_x + (2 * s->mb_y) * b_stride;
430  s->current_picture.motion_val[0][b_xy][0] = s->mv[0][0][0];
431  s->current_picture.motion_val[0][b_xy][1] = s->mv[0][0][1];
432  }
433 
434 intra:
435  /* decode each block */
436  if (s->mb_intra || HAS_CBP(h->mtype)) {
437  s->bdsp.clear_blocks(s->block[0]);
438  for (i = 0; i < 6; i++) {
439  if (h261_decode_block(h, s->block[i], i, cbp & 32) < 0)
440  return SLICE_ERROR;
441  cbp += cbp;
442  }
443  } else {
444  for (i = 0; i < 6; i++)
445  s->block_last_index[i] = -1;
446  }
447 
448  ff_mpv_reconstruct_mb(s, s->block);
449 
450  return SLICE_OK;
451 }
452 
453 /**
454  * Decode the H.261 picture header.
455  * @return <0 if no startcode found
456  */
458 {
459  MpegEncContext *const s = &h->s;
460  int format, i;
461  uint32_t startcode = 0;
462 
463  for (i = get_bits_left(&s->gb); i > 24; i -= 1) {
464  startcode = ((startcode << 1) | get_bits(&s->gb, 1)) & 0x000FFFFF;
465 
466  if (startcode == 0x10)
467  break;
468  }
469 
470  if (startcode != 0x10) {
471  av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
472  return -1;
473  }
474 
475  /* temporal reference */
476  i = get_bits(&s->gb, 5); /* picture timestamp */
477  if (i < (s->picture_number & 31))
478  i += 32;
479  s->picture_number = (s->picture_number & ~31) + i;
480 
481  s->avctx->framerate = (AVRational) { 30000, 1001 };
482 
483  /* PTYPE starts here */
484  skip_bits1(&s->gb); /* split screen off */
485  skip_bits1(&s->gb); /* camera off */
486  skip_bits1(&s->gb); /* freeze picture release off */
487 
488  format = get_bits1(&s->gb);
489 
490  // only 2 formats possible
491  if (format == 0) { // QCIF
492  s->width = 176;
493  s->height = 144;
494  s->mb_width = 11;
495  s->mb_height = 9;
496  } else { // CIF
497  s->width = 352;
498  s->height = 288;
499  s->mb_width = 22;
500  s->mb_height = 18;
501  }
502 
503  s->mb_num = s->mb_width * s->mb_height;
504 
505  skip_bits1(&s->gb); /* still image mode off */
506  skip_bits1(&s->gb); /* Reserved */
507 
508  /* PEI */
509  if (skip_1stop_8data_bits(&s->gb) < 0)
510  return AVERROR_INVALIDDATA;
511 
512  /* H.261 has no I-frames, but if we pass AV_PICTURE_TYPE_I for the first
513  * frame, the codec crashes if it does not contain all I-blocks
514  * (e.g. when a packet is lost). */
515  s->pict_type = AV_PICTURE_TYPE_P;
516 
517  h->gob_number = 0;
518  return 0;
519 }
520 
522 {
523  MpegEncContext *const s = &h->s;
524 
525  ff_set_qscale(s, s->qscale);
526 
527  /* decode mb's */
528  while (h->current_mba <= MBA_STUFFING) {
529  int ret;
530  /* DCT & quantize */
531  ret = h261_decode_mb(h);
532  if (ret < 0) {
533  if (ret == SLICE_END) {
534  h261_decode_mb_skipped(h, h->current_mba, 33);
535  return 0;
536  }
537  av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n",
538  s->mb_x + s->mb_y * s->mb_stride);
539  return -1;
540  }
541 
543  h->current_mba - h->mba_diff,
544  h->current_mba - 1);
545  }
546 
547  return -1;
548 }
549 
550 /**
551  * returns the number of bytes consumed for building the current frame
552  */
553 static int get_consumed_bytes(MpegEncContext *s, int buf_size)
554 {
555  int pos = get_bits_count(&s->gb) >> 3;
556  if (pos == 0)
557  pos = 1; // avoid infinite loops (i doubt that is needed but ...)
558  if (pos + 10 > buf_size)
559  pos = buf_size; // oops ;)
560 
561  return pos;
562 }
563 
564 static int h261_decode_frame(AVCodecContext *avctx, void *data,
565  int *got_frame, AVPacket *avpkt)
566 {
567  const uint8_t *buf = avpkt->data;
568  int buf_size = avpkt->size;
569  H261Context *h = avctx->priv_data;
570  MpegEncContext *s = &h->s;
571  int ret;
572  AVFrame *pict = data;
573 
574  ff_dlog(avctx, "*****frame %d size=%d\n", avctx->frame_number, buf_size);
575  ff_dlog(avctx, "bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);
576 
577  h->gob_start_code_skipped = 0;
578 
579 retry:
580  init_get_bits(&s->gb, buf, buf_size * 8);
581 
582  if (!s->context_initialized)
583  // we need the IDCT permutation for reading a custom matrix
585 
587 
588  /* skip if the header was thrashed */
589  if (ret < 0) {
590  av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
591  return -1;
592  }
593 
594  if (s->width != avctx->coded_width || s->height != avctx->coded_height) {
596  }
597 
598  if (!s->context_initialized) {
599  if ((ret = ff_mpv_common_init(s)) < 0)
600  return ret;
601 
602  ret = ff_set_dimensions(avctx, s->width, s->height);
603  if (ret < 0)
604  return ret;
605 
606  goto retry;
607  }
608 
609  // for skipping the frame
610  s->current_picture.f->pict_type = s->pict_type;
611  s->current_picture.f->key_frame = s->pict_type == AV_PICTURE_TYPE_I;
612 
613  if ((avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) ||
614  (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) ||
615  avctx->skip_frame >= AVDISCARD_ALL)
616  return get_consumed_bytes(s, buf_size);
617 
618  if (ff_mpv_frame_start(s, avctx) < 0)
619  return -1;
620 
622 
623  /* decode each macroblock */
624  s->mb_x = 0;
625  s->mb_y = 0;
626 
627  while (h->gob_number < (s->mb_height == 18 ? 12 : 5)) {
628  if (h261_resync(h) < 0)
629  break;
631  }
633 
634  av_assert0(s->current_picture.f->pict_type == s->current_picture_ptr->f->pict_type);
635  av_assert0(s->current_picture.f->pict_type == s->pict_type);
636 
637  if ((ret = av_frame_ref(pict, s->current_picture_ptr->f)) < 0)
638  return ret;
639  ff_print_debug_info(s, s->current_picture_ptr, pict);
640 
641  *got_frame = 1;
642 
643  return get_consumed_bytes(s, buf_size);
644 }
645 
647 {
648  H261Context *h = avctx->priv_data;
649  MpegEncContext *s = &h->s;
650 
652  return 0;
653 }
654 
656  .name = "h261",
657  .long_name = NULL_IF_CONFIG_SMALL("H.261"),
658  .type = AVMEDIA_TYPE_VIDEO,
659  .id = AV_CODEC_ID_H261,
660  .priv_data_size = sizeof(H261Context),
662  .close = h261_decode_end,
664  .capabilities = AV_CODEC_CAP_DR1,
665  .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
666  .max_lowres = 3,
667 };
static double val(void *priv, double ch)
Definition: aeval.c:76
static const char *const format[]
Definition: af_aiir.c:457
#define av_cold
Definition: attributes.h:88
uint8_t
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
Libavcodec external API header.
#define AV_EF_BITSTREAM
detect bitstream specification deviations
Definition: avcodec.h:1658
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
Definition: avcodec.h:1664
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
#define s(width, name)
Definition: cbs_vp9.c:257
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:71
float re
Definition: fft.c:82
#define SKIP_CACHE(name, gb, num)
Definition: get_bits.h:180
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:797
#define CLOSE_READER(name, gb)
Definition: get_bits.h:149
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:849
#define SHOW_UBITS(name, gb, num)
Definition: get_bits.h:211
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:498
#define SHOW_SBITS(name, gb, num)
Definition: get_bits.h:212
#define OPEN_READER(name, gb)
Definition: get_bits.h:138
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:467
static int skip_1stop_8data_bits(GetBitContext *gb)
Definition: get_bits.h:854
#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)
Definition: get_bits.h:738
#define UPDATE_CACHE(name, gb)
Definition: get_bits.h:178
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:219
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:538
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:379
#define SKIP_COUNTER(name, gb, num)
Definition: get_bits.h:185
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:446
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:659
#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_ID_H261
Definition: codec_id.h:52
@ AVDISCARD_ALL
discard all
Definition: avcodec.h:236
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition: avcodec.h:235
@ AVDISCARD_NONREF
discard all non reference
Definition: avcodec.h:232
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
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:443
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:275
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition: avutil.h:276
H.261 codec.
const int ff_h261_mtype_map[10]
Definition: h261data.c:75
RLTable ff_h261_rl_tcoeff
Definition: h261data.c:150
const uint8_t ff_h261_mv_tab[17][2]
Definition: h261data.c:89
const uint8_t ff_h261_mtype_bits[10]
Definition: h261data.c:69
#define MB_TYPE_H261_FIL
Definition: h261.h:49
const uint8_t ff_h261_mtype_code[10]
Definition: h261data.c:63
const uint8_t ff_h261_mba_code[35]
Definition: h261data.c:34
const uint8_t ff_h261_cbp_tab[63][2]
Definition: h261data.c:95
const uint8_t ff_h261_mba_bits[35]
Definition: h261data.c:48
int i
Definition: input.c:407
static VLC h261_mtype_vlc
Definition: h261dec.c:47
AVCodec ff_h261_decoder
Definition: h261dec.c:655
static int h261_decode_gob(H261Context *h)
Definition: h261dec.c:521
static int h261_decode_gob_header(H261Context *h)
Decode the group of blocks header or slice header.
Definition: h261dec.c:92
static int get_consumed_bytes(MpegEncContext *s, int buf_size)
returns the number of bytes consumed for building the current frame
Definition: h261dec.c:553
static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2)
Decode skipped macroblocks.
Definition: h261dec.c:171
#define H261_MTYPE_VLC_BITS
Definition: h261dec.c:39
static VLC h261_mv_vlc
Definition: h261dec.c:48
static int h261_decode_block(H261Context *h, int16_t *block, int n, int coded)
Decode a macroblock.
Definition: h261dec.c:241
#define TCOEFF_VLC_BITS
Definition: h261dec.c:42
#define H261_MBA_VLC_BITS
Definition: h261dec.c:38
static av_cold int h261_decode_end(AVCodecContext *avctx)
Definition: h261dec.c:646
static VLC h261_mba_vlc
Definition: h261dec.c:46
static VLC h261_cbp_vlc
Definition: h261dec.c:49
static int h261_resync(H261Context *h)
Decode the group of blocks / video packet header.
Definition: h261dec.c:146
static av_cold int h261_decode_init(AVCodecContext *avctx)
Definition: h261dec.c:68
#define H261_CBP_VLC_BITS
Definition: h261dec.c:41
static int h261_decode_picture_header(H261Context *h)
Decode the H.261 picture header.
Definition: h261dec.c:457
static av_cold void h261_decode_init_static(void)
Definition: h261dec.c:51
#define H261_MV_VLC_BITS
Definition: h261dec.c:40
static const int mvmap[17]
Definition: h261dec.c:211
#define MBA_STUFFING
Definition: h261dec.c:43
#define MBA_STARTCODE
Definition: h261dec.c:44
static int h261_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: h261dec.c:564
static int decode_mv_component(GetBitContext *gb, int v)
Definition: h261dec.c:215
static int h261_decode_mb(H261Context *h)
Definition: h261dec.c:333
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:41
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:84
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
#define AVOnce
Definition: thread.h:172
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:175
#define AV_ONCE_INIT
Definition: thread.h:173
#define check(x, y, S, v)
void ff_mpeg_er_frame_start(MpegEncContext *s)
Definition: mpeg_er.c:46
#define IS_INTRA4x4(a)
Definition: mpegutils.h:75
#define MB_TYPE_SKIP
Definition: mpegutils.h:62
#define HAS_CBP(a)
Definition: mpegutils.h:101
#define MB_TYPE_INTRA
Definition: mpegutils.h:73
#define IS_16X16(a)
Definition: mpegutils.h:86
#define MB_TYPE_16x16
Definition: mpegutils.h:54
#define MB_TYPE_L0
Definition: mpegutils.h:67
#define IS_QUANT(a)
Definition: mpegutils.h:95
@ FMT_H261
Definition: mpegutils.h:125
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
void ff_mpv_common_end(MpegEncContext *s)
Definition: mpegvideo.c:1111
void ff_mpv_frame_end(MpegEncContext *s)
Definition: mpegvideo.c:1405
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
Definition: mpegvideo.c:913
av_cold void ff_mpv_idct_init(MpegEncContext *s)
Definition: mpegvideo.c:331
void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict)
Definition: mpegvideo.c:1413
void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
Definition: mpegvideo.c:2256
void ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
Initialize the given MpegEncContext for decoding.
Definition: mpegvideo.c:699
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
Definition: mpegvideo.c:2339
void ff_init_block_index(MpegEncContext *s)
Definition: mpegvideo.c:2275
mpegvideo header.
#define SLICE_END
end marker found
Definition: mpegvideo.h:523
#define MV_DIR_FORWARD
Definition: mpegvideo.h:262
#define SLICE_OK
Definition: mpegvideo.h:521
#define MV_TYPE_16X16
1 vector for the whole mb
Definition: mpegvideo.h:266
#define SLICE_ERROR
Definition: mpegvideo.h:522
static void ff_update_block_index(MpegEncContext *s)
Definition: mpegvideo.h:750
const char data[16]
Definition: mxf.c:142
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
#define INIT_FIRST_VLC_RL(rl, static_size)
Definition: rl.h:71
#define FF_ARRAY_ELEMS(a)
unsigned int pos
Definition: spdifenc.c:412
main external API structure.
Definition: avcodec.h:536
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:746
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:1227
int coded_height
Definition: avcodec.h:724
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:724
void * priv_data
Definition: avcodec.h:563
enum AVDiscard skip_frame
Skip decoding for selected frames.
Definition: avcodec.h:2010
AVCodec.
Definition: codec.h:197
const char * name
Name of the codec implementation.
Definition: codec.h:204
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
This structure stores compressed data.
Definition: packet.h:346
int size
Definition: packet.h:370
uint8_t * data
Definition: packet.h:369
Rational number (pair of numerator and denominator).
Definition: rational.h:58
H261Context.
Definition: h261.h:37
MpegEncContext.
Definition: mpegvideo.h:81
RLTable.
Definition: rl.h:39
RL_VLC_ELEM * rl_vlc[32]
decoding only
Definition: rl.h:48
Definition: vlc.h:26
VLC_TYPE(* table)[2]
code, bits
Definition: vlc.h:28
uint8_t run
Definition: svq3.c:205
uint8_t level
Definition: svq3.c:206
#define ff_dlog(a,...)
#define av_log(a,...)
static int16_t block[64]
Definition: dct.c:116
if(ret< 0)
Definition: vf_mcdeint.c:282
#define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size)
Definition: vlc.h:120