FFmpeg
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 "common.h"
23 #include "cpu.h"
24 #include "dict.h"
25 #include "frame.h"
26 #include "imgutils.h"
27 #include "mem.h"
28 #include "samplefmt.h"
29 #include "hwcontext.h"
30 
31 #if FF_API_OLD_CHANNEL_LAYOUT
32 #define CHECK_CHANNELS_CONSISTENCY(frame) \
33  av_assert2(!(frame)->channel_layout || \
34  (frame)->channels == \
35  av_get_channel_layout_nb_channels((frame)->channel_layout))
36 #endif
37 
39 {
40  memset(frame, 0, sizeof(*frame));
41 
42  frame->pts =
45  frame->duration = 0;
46 #if FF_API_PKT_DURATION
48  frame->pkt_duration = 0;
50 #endif
51 #if FF_API_FRAME_PKT
53  frame->pkt_pos = -1;
54  frame->pkt_size = -1;
56 #endif
57  frame->time_base = (AVRational){ 0, 1 };
59  frame->format = -1; /* unknown */
66  frame->flags = 0;
67 }
68 
69 static void free_side_data(AVFrameSideData **ptr_sd)
70 {
71  AVFrameSideData *sd = *ptr_sd;
72 
73  av_buffer_unref(&sd->buf);
74  av_dict_free(&sd->metadata);
75  av_freep(ptr_sd);
76 }
77 
79 {
80  for (int i = 0; i < frame->nb_side_data; i++) {
82  }
83  frame->nb_side_data = 0;
84 
86 }
87 
89 {
90  AVFrame *frame = av_malloc(sizeof(*frame));
91 
92  if (!frame)
93  return NULL;
94 
96 
97  return frame;
98 }
99 
101 {
102  if (!frame || !*frame)
103  return;
104 
106  av_freep(frame);
107 }
108 
110 {
112  int ret, padded_height, total_size;
113  int plane_padding = FFMAX(16 + 16/*STRIDE_ALIGN*/, align);
114  ptrdiff_t linesizes[4];
115  size_t sizes[4];
116 
117  if (!desc)
118  return AVERROR(EINVAL);
119 
120  if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL)) < 0)
121  return ret;
122 
123  if (!frame->linesize[0]) {
124  if (align <= 0)
125  align = 32; /* STRIDE_ALIGN. Should be av_cpu_max_align() */
126 
127  for (int i = 1; i <= align; i += i) {
129  FFALIGN(frame->width, i));
130  if (ret < 0)
131  return ret;
132  if (!(frame->linesize[0] & (align-1)))
133  break;
134  }
135 
136  for (int i = 0; i < 4 && frame->linesize[i]; i++)
138  }
139 
140  for (int i = 0; i < 4; i++)
141  linesizes[i] = frame->linesize[i];
142 
143  padded_height = FFALIGN(frame->height, 32);
145  padded_height, linesizes)) < 0)
146  return ret;
147 
148  total_size = 4*plane_padding;
149  for (int i = 0; i < 4; i++) {
150  if (sizes[i] > INT_MAX - total_size)
151  return AVERROR(EINVAL);
152  total_size += sizes[i];
153  }
154 
155  frame->buf[0] = av_buffer_alloc(total_size);
156  if (!frame->buf[0]) {
157  ret = AVERROR(ENOMEM);
158  goto fail;
159  }
160 
161  if ((ret = av_image_fill_pointers(frame->data, frame->format, padded_height,
162  frame->buf[0]->data, frame->linesize)) < 0)
163  goto fail;
164 
165  for (int i = 1; i < 4; i++) {
166  if (frame->data[i])
167  frame->data[i] += i * plane_padding;
168  }
169 
171 
172  return 0;
173 fail:
175  return ret;
176 }
177 
179 {
181  int channels, planes;
182  int ret;
183 
184 #if FF_API_OLD_CHANNEL_LAYOUT
186  if (!frame->ch_layout.nb_channels) {
187  if (frame->channel_layout) {
189  } else {
192  }
193  }
196  frame->ch_layout.u.mask : 0;
198 #endif
200  planes = planar ? channels : 1;
201  if (!frame->linesize[0]) {
204  align);
205  if (ret < 0)
206  return ret;
207  }
208 
211  sizeof(*frame->extended_data));
213  sizeof(*frame->extended_buf));
214  if (!frame->extended_data || !frame->extended_buf) {
217  return AVERROR(ENOMEM);
218  }
220  } else
222 
223  for (int i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) {
225  if (!frame->buf[i]) {
227  return AVERROR(ENOMEM);
228  }
229  frame->extended_data[i] = frame->data[i] = frame->buf[i]->data;
230  }
231  for (int i = 0; i < planes - AV_NUM_DATA_POINTERS; i++) {
233  if (!frame->extended_buf[i]) {
235  return AVERROR(ENOMEM);
236  }
238  }
239  return 0;
240 
241 }
242 
244 {
245  if (frame->format < 0)
246  return AVERROR(EINVAL);
247 
249  if (frame->width > 0 && frame->height > 0)
250  return get_video_buffer(frame, align);
251  else if (frame->nb_samples > 0 &&
254  || frame->channel_layout || frame->channels > 0
255 #endif
256  ))
257  return get_audio_buffer(frame, align);
259 
260  return AVERROR(EINVAL);
261 }
262 
263 static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
264 {
265  int ret;
266 
267 #if FF_API_FRAME_KEY
269  dst->key_frame = src->key_frame;
271 #endif
272  dst->pict_type = src->pict_type;
273  dst->sample_aspect_ratio = src->sample_aspect_ratio;
274  dst->crop_top = src->crop_top;
275  dst->crop_bottom = src->crop_bottom;
276  dst->crop_left = src->crop_left;
277  dst->crop_right = src->crop_right;
278  dst->pts = src->pts;
279  dst->duration = src->duration;
280  dst->repeat_pict = src->repeat_pict;
281 #if FF_API_INTERLACED_FRAME
283  dst->interlaced_frame = src->interlaced_frame;
284  dst->top_field_first = src->top_field_first;
286 #endif
287 #if FF_API_PALETTE_HAS_CHANGED
289  dst->palette_has_changed = src->palette_has_changed;
291 #endif
292  dst->sample_rate = src->sample_rate;
293  dst->opaque = src->opaque;
294  dst->pkt_dts = src->pkt_dts;
295 #if FF_API_FRAME_PKT
297  dst->pkt_pos = src->pkt_pos;
298  dst->pkt_size = src->pkt_size;
300 #endif
301 #if FF_API_PKT_DURATION
303  dst->pkt_duration = src->pkt_duration;
305 #endif
306  dst->time_base = src->time_base;
307 #if FF_API_REORDERED_OPAQUE
309  dst->reordered_opaque = src->reordered_opaque;
311 #endif
312  dst->quality = src->quality;
313  dst->best_effort_timestamp = src->best_effort_timestamp;
314 #if FF_API_FRAME_PICTURE_NUMBER
316  dst->coded_picture_number = src->coded_picture_number;
317  dst->display_picture_number = src->display_picture_number;
319 #endif
320  dst->flags = src->flags;
321  dst->decode_error_flags = src->decode_error_flags;
322  dst->color_primaries = src->color_primaries;
323  dst->color_trc = src->color_trc;
324  dst->colorspace = src->colorspace;
325  dst->color_range = src->color_range;
326  dst->chroma_location = src->chroma_location;
327 
328  av_dict_copy(&dst->metadata, src->metadata, 0);
329 
330  for (int i = 0; i < src->nb_side_data; i++) {
331  const AVFrameSideData *sd_src = src->side_data[i];
332  AVFrameSideData *sd_dst;
333  if ( sd_src->type == AV_FRAME_DATA_PANSCAN
334  && (src->width != dst->width || src->height != dst->height))
335  continue;
336  if (force_copy) {
337  sd_dst = av_frame_new_side_data(dst, sd_src->type,
338  sd_src->size);
339  if (!sd_dst) {
340  wipe_side_data(dst);
341  return AVERROR(ENOMEM);
342  }
343  memcpy(sd_dst->data, sd_src->data, sd_src->size);
344  } else {
345  AVBufferRef *ref = av_buffer_ref(sd_src->buf);
346  sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, ref);
347  if (!sd_dst) {
349  wipe_side_data(dst);
350  return AVERROR(ENOMEM);
351  }
352  }
353  av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
354  }
355 
356  ret = av_buffer_replace(&dst->opaque_ref, src->opaque_ref);
357  ret |= av_buffer_replace(&dst->private_ref, src->private_ref);
358  return ret;
359 }
360 
361 int av_frame_ref(AVFrame *dst, const AVFrame *src)
362 {
363  int ret = 0;
364 
365  av_assert1(dst->width == 0 && dst->height == 0);
366 #if FF_API_OLD_CHANNEL_LAYOUT
368  av_assert1(dst->channels == 0);
370 #endif
371  av_assert1(dst->ch_layout.nb_channels == 0 &&
373 
374  dst->format = src->format;
375  dst->width = src->width;
376  dst->height = src->height;
377  dst->nb_samples = src->nb_samples;
378 #if FF_API_OLD_CHANNEL_LAYOUT
380  dst->channels = src->channels;
381  dst->channel_layout = src->channel_layout;
382  if (!av_channel_layout_check(&src->ch_layout)) {
383  if (src->channel_layout)
384  av_channel_layout_from_mask(&dst->ch_layout, src->channel_layout);
385  else {
386  dst->ch_layout.nb_channels = src->channels;
388  }
389  }
391 #endif
392 
393  ret = frame_copy_props(dst, src, 0);
394  if (ret < 0)
395  goto fail;
396 
397  // this check is needed only until FF_API_OLD_CHANNEL_LAYOUT is out
398  if (av_channel_layout_check(&src->ch_layout)) {
399  ret = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout);
400  if (ret < 0)
401  goto fail;
402  }
403 
404  /* duplicate the frame data if it's not refcounted */
405  if (!src->buf[0]) {
406  ret = av_frame_get_buffer(dst, 0);
407  if (ret < 0)
408  goto fail;
409 
410  ret = av_frame_copy(dst, src);
411  if (ret < 0)
412  goto fail;
413 
414  return 0;
415  }
416 
417  /* ref the buffers */
418  for (int i = 0; i < FF_ARRAY_ELEMS(src->buf); i++) {
419  if (!src->buf[i])
420  continue;
421  dst->buf[i] = av_buffer_ref(src->buf[i]);
422  if (!dst->buf[i]) {
423  ret = AVERROR(ENOMEM);
424  goto fail;
425  }
426  }
427 
428  if (src->extended_buf) {
429  dst->extended_buf = av_calloc(src->nb_extended_buf,
430  sizeof(*dst->extended_buf));
431  if (!dst->extended_buf) {
432  ret = AVERROR(ENOMEM);
433  goto fail;
434  }
435  dst->nb_extended_buf = src->nb_extended_buf;
436 
437  for (int i = 0; i < src->nb_extended_buf; i++) {
438  dst->extended_buf[i] = av_buffer_ref(src->extended_buf[i]);
439  if (!dst->extended_buf[i]) {
440  ret = AVERROR(ENOMEM);
441  goto fail;
442  }
443  }
444  }
445 
446  if (src->hw_frames_ctx) {
447  dst->hw_frames_ctx = av_buffer_ref(src->hw_frames_ctx);
448  if (!dst->hw_frames_ctx) {
449  ret = AVERROR(ENOMEM);
450  goto fail;
451  }
452  }
453 
454  /* duplicate extended data */
455  if (src->extended_data != src->data) {
456  int ch = dst->ch_layout.nb_channels;
457 
458  if (!ch) {
459  ret = AVERROR(EINVAL);
460  goto fail;
461  }
462 
463  dst->extended_data = av_malloc_array(sizeof(*dst->extended_data), ch);
464  if (!dst->extended_data) {
465  ret = AVERROR(ENOMEM);
466  goto fail;
467  }
468  memcpy(dst->extended_data, src->extended_data, sizeof(*src->extended_data) * ch);
469  } else
470  dst->extended_data = dst->data;
471 
472  memcpy(dst->data, src->data, sizeof(src->data));
473  memcpy(dst->linesize, src->linesize, sizeof(src->linesize));
474 
475  return 0;
476 
477 fail:
478  av_frame_unref(dst);
479  return ret;
480 }
481 
483 {
484  int ret = 0;
485 
486  if (dst == src)
487  return AVERROR(EINVAL);
488 
489  if (!src->buf[0]) {
490  av_frame_unref(dst);
491 
492  /* duplicate the frame data if it's not refcounted */
493  if ( src->data[0] || src->data[1]
494  || src->data[2] || src->data[3])
495  return av_frame_ref(dst, src);
496 
497  ret = frame_copy_props(dst, src, 0);
498  if (ret < 0)
499  goto fail;
500  }
501 
502  dst->format = src->format;
503  dst->width = src->width;
504  dst->height = src->height;
505  dst->nb_samples = src->nb_samples;
506 #if FF_API_OLD_CHANNEL_LAYOUT
508  dst->channels = src->channels;
509  dst->channel_layout = src->channel_layout;
510  if (!av_channel_layout_check(&src->ch_layout)) {
512  if (src->channel_layout)
513  av_channel_layout_from_mask(&dst->ch_layout, src->channel_layout);
514  else {
515  dst->ch_layout.nb_channels = src->channels;
517  }
518  } else {
519 #endif
520  ret = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout);
521  if (ret < 0)
522  goto fail;
523 #if FF_API_OLD_CHANNEL_LAYOUT
524  }
526 #endif
527 
528  wipe_side_data(dst);
529  av_dict_free(&dst->metadata);
530  ret = frame_copy_props(dst, src, 0);
531  if (ret < 0)
532  goto fail;
533 
534  /* replace the buffers */
535  for (int i = 0; i < FF_ARRAY_ELEMS(src->buf); i++) {
536  ret = av_buffer_replace(&dst->buf[i], src->buf[i]);
537  if (ret < 0)
538  goto fail;
539  }
540 
541  if (src->extended_buf) {
542  if (dst->nb_extended_buf != src->nb_extended_buf) {
543  int nb_extended_buf = FFMIN(dst->nb_extended_buf, src->nb_extended_buf);
544  void *tmp;
545 
546  for (int i = nb_extended_buf; i < dst->nb_extended_buf; i++)
548 
549  tmp = av_realloc_array(dst->extended_buf, sizeof(*dst->extended_buf),
550  src->nb_extended_buf);
551  if (!tmp) {
552  ret = AVERROR(ENOMEM);
553  goto fail;
554  }
555  dst->extended_buf = tmp;
556  dst->nb_extended_buf = src->nb_extended_buf;
557 
558  memset(&dst->extended_buf[nb_extended_buf], 0,
559  (src->nb_extended_buf - nb_extended_buf) * sizeof(*dst->extended_buf));
560  }
561 
562  for (int i = 0; i < src->nb_extended_buf; i++) {
563  ret = av_buffer_replace(&dst->extended_buf[i], src->extended_buf[i]);
564  if (ret < 0)
565  goto fail;
566  }
567  } else if (dst->extended_buf) {
568  for (int i = 0; i < dst->nb_extended_buf; i++)
570  av_freep(&dst->extended_buf);
571  }
572 
573  ret = av_buffer_replace(&dst->hw_frames_ctx, src->hw_frames_ctx);
574  if (ret < 0)
575  goto fail;
576 
577  if (dst->extended_data != dst->data)
578  av_freep(&dst->extended_data);
579 
580  if (src->extended_data != src->data) {
581  int ch = dst->ch_layout.nb_channels;
582 
583  if (!ch) {
584  ret = AVERROR(EINVAL);
585  goto fail;
586  }
587 
588  if (ch > SIZE_MAX / sizeof(*dst->extended_data))
589  goto fail;
590 
591  dst->extended_data = av_memdup(src->extended_data, sizeof(*dst->extended_data) * ch);
592  if (!dst->extended_data) {
593  ret = AVERROR(ENOMEM);
594  goto fail;
595  }
596  } else
597  dst->extended_data = dst->data;
598 
599  memcpy(dst->data, src->data, sizeof(src->data));
600  memcpy(dst->linesize, src->linesize, sizeof(src->linesize));
601 
602  return 0;
603 
604 fail:
605  av_frame_unref(dst);
606  return ret;
607 }
608 
610 {
612 
613  if (!ret)
614  return NULL;
615 
616  if (av_frame_ref(ret, src) < 0)
617  av_frame_free(&ret);
618 
619  return ret;
620 }
621 
623 {
624  if (!frame)
625  return;
626 
628 
629  for (int i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)
631  for (int i = 0; i < frame->nb_extended_buf; i++)
635 
637 
640 
641  if (frame->extended_data != frame->data)
643 
645 
647 }
648 
650 {
651  av_assert1(dst->width == 0 && dst->height == 0);
652 #if FF_API_OLD_CHANNEL_LAYOUT
654  av_assert1(dst->channels == 0);
656 #endif
657  av_assert1(dst->ch_layout.nb_channels == 0 &&
659 
660  *dst = *src;
661  if (src->extended_data == src->data)
662  dst->extended_data = dst->data;
664 }
665 
667 {
668  int ret = 1;
669 
670  /* assume non-refcounted frames are not writable */
671  if (!frame->buf[0])
672  return 0;
673 
674  for (int i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)
675  if (frame->buf[i])
677  for (int i = 0; i < frame->nb_extended_buf; i++)
679 
680  return ret;
681 }
682 
684 {
685  AVFrame tmp;
686  int ret;
687 
689  return 0;
690 
691  memset(&tmp, 0, sizeof(tmp));
692  tmp.format = frame->format;
693  tmp.width = frame->width;
694  tmp.height = frame->height;
695 #if FF_API_OLD_CHANNEL_LAYOUT
697  tmp.channels = frame->channels;
698  tmp.channel_layout = frame->channel_layout;
700 #endif
701  tmp.nb_samples = frame->nb_samples;
702  ret = av_channel_layout_copy(&tmp.ch_layout, &frame->ch_layout);
703  if (ret < 0) {
705  return ret;
706  }
707 
708  if (frame->hw_frames_ctx)
710  else
711  ret = av_frame_get_buffer(&tmp, 0);
712  if (ret < 0)
713  return ret;
714 
715  ret = av_frame_copy(&tmp, frame);
716  if (ret < 0) {
718  return ret;
719  }
720 
722  if (ret < 0) {
724  return ret;
725  }
726 
728 
729  *frame = tmp;
730  if (tmp.data == tmp.extended_data)
732 
733  return 0;
734 }
735 
737 {
738  return frame_copy_props(dst, src, 1);
739 }
740 
742 {
743  uint8_t *data;
744  int planes;
745 
746  if (frame->nb_samples) {
748 
749 #if FF_API_OLD_CHANNEL_LAYOUT
751  if (!channels) {
754  }
756 #endif
757  if (!channels)
758  return NULL;
760  } else
761  planes = 4;
762 
763  if (plane < 0 || plane >= planes || !frame->extended_data[plane])
764  return NULL;
765  data = frame->extended_data[plane];
766 
767  for (int i = 0; i < FF_ARRAY_ELEMS(frame->buf) && frame->buf[i]; i++) {
768  AVBufferRef *buf = frame->buf[i];
769  if (data >= buf->data && data < buf->data + buf->size)
770  return buf;
771  }
772  for (int i = 0; i < frame->nb_extended_buf; i++) {
773  AVBufferRef *buf = frame->extended_buf[i];
774  if (data >= buf->data && data < buf->data + buf->size)
775  return buf;
776  }
777  return NULL;
778 }
779 
782  AVBufferRef *buf)
783 {
784  AVFrameSideData *ret, **tmp;
785 
786  if (!buf)
787  return NULL;
788 
789  if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
790  return NULL;
791 
793  (frame->nb_side_data + 1) * sizeof(*frame->side_data));
794  if (!tmp)
795  return NULL;
796  frame->side_data = tmp;
797 
798  ret = av_mallocz(sizeof(*ret));
799  if (!ret)
800  return NULL;
801 
802  ret->buf = buf;
803  ret->data = ret->buf->data;
804  ret->size = buf->size;
805  ret->type = type;
806 
808 
809  return ret;
810 }
811 
814  size_t size)
815 {
819  if (!ret)
820  av_buffer_unref(&buf);
821  return ret;
822 }
823 
826 {
827  for (int i = 0; i < frame->nb_side_data; i++) {
828  if (frame->side_data[i]->type == type)
829  return frame->side_data[i];
830  }
831  return NULL;
832 }
833 
834 static int frame_copy_video(AVFrame *dst, const AVFrame *src)
835 {
836  int planes;
837 
838  if (dst->width < src->width ||
839  dst->height < src->height)
840  return AVERROR(EINVAL);
841 
842  if (src->hw_frames_ctx || dst->hw_frames_ctx)
843  return av_hwframe_transfer_data(dst, src, 0);
844 
846  for (int i = 0; i < planes; i++)
847  if (!dst->data[i] || !src->data[i])
848  return AVERROR(EINVAL);
849 
850  av_image_copy2(dst->data, dst->linesize,
851  src->data, src->linesize,
852  dst->format, src->width, src->height);
853 
854  return 0;
855 }
856 
857 static int frame_copy_audio(AVFrame *dst, const AVFrame *src)
858 {
860  int channels = dst->ch_layout.nb_channels;
861  int planes = planar ? channels : 1;
862 
863 #if FF_API_OLD_CHANNEL_LAYOUT
865  if (!channels || !src->ch_layout.nb_channels) {
866  if (dst->channels != src->channels ||
867  dst->channel_layout != src->channel_layout)
868  return AVERROR(EINVAL);
870  }
871  if (!channels) {
872  channels = dst->channels;
873  planes = planar ? channels : 1;
874  }
876 #endif
877 
878  if (dst->nb_samples != src->nb_samples ||
881  av_channel_layout_check(&src->ch_layout) &&
882 #endif
883  av_channel_layout_compare(&dst->ch_layout, &src->ch_layout))
885  )
886 #endif
887  return AVERROR(EINVAL);
888 
889  for (int i = 0; i < planes; i++)
890  if (!dst->extended_data[i] || !src->extended_data[i])
891  return AVERROR(EINVAL);
892 
893  av_samples_copy(dst->extended_data, src->extended_data, 0, 0,
894  dst->nb_samples, channels, dst->format);
895 
896  return 0;
897 }
898 
899 int av_frame_copy(AVFrame *dst, const AVFrame *src)
900 {
901  if (dst->format != src->format || dst->format < 0)
902  return AVERROR(EINVAL);
903 
905  if (dst->width > 0 && dst->height > 0)
906  return frame_copy_video(dst, src);
907  else if (dst->nb_samples > 0 &&
910  || dst->channels > 0
911 #endif
912  ))
913  return frame_copy_audio(dst, src);
915 
916  return AVERROR(EINVAL);
917 }
918 
920 {
921  for (int i = frame->nb_side_data - 1; i >= 0; i--) {
923  if (sd->type == type) {
926  frame->nb_side_data--;
927  }
928  }
929 }
930 
932 {
933  switch(type) {
934  case AV_FRAME_DATA_PANSCAN: return "AVPanScan";
935  case AV_FRAME_DATA_A53_CC: return "ATSC A53 Part 4 Closed Captions";
936  case AV_FRAME_DATA_STEREO3D: return "Stereo 3D";
937  case AV_FRAME_DATA_MATRIXENCODING: return "AVMatrixEncoding";
938  case AV_FRAME_DATA_DOWNMIX_INFO: return "Metadata relevant to a downmix procedure";
939  case AV_FRAME_DATA_REPLAYGAIN: return "AVReplayGain";
940  case AV_FRAME_DATA_DISPLAYMATRIX: return "3x3 displaymatrix";
941  case AV_FRAME_DATA_AFD: return "Active format description";
942  case AV_FRAME_DATA_MOTION_VECTORS: return "Motion vectors";
943  case AV_FRAME_DATA_SKIP_SAMPLES: return "Skip samples";
944  case AV_FRAME_DATA_AUDIO_SERVICE_TYPE: return "Audio service type";
945  case AV_FRAME_DATA_MASTERING_DISPLAY_METADATA: return "Mastering display metadata";
946  case AV_FRAME_DATA_CONTENT_LIGHT_LEVEL: return "Content light level metadata";
947  case AV_FRAME_DATA_GOP_TIMECODE: return "GOP timecode";
948  case AV_FRAME_DATA_S12M_TIMECODE: return "SMPTE 12-1 timecode";
949  case AV_FRAME_DATA_SPHERICAL: return "Spherical Mapping";
950  case AV_FRAME_DATA_ICC_PROFILE: return "ICC profile";
951  case AV_FRAME_DATA_DYNAMIC_HDR_PLUS: return "HDR Dynamic Metadata SMPTE2094-40 (HDR10+)";
952  case AV_FRAME_DATA_DYNAMIC_HDR_VIVID: return "HDR Dynamic Metadata CUVA 005.1 2021 (Vivid)";
953  case AV_FRAME_DATA_REGIONS_OF_INTEREST: return "Regions Of Interest";
954  case AV_FRAME_DATA_VIDEO_ENC_PARAMS: return "Video encoding parameters";
955  case AV_FRAME_DATA_SEI_UNREGISTERED: return "H.26[45] User Data Unregistered SEI message";
956  case AV_FRAME_DATA_FILM_GRAIN_PARAMS: return "Film grain parameters";
957  case AV_FRAME_DATA_DETECTION_BBOXES: return "Bounding boxes for object detection and classification";
958  case AV_FRAME_DATA_DOVI_RPU_BUFFER: return "Dolby Vision RPU Data";
959  case AV_FRAME_DATA_DOVI_METADATA: return "Dolby Vision Metadata";
960  case AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT: return "Ambient viewing environment";
961  }
962  return NULL;
963 }
964 
965 static int calc_cropping_offsets(size_t offsets[4], const AVFrame *frame,
966  const AVPixFmtDescriptor *desc)
967 {
968  for (int i = 0; frame->data[i]; i++) {
970  int shift_x = (i == 1 || i == 2) ? desc->log2_chroma_w : 0;
971  int shift_y = (i == 1 || i == 2) ? desc->log2_chroma_h : 0;
972 
973  if (desc->flags & AV_PIX_FMT_FLAG_PAL && i == 1) {
974  offsets[i] = 0;
975  break;
976  }
977 
978  /* find any component descriptor for this plane */
979  for (int j = 0; j < desc->nb_components; j++) {
980  if (desc->comp[j].plane == i) {
981  comp = &desc->comp[j];
982  break;
983  }
984  }
985  if (!comp)
986  return AVERROR_BUG;
987 
988  offsets[i] = (frame->crop_top >> shift_y) * frame->linesize[i] +
989  (frame->crop_left >> shift_x) * comp->step;
990  }
991 
992  return 0;
993 }
994 
996 {
997  const AVPixFmtDescriptor *desc;
998  size_t offsets[4];
999 
1000  if (!(frame->width > 0 && frame->height > 0))
1001  return AVERROR(EINVAL);
1002 
1003  if (frame->crop_left >= INT_MAX - frame->crop_right ||
1004  frame->crop_top >= INT_MAX - frame->crop_bottom ||
1005  (frame->crop_left + frame->crop_right) >= frame->width ||
1007  return AVERROR(ERANGE);
1008 
1010  if (!desc)
1011  return AVERROR_BUG;
1012 
1013  /* Apply just the right/bottom cropping for hwaccel formats. Bitstream
1014  * formats cannot be easily handled here either (and corresponding decoders
1015  * should not export any cropping anyway), so do the same for those as well.
1016  * */
1018  frame->width -= frame->crop_right;
1020  frame->crop_right = 0;
1021  frame->crop_bottom = 0;
1022  return 0;
1023  }
1024 
1025  /* calculate the offsets for each plane */
1027 
1028  /* adjust the offsets to avoid breaking alignment */
1029  if (!(flags & AV_FRAME_CROP_UNALIGNED)) {
1030  int log2_crop_align = frame->crop_left ? ff_ctz(frame->crop_left) : INT_MAX;
1031  int min_log2_align = INT_MAX;
1032 
1033  for (int i = 0; frame->data[i]; i++) {
1034  int log2_align = offsets[i] ? ff_ctz(offsets[i]) : INT_MAX;
1035  min_log2_align = FFMIN(log2_align, min_log2_align);
1036  }
1037 
1038  /* we assume, and it should always be true, that the data alignment is
1039  * related to the cropping alignment by a constant power-of-2 factor */
1040  if (log2_crop_align < min_log2_align)
1041  return AVERROR_BUG;
1042 
1043  if (min_log2_align < 5) {
1044  frame->crop_left &= ~((1 << (5 + log2_crop_align - min_log2_align)) - 1);
1046  }
1047  }
1048 
1049  for (int i = 0; frame->data[i]; i++)
1050  frame->data[i] += offsets[i];
1051 
1054  frame->crop_left = 0;
1055  frame->crop_right = 0;
1056  frame->crop_top = 0;
1057  frame->crop_bottom = 0;
1058 
1059  return 0;
1060 }
AVFrame::extended_buf
AVBufferRef ** extended_buf
For planar audio which requires more than AV_NUM_DATA_POINTERS AVBufferRef pointers,...
Definition: frame.h:604
AVFrame::color_trc
enum AVColorTransferCharacteristic color_trc
Definition: frame.h:660
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
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
free_side_data
static void free_side_data(AVFrameSideData **ptr_sd)
Definition: frame.c:69
AVFrame::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: frame.h:656
AVFrame::palette_has_changed
attribute_deprecated int palette_has_changed
Tell user application that palette has changed from previous frame.
Definition: frame.h:546
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:109
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:243
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:824
comp
static void comp(unsigned char *dst, ptrdiff_t dst_stride, unsigned char *src, ptrdiff_t src_stride, int add)
Definition: eamad.c:80
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:812
AVFrame::duration
int64_t duration
Duration of the frame, in the same units as pts.
Definition: frame.h:807
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2964
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
AV_FRAME_DATA_A53_CC
@ AV_FRAME_DATA_A53_CC
ATSC A53 Part 4 Closed Captions.
Definition: frame.h:59
AVFrame::nb_side_data
int nb_side_data
Definition: frame.h:611
AV_FRAME_DATA_DOVI_METADATA
@ AV_FRAME_DATA_DOVI_METADATA
Parsed Dolby Vision metadata, suitable for passing to a software implementation.
Definition: frame.h:204
AV_FRAME_DATA_FILM_GRAIN_PARAMS
@ AV_FRAME_DATA_FILM_GRAIN_PARAMS
Film grain parameters for a frame, described by AVFilmGrainParams.
Definition: frame.h:184
AVFrame::color_primaries
enum AVColorPrimaries color_primaries
Definition: frame.h:658
AV_FRAME_DATA_S12M_TIMECODE
@ AV_FRAME_DATA_S12M_TIMECODE
Timecode which conforms to SMPTE ST 12-1.
Definition: frame.h:152
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:100
AVFrame::opaque
void * opaque
Frame owner's private data.
Definition: frame.h:501
AVFrame::colorspace
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:667
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
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:683
AVFrameSideData::buf
AVBufferRef * buf
Definition: frame.h:251
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:452
AVFrame::width
int width
Definition: frame.h:412
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:573
data
const char data[16]
Definition: mxf.c:148
AV_FRAME_DATA_DOVI_RPU_BUFFER
@ AV_FRAME_DATA_DOVI_RPU_BUFFER
Dolby Vision RPU raw data, suitable for passing to x265 or other libraries.
Definition: frame.h:197
frame_copy_props
static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
Definition: frame.c:263
AV_FRAME_DATA_DISPLAYMATRIX
@ AV_FRAME_DATA_DISPLAYMATRIX
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: frame.h:85
get_audio_buffer
static int get_audio_buffer(AVFrame *frame, int align)
Definition: frame.c:178
AVFrame::flags
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:649
AVChannelLayout::order
enum AVChannelOrder order
Channel order used in this layout.
Definition: channel_layout.h:312
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
AVChannelLayout::mask
uint64_t mask
This member must be used for AV_CHANNEL_ORDER_NATIVE, and may be used for AV_CHANNEL_ORDER_AMBISONIC ...
Definition: channel_layout.h:339
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:317
AVFrame::buf
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:590
frame_copy_video
static int frame_copy_video(AVFrame *dst, const AVFrame *src)
Definition: frame.c:834
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:995
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:361
av_malloc
#define av_malloc(s)
Definition: tableprint_vlc.h:30
av_memdup
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition: mem.c:302
AVFrame::opaque_ref
AVBufferRef * opaque_ref
Frame owner's private data.
Definition: frame.h:768
AVFrame::chroma_location
enum AVChromaLocation chroma_location
Definition: frame.h:669
av_pix_fmt_count_planes
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:3004
AV_FRAME_DATA_MATRIXENCODING
@ AV_FRAME_DATA_MATRIXENCODING
The data is the AVMatrixEncoding enum defined in libavutil/channel_layout.h.
Definition: frame.h:68
fail
#define fail()
Definition: checkasm.h:138
AV_PIX_FMT_FLAG_HWACCEL
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition: pixdesc.h:128
samplefmt.h
wipe_side_data
static void wipe_side_data(AVFrame *frame)
Definition: frame.c:78
AVFrame::ch_layout
AVChannelLayout ch_layout
Channel layout of the audio data.
Definition: frame.h:802
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
AVChannelLayout::u
union AVChannelLayout::@332 u
Details about which channels are present in this layout.
AVFrame::channels
attribute_deprecated int channels
number of audio channels, only used for audio.
Definition: frame.h:731
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
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:88
get_frame_defaults
static void get_frame_defaults(AVFrame *frame)
Definition: frame.c:38
AVFrame::interlaced_frame
attribute_deprecated int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:530
avassert.h
AVFrameSideData::size
size_t size
Definition: frame.h:249
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
AVFrame::channel_layout
attribute_deprecated uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:575
AVFrame::reordered_opaque
attribute_deprecated int64_t reordered_opaque
reordered opaque 64 bits (generally an integer or a double precision float PTS but can be anything).
Definition: frame.h:561
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:215
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:112
av_channel_layout_from_mask
FF_ENABLE_DEPRECATION_WARNINGS int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask)
Initialize a native channel layout from a bitmask indicating which channels are present.
Definition: channel_layout.c:399
AV_FRAME_DATA_AUDIO_SERVICE_TYPE
@ AV_FRAME_DATA_AUDIO_SERVICE_TYPE
This side data must be associated with an audio frame and corresponds to enum AVAudioServiceType defi...
Definition: frame.h:114
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:609
AVFrame::pkt_size
attribute_deprecated int pkt_size
size of the corresponding packet containing the compressed frame.
Definition: frame.h:745
AVFrame::crop_right
size_t crop_right
Definition: frame.h:781
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:548
AVFrame::key_frame
attribute_deprecated int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:436
AV_FRAME_DATA_DYNAMIC_HDR_VIVID
@ AV_FRAME_DATA_DYNAMIC_HDR_VIVID
HDR Vivid dynamic metadata associated with a video frame.
Definition: frame.h:211
frame
static AVFrame * frame
Definition: demux_decode.c:54
frame_copy_audio
static int frame_copy_audio(AVFrame *dst, const AVFrame *src)
Definition: frame.c:857
AV_FRAME_DATA_SPHERICAL
@ AV_FRAME_DATA_SPHERICAL
The data represents the AVSphericalMapping structure defined in libavutil/spherical....
Definition: frame.h:131
NULL
#define NULL
Definition: coverity.c:32
sizes
static const int sizes[][2]
Definition: img2dec.c:58
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:736
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
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
AVFrame::coded_picture_number
attribute_deprecated int coded_picture_number
picture number in bitstream order
Definition: frame.h:474
AV_FRAME_DATA_ICC_PROFILE
@ AV_FRAME_DATA_ICC_PROFILE
The data contains an ICC profile as an opaque octet buffer following the format described by ISO 1507...
Definition: frame.h:144
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
@ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata associated with a video frame.
Definition: frame.h:120
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:780
AVFrame::pkt_dts
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
Definition: frame.h:459
AV_FRAME_DATA_AFD
@ AV_FRAME_DATA_AFD
Active Format Description data consisting of a single byte as specified in ETSI TS 101 154 using AVAc...
Definition: frame.h:90
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:741
AVCOL_RANGE_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
Definition: pixfmt.h:639
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:1026
AV_FRAME_DATA_SEI_UNREGISTERED
@ AV_FRAME_DATA_SEI_UNREGISTERED
User data unregistered metadata associated with a video frame.
Definition: frame.h:178
AVFrame::crop_bottom
size_t crop_bottom
Definition: frame.h:779
AVFrame::best_effort_timestamp
int64_t best_effort_timestamp
frame timestamp estimated using various heuristics, in stream time base
Definition: frame.h:676
AVFrame::crop_left
size_t crop_left
Definition: frame.h:780
AVFrame::pict_type
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:442
AV_FRAME_DATA_REPLAYGAIN
@ AV_FRAME_DATA_REPLAYGAIN
ReplayGain information in the form of the AVReplayGain struct.
Definition: frame.h:77
AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT
@ AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT
Ambient viewing environment metadata, as defined by H.274.
Definition: frame.h:216
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:361
av_frame_copy
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:899
cpu.h
AVFrame::quality
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
Definition: frame.h:485
AVFrame::display_picture_number
attribute_deprecated int display_picture_number
picture number in display order
Definition: frame.h:479
AVFrame::sample_rate
int sample_rate
Sample rate of the audio data.
Definition: frame.h:567
FF_API_OLD_CHANNEL_LAYOUT
#define FF_API_OLD_CHANNEL_LAYOUT
Definition: version.h:111
size
int size
Definition: twinvq_data.h:10344
AV_NUM_DATA_POINTERS
#define AV_NUM_DATA_POINTERS
Definition: frame.h:341
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AVFrame::time_base
AVRational time_base
Time base for the timestamps in this frame.
Definition: frame.h:467
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:248
av_frame_is_writable
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:666
AVCHROMA_LOC_UNSPECIFIED
@ AVCHROMA_LOC_UNSPECIFIED
Definition: pixfmt.h:693
AVFrame::pkt_pos
attribute_deprecated int64_t pkt_pos
reordered pos from the last AVPacket that has been input into the decoder
Definition: frame.h:687
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:427
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:919
AV_CHANNEL_ORDER_NATIVE
@ AV_CHANNEL_ORDER_NATIVE
The native channel order, i.e.
Definition: channel_layout.h:118
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:225
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:942
AVBufferRef::size
size_t size
Size of data in bytes.
Definition: buffer.h:94
AVFrame::private_ref
AVBufferRef * private_ref
AVBufferRef for internal use by a single libav* library.
Definition: frame.h:797
AV_FRAME_DATA_SKIP_SAMPLES
@ AV_FRAME_DATA_SKIP_SAMPLES
Recommmends skipping the specified number of samples.
Definition: frame.h:109
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:420
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition: frame.h:137
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
AVFrame::top_field_first
attribute_deprecated int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:538
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:401
av_malloc_array
#define av_malloc_array(a, b)
Definition: tableprint_vlc.h:31
common.h
av_assert1
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition: avassert.h:56
planes
static const struct @363 planes[]
AV_FRAME_DATA_STEREO3D
@ AV_FRAME_DATA_STEREO3D
Stereoscopic 3d metadata.
Definition: frame.h:64
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:649
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:622
AVFrame::pkt_duration
attribute_deprecated int64_t pkt_duration
duration of the corresponding packet, expressed in AVStream->time_base units, 0 if unknown.
Definition: frame.h:700
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:254
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
AVFrame::side_data
AVFrameSideData ** side_data
Definition: frame.h:610
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:602
av_calloc
void * av_calloc(size_t nmemb, size_t size)
Definition: mem.c:262
av_buffer_is_writable
int av_buffer_is_writable(const AVBufferRef *buf)
Definition: buffer.c:147
AVFrame::decode_error_flags
int decode_error_flags
decode error flags of the frame, set to a combination of FF_DECODE_ERROR_xxx flags if the decoder pro...
Definition: frame.h:717
ret
ret
Definition: filter_design.txt:187
AV_FRAME_DATA_GOP_TIMECODE
@ AV_FRAME_DATA_GOP_TIMECODE
The GOP timecode in 25 bit timecode format.
Definition: frame.h:125
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:916
dict.h
AVFrame::sample_aspect_ratio
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:447
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:448
AVFrame::hw_frames_ctx
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame.
Definition: frame.h:752
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:482
AV_FRAME_DATA_DYNAMIC_HDR_PLUS
@ AV_FRAME_DATA_DYNAMIC_HDR_PLUS
HDR dynamic metadata associated with a video frame.
Definition: frame.h:159
AVFrame::height
int height
Definition: frame.h:412
channel_layout.h
AV_FRAME_DATA_VIDEO_ENC_PARAMS
@ AV_FRAME_DATA_VIDEO_ENC_PARAMS
Encoding parameters for a video frame, as described by AVVideoEncParams.
Definition: frame.h:170
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
AVFrame::metadata
AVDictionary * metadata
metadata.
Definition: frame.h:708
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:640
AVFrameSideData::type
enum AVFrameSideDataType type
Definition: frame.h:247
ref
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:112
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:647
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
desc
const char * desc
Definition: libsvtav1.c:83
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:246
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:965
AVFrame::crop_top
size_t crop_top
Definition: frame.h:778
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
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:239
av_frame_side_data_name
const char * av_frame_side_data_name(enum AVFrameSideDataType type)
Definition: frame.c:931
AV_FRAME_DATA_REGIONS_OF_INTEREST
@ AV_FRAME_DATA_REGIONS_OF_INTEREST
Regions Of Interest, the data is an array of AVRegionOfInterest type, the number of array element is ...
Definition: frame.h:165
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
hwcontext.h
AVERROR_BUG
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:52
AVFrame::linesize
int linesize[AV_NUM_DATA_POINTERS]
For video, a positive or negative value, which is typically indicating the size in bytes of each pict...
Definition: frame.h:385
AVFrameSideData::metadata
AVDictionary * metadata
Definition: frame.h:250
AV_FRAME_DATA_MOTION_VECTORS
@ AV_FRAME_DATA_MOTION_VECTORS
Motion vectors exported by some codecs (on demand through the export_mvs flag set in the libavcodec A...
Definition: frame.h:97
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
CHECK_CHANNELS_CONSISTENCY
#define CHECK_CHANNELS_CONSISTENCY(frame)
Definition: frame.c:32
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:507
AV_FRAME_DATA_DOWNMIX_INFO
@ AV_FRAME_DATA_DOWNMIX_INFO
Metadata relevant to a downmix procedure.
Definition: frame.h:73
AVFrame::repeat_pict
int repeat_pict
Number of fields in this frame which should be repeated, i.e.
Definition: frame.h:521
AV_FRAME_DATA_DETECTION_BBOXES
@ AV_FRAME_DATA_DETECTION_BBOXES
Bounding boxes for object detection and classification, as described by AVDetectionBBoxHeader.
Definition: frame.h:190
AVFrame::nb_extended_buf
int nb_extended_buf
Number of elements in extended_buf.
Definition: frame.h:608
av_realloc
void * av_realloc(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory.
Definition: mem.c:153