changeset 14198:5558b7dfb4b1

fix position bar and length display for mov files
author reimar
date Tue, 21 Dec 2004 12:27:38 +0000
parents 2ae224195625
children c33462832c3a
files ChangeLog libmpdemux/demux_mov.c
diffstat 2 files changed, 51 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Tue Dec 21 12:25:59 2004 +0000
+++ b/ChangeLog	Tue Dec 21 12:27:38 2004 +0000
@@ -78,6 +78,7 @@
     * improved seeking precision in MPEG files
     * better subtitle language code handling for MKV files
     * support DVHS files and H.264 over MPEG-TS
+    * display length and position (in the seekbar) for mov files
 
     Streaming:
     * -cache-min and -cache-prefill options added
--- a/libmpdemux/demux_mov.c	Tue Dec 21 12:25:59 2004 +0000
+++ b/libmpdemux/demux_mov.c	Tue Dec 21 12:27:38 2004 +0000
@@ -1696,6 +1696,18 @@
     return 1;
 }
 
+/**
+ * \brief return the mov track that belongs to a demuxer stream
+ * \param ds the demuxer stream, may be NULL
+ * \return the mov track info structure belonging to the stream,
+ *          NULL if not found
+ */
+static mov_track_t *stream_track(mov_priv_t *priv, demux_stream_t *ds) {
+  if (ds && (ds->id >= 0) && (ds->id < priv->track_db))
+    return priv->tracks[ds->id];
+  return NULL;
+}
+
 // return value:
 //     0 = EOF or no stream found
 //     1 = successfully read a packet
@@ -1706,8 +1718,8 @@
     int x;
     off_t pos;
     
-    if(ds->id<0 || ds->id>=priv->track_db) return 0;
-    trak=priv->tracks[ds->id];
+    trak = stream_track(priv, ds);
+    if (!trak) return 0;
 
 if(trak->samplesize){
     // read chunk:
@@ -1835,12 +1847,13 @@
 void demux_seek_mov(demuxer_t *demuxer,float pts,int flags){
     mov_priv_t* priv=demuxer->priv;
     demux_stream_t* ds;
+    mov_track_t* trak;
 
 //    printf("MOV seek called  %5.3f  flag=%d  \n",pts,flags);
     
     ds=demuxer->video;
-    if(ds && ds->id>=0 && ds->id<priv->track_db){
-	mov_track_t* trak=priv->tracks[ds->id];
+    trak = stream_track(priv, ds);
+    if (trak) {
 	//if(flags&2) pts*=(float)trak->length/(float)trak->timescale;
 	//if(!(flags&1)) pts+=ds->pts;
 	pts=ds->pts=mov_seek_track(trak,pts,flags);
@@ -1848,8 +1861,8 @@
     }
 
     ds=demuxer->audio;
-    if(ds && ds->id>=0 && ds->id<priv->track_db){
-	mov_track_t* trak=priv->tracks[ds->id];
+    trak = stream_track(priv, ds);
+    if (trak) {
 	//if(flags&2) pts*=(float)trak->length/(float)trak->timescale;
 	//if(!(flags&1)) pts+=ds->pts;
 	ds->pts=mov_seek_track(trak,pts,flags);
@@ -1857,3 +1870,34 @@
 
 }
 
+int demux_mov_control(demuxer_t *demuxer, int cmd, void *arg){
+  mov_track_t* track;
+
+  // try the video track
+  track = stream_track(demuxer->priv, demuxer->video);
+  if (!track || !track->length)
+    // otherwise try to get the info from the audio track
+    track = stream_track(demuxer->priv, demuxer->audio);
+
+  if (!track || !track->length)
+    return DEMUXER_CTRL_DONTKNOW;
+
+  switch(cmd) {
+    case DEMUXER_CTRL_GET_TIME_LENGTH:
+      if (!track->timescale)
+        return DEMUXER_CTRL_DONTKNOW;
+      *((unsigned long *)arg) = track->length / track->timescale;
+      return DEMUXER_CTRL_OK;
+
+    case DEMUXER_CTRL_GET_PERCENT_POS:
+      {
+        off_t pos = track->pos;
+        if (track->durmap_size >= 1)
+          pos *= track->durmap[0].dur;
+        *((int *)arg) = (int)(100 * pos / track->length);
+        return DEMUXER_CTRL_OK;
+      }
+  }
+  return DEMUXER_CTRL_NOTIMPL;
+}
+