From b1956ff8245b53ef791747294d7bdc667c389a23 Mon Sep 17 00:00:00 2001 From: arpi Date: Sat, 18 Jan 2003 17:34:02 +0000 Subject: [PATCH] 2-pass libaf initialization to get better filter chain. -channels, -format, -srate function changed, they affect codec & preinit outformat only, use -af resample=XXX,channels=YYY,format=ZZZ to override. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@8996 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpcodecs/dec_audio.c | 52 +++++++++++++++++++++++++++++++++++++++-- mplayer.c | 32 ++++++++++++++++++------- 2 files changed, 74 insertions(+), 10 deletions(-) diff --git a/libmpcodecs/dec_audio.c b/libmpcodecs/dec_audio.c index 09c70efa81..7d301b07ca 100644 --- a/libmpcodecs/dec_audio.c +++ b/libmpcodecs/dec_audio.c @@ -276,13 +276,61 @@ void uninit_audio(sh_audio_t *sh_audio) sh_audio->a_in_buffer=NULL; } + /* Init audio filters */ +int preinit_audio_filters(sh_audio_t *sh_audio, + int in_samplerate, int in_channels, int in_format, int in_bps, + int* out_samplerate, int* out_channels, int* out_format, int out_bps){ + char strbuf[200]; + 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 = af_format_decode(in_format); + afs->input.bps = in_bps; + + // 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 = af_format_decode(*out_format ? *out_format : afs->input.format); + afs->output.bps = out_bps ? out_bps : afs->input.bps; + + // filter config: + memcpy(&afs->cfg,&af_cfg,sizeof(af_cfg_t)); + + mp_msg(MSGT_DECAUDIO, MSGL_INFO, "Checking audio filter chain for %dHz/%dch/%dbit -> %dHz/%dch/%dbit...\n", + afs->input.rate,afs->input.nch,afs->input.bps*8, + afs->output.rate,afs->output.nch,afs->output.bps*8); + + // 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=af_format_encode((void*)(&afs->output)); + + mp_msg(MSGT_DECAUDIO, MSGL_INFO, "AF_pre: af format: %d bps, %d ch, %d hz, %s\n", + afs->output.bps, afs->output.nch, afs->output.rate, + fmt2str(afs->output.format,strbuf,200)); + + sh_audio->afilter=(void*)afs; + return 1; +} + /* Init audio filters */ int init_audio_filters(sh_audio_t *sh_audio, int in_samplerate, int in_channels, int in_format, int in_bps, int out_samplerate, int out_channels, int out_format, int out_bps, int out_minsize, int out_maxsize){ - af_stream_t* afs=malloc(sizeof(af_stream_t)); - memset(afs,0,sizeof(af_stream_t)); + af_stream_t* afs=sh_audio->afilter; + if(!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; diff --git a/mplayer.c b/mplayer.c index dfe753cd60..55a2cf38cd 100644 --- a/mplayer.c +++ b/mplayer.c @@ -1625,13 +1625,29 @@ osd_text_buffer[0]=0; 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; +#if 1 + if(!preinit_audio_filters(sh_audio, + // input: + (int)(sh_audio->samplerate*playback_speed), + sh_audio->channels, sh_audio->sample_format, sh_audio->samplesize, + // output: + &ao_data.samplerate, &ao_data.channels, &ao_data.format, + audio_out_format_bits(ao_data.format)/8)){ + mp_msg(MSGT_CPLAYER,MSGL_ERR,"Error at audio filter chain pre-init!\n"); + } else { + mp_msg(MSGT_CPLAYER,MSGL_INFO,"AF_pre: %dHz %dch %s\n", + ao_data.samplerate, ao_data.channels, + audio_out_format_name(ao_data.format)); + } +#endif current_module="ao2_init"; if(!(audio_out=init_best_audio_out(audio_driver_list, (ao_plugin_cfg.plugin_list!=NULL), // plugin flag - force_srate?force_srate:sh_audio->samplerate*playback_speed, - audio_output_channels?audio_output_channels: - sh_audio->channels,audio_output_format?audio_output_format: - sh_audio->sample_format,0))){ + ao_data.samplerate, ao_data.channels, ao_data.format,0))){ // FAILED: mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_CannotInitAO); uninit_player(INITED_ACODEC); // close codec @@ -1639,11 +1655,11 @@ if(sh_audio){ } else { // SUCCESS: inited_flags|=INITED_AO; - mp_msg(MSGT_CPLAYER,MSGL_INFO,"AO: [%s] %dHz %dch %s\n", + mp_msg(MSGT_CPLAYER,MSGL_INFO,"AO: [%s] %dHz %dch %s (%d bps)\n", audio_out->info->short_name, - force_srate?force_srate:((int)(sh_audio->samplerate*playback_speed)), - sh_audio->channels, - audio_out_format_name(sh_audio->sample_format)); + ao_data.samplerate, ao_data.channels, + audio_out_format_name(ao_data.format), + audio_out_format_bits(ao_data.format)/8 ); mp_msg(MSGT_CPLAYER,MSGL_V,MSGTR_AODescription_AOAuthor, audio_out->info->name, audio_out->info->author); if(strlen(audio_out->info->comment) > 0)