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;
84 samplesref = avfilter_get_audio_buffer_ref_from_arrays(
85 data, linesize[0], AV_PERM_WRITE,
87 sample_fmt, channel_layout);
89 return AVERROR(ENOMEM);
91 samplesref->buf->free = buf_free;
92 samplesref->pts = pts;
93 samplesref->audio->sample_rate = sample_rate;
96 return av_asrc_buffer_add_audio_buffer_ref(ctx, samplesref, 0);
100 int av_asrc_buffer_add_buffer(AVFilterContext *ctx,
101 uint8_t *buf, int buf_size, int sample_rate,
102 int sample_fmt, int64_t channel_layout, int planar,
103 int64_t pts, int av_unused flags)
105 uint8_t *data[8] = {0};
107 int nb_channels = av_get_channel_layout_nb_channels(channel_layout),
108 nb_samples = buf_size / nb_channels / av_get_bytes_per_sample(sample_fmt);
110 av_samples_fill_arrays(data, linesize,
111 buf, nb_channels, nb_samples,
114 AV_NOWARN_DEPRECATED(
115 return av_asrc_buffer_add_samples(ctx,
116 data, linesize, nb_samples,
118 sample_fmt, channel_layout, planar,