changeset 8995:865cbed58cf8

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.
author arpi
date Sat, 18 Jan 2003 17:34:02 +0000
parents 06d7ef3c7b01
children c5772dde2914
files libmpcodecs/dec_audio.c mplayer.c
diffstat 2 files changed, 74 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/libmpcodecs/dec_audio.c	Sat Jan 18 17:31:58 2003 +0000
+++ b/libmpcodecs/dec_audio.c	Sat Jan 18 17:34:02 2003 +0000
@@ -277,12 +277,60 @@
 }
 
  /* 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;
--- a/mplayer.c	Sat Jan 18 17:31:58 2003 +0000
+++ b/mplayer.c	Sat Jan 18 17:34:02 2003 +0000
@@ -1625,13 +1625,29 @@
 
 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 @@
   } 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)