1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-11-26 19:01:44 +02:00
FFmpeg/libavfilter/af_aconvert.c
Michael Niedermayer a05a44e205 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
      759001c534 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 01:40:35 +01:00

186 lines
6.0 KiB
C

/*
* Copyright (c) 2010 S.N. Hemanth Meenakshisundaram <smeenaks@ucsd.edu>
* Copyright (c) 2011 Stefano Sabatini
* Copyright (c) 2011 Mina Nagy Zaki
*
* 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.
*
* 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
* sample format and channel layout conversion audio filter
*/
#include "libavutil/avstring.h"
#include "libavutil/channel_layout.h"
#include "libswresample/swresample.h"
#include "avfilter.h"
#include "audio.h"
#include "internal.h"
typedef struct {
enum AVSampleFormat out_sample_fmt;
int64_t out_chlayout;
struct SwrContext *swr;
} AConvertContext;
static av_cold int init(AVFilterContext *ctx, const char *args0)
{
AConvertContext *aconvert = ctx->priv;
char *arg, *ptr = NULL;
int ret = 0;
char *args = av_strdup(args0);
aconvert->out_sample_fmt = AV_SAMPLE_FMT_NONE;
aconvert->out_chlayout = 0;
if ((arg = av_strtok(args, ":", &ptr)) && strcmp(arg, "auto")) {
if ((ret = ff_parse_sample_format(&aconvert->out_sample_fmt, arg, ctx)) < 0)
goto end;
}
if ((arg = av_strtok(NULL, ":", &ptr)) && strcmp(arg, "auto")) {
if ((ret = ff_parse_channel_layout(&aconvert->out_chlayout, arg, ctx)) < 0)
goto end;
}
end:
av_freep(&args);
return ret;
}
static av_cold void uninit(AVFilterContext *ctx)
{
AConvertContext *aconvert = ctx->priv;
swr_free(&aconvert->swr);
}
static int query_formats(AVFilterContext *ctx)
{
AVFilterFormats *formats = NULL;
AConvertContext *aconvert = ctx->priv;
AVFilterLink *inlink = ctx->inputs[0];
AVFilterLink *outlink = ctx->outputs[0];
AVFilterChannelLayouts *layouts;
ff_formats_ref(ff_all_formats(AVMEDIA_TYPE_AUDIO),
&inlink->out_formats);
if (aconvert->out_sample_fmt != AV_SAMPLE_FMT_NONE) {
formats = NULL;
ff_add_format(&formats, aconvert->out_sample_fmt);
ff_formats_ref(formats, &outlink->in_formats);
} else
ff_formats_ref(ff_all_formats(AVMEDIA_TYPE_AUDIO),
&outlink->in_formats);
ff_channel_layouts_ref(ff_all_channel_layouts(),
&inlink->out_channel_layouts);
if (aconvert->out_chlayout != 0) {
layouts = NULL;
ff_add_channel_layout(&layouts, aconvert->out_chlayout);
ff_channel_layouts_ref(layouts, &outlink->in_channel_layouts);
} else
ff_channel_layouts_ref(ff_all_channel_layouts(),
&outlink->in_channel_layouts);
return 0;
}
static int config_output(AVFilterLink *outlink)
{
int ret;
AVFilterContext *ctx = outlink->src;
AVFilterLink *inlink = ctx->inputs[0];
AConvertContext *aconvert = ctx->priv;
char buf1[64], buf2[64];
/* if not specified in args, use the format and layout of the output */
if (aconvert->out_sample_fmt == AV_SAMPLE_FMT_NONE)
aconvert->out_sample_fmt = outlink->format;
if (aconvert->out_chlayout == 0)
aconvert->out_chlayout = outlink->channel_layout;
aconvert->swr = swr_alloc_set_opts(aconvert->swr,
aconvert->out_chlayout, aconvert->out_sample_fmt, inlink->sample_rate,
inlink->channel_layout, inlink->format, inlink->sample_rate,
0, ctx);
if (!aconvert->swr)
return AVERROR(ENOMEM);
ret = swr_init(aconvert->swr);
if (ret < 0)
return ret;
av_get_channel_layout_string(buf1, sizeof(buf1),
-1, inlink ->channel_layout);
av_get_channel_layout_string(buf2, sizeof(buf2),
-1, outlink->channel_layout);
av_log(ctx, AV_LOG_VERBOSE,
"fmt:%s cl:%s -> fmt:%s cl:%s\n",
av_get_sample_fmt_name(inlink ->format), buf1,
av_get_sample_fmt_name(outlink->format), buf2);
return 0;
}
static int filter_frame(AVFilterLink *inlink, AVFrame *insamplesref)
{
AConvertContext *aconvert = inlink->dst->priv;
const int n = insamplesref->nb_samples;
AVFilterLink *const outlink = inlink->dst->outputs[0];
AVFrame *outsamplesref = ff_get_audio_buffer(outlink, n);
int ret;
swr_convert(aconvert->swr, outsamplesref->extended_data, n,
(void *)insamplesref->extended_data, n);
av_frame_copy_props(outsamplesref, insamplesref);
outsamplesref->channels = outlink->channels;
outsamplesref->channel_layout = outlink->channel_layout;
ret = ff_filter_frame(outlink, outsamplesref);
av_frame_free(&insamplesref);
return ret;
}
static const AVFilterPad aconvert_inputs[] = {
{
.name = "default",
.type = AVMEDIA_TYPE_AUDIO,
.filter_frame = filter_frame,
},
{ NULL }
};
static const AVFilterPad aconvert_outputs[] = {
{
.name = "default",
.type = AVMEDIA_TYPE_AUDIO,
.config_props = config_output,
},
{ NULL }
};
AVFilter avfilter_af_aconvert = {
.name = "aconvert",
.description = NULL_IF_CONFIG_SMALL("Convert the input audio to sample_fmt:channel_layout."),
.priv_size = sizeof(AConvertContext),
.init = init,
.uninit = uninit,
.query_formats = query_formats,
.inputs = aconvert_inputs,
.outputs = aconvert_outputs,
};