FFmpeg
mpegvideo.c
Go to the documentation of this file.
1 /*
2  * The simplest mpeg encoder (well, it was the simplest!)
3  * Copyright (c) 2000,2001 Fabrice Bellard
4  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5  *
6  * 4MV & hq & B-frame encoding stuff by Michael Niedermayer <michaelni@gmx.at>
7  *
8  * This file is part of FFmpeg.
9  *
10  * FFmpeg is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License as published by the Free Software Foundation; either
13  * version 2.1 of the License, or (at your option) any later version.
14  *
15  * FFmpeg is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  * Lesser General Public License for more details.
19  *
20  * You should have received a copy of the GNU Lesser General Public
21  * License along with FFmpeg; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23  */
24 
25 /**
26  * @file
27  * The simplest mpeg encoder (well, it was the simplest!).
28  */
29 
30 #include "libavutil/attributes.h"
31 #include "libavutil/avassert.h"
32 #include "libavutil/imgutils.h"
33 #include "libavutil/internal.h"
34 #include "libavutil/mem.h"
35 
36 #include "avcodec.h"
37 #include "blockdsp.h"
38 #include "idctdsp.h"
39 #include "mathops.h"
40 #include "mpeg_er.h"
41 #include "mpegutils.h"
42 #include "mpegvideo.h"
43 #include "mpegvideodata.h"
44 #include "mpegvideo_unquantize.h"
45 #include "libavutil/refstruct.h"
46 
47 
48 static void gray16(uint8_t *dst, const uint8_t *src, ptrdiff_t linesize, int h)
49 {
50  while(h--)
51  memset(dst + h*linesize, 128, 16);
52 }
53 
54 static void gray8(uint8_t *dst, const uint8_t *src, ptrdiff_t linesize, int h)
55 {
56  while(h--)
57  memset(dst + h*linesize, 128, 8);
58 }
59 
60 /* init common dct for both encoder and decoder */
62 {
63  ff_blockdsp_init(&s->bdsp);
64  ff_hpeldsp_init(&s->hdsp, s->avctx->flags);
65  ff_videodsp_init(&s->vdsp, s->avctx->bits_per_raw_sample);
66 
67  if (s->avctx->debug & FF_DEBUG_NOMC) {
68  int i;
69  for (i=0; i<4; i++) {
70  s->hdsp.avg_pixels_tab[0][i] = gray16;
71  s->hdsp.put_pixels_tab[0][i] = gray16;
72  s->hdsp.put_no_rnd_pixels_tab[0][i] = gray16;
73 
74  s->hdsp.avg_pixels_tab[1][i] = gray8;
75  s->hdsp.put_pixels_tab[1][i] = gray8;
76  s->hdsp.put_no_rnd_pixels_tab[1][i] = gray8;
77  }
78  }
79 }
80 
81 av_cold void ff_init_scantable(const uint8_t *permutation, ScanTable *st,
82  const uint8_t *src_scantable)
83 {
84  st->scantable = src_scantable;
85 
86  for (int i = 0, end = -1; i < 64; i++) {
87  int j = src_scantable[i];
88  st->permutated[i] = permutation[j];
89  if (permutation[j] > end)
90  end = permutation[j];
91  st->raster_end[i] = end;
92  }
93 }
94 
96 {
97  if (s->codec_id == AV_CODEC_ID_MPEG4)
98  s->idsp.mpeg4_studio_profile = s->studio_profile;
99  ff_idctdsp_init(&s->idsp, s->avctx);
100 
101  /* load & permutate scantables
102  * note: only wmv uses different ones
103  */
104  if (s->alternate_scan) {
105  ff_init_scantable(s->idsp.idct_permutation, &s->inter_scantable, ff_alternate_vertical_scan);
106  ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_alternate_vertical_scan);
107  } else {
108  ff_init_scantable(s->idsp.idct_permutation, &s->inter_scantable, ff_zigzag_direct);
109  ff_init_scantable(s->idsp.idct_permutation, &s->intra_scantable, ff_zigzag_direct);
110  }
111  ff_permute_scantable(s->permutated_intra_h_scantable, ff_alternate_horizontal_scan,
112  s->idsp.idct_permutation);
113  ff_permute_scantable(s->permutated_intra_v_scantable, ff_alternate_vertical_scan,
114  s->idsp.idct_permutation);
115 }
116 
118 {
119  if (!FF_ALLOCZ_TYPED_ARRAY(s->blocks, 1 + s->encoding))
120  return AVERROR(ENOMEM);
121  s->block = s->blocks[0];
122 
123  if (s->out_format == FMT_H263) {
124  int mb_height = s->msmpeg4_version == MSMP4_VC1 ?
125  FFALIGN(s->mb_height, 2) : s->mb_height;
126  int y_size = s->b8_stride * (2 * mb_height + 1);
127  int c_size = s->mb_stride * (mb_height + 1);
128  int yc_size = y_size + 2 * c_size;
129  /* ac values */
130  if (!FF_ALLOCZ_TYPED_ARRAY(s->ac_val_base, yc_size))
131  return AVERROR(ENOMEM);
132  s->ac_val[0] = s->ac_val_base + s->b8_stride + 1;
133  s->ac_val[1] = s->ac_val_base + y_size + s->mb_stride + 1;
134  s->ac_val[2] = s->ac_val[1] + c_size;
135  }
136 
137  return 0;
138 }
139 
141 {
142  int nb_slices = s->slice_context_count, ret;
143  size_t slice_size = s->slice_ctx_size ? s->slice_ctx_size : sizeof(*s);
144 
145  s->parent = s;
146 
147  /* We initialize the copies before the original so that
148  * fields allocated in init_duplicate_context are NULL after
149  * copying. This prevents double-frees upon allocation error. */
150  for (int i = 1; i < nb_slices; i++) {
151  s->thread_context[i] = av_memdup(s, slice_size);
152  if (!s->thread_context[i])
153  return AVERROR(ENOMEM);
154  if ((ret = init_duplicate_context(s->thread_context[i])) < 0)
155  return ret;
156  s->thread_context[i]->start_mb_y =
157  (s->mb_height * (i ) + nb_slices / 2) / nb_slices;
158  s->thread_context[i]->end_mb_y =
159  (s->mb_height * (i + 1) + nb_slices / 2) / nb_slices;
160  }
161  s->start_mb_y = 0;
162  s->end_mb_y = nb_slices > 1 ? (s->mb_height + nb_slices / 2) / nb_slices
163  : s->mb_height;
164  return init_duplicate_context(s);
165 }
166 
168 {
169  if (!s)
170  return;
171 
172  av_freep(&s->sc.edge_emu_buffer);
173  av_freep(&s->sc.scratchpad_buf);
174  s->sc.obmc_scratchpad = NULL;
175  s->sc.linesize = 0;
176 
177  av_freep(&s->blocks);
178  av_freep(&s->ac_val_base);
179  s->block = NULL;
180 }
181 
183 {
184  for (int i = 1; i < s->slice_context_count; i++) {
185  free_duplicate_context(s->thread_context[i]);
186  av_freep(&s->thread_context[i]);
187  }
189 }
190 
192 {
193 #define COPY(a) bak->a = src->a
194  COPY(sc);
195  COPY(blocks);
196  COPY(block);
197  COPY(start_mb_y);
198  COPY(end_mb_y);
199  COPY(ac_val_base);
200  COPY(ac_val[0]);
201  COPY(ac_val[1]);
202  COPY(ac_val[2]);
203 #undef COPY
204 }
205 
207 {
208  MpegEncContext bak;
209  int ret;
210  // FIXME copy only needed parts
212  memcpy(dst, src, sizeof(MpegEncContext));
214 
215  ret = ff_mpv_framesize_alloc(dst->avctx, &dst->sc, dst->linesize);
216  if (ret < 0) {
217  av_log(dst->avctx, AV_LOG_ERROR, "failed to allocate context "
218  "scratch buffers.\n");
219  return ret;
220  }
221  return 0;
222 }
223 
224 /**
225  * Set the given MpegEncContext to common defaults
226  * (same for encoding and decoding).
227  * The changed fields will not depend upon the
228  * prior state of the MpegEncContext.
229  */
231 {
232  s->chroma_qscale_table = ff_default_chroma_qscale_table;
233  s->progressive_frame = 1;
234  s->progressive_sequence = 1;
235  s->picture_structure = PICT_FRAME;
236 
237  s->picture_number = 0;
238 
239  s->slice_context_count = 1;
240 }
241 
243 {
249  pools->alloc_mb_height = pools->alloc_mb_width = pools->alloc_mb_stride = 0;
250 }
251 
253 {
254  BufferPoolContext *const pools = &s->buffer_pools;
255  int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y;
256  int mb_height;
257 
258  if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO && !s->progressive_sequence)
259  s->mb_height = (s->height + 31) / 32 * 2;
260  else
261  s->mb_height = (s->height + 15) / 16;
262 
263  /* VC-1 can change from being progressive to interlaced on a per-frame
264  * basis. We therefore allocate certain buffers so big that they work
265  * in both instances. */
266  mb_height = s->msmpeg4_version == MSMP4_VC1 ?
267  FFALIGN(s->mb_height, 2) : s->mb_height;
268 
269  s->mb_width = (s->width + 15) / 16;
270  s->mb_stride = s->mb_width + 1;
271  s->b8_stride = s->mb_width * 2 + 1;
272  mb_array_size = mb_height * s->mb_stride;
273  mv_table_size = (mb_height + 2) * s->mb_stride + 1;
274 
275  /* set default edge pos, will be overridden
276  * in decode_header if needed */
277  s->h_edge_pos = s->mb_width * 16;
278  s->v_edge_pos = s->mb_height * 16;
279 
280  s->mb_num = s->mb_width * s->mb_height;
281 
282  s->block_wrap[0] =
283  s->block_wrap[1] =
284  s->block_wrap[2] =
285  s->block_wrap[3] = s->b8_stride;
286  s->block_wrap[4] =
287  s->block_wrap[5] = s->mb_stride;
288 
289  y_size = s->b8_stride * (2 * mb_height + 1);
290  c_size = s->mb_stride * (mb_height + 1);
291  yc_size = y_size + 2 * c_size;
292 
293  if (!FF_ALLOCZ_TYPED_ARRAY(s->mb_index2xy, s->mb_num + 1))
294  return AVERROR(ENOMEM);
295  for (y = 0; y < s->mb_height; y++)
296  for (x = 0; x < s->mb_width; x++)
297  s->mb_index2xy[x + y * s->mb_width] = x + y * s->mb_stride;
298 
299  s->mb_index2xy[s->mb_height * s->mb_width] = (s->mb_height - 1) * s->mb_stride + s->mb_width; // FIXME really needed?
300 
301 #define ALLOC_POOL(name, size, flags) do { \
302  pools->name ##_pool = av_refstruct_pool_alloc((size), (flags)); \
303  if (!pools->name ##_pool) \
304  return AVERROR(ENOMEM); \
305 } while (0)
306 
307  if (s->codec_id == AV_CODEC_ID_MPEG4 ||
308  (s->avctx->flags & AV_CODEC_FLAG_INTERLACED_ME)) {
309  /* interlaced direct mode decoding tables */
310  int16_t (*tmp)[2] = av_calloc(mv_table_size, 4 * sizeof(*tmp));
311  if (!tmp)
312  return AVERROR(ENOMEM);
313  s->p_field_mv_table_base = tmp;
314  tmp += s->mb_stride + 1;
315  for (int i = 0; i < 2; i++) {
316  for (int j = 0; j < 2; j++) {
317  s->p_field_mv_table[i][j] = tmp;
318  tmp += mv_table_size;
319  }
320  }
321  if (s->codec_id == AV_CODEC_ID_MPEG4) {
322  ALLOC_POOL(mbskip_table, mb_array_size + 2,
323  !s->encoding ? AV_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME : 0);
324  if (!s->encoding) {
325  /* cbp, pred_dir */
326  if (!(s->cbp_table = av_mallocz(mb_array_size)) ||
327  !(s->pred_dir_table = av_mallocz(mb_array_size)))
328  return AVERROR(ENOMEM);
329  }
330  }
331  }
332 
333  if (s->msmpeg4_version >= MSMP4_V3) {
334  s->coded_block_base = av_mallocz(y_size);
335  if (!s->coded_block_base)
336  return AVERROR(ENOMEM);
337  s->coded_block = s->coded_block_base + s->b8_stride + 1;
338  }
339 
340  if (s->h263_pred || s->h263_plus || !s->encoding) {
341  /* dc values */
342  // MN: we need these for error resilience of intra-frames
343  if (!FF_ALLOCZ_TYPED_ARRAY(s->dc_val_base, yc_size))
344  return AVERROR(ENOMEM);
345  s->dc_val[0] = s->dc_val_base + s->b8_stride + 1;
346  s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1;
347  s->dc_val[2] = s->dc_val[1] + c_size;
348  for (i = 0; i < yc_size; i++)
349  s->dc_val_base[i] = 1024;
350  }
351 
352  // Note the + 1 is for a quicker MPEG-4 slice_end detection
353  if (!(s->mbskip_table = av_mallocz(mb_array_size + 2)) ||
354  /* which mb is an intra block, init macroblock skip table */
355  !(s->mbintra_table = av_malloc(mb_array_size)))
356  return AVERROR(ENOMEM);
357  memset(s->mbintra_table, 1, mb_array_size);
358 
359  ALLOC_POOL(qscale_table, mv_table_size, 0);
360  ALLOC_POOL(mb_type, mv_table_size * sizeof(uint32_t), 0);
361 
362  if (s->out_format == FMT_H263 || s->encoding ||
363  (s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_MVS)) {
364  const int b8_array_size = s->b8_stride * mb_height * 2;
365  int mv_size = 2 * (b8_array_size + 4) * sizeof(int16_t);
366  int ref_index_size = 4 * mb_array_size;
367 
368  /* FIXME: The output of H.263 with OBMC depends upon
369  * the earlier content of the buffer; therefore we set
370  * the flags to always reset returned buffers here. */
372  ALLOC_POOL(ref_index, ref_index_size, 0);
373  }
374 #undef ALLOC_POOL
375  pools->alloc_mb_width = s->mb_width;
376  pools->alloc_mb_height = mb_height;
377  pools->alloc_mb_stride = s->mb_stride;
378 
379  return !CONFIG_MPEGVIDEODEC || s->encoding ? 0 : ff_mpeg_er_init(s);
380 }
381 
383 {
384  memset(&s->buffer_pools, 0, sizeof(s->buffer_pools));
385  memset(&s->next_pic, 0, sizeof(s->next_pic));
386  memset(&s->last_pic, 0, sizeof(s->last_pic));
387  memset(&s->cur_pic, 0, sizeof(s->cur_pic));
388 
389  memset(s->thread_context, 0, sizeof(s->thread_context));
390 
391  s->block = NULL;
392  s->blocks = NULL;
393  s->ac_val_base = NULL;
394  s->ac_val[0] =
395  s->ac_val[1] =
396  s->ac_val[2] =NULL;
397  memset(&s->sc, 0, sizeof(s->sc));
398 
399 
400  s->p_field_mv_table_base = NULL;
401  for (int i = 0; i < 2; i++)
402  for (int j = 0; j < 2; j++)
403  s->p_field_mv_table[i][j] = NULL;
404 
405  s->dc_val_base = NULL;
406  s->coded_block_base = NULL;
407  s->mbintra_table = NULL;
408  s->cbp_table = NULL;
409  s->pred_dir_table = NULL;
410 
411  s->mbskip_table = NULL;
412 
413  s->er.error_status_table = NULL;
414  s->er.er_temp_buffer = NULL;
415  s->mb_index2xy = NULL;
416 }
417 
418 /**
419  * init common structure for both encoder and decoder.
420  * this assumes that some variables like width/height are already set
421  */
423 {
424  int nb_slices = (HAVE_THREADS &&
425  s->avctx->active_thread_type & FF_THREAD_SLICE) ?
426  s->avctx->thread_count : 1;
427  int ret;
428 
429  clear_context(s);
430 
431  if (s->encoding && s->avctx->slices)
432  nb_slices = s->avctx->slices;
433 
434  if (s->avctx->pix_fmt == AV_PIX_FMT_NONE) {
435  av_log(s->avctx, AV_LOG_ERROR,
436  "decoding to AV_PIX_FMT_NONE is not supported.\n");
437  return AVERROR(EINVAL);
438  }
439 
440  if ((s->width || s->height) &&
441  av_image_check_size(s->width, s->height, 0, s->avctx))
442  return AVERROR(EINVAL);
443 
444  dsp_init(s);
445 
446  /* set chroma shifts */
447  ret = av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt,
448  &s->chroma_x_shift,
449  &s->chroma_y_shift);
450  if (ret)
451  return ret;
452 
454  goto fail;
455 
456  if (nb_slices > MAX_THREADS || (nb_slices > s->mb_height && s->mb_height)) {
457  int max_slices;
458  if (s->mb_height)
459  max_slices = FFMIN(MAX_THREADS, s->mb_height);
460  else
461  max_slices = MAX_THREADS;
462  av_log(s->avctx, AV_LOG_WARNING, "too many threads/slices (%d),"
463  " reducing to %d\n", nb_slices, max_slices);
464  nb_slices = max_slices;
465  }
466 
467  s->context_initialized = 1;
468  memset(s->thread_context, 0, sizeof(s->thread_context));
469  s->thread_context[0] = s;
470  s->slice_context_count = nb_slices;
471 
472 // if (s->width && s->height) {
474  if (ret < 0)
475  goto fail;
476 // }
477 
478  return 0;
479  fail:
481  return ret;
482 }
483 
485 {
487 
488  free_buffer_pools(&s->buffer_pools);
489  av_freep(&s->p_field_mv_table_base);
490  for (int i = 0; i < 2; i++)
491  for (int j = 0; j < 2; j++)
492  s->p_field_mv_table[i][j] = NULL;
493 
494  av_freep(&s->dc_val_base);
495  av_freep(&s->coded_block_base);
496  av_freep(&s->mbintra_table);
497  av_freep(&s->cbp_table);
498  av_freep(&s->pred_dir_table);
499 
500  av_freep(&s->mbskip_table);
501 
502  av_freep(&s->er.error_status_table);
503  av_freep(&s->er.er_temp_buffer);
504  av_freep(&s->mb_index2xy);
505 
506  s->linesize = s->uvlinesize = 0;
507 }
508 
510 {
512  if (s->slice_context_count > 1)
513  s->slice_context_count = 1;
514 
515  ff_mpv_unref_picture(&s->last_pic);
516  ff_mpv_unref_picture(&s->cur_pic);
517  ff_mpv_unref_picture(&s->next_pic);
518 
519  s->context_initialized = 0;
520  s->context_reinit = 0;
521  s->linesize = s->uvlinesize = 0;
522 }
523 
524 
525 /**
526  * Clean dc, ac for the current non-intra MB.
527  */
529 {
530  int wrap = s->b8_stride;
531  int xy = s->block_index[0];
532 
533  s->dc_val[0][xy ] =
534  s->dc_val[0][xy + 1 ] =
535  s->dc_val[0][xy + wrap] =
536  s->dc_val[0][xy + 1 + wrap] = 1024;
537  /* ac pred */
538  memset(s->ac_val[0][xy ], 0, 32 * sizeof(int16_t));
539  memset(s->ac_val[0][xy + wrap], 0, 32 * sizeof(int16_t));
540  /* chroma */
541  wrap = s->mb_stride;
542  xy = s->mb_x + s->mb_y * wrap;
543  s->dc_val[1][xy] =
544  s->dc_val[2][xy] = 1024;
545  /* ac pred */
546  memset(s->ac_val[1][xy], 0, 16 * sizeof(int16_t));
547  memset(s->ac_val[2][xy], 0, 16 * sizeof(int16_t));
548 
549  s->mbintra_table[xy]= 0;
550 }
551 
552 void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename
553  const int linesize = s->cur_pic.linesize[0]; //not s->linesize as this would be wrong for field pics
554  const int uvlinesize = s->cur_pic.linesize[1];
555  const int width_of_mb = (4 + (s->avctx->bits_per_raw_sample > 8)) - s->avctx->lowres;
556  const int height_of_mb = 4 - s->avctx->lowres;
557 
558  s->block_index[0]= s->b8_stride*(s->mb_y*2 ) - 2 + s->mb_x*2;
559  s->block_index[1]= s->b8_stride*(s->mb_y*2 ) - 1 + s->mb_x*2;
560  s->block_index[2]= s->b8_stride*(s->mb_y*2 + 1) - 2 + s->mb_x*2;
561  s->block_index[3]= s->b8_stride*(s->mb_y*2 + 1) - 1 + s->mb_x*2;
562  s->block_index[4]= s->mb_stride*(s->mb_y + 1) + s->b8_stride*s->mb_height*2 + s->mb_x - 1;
563  s->block_index[5]= s->mb_stride*(s->mb_y + s->mb_height + 2) + s->b8_stride*s->mb_height*2 + s->mb_x - 1;
564  //block_index is not used by mpeg2, so it is not affected by chroma_format
565 
566  s->dest[0] = s->cur_pic.data[0] + (int)((s->mb_x - 1U) << width_of_mb);
567  s->dest[1] = s->cur_pic.data[1] + (int)((s->mb_x - 1U) << (width_of_mb - s->chroma_x_shift));
568  s->dest[2] = s->cur_pic.data[2] + (int)((s->mb_x - 1U) << (width_of_mb - s->chroma_x_shift));
569 
570  if (s->picture_structure == PICT_FRAME) {
571  s->dest[0] += s->mb_y * linesize << height_of_mb;
572  s->dest[1] += s->mb_y * uvlinesize << (height_of_mb - s->chroma_y_shift);
573  s->dest[2] += s->mb_y * uvlinesize << (height_of_mb - s->chroma_y_shift);
574  } else {
575  s->dest[0] += (s->mb_y>>1) * linesize << height_of_mb;
576  s->dest[1] += (s->mb_y>>1) * uvlinesize << (height_of_mb - s->chroma_y_shift);
577  s->dest[2] += (s->mb_y>>1) * uvlinesize << (height_of_mb - s->chroma_y_shift);
578  av_assert1((s->mb_y&1) == (s->picture_structure == PICT_BOTTOM_FIELD));
579  }
580 }
581 
582 /**
583  * set qscale and update qscale dependent variables.
584  */
585 void ff_set_qscale(MpegEncContext * s, int qscale)
586 {
587  if (qscale < 1)
588  qscale = 1;
589  else if (qscale > 31)
590  qscale = 31;
591 
592  s->qscale = qscale;
593  s->chroma_qscale= s->chroma_qscale_table[qscale];
594 
595  s->y_dc_scale= s->y_dc_scale_table[ qscale ];
596  s->c_dc_scale= s->c_dc_scale_table[ s->chroma_qscale ];
597 }
FF_ALLOCZ_TYPED_ARRAY
#define FF_ALLOCZ_TYPED_ARRAY(p, nelem)
Definition: internal.h:78
PICT_FRAME
#define PICT_FRAME
Definition: mpegutils.h:33
ff_mpv_common_init
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
Definition: mpegvideo.c:422
mpegvideo_unquantize.h
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:215
BufferPoolContext::ref_index_pool
struct AVRefStructPool * ref_index_pool
Definition: mpegpicture.h:49
blockdsp.h
AVERROR
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 they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
BufferPoolContext::mbskip_table_pool
struct AVRefStructPool * mbskip_table_pool
Definition: mpegpicture.h:45
ff_mpv_init_duplicate_contexts
av_cold int ff_mpv_init_duplicate_contexts(MpegEncContext *s)
Initialize an MpegEncContext's thread contexts.
Definition: mpegvideo.c:140
backup_duplicate_context
static void backup_duplicate_context(MpegEncContext *bak, MpegEncContext *src)
Definition: mpegvideo.c:191
AV_CODEC_ID_MPEG4
@ AV_CODEC_ID_MPEG4
Definition: codec_id.h:64
ff_update_duplicate_context
int ff_update_duplicate_context(MpegEncContext *dst, const MpegEncContext *src)
Definition: mpegvideo.c:206
ff_clean_intra_table_entries
void ff_clean_intra_table_entries(MpegEncContext *s)
Clean dc, ac for the current non-intra MB.
Definition: mpegvideo.c:528
PICT_BOTTOM_FIELD
#define PICT_BOTTOM_FIELD
Definition: mpegutils.h:32
ff_init_block_index
void ff_init_block_index(MpegEncContext *s)
Definition: mpegvideo.c:552
mpegvideo.h
AV_CODEC_FLAG_INTERLACED_ME
#define AV_CODEC_FLAG_INTERLACED_ME
interlaced motion estimation
Definition: avcodec.h:331
mpegutils.h
ff_idctdsp_init
av_cold void ff_idctdsp_init(IDCTDSPContext *c, AVCodecContext *avctx)
Definition: idctdsp.c:228
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:304
ff_permute_scantable
av_cold void ff_permute_scantable(uint8_t dst[64], const uint8_t src[64], const uint8_t permutation[64])
Definition: idctdsp.c:30
fail
#define fail()
Definition: checkasm.h:194
AV_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME
#define AV_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME
If this flag is set, the entries will be zeroed before being returned to the user (after the init or ...
Definition: refstruct.h:221
wrap
#define wrap(func)
Definition: neontest.h:65
MAX_THREADS
#define MAX_THREADS
Definition: frame_thread_encoder.c:37
av_pix_fmt_get_chroma_sub_sample
int av_pix_fmt_get_chroma_sub_sample(enum AVPixelFormat pix_fmt, int *h_shift, int *v_shift)
Utility function to access log2_chroma_w log2_chroma_h from the pixel format AVPixFmtDescriptor.
Definition: pixdesc.c:3369
ff_videodsp_init
av_cold void ff_videodsp_init(VideoDSPContext *ctx, int bpc)
Definition: videodsp.c:39
refstruct.h
BufferPoolContext::alloc_mb_stride
int alloc_mb_stride
mb_stride used to allocate tables
Definition: mpegpicture.h:52
ff_mpv_init_context_frame
av_cold int ff_mpv_init_context_frame(MpegEncContext *s)
Initialize and allocates MpegEncContext fields dependent on the resolution.
Definition: mpegvideo.c:252
avassert.h
gray16
static void gray16(uint8_t *dst, const uint8_t *src, ptrdiff_t linesize, int h)
Definition: mpegvideo.c:48
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:209
av_cold
#define av_cold
Definition: attributes.h:90
free_buffer_pools
static av_cold void free_buffer_pools(BufferPoolContext *pools)
Definition: mpegvideo.c:242
ff_blockdsp_init
av_cold void ff_blockdsp_init(BlockDSPContext *c)
Definition: blockdsp.c:58
s
#define s(width, name)
Definition: cbs_vp9.c:198
ff_mpv_framesize_alloc
int ff_mpv_framesize_alloc(AVCodecContext *avctx, ScratchpadContext *sc, int linesize)
Definition: mpegpicture.c:138
BufferPoolContext::mb_type_pool
struct AVRefStructPool * mb_type_pool
Definition: mpegpicture.h:47
ALLOC_POOL
#define ALLOC_POOL(name, size, flags)
ScanTable::scantable
const uint8_t * scantable
Definition: mpegvideo.h:48
free_duplicate_contexts
static av_cold void free_duplicate_contexts(MpegEncContext *s)
Definition: mpegvideo.c:182
BufferPoolContext::alloc_mb_height
int alloc_mb_height
mb_height used to allocate tables
Definition: mpegpicture.h:51
ff_hpeldsp_init
av_cold void ff_hpeldsp_init(HpelDSPContext *c, int flags)
Definition: hpeldsp.c:338
FMT_H263
@ FMT_H263
Definition: mpegvideo.h:56
ff_mpv_common_end
av_cold void ff_mpv_common_end(MpegEncContext *s)
Definition: mpegvideo.c:509
ff_mpv_unref_picture
void ff_mpv_unref_picture(MPVWorkPicture *pic)
Definition: mpegpicture.c:98
NULL
#define NULL
Definition: coverity.c:32
tmp
static uint8_t tmp[20]
Definition: aes_ctr.c:47
ff_mpv_idct_init
av_cold void ff_mpv_idct_init(MpegEncContext *s)
Definition: mpegvideo.c:95
ff_mpv_common_defaults
av_cold void ff_mpv_common_defaults(MpegEncContext *s)
Set the given MpegEncContext to common defaults (same for encoding and decoding).
Definition: mpegvideo.c:230
ff_set_qscale
void ff_set_qscale(MpegEncContext *s, int qscale)
set qscale and update qscale dependent variables.
Definition: mpegvideo.c:585
mathops.h
ff_alternate_horizontal_scan
const uint8_t ff_alternate_horizontal_scan[64]
Definition: mpegvideodata.c:52
free_duplicate_context
static av_cold void free_duplicate_context(MpegEncContext *s)
Definition: mpegvideo.c:167
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:83
ff_mpeg_er_init
int ff_mpeg_er_init(MpegEncContext *s)
Definition: mpeg_er.c:102
init_duplicate_context
static av_cold int init_duplicate_context(MpegEncContext *s)
Definition: mpegvideo.c:117
FF_THREAD_SLICE
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
Definition: avcodec.h:1573
BufferPoolContext::qscale_table_pool
struct AVRefStructPool * qscale_table_pool
Definition: mpegpicture.h:46
mpegvideodata.h
attributes.h
clear_context
static void clear_context(MpegEncContext *s)
Definition: mpegvideo.c:382
ff_init_scantable
av_cold void ff_init_scantable(const uint8_t *permutation, ScanTable *st, const uint8_t *src_scantable)
Definition: mpegvideo.c:81
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
ff_alternate_vertical_scan
const uint8_t ff_alternate_vertical_scan[64]
Definition: mpegvideodata.c:63
dsp_init
static av_cold void dsp_init(MpegEncContext *s)
Definition: mpegvideo.c:61
internal.h
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:256
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
FF_DEBUG_NOMC
#define FF_DEBUG_NOMC
Definition: avcodec.h:1389
idctdsp.h
avcodec.h
ff_zigzag_direct
const uint8_t ff_zigzag_direct[64]
Definition: mathtables.c:98
ret
ret
Definition: filter_design.txt:187
U
#define U(x)
Definition: vpx_arith.h:37
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
BufferPoolContext::motion_val_pool
struct AVRefStructPool * motion_val_pool
Definition: mpegpicture.h:48
ff_default_chroma_qscale_table
const uint8_t ff_default_chroma_qscale_table[32]
Definition: mpegvideodata.c:21
mem.h
AV_CODEC_EXPORT_DATA_MVS
#define AV_CODEC_EXPORT_DATA_MVS
Export motion vectors through frame side data.
Definition: avcodec.h:386
COPY
#define COPY(a)
ScanTable
Scantable.
Definition: mpegvideo.h:47
av_refstruct_pool_uninit
static void av_refstruct_pool_uninit(AVRefStructPool **poolp)
Mark the pool as being available for freeing.
Definition: refstruct.h:292
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
ScanTable::permutated
uint8_t permutated[64]
Definition: mpegvideo.h:49
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
mpeg_er.h
imgutils.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
BufferPoolContext
Definition: mpegpicture.h:44
ff_mpv_free_context_frame
av_cold void ff_mpv_free_context_frame(MpegEncContext *s)
Frees and resets MpegEncContext fields depending on the resolution as well as the slice thread contex...
Definition: mpegvideo.c:484
h
h
Definition: vp9dsp_template.c:2070
av_image_check_size
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:318
BufferPoolContext::alloc_mb_width
int alloc_mb_width
mb_width used to allocate tables
Definition: mpegpicture.h:50
AV_CODEC_ID_MPEG2VIDEO
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition: codec_id.h:54
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:64
gray8
static void gray8(uint8_t *dst, const uint8_t *src, ptrdiff_t linesize, int h)
Definition: mpegvideo.c:54
src
#define src
Definition: vp8dsp.c:248
ScanTable::raster_end
uint8_t raster_end[64]
Definition: mpegvideo.h:50