diff options
author | mplayer-svn <svn@mplayerhq.hu> | 2012-03-04 14:37:31 +0000 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2012-08-03 01:52:40 +0200 |
commit | bbc9fccd46de31bacdf132762a7c0d1f8a4caf53 (patch) | |
tree | 6890f6648aac93605336a76d7bc5d236e8ea4446 | |
parent | 0dce860f6c74df1c10351bd8bbbdcc406236925e (diff) | |
download | mpv-bbc9fccd46de31bacdf132762a7c0d1f8a4caf53.tar.bz2 mpv-bbc9fccd46de31bacdf132762a7c0d1f8a4caf53.tar.xz |
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 <inttypes.h> 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
-rw-r--r-- | cfg-mplayer.h | 2 | ||||
-rw-r--r-- | mplayer.c | 6 | ||||
-rw-r--r-- | osdep/shmem.c | 20 | ||||
-rw-r--r-- | osdep/shmem.h | 6 | ||||
-rw-r--r-- | stream/cache2.c | 55 | ||||
-rw-r--r-- | stream/stream.h | 4 |
6 files changed, 51 insertions, 42 deletions
diff --git a/cfg-mplayer.h b/cfg-mplayer.h index 29bdaaef53..9857443aa8 100644 --- a/cfg-mplayer.h +++ b/cfg-mplayer.h @@ -370,7 +370,7 @@ const m_option_t common_opts[] = { // ------------------------- stream options -------------------- #ifdef CONFIG_STREAM_CACHE - {"cache", &stream_cache_size, CONF_TYPE_INT, CONF_RANGE, 32, 1048576, NULL}, + {"cache", &stream_cache_size, CONF_TYPE_INT, CONF_RANGE, 32, 0x7fffffff, NULL}, {"no-cache", &stream_cache_size, CONF_TYPE_FLAG, 0, 1, 0, NULL}, OPT_FLOATRANGE("cache-min", stream_cache_min_percent, 0, 0, 99), OPT_FLOATRANGE("cache-seek-min", stream_cache_seek_min_percent, 0, 0, 99), @@ -3814,9 +3814,9 @@ goto_enable_cache: int res; float stream_cache_min_percent = opts->stream_cache_min_percent; float stream_cache_seek_min_percent = opts->stream_cache_seek_min_percent; - res = stream_enable_cache(mpctx->stream, stream_cache_size * 1024, - stream_cache_size * 1024 * (stream_cache_min_percent / 100.0), - stream_cache_size * 1024 * (stream_cache_seek_min_percent / 100.0)); + res = stream_enable_cache(mpctx->stream, stream_cache_size * 1024ull, + stream_cache_size * 1024ull * (stream_cache_min_percent / 100.0), + stream_cache_size * 1024ull * (stream_cache_seek_min_percent / 100.0)); if (res == 0) if (libmpdemux_was_interrupted(mpctx)) goto goto_next_file; diff --git a/osdep/shmem.c b/osdep/shmem.c index 02140b5756..56b5b301b5 100644 --- a/osdep/shmem.c +++ b/osdep/shmem.c @@ -36,6 +36,7 @@ #endif #include <sys/socket.h> #include <fcntl.h> +#include <inttypes.h> #include "mp_msg.h" @@ -56,16 +57,21 @@ static int shmem_type=0; -void* shmem_alloc(int size){ +void* shmem_alloc(int64_t size){ void* p; static int devzero = -1; +if (size > SIZE_MAX) { + mp_msg(MSGT_OSDEP, MSGL_FATAL, + "Shared memory allocation larger than system max. allocation size.\n"); + return NULL; +} while(1){ switch(shmem_type){ case 0: // ========= MAP_ANON|MAP_SHARED ========== #ifdef MAP_ANON p=mmap(0,size,PROT_READ|PROT_WRITE,MAP_ANON|MAP_SHARED,-1,0); if(p==MAP_FAILED) break; // failed - mp_dbg(MSGT_OSDEP, MSGL_DBG2, "shmem: %d bytes allocated using mmap anon (%p)\n",size,p); + mp_dbg(MSGT_OSDEP, MSGL_DBG2, "shmem: %"PRId64" bytes allocated using mmap anon (%p)\n",size,p); return p; #else // system does not support MAP_ANON at all (e.g. solaris 2.5.1/2.6), just fail @@ -76,7 +82,7 @@ while(1){ if (devzero == -1 && (devzero = open("/dev/zero", O_RDWR, 0)) == -1) break; p=mmap(0,size,PROT_READ|PROT_WRITE,MAP_SHARED,devzero,0); if(p==MAP_FAILED) break; // failed - mp_dbg(MSGT_OSDEP, MSGL_DBG2, "shmem: %d bytes allocated using mmap /dev/zero (%p)\n",size,p); + mp_dbg(MSGT_OSDEP, MSGL_DBG2, "shmem: %"PRId64" bytes allocated using mmap /dev/zero (%p)\n",size,p); return p; case 2: { // ========= shmget() ========== #ifdef HAVE_SHM @@ -93,7 +99,7 @@ while(1){ if (shmdt(p) == -1) perror ("shmdt()"); break; } - mp_dbg(MSGT_OSDEP, MSGL_DBG2, "shmem: %d bytes allocated using SHM (%p)\n",size,p); + mp_dbg(MSGT_OSDEP, MSGL_DBG2, "shmem: %"PRId64" bytes allocated using SHM (%p)\n",size,p); return p; #else mp_msg(MSGT_OSDEP, MSGL_FATAL, "shmem: no SHM support was compiled in!\n"); @@ -102,19 +108,19 @@ while(1){ } default: mp_msg(MSGT_OSDEP, MSGL_FATAL, - "FATAL: Cannot allocate %d bytes of shared memory :(\n",size); + "FATAL: Cannot allocate %"PRId64" bytes of shared memory :(\n",size); return NULL; } ++shmem_type; } } -void shmem_free(void* p,int size){ +void shmem_free(void* p,int64_t size){ switch(shmem_type){ case 0: case 1: if(munmap(p,size)) { - mp_msg(MSGT_OSDEP, MSGL_ERR, "munmap failed on %p %d bytes: %s\n", + mp_msg(MSGT_OSDEP, MSGL_ERR, "munmap failed on %p %"PRId64" bytes: %s\n", p,size,strerror(errno)); } break; diff --git a/osdep/shmem.h b/osdep/shmem.h index 7696e45281..1aa8382f09 100644 --- a/osdep/shmem.h +++ b/osdep/shmem.h @@ -19,7 +19,9 @@ #ifndef MPLAYER_SHMEM_H #define MPLAYER_SHMEM_H -void* shmem_alloc(int size); -void shmem_free(void* p,int size); +#include <stdint.h> + +void* shmem_alloc(int64_t size); +void shmem_free(void* p,int64_t size); #endif /* MPLAYER_SHMEM_H */ 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(newb<min_fill) min_fill=newb; // statistics... // printf("*** newb: %d bytes ***\n",newb); @@ -170,14 +167,14 @@ static int cache_read(cache_vars_t *s, unsigned char *buf, int size) static int cache_fill(cache_vars_t *s) { - int back,back2,newb,space,len,pos; - off_t read=s->read_filepos; + int64_t back,back2,newb,space,len,pos; + int64_t read=s->read_filepos; int read_chunk; int wraparound_copy = 0; if(read<s->min_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_filepos<s->min_filepos || s->max_filepos-s->read_filepos<min){ mp_tmsg(MSGT_CACHE,MSGL_STATUS,"\rCache fill: %5.2f%% (%"PRId64" bytes) ", 100.0*(float)(s->max_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) |