diff options
author | anders <anders@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2002-10-05 11:02:39 +0000 |
---|---|---|
committer | anders <anders@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2002-10-05 11:02:39 +0000 |
commit | 24556149010249ccd4d223d71b77148e616502e8 (patch) | |
tree | 17ffc8345269ad1052fcd213b29eb63949038a09 | |
parent | 65d1d8d94832d99175479bf50e1a9591248b8c6e (diff) | |
download | mpv-24556149010249ccd4d223d71b77148e616502e8.tar.bz2 mpv-24556149010249ccd4d223d71b77148e616502e8.tar.xz |
Adding function for estimating required buffer length
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@7599 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r-- | libaf/af.c | 48 | ||||
-rw-r--r-- | libaf/af.h | 11 |
2 files changed, 58 insertions, 1 deletions
diff --git a/libaf/af.c b/libaf/af.c index 9313dffd27..d7be6a265f 100644 --- a/libaf/af.c +++ b/libaf/af.c @@ -408,6 +408,54 @@ int af_inputlen(af_stream_t* s, int len) return t * (((len/t) * mul.d - 1)/mul.n); } +/* Calculate how long the input IN to the filters should be to produce + a certain output length OUT but with the following three constraints: + 1. IN <= max_insize, where max_insize is the maximum possible input + block length + 2. OUT <= max_outsize, where max_outsize is the maximum possible + output block length + 3. If possible OUT >= len. + Return -1 in case of error */ +int af_calc_insize_constrained(af_stream_t* s, int len, + int max_outsize,int max_insize) +{ + int t = s->input.bps*s->input.nch; + int in = 0; + int out = 0; + af_instance_t* af=s->first; + register frac_t mul = {1,1}; + // Iterate through all filters and calculate total multiplication factor + do{ + mul.n *= af->mul.n; + mul.d *= af->mul.d; + af=af->next; + }while(af); + in = t * (((len/t) * mul.d)/mul.n); + + // Try to meet constraint nr 3. + out = t * (((in/t)*mul.n + 1)/mul.d); + while(in <= max_insize && out <= max_outsize){ + printf("debug in = %i out = %i \n",in,out); + + if(out > len) + return in; + out = t * (((in/t)*mul.n + 1)/mul.d); + in+=t; + } + + // Could no meet constraint nr 3. + while((out > max_outsize || in > max_insize) && in > 1) + { + in-=t; + out = t * (((in/t)*mul.n + 1)/mul.d); + } + if(in > 1) + return in; + + // Input parameters are probably incorrect + return -1; +} + /* Helper function called by the macro with the same name this function should not be called directly */ inline int af_resize_local_buffer(af_instance_t* af, af_data_t* data) diff --git a/libaf/af.h b/libaf/af.h index 31991cd2c5..6f8a9d4672 100644 --- a/libaf/af.h +++ b/libaf/af.h @@ -146,7 +146,16 @@ int af_outputlen(af_stream_t* s, int len); the input length required to produce the output length "len". The calculated length is <= the actual length */ int af_inputlen(af_stream_t* s, int len); - +/* Calculate how long the input IN to the filters should be to produce + a certain output length OUT but with the following three constraints: + 1. IN <= max_insize, where max_insize is the maximum possible input + block length + 2. OUT <= max_outsize, where max_outsize is the maximum possible + output block length + 3. If possible OUT >= len. + Return -1 in case of error */ +int af_calc_insize_constrained(af_stream_t* s, int len, + int max_outsize,int max_insize); // Helper functions and macros used inside the audio filters |