Libav
frame.c
Go to the documentation of this file.
1 /*
2  * This file is part of Libav.
3  *
4  * Libav 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  * Libav 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 Libav; 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 "buffer.h"
21 #include "common.h"
22 #include "dict.h"
23 #include "frame.h"
24 #include "imgutils.h"
25 #include "mem.h"
26 #include "samplefmt.h"
27 
28 static void get_frame_defaults(AVFrame *frame)
29 {
30  if (frame->extended_data != frame->data)
31  av_freep(&frame->extended_data);
32 
33  memset(frame, 0, sizeof(*frame));
34 
35  frame->pts = AV_NOPTS_VALUE;
36  frame->key_frame = 1;
37  frame->sample_aspect_ratio = (AVRational){ 0, 1 };
38  frame->format = -1; /* unknown */
39  frame->extended_data = frame->data;
45 }
46 
47 static void free_side_data(AVFrameSideData **ptr_sd)
48 {
49  AVFrameSideData *sd = *ptr_sd;
50 
51  av_freep(&sd->data);
52  av_dict_free(&sd->metadata);
53  av_freep(ptr_sd);
54 }
55 
56 static void wipe_side_data(AVFrame *frame)
57 {
58  int i;
59 
60  for (i = 0; i < frame->nb_side_data; i++) {
61  free_side_data(&frame->side_data[i]);
62  }
63  frame->nb_side_data = 0;
64 
65  av_freep(&frame->side_data);
66 }
67 
69 {
70  AVFrame *frame = av_mallocz(sizeof(*frame));
71 
72  if (!frame)
73  return NULL;
74 
75  get_frame_defaults(frame);
76 
77  return frame;
78 }
79 
80 void av_frame_free(AVFrame **frame)
81 {
82  if (!frame || !*frame)
83  return;
84 
85  av_frame_unref(*frame);
86  av_freep(frame);
87 }
88 
89 static int get_video_buffer(AVFrame *frame, int align)
90 {
92  int ret, i;
93 
94  if (!desc)
95  return AVERROR(EINVAL);
96 
97  if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL)) < 0)
98  return ret;
99 
100  if (!frame->linesize[0]) {
101  ret = av_image_fill_linesizes(frame->linesize, frame->format,
102  frame->width);
103  if (ret < 0)
104  return ret;
105 
106  for (i = 0; i < 4 && frame->linesize[i]; i++)
107  frame->linesize[i] = FFALIGN(frame->linesize[i], align);
108  }
109 
110  for (i = 0; i < 4 && frame->linesize[i]; i++) {
111  int h = frame->height;
112  if (i == 1 || i == 2)
113  h = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
114 
115  frame->buf[i] = av_buffer_alloc(frame->linesize[i] * h);
116  if (!frame->buf[i])
117  goto fail;
118 
119  frame->data[i] = frame->buf[i]->data;
120  }
121  if (desc->flags & AV_PIX_FMT_FLAG_PAL || desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL) {
122  av_buffer_unref(&frame->buf[1]);
123  frame->buf[1] = av_buffer_alloc(1024);
124  if (!frame->buf[1])
125  goto fail;
126  frame->data[1] = frame->buf[1]->data;
127  }
128 
129  frame->extended_data = frame->data;
130 
131  return 0;
132 fail:
133  av_frame_unref(frame);
134  return AVERROR(ENOMEM);
135 }
136 
137 static int get_audio_buffer(AVFrame *frame, int align)
138 {
139  int channels = av_get_channel_layout_nb_channels(frame->channel_layout);
140  int planar = av_sample_fmt_is_planar(frame->format);
141  int planes = planar ? channels : 1;
142  int ret, i;
143 
144  if (!frame->linesize[0]) {
145  ret = av_samples_get_buffer_size(&frame->linesize[0], channels,
146  frame->nb_samples, frame->format,
147  align);
148  if (ret < 0)
149  return ret;
150  }
151 
152  if (planes > AV_NUM_DATA_POINTERS) {
153  frame->extended_data = av_mallocz(planes *
154  sizeof(*frame->extended_data));
155  frame->extended_buf = av_mallocz((planes - AV_NUM_DATA_POINTERS) *
156  sizeof(*frame->extended_buf));
157  if (!frame->extended_data || !frame->extended_buf) {
158  av_freep(&frame->extended_data);
159  av_freep(&frame->extended_buf);
160  return AVERROR(ENOMEM);
161  }
162  frame->nb_extended_buf = planes - AV_NUM_DATA_POINTERS;
163  } else
164  frame->extended_data = frame->data;
165 
166  for (i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) {
167  frame->buf[i] = av_buffer_alloc(frame->linesize[0]);
168  if (!frame->buf[i]) {
169  av_frame_unref(frame);
170  return AVERROR(ENOMEM);
171  }
172  frame->extended_data[i] = frame->data[i] = frame->buf[i]->data;
173  }
174  for (i = 0; i < planes - AV_NUM_DATA_POINTERS; i++) {
175  frame->extended_buf[i] = av_buffer_alloc(frame->linesize[0]);
176  if (!frame->extended_buf[i]) {
177  av_frame_unref(frame);
178  return AVERROR(ENOMEM);
179  }
180  frame->extended_data[i + AV_NUM_DATA_POINTERS] = frame->extended_buf[i]->data;
181  }
182  return 0;
183 
184 }
185 
186 int av_frame_get_buffer(AVFrame *frame, int align)
187 {
188  if (frame->format < 0)
189  return AVERROR(EINVAL);
190 
191  if (frame->width > 0 && frame->height > 0)
192  return get_video_buffer(frame, align);
193  else if (frame->nb_samples > 0 && frame->channel_layout)
194  return get_audio_buffer(frame, align);
195 
196  return AVERROR(EINVAL);
197 }
198 
199 int av_frame_ref(AVFrame *dst, const AVFrame *src)
200 {
201  int i, ret = 0;
202 
203  dst->format = src->format;
204  dst->width = src->width;
205  dst->height = src->height;
206  dst->channel_layout = src->channel_layout;
207  dst->nb_samples = src->nb_samples;
208 
209  ret = av_frame_copy_props(dst, src);
210  if (ret < 0)
211  return ret;
212 
213  /* duplicate the frame data if it's not refcounted */
214  if (!src->buf[0]) {
215  ret = av_frame_get_buffer(dst, 32);
216  if (ret < 0)
217  return ret;
218 
219  ret = av_frame_copy(dst, src);
220  if (ret < 0)
221  av_frame_unref(dst);
222 
223  return ret;
224  }
225 
226  /* ref the buffers */
227  for (i = 0; i < FF_ARRAY_ELEMS(src->buf) && src->buf[i]; i++) {
228  dst->buf[i] = av_buffer_ref(src->buf[i]);
229  if (!dst->buf[i]) {
230  ret = AVERROR(ENOMEM);
231  goto fail;
232  }
233  }
234 
235  if (src->extended_buf) {
236  dst->extended_buf = av_mallocz(sizeof(*dst->extended_buf) *
237  src->nb_extended_buf);
238  if (!dst->extended_buf) {
239  ret = AVERROR(ENOMEM);
240  goto fail;
241  }
242  dst->nb_extended_buf = src->nb_extended_buf;
243 
244  for (i = 0; i < src->nb_extended_buf; i++) {
245  dst->extended_buf[i] = av_buffer_ref(src->extended_buf[i]);
246  if (!dst->extended_buf[i]) {
247  ret = AVERROR(ENOMEM);
248  goto fail;
249  }
250  }
251  }
252 
253  if (src->hw_frames_ctx) {
255  if (!dst->hw_frames_ctx) {
256  ret = AVERROR(ENOMEM);
257  goto fail;
258  }
259  }
260 
261  /* duplicate extended data */
262  if (src->extended_data != src->data) {
264 
265  if (!ch) {
266  ret = AVERROR(EINVAL);
267  goto fail;
268  }
269 
270  dst->extended_data = av_malloc(sizeof(*dst->extended_data) * ch);
271  if (!dst->extended_data) {
272  ret = AVERROR(ENOMEM);
273  goto fail;
274  }
275  memcpy(dst->extended_data, src->extended_data, sizeof(*src->extended_data) * ch);
276  } else
277  dst->extended_data = dst->data;
278 
279  memcpy(dst->data, src->data, sizeof(src->data));
280  memcpy(dst->linesize, src->linesize, sizeof(src->linesize));
281 
282  return 0;
283 
284 fail:
285  av_frame_unref(dst);
286  return ret;
287 }
288 
290 {
291  AVFrame *ret = av_frame_alloc();
292 
293  if (!ret)
294  return NULL;
295 
296  if (av_frame_ref(ret, src) < 0)
297  av_frame_free(&ret);
298 
299  return ret;
300 }
301 
303 {
304  int i;
305 
306  wipe_side_data(frame);
307 
308  for (i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)
309  av_buffer_unref(&frame->buf[i]);
310  for (i = 0; i < frame->nb_extended_buf; i++)
311  av_buffer_unref(&frame->extended_buf[i]);
312  av_freep(&frame->extended_buf);
313 
315 
316  get_frame_defaults(frame);
317 }
318 
320 {
321  *dst = *src;
322  if (src->extended_data == src->data)
323  dst->extended_data = dst->data;
324  memset(src, 0, sizeof(*src));
325  get_frame_defaults(src);
326 }
327 
329 {
330  int i, ret = 1;
331 
332  /* assume non-refcounted frames are not writable */
333  if (!frame->buf[0])
334  return 0;
335 
336  for (i = 0; i < FF_ARRAY_ELEMS(frame->buf) && frame->buf[i]; i++)
337  ret &= !!av_buffer_is_writable(frame->buf[i]);
338  for (i = 0; i < frame->nb_extended_buf; i++)
339  ret &= !!av_buffer_is_writable(frame->extended_buf[i]);
340 
341  return ret;
342 }
343 
345 {
346  AVFrame tmp;
347  int ret;
348 
349  if (!frame->buf[0])
350  return AVERROR(EINVAL);
351 
352  if (av_frame_is_writable(frame))
353  return 0;
354 
355  memset(&tmp, 0, sizeof(tmp));
356  tmp.format = frame->format;
357  tmp.width = frame->width;
358  tmp.height = frame->height;
359  tmp.channel_layout = frame->channel_layout;
360  tmp.nb_samples = frame->nb_samples;
361  ret = av_frame_get_buffer(&tmp, 32);
362  if (ret < 0)
363  return ret;
364 
365  ret = av_frame_copy(&tmp, frame);
366  if (ret < 0) {
367  av_frame_unref(&tmp);
368  return ret;
369  }
370 
371  ret = av_frame_copy_props(&tmp, frame);
372  if (ret < 0) {
373  av_frame_unref(&tmp);
374  return ret;
375  }
376 
377  av_frame_unref(frame);
378 
379  *frame = tmp;
380  if (tmp.data == tmp.extended_data)
381  frame->extended_data = frame->data;
382 
383  return 0;
384 }
385 
387 {
388  int i;
389 
390  dst->key_frame = src->key_frame;
391  dst->pict_type = src->pict_type;
393  dst->pts = src->pts;
394  dst->repeat_pict = src->repeat_pict;
396  dst->top_field_first = src->top_field_first;
398  dst->sample_rate = src->sample_rate;
399  dst->opaque = src->opaque;
400 #if FF_API_PKT_PTS
402  dst->pkt_pts = src->pkt_pts;
404 #endif
405  dst->pkt_dts = src->pkt_dts;
407  dst->quality = src->quality;
410  dst->flags = src->flags;
411  dst->color_primaries = src->color_primaries;
412  dst->color_trc = src->color_trc;
413  dst->colorspace = src->colorspace;
414  dst->color_range = src->color_range;
415  dst->chroma_location = src->chroma_location;
416 
417 #if FF_API_ERROR_FRAME
419  memcpy(dst->error, src->error, sizeof(dst->error));
421 #endif
422 
423  for (i = 0; i < src->nb_side_data; i++) {
424  const AVFrameSideData *sd_src = src->side_data[i];
425  AVFrameSideData *sd_dst = av_frame_new_side_data(dst, sd_src->type,
426  sd_src->size);
427  if (!sd_dst) {
428  wipe_side_data(dst);
429  return AVERROR(ENOMEM);
430  }
431  memcpy(sd_dst->data, sd_src->data, sd_src->size);
432  av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
433  }
434 
435  return 0;
436 }
437 
439 {
440  uint8_t *data;
441  int planes, i;
442 
443  if (frame->nb_samples) {
444  int channels = av_get_channel_layout_nb_channels(frame->channel_layout);
445  if (!channels)
446  return NULL;
447  planes = av_sample_fmt_is_planar(frame->format) ? channels : 1;
448  } else
449  planes = 4;
450 
451  if (plane < 0 || plane >= planes || !frame->extended_data[plane])
452  return NULL;
453  data = frame->extended_data[plane];
454 
455  for (i = 0; i < FF_ARRAY_ELEMS(frame->buf) && frame->buf[i]; i++) {
456  AVBufferRef *buf = frame->buf[i];
457  if (data >= buf->data && data < buf->data + buf->size)
458  return buf;
459  }
460  for (i = 0; i < frame->nb_extended_buf; i++) {
461  AVBufferRef *buf = frame->extended_buf[i];
462  if (data >= buf->data && data < buf->data + buf->size)
463  return buf;
464  }
465  return NULL;
466 }
467 
469  enum AVFrameSideDataType type,
470  int size)
471 {
472  AVFrameSideData *ret, **tmp;
473 
474  if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
475  return NULL;
476 
477  tmp = av_realloc(frame->side_data,
478  (frame->nb_side_data + 1) * sizeof(*frame->side_data));
479  if (!tmp)
480  return NULL;
481  frame->side_data = tmp;
482 
483  ret = av_mallocz(sizeof(*ret));
484  if (!ret)
485  return NULL;
486 
487  ret->data = av_malloc(size);
488  if (!ret->data) {
489  av_freep(&ret);
490  return NULL;
491  }
492 
493  ret->size = size;
494  ret->type = type;
495 
496  frame->side_data[frame->nb_side_data++] = ret;
497 
498  return ret;
499 }
500 
502  enum AVFrameSideDataType type)
503 {
504  int i;
505 
506  for (i = 0; i < frame->nb_side_data; i++) {
507  if (frame->side_data[i]->type == type)
508  return frame->side_data[i];
509  }
510  return NULL;
511 }
512 
513 static int frame_copy_video(AVFrame *dst, const AVFrame *src)
514 {
515  const uint8_t *src_data[4];
516  int i, planes;
517 
518  if (dst->width != src->width ||
519  dst->height != src->height)
520  return AVERROR(EINVAL);
521 
522  planes = av_pix_fmt_count_planes(dst->format);
523  for (i = 0; i < planes; i++)
524  if (!dst->data[i] || !src->data[i])
525  return AVERROR(EINVAL);
526 
527  memcpy(src_data, src->data, sizeof(src_data));
528  av_image_copy(dst->data, dst->linesize,
529  src_data, src->linesize,
530  dst->format, dst->width, dst->height);
531 
532  return 0;
533 }
534 
535 static int frame_copy_audio(AVFrame *dst, const AVFrame *src)
536 {
537  int planar = av_sample_fmt_is_planar(dst->format);
539  int planes = planar ? channels : 1;
540  int i;
541 
542  if (dst->nb_samples != src->nb_samples ||
543  dst->channel_layout != src->channel_layout)
544  return AVERROR(EINVAL);
545 
546  for (i = 0; i < planes; i++)
547  if (!dst->extended_data[i] || !src->extended_data[i])
548  return AVERROR(EINVAL);
549 
551  dst->nb_samples, channels, dst->format);
552 
553  return 0;
554 }
555 
556 int av_frame_copy(AVFrame *dst, const AVFrame *src)
557 {
558  if (dst->format != src->format || dst->format < 0)
559  return AVERROR(EINVAL);
560 
561  if (dst->width > 0 && dst->height > 0)
562  return frame_copy_video(dst, src);
563  else if (dst->nb_samples > 0 && dst->channel_layout)
564  return frame_copy_audio(dst, src);
565 
566  return AVERROR(EINVAL);
567 }
568 
570 {
571  int i;
572 
573  for (i = 0; i < frame->nb_side_data; i++) {
574  AVFrameSideData *sd = frame->side_data[i];
575  if (sd->type == type) {
576  free_side_data(&frame->side_data[i]);
577  frame->side_data[i] = frame->side_data[frame->nb_side_data - 1];
578  frame->nb_side_data--;
579  }
580  }
581 }
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
Definition: pixdesc.h:134
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
#define AV_NUM_DATA_POINTERS
Definition: frame.h:141
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:106
int size
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1768
This structure describes decoded (raw) audio or video data.
Definition: frame.h:140
misc image utilities
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1805
memory handling functions
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:308
const char * desc
Definition: nvenc.c:101
AVDictionary * metadata
Definition: frame.h:111
void * opaque
for some private data of the user
Definition: frame.h:244
int nb_extended_buf
Number of elements in extended_buf.
Definition: frame.h:326
int repeat_pict
When decoding, this signals how much the picture must be delayed.
Definition: frame.h:258
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:189
static void wipe_side_data(AVFrame *frame)
Definition: frame.c:56
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:319
#define FF_ARRAY_ELEMS(a)
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:202
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:501
AVBufferRef * hw_frames_ctx
For hwaccel-format frames, this should be a reference to the AVHWFramesContext describing the frame...
Definition: frame.h:365
Public dictionary API.
uint8_t
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:68
static int frame_copy_video(AVFrame *dst, const AVFrame *src)
Definition: frame.c:513
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:199
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:211
const char data[16]
Definition: mxf.c:70
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:263
int nb_side_data
Definition: frame.h:329
#define FFALIGN(x, a)
Definition: macros.h:48
attribute_deprecated uint64_t error[AV_NUM_DATA_POINTERS]
Definition: frame.h:251
AVFrameSideData ** side_data
Definition: frame.h:328
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:101
#define src
Definition: vp8dsp.c:254
int width
width and height of the video frame
Definition: frame.h:179
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:100
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:80
enum AVColorRange color_range
Definition: frame.h:351
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:175
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
enum AVColorSpace colorspace
Definition: frame.h:357
static int get_audio_buffer(AVFrame *frame, int align)
Definition: frame.c:137
#define fail()
Definition: checkasm.h:80
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
Definition: imgutils.c:268
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:556
reference-counted frame API
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:294
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:105
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:223
audio channel layout utility functions
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:201
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:349
#define FFMIN(a, b)
Definition: common.h:66
int display_picture_number
picture number in display order
Definition: frame.h:234
AVBufferRef ** extended_buf
For planar audio which requires more than AV_NUM_DATA_POINTERS AVBufferRef pointers, this array will hold all the references which cannot fit into AVFrame.buf.
Definition: frame.h:322
#define AV_PIX_FMT_FLAG_PSEUDOPAL
The pixel format is "pseudo-paletted".
Definition: pixdesc.h:156
AVBufferRef * av_frame_get_plane_buffer(AVFrame *frame, int plane)
Get the buffer reference a given data plane is stored in.
Definition: frame.c:438
AVFrameSideDataType
Definition: frame.h:47
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
Definition: frame.h:239
int av_buffer_is_writable(const AVBufferRef *buf)
Definition: buffer.c:121
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:289
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:191
NULL
Definition: eval.c:55
int coded_picture_number
picture number in bitstream order
Definition: frame.h:230
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:328
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
Definition: buffer.c:66
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:158
static int get_video_buffer(AVFrame *frame, int align)
Definition: frame.c:89
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:80
uint8_t * data
The data buffer.
Definition: buffer.h:89
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:206
uint8_t * data
Definition: frame.h:109
int av_samples_copy(uint8_t **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:187
void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
If side data of the supplied type exists in the frame, free it and remove it from the frame...
Definition: frame.c:569
int64_t reordered_opaque
reordered opaque 64 bits (generally an integer or a double precision float PTS but can be anything)...
Definition: frame.h:284
int sample_rate
Sample rate of the audio data.
Definition: frame.h:289
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:69
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, int size)
Add a new side data to a frame.
Definition: frame.c:468
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:108
rational number numerator/denominator
Definition: rational.h:43
int palette_has_changed
Tell user application that palette has changed from previous frame.
Definition: frame.h:273
refcounted data buffer API
enum AVChromaLocation chroma_location
Definition: frame.h:359
static int frame_copy_audio(AVFrame *dst, const AVFrame *src)
Definition: frame.c:535
int size
Size of data in bytes.
Definition: buffer.h:93
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:186
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:302
enum AVFrameSideDataType type
Definition: frame.h:108
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
Definition: frame.c:344
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:146
attribute_deprecated int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
Definition: frame.h:219
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
Definition: frame.h:225
A reference to a data buffer.
Definition: buffer.h:81
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:77
common internal and external API header
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:117
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:92
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:78
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:268
static uint8_t tmp[8]
Definition: des.c:38
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:196
enum AVColorPrimaries color_primaries
Definition: frame.h:353
int height
Definition: frame.h:179
static void free_side_data(AVFrameSideData **ptr_sd)
Definition: frame.c:47
enum AVColorTransferCharacteristic color_trc
Definition: frame.h:355
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:174
static void get_frame_defaults(AVFrame *frame)
Definition: frame.c:28
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:184
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:211
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:386
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:235
#define AV_CEIL_RSHIFT(a, b)
Fast a / (1 << b) rounded toward +inf, assuming a >= 0 and b >= 0.
Definition: common.h:57