Mercurial > mplayer.hg
changeset 15811:9b4bbb6098f6
make -srate work again, unify audio filter init and preinit.
author | reimar |
---|---|
date | Fri, 24 Jun 2005 10:50:53 +0000 |
parents | 27b1d5a4f972 |
children | 6a9db8a1a5bd |
files | libaf/af.c libaf/af.h libmpcodecs/dec_audio.c libmpcodecs/dec_audio.h mencoder.c mplayer.c |
diffstat | 6 files changed, 40 insertions(+), 72 deletions(-) [+] |
line wrap: on
line diff
--- a/libaf/af.c Thu Jun 23 23:40:07 2005 +0000 +++ b/libaf/af.c Fri Jun 24 10:50:53 2005 +0000 @@ -329,12 +329,11 @@ and output should contain the format of the current movie and the formate of the preferred output respectively. The function is reentrant i.e. if called with an already initialized stream the - stream will be reinitialized. If the binary parameter - "force_output" is set, the output format will be converted to the - format given in "s", otherwise the output fromat in the last filter - will be copied "s". The return value is 0 if success and -1 if - failure */ -int af_init(af_stream_t* s, int force_output) + stream will be reinitialized. + If one of the prefered output parameters is 0 the one that needs + no conversion is used (i.e. the output format in the last filter). + The return value is 0 if success and -1 if failure */ +int af_init(af_stream_t* s) { int i=0; @@ -373,17 +372,11 @@ if (!af_append(s,s->first,"dummy") || AF_OK != af_reinit(s,s->first)) return -1; - // If force_output isn't set do not compensate for output format - if(!force_output){ - memcpy(&s->output, s->last->data, sizeof(af_data_t)); - return 0; - } - // Check output format if((AF_INIT_TYPE_MASK & s->cfg.force) != AF_INIT_FORCE){ af_instance_t* af = NULL; // New filter // Check output frequency if not OK fix with resample - if(s->last->data->rate!=s->output.rate){ + if(s->output.rate && s->last->data->rate!=s->output.rate){ // try to find a filter that can change samplrate af = af_control_any_rev(s, AF_CONTROL_RESAMPLE_RATE | AF_CONTROL_SET, &(s->output.rate)); @@ -428,7 +421,7 @@ // Check number of output channels fix if not OK // If needed always inserted last -> easy to screw up other filters - if(s->last->data->nch!=s->output.nch){ + if(s->output.nch && s->last->data->nch!=s->output.nch){ if(!strcmp(s->last->info->name,"format")) af = af_prepend(s,s->last,"channels"); else @@ -441,7 +434,7 @@ } // Check output format fix if not OK - if(s->last->data->format != s->output.format){ + if(s->output.format && s->last->data->format != s->output.format){ if(strcmp(s->last->info->name,"format")) af = af_append(s,s->last,"format"); else @@ -458,6 +451,9 @@ if(AF_OK != af_reinit(s,s->first)) return -1; + if (!s->output.format) s->output.format = s->last->data->format; + if (!s->output.nch) s->output.nch = s->last->data->nch; + if (!s->output.rate) s->output.rate = s->last->data->rate; if((s->last->data->format != s->output.format) || (s->last->data->nch != s->output.nch) || (s->last->data->rate != s->output.rate)) {
--- a/libaf/af.h Thu Jun 23 23:40:07 2005 +0000 +++ b/libaf/af.h Fri Jun 24 10:50:53 2005 +0000 @@ -134,7 +134,7 @@ format given in "s", otherwise the output fromat in the last filter will be copied "s". The return value is 0 if success and -1 if failure */ -int af_init(af_stream_t* s, int force_output); +int af_init(af_stream_t* s); // Uninit and remove all filters void af_uninit(af_stream_t* s);
--- a/libmpcodecs/dec_audio.c Thu Jun 23 23:40:07 2005 +0000 +++ b/libmpcodecs/dec_audio.c Fri Jun 24 10:50:53 2005 +0000 @@ -260,6 +260,7 @@ } if(sh_audio->a_out_buffer!=sh_audio->a_buffer) free(sh_audio->a_out_buffer); sh_audio->a_out_buffer=NULL; + sh_audio->a_out_buffer_size=0; if(sh_audio->a_buffer) free(sh_audio->a_buffer); sh_audio->a_buffer=NULL; if(sh_audio->a_in_buffer) free(sh_audio->a_in_buffer); @@ -270,50 +271,14 @@ int preinit_audio_filters(sh_audio_t *sh_audio, int in_samplerate, int in_channels, int in_format, int* out_samplerate, int* out_channels, int* out_format){ - af_stream_t* afs=malloc(sizeof(af_stream_t)); - memset(afs,0,sizeof(af_stream_t)); - - // input format: same as codec's output format: - afs->input.rate = in_samplerate; - afs->input.nch = in_channels; - afs->input.format = in_format; - af_fix_parameters(&(afs->input)); - - // output format: same as ao driver's input format (if missing, fallback to input) - afs->output.rate = *out_samplerate ? *out_samplerate : afs->input.rate; - afs->output.nch = *out_channels ? *out_channels : afs->input.nch; - afs->output.format = *out_format ? *out_format : afs->input.format; - af_fix_parameters(&(afs->output)); - - // filter config: - memcpy(&afs->cfg,&af_cfg,sizeof(af_cfg_t)); - - mp_msg(MSGT_DECAUDIO, MSGL_INFO, "Checking audio filter chain for %dHz/%dch/%s -> %dHz/%dch/%s...\n", - afs->input.rate,afs->input.nch,af_fmt2str_short(afs->input.format), - afs->output.rate,afs->output.nch,af_fmt2str_short(afs->output.format)); - - // let's autoprobe it! - if(0 != af_init(afs,0)){ - free(afs); - return 0; // failed :( - } - - *out_samplerate=afs->output.rate; - *out_channels=afs->output.nch; - *out_format=afs->output.format; - - mp_msg(MSGT_DECAUDIO, MSGL_INFO, "AF_pre: %dHz/%dch/%s\n", - afs->output.rate, afs->output.nch, - af_fmt2str_short(afs->output.format)); - - sh_audio->afilter=(void*)afs; - return 1; + init_audio_filters(sh_audio, in_samplerate, in_channels, in_format, + out_samplerate, out_channels, out_format, 0, 0); } /* Init audio filters */ int init_audio_filters(sh_audio_t *sh_audio, int in_samplerate, int in_channels, int in_format, - int out_samplerate, int out_channels, int out_format, + int *out_samplerate, int *out_channels, int *out_format, int out_minsize, int out_maxsize){ af_stream_t* afs=sh_audio->afilter; if(!afs){ @@ -328,9 +293,9 @@ af_fix_parameters(&(afs->input)); // output format: same as ao driver's input format (if missing, fallback to input) - afs->output.rate = out_samplerate ? out_samplerate : afs->input.rate; - afs->output.nch = out_channels ? out_channels : afs->input.nch; - afs->output.format = out_format ? out_format : afs->input.format; + afs->output.rate = *out_samplerate; + afs->output.nch = *out_channels; + afs->output.format = *out_format; af_fix_parameters(&(afs->output)); // filter config: @@ -341,12 +306,17 @@ afs->output.rate,afs->output.nch,af_fmt2str_short(afs->output.format)); // let's autoprobe it! - if(0 != af_init(afs,1)){ + if(0 != af_init(afs)){ sh_audio->afilter=NULL; free(afs); return 0; // failed :( } + + *out_samplerate=afs->output.rate; + *out_channels=afs->output.nch; + *out_format=afs->output.format; + if (out_maxsize || out_minsize) { // allocate the a_out_* buffers: if(out_maxsize<out_minsize) out_maxsize=out_minsize; if(out_maxsize<8192) out_maxsize=MAX_OUTBURST; // not sure this is ok @@ -355,6 +325,7 @@ sh_audio->a_out_buffer=malloc(sh_audio->a_out_buffer_size); memset(sh_audio->a_out_buffer,0,sh_audio->a_out_buffer_size); sh_audio->a_out_buffer_len=0; + } // ok! sh_audio->afilter=(void*)afs;
--- a/libmpcodecs/dec_audio.h Thu Jun 23 23:40:07 2005 +0000 +++ b/libmpcodecs/dec_audio.h Fri Jun 24 10:50:53 2005 +0000 @@ -12,7 +12,7 @@ extern int init_audio_filters(sh_audio_t *sh_audio, int in_samplerate, int in_channels, int in_format, - int out_samplerate, int out_channels, int out_format, + int *out_samplerate, int *out_channels, int *out_format, int out_minsize, int out_maxsize); extern int preinit_audio_filters(sh_audio_t *sh_audio, int in_samplerate, int in_channels, int in_format,
--- a/mencoder.c Thu Jun 23 23:40:07 2005 +0000 +++ b/mencoder.c Fri Jun 24 10:50:53 2005 +0000 @@ -819,9 +819,9 @@ mux_a->codec=out_audio_codec; -ao_data.samplerate = force_srate ? force_srate : new_srate; -ao_data.channels = audio_output_channels ? audio_output_channels : sh_audio->channels; -ao_data.format = audio_output_format ? audio_output_format : sh_audio->sample_format; +ao_data.samplerate = force_srate; +ao_data.channels = 0; +ao_data.format = audio_output_format; if(!preinit_audio_filters(sh_audio, // input: new_srate, @@ -833,7 +833,7 @@ } aparams.channels = ao_data.channels; -aparams.sample_rate = force_srate ? force_srate : ao_data.samplerate; +aparams.sample_rate = ao_data.samplerate; aparams.audio_preload = 1000 * audio_preload; if(mux_a->codec != ACODEC_COPY) { aencoder = new_audio_encoder(mux_a, &aparams); @@ -841,7 +841,7 @@ mencoder_exit(1, NULL); if(!init_audio_filters(sh_audio, new_srate, sh_audio->channels, sh_audio->sample_format, - aparams.sample_rate, aparams.channels, aencoder->input_format, + &aparams.sample_rate, &aparams.channels, &aencoder->input_format, aencoder->min_buffer_size, aencoder->max_buffer_size)) { mp_msg(MSGT_CPLAYER,MSGL_FATAL,MSGTR_NoMatchingFilter); mencoder_exit(1,NULL); @@ -951,9 +951,9 @@ new_srate, sh_audio->channels, sh_audio->sample_format, - mux_a->wf->nSamplesPerSec, - mux_a->wf->nChannels, - out_format, + &mux_a->wf->nSamplesPerSec, + &mux_a->wf->nChannels, + &out_format, out_minsize, out_maxsize)) {
--- a/mplayer.c Thu Jun 23 23:40:07 2005 +0000 +++ b/mplayer.c Fri Jun 24 10:50:53 2005 +0000 @@ -955,7 +955,7 @@ } result = init_audio_filters(sh_audio, new_srate, sh_audio->channels, sh_audio->sample_format, - ao_data->samplerate, ao_data->channels, ao_data->format, + &ao_data->samplerate, &ao_data->channels, &ao_data->format, ao_data->outburst * 4, ao_data->buffersize); mixer.afilter = sh_audio->afilter; #ifdef HAVE_NEW_GUI @@ -2133,10 +2133,11 @@ if(sh_audio){ //const ao_info_t *info=audio_out->info; current_module="af_preinit"; - ao_data.samplerate=force_srate?force_srate:sh_audio->samplerate*playback_speed; - ao_data.channels=audio_output_channels?audio_output_channels:sh_audio->channels; - ao_data.format=audio_output_format?audio_output_format:sh_audio->sample_format; + ao_data.samplerate=force_srate; + ao_data.channels=0; + ao_data.format=audio_output_format; #if 1 + // first init to detect best values if(!preinit_audio_filters(sh_audio, // input: (int)(sh_audio->samplerate*playback_speed),