FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "avcodec.h"
30 #include "mpeg_er.h"
31 #include "mpegutils.h"
32 #include "mpegvideo.h"
33 #include "h263.h"
34 #include "h261.h"
35 #include "internal.h"
36 
37 #define H261_MBA_VLC_BITS 9
38 #define H261_MTYPE_VLC_BITS 6
39 #define H261_MV_VLC_BITS 7
40 #define H261_CBP_VLC_BITS 9
41 #define TCOEFF_VLC_BITS 9
42 #define MBA_STUFFING 33
43 #define MBA_STARTCODE 34
44 
49 
51 {
52  static int done = 0;
53 
54  if (!done) {
55  done = 1;
56  INIT_VLC_STATIC(&h261_mba_vlc, H261_MBA_VLC_BITS, 35,
57  ff_h261_mba_bits, 1, 1,
58  ff_h261_mba_code, 1, 1, 662);
59  INIT_VLC_STATIC(&h261_mtype_vlc, H261_MTYPE_VLC_BITS, 10,
60  ff_h261_mtype_bits, 1, 1,
61  ff_h261_mtype_code, 1, 1, 80);
62  INIT_VLC_STATIC(&h261_mv_vlc, H261_MV_VLC_BITS, 17,
63  &ff_h261_mv_tab[0][1], 2, 1,
64  &ff_h261_mv_tab[0][0], 2, 1, 144);
65  INIT_VLC_STATIC(&h261_cbp_vlc, H261_CBP_VLC_BITS, 63,
66  &ff_h261_cbp_tab[0][1], 2, 1,
67  &ff_h261_cbp_tab[0][0], 2, 1, 512);
69  }
70 }
71 
73 {
74  H261Context *h = avctx->priv_data;
75  MpegEncContext *const s = &h->s;
76 
77  // set defaults
79  ff_mpv_decode_init(s, avctx);
80 
81  s->out_format = FMT_H261;
82  s->low_delay = 1;
83  avctx->pix_fmt = AV_PIX_FMT_YUV420P;
84 
87 
89 
90  return 0;
91 }
92 
93 /**
94  * Decode the group of blocks header or slice header.
95  * @return <0 if an error occurred
96  */
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  if (skip_1stop_8data_bits(&s->gb) < 0)
129  return AVERROR_INVALIDDATA;
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 
147 /**
148  * Decode the group of blocks / video packet header.
149  * @return <0 if no resync found
150  */
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 
188 /**
189  * Decode skipped macroblocks.
190  * @return 0
191  */
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  if (s->current_picture.motion_val[0]) {
220  int b_stride = 2*s->mb_width + 1;
221  int b_xy = 2 * s->mb_x + (2 * s->mb_y) * b_stride;
222  s->current_picture.motion_val[0][b_xy][0] = s->mv[0][0][0];
223  s->current_picture.motion_val[0][b_xy][1] = s->mv[0][0][1];
224  }
225 
227  }
228 
229  return 0;
230 }
231 
232 static const int mvmap[17] = {
233  0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15, -16
234 };
235 
236 static int decode_mv_component(GetBitContext *gb, int v)
237 {
238  int mv_diff = get_vlc2(gb, h261_mv_vlc.table, H261_MV_VLC_BITS, 2);
239 
240  /* check if mv_diff is valid */
241  if (mv_diff < 0)
242  return v;
243 
244  mv_diff = mvmap[mv_diff];
245 
246  if (mv_diff && !get_bits1(gb))
247  mv_diff = -mv_diff;
248 
249  v += mv_diff;
250  if (v <= -16)
251  v += 32;
252  else if (v >= 16)
253  v -= 32;
254 
255  return v;
256 }
257 
258 /**
259  * Decode a macroblock.
260  * @return <0 if an error occurred
261  */
262 static int h261_decode_block(H261Context *h, int16_t *block, int n, int coded)
263 {
264  MpegEncContext *const s = &h->s;
265  int level, i, j, run;
266  RLTable *rl = &ff_h261_rl_tcoeff;
267  const uint8_t *scan_table;
268 
269  /* For the variable length encoding there are two code tables, one being
270  * used for the first transmitted LEVEL in INTER, INTER + MC and
271  * INTER + MC + FIL blocks, the second for all other LEVELs except the
272  * first one in INTRA blocks which is fixed length coded with 8 bits.
273  * NOTE: The two code tables only differ in one VLC so we handle that
274  * manually. */
275  scan_table = s->intra_scantable.permutated;
276  if (s->mb_intra) {
277  /* DC coef */
278  level = get_bits(&s->gb, 8);
279  // 0 (00000000b) and -128 (10000000b) are FORBIDDEN
280  if ((level & 0x7F) == 0) {
281  av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n",
282  level, s->mb_x, s->mb_y);
283  return -1;
284  }
285  /* The code 1000 0000 is not used, the reconstruction level of 1024
286  * being coded as 1111 1111. */
287  if (level == 255)
288  level = 128;
289  block[0] = level;
290  i = 1;
291  } else if (coded) {
292  // Run Level Code
293  // EOB Not possible for first level when cbp is available (that's why the table is different)
294  // 0 1 1s
295  // * * 0*
296  int check = show_bits(&s->gb, 2);
297  i = 0;
298  if (check & 0x2) {
299  skip_bits(&s->gb, 2);
300  block[0] = (check & 0x1) ? -1 : 1;
301  i = 1;
302  }
303  } else {
304  i = 0;
305  }
306  if (!coded) {
307  s->block_last_index[n] = i - 1;
308  return 0;
309  }
310  {
311  OPEN_READER(re, &s->gb);
312  i--; // offset by -1 to allow direct indexing of scan_table
313  for (;;) {
314  UPDATE_CACHE(re, &s->gb);
315  GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TCOEFF_VLC_BITS, 2, 0);
316  if (run == 66) {
317  if (level) {
318  CLOSE_READER(re, &s->gb);
319  av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n",
320  s->mb_x, s->mb_y);
321  return -1;
322  }
323  /* escape */
324  /* The remaining combinations of (run, level) are encoded with a
325  * 20-bit word consisting of 6 bits escape, 6 bits run and 8 bits
326  * level. */
327  run = SHOW_UBITS(re, &s->gb, 6) + 1;
328  SKIP_CACHE(re, &s->gb, 6);
329  level = SHOW_SBITS(re, &s->gb, 8);
330  SKIP_COUNTER(re, &s->gb, 6 + 8);
331  } else if (level == 0) {
332  break;
333  } else {
334  if (SHOW_UBITS(re, &s->gb, 1))
335  level = -level;
336  SKIP_COUNTER(re, &s->gb, 1);
337  }
338  i += run;
339  if (i >= 64) {
340  CLOSE_READER(re, &s->gb);
341  av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d\n",
342  s->mb_x, s->mb_y);
343  return -1;
344  }
345  j = scan_table[i];
346  block[j] = level;
347  }
348  CLOSE_READER(re, &s->gb);
349  }
350  s->block_last_index[n] = i;
351  return 0;
352 }
353 
355 {
356  MpegEncContext *const s = &h->s;
357  int i, cbp, xy;
358 
359  cbp = 63;
360  // Read mba
361  do {
362  h->mba_diff = get_vlc2(&s->gb, h261_mba_vlc.table,
363  H261_MBA_VLC_BITS, 2);
364 
365  /* Check for slice end */
366  /* NOTE: GOB can be empty (no MB data) or exist only of MBA_stuffing */
367  if (h->mba_diff == MBA_STARTCODE) { // start code
368  h->gob_start_code_skipped = 1;
369  return SLICE_END;
370  }
371  } while (h->mba_diff == MBA_STUFFING); // stuffing
372 
373  if (h->mba_diff < 0) {
374  if (get_bits_left(&s->gb) <= 7)
375  return SLICE_END;
376 
377  av_log(s->avctx, AV_LOG_ERROR, "illegal mba at %d %d\n", s->mb_x, s->mb_y);
378  return SLICE_ERROR;
379  }
380 
381  h->mba_diff += 1;
382  h->current_mba += h->mba_diff;
383 
384  if (h->current_mba > MBA_STUFFING)
385  return SLICE_ERROR;
386 
387  s->mb_x = ((h->gob_number - 1) % 2) * 11 + ((h->current_mba - 1) % 11);
388  s->mb_y = ((h->gob_number - 1) / 2) * 3 + ((h->current_mba - 1) / 11);
389  xy = s->mb_x + s->mb_y * s->mb_stride;
392 
393  // Read mtype
394  h->mtype = get_vlc2(&s->gb, h261_mtype_vlc.table, H261_MTYPE_VLC_BITS, 2);
395  if (h->mtype < 0) {
396  av_log(s->avctx, AV_LOG_ERROR, "Invalid mtype index %d\n",
397  h->mtype);
398  return SLICE_ERROR;
399  }
401  h->mtype = ff_h261_mtype_map[h->mtype];
402 
403  // Read mquant
404  if (IS_QUANT(h->mtype))
405  ff_set_qscale(s, get_bits(&s->gb, 5));
406 
407  s->mb_intra = IS_INTRA4x4(h->mtype);
408 
409  // Read mv
410  if (IS_16X16(h->mtype)) {
411  /* Motion vector data is included for all MC macroblocks. MVD is
412  * obtained from the macroblock vector by subtracting the vector
413  * of the preceding macroblock. For this calculation the vector
414  * of the preceding macroblock is regarded as zero in the
415  * following three situations:
416  * 1) evaluating MVD for macroblocks 1, 12 and 23;
417  * 2) evaluating MVD for macroblocks in which MBA does not represent a difference of 1;
418  * 3) MTYPE of the previous macroblock was not MC. */
419  if ((h->current_mba == 1) || (h->current_mba == 12) ||
420  (h->current_mba == 23) || (h->mba_diff != 1)) {
421  h->current_mv_x = 0;
422  h->current_mv_y = 0;
423  }
424 
427  } else {
428  h->current_mv_x = 0;
429  h->current_mv_y = 0;
430  }
431 
432  // Read cbp
433  if (HAS_CBP(h->mtype))
434  cbp = get_vlc2(&s->gb, h261_cbp_vlc.table, H261_CBP_VLC_BITS, 2) + 1;
435 
436  if (s->mb_intra) {
438  goto intra;
439  }
440 
441  //set motion vectors
442  s->mv_dir = MV_DIR_FORWARD;
443  s->mv_type = MV_TYPE_16X16;
445  s->mv[0][0][0] = h->current_mv_x * 2; // gets divided by 2 in motion compensation
446  s->mv[0][0][1] = h->current_mv_y * 2;
447 
448  if (s->current_picture.motion_val[0]) {
449  int b_stride = 2*s->mb_width + 1;
450  int b_xy = 2 * s->mb_x + (2 * s->mb_y) * b_stride;
451  s->current_picture.motion_val[0][b_xy][0] = s->mv[0][0][0];
452  s->current_picture.motion_val[0][b_xy][1] = s->mv[0][0][1];
453  }
454 
455 intra:
456  /* decode each block */
457  if (s->mb_intra || HAS_CBP(h->mtype)) {
458  s->bdsp.clear_blocks(s->block[0]);
459  for (i = 0; i < 6; i++) {
460  if (h261_decode_block(h, s->block[i], i, cbp & 32) < 0)
461  return SLICE_ERROR;
462  cbp += cbp;
463  }
464  } else {
465  for (i = 0; i < 6; i++)
466  s->block_last_index[i] = -1;
467  }
468 
470 
471  return SLICE_OK;
472 }
473 
474 /**
475  * Decode the H.261 picture header.
476  * @return <0 if no startcode found
477  */
479 {
480  MpegEncContext *const s = &h->s;
481  int format, i;
482  uint32_t startcode = 0;
483 
484  for (i = get_bits_left(&s->gb); i > 24; i -= 1) {
485  startcode = ((startcode << 1) | get_bits(&s->gb, 1)) & 0x000FFFFF;
486 
487  if (startcode == 0x10)
488  break;
489  }
490 
491  if (startcode != 0x10) {
492  av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
493  return -1;
494  }
495 
496  /* temporal reference */
497  i = get_bits(&s->gb, 5); /* picture timestamp */
498  if (i < (s->picture_number & 31))
499  i += 32;
500  s->picture_number = (s->picture_number & ~31) + i;
501 
502  s->avctx->framerate = (AVRational) { 30000, 1001 };
503 
504  /* PTYPE starts here */
505  skip_bits1(&s->gb); /* split screen off */
506  skip_bits1(&s->gb); /* camera off */
507  skip_bits1(&s->gb); /* freeze picture release off */
508 
509  format = get_bits1(&s->gb);
510 
511  // only 2 formats possible
512  if (format == 0) { // QCIF
513  s->width = 176;
514  s->height = 144;
515  s->mb_width = 11;
516  s->mb_height = 9;
517  } else { // CIF
518  s->width = 352;
519  s->height = 288;
520  s->mb_width = 22;
521  s->mb_height = 18;
522  }
523 
524  s->mb_num = s->mb_width * s->mb_height;
525 
526  skip_bits1(&s->gb); /* still image mode off */
527  skip_bits1(&s->gb); /* Reserved */
528 
529  /* PEI */
530  if (skip_1stop_8data_bits(&s->gb) < 0)
531  return AVERROR_INVALIDDATA;
532 
533  /* H.261 has no I-frames, but if we pass AV_PICTURE_TYPE_I for the first
534  * frame, the codec crashes if it does not contain all I-blocks
535  * (e.g. when a packet is lost). */
537 
538  h->gob_number = 0;
539  return 0;
540 }
541 
543 {
544  MpegEncContext *const s = &h->s;
545 
546  ff_set_qscale(s, s->qscale);
547 
548  /* decode mb's */
549  while (h->current_mba <= MBA_STUFFING) {
550  int ret;
551  /* DCT & quantize */
552  ret = h261_decode_mb(h);
553  if (ret < 0) {
554  if (ret == SLICE_END) {
556  return 0;
557  }
558  av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n",
559  s->mb_x + s->mb_y * s->mb_stride);
560  return -1;
561  }
562 
564  h->current_mba - h->mba_diff,
565  h->current_mba - 1);
566  }
567 
568  return -1;
569 }
570 
571 /**
572  * returns the number of bytes consumed for building the current frame
573  */
574 static int get_consumed_bytes(MpegEncContext *s, int buf_size)
575 {
576  int pos = get_bits_count(&s->gb) >> 3;
577  if (pos == 0)
578  pos = 1; // avoid infinite loops (i doubt that is needed but ...)
579  if (pos + 10 > buf_size)
580  pos = buf_size; // oops ;)
581 
582  return pos;
583 }
584 
585 static int h261_decode_frame(AVCodecContext *avctx, void *data,
586  int *got_frame, AVPacket *avpkt)
587 {
588  const uint8_t *buf = avpkt->data;
589  int buf_size = avpkt->size;
590  H261Context *h = avctx->priv_data;
591  MpegEncContext *s = &h->s;
592  int ret;
593  AVFrame *pict = data;
594 
595  ff_dlog(avctx, "*****frame %d size=%d\n", avctx->frame_number, buf_size);
596  ff_dlog(avctx, "bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);
597 
598  h->gob_start_code_skipped = 0;
599 
600 retry:
601  init_get_bits(&s->gb, buf, buf_size * 8);
602 
603  if (!s->context_initialized)
604  // we need the IDCT permutation for reading a custom matrix
605  ff_mpv_idct_init(s);
606 
608 
609  /* skip if the header was thrashed */
610  if (ret < 0) {
611  av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
612  return -1;
613  }
614 
615  if (s->width != avctx->coded_width || s->height != avctx->coded_height) {
616  ParseContext pc = s->parse_context; // FIXME move this demuxing hack to libavformat
617  s->parse_context.buffer = 0;
619  s->parse_context = pc;
620  }
621 
622  if (!s->context_initialized) {
623  if ((ret = ff_mpv_common_init(s)) < 0)
624  return ret;
625 
626  ret = ff_set_dimensions(avctx, s->width, s->height);
627  if (ret < 0)
628  return ret;
629 
630  goto retry;
631  }
632 
633  // for skipping the frame
636 
637  if ((avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) ||
639  avctx->skip_frame >= AVDISCARD_ALL)
640  return get_consumed_bytes(s, buf_size);
641 
642  if (ff_mpv_frame_start(s, avctx) < 0)
643  return -1;
644 
646 
647  /* decode each macroblock */
648  s->mb_x = 0;
649  s->mb_y = 0;
650 
651  while (h->gob_number < (s->mb_height == 18 ? 12 : 5)) {
652  if (h261_resync(h) < 0)
653  break;
654  h261_decode_gob(h);
655  }
656  ff_mpv_frame_end(s);
657 
660 
661  if ((ret = av_frame_ref(pict, s->current_picture_ptr->f)) < 0)
662  return ret;
664 
665  *got_frame = 1;
666 
667  return get_consumed_bytes(s, buf_size);
668 }
669 
671 {
672  H261Context *h = avctx->priv_data;
673  MpegEncContext *s = &h->s;
674 
676  return 0;
677 }
678 
680  .name = "h261",
681  .long_name = NULL_IF_CONFIG_SMALL("H.261"),
682  .type = AVMEDIA_TYPE_VIDEO,
683  .id = AV_CODEC_ID_H261,
684  .priv_data_size = sizeof(H261Context),
686  .close = h261_decode_end,
688  .capabilities = AV_CODEC_CAP_DR1,
689  .max_lowres = 3,
690 };
#define SLICE_ERROR
Definition: mpegvideo.h:502
AVRational framerate
Definition: avcodec.h:3460
#define MB_TYPE_SKIP
Definition: avcodec.h:1307
const char const char void * val
Definition: avisynth_c.h:771
discard all frames except keyframes
Definition: avcodec.h:829
void ff_init_block_index(MpegEncContext *s)
Definition: mpegvideo.c:2739
int picture_number
Definition: mpegvideo.h:124
const char * s
Definition: avisynth_c.h:768
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define H261_CBP_VLC_BITS
Definition: h261dec.c:40
This structure describes decoded (raw) audio or video data.
Definition: frame.h:201
static int get_consumed_bytes(MpegEncContext *s, int buf_size)
returns the number of bytes consumed for building the current frame
Definition: h261dec.c:574
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:1963
#define H261_MBA_VLC_BITS
Definition: h261dec.c:37
float re
Definition: fft.c:82
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:261
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:211
MpegEncContext s
Definition: h261.h:38
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
#define H261_MV_VLC_BITS
Definition: h261dec.c:39
#define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size)
Definition: vlc.h:75
#define SKIP_COUNTER(name, gb, num)
Definition: get_bits.h:167
const uint8_t ff_h261_mba_bits[35]
Definition: h261data.c:48
int size
Definition: avcodec.h:1680
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
Definition: avcodec.h:3065
void(* clear_blocks)(int16_t *blocks)
Definition: blockdsp.h:37
int current_mv_x
Definition: h261.h:43
H261Context.
Definition: h261.h:37
#define MB_TYPE_INTRA
Definition: mpegutils.h:75
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1989
int gob_number
Definition: h261.h:45
#define TCOEFF_VLC_BITS
Definition: h261dec.c:41
#define AV_EF_BITSTREAM
detect bitstream specification deviations
Definition: avcodec.h:3059
mpegvideo header.
#define HAS_CBP(a)
Definition: mpegutils.h:103
discard all
Definition: avcodec.h:830
uint8_t permutated[64]
Definition: idctdsp.h:33
uint8_t run
Definition: svq3.c:206
#define SLICE_OK
Definition: mpegvideo.h:501
int mb_num
number of MBs of a picture
Definition: mpegvideo.h:130
#define MBA_STUFFING
Definition: h261dec.c:42
AVCodec.
Definition: avcodec.h:3739
const uint8_t ff_h261_mba_code[35]
Definition: h261data.c:34
RLTable.
Definition: rl.h:39
int qscale
QP.
Definition: mpegvideo.h:201
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
Definition: decode_audio.c:42
static VLC h261_mtype_vlc
Definition: h261dec.c:46
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:478
enum AVDiscard skip_frame
Skip decoding for selected frames.
Definition: avcodec.h:3386
static int16_t block[64]
Definition: dct.c:115
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
uint8_t
#define av_cold
Definition: attributes.h:82
enum OutputFormat out_format
output format
Definition: mpegvideo.h:101
static int h261_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
Definition: h261dec.c:585
int current_mv_y
Definition: h261.h:44
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:395
Picture current_picture
copy of the current picture structure.
Definition: mpegvideo.h:177
GetBitContext last_resync_gb
used to search for the next resync marker
Definition: mpegvideo.h:358
uint8_t * data
Definition: avcodec.h:1679
static int get_bits_count(const GetBitContext *s)
Definition: get_bits.h:199
static int h261_decode_block(H261Context *h, int16_t *block, int n, int coded)
Decode a macroblock.
Definition: h261dec.c:262
#define ff_dlog(a,...)
av_cold void ff_mpv_idct_init(MpegEncContext *s)
Definition: mpegvideo.c:330
int mb_height
number of MBs horizontally & vertically
Definition: mpegvideo.h:126
static av_cold void h261_decode_init_vlc(H261Context *h)
Definition: h261dec.c:50
#define av_log(a,...)
static void ff_update_block_index(MpegEncContext *s)
Definition: mpegvideo.h:731
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
Definition: mpegvideo.c:2802
av_cold void ff_h261_common_init(void)
Definition: h261.c:83
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:587
#define UPDATE_CACHE(name, gb)
Definition: get_bits.h:160
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
AVCodec ff_h261_decoder
Definition: h261dec.c:679
static av_cold int h261_decode_init(AVCodecContext *avctx)
Definition: h261dec.c:72
int mb_skipped
MUST BE SET only during DECODING.
Definition: mpegvideo.h:192
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
simple assert() macros that are a bit more flexible than ISO C assert().
int mtype
Definition: h261.h:42
const char * name
Name of the codec implementation.
Definition: avcodec.h:3746
int low_delay
no reordering needed / has no B-frames
Definition: mpegvideo.h:404
GetBitContext gb
Definition: mpegvideo.h:446
#define CLOSE_READER(name, gb)
Definition: get_bits.h:131
void ff_mpv_common_end(MpegEncContext *s)
Definition: mpegvideo.c:1115
#define INIT_VLC_RL(rl, static_size)
Definition: rl.h:63
#define GET_RL_VLC(level, run, name, gb, table, bits,max_depth, need_update)
Definition: get_bits.h:509
Definition: vlc.h:26
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:284
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:3050
static const int mvmap[17]
Definition: h261dec.c:232
int16_t(*[2] motion_val)[2]
Definition: mpegpicture.h:53
Picture * current_picture_ptr
pointer to the current picture
Definition: mpegvideo.h:181
void ff_mpeg_er_frame_start(MpegEncContext *s)
Definition: mpeg_er.c:46
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:296
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:554
int block_last_index[12]
last non zero coefficient in block
Definition: mpegvideo.h:83
int n
Definition: avisynth_c.h:684
const uint8_t ff_h261_mtype_code[10]
Definition: h261data.c:63
static av_cold int h261_decode_end(AVCodecContext *avctx)
Definition: h261dec.c:670
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:97
RL_VLC_ELEM * rl_vlc[32]
decoding only
Definition: rl.h:48
#define SHOW_UBITS(name, gb, num)
Definition: get_bits.h:193
#define FF_ARRAY_ELEMS(a)
void ff_mpv_decode_defaults(MpegEncContext *s)
Set the given MpegEncContext to defaults for decoding.
Definition: mpegvideo.c:657
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:266
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:223
int mba_diff
Definition: h261.h:41
main external API structure.
Definition: avcodec.h:1761
ScanTable intra_scantable
Definition: mpegvideo.h:88
int height
picture size. must be a multiple of 16
Definition: mpegvideo.h:97
#define IS_QUANT(a)
Definition: mpegutils.h:97
#define OPEN_READER(name, gb)
Definition: get_bits.h:120
void * buf
Definition: avisynth_c.h:690
void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict)
Definition: mpegvideo.c:1959
#define SLICE_END
end marker found
Definition: mpegvideo.h:503
static int h261_decode_gob(H261Context *h)
Definition: h261dec.c:542
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:313
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:338
H.261 codec.
int coded_height
Definition: avcodec.h:1963
static const char * format
Definition: movenc.c:47
#define IS_16X16(a)
Definition: mpegutils.h:88
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:306
Rational number (pair of numerator and denominator).
Definition: rational.h:58
struct AVFrame * f
Definition: mpegpicture.h:46
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:425
int context_initialized
Definition: mpegvideo.h:121
#define MB_TYPE_16x16
Definition: avcodec.h:1299
#define H261_MTYPE_VLC_BITS
Definition: h261dec.c:38
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:1189
#define SKIP_CACHE(name, gb, num)
Definition: get_bits.h:162
RLTable ff_h261_rl_tcoeff
Definition: h261data.c:150
static VLC h261_cbp_vlc
Definition: h261dec.c:48
#define MV_DIR_FORWARD
Definition: mpegvideo.h:262
int pict_type
AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ...
Definition: mpegvideo.h:209
static VLC h261_mv_vlc
Definition: h261dec.c:47
int gob_start_code_skipped
Definition: h261.h:46
uint8_t level
Definition: svq3.c:207
int mv[2][4][2]
motion vectors for a macroblock first coordinate : 0 = forward 1 = backward second " : depend...
Definition: mpegvideo.h:276
MpegEncContext.
Definition: mpegvideo.h:78
struct AVCodecContext * avctx
Definition: mpegvideo.h:95
#define SHOW_SBITS(name, gb, num)
Definition: get_bits.h:194
discard all non reference
Definition: avcodec.h:826
#define MB_TYPE_H261_FIL
Definition: h261.h:49
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
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:127
void ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
Definition: mpegvideo.c:662
if(ret< 0)
Definition: vf_mcdeint.c:279
static VLC h261_mba_vlc
Definition: h261dec.c:45
Bi-dir predicted.
Definition: avutil.h:276
static int h261_decode_mb(H261Context *h)
Definition: h261dec.c:354
void * priv_data
Definition: avcodec.h:1803
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
Definition: mpegvideo.c:877
#define IS_INTRA4x4(a)
Definition: mpegutils.h:77
static int decode_mv_component(GetBitContext *gb, int v)
Definition: h261dec.c:236
#define MBA_STARTCODE
Definition: h261dec.c:43
void ff_mpv_frame_end(MpegEncContext *s)
Definition: mpegvideo.c:1417
void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
Definition: mpegvideo.c:2720
int16_t(* block)[64]
points to one of the following blocks
Definition: mpegvideo.h:498
ParseContext parse_context
Definition: mpegvideo.h:362
VLC_TYPE(* table)[2]
code, bits
Definition: vlc.h:28
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:279
static const uint8_t * align_get_bits(GetBitContext *s)
Definition: get_bits.h:464
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:2554
uint32_t * mb_type
types and macros are defined in mpegutils.h
Definition: mpegpicture.h:56
static int skip_1stop_8data_bits(GetBitContext *gb)
Definition: get_bits.h:592
This structure stores compressed data.
Definition: avcodec.h:1656
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
Definition: avcodec.h:1002
#define MB_TYPE_L0
Definition: avcodec.h:1312
Predicted.
Definition: avutil.h:275
#define check(x, y, S, v)