changeset 16612:e94616c973e3

Report total time
author reimar
date Tue, 27 Sep 2005 19:04:10 +0000
parents 9574fb378080
children 465ad78c43c9
files libmpdemux/demux_mpc.c
diffstat 1 files changed, 16 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demux_mpc.c	Tue Sep 27 11:21:13 2005 +0000
+++ b/libmpdemux/demux_mpc.c	Tue Sep 27 19:04:10 2005 +0000
@@ -23,6 +23,7 @@
   float last_pts;
   uint32_t dword;
   int pos;
+  float length;
 } da_priv_t;
 
 extern void free_sh_audio(sh_audio_t* sh);
@@ -70,6 +71,7 @@
 }
 
 static demuxer_t *demux_mpc_open(demuxer_t* demuxer) {
+  float seconds = 0;
   stream_t *s = demuxer->stream;
   sh_audio_t* sh_audio;
   da_priv_t* priv = demuxer->priv;
@@ -81,7 +83,6 @@
     char *header = &wf[sizeof(WAVEFORMATEX)];
     const int freqs[4] = {44100, 48000, 37800, 32000};
     int frames;
-    int seconds;
     sh_audio->format = mmioFOURCC('M', 'P', 'C', ' ');
     memcpy(header, priv, HDR_SIZE);
     free(priv);
@@ -92,8 +93,8 @@
     sh_audio->wf->nSamplesPerSec = freqs[header[10] & 3];
     sh_audio->wf->nBlockAlign = 32 * 36;
     sh_audio->wf->wBitsPerSample = 16;
-    seconds = 1152 * frames / sh_audio->wf->nSamplesPerSec;
-    if (demuxer->movi_end > demuxer->movi_start && seconds > 0)
+    seconds = 1152 * frames / (float)sh_audio->wf->nSamplesPerSec;
+    if (demuxer->movi_end > demuxer->movi_start && seconds > 1)
       sh_audio->wf->nAvgBytesPerSec = (demuxer->movi_end - demuxer->movi_start) / seconds;
     else
       sh_audio->wf->nAvgBytesPerSec = 32 * 1024; // dummy to make mencoder not hang
@@ -104,6 +105,7 @@
 
   priv = (da_priv_t *)malloc(sizeof(da_priv_t));
   priv->last_pts = -1;
+  priv->length = seconds;
   priv->dword = 0;
   priv->pos = 0;
   stream_read(s, (void *)&priv->dword, 4);
@@ -164,6 +166,17 @@
 }
 
 static int demux_mpc_control(demuxer_t *demuxer,int cmd, void *arg){
+  da_priv_t* priv = demuxer->priv;
+  switch (cmd) {
+    case DEMUXER_CTRL_GET_TIME_LENGTH:
+      if (priv->length < 1) return DEMUXER_CTRL_DONTKNOW;
+      *((double *)arg) = priv->length;
+      return DEMUXER_CTRL_OK;
+    case DEMUXER_CTRL_GET_PERCENT_POS:
+      if (priv->length < 1) return DEMUXER_CTRL_DONTKNOW;
+      *((int *)arg) = priv->last_pts * 100 / priv->length;
+      return DEMUXER_CTRL_OK;
+  }
   return DEMUXER_CTRL_NOTIMPL;
 }