summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorarpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-09-28 02:23:20 +0000
committerarpi <arpi@b3059339-0415-0410-9bf9-f77b7e298cf2>2002-09-28 02:23:20 +0000
commitdbf0fe78c631aa786c54afe7fbb1ee63c359a0b0 (patch)
treec0a5c20701f23da143ef9b0d12ec2b78b49c5dc0
parent7f62a29ed9126ba3d55f45476f42510ca98beed7 (diff)
downloadmpv-dbf0fe78c631aa786c54afe7fbb1ee63c359a0b0.tar.bz2
mpv-dbf0fe78c631aa786c54afe7fbb1ee63c359a0b0.tar.xz
-ac/-afm rewrite, now works the same way as -vc/-vfm
including audio codec fallbacks if init failed git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@7523 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r--cfg-common.h6
-rw-r--r--help/help_mp-en.h1
-rw-r--r--libmpcodecs/dec_audio.c110
-rw-r--r--libmpcodecs/dec_audio.h6
-rw-r--r--mencoder.c4
-rw-r--r--mplayer.c8
6 files changed, 112 insertions, 23 deletions
diff --git a/cfg-common.h b/cfg-common.h
index 7b36eb5e74..17e9ef2131 100644
--- a/cfg-common.h
+++ b/cfg-common.h
@@ -106,9 +106,11 @@
// select audio/video codec (by name) or codec family (by number):
// {"afm", &audio_family, CONF_TYPE_INT, CONF_MIN, 0, 22, NULL}, // keep ranges in sync
// {"vfm", &video_family, CONF_TYPE_INT, CONF_MIN, 0, 29, NULL}, // with codec-cfg.c
- {"afm", &audio_fm, CONF_TYPE_STRING, 0, 0, 0, NULL},
+// {"afm", &audio_fm, CONF_TYPE_STRING, 0, 0, 0, NULL},
+ {"afm", &audio_fm_list, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL},
{"vfm", &video_fm_list, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL},
- {"ac", &audio_codec, CONF_TYPE_STRING, 0, 0, 0, NULL},
+// {"ac", &audio_codec, CONF_TYPE_STRING, 0, 0, 0, NULL},
+ {"ac", &audio_codec_list, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL},
{"vc", &video_codec_list, CONF_TYPE_STRING_LIST, 0, 0, 0, NULL},
// postprocessing:
diff --git a/help/help_mp-en.h b/help/help_mp-en.h
index 7a244a29e4..165ce9ddb6 100644
--- a/help/help_mp-en.h
+++ b/help/help_mp-en.h
@@ -125,6 +125,7 @@ static char help_text[]=
#define MSGTR_InitializingAudioCodec "Initializing audio codec...\n"
#define MSGTR_ErrorInitializingVODevice "Error opening/initializing the selected video_out (-vo) device!\n"
#define MSGTR_ForcedVideoCodec "Forced video codec: %s\n"
+#define MSGTR_ForcedAudioCodec "Forced audio codec: %s\n"
#define MSGTR_AODescription_AOAuthor "AO: Description: %s\nAO: Author: %s\n"
#define MSGTR_AOComment "AO: Comment: %s\n"
#define MSGTR_Video_NoVideo "Video: no video!!!\n"
diff --git a/libmpcodecs/dec_audio.c b/libmpcodecs/dec_audio.c
index 01535a3375..8c4501c570 100644
--- a/libmpcodecs/dec_audio.c
+++ b/libmpcodecs/dec_audio.c
@@ -42,21 +42,9 @@ void afm_help(){
mpcodecs_ad_drivers[i]->info->name);
}
-int init_audio(sh_audio_t *sh_audio)
+int init_audio_codec(sh_audio_t *sh_audio)
{
unsigned i;
- for (i=0; mpcodecs_ad_drivers[i] != NULL; i++)
-// if(mpcodecs_ad_drivers[i]->info->id==sh_audio->codec->driver){
- if(!strcmp(mpcodecs_ad_drivers[i]->info->short_name,sh_audio->codec->drv)){
- mpadec=mpcodecs_ad_drivers[i]; break;
- }
- if(!mpadec){
- mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_AudioCodecFamilyNotAvailableStr,
- sh_audio->codec->name, sh_audio->codec->drv);
- return 0; // no such driver
- }
-
- mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_OpeningAudioDecoder,mpadec->info->short_name,mpadec->info->name);
// reset in/out buffer size/pointer:
sh_audio->a_buffer_size=0;
@@ -125,11 +113,103 @@ int init_audio(sh_audio_t *sh_audio)
if(!sh_audio->o_bps)
sh_audio->o_bps=sh_audio->channels*sh_audio->samplerate*sh_audio->samplesize;
+
+ mp_msg(MSGT_DECAUDIO,MSGL_INFO,"AUDIO: %d Hz, %d ch, sfmt: 0x%X (%d bps), ratio: %d->%d (%3.1f kbit)\n",
+ sh_audio->samplerate,sh_audio->channels,
+ sh_audio->sample_format,sh_audio->samplesize,
+ sh_audio->i_bps,sh_audio->o_bps,sh_audio->i_bps*8*0.001);
return 1;
}
-int init_best_audio_codec(sh_audio_t *sh_audio,char* audio_codec,char* audio_fm){
+int init_audio(sh_audio_t *sh_audio,char* codecname,char* afm,int status){
+ unsigned int orig_fourcc=sh_audio->wf?sh_audio->wf->wFormatTag:0;
+ sh_audio->codec=NULL;
+ while(1){
+ int i;
+ // restore original fourcc:
+ if(sh_audio->wf) sh_audio->wf->wFormatTag=i=orig_fourcc;
+ if(!(sh_audio->codec=find_codec(sh_audio->format,
+ sh_audio->wf?(&i):NULL, sh_audio->codec,1) )) break;
+ if(sh_audio->wf) sh_audio->wf->wFormatTag=i;
+ // ok we found one codec
+ if(sh_audio->codec->flags&CODECS_FLAG_SELECTED) continue; // already tried & failed
+ if(codecname && strcmp(sh_audio->codec->name,codecname)) continue; // -ac
+ if(afm && strcmp(sh_audio->codec->drv,afm)) continue; // afm doesn't match
+ if(sh_audio->codec->status<status) continue; // too unstable
+ sh_audio->codec->flags|=CODECS_FLAG_SELECTED; // tagging it
+ // ok, it matches all rules, let's find the driver!
+ for (i=0; mpcodecs_ad_drivers[i] != NULL; i++)
+ if(!strcmp(mpcodecs_ad_drivers[i]->info->short_name,sh_audio->codec->drv)) break;
+ mpadec=mpcodecs_ad_drivers[i];
+ if(!mpadec){ // driver not available (==compiled in)
+ mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_AudioCodecFamilyNotAvailableStr,
+ sh_audio->codec->name, sh_audio->codec->drv);
+ continue;
+ }
+ // it's available, let's try to init!
+ // init()
+ mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_OpeningAudioDecoder,mpadec->info->short_name,mpadec->info->name);
+ if(!init_audio_codec(sh_audio)){
+ mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_ADecoderInitFailed);
+ continue; // try next...
+ }
+ // Yeah! We got it!
+ return 1;
+ }
+ return 0;
+}
+
+int init_best_audio_codec(sh_audio_t *sh_audio,char** audio_codec_list,char** audio_fm_list){
+char* ac_l_default[2]={"",(char*)NULL};
+// hack:
+if(!audio_codec_list) audio_codec_list=ac_l_default;
+// Go through the codec.conf and find the best codec...
+sh_audio->inited=0;
+codecs_reset_selection(1);
+while(!sh_audio->inited && *audio_codec_list){
+ char* audio_codec=*(audio_codec_list++);
+ if(audio_codec[0]){
+ if(audio_codec[0]=='-'){
+ // disable this codec:
+ select_codec(audio_codec+1,1);
+ } else {
+ // forced codec by name:
+ mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_ForcedAudioCodec,audio_codec);
+ init_audio(sh_audio,audio_codec,NULL,-1);
+ }
+ } else {
+ int status;
+ // try in stability order: UNTESTED, WORKING, BUGGY. never try CRASHING.
+ if(audio_fm_list){
+ char** fmlist=audio_fm_list;
+ // try first the preferred codec families:
+ while(!sh_audio->inited && *fmlist){
+ char* audio_fm=*(fmlist++);
+ mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_TryForceAudioFmtStr,audio_fm);
+ for(status=CODECS_STATUS__MAX;status>=CODECS_STATUS__MIN;--status)
+ if(init_audio(sh_audio,NULL,audio_fm,status)) break;
+ }
+ }
+ if(!sh_audio->inited)
+ for(status=CODECS_STATUS__MAX;status>=CODECS_STATUS__MIN;--status)
+ if(init_audio(sh_audio,NULL,NULL,status)) break;
+ }
+}
+
+if(!sh_audio->inited){
+ mp_msg(MSGT_DECAUDIO,MSGL_HINT, MSGTR_TryUpgradeCodecsConfOrRTFM,get_path("codecs.conf"));
+ mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CantFindAudioCodec,sh_audio->format);
+ return 0; // failed
+}
+
+mp_msg(MSGT_DECAUDIO,MSGL_INFO,"Selected audio codec: [%s] afm:%s (%s)\n",
+ sh_audio->codec->name,sh_audio->codec->drv,sh_audio->codec->info);
+return 1; // success
+}
+
+
+int init_best_audio_codec_old(sh_audio_t *sh_audio,char* audio_codec,char* audio_fm){
// Go through the codec.conf and find the best codec...
sh_audio->codec=NULL;
if(audio_fm) mp_msg(MSGT_DECAUDIO,MSGL_INFO,MSGTR_TryForceAudioFmtStr,audio_fm);
@@ -153,7 +233,7 @@ int init_best_audio_codec(sh_audio_t *sh_audio,char* audio_codec,char* audio_fm)
break;
}
// found it...
- if(!init_audio(sh_audio)){
+ if(!init_audio_codec(sh_audio)){
mp_msg(MSGT_DECAUDIO,MSGL_ERR,MSGTR_CouldntInitAudioCodec);
return 0;
}
diff --git a/libmpcodecs/dec_audio.h b/libmpcodecs/dec_audio.h
index c71a20e568..d4d5b67917 100644
--- a/libmpcodecs/dec_audio.h
+++ b/libmpcodecs/dec_audio.h
@@ -1,8 +1,10 @@
// dec_audio.c:
extern void afm_help();
-extern int init_best_audio_codec(sh_audio_t *sh_audio,char* audio_codec,char* audio_fm);
-extern int init_audio(sh_audio_t *sh_audio);
+//extern int init_best_audio_codec(sh_audio_t *sh_audio,char* audio_codec,char* audio_fm);
+extern int init_audio_codec(sh_audio_t *sh_audio);
+extern int init_audio(sh_audio_t *sh_audio,char* codecname,char* afm,int status);
+extern int init_best_audio_codec(sh_audio_t *sh_audio,char** audio_codec_list,char** audio_fm_list);
extern int decode_audio(sh_audio_t *sh_audio,unsigned char *buf,int minlen,int maxlen);
extern void resync_audio_stream(sh_audio_t *sh_audio);
extern void skip_audio_frame(sh_audio_t *sh_audio);
diff --git a/mencoder.c b/mencoder.c
index cdf9735767..fe7181ffdc 100644
--- a/mencoder.c
+++ b/mencoder.c
@@ -94,9 +94,11 @@ static char* spudec_ifo=NULL;
static int has_audio=1;
char *audio_codec=NULL; // override audio codec
char *video_codec=NULL; // override video codec
+char **audio_codec_list=NULL; // override video codec
char **video_codec_list=NULL; // override video codec
char* audio_fm=NULL; // override audio codec family
char* video_fm=NULL; // override video codec family
+char** audio_fm_list=NULL; // override video codec family
char** video_fm_list=NULL; // override video codec family
int out_audio_codec=-1;
@@ -488,7 +490,7 @@ sh_video=d_video->sh;
if(sh_audio && (out_audio_codec || seek_to_sec || !sh_audio->wf)){
// Go through the codec.conf and find the best codec...
mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
- if(!init_best_audio_codec(sh_audio,audio_codec,audio_fm)){
+ if(!init_best_audio_codec(sh_audio,audio_codec_list,audio_fm_list)){
sh_audio=d_audio->sh=NULL; // failed to init :(
}
mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
diff --git a/mplayer.c b/mplayer.c
index 18210fd313..133bbd5c1b 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -178,9 +178,11 @@ int has_audio=1;
int has_video=1;
char *audio_codec=NULL; // override audio codec
char *video_codec=NULL; // override video codec
+char **audio_codec_list=NULL; // override video codec
char **video_codec_list=NULL; // override video codec
char *audio_fm=NULL; // override audio codec family
char *video_fm=NULL; // override video codec family
+char **audio_fm_list=NULL; // override video codec family
char **video_fm_list=NULL; // override video codec family
// streaming:
@@ -631,7 +633,7 @@ if(!parse_codec_cfg(get_path("codecs.conf"))){
printf("vc#%d: '%s'\n",i,video_codec_list[i]);
}
#endif
- if(audio_codec && strcmp(audio_codec,"help")==0){
+ if(audio_codec_list && strcmp(audio_codec_list[0],"help")==0){
mp_msg(MSGT_CPLAYER, MSGL_INFO, MSGTR_AvailableAudioCodecs);
list_codecs(1);
printf("\n");
@@ -648,7 +650,7 @@ if(!parse_codec_cfg(get_path("codecs.conf"))){
printf("\n");
exit(0);
}
- if(audio_fm && strcmp(audio_fm,"help")==0){
+ if(audio_fm_list && strcmp(audio_fm_list[0],"help")==0){
afm_help();
printf("\n");
exit(0);
@@ -1216,7 +1218,7 @@ if(sh_audio){
// Go through the codec.conf and find the best codec...
current_module="init_audio_codec";
mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");
- if(!init_best_audio_codec(sh_audio,audio_codec,audio_fm)){
+ if(!init_best_audio_codec(sh_audio,audio_codec_list,audio_fm_list)){
sh_audio=d_audio->sh=NULL; // failed to init :(
}
mp_msg(MSGT_CPLAYER,MSGL_INFO,"==========================================================================\n");