diff options
author | reimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2010-10-27 19:04:04 +0000 |
---|---|---|
committer | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2010-11-07 21:46:22 +0200 |
commit | f94717cdc4dfb35ac8dc3b5d593f6e523fdd621e (patch) | |
tree | 596d9111d6cf4f35eddeef339097d06f1ec417a0 /stream/stream.c | |
parent | c6fb4e2aa2f5a16aaa35411201c600c8ae801c38 (diff) | |
download | mpv-f94717cdc4dfb35ac8dc3b5d593f6e523fdd621e.tar.bz2 mpv-f94717cdc4dfb35ac8dc3b5d593f6e523fdd621e.tar.xz |
cache, stream: avoid extra memcpy when using cache
Add a stream_read_internal() function that reads directly into a given
buffer instead of the stream's internal one. Use this to read directly
into cache memory, avoiding a memcpy(). This requires also adding a
stream_seek_internal() as the normal seek function reads into the
stream's buffer.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32559 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'stream/stream.c')
-rw-r--r-- | stream/stream.c | 89 |
1 files changed, 53 insertions, 36 deletions
diff --git a/stream/stream.c b/stream/stream.c index ca45f511e5..041b3a8c67 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -275,36 +275,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); @@ -322,30 +329,8 @@ int stream_write_buffer(stream_t *s, unsigned char *buf, int len) { 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: @@ -363,7 +348,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; } @@ -374,9 +359,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 @@ -392,6 +374,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 + } s->eof = 0; // EOF reset when seek succeeds. while (stream_fill_buffer(s) > 0) { |