diff stream/cache2.c @ 34704:cc658103f214

Allow using a cache size of up to 4 TB. Obviously anything close to 4 GB will always fail on 32 bit systems.
author reimar
date Sun, 04 Mar 2012 14:47:37 +0000
parents 4ccdcd1ff6ba
children ba926fab9550
line wrap: on
line diff
--- a/stream/cache2.c	Sun Mar 04 14:37:31 2012 +0000
+++ b/stream/cache2.c	Sun Mar 04 14:47:37 2012 +0000
@@ -70,11 +70,11 @@
 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
@@ -117,9 +117,9 @@
 {
   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);
 
@@ -173,7 +173,7 @@
 
 static int cache_fill(cache_vars_t *s)
 {
-  int back,back2,newb,space,len,pos;
+  int64_t back,back2,newb,space,len,pos;
   off_t read=s->read_filepos;
   int read_chunk;
   int wraparound_copy = 0;
@@ -334,7 +334,7 @@
   return 1;
 }
 
-static void *shared_alloc(int size) {
+static void *shared_alloc(int64_t size) {
 #if FORKED_CACHE
     return shmem_alloc(size);
 #else
@@ -342,7 +342,7 @@
 #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
@@ -350,8 +350,8 @@
 #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;
 
@@ -441,7 +441,7 @@
 /**
  * \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;
@@ -450,6 +450,10 @@
     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;
@@ -498,7 +502,7 @@
         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",
+    mp_msg(MSGT_CACHE,MSGL_V,"CACHE_PRE_INIT: %"PRId64" [%"PRId64"] %"PRId64"  pre:%"PRId64"  eof:%d  \n",
 	(int64_t)s->min_filepos,(int64_t)s->read_filepos,(int64_t)s->max_filepos,min,s->eof);
     while(s->read_filepos<s->min_filepos || s->max_filepos-s->read_filepos<min){
 	mp_msg(MSGT_CACHE,MSGL_STATUS,MSGTR_CacheFill,