FFmpeg
Loading...
Searching...
No Matches
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 "frame_internal.h"
25#include "imgutils.h"
26#include "mem.h"
27#include "refstruct.h"
28#include "samplefmt.h"
29#include "side_data.h"
30#include "hwcontext.h"
31
33{
34 memset(frame, 0, sizeof(*frame));
35
36 frame->pts =
37 frame->pkt_dts = AV_NOPTS_VALUE;
38 frame->best_effort_timestamp = AV_NOPTS_VALUE;
39 frame->duration = 0;
40 frame->time_base = (AVRational){ 0, 1 };
41 frame->sample_aspect_ratio = (AVRational){ 0, 1 };
42 frame->format = -1; /* unknown */
43 frame->extended_data = frame->data;
44 frame->color_primaries = AVCOL_PRI_UNSPECIFIED;
45 frame->color_trc = AVCOL_TRC_UNSPECIFIED;
46 frame->colorspace = AVCOL_SPC_UNSPECIFIED;
47 frame->color_range = AVCOL_RANGE_UNSPECIFIED;
48 frame->chroma_location = AVCHROMA_LOC_UNSPECIFIED;
49 frame->alpha_mode = AVALPHA_MODE_UNSPECIFIED;
50 frame->flags = 0;
51}
52
54{
55 AVFrame *frame = av_malloc(sizeof(*frame));
56
57 if (!frame)
58 return NULL;
59
61
62 return frame;
63}
64
66{
67 if (!frame || !*frame)
68 return;
69
72}
73
74#define ALIGN (HAVE_SIMD_ALIGN_64 ? 64 : 32)
75
77 AVBufferRef *(*alloc)(void *opaque, size_t size),
78 void *opaque)
79{
81 int ret, padded_height;
82 int plane_padding;
83 ptrdiff_t linesizes[4];
84 size_t total_size, sizes[4];
85
86 if (!desc)
87 return AVERROR(EINVAL);
88
89 if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL)) < 0)
90 return ret;
91
92 if (align <= 0)
93 align = ALIGN;
94 plane_padding = FFMAX(ALIGN, align);
95
96 if (!frame->linesize[0]) {
97 for (int i = 1; i <= align; i += i) {
98 ret = av_image_fill_linesizes(frame->linesize, frame->format,
99 FFALIGN(frame->width, i));
100 if (ret < 0)
101 return ret;
102 if (!(frame->linesize[0] & (align-1)))
103 break;
104 }
105
106 for (int i = 0; i < 4 && frame->linesize[i]; i++)
107 frame->linesize[i] = FFALIGN(frame->linesize[i], align);
108 }
109
110 for (int i = 0; i < 4; i++)
111 linesizes[i] = frame->linesize[i];
112
113 padded_height = FFALIGN(frame->height, 32);
115 padded_height, linesizes)) < 0)
116 return ret;
117
118 total_size = 4 * plane_padding + 4 * align;
119 for (int i = 0; i < 4; i++) {
120 if (sizes[i] > SIZE_MAX - total_size)
121 return AVERROR(EINVAL);
122 total_size += sizes[i];
123 }
124
125 frame->buf[0] = alloc ? alloc(opaque, total_size) : av_buffer_alloc(total_size);
126 if (!frame->buf[0]) {
127 ret = AVERROR(ENOMEM);
128 goto fail;
129 }
130
131 if ((ret = av_image_fill_pointers(frame->data, frame->format, padded_height,
132 frame->buf[0]->data, frame->linesize)) < 0)
133 goto fail;
134
135 for (int i = 1; i < 4; i++) {
136 if (frame->data[i])
137 frame->data[i] += i * plane_padding;
138 frame->data[i] = (uint8_t *)FFALIGN((uintptr_t)frame->data[i], align);
139 }
140
141 frame->extended_data = frame->data;
142
143 return 0;
144fail:
146 return ret;
147}
148
150{
151 int planar = av_sample_fmt_is_planar(frame->format);
152 int channels, planes;
153 size_t size;
154 int ret;
155
156 channels = frame->ch_layout.nb_channels;
157 planes = planar ? channels : 1;
158 if (!frame->linesize[0]) {
160 frame->nb_samples, frame->format,
161 align);
162 if (ret < 0)
163 return ret;
164 }
165
166 if (align <= 0)
167 align = ALIGN;
168
170 frame->extended_data = av_calloc(planes,
171 sizeof(*frame->extended_data));
172 frame->extended_buf = av_calloc(planes - AV_NUM_DATA_POINTERS,
173 sizeof(*frame->extended_buf));
174 if (!frame->extended_data || !frame->extended_buf) {
175 av_freep(&frame->extended_data);
176 av_freep(&frame->extended_buf);
177 return AVERROR(ENOMEM);
178 }
179 frame->nb_extended_buf = planes - AV_NUM_DATA_POINTERS;
180 } else
181 frame->extended_data = frame->data;
182
183 if (frame->linesize[0] > SIZE_MAX - align)
184 return AVERROR(EINVAL);
185 size = frame->linesize[0] + (size_t)align;
186
187 for (int i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) {
188 frame->buf[i] = av_buffer_alloc(size);
189 if (!frame->buf[i]) {
191 return AVERROR(ENOMEM);
192 }
193 frame->extended_data[i] = frame->data[i] =
194 (uint8_t *)FFALIGN((uintptr_t)frame->buf[i]->data, align);
195 }
196 for (int i = 0; i < planes - AV_NUM_DATA_POINTERS; i++) {
197 frame->extended_buf[i] = av_buffer_alloc(size);
198 if (!frame->extended_buf[i]) {
200 return AVERROR(ENOMEM);
201 }
202 frame->extended_data[i + AV_NUM_DATA_POINTERS] =
203 (uint8_t *)FFALIGN((uintptr_t)frame->extended_buf[i]->data, align);
204 }
205 return 0;
206
207}
208
210{
211 if (frame->format < 0)
212 return AVERROR(EINVAL);
213
214 if (frame->width > 0 && frame->height > 0)
216 else if (frame->nb_samples > 0 &&
217 (av_channel_layout_check(&frame->ch_layout)))
219
220 return AVERROR(EINVAL);
221}
222
223static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
224{
225 dst->pict_type = src->pict_type;
226 dst->sample_aspect_ratio = src->sample_aspect_ratio;
227 dst->crop_top = src->crop_top;
228 dst->crop_bottom = src->crop_bottom;
229 dst->crop_left = src->crop_left;
230 dst->crop_right = src->crop_right;
231 dst->pts = src->pts;
232 dst->duration = src->duration;
233 dst->repeat_pict = src->repeat_pict;
234 dst->sample_rate = src->sample_rate;
235 dst->opaque = src->opaque;
236 dst->pkt_dts = src->pkt_dts;
237 dst->time_base = src->time_base;
238 dst->quality = src->quality;
239 dst->best_effort_timestamp = src->best_effort_timestamp;
240 dst->flags = src->flags;
241 dst->decode_error_flags = src->decode_error_flags;
242 dst->color_primaries = src->color_primaries;
243 dst->color_trc = src->color_trc;
244 dst->colorspace = src->colorspace;
245 dst->color_range = src->color_range;
246 dst->chroma_location = src->chroma_location;
247 dst->alpha_mode = src->alpha_mode;
248
249 av_dict_copy(&dst->metadata, src->metadata, 0);
250
251 for (int i = 0; i < src->nb_side_data; i++) {
252 const AVFrameSideData *sd_src = src->side_data[i];
253 AVFrameSideData *sd_dst;
254 if ( sd_src->type == AV_FRAME_DATA_PANSCAN
255 && (src->width != dst->width || src->height != dst->height))
256 continue;
257 if (force_copy) {
258 sd_dst = av_frame_new_side_data(dst, sd_src->type,
259 sd_src->size);
260 if (!sd_dst) {
261 av_frame_side_data_free(&dst->side_data, &dst->nb_side_data);
262 return AVERROR(ENOMEM);
263 }
264 memcpy(sd_dst->data, sd_src->data, sd_src->size);
265 } else {
266 AVBufferRef *ref = av_buffer_ref(sd_src->buf);
267 sd_dst = av_frame_new_side_data_from_buf(dst, sd_src->type, ref);
268 if (!sd_dst) {
270 av_frame_side_data_free(&dst->side_data, &dst->nb_side_data);
271 return AVERROR(ENOMEM);
272 }
273 }
274 av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
275 }
276
277 av_refstruct_replace(&dst->private_ref, src->private_ref);
278 return av_buffer_replace(&dst->opaque_ref, src->opaque_ref);
279}
280
282{
283 int ret = 0;
284
285 av_assert1(dst->width == 0 && dst->height == 0);
286 av_assert1(dst->ch_layout.nb_channels == 0 &&
287 dst->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC);
288
289 dst->format = src->format;
290 dst->width = src->width;
291 dst->height = src->height;
292 dst->nb_samples = src->nb_samples;
293
295 if (ret < 0)
296 goto fail;
297
298 ret = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout);
299 if (ret < 0)
300 goto fail;
301
302 /* duplicate the frame data if it's not refcounted */
303 if (!src->buf[0]) {
305 if (ret < 0)
306 goto fail;
307
309 if (ret < 0)
310 goto fail;
311
312 return 0;
313 }
314
315 /* ref the buffers */
316 for (int i = 0; i < FF_ARRAY_ELEMS(src->buf); i++) {
317 if (!src->buf[i])
318 continue;
319 dst->buf[i] = av_buffer_ref(src->buf[i]);
320 if (!dst->buf[i]) {
321 ret = AVERROR(ENOMEM);
322 goto fail;
323 }
324 }
325
326 if (src->extended_buf) {
327 dst->extended_buf = av_calloc(src->nb_extended_buf,
328 sizeof(*dst->extended_buf));
329 if (!dst->extended_buf) {
330 ret = AVERROR(ENOMEM);
331 goto fail;
332 }
333 dst->nb_extended_buf = src->nb_extended_buf;
334
335 for (int i = 0; i < src->nb_extended_buf; i++) {
336 dst->extended_buf[i] = av_buffer_ref(src->extended_buf[i]);
337 if (!dst->extended_buf[i]) {
338 ret = AVERROR(ENOMEM);
339 goto fail;
340 }
341 }
342 }
343
344 if (src->hw_frames_ctx) {
345 dst->hw_frames_ctx = av_buffer_ref(src->hw_frames_ctx);
346 if (!dst->hw_frames_ctx) {
347 ret = AVERROR(ENOMEM);
348 goto fail;
349 }
350 }
351
352 /* duplicate extended data */
353 if (src->extended_data != src->data) {
354 int ch = dst->ch_layout.nb_channels;
355
356 if (ch <= 0 || ch > SIZE_MAX / sizeof(*dst->extended_data)) {
357 ret = AVERROR(EINVAL);
358 goto fail;
359 }
360
361 dst->extended_data = av_memdup(src->extended_data, sizeof(*dst->extended_data) * ch);
362 if (!dst->extended_data) {
363 ret = AVERROR(ENOMEM);
364 goto fail;
365 }
366 } else
367 dst->extended_data = dst->data;
368
369 memcpy(dst->data, src->data, sizeof(src->data));
370 memcpy(dst->linesize, src->linesize, sizeof(src->linesize));
371
372 return 0;
373
374fail:
376 return ret;
377}
378
380{
381 int ret = 0;
382
383 if (dst == src)
384 return AVERROR(EINVAL);
385
386 if (!src->buf[0]) {
388
389 /* duplicate the frame data if it's not refcounted */
390 if ( src->data[0] || src->data[1]
391 || src->data[2] || src->data[3])
392 return av_frame_ref(dst, src);
393
395 if (ret < 0)
396 goto fail;
397 }
398
399 dst->format = src->format;
400 dst->width = src->width;
401 dst->height = src->height;
402 dst->nb_samples = src->nb_samples;
403
404 ret = av_channel_layout_copy(&dst->ch_layout, &src->ch_layout);
405 if (ret < 0)
406 goto fail;
407
408 av_frame_side_data_free(&dst->side_data, &dst->nb_side_data);
409 av_dict_free(&dst->metadata);
411 if (ret < 0)
412 goto fail;
413
414 /* replace the buffers */
415 for (int i = 0; i < FF_ARRAY_ELEMS(src->buf); i++) {
416 ret = av_buffer_replace(&dst->buf[i], src->buf[i]);
417 if (ret < 0)
418 goto fail;
419 }
420
421 if (src->extended_buf) {
422 if (dst->nb_extended_buf != src->nb_extended_buf) {
423 int nb_extended_buf = FFMIN(dst->nb_extended_buf, src->nb_extended_buf);
424 void *tmp;
425
426 for (int i = nb_extended_buf; i < dst->nb_extended_buf; i++)
427 av_buffer_unref(&dst->extended_buf[i]);
428
429 tmp = av_realloc_array(dst->extended_buf, src->nb_extended_buf,
430 sizeof(*dst->extended_buf));
431 if (!tmp) {
432 ret = AVERROR(ENOMEM);
433 goto fail;
434 }
435 dst->extended_buf = tmp;
436 dst->nb_extended_buf = src->nb_extended_buf;
437
438 memset(&dst->extended_buf[nb_extended_buf], 0,
439 (src->nb_extended_buf - nb_extended_buf) * sizeof(*dst->extended_buf));
440 }
441
442 for (int i = 0; i < src->nb_extended_buf; i++) {
443 ret = av_buffer_replace(&dst->extended_buf[i], src->extended_buf[i]);
444 if (ret < 0)
445 goto fail;
446 }
447 } else if (dst->extended_buf) {
448 for (int i = 0; i < dst->nb_extended_buf; i++)
449 av_buffer_unref(&dst->extended_buf[i]);
450 av_freep(&dst->extended_buf);
451 }
452
453 ret = av_buffer_replace(&dst->hw_frames_ctx, src->hw_frames_ctx);
454 if (ret < 0)
455 goto fail;
456
457 if (dst->extended_data != dst->data)
458 av_freep(&dst->extended_data);
459
460 if (src->extended_data != src->data) {
461 int ch = dst->ch_layout.nb_channels;
462
463 if (ch <= 0 || ch > SIZE_MAX / sizeof(*dst->extended_data)) {
464 ret = AVERROR(EINVAL);
465 goto fail;
466 }
467
468 dst->extended_data = av_memdup(src->extended_data, sizeof(*dst->extended_data) * ch);
469 if (!dst->extended_data) {
470 ret = AVERROR(ENOMEM);
471 goto fail;
472 }
473 } else
474 dst->extended_data = dst->data;
475
476 memcpy(dst->data, src->data, sizeof(src->data));
477 memcpy(dst->linesize, src->linesize, sizeof(src->linesize));
478
479 return 0;
480
481fail:
483 return ret;
484}
485
487{
489
490 if (!ret)
491 return NULL;
492
493 if (av_frame_ref(ret, src) < 0)
495
496 return ret;
497}
498
500{
501 if (!frame)
502 return;
503
504 av_frame_side_data_free(&frame->side_data, &frame->nb_side_data);
505
506 for (int i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)
507 av_buffer_unref(&frame->buf[i]);
508 for (int i = 0; i < frame->nb_extended_buf; i++)
509 av_buffer_unref(&frame->extended_buf[i]);
510 av_freep(&frame->extended_buf);
511 av_dict_free(&frame->metadata);
512
513 av_buffer_unref(&frame->hw_frames_ctx);
514
515 av_buffer_unref(&frame->opaque_ref);
516 av_refstruct_unref(&frame->private_ref);
517
518 if (frame->extended_data != frame->data)
519 av_freep(&frame->extended_data);
520
521 av_channel_layout_uninit(&frame->ch_layout);
522
524}
525
527{
528 av_assert1(dst->width == 0 && dst->height == 0);
529 av_assert1(dst->ch_layout.nb_channels == 0 &&
530 dst->ch_layout.order == AV_CHANNEL_ORDER_UNSPEC);
531
532 *dst = *src;
533 if (src->extended_data == src->data)
534 dst->extended_data = dst->data;
536}
537
539{
540 int ret = 1;
541
542 /* assume non-refcounted frames are not writable */
543 if (!frame->buf[0])
544 return 0;
545
546 for (int i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)
547 if (frame->buf[i])
548 ret &= !!av_buffer_is_writable(frame->buf[i]);
549 for (int i = 0; i < frame->nb_extended_buf; i++)
550 ret &= !!av_buffer_is_writable(frame->extended_buf[i]);
551
552 return ret;
553}
554
556{
557 AVFrame tmp;
558 int ret;
559
561 return 0;
562
563 memset(&tmp, 0, sizeof(tmp));
564 tmp.format = frame->format;
565 tmp.width = frame->width;
566 tmp.height = frame->height;
567 tmp.nb_samples = frame->nb_samples;
568 ret = av_channel_layout_copy(&tmp.ch_layout, &frame->ch_layout);
569 if (ret < 0) {
571 return ret;
572 }
573
574 if (frame->hw_frames_ctx)
575 ret = av_hwframe_get_buffer(frame->hw_frames_ctx, &tmp, 0);
576 else
578 if (ret < 0)
579 return ret;
580
582 if (ret < 0) {
584 return ret;
585 }
586
588 if (ret < 0) {
590 return ret;
591 }
592
594
595 *frame = tmp;
596 if (tmp.data == tmp.extended_data)
597 frame->extended_data = frame->data;
598
599 return 0;
600}
601
603{
604 return frame_copy_props(dst, src, 1);
605}
606
608{
609 uintptr_t data;
610 int planes;
611
612 if (frame->nb_samples) {
613 int channels = frame->ch_layout.nb_channels;
614 if (!channels)
615 return NULL;
617 } else
618 planes = 4;
619
620 if (plane < 0 || plane >= planes || !frame->extended_data[plane])
621 return NULL;
622 data = (uintptr_t)frame->extended_data[plane];
623
624 for (int i = 0; i < FF_ARRAY_ELEMS(frame->buf) && frame->buf[i]; i++) {
625 AVBufferRef *buf = frame->buf[i];
626 uintptr_t buf_begin = (uintptr_t)buf->data;
627
628 if (data >= buf_begin && data < buf_begin + buf->size)
629 return buf;
630 }
631 for (int i = 0; i < frame->nb_extended_buf; i++) {
632 AVBufferRef *buf = frame->extended_buf[i];
633 uintptr_t buf_begin = (uintptr_t)buf->data;
634
635 if (data >= buf_begin && data < buf_begin + buf->size)
636 return buf;
637 }
638 return NULL;
639}
640
643 AVBufferRef *buf)
644{
645 return
647 &frame->side_data, &frame->nb_side_data, type, buf);
648}
649
661
664{
666 frame->side_data, frame->nb_side_data,
667 type
668 );
669}
670
672{
673 int planes;
674
675 if (dst->width < src->width ||
676 dst->height < src->height)
677 return AVERROR(EINVAL);
678
679 if (src->hw_frames_ctx || dst->hw_frames_ctx)
680 return av_hwframe_transfer_data(dst, src, 0);
681
683 for (int i = 0; i < planes; i++)
684 if (!dst->data[i] || !src->data[i])
685 return AVERROR(EINVAL);
686
687 av_image_copy2(dst->data, dst->linesize,
688 src->data, src->linesize,
689 dst->format, src->width, src->height);
690
691 return 0;
692}
693
695{
696 int planar = av_sample_fmt_is_planar(dst->format);
697 int channels = dst->ch_layout.nb_channels;
698 int planes = planar ? channels : 1;
699
700 if (dst->nb_samples != src->nb_samples ||
701 av_channel_layout_compare(&dst->ch_layout, &src->ch_layout))
702 return AVERROR(EINVAL);
703
704 for (int i = 0; i < planes; i++)
705 if (!dst->extended_data[i] || !src->extended_data[i])
706 return AVERROR(EINVAL);
707
708 av_samples_copy(dst->extended_data, src->extended_data, 0, 0,
709 dst->nb_samples, channels, dst->format);
710
711 return 0;
712}
713
715{
716 if (dst->format != src->format || dst->format < 0)
717 return AVERROR(EINVAL);
718
719 if (dst->width > 0 && dst->height > 0)
720 return frame_copy_video(dst, src);
721 else if (dst->nb_samples > 0 &&
722 (av_channel_layout_check(&dst->ch_layout)))
723 return frame_copy_audio(dst, src);
724
725 return AVERROR(EINVAL);
726}
727
732
733static int calc_cropping_offsets(ptrdiff_t offsets[4], const AVFrame *frame,
735{
736 for (int i = 0; frame->data[i]; i++) {
738 int shift_x = (i == 1 || i == 2) ? desc->log2_chroma_w : 0;
739 int shift_y = (i == 1 || i == 2) ? desc->log2_chroma_h : 0;
740
741 if (desc->flags & AV_PIX_FMT_FLAG_PAL && i == 1) {
742 offsets[i] = 0;
743 break;
744 }
745
746 /* find any component descriptor for this plane */
747 for (int j = 0; j < desc->nb_components; j++) {
748 if (desc->comp[j].plane == i) {
749 comp = &desc->comp[j];
750 break;
751 }
752 }
753 if (!comp)
754 return AVERROR_BUG;
755
756 offsets[i] = (ptrdiff_t)(frame->crop_top >> shift_y) * frame->linesize[i] +
757 (ptrdiff_t)(frame->crop_left >> shift_x) * comp->step;
758 }
759
760 return 0;
761}
762
764{
766 ptrdiff_t offsets[4];
767 int ret;
768
769 if (!(frame->width > 0 && frame->height > 0))
770 return AVERROR(EINVAL);
771
772 if (frame->crop_left >= INT_MAX - frame->crop_right ||
773 frame->crop_top >= INT_MAX - frame->crop_bottom ||
774 (frame->crop_left + frame->crop_right) >= frame->width ||
775 (frame->crop_top + frame->crop_bottom) >= frame->height)
776 return AVERROR(ERANGE);
777
778 desc = av_pix_fmt_desc_get(frame->format);
779 if (!desc)
780 return AVERROR_BUG;
781
782 /* Apply just the right/bottom cropping for hwaccel formats. Bitstream
783 * formats cannot be easily handled here either (and corresponding decoders
784 * should not export any cropping anyway), so do the same for those as well.
785 * */
787 frame->width -= frame->crop_right;
788 frame->height -= frame->crop_bottom;
789 frame->crop_right = 0;
790 frame->crop_bottom = 0;
791 return 0;
792 }
793
794 /* calculate the offsets for each plane */
796 if (ret < 0)
797 return ret;
798
799 /* adjust the offsets to avoid breaking alignment */
801 int log2_crop_align = frame->crop_left ? ff_ctz(frame->crop_left) : INT_MAX;
802 int min_log2_align = INT_MAX;
803
804 for (int i = 0; frame->data[i]; i++) {
805 int log2_align = offsets[i] ? ff_ctzll(offsets[i]) : INT_MAX;
806 min_log2_align = FFMIN(log2_align, min_log2_align);
807 }
808
809 /* The data alignment is the cropping alignment scaled by a power of 2,
810 * up for multi-byte pixels and down for subsampled planes */
811 if (min_log2_align < 5 && log2_crop_align != INT_MAX) {
812 frame->crop_left &= ~((1 << (5 + log2_crop_align - min_log2_align)) - 1);
814 if (ret < 0)
815 return ret;
816 }
817 }
818
819 for (int i = 0; frame->data[i]; i++)
820 frame->data[i] += offsets[i];
821
822 frame->width -= (frame->crop_left + frame->crop_right);
823 frame->height -= (frame->crop_top + frame->crop_bottom);
824 frame->crop_left = 0;
825 frame->crop_right = 0;
826 frame->crop_top = 0;
827 frame->crop_bottom = 0;
828
829 return 0;
830}
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:97
channels
Definition aptx.h:31
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
Definition avassert.h:58
static const uint8_t *BS_FUNC align(BSCTX *bc)
Skip bits to a byte boundary.
refcounted data buffer API
#define flags(name, subs,...)
Definition cbs_h264.c:74
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
Public libavutil channel layout APIs header.
#define NULL
Definition coverity.c:32
static AVFrame * frame
Public dictionary API.
int ret
Definition ffplay.c:391
int ff_frame_get_video_buffer(AVFrame *frame, int align, AVBufferRef *(*alloc)(void *opaque, size_t size), void *opaque)
Allocate the buffer of a video frame like av_frame_get_buffer().
Definition frame.c:76
static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
Definition frame.c:223
static int frame_copy_video(AVFrame *dst, const AVFrame *src)
Definition frame.c:671
static void get_frame_defaults(AVFrame *frame)
Definition frame.c:32
static int get_audio_buffer(AVFrame *frame, int align)
Definition frame.c:149
static int frame_copy_audio(AVFrame *dst, const AVFrame *src)
Definition frame.c:694
static int calc_cropping_offsets(ptrdiff_t offsets[4], const AVFrame *frame, const AVPixFmtDescriptor *desc)
Definition frame.c:733
reference-counted frame API
#define AV_NUM_DATA_POINTERS
Definition frame.h:480
#define fail
Definition test.h:479
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
void av_channel_layout_uninit(AVChannelLayout *channel_layout)
Free any allocated data in the channel layout and reset the channel count to 0.
int av_channel_layout_check(const AVChannelLayout *channel_layout)
Check whether a channel layout is valid, i.e.
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
@ AV_CHANNEL_ORDER_UNSPEC
Only the channel count is specified, without any further information about the channel order.
int av_buffer_is_writable(const AVBufferRef *buf)
Definition buffer.c:148
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:140
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
Definition buffer.c:234
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition buffer.c:104
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
Definition buffer.c:78
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
Definition dict.c:236
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition dict.c:250
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition error.h:52
#define AVERROR(e)
Definition error.h:45
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition frame.c:499
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition frame.c:662
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:728
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:140
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:379
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition frame.c:538
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition frame.c:209
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition frame.c:526
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:281
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:109
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:65
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:650
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:641
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition frame.c:602
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition frame.c:53
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition frame.c:486
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
Definition frame.c:555
AVFrameSideDataType
Definition frame.h:49
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:763
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition frame.c:714
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:1206
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:607
@ AV_FRAME_CROP_UNALIGNED
Apply the maximum possible cropping, even if it requires setting the AVFrame.data[] entries to unalig...
Definition frame.h:1057
@ AV_FRAME_DATA_PANSCAN
The data is the AVPanScan struct defined in libavcodec.
Definition frame.h:53
#define ff_ctzll
Definition intmath.h:125
#define ff_ctz
Definition intmath.h:105
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition mem.c:318
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
Definition mem.c:408
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
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
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
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
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
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition samplefmt.c:115
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:122
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:223
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition avutil.h:247
#define ALIGN
Definition hashtable.c:32
static const int offsets[]
Definition hevc_pel.c:34
int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags)
Copy data to or from a hw surface.
Definition hwcontext.c:498
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
Definition hwcontext.c:564
static const int sizes[][2]
Definition img2dec.c:63
misc image utilities
enum MPFType type
Definition jpegmpfenc.c:55
AVFrameSideData * ff_frame_side_data_add_from_buf(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, AVBufferRef *buf)
Definition side_data.c:180
const char * desc
Definition libsvtav1.c:110
static const struct @257111027162314367033347246032313251342043035002 planes[]
#define FFMIN(a, b)
Definition macros.h:49
#define FFMAX(a, b)
Definition macros.h:47
#define FFALIGN(x, a)
Definition macros.h:78
void * av_calloc(size_t nmemb, size_t size)
Definition mem.c:370
Memory handling functions.
const char data[16]
Definition mxf.c:155
#define av_malloc(s)
Definition ops_static.c:52
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3524
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3484
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
Definition pixdesc.h:124
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
Definition pixdesc.h:128
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
Definition pixdesc.h:120
@ AVCHROMA_LOC_UNSPECIFIED
Definition pixfmt.h:812
@ AVCOL_RANGE_UNSPECIFIED
Definition pixfmt.h:758
@ AVALPHA_MODE_UNSPECIFIED
Unknown alpha handling, or no alpha channel.
Definition pixfmt.h:826
@ AVCOL_PRI_UNSPECIFIED
Definition pixfmt.h:650
@ AVCOL_TRC_UNSPECIFIED
Definition pixfmt.h:680
@ AVCOL_SPC_UNSPECIFIED
Definition pixfmt.h:714
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:121
void av_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
Definition refstruct.c:161
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
Definition buffer.h:82
uint8_t * data
The data buffer.
Definition buffer.h:90
Structure to hold side data for an AVFrame.
Definition frame.h:334
enum AVFrameSideDataType type
Definition frame.h:335
AVDictionary * metadata
Definition frame.h:338
size_t size
Definition frame.h:337
uint8_t * data
Definition frame.h:336
AVBufferRef * buf
Definition frame.h:339
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
Rational number (pair of numerator and denominator).
Definition rational.h:58
Definition format.c:918
#define av_freep(p)
static uint8_t tmp[40]
Definition aes_ctr.c:52
#define src
Definition vp8dsp.c:248
static int ref[MAX_W *MAX_W]
int size