FFmpeg
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
frame.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include "channel_layout.h"
20 #include "avassert.h"
21 #include "buffer.h"
22 #include "dict.h"
23 #include "frame.h"
24 #include "imgutils.h"
25 #include "mem.h"
26 #include "refstruct.h"
27 #include "samplefmt.h"
28 #include "side_data.h"
29 #include "hwcontext.h"
30 
32 {
33  memset(frame, 0, sizeof(*frame));
34 
35  frame->pts =
36  frame->pkt_dts = AV_NOPTS_VALUE;
37  frame->best_effort_timestamp = AV_NOPTS_VALUE;
38  frame->duration = 0;
39  frame->time_base = (AVRational){ 0, 1 };
40  frame->sample_aspect_ratio = (AVRational){ 0, 1 };
41  frame->format = -1; /* unknown */
42  frame->extended_data = frame->data;
43  frame->color_primaries = AVCOL_PRI_UNSPECIFIED;
44  frame->color_trc = AVCOL_TRC_UNSPECIFIED;
45  frame->colorspace = AVCOL_SPC_UNSPECIFIED;
46  frame->color_range = AVCOL_RANGE_UNSPECIFIED;
47  frame->chroma_location = AVCHROMA_LOC_UNSPECIFIED;
48  frame->flags = 0;
49 }
50 
52 {
53  AVFrame *frame = av_malloc(sizeof(*frame));
54 
55  if (!frame)
56  return NULL;
57 
59 
60  return frame;
61 }
62 
64 {
65  if (!frame || !*frame)
66  return;
67 
69  av_freep(frame);
70 }
71 
72 #define ALIGN (HAVE_SIMD_ALIGN_64 ? 64 : 32)
73 
75 {
77  int ret, padded_height;
78  int plane_padding;
79  ptrdiff_t linesizes[4];
80  size_t total_size, sizes[4];
81 
82  if (!desc)
83  return AVERROR(EINVAL);
84 
85  if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL)) < 0)
86  return ret;
87 
88  if (align <= 0)
89  align = ALIGN;
90  plane_padding = FFMAX(ALIGN, align);
91 
92  if (!frame->linesize[0]) {
93  for (int i = 1; i <= align; i += i) {
94  ret = av_image_fill_linesizes(frame->linesize, frame->format,
95  FFALIGN(frame->width, i));
96  if (ret < 0)
97  return ret;
98  if (!(frame->linesize[0] & (align-1)))
99  break;
100  }
101 
102  for (int i = 0; i < 4 && frame->linesize[i]; i++)
103  frame->linesize[i] = FFALIGN(frame->linesize[i], align);
104  }
105 
106  for (int i = 0; i < 4; i++)
107  linesizes[i] = frame->linesize[i];
108 
109  padded_height = FFALIGN(frame->height, 32);
110  if ((ret = av_image_fill_plane_sizes(sizes, frame->format,
111  padded_height, linesizes)) < 0)
112  return ret;
113 
114  total_size = 4 * plane_padding + 4 * align;
115  for (int i = 0; i < 4; i++) {
116  if (sizes[i] > SIZE_MAX - total_size)
117  return AVERROR(EINVAL);
118  total_size += sizes[i];
119  }
120 
121  frame->buf[0] = av_buffer_alloc(total_size);
122  if (!frame->buf[0]) {
123  ret = AVERROR(ENOMEM);
124  goto fail;
125  }
126 
127  if ((ret = av_image_fill_pointers(frame->data, frame->format, padded_height,
128  frame->buf[0]->data, frame->linesize)) < 0)
129  goto fail;
130 
131  for (int i = 1; i < 4; i++) {
132  if (frame->data[i])
133  frame->data[i] += i * plane_padding;
134  frame->data[i] = (uint8_t *)FFALIGN((uintptr_t)frame->data[i], align);
135  }
136 
137  frame->extended_data = frame->data;
138 
139  return 0;
140 fail:
142  return ret;
143 }
144 
146 {
147  int planar = av_sample_fmt_is_planar(frame->format);
148  int channels, planes;
149  size_t size;
150  int ret;
151 
152  channels = frame->ch_layout.nb_channels;
153  planes = planar ? channels : 1;
154  if (!frame->linesize[0]) {
155  ret = av_samples_get_buffer_size(&frame->linesize[0], channels,
156  frame->nb_samples, frame->format,
157  align);
158  if (ret < 0)
159  return ret;
160  }
161 
162  if (align <= 0)
163  align = ALIGN;
164 
166  frame->extended_data = av_calloc(planes,
167  sizeof(*frame->extended_data));
168  frame->extended_buf = av_calloc(planes - AV_NUM_DATA_POINTERS,
169  sizeof(*frame->extended_buf));
170  if (!frame->extended_data || !frame->extended_buf) {
171  av_freep(&frame->extended_data);
172  av_freep(&frame->extended_buf);
173  return AVERROR(ENOMEM);
174  }
175  frame->nb_extended_buf = planes - AV_NUM_DATA_POINTERS;
176  } else
177  frame->extended_data = frame->data;
178 
179  if (frame->linesize[0] > SIZE_MAX - align)
180  return AVERROR(EINVAL);
181  size = frame->linesize[0] + (size_t)align;
182 
183  for (int i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) {
184  frame->buf[i] = av_buffer_alloc(size);
185  if (!frame->buf[i]) {
187  return AVERROR(ENOMEM);
188  }
189  frame->extended_data[i] = frame->data[i] =
190  (uint8_t *)FFALIGN((uintptr_t)frame->buf[i]->data, align);
191  }
192  for (int i = 0; i < planes - AV_NUM_DATA_POINTERS; i++) {
193  frame->extended_buf[i] = av_buffer_alloc(size);
194  if (!frame->extended_buf[i]) {
196  return AVERROR(ENOMEM);
197  }
198  frame->extended_data[i + AV_NUM_DATA_POINTERS] =
199  (uint8_t *)FFALIGN((uintptr_t)frame->extended_buf[i]->data, align);
200  }
201  return 0;
202 
203 }
204 
206 {
207  if (frame->format < 0)
208  return AVERROR(EINVAL);
209 
210  if (frame->width > 0 && frame->height > 0)
211  return get_video_buffer(frame, align);
212  else if (frame->nb_samples > 0 &&
213  (av_channel_layout_check(&frame->ch_layout)))
214  return get_audio_buffer(frame, align);
215 
216  return AVERROR(EINVAL);
217 }
218 
219 static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
220 {
221  dst->pict_type = src->pict_type;
222  dst->sample_aspect_ratio = src->sample_aspect_ratio;
223  dst->crop_top = src->crop_top;
224  dst->crop_bottom = src->crop_bottom;
225  dst->crop_left = src->crop_left;
226  dst->crop_right = src->crop_right;
227  dst->pts = src->pts;
228  dst->duration = src->duration;
229  dst->repeat_pict = src->repeat_pict;
230  dst->sample_rate = src->sample_rate;
231  dst->opaque = src->opaque;
232  dst->pkt_dts = src->pkt_dts;
233  dst->time_base = src->time_base;
234  dst->quality = src->quality;
235  dst->best_effort_timestamp = src->best_effort_timestamp;
236  dst->flags = src->flags;
237  dst->decode_error_flags = src->decode_error_flags;
238  dst->color_primaries = src->color_primaries;
239  dst->color_trc = src->color_trc;
240  dst->colorspace = src->colorspace;
241  dst->color_range = src->color_range;
242  dst->chroma_location = src->chroma_location;
243 
244  av_dict_copy(&dst->metadata, src->metadata, 0);
245 
246  for (int i = 0; i < src->nb_side_data; i++) {
247  const AVFrameSideData *sd_src = src->side_data[i];
248  AVFrameSideData *sd_dst;
249  if ( sd_src->type == AV_FRAME_DATA_PANSCAN
250  && (src->width != dst->width || src->height != dst->height))
251  continue;
252  if (force_copy) {
253  sd_dst = av_frame_new_side_data(dst, sd_src->type,
254  sd_src->size);
255  if (!sd_dst) {
256  av_frame_side_data_free(&dst->side_data, &dst->nb_side_data);
257  return AVERROR(ENOMEM);
258  }
259  memcpy(sd_dst->data, sd_src->data, sd_src->size);
260  } else {
261  AVBufferRef *ref = av_buffer_ref(sd_src->buf);
262  sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, ref);
263  if (!sd_dst) {
265  av_frame_side_data_free(&dst->side_data, &dst->nb_side_data);
266  return AVERROR(ENOMEM);
267  }
268  }
269  av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
270  }
271 
272  av_refstruct_replace(&dst->private_ref, src->private_ref);
273  return av_buffer_replace(&dst->opaque_ref, src->opaque_ref);
274 }
275 
277 {
278  int ret = 0;
279 
280  av_assert1(dst->width == 0 && dst->height == 0);
281  av_assert1(dst->ch_layout.nb_channels == 0 &&
282  dst->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC);
283 
284  dst->format = src->format;
285  dst->width = src->width;
286  dst->height = src->height;
287  dst->nb_samples = src->nb_samples;
288 
289  ret = frame_copy_props(dst, src, 0);
290  if (ret < 0)
291  goto fail;
292 
293  ret = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout);
294  if (ret < 0)
295  goto fail;
296 
297  /* duplicate the frame data if it's not refcounted */
298  if (!src->buf[0]) {
300  if (ret < 0)
301  goto fail;
302 
303  ret = av_frame_copy(dst, src);
304  if (ret < 0)
305  goto fail;
306 
307  return 0;
308  }
309 
310  /* ref the buffers */
311  for (int i = 0; i < FF_ARRAY_ELEMS(src->buf); i++) {
312  if (!src->buf[i])
313  continue;
314  dst->buf[i] = av_buffer_ref(src->buf[i]);
315  if (!dst->buf[i]) {
316  ret = AVERROR(ENOMEM);
317  goto fail;
318  }
319  }
320 
321  if (src->extended_buf) {
322  dst->extended_buf = av_calloc(src->nb_extended_buf,
323  sizeof(*dst->extended_buf));
324  if (!dst->extended_buf) {
325  ret = AVERROR(ENOMEM);
326  goto fail;
327  }
328  dst->nb_extended_buf = src->nb_extended_buf;
329 
330  for (int i = 0; i < src->nb_extended_buf; i++) {
331  dst->extended_buf[i] = av_buffer_ref(src->extended_buf[i]);
332  if (!dst->extended_buf[i]) {
333  ret = AVERROR(ENOMEM);
334  goto fail;
335  }
336  }
337  }
338 
339  if (src->hw_frames_ctx) {
340  dst->hw_frames_ctx = av_buffer_ref(src->hw_frames_ctx);
341  if (!dst->hw_frames_ctx) {
342  ret = AVERROR(ENOMEM);
343  goto fail;
344  }
345  }
346 
347  /* duplicate extended data */
348  if (src->extended_data != src->data) {
349  int ch = dst->ch_layout.nb_channels;
350 
351  if (ch <= 0 || ch > SIZE_MAX / sizeof(*dst->extended_data)) {
352  ret = AVERROR(EINVAL);
353  goto fail;
354  }
355 
356  dst->extended_data = av_memdup(src->extended_data, sizeof(*dst->extended_data) * ch);
357  if (!dst->extended_data) {
358  ret = AVERROR(ENOMEM);
359  goto fail;
360  }
361  } else
362  dst->extended_data = dst->data;
363 
364  memcpy(dst->data, src->data, sizeof(src->data));
365  memcpy(dst->linesize, src->linesize, sizeof(src->linesize));
366 
367  return 0;
368 
369 fail:
371  return ret;
372 }
373 
375 {
376  int ret = 0;
377 
378  if (dst == src)
379  return AVERROR(EINVAL);
380 
381  if (!src->buf[0]) {
383 
384  /* duplicate the frame data if it's not refcounted */
385  if ( src->data[0] || src->data[1]
386  || src->data[2] || src->data[3])
387  return av_frame_ref(dst, src);
388 
389  ret = frame_copy_props(dst, src, 0);
390  if (ret < 0)
391  goto fail;
392  }
393 
394  dst->format = src->format;
395  dst->width = src->width;
396  dst->height = src->height;
397  dst->nb_samples = src->nb_samples;
398 
399  ret = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout);
400  if (ret < 0)
401  goto fail;
402 
403  av_frame_side_data_free(&dst->side_data, &dst->nb_side_data);
404  av_dict_free(&dst->metadata);
405  ret = frame_copy_props(dst, src, 0);
406  if (ret < 0)
407  goto fail;
408 
409  /* replace the buffers */
410  for (int i = 0; i < FF_ARRAY_ELEMS(src->buf); i++) {
411  ret = av_buffer_replace(&dst->buf[i], src->buf[i]);
412  if (ret < 0)
413  goto fail;
414  }
415 
416  if (src->extended_buf) {
417  if (dst->nb_extended_buf != src->nb_extended_buf) {
418  int nb_extended_buf = FFMIN(dst->nb_extended_buf, src->nb_extended_buf);
419  void *tmp;
420 
421  for (int i = nb_extended_buf; i < dst->nb_extended_buf; i++)
422  av_buffer_unref(&dst->extended_buf[i]);
423 
424  tmp = av_realloc_array(dst->extended_buf, src->nb_extended_buf,
425  sizeof(*dst->extended_buf));
426  if (!tmp) {
427  ret = AVERROR(ENOMEM);
428  goto fail;
429  }
430  dst->extended_buf = tmp;
431  dst->nb_extended_buf = src->nb_extended_buf;
432 
433  memset(&dst->extended_buf[nb_extended_buf], 0,
434  (src->nb_extended_buf - nb_extended_buf) * sizeof(*dst->extended_buf));
435  }
436 
437  for (int i = 0; i < src->nb_extended_buf; i++) {
438  ret = av_buffer_replace(&dst->extended_buf[i], src->extended_buf[i]);
439  if (ret < 0)
440  goto fail;
441  }
442  } else if (dst->extended_buf) {
443  for (int i = 0; i < dst->nb_extended_buf; i++)
444  av_buffer_unref(&dst->extended_buf[i]);
445  av_freep(&dst->extended_buf);
446  }
447 
448  ret = av_buffer_replace(&dst->hw_frames_ctx, src->hw_frames_ctx);
449  if (ret < 0)
450  goto fail;
451 
452  if (dst->extended_data != dst->data)
453  av_freep(&dst->extended_data);
454 
455  if (src->extended_data != src->data) {
456  int ch = dst->ch_layout.nb_channels;
457 
458  if (ch <= 0 || ch > SIZE_MAX / sizeof(*dst->extended_data)) {
459  ret = AVERROR(EINVAL);
460  goto fail;
461  }
462 
463  dst->extended_data = av_memdup(src->extended_data, sizeof(*dst->extended_data) * ch);
464  if (!dst->extended_data) {
465  ret = AVERROR(ENOMEM);
466  goto fail;
467  }
468  } else
469  dst->extended_data = dst->data;
470 
471  memcpy(dst->data, src->data, sizeof(src->data));
472  memcpy(dst->linesize, src->linesize, sizeof(src->linesize));
473 
474  return 0;
475 
476 fail:
478  return ret;
479 }
480 
482 {
484 
485  if (!ret)
486  return NULL;
487 
488  if (av_frame_ref(ret, src) < 0)
489  av_frame_free(&ret);
490 
491  return ret;
492 }
493 
495 {
496  if (!frame)
497  return;
498 
499  av_frame_side_data_free(&frame->side_data, &frame->nb_side_data);
500 
501  for (int i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)
502  av_buffer_unref(&frame->buf[i]);
503  for (int i = 0; i < frame->nb_extended_buf; i++)
504  av_buffer_unref(&frame->extended_buf[i]);
505  av_freep(&frame->extended_buf);
506  av_dict_free(&frame->metadata);
507 
508  av_buffer_unref(&frame->hw_frames_ctx);
509 
510  av_buffer_unref(&frame->opaque_ref);
511  av_refstruct_unref(&frame->private_ref);
512 
513  if (frame->extended_data != frame->data)
514  av_freep(&frame->extended_data);
515 
516  av_channel_layout_uninit(&frame->ch_layout);
517 
519 }
520 
522 {
523  av_assert1(dst->width == 0 && dst->height == 0);
524  av_assert1(dst->ch_layout.nb_channels == 0 &&
525  dst->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC);
526 
527  *dst = *src;
528  if (src->extended_data == src->data)
529  dst->extended_data = dst->data;
531 }
532 
534 {
535  int ret = 1;
536 
537  /* assume non-refcounted frames are not writable */
538  if (!frame->buf[0])
539  return 0;
540 
541  for (int i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)
542  if (frame->buf[i])
543  ret &= !!av_buffer_is_writable(frame->buf[i]);
544  for (int i = 0; i < frame->nb_extended_buf; i++)
545  ret &= !!av_buffer_is_writable(frame->extended_buf[i]);
546 
547  return ret;
548 }
549 
551 {
552  AVFrame tmp;
553  int ret;
554 
556  return 0;
557 
558  memset(&tmp, 0, sizeof(tmp));
559  tmp.format = frame->format;
560  tmp.width = frame->width;
561  tmp.height = frame->height;
562  tmp.nb_samples = frame->nb_samples;
563  ret = av_channel_layout_copy(&tmp.ch_layout, &frame->ch_layout);
564  if (ret < 0) {
566  return ret;
567  }
568 
569  if (frame->hw_frames_ctx)
570  ret = av_hwframe_get_buffer(frame->hw_frames_ctx, &tmp, 0);
571  else
572  ret = av_frame_get_buffer(&tmp, 0);
573  if (ret < 0)
574  return ret;
575 
576  ret = av_frame_copy(&tmp, frame);
577  if (ret < 0) {
579  return ret;
580  }
581 
583  if (ret < 0) {
585  return ret;
586  }
587 
589 
590  *frame = tmp;
591  if (tmp.data == tmp.extended_data)
592  frame->extended_data = frame->data;
593 
594  return 0;
595 }
596 
598 {
599  return frame_copy_props(dst, src, 1);
600 }
601 
603 {
604  uintptr_t data;
605  int planes;
606 
607  if (frame->nb_samples) {
608  int channels = frame->ch_layout.nb_channels;
609  if (!channels)
610  return NULL;
611  planes = av_sample_fmt_is_planar(frame->format) ? channels : 1;
612  } else
613  planes = 4;
614 
615  if (plane < 0 || plane >= planes || !frame->extended_data[plane])
616  return NULL;
617  data = (uintptr_t)frame->extended_data[plane];
618 
619  for (int i = 0; i < FF_ARRAY_ELEMS(frame->buf) && frame->buf[i]; i++) {
620  AVBufferRef *buf = frame->buf[i];
621  uintptr_t buf_begin = (uintptr_t)buf->data;
622 
623  if (data >= buf_begin && data < buf_begin + buf->size)
624  return buf;
625  }
626  for (int i = 0; i < frame->nb_extended_buf; i++) {
627  AVBufferRef *buf = frame->extended_buf[i];
628  uintptr_t buf_begin = (uintptr_t)buf->data;
629 
630  if (data >= buf_begin && data < buf_begin + buf->size)
631  return buf;
632  }
633  return NULL;
634 }
635 
638  AVBufferRef *buf)
639 {
640  return
642  &frame->side_data, &frame->nb_side_data, type, buf);
643 }
644 
647  size_t size)
648 {
652  if (!ret)
653  av_buffer_unref(&buf);
654  return ret;
655 }
656 
659 {
661  frame->side_data, frame->nb_side_data,
662  type
663  );
664 }
665 
666 static int frame_copy_video(AVFrame *dst, const AVFrame *src)
667 {
668  int planes;
669 
670  if (dst->width < src->width ||
671  dst->height < src->height)
672  return AVERROR(EINVAL);
673 
674  if (src->hw_frames_ctx || dst->hw_frames_ctx)
675  return av_hwframe_transfer_data(dst, src, 0);
676 
678  for (int i = 0; i < planes; i++)
679  if (!dst->data[i] || !src->data[i])
680  return AVERROR(EINVAL);
681 
682  av_image_copy2(dst->data, dst->linesize,
683  src->data, src->linesize,
684  dst->format, src->width, src->height);
685 
686  return 0;
687 }
688 
689 static int frame_copy_audio(AVFrame *dst, const AVFrame *src)
690 {
691  int planar = av_sample_fmt_is_planar(dst->format);
692  int channels = dst->ch_layout.nb_channels;
693  int planes = planar ? channels : 1;
694 
695  if (dst->nb_samples != src->nb_samples ||
696  av_channel_layout_compare(&dst->ch_layout, &src->ch_layout))
697  return AVERROR(EINVAL);
698 
699  for (int i = 0; i < planes; i++)
700  if (!dst->extended_data[i] || !src->extended_data[i])
701  return AVERROR(EINVAL);
702 
703  av_samples_copy(dst->extended_data, src->extended_data, 0, 0,
704  dst->nb_samples, channels, dst->format);
705 
706  return 0;
707 }
708 
710 {
711  if (dst->format != src->format || dst->format < 0)
712  return AVERROR(EINVAL);
713 
714  if (dst->width > 0 && dst->height > 0)
715  return frame_copy_video(dst, src);
716  else if (dst->nb_samples > 0 &&
717  (av_channel_layout_check(&dst->ch_layout)))
718  return frame_copy_audio(dst, src);
719 
720  return AVERROR(EINVAL);
721 }
722 
724 {
725  av_frame_side_data_remove(&frame->side_data, &frame->nb_side_data, type);
726 }
727 
728 static int calc_cropping_offsets(size_t offsets[4], const AVFrame *frame,
729  const AVPixFmtDescriptor *desc)
730 {
731  for (int i = 0; frame->data[i]; i++) {
733  int shift_x = (i == 1 || i == 2) ? desc->log2_chroma_w : 0;
734  int shift_y = (i == 1 || i == 2) ? desc->log2_chroma_h : 0;
735 
736  if (desc->flags & AV_PIX_FMT_FLAG_PAL && i == 1) {
737  offsets[i] = 0;
738  break;
739  }
740 
741  /* find any component descriptor for this plane */
742  for (int j = 0; j < desc->nb_components; j++) {
743  if (desc->comp[j].plane == i) {
744  comp = &desc->comp[j];
745  break;
746  }
747  }
748  if (!comp)
749  return AVERROR_BUG;
750 
751  offsets[i] = (frame->crop_top >> shift_y) * frame->linesize[i] +
752  (frame->crop_left >> shift_x) * comp->step;
753  }
754 
755  return 0;
756 }
757 
759 {
760  const AVPixFmtDescriptor *desc;
761  size_t offsets[4];
762  int ret;
763 
764  if (!(frame->width > 0 && frame->height > 0))
765  return AVERROR(EINVAL);
766 
767  if (frame->crop_left >= INT_MAX - frame->crop_right ||
768  frame->crop_top >= INT_MAX - frame->crop_bottom ||
769  (frame->crop_left + frame->crop_right) >= frame->width ||
770  (frame->crop_top + frame->crop_bottom) >= frame->height)
771  return AVERROR(ERANGE);
772 
773  desc = av_pix_fmt_desc_get(frame->format);
774  if (!desc)
775  return AVERROR_BUG;
776 
777  /* Apply just the right/bottom cropping for hwaccel formats. Bitstream
778  * formats cannot be easily handled here either (and corresponding decoders
779  * should not export any cropping anyway), so do the same for those as well.
780  * */
782  frame->width -= frame->crop_right;
783  frame->height -= frame->crop_bottom;
784  frame->crop_right = 0;
785  frame->crop_bottom = 0;
786  return 0;
787  }
788 
789  /* calculate the offsets for each plane */
791  if (ret < 0)
792  return ret;
793 
794  /* adjust the offsets to avoid breaking alignment */
795  if (!(flags & AV_FRAME_CROP_UNALIGNED)) {
796  int log2_crop_align = frame->crop_left ? ff_ctz(frame->crop_left) : INT_MAX;
797  int min_log2_align = INT_MAX;
798 
799  for (int i = 0; frame->data[i]; i++) {
800  int log2_align = offsets[i] ? ff_ctz(offsets[i]) : INT_MAX;
801  min_log2_align = FFMIN(log2_align, min_log2_align);
802  }
803 
804  /* we assume, and it should always be true, that the data alignment is
805  * related to the cropping alignment by a constant power-of-2 factor */
806  if (log2_crop_align < min_log2_align)
807  return AVERROR_BUG;
808 
809  if (min_log2_align < 5 && log2_crop_align != INT_MAX) {
810  frame->crop_left &= ~((1 << (5 + log2_crop_align - min_log2_align)) - 1);
812  if (ret < 0)
813  return ret;
814  }
815  }
816 
817  for (int i = 0; frame->data[i]; i++)
818  frame->data[i] += offsets[i];
819 
820  frame->width -= (frame->crop_left + frame->crop_right);
821  frame->height -= (frame->crop_top + frame->crop_bottom);
822  frame->crop_left = 0;
823  frame->crop_right = 0;
824  frame->crop_top = 0;
825  frame->crop_bottom = 0;
826 
827  return 0;
828 }
flags
const SwsFlags flags[]
Definition: swscale.c:61
av_samples_copy
int av_samples_copy(uint8_t *const *dst, uint8_t *const *src, int dst_offset, int src_offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Copy samples from src to dst.
Definition: samplefmt.c:222
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
get_video_buffer
static int get_video_buffer(AVFrame *frame, int align)
Definition: frame.c:74
av_frame_get_buffer
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:205
ff_ctz
#define ff_ctz
Definition: intmath.h:107
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:657
comp
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
Definition: eamad.c:79
av_frame_new_side_data
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, size_t size)
Add a new side data to a frame.
Definition: frame.c:645
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3341
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:63
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:410
av_frame_make_writable
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
Definition: frame.c:550
AVFrameSideData::buf
AVBufferRef * buf
Definition: frame.h:270
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:647
data
const char data[16]
Definition: mxf.c:149
frame_copy_props
static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
Definition: frame.c:219
get_audio_buffer
static int get_audio_buffer(AVFrame *frame, int align)
Definition: frame.c:145
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
av_buffer_ref
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:103
AV_FRAME_CROP_UNALIGNED
@ AV_FRAME_CROP_UNALIGNED
Apply the maximum possible cropping, even if it requires setting the AVFrame.data[] entries to unalig...
Definition: frame.h:978
frame_copy_video
static int frame_copy_video(AVFrame *dst, const AVFrame *src)
Definition: frame.c:666
av_frame_apply_cropping
int av_frame_apply_cropping(AVFrame *frame, int flags)
Crop the given video AVFrame according to its crop_left/crop_top/crop_right/ crop_bottom fields.
Definition: frame.c:758
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:31
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:304
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3381
ALIGN
#define ALIGN
Definition: frame.c:72
fail
#define fail()
Definition: checkasm.h:196
AV_PIX_FMT_FLAG_HWACCEL
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:128
samplefmt.h
type
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 type
Definition: writing_filters.txt:86
av_image_fill_pointers
int av_image_fill_pointers(uint8_t *data[4], enum AVPixelFormat pix_fmt, int height, uint8_t *ptr, const int linesizes[4])
Fill plane data pointers for an image with pixel format pix_fmt and height height.
Definition: imgutils.c:145
planar
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1<< 16)) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(UINT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(UINT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out->ch+ch,(const uint8_t **) in->ch+ch, off *(out-> planar
Definition: audioconvert.c:56
AVFrameSideDataType
AVFrameSideDataType
Definition: frame.h:49
refstruct.h
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:51
get_frame_defaults
static void get_frame_defaults(AVFrame *frame)
Definition: frame.c:31
avassert.h
AVFrameSideData::size
size_t size
Definition: frame.h:268
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_image_fill_linesizes
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
Definition: imgutils.c:89
offsets
static const int offsets[]
Definition: hevc_pel.c:34
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:217
AV_CHANNEL_ORDER_UNSPEC
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
Definition: channel_layout.h:119
av_sample_fmt_is_planar
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:114
channels
channels
Definition: aptx.h:31
av_frame_clone
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:481
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:622
if
if(ret)
Definition: filter_design.txt:179
frame_copy_audio
static int frame_copy_audio(AVFrame *dst, const AVFrame *src)
Definition: frame.c:689
ff_frame_side_data_add_from_buf
AVFrameSideData * ff_frame_side_data_add_from_buf(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, AVBufferRef *buf)
Definition: side_data.c:171
NULL
#define NULL
Definition: coverity.c:32
sizes
static const int sizes[][2]
Definition: img2dec.c:60
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:597
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:139
AVComponentDescriptor
Definition: pixdesc.h:30
tmp
static uint8_t tmp[20]
Definition: aes_ctr.c:47
av_image_fill_plane_sizes
int av_image_fill_plane_sizes(size_t sizes[4], enum AVPixelFormat pix_fmt, int height, const ptrdiff_t linesizes[4])
Fill plane sizes for an image with pixel format pix_fmt and height height.
Definition: imgutils.c:111
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
av_frame_side_data_remove
void av_frame_side_data_remove(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type)
Remove and free all side data instances of the given type from an array.
Definition: side_data.c:100
av_frame_new_side_data_from_buf
AVFrameSideData * av_frame_new_side_data_from_buf(AVFrame *frame, enum AVFrameSideDataType type, AVBufferRef *buf)
Add a new side data to a frame from an existing AVBufferRef.
Definition: frame.c:636
av_frame_get_plane_buffer
AVBufferRef * av_frame_get_plane_buffer(const AVFrame *frame, int plane)
Get the buffer reference a given data plane is stored in.
Definition: frame.c:602
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:716
AV_FRAME_DATA_PANSCAN
@ AV_FRAME_DATA_PANSCAN
The data is the AVPanScan struct defined in libavcodec.
Definition: frame.h:53
av_frame_ref
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:276
dst
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition: dsp.h:87
av_frame_copy
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:709
for
for(k=2;k<=8;++k)
Definition: h264pred_template.c:424
size
int size
Definition: twinvq_data.h:10344
AV_NUM_DATA_POINTERS
#define AV_NUM_DATA_POINTERS
Definition: frame.h:411
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:247
AV_PIX_FMT_FLAG_BITSTREAM
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
Definition: pixdesc.h:124
AVFrameSideData::data
uint8_t * data
Definition: frame.h:267
av_frame_is_writable
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:533
AVCHROMA_LOC_UNSPECIFIED
@ AVCHROMA_LOC_UNSPECIFIED
Definition: pixfmt.h:770
frame.h
buffer.h
align
static const uint8_t *BS_FUNC() align(BSCTX *bc)
Skip bits to a byte boundary.
Definition: bitstream_template.h:411
av_frame_remove_side_data
void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
Remove and free all side data instances of the given type.
Definition: frame.c:723
av_dict_free
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition: dict.c:233
av_buffer_alloc
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
Definition: buffer.c:77
av_channel_layout_compare
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
Definition: channel_layout.c:809
av_refstruct_unref
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
Definition: refstruct.c:120
planes
static const struct @509 planes[]
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
av_frame_side_data_free
void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd)
Free all side data entries and their contents, then zeroes out the values which the pointers are poin...
Definition: side_data.c:131
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:57
FFMIN
#define FFMIN(a, b)
Definition: macros.h:49
av_frame_move_ref
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:521
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:494
av_buffer_replace
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
Definition: buffer.c:233
av_samples_get_buffer_size
int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Get the required buffer size for the given audio parameters.
Definition: samplefmt.c:121
AVCOL_SPC_UNSPECIFIED
@ AVCOL_SPC_UNSPECIFIED
Definition: pixfmt.h:676
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:264
av_buffer_is_writable
int av_buffer_is_writable(const AVBufferRef *buf)
Definition: buffer.c:147
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
av_channel_layout_check
int av_channel_layout_check(const AVChannelLayout *channel_layout)
Check whether a channel layout is valid, i.e.
Definition: channel_layout.c:783
side_data.h
dict.h
av_hwframe_transfer_data
int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags)
Copy data to or from a hw surface.
Definition: hwcontext.c:444
av_frame_replace
int av_frame_replace(AVFrame *dst, const AVFrame *src)
Ensure the destination frame refers to the same data described by the source frame,...
Definition: frame.c:374
channel_layout.h
av_image_copy2
static void av_image_copy2(uint8_t *const dst_data[4], const int dst_linesizes[4], uint8_t *const src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Wrapper around av_image_copy() to workaround the limitation that the conversion from uint8_t * const ...
Definition: imgutils.h:184
av_refstruct_replace
void av_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
Definition: refstruct.c:160
av_channel_layout_uninit
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
Definition: channel_layout.c:442
AVFrameSideData::type
enum AVFrameSideDataType type
Definition: frame.h:266
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:117
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:449
desc
const char * desc
Definition: libsvtav1.c:79
mem.h
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:265
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
FFALIGN
#define FFALIGN(x, a)
Definition: macros.h:78
calc_cropping_offsets
static int calc_cropping_offsets(size_t offsets[4], const AVFrame *frame, const AVPixFmtDescriptor *desc)
Definition: frame.c:728
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:35
av_dict_copy
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:247
av_frame_side_data_get
static const AVFrameSideData * av_frame_side_data_get(AVFrameSideData *const *sd, const int nb_sd, enum AVFrameSideDataType type)
Wrapper around av_frame_side_data_get_c() to workaround the limitation that for any type T the conver...
Definition: frame.h:1127
imgutils.h
hwcontext.h
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
AVFrameSideData::metadata
AVDictionary * metadata
Definition: frame.h:269
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_PIX_FMT_FLAG_PAL
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
Definition: pixdesc.h:120
av_hwframe_get_buffer
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
Definition: hwcontext.c:502
src
#define src
Definition: vp8dsp.c:248