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 "asrc_abuffer.h"
34 #include "libavutil/avstring.h"
35 #include "libavutil/channel_layout.h"
36 #include "libavutil/fifo.h"
37 #include "libavutil/imgutils.h"
41 AVRational time_base; ///< time_base to set in the output link
43 unsigned nb_failed_requests;
46 AVFilterContext *scale;
48 enum AVPixelFormat pix_fmt;
49 AVRational sample_aspect_ratio;
53 // Audio format of incoming buffers
55 unsigned int sample_format;
56 int64_t channel_layout;
58 // Normalization filters
59 AVFilterContext *aconvert;
60 AVFilterContext *aresample;
61 } BufferSourceContext;
63 static void buf_free(AVFilterBuffer *ptr)
69 int av_asrc_buffer_add_audio_buffer_ref(AVFilterContext *ctx,
70 AVFilterBufferRef *samplesref,
73 return av_buffersrc_add_ref(ctx, samplesref, AV_BUFFERSRC_FLAG_NO_COPY);
76 int av_asrc_buffer_add_samples(AVFilterContext *ctx,
77 uint8_t *data[8], int linesize[8],
78 int nb_samples, int sample_rate,
79 int sample_fmt, int64_t channel_layout, int planar,
80 int64_t pts, int av_unused flags)
82 AVFilterBufferRef *samplesref;
85 return AVERROR(EINVAL);
86 samplesref = avfilter_get_audio_buffer_ref_from_arrays(
87 data, linesize[0], AV_PERM_WRITE,
89 sample_fmt, channel_layout);
91 return AVERROR(ENOMEM);
93 samplesref->buf->free = buf_free;
94 samplesref->pts = pts;
95 samplesref->audio->sample_rate = sample_rate;
98 return av_asrc_buffer_add_audio_buffer_ref(ctx, samplesref, 0);
102 int av_asrc_buffer_add_buffer(AVFilterContext *ctx,
103 uint8_t *buf, int buf_size, int sample_rate,
104 int sample_fmt, int64_t channel_layout, int planar,
105 int64_t pts, int av_unused flags)
107 uint8_t *data[8] = {0};
109 int nb_channels = av_get_channel_layout_nb_channels(channel_layout),
110 nb_samples = buf_size / nb_channels / av_get_bytes_per_sample(sample_fmt);
112 av_samples_fill_arrays(data, linesize,
113 buf, nb_channels, nb_samples,
116 AV_NOWARN_DEPRECATED(
117 return av_asrc_buffer_add_samples(ctx,
118 data, linesize, nb_samples,
120 sample_fmt, channel_layout, planar,