ffmpeg/libavfilter/af_amerge.c

359 lines
12 KiB
C
Raw Normal View History

2011-11-06 20:28:05 +00:00
/*
* Copyright (c) 2011 Nicolas George <nicolas.george@normalesup.org>
*
* This file is part of FFmpeg.
*
* FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
2011-11-06 20:28:05 +00:00
*
* You should have received a copy of the GNU Lesser General Public
* License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* @file
* Audio merging filter
*/
#include "libavutil/avstring.h"
2012-06-03 19:32:22 +00:00
#include "libavutil/bprint.h"
#include "libavutil/channel_layout.h"
2012-06-03 19:32:22 +00:00
#include "libavutil/opt.h"
2011-11-06 20:28:05 +00:00
#include "avfilter.h"
#include "filters.h"
#include "audio.h"
2011-11-06 20:28:05 +00:00
#include "internal.h"
#define SWR_CH_MAX 64
typedef struct AMergeContext {
2012-06-03 19:32:22 +00:00
const AVClass *class;
int nb_inputs;
2011-11-06 20:28:05 +00:00
int route[SWR_CH_MAX]; /**< channels routing, see copy_samples */
int bps;
2012-05-31 19:47:10 +00:00
struct amerge_input {
int nb_ch; /**< number of channels for the input */
2012-06-03 19:32:22 +00:00
} *in;
2011-11-06 20:28:05 +00:00
} AMergeContext;
2012-06-03 19:32:22 +00:00
#define OFFSET(x) offsetof(AMergeContext, x)
#define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
2012-06-03 19:32:22 +00:00
static const AVOption amerge_options[] = {
{ "inputs", "specify the number of inputs", OFFSET(nb_inputs),
AV_OPT_TYPE_INT, { .i64 = 2 }, 1, SWR_CH_MAX, FLAGS },
{ NULL }
2012-06-03 19:32:22 +00:00
};
AVFILTER_DEFINE_CLASS(amerge);
2012-06-03 19:32:22 +00:00
2011-11-06 20:28:05 +00:00
static av_cold void uninit(AVFilterContext *ctx)
{
AMergeContext *s = ctx->priv;
2011-11-06 20:28:05 +00:00
av_freep(&s->in);
2011-11-06 20:28:05 +00:00
}
static int query_formats(AVFilterContext *ctx)
{
static const enum AVSampleFormat packed_sample_fmts[] = {
AV_SAMPLE_FMT_U8,
AV_SAMPLE_FMT_S16,
AV_SAMPLE_FMT_S32,
AV_SAMPLE_FMT_FLT,
AV_SAMPLE_FMT_DBL,
AV_SAMPLE_FMT_NONE
};
AMergeContext *s = ctx->priv;
AVChannelLayout *inlayout[SWR_CH_MAX] = { NULL }, outlayout = { 0 };
uint64_t outmask = 0;
Merge remote-tracking branch 'qatar/master' * qatar/master: (26 commits) fate: use diff -b in oneline comparison Add missing version bumps and APIchanges/Changelog entries. lavfi: move buffer management function to a separate file. lavfi: move formats-related functions from default.c to formats.c lavfi: move video-related functions to a separate file. fate: make smjpeg a demux test fate: separate sierra-vmd audio and video tests fate: separate smacker audio and video tests libmp3lame: set supported channel layouts. avconv: automatically insert asyncts when -async is used. avconv: add support for audio filters. lavfi: add asyncts filter. lavfi: add aformat filter lavfi: add an audio buffer sink. lavfi: add an audio buffer source. buffersrc: add av_buffersrc_write_frame(). buffersrc: fix invalid read in uninit if the fifo hasn't been allocated lavfi: rename vsrc_buffer.c to buffersrc.c avfiltergraph: reindent lavfi: add channel layout/sample rate negotiation. ... Conflicts: Changelog doc/APIchanges doc/filters.texi ffmpeg.c ffprobe.c libavcodec/libmp3lame.c libavfilter/Makefile libavfilter/af_aformat.c libavfilter/allfilters.c libavfilter/avfilter.c libavfilter/avfilter.h libavfilter/avfiltergraph.c libavfilter/buffersrc.c libavfilter/defaults.c libavfilter/formats.c libavfilter/src_buffer.c libavfilter/version.h libavfilter/vf_yadif.c libavfilter/vsrc_buffer.c libavfilter/vsrc_buffer.h libavutil/avutil.h tests/fate/audio.mak tests/fate/demux.mak tests/fate/video.mak Merged-by: Michael Niedermayer <michaelni@gmx.at>
2012-05-16 00:27:31 +00:00
AVFilterChannelLayouts *layouts;
int i, ret, overlap = 0, nb_ch = 0;
2011-11-06 20:28:05 +00:00
for (i = 0; i < s->nb_inputs; i++) {
if (!ctx->inputs[i]->incfg.channel_layouts ||
!ctx->inputs[i]->incfg.channel_layouts->nb_channel_layouts) {
av_log(ctx, AV_LOG_WARNING,
2011-11-06 20:28:05 +00:00
"No channel layout for input %d\n", i + 1);
return AVERROR(EAGAIN);
2011-11-06 20:28:05 +00:00
}
inlayout[i] = &ctx->inputs[i]->incfg.channel_layouts->channel_layouts[0];
if (ctx->inputs[i]->incfg.channel_layouts->nb_channel_layouts > 1) {
2011-11-06 20:28:05 +00:00
char buf[256];
av_channel_layout_describe(inlayout[i], buf, sizeof(buf));
2011-11-06 20:28:05 +00:00
av_log(ctx, AV_LOG_INFO, "Using \"%s\" for input %d\n", buf, i + 1);
}
s->in[i].nb_ch = FF_LAYOUT2COUNT(inlayout[i]);
if (s->in[i].nb_ch) {
2012-06-03 19:32:22 +00:00
overlap++;
} else {
s->in[i].nb_ch = inlayout[i]->nb_channels;
if (av_channel_layout_subset(inlayout[i], outmask))
overlap++;
outmask |= inlayout[i]->order == AV_CHANNEL_ORDER_NATIVE ?
inlayout[i]->u.mask : 0;
}
nb_ch += s->in[i].nb_ch;
2011-11-06 20:28:05 +00:00
}
2012-06-03 19:32:22 +00:00
if (nb_ch > SWR_CH_MAX) {
2011-11-06 20:28:05 +00:00
av_log(ctx, AV_LOG_ERROR, "Too many channels (max %d)\n", SWR_CH_MAX);
return AVERROR(EINVAL);
}
2012-06-03 19:32:22 +00:00
if (overlap) {
2011-11-06 20:28:05 +00:00
av_log(ctx, AV_LOG_WARNING,
"Input channel layouts overlap: "
"output layout will be determined by the number of distinct input channels\n");
2012-06-03 19:32:22 +00:00
for (i = 0; i < nb_ch; i++)
s->route[i] = i;
av_channel_layout_default(&outlayout, nb_ch);
if (!KNOWN(&outlayout) && nb_ch)
av_channel_layout_from_mask(&outlayout, 0xFFFFFFFFFFFFFFFFULL >> (64 - nb_ch));
2011-11-06 20:28:05 +00:00
} else {
2012-06-03 19:32:22 +00:00
int *route[SWR_CH_MAX];
2011-11-06 20:28:05 +00:00
int c, out_ch_number = 0;
av_channel_layout_from_mask(&outlayout, outmask);
route[0] = s->route;
for (i = 1; i < s->nb_inputs; i++)
route[i] = route[i - 1] + s->in[i - 1].nb_ch;
2011-11-06 20:28:05 +00:00
for (c = 0; c < 64; c++)
for (i = 0; i < s->nb_inputs; i++)
if (av_channel_layout_index_from_channel(inlayout[i], c) >= 0)
2011-11-06 20:28:05 +00:00
*(route[i]++) = out_ch_number++;
}
if ((ret = ff_set_common_formats_from_list(ctx, packed_sample_fmts)) < 0)
return ret;
for (i = 0; i < s->nb_inputs; i++) {
Merge remote-tracking branch 'qatar/master' * qatar/master: (26 commits) fate: use diff -b in oneline comparison Add missing version bumps and APIchanges/Changelog entries. lavfi: move buffer management function to a separate file. lavfi: move formats-related functions from default.c to formats.c lavfi: move video-related functions to a separate file. fate: make smjpeg a demux test fate: separate sierra-vmd audio and video tests fate: separate smacker audio and video tests libmp3lame: set supported channel layouts. avconv: automatically insert asyncts when -async is used. avconv: add support for audio filters. lavfi: add asyncts filter. lavfi: add aformat filter lavfi: add an audio buffer sink. lavfi: add an audio buffer source. buffersrc: add av_buffersrc_write_frame(). buffersrc: fix invalid read in uninit if the fifo hasn't been allocated lavfi: rename vsrc_buffer.c to buffersrc.c avfiltergraph: reindent lavfi: add channel layout/sample rate negotiation. ... Conflicts: Changelog doc/APIchanges doc/filters.texi ffmpeg.c ffprobe.c libavcodec/libmp3lame.c libavfilter/Makefile libavfilter/af_aformat.c libavfilter/allfilters.c libavfilter/avfilter.c libavfilter/avfilter.h libavfilter/avfiltergraph.c libavfilter/buffersrc.c libavfilter/defaults.c libavfilter/formats.c libavfilter/src_buffer.c libavfilter/version.h libavfilter/vf_yadif.c libavfilter/vsrc_buffer.c libavfilter/vsrc_buffer.h libavutil/avutil.h tests/fate/audio.mak tests/fate/demux.mak tests/fate/video.mak Merged-by: Michael Niedermayer <michaelni@gmx.at>
2012-05-16 00:27:31 +00:00
layouts = NULL;
if ((ret = ff_add_channel_layout(&layouts, inlayout[i])) < 0)
return ret;
if ((ret = ff_channel_layouts_ref(layouts, &ctx->inputs[i]->outcfg.channel_layouts)) < 0)
return ret;
2011-11-06 20:28:05 +00:00
}
Merge remote-tracking branch 'qatar/master' * qatar/master: (26 commits) fate: use diff -b in oneline comparison Add missing version bumps and APIchanges/Changelog entries. lavfi: move buffer management function to a separate file. lavfi: move formats-related functions from default.c to formats.c lavfi: move video-related functions to a separate file. fate: make smjpeg a demux test fate: separate sierra-vmd audio and video tests fate: separate smacker audio and video tests libmp3lame: set supported channel layouts. avconv: automatically insert asyncts when -async is used. avconv: add support for audio filters. lavfi: add asyncts filter. lavfi: add aformat filter lavfi: add an audio buffer sink. lavfi: add an audio buffer source. buffersrc: add av_buffersrc_write_frame(). buffersrc: fix invalid read in uninit if the fifo hasn't been allocated lavfi: rename vsrc_buffer.c to buffersrc.c avfiltergraph: reindent lavfi: add channel layout/sample rate negotiation. ... Conflicts: Changelog doc/APIchanges doc/filters.texi ffmpeg.c ffprobe.c libavcodec/libmp3lame.c libavfilter/Makefile libavfilter/af_aformat.c libavfilter/allfilters.c libavfilter/avfilter.c libavfilter/avfilter.h libavfilter/avfiltergraph.c libavfilter/buffersrc.c libavfilter/defaults.c libavfilter/formats.c libavfilter/src_buffer.c libavfilter/version.h libavfilter/vf_yadif.c libavfilter/vsrc_buffer.c libavfilter/vsrc_buffer.h libavutil/avutil.h tests/fate/audio.mak tests/fate/demux.mak tests/fate/video.mak Merged-by: Michael Niedermayer <michaelni@gmx.at>
2012-05-16 00:27:31 +00:00
layouts = NULL;
if ((ret = ff_add_channel_layout(&layouts, &outlayout)) < 0)
return ret;
if ((ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->incfg.channel_layouts)) < 0)
return ret;
return ff_set_common_all_samplerates(ctx);
2011-11-06 20:28:05 +00:00
}
static int config_output(AVFilterLink *outlink)
{
AVFilterContext *ctx = outlink->src;
AMergeContext *s = ctx->priv;
2012-06-03 19:32:22 +00:00
AVBPrint bp;
char buf[128];
2011-11-06 20:28:05 +00:00
int i;
s->bps = av_get_bytes_per_sample(ctx->outputs[0]->format);
2011-11-06 20:28:05 +00:00
outlink->time_base = ctx->inputs[0]->time_base;
2012-06-03 19:32:22 +00:00
av_bprint_init(&bp, 0, AV_BPRINT_SIZE_AUTOMATIC);
for (i = 0; i < s->nb_inputs; i++) {
2012-06-03 19:32:22 +00:00
av_bprintf(&bp, "%sin%d:", i ? " + " : "", i);
av_channel_layout_describe(&ctx->inputs[i]->ch_layout, buf, sizeof(buf));
av_bprintf(&bp, "%s", buf);
2011-11-06 20:28:05 +00:00
}
2012-06-03 19:32:22 +00:00
av_bprintf(&bp, " -> out:");
av_channel_layout_describe(&ctx->outputs[0]->ch_layout, buf, sizeof(buf));
av_bprintf(&bp, "%s", buf);
av_log(ctx, AV_LOG_VERBOSE, "%s\n", bp.str);
2012-06-03 19:32:22 +00:00
2011-11-06 20:28:05 +00:00
return 0;
}
/**
2012-06-03 19:32:22 +00:00
* Copy samples from several input streams to one output stream.
* @param nb_inputs number of inputs
* @param in inputs; used only for the nb_ch field;
2011-11-06 20:28:05 +00:00
* @param route routing values;
* input channel i goes to output channel route[i];
* i < in[0].nb_ch are the channels from the first output;
* i >= in[0].nb_ch are the channels from the second output
2011-11-06 20:28:05 +00:00
* @param ins pointer to the samples of each inputs, in packed format;
* will be left at the end of the copied samples
* @param outs pointer to the samples of the output, in packet format;
* must point to a buffer big enough;
* will be left at the end of the copied samples
* @param ns number of samples to copy
* @param bps bytes per sample
*/
2012-06-03 19:32:22 +00:00
static inline void copy_samples(int nb_inputs, struct amerge_input in[],
int *route, uint8_t *ins[],
2011-11-06 20:28:05 +00:00
uint8_t **outs, int ns, int bps)
{
int *route_cur;
2012-06-03 19:32:22 +00:00
int i, c, nb_ch = 0;
2011-11-06 20:28:05 +00:00
2012-06-03 19:32:22 +00:00
for (i = 0; i < nb_inputs; i++)
nb_ch += in[i].nb_ch;
2011-11-06 20:28:05 +00:00
while (ns--) {
route_cur = route;
2012-06-03 19:32:22 +00:00
for (i = 0; i < nb_inputs; i++) {
for (c = 0; c < in[i].nb_ch; c++) {
2011-11-06 20:28:05 +00:00
memcpy((*outs) + bps * *(route_cur++), ins[i], bps);
ins[i] += bps;
}
}
2012-06-03 19:32:22 +00:00
*outs += nb_ch * bps;
2011-11-06 20:28:05 +00:00
}
}
static void free_frames(int nb_inputs, AVFrame **input_frames)
{
int i;
for (i = 0; i < nb_inputs; i++)
av_frame_free(&input_frames[i]);
}
static int try_push_frame(AVFilterContext *ctx, int nb_samples)
2011-11-06 20:28:05 +00:00
{
AMergeContext *s = ctx->priv;
AVFilterLink *outlink = ctx->outputs[0];
int i, ret;
AVFrame *outbuf, *inbuf[SWR_CH_MAX] = { NULL };
uint8_t *outs, *ins[SWR_CH_MAX];
for (i = 0; i < ctx->nb_inputs; i++) {
ret = ff_inlink_consume_samples(ctx->inputs[i], nb_samples, nb_samples, &inbuf[i]);
if (ret < 0) {
free_frames(i, inbuf);
return ret;
}
ins[i] = inbuf[i]->data[0];
}
2011-11-06 20:28:05 +00:00
Merge commit '7e350379f87e7f74420b4813170fe808e2313911' * commit '7e350379f87e7f74420b4813170fe808e2313911': lavfi: switch to AVFrame. Conflicts: doc/filters.texi libavfilter/af_ashowinfo.c libavfilter/audio.c libavfilter/avfilter.c libavfilter/avfilter.h libavfilter/buffersink.c libavfilter/buffersrc.c libavfilter/buffersrc.h libavfilter/f_select.c libavfilter/f_setpts.c libavfilter/fifo.c libavfilter/split.c libavfilter/src_movie.c libavfilter/version.h libavfilter/vf_aspect.c libavfilter/vf_bbox.c libavfilter/vf_blackframe.c libavfilter/vf_delogo.c libavfilter/vf_drawbox.c libavfilter/vf_drawtext.c libavfilter/vf_fade.c libavfilter/vf_fieldorder.c libavfilter/vf_fps.c libavfilter/vf_frei0r.c libavfilter/vf_gradfun.c libavfilter/vf_hqdn3d.c libavfilter/vf_lut.c libavfilter/vf_overlay.c libavfilter/vf_pad.c libavfilter/vf_scale.c libavfilter/vf_showinfo.c libavfilter/vf_transpose.c libavfilter/vf_vflip.c libavfilter/vf_yadif.c libavfilter/video.c libavfilter/vsrc_testsrc.c libavfilter/yadif.h Following are notes about the merge authorship and various technical details. Michael Niedermayer: * Main merge operation, notably avfilter.c and video.c * Switch to AVFrame: - afade - anullsrc - apad - aresample - blackframe - deshake - idet - il - mandelbrot - mptestsrc - noise - setfield - smartblur - tinterlace * various merge changes and fixes in: - ashowinfo - blackdetect - field - fps - select - testsrc - yadif Nicolas George: * Switch to AVFrame: - make rawdec work with refcounted frames. Adapted from commit 759001c534287a96dc96d1e274665feb7059145d by Anton Khirnov. Also, fix the use of || instead of | in a flags check. - make buffer sink and src, audio and video work all together Clément Bœsch: * Switch to AVFrame: - aevalsrc - alphaextract - blend - cellauto - colormatrix - concat - earwax - ebur128 - edgedetect - geq - histeq - histogram - hue - kerndeint - life - movie - mp (with the help of Michael) - overlay - pad - pan - pp - pp - removelogo - sendcmd - showspectrum - showwaves - silencedetect - stereo3d - subtitles - super2xsai - swapuv - thumbnail - tile Hendrik Leppkes: * Switch to AVFrame: - aconvert - amerge - asetnsamples - atempo - biquads Matthieu Bouron: * Switch to AVFrame - alphamerge - decimate - volumedetect Stefano Sabatini: * Switch to AVFrame: - astreamsync - flite - framestep Signed-off-by: Michael Niedermayer <michaelni@gmx.at> Signed-off-by: Nicolas George <nicolas.george@normalesup.org> Signed-off-by: Clément Bœsch <ubitux@gmail.com> Signed-off-by: Hendrik Leppkes <h.leppkes@gmail.com> Signed-off-by: Matthieu Bouron <matthieu.bouron@gmail.com> Signed-off-by: Stefano Sabatini <stefasab@gmail.com> Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-10 00:30:30 +00:00
outbuf = ff_get_audio_buffer(ctx->outputs[0], nb_samples);
if (!outbuf) {
free_frames(s->nb_inputs, inbuf);
return AVERROR(ENOMEM);
2011-11-06 20:28:05 +00:00
}
outs = outbuf->data[0];
outbuf->pts = inbuf[0]->pts;
Merge commit '7e350379f87e7f74420b4813170fe808e2313911' * commit '7e350379f87e7f74420b4813170fe808e2313911': lavfi: switch to AVFrame. Conflicts: doc/filters.texi libavfilter/af_ashowinfo.c libavfilter/audio.c libavfilter/avfilter.c libavfilter/avfilter.h libavfilter/buffersink.c libavfilter/buffersrc.c libavfilter/buffersrc.h libavfilter/f_select.c libavfilter/f_setpts.c libavfilter/fifo.c libavfilter/split.c libavfilter/src_movie.c libavfilter/version.h libavfilter/vf_aspect.c libavfilter/vf_bbox.c libavfilter/vf_blackframe.c libavfilter/vf_delogo.c libavfilter/vf_drawbox.c libavfilter/vf_drawtext.c libavfilter/vf_fade.c libavfilter/vf_fieldorder.c libavfilter/vf_fps.c libavfilter/vf_frei0r.c libavfilter/vf_gradfun.c libavfilter/vf_hqdn3d.c libavfilter/vf_lut.c libavfilter/vf_overlay.c libavfilter/vf_pad.c libavfilter/vf_scale.c libavfilter/vf_showinfo.c libavfilter/vf_transpose.c libavfilter/vf_vflip.c libavfilter/vf_yadif.c libavfilter/video.c libavfilter/vsrc_testsrc.c libavfilter/yadif.h Following are notes about the merge authorship and various technical details. Michael Niedermayer: * Main merge operation, notably avfilter.c and video.c * Switch to AVFrame: - afade - anullsrc - apad - aresample - blackframe - deshake - idet - il - mandelbrot - mptestsrc - noise - setfield - smartblur - tinterlace * various merge changes and fixes in: - ashowinfo - blackdetect - field - fps - select - testsrc - yadif Nicolas George: * Switch to AVFrame: - make rawdec work with refcounted frames. Adapted from commit 759001c534287a96dc96d1e274665feb7059145d by Anton Khirnov. Also, fix the use of || instead of | in a flags check. - make buffer sink and src, audio and video work all together Clément Bœsch: * Switch to AVFrame: - aevalsrc - alphaextract - blend - cellauto - colormatrix - concat - earwax - ebur128 - edgedetect - geq - histeq - histogram - hue - kerndeint - life - movie - mp (with the help of Michael) - overlay - pad - pan - pp - pp - removelogo - sendcmd - showspectrum - showwaves - silencedetect - stereo3d - subtitles - super2xsai - swapuv - thumbnail - tile Hendrik Leppkes: * Switch to AVFrame: - aconvert - amerge - asetnsamples - atempo - biquads Matthieu Bouron: * Switch to AVFrame - alphamerge - decimate - volumedetect Stefano Sabatini: * Switch to AVFrame: - astreamsync - flite - framestep Signed-off-by: Michael Niedermayer <michaelni@gmx.at> Signed-off-by: Nicolas George <nicolas.george@normalesup.org> Signed-off-by: Clément Bœsch <ubitux@gmail.com> Signed-off-by: Hendrik Leppkes <h.leppkes@gmail.com> Signed-off-by: Matthieu Bouron <matthieu.bouron@gmail.com> Signed-off-by: Stefano Sabatini <stefasab@gmail.com> Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-10 00:30:30 +00:00
outbuf->nb_samples = nb_samples;
if ((ret = av_channel_layout_copy(&outbuf->ch_layout, &outlink->ch_layout)) < 0)
return ret;
#if FF_API_OLD_CHANNEL_LAYOUT
FF_DISABLE_DEPRECATION_WARNINGS
Merge commit '7e350379f87e7f74420b4813170fe808e2313911' * commit '7e350379f87e7f74420b4813170fe808e2313911': lavfi: switch to AVFrame. Conflicts: doc/filters.texi libavfilter/af_ashowinfo.c libavfilter/audio.c libavfilter/avfilter.c libavfilter/avfilter.h libavfilter/buffersink.c libavfilter/buffersrc.c libavfilter/buffersrc.h libavfilter/f_select.c libavfilter/f_setpts.c libavfilter/fifo.c libavfilter/split.c libavfilter/src_movie.c libavfilter/version.h libavfilter/vf_aspect.c libavfilter/vf_bbox.c libavfilter/vf_blackframe.c libavfilter/vf_delogo.c libavfilter/vf_drawbox.c libavfilter/vf_drawtext.c libavfilter/vf_fade.c libavfilter/vf_fieldorder.c libavfilter/vf_fps.c libavfilter/vf_frei0r.c libavfilter/vf_gradfun.c libavfilter/vf_hqdn3d.c libavfilter/vf_lut.c libavfilter/vf_overlay.c libavfilter/vf_pad.c libavfilter/vf_scale.c libavfilter/vf_showinfo.c libavfilter/vf_transpose.c libavfilter/vf_vflip.c libavfilter/vf_yadif.c libavfilter/video.c libavfilter/vsrc_testsrc.c libavfilter/yadif.h Following are notes about the merge authorship and various technical details. Michael Niedermayer: * Main merge operation, notably avfilter.c and video.c * Switch to AVFrame: - afade - anullsrc - apad - aresample - blackframe - deshake - idet - il - mandelbrot - mptestsrc - noise - setfield - smartblur - tinterlace * various merge changes and fixes in: - ashowinfo - blackdetect - field - fps - select - testsrc - yadif Nicolas George: * Switch to AVFrame: - make rawdec work with refcounted frames. Adapted from commit 759001c534287a96dc96d1e274665feb7059145d by Anton Khirnov. Also, fix the use of || instead of | in a flags check. - make buffer sink and src, audio and video work all together Clément Bœsch: * Switch to AVFrame: - aevalsrc - alphaextract - blend - cellauto - colormatrix - concat - earwax - ebur128 - edgedetect - geq - histeq - histogram - hue - kerndeint - life - movie - mp (with the help of Michael) - overlay - pad - pan - pp - pp - removelogo - sendcmd - showspectrum - showwaves - silencedetect - stereo3d - subtitles - super2xsai - swapuv - thumbnail - tile Hendrik Leppkes: * Switch to AVFrame: - aconvert - amerge - asetnsamples - atempo - biquads Matthieu Bouron: * Switch to AVFrame - alphamerge - decimate - volumedetect Stefano Sabatini: * Switch to AVFrame: - astreamsync - flite - framestep Signed-off-by: Michael Niedermayer <michaelni@gmx.at> Signed-off-by: Nicolas George <nicolas.george@normalesup.org> Signed-off-by: Clément Bœsch <ubitux@gmail.com> Signed-off-by: Hendrik Leppkes <h.leppkes@gmail.com> Signed-off-by: Matthieu Bouron <matthieu.bouron@gmail.com> Signed-off-by: Stefano Sabatini <stefasab@gmail.com> Merged-by: Michael Niedermayer <michaelni@gmx.at>
2013-03-10 00:30:30 +00:00
outbuf->channel_layout = outlink->channel_layout;
outbuf->channels = outlink->ch_layout.nb_channels;
FF_ENABLE_DEPRECATION_WARNINGS
#endif
2011-11-06 20:28:05 +00:00
while (nb_samples) {
/* Unroll the most common sample formats: speed +~350% for the loop,
+~13% overall (including two common decoders) */
switch (s->bps) {
2011-11-06 20:28:05 +00:00
case 1:
copy_samples(s->nb_inputs, s->in, s->route, ins, &outs, nb_samples, 1);
2011-11-06 20:28:05 +00:00
break;
case 2:
copy_samples(s->nb_inputs, s->in, s->route, ins, &outs, nb_samples, 2);
2011-11-06 20:28:05 +00:00
break;
case 4:
copy_samples(s->nb_inputs, s->in, s->route, ins, &outs, nb_samples, 4);
2011-11-06 20:28:05 +00:00
break;
default:
copy_samples(s->nb_inputs, s->in, s->route, ins, &outs, nb_samples, s->bps);
2011-11-06 20:28:05 +00:00
break;
}
nb_samples = 0;
2011-11-06 20:28:05 +00:00
}
free_frames(s->nb_inputs, inbuf);
return ff_filter_frame(ctx->outputs[0], outbuf);
2011-11-06 20:28:05 +00:00
}
static int activate(AVFilterContext *ctx)
{
int i, status;
int ret, nb_samples;
int64_t pts;
FF_FILTER_FORWARD_STATUS_BACK_ALL(ctx->outputs[0], ctx);
nb_samples = ff_inlink_queued_samples(ctx->inputs[0]);
for (i = 1; i < ctx->nb_inputs && nb_samples > 0; i++) {
nb_samples = FFMIN(ff_inlink_queued_samples(ctx->inputs[i]), nb_samples);
}
if (nb_samples) {
ret = try_push_frame(ctx, nb_samples);
if (ret < 0)
return ret;
}
for (i = 0; i < ctx->nb_inputs; i++) {
if (ff_inlink_queued_samples(ctx->inputs[i]))
continue;
if (ff_inlink_acknowledge_status(ctx->inputs[i], &status, &pts)) {
ff_outlink_set_status(ctx->outputs[0], status, pts);
return 0;
} else if (ff_outlink_frame_wanted(ctx->outputs[0])) {
ff_inlink_request_frame(ctx->inputs[i]);
return 0;
}
}
return 0;
}
static av_cold int init(AVFilterContext *ctx)
2012-06-03 19:32:22 +00:00
{
AMergeContext *s = ctx->priv;
int i, ret;
2012-06-03 19:32:22 +00:00
s->in = av_calloc(s->nb_inputs, sizeof(*s->in));
if (!s->in)
2012-06-03 19:32:22 +00:00
return AVERROR(ENOMEM);
for (i = 0; i < s->nb_inputs; i++) {
char *name = av_asprintf("in%d", i);
2012-06-03 19:32:22 +00:00
AVFilterPad pad = {
.name = name,
.type = AVMEDIA_TYPE_AUDIO,
};
if (!name)
return AVERROR(ENOMEM);
if ((ret = ff_append_inpad_free_name(ctx, &pad)) < 0)
return ret;
2012-06-03 19:32:22 +00:00
}
return 0;
}
static const AVFilterPad amerge_outputs[] = {
{
.name = "default",
.type = AVMEDIA_TYPE_AUDIO,
.config_props = config_output,
},
};
const AVFilter ff_af_amerge = {
2011-11-06 20:28:05 +00:00
.name = "amerge",
.description = NULL_IF_CONFIG_SMALL("Merge two or more audio streams into "
2011-11-06 20:28:05 +00:00
"a single multi-channel stream."),
.priv_size = sizeof(AMergeContext),
2012-06-03 19:32:22 +00:00
.init = init,
2011-11-06 20:28:05 +00:00
.uninit = uninit,
.activate = activate,
.inputs = NULL,
2021-08-12 11:05:31 +00:00
FILTER_OUTPUTS(amerge_outputs),
avfilter: Replace query_formats callback with union of list and callback If one looks at the many query_formats callbacks in existence, one will immediately recognize that there is one type of default callback for video and a slightly different default callback for audio: It is "return ff_set_common_formats_from_list(ctx, pix_fmts);" for video with a filter-specific pix_fmts list. For audio, it is the same with a filter-specific sample_fmts list together with ff_set_common_all_samplerates() and ff_set_common_all_channel_counts(). This commit allows to remove the boilerplate query_formats callbacks by replacing said callback with a union consisting the old callback and pointers for pixel and sample format arrays. For the not uncommon case in which these lists only contain a single entry (besides the sentinel) enum AVPixelFormat and enum AVSampleFormat fields are also added to the union to store them directly in the AVFilter, thereby avoiding a relocation. The state of said union will be contained in a new, dedicated AVFilter field (the nb_inputs and nb_outputs fields have been shrunk to uint8_t in order to create a hole for this new field; this is no problem, as the maximum of all the nb_inputs is four; for nb_outputs it is only two). The state's default value coincides with the earlier default of query_formats being unset, namely that the filter accepts all formats (and also sample rates and channel counts/layouts for audio) provided that these properties agree coincide for all inputs and outputs. By using different union members for audio and video filters the type-unsafety of using the same functions for audio and video lists will furthermore be more confined to formats.c than before. When the new fields are used, they will also avoid allocations: Currently something nearly equivalent to ff_default_query_formats() is called after every successful call to a query_formats callback; yet in the common case that the newly allocated AVFilterFormats are not used at all (namely if there are no free links) these newly allocated AVFilterFormats are freed again without ever being used. Filters no longer using the callback will not exhibit this any more. Reviewed-by: Paul B Mahol <onemda@gmail.com> Reviewed-by: Nicolas George <george@nsup.org> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
2021-09-27 10:07:35 +00:00
FILTER_QUERY_FUNC(query_formats),
.priv_class = &amerge_class,
2013-04-13 17:43:17 +00:00
.flags = AVFILTER_FLAG_DYNAMIC_INPUTS,
2011-11-06 20:28:05 +00:00
};