changeset 16321:efbfac98cab1

Allow forcing of demuxers and codecs by prepending '+'
author reimar
date Tue, 30 Aug 2005 23:56:24 +0000
parents 2b6430db786a
children 9cb2b9b6a9b7
files DOCS/man/en/mplayer.1 codec-cfg.c codec-cfg.h libmpcodecs/dec_audio.c libmpcodecs/dec_video.c libmpdemux/demuxer.c libmpdemux/demuxer.h
diffstat 7 files changed, 65 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/DOCS/man/en/mplayer.1	Tue Aug 30 23:24:47 2005 +0000
+++ b/DOCS/man/en/mplayer.1	Tue Aug 30 23:56:24 2005 +0000
@@ -787,6 +787,7 @@
 .TP
 .B \-audio-demuxer <name> (\-audiofile only)
 Force audio demuxer type for \-audiofile.
+Use a '+' before the name to force it, this will skip some checks!
 Give the demuxer name as printed by \-audio-demuxer help.
 For backward compatibility it also accepts the demuxer ID as defined in
 libmpdemux/\:demuxer.h.
@@ -3136,10 +3137,11 @@
 .SH "DECODING/\:FILTERING OPTIONS"
 .
 .TP
-.B \-ac <[-]codec1,[-]codec2,...[,]>
+.B \-ac <[-|+]codec1,[-|+]codec2,...[,]>
 Specify a priority list of audio codecs to be used, according to their codec
 name in codecs.conf.
 Use a '-' before the codec name to omit it.
+Use a '+' before the codec name to force it, this will likely crash!
 If the list has a trailing ',' MPlayer will fall back on codecs not
 contained in the list.
 .br
@@ -3541,6 +3543,7 @@
 Specify a priority list of video codecs to be used, according to their codec
 name in codecs.conf.
 Use a '-' before the codec name to omit it.
+Use a '+' before the codec name to force it, this will likely crash!
 If the list has a trailing ',' MPlayer will fall back on codecs not
 contained in the list.
 .br
--- a/codec-cfg.c	Tue Aug 30 23:24:47 2005 +0000
+++ b/codec-cfg.c	Tue Aug 30 23:56:24 2005 +0000
@@ -757,19 +757,19 @@
 }
 
 codecs_t *find_audio_codec(unsigned int fourcc, unsigned int *fourccmap,
-		codecs_t *start)
+		codecs_t *start, int force)
 {
-	return find_codec(fourcc, fourccmap, start, 1);
+	return find_codec(fourcc, fourccmap, start, 1, force);
 }
 
 codecs_t *find_video_codec(unsigned int fourcc, unsigned int *fourccmap,
-		codecs_t *start)
+		codecs_t *start, int force)
 {
-	return find_codec(fourcc, fourccmap, start, 0);
+	return find_codec(fourcc, fourccmap, start, 0, force);
 }
 
 codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap,
-		codecs_t *start, int audioflag)
+		codecs_t *start, int audioflag, int force)
 {
 	int i, j;
 	codecs_t *c;
@@ -806,6 +806,7 @@
 					return c;
 				}
 			}
+			if (force) return c;
 		}
 	}
 	return NULL;
--- a/codec-cfg.h	Tue Aug 30 23:24:47 2005 +0000
+++ b/codec-cfg.h	Tue Aug 30 23:56:24 2005 +0000
@@ -59,9 +59,12 @@
 } codecs_t;
 
 int parse_codec_cfg(char *cfgfile);
-codecs_t* find_video_codec(unsigned int fourcc, unsigned int *fourccmap, codecs_t *start);
-codecs_t* find_audio_codec(unsigned int fourcc, unsigned int *fourccmap, codecs_t *start);
-codecs_t* find_codec(unsigned int fourcc,unsigned int *fourccmap,codecs_t *start,int audioflag);
+codecs_t* find_video_codec(unsigned int fourcc, unsigned int *fourccmap,
+                           codecs_t *start, int force);
+codecs_t* find_audio_codec(unsigned int fourcc, unsigned int *fourccmap,
+                           codecs_t *start, int force);
+codecs_t* find_codec(unsigned int fourcc, unsigned int *fourccmap,
+                     codecs_t *start, int audioflag, int force);
 void select_codec(char* codecname,int audioflag);
 void list_codecs(int audioflag);
 void codecs_reset_selection(int audioflag);
--- a/libmpcodecs/dec_audio.c	Tue Aug 30 23:24:47 2005 +0000
+++ b/libmpcodecs/dec_audio.c	Tue Aug 30 23:56:24 2005 +0000
@@ -119,6 +119,11 @@
 
 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;
+    int force = 0;
+    if (codecname && codecname[0] == '+') {
+      codecname = &codecname[1];
+      force = 1;
+    }
     sh_audio->codec=NULL;
     while(1){
 	ad_functions_t* mpadec;
@@ -126,14 +131,14 @@
 	sh_audio->ad_driver = 0;
 	// 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->codec=find_audio_codec(sh_audio->format,
+          sh_audio->wf?(&i):NULL, sh_audio->codec, force) )) 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
+	if(!force && 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++)
--- a/libmpcodecs/dec_video.c	Tue Aug 30 23:24:47 2005 +0000
+++ b/libmpcodecs/dec_video.c	Tue Aug 30 23:56:24 2005 +0000
@@ -166,19 +166,24 @@
     unsigned int orig_fourcc=sh_video->bih?sh_video->bih->biCompression:0;
     sh_video->codec=NULL;
     sh_video->vf_inited=0;
+    int force = 0;
+    if (codecname && codecname[0] == '+') {
+      codecname = &codecname[1];
+      force = 1;
+    }
 
     while(1){
 	int i;
 	// restore original fourcc:
 	if(sh_video->bih) sh_video->bih->biCompression=orig_fourcc;
-	if(!(sh_video->codec=find_codec(sh_video->format,
+	if(!(sh_video->codec=find_video_codec(sh_video->format,
           sh_video->bih?((unsigned int*) &sh_video->bih->biCompression):NULL,
-          sh_video->codec,0) )) break;
+          sh_video->codec,force) )) break;
 	// ok we found one codec
 	if(sh_video->codec->flags&CODECS_FLAG_SELECTED) continue; // already tried & failed
 	if(codecname && strcmp(sh_video->codec->name,codecname)) continue; // -vc
 	if(vfm && strcmp(sh_video->codec->drv,vfm)) continue; // vfm doesn't match
-	if(sh_video->codec->status<status) continue; // too unstable
+	if(!force && sh_video->codec->status<status) continue; // too unstable
 	sh_video->codec->flags|=CODECS_FLAG_SELECTED; // tagging it
 	// ok, it matches all rules, let's find the driver!
 	for (i=0; mpcodecs_vd_drivers[i] != NULL; i++)
--- a/libmpdemux/demuxer.c	Tue Aug 30 23:24:47 2005 +0000
+++ b/libmpdemux/demuxer.c	Tue Aug 30 23:56:24 2005 +0000
@@ -528,14 +528,21 @@
  * Get demuxer type for a given demuxer name
  *
  * @param demuxer_name    string with demuxer name of demuxer number
+ * @param force           will be set if demuxer should be forced.
+ *                        May be NULL.
  * @return                DEMUXER_TYPE_xxx, -1 if error or not found
  */
-int get_demuxer_type_from_name(char *demuxer_name)
+int get_demuxer_type_from_name(char *demuxer_name, int *force)
 {
   int i;
   long type_int;
   char *endptr;
 
+  if (!demuxer_name || !demuxer_name[0])
+    return DEMUXER_TYPE_UNKNOWN;
+  if (force) *force = demuxer_name[0] == '+';
+  if (demuxer_name[0] == '+')
+    demuxer_name = &demuxer_name[1];
   for (i = 0; demuxer_list[i]; i++) {
     if (demuxer_list[i]->type > DEMUXER_TYPE_MAX) // Can't select special demuxers from commandline
       continue;
@@ -568,7 +575,9 @@
   (ex: tv,mf).
 */
 
-static demuxer_t* demux_open_stream(stream_t *stream,int file_format,int audio_id,int video_id,int dvdsub_id,char* filename){
+static demuxer_t* demux_open_stream(stream_t *stream, int file_format,
+                    int force, int audio_id, int video_id, int dvdsub_id,
+                    char* filename) {
 
 //int file_format=(*file_format_ptr);
 
@@ -586,7 +595,7 @@
 if (file_format) {
   if ((demuxer_desc = get_demuxer_desc_from_type(file_format))) {
     demuxer = new_demuxer(stream,demuxer_desc->type,audio_id,video_id,dvdsub_id,filename);
-    if (demuxer_desc->check_file) {
+    if (!force && demuxer_desc->check_file) {
       if ((fformat = demuxer_desc->check_file(demuxer)) != 0) {
         if (fformat == demuxer_desc->type) {
           // Move messages to demuxer detection code?
@@ -595,7 +604,8 @@
         } else {
           // Format changed after check, recurse
           free_demuxer(demuxer);
-          return demux_open_stream(stream,fformat,audio_id,video_id,dvdsub_id,filename);
+          return demux_open_stream(stream, fformat, force,
+                   audio_id, video_id, dvdsub_id, filename);
         }
       } else {
         // Check failed for forced demuxer, quit
@@ -621,7 +631,8 @@
       } else {
         // Format changed after check, recurse
         free_demuxer(demuxer);
-        demuxer=demux_open_stream(stream,fformat,audio_id,video_id,dvdsub_id,filename);
+        demuxer=demux_open_stream(stream, fformat, force,
+                  audio_id, video_id, dvdsub_id, filename);
         if(demuxer) return demuxer; // done!
         file_format = DEMUXER_TYPE_UNKNOWN;
       }
@@ -643,7 +654,8 @@
   file_format=demuxer_type_by_filename(filename);
   if(file_format!=DEMUXER_TYPE_UNKNOWN){
     // we like recursion :)
-    demuxer=demux_open_stream(stream,file_format,audio_id,video_id,dvdsub_id,filename);
+    demuxer=demux_open_stream(stream, file_format, force,
+              audio_id, video_id, dvdsub_id, filename);
     if(demuxer) return demuxer; // done!
     file_format=DEMUXER_TYPE_UNKNOWN; // continue fuzzy guessing...
     mp_msg(MSGT_DEMUXER,MSGL_V,"demuxer: continue fuzzy content-based format guessing...\n");
@@ -662,7 +674,8 @@
       } else {
         // Format changed after check, recurse
         free_demuxer(demuxer);
-        demuxer=demux_open_stream(stream,fformat,audio_id,video_id,dvdsub_id,filename);
+        demuxer=demux_open_stream(stream, fformat, force,
+                  audio_id, video_id, dvdsub_id, filename);
         if(demuxer) return demuxer; // done!
         file_format = DEMUXER_TYPE_UNKNOWN;
       }
@@ -718,16 +731,18 @@
   demuxer_t *vd,*ad = NULL,*sd = NULL;
   int afmt =DEMUXER_TYPE_UNKNOWN,sfmt = DEMUXER_TYPE_UNKNOWN ;
   int audio_demuxer_type = 0, sub_demuxer_type = 0;
+  int demuxer_force = 0, audio_demuxer_force = 0,
+      sub_demuxer_force = 0;
 
   demux_aid_vid_mismatch = 0;
 
-  if (demuxer_name && ((demuxer_type = get_demuxer_type_from_name(demuxer_name)) < 0)) {
+  if ((demuxer_type = get_demuxer_type_from_name(demuxer_name, &demuxer_force)) < 0) {
     mp_msg(MSGT_DEMUXER,MSGL_ERR,"-demuxer %s does not exist.\n",demuxer_name);
   }
-  if (audio_demuxer_name && ((audio_demuxer_type = get_demuxer_type_from_name(audio_demuxer_name)) < 0)) {
+  if ((audio_demuxer_type = get_demuxer_type_from_name(audio_demuxer_name, &audio_demuxer_force)) < 0) {
     mp_msg(MSGT_DEMUXER,MSGL_ERR,"-audio-demuxer %s does not exist.\n",audio_demuxer_name);
   }
-  if (sub_demuxer_name && ((sub_demuxer_type = get_demuxer_type_from_name(sub_demuxer_name)) < 0)) {
+  if ((sub_demuxer_type = get_demuxer_type_from_name(sub_demuxer_name, &sub_demuxer_force)) < 0) {
     mp_msg(MSGT_DEMUXER,MSGL_ERR,"-sub-demuxer %s does not exist.\n",sub_demuxer_name);
   }
 
@@ -754,14 +769,17 @@
     }
   }
 
-  vd = demux_open_stream(vs,demuxer_type ? demuxer_type : file_format,audio_stream ? -2 : audio_id,video_id, sub_stream ? -2 : dvdsub_id, filename);
+  vd = demux_open_stream(vs, demuxer_type ? demuxer_type : file_format,
+         demuxer_force, audio_stream ? -2 : audio_id, video_id,
+         sub_stream ? -2 : dvdsub_id, filename);
   if(!vd) {
     if(as) free_stream(as);
     if(ss) free_stream(ss);
     return NULL;
   }
   if(as) {
-    ad = demux_open_stream(as,audio_demuxer_type ? audio_demuxer_type : afmt,audio_id,-2,-2, audio_stream);
+    ad = demux_open_stream(as, audio_demuxer_type ? audio_demuxer_type : afmt,
+           audio_demuxer_force, audio_id, -2, -2, audio_stream);
     if(!ad) {
       mp_msg(MSGT_DEMUXER,MSGL_WARN,MSGTR_OpeningAudioDemuxerFailed,audio_stream);
       free_stream(as);
@@ -770,7 +788,8 @@
       hr_mp3_seek=1; // Enable high res seeking
   }
   if(ss) {
-    sd = demux_open_stream(ss,sub_demuxer_type ? sub_demuxer_type : sfmt,-2,-2,dvdsub_id, sub_stream);
+    sd = demux_open_stream(ss, sub_demuxer_type ? sub_demuxer_type : sfmt,
+           sub_demuxer_force, -2, -2, dvdsub_id, sub_stream);
     if(!sd) {
       mp_msg(MSGT_DEMUXER,MSGL_WARN,MSGTR_OpeningSubtitlesDemuxerFailed,sub_stream);
       free_stream(ss);
--- a/libmpdemux/demuxer.h	Tue Aug 30 23:24:47 2005 +0000
+++ b/libmpdemux/demuxer.h	Tue Aug 30 23:56:24 2005 +0000
@@ -327,4 +327,4 @@
 extern int demuxer_type_by_filename(char* filename);
 
 extern void demuxer_help(void);
-extern int get_demuxer_type_from_name(char *demuxer_name);
+extern int get_demuxer_type_from_name(char *demuxer_name, int *force);