[MPlayer-cvslog] r32559 - in trunk/stream: cache2.c stream.c stream.h

reimar subversion at mplayerhq.hu
Wed Oct 27 21:04:04 CEST 2010


Author: reimar
Date: Wed Oct 27 21:04:04 2010
New Revision: 32559

Log:
Add internal read and seek function to avoid a useless memcpy when using
the cache.

Modified:
   trunk/stream/cache2.c
   trunk/stream/stream.c
   trunk/stream/stream.h

Modified: trunk/stream/cache2.c
==============================================================================
--- trunk/stream/cache2.c	Wed Oct 27 20:38:39 2010	(r32558)
+++ trunk/stream/cache2.c	Wed Oct 27 21:04:04 2010	(r32559)
@@ -182,7 +182,7 @@ static int cache_fill(cache_vars_t *s)
         s->offset= // FIXME!?
         s->min_filepos=s->max_filepos=read; // drop cache content :(
         if(s->stream->eof) stream_reset(s->stream);
-        stream_seek(s->stream,read);
+        stream_seek_internal(s->stream,read);
         mp_msg(MSGT_CACHE,MSGL_DBG2,"Seek done. new pos: 0x%"PRIX64"  \n",(int64_t)stream_tell(s->stream));
       }
   }
@@ -224,7 +224,7 @@ static int cache_fill(cache_vars_t *s)
   s->min_filepos=read-back; // avoid seeking-back to temp area...
 #endif
 
-  len=stream_read(s->stream,&s->buffer[pos],space);
+  len = stream_read_internal(s->stream, &s->buffer[pos], space);
   s->eof= !len;
 
   s->max_filepos+=len;

Modified: trunk/stream/stream.c
==============================================================================
--- trunk/stream/stream.c	Wed Oct 27 20:38:39 2010	(r32558)
+++ trunk/stream/stream.c	Wed Oct 27 21:04:04 2010	(r32559)
@@ -280,36 +280,43 @@ void stream_capture_do(stream_t *s)
   }
 }
 
-int stream_fill_buffer(stream_t *s){
-  int len;
+int stream_read_internal(stream_t *s, void *buf, int len)
+{
   // we will retry even if we already reached EOF previously.
   switch(s->type){
   case STREAMTYPE_STREAM:
 #ifdef CONFIG_NETWORKING
     if( s->streaming_ctrl!=NULL && s->streaming_ctrl->streaming_read ) {
-	    len=s->streaming_ctrl->streaming_read(s->fd,s->buffer,STREAM_BUFFER_SIZE, s->streaming_ctrl);
+      len=s->streaming_ctrl->streaming_read(s->fd, buf, len, s->streaming_ctrl);
     } else
 #endif
     if (s->fill_buffer)
-      len = s->fill_buffer(s, s->buffer, STREAM_BUFFER_SIZE);
+      len = s->fill_buffer(s, buf, len);
     else
-      len=read(s->fd,s->buffer,STREAM_BUFFER_SIZE);
+      len = read(s->fd, buf, len);
     break;
   case STREAMTYPE_DS:
-    len = demux_read_data((demux_stream_t*)s->priv,s->buffer,STREAM_BUFFER_SIZE);
+    len = demux_read_data((demux_stream_t*)s->priv, buf, len);
     break;
 
 
   default:
-    len= s->fill_buffer ? s->fill_buffer(s,s->buffer,STREAM_BUFFER_SIZE) : 0;
+    len= s->fill_buffer ? s->fill_buffer(s, buf, len) : 0;
   }
   if(len<=0){ s->eof=1; return 0; }
   // When reading succeeded we are obviously not at eof.
   // This e.g. avoids issues with eof getting stuck when lavf seeks in MPEG-TS
   s->eof=0;
+  s->pos+=len;
+  return len;
+}
+
+int stream_fill_buffer(stream_t *s){
+  int len = stream_read_internal(s, s->buffer, STREAM_BUFFER_SIZE);
+  if (len <= 0)
+    return 0;
   s->buf_pos=0;
   s->buf_len=len;
-  s->pos+=len;
 //  printf("[%d]",len);fflush(stdout);
   if (s->capture_file)
     stream_capture_do(s);
@@ -327,30 +334,8 @@ int stream_write_buffer(stream_t *s, uns
   return rd;
 }
 
-int stream_seek_long(stream_t *s,off_t pos){
-off_t newpos=0;
-
-//  if( mp_msg_test(MSGT_STREAM,MSGL_DBG3) ) printf("seek_long to 0x%X\n",(unsigned int)pos);
-
-  s->buf_pos=s->buf_len=0;
-
-  if(s->mode == STREAM_WRITE) {
-    if(!s->seek || !s->seek(s,pos))
-      return 0;
-    return 1;
-  }
-
-  if(s->sector_size)
-      newpos = (pos/s->sector_size)*s->sector_size;
-  else
-      newpos = pos&(~((off_t)STREAM_BUFFER_SIZE-1));
-
-if( mp_msg_test(MSGT_STREAM,MSGL_DBG3) ){
-  mp_msg(MSGT_STREAM,MSGL_DBG3, "s->pos=%"PRIX64"  newpos=%"PRIX64"  new_bufpos=%"PRIX64"  buflen=%X  \n",
-    (int64_t)s->pos,(int64_t)newpos,(int64_t)pos,s->buf_len);
-}
-  pos-=newpos;
-
+int stream_seek_internal(stream_t *s, off_t newpos)
+{
 if(newpos==0 || newpos!=s->pos){
   switch(s->type){
   case STREAMTYPE_STREAM:
@@ -368,7 +353,7 @@ if(newpos==0 || newpos!=s->pos){
     }
 
     if( s->streaming_ctrl!=NULL && s->streaming_ctrl->streaming_seek ) {
-      if( s->streaming_ctrl->streaming_seek( s->fd, pos, s->streaming_ctrl )<0 ) {
+      if( s->streaming_ctrl->streaming_seek( s->fd, newpos, s->streaming_ctrl )<0 ) {
         mp_msg(MSGT_STREAM,MSGL_INFO,"Stream not seekable!\n");
         return 1;
       }
@@ -379,9 +364,6 @@ if(newpos==0 || newpos!=s->pos){
       mp_msg(MSGT_STREAM,MSGL_INFO,"Cannot seek backward in linear streams!\n");
       return 1;
     }
-    while(s->pos<newpos){
-      if(stream_fill_buffer(s)<=0) break; // EOF
-    }
     break;
   default:
     // This should at the beginning as soon as all streams are converted
@@ -397,6 +379,41 @@ if(newpos==0 || newpos!=s->pos){
 //} else {
 //   putchar('%');fflush(stdout);
 }
+  return -1;
+}
+
+int stream_seek_long(stream_t *s,off_t pos){
+  int res;
+off_t newpos=0;
+
+//  if( mp_msg_test(MSGT_STREAM,MSGL_DBG3) ) printf("seek_long to 0x%X\n",(unsigned int)pos);
+
+  s->buf_pos=s->buf_len=0;
+
+  if(s->mode == STREAM_WRITE) {
+    if(!s->seek || !s->seek(s,pos))
+      return 0;
+    return 1;
+  }
+
+  if(s->sector_size)
+      newpos = (pos/s->sector_size)*s->sector_size;
+  else
+      newpos = pos&(~((off_t)STREAM_BUFFER_SIZE-1));
+
+if( mp_msg_test(MSGT_STREAM,MSGL_DBG3) ){
+  mp_msg(MSGT_STREAM,MSGL_DBG3, "s->pos=%"PRIX64"  newpos=%"PRIX64"  new_bufpos=%"PRIX64"  buflen=%X  \n",
+    (int64_t)s->pos,(int64_t)newpos,(int64_t)pos,s->buf_len);
+}
+  pos-=newpos;
+
+  res = stream_seek_internal(s, newpos);
+  if (res >= 0)
+    return res;
+
+  while(s->pos<newpos){
+    if(stream_fill_buffer(s)<=0) break; // EOF
+  }
 
 while(stream_fill_buffer(s) > 0 && pos >= 0) {
   if(pos<=s->buf_len){

Modified: trunk/stream/stream.h
==============================================================================
--- trunk/stream/stream.h	Wed Oct 27 20:38:39 2010	(r32558)
+++ trunk/stream/stream.h	Wed Oct 27 21:04:04 2010	(r32559)
@@ -335,6 +335,10 @@ void stream_set_interrupt_callback(int (
 /// Call the interrupt checking callback if there is one and
 /// wait for time milliseconds
 int stream_check_interrupt(int time);
+/// Internal read function bypassing the stream buffer
+int stream_read_internal(stream_t *s, void *buf, int len);
+/// Internal seek function bypassing the stream buffer
+int stream_seek_internal(stream_t *s, off_t newpos);
 
 extern int bluray_angle;
 extern int bluray_chapter;


More information about the MPlayer-cvslog mailing list