FFmpeg
mpegvideo_dec.c
Go to the documentation of this file.
1 /*
2  * Common mpeg video decoding code
3  * Copyright (c) 2000,2001 Fabrice Bellard
4  * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
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 #include <limits.h>
24 
25 #include "libavutil/avassert.h"
26 #include "libavutil/imgutils.h"
27 #include "libavutil/internal.h"
29 
30 #include "avcodec.h"
31 #include "internal.h"
32 #include "mpegutils.h"
33 #include "mpegvideo.h"
34 #include "mpegvideodec.h"
35 #include "threadframe.h"
36 
38 {
40 
41  s->avctx = avctx;
42  s->width = avctx->coded_width;
43  s->height = avctx->coded_height;
44  s->codec_id = avctx->codec->id;
45  s->workaround_bugs = avctx->workaround_bugs;
46 
47  /* convert fourcc to upper case */
48  s->codec_tag = ff_toupper4(avctx->codec_tag);
49 }
50 
52  const AVCodecContext *src)
53 {
54  MpegEncContext *const s1 = src->priv_data;
55  MpegEncContext *const s = dst->priv_data;
56  int ret;
57 
58  if (dst == src)
59  return 0;
60 
61  av_assert0(s != s1);
62 
63  // FIXME can parameters change on I-frames?
64  // in that case dst may need a reinit
65  if (!s->context_initialized) {
66  void *private_ctx = s->private_ctx;
67  int err;
68  memcpy(s, s1, sizeof(*s));
69 
70  s->avctx = dst;
71  s->private_ctx = private_ctx;
72  s->bitstream_buffer = NULL;
73  s->bitstream_buffer_size = s->allocated_bitstream_buffer_size = 0;
74 
75  if (s1->context_initialized) {
76 // s->picture_range_start += MAX_PICTURE_COUNT;
77 // s->picture_range_end += MAX_PICTURE_COUNT;
79  if ((err = ff_mpv_common_init(s)) < 0) {
80  memset(s, 0, sizeof(*s));
81  s->avctx = dst;
82  s->private_ctx = private_ctx;
83  return err;
84  }
85  }
86  }
87 
88  if (s->height != s1->height || s->width != s1->width || s->context_reinit) {
89  s->height = s1->height;
90  s->width = s1->width;
92  return ret;
93  }
94 
95  s->avctx->coded_height = s1->avctx->coded_height;
96  s->avctx->coded_width = s1->avctx->coded_width;
97  s->avctx->width = s1->avctx->width;
98  s->avctx->height = s1->avctx->height;
99 
100  s->quarter_sample = s1->quarter_sample;
101 
102  s->coded_picture_number = s1->coded_picture_number;
103  s->picture_number = s1->picture_number;
104 
105  av_assert0(!s->picture || s->picture != s1->picture);
106  if (s->picture)
107  for (int i = 0; i < MAX_PICTURE_COUNT; i++) {
108  ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
109  if (s1->picture && s1->picture[i].f->buf[0] &&
110  (ret = ff_mpeg_ref_picture(s->avctx, &s->picture[i], &s1->picture[i])) < 0)
111  return ret;
112  }
113 
114 #define UPDATE_PICTURE(pic)\
115 do {\
116  ff_mpeg_unref_picture(s->avctx, &s->pic);\
117  if (s1->pic.f && s1->pic.f->buf[0])\
118  ret = ff_mpeg_ref_picture(s->avctx, &s->pic, &s1->pic);\
119  else\
120  ret = ff_update_picture_tables(&s->pic, &s1->pic);\
121  if (ret < 0)\
122  return ret;\
123 } while (0)
124 
128 
129 #define REBASE_PICTURE(pic, new_ctx, old_ctx) \
130  ((pic && pic >= old_ctx->picture && \
131  pic < old_ctx->picture + MAX_PICTURE_COUNT) ? \
132  &new_ctx->picture[pic - old_ctx->picture] : NULL)
133 
134  s->last_picture_ptr = REBASE_PICTURE(s1->last_picture_ptr, s, s1);
135  s->current_picture_ptr = REBASE_PICTURE(s1->current_picture_ptr, s, s1);
136  s->next_picture_ptr = REBASE_PICTURE(s1->next_picture_ptr, s, s1);
137 
138  // Error/bug resilience
139  s->workaround_bugs = s1->workaround_bugs;
140  s->padding_bug_score = s1->padding_bug_score;
141 
142  // MPEG-4 timing info
143  memcpy(&s->last_time_base, &s1->last_time_base,
144  (char *) &s1->pb_field_time + sizeof(s1->pb_field_time) -
145  (char *) &s1->last_time_base);
146 
147  // B-frame info
148  s->max_b_frames = s1->max_b_frames;
149  s->low_delay = s1->low_delay;
150  s->droppable = s1->droppable;
151 
152  // DivX handling (doesn't work)
153  s->divx_packed = s1->divx_packed;
154 
155  if (s1->bitstream_buffer) {
156  if (s1->bitstream_buffer_size +
157  AV_INPUT_BUFFER_PADDING_SIZE > s->allocated_bitstream_buffer_size) {
158  av_fast_malloc(&s->bitstream_buffer,
159  &s->allocated_bitstream_buffer_size,
160  s1->allocated_bitstream_buffer_size);
161  if (!s->bitstream_buffer) {
162  s->bitstream_buffer_size = 0;
163  return AVERROR(ENOMEM);
164  }
165  }
166  s->bitstream_buffer_size = s1->bitstream_buffer_size;
167  memcpy(s->bitstream_buffer, s1->bitstream_buffer,
168  s1->bitstream_buffer_size);
169  memset(s->bitstream_buffer + s->bitstream_buffer_size, 0,
171  }
172 
173  // linesize-dependent scratch buffer allocation
174  if (!s->sc.edge_emu_buffer)
175  if (s1->linesize) {
176  if (ff_mpeg_framesize_alloc(s->avctx, &s->me,
177  &s->sc, s1->linesize) < 0) {
178  av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate context "
179  "scratch buffers.\n");
180  return AVERROR(ENOMEM);
181  }
182  } else {
183  av_log(s->avctx, AV_LOG_ERROR, "Context scratch buffers could not "
184  "be allocated due to unknown size.\n");
185  }
186 
187  // MPEG-2/interlacing info
188  memcpy(&s->progressive_sequence, &s1->progressive_sequence,
189  (char *) &s1->rtp_mode - (char *) &s1->progressive_sequence);
190 
191  return 0;
192 }
193 
195 {
196  int err = 0;
197 
198  if (!s->context_initialized)
199  return AVERROR(EINVAL);
200 
202 
203  if (s->picture)
204  for (int i = 0; i < MAX_PICTURE_COUNT; i++)
205  s->picture[i].needs_realloc = 1;
206 
207  s->last_picture_ptr =
208  s->next_picture_ptr =
209  s->current_picture_ptr = NULL;
210 
211  // init
212  if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO && !s->progressive_sequence)
213  s->mb_height = (s->height + 31) / 32 * 2;
214  else
215  s->mb_height = (s->height + 15) / 16;
216 
217  if ((s->width || s->height) &&
218  (err = av_image_check_size(s->width, s->height, 0, s->avctx)) < 0)
219  goto fail;
220 
221  /* set chroma shifts */
222  err = av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt,
223  &s->chroma_x_shift,
224  &s->chroma_y_shift);
225  if (err < 0)
226  goto fail;
227 
228  if ((err = ff_mpv_init_context_frame(s)))
229  goto fail;
230 
231  memset(s->thread_context, 0, sizeof(s->thread_context));
232  s->thread_context[0] = s;
233 
234  if (s->width && s->height) {
236  if (err < 0)
237  goto fail;
238  }
239  s->context_reinit = 0;
240 
241  return 0;
242  fail:
244  s->context_reinit = 1;
245  return err;
246 }
247 
249 {
250  return ff_alloc_picture(s->avctx, pic, &s->me, &s->sc, 0, 0,
251  s->chroma_x_shift, s->chroma_y_shift, s->out_format,
252  s->mb_stride, s->mb_width, s->mb_height, s->b8_stride,
253  &s->linesize, &s->uvlinesize);
254 }
255 
256 static void gray_frame(AVFrame *frame)
257 {
258  int h_chroma_shift, v_chroma_shift;
259 
260  av_pix_fmt_get_chroma_sub_sample(frame->format, &h_chroma_shift, &v_chroma_shift);
261 
262  for (int i = 0; i < frame->height; i++)
263  memset(frame->data[0] + frame->linesize[0] * i, 0x80, frame->width);
264  for (int i = 0; i < AV_CEIL_RSHIFT(frame->height, v_chroma_shift); i++) {
265  memset(frame->data[1] + frame->linesize[1] * i,
266  0x80, AV_CEIL_RSHIFT(frame->width, h_chroma_shift));
267  memset(frame->data[2] + frame->linesize[2] * i,
268  0x80, AV_CEIL_RSHIFT(frame->width, h_chroma_shift));
269  }
270 }
271 
272 /**
273  * generic function called after decoding
274  * the header and before a frame is decoded.
275  */
277 {
278  Picture *pic;
279  int idx, ret;
280 
281  s->mb_skipped = 0;
282 
284  av_log(avctx, AV_LOG_ERROR, "Attempt to start a frame outside SETUP state\n");
285  return -1;
286  }
287 
288  /* mark & release old frames */
289  if (s->pict_type != AV_PICTURE_TYPE_B && s->last_picture_ptr &&
290  s->last_picture_ptr != s->next_picture_ptr &&
291  s->last_picture_ptr->f->buf[0]) {
292  ff_mpeg_unref_picture(s->avctx, s->last_picture_ptr);
293  }
294 
295  /* release forgotten pictures */
296  /* if (MPEG-124 / H.263) */
297  for (int i = 0; i < MAX_PICTURE_COUNT; i++) {
298  if (&s->picture[i] != s->last_picture_ptr &&
299  &s->picture[i] != s->next_picture_ptr &&
300  s->picture[i].reference && !s->picture[i].needs_realloc) {
301  ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
302  }
303  }
304 
305  ff_mpeg_unref_picture(s->avctx, &s->current_picture);
306  ff_mpeg_unref_picture(s->avctx, &s->last_picture);
307  ff_mpeg_unref_picture(s->avctx, &s->next_picture);
308 
309  /* release non reference frames */
310  for (int i = 0; i < MAX_PICTURE_COUNT; i++) {
311  if (!s->picture[i].reference)
312  ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
313  }
314 
315  if (s->current_picture_ptr && !s->current_picture_ptr->f->buf[0]) {
316  // we already have an unused image
317  // (maybe it was set before reading the header)
318  pic = s->current_picture_ptr;
319  } else {
320  idx = ff_find_unused_picture(s->avctx, s->picture, 0);
321  if (idx < 0) {
322  av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n");
323  return idx;
324  }
325  pic = &s->picture[idx];
326  }
327 
328  pic->reference = 0;
329  if (!s->droppable) {
330  if (s->pict_type != AV_PICTURE_TYPE_B)
331  pic->reference = 3;
332  }
333 
334  pic->f->coded_picture_number = s->coded_picture_number++;
335 
336  if (alloc_picture(s, pic) < 0)
337  return -1;
338 
339  s->current_picture_ptr = pic;
340  // FIXME use only the vars from current_pic
341  s->current_picture_ptr->f->top_field_first = s->top_field_first;
342  if (s->codec_id == AV_CODEC_ID_MPEG1VIDEO ||
343  s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
344  if (s->picture_structure != PICT_FRAME)
345  s->current_picture_ptr->f->top_field_first =
346  (s->picture_structure == PICT_TOP_FIELD) == s->first_field;
347  }
348  s->current_picture_ptr->f->interlaced_frame = !s->progressive_frame &&
349  !s->progressive_sequence;
350  s->current_picture_ptr->field_picture = s->picture_structure != PICT_FRAME;
351 
352  s->current_picture_ptr->f->pict_type = s->pict_type;
353  s->current_picture_ptr->f->key_frame = s->pict_type == AV_PICTURE_TYPE_I;
354 
355  if ((ret = ff_mpeg_ref_picture(s->avctx, &s->current_picture,
356  s->current_picture_ptr)) < 0)
357  return ret;
358 
359  if (s->pict_type != AV_PICTURE_TYPE_B) {
360  s->last_picture_ptr = s->next_picture_ptr;
361  if (!s->droppable)
362  s->next_picture_ptr = s->current_picture_ptr;
363  }
364  ff_dlog(s->avctx, "L%p N%p C%p L%p N%p C%p type:%d drop:%d\n",
365  s->last_picture_ptr, s->next_picture_ptr,s->current_picture_ptr,
366  s->last_picture_ptr ? s->last_picture_ptr->f->data[0] : NULL,
367  s->next_picture_ptr ? s->next_picture_ptr->f->data[0] : NULL,
368  s->current_picture_ptr ? s->current_picture_ptr->f->data[0] : NULL,
369  s->pict_type, s->droppable);
370 
371  if ((!s->last_picture_ptr || !s->last_picture_ptr->f->buf[0]) &&
372  (s->pict_type != AV_PICTURE_TYPE_I)) {
373  int h_chroma_shift, v_chroma_shift;
374  av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt,
375  &h_chroma_shift, &v_chroma_shift);
376  if (s->pict_type == AV_PICTURE_TYPE_B && s->next_picture_ptr && s->next_picture_ptr->f->buf[0])
378  "allocating dummy last picture for B frame\n");
379  else if (s->pict_type != AV_PICTURE_TYPE_I)
381  "warning: first frame is no keyframe\n");
382 
383  /* Allocate a dummy frame */
384  idx = ff_find_unused_picture(s->avctx, s->picture, 0);
385  if (idx < 0) {
386  av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n");
387  return idx;
388  }
389  s->last_picture_ptr = &s->picture[idx];
390 
391  s->last_picture_ptr->reference = 3;
392  s->last_picture_ptr->f->key_frame = 0;
393  s->last_picture_ptr->f->pict_type = AV_PICTURE_TYPE_P;
394 
395  if (alloc_picture(s, s->last_picture_ptr) < 0) {
396  s->last_picture_ptr = NULL;
397  return -1;
398  }
399 
400  if (!avctx->hwaccel) {
401  for (int i = 0; i < avctx->height; i++)
402  memset(s->last_picture_ptr->f->data[0] + s->last_picture_ptr->f->linesize[0]*i,
403  0x80, avctx->width);
404  if (s->last_picture_ptr->f->data[2]) {
405  for (int i = 0; i < AV_CEIL_RSHIFT(avctx->height, v_chroma_shift); i++) {
406  memset(s->last_picture_ptr->f->data[1] + s->last_picture_ptr->f->linesize[1]*i,
407  0x80, AV_CEIL_RSHIFT(avctx->width, h_chroma_shift));
408  memset(s->last_picture_ptr->f->data[2] + s->last_picture_ptr->f->linesize[2]*i,
409  0x80, AV_CEIL_RSHIFT(avctx->width, h_chroma_shift));
410  }
411  }
412 
413  if (s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == AV_CODEC_ID_H263) {
414  for (int i = 0; i < avctx->height; i++)
415  memset(s->last_picture_ptr->f->data[0] + s->last_picture_ptr->f->linesize[0] * i,
416  16, avctx->width);
417  }
418  }
419 
420  ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 0);
421  ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 1);
422  }
423  if ((!s->next_picture_ptr || !s->next_picture_ptr->f->buf[0]) &&
424  s->pict_type == AV_PICTURE_TYPE_B) {
425  /* Allocate a dummy frame */
426  idx = ff_find_unused_picture(s->avctx, s->picture, 0);
427  if (idx < 0) {
428  av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n");
429  return idx;
430  }
431  s->next_picture_ptr = &s->picture[idx];
432 
433  s->next_picture_ptr->reference = 3;
434  s->next_picture_ptr->f->key_frame = 0;
435  s->next_picture_ptr->f->pict_type = AV_PICTURE_TYPE_P;
436 
437  if (alloc_picture(s, s->next_picture_ptr) < 0) {
438  s->next_picture_ptr = NULL;
439  return -1;
440  }
441  ff_thread_report_progress(&s->next_picture_ptr->tf, INT_MAX, 0);
442  ff_thread_report_progress(&s->next_picture_ptr->tf, INT_MAX, 1);
443  }
444 
445 #if 0 // BUFREF-FIXME
446  memset(s->last_picture.f->data, 0, sizeof(s->last_picture.f->data));
447  memset(s->next_picture.f->data, 0, sizeof(s->next_picture.f->data));
448 #endif
449  if (s->last_picture_ptr) {
450  if (s->last_picture_ptr->f->buf[0] &&
451  (ret = ff_mpeg_ref_picture(s->avctx, &s->last_picture,
452  s->last_picture_ptr)) < 0)
453  return ret;
454  }
455  if (s->next_picture_ptr) {
456  if (s->next_picture_ptr->f->buf[0] &&
457  (ret = ff_mpeg_ref_picture(s->avctx, &s->next_picture,
458  s->next_picture_ptr)) < 0)
459  return ret;
460  }
461 
462  av_assert0(s->pict_type == AV_PICTURE_TYPE_I || (s->last_picture_ptr &&
463  s->last_picture_ptr->f->buf[0]));
464 
465  if (s->picture_structure != PICT_FRAME) {
466  for (int i = 0; i < 4; i++) {
467  if (s->picture_structure == PICT_BOTTOM_FIELD) {
468  s->current_picture.f->data[i] +=
469  s->current_picture.f->linesize[i];
470  }
471  s->current_picture.f->linesize[i] *= 2;
472  s->last_picture.f->linesize[i] *= 2;
473  s->next_picture.f->linesize[i] *= 2;
474  }
475  }
476 
477  /* set dequantizer, we can't do it during init as
478  * it might change for MPEG-4 and we can't do it in the header
479  * decode as init is not called for MPEG-4 there yet */
480  if (s->mpeg_quant || s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
481  s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra;
482  s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter;
483  } else if (s->out_format == FMT_H263 || s->out_format == FMT_H261) {
484  s->dct_unquantize_intra = s->dct_unquantize_h263_intra;
485  s->dct_unquantize_inter = s->dct_unquantize_h263_inter;
486  } else {
487  s->dct_unquantize_intra = s->dct_unquantize_mpeg1_intra;
488  s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter;
489  }
490 
491  if (s->avctx->debug & FF_DEBUG_NOMC)
492  gray_frame(s->current_picture_ptr->f);
493 
494  return 0;
495 }
496 
497 /* called after a frame has been decoded. */
499 {
500  emms_c();
501 
502  if (s->current_picture.reference)
503  ff_thread_report_progress(&s->current_picture_ptr->tf, INT_MAX, 0);
504 }
505 
507 {
508  ff_print_debug_info2(s->avctx, pict, s->mbskip_table, p->mb_type,
509  p->qscale_table, p->motion_val,
510  s->mb_width, s->mb_height, s->mb_stride, s->quarter_sample);
511 }
512 
514 {
515  AVVideoEncParams *par;
516  int mult = (qp_type == FF_MPV_QSCALE_TYPE_MPEG1) ? 2 : 1;
517  unsigned int nb_mb = p->alloc_mb_height * p->alloc_mb_width;
518 
519  if (!(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS))
520  return 0;
521 
523  if (!par)
524  return AVERROR(ENOMEM);
525 
526  for (unsigned y = 0; y < p->alloc_mb_height; y++)
527  for (unsigned x = 0; x < p->alloc_mb_width; x++) {
528  const unsigned int block_idx = y * p->alloc_mb_width + x;
529  const unsigned int mb_xy = y * p->alloc_mb_stride + x;
530  AVVideoBlockParams *const b = av_video_enc_params_block(par, block_idx);
531 
532  b->src_x = x * 16;
533  b->src_y = y * 16;
534  b->w = 16;
535  b->h = 16;
536 
537  b->delta_qp = p->qscale_table[mb_xy] * mult;
538  }
539 
540  return 0;
541 }
542 
544 {
545  ff_draw_horiz_band(s->avctx, s->current_picture_ptr->f,
546  s->last_picture_ptr ? s->last_picture_ptr->f : NULL,
547  y, h, s->picture_structure,
548  s->first_field, s->low_delay);
549 }
550 
552 {
553  MpegEncContext *const s = avctx->priv_data;
554 
555  if (!s->picture)
556  return;
557 
558  for (int i = 0; i < MAX_PICTURE_COUNT; i++)
559  ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
560  s->current_picture_ptr = s->last_picture_ptr = s->next_picture_ptr = NULL;
561 
562  ff_mpeg_unref_picture(s->avctx, &s->current_picture);
563  ff_mpeg_unref_picture(s->avctx, &s->last_picture);
564  ff_mpeg_unref_picture(s->avctx, &s->next_picture);
565 
566  s->mb_x = s->mb_y = 0;
567 
568 #if FF_API_FLAG_TRUNCATED
569  s->parse_context.state = -1;
570  s->parse_context.frame_start_found = 0;
571  s->parse_context.overread = 0;
572  s->parse_context.overread_index = 0;
573  s->parse_context.index = 0;
574  s->parse_context.last_index = 0;
575 #endif
576  s->bitstream_buffer_size = 0;
577  s->pp_time = 0;
578 }
579 
581 {
582  if (s->pict_type != AV_PICTURE_TYPE_B && !s->partitioned_frame && !s->er.error_occurred)
583  ff_thread_report_progress(&s->current_picture_ptr->tf, s->mb_y, 0);
584 }
PICT_FRAME
#define PICT_FRAME
Definition: mpegutils.h:38
ff_mpv_common_init
av_cold int ff_mpv_common_init(MpegEncContext *s)
init common structure for both encoder and decoder.
Definition: mpegvideo.c:736
AVCodecContext::hwaccel
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:1379
ff_mpeg_framesize_alloc
int ff_mpeg_framesize_alloc(AVCodecContext *avctx, MotionEstContext *me, ScratchpadContext *sc, int linesize)
Definition: mpegpicture.c:78
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
AVCodecContext::workaround_bugs
int workaround_bugs
Work around bugs in encoders which sometimes cannot be detected automatically.
Definition: avcodec.h:1271
ff_mpv_init_context_frame
int ff_mpv_init_context_frame(MpegEncContext *s)
Initialize and allocates MpegEncContext fields dependent on the resolution.
Definition: mpegvideo.c:523
ff_mpv_common_defaults
void ff_mpv_common_defaults(MpegEncContext *s)
Set the given MpegEncContext to common defaults (same for encoding and decoding).
Definition: mpegvideo.c:505
ff_thread_can_start_frame
int ff_thread_can_start_frame(AVCodecContext *avctx)
Definition: pthread_frame.c:941
AVFrame::coded_picture_number
int coded_picture_number
picture number in bitstream order
Definition: frame.h:452
Picture::alloc_mb_width
int alloc_mb_width
mb_width used to allocate tables
Definition: mpegpicture.h:71
MpegEncContext::current_picture
Picture current_picture
copy of the current picture structure.
Definition: mpegvideo.h:163
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:325
ff_mpv_report_decode_progress
void ff_mpv_report_decode_progress(MpegEncContext *s)
Definition: mpegvideo_dec.c:580
internal.h
last_picture
enum AVPictureType last_picture
Definition: movenc.c:69
b
#define b
Definition: input.c:34
MpegEncContext::next_picture
Picture next_picture
copy of the next picture structure.
Definition: mpegvideo.h:151
ff_toupper4
unsigned int ff_toupper4(unsigned int x)
Definition: to_upper4.h:29
PICT_BOTTOM_FIELD
#define PICT_BOTTOM_FIELD
Definition: mpegutils.h:37
mpegvideo.h
MpegEncContext::avctx
struct AVCodecContext * avctx
Definition: mpegvideo.h:79
Picture
Picture.
Definition: mpegpicture.h:46
mpegutils.h
AV_VIDEO_ENC_PARAMS_MPEG2
@ AV_VIDEO_ENC_PARAMS_MPEG2
Definition: video_enc_params.h:65
gray_frame
static void gray_frame(AVFrame *frame)
Definition: mpegvideo_dec.c:256
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:398
fail
#define fail()
Definition: checkasm.h:130
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:2690
AVCodecContext::coded_height
int coded_height
Definition: avcodec.h:577
AVVideoEncParams
Video encoding parameters for a given frame.
Definition: video_enc_params.h:73
MAX_PICTURE_COUNT
#define MAX_PICTURE_COUNT
Definition: mpegpicture.h:33
mult
static int16_t mult(Float11 *f1, Float11 *f2)
Definition: g726.c:60
avassert.h
mpegvideodec.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
ff_thread_report_progress
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
Definition: pthread_frame.c:595
ff_mpv_common_frame_size_change
int ff_mpv_common_frame_size_change(MpegEncContext *s)
Definition: mpegvideo_dec.c:194
s
#define s(width, name)
Definition: cbs_vp9.c:256
ff_mpeg_unref_picture
void ff_mpeg_unref_picture(AVCodecContext *avctx, Picture *pic)
Deallocate a picture; frees the picture tables in case they need to be reallocated anyway.
Definition: mpegpicture.c:317
AV_CEIL_RSHIFT
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:50
s1
#define s1
Definition: regdef.h:38
REBASE_PICTURE
#define REBASE_PICTURE(pic, new_ctx, old_ctx)
FMT_H261
@ FMT_H261
Definition: mpegutils.h:118
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
UPDATE_PICTURE
#define UPDATE_PICTURE(pic)
AV_LOG_DEBUG
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:201
PICT_TOP_FIELD
#define PICT_TOP_FIELD
Definition: mpegutils.h:36
limits.h
if
if(ret)
Definition: filter_design.txt:179
Picture::reference
int reference
Definition: mpegpicture.h:89
ff_find_unused_picture
int ff_find_unused_picture(AVCodecContext *avctx, Picture *picture, int shared)
Definition: mpegpicture.c:462
threadframe.h
ff_print_debug_info2
void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict, uint8_t *mbskip_table, uint32_t *mbtype_table, int8_t *qscale_table, int16_t(*motion_val[2])[2], int mb_width, int mb_height, int mb_stride, int quarter_sample)
Print debugging info for the given picture.
Definition: mpegutils.c:103
NULL
#define NULL
Definition: coverity.c:32
ff_mpv_idct_init
av_cold void ff_mpv_idct_init(MpegEncContext *s)
Definition: mpegvideo.c:329
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
ff_alloc_picture
int ff_alloc_picture(AVCodecContext *avctx, Picture *pic, MotionEstContext *me, ScratchpadContext *sc, int shared, int encoding, int chroma_x_shift, int chroma_y_shift, int out_format, int mb_stride, int mb_width, int mb_height, int b8_stride, ptrdiff_t *linesize, ptrdiff_t *uvlinesize)
Allocate a Picture.
Definition: mpegpicture.c:253
FF_MPV_QSCALE_TYPE_MPEG1
#define FF_MPV_QSCALE_TYPE_MPEG1
Definition: mpegvideodec.h:38
AV_CODEC_ID_MPEG1VIDEO
@ AV_CODEC_ID_MPEG1VIDEO
Definition: codec_id.h:51
MpegEncContext::private_ctx
void * private_ctx
Definition: mpegvideo.h:82
ff_dlog
#define ff_dlog(a,...)
Definition: tableprint_vlc.h:28
av_video_enc_params_create_side_data
AVVideoEncParams * av_video_enc_params_create_side_data(AVFrame *frame, enum AVVideoEncParamsType type, unsigned int nb_blocks)
Allocates memory for AVEncodeInfoFrame plus an array of.
Definition: video_enc_params.c:58
f
f
Definition: af_crystalizer.c:122
ff_mpeg_ref_picture
int ff_mpeg_ref_picture(AVCodecContext *avctx, Picture *dst, Picture *src)
Definition: mpegpicture.c:377
ff_draw_horiz_band
void ff_draw_horiz_band(AVCodecContext *avctx, AVFrame *cur, AVFrame *last, int y, int h, int picture_structure, int first_field, int low_delay)
Draw a horizontal band if supported.
Definition: mpegutils.c:51
AV_CODEC_ID_H263
@ AV_CODEC_ID_H263
Definition: codec_id.h:54
ff_mpeg_draw_horiz_band
void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
Definition: mpegvideo_dec.c:543
Picture::alloc_mb_height
int alloc_mb_height
mb_height used to allocate tables
Definition: mpegpicture.h:72
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:276
ff_mpeg_flush
void ff_mpeg_flush(AVCodecContext *avctx)
Definition: mpegvideo_dec.c:551
Picture::motion_val
int16_t(*[2] motion_val)[2]
Definition: mpegpicture.h:54
AVCodec::id
enum AVCodecID id
Definition: codec.h:210
FMT_H263
@ FMT_H263
Definition: mpegutils.h:119
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:271
internal.h
ff_mpv_decode_init
void ff_mpv_decode_init(MpegEncContext *s, AVCodecContext *avctx)
Initialize the given MpegEncContext for decoding.
Definition: mpegvideo_dec.c:37
AVVideoBlockParams
Data structure for storing block-level encoding information.
Definition: video_enc_params.h:120
ff_mpv_export_qp_table
int ff_mpv_export_qp_table(MpegEncContext *s, AVFrame *f, Picture *p, int qp_type)
Definition: mpegvideo_dec.c:513
AVCodecContext::height
int height
Definition: avcodec.h:562
FF_DEBUG_NOMC
#define FF_DEBUG_NOMC
Definition: avcodec.h:1337
avcodec.h
ret
ret
Definition: filter_design.txt:187
frame
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
Definition: filter_design.txt:264
Picture::qscale_table
int8_t * qscale_table
Definition: mpegpicture.h:51
alloc_picture
static int alloc_picture(MpegEncContext *s, Picture *pic)
Definition: mpegvideo_dec.c:248
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS
#define AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS
Decoding only.
Definition: avcodec.h:357
ff_mpv_free_context_frame
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:823
ff_mpeg_update_thread_context
int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src)
Definition: mpegvideo_dec.c:51
AVCodecContext
main external API structure.
Definition: avcodec.h:389
Picture::mb_type
uint32_t * mb_type
types and macros are defined in mpegutils.h
Definition: mpegpicture.h:57
AV_PICTURE_TYPE_B
@ AV_PICTURE_TYPE_B
Bi-dir predicted.
Definition: avutil.h:276
Picture::f
struct AVFrame * f
Definition: mpegpicture.h:47
ff_mpv_frame_end
void ff_mpv_frame_end(MpegEncContext *s)
Definition: mpegvideo_dec.c:498
AVCodecContext::coded_width
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:577
AV_PICTURE_TYPE_P
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:275
ff_mpv_init_duplicate_contexts
int ff_mpv_init_duplicate_contexts(MpegEncContext *s)
Initialize an MpegEncContext's thread contexts.
Definition: mpegvideo.c:394
AVCodecContext::codec_tag
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:414
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:416
av_fast_malloc
void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size)
Allocate a buffer, reusing the given one if large enough.
Definition: mem.c:561
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:562
imgutils.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
av_video_enc_params_block
static av_always_inline AVVideoBlockParams * av_video_enc_params_block(AVVideoEncParams *par, unsigned int idx)
Definition: video_enc_params.h:143
h
h
Definition: vp9dsp_template.c:2038
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
ff_print_debug_info
void ff_print_debug_info(MpegEncContext *s, Picture *p, AVFrame *pict)
Definition: mpegvideo_dec.c:506
AV_CODEC_ID_FLV1
@ AV_CODEC_ID_FLV1
Definition: codec_id.h:71
AV_CODEC_ID_MPEG2VIDEO
@ AV_CODEC_ID_MPEG2VIDEO
preferred ID for MPEG-1/2 video decoding
Definition: codec_id.h:52
MpegEncContext
MpegEncContext.
Definition: mpegvideo.h:62
Picture::alloc_mb_stride
int alloc_mb_stride
mb_stride used to allocate tables
Definition: mpegpicture.h:73
video_enc_params.h