Libav
h261dec.c
Go to the documentation of this file.
1 /*
2  * H261 decoder
3  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
4  * Copyright (c) 2004 Maarten Daniels
5  *
6  * This file is part of Libav.
7  *
8  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
28 #include "avcodec.h"
29 #include "mpegvideo.h"
30 #include "h263.h"
31 #include "h261.h"
32 #include "internal.h"
33 
34 #define H261_MBA_VLC_BITS 9
35 #define H261_MTYPE_VLC_BITS 6
36 #define H261_MV_VLC_BITS 7
37 #define H261_CBP_VLC_BITS 9
38 #define TCOEFF_VLC_BITS 9
39 #define MBA_STUFFING 33
40 #define MBA_STARTCODE 34
41 
46 
48 {
49  static int done = 0;
50 
51  if (!done) {
52  done = 1;
53  INIT_VLC_STATIC(&h261_mba_vlc, H261_MBA_VLC_BITS, 35,
54  ff_h261_mba_bits, 1, 1,
55  ff_h261_mba_code, 1, 1, 662);
56  INIT_VLC_STATIC(&h261_mtype_vlc, H261_MTYPE_VLC_BITS, 10,
57  ff_h261_mtype_bits, 1, 1,
58  ff_h261_mtype_code, 1, 1, 80);
59  INIT_VLC_STATIC(&h261_mv_vlc, H261_MV_VLC_BITS, 17,
60  &ff_h261_mv_tab[0][1], 2, 1,
61  &ff_h261_mv_tab[0][0], 2, 1, 144);
62  INIT_VLC_STATIC(&h261_cbp_vlc, H261_CBP_VLC_BITS, 63,
63  &ff_h261_cbp_tab[0][1], 2, 1,
64  &ff_h261_cbp_tab[0][0], 2, 1, 512);
66  }
67 }
68 
70 {
71  H261Context *h = avctx->priv_data;
72  MpegEncContext *const s = &h->s;
73 
74  // set defaults
76  s->avctx = avctx;
77  s->width = s->avctx->coded_width;
78  s->height = s->avctx->coded_height;
79  s->codec_id = s->avctx->codec->id;
80  s->out_format = FMT_H261;
81  s->low_delay = 1;
82  avctx->pix_fmt = AV_PIX_FMT_YUV420P;
83  s->codec_id = avctx->codec->id;
84 
87 
89 
90  return 0;
91 }
92 
98 {
99  unsigned int val;
100  MpegEncContext *const s = &h->s;
101 
102  if (!h->gob_start_code_skipped) {
103  /* Check for GOB Start Code */
104  val = show_bits(&s->gb, 15);
105  if (val)
106  return -1;
107 
108  /* We have a GBSC */
109  skip_bits(&s->gb, 16);
110  }
111 
112  h->gob_start_code_skipped = 0;
113 
114  h->gob_number = get_bits(&s->gb, 4); /* GN */
115  s->qscale = get_bits(&s->gb, 5); /* GQUANT */
116 
117  /* Check if gob_number is valid */
118  if (s->mb_height == 18) { // CIF
119  if ((h->gob_number <= 0) || (h->gob_number > 12))
120  return -1;
121  } else { // QCIF
122  if ((h->gob_number != 1) && (h->gob_number != 3) &&
123  (h->gob_number != 5))
124  return -1;
125  }
126 
127  /* GEI */
128  while (get_bits1(&s->gb) != 0)
129  skip_bits(&s->gb, 8);
130 
131  if (s->qscale == 0) {
132  av_log(s->avctx, AV_LOG_ERROR, "qscale has forbidden 0 value\n");
134  return -1;
135  }
136 
137  /* For the first transmitted macroblock in a GOB, MBA is the absolute
138  * address. For subsequent macroblocks, MBA is the difference between
139  * the absolute addresses of the macroblock and the last transmitted
140  * macroblock. */
141  h->current_mba = 0;
142  h->mba_diff = 0;
143 
144  return 0;
145 }
146 
151 static int h261_resync(H261Context *h)
152 {
153  MpegEncContext *const s = &h->s;
154  int left, ret;
155 
156  if (h->gob_start_code_skipped) {
157  ret = h261_decode_gob_header(h);
158  if (ret >= 0)
159  return 0;
160  } else {
161  if (show_bits(&s->gb, 15) == 0) {
162  ret = h261_decode_gob_header(h);
163  if (ret >= 0)
164  return 0;
165  }
166  // OK, it is not where it is supposed to be ...
167  s->gb = s->last_resync_gb;
168  align_get_bits(&s->gb);
169  left = get_bits_left(&s->gb);
170 
171  for (; left > 15 + 1 + 4 + 5; left -= 8) {
172  if (show_bits(&s->gb, 15) == 0) {
173  GetBitContext bak = s->gb;
174 
175  ret = h261_decode_gob_header(h);
176  if (ret >= 0)
177  return 0;
178 
179  s->gb = bak;
180  }
181  skip_bits(&s->gb, 8);
182  }
183  }
184 
185  return -1;
186 }
187 
192 static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2)
193 {
194  MpegEncContext *const s = &h->s;
195  int i;
196 
197  s->mb_intra = 0;
198 
199  for (i = mba1; i < mba2; i++) {
200  int j, xy;
201 
202  s->mb_x = ((h->gob_number - 1) % 2) * 11 + i % 11;
203  s->mb_y = ((h->gob_number - 1) / 2) * 3 + i / 11;
204  xy = s->mb_x + s->mb_y * s->mb_stride;
207 
208  for (j = 0; j < 6; j++)
209  s->block_last_index[j] = -1;
210 
211  s->mv_dir = MV_DIR_FORWARD;
212  s->mv_type = MV_TYPE_16X16;
214  s->mv[0][0][0] = 0;
215  s->mv[0][0][1] = 0;
216  s->mb_skipped = 1;
217  h->mtype &= ~MB_TYPE_H261_FIL;
218 
219  ff_MPV_decode_mb(s, s->block);
220  }
221 
222  return 0;
223 }
224 
225 static const int mvmap[17] = {
226  0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16
227 };
228 
229 static int decode_mv_component(GetBitContext *gb, int v)
230 {
231  int mv_diff = get_vlc2(gb, h261_mv_vlc.table, H261_MV_VLC_BITS, 2);
232 
233  /* check if mv_diff is valid */
234  if (mv_diff < 0)
235  return v;
236 
237  mv_diff = mvmap[mv_diff];
238 
239  if (mv_diff && !get_bits1(gb))
240  mv_diff = -mv_diff;
241 
242  v += mv_diff;
243  if (v <= -16)
244  v += 32;
245  else if (v >= 16)
246  v -= 32;
247 
248  return v;
249 }
250 
255 static int h261_decode_block(H261Context *h, int16_t *block, int n, int coded)
256 {
257  MpegEncContext *const s = &h->s;
258  int code, level, i, j, run;
259  RLTable *rl = &ff_h261_rl_tcoeff;
260  const uint8_t *scan_table;
261 
262  /* For the variable length encoding there are two code tables, one being
263  * used for the first transmitted LEVEL in INTER, INTER + MC and
264  * INTER + MC + FIL blocks, the second for all other LEVELs except the
265  * first one in INTRA blocks which is fixed length coded with 8 bits.
266  * NOTE: The two code tables only differ in one VLC so we handle that
267  * manually. */
268  scan_table = s->intra_scantable.permutated;
269  if (s->mb_intra) {
270  /* DC coef */
271  level = get_bits(&s->gb, 8);
272  // 0 (00000000b) and -128 (10000000b) are FORBIDDEN
273  if ((level & 0x7F) == 0) {
274  av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n",
275  level, s->mb_x, s->mb_y);
276  return -1;
277  }
278  /* The code 1000 0000 is not used, the reconstruction level of 1024
279  * being coded as 1111 1111. */
280  if (level == 255)
281  level = 128;
282  block[0] = level;
283  i = 1;
284  } else if (coded) {
285  // Run Level Code
286  // EOB Not possible for first level when cbp is available (that's why the table is different)
287  // 0 1 1s
288  // * * 0*
289  int check = show_bits(&s->gb, 2);
290  i = 0;
291  if (check & 0x2) {
292  skip_bits(&s->gb, 2);
293  block[0] = (check & 0x1) ? -1 : 1;
294  i = 1;
295  }
296  } else {
297  i = 0;
298  }
299  if (!coded) {
300  s->block_last_index[n] = i - 1;
301  return 0;
302  }
303  for (;;) {
304  code = get_vlc2(&s->gb, rl->vlc.table, TCOEFF_VLC_BITS, 2);
305  if (code < 0) {
306  av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n",
307  s->mb_x, s->mb_y);
308  return -1;
309  }
310  if (code == rl->n) {
311  /* escape */
312  /* The remaining combinations of (run, level) are encoded with a
313  * 20-bit word consisting of 6 bits escape, 6 bits run and 8 bits
314  * level. */
315  run = get_bits(&s->gb, 6);
316  level = get_sbits(&s->gb, 8);
317  } else if (code == 0) {
318  break;
319  } else {
320  run = rl->table_run[code];
321  level = rl->table_level[code];
322  if (get_bits1(&s->gb))
323  level = -level;
324  }
325  i += run;
326  if (i >= 64) {
327  av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d\n",
328  s->mb_x, s->mb_y);
329  return -1;
330  }
331  j = scan_table[i];
332  block[j] = level;
333  i++;
334  }
335  s->block_last_index[n] = i - 1;
336  return 0;
337 }
338 
340 {
341  MpegEncContext *const s = &h->s;
342  int i, cbp, xy;
343 
344  cbp = 63;
345  // Read mba
346  do {
347  h->mba_diff = get_vlc2(&s->gb, h261_mba_vlc.table,
348  H261_MBA_VLC_BITS, 2);
349 
350  /* Check for slice end */
351  /* NOTE: GOB can be empty (no MB data) or exist only of MBA_stuffing */
352  if (h->mba_diff == MBA_STARTCODE) { // start code
353  h->gob_start_code_skipped = 1;
354  return SLICE_END;
355  }
356  } while (h->mba_diff == MBA_STUFFING); // stuffing
357 
358  if (h->mba_diff < 0) {
359  if (get_bits_left(&s->gb) <= 7)
360  return SLICE_END;
361 
362  av_log(s->avctx, AV_LOG_ERROR, "illegal mba at %d %d\n", s->mb_x, s->mb_y);
363  return SLICE_ERROR;
364  }
365 
366  h->mba_diff += 1;
367  h->current_mba += h->mba_diff;
368 
369  if (h->current_mba > MBA_STUFFING)
370  return SLICE_ERROR;
371 
372  s->mb_x = ((h->gob_number - 1) % 2) * 11 + ((h->current_mba - 1) % 11);
373  s->mb_y = ((h->gob_number - 1) / 2) * 3 + ((h->current_mba - 1) / 11);
374  xy = s->mb_x + s->mb_y * s->mb_stride;
377 
378  // Read mtype
379  h->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2);
380  if (h->mtype < 0 || h->mtype >= FF_ARRAY_ELEMS(ff_h261_mtype_map)) {
381  av_log(s->avctx, AV_LOG_ERROR, "Invalid mtype index %d\n",
382  h->mtype);
383  return SLICE_ERROR;
384  }
385  h->mtype = ff_h261_mtype_map[h->mtype];
386 
387  // Read mquant
388  if (IS_QUANT(h->mtype))
389  ff_set_qscale(s, get_bits(&s->gb, 5));
390 
391  s->mb_intra = IS_INTRA4x4(h->mtype);
392 
393  // Read mv
394  if (IS_16X16(h->mtype)) {
395  /* Motion vector data is included for all MC macroblocks. MVD is
396  * obtained from the macroblock vector by subtracting the vector
397  * of the preceding macroblock. For this calculation the vector
398  * of the preceding macroblock is regarded as zero in the
399  * following three situations:
400  * 1) evaluating MVD for macroblocks 1, 12 and 23;
401  * 2) evaluating MVD for macroblocks in which MBA does not represent a difference of 1;
402  * 3) MTYPE of the previous macroblock was not MC. */
403  if ((h->current_mba == 1) || (h->current_mba == 12) ||
404  (h->current_mba == 23) || (h->mba_diff != 1)) {
405  h->current_mv_x = 0;
406  h->current_mv_y = 0;
407  }
408 
411  } else {
412  h->current_mv_x = 0;
413  h->current_mv_y = 0;
414  }
415 
416  // Read cbp
417  if (HAS_CBP(h->mtype))
418  cbp = get_vlc2(&s->gb, h261_cbp_vlc.table, H261_CBP_VLC_BITS, 2) + 1;
419 
420  if (s->mb_intra) {
422  goto intra;
423  }
424 
425  //set motion vectors
426  s->mv_dir = MV_DIR_FORWARD;
427  s->mv_type = MV_TYPE_16X16;
429  s->mv[0][0][0] = h->current_mv_x * 2; // gets divided by 2 in motion compensation
430  s->mv[0][0][1] = h->current_mv_y * 2;
431 
432 intra:
433  /* decode each block */
434  if (s->mb_intra || HAS_CBP(h->mtype)) {
435  s->dsp.clear_blocks(s->block[0]);
436  for (i = 0; i < 6; i++) {
437  if (h261_decode_block(h, s->block[i], i, cbp & 32) < 0)
438  return SLICE_ERROR;
439  cbp += cbp;
440  }
441  } else {
442  for (i = 0; i < 6; i++)
443  s->block_last_index[i] = -1;
444  }
445 
446  ff_MPV_decode_mb(s, s->block);
447 
448  return SLICE_OK;
449 }
450 
456 {
457  MpegEncContext *const s = &h->s;
458  int format, i;
459  uint32_t startcode = 0;
460 
461  for (i = get_bits_left(&s->gb); i > 24; i -= 1) {
462  startcode = ((startcode << 1) | get_bits(&s->gb, 1)) & 0x000FFFFF;
463 
464  if (startcode == 0x10)
465  break;
466  }
467 
468  if (startcode != 0x10) {
469  av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
470  return -1;
471  }
472 
473  /* temporal reference */
474  i = get_bits(&s->gb, 5); /* picture timestamp */
475  if (i < (s->picture_number & 31))
476  i += 32;
477  s->picture_number = (s->picture_number & ~31) + i;
478 
479  s->avctx->time_base = (AVRational) { 1001, 30000 };
480 
481  /* PTYPE starts here */
482  skip_bits1(&s->gb); /* split screen off */
483  skip_bits1(&s->gb); /* camera off */
484  skip_bits1(&s->gb); /* freeze picture release off */
485 
486  format = get_bits1(&s->gb);
487 
488  // only 2 formats possible
489  if (format == 0) { // QCIF
490  s->width = 176;
491  s->height = 144;
492  s->mb_width = 11;
493  s->mb_height = 9;
494  } else { // CIF
495  s->width = 352;
496  s->height = 288;
497  s->mb_width = 22;
498  s->mb_height = 18;
499  }
500 
501  s->mb_num = s->mb_width * s->mb_height;
502 
503  skip_bits1(&s->gb); /* still image mode off */
504  skip_bits1(&s->gb); /* Reserved */
505 
506  /* PEI */
507  while (get_bits1(&s->gb) != 0)
508  skip_bits(&s->gb, 8);
509 
510  /* H.261 has no I-frames, but if we pass AV_PICTURE_TYPE_I for the first
511  * frame, the codec crashes if it does not contain all I-blocks
512  * (e.g. when a packet is lost). */
514 
515  h->gob_number = 0;
516  return 0;
517 }
518 
520 {
521  MpegEncContext *const s = &h->s;
522 
523  ff_set_qscale(s, s->qscale);
524 
525  /* decode mb's */
526  while (h->current_mba <= MBA_STUFFING) {
527  int ret;
528  /* DCT & quantize */
529  ret = h261_decode_mb(h);
530  if (ret < 0) {
531  if (ret == SLICE_END) {
533  return 0;
534  }
535  av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n",
536  s->mb_x + s->mb_y * s->mb_stride);
537  return -1;
538  }
539 
541  h->current_mba - h->mba_diff,
542  h->current_mba - 1);
543  }
544 
545  return -1;
546 }
547 
551 static int get_consumed_bytes(MpegEncContext *s, int buf_size)
552 {
553  int pos = get_bits_count(&s->gb) >> 3;
554  if (pos == 0)
555  pos = 1; // avoid infinite loops (i doubt that is needed but ...)
556  if (pos + 10 > buf_size)
557  pos = buf_size; // oops ;)
558 
559  return pos;
560 }
561 
562 static int h261_decode_frame(AVCodecContext *avctx, void *data,
563  int *got_frame, AVPacket *avpkt)
564 {
565  const uint8_t *buf = avpkt->data;
566  int buf_size = avpkt->size;
567  H261Context *h = avctx->priv_data;
568  MpegEncContext *s = &h->s;
569  int ret;
570  AVFrame *pict = data;
571 
572  av_dlog(avctx, "*****frame %d size=%d\n", avctx->frame_number, buf_size);
573  av_dlog(avctx, "bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);
574  s->flags = avctx->flags;
575  s->flags2 = avctx->flags2;
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 permutaton for reading a custom matrix
584  if (ff_MPV_common_init(s) < 0)
585  return -1;
586 
588 
589  /* skip if the header was thrashed */
590  if (ret < 0) {
591  av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
592  return -1;
593  }
594 
595  if (s->width != avctx->coded_width || s->height != avctx->coded_height) {
596  ParseContext pc = s->parse_context; // FIXME move this demuxing hack to libavformat
597  s->parse_context.buffer = 0;
599  s->parse_context = pc;
600  }
601  if (!s->context_initialized) {
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
612 
613  if ((avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) ||
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;
630  h261_decode_gob(h);
631  }
632  ff_MPV_frame_end(s);
633 
635  assert(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;
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),
664  .capabilities = CODEC_CAP_DR1,
665 };
#define SLICE_ERROR
Definition: mpegvideo.h:681
const struct AVCodec * codec
Definition: avcodec.h:1063
#define MB_TYPE_SKIP
Definition: avcodec.h:813
discard all frames except keyframes
Definition: avcodec.h:545
void ff_init_block_index(MpegEncContext *s)
Definition: mpegvideo.c:2372
int picture_number
Definition: mpegvideo.h:298
#define H261_CBP_VLC_BITS
Definition: h261dec.c:37
This structure describes decoded (raw) audio or video data.
Definition: frame.h:107
static int get_consumed_bytes(MpegEncContext *s, int buf_size)
returns the number of bytes consumed for building the current frame
Definition: h261dec.c:551
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1227
#define H261_MBA_VLC_BITS
Definition: h261dec.c:34
av_cold int ff_MPV_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
Definition: mpegvideo.c:1205
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:240
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:144
MpegEncContext s
Definition: h261.h:38
#define H261_MV_VLC_BITS
Definition: h261dec.c:36
const uint8_t ff_h261_mba_bits[35]
Definition: h261data.c:47
int size
Definition: avcodec.h:974
enum AVCodecID codec_id
Definition: mpegvideo.h:280
int current_mv_x
Definition: h261.h:44
H261Context.
Definition: h261.h:37
void ff_print_debug_info(MpegEncContext *s, Picture *p)
Print debugging info for the given picture.
Definition: mpegvideo.c:1864
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1247
int gob_number
Definition: h261.h:46
#define TCOEFF_VLC_BITS
Definition: h261dec.c:38
#define AV_EF_BITSTREAM
Definition: avcodec.h:2399
mpegvideo header.
#define FF_ARRAY_ELEMS(a)
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:546
uint8_t permutated[64]
Definition: dsputil.h:113
#define IS_INTRA4x4(a)
Definition: mpegvideo.h:158
const int8_t * table_level
Definition: rl.h:43
uint8_t run
Definition: svq3.c:142
#define SLICE_OK
Definition: mpegvideo.h:680
int mb_num
number of MBs of a picture
Definition: mpegvideo.h:305
#define MBA_STUFFING
Definition: h261dec.c:39
AVCodec.
Definition: avcodec.h:2755
const uint8_t ff_h261_mba_code[35]
Definition: h261data.c:33
RLTable.
Definition: rl.h:38
int qscale
QP.
Definition: mpegvideo.h:392
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:226
static VLC h261_mtype_vlc
Definition: h261dec.c:43
const uint8_t ff_h261_cbp_tab[63][2]
Definition: h261data.c:94
static int h261_decode_picture_header(H261Context *h)
Decode the H.261 picture header.
Definition: h261dec.c:455
#define HAS_CBP(a)
Definition: mpegvideo.h:180
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1173
enum AVDiscard skip_frame
Definition: avcodec.h:2701
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:269
#define MB_TYPE_INTRA
Definition: mpegvideo.h:157
uint8_t
#define av_cold
Definition: attributes.h:66
#define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size)
Definition: get_bits.h:443
enum OutputFormat out_format
output format
Definition: mpegvideo.h:272
static int h261_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: h261dec.c:562
int current_mv_y
Definition: h261.h:45
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:174
Picture current_picture
copy of the current picture structure.
Definition: mpegvideo.h:366
GetBitContext last_resync_gb
used to search for the next resync marker
Definition: mpegvideo.h:546
#define IS_QUANT(a)
Definition: mpegvideo.h:177
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:711
const char data[16]
Definition: mxf.c:66
uint8_t * data
Definition: avcodec.h:973
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:194
static int h261_decode_block(H261Context *h, int16_t *block, int n, int coded)
Decode a macroblock.
Definition: h261dec.c:255
int flags2
AVCodecContext.flags2.
Definition: mpegvideo.h:284
int mb_height
number of MBs horizontally & vertically
Definition: mpegvideo.h:300
void ff_MPV_frame_end(MpegEncContext *s)
Definition: mpegvideo.c:1843
static av_cold void h261_decode_init_vlc(H261Context *h)
Definition: h261dec.c:47
static void ff_update_block_index(MpegEncContext *s)
Definition: mpegvideo.h:832
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
Definition: mpegvideo.c:2463
av_cold void ff_h261_common_init(void)
Definition: h261.c:83
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:555
enum AVCodecID id
Definition: avcodec.h:2769
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
AVCodec ff_h261_decoder
Definition: h261dec.c:655
static av_cold int h261_decode_init(AVCodecContext *avctx)
Definition: h261dec.c:69
int mb_skipped
MUST BE SET only during DECODING.
Definition: mpegvideo.h:381
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:142
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1142
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:148
int mtype
Definition: h261.h:43
const char * name
Name of the codec implementation.
Definition: avcodec.h:2762
int low_delay
no reordering needed / has no b-frames
Definition: mpegvideo.h:591
GetBitContext gb
Definition: mpegvideo.h:632
VLC vlc
decoding only deprecated FIXME remove
Definition: rl.h:47
#define INIT_VLC_RL(rl, static_size)
Definition: rl.h:59
Definition: get_bits.h:64
int n
number of entries of table_vlc minus 1
Definition: rl.h:39
void ff_mpeg_er_frame_start(MpegEncContext *s)
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:168
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:2390
static const int mvmap[17]
Definition: h261dec.c:225
void(* clear_blocks)(int16_t *blocks)
Definition: dsputil.h:143
Picture * current_picture_ptr
pointer to the current picture
Definition: mpegvideo.h:370
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:254
const int8_t * table_run
Definition: rl.h:42
int current_mba
Definition: h261.h:40
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:522
int block_last_index[12]
last non zero coefficient in block
Definition: mpegvideo.h:314
const uint8_t ff_h261_mtype_code[10]
Definition: h261data.c:62
static av_cold int h261_decode_end(AVCodecContext *avctx)
Definition: h261dec.c:646
const uint8_t ff_h261_mtype_bits[10]
Definition: h261data.c:68
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:1628
static int h261_decode_gob_header(H261Context *h)
Decode the group of blocks header or slice header.
Definition: h261dec.c:97
const uint8_t ff_h261_mv_tab[17][2]
Definition: h261data.c:88
#define MV_TYPE_16X16
1 vector for the whole mb
Definition: mpegvideo.h:441
const int ff_h261_mtype_map[10]
Definition: h261data.c:74
uint8_t * buffer
Definition: parser.h:29
Libavcodec external API header.
int mba_diff
Definition: h261.h:42
main external API structure.
Definition: avcodec.h:1054
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:489
ScanTable intra_scantable
Definition: mpegvideo.h:319
int height
picture size. must be a multiple of 16
Definition: mpegvideo.h:268
#define SLICE_END
end marker found
Definition: mpegvideo.h:682
static int h261_decode_gob(H261Context *h)
Definition: h261dec.c:519
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:271
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:296
void ff_MPV_decode_mb(MpegEncContext *s, int16_t block[12][64])
Definition: mpegvideo.c:2304
h261codec.
int coded_height
Definition: avcodec.h:1227
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:263
rational number numerator/denominator
Definition: rational.h:43
static int h261_resync(H261Context *h)
Decode the group of blocks / video packet header.
Definition: h261dec.c:151
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:375
int context_initialized
Definition: mpegvideo.h:295
#define MB_TYPE_16x16
Definition: avcodec.h:805
DSPContext dsp
pointers for accelerated dsp functions
Definition: mpegvideo.h:411
#define H261_MTYPE_VLC_BITS
Definition: h261dec.c:35
RLTable ff_h261_rl_tcoeff
Definition: h261data.c:149
static VLC h261_cbp_vlc
Definition: h261dec.c:45
#define MV_DIR_FORWARD
Definition: mpegvideo.h:437
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:399
static VLC h261_mv_vlc
Definition: h261dec.c:44
int gob_start_code_skipped
Definition: h261.h:47
uint8_t level
Definition: svq3.c:143
int mv[2][4][2]
motion vectors for a macroblock first coordinate : 0 = forward 1 = backward second " : depend...
Definition: mpegvideo.h:451
MpegEncContext.
Definition: mpegvideo.h:264
struct AVCodecContext * avctx
Definition: mpegvideo.h:266
discard all non reference
Definition: avcodec.h:543
#define MB_TYPE_H261_FIL
Definition: h261.h:50
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:65
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:301
static VLC h261_mba_vlc
Definition: h261dec.c:42
Bi-dir predicted.
Definition: avutil.h:255
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:498
static int h261_decode_mb(H261Context *h)
Definition: h261dec.c:339
void * priv_data
Definition: avcodec.h:1090
static int decode_mv_component(GetBitContext *gb, int v)
Definition: h261dec.c:229
#define MBA_STARTCODE
Definition: h261dec.c:40
void ff_MPV_common_end(MpegEncContext *s)
Definition: mpegvideo.c:1436
int16_t(* block)[64]
points to one of the following blocks
Definition: mpegvideo.h:677
ParseContext parse_context
Definition: mpegvideo.h:551
VLC_TYPE(* table)[2]
code, bits
Definition: get_bits.h:66
static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2)
Decode skipped macroblocks.
Definition: h261dec.c:192
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:163
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:416
int flags2
CODEC_FLAG2_*.
Definition: avcodec.h:1149
#define IS_16X16(a)
Definition: mpegvideo.h:168
struct AVFrame f
Definition: mpegvideo.h:100
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:1810
int flags
AVCodecContext.flags (HQ, MV4, ...)
Definition: mpegvideo.h:283
uint32_t * mb_type
Definition: mpegvideo.h:110
This structure stores compressed data.
Definition: avcodec.h:950
#define MB_TYPE_L0
Definition: avcodec.h:818
Predicted.
Definition: avutil.h:254
void ff_MPV_decode_defaults(MpegEncContext *s)
Set the given MpegEncContext to defaults for decoding.
Definition: mpegvideo.c:1019
#define check(x, y, S, v)
static int16_t block[64]
Definition: dct-test.c:170