[Mplayer-cvslog] CVS: main/libmpdemux demuxer.h,1.64,1.65 demux_avi.c,1.57,1.58 aviheader.c,1.50,1.51

Alex Beregszaszi alex at mplayerhq.hu
Wed Oct 22 21:01:50 CEST 2003


Update of /cvsroot/mplayer/main/libmpdemux
In directory mail:/var/tmp.root/cvs-serv2994/libmpdemux

Modified Files:
	demuxer.h demux_avi.c aviheader.c 
Log Message:
Saving and loading external index file. Patch by Jason Tackaberry <tack at auc.ca>

Index: demuxer.h
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demuxer.h,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -r1.64 -r1.65
--- demuxer.h	29 Aug 2003 08:03:56 -0000	1.64
+++ demuxer.h	22 Oct 2003 19:01:37 -0000	1.65
@@ -265,6 +265,7 @@
 
 // AVI demuxer params:
 extern int index_mode;  // -1=untouched  0=don't use index  1=use (geneate) index
+extern char *index_file_save, *index_file_load;
 extern int force_ni;
 extern int pts_from_bps;
 

Index: demux_avi.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demux_avi.c,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -r1.57 -r1.58
--- demux_avi.c	27 Aug 2003 22:30:54 -0000	1.57
+++ demux_avi.c	22 Oct 2003 19:01:37 -0000	1.58
@@ -425,6 +425,7 @@
 
 // AVI demuxer parameters:
 int index_mode=-1;  // -1=untouched  0=don't use index  1=use (geneate) index
+char *index_file_save = NULL, *index_file_load = NULL;
 int force_ni=0;     // force non-interleaved AVI parsing
 
 void read_avi_header(demuxer_t *demuxer,int index_mode);

Index: aviheader.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/aviheader.c,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -r1.50 -r1.51
--- aviheader.c	1 Nov 2002 17:46:43 -0000	1.50
+++ aviheader.c	22 Oct 2003 19:01:37 -0000	1.51
@@ -2,6 +2,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <errno.h>
 
 #include "config.h"
 #include "mp_msg.h"
@@ -44,6 +45,9 @@
   char* hdr=NULL;
   //
   if(stream_eof(demuxer->stream)) break;
+  // Imply -forceidx if -saveidx is specified
+  if (index_file_save)
+    index_mode = 2;
   //
   if(id==mmioFOURCC('L','I','S','T')){
     unsigned len=stream_read_dword_le(demuxer->stream);   // list size
@@ -299,6 +303,44 @@
   
 }
 
+/* Read a saved index file */
+if (index_file_load) {
+  FILE *fp;
+  char magic[7];
+  unsigned int i;
+
+  if ((fp = fopen(index_file_load, "r")) == NULL) {
+    mp_msg(MSGT_HEADER,MSGL_ERR, "Can't read index file %s: %s\n", index_file_load, strerror(errno));
+    goto gen_index;
+  }
+  fread(&magic, 6, 1, fp);
+  if (strncmp(magic, "MPIDX1", 6)) {
+    mp_msg(MSGT_HEADER,MSGL_ERR, "%s is not a valid MPlayer index file\n", index_file_load);
+    goto gen_index;
+  }
+  fread(&priv->idx_size, sizeof(priv->idx_size), 1, fp);
+  priv->idx=malloc(priv->idx_size*sizeof(AVIINDEXENTRY));
+  if (!priv->idx) {
+    mp_msg(MSGT_HEADER,MSGL_ERR, "Could not allocate memory for index data from %s\n", index_file_load);
+    priv->idx_size = 0;
+    goto gen_index;
+  }
+
+  for (i=0; i<priv->idx_size;i++) {
+    AVIINDEXENTRY *idx;
+    idx=&((AVIINDEXENTRY *)priv->idx)[i];
+    fread(idx, sizeof(AVIINDEXENTRY), 1, fp);
+    if (feof(fp)) {
+      mp_msg(MSGT_HEADER,MSGL_ERR, "Premature end of index file %s\n", index_file_load);
+      free(priv->idx);
+      priv->idx_size = 0;
+      goto gen_index;
+    }
+  }
+  fclose(fp);
+  mp_msg(MSGT_HEADER,MSGL_INFO, "Loaded index file: %s\n", index_file_load);
+}
+gen_index:
 if(index_mode>=2 || (priv->idx_size==0 && index_mode==1)){
   // build index for file:
   stream_reset(demuxer->stream);
@@ -381,8 +423,26 @@
   priv->idx_size=priv->idx_pos;
   mp_msg(MSGT_HEADER,MSGL_INFO,"AVI: Generated index table for %d chunks!\n",priv->idx_size);
   if(verbose>=2) print_index(priv->idx,priv->idx_size);
-}
 
+  /* Write generated index to a file */
+  if (index_file_save) {
+    FILE *fp;
+    unsigned int i;
+
+    if ((fp=fopen(index_file_save, "w")) == NULL) {
+      mp_msg(MSGT_HEADER,MSGL_ERR, "Couldn't write index file %s: %s\n", index_file_save, strerror(errno));
+      return;
+    }
+    fwrite("MPIDX1", 6, 1, fp);
+    fwrite(&priv->idx_size, sizeof(priv->idx_size), 1, fp);
+    for (i=0; i<priv->idx_size; i++) {
+      AVIINDEXENTRY *idx = &((AVIINDEXENTRY *)priv->idx)[i];
+      fwrite(idx, sizeof(AVIINDEXENTRY), 1, fp);
+    }
+    fclose(fp);
+    mp_msg(MSGT_HEADER,MSGL_INFO, "Saved index file: %s\n", index_file_save);
+  }
+}
 }
 
 #undef MIN



More information about the MPlayer-cvslog mailing list