mirror of
https://github.com/mpv-player/mpv
synced 2024-09-05 02:48:21 +02:00
-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
This commit is contained in:
parent
7f62a29ed9
commit
dbf0fe78c6
@ -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:
|
||||
|
@ -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"
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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");
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user