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
82  fail);
83 
84  FF_ALLOCZ_ARRAY_OR_GOTO(avctx, me->scratchpad, alloc_size, 4 * 16 * 2,
85  fail)
86  me->temp = me->scratchpad;
87  sc->rd_scratchpad = me->scratchpad;
88  sc->b_scratchpad = me->scratchpad;
89  sc->obmc_scratchpad = me->scratchpad + 16;
90 
91  return 0;
92 fail:
94  return AVERROR(ENOMEM);
95 }
96 
97 /**
98  * Allocate a frame buffer
99  */
100 static int alloc_frame_buffer(AVCodecContext *avctx, Picture *pic,
102  int chroma_x_shift, int chroma_y_shift,
103  int linesize, int uvlinesize)
104 {
105  int edges_needed = av_codec_is_encoder(avctx->codec);
106  int r, ret;
107 
108  pic->tf.f = pic->f;
109  if (avctx->codec_id != AV_CODEC_ID_WMV3IMAGE &&
110  avctx->codec_id != AV_CODEC_ID_VC1IMAGE &&
111  avctx->codec_id != AV_CODEC_ID_MSS2) {
112  if (edges_needed) {
113  pic->f->width = avctx->width + 2 * EDGE_WIDTH;
114  pic->f->height = avctx->height + 2 * EDGE_WIDTH;
115  }
116 
117  r = ff_thread_get_buffer(avctx, &pic->tf,
118  pic->reference ? AV_GET_BUFFER_FLAG_REF : 0);
119  } else {
120  pic->f->width = avctx->width;
121  pic->f->height = avctx->height;
122  pic->f->format = avctx->pix_fmt;
123  r = avcodec_default_get_buffer2(avctx, pic->f, 0);
124  }
125 
126  if (r < 0 || !pic->f->buf[0]) {
127  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed (%d %p)\n",
128  r, pic->f->data[0]);
129  return -1;
130  }
131 
132  if (edges_needed) {
133  int i;
134  for (i = 0; pic->f->data[i]; i++) {
135  int offset = (EDGE_WIDTH >> (i ? chroma_y_shift : 0)) *
136  pic->f->linesize[i] +
137  (EDGE_WIDTH >> (i ? chroma_x_shift : 0));
138  pic->f->data[i] += offset;
139  }
140  pic->f->width = avctx->width;
141  pic->f->height = avctx->height;
142  }
143 
144  if (avctx->hwaccel) {
145  assert(!pic->hwaccel_picture_private);
146  if (avctx->hwaccel->frame_priv_data_size) {
148  if (!pic->hwaccel_priv_buf) {
149  av_log(avctx, AV_LOG_ERROR, "alloc_frame_buffer() failed (hwaccel private data allocation)\n");
150  return -1;
151  }
153  }
154  }
155 
156  if ((linesize && linesize != pic->f->linesize[0]) ||
157  (uvlinesize && uvlinesize != pic->f->linesize[1])) {
158  av_log(avctx, AV_LOG_ERROR,
159  "get_buffer() failed (stride changed: linesize=%d/%d uvlinesize=%d/%d)\n",
160  linesize, pic->f->linesize[0],
161  uvlinesize, pic->f->linesize[1]);
162  ff_mpeg_unref_picture(avctx, pic);
163  return -1;
164  }
165 
166  if (av_pix_fmt_count_planes(pic->f->format) > 2 &&
167  pic->f->linesize[1] != pic->f->linesize[2]) {
168  av_log(avctx, AV_LOG_ERROR,
169  "get_buffer() failed (uv stride mismatch)\n");
170  ff_mpeg_unref_picture(avctx, pic);
171  return -1;
172  }
173 
174  if (!sc->edge_emu_buffer &&
175  (ret = ff_mpeg_framesize_alloc(avctx, me, sc,
176  pic->f->linesize[0])) < 0) {
177  av_log(avctx, AV_LOG_ERROR,
178  "get_buffer() failed to allocate context scratch buffers.\n");
179  ff_mpeg_unref_picture(avctx, pic);
180  return ret;
181  }
182 
183  return 0;
184 }
185 
186 static int alloc_picture_tables(AVCodecContext *avctx, Picture *pic, int encoding, int out_format,
187  int mb_stride, int mb_width, int mb_height, int b8_stride)
188 {
189  const int big_mb_num = mb_stride * (mb_height + 1) + 1;
190  const int mb_array_size = mb_stride * mb_height;
191  const int b8_array_size = b8_stride * mb_height * 2;
192  int i;
193 
194 
195  pic->mbskip_table_buf = av_buffer_allocz(mb_array_size + 2);
196  pic->qscale_table_buf = av_buffer_allocz(big_mb_num + mb_stride);
197  pic->mb_type_buf = av_buffer_allocz((big_mb_num + mb_stride) *
198  sizeof(uint32_t));
199  if (!pic->mbskip_table_buf || !pic->qscale_table_buf || !pic->mb_type_buf)
200  return AVERROR(ENOMEM);
201 
202  if (encoding) {
203  pic->mb_var_buf = av_buffer_allocz(mb_array_size * sizeof(int16_t));
204  pic->mc_mb_var_buf = av_buffer_allocz(mb_array_size * sizeof(int16_t));
205  pic->mb_mean_buf = av_buffer_allocz(mb_array_size);
206  if (!pic->mb_var_buf || !pic->mc_mb_var_buf || !pic->mb_mean_buf)
207  return AVERROR(ENOMEM);
208  }
209 
210  if (out_format == FMT_H263 || encoding ||
211 #if FF_API_DEBUG_MV
212  avctx->debug_mv ||
213 #endif
215  int mv_size = 2 * (b8_array_size + 4) * sizeof(int16_t);
216  int ref_index_size = 4 * mb_array_size;
217 
218  for (i = 0; mv_size && i < 2; i++) {
219  pic->motion_val_buf[i] = av_buffer_allocz(mv_size);
220  pic->ref_index_buf[i] = av_buffer_allocz(ref_index_size);
221  if (!pic->motion_val_buf[i] || !pic->ref_index_buf[i])
222  return AVERROR(ENOMEM);
223  }
224  }
225 
226  pic->alloc_mb_width = mb_width;
227  pic->alloc_mb_height = mb_height;
228 
229  return 0;
230 }
231 
232 /**
233  * Allocate a Picture.
234  * The pixels are allocated/set by calling get_buffer() if shared = 0
235  */
237  ScratchpadContext *sc, int shared, int encoding,
238  int chroma_x_shift, int chroma_y_shift, int out_format,
239  int mb_stride, int mb_width, int mb_height, int b8_stride,
240  ptrdiff_t *linesize, ptrdiff_t *uvlinesize)
241 {
242  int i, ret;
243 
244  if (pic->qscale_table_buf)
245  if ( pic->alloc_mb_width != mb_width
246  || pic->alloc_mb_height != mb_height)
248 
249  if (shared) {
250  av_assert0(pic->f->data[0]);
251  pic->shared = 1;
252  } else {
253  av_assert0(!pic->f->buf[0]);
254  if (alloc_frame_buffer(avctx, pic, me, sc,
255  chroma_x_shift, chroma_y_shift,
256  *linesize, *uvlinesize) < 0)
257  return -1;
258 
259  *linesize = pic->f->linesize[0];
260  *uvlinesize = pic->f->linesize[1];
261  }
262 
263  if (!pic->qscale_table_buf)
264  ret = alloc_picture_tables(avctx, pic, encoding, out_format,
265  mb_stride, mb_width, mb_height, b8_stride);
266  else
267  ret = make_tables_writable(pic);
268  if (ret < 0)
269  goto fail;
270 
271  if (encoding) {
272  pic->mb_var = (uint16_t*)pic->mb_var_buf->data;
273  pic->mc_mb_var = (uint16_t*)pic->mc_mb_var_buf->data;
274  pic->mb_mean = pic->mb_mean_buf->data;
275  }
276 
277  pic->mbskip_table = pic->mbskip_table_buf->data;
278  pic->qscale_table = pic->qscale_table_buf->data + 2 * mb_stride + 1;
279  pic->mb_type = (uint32_t*)pic->mb_type_buf->data + 2 * mb_stride + 1;
280 
281  if (pic->motion_val_buf[0]) {
282  for (i = 0; i < 2; i++) {
283  pic->motion_val[i] = (int16_t (*)[2])pic->motion_val_buf[i]->data + 4;
284  pic->ref_index[i] = pic->ref_index_buf[i]->data;
285  }
286  }
287 
288  return 0;
289 fail:
290  av_log(avctx, AV_LOG_ERROR, "Error allocating a picture.\n");
291  ff_mpeg_unref_picture(avctx, pic);
293  return AVERROR(ENOMEM);
294 }
295 
296 /**
297  * Deallocate a picture.
298  */
300 {
301  int off = offsetof(Picture, mb_mean) + sizeof(pic->mb_mean);
302 
303  pic->tf.f = pic->f;
304  /* WM Image / Screen codecs allocate internal buffers with different
305  * dimensions / colorspaces; ignore user-defined callbacks for these. */
306  if (avctx->codec_id != AV_CODEC_ID_WMV3IMAGE &&
307  avctx->codec_id != AV_CODEC_ID_VC1IMAGE &&
308  avctx->codec_id != AV_CODEC_ID_MSS2)
309  ff_thread_release_buffer(avctx, &pic->tf);
310  else if (pic->f)
311  av_frame_unref(pic->f);
312 
314 
315  if (pic->needs_realloc)
317 
318  memset((uint8_t*)pic + off, 0, sizeof(*pic) - off);
319 }
320 
322 {
323  int i;
324 
325 #define UPDATE_TABLE(table) \
326 do { \
327  if (src->table && \
328  (!dst->table || dst->table->buffer != src->table->buffer)) { \
329  av_buffer_unref(&dst->table); \
330  dst->table = av_buffer_ref(src->table); \
331  if (!dst->table) { \
332  ff_free_picture_tables(dst); \
333  return AVERROR(ENOMEM); \
334  } \
335  } \
336 } while (0)
337 
338  UPDATE_TABLE(mb_var_buf);
339  UPDATE_TABLE(mc_mb_var_buf);
340  UPDATE_TABLE(mb_mean_buf);
341  UPDATE_TABLE(mbskip_table_buf);
342  UPDATE_TABLE(qscale_table_buf);
343  UPDATE_TABLE(mb_type_buf);
344  for (i = 0; i < 2; i++) {
345  UPDATE_TABLE(motion_val_buf[i]);
346  UPDATE_TABLE(ref_index_buf[i]);
347  }
348 
349  dst->mb_var = src->mb_var;
350  dst->mc_mb_var = src->mc_mb_var;
351  dst->mb_mean = src->mb_mean;
352  dst->mbskip_table = src->mbskip_table;
353  dst->qscale_table = src->qscale_table;
354  dst->mb_type = src->mb_type;
355  for (i = 0; i < 2; i++) {
356  dst->motion_val[i] = src->motion_val[i];
357  dst->ref_index[i] = src->ref_index[i];
358  }
359 
360  dst->alloc_mb_width = src->alloc_mb_width;
361  dst->alloc_mb_height = src->alloc_mb_height;
362 
363  return 0;
364 }
365 
367 {
368  int ret;
369 
370  av_assert0(!dst->f->buf[0]);
371  av_assert0(src->f->buf[0]);
372 
373  src->tf.f = src->f;
374  dst->tf.f = dst->f;
375  ret = ff_thread_ref_frame(&dst->tf, &src->tf);
376  if (ret < 0)
377  goto fail;
378 
380  if (ret < 0)
381  goto fail;
382 
383  if (src->hwaccel_picture_private) {
384  dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf);
385  if (!dst->hwaccel_priv_buf) {
386  ret = AVERROR(ENOMEM);
387  goto fail;
388  }
390  }
391 
392  dst->field_picture = src->field_picture;
393  dst->mb_var_sum = src->mb_var_sum;
394  dst->mc_mb_var_sum = src->mc_mb_var_sum;
395  dst->b_frame_score = src->b_frame_score;
396  dst->needs_realloc = src->needs_realloc;
397  dst->reference = src->reference;
398  dst->shared = src->shared;
399 
400  memcpy(dst->encoding_error, src->encoding_error,
401  sizeof(dst->encoding_error));
402 
403  return 0;
404 fail:
405  ff_mpeg_unref_picture(avctx, dst);
406  return ret;
407 }
408 
409 static inline int pic_is_unused(Picture *pic)
410 {
411  if (!pic->f->buf[0])
412  return 1;
413  if (pic->needs_realloc && !(pic->reference & DELAYED_PIC_REF))
414  return 1;
415  return 0;
416 }
417 
418 static int find_unused_picture(AVCodecContext *avctx, Picture *picture, int shared)
419 {
420  int i;
421 
422  if (shared) {
423  for (i = 0; i < MAX_PICTURE_COUNT; i++) {
424  if (!picture[i].f->buf[0])
425  return i;
426  }
427  } else {
428  for (i = 0; i < MAX_PICTURE_COUNT; i++) {
429  if (pic_is_unused(&picture[i]))
430  return i;
431  }
432  }
433 
434  av_log(avctx, AV_LOG_FATAL,
435  "Internal error, picture buffer overflow\n");
436  /* We could return -1, but the codec would crash trying to draw into a
437  * non-existing frame anyway. This is safer than waiting for a random crash.
438  * Also the return of this is never useful, an encoder must only allocate
439  * as much as allowed in the specification. This has no relationship to how
440  * much libavcodec could allocate (and MAX_PICTURE_COUNT is always large
441  * enough for such valid streams).
442  * Plus, a decoder has to check stream validity and remove frames if too
443  * many reference frames are around. Waiting for "OOM" is not correct at
444  * all. Similarly, missing reference frames have to be replaced by
445  * interpolated/MC frames, anything else is a bug in the codec ...
446  */
447  abort();
448  return -1;
449 }
450 
451 int ff_find_unused_picture(AVCodecContext *avctx, Picture *picture, int shared)
452 {
453  int ret = find_unused_picture(avctx, picture, shared);
454 
455  if (ret >= 0 && ret < MAX_PICTURE_COUNT) {
456  if (picture[ret].needs_realloc) {
457  picture[ret].needs_realloc = 0;
458  ff_free_picture_tables(&picture[ret]);
459  ff_mpeg_unref_picture(avctx, &picture[ret]);
460  }
461  }
462  return ret;
463 }
464 
466 {
467  int i;
468 
469  pic->alloc_mb_width =
470  pic->alloc_mb_height = 0;
471 
478 
479  for (i = 0; i < 2; i++) {
482  }
483 }
AVCodecContext::hwaccel
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
Definition: avcodec.h:1690
Picture::mb_var_buf
AVBufferRef * mb_var_buf
Definition: mpegpicture.h:64
Picture::ref_index_buf
AVBufferRef * ref_index_buf[2]
Definition: mpegpicture.h:61
EMU_EDGE_HEIGHT
#define EMU_EDGE_HEIGHT
ScratchpadContext::obmc_scratchpad
uint8_t * obmc_scratchpad
Definition: mpegpicture.h:38
ff_mpeg_framesize_alloc
int ff_mpeg_framesize_alloc(AVCodecContext *avctx, MotionEstContext *me, ScratchpadContext *sc, int linesize)
Definition: mpegpicture.c:58
r
const char * r
Definition: vf_curves.c:114
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
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:89
ScratchpadContext::rd_scratchpad
uint8_t * rd_scratchpad
scratchpad for rate distortion mb decision
Definition: mpegpicture.h:37
MotionEstContext
Motion estimation context.
Definition: motion_est.h:47
Picture::alloc_mb_width
int alloc_mb_width
mb_width used to allocate tables
Definition: mpegpicture.h:70
Picture::field_picture
int field_picture
whether or not the picture was encoded in separate fields
Definition: mpegpicture.h:79
pixdesc.h
AVFrame::width
int width
Definition: frame.h:358
ff_free_picture_tables
void ff_free_picture_tables(Picture *pic)
Definition: mpegpicture.c:465
Picture::ref_index
int8_t * ref_index[2]
Definition: mpegpicture.h:62
AVCodecContext::debug_mv
int debug_mv
debug motion vectors
Definition: avcodec.h:2157
av_buffer_allocz
AVBufferRef * av_buffer_allocz(int size)
Same as av_buffer_alloc(), except the returned buffer will be initialized to zero.
Definition: buffer.c:83
Picture
Picture.
Definition: mpegpicture.h:45
Picture::mb_mean
uint8_t * mb_mean
Table for MB luminance.
Definition: mpegpicture.h:74
mpegutils.h
AVFrame::buf
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:491
make_tables_writable
static int make_tables_writable(Picture *pic)
Definition: mpegpicture.c:33
UPDATE_TABLE
#define UPDATE_TABLE(table)
ThreadFrame::f
AVFrame * f
Definition: thread.h:35
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:314
ScratchpadContext
Definition: mpegpicture.h:35
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2589
Picture::needs_realloc
int needs_realloc
Picture needs to be reallocated (eg due to a frame size change)
Definition: mpegpicture.h:85
alloc_picture_tables
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:186
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:535
fail
#define fail()
Definition: checkasm.h:123
ff_thread_get_buffer
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
Picture::mbskip_table
uint8_t * mbskip_table
Definition: mpegpicture.h:59
motion_est.h
MAX_PICTURE_COUNT
#define MAX_PICTURE_COUNT
Definition: mpegpicture.h:32
av_image_check_size2
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:253
avassert.h
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
Picture::b_frame_score
int b_frame_score
Definition: mpegpicture.h:84
ff_mpeg_unref_picture
void ff_mpeg_unref_picture(AVCodecContext *avctx, Picture *pic)
Deallocate a picture.
Definition: mpegpicture.c:299
Picture::hwaccel_priv_buf
AVBufferRef * hwaccel_priv_buf
Definition: mpegpicture.h:76
AV_GET_BUFFER_FLAG_REF
#define AV_GET_BUFFER_FLAG_REF
The decoder will keep a reference to the frame and may reuse it later.
Definition: avcodec.h:509
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AVCodecContext::max_pixels
int64_t max_pixels
The number of pixels per image to maximally accept.
Definition: avcodec.h:2256
AV_CODEC_ID_VC1IMAGE
@ AV_CODEC_ID_VC1IMAGE
Definition: codec_id.h:201
f
#define f(width, name)
Definition: cbs_vp9.c:255
Picture::encoding_error
uint64_t encoding_error[AV_NUM_DATA_POINTERS]
Definition: mpegpicture.h:90
Picture::hwaccel_picture_private
void * hwaccel_picture_private
Hardware accelerator private data.
Definition: mpegpicture.h:77
AVCodecContext::codec_id
enum AVCodecID codec_id
Definition: avcodec.h:536
FFABS
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Definition: common.h:72
if
if(ret)
Definition: filter_design.txt:179
Picture::reference
int reference
Definition: mpegpicture.h:87
Picture::mb_type_buf
AVBufferRef * mb_type_buf
Definition: mpegpicture.h:55
ff_find_unused_picture
int ff_find_unused_picture(AVCodecContext *avctx, Picture *picture, int shared)
Definition: mpegpicture.c:451
AVERROR_PATCHWELCOME
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
Definition: error.h:62
av_buffer_unref
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
me
#define me
Definition: vf_colormatrix.c:104
EDGE_WIDTH
#define EDGE_WIDTH
Definition: mpegpicture.h:33
Picture::mb_mean_buf
AVBufferRef * mb_mean_buf
Definition: mpegpicture.h:73
Picture::motion_val_buf
AVBufferRef * motion_val_buf[2]
Definition: mpegpicture.h:52
Picture::tf
ThreadFrame tf
Definition: mpegpicture.h:47
src
#define src
Definition: vp8dsp.c:254
Picture::mc_mb_var
uint16_t * mc_mb_var
Table for motion compensated MB variances.
Definition: mpegpicture.h:68
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:236
alloc_frame_buffer
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:100
ff_thread_release_buffer
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
Definition: pthread_frame.c:1006
DELAYED_PIC_REF
#define DELAYED_PIC_REF
Value of Picture.reference when Picture is not a reference picture, but is held for delayed output.
Definition: diracdec.c:67
ff_mpeg_ref_picture
int ff_mpeg_ref_picture(AVCodecContext *avctx, Picture *dst, Picture *src)
Definition: mpegpicture.c:366
Picture::mc_mb_var_sum
int64_t mc_mb_var_sum
motion compensated MB variance for current frame
Definition: mpegpicture.h:82
Picture::qscale_table_buf
AVBufferRef * qscale_table_buf
Definition: mpegpicture.h:49
Picture::alloc_mb_height
int alloc_mb_height
mb_height used to allocate tables
Definition: mpegpicture.h:71
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:373
mpegpicture.h
offset
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
Definition: writing_filters.txt:86
Picture::motion_val
int16_t(*[2] motion_val)[2]
Definition: mpegpicture.h:53
AV_CODEC_ID_MSS2
@ AV_CODEC_ID_MSS2
Definition: codec_id.h:216
av_codec_is_encoder
int av_codec_is_encoder(const AVCodec *codec)
Definition: utils.c:94
avcodec_default_get_buffer2
int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags)
The default callback for AVCodecContext.get_buffer2().
Definition: decode.c:1649
FMT_H263
@ FMT_H263
Definition: mpegutils.h:126
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
MAKE_WRITABLE
#define MAKE_WRITABLE(table)
common.h
uint8_t
uint8_t
Definition: audio_convert.c:194
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:554
ff_update_picture_tables
int ff_update_picture_tables(Picture *dst, Picture *src)
Definition: mpegpicture.c:321
AVCodecContext::height
int height
Definition: avcodec.h:699
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:736
avcodec.h
ret
ret
Definition: filter_design.txt:187
AV_LOG_FATAL
#define AV_LOG_FATAL
Something went wrong and recovery is not possible.
Definition: log.h:170
Picture::qscale_table
int8_t * qscale_table
Definition: mpegpicture.h:50
pic_is_unused
static int pic_is_unused(Picture *pic)
Definition: mpegpicture.c:409
AVCodecContext
main external API structure.
Definition: avcodec.h:526
AVFrame::height
int height
Definition: frame.h:358
Picture::shared
int shared
Definition: mpegpicture.h:88
ScratchpadContext::edge_emu_buffer
uint8_t * edge_emu_buffer
temporary buffer for if MVs point to out-of-frame data
Definition: mpegpicture.h:36
Picture::mb_type
uint32_t * mb_type
types and macros are defined in mpegutils.h
Definition: mpegpicture.h:56
Picture::f
struct AVFrame * f
Definition: mpegpicture.h:46
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AVHWAccel::frame_priv_data_size
int frame_priv_data_size
Size of per-frame hardware accelerator private data.
Definition: avcodec.h:2520
AVCodecContext::export_side_data
int export_side_data
Bit set of AV_CODEC_EXPORT_DATA_* flags, which affects the kind of metadata exported in frame,...
Definition: avcodec.h:2354
Picture::mb_var_sum
int64_t mb_var_sum
sum of MB variance for current frame
Definition: mpegpicture.h:81
av_buffer_ref
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:93
ff_thread_ref_frame
int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src)
Definition: utils.c:1885
find_unused_picture
static int find_unused_picture(AVCodecContext *avctx, Picture *picture, int shared)
Definition: mpegpicture.c:418
AV_CODEC_EXPORT_DATA_MVS
#define AV_CODEC_EXPORT_DATA_MVS
Export motion vectors through frame side data.
Definition: avcodec.h:403
Picture::mc_mb_var_buf
AVBufferRef * mc_mb_var_buf
Definition: mpegpicture.h:67
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:48
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:699
imgutils.h
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:331
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
Picture::mbskip_table_buf
AVBufferRef * mbskip_table_buf
Definition: mpegpicture.h:58
AV_CODEC_ID_WMV3IMAGE
@ AV_CODEC_ID_WMV3IMAGE
Definition: codec_id.h:200
ScratchpadContext::b_scratchpad
uint8_t * b_scratchpad
scratchpad used for writing into write only buffers
Definition: mpegpicture.h:39
Picture::mb_var
uint16_t * mb_var
Table for MB variances.
Definition: mpegpicture.h:65
FF_ALLOCZ_ARRAY_OR_GOTO
#define FF_ALLOCZ_ARRAY_OR_GOTO(ctx, p, nelem, elsize, label)
Definition: internal.h:167
FF_API_DEBUG_MV
#define FF_API_DEBUG_MV
Definition: version.h:58