FFmpeg
mpegpicture.c
Go to the documentation of this file.
1 /*
2  * Mpeg video formats-related picture management functions
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include <stdint.h>
22 
23 #include "libavutil/avassert.h"
24 #include "libavutil/common.h"
25 #include "libavutil/pixdesc.h"
26 #include "libavutil/imgutils.h"
27 
28 #include "avcodec.h"
29 #include "motion_est.h"
30 #include "mpegpicture.h"
31 #include "mpegutils.h"
32 
33 static int make_tables_writable(Picture *pic)
34 {
35  int ret, i;
36 #define MAKE_WRITABLE(table) \
37 do {\
38  if (pic->table &&\
39  (ret = av_buffer_make_writable(&pic->table)) < 0)\
40  return ret;\
41 } while (0)
42 
43  MAKE_WRITABLE(mb_var_buf);
44  MAKE_WRITABLE(mc_mb_var_buf);
45  MAKE_WRITABLE(mb_mean_buf);
46  MAKE_WRITABLE(mbskip_table_buf);
47  MAKE_WRITABLE(qscale_table_buf);
48  MAKE_WRITABLE(mb_type_buf);
49 
50  for (i = 0; i < 2; i++) {
51  MAKE_WRITABLE(motion_val_buf[i]);
52  MAKE_WRITABLE(ref_index_buf[i]);
53  }
54 
55  return 0;
56 }
57 
59  ScratchpadContext *sc, int linesize)
60 {
61 # define EMU_EDGE_HEIGHT (4 * 70)
62  int alloc_size = FFALIGN(FFABS(linesize) + 64, 32);
63 
64  if (avctx->hwaccel)
65  return 0;
66 
67  if (linesize < 24) {
68  av_log(avctx, AV_LOG_ERROR, "Image too small, temporary buffers cannot function\n");
69  return AVERROR_PATCHWELCOME;
70  }
71 
72  if (av_image_check_size2(alloc_size, EMU_EDGE_HEIGHT, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx) < 0)
73  return AVERROR(ENOMEM);
74 
75  // edge emu needs blocksize + filter length - 1
76  // (= 17x17 for halfpel / 21x21 for H.264)
77  // VC-1 computes luma and chroma simultaneously and needs 19X19 + 9x9
78  // at uvlinesize. It supports only YUV420 so 24x24 is enough
79  // linesize * interlaced * MBsize
80  // we also use this buffer for encoding in encode_mb_internal() needig an additional 32 lines
81  if (!FF_ALLOCZ_TYPED_ARRAY(sc->edge_emu_buffer, alloc_size * EMU_EDGE_HEIGHT) ||
82  !FF_ALLOCZ_TYPED_ARRAY(me->scratchpad, alloc_size * 4 * 16 * 2))
83  return AVERROR(ENOMEM);
84  me->temp = me->scratchpad;
85  sc->rd_scratchpad = me->scratchpad;
86  sc->b_scratchpad = me->scratchpad;
87  sc->obmc_scratchpad = me->scratchpad + 16;
88 
89  return 0;
90 }
91 
92 /**
93  * Allocate a frame buffer
94  */
95 static int alloc_frame_buffer(AVCodecContext *avctx, Picture *pic,
97  int chroma_x_shift, int chroma_y_shift,
98  int linesize, int uvlinesize)
99 {
100  int edges_needed = av_codec_is_encoder(avctx->codec);
101  int r, ret;
102 
103  pic->tf.f = pic->f;
104  if (avctx->codec_id != AV_CODEC_ID_WMV3IMAGE &&
105  avctx->codec_id != AV_CODEC_ID_VC1IMAGE &&
106  avctx->codec_id != AV_CODEC_ID_MSS2) {
107  if (edges_needed) {
108  pic->f->width = avctx->width + 2 * EDGE_WIDTH;
109  pic->f->height = avctx->height + 2 * EDGE_WIDTH;
110  }
111 
112  r = ff_thread_get_buffer(avctx, &pic->tf,
113  pic->reference ? AV_GET_BUFFER_FLAG_REF : 0);
114  } else {
115  pic->f->width = avctx->width;
116  pic->f->height = avctx->height;
117  pic->f->format = avctx->pix_fmt;
118  r = avcodec_default_get_buffer2(avctx, pic->f, 0);
119  }
120 
121  if (r < 0 || !pic->f->buf[0]) {
122  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed (%d %p)\n",
123  r, pic->f->data[0]);
124  return -1;
125  }
126 
127  if (edges_needed) {
128  int i;
129  for (i = 0; pic->f->data[i]; i++) {
130  int offset = (EDGE_WIDTH >> (i ? chroma_y_shift : 0)) *
131  pic->f->linesize[i] +
132  (EDGE_WIDTH >> (i ? chroma_x_shift : 0));
133  pic->f->data[i] += offset;
134  }
135  pic->f->width = avctx->width;
136  pic->f->height = avctx->height;
137  }
138 
139  if (avctx->hwaccel) {
140  assert(!pic->hwaccel_picture_private);
141  if (avctx->hwaccel->frame_priv_data_size) {
143  if (!pic->hwaccel_priv_buf) {
144  av_log(avctx, AV_LOG_ERROR, "alloc_frame_buffer() failed (hwaccel private data allocation)\n");
145  return -1;
146  }
148  }
149  }
150 
151  if ((linesize && linesize != pic->f->linesize[0]) ||
152  (uvlinesize && uvlinesize != pic->f->linesize[1])) {
153  av_log(avctx, AV_LOG_ERROR,
154  "get_buffer() failed (stride changed: linesize=%d/%d uvlinesize=%d/%d)\n",
155  linesize, pic->f->linesize[0],
156  uvlinesize, pic->f->linesize[1]);
157  ff_mpeg_unref_picture(avctx, pic);
158  return -1;
159  }
160 
161  if (av_pix_fmt_count_planes(pic->f->format) > 2 &&
162  pic->f->linesize[1] != pic->f->linesize[2]) {
163  av_log(avctx, AV_LOG_ERROR,
164  "get_buffer() failed (uv stride mismatch)\n");
165  ff_mpeg_unref_picture(avctx, pic);
166  return -1;
167  }
168 
169  if (!sc->edge_emu_buffer &&
170  (ret = ff_mpeg_framesize_alloc(avctx, me, sc,
171  pic->f->linesize[0])) < 0) {
172  av_log(avctx, AV_LOG_ERROR,
173  "get_buffer() failed to allocate context scratch buffers.\n");
174  ff_mpeg_unref_picture(avctx, pic);
175  return ret;
176  }
177 
178  return 0;
179 }
180 
181 static int alloc_picture_tables(AVCodecContext *avctx, Picture *pic, int encoding, int out_format,
182  int mb_stride, int mb_width, int mb_height, int b8_stride)
183 {
184  const int big_mb_num = mb_stride * (mb_height + 1) + 1;
185  const int mb_array_size = mb_stride * mb_height;
186  const int b8_array_size = b8_stride * mb_height * 2;
187  int i;
188 
189 
190  pic->mbskip_table_buf = av_buffer_allocz(mb_array_size + 2);
191  pic->qscale_table_buf = av_buffer_allocz(big_mb_num + mb_stride);
192  pic->mb_type_buf = av_buffer_allocz((big_mb_num + mb_stride) *
193  sizeof(uint32_t));
194  if (!pic->mbskip_table_buf || !pic->qscale_table_buf || !pic->mb_type_buf)
195  return AVERROR(ENOMEM);
196 
197  if (encoding) {
198  pic->mb_var_buf = av_buffer_allocz(mb_array_size * sizeof(int16_t));
199  pic->mc_mb_var_buf = av_buffer_allocz(mb_array_size * sizeof(int16_t));
200  pic->mb_mean_buf = av_buffer_allocz(mb_array_size);
201  if (!pic->mb_var_buf || !pic->mc_mb_var_buf || !pic->mb_mean_buf)
202  return AVERROR(ENOMEM);
203  }
204 
205  if (out_format == FMT_H263 || encoding ||
207  int mv_size = 2 * (b8_array_size + 4) * sizeof(int16_t);
208  int ref_index_size = 4 * mb_array_size;
209 
210  for (i = 0; mv_size && i < 2; i++) {
211  pic->motion_val_buf[i] = av_buffer_allocz(mv_size);
212  pic->ref_index_buf[i] = av_buffer_allocz(ref_index_size);
213  if (!pic->motion_val_buf[i] || !pic->ref_index_buf[i])
214  return AVERROR(ENOMEM);
215  }
216  }
217 
218  pic->alloc_mb_width = mb_width;
219  pic->alloc_mb_height = mb_height;
220  pic->alloc_mb_stride = mb_stride;
221 
222  return 0;
223 }
224 
225 /**
226  * Allocate a Picture.
227  * The pixels are allocated/set by calling get_buffer() if shared = 0
228  */
230  ScratchpadContext *sc, int shared, int encoding,
231  int chroma_x_shift, int chroma_y_shift, int out_format,
232  int mb_stride, int mb_width, int mb_height, int b8_stride,
233  ptrdiff_t *linesize, ptrdiff_t *uvlinesize)
234 {
235  int i, ret;
236 
237  if (pic->qscale_table_buf)
238  if ( pic->alloc_mb_width != mb_width
239  || pic->alloc_mb_height != mb_height)
241 
242  if (shared) {
243  av_assert0(pic->f->data[0]);
244  pic->shared = 1;
245  } else {
246  av_assert0(!pic->f->buf[0]);
247  if (alloc_frame_buffer(avctx, pic, me, sc,
248  chroma_x_shift, chroma_y_shift,
249  *linesize, *uvlinesize) < 0)
250  return -1;
251 
252  *linesize = pic->f->linesize[0];
253  *uvlinesize = pic->f->linesize[1];
254  }
255 
256  if (!pic->qscale_table_buf)
257  ret = alloc_picture_tables(avctx, pic, encoding, out_format,
258  mb_stride, mb_width, mb_height, b8_stride);
259  else
260  ret = make_tables_writable(pic);
261  if (ret < 0)
262  goto fail;
263 
264  if (encoding) {
265  pic->mb_var = (uint16_t*)pic->mb_var_buf->data;
266  pic->mc_mb_var = (uint16_t*)pic->mc_mb_var_buf->data;
267  pic->mb_mean = pic->mb_mean_buf->data;
268  }
269 
270  pic->mbskip_table = pic->mbskip_table_buf->data;
271  pic->qscale_table = pic->qscale_table_buf->data + 2 * mb_stride + 1;
272  pic->mb_type = (uint32_t*)pic->mb_type_buf->data + 2 * mb_stride + 1;
273 
274  if (pic->motion_val_buf[0]) {
275  for (i = 0; i < 2; i++) {
276  pic->motion_val[i] = (int16_t (*)[2])pic->motion_val_buf[i]->data + 4;
277  pic->ref_index[i] = pic->ref_index_buf[i]->data;
278  }
279  }
280 
281  return 0;
282 fail:
283  av_log(avctx, AV_LOG_ERROR, "Error allocating a picture.\n");
284  ff_mpeg_unref_picture(avctx, pic);
286  return AVERROR(ENOMEM);
287 }
288 
289 /**
290  * Deallocate a picture.
291  */
293 {
294  int off = offsetof(Picture, mb_mean) + sizeof(pic->mb_mean);
295 
296  pic->tf.f = pic->f;
297  /* WM Image / Screen codecs allocate internal buffers with different
298  * dimensions / colorspaces; ignore user-defined callbacks for these. */
299  if (avctx->codec_id != AV_CODEC_ID_WMV3IMAGE &&
300  avctx->codec_id != AV_CODEC_ID_VC1IMAGE &&
301  avctx->codec_id != AV_CODEC_ID_MSS2)
302  ff_thread_release_buffer(avctx, &pic->tf);
303  else if (pic->f)
304  av_frame_unref(pic->f);
305 
307 
308  if (pic->needs_realloc)
310 
311  memset((uint8_t*)pic + off, 0, sizeof(*pic) - off);
312 }
313 
315 {
316  int i, ret;
317 
318  ret = av_buffer_replace(&dst->mb_var_buf, src->mb_var_buf);
319  ret |= av_buffer_replace(&dst->mc_mb_var_buf, src->mc_mb_var_buf);
320  ret |= av_buffer_replace(&dst->mb_mean_buf, src->mb_mean_buf);
323  ret |= av_buffer_replace(&dst->mb_type_buf, src->mb_type_buf);
324  for (i = 0; i < 2; i++) {
325  ret |= av_buffer_replace(&dst->motion_val_buf[i], src->motion_val_buf[i]);
326  ret |= av_buffer_replace(&dst->ref_index_buf[i], src->ref_index_buf[i]);
327  }
328 
329  if (ret < 0) {
331  return ret;
332  }
333 
334  dst->mb_var = src->mb_var;
335  dst->mc_mb_var = src->mc_mb_var;
336  dst->mb_mean = src->mb_mean;
337  dst->mbskip_table = src->mbskip_table;
338  dst->qscale_table = src->qscale_table;
339  dst->mb_type = src->mb_type;
340  for (i = 0; i < 2; i++) {
341  dst->motion_val[i] = src->motion_val[i];
342  dst->ref_index[i] = src->ref_index[i];
343  }
344 
345  dst->alloc_mb_width = src->alloc_mb_width;
346  dst->alloc_mb_height = src->alloc_mb_height;
347  dst->alloc_mb_stride = src->alloc_mb_stride;
348 
349  return 0;
350 }
351 
353 {
354  int ret;
355 
356  av_assert0(!dst->f->buf[0]);
357  av_assert0(src->f->buf[0]);
358 
359  src->tf.f = src->f;
360  dst->tf.f = dst->f;
361  ret = ff_thread_ref_frame(&dst->tf, &src->tf);
362  if (ret < 0)
363  goto fail;
364 
365  ret = ff_update_picture_tables(dst, src);
366  if (ret < 0)
367  goto fail;
368 
369  if (src->hwaccel_picture_private) {
371  if (!dst->hwaccel_priv_buf) {
372  ret = AVERROR(ENOMEM);
373  goto fail;
374  }
376  }
377 
378  dst->field_picture = src->field_picture;
379  dst->mb_var_sum = src->mb_var_sum;
380  dst->mc_mb_var_sum = src->mc_mb_var_sum;
381  dst->b_frame_score = src->b_frame_score;
382  dst->needs_realloc = src->needs_realloc;
383  dst->reference = src->reference;
384  dst->shared = src->shared;
385 
386  memcpy(dst->encoding_error, src->encoding_error,
387  sizeof(dst->encoding_error));
388 
389  return 0;
390 fail:
391  ff_mpeg_unref_picture(avctx, dst);
392  return ret;
393 }
394 
395 static inline int pic_is_unused(Picture *pic)
396 {
397  if (!pic->f->buf[0])
398  return 1;
399  if (pic->needs_realloc && !(pic->reference & DELAYED_PIC_REF))
400  return 1;
401  return 0;
402 }
403 
404 static int find_unused_picture(AVCodecContext *avctx, Picture *picture, int shared)
405 {
406  int i;
407 
408  if (shared) {
409  for (i = 0; i < MAX_PICTURE_COUNT; i++) {
410  if (!picture[i].f->buf[0])
411  return i;
412  }
413  } else {
414  for (i = 0; i < MAX_PICTURE_COUNT; i++) {
415  if (pic_is_unused(&picture[i]))
416  return i;
417  }
418  }
419 
420  av_log(avctx, AV_LOG_FATAL,
421  "Internal error, picture buffer overflow\n");
422  /* We could return -1, but the codec would crash trying to draw into a
423  * non-existing frame anyway. This is safer than waiting for a random crash.
424  * Also the return of this is never useful, an encoder must only allocate
425  * as much as allowed in the specification. This has no relationship to how
426  * much libavcodec could allocate (and MAX_PICTURE_COUNT is always large
427  * enough for such valid streams).
428  * Plus, a decoder has to check stream validity and remove frames if too
429  * many reference frames are around. Waiting for "OOM" is not correct at
430  * all. Similarly, missing reference frames have to be replaced by
431  * interpolated/MC frames, anything else is a bug in the codec ...
432  */
433  abort();
434  return -1;
435 }
436 
437 int ff_find_unused_picture(AVCodecContext *avctx, Picture *picture, int shared)
438 {
439  int ret = find_unused_picture(avctx, picture, shared);
440 
441  if (ret >= 0 && ret < MAX_PICTURE_COUNT) {
442  if (picture[ret].needs_realloc) {
443  picture[ret].needs_realloc = 0;
444  ff_free_picture_tables(&picture[ret]);
445  ff_mpeg_unref_picture(avctx, &picture[ret]);
446  }
447  }
448  return ret;
449 }
450 
452 {
453  int i;
454 
455  pic->alloc_mb_width =
456  pic->alloc_mb_height = 0;
457 
464 
465  for (i = 0; i < 2; i++) {
467  av_buffer_unref(&pic->ref_index_buf[i]);
468  }
469 }
uint8_t * scratchpad
data area for the ME algo, so that the ME does not need to malloc/free.
Definition: motion_est.h:52
const struct AVCodec * codec
Definition: avcodec.h:540
int8_t * ref_index[2]
Definition: mpegpicture.h:62
AVBufferRef * mb_var_buf
Definition: mpegpicture.h:64
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
Definition: buffer.c:125
int av_codec_is_encoder(const AVCodec *codec)
Definition: utils.c:96
uint8_t * mb_mean
Table for MB luminance.
Definition: mpegpicture.h:75
uint8_t * edge_emu_buffer
temporary buffer for if MVs point to out-of-frame data
Definition: mpegpicture.h:36
misc image utilities
AVFrame * f
Definition: thread.h:35
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2613
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:505
uint16_t * mb_var
Table for MB variances.
Definition: mpegpicture.h:65
static int pic_is_unused(Picture *pic)
Definition: mpegpicture.c:395
#define me
int needs_realloc
Picture needs to be reallocated (eg due to a frame size change)
Definition: mpegpicture.h:86
#define DELAYED_PIC_REF
Value of Picture.reference when Picture is not a reference picture, but is held for delayed output...
Definition: diracdec.c:68
int field_picture
whether or not the picture was encoded in separate fields
Definition: mpegpicture.h:80
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:741
static int alloc_frame_buffer(AVCodecContext *avctx, Picture *pic, MotionEstContext *me, ScratchpadContext *sc, int chroma_x_shift, int chroma_y_shift, int linesize, int uvlinesize)
Allocate a frame buffer.
Definition: mpegpicture.c:95
int ff_mpeg_ref_picture(AVCodecContext *avctx, Picture *dst, Picture *src)
Definition: mpegpicture.c:352
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:1675
int b_frame_score
Definition: mpegpicture.h:85
int alloc_mb_width
mb_width used to allocate tables
Definition: mpegpicture.h:70
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int export_side_data
Bit set of AV_CODEC_EXPORT_DATA_* flags, which affects the kind of metadata exported in frame...
Definition: avcodec.h:2337
uint8_t
#define AV_CODEC_EXPORT_DATA_MVS
Export motion vectors through frame side data.
Definition: avcodec.h:403
static int make_tables_writable(Picture *pic)
Definition: mpegpicture.c:33
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
#define f(width, name)
Definition: cbs_vp9.c:255
Motion estimation context.
Definition: motion_est.h:47
void ff_free_picture_tables(Picture *pic)
Definition: mpegpicture.c:451
int ff_find_unused_picture(AVCodecContext *avctx, Picture *picture, int shared)
Definition: mpegpicture.c:437
AVBufferRef * mb_type_buf
Definition: mpegpicture.h:55
#define FFALIGN(x, a)
Definition: macros.h:48
#define av_log(a,...)
AVBufferRef * mb_mean_buf
Definition: mpegpicture.h:74
#define EDGE_WIDTH
Definition: mpegpicture.h:33
ThreadFrame tf
Definition: mpegpicture.h:47
#define src
Definition: vp8dsp.c:255
int width
Definition: frame.h:372
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
uint8_t * mbskip_table
Definition: mpegpicture.h:59
static int alloc_picture_tables(AVCodecContext *avctx, Picture *pic, int encoding, int out_format, int mb_stride, int mb_width, int mb_height, int b8_stride)
Definition: mpegpicture.c:181
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
uint8_t * rd_scratchpad
scratchpad for rate distortion mb decision
Definition: mpegpicture.h:37
uint64_t encoding_error[AV_NUM_DATA_POINTERS]
Definition: mpegpicture.h:91
#define MAX_PICTURE_COUNT
Definition: mpegpicture.h:32
int reference
Definition: mpegpicture.h:88
const char * r
Definition: vf_curves.c:116
simple assert() macros that are a bit more flexible than ISO C assert().
int64_t max_pixels
The number of pixels per image to maximally accept.
Definition: avcodec.h:2239
#define fail()
Definition: checkasm.h:133
the pkt_dts and pkt_pts fields in AVFrame will work as usual Restrictions on codec whose streams don t reset across will not work because their bitstreams cannot be decoded in parallel *The contents of buffers must not be read before as well as code calling up to before the decode process starts Call have so the codec calls ff_thread_report set FF_CODEC_CAP_ALLOCATE_PROGRESS in AVCodec caps_internal and use ff_thread_get_buffer() to allocate frames.The frames must then be freed with ff_thread_release_buffer().Otherwise decode directly into the user-supplied frames.Call ff_thread_report_progress() after some part of the current picture has decoded.A good place to put this is where draw_horiz_band() is called-add this if it isn't called anywhere
AVBufferRef * hwaccel_priv_buf
Definition: mpegpicture.h:77
AVBufferRef * motion_val_buf[2]
Definition: mpegpicture.h:52
int width
picture width / height.
Definition: avcodec.h:704
int16_t(*[2] motion_val)[2]
Definition: mpegpicture.h:53
Picture.
Definition: mpegpicture.h:45
void * hwaccel_picture_private
Hardware accelerator private data.
Definition: mpegpicture.h:78
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
Definition: utils.c:1907
if(ret)
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:387
uint16_t * mc_mb_var
Table for motion compensated MB variances.
Definition: mpegpicture.h:68
AVBufferRef * qscale_table_buf
Definition: mpegpicture.h:49
int alloc_mb_height
mb_height used to allocate tables
Definition: mpegpicture.h:71
int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags)
The default callback for AVCodecContext.get_buffer2().
Definition: decode.c:1673
Libavcodec external API header.
enum AVCodecID codec_id
Definition: avcodec.h:541
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:345
main external API structure.
Definition: avcodec.h:531
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:229
uint8_t * data
The data buffer.
Definition: buffer.h:89
AVBufferRef * av_buffer_allocz(int size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
Definition: buffer.c:83
int ff_mpeg_framesize_alloc(AVCodecContext *avctx, MotionEstContext *me, ScratchpadContext *sc, int linesize)
Definition: mpegpicture.c:58
int64_t mc_mb_var_sum
motion compensated MB variance for current frame
Definition: mpegpicture.h:83
struct AVFrame * f
Definition: mpegpicture.h:46
static int find_unused_picture(AVCodecContext *avctx, Picture *picture, int shared)
Definition: mpegpicture.c:404
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:553
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:328
int8_t * qscale_table
Definition: mpegpicture.h:50
void ff_mpeg_unref_picture(AVCodecContext *avctx, Picture *pic)
Deallocate a picture.
Definition: mpegpicture.c:292
#define MAKE_WRITABLE(table)
common internal and external API header
AVBufferRef * mbskip_table_buf
Definition: mpegpicture.h:58
int shared
Definition: mpegpicture.h:89
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
uint8_t * b_scratchpad
scratchpad used for writing into write only buffers
Definition: mpegpicture.h:39
int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enum AVPixelFormat pix_fmt, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of a plane of an image with...
Definition: imgutils.c:288
int ff_update_picture_tables(Picture *dst, Picture *src)
Definition: mpegpicture.c:314
uint8_t * obmc_scratchpad
Definition: mpegpicture.h:38
int frame_priv_data_size
Size of per-frame hardware accelerator private data.
Definition: avcodec.h:2501
AVBufferRef * mc_mb_var_buf
Definition: mpegpicture.h:67
#define EMU_EDGE_HEIGHT
int height
Definition: frame.h:372
uint32_t * mb_type
types and macros are defined in mpegutils.h
Definition: mpegpicture.h:56
uint8_t * temp
Definition: motion_est.h:56
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:188
#define FF_ALLOCZ_TYPED_ARRAY(p, nelem)
Definition: internal.h:103
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
int alloc_mb_stride
mb_stride used to allocate tables
Definition: mpegpicture.h:72
int64_t mb_var_sum
sum of MB variance for current frame
Definition: mpegpicture.h:82
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:514
int i
Definition: input.c:407
int av_buffer_replace(AVBufferRef **pdst, AVBufferRef *src)
Ensure dst refers to the same data as src.
Definition: buffer.c:219
AVBufferRef * ref_index_buf[2]
Definition: mpegpicture.h:61