]> git.sesse.net Git - ffmpeg/blob - libavutil/frame.c
lavu/frame: put frame QP elements under a new version guard
[ffmpeg] / libavutil / frame.c
1 /*
2  *
3  * This file is part of FFmpeg.
4  *
5  * FFmpeg is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * FFmpeg is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with FFmpeg; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19
20 #include "channel_layout.h"
21 #include "avassert.h"
22 #include "buffer.h"
23 #include "common.h"
24 #include "dict.h"
25 #include "frame.h"
26 #include "imgutils.h"
27 #include "mem.h"
28 #include "samplefmt.h"
29
30 MAKE_ACCESSORS(AVFrame, frame, int64_t, best_effort_timestamp)
31 MAKE_ACCESSORS(AVFrame, frame, int64_t, pkt_duration)
32 MAKE_ACCESSORS(AVFrame, frame, int64_t, pkt_pos)
33 MAKE_ACCESSORS(AVFrame, frame, int64_t, channel_layout)
34 MAKE_ACCESSORS(AVFrame, frame, int,     channels)
35 MAKE_ACCESSORS(AVFrame, frame, int,     sample_rate)
36 MAKE_ACCESSORS(AVFrame, frame, AVDictionary *, metadata)
37 MAKE_ACCESSORS(AVFrame, frame, int,     decode_error_flags)
38 MAKE_ACCESSORS(AVFrame, frame, int,     pkt_size)
39 MAKE_ACCESSORS(AVFrame, frame, enum AVColorSpace, colorspace)
40 MAKE_ACCESSORS(AVFrame, frame, enum AVColorRange, color_range)
41
42 #define CHECK_CHANNELS_CONSISTENCY(frame) \
43     av_assert2(!(frame)->channel_layout || \
44                (frame)->channels == \
45                av_get_channel_layout_nb_channels((frame)->channel_layout))
46
47 AVDictionary **avpriv_frame_get_metadatap(AVFrame *frame) {return &frame->metadata;};
48
49 #if FF_API_FRAME_QP
50 int av_frame_set_qp_table(AVFrame *f, AVBufferRef *buf, int stride, int qp_type)
51 {
52     av_buffer_unref(&f->qp_table_buf);
53
54     f->qp_table_buf = buf;
55
56 FF_DISABLE_DEPRECATION_WARNINGS
57     f->qscale_table = buf->data;
58     f->qstride      = stride;
59     f->qscale_type  = qp_type;
60 FF_ENABLE_DEPRECATION_WARNINGS
61
62     return 0;
63 }
64
65 int8_t *av_frame_get_qp_table(AVFrame *f, int *stride, int *type)
66 {
67 FF_DISABLE_DEPRECATION_WARNINGS
68     *stride = f->qstride;
69     *type   = f->qscale_type;
70 FF_ENABLE_DEPRECATION_WARNINGS
71
72     if (!f->qp_table_buf)
73         return NULL;
74
75     return f->qp_table_buf->data;
76 }
77 #endif
78
79 const char *av_get_colorspace_name(enum AVColorSpace val)
80 {
81     static const char * const name[] = {
82         [AVCOL_SPC_RGB]       = "GBR",
83         [AVCOL_SPC_BT709]     = "bt709",
84         [AVCOL_SPC_FCC]       = "fcc",
85         [AVCOL_SPC_BT470BG]   = "bt470bg",
86         [AVCOL_SPC_SMPTE170M] = "smpte170m",
87         [AVCOL_SPC_SMPTE240M] = "smpte240m",
88         [AVCOL_SPC_YCOCG]     = "YCgCo",
89     };
90     if ((unsigned)val >= FF_ARRAY_ELEMS(name))
91         return NULL;
92     return name[val];
93 }
94
95 static void get_frame_defaults(AVFrame *frame)
96 {
97     if (frame->extended_data != frame->data)
98         av_freep(&frame->extended_data);
99
100     memset(frame, 0, sizeof(*frame));
101
102     frame->pts                   =
103     frame->pkt_dts               =
104     frame->pkt_pts               = AV_NOPTS_VALUE;
105     av_frame_set_best_effort_timestamp(frame, AV_NOPTS_VALUE);
106     av_frame_set_pkt_duration         (frame, 0);
107     av_frame_set_pkt_pos              (frame, -1);
108     av_frame_set_pkt_size             (frame, -1);
109     frame->key_frame           = 1;
110     frame->sample_aspect_ratio = (AVRational){ 0, 1 };
111     frame->format              = -1; /* unknown */
112     frame->extended_data       = frame->data;
113     frame->color_primaries     = AVCOL_PRI_UNSPECIFIED;
114     frame->color_trc           = AVCOL_TRC_UNSPECIFIED;
115     frame->colorspace          = AVCOL_SPC_UNSPECIFIED;
116     frame->color_range         = AVCOL_RANGE_UNSPECIFIED;
117     frame->chroma_location     = AVCHROMA_LOC_UNSPECIFIED;
118 }
119
120 static void free_side_data(AVFrameSideData **ptr_sd)
121 {
122     AVFrameSideData *sd = *ptr_sd;
123
124     av_buffer_unref(&sd->buf);
125     av_dict_free(&sd->metadata);
126     av_freep(ptr_sd);
127 }
128
129 static void wipe_side_data(AVFrame *frame)
130 {
131     int i;
132
133     for (i = 0; i < frame->nb_side_data; i++) {
134         free_side_data(&frame->side_data[i]);
135     }
136     frame->nb_side_data = 0;
137
138     av_freep(&frame->side_data);
139 }
140
141 AVFrame *av_frame_alloc(void)
142 {
143     AVFrame *frame = av_mallocz(sizeof(*frame));
144
145     if (!frame)
146         return NULL;
147
148     frame->extended_data = NULL;
149     get_frame_defaults(frame);
150
151     return frame;
152 }
153
154 void av_frame_free(AVFrame **frame)
155 {
156     if (!frame || !*frame)
157         return;
158
159     av_frame_unref(*frame);
160     av_freep(frame);
161 }
162
163 static int get_video_buffer(AVFrame *frame, int align)
164 {
165     const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
166     int ret, i;
167
168     if (!desc)
169         return AVERROR(EINVAL);
170
171     if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL)) < 0)
172         return ret;
173
174     if (!frame->linesize[0]) {
175         for(i=1; i<=align; i+=i) {
176             ret = av_image_fill_linesizes(frame->linesize, frame->format,
177                                           FFALIGN(frame->width, i));
178             if (ret < 0)
179                 return ret;
180             if (!(frame->linesize[0] & (align-1)))
181                 break;
182         }
183
184         for (i = 0; i < 4 && frame->linesize[i]; i++)
185             frame->linesize[i] = FFALIGN(frame->linesize[i], align);
186     }
187
188     for (i = 0; i < 4 && frame->linesize[i]; i++) {
189         int h = FFALIGN(frame->height, 32);
190         if (i == 1 || i == 2)
191             h = FF_CEIL_RSHIFT(h, desc->log2_chroma_h);
192
193         frame->buf[i] = av_buffer_alloc(frame->linesize[i] * h + 16 + 16/*STRIDE_ALIGN*/ - 1);
194         if (!frame->buf[i])
195             goto fail;
196
197         frame->data[i] = frame->buf[i]->data;
198     }
199     if (desc->flags & AV_PIX_FMT_FLAG_PAL || desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL) {
200         av_buffer_unref(&frame->buf[1]);
201         frame->buf[1] = av_buffer_alloc(1024);
202         if (!frame->buf[1])
203             goto fail;
204         frame->data[1] = frame->buf[1]->data;
205     }
206
207     frame->extended_data = frame->data;
208
209     return 0;
210 fail:
211     av_frame_unref(frame);
212     return AVERROR(ENOMEM);
213 }
214
215 static int get_audio_buffer(AVFrame *frame, int align)
216 {
217     int channels;
218     int planar   = av_sample_fmt_is_planar(frame->format);
219     int planes;
220     int ret, i;
221
222     if (!frame->channels)
223         frame->channels = av_get_channel_layout_nb_channels(frame->channel_layout);
224
225     channels = frame->channels;
226     planes = planar ? channels : 1;
227
228     CHECK_CHANNELS_CONSISTENCY(frame);
229     if (!frame->linesize[0]) {
230         ret = av_samples_get_buffer_size(&frame->linesize[0], channels,
231                                          frame->nb_samples, frame->format,
232                                          align);
233         if (ret < 0)
234             return ret;
235     }
236
237     if (planes > AV_NUM_DATA_POINTERS) {
238         frame->extended_data = av_mallocz_array(planes,
239                                           sizeof(*frame->extended_data));
240         frame->extended_buf  = av_mallocz_array((planes - AV_NUM_DATA_POINTERS),
241                                           sizeof(*frame->extended_buf));
242         if (!frame->extended_data || !frame->extended_buf) {
243             av_freep(&frame->extended_data);
244             av_freep(&frame->extended_buf);
245             return AVERROR(ENOMEM);
246         }
247         frame->nb_extended_buf = planes - AV_NUM_DATA_POINTERS;
248     } else
249         frame->extended_data = frame->data;
250
251     for (i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) {
252         frame->buf[i] = av_buffer_alloc(frame->linesize[0]);
253         if (!frame->buf[i]) {
254             av_frame_unref(frame);
255             return AVERROR(ENOMEM);
256         }
257         frame->extended_data[i] = frame->data[i] = frame->buf[i]->data;
258     }
259     for (i = 0; i < planes - AV_NUM_DATA_POINTERS; i++) {
260         frame->extended_buf[i] = av_buffer_alloc(frame->linesize[0]);
261         if (!frame->extended_buf[i]) {
262             av_frame_unref(frame);
263             return AVERROR(ENOMEM);
264         }
265         frame->extended_data[i + AV_NUM_DATA_POINTERS] = frame->extended_buf[i]->data;
266     }
267     return 0;
268
269 }
270
271 int av_frame_get_buffer(AVFrame *frame, int align)
272 {
273     if (frame->format < 0)
274         return AVERROR(EINVAL);
275
276     if (frame->width > 0 && frame->height > 0)
277         return get_video_buffer(frame, align);
278     else if (frame->nb_samples > 0 && (frame->channel_layout || frame->channels > 0))
279         return get_audio_buffer(frame, align);
280
281     return AVERROR(EINVAL);
282 }
283
284 static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
285 {
286     int i;
287
288     dst->key_frame              = src->key_frame;
289     dst->pict_type              = src->pict_type;
290     dst->sample_aspect_ratio    = src->sample_aspect_ratio;
291     dst->pts                    = src->pts;
292     dst->repeat_pict            = src->repeat_pict;
293     dst->interlaced_frame       = src->interlaced_frame;
294     dst->top_field_first        = src->top_field_first;
295     dst->palette_has_changed    = src->palette_has_changed;
296     dst->sample_rate            = src->sample_rate;
297     dst->opaque                 = src->opaque;
298     dst->pkt_pts                = src->pkt_pts;
299     dst->pkt_dts                = src->pkt_dts;
300     dst->pkt_pos                = src->pkt_pos;
301     dst->pkt_size               = src->pkt_size;
302     dst->pkt_duration           = src->pkt_duration;
303     dst->reordered_opaque       = src->reordered_opaque;
304     dst->quality                = src->quality;
305     dst->best_effort_timestamp  = src->best_effort_timestamp;
306     dst->coded_picture_number   = src->coded_picture_number;
307     dst->display_picture_number = src->display_picture_number;
308     dst->flags                  = src->flags;
309     dst->decode_error_flags     = src->decode_error_flags;
310     dst->color_primaries        = src->color_primaries;
311     dst->color_trc              = src->color_trc;
312     dst->colorspace             = src->colorspace;
313     dst->color_range            = src->color_range;
314     dst->chroma_location        = src->chroma_location;
315
316     av_dict_copy(&dst->metadata, src->metadata, 0);
317
318     memcpy(dst->error, src->error, sizeof(dst->error));
319
320     for (i = 0; i < src->nb_side_data; i++) {
321         const AVFrameSideData *sd_src = src->side_data[i];
322         AVFrameSideData *sd_dst;
323         if (   sd_src->type == AV_FRAME_DATA_PANSCAN
324             && (src->width != dst->width || src->height != dst->height))
325             continue;
326         if (force_copy) {
327             sd_dst = av_frame_new_side_data(dst, sd_src->type,
328                                             sd_src->size);
329             if (!sd_dst) {
330                 wipe_side_data(dst);
331                 return AVERROR(ENOMEM);
332             }
333             memcpy(sd_dst->data, sd_src->data, sd_src->size);
334         } else {
335             sd_dst = av_frame_new_side_data(dst, sd_src->type, 0);
336             if (!sd_dst) {
337                 wipe_side_data(dst);
338                 return AVERROR(ENOMEM);
339             }
340             sd_dst->buf = av_buffer_ref(sd_src->buf);
341             if (!sd_dst->buf) {
342                 wipe_side_data(dst);
343                 return AVERROR(ENOMEM);
344             }
345             sd_dst->data = sd_dst->buf->data;
346             sd_dst->size = sd_dst->buf->size;
347         }
348         av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
349     }
350
351 #if FF_API_FRAME_QP
352 FF_DISABLE_DEPRECATION_WARNINGS
353     dst->qscale_table = NULL;
354     dst->qstride      = 0;
355     dst->qscale_type  = 0;
356     if (src->qp_table_buf) {
357         dst->qp_table_buf = av_buffer_ref(src->qp_table_buf);
358         if (dst->qp_table_buf) {
359             dst->qscale_table = dst->qp_table_buf->data;
360             dst->qstride      = src->qstride;
361             dst->qscale_type  = src->qscale_type;
362         }
363     }
364 FF_ENABLE_DEPRECATION_WARNINGS
365 #endif
366
367     return 0;
368 }
369
370 int av_frame_ref(AVFrame *dst, const AVFrame *src)
371 {
372     int i, ret = 0;
373
374     dst->format         = src->format;
375     dst->width          = src->width;
376     dst->height         = src->height;
377     dst->channels       = src->channels;
378     dst->channel_layout = src->channel_layout;
379     dst->nb_samples     = src->nb_samples;
380
381     ret = frame_copy_props(dst, src, 0);
382     if (ret < 0)
383         return ret;
384
385     /* duplicate the frame data if it's not refcounted */
386     if (!src->buf[0]) {
387         ret = av_frame_get_buffer(dst, 32);
388         if (ret < 0)
389             return ret;
390
391         ret = av_frame_copy(dst, src);
392         if (ret < 0)
393             av_frame_unref(dst);
394
395         return ret;
396     }
397
398     /* ref the buffers */
399     for (i = 0; i < FF_ARRAY_ELEMS(src->buf); i++) {
400         if (!src->buf[i])
401             continue;
402         dst->buf[i] = av_buffer_ref(src->buf[i]);
403         if (!dst->buf[i]) {
404             ret = AVERROR(ENOMEM);
405             goto fail;
406         }
407     }
408
409     if (src->extended_buf) {
410         dst->extended_buf = av_mallocz_array(sizeof(*dst->extended_buf),
411                                        src->nb_extended_buf);
412         if (!dst->extended_buf) {
413             ret = AVERROR(ENOMEM);
414             goto fail;
415         }
416         dst->nb_extended_buf = src->nb_extended_buf;
417
418         for (i = 0; i < src->nb_extended_buf; i++) {
419             dst->extended_buf[i] = av_buffer_ref(src->extended_buf[i]);
420             if (!dst->extended_buf[i]) {
421                 ret = AVERROR(ENOMEM);
422                 goto fail;
423             }
424         }
425     }
426
427     /* duplicate extended data */
428     if (src->extended_data != src->data) {
429         int ch = src->channels;
430
431         if (!ch) {
432             ret = AVERROR(EINVAL);
433             goto fail;
434         }
435         CHECK_CHANNELS_CONSISTENCY(src);
436
437         dst->extended_data = av_malloc_array(sizeof(*dst->extended_data), ch);
438         if (!dst->extended_data) {
439             ret = AVERROR(ENOMEM);
440             goto fail;
441         }
442         memcpy(dst->extended_data, src->extended_data, sizeof(*src->extended_data) * ch);
443     } else
444         dst->extended_data = dst->data;
445
446     memcpy(dst->data,     src->data,     sizeof(src->data));
447     memcpy(dst->linesize, src->linesize, sizeof(src->linesize));
448
449     return 0;
450
451 fail:
452     av_frame_unref(dst);
453     return ret;
454 }
455
456 AVFrame *av_frame_clone(const AVFrame *src)
457 {
458     AVFrame *ret = av_frame_alloc();
459
460     if (!ret)
461         return NULL;
462
463     if (av_frame_ref(ret, src) < 0)
464         av_frame_free(&ret);
465
466     return ret;
467 }
468
469 void av_frame_unref(AVFrame *frame)
470 {
471     int i;
472
473     if (!frame)
474         return;
475
476     wipe_side_data(frame);
477
478     for (i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)
479         av_buffer_unref(&frame->buf[i]);
480     for (i = 0; i < frame->nb_extended_buf; i++)
481         av_buffer_unref(&frame->extended_buf[i]);
482     av_freep(&frame->extended_buf);
483     av_dict_free(&frame->metadata);
484 #if FF_API_FRAME_QP
485     av_buffer_unref(&frame->qp_table_buf);
486 #endif
487
488     get_frame_defaults(frame);
489 }
490
491 void av_frame_move_ref(AVFrame *dst, AVFrame *src)
492 {
493     *dst = *src;
494     if (src->extended_data == src->data)
495         dst->extended_data = dst->data;
496     memset(src, 0, sizeof(*src));
497     get_frame_defaults(src);
498 }
499
500 int av_frame_is_writable(AVFrame *frame)
501 {
502     int i, ret = 1;
503
504     /* assume non-refcounted frames are not writable */
505     if (!frame->buf[0])
506         return 0;
507
508     for (i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)
509         if (frame->buf[i])
510             ret &= !!av_buffer_is_writable(frame->buf[i]);
511     for (i = 0; i < frame->nb_extended_buf; i++)
512         ret &= !!av_buffer_is_writable(frame->extended_buf[i]);
513
514     return ret;
515 }
516
517 int av_frame_make_writable(AVFrame *frame)
518 {
519     AVFrame tmp;
520     int ret;
521
522     if (!frame->buf[0])
523         return AVERROR(EINVAL);
524
525     if (av_frame_is_writable(frame))
526         return 0;
527
528     memset(&tmp, 0, sizeof(tmp));
529     tmp.format         = frame->format;
530     tmp.width          = frame->width;
531     tmp.height         = frame->height;
532     tmp.channels       = frame->channels;
533     tmp.channel_layout = frame->channel_layout;
534     tmp.nb_samples     = frame->nb_samples;
535     ret = av_frame_get_buffer(&tmp, 32);
536     if (ret < 0)
537         return ret;
538
539     ret = av_frame_copy(&tmp, frame);
540     if (ret < 0) {
541         av_frame_unref(&tmp);
542         return ret;
543     }
544
545     ret = av_frame_copy_props(&tmp, frame);
546     if (ret < 0) {
547         av_frame_unref(&tmp);
548         return ret;
549     }
550
551     av_frame_unref(frame);
552
553     *frame = tmp;
554     if (tmp.data == tmp.extended_data)
555         frame->extended_data = frame->data;
556
557     return 0;
558 }
559
560 int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
561 {
562     return frame_copy_props(dst, src, 1);
563 }
564
565 AVBufferRef *av_frame_get_plane_buffer(AVFrame *frame, int plane)
566 {
567     uint8_t *data;
568     int planes, i;
569
570     if (frame->nb_samples) {
571         int channels = frame->channels;
572         if (!channels)
573             return NULL;
574         CHECK_CHANNELS_CONSISTENCY(frame);
575         planes = av_sample_fmt_is_planar(frame->format) ? channels : 1;
576     } else
577         planes = 4;
578
579     if (plane < 0 || plane >= planes || !frame->extended_data[plane])
580         return NULL;
581     data = frame->extended_data[plane];
582
583     for (i = 0; i < FF_ARRAY_ELEMS(frame->buf) && frame->buf[i]; i++) {
584         AVBufferRef *buf = frame->buf[i];
585         if (data >= buf->data && data < buf->data + buf->size)
586             return buf;
587     }
588     for (i = 0; i < frame->nb_extended_buf; i++) {
589         AVBufferRef *buf = frame->extended_buf[i];
590         if (data >= buf->data && data < buf->data + buf->size)
591             return buf;
592     }
593     return NULL;
594 }
595
596 AVFrameSideData *av_frame_new_side_data(AVFrame *frame,
597                                         enum AVFrameSideDataType type,
598                                         int size)
599 {
600     AVFrameSideData *ret, **tmp;
601
602     if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
603         return NULL;
604
605     tmp = av_realloc(frame->side_data,
606                      (frame->nb_side_data + 1) * sizeof(*frame->side_data));
607     if (!tmp)
608         return NULL;
609     frame->side_data = tmp;
610
611     ret = av_mallocz(sizeof(*ret));
612     if (!ret)
613         return NULL;
614
615     if (size > 0) {
616         ret->buf = av_buffer_alloc(size);
617         if (!ret->buf) {
618             av_freep(&ret);
619             return NULL;
620         }
621
622         ret->data = ret->buf->data;
623         ret->size = size;
624     }
625     ret->type = type;
626
627     frame->side_data[frame->nb_side_data++] = ret;
628
629     return ret;
630 }
631
632 AVFrameSideData *av_frame_get_side_data(const AVFrame *frame,
633                                         enum AVFrameSideDataType type)
634 {
635     int i;
636
637     for (i = 0; i < frame->nb_side_data; i++) {
638         if (frame->side_data[i]->type == type)
639             return frame->side_data[i];
640     }
641     return NULL;
642 }
643
644 static int frame_copy_video(AVFrame *dst, const AVFrame *src)
645 {
646     const uint8_t *src_data[4];
647     int i, planes;
648
649     if (dst->width  < src->width ||
650         dst->height < src->height)
651         return AVERROR(EINVAL);
652
653     planes = av_pix_fmt_count_planes(dst->format);
654     for (i = 0; i < planes; i++)
655         if (!dst->data[i] || !src->data[i])
656             return AVERROR(EINVAL);
657
658     memcpy(src_data, src->data, sizeof(src_data));
659     av_image_copy(dst->data, dst->linesize,
660                   src_data, src->linesize,
661                   dst->format, src->width, src->height);
662
663     return 0;
664 }
665
666 static int frame_copy_audio(AVFrame *dst, const AVFrame *src)
667 {
668     int planar   = av_sample_fmt_is_planar(dst->format);
669     int channels = dst->channels;
670     int planes   = planar ? channels : 1;
671     int i;
672
673     if (dst->nb_samples     != src->nb_samples ||
674         dst->channels       != src->channels ||
675         dst->channel_layout != src->channel_layout)
676         return AVERROR(EINVAL);
677
678     CHECK_CHANNELS_CONSISTENCY(src);
679
680     for (i = 0; i < planes; i++)
681         if (!dst->extended_data[i] || !src->extended_data[i])
682             return AVERROR(EINVAL);
683
684     av_samples_copy(dst->extended_data, src->extended_data, 0, 0,
685                     dst->nb_samples, channels, dst->format);
686
687     return 0;
688 }
689
690 int av_frame_copy(AVFrame *dst, const AVFrame *src)
691 {
692     if (dst->format != src->format || dst->format < 0)
693         return AVERROR(EINVAL);
694
695     if (dst->width > 0 && dst->height > 0)
696         return frame_copy_video(dst, src);
697     else if (dst->nb_samples > 0 && dst->channel_layout)
698         return frame_copy_audio(dst, src);
699
700     return AVERROR(EINVAL);
701 }
702
703 void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
704 {
705     int i;
706
707     for (i = 0; i < frame->nb_side_data; i++) {
708         AVFrameSideData *sd = frame->side_data[i];
709         if (sd->type == type) {
710             free_side_data(&frame->side_data[i]);
711             frame->side_data[i] = frame->side_data[frame->nb_side_data - 1];
712             frame->nb_side_data--;
713         }
714     }
715 }
716
717 const char *av_frame_side_data_name(enum AVFrameSideDataType type)
718 {
719     switch(type) {
720     case AV_FRAME_DATA_PANSCAN:         return "AVPanScan";
721     case AV_FRAME_DATA_A53_CC:          return "ATSC A53 Part 4 Closed Captions";
722     case AV_FRAME_DATA_STEREO3D:        return "Stereoscopic 3d metadata";
723     case AV_FRAME_DATA_MATRIXENCODING:  return "AVMatrixEncoding";
724     case AV_FRAME_DATA_DOWNMIX_INFO:    return "Metadata relevant to a downmix procedure";
725     case AV_FRAME_DATA_REPLAYGAIN:      return "AVReplayGain";
726     case AV_FRAME_DATA_DISPLAYMATRIX:   return "3x3 displaymatrix";
727     case AV_FRAME_DATA_MOTION_VECTORS:  return "Motion vectors";
728     }
729     return NULL;
730 }