changeset 20303:21dd6cf54fff

Try other demuxers if open() fails.
author reimar
date Thu, 19 Oct 2006 18:20:12 +0000
parents 2f7c26c86574
children c9c6db3c2645
files libmpdemux/demuxer.c
diffstat 1 files changed, 18 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demuxer.c	Thu Oct 19 18:08:44 2006 +0000
+++ b/libmpdemux/demuxer.c	Thu Oct 19 18:20:12 2006 +0000
@@ -668,36 +668,41 @@
         fformat = demuxer_desc->type;
       if (fformat != 0) {
         if (fformat == demuxer_desc->type) {
+          demuxer_t *demux2 = demuxer;
           // Move messages to demuxer detection code?
           mp_msg(MSGT_DEMUXER, MSGL_INFO, MSGTR_Detected_XXX_FileFormat, demuxer_desc->shortdesc);
           file_format = demuxer_desc->type = fformat;
+          if (!demuxer->desc->open || (demux2 = demuxer->desc->open(demuxer))) {
+            demuxer = demux2;
+            goto dmx_open;
+          }
         } else {
           // Format changed after check, recurse
           free_demuxer(demuxer);
           return demux_open_stream(stream, fformat, force,
                    audio_id, video_id, dvdsub_id, filename);
         }
-      } else {
+      }
         // Check failed for forced demuxer, quit
         free_demuxer(demuxer);
         return NULL;
-      }
     }
   }
 }
 
-if (demuxer)
-  goto dmx_open;
-
 // Test demuxers with safe file checks
 for (i = 0; (demuxer_desc = demuxer_list[i]); i++) {
   if (demuxer_desc->safe_check) {
     demuxer = new_demuxer(stream,demuxer_desc->type,audio_id,video_id,dvdsub_id,filename);
     if ((fformat = demuxer_desc->check_file(demuxer)) != 0) {
       if (fformat == demuxer_desc->type) {
+        demuxer_t *demux2 = demuxer;
         mp_msg(MSGT_DEMUXER, MSGL_INFO, MSGTR_Detected_XXX_FileFormat, demuxer_desc->shortdesc);
         file_format = fformat;
-        break;
+        if (!demuxer->desc->open || (demux2 = demuxer->desc->open(demuxer))) {
+          demuxer = demux2;
+          goto dmx_open;
+        }
       } else {
         if (fformat == DEMUXER_TYPE_PLAYLIST)
           return demuxer; // handled in mplayer.c
@@ -708,16 +713,12 @@
         if(demuxer) return demuxer; // done!
         file_format = DEMUXER_TYPE_UNKNOWN;
       }
-    } else {
+    }
       free_demuxer(demuxer);
       demuxer = NULL;
-    }
   }
 }
 
-if (demuxer)
-  goto dmx_open;
-
 // If no forced demuxer perform file extension based detection
 // Ok. We're over the stable detectable fileformats, the next ones are a bit
 // fuzzy. So by default (extension_parsing==1) try extension-based detection
@@ -740,9 +741,13 @@
     demuxer = new_demuxer(stream,demuxer_desc->type,audio_id,video_id,dvdsub_id,filename);
     if ((fformat = demuxer_desc->check_file(demuxer)) != 0) {
       if (fformat == demuxer_desc->type) {
+        demuxer_t *demux2 = demuxer;
         mp_msg(MSGT_DEMUXER, MSGL_INFO, MSGTR_Detected_XXX_FileFormat, demuxer_desc->shortdesc);
         file_format = fformat;
-        break;
+        if (!demuxer->desc->open || (demux2 = demuxer->desc->open(demuxer))) {
+          demuxer = demux2;
+          goto dmx_open;
+        }
       } else {
         if (fformat == DEMUXER_TYPE_PLAYLIST)
           return demuxer; // handled in mplayer.c
@@ -753,27 +758,18 @@
         if(demuxer) return demuxer; // done!
         file_format = DEMUXER_TYPE_UNKNOWN;
       }
-    } else {
+    }
       free_demuxer(demuxer);
       demuxer = NULL;
-    }
   }
 }
 
-//=============== Unknown, exiting... ===========================
-if(file_format==DEMUXER_TYPE_UNKNOWN || demuxer == NULL){
-  //mp_msg(MSGT_DEMUXER,MSGL_ERR,MSGTR_FormatNotRecognized); // will be done by mplayer.c after fallback to playlist-parsing
   return NULL;
-}
 //====== File format recognized, set up these for compatibility: =========
 dmx_open:
 
 demuxer->file_format=file_format;
 
-if (demuxer->desc->open)
-  if (!(demuxer = demuxer->desc->open(demuxer)))
-    return NULL;
-
 if ((sh_video=demuxer->video->sh) && sh_video->bih){
 int biComp=le2me_32(sh_video->bih->biCompression);
   mp_msg(MSGT_DEMUX,MSGL_INFO,"VIDEO:  [%.4s]  %dx%d  %dbpp  %5.3f fps  %5.1f kbps (%4.1f kbyte/s)\n",