3 * Copyright (c) 2007 Bobby Bingham
5 * This file is part of Libav.
7 * Libav is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * Libav is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with Libav; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "libavutil/pixdesc.h"
25 #include "libavutil/rational.h"
26 #include "libavutil/audioconvert.h"
27 #include "libavutil/imgutils.h"
28 #include "libavcodec/avcodec.h"
32 unsigned avfilter_version(void) {
33 return LIBAVFILTER_VERSION_INT;
36 const char *avfilter_configuration(void)
38 return LIBAV_CONFIGURATION;
41 const char *avfilter_license(void)
43 #define LICENSE_PREFIX "libavfilter license: "
44 return LICENSE_PREFIX LIBAV_LICENSE + sizeof(LICENSE_PREFIX) - 1;
47 AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask)
49 AVFilterBufferRef *ret = av_malloc(sizeof(AVFilterBufferRef));
53 if (ref->type == AVMEDIA_TYPE_VIDEO) {
54 ret->video = av_malloc(sizeof(AVFilterBufferRefVideoProps));
59 *ret->video = *ref->video;
60 ret->extended_data = ret->data;
61 } else if (ref->type == AVMEDIA_TYPE_AUDIO) {
62 ret->audio = av_malloc(sizeof(AVFilterBufferRefAudioProps));
67 *ret->audio = *ref->audio;
69 if (ref->extended_data != ref->data) {
70 int nb_channels = av_get_channel_layout_nb_channels(ref->audio->channel_layout);
71 if (!(ret->extended_data = av_malloc(sizeof(*ret->extended_data) *
73 av_freep(&ret->audio);
77 memcpy(ret->extended_data, ref->extended_data,
78 sizeof(*ret->extended_data) * nb_channels);
80 ret->extended_data = ret->data;
83 ret->buf->refcount ++;
87 void avfilter_unref_buffer(AVFilterBufferRef *ref)
91 if (!(--ref->buf->refcount))
92 ref->buf->free(ref->buf);
93 if (ref->extended_data != ref->data)
94 av_freep(&ref->extended_data);
100 void avfilter_insert_pad(unsigned idx, unsigned *count, size_t padidx_off,
101 AVFilterPad **pads, AVFilterLink ***links,
106 idx = FFMIN(idx, *count);
108 *pads = av_realloc(*pads, sizeof(AVFilterPad) * (*count + 1));
109 *links = av_realloc(*links, sizeof(AVFilterLink*) * (*count + 1));
110 memmove(*pads +idx+1, *pads +idx, sizeof(AVFilterPad) * (*count-idx));
111 memmove(*links+idx+1, *links+idx, sizeof(AVFilterLink*) * (*count-idx));
112 memcpy(*pads+idx, newpad, sizeof(AVFilterPad));
113 (*links)[idx] = NULL;
116 for (i = idx+1; i < *count; i++)
118 (*(unsigned *)((uint8_t *) *links[i] + padidx_off))++;
121 int avfilter_link(AVFilterContext *src, unsigned srcpad,
122 AVFilterContext *dst, unsigned dstpad)
126 if (src->output_count <= srcpad || dst->input_count <= dstpad ||
127 src->outputs[srcpad] || dst->inputs[dstpad])
130 if (src->output_pads[srcpad].type != dst->input_pads[dstpad].type) {
131 av_log(src, AV_LOG_ERROR,
132 "Media type mismatch between the '%s' filter output pad %d and the '%s' filter input pad %d\n",
133 src->name, srcpad, dst->name, dstpad);
134 return AVERROR(EINVAL);
137 src->outputs[srcpad] =
138 dst-> inputs[dstpad] = link = av_mallocz(sizeof(AVFilterLink));
142 link->srcpad = &src->output_pads[srcpad];
143 link->dstpad = &dst->input_pads[dstpad];
144 link->type = src->output_pads[srcpad].type;
145 assert(PIX_FMT_NONE == -1 && AV_SAMPLE_FMT_NONE == -1);
151 int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt,
152 unsigned filt_srcpad_idx, unsigned filt_dstpad_idx)
155 unsigned dstpad_idx = link->dstpad - link->dst->input_pads;
157 av_log(link->dst, AV_LOG_INFO, "auto-inserting filter '%s' "
158 "between the filter '%s' and the filter '%s'\n",
159 filt->name, link->src->name, link->dst->name);
161 link->dst->inputs[dstpad_idx] = NULL;
162 if ((ret = avfilter_link(filt, filt_dstpad_idx, link->dst, dstpad_idx)) < 0) {
163 /* failed to link output filter to new filter */
164 link->dst->inputs[dstpad_idx] = link;
168 /* re-hookup the link to the new destination filter we inserted */
170 link->dstpad = &filt->input_pads[filt_srcpad_idx];
171 filt->inputs[filt_srcpad_idx] = link;
173 /* if any information on supported media formats already exists on the
174 * link, we need to preserve that */
175 if (link->out_formats)
176 avfilter_formats_changeref(&link->out_formats,
177 &filt->outputs[filt_dstpad_idx]->out_formats);
182 int avfilter_config_links(AVFilterContext *filter)
184 int (*config_link)(AVFilterLink *);
188 for (i = 0; i < filter->input_count; i ++) {
189 AVFilterLink *link = filter->inputs[i];
193 switch (link->init_state) {
196 case AVLINK_STARTINIT:
197 av_log(filter, AV_LOG_INFO, "circular filter chain detected\n");
200 link->init_state = AVLINK_STARTINIT;
202 if ((ret = avfilter_config_links(link->src)) < 0)
205 if (!(config_link = link->srcpad->config_props))
206 config_link = avfilter_default_config_output_link;
207 if ((ret = config_link(link)) < 0)
210 if (link->time_base.num == 0 && link->time_base.den == 0)
211 link->time_base = link->src && link->src->input_count ?
212 link->src->inputs[0]->time_base : AV_TIME_BASE_Q;
214 if (link->sample_aspect_ratio.num == 0 && link->sample_aspect_ratio.den == 0)
215 link->sample_aspect_ratio = link->src->input_count ?
216 link->src->inputs[0]->sample_aspect_ratio : (AVRational){1,1};
218 if (link->sample_rate == 0 && link->src && link->src->input_count)
219 link->sample_rate = link->src->inputs[0]->sample_rate;
221 if (link->channel_layout == 0 && link->src && link->src->input_count)
222 link->channel_layout = link->src->inputs[0]->channel_layout;
224 if ((config_link = link->dstpad->config_props))
225 if ((ret = config_link(link)) < 0)
228 link->init_state = AVLINK_INIT;
236 static char *ff_get_ref_perms_string(char *buf, size_t buf_size, int perms)
238 snprintf(buf, buf_size, "%s%s%s%s%s%s",
239 perms & AV_PERM_READ ? "r" : "",
240 perms & AV_PERM_WRITE ? "w" : "",
241 perms & AV_PERM_PRESERVE ? "p" : "",
242 perms & AV_PERM_REUSE ? "u" : "",
243 perms & AV_PERM_REUSE2 ? "U" : "",
244 perms & AV_PERM_NEG_LINESIZES ? "n" : "");
249 static void ff_dlog_ref(void *ctx, AVFilterBufferRef *ref, int end)
251 av_unused char buf[16];
253 "ref[%p buf:%p refcount:%d perms:%s data:%p linesize[%d, %d, %d, %d] pts:%"PRId64" pos:%"PRId64,
254 ref, ref->buf, ref->buf->refcount, ff_get_ref_perms_string(buf, sizeof(buf), ref->perms), ref->data[0],
255 ref->linesize[0], ref->linesize[1], ref->linesize[2], ref->linesize[3],
259 av_dlog(ctx, " a:%d/%d s:%dx%d i:%c iskey:%d type:%c",
260 ref->video->pixel_aspect.num, ref->video->pixel_aspect.den,
261 ref->video->w, ref->video->h,
262 !ref->video->interlaced ? 'P' : /* Progressive */
263 ref->video->top_field_first ? 'T' : 'B', /* Top / Bottom */
264 ref->video->key_frame,
265 av_get_picture_type_char(ref->video->pict_type));
268 av_dlog(ctx, " cl:%"PRId64"d n:%d r:%d p:%d",
269 ref->audio->channel_layout,
270 ref->audio->nb_samples,
271 ref->audio->sample_rate,
275 av_dlog(ctx, "]%s", end ? "\n" : "");
278 static void ff_dlog_link(void *ctx, AVFilterLink *link, int end)
280 if (link->type == AVMEDIA_TYPE_VIDEO) {
282 "link[%p s:%dx%d fmt:%-16s %-16s->%-16s]%s",
283 link, link->w, link->h,
284 av_pix_fmt_descriptors[link->format].name,
285 link->src ? link->src->filter->name : "",
286 link->dst ? link->dst->filter->name : "",
290 av_get_channel_layout_string(buf, sizeof(buf), -1, link->channel_layout);
293 "link[%p r:%"PRId64" cl:%s fmt:%-16s %-16s->%-16s]%s",
294 link, link->sample_rate, buf,
295 av_get_sample_fmt_name(link->format),
296 link->src ? link->src->filter->name : "",
297 link->dst ? link->dst->filter->name : "",
302 #define FF_DPRINTF_START(ctx, func) av_dlog(NULL, "%-16s: ", #func)
304 AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, int w, int h)
306 AVFilterBufferRef *ret = NULL;
308 av_unused char buf[16];
309 FF_DPRINTF_START(NULL, get_video_buffer); ff_dlog_link(NULL, link, 0);
310 av_dlog(NULL, " perms:%s w:%d h:%d\n", ff_get_ref_perms_string(buf, sizeof(buf), perms), w, h);
312 if (link->dstpad->get_video_buffer)
313 ret = link->dstpad->get_video_buffer(link, perms, w, h);
316 ret = avfilter_default_get_video_buffer(link, perms, w, h);
319 ret->type = AVMEDIA_TYPE_VIDEO;
321 FF_DPRINTF_START(NULL, get_video_buffer); ff_dlog_link(NULL, link, 0); av_dlog(NULL, " returning "); ff_dlog_ref(NULL, ret, 1);
327 avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms,
328 int w, int h, enum PixelFormat format)
330 AVFilterBuffer *pic = av_mallocz(sizeof(AVFilterBuffer));
331 AVFilterBufferRef *picref = av_mallocz(sizeof(AVFilterBufferRef));
337 picref->buf->free = ff_avfilter_default_free_buffer;
338 if (!(picref->video = av_mallocz(sizeof(AVFilterBufferRefVideoProps))))
341 pic->w = picref->video->w = w;
342 pic->h = picref->video->h = h;
344 /* make sure the buffer gets read permission or it's useless for output */
345 picref->perms = perms | AV_PERM_READ;
348 picref->type = AVMEDIA_TYPE_VIDEO;
349 pic->format = picref->format = format;
351 memcpy(pic->data, data, 4*sizeof(data[0]));
352 memcpy(pic->linesize, linesize, 4*sizeof(linesize[0]));
353 memcpy(picref->data, pic->data, sizeof(picref->data));
354 memcpy(picref->linesize, pic->linesize, sizeof(picref->linesize));
356 pic-> extended_data = pic->data;
357 picref->extended_data = picref->data;
362 if (picref && picref->video)
363 av_free(picref->video);
369 AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms,
372 AVFilterBufferRef *ret = NULL;
374 if (link->dstpad->get_audio_buffer)
375 ret = link->dstpad->get_audio_buffer(link, perms, nb_samples);
378 ret = avfilter_default_get_audio_buffer(link, perms, nb_samples);
381 ret->type = AVMEDIA_TYPE_AUDIO;
386 AVFilterBufferRef *avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data,
387 int linesize, int perms,
389 enum AVSampleFormat sample_fmt,
390 uint64_t channel_layout)
393 AVFilterBuffer *samples = av_mallocz(sizeof(*samples));
394 AVFilterBufferRef *samplesref = av_mallocz(sizeof(*samplesref));
396 if (!samples || !samplesref)
399 samplesref->buf = samples;
400 samplesref->buf->free = ff_avfilter_default_free_buffer;
401 if (!(samplesref->audio = av_mallocz(sizeof(*samplesref->audio))))
404 samplesref->audio->nb_samples = nb_samples;
405 samplesref->audio->channel_layout = channel_layout;
406 samplesref->audio->planar = av_sample_fmt_is_planar(sample_fmt);
408 planes = samplesref->audio->planar ? av_get_channel_layout_nb_channels(channel_layout) : 1;
410 /* make sure the buffer gets read permission or it's useless for output */
411 samplesref->perms = perms | AV_PERM_READ;
413 samples->refcount = 1;
414 samplesref->type = AVMEDIA_TYPE_AUDIO;
415 samplesref->format = sample_fmt;
417 memcpy(samples->data, data,
418 FFMIN(FF_ARRAY_ELEMS(samples->data), planes)*sizeof(samples->data[0]));
419 memcpy(samplesref->data, samples->data, sizeof(samples->data));
421 samples->linesize[0] = samplesref->linesize[0] = linesize;
423 if (planes > FF_ARRAY_ELEMS(samples->data)) {
424 samples-> extended_data = av_mallocz(sizeof(*samples->extended_data) *
426 samplesref->extended_data = av_mallocz(sizeof(*samplesref->extended_data) *
429 if (!samples->extended_data || !samplesref->extended_data)
432 memcpy(samples-> extended_data, data, sizeof(*data)*planes);
433 memcpy(samplesref->extended_data, data, sizeof(*data)*planes);
435 samples->extended_data = samples->data;
436 samplesref->extended_data = samplesref->data;
442 if (samples && samples->extended_data != samples->data)
443 av_freep(&samples->extended_data);
445 av_freep(&samplesref->audio);
446 if (samplesref->extended_data != samplesref->data)
447 av_freep(&samplesref->extended_data);
449 av_freep(&samplesref);
454 int avfilter_request_frame(AVFilterLink *link)
456 FF_DPRINTF_START(NULL, request_frame); ff_dlog_link(NULL, link, 1);
458 if (link->srcpad->request_frame)
459 return link->srcpad->request_frame(link);
460 else if (link->src->inputs[0])
461 return avfilter_request_frame(link->src->inputs[0]);
465 int avfilter_poll_frame(AVFilterLink *link)
467 int i, min = INT_MAX;
469 if (link->srcpad->poll_frame)
470 return link->srcpad->poll_frame(link);
472 for (i = 0; i < link->src->input_count; i++) {
474 if (!link->src->inputs[i])
476 val = avfilter_poll_frame(link->src->inputs[i]);
477 min = FFMIN(min, val);
483 /* XXX: should we do the duplicating of the picture ref here, instead of
484 * forcing the source filter to do it? */
485 void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref)
487 void (*start_frame)(AVFilterLink *, AVFilterBufferRef *);
488 AVFilterPad *dst = link->dstpad;
489 int perms = picref->perms;
491 FF_DPRINTF_START(NULL, start_frame); ff_dlog_link(NULL, link, 0); av_dlog(NULL, " "); ff_dlog_ref(NULL, picref, 1);
493 if (!(start_frame = dst->start_frame))
494 start_frame = avfilter_default_start_frame;
496 if (picref->linesize[0] < 0)
497 perms |= AV_PERM_NEG_LINESIZES;
498 /* prepare to copy the picture if it has insufficient permissions */
499 if ((dst->min_perms & perms) != dst->min_perms || dst->rej_perms & perms) {
500 av_log(link->dst, AV_LOG_DEBUG,
501 "frame copy needed (have perms %x, need %x, reject %x)\n",
503 link->dstpad->min_perms, link->dstpad->rej_perms);
505 link->cur_buf = avfilter_get_video_buffer(link, dst->min_perms, link->w, link->h);
506 link->src_buf = picref;
507 avfilter_copy_buffer_ref_props(link->cur_buf, link->src_buf);
510 link->cur_buf = picref;
512 start_frame(link, link->cur_buf);
515 void avfilter_end_frame(AVFilterLink *link)
517 void (*end_frame)(AVFilterLink *);
519 if (!(end_frame = link->dstpad->end_frame))
520 end_frame = avfilter_default_end_frame;
524 /* unreference the source picture if we're feeding the destination filter
525 * a copied version dues to permission issues */
527 avfilter_unref_buffer(link->src_buf);
528 link->src_buf = NULL;
532 void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir)
534 uint8_t *src[4], *dst[4];
536 void (*draw_slice)(AVFilterLink *, int, int, int);
538 FF_DPRINTF_START(NULL, draw_slice); ff_dlog_link(NULL, link, 0); av_dlog(NULL, " y:%d h:%d dir:%d\n", y, h, slice_dir);
540 /* copy the slice if needed for permission reasons */
542 vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h;
544 for (i = 0; i < 4; i++) {
545 if (link->src_buf->data[i]) {
546 src[i] = link->src_buf-> data[i] +
547 (y >> (i==1 || i==2 ? vsub : 0)) * link->src_buf-> linesize[i];
548 dst[i] = link->cur_buf->data[i] +
549 (y >> (i==1 || i==2 ? vsub : 0)) * link->cur_buf->linesize[i];
551 src[i] = dst[i] = NULL;
554 for (i = 0; i < 4; i++) {
556 av_image_get_linesize(link->format, link->cur_buf->video->w, i);
558 if (!src[i]) continue;
560 for (j = 0; j < h >> (i==1 || i==2 ? vsub : 0); j++) {
561 memcpy(dst[i], src[i], planew);
562 src[i] += link->src_buf->linesize[i];
563 dst[i] += link->cur_buf->linesize[i];
568 if (!(draw_slice = link->dstpad->draw_slice))
569 draw_slice = avfilter_default_draw_slice;
570 draw_slice(link, y, h, slice_dir);
573 void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
575 void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *);
576 AVFilterPad *dst = link->dstpad;
578 FF_DPRINTF_START(NULL, filter_samples); ff_dlog_link(NULL, link, 1);
580 if (!(filter_samples = dst->filter_samples))
581 filter_samples = avfilter_default_filter_samples;
583 /* prepare to copy the samples if the buffer has insufficient permissions */
584 if ((dst->min_perms & samplesref->perms) != dst->min_perms ||
585 dst->rej_perms & samplesref->perms) {
586 int i, planar = av_sample_fmt_is_planar(samplesref->format);
587 int planes = !planar ? 1:
588 av_get_channel_layout_nb_channels(samplesref->audio->channel_layout);
590 av_log(link->dst, AV_LOG_DEBUG,
591 "Copying audio data in avfilter (have perms %x, need %x, reject %x)\n",
592 samplesref->perms, link->dstpad->min_perms, link->dstpad->rej_perms);
594 link->cur_buf = avfilter_default_get_audio_buffer(link, dst->min_perms,
595 samplesref->audio->nb_samples);
596 link->cur_buf->pts = samplesref->pts;
597 link->cur_buf->audio->sample_rate = samplesref->audio->sample_rate;
599 /* Copy actual data into new samples buffer */
600 for (i = 0; i < planes; i++)
601 memcpy(link->cur_buf->extended_data[i], samplesref->extended_data[i], samplesref->linesize[0]);
603 avfilter_unref_buffer(samplesref);
605 link->cur_buf = samplesref;
607 filter_samples(link, link->cur_buf);
610 #define MAX_REGISTERED_AVFILTERS_NB 64
612 static AVFilter *registered_avfilters[MAX_REGISTERED_AVFILTERS_NB + 1];
614 static int next_registered_avfilter_idx = 0;
616 AVFilter *avfilter_get_by_name(const char *name)
620 for (i = 0; registered_avfilters[i]; i++)
621 if (!strcmp(registered_avfilters[i]->name, name))
622 return registered_avfilters[i];
627 int avfilter_register(AVFilter *filter)
629 if (next_registered_avfilter_idx == MAX_REGISTERED_AVFILTERS_NB)
632 registered_avfilters[next_registered_avfilter_idx++] = filter;
636 AVFilter **av_filter_next(AVFilter **filter)
638 return filter ? ++filter : ®istered_avfilters[0];
641 void avfilter_uninit(void)
643 memset(registered_avfilters, 0, sizeof(registered_avfilters));
644 next_registered_avfilter_idx = 0;
647 static int pad_count(const AVFilterPad *pads)
651 for(count = 0; pads->name; count ++) pads ++;
655 static const char *filter_name(void *p)
657 AVFilterContext *filter = p;
658 return filter->filter->name;
661 static const AVClass avfilter_class = {
665 LIBAVUTIL_VERSION_INT,
668 int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name)
670 AVFilterContext *ret;
674 return AVERROR(EINVAL);
676 ret = av_mallocz(sizeof(AVFilterContext));
678 return AVERROR(ENOMEM);
680 ret->av_class = &avfilter_class;
681 ret->filter = filter;
682 ret->name = inst_name ? av_strdup(inst_name) : NULL;
683 if (filter->priv_size) {
684 ret->priv = av_mallocz(filter->priv_size);
689 ret->input_count = pad_count(filter->inputs);
690 if (ret->input_count) {
691 ret->input_pads = av_malloc(sizeof(AVFilterPad) * ret->input_count);
692 if (!ret->input_pads)
694 memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad) * ret->input_count);
695 ret->inputs = av_mallocz(sizeof(AVFilterLink*) * ret->input_count);
700 ret->output_count = pad_count(filter->outputs);
701 if (ret->output_count) {
702 ret->output_pads = av_malloc(sizeof(AVFilterPad) * ret->output_count);
703 if (!ret->output_pads)
705 memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad) * ret->output_count);
706 ret->outputs = av_mallocz(sizeof(AVFilterLink*) * ret->output_count);
715 av_freep(&ret->inputs);
716 av_freep(&ret->input_pads);
717 ret->input_count = 0;
718 av_freep(&ret->outputs);
719 av_freep(&ret->output_pads);
720 ret->output_count = 0;
721 av_freep(&ret->priv);
723 return AVERROR(ENOMEM);
726 void avfilter_free(AVFilterContext *filter)
731 if (filter->filter->uninit)
732 filter->filter->uninit(filter);
734 for (i = 0; i < filter->input_count; i++) {
735 if ((link = filter->inputs[i])) {
737 link->src->outputs[link->srcpad - link->src->output_pads] = NULL;
738 avfilter_formats_unref(&link->in_formats);
739 avfilter_formats_unref(&link->out_formats);
743 for (i = 0; i < filter->output_count; i++) {
744 if ((link = filter->outputs[i])) {
746 link->dst->inputs[link->dstpad - link->dst->input_pads] = NULL;
747 avfilter_formats_unref(&link->in_formats);
748 avfilter_formats_unref(&link->out_formats);
753 av_freep(&filter->name);
754 av_freep(&filter->input_pads);
755 av_freep(&filter->output_pads);
756 av_freep(&filter->inputs);
757 av_freep(&filter->outputs);
758 av_freep(&filter->priv);
762 int avfilter_init_filter(AVFilterContext *filter, const char *args, void *opaque)
766 if (filter->filter->init)
767 ret = filter->filter->init(filter, args, opaque);
771 int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src)
774 dst->format = src->format;
777 case AVMEDIA_TYPE_VIDEO:
778 dst->video->w = src->width;
779 dst->video->h = src->height;
780 dst->video->pixel_aspect = src->sample_aspect_ratio;
781 dst->video->interlaced = src->interlaced_frame;
782 dst->video->top_field_first = src->top_field_first;
783 dst->video->key_frame = src->key_frame;
784 dst->video->pict_type = src->pict_type;
786 case AVMEDIA_TYPE_AUDIO:
787 dst->audio->sample_rate = src->sample_rate;
788 dst->audio->channel_layout = src->channel_layout;
791 return AVERROR(EINVAL);
797 int avfilter_copy_buf_props(AVFrame *dst, const AVFilterBufferRef *src)
799 int planes, nb_channels;
801 memcpy(dst->data, src->data, sizeof(dst->data));
802 memcpy(dst->linesize, src->linesize, sizeof(dst->linesize));
805 dst->format = src->format;
808 case AVMEDIA_TYPE_VIDEO:
809 dst->width = src->video->w;
810 dst->height = src->video->h;
811 dst->sample_aspect_ratio = src->video->pixel_aspect;
812 dst->interlaced_frame = src->video->interlaced;
813 dst->top_field_first = src->video->top_field_first;
814 dst->key_frame = src->video->key_frame;
815 dst->pict_type = src->video->pict_type;
817 case AVMEDIA_TYPE_AUDIO:
818 nb_channels = av_get_channel_layout_nb_channels(src->audio->channel_layout);
819 planes = av_sample_fmt_is_planar(src->format) ? nb_channels : 1;
821 if (planes > FF_ARRAY_ELEMS(dst->data)) {
822 dst->extended_data = av_mallocz(planes * sizeof(*dst->extended_data));
823 if (!dst->extended_data)
824 return AVERROR(ENOMEM);
825 memcpy(dst->extended_data, src->extended_data,
826 planes * sizeof(dst->extended_data));
828 dst->extended_data = dst->data;
830 dst->sample_rate = src->audio->sample_rate;
831 dst->channel_layout = src->audio->channel_layout;
832 dst->nb_samples = src->audio->nb_samples;
835 return AVERROR(EINVAL);
841 void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilterBufferRef *src)
843 // copy common properties
848 case AVMEDIA_TYPE_VIDEO: *dst->video = *src->video; break;
849 case AVMEDIA_TYPE_AUDIO: *dst->audio = *src->audio; break;