Differences between revisions 3 and 4
Revision 3 as of 2014-04-19 10:33:15
Size: 2219
Editor: lu_zero
Comment:
Revision 4 as of 2014-04-19 10:39:53
Size: 2556
Editor: lu_zero
Comment:
Deletions are marked like this. Additions are marked like this.
Line 11: Line 11:
introduced. introduced, reducing the boilerplate code and providing an example for the developers not using AVFrame but their own abstraction.
Line 75: Line 75:
The internals are quite straightforward and the two functions are leveraging the already public avresample and avformat functions ('''avresample_convert''', '''avresample_open''', '''avresample_close''', allocators).

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, reducing the boilerplate code and providing an example for the developers not using AVFrame but their own abstraction.

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

The internals are quite straightforward and the two functions are leveraging the already public avresample and avformat functions (avresample_convert, avresample_open, avresample_close, allocators).


CategoryBlueprint CategoryWIP