From: Michal Sojka Date: Fri, 7 May 2010 22:08:32 +0000 (+0200) Subject: More tuning - still not finisher X-Git-Url: http://rtime.felk.cvut.cz/gitweb/frescor/ffmpeg.git/commitdiff_plain/f23ee889a96f85219df3680276cf09164833440b More tuning - still not finisher --- diff --git a/libavformat/aviobuf.c b/libavformat/aviobuf.c index 1dac20298..c18e9a030 100644 --- a/libavformat/aviobuf.c +++ b/libavformat/aviobuf.c @@ -95,6 +95,8 @@ static void flush_buffer_o_direct(ByteIOContext *s) size_t to_write = (data_len + BLOCK_SIZE - 1) & ~(BLOCK_SIZE - 1); size_t whole_blocks = data_len & ~(BLOCK_SIZE - 1); int64_t res = AVERROR(EPIPE); + + av_log(NULL, AV_LOG_ERROR, " really writing %zx\n", to_write); if (data_len > 0) { if (s->write_packet && !s->error){ int ret= s->write_packet(s->opaque, s->buffer, to_write); @@ -121,7 +123,7 @@ static void flush_buffer_o_direct(ByteIOContext *s) static void flush_buffer(ByteIOContext *s) { - av_log(NULL, AV_LOG_ERROR, "WRITE %p: pos=%zd len=%zd\n", s, s->pos, s->buf_ptr - s->buffer); + av_log(NULL, AV_LOG_ERROR, "WRITE %p: pos=%zx len=%zx\n", s, s->pos, s->buf_ptr - s->buffer); if (s->o_direct_flag) { flush_buffer_o_direct(s); return; @@ -194,7 +196,7 @@ int64_t url_fseek(ByteIOContext *s, int64_t offset, int whence) offset += offset1; } //if (s->o_direct_flag) - av_log(NULL, AV_LOG_ERROR, "SEEK %p: from %llu to %llu\n", s, pos, offset); + av_log(NULL, AV_LOG_ERROR, "SEEK %p: from %llx to %llx\n", s, pos, offset); offset1 = offset - pos; if (!s->must_flush && @@ -202,7 +204,7 @@ int64_t url_fseek(ByteIOContext *s, int64_t offset, int whence) /* can do the seek inside the buffer */ s->buf_ptr = s->buffer + offset1; if (s->o_direct_flag) - av_log(NULL, AV_LOG_ERROR, "Internal seek by %llu\n", offset1); + av_log(NULL, AV_LOG_ERROR, "Internal seek by %llx\n", offset1); } else if(s->is_streamed && !s->write_flag && offset1 >= 0 && offset1 < (s->buf_end - s->buffer) + (1<<16)){ while(s->pos < offset && !s->eof_reached) @@ -219,13 +221,26 @@ int64_t url_fseek(ByteIOContext *s, int64_t offset, int whence) s->must_flush = 1; } #endif /* CONFIG_MUXERS || CONFIG_NETWORK */ -#warning TODO read the whole block from the file to the buffer - if (!s->seek || (res = s->seek(s->opaque, offset, SEEK_SET)) < 0) - return res; - if (!s->write_flag) - s->buf_end = s->buffer; - s->buf_ptr = s->buffer; - s->pos = offset; + if (s->o_direct_flag) { + /* Read the whole block from the seek destination */ + offset1 = offset & ~(BLOCK_SIZE - 1); + if (!s->seek || (res = s->seek(s->opaque, offset1, SEEK_SET)) < 0) + return res; + av_log(NULL, AV_LOG_ERROR, "READ block from %llx\n", offset1); + if ((res = s->read_packet(s->opaque, s->buffer, BLOCK_SIZE)) < 0) + return res; + if (!s->seek || (res = s->seek(s->opaque, offset1, SEEK_SET)) < 0) + return res; + s->buf_ptr = s->buffer + offset - offset1; + s->pos = offset; + } else { + if (!s->seek || (res = s->seek(s->opaque, offset, SEEK_SET)) < 0) + return res; + if (!s->write_flag) + s->buf_end = s->buffer; + s->buf_ptr = s->buffer; + s->pos = offset; + } } s->eof_reached = 0; return offset; @@ -660,7 +675,6 @@ int url_fopen(ByteIOContext **s, const char *filename, int flags) URLContext *h; int err; - av_log(NULL, AV_LOG_ERROR, "%s: %p %s\n", __func__, s, filename); err = url_open(&h, filename, flags); if (err < 0) return err;