From bbc9fccd46de31bacdf132762a7c0d1f8a4caf53 Mon Sep 17 00:00:00 2001 From: mplayer-svn Date: Sun, 4 Mar 2012 14:37:31 +0000 Subject: cache2: allow cache sizes up to 4 TB Remove variable that is only assigned but never used. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@34791 b3059339-0415-0410-9bf9-f77b7e298cf2 Allow using a cache size of up to 4 TB. Obviously anything close to 4 GB will always fail on 32 bit systems. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@34792 b3059339-0415-0410-9bf9-f77b7e298cf2 Replace off_t by int64_t in cache code. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@34793 b3059339-0415-0410-9bf9-f77b7e298cf2 Remove casts that are no longer necessary. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@34794 b3059339-0415-0410-9bf9-f77b7e298cf2 Fix header file after r34793. Patch by Stephen Sheldon, sfsheldo gmail com. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@34802 b3059339-0415-0410-9bf9-f77b7e298cf2 Put #include into the header file where it should be. Reported by Stephen Sheldon, sfsheldo gmail com. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@34798 b3059339-0415-0410-9bf9-f77b7e298cf2 Correct r34798. The header only needs stdint.h while the C file needs inttypes.h. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@34799 b3059339-0415-0410-9bf9-f77b7e298cf2 Author: reimar --- stream/cache2.c | 55 ++++++++++++++++++++++++++++--------------------------- stream/stream.h | 4 ++-- 2 files changed, 30 insertions(+), 29 deletions(-) (limited to 'stream') diff --git a/stream/cache2.c b/stream/cache2.c index b69a3ee8c7..b6bdd10b25 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -65,21 +65,21 @@ static void *ThreadProc(void *s); typedef struct { // constats: unsigned char *buffer; // base pointer of the allocated buffer memory - int buffer_size; // size of the allocated buffer memory + int64_t buffer_size; // size of the allocated buffer memory int sector_size; // size of a single sector (2048/2324) - int back_size; // we should keep back_size amount of old bytes for backward seek - int fill_limit; // we should fill buffer only if space>=fill_limit - int seek_limit; // keep filling cache if distance is less that seek limit + int64_t back_size; // we should keep back_size amount of old bytes for backward seek + int64_t fill_limit; // we should fill buffer only if space>=fill_limit + int64_t seek_limit; // keep filling cache if distance is less that seek limit #if FORKED_CACHE pid_t ppid; // parent PID to detect killed parent #endif // filler's pointers: int eof; - off_t min_filepos; // buffer contain only a part of the file, from min-max pos - off_t max_filepos; - off_t offset; // filepos <-> bufferpos offset value (filepos of the buffer's first byte) + int64_t min_filepos; // buffer contain only a part of the file, from min-max pos + int64_t max_filepos; + int64_t offset; // filepos <-> bufferpos offset value (filepos of the buffer's first byte) // reader's pointers: - off_t read_filepos; + int64_t read_filepos; // commands/locking: // int seek_lock; // 1 if we will seek/reset buffer, 2 if we are ready for cmd // int fifo_flag; // 1 if we should use FIFO to notice cache about buffer reads. @@ -93,8 +93,6 @@ typedef struct { volatile double stream_time_pos; } cache_vars_t; -static int min_fill=0; - static void cache_wakeup(stream_t *s) { #if FORKED_CACHE @@ -113,9 +111,9 @@ static int cache_read(cache_vars_t *s, unsigned char *buf, int size) { int total=0; int sleep_count = 0; - int last_max = s->max_filepos; + int64_t last_max = s->max_filepos; while(size>0){ - int pos,newb,len; + int64_t pos,newb,len; //printf("CACHE2_READ: 0x%X <= 0x%X <= 0x%X \n",s->min_filepos,s->read_filepos,s->max_filepos); @@ -139,7 +137,6 @@ static int cache_read(cache_vars_t *s, unsigned char *buf, int size) sleep_count = 0; newb=s->max_filepos-s->read_filepos; // new bytes in the buffer - if(newbread_filepos; + int64_t back,back2,newb,space,len,pos; + int64_t read=s->read_filepos; int read_chunk; int wraparound_copy = 0; if(readmin_filepos || read>s->max_filepos){ // seek... - mp_msg(MSGT_CACHE,MSGL_DBG2,"Out of boundaries... seeking to 0x%"PRIX64" \n",(int64_t)read); + mp_msg(MSGT_CACHE,MSGL_DBG2,"Out of boundaries... seeking to 0x%"PRIX64" \n",read); // drop cache contents only if seeking backward or too much fwd. // This is also done for on-disk files, since it loses the backseek cache. // That in turn can cause major bandwidth increase and performance @@ -328,7 +325,7 @@ static int cache_execute_control(cache_vars_t *s) { return 1; } -static void *shared_alloc(int size) { +static void *shared_alloc(int64_t size) { #if FORKED_CACHE return shmem_alloc(size); #else @@ -336,7 +333,7 @@ static void *shared_alloc(int size) { #endif } -static void shared_free(void *ptr, int size) { +static void shared_free(void *ptr, int64_t size) { #if FORKED_CACHE shmem_free(ptr, size); #else @@ -344,8 +341,8 @@ static void shared_free(void *ptr, int size) { #endif } -static cache_vars_t* cache_init(int size,int sector){ - int num; +static cache_vars_t* cache_init(int64_t size,int sector){ + int64_t num; cache_vars_t* s=shared_alloc(sizeof(cache_vars_t)); if(s==NULL) return NULL; @@ -435,7 +432,7 @@ static void cache_mainloop(cache_vars_t *s) { /** * \return 1 on success, 0 if the function was interrupted and -1 on error */ -int stream_enable_cache(stream_t *stream,int size,int min,int seek_limit){ +int stream_enable_cache(stream_t *stream,int64_t size,int64_t min,int64_t seek_limit){ int ss = stream->sector_size ? stream->sector_size : STREAM_BUFFER_SIZE; int res = -1; cache_vars_t* s; @@ -444,6 +441,10 @@ int stream_enable_cache(stream_t *stream,int size,int min,int seek_limit){ mp_msg(MSGT_CACHE,MSGL_STATUS,"\rThis stream is non-cacheable\n"); return 1; } + if (size > SIZE_MAX) { + mp_msg(MSGT_CACHE, MSGL_FATAL, "Cache size larger than max. allocation size\n"); + return -1; + } s=cache_init(size,ss); if(s == NULL) return -1; @@ -490,12 +491,12 @@ int stream_enable_cache(stream_t *stream,int size,int min,int seek_limit){ goto err_out; } // wait until cache is filled at least prefill_init % - mp_msg(MSGT_CACHE,MSGL_V,"CACHE_PRE_INIT: %"PRId64" [%"PRId64"] %"PRId64" pre:%d eof:%d \n", - (int64_t)s->min_filepos,(int64_t)s->read_filepos,(int64_t)s->max_filepos,min,s->eof); + mp_msg(MSGT_CACHE,MSGL_V,"CACHE_PRE_INIT: %"PRId64" [%"PRId64"] %"PRId64" pre:%"PRId64" eof:%d \n", + s->min_filepos,s->read_filepos,s->max_filepos,min,s->eof); while(s->read_fileposmin_filepos || s->max_filepos-s->read_fileposmax_filepos-s->read_filepos)/(float)(s->buffer_size), - (int64_t)s->max_filepos-s->read_filepos + s->max_filepos-s->read_filepos ); if(s->eof) break; // file is smaller than prefill size if(stream_check_interrupt(PREFILL_SLEEP_TIME)) { @@ -566,9 +567,9 @@ int cache_fill_status(stream_t *s) { return (cv->max_filepos-cv->read_filepos)/(cv->buffer_size / 100); } -int cache_stream_seek_long(stream_t *stream,off_t pos){ +int cache_stream_seek_long(stream_t *stream,int64_t pos){ cache_vars_t* s; - off_t newpos; + int64_t newpos; if(!stream->cache_pid) return stream_seek_long(stream,pos); s=stream->cache_data; @@ -592,7 +593,7 @@ int cache_stream_seek_long(stream_t *stream,off_t pos){ // stream->buf_pos=stream->buf_len=0; // return 1; - mp_msg(MSGT_CACHE,MSGL_V,"cache_stream_seek: WARNING! Can't seek to 0x%"PRIX64" !\n",(int64_t)(pos+newpos)); + mp_msg(MSGT_CACHE,MSGL_V,"cache_stream_seek: WARNING! Can't seek to 0x%"PRIX64" !\n",pos+newpos); return 0; } diff --git a/stream/stream.h b/stream/stream.h index 3ad65bb656..c34da4b61a 100644 --- a/stream/stream.h +++ b/stream/stream.h @@ -183,9 +183,9 @@ int stream_fill_buffer(stream_t *s); int stream_seek_long(stream_t *s, off_t pos); #ifdef CONFIG_STREAM_CACHE -int stream_enable_cache(stream_t *stream,int size,int min,int prefill); +int stream_enable_cache(stream_t *stream,int64_t size,int64_t min,int64_t prefill); int cache_stream_fill_buffer(stream_t *s); -int cache_stream_seek_long(stream_t *s,off_t pos); +int cache_stream_seek_long(stream_t *s,int64_t pos); #else // no cache, define wrappers: #define cache_stream_fill_buffer(x) stream_fill_buffer(x) -- cgit v1.2.3