[MPlayer-cvslog] r34792 - in trunk: cfg-common.h mencoder.c mplayer.c osdep/shmem.c osdep/shmem.h stream/cache2.c stream/stream.h

reimar subversion at mplayerhq.hu
Sun Mar 4 15:47:37 CET 2012


Author: reimar
Date: Sun Mar  4 15:47:37 2012
New Revision: 34792

Log:
Allow using a cache size of up to 4 TB.
Obviously anything close to 4 GB will always fail
on 32 bit systems.

Modified:
   trunk/cfg-common.h
   trunk/mencoder.c
   trunk/mplayer.c
   trunk/osdep/shmem.c
   trunk/osdep/shmem.h
   trunk/stream/cache2.c
   trunk/stream/stream.h

Modified: trunk/cfg-common.h
==============================================================================
--- trunk/cfg-common.h	Sun Mar  4 15:37:31 2012	(r34791)
+++ trunk/cfg-common.h	Sun Mar  4 15:47:37 2012	(r34792)
@@ -315,7 +315,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},
     {"nocache", &stream_cache_size, CONF_TYPE_FLAG, 0, 1, 0, NULL},
     {"cache-min", &stream_cache_min_percent, CONF_TYPE_FLOAT, CONF_RANGE, 0, 99, NULL},
     {"cache-seek-min", &stream_cache_seek_min_percent, CONF_TYPE_FLOAT, CONF_RANGE, 0, 99, NULL},

Modified: trunk/mencoder.c
==============================================================================
--- trunk/mencoder.c	Sun Mar  4 15:37:31 2012	(r34791)
+++ trunk/mencoder.c	Sun Mar  4 15:47:37 2012	(r34792)
@@ -678,7 +678,7 @@ if(stream->type==STREAMTYPE_DVDNAV){
 
   stream->start_pos+=seek_to_byte;
 
-  if(stream_cache_size>0) stream_enable_cache(stream,stream_cache_size*1024,0,0);
+  if(stream_cache_size>0) stream_enable_cache(stream,stream_cache_size*1024ull,0,0);
 
   if(demuxer2) audio_id=-2; /* do NOT read audio packets... */
 

Modified: trunk/mplayer.c
==============================================================================
--- trunk/mplayer.c	Sun Mar  4 15:37:31 2012	(r34791)
+++ trunk/mplayer.c	Sun Mar  4 15:47:37 2012	(r34792)
@@ -3298,9 +3298,9 @@ goto_enable_cache:
     if (stream_cache_size > 0) {
         int res;
         current_module = "enable_cache";
-        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 ((mpctx->eof = libmpdemux_was_interrupted(PT_NEXT_ENTRY)))
                 goto goto_next_file;

Modified: trunk/osdep/shmem.c
==============================================================================
--- trunk/osdep/shmem.c	Sun Mar  4 15:37:31 2012	(r34791)
+++ trunk/osdep/shmem.c	Sun Mar  4 15:47:37 2012	(r34792)
@@ -36,6 +36,7 @@
 #endif
 #include <sys/socket.h>
 #include <fcntl.h>
+#include <inttypes.h>
 
 #include "mp_msg.h"
 #include "shmem.h"
@@ -55,16 +56,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
@@ -75,7 +81,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
@@ -92,7 +98,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");
@@ -101,19 +107,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;

Modified: trunk/osdep/shmem.h
==============================================================================
--- trunk/osdep/shmem.h	Sun Mar  4 15:37:31 2012	(r34791)
+++ trunk/osdep/shmem.h	Sun Mar  4 15:47:37 2012	(r34792)
@@ -19,7 +19,7 @@
 #ifndef MPLAYER_SHMEM_H
 #define MPLAYER_SHMEM_H
 
-void* shmem_alloc(int size);
-void shmem_free(void* p,int size);
+void* shmem_alloc(int64_t size);
+void shmem_free(void* p,int64_t size);
 
 #endif /* MPLAYER_SHMEM_H */

Modified: trunk/stream/cache2.c
==============================================================================
--- trunk/stream/cache2.c	Sun Mar  4 15:37:31 2012	(r34791)
+++ trunk/stream/cache2.c	Sun Mar  4 15:47:37 2012	(r34792)
@@ -70,11 +70,11 @@ 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
@@ -117,9 +117,9 @@ static int cache_read(cache_vars_t *s, u
 {
   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_read(cache_vars_t *s, u
 
 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 @@ static int cache_execute_control(cache_v
   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 @@ 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
@@ -350,8 +350,8 @@ static void shared_free(void *ptr, int s
 #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 @@ static void cache_mainloop(cache_vars_t 
 /**
  * \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 @@ int stream_enable_cache(stream_t *stream
     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 @@ int stream_enable_cache(stream_t *stream
         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,

Modified: trunk/stream/stream.h
==============================================================================
--- trunk/stream/stream.h	Sun Mar  4 15:37:31 2012	(r34791)
+++ trunk/stream/stream.h	Sun Mar  4 15:47:37 2012	(r34792)
@@ -191,7 +191,7 @@ int stream_seek_long(stream_t *s, off_t 
 void stream_capture_do(stream_t *s);
 
 #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);
 #else


More information about the MPlayer-cvslog mailing list