ffmpeg-20150921/libswresample/resample.c
// in fact the whole handle multiple ridiculously small buffers might need more thinking...
in fact the whole handle multiple ridiculously small buffers might need more thinking
in fact the whole handle multiple ridiculously small buffers might need more thinking
static int invert_initial_buffer(ResampleContext *c, AudioData *dst, const AudioData *src,
                                 int in_count, int *out_idx, int *out_sz)
{
    int n, ch, num = FFMIN(in_count + *out_sz, c->filter_length + 1), res;
    if (c->index >= 0)
        return 0;
    if ((res = swri_realloc_audio(dst, c->filter_length * 2 + 1)) < 0)
        return res;
    for (n = *out_sz; n < num; n++) {
        for (ch = 0; ch < src->ch_count; ch++) {
            memcpy(dst->ch[ch] + ((c->filter_length + n) * c->felem_size),
                   src->ch[ch] + ((n - *out_sz) * c->felem_size), c->felem_size);
        }
    }
    if (num < c->filter_length + 1) {
        *out_sz = num;
        *out_idx = c->filter_length;
        return INT_MAX;
    }
    for (n = 1; n <= c->filter_length; n++) {
        for (ch = 0; ch < src->ch_count; ch++) {
            memcpy(dst->ch[ch] + ((c->filter_length - n) * c->felem_size),
                   dst->ch[ch] + ((c->filter_length + n) * c->felem_size),
                   c->felem_size);
        }
    }
    res = num - *out_sz;
    *out_idx = c->filter_length + (c->index >> c->phase_shift);
    *out_sz = FFMAX(*out_sz + c->filter_length,
                    1 + c->filter_length * 2) - *out_idx;
    c->index &= c->phase_mask;
    return FFMAX(res, 0);
}
static int invert_initial_buffer ( ResampleContext * c , AudioData * dst , const AudioData * src , int in_count , int * out_idx , int * out_sz ) { int n , ch , num = FFMIN ( in_count + * out_sz , c -> filter_length + 1 ) , res ; if ( c -> index >= 0 ) return 0 ; if ( ( res = swri_realloc_audio ( dst , c -> filter_length * 2 + 1 ) ) < 0 ) return res ; for ( n = * out_sz ; n < num ; n ++ ) { for ( ch = 0 ; ch < src -> ch_count ; ch ++ ) { memcpy ( dst -> ch [ ch ] + ( ( c -> filter_length + n ) * c -> felem_size ) , src -> ch [ ch ] + ( ( n - * out_sz ) * c -> felem_size ) , c -> felem_size ) ; } } if ( num < c -> filter_length + 1 ) { * out_sz = num ; * out_idx = c -> filter_length ; return INT_MAX ; } for ( n = 1 ; n <= c -> filter_length ; n ++ ) { for ( ch = 0 ; ch < src -> ch_count ; ch ++ ) { memcpy ( dst -> ch [ ch ] + ( ( c -> filter_length - n ) * c -> felem_size ) , dst -> ch [ ch ] + ( ( c -> filter_length + n ) * c -> felem_size ) , c -> felem_size ) ; } } res = num - * out_sz ; * out_idx = c -> filter_length + ( c -> index >> c -> phase_shift ) ; * out_sz = FFMAX ( * out_sz + c -> filter_length , 1 + c -> filter_length * 2 ) - * out_idx ; c -> index &= c -> phase_mask ; return FFMAX ( res , 0 ) ; }
in fact the whole handle multiple ridiculously small buffers might need more thinking...
in fact the whole handle multiple ridiculously small buffers might need more thinking ...
// copy // if not enough data is in, return and wait for more // else invert