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
This commit is contained in:
arpi 2003-01-18 17:34:02 +00:00
parent 10a2ba079b
commit b1956ff824
2 changed files with 74 additions and 10 deletions

View File

@ -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;

View File

@ -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)