2 * Copyright (c) 2008 Vitor Sessak
3 * Copyright (c) 2010 S.N. Hemanth Meenakshisundaram
4 * Copyright (c) 2011 Mina Nagy Zaki
6 * This file is part of FFmpeg.
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 * memory buffer source filter
32 #include "buffersrc.h"
33 #include "vsrc_buffer.h"
34 #include "asrc_abuffer.h"
35 #include "libavutil/audioconvert.h"
36 #include "libavutil/avstring.h"
37 #include "libavutil/fifo.h"
38 #include "libavutil/imgutils.h"
42 AVRational time_base; ///< time_base to set in the output link
44 unsigned nb_failed_requests;
47 AVFilterContext *scale;
49 enum PixelFormat pix_fmt;
50 AVRational sample_aspect_ratio;
54 // Audio format of incoming buffers
56 unsigned int sample_format;
57 int64_t channel_layout;
59 // Normalization filters
60 AVFilterContext *aconvert;
61 AVFilterContext *aresample;
62 } BufferSourceContext;
64 static void buf_free(AVFilterBuffer *ptr)
70 int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter,
71 AVFilterBufferRef *picref, int flags)
73 return av_buffersrc_add_ref(buffer_filter, picref, 0);
79 int av_vsrc_buffer_add_frame(AVFilterContext *buffer_src,
80 const AVFrame *frame, int flags)
82 return av_buffersrc_add_frame(buffer_src, frame, 0);
86 unsigned av_vsrc_buffer_get_nb_failed_requests(AVFilterContext *buffer_src)
88 return ((BufferSourceContext *)buffer_src->priv)->nb_failed_requests;
91 int av_asrc_buffer_add_audio_buffer_ref(AVFilterContext *ctx,
92 AVFilterBufferRef *samplesref,
95 return av_buffersrc_add_ref(ctx, samplesref, AV_BUFFERSRC_FLAG_NO_COPY);
98 int av_asrc_buffer_add_samples(AVFilterContext *ctx,
99 uint8_t *data[8], int linesize[8],
100 int nb_samples, int sample_rate,
101 int sample_fmt, int64_t channel_layout, int planar,
102 int64_t pts, int av_unused flags)
104 AVFilterBufferRef *samplesref;
106 samplesref = avfilter_get_audio_buffer_ref_from_arrays(
107 data, linesize[0], AV_PERM_WRITE,
109 sample_fmt, channel_layout);
111 return AVERROR(ENOMEM);
113 samplesref->buf->free = buf_free;
114 samplesref->pts = pts;
115 samplesref->audio->sample_rate = sample_rate;
117 AV_NOWARN_DEPRECATED(
118 return av_asrc_buffer_add_audio_buffer_ref(ctx, samplesref, 0);
122 int av_asrc_buffer_add_buffer(AVFilterContext *ctx,
123 uint8_t *buf, int buf_size, int sample_rate,
124 int sample_fmt, int64_t channel_layout, int planar,
125 int64_t pts, int av_unused flags)
127 uint8_t *data[8] = {0};
129 int nb_channels = av_get_channel_layout_nb_channels(channel_layout),
130 nb_samples = buf_size / nb_channels / av_get_bytes_per_sample(sample_fmt);
132 av_samples_fill_arrays(data, linesize,
133 buf, nb_channels, nb_samples,
136 AV_NOWARN_DEPRECATED(
137 return av_asrc_buffer_add_samples(ctx,
138 data, linesize, nb_samples,
140 sample_fmt, channel_layout, planar,