[MPlayer-dev-eng] [PATCH] forcing codec or demuxers

Reimar Döffinger Reimar.Doeffinger at stud.uni-karlsruhe.de
Sat Aug 27 19:04:57 CEST 2005


> the attached patch lets you force demuxers or codecs by adding a '+' in
> front of the name.
> Forcing means in the case of codecs not checking fourcc or status,
> in the case of the demuxer not calling the check function.
> Okay to apply? I intend to apply soon.

....
-------------- next part --------------
Index: codec-cfg.c
===================================================================
RCS file: /cvsroot/mplayer/main/codec-cfg.c,v
retrieving revision 1.119
diff -u -r1.119 codec-cfg.c
--- codec-cfg.c	1 May 2005 13:58:30 -0000	1.119
+++ codec-cfg.c	27 Aug 2005 16:47:19 -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;
Index: codec-cfg.h
===================================================================
RCS file: /cvsroot/mplayer/main/codec-cfg.h,v
retrieving revision 1.72
diff -u -r1.72 codec-cfg.h
--- codec-cfg.h	28 Jul 2005 12:55:01 -0000	1.72
+++ codec-cfg.h	27 Aug 2005 16:47:19 -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);
Index: DOCS/man/en/mplayer.1
===================================================================
RCS file: /cvsroot/mplayer/main/DOCS/man/en/mplayer.1,v
retrieving revision 1.1075
diff -u -r1.1075 mplayer.1
--- DOCS/man/en/mplayer.1	23 Aug 2005 19:27:18 -0000	1.1075
+++ DOCS/man/en/mplayer.1	27 Aug 2005 16:48:47 -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
Index: libmpcodecs/dec_audio.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/dec_audio.c,v
retrieving revision 1.43
diff -u -r1.43 dec_audio.c
--- libmpcodecs/dec_audio.c	25 Aug 2005 18:22:12 -0000	1.43
+++ libmpcodecs/dec_audio.c	27 Aug 2005 16:49:48 -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++)
Index: libmpcodecs/dec_video.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/dec_video.c,v
retrieving revision 1.161
diff -u -r1.161 dec_video.c
--- libmpcodecs/dec_video.c	20 Jun 2005 23:07:35 -0000	1.161
+++ libmpcodecs/dec_video.c	27 Aug 2005 16:49:50 -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++)
Index: libmpdemux/demuxer.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demuxer.c,v
retrieving revision 1.199
diff -u -r1.199 demuxer.c
--- libmpdemux/demuxer.c	26 Aug 2005 17:40:01 -0000	1.199
+++ libmpdemux/demuxer.c	27 Aug 2005 16:50:48 -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);
Index: libmpdemux/demuxer.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demuxer.h,v
retrieving revision 1.80
diff -u -r1.80 demuxer.h
--- libmpdemux/demuxer.h	26 Aug 2005 17:40:02 -0000	1.80
+++ libmpdemux/demuxer.h	27 Aug 2005 16:50:48 -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);


More information about the MPlayer-dev-eng mailing list