FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules 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 "libavutil/thread.h"
30 #include "avcodec.h"
31 #include "codec_internal.h"
32 #include "decode.h"
33 #include "mpeg_er.h"
34 #include "mpegutils.h"
35 #include "mpegvideo.h"
36 #include "mpegvideodec.h"
37 #include "h261.h"
38 
39 #define H261_MBA_VLC_BITS 8
40 #define H261_MTYPE_VLC_BITS 6
41 #define H261_MV_VLC_BITS 7
42 #define H261_CBP_VLC_BITS 9
43 #define TCOEFF_VLC_BITS 9
44 #define MBA_STUFFING 33
45 #define MBA_STARTCODE 34
46 
47 static VLCElem h261_mba_vlc[540];
49 static VLCElem h261_mv_vlc[144];
50 static VLCElem h261_cbp_vlc[512];
51 
52 typedef struct H261DecContext {
54 
56 
58  int mba_diff;
62  int gob_start_code_skipped; // 1 if gob start code is already read before gob header is read
64 
66 {
68  ff_h261_mba_bits, 1, 1,
69  ff_h261_mba_code, 1, 1, 0);
71  ff_h261_mtype_bits, 1, 1,
72  ff_h261_mtype_code, 1, 1,
73  ff_h261_mtype_map, 2, 2, 0);
75  &ff_h261_mv_tab[0][1], 2, 1,
76  &ff_h261_mv_tab[0][0], 2, 1, 0);
78  &ff_h261_cbp_tab[0][1], 2, 1,
79  &ff_h261_cbp_tab[0][0], 2, 1, 0);
81 }
82 
84 {
85  static AVOnce init_static_once = AV_ONCE_INIT;
86  H261DecContext *const h = avctx->priv_data;
87  MpegEncContext *const s = &h->s;
88  int ret;
89 
90  avctx->framerate = (AVRational) { 30000, 1001 };
91 
92  s->private_ctx = &h->common;
93  // set defaults
94  ret = ff_mpv_decode_init(s, avctx);
95  if (ret < 0)
96  return ret;
97 
98  s->out_format = FMT_H261;
99  s->low_delay = 1;
100  avctx->pix_fmt = AV_PIX_FMT_YUV420P;
101 
102  ff_thread_once(&init_static_once, h261_decode_init_static);
103 
104  return 0;
105 }
106 
107 static inline void h261_init_dest(MpegEncContext *s)
108 {
109  const unsigned block_size = 8 >> s->avctx->lowres;
111  s->dest[0] += 2 * block_size;
112  s->dest[1] += block_size;
113  s->dest[2] += block_size;
114 }
115 
116 /**
117  * Decode the group of blocks header or slice header.
118  * @return <0 if an error occurred
119  */
121 {
122  unsigned int val;
123  MpegEncContext *const s = &h->s;
124 
125  if (!h->gob_start_code_skipped) {
126  /* Check for GOB Start Code */
127  val = show_bits(&s->gb, 15);
128  if (val)
129  return -1;
130 
131  /* We have a GBSC */
132  skip_bits(&s->gb, 16);
133  }
134 
135  h->gob_start_code_skipped = 0;
136 
137  h->gob_number = get_bits(&s->gb, 4); /* GN */
138  s->qscale = get_bits(&s->gb, 5); /* GQUANT */
139 
140  /* Check if gob_number is valid */
141  if (s->mb_height == 18) { // CIF
142  if ((h->gob_number <= 0) || (h->gob_number > 12))
143  return -1;
144  } else { // QCIF
145  if ((h->gob_number != 1) && (h->gob_number != 3) &&
146  (h->gob_number != 5))
147  return -1;
148  }
149 
150  /* GEI */
151  if (skip_1stop_8data_bits(&s->gb) < 0)
152  return AVERROR_INVALIDDATA;
153 
154  if (s->qscale == 0) {
155  av_log(s->avctx, AV_LOG_ERROR, "qscale has forbidden 0 value\n");
156  if (s->avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_COMPLIANT))
157  return -1;
158  s->qscale = 1;
159  }
160 
161  /* For the first transmitted macroblock in a GOB, MBA is the absolute
162  * address. For subsequent macroblocks, MBA is the difference between
163  * the absolute addresses of the macroblock and the last transmitted
164  * macroblock. */
165  h->current_mba = 0;
166  h->mba_diff = 0;
167 
168  return 0;
169 }
170 
171 /**
172  * Decode skipped macroblocks.
173  * @return 0
174  */
175 static int h261_decode_mb_skipped(H261DecContext *h, int mba1, int mba2)
176 {
177  MpegEncContext *const s = &h->s;
178  int i;
179 
180  s->mb_intra = 0;
181 
182  for (i = mba1; i < mba2; i++) {
183  int j, xy;
184 
185  s->mb_x = ((h->gob_number - 1) % 2) * 11 + i % 11;
186  s->mb_y = ((h->gob_number - 1) / 2) * 3 + i / 11;
187  xy = s->mb_x + s->mb_y * s->mb_stride;
188  h261_init_dest(s);
189 
190  for (j = 0; j < 6; j++)
191  s->block_last_index[j] = -1;
192 
193  s->mv_dir = MV_DIR_FORWARD;
194  s->mv_type = MV_TYPE_16X16;
195  s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
196  s->mv[0][0][0] = 0;
197  s->mv[0][0][1] = 0;
198  s->mb_skipped = 1;
199  h->common.mtype &= ~MB_TYPE_H261_FIL;
200 
201  if (s->cur_pic.motion_val[0]) {
202  int b_stride = 2*s->mb_width + 1;
203  int b_xy = 2 * s->mb_x + (2 * s->mb_y) * b_stride;
204  s->cur_pic.motion_val[0][b_xy][0] = s->mv[0][0][0];
205  s->cur_pic.motion_val[0][b_xy][1] = s->mv[0][0][1];
206  }
207 
208  ff_mpv_reconstruct_mb(s, s->block);
209  }
210 
211  return 0;
212 }
213 
214 static int decode_mv_component(GetBitContext *gb, int v)
215 {
216  int mv_diff = get_vlc2(gb, h261_mv_vlc, H261_MV_VLC_BITS, 2);
217 
218  /* check if mv_diff is valid */
219  if (mv_diff < 0)
220  return v;
221 
222  if (mv_diff && get_bits1(gb))
223  mv_diff = -mv_diff;
224 
225  v += mv_diff;
226  if (v <= -16)
227  v += 32;
228  else if (v >= 16)
229  v -= 32;
230 
231  return v;
232 }
233 
234 /**
235  * Decode a macroblock.
236  * @return <0 if an error occurred
237  */
238 static int h261_decode_block(H261DecContext *h, int16_t *block, int n, int coded)
239 {
240  MpegEncContext *const s = &h->s;
241  int level, i, j, run;
242  const RLTable *rl = &ff_h261_rl_tcoeff;
243  const uint8_t *scan_table;
244  const int qmul = s->qscale << 1, qadd = (s->qscale - 1) | 1;
245 
246  /* For the variable length encoding there are two code tables, one being
247  * used for the first transmitted LEVEL in INTER, INTER + MC and
248  * INTER + MC + FIL blocks, the second for all other LEVELs except the
249  * first one in INTRA blocks which is fixed length coded with 8 bits.
250  * NOTE: The two code tables only differ in one VLC so we handle that
251  * manually. */
252  scan_table = s->intra_scantable.permutated;
253  if (s->mb_intra) {
254  /* DC coef */
255  level = get_bits(&s->gb, 8);
256  // 0 (00000000b) and -128 (10000000b) are FORBIDDEN
257  if ((level & 0x7F) == 0) {
258  av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n",
259  level, s->mb_x, s->mb_y);
260  return -1;
261  }
262  /* The code 1000 0000 is not used, the reconstruction level of 1024
263  * being coded as 1111 1111. */
264  if (level == 255)
265  level = 128;
266  block[0] = level * 8;
267  i = 1;
268  } else if (coded) {
269  // Run Level Code
270  // EOB Not possible for first level when cbp is available (that's why the table is different)
271  // 0 1 1s
272  // * * 0*
273  int check = show_bits(&s->gb, 2);
274  i = 0;
275  if (check & 0x2) {
276  skip_bits(&s->gb, 2);
277  block[0] = qmul + qadd;
278  block[0] *= (check & 0x1) ? -1 : 1;
279  i = 1;
280  }
281  } else {
282  i = 0;
283  }
284  if (!coded) {
285  s->block_last_index[n] = i - 1;
286  return 0;
287  }
288  {
289  OPEN_READER(re, &s->gb);
290  i--; // offset by -1 to allow direct indexing of scan_table
291  for (;;) {
292  UPDATE_CACHE(re, &s->gb);
293  GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TCOEFF_VLC_BITS, 2, 0);
294  if (run == 66) {
295  if (level) {
296  CLOSE_READER(re, &s->gb);
297  av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n",
298  s->mb_x, s->mb_y);
299  return -1;
300  }
301  /* escape */
302  /* The remaining combinations of (run, level) are encoded with a
303  * 20-bit word consisting of 6 bits escape, 6 bits run and 8 bits
304  * level. */
305  run = SHOW_UBITS(re, &s->gb, 6) + 1;
306  SKIP_CACHE(re, &s->gb, 6);
307  level = SHOW_SBITS(re, &s->gb, 8);
308  if (level > 0)
309  level = level * qmul + qadd;
310  else if (level < 0)
311  level = level * qmul - qadd;
312  SKIP_COUNTER(re, &s->gb, 6 + 8);
313  } else if (level == 0) {
314  break;
315  } else {
316  level = level * qmul + qadd;
317  if (SHOW_UBITS(re, &s->gb, 1))
318  level = -level;
319  SKIP_COUNTER(re, &s->gb, 1);
320  }
321  i += run;
322  if (i >= 64) {
323  CLOSE_READER(re, &s->gb);
324  av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d\n",
325  s->mb_x, s->mb_y);
326  return -1;
327  }
328  j = scan_table[i];
329  block[j] = level;
330  }
331  CLOSE_READER(re, &s->gb);
332  }
333  s->block_last_index[n] = i;
334  return 0;
335 }
336 
338 {
339  MpegEncContext *const s = &h->s;
340  H261Context *const com = &h->common;
341  int i, cbp, xy;
342 
343  cbp = 63;
344  // Read mba
345  do {
346  h->mba_diff = get_vlc2(&s->gb, h261_mba_vlc,
347  H261_MBA_VLC_BITS, 2);
348 
349  /* Check for slice end */
350  /* NOTE: GOB can be empty (no MB data) or exist only of MBA_stuffing */
351  if (h->mba_diff == MBA_STARTCODE) { // start code
352  h->gob_start_code_skipped = 1;
353  return SLICE_END;
354  }
355  } while (h->mba_diff == MBA_STUFFING); // stuffing
356 
357  if (h->mba_diff < 0) {
358  if (get_bits_left(&s->gb) <= 7)
359  return SLICE_END;
360 
361  av_log(s->avctx, AV_LOG_ERROR, "illegal mba at %d %d\n", s->mb_x, s->mb_y);
362  return SLICE_ERROR;
363  }
364 
365  h->mba_diff += 1;
366  h->current_mba += h->mba_diff;
367 
368  if (h->current_mba > MBA_STUFFING)
369  return SLICE_ERROR;
370 
371  s->mb_x = ((h->gob_number - 1) % 2) * 11 + ((h->current_mba - 1) % 11);
372  s->mb_y = ((h->gob_number - 1) / 2) * 3 + ((h->current_mba - 1) / 11);
373  xy = s->mb_x + s->mb_y * s->mb_stride;
374  h261_init_dest(s);
375 
376  // Read mtype
378  if (com->mtype < 0) {
379  av_log(s->avctx, AV_LOG_ERROR, "Invalid mtype index\n");
380  return SLICE_ERROR;
381  }
382 
383  // Read mquant
384  if (IS_QUANT(com->mtype)) {
385  s->qscale = get_bits(&s->gb, 5);
386  if (!s->qscale)
387  s->qscale = 1;
388  }
389 
390  s->mb_intra = IS_INTRA4x4(com->mtype);
391 
392  // Read mv
393  if (IS_16X16(com->mtype)) {
394  /* Motion vector data is included for all MC macroblocks. MVD is
395  * obtained from the macroblock vector by subtracting the vector
396  * of the preceding macroblock. For this calculation the vector
397  * of the preceding macroblock is regarded as zero in the
398  * following three situations:
399  * 1) evaluating MVD for macroblocks 1, 12 and 23;
400  * 2) evaluating MVD for macroblocks in which MBA does not represent a difference of 1;
401  * 3) MTYPE of the previous macroblock was not MC. */
402  if ((h->current_mba == 1) || (h->current_mba == 12) ||
403  (h->current_mba == 23) || (h->mba_diff != 1)) {
404  h->current_mv_x = 0;
405  h->current_mv_y = 0;
406  }
407 
408  h->current_mv_x = decode_mv_component(&s->gb, h->current_mv_x);
409  h->current_mv_y = decode_mv_component(&s->gb, h->current_mv_y);
410  } else {
411  h->current_mv_x = 0;
412  h->current_mv_y = 0;
413  }
414 
415  // Read cbp
416  if (HAS_CBP(com->mtype))
417  cbp = get_vlc2(&s->gb, h261_cbp_vlc, H261_CBP_VLC_BITS, 1) + 1;
418 
419  if (s->mb_intra) {
420  s->cur_pic.mb_type[xy] = MB_TYPE_INTRA;
421  goto intra;
422  }
423 
424  //set motion vectors
425  s->mv_dir = MV_DIR_FORWARD;
426  s->mv_type = MV_TYPE_16X16;
427  s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
428  s->mv[0][0][0] = h->current_mv_x * 2; // gets divided by 2 in motion compensation
429  s->mv[0][0][1] = h->current_mv_y * 2;
430 
431  if (s->cur_pic.motion_val[0]) {
432  int b_stride = 2*s->mb_width + 1;
433  int b_xy = 2 * s->mb_x + (2 * s->mb_y) * b_stride;
434  s->cur_pic.motion_val[0][b_xy][0] = s->mv[0][0][0];
435  s->cur_pic.motion_val[0][b_xy][1] = s->mv[0][0][1];
436  }
437 
438 intra:
439  /* decode each block */
440  if (s->mb_intra || HAS_CBP(com->mtype)) {
441  s->bdsp.clear_blocks(s->block[0]);
442  for (i = 0; i < 6; i++) {
443  if (h261_decode_block(h, s->block[i], i, cbp & 32) < 0)
444  return SLICE_ERROR;
445  cbp += cbp;
446  }
447  } else {
448  for (i = 0; i < 6; i++)
449  s->block_last_index[i] = -1;
450  }
451 
452  ff_mpv_reconstruct_mb(s, s->block);
453 
454  return SLICE_OK;
455 }
456 
457 /**
458  * Decode the H.261 picture header.
459  * @return <0 if no startcode found
460  */
462 {
463  MpegEncContext *const s = &h->s;
464  int format, i;
465  uint32_t startcode = 0;
466 
467  for (i = get_bits_left(&s->gb); i > 24; i -= 1) {
468  startcode = ((startcode << 1) | get_bits(&s->gb, 1)) & 0x000FFFFF;
469 
470  if (startcode == 0x10)
471  break;
472  }
473 
474  if (startcode != 0x10) {
475  av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
476  return -1;
477  }
478 
479  /* temporal reference */
480  skip_bits(&s->gb, 5); /* picture timestamp */
481 
482  /* PTYPE starts here */
483  skip_bits1(&s->gb); /* split screen off */
484  skip_bits1(&s->gb); /* camera off */
485  skip_bits1(&s->gb); /* freeze picture release off */
486 
487  format = get_bits1(&s->gb);
488 
489  // only 2 formats possible
490  if (format == 0) { // QCIF
491  s->width = 176;
492  s->height = 144;
493  } else { // CIF
494  s->width = 352;
495  s->height = 288;
496  }
497 
498  skip_bits1(&s->gb); /* still image mode off */
499  skip_bits1(&s->gb); /* Reserved */
500 
501  /* PEI */
502  if (skip_1stop_8data_bits(&s->gb) < 0)
503  return AVERROR_INVALIDDATA;
504 
505  /* H.261 has no I-frames, but if we pass AV_PICTURE_TYPE_I for the first
506  * frame, the codec crashes if it does not contain all I-blocks
507  * (e.g. when a packet is lost). */
508  s->pict_type = AV_PICTURE_TYPE_P;
509 
510  h->gob_number = 0;
511  return 0;
512 }
513 
515 {
516  MpegEncContext *const s = &h->s;
517 
518  /* decode mb's */
519  while (h->current_mba <= MBA_STUFFING) {
520  int ret;
521  /* DCT & quantize */
522  ret = h261_decode_mb(h);
523  if (ret < 0) {
524  if (ret == SLICE_END) {
525  h261_decode_mb_skipped(h, h->current_mba, 33);
526  return 0;
527  }
528  av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n",
529  s->mb_x + s->mb_y * s->mb_stride);
530  return -1;
531  }
532 
534  h->current_mba - h->mba_diff,
535  h->current_mba - 1);
536  }
537 
538  return -1;
539 }
540 
541 static int h261_decode_frame(AVCodecContext *avctx, AVFrame *pict,
542  int *got_frame, AVPacket *avpkt)
543 {
544  H261DecContext *const h = avctx->priv_data;
545  const uint8_t *buf = avpkt->data;
546  int buf_size = avpkt->size;
547  MpegEncContext *s = &h->s;
548  int ret;
549 
550  ff_dlog(avctx, "*****frame %"PRId64" size=%d\n", avctx->frame_num, buf_size);
551  ff_dlog(avctx, "bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);
552 
553  h->gob_start_code_skipped = 0;
554 
555  init_get_bits(&s->gb, buf, buf_size * 8);
556 
558 
559  /* skip if the header was thrashed */
560  if (ret < 0) {
561  av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
562  return -1;
563  }
564 
565  if (s->width != avctx->coded_width || s->height != avctx->coded_height) {
567  }
568 
569  if (!s->context_initialized) {
570  if ((ret = ff_mpv_common_init(s)) < 0)
571  return ret;
572 
573  ret = ff_set_dimensions(avctx, s->width, s->height);
574  if (ret < 0)
575  return ret;
576  }
577 
578  if ((avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) ||
579  avctx->skip_frame >= AVDISCARD_ALL)
580  return buf_size;
581 
582  if (ff_mpv_frame_start(s, avctx) < 0)
583  return -1;
584 
586 
587  /* decode each macroblock */
588  s->mb_x = 0;
589  s->mb_y = 0;
590 
591  while (h->gob_number < (s->mb_height == 18 ? 12 : 5)) {
592  if (h261_decode_gob_header(h) < 0)
593  break;
595  }
597 
598  av_assert0(s->pict_type == s->cur_pic.ptr->f->pict_type);
599 
600  if ((ret = av_frame_ref(pict, s->cur_pic.ptr->f)) < 0)
601  return ret;
602  ff_print_debug_info(s, s->cur_pic.ptr, pict);
603 
604  *got_frame = 1;
605 
606  return buf_size;
607 }
608 
610  .p.name = "h261",
611  CODEC_LONG_NAME("H.261"),
612  .p.type = AVMEDIA_TYPE_VIDEO,
613  .p.id = AV_CODEC_ID_H261,
614  .priv_data_size = sizeof(H261DecContext),
617  .close = ff_mpv_decode_close,
618  .p.capabilities = AV_CODEC_CAP_DR1,
619  .p.max_lowres = 3,
620  .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
621 };
ff_mpv_common_init
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
Definition: mpegvideo.c:425
IS_INTRA4x4
#define IS_INTRA4x4(a)
Definition: mpegutils.h:69
MV_TYPE_16X16
#define MV_TYPE_16X16
1 vector for the whole mb
Definition: mpegvideo.h:192
H261_MV_VLC_BITS
#define H261_MV_VLC_BITS
Definition: h261dec.c:41
level
uint8_t level
Definition: svq3.c:205
MBA_STARTCODE
#define MBA_STARTCODE
Definition: h261dec.c:45
h261_decode_mb
static int h261_decode_mb(H261DecContext *h)
Definition: h261dec.c:337
get_bits_left
static int get_bits_left(GetBitContext *gb)
Definition: get_bits.h:678
ff_mpv_decode_init
av_cold int ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
Initialize the given MpegEncContext for decoding.
Definition: mpegvideo_dec.c:47
H261Context::mtype
int mtype
Definition: h261.h:38
AV_EF_COMPLIANT
#define AV_EF_COMPLIANT
consider all spec non compliances as errors
Definition: defs.h:55
thread.h
H261_CBP_VLC_BITS
#define H261_CBP_VLC_BITS
Definition: h261dec.c:42
h261_cbp_vlc
static VLCElem h261_cbp_vlc[512]
Definition: h261dec.c:50
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:410
h261_decode_init_static
static av_cold void h261_decode_init_static(void)
Definition: h261dec.c:65
H261DecContext::current_mv_x
int current_mv_x
Definition: h261dec.c:59
AVPacket::data
uint8_t * data
Definition: packet.h:539
H261_MBA_VLC_BITS
#define H261_MBA_VLC_BITS
Definition: h261dec.c:39
MB_TYPE_16x16
#define MB_TYPE_16x16
Definition: mpegutils.h:41
FFCodec
Definition: codec_internal.h:127
ff_init_block_index
void ff_init_block_index(MpegEncContext *s)
Definition: mpegvideo.c:555
mpegvideo.h
UPDATE_CACHE
#define UPDATE_CACHE(name, gb)
Definition: get_bits.h:208
FMT_H261
@ FMT_H261
Definition: mpegvideo.h:55
h261_decode_picture_header
static int h261_decode_picture_header(H261DecContext *h)
Decode the H.261 picture header.
Definition: h261dec.c:461
mpegutils.h
ff_set_dimensions
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:91
init_get_bits
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
Definition: get_bits.h:497
h261_decode_gob_header
static int h261_decode_gob_header(H261DecContext *h)
Decode the group of blocks header or slice header.
Definition: h261dec.c:120
AV_CODEC_ID_H261
@ AV_CODEC_ID_H261
Definition: codec_id.h:55
skip_bits
static void skip_bits(GetBitContext *s, int n)
Definition: get_bits.h:364
AVCodecContext::framerate
AVRational framerate
Definition: avcodec.h:574
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:318
MBA_STUFFING
#define MBA_STUFFING
Definition: h261dec.c:44
ff_mpv_reconstruct_mb
void ff_mpv_reconstruct_mb(MpegEncContext *s, int16_t block[12][64])
Definition: mpegvideo_dec.c:1087
SKIP_CACHE
#define SKIP_CACHE(name, gb, num)
Definition: get_bits.h:211
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
AVCodecContext::skip_frame
enum AVDiscard skip_frame
Skip decoding for selected frames.
Definition: avcodec.h:1841
h261.h
RLTable
RLTable.
Definition: rl.h:39
GetBitContext
Definition: get_bits.h:108
AV_EF_BITSTREAM
#define AV_EF_BITSTREAM
detect bitstream specification deviations
Definition: defs.h:49
val
static double val(void *priv, double ch)
Definition: aeval.c:77
AVCodecContext::coded_height
int coded_height
Definition: avcodec.h:647
SLICE_END
#define SLICE_END
end marker found
Definition: mpegvideo.h:326
HAS_CBP
#define HAS_CBP(a)
Definition: mpegutils.h:87
avassert.h
ff_thread_once
static int ff_thread_once(char *control, void(*routine)(void))
Definition: thread.h:205
mpegvideodec.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
INIT_FIRST_VLC_RL
#define INIT_FIRST_VLC_RL(rl, static_size)
Definition: rl.h:93
av_cold
#define av_cold
Definition: attributes.h:90
check
#define check(x, y, S, v)
Definition: motion_est_template.c:405
CLOSE_READER
#define CLOSE_READER(name, gb)
Definition: get_bits.h:184
h261_decode_init
static av_cold int h261_decode_init(AVCodecContext *avctx)
Definition: h261dec.c:83
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:341
s
#define s(width, name)
Definition: cbs_vp9.c:198
format
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample format(the sample packing is implied by the sample format) and sample rate. The lists are not just lists
SHOW_SBITS
#define SHOW_SBITS(name, gb, num)
Definition: get_bits.h:243
h261_decode_block
static int h261_decode_block(H261DecContext *h, int16_t *block, int n, int coded)
Decode a macroblock.
Definition: h261dec.c:238
ff_h261_mba_code
const uint8_t ff_h261_mba_code[35]
Definition: h261data.c:34
ff_mpeg_er_frame_start
void ff_mpeg_er_frame_start(MpegEncContext *s)
Definition: mpeg_er.c:49
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
decode.h
ff_h261_mv_tab
const uint8_t ff_h261_mv_tab[17][2]
Definition: h261data.c:89
AV_PIX_FMT_YUV420P
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:73
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:326
ff_mpv_common_end
av_cold void ff_mpv_common_end(MpegEncContext *s)
Definition: mpegvideo.c:512
if
if(ret)
Definition: filter_design.txt:179
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:221
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:203
run
uint8_t run
Definition: svq3.c:204
H261DecContext::common
H261Context common
Definition: h261dec.c:55
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
ff_mpv_decode_close
av_cold int ff_mpv_decode_close(AVCodecContext *avctx)
Definition: mpegvideo_dec.c:145
H261DecContext::current_mv_y
int current_mv_y
Definition: h261dec.c:60
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:279
get_bits1
static unsigned int get_bits1(GetBitContext *s)
Definition: get_bits.h:371
H261DecContext::gob_start_code_skipped
int gob_start_code_skipped
Definition: h261dec.c:62
get_vlc2
static av_always_inline int get_vlc2(GetBitContext *s, const VLCElem *table, int bits, int max_depth)
Parse a vlc code.
Definition: get_bits.h:635
AVOnce
#define AVOnce
Definition: thread.h:202
h261_mtype_vlc
static VLCElem h261_mtype_vlc[80]
Definition: h261dec.c:48
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:28
AVDISCARD_NONKEY
@ AVDISCARD_NONKEY
discard all frames except keyframes
Definition: defs.h:220
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVPacket::size
int size
Definition: packet.h:540
av_frame_ref
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:308
codec_internal.h
VLCElem
Definition: vlc.h:32
FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
#define FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM
The decoder extracts and fills its parameters even if the frame is skipped due to the skip_frame sett...
Definition: codec_internal.h:54
MB_TYPE_SKIP
#define MB_TYPE_SKIP
Definition: mpegutils.h:61
ff_mpv_frame_start
int ff_mpv_frame_start(MpegEncContext *s, AVCodecContext *avctx)
generic function called after decoding the header and before a frame is decoded.
Definition: mpegvideo_dec.c:326
OPEN_READER
#define OPEN_READER(name, gb)
Definition: get_bits.h:173
skip_bits1
static void skip_bits1(GetBitContext *s)
Definition: get_bits.h:396
h261_decode_mb_skipped
static int h261_decode_mb_skipped(H261DecContext *h, int mba1, int mba2)
Decode skipped macroblocks.
Definition: h261dec.c:175
IS_16X16
#define IS_16X16(a)
Definition: mpegutils.h:80
H261Context
H261Context.
Definition: h261.h:37
H261_MTYPE_VLC_BITS
#define H261_MTYPE_VLC_BITS
Definition: h261dec.c:40
h261_init_dest
static void h261_init_dest(MpegEncContext *s)
Definition: h261dec.c:107
h261_decode_frame
static int h261_decode_frame(AVCodecContext *avctx, AVFrame *pict, int *got_frame, AVPacket *avpkt)
Definition: h261dec.c:541
ff_print_debug_info
void ff_print_debug_info(const MpegEncContext *s, const MPVPicture *p, AVFrame *pict)
Definition: mpegvideo_dec.c:385
SKIP_COUNTER
#define SKIP_COUNTER(name, gb, num)
Definition: get_bits.h:216
ff_h261_cbp_tab
const uint8_t ff_h261_cbp_tab[63][2]
Definition: h261data.c:95
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
show_bits
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Definition: get_bits.h:354
IS_QUANT
#define IS_QUANT(a)
Definition: mpegutils.h:85
ff_h261_mtype_code
const uint8_t ff_h261_mtype_code[10]
Definition: h261data.c:63
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
H261DecContext::current_mba
int current_mba
Definition: h261dec.c:57
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:671
VLC_INIT_STATIC_SPARSE_TABLE
#define VLC_INIT_STATIC_SPARSE_TABLE(vlc_table, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, symbols, symbols_wrap, symbols_size, flags)
Definition: vlc.h:266
avcodec.h
ff_h261_decoder
const FFCodec ff_h261_decoder
Definition: h261dec.c:609
GET_RL_VLC
#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update)
Definition: get_bits.h:589
AVCodecContext::frame_num
int64_t frame_num
Frame counter, set by libavcodec.
Definition: avcodec.h:2060
ret
ret
Definition: filter_design.txt:187
SLICE_OK
#define SLICE_OK
Definition: mpegvideo.h:324
h261_mba_vlc
static VLCElem h261_mba_vlc[540]
Definition: h261dec.c:47
h261_mv_vlc
static VLCElem h261_mv_vlc[144]
Definition: h261dec.c:49
ff_h261_rl_tcoeff
RLTable ff_h261_rl_tcoeff
Definition: h261data.c:150
skip_1stop_8data_bits
static int skip_1stop_8data_bits(GetBitContext *gb)
Definition: get_bits.h:683
AVCodecContext
main external API structure.
Definition: avcodec.h:451
SHOW_UBITS
#define SHOW_UBITS(name, gb, num)
Definition: get_bits.h:242
ff_h261_mtype_map
const uint16_t ff_h261_mtype_map[10]
Definition: h261data.c:75
VLC_INIT_STATIC_TABLE
#define VLC_INIT_STATIC_TABLE(vlc_table, nb_bits, nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, flags)
Definition: vlc.h:278
H261DecContext::mba_diff
int mba_diff
Definition: h261dec.c:58
ff_h261_mtype_bits
const uint8_t ff_h261_mtype_bits[10]
Definition: h261data.c:69
ff_mpv_frame_end
void ff_mpv_frame_end(MpegEncContext *s)
Definition: mpegvideo_dec.c:377
AVCodecContext::coded_width
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:647
h261_decode_gob
static int h261_decode_gob(H261DecContext *h)
Definition: h261dec.c:514
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:280
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
H261DecContext::gob_number
int gob_number
Definition: h261dec.c:61
SLICE_ERROR
#define SLICE_ERROR
Definition: mpegvideo.h:325
MV_DIR_FORWARD
#define MV_DIR_FORWARD
Definition: mpegvideo.h:188
AVPacket
This structure stores compressed data.
Definition: packet.h:516
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:478
decode_mv_component
static int decode_mv_component(GetBitContext *gb, int v)
Definition: h261dec.c:214
mpeg_er.h
block
The exact code depends on how similar the blocks are and how related they are to the block
Definition: filter_design.txt:207
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
h
h
Definition: vp9dsp_template.c:2070
ff_h261_mba_bits
const uint8_t ff_h261_mba_bits[35]
Definition: h261data.c:48
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:64
H261DecContext
Definition: h261dec.c:52
MB_TYPE_FORWARD_MV
#define MB_TYPE_FORWARD_MV
Definition: mpegutils.h:49
TCOEFF_VLC_BITS
#define TCOEFF_VLC_BITS
Definition: h261dec.c:43
H261DecContext::s
MpegEncContext s
Definition: h261dec.c:53
RLTable::rl_vlc
RL_VLC_ELEM * rl_vlc[32]
decoding only
Definition: rl.h:48
MB_TYPE_INTRA
#define MB_TYPE_INTRA
Definition: mpegutils.h:64
MB_TYPE_H261_FIL
#define MB_TYPE_H261_FIL
Definition: h261.h:41