changeset 14502:8769fa370f83

Move generic length and percent pos calculation to demuxer.c
author reimar
date Sat, 15 Jan 2005 16:11:45 +0000
parents 128f5f22f310
children af82f404a979
files libmpdemux/demux_asf.c libmpdemux/demux_avi.c libmpdemux/demux_mkv.c libmpdemux/demux_mpg.c libmpdemux/demux_ty.c libmpdemux/demuxer.c
diffstat 6 files changed, 14 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demux_asf.c	Sat Jan 15 16:08:04 2005 +0000
+++ b/libmpdemux/demux_asf.c	Sat Jan 15 16:11:45 2005 +0000
@@ -423,11 +423,7 @@
 	    return DEMUXER_CTRL_OK;
 
 	case DEMUXER_CTRL_GET_PERCENT_POS:
-	    if (demuxer->movi_end==demuxer->movi_start) {
 		return DEMUXER_CTRL_DONTKNOW;
-	    }
-    	    *((int *)arg)=(int)((demuxer->filepos-demuxer->movi_start)/((demuxer->movi_end-demuxer->movi_start)/100));
-	    return DEMUXER_CTRL_OK;
 
 	default:
 	    return DEMUXER_CTRL_NOTIMPL;
--- a/libmpdemux/demux_avi.c	Sat Jan 15 16:08:04 2005 +0000
+++ b/libmpdemux/demux_avi.c	Sat Jan 15 16:11:45 2005 +0000
@@ -846,9 +846,7 @@
 
 	case DEMUXER_CTRL_GET_PERCENT_POS:
     	    if (!priv->numberofframes) {
-		if (demuxer->movi_end==demuxer->movi_start) return DEMUXER_CTRL_DONTKNOW;
-		*((int *)arg)=(int)((demuxer->filepos-demuxer->movi_start)/((demuxer->movi_end-demuxer->movi_start)/100));
-		return DEMUXER_CTRL_OK; 
+              return DEMUXER_CTRL_DONTKNOW;
 	    }
 	    *((int *)arg)=(int)(priv->video_pack_no*100/priv->numberofframes);
 	    if (sh_video->video.dwLength<=1) return DEMUXER_CTRL_GUESS;
--- a/libmpdemux/demux_mkv.c	Sat Jan 15 16:08:04 2005 +0000
+++ b/libmpdemux/demux_mkv.c	Sat Jan 15 16:11:45 2005 +0000
@@ -3328,12 +3328,7 @@
     case DEMUXER_CTRL_GET_PERCENT_POS:
       if (mkv_d->duration == 0)
         {
-          if (demuxer->movi_start == demuxer->movi_end)
             return DEMUXER_CTRL_DONTKNOW;
-
-          *((int *)arg) = (int)((demuxer->filepos - demuxer->movi_start) /
-                                ((demuxer->movi_end-demuxer->movi_start)/100));
-          return DEMUXER_CTRL_OK;
         }
 
       *((int *) arg) = (int) (100 * mkv_d->last_pts / mkv_d->duration);
--- a/libmpdemux/demux_mpg.c	Sat Jan 15 16:08:04 2005 +0000
+++ b/libmpdemux/demux_mpg.c	Sat Jan 15 16:11:45 2005 +0000
@@ -520,20 +520,14 @@
               *((unsigned long *)arg)=(long)mpg_d->final_pts;
               return DEMUXER_CTRL_GUESS;
             }
-	    if(!sh_video || !sh_video->i_bps)  // unspecified or VBR 
     		return DEMUXER_CTRL_DONTKNOW;
-	    *((unsigned long *)arg)=(demuxer->movi_end-demuxer->movi_start)/sh_video->i_bps;
-	    return DEMUXER_CTRL_GUESS;
 
 	case DEMUXER_CTRL_GET_PERCENT_POS:
-	    if (demuxer->movi_end==demuxer->movi_start) 
-    		return DEMUXER_CTRL_DONTKNOW;
             if (mpg_d && mpg_d->has_valid_timestamps && mpg_d->final_pts > 0.0) {
               *((int *)arg)=(int)(100 * mpg_d->last_pts / mpg_d->final_pts);
               return DEMUXER_CTRL_OK;
             }
-    	    *((int *)arg)=(int)((demuxer->filepos-demuxer->movi_start)/((demuxer->movi_end-demuxer->movi_start)/100));
-	    return DEMUXER_CTRL_OK;
+	    return DEMUXER_CTRL_DONTKNOW;
 
 	default:
 	    return DEMUXER_CTRL_NOTIMPL;
--- a/libmpdemux/demux_ty.c	Sat Jan 15 16:08:04 2005 +0000
+++ b/libmpdemux/demux_ty.c	Sat Jan 15 16:11:45 2005 +0000
@@ -1027,12 +1027,7 @@
 	      return DEMUXER_CTRL_GUESS;
 
 	   case DEMUXER_CTRL_GET_PERCENT_POS:
-	      if (demuxer->movi_end==demuxer->movi_start) 
     		   return DEMUXER_CTRL_DONTKNOW;
-    	    *((int *)arg)=
-             (int)((demuxer->filepos-demuxer->movi_start)/
-             ((demuxer->movi_end-demuxer->movi_start)/100));
-	       return DEMUXER_CTRL_OK;
 	    default:
 	       return DEMUXER_CTRL_NOTIMPL;
     }
--- a/libmpdemux/demuxer.c	Sat Jan 15 16:08:04 2005 +0000
+++ b/libmpdemux/demuxer.c	Sat Jan 15 16:11:45 2005 +0000
@@ -1717,7 +1717,12 @@
 
 unsigned long demuxer_get_time_length(demuxer_t *demuxer){     
     unsigned long get_time_ans;     
+    sh_video_t *sh_video = demuxer->video->sh;
+    // <= 0 means DEMUXER_CTRL_NOTIMPL or DEMUXER_CTRL_DONTKNOW
     if (demux_control(demuxer, DEMUXER_CTRL_GET_TIME_LENGTH,(void *)&get_time_ans)<=0)  {
+      if (sh_video && sh_video->i_bps)
+        get_time_ans = (demuxer->movi_end-demuxer->movi_start)/sh_video->i_bps;
+      else
         get_time_ans=0;     
     }
     return get_time_ans;
@@ -1727,9 +1732,14 @@
     int ans = 0;
     int res = demux_control(demuxer, DEMUXER_CTRL_GET_PERCENT_POS, &ans);
     int len = (demuxer->movi_end - demuxer->movi_start) / 100;
-    if (res == DEMUXER_CTRL_NOTIMPL && len > 0)
+    if (res <= 0) {
+      if (len > 0)
       ans = (demuxer->filepos - demuxer->movi_start) / len;
-    if (ans>100 || ans<0) ans=0;
+      else
+       ans = 0;
+    }
+    if (ans < 0) ans = 0;
+    if (ans > 100) ans = 100;
     return ans;
 }