[FFmpeg-devel] [PATCH] avformat/mxf: support MCA audio information

Tomas Härdin tjoppen at acc.umu.se
Wed Oct 20 11:40:58 EEST 2021


mån 2021-10-18 klockan 17:06 +0200 skrev Marc-Antoine Arnaud:
> 
> +static int mxf_audio_remapping(int* channel_ordering, uint8_t* data,
> int size, int sample_size, int channels)
> +{
> +    int sample_offset = channels * sample_size;
> +    int number_of_samples = size / sample_offset;
> +    uint8_t* tmp = av_malloc(sample_offset);

You could avoid this allocation using

    uint8_t tmp[FF_SANE_NB_CHANNELS*4];

since mxfdec only handles up to 32-bit PCM. Maybe *8 if someone down
the line decides to add support for 64-bit PCM. Not that I understand
why anyone would ever use that.. Don't think SMPTE defines a UL for it.

> +    uint8_t* data_ptr = data;

you can just use data

> +
> +    if (!tmp)
> +        return AVERROR(ENOMEM);
> +
> +    for (int sample = 0; sample < number_of_samples; ++sample) {
> +        memcpy(tmp, data_ptr, sample_offset);
> +
> +        for (int channel = 0; channel < channels; ++channel) {
> +            for (int sample_index = 0; sample_index < sample_size;
> ++sample_index) {
> +                data_ptr[sample_size * channel_ordering[channel] +
> sample_index] = tmp[sample_size * channel + sample_index];
> +            }

why not memcpy()? Should get inlined by any decent compiler I think

/Tomas



More information about the ffmpeg-devel mailing list