[MPlayer-dev-eng] [PATCH] Fix af_lavcresample to use the new ch_layout scheme.

Alexander Strasser eclipse7 at gmx.net
Tue Apr 9 02:10:03 EEST 2024


Committed by Ivan (iive) as SVN r38458 .

  Alexander


On 2024-04-07 17:09 +0200, Alexander Strasser wrote:
> LGTM
>
> Should go in right after my patch set IMHO
>
>
>   Alexander
>
> On 2024-04-07 15:14 +0300, Ivan Kalvachev wrote:
> > Just like the rest of FFmpeg 7.x swresample library doesn't accept
> > "number of channels" as separate parameter anymore and requires it to
> > be part of channel layout structure that also describes the audio
> > speakers layout.
> >
> > While Alexander Strasser's (beastd) patch series mostly fix this kind
> > of change in other parts of the code, here it remained unnoticed
> > because it doesn't cause compilation failure.
> >
> > The existing af_lavcresample code uses av_opt_set*() and because of
> > that the errors are returned at runtime.
> >
> > Since lavresample is automatically inserted to change the sample rate
> > (e.g. 44100->48000) it caused some videos to lose sound entirely.
> >
> > To fix it, I'm just getting the default channel layout for the given
> > number of channels. It's the simplest code that makes it work.
> >
> > This together with the change of ad_ffmpeg.c patch let's me play
> > everything so far.
> >
> > Best Regards
> >     Ivan Kalvachev
>
> > Index: af_lavcresample.c
> > ===================================================================
> > --- af_lavcresample.c	(revision 38449)
> > +++ af_lavcresample.c	(working copy)
> > @@ -57,6 +57,7 @@
> >  // Initialization and runtime control
> >  static int control(struct af_instance_s* af, int cmd, void* arg)
> >  {
> > +  AVChannelLayout ch_layout;
> >    af_resample_t* s   = (af_resample_t*)af->setup;
> >    af_data_t *data= (af_data_t*)arg;
> >    int out_rate, test_output_res; // helpers for checking input format
> > @@ -73,6 +74,8 @@
> >      af->mul = (double)af->data->rate / data->rate;
> >      af->delay = af->data->nch * s->filter_length / FFMIN(af->mul, 1); // *bps*.5
> >
> > +    av_channel_layout_default(&ch_layout, af->data->nch);
> > +
> >      if (s->ctx_out_rate != af->data->rate || s->ctx_in_rate != data->rate || s->ctx_filter_size != s->filter_length ||
> >          s->ctx_phase_shift != s->phase_shift || s->ctx_linear != s->linear || s->ctx_cutoff != s->cutoff) {
> >          swr_free(&s->swrctx);
> > @@ -85,8 +88,9 @@
> >          av_opt_set_double(s->swrctx, "cutoff", s->cutoff, 0);
> >          av_opt_set_sample_fmt(s->swrctx, "in_sample_fmt", AV_SAMPLE_FMT_S16, 0);
> >          av_opt_set_sample_fmt(s->swrctx, "out_sample_fmt", AV_SAMPLE_FMT_S16, 0);
> > -        av_opt_set_int(s->swrctx, "in_channel_count", af->data->nch, 0);
> > -        av_opt_set_int(s->swrctx, "out_channel_count", af->data->nch, 0);
> > +        if(av_opt_set_chlayout(s->swrctx, "in_chlayout",  &ch_layout, 0) < 0) return AF_ERROR;
> > +        if(av_opt_set_chlayout(s->swrctx, "out_chlayout", &ch_layout, 0) < 0) return AF_ERROR;
> > +
> >          if(swr_init(s->swrctx) < 0) return AF_ERROR;
> >          s->ctx_out_rate    = af->data->rate;
> >          s->ctx_in_rate     = data->rate;


More information about the MPlayer-dev-eng mailing list