74#define ALIGN (HAVE_SIMD_ALIGN_64 ? 64 : 32)
81 int ret, padded_height;
83 ptrdiff_t linesizes[4];
84 size_t total_size,
sizes[4];
96 if (!
frame->linesize[0]) {
106 for (
int i = 0;
i < 4 &&
frame->linesize[
i];
i++)
110 for (
int i = 0;
i < 4;
i++)
111 linesizes[
i] =
frame->linesize[
i];
115 padded_height, linesizes)) < 0)
118 total_size = 4 * plane_padding + 4 *
align;
119 for (
int i = 0;
i < 4;
i++) {
120 if (
sizes[
i] > SIZE_MAX - total_size)
126 if (!
frame->buf[0]) {
135 for (
int i = 1;
i < 4;
i++) {
137 frame->data[
i] +=
i * plane_padding;
158 if (!
frame->linesize[0]) {
171 sizeof(*
frame->extended_data));
173 sizeof(*
frame->extended_buf));
174 if (!
frame->extended_data || !
frame->extended_buf) {
198 if (!
frame->extended_buf[
i]) {
211 if (
frame->format < 0)
216 else if (
frame->nb_samples > 0 &&
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;
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;
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;
251 for (
int i = 0;
i <
src->nb_side_data;
i++) {
255 && (
src->width !=
dst->width ||
src->height !=
dst->height))
289 dst->format =
src->format;
291 dst->height =
src->height;
292 dst->nb_samples =
src->nb_samples;
326 if (
src->extended_buf) {
328 sizeof(*
dst->extended_buf));
329 if (!
dst->extended_buf) {
333 dst->nb_extended_buf =
src->nb_extended_buf;
335 for (
int i = 0;
i <
src->nb_extended_buf;
i++) {
337 if (!
dst->extended_buf[
i]) {
344 if (
src->hw_frames_ctx) {
346 if (!
dst->hw_frames_ctx) {
353 if (
src->extended_data !=
src->data) {
354 int ch =
dst->ch_layout.nb_channels;
356 if (ch <= 0 || ch > SIZE_MAX /
sizeof(*
dst->extended_data)) {
362 if (!
dst->extended_data) {
367 dst->extended_data =
dst->data;
369 memcpy(
dst->data,
src->data,
sizeof(
src->data));
370 memcpy(
dst->linesize,
src->linesize,
sizeof(
src->linesize));
390 if (
src->data[0] ||
src->data[1]
391 ||
src->data[2] ||
src->data[3])
399 dst->format =
src->format;
401 dst->height =
src->height;
402 dst->nb_samples =
src->nb_samples;
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);
426 for (
int i = nb_extended_buf;
i <
dst->nb_extended_buf;
i++)
430 sizeof(*
dst->extended_buf));
436 dst->nb_extended_buf =
src->nb_extended_buf;
438 memset(&
dst->extended_buf[nb_extended_buf], 0,
439 (
src->nb_extended_buf - nb_extended_buf) *
sizeof(*
dst->extended_buf));
442 for (
int i = 0;
i <
src->nb_extended_buf;
i++) {
447 }
else if (
dst->extended_buf) {
448 for (
int i = 0;
i <
dst->nb_extended_buf;
i++)
457 if (
dst->extended_data !=
dst->data)
460 if (
src->extended_data !=
src->data) {
461 int ch =
dst->ch_layout.nb_channels;
463 if (ch <= 0 || ch > SIZE_MAX /
sizeof(*
dst->extended_data)) {
469 if (!
dst->extended_data) {
474 dst->extended_data =
dst->data;
476 memcpy(
dst->data,
src->data,
sizeof(
src->data));
477 memcpy(
dst->linesize,
src->linesize,
sizeof(
src->linesize));
508 for (
int i = 0;
i <
frame->nb_extended_buf;
i++)
533 if (
src->extended_data ==
src->data)
534 dst->extended_data =
dst->data;
549 for (
int i = 0;
i <
frame->nb_extended_buf;
i++)
563 memset(&
tmp, 0,
sizeof(
tmp));
574 if (
frame->hw_frames_ctx)
596 if (
tmp.data ==
tmp.extended_data)
612 if (
frame->nb_samples) {
620 if (plane < 0 || plane >=
planes || !
frame->extended_data[plane])
622 data = (uintptr_t)
frame->extended_data[plane];
626 uintptr_t buf_begin = (uintptr_t)buf->
data;
631 for (
int i = 0;
i <
frame->nb_extended_buf;
i++) {
633 uintptr_t buf_begin = (uintptr_t)buf->
data;
675 if (
dst->width <
src->width ||
676 dst->height <
src->height)
679 if (
src->hw_frames_ctx ||
dst->hw_frames_ctx)
700 if (
dst->nb_samples !=
src->nb_samples ||
705 if (!
dst->extended_data[
i] || !
src->extended_data[
i])
716 if (
dst->format !=
src->format ||
dst->format < 0)
719 if (
dst->width > 0 &&
dst->height > 0)
721 else if (
dst->nb_samples > 0 &&
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;
747 for (
int j = 0; j <
desc->nb_components; j++) {
748 if (
desc->comp[j].plane ==
i) {
757 (ptrdiff_t)(
frame->crop_left >> shift_x) *
comp->step;
772 if (
frame->crop_left >= INT_MAX -
frame->crop_right ||
773 frame->crop_top >= INT_MAX -
frame->crop_bottom ||
789 frame->crop_right = 0;
790 frame->crop_bottom = 0;
801 int log2_crop_align =
frame->crop_left ?
ff_ctz(
frame->crop_left) : INT_MAX;
802 int min_log2_align = INT_MAX;
804 for (
int i = 0;
frame->data[
i];
i++) {
806 min_log2_align =
FFMIN(log2_align, min_log2_align);
811 if (min_log2_align < 5 && log2_crop_align != INT_MAX) {
812 frame->crop_left &= ~((1 << (5 + log2_crop_align - min_log2_align)) - 1);
819 for (
int i = 0;
frame->data[
i];
i++)
824 frame->crop_left = 0;
825 frame->crop_right = 0;
827 frame->crop_bottom = 0;
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
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.
static const uint8_t *BS_FUNC align(BSCTX *bc)
Skip bits to a byte boundary.
refcounted data buffer API
#define flags(name, subs,...)
#define i(width, name, range_min, range_max)
Public libavutil channel layout APIs header.
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().
static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
static int frame_copy_video(AVFrame *dst, const AVFrame *src)
static void get_frame_defaults(AVFrame *frame)
static int get_audio_buffer(AVFrame *frame, int align)
static int frame_copy_audio(AVFrame *dst, const AVFrame *src)
static int calc_cropping_offsets(ptrdiff_t offsets[4], const AVFrame *frame, const AVPixFmtDescriptor *desc)
reference-counted frame API
#define AV_NUM_DATA_POINTERS
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)
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values.
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
Remove and free all side data instances of the given type.
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...
int av_frame_replace(AVFrame *dst, const AVFrame *src)
Ensure the destination frame refers to the same data described by the source frame,...
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
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.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, size_t size)
Add a new side data to a frame.
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.
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
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.
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
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...
AVBufferRef * av_frame_get_plane_buffer(const AVFrame *frame, int plane)
Get the buffer reference a given data plane is stored in.
@ AV_FRAME_CROP_UNALIGNED
Apply the maximum possible cropping, even if it requires setting the AVFrame.data[] entries to unalig...
@ AV_FRAME_DATA_PANSCAN
The data is the AVPanScan struct defined in libavcodec.
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
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...
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.
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.
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 ...
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.
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
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.
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.
#define AV_NOPTS_VALUE
Undefined timestamp value.
static const int offsets[]
int av_hwframe_transfer_data(AVFrame *dst, const AVFrame *src, int flags)
Copy data to or from a hw surface.
int av_hwframe_get_buffer(AVBufferRef *hwframe_ref, AVFrame *frame, int flags)
Allocate a new frame attached to the given AVHWFramesContext.
static const int sizes[][2]
AVFrameSideData * ff_frame_side_data_add_from_buf(AVFrameSideData ***sd, int *nb_sd, enum AVFrameSideDataType type, AVBufferRef *buf)
static const struct @257111027162314367033347246032313251342043035002 planes[]
void * av_calloc(size_t nmemb, size_t size)
Memory handling functions.
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
#define AV_PIX_FMT_FLAG_BITSTREAM
All values of a component are bit-wise packed end to end.
#define AV_PIX_FMT_FLAG_HWACCEL
Pixel format is an HW accelerated format.
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
@ AVCHROMA_LOC_UNSPECIFIED
@ AVCOL_RANGE_UNSPECIFIED
@ AVALPHA_MODE_UNSPECIFIED
Unknown alpha handling, or no alpha channel.
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
void av_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
#define FF_ARRAY_ELEMS(a)
A reference to a data buffer.
uint8_t * data
The data buffer.
Structure to hold side data for an AVFrame.
enum AVFrameSideDataType type
This structure describes decoded (raw) audio or video data.
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Rational number (pair of numerator and denominator).
static int ref[MAX_W *MAX_W]