Differences between revisions 2 and 3
Revision 2 as of 2014-04-19 10:26:40
Size: 2229
Editor: lu_zero
Comment:
Revision 3 as of 2014-04-19 10:33:15
Size: 2219
Editor: lu_zero
Comment:
Deletions are marked like this. Additions are marked like this.
Line 50: Line 50:
 out->format      = format;  out->format = format;
Line 52: Line 52:
 out->sample_rate  = rate;  out->sample_rate = rate;
Line 58: Line 58:
  avresample_convert_frame(avr, out, NULL);
         process(out);
  avresample_config(avr, out, in);
         avresample_convert_frame(avr, out, in);
        avresample_convert_frame(avr, out, NULL);
        process(out);
        avresample_config(avr, out, in);
        avresample_convert_frame(avr, out, in);

This page is documenting a work in progress feature do not assume it is available on the mainline branch.

Rationale

AVResample is getting extended and some resamplers and mixers have additional parameters that can be user-tuned. In order to match AVScale an AVFrame-based API will be introduced.

API Design

The API extension includes

  • A new function, with slightly different semantics, to configure/reconfigure the resampling context passing extended options.
  • A set of AVFrame based function to have a simplified setup.

Additional options

The new avresample_open2() will match the similarly-named functions in AVCodec and AVFormat.

int avresample_open2(AVAudioResampleContext *avr, AVDictionary **opts);

The function is currently equivalent of using the AVOption api directly on the avr context and then call avresample_open.

AVFrame based API

The main focus had been to simplify the setup and make AVResample simpler to use.

int avresample_config(AVAudioResampleContext *avr, AVFrame *out, AVFrame *in, AVDictionary **opts);

int avresample_convert_frame(AVAudioResampleContext *avr, AVFrame *out, AVFrame *in);

The normal workflow would be quite simplified

 AVAudioResampleContext *avr = avresample_alloc();
 AVFrame *out = av_frame_alloc();
 AVFrame *in;

 out->format         = format;
 out->channel_layout = layout;
 out->sample_rate    = rate;

 while (fill_input(in)) {
    ret = avresample_convert_frame(avr, out, in);

    if (configuration_changed(ret))
        avresample_convert_frame(avr, out, NULL);
        process(out);
        avresample_config(avr, out, in);
        avresample_convert_frame(avr, out, in);
    }
    process(out);
 }

 ret = avresample_convert_frame(avr, out, NULL);

 process(out);

Albeit not checking for allocation errors to keep the code compact, the code above is all that's needed to adapt to changes to the input format and convert to a fixed output.

Architecture Design


CategoryBlueprint CategoryWIP