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) {
77  if ((err = ff_mpv_common_init(s)) < 0) {
78  memset(s, 0, sizeof(*s));
79  s->avctx = dst;
80  s->private_ctx = private_ctx;
81  return err;
82  }
83  }
84  }
85 
86  if (s->height != s1->height || s->width != s1->width || s->context_reinit) {
87  s->height = s1->height;
88  s->width = s1->width;
90  return ret;
91  }
92 
93  s->quarter_sample = s1->quarter_sample;
94 
95  s->coded_picture_number = s1->coded_picture_number;
96  s->picture_number = s1->picture_number;
97 
98  av_assert0(!s->picture || s->picture != s1->picture);
99  if (s->picture)
100  for (int i = 0; i < MAX_PICTURE_COUNT; i++) {
101  ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
102  if (s1->picture && s1->picture[i].f->buf[0] &&
103  (ret = ff_mpeg_ref_picture(s->avctx, &s->picture[i], &s1->picture[i])) < 0)
104  return ret;
105  }
106 
107 #define UPDATE_PICTURE(pic)\
108 do {\
109  ff_mpeg_unref_picture(s->avctx, &s->pic);\
110  if (s1->pic.f && s1->pic.f->buf[0])\
111  ret = ff_mpeg_ref_picture(s->avctx, &s->pic, &s1->pic);\
112  else\
113  ret = ff_update_picture_tables(&s->pic, &s1->pic);\
114  if (ret < 0)\
115  return ret;\
116 } while (0)
117 
121 
122 #define REBASE_PICTURE(pic, new_ctx, old_ctx) \
123  ((pic && pic >= old_ctx->picture && \
124  pic < old_ctx->picture + MAX_PICTURE_COUNT) ? \
125  &new_ctx->picture[pic - old_ctx->picture] : NULL)
126 
127  s->last_picture_ptr = REBASE_PICTURE(s1->last_picture_ptr, s, s1);
128  s->current_picture_ptr = REBASE_PICTURE(s1->current_picture_ptr, s, s1);
129  s->next_picture_ptr = REBASE_PICTURE(s1->next_picture_ptr, s, s1);
130 
131  // Error/bug resilience
132  s->workaround_bugs = s1->workaround_bugs;
133  s->padding_bug_score = s1->padding_bug_score;
134 
135  // MPEG-4 timing info
136  memcpy(&s->last_time_base, &s1->last_time_base,
137  (char *) &s1->pb_field_time + sizeof(s1->pb_field_time) -
138  (char *) &s1->last_time_base);
139 
140  // B-frame info
141  s->max_b_frames = s1->max_b_frames;
142  s->low_delay = s1->low_delay;
143  s->droppable = s1->droppable;
144 
145  // DivX handling (doesn't work)
146  s->divx_packed = s1->divx_packed;
147 
148  if (s1->bitstream_buffer) {
149  if (s1->bitstream_buffer_size +
150  AV_INPUT_BUFFER_PADDING_SIZE > s->allocated_bitstream_buffer_size) {
151  av_fast_malloc(&s->bitstream_buffer,
152  &s->allocated_bitstream_buffer_size,
153  s1->allocated_bitstream_buffer_size);
154  if (!s->bitstream_buffer) {
155  s->bitstream_buffer_size = 0;
156  return AVERROR(ENOMEM);
157  }
158  }
159  s->bitstream_buffer_size = s1->bitstream_buffer_size;
160  memcpy(s->bitstream_buffer, s1->bitstream_buffer,
161  s1->bitstream_buffer_size);
162  memset(s->bitstream_buffer + s->bitstream_buffer_size, 0,
164  }
165 
166  // linesize-dependent scratch buffer allocation
167  if (!s->sc.edge_emu_buffer)
168  if (s1->linesize) {
169  if (ff_mpeg_framesize_alloc(s->avctx, &s->me,
170  &s->sc, s1->linesize) < 0) {
171  av_log(s->avctx, AV_LOG_ERROR, "Failed to allocate context "
172  "scratch buffers.\n");
173  return AVERROR(ENOMEM);
174  }
175  } else {
176  av_log(s->avctx, AV_LOG_ERROR, "Context scratch buffers could not "
177  "be allocated due to unknown size.\n");
178  }
179 
180  // MPEG-2/interlacing info
181  memcpy(&s->progressive_sequence, &s1->progressive_sequence,
182  (char *) &s1->rtp_mode - (char *) &s1->progressive_sequence);
183 
184  return 0;
185 }
186 
188 {
189  int err = 0;
190 
191  if (!s->context_initialized)
192  return AVERROR(EINVAL);
193 
195 
196  if (s->picture)
197  for (int i = 0; i < MAX_PICTURE_COUNT; i++)
198  s->picture[i].needs_realloc = 1;
199 
200  s->last_picture_ptr =
201  s->next_picture_ptr =
202  s->current_picture_ptr = NULL;
203 
204  if ((s->width || s->height) &&
205  (err = av_image_check_size(s->width, s->height, 0, s->avctx)) < 0)
206  goto fail;
207 
208  /* set chroma shifts */
209  err = av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt,
210  &s->chroma_x_shift,
211  &s->chroma_y_shift);
212  if (err < 0)
213  goto fail;
214 
215  if ((err = ff_mpv_init_context_frame(s)))
216  goto fail;
217 
218  memset(s->thread_context, 0, sizeof(s->thread_context));
219  s->thread_context[0] = s;
220 
221  if (s->width && s->height) {
223  if (err < 0)
224  goto fail;
225  }
226  s->context_reinit = 0;
227 
228  return 0;
229  fail:
231  s->context_reinit = 1;
232  return err;
233 }
234 
236 {
237  return ff_alloc_picture(s->avctx, pic, &s->me, &s->sc, 0, 0,
238  s->chroma_x_shift, s->chroma_y_shift, s->out_format,
239  s->mb_stride, s->mb_width, s->mb_height, s->b8_stride,
240  &s->linesize, &s->uvlinesize);
241 }
242 
243 static void gray_frame(AVFrame *frame)
244 {
245  int h_chroma_shift, v_chroma_shift;
246 
247  av_pix_fmt_get_chroma_sub_sample(frame->format, &h_chroma_shift, &v_chroma_shift);
248 
249  for (int i = 0; i < frame->height; i++)
250  memset(frame->data[0] + frame->linesize[0] * i, 0x80, frame->width);
251  for (int i = 0; i < AV_CEIL_RSHIFT(frame->height, v_chroma_shift); i++) {
252  memset(frame->data[1] + frame->linesize[1] * i,
253  0x80, AV_CEIL_RSHIFT(frame->width, h_chroma_shift));
254  memset(frame->data[2] + frame->linesize[2] * i,
255  0x80, AV_CEIL_RSHIFT(frame->width, h_chroma_shift));
256  }
257 }
258 
259 /**
260  * generic function called after decoding
261  * the header and before a frame is decoded.
262  */
264 {
265  Picture *pic;
266  int idx, ret;
267 
268  s->mb_skipped = 0;
269 
271  av_log(avctx, AV_LOG_ERROR, "Attempt to start a frame outside SETUP state\n");
272  return -1;
273  }
274 
275  /* mark & release old frames */
276  if (s->pict_type != AV_PICTURE_TYPE_B && s->last_picture_ptr &&
277  s->last_picture_ptr != s->next_picture_ptr &&
278  s->last_picture_ptr->f->buf[0]) {
279  ff_mpeg_unref_picture(s->avctx, s->last_picture_ptr);
280  }
281 
282  /* release non reference/forgotten frames */
283  for (int i = 0; i < MAX_PICTURE_COUNT; i++) {
284  if (!s->picture[i].reference ||
285  (&s->picture[i] != s->last_picture_ptr &&
286  &s->picture[i] != s->next_picture_ptr &&
287  !s->picture[i].needs_realloc)) {
288  ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
289  }
290  }
291 
292  ff_mpeg_unref_picture(s->avctx, &s->current_picture);
293  ff_mpeg_unref_picture(s->avctx, &s->last_picture);
294  ff_mpeg_unref_picture(s->avctx, &s->next_picture);
295 
296  if (s->current_picture_ptr && !s->current_picture_ptr->f->buf[0]) {
297  // we already have an unused image
298  // (maybe it was set before reading the header)
299  pic = s->current_picture_ptr;
300  } else {
301  idx = ff_find_unused_picture(s->avctx, s->picture, 0);
302  if (idx < 0) {
303  av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n");
304  return idx;
305  }
306  pic = &s->picture[idx];
307  }
308 
309  pic->reference = 0;
310  if (!s->droppable) {
311  if (s->pict_type != AV_PICTURE_TYPE_B)
312  pic->reference = 3;
313  }
314 
315  pic->f->coded_picture_number = s->coded_picture_number++;
316 
317  if (alloc_picture(s, pic) < 0)
318  return -1;
319 
320  s->current_picture_ptr = pic;
321  // FIXME use only the vars from current_pic
322  s->current_picture_ptr->f->top_field_first = s->top_field_first;
323  if (s->codec_id == AV_CODEC_ID_MPEG1VIDEO ||
324  s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
325  if (s->picture_structure != PICT_FRAME)
326  s->current_picture_ptr->f->top_field_first =
327  (s->picture_structure == PICT_TOP_FIELD) == s->first_field;
328  }
329  s->current_picture_ptr->f->interlaced_frame = !s->progressive_frame &&
330  !s->progressive_sequence;
331  s->current_picture_ptr->field_picture = s->picture_structure != PICT_FRAME;
332 
333  s->current_picture_ptr->f->pict_type = s->pict_type;
334  s->current_picture_ptr->f->key_frame = s->pict_type == AV_PICTURE_TYPE_I;
335 
336  if ((ret = ff_mpeg_ref_picture(s->avctx, &s->current_picture,
337  s->current_picture_ptr)) < 0)
338  return ret;
339 
340  if (s->pict_type != AV_PICTURE_TYPE_B) {
341  s->last_picture_ptr = s->next_picture_ptr;
342  if (!s->droppable)
343  s->next_picture_ptr = s->current_picture_ptr;
344  }
345  ff_dlog(s->avctx, "L%p N%p C%p L%p N%p C%p type:%d drop:%d\n",
346  s->last_picture_ptr, s->next_picture_ptr,s->current_picture_ptr,
347  s->last_picture_ptr ? s->last_picture_ptr->f->data[0] : NULL,
348  s->next_picture_ptr ? s->next_picture_ptr->f->data[0] : NULL,
349  s->current_picture_ptr ? s->current_picture_ptr->f->data[0] : NULL,
350  s->pict_type, s->droppable);
351 
352  if ((!s->last_picture_ptr || !s->last_picture_ptr->f->buf[0]) &&
353  (s->pict_type != AV_PICTURE_TYPE_I)) {
354  int h_chroma_shift, v_chroma_shift;
355  av_pix_fmt_get_chroma_sub_sample(s->avctx->pix_fmt,
356  &h_chroma_shift, &v_chroma_shift);
357  if (s->pict_type == AV_PICTURE_TYPE_B && s->next_picture_ptr && s->next_picture_ptr->f->buf[0])
359  "allocating dummy last picture for B frame\n");
360  else if (s->pict_type != AV_PICTURE_TYPE_I)
362  "warning: first frame is no keyframe\n");
363 
364  /* Allocate a dummy frame */
365  idx = ff_find_unused_picture(s->avctx, s->picture, 0);
366  if (idx < 0) {
367  av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n");
368  return idx;
369  }
370  s->last_picture_ptr = &s->picture[idx];
371 
372  s->last_picture_ptr->reference = 3;
373  s->last_picture_ptr->f->key_frame = 0;
374  s->last_picture_ptr->f->pict_type = AV_PICTURE_TYPE_P;
375 
376  if (alloc_picture(s, s->last_picture_ptr) < 0) {
377  s->last_picture_ptr = NULL;
378  return -1;
379  }
380 
381  if (!avctx->hwaccel) {
382  for (int i = 0; i < avctx->height; i++)
383  memset(s->last_picture_ptr->f->data[0] + s->last_picture_ptr->f->linesize[0]*i,
384  0x80, avctx->width);
385  if (s->last_picture_ptr->f->data[2]) {
386  for (int i = 0; i < AV_CEIL_RSHIFT(avctx->height, v_chroma_shift); i++) {
387  memset(s->last_picture_ptr->f->data[1] + s->last_picture_ptr->f->linesize[1]*i,
388  0x80, AV_CEIL_RSHIFT(avctx->width, h_chroma_shift));
389  memset(s->last_picture_ptr->f->data[2] + s->last_picture_ptr->f->linesize[2]*i,
390  0x80, AV_CEIL_RSHIFT(avctx->width, h_chroma_shift));
391  }
392  }
393 
394  if (s->codec_id == AV_CODEC_ID_FLV1 || s->codec_id == AV_CODEC_ID_H263) {
395  for (int i = 0; i < avctx->height; i++)
396  memset(s->last_picture_ptr->f->data[0] + s->last_picture_ptr->f->linesize[0] * i,
397  16, avctx->width);
398  }
399  }
400 
401  ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 0);
402  ff_thread_report_progress(&s->last_picture_ptr->tf, INT_MAX, 1);
403  }
404  if ((!s->next_picture_ptr || !s->next_picture_ptr->f->buf[0]) &&
405  s->pict_type == AV_PICTURE_TYPE_B) {
406  /* Allocate a dummy frame */
407  idx = ff_find_unused_picture(s->avctx, s->picture, 0);
408  if (idx < 0) {
409  av_log(s->avctx, AV_LOG_ERROR, "no frame buffer available\n");
410  return idx;
411  }
412  s->next_picture_ptr = &s->picture[idx];
413 
414  s->next_picture_ptr->reference = 3;
415  s->next_picture_ptr->f->key_frame = 0;
416  s->next_picture_ptr->f->pict_type = AV_PICTURE_TYPE_P;
417 
418  if (alloc_picture(s, s->next_picture_ptr) < 0) {
419  s->next_picture_ptr = NULL;
420  return -1;
421  }
422  ff_thread_report_progress(&s->next_picture_ptr->tf, INT_MAX, 0);
423  ff_thread_report_progress(&s->next_picture_ptr->tf, INT_MAX, 1);
424  }
425 
426 #if 0 // BUFREF-FIXME
427  memset(s->last_picture.f->data, 0, sizeof(s->last_picture.f->data));
428  memset(s->next_picture.f->data, 0, sizeof(s->next_picture.f->data));
429 #endif
430  if (s->last_picture_ptr) {
431  if (s->last_picture_ptr->f->buf[0] &&
432  (ret = ff_mpeg_ref_picture(s->avctx, &s->last_picture,
433  s->last_picture_ptr)) < 0)
434  return ret;
435  }
436  if (s->next_picture_ptr) {
437  if (s->next_picture_ptr->f->buf[0] &&
438  (ret = ff_mpeg_ref_picture(s->avctx, &s->next_picture,
439  s->next_picture_ptr)) < 0)
440  return ret;
441  }
442 
443  av_assert0(s->pict_type == AV_PICTURE_TYPE_I || (s->last_picture_ptr &&
444  s->last_picture_ptr->f->buf[0]));
445 
446  if (s->picture_structure != PICT_FRAME) {
447  for (int i = 0; i < 4; i++) {
448  if (s->picture_structure == PICT_BOTTOM_FIELD) {
449  s->current_picture.f->data[i] = FF_PTR_ADD(s->current_picture.f->data[i],
450  s->current_picture.f->linesize[i]);
451  }
452  s->current_picture.f->linesize[i] *= 2;
453  s->last_picture.f->linesize[i] *= 2;
454  s->next_picture.f->linesize[i] *= 2;
455  }
456  }
457 
458  /* set dequantizer, we can't do it during init as
459  * it might change for MPEG-4 and we can't do it in the header
460  * decode as init is not called for MPEG-4 there yet */
461  if (s->mpeg_quant || s->codec_id == AV_CODEC_ID_MPEG2VIDEO) {
462  s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra;
463  s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter;
464  } else if (s->out_format == FMT_H263 || s->out_format == FMT_H261) {
465  s->dct_unquantize_intra = s->dct_unquantize_h263_intra;
466  s->dct_unquantize_inter = s->dct_unquantize_h263_inter;
467  } else {
468  s->dct_unquantize_intra = s->dct_unquantize_mpeg1_intra;
469  s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter;
470  }
471 
472  if (s->avctx->debug & FF_DEBUG_NOMC)
473  gray_frame(s->current_picture_ptr->f);
474 
475  return 0;
476 }
477 
478 /* called after a frame has been decoded. */
480 {
481  emms_c();
482 
483  if (s->current_picture.reference)
484  ff_thread_report_progress(&s->current_picture_ptr->tf, INT_MAX, 0);
485 }
486 
487 void ff_print_debug_info(const MpegEncContext *s, const Picture *p, AVFrame *pict)
488 {
489  ff_print_debug_info2(s->avctx, pict, s->mbskip_table, p->mb_type,
490  p->qscale_table, p->motion_val,
491  s->mb_width, s->mb_height, s->mb_stride, s->quarter_sample);
492 }
493 
494 int ff_mpv_export_qp_table(const MpegEncContext *s, AVFrame *f, const Picture *p, int qp_type)
495 {
496  AVVideoEncParams *par;
497  int mult = (qp_type == FF_MPV_QSCALE_TYPE_MPEG1) ? 2 : 1;
498  unsigned int nb_mb = p->alloc_mb_height * p->alloc_mb_width;
499 
500  if (!(s->avctx->export_side_data & AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS))
501  return 0;
502 
504  if (!par)
505  return AVERROR(ENOMEM);
506 
507  for (unsigned y = 0; y < p->alloc_mb_height; y++)
508  for (unsigned x = 0; x < p->alloc_mb_width; x++) {
509  const unsigned int block_idx = y * p->alloc_mb_width + x;
510  const unsigned int mb_xy = y * p->alloc_mb_stride + x;
511  AVVideoBlockParams *const b = av_video_enc_params_block(par, block_idx);
512 
513  b->src_x = x * 16;
514  b->src_y = y * 16;
515  b->w = 16;
516  b->h = 16;
517 
518  b->delta_qp = p->qscale_table[mb_xy] * mult;
519  }
520 
521  return 0;
522 }
523 
525 {
526  ff_draw_horiz_band(s->avctx, s->current_picture_ptr->f,
527  s->last_picture_ptr ? s->last_picture_ptr->f : NULL,
528  y, h, s->picture_structure,
529  s->first_field, s->low_delay);
530 }
531 
533 {
534  MpegEncContext *const s = avctx->priv_data;
535 
536  if (!s->picture)
537  return;
538 
539  for (int i = 0; i < MAX_PICTURE_COUNT; i++)
540  ff_mpeg_unref_picture(s->avctx, &s->picture[i]);
541  s->current_picture_ptr = s->last_picture_ptr = s->next_picture_ptr = NULL;
542 
543  ff_mpeg_unref_picture(s->avctx, &s->current_picture);
544  ff_mpeg_unref_picture(s->avctx, &s->last_picture);
545  ff_mpeg_unref_picture(s->avctx, &s->next_picture);
546 
547  s->mb_x = s->mb_y = 0;
548 
549 #if FF_API_FLAG_TRUNCATED
550  s->parse_context.state = -1;
551  s->parse_context.frame_start_found = 0;
552  s->parse_context.overread = 0;
553  s->parse_context.overread_index = 0;
554  s->parse_context.index = 0;
555  s->parse_context.last_index = 0;
556 #endif
557  s->bitstream_buffer_size = 0;
558  s->pp_time = 0;
559 }
560 
562 {
563  if (s->pict_type != AV_PICTURE_TYPE_B && !s->partitioned_frame && !s->er.error_occurred)
564  ff_thread_report_progress(&s->current_picture_ptr->tf, s->mb_y, 0);
565 }
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:668
ff_draw_horiz_band
void ff_draw_horiz_band(AVCodecContext *avctx, const AVFrame *cur, const 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
AVCodecContext::hwaccel
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:1369
ff_mpeg_framesize_alloc
int ff_mpeg_framesize_alloc(AVCodecContext *avctx, MotionEstContext *me, ScratchpadContext *sc, int linesize)
Definition: mpegpicture.c:87
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:1280
ff_mpv_export_qp_table
int ff_mpv_export_qp_table(const MpegEncContext *s, AVFrame *f, const Picture *p, int qp_type)
Definition: mpegvideo_dec.c:494
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:525
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:507
ff_thread_can_start_frame
int ff_thread_can_start_frame(AVCodecContext *avctx)
Definition: pthread_frame.c:958
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:65
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:561
internal.h
last_picture
enum AVPictureType last_picture
Definition: movenc.c:69
b
#define b
Definition: input.c:41
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:243
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:407
fail
#define fail()
Definition: checkasm.h:133
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:2886
AVCodecContext::coded_height
int coded_height
Definition: avcodec.h:586
ff_print_debug_info
void ff_print_debug_info(const MpegEncContext *s, const Picture *p, AVFrame *pict)
Definition: mpegvideo_dec.c:487
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:611
ff_mpv_common_frame_size_change
int ff_mpv_common_frame_size_change(MpegEncContext *s)
Definition: mpegvideo_dec.c:187
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:312
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:77
ff_find_unused_picture
int ff_find_unused_picture(AVCodecContext *avctx, Picture *picture, int shared)
Definition: mpegpicture.c:449
threadframe.h
NULL
#define NULL
Definition: coverity.c:32
ff_mpv_idct_init
av_cold void ff_mpv_idct_init(MpegEncContext *s)
Definition: mpegvideo.c:331
AV_PICTURE_TYPE_I
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
FF_PTR_ADD
#define FF_PTR_ADD(ptr, off)
Definition: internal.h:99
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:254
FF_MPV_QSCALE_TYPE_MPEG1
#define FF_MPV_QSCALE_TYPE_MPEG1
Definition: mpegvideodec.h:40
AV_CODEC_ID_MPEG1VIDEO
@ AV_CODEC_ID_MPEG1VIDEO
Definition: codec_id.h:53
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:369
AV_CODEC_ID_H263
@ AV_CODEC_ID_H263
Definition: codec_id.h:56
ff_mpeg_draw_horiz_band
void ff_mpeg_draw_horiz_band(MpegEncContext *s, int y, int h)
Definition: mpegvideo_dec.c:524
Picture::alloc_mb_height
int alloc_mb_height
mb_height used to allocate tables
Definition: mpegpicture.h:66
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:263
ff_mpeg_flush
void ff_mpeg_flush(AVCodecContext *avctx)
Definition: mpegvideo_dec.c:532
Picture::motion_val
int16_t(*[2] motion_val)[2]
Definition: mpegpicture.h:54
AVCodec::id
enum AVCodecID id
Definition: codec.h:218
FMT_H263
@ FMT_H263
Definition: mpegutils.h:119
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
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
AVCodecContext::height
int height
Definition: avcodec.h:571
FF_DEBUG_NOMC
#define FF_DEBUG_NOMC
Definition: avcodec.h:1342
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:235
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:366
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:750
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:398
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:479
AVCodecContext::coded_width
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:586
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:396
AVCodecContext::codec_tag
unsigned int codec_tag
fourcc (LSB first, so "ABCD" -> ('D'<<24) + ('C'<<16) + ('B'<<8) + 'A').
Definition: avcodec.h:423
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:425
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:565
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:571
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
AV_CODEC_ID_FLV1
@ AV_CODEC_ID_FLV1
Definition: codec_id.h:73
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:62
Picture::alloc_mb_stride
int alloc_mb_stride
mb_stride used to allocate tables
Definition: mpegpicture.h:67
video_enc_params.h
ff_print_debug_info2
void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict, const uint8_t *mbskip_table, const uint32_t *mbtype_table, const int8_t *qscale_table, int16_t(*const 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:156