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/mem_internal.h"
29 #include "libavutil/thread.h"
30 #include "avcodec.h"
31 #include "codec_internal.h"
32 #include "decode.h"
33 #include "get_bits.h"
34 #include "mpeg_er.h"
35 #include "mpegutils.h"
36 #include "mpegvideo.h"
37 #include "mpegvideodec.h"
38 #include "h261.h"
39 
40 #define SLICE_OK 0
41 #define SLICE_ERROR -1
42 #define SLICE_END -2 ///<end marker found
43 
44 #define H261_MBA_VLC_BITS 8
45 #define H261_MTYPE_VLC_BITS 6
46 #define H261_MV_VLC_BITS 7
47 #define H261_CBP_VLC_BITS 9
48 #define TCOEFF_VLC_BITS 9
49 #define MBA_STUFFING 33
50 #define MBA_STARTCODE 34
51 
52 static VLCElem h261_mba_vlc[540];
54 static VLCElem h261_mv_vlc[144];
55 static VLCElem h261_cbp_vlc[512];
56 
57 typedef struct H261DecContext {
59 
61 
63 
65  int mba_diff;
69  int gob_start_code_skipped; // 1 if gob start code is already read before gob header is read
70 
71  DECLARE_ALIGNED_32(int16_t, block)[6][64];
73 
75 {
77  ff_h261_mba_bits, 1, 1,
78  ff_h261_mba_code, 1, 1, 0);
80  ff_h261_mtype_bits, 1, 1,
81  ff_h261_mtype_code, 1, 1,
82  ff_h261_mtype_map, 2, 2, 0);
84  &ff_h261_mv_tab[0][1], 2, 1,
85  &ff_h261_mv_tab[0][0], 2, 1, 0);
87  &ff_h261_cbp_tab[0][1], 2, 1,
88  &ff_h261_cbp_tab[0][0], 2, 1, 0);
90 }
91 
93 {
94  static AVOnce init_static_once = AV_ONCE_INIT;
95  H261DecContext *const h = avctx->priv_data;
96  MpegEncContext *const s = &h->s;
97  int ret;
98 
99  avctx->framerate = (AVRational) { 30000, 1001 };
100 
101  /* The H.261 analog of intra/key frames is setting the freeze picture release flag,
102  * but this does not guarantee that the frame uses intra-only encoding,
103  * so we still need to allocate dummy frames. So set pict_type to P here
104  * for all frames and override it after having decoded the frame. */
105  s->pict_type = AV_PICTURE_TYPE_P;
106 
107  s->private_ctx = &h->common;
108  // set defaults
109  ret = ff_mpv_decode_init(s, avctx);
110  if (ret < 0)
111  return ret;
112 
113  s->out_format = FMT_H261;
114  s->low_delay = 1;
115  avctx->pix_fmt = AV_PIX_FMT_YUV420P;
116 
117  ff_thread_once(&init_static_once, h261_decode_init_static);
118 
119  return 0;
120 }
121 
122 static inline void h261_init_dest(MpegEncContext *s)
123 {
124  const unsigned block_size = 8 >> s->avctx->lowres;
126  s->dest[0] += 2 * block_size;
127  s->dest[1] += block_size;
128  s->dest[2] += block_size;
129 }
130 
131 /**
132  * Decode the group of blocks header or slice header.
133  * @return <0 if an error occurred
134  */
136 {
137  unsigned int val;
138  MpegEncContext *const s = &h->s;
139 
140  if (!h->gob_start_code_skipped) {
141  /* Check for GOB Start Code */
142  val = show_bits(&h->gb, 15);
143  if (val)
144  return -1;
145 
146  /* We have a GBSC */
147  skip_bits(&h->gb, 16);
148  }
149 
150  h->gob_start_code_skipped = 0;
151 
152  h->gob_number = get_bits(&h->gb, 4); /* GN */
153  s->qscale = get_bits(&h->gb, 5); /* GQUANT */
154 
155  /* Check if gob_number is valid */
156  if (s->mb_height == 18) { // CIF
157  if ((h->gob_number <= 0) || (h->gob_number > 12))
158  return -1;
159  } else { // QCIF
160  if ((h->gob_number != 1) && (h->gob_number != 3) &&
161  (h->gob_number != 5))
162  return -1;
163  }
164 
165  /* GEI */
166  if (skip_1stop_8data_bits(&h->gb) < 0)
167  return AVERROR_INVALIDDATA;
168 
169  if (s->qscale == 0) {
170  av_log(s->avctx, AV_LOG_ERROR, "qscale has forbidden 0 value\n");
171  if (s->avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_COMPLIANT))
172  return -1;
173  s->qscale = 1;
174  }
175 
176  /* For the first transmitted macroblock in a GOB, MBA is the absolute
177  * address. For subsequent macroblocks, MBA is the difference between
178  * the absolute addresses of the macroblock and the last transmitted
179  * macroblock. */
180  h->current_mba = 0;
181  h->mba_diff = 0;
182 
183  return 0;
184 }
185 
186 /**
187  * Decode skipped macroblocks.
188  * @return 0
189  */
190 static int h261_decode_mb_skipped(H261DecContext *h, int mba1, int mba2)
191 {
192  MpegEncContext *const s = &h->s;
193  int i;
194 
195  s->mb_intra = 0;
196 
197  for (i = mba1; i < mba2; i++) {
198  int j, xy;
199 
200  s->mb_x = ((h->gob_number - 1) % 2) * 11 + i % 11;
201  s->mb_y = ((h->gob_number - 1) / 2) * 3 + i / 11;
202  xy = s->mb_x + s->mb_y * s->mb_stride;
203  h261_init_dest(s);
204 
205  for (j = 0; j < 6; j++)
206  s->block_last_index[j] = -1;
207 
208  s->mv_dir = MV_DIR_FORWARD;
209  s->mv_type = MV_TYPE_16X16;
210  s->cur_pic.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
211  s->mv[0][0][0] = 0;
212  s->mv[0][0][1] = 0;
213  s->mb_skipped = 1;
214  h->common.mtype &= ~MB_TYPE_H261_FIL;
215 
216  if (s->cur_pic.motion_val[0]) {
217  int b_stride = 2*s->mb_width + 1;
218  int b_xy = 2 * s->mb_x + (2 * s->mb_y) * b_stride;
219  s->cur_pic.motion_val[0][b_xy][0] = s->mv[0][0][0];
220  s->cur_pic.motion_val[0][b_xy][1] = s->mv[0][0][1];
221  }
222 
223  ff_mpv_reconstruct_mb(s, h->block);
224  }
225 
226  return 0;
227 }
228 
229 static int decode_mv_component(GetBitContext *gb, int v)
230 {
231  int mv_diff = get_vlc2(gb, h261_mv_vlc, H261_MV_VLC_BITS, 2);
232 
233  /* check if mv_diff is valid */
234  if (mv_diff < 0)
235  return v;
236 
237  if (mv_diff && get_bits1(gb))
238  mv_diff = -mv_diff;
239 
240  v += mv_diff;
241  if (v <= -16)
242  v += 32;
243  else if (v >= 16)
244  v -= 32;
245 
246  return v;
247 }
248 
249 /**
250  * Decode a macroblock.
251  * @return <0 if an error occurred
252  */
253 static int h261_decode_block(H261DecContext *h, int16_t *block, int n, int coded)
254 {
255  MpegEncContext *const s = &h->s;
256  int level, i, j, run;
257  const RLTable *rl = &ff_h261_rl_tcoeff;
258  const uint8_t *scan_table;
259  const int qmul = s->qscale << 1, qadd = (s->qscale - 1) | 1;
260 
261  /* For the variable length encoding there are two code tables, one being
262  * used for the first transmitted LEVEL in INTER, INTER + MC and
263  * INTER + MC + FIL blocks, the second for all other LEVELs except the
264  * first one in INTRA blocks which is fixed length coded with 8 bits.
265  * NOTE: The two code tables only differ in one VLC so we handle that
266  * manually. */
267  scan_table = s->intra_scantable.permutated;
268  if (s->mb_intra) {
269  /* DC coef */
270  level = get_bits(&h->gb, 8);
271  // 0 (00000000b) and -128 (10000000b) are FORBIDDEN
272  if ((level & 0x7F) == 0) {
273  av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n",
274  level, s->mb_x, s->mb_y);
275  return -1;
276  }
277  /* The code 1000 0000 is not used, the reconstruction level of 1024
278  * being coded as 1111 1111. */
279  if (level == 255)
280  level = 128;
281  block[0] = level * 8;
282  i = 1;
283  } else if (coded) {
284  // Run Level Code
285  // EOB Not possible for first level when cbp is available (that's why the table is different)
286  // 0 1 1s
287  // * * 0*
288  int check = show_bits(&h->gb, 2);
289  i = 0;
290  if (check & 0x2) {
291  skip_bits(&h->gb, 2);
292  block[0] = qmul + qadd;
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  {
304  OPEN_READER(re, &h->gb);
305  i--; // offset by -1 to allow direct indexing of scan_table
306  for (;;) {
307  UPDATE_CACHE(re, &h->gb);
308  GET_RL_VLC(level, run, re, &h->gb, rl->rl_vlc[0], TCOEFF_VLC_BITS, 2, 0);
309  if (run == 66) {
310  if (level) {
311  CLOSE_READER(re, &h->gb);
312  av_log(s->avctx, AV_LOG_ERROR, "illegal ac vlc code at %dx%d\n",
313  s->mb_x, s->mb_y);
314  return -1;
315  }
316  /* escape */
317  /* The remaining combinations of (run, level) are encoded with a
318  * 20-bit word consisting of 6 bits escape, 6 bits run and 8 bits
319  * level. */
320  run = SHOW_UBITS(re, &h->gb, 6) + 1;
321  SKIP_CACHE(re, &h->gb, 6);
322  level = SHOW_SBITS(re, &h->gb, 8);
323  if (level > 0)
324  level = level * qmul + qadd;
325  else if (level < 0)
326  level = level * qmul - qadd;
327  SKIP_COUNTER(re, &h->gb, 6 + 8);
328  } else if (level == 0) {
329  break;
330  } else {
331  level = level * qmul + qadd;
332  if (SHOW_UBITS(re, &h->gb, 1))
333  level = -level;
334  SKIP_COUNTER(re, &h->gb, 1);
335  }
336  i += run;
337  if (i >= 64) {
338  CLOSE_READER(re, &h->gb);
339  av_log(s->avctx, AV_LOG_ERROR, "run overflow at %dx%d\n",
340  s->mb_x, s->mb_y);
341  return -1;
342  }
343  j = scan_table[i];
344  block[j] = level;
345  }
346  CLOSE_READER(re, &h->gb);
347  }
348  s->block_last_index[n] = i;
349  return 0;
350 }
351 
353 {
354  MpegEncContext *const s = &h->s;
355  H261Context *const com = &h->common;
356  int i, cbp, xy;
357 
358  cbp = 63;
359  // Read mba
360  do {
361  h->mba_diff = get_vlc2(&h->gb, h261_mba_vlc,
362  H261_MBA_VLC_BITS, 2);
363 
364  /* Check for slice end */
365  /* NOTE: GOB can be empty (no MB data) or exist only of MBA_stuffing */
366  if (h->mba_diff == MBA_STARTCODE) { // start code
367  h->gob_start_code_skipped = 1;
368  return SLICE_END;
369  }
370  } while (h->mba_diff == MBA_STUFFING); // stuffing
371 
372  if (h->mba_diff < 0) {
373  if (get_bits_left(&h->gb) <= 7)
374  return SLICE_END;
375 
376  av_log(s->avctx, AV_LOG_ERROR, "illegal mba at %d %d\n", s->mb_x, s->mb_y);
377  return SLICE_ERROR;
378  }
379 
380  h->mba_diff += 1;
381  h->current_mba += h->mba_diff;
382 
383  if (h->current_mba > MBA_STUFFING)
384  return SLICE_ERROR;
385 
386  s->mb_x = ((h->gob_number - 1) % 2) * 11 + ((h->current_mba - 1) % 11);
387  s->mb_y = ((h->gob_number - 1) / 2) * 3 + ((h->current_mba - 1) / 11);
388  xy = s->mb_x + s->mb_y * s->mb_stride;
389  h261_init_dest(s);
390 
391  // Read mtype
393  if (com->mtype < 0) {
394  av_log(s->avctx, AV_LOG_ERROR, "Invalid mtype index\n");
395  return SLICE_ERROR;
396  }
397 
398  // Read mquant
399  if (IS_QUANT(com->mtype)) {
400  s->qscale = get_bits(&h->gb, 5);
401  if (!s->qscale)
402  s->qscale = 1;
403  }
404 
405  s->mb_intra = IS_INTRA4x4(com->mtype);
406 
407  // Read mv
408  if (IS_16X16(com->mtype)) {
409  /* Motion vector data is included for all MC macroblocks. MVD is
410  * obtained from the macroblock vector by subtracting the vector
411  * of the preceding macroblock. For this calculation the vector
412  * of the preceding macroblock is regarded as zero in the
413  * following three situations:
414  * 1) evaluating MVD for macroblocks 1, 12 and 23;
415  * 2) evaluating MVD for macroblocks in which MBA does not represent a difference of 1;
416  * 3) MTYPE of the previous macroblock was not MC. */
417  if ((h->current_mba == 1) || (h->current_mba == 12) ||
418  (h->current_mba == 23) || (h->mba_diff != 1)) {
419  h->current_mv_x = 0;
420  h->current_mv_y = 0;
421  }
422 
423  h->current_mv_x = decode_mv_component(&h->gb, h->current_mv_x);
424  h->current_mv_y = decode_mv_component(&h->gb, h->current_mv_y);
425  } else {
426  h->current_mv_x = 0;
427  h->current_mv_y = 0;
428  }
429 
430  // Read cbp
431  if (HAS_CBP(com->mtype))
432  cbp = get_vlc2(&h->gb, h261_cbp_vlc, H261_CBP_VLC_BITS, 1) + 1;
433 
434  if (s->mb_intra) {
435  s->cur_pic.mb_type[xy] = MB_TYPE_INTRA;
436  goto intra;
437  }
438 
439  //set motion vectors
440  s->mv_dir = MV_DIR_FORWARD;
441  s->mv_type = MV_TYPE_16X16;
442  s->cur_pic.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_FORWARD_MV;
443  s->mv[0][0][0] = h->current_mv_x * 2; // gets divided by 2 in motion compensation
444  s->mv[0][0][1] = h->current_mv_y * 2;
445 
446  if (s->cur_pic.motion_val[0]) {
447  int b_stride = 2*s->mb_width + 1;
448  int b_xy = 2 * s->mb_x + (2 * s->mb_y) * b_stride;
449  s->cur_pic.motion_val[0][b_xy][0] = s->mv[0][0][0];
450  s->cur_pic.motion_val[0][b_xy][1] = s->mv[0][0][1];
451  }
452 
453 intra:
454  /* decode each block */
455  if (s->mb_intra || HAS_CBP(com->mtype)) {
456  s->bdsp.clear_blocks(h->block[0]);
457  for (i = 0; i < 6; i++) {
458  if (h261_decode_block(h, h->block[i], i, cbp & 32) < 0)
459  return SLICE_ERROR;
460  cbp += cbp;
461  }
462  } else {
463  for (i = 0; i < 6; i++)
464  s->block_last_index[i] = -1;
465  }
466 
467  ff_mpv_reconstruct_mb(s, h->block);
468 
469  return SLICE_OK;
470 }
471 
472 /**
473  * Decode the H.261 picture header.
474  * @return <0 if no startcode found
475  */
476 static int h261_decode_picture_header(H261DecContext *h, int *is_key)
477 {
478  MpegEncContext *const s = &h->s;
479  uint32_t startcode = 0;
480 
481  for (int i = get_bits_left(&h->gb); i > 24; i -= 1) {
482  startcode = ((startcode << 1) | get_bits(&h->gb, 1)) & 0x000FFFFF;
483 
484  if (startcode == 0x10)
485  break;
486  }
487 
488  if (startcode != 0x10) {
489  av_log(s->avctx, AV_LOG_ERROR, "Bad picture start code\n");
490  return -1;
491  }
492 
493  /* temporal reference */
494  skip_bits(&h->gb, 5); /* picture timestamp */
495 
496  /* PTYPE starts here */
497  skip_bits1(&h->gb); /* split screen off */
498  skip_bits1(&h->gb); /* camera off */
499  *is_key = get_bits1(&h->gb); /* freeze picture release off */
500 
501  int format = get_bits1(&h->gb);
502 
503  // only 2 formats possible
504  if (format == 0) { // QCIF
505  s->width = 176;
506  s->height = 144;
507  } else { // CIF
508  s->width = 352;
509  s->height = 288;
510  }
511 
512  skip_bits1(&h->gb); /* still image mode off */
513  skip_bits1(&h->gb); /* Reserved */
514 
515  /* PEI */
516  if (skip_1stop_8data_bits(&h->gb) < 0)
517  return AVERROR_INVALIDDATA;
518 
519  h->gob_number = 0;
520  return 0;
521 }
522 
524 {
525  MpegEncContext *const s = &h->s;
526 
527  /* decode mb's */
528  while (h->current_mba <= MBA_STUFFING) {
529  int ret;
530  /* DCT & quantize */
531  ret = h261_decode_mb(h);
532  if (ret < 0) {
533  if (ret == SLICE_END) {
534  h261_decode_mb_skipped(h, h->current_mba, 33);
535  return 0;
536  }
537  av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n",
538  s->mb_x + s->mb_y * s->mb_stride);
539  return -1;
540  }
541 
543  h->current_mba - h->mba_diff,
544  h->current_mba - 1);
545  }
546 
547  return -1;
548 }
549 
550 static int h261_decode_frame(AVCodecContext *avctx, AVFrame *pict,
551  int *got_frame, AVPacket *avpkt)
552 {
553  H261DecContext *const h = avctx->priv_data;
554  const uint8_t *buf = avpkt->data;
555  int buf_size = avpkt->size;
556  MpegEncContext *s = &h->s;
557  int ret, is_key;
558 
559  ff_dlog(avctx, "*****frame %"PRId64" size=%d\n", avctx->frame_num, buf_size);
560  ff_dlog(avctx, "bytes=%x %x %x %x\n", buf[0], buf[1], buf[2], buf[3]);
561 
562  h->gob_start_code_skipped = 0;
563 
564  init_get_bits(&h->gb, buf, buf_size * 8);
565 
566  ret = h261_decode_picture_header(h, &is_key);
567 
568  /* skip if the header was thrashed */
569  if (ret < 0) {
570  av_log(s->avctx, AV_LOG_ERROR, "header damaged\n");
571  return -1;
572  }
573 
574  if (s->width != avctx->coded_width || s->height != avctx->coded_height) {
576  }
577 
578  if (!s->context_initialized) {
579  if ((ret = ff_mpv_common_init(s)) < 0)
580  return ret;
581 
582  ret = ff_set_dimensions(avctx, s->width, s->height);
583  if (ret < 0)
584  return ret;
585  }
586 
587  if ((avctx->skip_frame >= AVDISCARD_NONINTRA && !is_key) ||
588  avctx->skip_frame >= AVDISCARD_ALL)
589  return buf_size;
590 
591  if (ff_mpv_frame_start(s, avctx) < 0)
592  return -1;
593 
595 
596  /* decode each macroblock */
597  s->mb_x = 0;
598  s->mb_y = 0;
599 
600  while (h->gob_number < (s->mb_height == 18 ? 12 : 5)) {
601  if (h261_decode_gob_header(h) < 0)
602  break;
604  }
606 
607  if (is_key) {
608  s->cur_pic.ptr->f->pict_type = AV_PICTURE_TYPE_I;
609  s->cur_pic.ptr->f->flags |= AV_FRAME_FLAG_KEY;
610  }
611 
612  if ((ret = av_frame_ref(pict, s->cur_pic.ptr->f)) < 0)
613  return ret;
614  ff_print_debug_info(s, s->cur_pic.ptr, pict);
615 
616  *got_frame = 1;
617 
618  return buf_size;
619 }
620 
622  .p.name = "h261",
623  CODEC_LONG_NAME("H.261"),
624  .p.type = AVMEDIA_TYPE_VIDEO,
625  .p.id = AV_CODEC_ID_H261,
626  .priv_data_size = sizeof(H261DecContext),
629  .close = ff_mpv_decode_close,
630  .p.capabilities = AV_CODEC_CAP_DR1,
631  .p.max_lowres = 3,
632  .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM,
633 };
ff_mpv_common_init
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
Definition: mpegvideo.c:378
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:175
H261_MV_VLC_BITS
#define H261_MV_VLC_BITS
Definition: h261dec.c:46
level
uint8_t level
Definition: svq3.c:208
MBA_STARTCODE
#define MBA_STARTCODE
Definition: h261dec.c:50
h261_decode_mb
static int h261_decode_mb(H261DecContext *h)
Definition: h261dec.c:352
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
mem_internal.h
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:47
h261_cbp_vlc
static VLCElem h261_cbp_vlc[512]
Definition: h261dec.c:55
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:421
h261_decode_init_static
static av_cold void h261_decode_init_static(void)
Definition: h261dec.c:74
H261DecContext::current_mv_x
int current_mv_x
Definition: h261dec.c:66
AVPacket::data
uint8_t * data
Definition: packet.h:552
H261_MBA_VLC_BITS
#define H261_MBA_VLC_BITS
Definition: h261dec.c:44
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:491
mpegvideo.h
UPDATE_CACHE
#define UPDATE_CACHE(name, gb)
Definition: get_bits.h:208
FMT_H261
@ FMT_H261
Definition: mpegvideo.h:54
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:135
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:551
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:49
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
h261_decode_picture_header
static int h261_decode_picture_header(H261DecContext *h, int *is_key)
Decode the H.261 picture header.
Definition: h261dec.c:476
AVCodecContext::skip_frame
enum AVDiscard skip_frame
Skip decoding for selected frames.
Definition: avcodec.h:1662
SLICE_OK
#define SLICE_OK
Definition: h261dec.c:40
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:607
HAS_CBP
#define HAS_CBP(a)
Definition: mpegutils.h:87
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:210
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
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:636
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
H261DecContext::gb
GetBitContext gb
Definition: h261dec.c:60
h261_decode_init
static av_cold int h261_decode_init(AVCodecContext *avctx)
Definition: h261dec.c:92
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
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:253
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:46
decode.h
get_bits.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:447
if
if(ret)
Definition: filter_design.txt:179
AVDISCARD_ALL
@ AVDISCARD_ALL
discard all
Definition: defs.h:229
AV_ONCE_INIT
#define AV_ONCE_INIT
Definition: thread.h:203
format
New swscale design to change SwsGraph is what coordinates multiple passes These can include cascaded scaling error diffusion and so on Or we could have separate passes for the vertical and horizontal scaling In between each SwsPass lies a fully allocated image buffer Graph passes may have different levels of e g we can have a single threaded error diffusion pass following a multi threaded scaling pass SwsGraph is internally recreated whenever the image format
Definition: swscale-v2.txt:14
run
uint8_t run
Definition: svq3.c:207
H261DecContext::common
H261Context common
Definition: h261dec.c:62
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:125
H261DecContext::current_mv_y
int current_mv_y
Definition: h261dec.c:67
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:278
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:69
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:53
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:28
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:553
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:276
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:306
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:190
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:45
h261_init_dest
static void h261_init_dest(MpegEncContext *s)
Definition: h261dec.c:122
h261_decode_frame
static int h261_decode_frame(AVCodecContext *avctx, AVFrame *pict, int *got_frame, AVPacket *avpkt)
Definition: h261dec.c:550
ff_print_debug_info
void ff_print_debug_info(const MpegEncContext *s, const MPVPicture *p, AVFrame *pict)
Definition: mpegvideo_dec.c:365
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
AVDISCARD_NONINTRA
@ AVDISCARD_NONINTRA
discard all non intra frames
Definition: defs.h:227
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:179
H261DecContext::current_mba
int current_mba
Definition: h261dec.c:64
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:631
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:621
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:1878
ret
ret
Definition: filter_design.txt:187
h261_mba_vlc
static VLCElem h261_mba_vlc[540]
Definition: h261dec.c:52
h261_mv_vlc
static VLCElem h261_mv_vlc[144]
Definition: h261dec.c:54
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:431
SLICE_ERROR
#define SLICE_ERROR
Definition: h261dec.c:41
SHOW_UBITS
#define SHOW_UBITS(name, gb, num)
Definition: get_bits.h:242
SLICE_END
#define SLICE_END
end marker found
Definition: h261dec.c:42
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:65
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:357
AVCodecContext::coded_width
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:607
h261_decode_gob
static int h261_decode_gob(H261DecContext *h)
Definition: h261dec.c:523
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:279
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:200
ff_mpv_reconstruct_mb
void ff_mpv_reconstruct_mb(MPVContext *s, int16_t block[][64])
Definition: mpegvideo_dec.c:1083
H261DecContext::gob_number
int gob_number
Definition: h261dec.c:68
MV_DIR_FORWARD
#define MV_DIR_FORWARD
Definition: mpegvideo.h:171
AVPacket
This structure stores compressed data.
Definition: packet.h:529
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:458
decode_mv_component
static int decode_mv_component(GetBitContext *gb, int v)
Definition: h261dec.c:229
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
H261DecContext::DECLARE_ALIGNED_32
DECLARE_ALIGNED_32(int16_t, block)[6][64]
ff_h261_mba_bits
const uint8_t ff_h261_mba_bits[35]
Definition: h261data.c:48
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:63
H261DecContext
Definition: h261dec.c:57
MB_TYPE_FORWARD_MV
#define MB_TYPE_FORWARD_MV
Definition: mpegutils.h:49
TCOEFF_VLC_BITS
#define TCOEFF_VLC_BITS
Definition: h261dec.c:48
H261DecContext::s
MpegEncContext s
Definition: h261dec.c:58
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