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 "mpeg_er.h"
30 #include "mpegutils.h"
31 #include "mpegvideo.h"
32 #include "h263.h"
33 #include "h261.h"
34 #include "internal.h"
35 
36 #define H261_MBA_VLC_BITS 9
37 #define H261_MTYPE_VLC_BITS 6
38 #define H261_MV_VLC_BITS 7
39 #define H261_CBP_VLC_BITS 9
40 #define TCOEFF_VLC_BITS 9
41 #define MBA_STUFFING 33
42 #define MBA_STARTCODE 34
43 
48 
50 {
51  static int done = 0;
52 
53  if (!done) {
54  done = 1;
55  INIT_VLC_STATIC(&h261_mba_vlc, H261_MBA_VLC_BITS, 35,
56  ff_h261_mba_bits, 1, 1,
57  ff_h261_mba_code, 1, 1, 662);
58  INIT_VLC_STATIC(&h261_mtype_vlc, H261_MTYPE_VLC_BITS, 10,
59  ff_h261_mtype_bits, 1, 1,
60  ff_h261_mtype_code, 1, 1, 80);
61  INIT_VLC_STATIC(&h261_mv_vlc, H261_MV_VLC_BITS, 17,
62  &ff_h261_mv_tab[0][1], 2, 1,
63  &ff_h261_mv_tab[0][0], 2, 1, 144);
64  INIT_VLC_STATIC(&h261_cbp_vlc, H261_CBP_VLC_BITS, 63,
65  &ff_h261_cbp_tab[0][1], 2, 1,
66  &ff_h261_cbp_tab[0][0], 2, 1, 512);
68  }
69 }
70 
72 {
73  H261Context *h = avctx->priv_data;
74  MpegEncContext *const s = &h->s;
75 
76  // set defaults
78  s->avctx = avctx;
79  s->width = s->avctx->coded_width;
80  s->height = s->avctx->coded_height;
81  s->codec_id = s->avctx->codec->id;
82  s->out_format = FMT_H261;
83  s->low_delay = 1;
84  avctx->pix_fmt = AV_PIX_FMT_YUV420P;
85  s->codec_id = avctx->codec->id;
86 
89 
91 
92  return 0;
93 }
94 
100 {
101  unsigned int val;
102  MpegEncContext *const s = &h->s;
103 
104  if (!h->gob_start_code_skipped) {
105  /* Check for GOB Start Code */
106  val = show_bits(&s->gb, 15);
107  if (val)
108  return -1;
109 
110  /* We have a GBSC */
111  skip_bits(&s->gb, 16);
112  }
113 
114  h->gob_start_code_skipped = 0;
115 
116  h->gob_number = get_bits(&s->gb, 4); /* GN */
117  s->qscale = get_bits(&s->gb, 5); /* GQUANT */
118 
119  /* Check if gob_number is valid */
120  if (s->mb_height == 18) { // CIF
121  if ((h->gob_number <= 0) || (h->gob_number > 12))
122  return -1;
123  } else { // QCIF
124  if ((h->gob_number != 1) && (h->gob_number != 3) &&
125  (h->gob_number != 5))
126  return -1;
127  }
128 
129  /* GEI */
130  while (get_bits1(&s->gb) != 0)
131  skip_bits(&s->gb, 8);
132 
133  if (s->qscale == 0) {
134  av_log(s->avctx, AV_LOG_ERROR, "qscale has forbidden 0 value\n");
136  return -1;
137  }
138 
139  /* For the first transmitted macroblock in a GOB, MBA is the absolute
140  * address. For subsequent macroblocks, MBA is the difference between
141  * the absolute addresses of the macroblock and the last transmitted
142  * macroblock. */
143  h->current_mba = 0;
144  h->mba_diff = 0;
145 
146  return 0;
147 }
148 
153 static int h261_resync(H261Context *h)
154 {
155  MpegEncContext *const s = &h->s;
156  int left, ret;
157 
158  if (h->gob_start_code_skipped) {
159  ret = h261_decode_gob_header(h);
160  if (ret >= 0)
161  return 0;
162  } else {
163  if (show_bits(&s->gb, 15) == 0) {
164  ret = h261_decode_gob_header(h);
165  if (ret >= 0)
166  return 0;
167  }
168  // OK, it is not where it is supposed to be ...
169  s->gb = s->last_resync_gb;
170  align_get_bits(&s->gb);
171  left = get_bits_left(&s->gb);
172 
173  for (; left > 15 + 1 + 4 + 5; left -= 8) {
174  if (show_bits(&s->gb, 15) == 0) {
175  GetBitContext bak = s->gb;
176 
177  ret = h261_decode_gob_header(h);
178  if (ret >= 0)
179  return 0;
180 
181  s->gb = bak;
182  }
183  skip_bits(&s->gb, 8);
184  }
185  }
186 
187  return -1;
188 }
189 
194 static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2)
195 {
196  MpegEncContext *const s = &h->s;
197  int i;
198 
199  s->mb_intra = 0;
200 
201  for (i = mba1; i < mba2; i++) {
202  int j, xy;
203 
204  s->mb_x = ((h->gob_number - 1) % 2) * 11 + i % 11;
205  s->mb_y = ((h->gob_number - 1) / 2) * 3 + i / 11;
206  xy = s->mb_x + s->mb_y * s->mb_stride;
209 
210  for (j = 0; j < 6; j++)
211  s->block_last_index[j] = -1;
212 
213  s->mv_dir = MV_DIR_FORWARD;
214  s->mv_type = MV_TYPE_16X16;
216  s->mv[0][0][0] = 0;
217  s->mv[0][0][1] = 0;
218  s->mb_skipped = 1;
219  h->mtype &= ~MB_TYPE_H261_FIL;
220 
221  ff_mpv_decode_mb(s, s->block);
222  }
223 
224  return 0;
225 }
226 
227 static const int mvmap[17] = {
228  0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16
229 };
230 
231 static int decode_mv_component(GetBitContext *gb, int v)
232 {
233  int mv_diff = get_vlc2(gb, h261_mv_vlc.table, H261_MV_VLC_BITS, 2);
234 
235  /* check if mv_diff is valid */
236  if (mv_diff < 0)
237  return v;
238 
239  mv_diff = mvmap[mv_diff];
240 
241  if (mv_diff && !get_bits1(gb))
242  mv_diff = -mv_diff;
243 
244  v += mv_diff;
245  if (v <= -16)
246  v += 32;
247  else if (v >= 16)
248  v -= 32;
249 
250  return v;
251 }
252 
257 static int h261_decode_block(H261Context *h, int16_t *block, int n, int coded)
258 {
259  MpegEncContext *const s = &h->s;
260  int code, level, i, j, run;
261  RLTable *rl = &ff_h261_rl_tcoeff;
262  const uint8_t *scan_table;
263 
264  /* For the variable length encoding there are two code tables, one being
265  * used for the first transmitted LEVEL in INTER, INTER + MC and
266  * INTER + MC + FIL blocks, the second for all other LEVELs except the
267  * first one in INTRA blocks which is fixed length coded with 8 bits.
268  * NOTE: The two code tables only differ in one VLC so we handle that
269  * manually. */
270  scan_table = s->intra_scantable.permutated;
271  if (s->mb_intra) {
272  /* DC coef */
273  level = get_bits(&s->gb, 8);
274  // 0 (00000000b) and -128 (10000000b) are FORBIDDEN
275  if ((level & 0x7F) == 0) {
276  av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n",
277  level, s->mb_x, s->mb_y);
278  return -1;
279  }
280  /* The code 1000 0000 is not used, the reconstruction level of 1024
281  * being coded as 1111 1111. */
282  if (level == 255)
283  level = 128;
284  block[0] = level;
285  i = 1;
286  } else if (coded) {
287  // Run Level Code
288  // EOB Not possible for first level when cbp is available (that's why the table is different)
289  // 0 1 1s
290  // * * 0*
291  int check = show_bits(&s->gb, 2);
292  i = 0;
293  if (check & 0x2) {
294  skip_bits(&s->gb, 2);
295  block[0] = (check & 0x1) ? -1 : 1;
296  i = 1;
297  }
298  } else {
299  i = 0;
300  }
301  if (!coded) {
302  s->block_last_index[n] = i - 1;
303  return 0;
304  }
305  for (;;) {
306  code = get_vlc2(&s->gb, rl->vlc.table, TCOEFF_VLC_BITS, 2);
307  if (code < 0) {
308  av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n",
309  s->mb_x, s->mb_y);
310  return -1;
311  }
312  if (code == rl->n) {
313  /* escape */
314  /* The remaining combinations of (run, level) are encoded with a
315  * 20-bit word consisting of 6 bits escape, 6 bits run and 8 bits
316  * level. */
317  run = get_bits(&s->gb, 6);
318  level = get_sbits(&s->gb, 8);
319  } else if (code == 0) {
320  break;
321  } else {
322  run = rl->table_run[code];
323  level = rl->table_level[code];
324  if (get_bits1(&s->gb))
325  level = -level;
326  }
327  i += run;
328  if (i >= 64) {
329  av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d\n",
330  s->mb_x, s->mb_y);
331  return -1;
332  }
333  j = scan_table[i];
334  block[j] = level;
335  i++;
336  }
337  s->block_last_index[n] = i - 1;
338  return 0;
339 }
340 
342 {
343  MpegEncContext *const s = &h->s;
344  int i, cbp, xy;
345 
346  cbp = 63;
347  // Read mba
348  do {
349  h->mba_diff = get_vlc2(&s->gb, h261_mba_vlc.table,
350  H261_MBA_VLC_BITS, 2);
351 
352  /* Check for slice end */
353  /* NOTE: GOB can be empty (no MB data) or exist only of MBA_stuffing */
354  if (h->mba_diff == MBA_STARTCODE) { // start code
355  h->gob_start_code_skipped = 1;
356  return SLICE_END;
357  }
358  } while (h->mba_diff == MBA_STUFFING); // stuffing
359 
360  if (h->mba_diff < 0) {
361  if (get_bits_left(&s->gb) <= 7)
362  return SLICE_END;
363 
364  av_log(s->avctx, AV_LOG_ERROR, "illegal mba at %d %d\n", s->mb_x, s->mb_y);
365  return SLICE_ERROR;
366  }
367 
368  h->mba_diff += 1;
369  h->current_mba += h->mba_diff;
370 
371  if (h->current_mba > MBA_STUFFING)
372  return SLICE_ERROR;
373 
374  s->mb_x = ((h->gob_number - 1) % 2) * 11 + ((h->current_mba - 1) % 11);
375  s->mb_y = ((h->gob_number - 1) / 2) * 3 + ((h->current_mba - 1) / 11);
376  xy = s->mb_x + s->mb_y * s->mb_stride;
379 
380  // Read mtype
381  h->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2);
382  if (h->mtype < 0 || h->mtype >= FF_ARRAY_ELEMS(ff_h261_mtype_map)) {
383  av_log(s->avctx, AV_LOG_ERROR, "Invalid mtype index %d\n",
384  h->mtype);
385  return SLICE_ERROR;
386  }
387  h->mtype = ff_h261_mtype_map[h->mtype];
388 
389  // Read mquant
390  if (IS_QUANT(h->mtype))
391  ff_set_qscale(s, get_bits(&s->gb, 5));
392 
393  s->mb_intra = IS_INTRA4x4(h->mtype);
394 
395  // Read mv
396  if (IS_16X16(h->mtype)) {
397  /* Motion vector data is included for all MC macroblocks. MVD is
398  * obtained from the macroblock vector by subtracting the vector
399  * of the preceding macroblock. For this calculation the vector
400  * of the preceding macroblock is regarded as zero in the
401  * following three situations:
402  * 1) evaluating MVD for macroblocks 1, 12 and 23;
403  * 2) evaluating MVD for macroblocks in which MBA does not represent a difference of 1;
404  * 3) MTYPE of the previous macroblock was not MC. */
405  if ((h->current_mba == 1) || (h->current_mba == 12) ||
406  (h->current_mba == 23) || (h->mba_diff != 1)) {
407  h->current_mv_x = 0;
408  h->current_mv_y = 0;
409  }
410 
413  } else {
414  h->current_mv_x = 0;
415  h->current_mv_y = 0;
416  }
417 
418  // Read cbp
419  if (HAS_CBP(h->mtype))
420  cbp = get_vlc2(&s->gb, h261_cbp_vlc.table, H261_CBP_VLC_BITS, 2) + 1;
421 
422  if (s->mb_intra) {
424  goto intra;
425  }
426 
427  //set motion vectors
428  s->mv_dir = MV_DIR_FORWARD;
429  s->mv_type = MV_TYPE_16X16;
431  s->mv[0][0][0] = h->current_mv_x * 2; // gets divided by 2 in motion compensation
432  s->mv[0][0][1] = h->current_mv_y * 2;
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_decode_mb(s, s->block);
449 
450  return SLICE_OK;
451 }
452 
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->time_base = (AVRational) { 1001, 30000 };
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  while (get_bits1(&s->gb) != 0)
510  skip_bits(&s->gb, 8);
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). */
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) {
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 
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  av_dlog(avctx, "*****frame %d size=%d\n", avctx->frame_number, buf_size);
575  av_dlog(avctx, "bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);
576  s->flags = avctx->flags;
577  s->flags2 = avctx->flags2;
578 
579  h->gob_start_code_skipped = 0;
580 
581 retry:
582  init_get_bits(&s->gb, buf, buf_size * 8);
583 
584  if (!s->context_initialized)
585  // we need the IDCT permutaton for reading a custom matrix
586  ff_mpv_idct_init(s);
587 
589 
590  /* skip if the header was thrashed */
591  if (ret < 0) {
592  av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
593  return -1;
594  }
595 
596  if (s->width != avctx->coded_width || s->height != avctx->coded_height) {
597  ParseContext pc = s->parse_context; // FIXME move this demuxing hack to libavformat
598  s->parse_context.buffer = 0;
600  s->parse_context = pc;
601  }
602 
603  if (!s->context_initialized) {
604  if ((ret = ff_mpv_common_init(s)) < 0)
605  return ret;
606 
607  ret = ff_set_dimensions(avctx, s->width, s->height);
608  if (ret < 0)
609  return ret;
610 
611  goto retry;
612  }
613 
614  // for skipping the frame
617 
618  if ((avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) ||
620  avctx->skip_frame >= AVDISCARD_ALL)
621  return get_consumed_bytes(s, buf_size);
622 
623  if (ff_mpv_frame_start(s, avctx) < 0)
624  return -1;
625 
627 
628  /* decode each macroblock */
629  s->mb_x = 0;
630  s->mb_y = 0;
631 
632  while (h->gob_number < (s->mb_height == 18 ? 12 : 5)) {
633  if (h261_resync(h) < 0)
634  break;
635  h261_decode_gob(h);
636  }
637  ff_mpv_frame_end(s);
638 
640  assert(s->current_picture.f->pict_type == s->pict_type);
641 
642  if ((ret = av_frame_ref(pict, s->current_picture_ptr->f)) < 0)
643  return ret;
645 
646  *got_frame = 1;
647 
648  return get_consumed_bytes(s, buf_size);
649 }
650 
652 {
653  H261Context *h = avctx->priv_data;
654  MpegEncContext *s = &h->s;
655 
657  return 0;
658 }
659 
661  .name = "h261",
662  .long_name = NULL_IF_CONFIG_SMALL("H.261"),
663  .type = AVMEDIA_TYPE_VIDEO,
664  .id = AV_CODEC_ID_H261,
665  .priv_data_size = sizeof(H261Context),
669  .capabilities = CODEC_CAP_DR1,
670 };
#define SLICE_ERROR
Definition: mpegvideo.h:604
const struct AVCodec * codec
Definition: avcodec.h:1059
#define MB_TYPE_SKIP
Definition: avcodec.h:786
discard all frames except keyframes
Definition: avcodec.h:567
void ff_init_block_index(MpegEncContext *s)
Definition: mpegvideo.c:2368
int picture_number
Definition: mpegvideo.h:253
#define H261_CBP_VLC_BITS
Definition: h261dec.c:39
This structure describes decoded (raw) audio or video data.
Definition: frame.h:135
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
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:1234
#define H261_MBA_VLC_BITS
Definition: h261dec.c:36
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:133
MpegEncContext s
Definition: h261.h:38
#define H261_MV_VLC_BITS
Definition: h261dec.c:38
const uint8_t ff_h261_mba_bits[35]
Definition: h261data.c:48
int size
Definition: avcodec.h:974
enum AVCodecID codec_id
Definition: mpegvideo.h:235
void(* clear_blocks)(int16_t *blocks)
Definition: blockdsp.h:36
int current_mv_x
Definition: h261.h:44
H261Context.
Definition: h261.h:37
#define MB_TYPE_INTRA
Definition: mpegutils.h:69
void ff_print_debug_info(MpegEncContext *s, Picture *p)
Print debugging info for the given picture.
Definition: mpegvideo.c:1910
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1254
int gob_number
Definition: h261.h:46
#define TCOEFF_VLC_BITS
Definition: h261dec.c:40
#define AV_EF_BITSTREAM
Definition: avcodec.h:2415
mpegvideo header.
#define HAS_CBP(a)
Definition: mpegutils.h:97
#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:568
uint8_t permutated[64]
Definition: idctdsp.h:31
const int8_t * table_level
Definition: rl.h:43
uint8_t run
Definition: svq3.c:146
#define SLICE_OK
Definition: mpegvideo.h:603
int mb_num
number of MBs of a picture
Definition: mpegvideo.h:259
#define MBA_STUFFING
Definition: h261dec.c:41
AVCodec.
Definition: avcodec.h:2796
const uint8_t ff_h261_mba_code[35]
Definition: h261data.c:34
RLTable.
Definition: rl.h:38
int qscale
QP.
Definition: mpegvideo.h:332
static int get_sbits(GetBitContext *s, int n)
Definition: get_bits.h:226
static VLC h261_mtype_vlc
Definition: h261dec.c:45
const uint8_t ff_h261_cbp_tab[63][2]
Definition: h261data.c:95
static int h261_decode_picture_header(H261Context *h)
Decode the H.261 picture header.
Definition: h261dec.c:457
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1175
enum AVDiscard skip_frame
Definition: avcodec.h:2727
static int decode(MimicContext *ctx, int quality, int num_coeffs, int is_iframe)
Definition: mimic.c:275
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:227
static int h261_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: h261dec.c:564
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:188
void ff_mpv_decode_mb(MpegEncContext *s, int16_t block[12][64])
Definition: mpegvideo.c:2351
Picture current_picture
copy of the current picture structure.
Definition: mpegvideo.h:306
GetBitContext last_resync_gb
used to search for the next resync marker
Definition: mpegvideo.h:474
#define CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:684
const char data[16]
Definition: mxf.c:70
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:257
int flags2
AVCodecContext.flags2.
Definition: mpegvideo.h:239
av_cold void ff_mpv_idct_init(MpegEncContext *s)
Definition: mpegvideo.c:408
int mb_height
number of MBs horizontally & vertically
Definition: mpegvideo.h:255
static av_cold void h261_decode_init_vlc(H261Context *h)
Definition: h261dec.c:49
static void ff_update_block_index(MpegEncContext *s)
Definition: mpegvideo.h:756
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
Definition: mpegvideo.c:2459
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:2810
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:123
AVCodec ff_h261_decoder
Definition: h261dec.c:660
static av_cold int h261_decode_init(AVCodecContext *avctx)
Definition: h261dec.c:71
int mb_skipped
MUST BE SET only during DECODING.
Definition: mpegvideo.h:321
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:150
int flags
CODEC_FLAG_*.
Definition: avcodec.h:1144
void av_log(void *avcl, int level, const char *fmt,...)
Definition: log.c:169
int mtype
Definition: h261.h:43
const char * name
Name of the codec implementation.
Definition: avcodec.h:2803
int low_delay
no reordering needed / has no b-frames
Definition: mpegvideo.h:519
GetBitContext gb
Definition: mpegvideo.h:558
VLC vlc
decoding only deprecated FIXME remove
Definition: rl.h:47
void ff_mpv_common_end(MpegEncContext *s)
Definition: mpegvideo.c:1478
#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
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:196
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:2406
static const int mvmap[17]
Definition: h261dec.c:227
Picture * current_picture_ptr
pointer to the current picture
Definition: mpegvideo.h:310
void ff_mpeg_er_frame_start(MpegEncContext *s)
Definition: mpeg_er.c:45
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:209
const uint8_t ff_h261_mtype_code[10]
Definition: h261data.c:63
static av_cold int h261_decode_end(AVCodecContext *avctx)
Definition: h261dec.c:651
const uint8_t ff_h261_mtype_bits[10]
Definition: h261data.c:69
static int h261_decode_gob_header(H261Context *h)
Decode the group of blocks header or slice header.
Definition: h261dec.c:99
void ff_mpv_decode_defaults(MpegEncContext *s)
Set the given MpegEncContext to defaults for decoding.
Definition: mpegvideo.c:1050
const uint8_t ff_h261_mv_tab[17][2]
Definition: h261data.c:89
#define MV_TYPE_16X16
1 vector for the whole mb
Definition: mpegvideo.h:388
const int ff_h261_mtype_map[10]
Definition: h261data.c:75
uint8_t * buffer
Definition: parser.h:29
Libavcodec external API header.
BlockDSPContext bdsp
Definition: mpegvideo.h:351
int mba_diff
Definition: h261.h:42
main external API structure.
Definition: avcodec.h:1050
static void close(AVCodecParserContext *s)
Definition: h264_parser.c:490
ScanTable intra_scantable
Definition: mpegvideo.h:214
int height
picture size. must be a multiple of 16
Definition: mpegvideo.h:223
#define IS_QUANT(a)
Definition: mpegutils.h:91
#define SLICE_END
end marker found
Definition: mpegvideo.h:605
static int h261_decode_gob(H261Context *h)
Definition: h261dec.c:521
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:271
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:296
h261codec.
int coded_height
Definition: avcodec.h:1234
#define IS_16X16(a)
Definition: mpegutils.h:82
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:263
rational number numerator/denominator
Definition: rational.h:43
struct AVFrame * f
Definition: mpegvideo.h:100
static int h261_resync(H261Context *h)
Decode the group of blocks / video packet header.
Definition: h261dec.c:153
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:250
#define MB_TYPE_16x16
Definition: avcodec.h:778
#define H261_MTYPE_VLC_BITS
Definition: h261dec.c:37
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:1677
RLTable ff_h261_rl_tcoeff
Definition: h261data.c:150
static VLC h261_cbp_vlc
Definition: h261dec.c:47
#define MV_DIR_FORWARD
Definition: mpegvideo.h:384
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:339
static VLC h261_mv_vlc
Definition: h261dec.c:46
int gob_start_code_skipped
Definition: h261.h:47
uint8_t level
Definition: svq3.c:147
int mv[2][4][2]
motion vectors for a macroblock first coordinate : 0 = forward 1 = backward second " : depend...
Definition: mpegvideo.h:398
MpegEncContext.
Definition: mpegvideo.h:204
struct AVCodecContext * avctx
Definition: mpegvideo.h:221
discard all non reference
Definition: avcodec.h:565
#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:256
static VLC h261_mba_vlc
Definition: h261dec.c:44
Bi-dir predicted.
Definition: avutil.h:255
static av_cold int init(AVCodecParserContext *s)
Definition: h264_parser.c:499
static int h261_decode_mb(H261Context *h)
Definition: h261dec.c:341
void * priv_data
Definition: avcodec.h:1092
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
Definition: mpegvideo.c:1235
#define IS_INTRA4x4(a)
Definition: mpegutils.h:71
static int decode_mv_component(GetBitContext *gb, int v)
Definition: h261dec.c:231
#define MBA_STARTCODE
Definition: h261dec.c:42
void ff_mpv_frame_end(MpegEncContext *s)
Definition: mpegvideo.c:1889
int16_t(* block)[64]
points to one of the following blocks
Definition: mpegvideo.h:600
ParseContext parse_context
Definition: mpegvideo.h:479
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:194
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:191
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:416
int flags2
CODEC_FLAG2_*.
Definition: avcodec.h:1151
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:1822
int flags
AVCodecContext.flags (HQ, MV4, ...)
Definition: mpegvideo.h:238
uint32_t * mb_type
types and macros are defined in mpegutils.h
Definition: mpegvideo.h:110
This structure stores compressed data.
Definition: avcodec.h:950
#define MB_TYPE_L0
Definition: avcodec.h:791
Predicted.
Definition: avutil.h:254
#define check(x, y, S, v)
static int16_t block[64]
Definition: dct-test.c:88