[Mplayer-dev-eng] Largefiles patch

Stephen Davies steve at daviesfam.org
Tue Jul 31 21:31:11 CEST 2001


Hi,

Here's my largefiles patch again; against today's CVS.

I removed the %qd's, mostly.  Where I thought they should stay, I ifdeffed
for _LARGEFILE_SOURCE.  And replaced %qd with %lld - I see that "q" is
deprecated in the printf man page.

Your comments and I'll make a final tweak if necessary.

Steve

-------------- next part --------------
diff -U3 -r main.orig/configure main/configure
--- main.orig/configure	Mon Jul 30 15:53:07 2001
+++ main/configure	Tue Jul 31 14:54:43 2001
@@ -6,6 +6,9 @@
 #
 # Changes in reversed order:
 #
+# 2001/07/31 by Steve Davies
+# - added --enable-largefiles
+#
 # 2001/07/12 by Juergen Keil
 #  - add support for non-x86 targets
 #  - add autoconf checks for loader/wine
@@ -122,6 +125,7 @@
 				data [/usr/local/share/mplayer] 
 	--enable-debug[=1-3]	compile debugging information into mplayer [disable]
 	--enable-profile	compile profiling information into mplayer [disable]
+	--enable-largefiles	build with support for files >2^32 bytes long [disable]
         --enable-mmx            build with mmx support [autodetect]
         --enable-mmx2           build with mmx2 support (PIII, Athlon) [autodetect]
         --enable-3dnow          build with 3dnow! support [autodetect]
@@ -959,6 +963,9 @@
   --enable-debug)
   	_debug='-g'
 	;;
+  --enable-largefiles)
+	_largefiles=yes
+	;;
   --enable-debug=*)
         _debug=`echo $_echo_n '-g'$_echo_c; echo $ac_option | cut -d '=' -f 2`
 	;;
@@ -1569,6 +1576,11 @@
 # for MT applications: 
 if [ "$system_name" = "FreeBSD" ]; then
 CFLAGS="$CFLAGS -D_THREAD_SAFE"
+fi
+
+# 64 bit file offsets?
+if [ "$_largefiles" = "yes" ]; then
+CFLAGS="$CFLAGS -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
 fi
 
 # echo 'CFLAGS=$(OPTFLAGS) -Wall -DMPG12PLAY' >> config.mak
diff -U3 -r main.orig/demuxer.c main/demuxer.c
--- main.orig/demuxer.c	Sun Jul 29 22:07:34 2001
+++ main/demuxer.c	Tue Jul 31 14:27:11 2001
@@ -1,5 +1,8 @@
 //=================== DEMUXER v2.5 =========================
 
+#include <sys/types.h>
+#include <sys/stat.h>
+
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -96,12 +99,12 @@
       ds->first=ds->last=dp;
     }
     if(verbose>=2)
-      printf("DEMUX: Append packet to %s, len=%d  pts=%5.3f  pos=%d  [packs: A=%d V=%d]\n",
+      printf("DEMUX: Append packet to %s, len=%d  pts=%5.3f  pos=%u  [packs: A=%d V=%d]\n",
         (ds==ds->demuxer->audio)?"d_audio":"d_video",
-        dp->len,dp->pts,dp->pos,ds->demuxer->audio->packs,ds->demuxer->video->packs);
+        dp->len,dp->pts,(unsigned int)dp->pos,ds->demuxer->audio->packs,ds->demuxer->video->packs);
 }
 
-void ds_read_packet(demux_stream_t *ds,stream_t *stream,int len,float pts,int pos,int flags){
+void ds_read_packet(demux_stream_t *ds,stream_t *stream,int len,float pts,off_t pos,int flags){
     demux_packet_t* dp=new_demux_packet(len);
     stream_read(stream,dp->buffer,len);
     dp->pts=pts; //(float)pts/90000.0f;
@@ -574,4 +577,3 @@
 demuxer->file_format=file_format;
 return demuxer;
 }
-
diff -U3 -r main.orig/demuxer.h main/demuxer.h
--- main.orig/demuxer.h	Sat Jul 21 23:36:39 2001
+++ main/demuxer.h	Tue Jul 31 14:05:42 2001
@@ -18,10 +18,11 @@
 #define DEMUXER_TIME_BPS 3
 
 
+// Holds one packet/frame/whatever
 typedef struct demux_packet_st {
   int len;
   float pts;
-  int pos;  // pozicio indexben (AVI) ill. fileban (MPG)
+  off_t pos;  // pozicio indexben (AVI) ill. fileban (MPG)
   unsigned char* buffer;
   int flags; // keyframe, etc
   struct demux_packet_st* next;
@@ -34,8 +35,8 @@
   float pts;               // current buffer's pts
   int pts_bytes;           // number of bytes read after last pts stamp
   int eof;                 // end of demuxed stream? (true if all buffer empty)
-  int pos;                 // position in the input stream (file)
-  int dpos;                // position in the demuxed stream
+  off_t pos;                 // position in the input stream (file)
+  off_t dpos;                // position in the demuxed stream
   int pack_no;		   // serial number of packet
   int flags;               // flags of current packet (keyframe etc)
 //---------------
@@ -55,12 +56,12 @@
 typedef struct demuxer_st {
   stream_t *stream;
   int synced;  // stream synced (used by mpeg)
-  int filepos; // input stream current pos.
+  off_t filepos; // input stream current pos.
   int type;    // demuxer type: mpeg PS, mpeg ES, avi, avi-ni, avi-nini, asf
   int file_format;  // file format: mpeg/avi/asf
 //  int time_src;// time source (pts/file/bps)
-  unsigned int movi_start;
-  unsigned int movi_end;
+  off_t movi_start;
+  off_t movi_end;
   //
   demux_stream_t *audio;
   demux_stream_t *video;
@@ -68,6 +69,7 @@
 
   // index:
 //  AVIINDEXENTRY* idx;
+// FIXME: off_t???
   void* idx;
   int idx_size;
   int idx_pos;
@@ -103,12 +105,12 @@
 demuxer_t* new_demuxer(stream_t *stream,int type,int a_id,int v_id,int s_id);
 
 void ds_add_packet(demux_stream_t *ds,demux_packet_t* dp);
-void ds_read_packet(demux_stream_t *ds,stream_t *stream,int len,float pts,int pos,int flags);
+void ds_read_packet(demux_stream_t *ds,stream_t *stream,int len,float pts,off_t pos,int flags);
 
 int demux_fill_buffer(demuxer_t *demux,demux_stream_t *ds);
 int ds_fill_buffer(demux_stream_t *ds);
 
-inline static int ds_tell(demux_stream_t *ds){
+inline static off_t ds_tell(demux_stream_t *ds){
   return (ds->dpos-ds->buffer_size)+ds->buffer_pos;
 }
 
diff -U3 -r main.orig/mplayer.c main/mplayer.c
--- main.orig/mplayer.c	Mon Jul 30 03:00:54 2001
+++ main/mplayer.c	Tue Jul 31 14:33:43 2001
@@ -1,24 +1,25 @@
 // AVI & MPEG Player    v0.18   (C) 2000-2001. by A'rpi/ESP-team
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <signal.h>
+#include "version.h"
+#include "config.h"
 
 #include <sys/ioctl.h>
-#include <unistd.h>
-#include <time.h>
 #include <sys/mman.h>
-
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <sys/time.h>
 #include <sys/stat.h>
+
+#include <signal.h>
+
+#include <time.h>
+
 #include <fcntl.h>
+#include <unistd.h>
 
-#include "version.h"
-#include "config.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 
 #ifdef __FreeBSD__
 #include <sys/cdrio.h>
@@ -227,7 +228,7 @@
 int osd_level=2;
 int divx_quality=0;
 char *seek_to_sec=NULL;
-int seek_to_byte=0;
+off_t seek_to_byte=0;
 int has_audio=1;
 char *audio_codec=NULL; // override audio codec
 char *video_codec=NULL; // override video codec
@@ -641,7 +642,7 @@
   stream->end_pos=ret2;
 } else {
 //============ Open plain FILE ============
-  int len;
+  off_t len;
   if(!strcmp(filename,"-")){
       // read from stdin
       printf("Reading from stdin...\n");
@@ -656,6 +657,14 @@
        f=open(filename,O_RDONLY);
        if(f<0){ fprintf(stderr,"File not found: '%s'\n",filename);return 1; }
        len=lseek(f,0,SEEK_END); lseek(f,0,SEEK_SET);
+       if (len == -1)
+	 perror("Error: lseek failed to obtain video file size");
+       else
+#ifdef _LARGEFILE_SOURCE
+	 fprintf(stderr, "File size is %lld bytes\n", (long long)len);
+#else
+	 fprintf(stderr, "File size is %u bytes\n", (unsigned int)len);
+#endif
        stream=new_stream(f,STREAMTYPE_FILE);
        stream->end_pos=len;
 #ifdef STREAMING
diff -U3 -r main.orig/seek.c main/seek.c
--- main.orig/seek.c	Sun Jul 29 22:07:34 2001
+++ main/seek.c	Tue Jul 31 14:03:27 2001
@@ -58,6 +58,7 @@
 
 switch(demuxer->file_format){
 
+  //FIXME: OFF_T - Didn't check AVI case yet (avi files can't be >2G anyway?)
   case DEMUXER_TYPE_AVI: {
   //================= seek in AVI ==========================
     int rel_seek_frames=rel_seek_secs*sh_video->fps;
@@ -187,12 +188,14 @@
   }
   break;
 
+  //FIXME: OFF_T - didn't test ASF case yet (don't have a large asf...)
+  //FIXME: reports good or bad to steve at daviesfam.org please
   case DEMUXER_TYPE_ASF: {
   //================= seek in ASF ==========================
     float p_rate=10; // packets / sec
-    int rel_seek_packs=rel_seek_secs*p_rate;
-    int rel_seek_bytes=rel_seek_packs*asf_packetsize;
-    int newpos;
+    off_t rel_seek_packs=rel_seek_secs*p_rate; // FIXME: int may be enough?
+    off_t rel_seek_bytes=rel_seek_packs*asf_packetsize;
+    off_t newpos;
     //printf("ASF: packs: %d  duration: %d  \n",(int)fileh.packets,*((int*)&fileh.duration));
 //    printf("ASF_seek: %d secs -> %d packs -> %d bytes  \n",
 //       rel_seek_secs,rel_seek_packs,rel_seek_bytes);
@@ -228,14 +231,14 @@
   case DEMUXER_TYPE_MPEG_ES:
   case DEMUXER_TYPE_MPEG_PS: {
   //================= seek in MPEG ==========================
-        int newpos;
+        off_t newpos;
         if(!sh_video->i_bps) // unspecified?
           newpos=demuxer->filepos+2324*75*rel_seek_secs; // 174.3 kbyte/sec
         else
           newpos=demuxer->filepos+(sh_video->i_bps)*rel_seek_secs;
 
         if(newpos<seek_to_byte) newpos=seek_to_byte;
-        newpos&=~(STREAM_BUFFER_SIZE-1);  /* sector boundary */
+        newpos&=~((long long)STREAM_BUFFER_SIZE-1);  /* sector boundary */
         stream_seek(demuxer->stream,newpos);
 
         // re-sync video:
diff -U3 -r main.orig/stream.c main/stream.c
--- main.orig/stream.c	Thu Jun 21 01:06:40 2001
+++ main/stream.c	Tue Jul 31 14:43:26 2001
@@ -1,10 +1,15 @@
 
-#include <stdio.h>
-#include <stdlib.h>
+#include "config.h"
 
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <sys/ioctl.h>
+#include <fcntl.h>
 #include <unistd.h>
 
+#include <stdio.h>
+#include <stdlib.h>
+
 #include "stream.h"
 
 extern int verbose; // defined in mplayer.c
@@ -40,14 +45,19 @@
   return len;
 }
 
-int stream_seek_long(stream_t *s,unsigned int pos){
-unsigned int newpos;
+int stream_seek_long(stream_t *s,off_t pos){
+off_t newpos;
 
-//  if(verbose>=3) printf("seek to 0x%X\n",pos);
+//  if(verbose>=3) printf("seek to 0x%X\n",(unsigned int)pos);
 
 if(verbose>=3){
+#ifdef _LARGEFILE_SOURCE
+  printf("s->pos=%llX  newpos=%llX  new_bufpos=%llX  buflen=%X  \n",
+    (long long)s->pos,(long long)newpos,(long long)pos,s->buf_len);
+#else
   printf("s->pos=%X  newpos=%X  new_bufpos=%X  buflen=%X  \n",
     (unsigned int)s->pos,newpos,pos,s->buf_len);
+#endif
 }
 
   s->buf_pos=s->buf_len=0;
@@ -55,7 +65,7 @@
   switch(s->type){
   case STREAMTYPE_FILE:
   case STREAMTYPE_STREAM:
-    newpos=pos&(~(STREAM_BUFFER_SIZE-1));break;
+    newpos=pos&(~((long long)STREAM_BUFFER_SIZE-1));break;
   case STREAMTYPE_VCD:
     newpos=(pos/VCD_SECTOR_DATA)*VCD_SECTOR_DATA;break;
   }
@@ -97,7 +107,11 @@
     s->buf_pos=pos; // byte position in sector
     return 1;
   }
-  if(verbose) printf("stream_seek: WARNING! Can't seek to 0x%X !\n",pos+newpos);
+#ifdef _LARGEFILE_SOURCE
+  if(verbose) printf("stream_seek: WARNING! Can't seek to 0x%llX !\n",(long long)(pos+newpos));
+#else
+  if(verbose) printf("stream_seek: WARNING! Can't seek to 0x%X !\n",(pos+newpos));
+#endif
   return 0;
 }
 
diff -U3 -r main.orig/stream.h main/stream.h
--- main.orig/stream.h	Mon Jun  4 18:51:17 2001
+++ main/stream.h	Tue Jul 31 13:53:16 2001
@@ -20,16 +20,17 @@
 
 typedef struct {
   int fd;
-  long pos;
+  off_t pos;
   int eof;
   int type; // 0=file 1=VCD
   unsigned int buf_pos,buf_len;
-  long start_pos,end_pos;
+  off_t start_pos,end_pos;
   unsigned char buffer[STREAM_BUFFER_SIZE>VCD_SECTOR_SIZE?STREAM_BUFFER_SIZE:VCD_SECTOR_SIZE];
 } stream_t;
 
 int stream_fill_buffer(stream_t *s);
-int stream_seek_long(stream_t *s,unsigned int pos);
+
+int stream_seek_long(stream_t *s,off_t pos);
 
 inline static int stream_read_char(stream_t *s){
   return (s->buf_pos<s->buf_len)?s->buffer[s->buf_pos++]:
@@ -91,16 +92,16 @@
   return s->eof;
 }
 
-inline static int stream_tell(stream_t *s){
+inline static off_t stream_tell(stream_t *s){
   return s->pos+s->buf_pos-s->buf_len;
 }
 
-inline static int stream_seek(stream_t *s,unsigned int pos){
+inline static int stream_seek(stream_t *s,off_t pos){
 
-//  if(verbose>=3) printf("seek to 0x%X\n",pos);
+//  if(verbose>=3) printf("seek to 0x%qX\n",(long long)pos);
 
   if(pos<s->pos){
-    int x=pos-(s->pos-s->buf_len);
+    off_t x=pos-(s->pos-s->buf_len);
     if(x>=0){
       s->buf_pos=x;
 //      putchar('*');fflush(stdout);


More information about the MPlayer-dev-eng mailing list