[Mplayer-dev-eng] Large file support patch
Stephen Davies
steve at daviesfam.org
Tue Jul 3 15:10:27 CEST 2001
Hi,
Here's my patch to support large files in mplayer.
I've added an --enable-largefiles switch to configure to enable it; by
default it's turned off.
The patch essentially makes sure that all variables and structures holding
file offsets are type off_t, and uses the _LARGEFILE_SOURCE and
_FILE_OFFSET_BITS defines to enable glibc's 64 bit offset support.
With these, off_t is 64bits, without them it is 32bit.
Its tested and works nicely for mpegs. I haven't tested ASF files though
I think if made the right changes (anyone have a large asf?). I haven't
changed the AVI seeking code - if I'm not mistaken they can't be larger
than 2GB anyway.
My system in Mandrake 8 originally; glibc 2.1.3.
Let me know if this patch is of interest, any issues with it please let me
know.
Regards,
Steve
diff -U3 -rN main.b4changes/configure main/configure
--- main.b4changes/configure Fri Jun 29 11:45:00 2001
+++ main/configure Tue Jul 3 13:17:55 2001
@@ -6,6 +6,9 @@
#
# Changes in reversed order:
#
+# 2001/07/03 by Steve Davies
+# - added --enable-largefiles
+#
# 2001/06/05 by Pontscho
# - added alsa and esd detection
#
@@ -101,6 +104,7 @@
--prefix=DIR use this prefix for installing mplayer [/usr/local]
--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]
@@ -764,6 +768,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`
;;
@@ -1282,6 +1289,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
diff -U3 -rN main.b4changes/demuxer.c main/demuxer.c
--- main.b4changes/demuxer.c Mon Jun 4 00:34:59 2001
+++ main/demuxer.c Tue Jul 3 13:27:33 2001
@@ -1,5 +1,8 @@
//=================== DEMUXER v2.5 =========================
+#include <sys/types.h>
+#include <sys/stat.h>
+
#include <stdio.h>
#include <stdlib.h>
@@ -65,12 +68,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=%qd [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,(long long)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;
@@ -245,4 +248,3 @@
return len;
}
}
-
diff -U3 -rN main.b4changes/demuxer.h main/demuxer.h
--- main.b4changes/demuxer.h Mon Jun 4 00:34:59 2001
+++ main/demuxer.h Tue Jul 3 13:27:41 2001
@@ -16,10 +16,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;
@@ -32,8 +33,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)
//---------------
@@ -54,12 +55,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 endpos; // input stream end pos. (return EOF fi filepos>endpos)
int type; // mpeg system stream, mpeg elementary s., avi raw, avi indexed
// 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;
@@ -67,6 +68,7 @@
// index:
// AVIINDEXENTRY* idx;
+// FIXME: off_t???
void* idx;
int idx_size;
int idx_pos;
@@ -102,12 +104,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 -rN main.b4changes/mplayer.c main/mplayer.c
--- main.b4changes/mplayer.c Sat Jun 30 23:17:14 2001
+++ main/mplayer.c Tue Jul 3 13:40:37 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>
#if defined(sun)
#define DEFAULT_CDROM_DEVICE "/vol/dev/aliases/cdrom0"
@@ -312,7 +313,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;
//int has_video=1;
int audio_format=0; // override
@@ -684,7 +685,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");
@@ -699,6 +700,10 @@
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
+ fprintf(stderr, "File size is %qd bytes\n", (long long)len);
stream=new_stream(f,STREAMTYPE_FILE);
stream->end_pos=len;
#ifdef STREAMING
@@ -2202,6 +2207,7 @@
switch(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;
@@ -2324,12 +2330,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);
@@ -2359,14 +2367,14 @@
case DEMUXER_TYPE_MPEG_ES:
case DEMUXER_TYPE_MPEG_PS: {
//================= seek in MPEG ==========================
- int newpos;
+ off_t newpos;
if(picture->bitrate==0x3FFFF) // unspecified?
newpos=demuxer->filepos+2324*75*rel_seek_secs; // 174.3 kbyte/sec
else
newpos=demuxer->filepos+(picture->bitrate*1000/16)*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:
videobuf_code_len=0; // reset ES stream buffer
diff -U3 -rN main.b4changes/stream.c main/stream.c
--- main.b4changes/stream.c Thu Jun 21 01:06:40 2001
+++ main/stream.c Mon Jul 2 14:39:12 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,14 @@
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%qX\n",(long long)pos);
if(verbose>=3){
- printf("s->pos=%X newpos=%X new_bufpos=%X buflen=%X \n",
- (unsigned int)s->pos,newpos,pos,s->buf_len);
+ printf("s->pos=%qX newpos=%qX new_bufpos=%qX buflen=%X \n",
+ (long long)s->pos,(long long)newpos,(long long)pos,s->buf_len);
}
s->buf_pos=s->buf_len=0;
@@ -55,7 +60,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 +102,7 @@
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);
+ if(verbose) printf("stream_seek: WARNING! Can't seek to 0x%qX !\n",(long long)(pos+newpos));
return 0;
}
diff -U3 -rN main.b4changes/stream.h main/stream.h
--- main.b4changes/stream.h Mon Jun 4 18:51:17 2001
+++ main/stream.h Mon Jul 2 15:06:12 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);
_______________________________________________
Mplayer-dev-eng mailing list
Mplayer-dev-eng at lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/mplayer-dev-eng
More information about the MPlayer-dev-eng
mailing list