[FFmpeg-devel] [PATCH] Add af_resample - sample fmt and channel layout conversion filter
Michael Niedermayer
michaelni
Wed Sep 22 23:21:37 CEST 2010
On Sun, Sep 12, 2010 at 02:50:00PM -0700, S.N. Hemanth Meenakshisundaram wrote:
>
> Now modified af_resample to wrap the channel mix functions in
> lavc/resample.c the way Stefano wanted - exposing the channel mix
> routines as ff_* functions.
>
> With this af_resample has no duplicate code, calls lavc routines for
> both sample format conversion and channel mixing.
>
> This patch contains the extra resample_internal.h header and
> audioconvert functions required to represent the channel conversion
> required as a number.
>
> The patch isn't well split now, but once any changes required to this
> are done, I will split it properly. Please review and comment.
>
> af_resample is required for ffmpeg.c integration and many other lavfi
> audio filters to work.
>
> Regards,
>
> ---
> libavcodec/audioconvert.c | 17 ++
> libavcodec/audioconvert.h | 10 +
> libavcodec/resample.c | 21 ++-
> libavcodec/resample_internal.h | 36 ++++
> libavfilter/Makefile | 1 +
> libavfilter/af_resample.c | 378 ++++++++++++++++++++++++++++++++++++++++
> libavfilter/allfilters.c | 1 +
> 7 files changed, 454 insertions(+), 10 deletions(-)
> create mode 100644 libavcodec/resample_internal.h
> create mode 100644 libavfilter/af_resample.c
>
>
>
> libavcodec/audioconvert.c | 17 +
> libavcodec/audioconvert.h | 10 +
> libavcodec/resample.c | 21 +-
> libavcodec/resample_internal.h | 36 +++
> libavfilter/Makefile | 1
> libavfilter/af_resample.c | 378 +++++++++++++++++++++++++++++++++++++++++
> libavfilter/allfilters.c | 1
> 7 files changed, 454 insertions(+), 10 deletions(-)
> 331672e66f98cef708612cf26bbc18562a188c7f 0001-Add-af_resample-sample-fmt-and-channel-layout-conver.patch
> diff --git a/libavcodec/audioconvert.c b/libavcodec/audioconvert.c
> index c6dc1b1..17fa19a 100644
> --- a/libavcodec/audioconvert.c
> +++ b/libavcodec/audioconvert.c
> @@ -121,6 +121,11 @@ static const struct {
> { 0 }
> };
>
> +int avcodec_get_num_channel_layouts(void)
> +{
> + return (sizeof(channel_layout_map)/sizeof(channel_layout_map[0]));
> +}
the number is something close to 2^channels
> +
> int64_t avcodec_get_channel_layout(const char *name)
> {
> int i = 0;
> @@ -162,6 +167,18 @@ void avcodec_get_channel_layout_string(char *buf, int buf_size, int nb_channels,
> }
> }
>
> +int avcodec_get_channel_layout_index(int64_t channel_layout)
> +{
> + int i = 1;
> + do {
> + if (channel_layout_map[i].layout == channel_layout)
> + return i;
> + i++;
> + } while (channel_layout_map[i].name);
> +
> + return 0;
> +}
there are more layouts besides neither of these functions belong to public api
[...]
> @@ -53,7 +54,7 @@ struct ReSampleContext {
> };
>
> /* n1: number of samples */
> -static void stereo_to_mono(short *output, short *input, int n1)
> +void ff_stereo_to_mono(short *output, short *input, int n1)
> {
> short *p, *q;
> int n = n1;
the functions belong to libavfilter
what is the plan to move them there?
maybe iam missing something but these added dependancies dont seem to make
that easier
[...]
> +static void filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref)
> +{
> + ResampleContext *resample = link->dst->priv;
> + AVFilterLink *outlink = link->dst->outputs[0];
> + short samples_nb_changed = 0;
> +
> + /**
> + * If input data of this buffer differs from the earlier buffer/s, set flag
> + * to reconfigure the channel and sample format conversions.
> + */
> +
> + samples_nb_changed = (samplesref->audio->samples_nb != resample->in_samples_nb);
> + resample->in_samples_nb = samplesref->audio->samples_nb;
> + resample->reconfig_sample_fmt = (samplesref->format != resample->in_sample_fmt) || samples_nb_changed;
> + resample->in_sample_fmt = samplesref->format;
> + resample->reconfig_channel_layout = (samplesref->audio->channel_layout != resample->in_channel_layout) || samples_nb_changed;
> + resample->in_channel_layout = samplesref->audio->channel_layout;
> +
> + /* Convert to s16 sample format first, then to desired channel layout and finally to desired sample format */
we need a float path at some point
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
No human being will ever know the Truth, for even if they happen to say it
by chance, they would not even known they had done so. -- Xenophanes
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100922/db053821/attachment.pgp>
More information about the ffmpeg-devel
mailing list